[llvm-branch-commits] [lld] [NFC][ELF] Avoid need to copy Symbol in replaceWithDefined (PR #210612)
Jessica Clarke via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Sun Jul 19 09:33:40 PDT 2026
https://github.com/jrtc27 created https://github.com/llvm/llvm-project/pull/210612
Firstly, by overwriting the symbol, it will have its existing flags, so
there is no need to copy them back; all we need to do is mask out the
other bits on the existing symbol.
Secondly, copying the whole symbol just to preserve the symbol version
that gets cleared by Defined::overwrite is a waste; just copy the single
member to reinstate it.
---
<sub>Stack created with <a href="https://github.com/github/gh-stack">GitHub Stacks CLI</a> • <a href="https://gh.io/stacks-feedback">Give Feedback 💬</a></sub>
>From 27e4ed3aae2865b474646cabb25aaa9902832468 Mon Sep 17 00:00:00 2001
From: Jessica Clarke <jrtc27 at jrtc27.com>
Date: Sun, 19 Jul 2026 13:31:59 +0100
Subject: [PATCH] [NFC][ELF] Avoid need to copy Symbol in replaceWithDefined
Firstly, by overwriting the symbol, it will have its existing flags, so
there is no need to copy them back; all we need to do is mask out the
other bits on the existing symbol.
Secondly, copying the whole symbol just to preserve the symbol version
that gets cleared by Defined::overwrite is a waste; just copy the single
member to reinstate it.
---
lld/ELF/Relocations.cpp | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index 4702d941d28ca..9050d97dd4573 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -243,16 +243,15 @@ static SmallPtrSet<SharedSymbol *, 4> getSymbolsAt(Ctx &ctx, SharedSymbol &ss) {
// location.
static void replaceWithDefined(Ctx &ctx, Symbol &sym, SectionBase &sec,
uint64_t value, uint64_t size) {
- Symbol old = sym;
+ uint16_t versionId = sym.versionId;
Defined(ctx, sym.file, StringRef(), sym.binding, sym.stOther, sym.type, value,
size, &sec)
.overwrite(sym);
- sym.versionId = old.versionId;
+ sym.versionId = versionId;
sym.isUsedInRegularObj = true;
// A copy relocated alias may need a GOT entry.
- sym.flags.store(old.flags.load(std::memory_order_relaxed) & NEEDS_GOT,
- std::memory_order_relaxed);
+ sym.flags.fetch_and(NEEDS_GOT, std::memory_order_relaxed);
}
// Reserve space in .bss or .bss.rel.ro for copy relocation.
More information about the llvm-branch-commits
mailing list