[llvm-branch-commits] [lld] [NFC][ELF] Only create alias in handleNonPreemptibleIfunc if needed (PR #210613)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Sun Jul 19 09:34:19 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lld-elf
Author: Jessica Clarke (jrtc27)
<details>
<summary>Changes</summary>
In the no direct relocations case, the original IFUNC symbol keeps its
value, and so there's no need to create a separate alias; it's only
needed when the original symbol is being redirected to the IPLT as a
normal function symbol.
This change also shifts the isInIplt assignment to be explicit and
mirror the allocateAux/pltIdx uses, rather than relying on makeDefined
copying it, and to be clear that this is in fact deliberately and
consistently being copied like them.
---
<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/210613.diff
1 Files Affected:
- (modified) lld/ELF/Relocations.cpp (+23-18)
``````````diff
diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index 9050d97dd4573..71daf6fb95a8f 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -1230,11 +1230,10 @@ static bool handleNonPreemptibleIfunc(Ctx &ctx, Symbol &sym, uint16_t flags) {
// ("canonicalizing" it), so all references see the same address, and the
// resolver is called exactly once. This may result in two GOT entries: one
// in .got.plt for the IRELATIVE, and one in .got pointing to the canonical
- // IPLT entry (for GOT-generating relocations).
- //
- // We clone the symbol to preserve the original resolver address for the
- // IRELATIVE addend. The clone is tracked in ctx.irelativeSyms so that linker
- // relaxation can adjust its value when the resolver address changes.
+ // IPLT entry (for GOT-generating relocations). We clone the symbol to
+ // preserve the original resolver address for the IRELATIVE addend. The clone
+ // is tracked in ctx.irelativeSyms so that linker relaxation can adjust its
+ // value when the resolver address changes.
//
// Note: IRELATIVE relocations are needed even in static executables; see
// `addRelIpltSymbols`.
@@ -1244,20 +1243,23 @@ static bool handleNonPreemptibleIfunc(Ctx &ctx, Symbol &sym, uint16_t flags) {
if (!(flags & (NEEDS_GOT | NEEDS_PLT | HAS_DIRECT_RELOC)))
return true;
- sym.isInIplt = true;
-
- auto *irelativeSym = makeDefined(cast<Defined>(sym));
- irelativeSym->allocateAux(ctx);
- ctx.irelativeSyms.push_back(irelativeSym);
- auto &dyn = getIRelativeSection(ctx);
- addPltEntry(ctx, *ctx.in.iplt, *ctx.in.igotPlt, dyn, ctx.target->iRelativeRel,
- *irelativeSym);
- sym.allocateAux(ctx);
- ctx.symAux.back().pltIdx = ctx.symAux[irelativeSym->auxIdx].pltIdx;
+ auto addIpltEntry = [&](Symbol &irelativeSym) {
+ irelativeSym.isInIplt = true;
+ irelativeSym.allocateAux(ctx);
+ auto &dyn = getIRelativeSection(ctx);
+ addPltEntry(ctx, *ctx.in.iplt, *ctx.in.igotPlt, dyn,
+ ctx.target->iRelativeRel, irelativeSym);
+ };
if (flags & HAS_DIRECT_RELOC) {
// Change the value to the IPLT and redirect all references to it.
auto &d = cast<Defined>(sym);
+ auto *irelativeSym = makeDefined(d);
+ addIpltEntry(*irelativeSym);
+ ctx.irelativeSyms.push_back(irelativeSym);
+ sym.isInIplt = true;
+ sym.allocateAux(ctx);
+ ctx.symAux.back().pltIdx = ctx.symAux[irelativeSym->auxIdx].pltIdx;
d.section = ctx.in.iplt.get();
d.value = d.getPltIdx(ctx) * ctx.target->ipltEntrySize;
d.size = 0;
@@ -1270,9 +1272,12 @@ static bool handleNonPreemptibleIfunc(Ctx &ctx, Symbol &sym, uint16_t flags) {
"R_AARCH64_AUTH_IRELATIVE is not supported yet");
addGotEntry(ctx, sym);
}
- } else if (flags & NEEDS_GOT) {
- // Redirect GOT accesses to point to the Igot.
- sym.gotInIgot = true;
+ } else {
+ addIpltEntry(sym);
+ if (flags & NEEDS_GOT) {
+ // Redirect GOT accesses to point to the Igot.
+ sym.gotInIgot = true;
+ }
}
return true;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/210613
More information about the llvm-branch-commits
mailing list