[lld] 5a0261c - [ELF] Defer ctx.hasTlsIe assignment to postScanRelocations. NFC
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sun Feb 15 18:20:57 PST 2026
Author: Fangrui Song
Date: 2026-02-15T18:20:51-08:00
New Revision: 5a0261c5534d05085d4b0d969a257cb85ac9c0b4
URL: https://github.com/llvm/llvm-project/commit/5a0261c5534d05085d4b0d969a257cb85ac9c0b4
DIFF: https://github.com/llvm/llvm-project/commit/5a0261c5534d05085d4b0d969a257cb85ac9c0b4.diff
LOG: [ELF] Defer ctx.hasTlsIe assignment to postScanRelocations. NFC
Move ctx.hasTlsIe stores from the relocation scan phase to
postScanRelocations. The ctx.hasTlsIe value is ignored for
`!shared` case, so we can remove some redundant assignment.
Added:
Modified:
lld/ELF/RelocScan.h
lld/ELF/Relocations.cpp
Removed:
################################################################################
diff --git a/lld/ELF/RelocScan.h b/lld/ELF/RelocScan.h
index d52afda26effb..aaa3f9fd6e9d3 100644
--- a/lld/ELF/RelocScan.h
+++ b/lld/ELF/RelocScan.h
@@ -109,7 +109,6 @@ class RelocScan {
// Optimize to Local Exec.
sec->addReloc({R_TPREL, type, offset, addend, &sym});
} else {
- ctx.hasTlsIe.store(true, std::memory_order_relaxed);
sym.setFlags(NEEDS_TLSIE);
// R_GOT (absolute GOT address) needs a RELATIVE dynamic relocation in
// PIC. This is used by R_386_TLS_IE.
@@ -146,7 +145,6 @@ class RelocScan {
}
if (sym.isPreemptible) {
// Optimize to Initial Exec.
- ctx.hasTlsIe.store(true, std::memory_order_relaxed);
sym.setFlags(NEEDS_TLSIE);
sec->addReloc({ieExpr, type, offset, addend, &sym});
} else {
@@ -164,7 +162,6 @@ class RelocScan {
sec->addReloc({sharedExpr, type, offset, addend, &sym});
} else if (sym.isPreemptible) {
// Optimize to Initial Exec.
- ctx.hasTlsIe.store(true, std::memory_order_relaxed);
sym.setFlags(NEEDS_TLSIE);
sec->addReloc({ieExpr, type, offset, addend, &sym});
} else {
diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index 1827e4800cd7f..1074e7f24db43 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -1292,7 +1292,6 @@ unsigned RelocScan::handleTlsRelocation(RelExpr expr, RelType type,
if (oneof<R_GOT, R_GOTPLT, R_GOT_PC, RE_AARCH64_GOT_PAGE_PC,
RE_LOONGARCH_GOT_PAGE_PC, R_GOT_OFF, R_TLSIE_HINT>(expr)) {
- ctx.hasTlsIe.store(true, std::memory_order_relaxed);
// Initial-Exec relocs can be optimized to Local-Exec if the symbol is
// locally defined. This is not supported on SystemZ.
if (execOptimize && isLocalInExecutable && ctx.arg.emachine != EM_S390) {
@@ -1313,7 +1312,6 @@ unsigned RelocScan::handleTlsRelocation(RelExpr expr, RelType type,
// NEEDS_TLSIE shouldn't set. So we check independently.
if (ctx.arg.emachine == EM_LOONGARCH && expr == RE_LOONGARCH_GOT &&
execOptimize && isLocalInExecutable) {
- ctx.hasTlsIe.store(true, std::memory_order_relaxed);
sec->addReloc({R_RELAX_TLS_IE_TO_LE, type, offset, addend, &sym});
return 1;
}
@@ -1506,6 +1504,7 @@ static bool handleNonPreemptibleIfunc(Ctx &ctx, Symbol &sym, uint16_t flags) {
}
void elf::postScanRelocations(Ctx &ctx) {
+ bool needsTlsIe = false;
auto fn = [&](Symbol &sym) {
auto flags = sym.flags.load(std::memory_order_relaxed);
if (handleNonPreemptibleIfunc(ctx, sym, flags))
@@ -1605,8 +1604,10 @@ void elf::postScanRelocations(Ctx &ctx) {
{R_ABS, ctx.target->tlsOffsetRel, sym.getGotOffset(ctx), 0, &sym});
}
- if (flags & NEEDS_TLSIE)
+ if (flags & NEEDS_TLSIE) {
+ needsTlsIe = true;
addTpOffsetGotEntry(ctx, sym);
+ }
};
GotSection *got = ctx.in.got.get();
@@ -1629,6 +1630,9 @@ void elf::postScanRelocations(Ctx &ctx) {
for (Symbol *sym : file->getLocalSymbols())
fn(*sym);
+ if (needsTlsIe)
+ ctx.hasTlsIe.store(true, std::memory_order_relaxed);
+
if (ctx.arg.branchToBranch)
ctx.target->applyBranchToBranchOpt();
}
More information about the llvm-commits
mailing list