diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp index ed53228359f86..7579def5865bb 100644 --- a/lld/ELF/Relocations.cpp +++ b/lld/ELF/Relocations.cpp @@ -885,10 +885,12 @@ static void addPltEntry(Ctx &ctx, PltSection &plt, GotPltSection &gotPlt, RelocationBaseSection &rel, RelType type, Symbol &sym) { plt.addEntry(sym); gotPlt.addEntry(sym); - rel.addReloc({type, &gotPlt, sym.getGotPltOffset(ctx), - sym.isPreemptible ? DynamicReloc::AgainstSymbol - : DynamicReloc::AddendOnly, - sym, 0, R_ABS}); + if (sym.isPreemptible) + rel.addReloc({type, &gotPlt, sym.getGotPltOffset(ctx), + DynamicReloc::AgainstSymbol, sym, 0, R_ADDEND}); + else + rel.addReloc({type, &gotPlt, sym.getGotPltOffset(ctx), + DynamicReloc::AddendOnly, sym, 0, R_ABS}); } void elf::addGotEntry(Ctx &ctx, Symbol &sym) { @@ -899,7 +901,7 @@ void elf::addGotEntry(Ctx &ctx, Symbol &sym) { if (sym.isPreemptible) { ctx.mainPart->relaDyn->addReloc({ctx.target->gotRel, ctx.in.got.get(), off, DynamicReloc::AgainstSymbol, sym, 0, - R_ABS}); + R_ADDEND}); return; } @@ -921,7 +923,7 @@ static void addGotAuthEntry(Ctx &ctx, Symbol &sym) { if (sym.isPreemptible) { ctx.mainPart->relaDyn->addReloc({R_AARCH64_AUTH_GLOB_DAT, ctx.in.got.get(), off, DynamicReloc::AgainstSymbol, sym, 0, - R_ABS}); + R_ADDEND}); return; } diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index da0cf1298d1ab..90f87ddb79005 100644 --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -1065,9 +1065,9 @@ void MipsGotSection::build() { // for the TP-relative offset as we don't know how much other data will // be allocated before us in the static TLS block. if (s->isPreemptible || ctx.arg.shared) - ctx.mainPart->relaDyn->addReloc( - {ctx.target->tlsGotRel, this, offset, - DynamicReloc::AgainstSymbolWithTargetVA, *s, 0, R_ABS}); + ctx.mainPart->relaDyn->addReloc({ctx.target->tlsGotRel, this, offset, + DynamicReloc::AgainstSymbol, *s, 0, + R_ABS}); } for (std::pair &p : got.dynTlsSymbols) { Symbol *s = p.first; @@ -1650,14 +1650,11 @@ int64_t DynamicReloc::computeAddend(Ctx &ctx) const { case Computed: llvm_unreachable("addend already computed"); case AddendOnly: - case AgainstSymbolWithTargetVA: { + case AgainstSymbol: { uint64_t ca = inputSec->getRelocTargetVA( ctx, Relocation{expr, type, 0, addend, sym}, getOffset()); return ctx.arg.is64 ? ca : SignExtend64<32>(ca); } - case AgainstSymbol: - assert(sym != nullptr); - return addend; case MipsMultiGotPage: assert(sym == nullptr); return getMipsPageAddr(outputSec->addr) + addend; @@ -1700,7 +1697,7 @@ void RelocationBaseSection::addAddendOnlyRelocIfNonPreemptible( // No need to write an addend to the section for preemptible symbols. if (sym.isPreemptible) addReloc({dynType, &isec, offsetInSec, DynamicReloc::AgainstSymbol, sym, 0, - R_ABS}); + R_ADDEND}); else addReloc(DynamicReloc::AddendOnly, dynType, isec, offsetInSec, sym, 0, R_ABS, addendRelType); diff --git a/lld/ELF/SyntheticSections.h b/lld/ELF/SyntheticSections.h index 8185417755d25..bd8fdc5f00391 100644 --- a/lld/ELF/SyntheticSections.h +++ b/lld/ELF/SyntheticSections.h @@ -427,13 +427,9 @@ class DynamicReloc { /// Useful for various relative and TLS relocations (e.g. R_X86_64_TPOFF64). AddendOnly, /// The resulting dynamic relocation references symbol #sym from the dynamic - /// symbol table and uses #addend as the value of computeAddend(ctx). + /// symbol table and uses InputSection::getRelocTargetVA() for the final + /// addend. AgainstSymbol, - /// The resulting dynamic relocation references symbol #sym from the dynamic - /// symbol table and uses InputSection::getRelocTargetVA() + #addend for the - /// final addend. It can be used for relocations that write the symbol VA as - // the addend (e.g. R_MIPS_TLS_TPREL64) but still reference the symbol. - AgainstSymbolWithTargetVA, /// This is used by the MIPS multi-GOT implementation. It relocates /// addresses of 64kb pages that lie inside the output section. MipsMultiGotPage, @@ -463,7 +459,7 @@ class DynamicReloc { uint32_t getSymIndex(SymbolTableBaseSection *symTab) const; bool needsDynSymIndex() const { assert(kind != Computed && "cannot check kind after computeRaw"); - return kind == AgainstSymbol || kind == AgainstSymbolWithTargetVA; + return kind == AgainstSymbol; } /// Computes the addend of the dynamic relocation. Note that this is not the