[lld] [NFC][ELF] Only create alias in handleNonPreemptibleIfunc if needed (PR #210613)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 2 12:40:09 PDT 2026
https://github.com/MaskRay updated https://github.com/llvm/llvm-project/pull/210613
>From f12f76c8cc485321da15591f41362c31f167be82 Mon Sep 17 00:00:00 2001
From: Jessica Clarke <jrtc27 at jrtc27.com>
Date: Sun, 19 Jul 2026 14:02:36 +0100
Subject: [PATCH] [NFC][ELF] Only create alias in handleNonPreemptibleIfunc if
needed
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.
---
lld/ELF/Relocations.cpp | 41 +++++++++++++++++++++++------------------
1 file changed, 23 insertions(+), 18 deletions(-)
diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index d335da63ebf84..fd852e3dba1ae 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -1232,11 +1232,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`.
@@ -1246,20 +1245,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;
@@ -1272,9 +1274,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;
}
More information about the llvm-commits
mailing list