[llvm-branch-commits] [lld] [NFC][ELF] Avoid need to copy Symbol in replaceWithDefined (PR #210612)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Sun Jul 19 09:34:18 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lld-elf
Author: Jessica Clarke (jrtc27)
<details>
<summary>Changes</summary>
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>
---
Full diff: https://github.com/llvm/llvm-project/pull/210612.diff
1 Files Affected:
- (modified) lld/ELF/Relocations.cpp (+3-4)
``````````diff
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.
``````````
</details>
https://github.com/llvm/llvm-project/pull/210612
More information about the llvm-branch-commits
mailing list