Skip to content

[NFCI][ELF] Merge AgainstSymbol and AgainstSymbolWithTargetVA #150798

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions lld/ELF/Relocations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}

Expand All @@ -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;
}

Expand Down
13 changes: 5 additions & 8 deletions lld/ELF/SyntheticSections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Symbol *, size_t> &p : got.dynTlsSymbols) {
Symbol *s = p.first;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 3 additions & 7 deletions lld/ELF/SyntheticSections.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
Loading