From 804b632a64d56a4abee7206093e76635a8ab9070 Mon Sep 17 00:00:00 2001 From: Jessica Clarke Date: Sat, 26 Jul 2025 21:32:57 +0100 Subject: [PATCH 1/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20ch?= =?UTF-8?q?anges=20to=20main=20this=20commit=20is=20based=20on?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Created using spr 1.3.5 [skip ci] --- lld/ELF/Config.h | 2 ++ lld/ELF/Driver.cpp | 1 + lld/ELF/Relocations.cpp | 3 +-- lld/ELF/Target.cpp | 3 +-- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lld/ELF/Config.h b/lld/ELF/Config.h index d9639b06ca4bf..958e5caaf0dfa 100644 --- a/lld/ELF/Config.h +++ b/lld/ELF/Config.h @@ -701,6 +701,8 @@ struct Ctx : CommonLinkerContext { std::unique_ptr tar; // InputFile for linker created symbols with no source location. InputFile *internalFile = nullptr; + // Dummy Undefined for relocations without a symbol. + Undefined *dummySym = nullptr; // True if symbols can be exported (isExported) or preemptible. bool hasDynsym = false; // True if SHT_LLVM_SYMPART is used. diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index 21d228eda6470..4dcf577ebcb16 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -3138,6 +3138,7 @@ template void LinkerDriver::link(opt::InputArgList &args) { ctx.symtab->insert(arg->getValue())->traced = true; ctx.internalFile = createInternalFile(ctx, ""); + ctx.dummySym = make(ctx.internalFile, "", STB_LOCAL, 0, 0); // Handle -u/--undefined before input files. If both a.a and b.so define foo, // -u foo a.a b.so will extract a.a. diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp index bd22fe2f1aa25..e847e85b060fe 100644 --- a/lld/ELF/Relocations.cpp +++ b/lld/ELF/Relocations.cpp @@ -1948,13 +1948,12 @@ void elf::postScanRelocations(Ctx &ctx) { GotSection *got = ctx.in.got.get(); if (ctx.needsTlsLd.load(std::memory_order_relaxed) && got->addTlsIndex()) { - static Undefined dummy(ctx.internalFile, "", STB_LOCAL, 0, 0); if (ctx.arg.shared) ctx.mainPart->relaDyn->addReloc( {ctx.target->tlsModuleIndexRel, got, got->getTlsIndexOff()}); else got->addConstant({R_ADDEND, ctx.target->symbolicRel, - got->getTlsIndexOff(), 1, &dummy}); + got->getTlsIndexOff(), 1, ctx.dummySym}); } assert(ctx.symAux.size() == 1); diff --git a/lld/ELF/Target.cpp b/lld/ELF/Target.cpp index ad7d57d30668d..4946484074d05 100644 --- a/lld/ELF/Target.cpp +++ b/lld/ELF/Target.cpp @@ -105,10 +105,9 @@ ErrorPlace elf::getErrorPlace(Ctx &ctx, const uint8_t *loc) { if (isecLoc <= loc && loc < isecLoc + isec->getSize()) { std::string objLoc = isec->getLocation(loc - isecLoc); // Return object file location and source file location. - Undefined dummy(ctx.internalFile, "", STB_LOCAL, 0, 0); ELFSyncStream msg(ctx, DiagLevel::None); if (isec->file) - msg << isec->getSrcMsg(dummy, loc - isecLoc); + msg << isec->getSrcMsg(*ctx.dummySym, loc - isecLoc); return {isec, objLoc + ": ", std::string(msg.str())}; } } From e6caa93407ee13898966f6975fd1a04cd99643d9 Mon Sep 17 00:00:00 2001 From: Jessica Clarke Date: Sat, 26 Jul 2025 22:05:10 +0100 Subject: [PATCH 2/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20ch?= =?UTF-8?q?anges=20introduced=20through=20rebase?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Created using spr 1.3.5 [skip ci] --- lld/ELF/SyntheticSections.cpp | 4 +++- lld/ELF/SyntheticSections.h | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index efec41a737b62..16f1ab36a88b1 100644 --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -1647,6 +1647,8 @@ uint64_t DynamicReloc::getOffset() const { int64_t DynamicReloc::computeAddend(Ctx &ctx) const { switch (kind) { + case Computed: + llvm_unreachable("addend already computed"); case AddendOnly: assert(sym == nullptr); return addend; @@ -1748,7 +1750,7 @@ void DynamicReloc::computeRaw(Ctx &ctx, SymbolTableBaseSection *symt) { r_offset = getOffset(); r_sym = getSymIndex(symt); addend = computeAddend(ctx); - kind = AddendOnly; // Catch errors + kind = Computed; // Catch errors } void RelocationBaseSection::computeRels() { diff --git a/lld/ELF/SyntheticSections.h b/lld/ELF/SyntheticSections.h index 5f01513630597..8e069e3dd9565 100644 --- a/lld/ELF/SyntheticSections.h +++ b/lld/ELF/SyntheticSections.h @@ -419,6 +419,9 @@ class StringTableSection final : public SyntheticSection { class DynamicReloc { public: enum Kind { + /// The resulting dynamic relocation has already had its addend computed. + /// Calling computeAddend() is an error. Only for internal use. + Computed, /// The resulting dynamic relocation does not reference a symbol (#sym must /// be nullptr) and uses #addend as the result of computeAddend(ctx). AddendOnly, @@ -461,6 +464,7 @@ class DynamicReloc { uint64_t getOffset() const; uint32_t getSymIndex(SymbolTableBaseSection *symTab) const; bool needsDynSymIndex() const { + assert(kind != Computed && "cannot check kind after computeRaw"); return kind == AgainstSymbol || kind == AgainstSymbolWithTargetVA; }