Skip to content

Commit 304c96a

Browse files
jrtc27github-actions[bot]
authored andcommitted
Automerge: [NFCI][ELF] Merge AgainstSymbol and AgainstSymbolWithTargetVA
The former is just a special case of the latter, ignoring the expr and always just using the addend. If we use R_ADDEND as expr (which previously had no effect, and so was misleadingly R_ABS not R_ADDEND in all but one use) then we don't need to maintain this as a separate case. Aside from the internal Computed Kind, this just leaves MipsMultiGotPage as a special case; the only difference between the other two Kind values is what needsDynSymIndex returns. Reviewers: MaskRay Reviewed By: MaskRay Pull Request: llvm/llvm-project#150798
2 parents 27c0471 + 54df4b8 commit 304c96a

File tree

3 files changed

+16
-21
lines changed

3 files changed

+16
-21
lines changed

lld/ELF/Relocations.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -885,10 +885,12 @@ static void addPltEntry(Ctx &ctx, PltSection &plt, GotPltSection &gotPlt,
885885
RelocationBaseSection &rel, RelType type, Symbol &sym) {
886886
plt.addEntry(sym);
887887
gotPlt.addEntry(sym);
888-
rel.addReloc({type, &gotPlt, sym.getGotPltOffset(ctx),
889-
sym.isPreemptible ? DynamicReloc::AgainstSymbol
890-
: DynamicReloc::AddendOnly,
891-
sym, 0, R_ABS});
888+
if (sym.isPreemptible)
889+
rel.addReloc({type, &gotPlt, sym.getGotPltOffset(ctx),
890+
DynamicReloc::AgainstSymbol, sym, 0, R_ADDEND});
891+
else
892+
rel.addReloc({type, &gotPlt, sym.getGotPltOffset(ctx),
893+
DynamicReloc::AddendOnly, sym, 0, R_ABS});
892894
}
893895

894896
void elf::addGotEntry(Ctx &ctx, Symbol &sym) {
@@ -899,7 +901,7 @@ void elf::addGotEntry(Ctx &ctx, Symbol &sym) {
899901
if (sym.isPreemptible) {
900902
ctx.mainPart->relaDyn->addReloc({ctx.target->gotRel, ctx.in.got.get(), off,
901903
DynamicReloc::AgainstSymbol, sym, 0,
902-
R_ABS});
904+
R_ADDEND});
903905
return;
904906
}
905907

@@ -921,7 +923,7 @@ static void addGotAuthEntry(Ctx &ctx, Symbol &sym) {
921923
if (sym.isPreemptible) {
922924
ctx.mainPart->relaDyn->addReloc({R_AARCH64_AUTH_GLOB_DAT, ctx.in.got.get(),
923925
off, DynamicReloc::AgainstSymbol, sym, 0,
924-
R_ABS});
926+
R_ADDEND});
925927
return;
926928
}
927929

lld/ELF/SyntheticSections.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,9 +1065,9 @@ void MipsGotSection::build() {
10651065
// for the TP-relative offset as we don't know how much other data will
10661066
// be allocated before us in the static TLS block.
10671067
if (s->isPreemptible || ctx.arg.shared)
1068-
ctx.mainPart->relaDyn->addReloc(
1069-
{ctx.target->tlsGotRel, this, offset,
1070-
DynamicReloc::AgainstSymbolWithTargetVA, *s, 0, R_ABS});
1068+
ctx.mainPart->relaDyn->addReloc({ctx.target->tlsGotRel, this, offset,
1069+
DynamicReloc::AgainstSymbol, *s, 0,
1070+
R_ABS});
10711071
}
10721072
for (std::pair<Symbol *, size_t> &p : got.dynTlsSymbols) {
10731073
Symbol *s = p.first;
@@ -1650,14 +1650,11 @@ int64_t DynamicReloc::computeAddend(Ctx &ctx) const {
16501650
case Computed:
16511651
llvm_unreachable("addend already computed");
16521652
case AddendOnly:
1653-
case AgainstSymbolWithTargetVA: {
1653+
case AgainstSymbol: {
16541654
uint64_t ca = inputSec->getRelocTargetVA(
16551655
ctx, Relocation{expr, type, 0, addend, sym}, getOffset());
16561656
return ctx.arg.is64 ? ca : SignExtend64<32>(ca);
16571657
}
1658-
case AgainstSymbol:
1659-
assert(sym != nullptr);
1660-
return addend;
16611658
case MipsMultiGotPage:
16621659
assert(sym == nullptr);
16631660
return getMipsPageAddr(outputSec->addr) + addend;
@@ -1700,7 +1697,7 @@ void RelocationBaseSection::addAddendOnlyRelocIfNonPreemptible(
17001697
// No need to write an addend to the section for preemptible symbols.
17011698
if (sym.isPreemptible)
17021699
addReloc({dynType, &isec, offsetInSec, DynamicReloc::AgainstSymbol, sym, 0,
1703-
R_ABS});
1700+
R_ADDEND});
17041701
else
17051702
addReloc(DynamicReloc::AddendOnly, dynType, isec, offsetInSec, sym, 0,
17061703
R_ABS, addendRelType);

lld/ELF/SyntheticSections.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -427,13 +427,9 @@ class DynamicReloc {
427427
/// Useful for various relative and TLS relocations (e.g. R_X86_64_TPOFF64).
428428
AddendOnly,
429429
/// The resulting dynamic relocation references symbol #sym from the dynamic
430-
/// symbol table and uses #addend as the value of computeAddend(ctx).
430+
/// symbol table and uses InputSection::getRelocTargetVA() for the final
431+
/// addend.
431432
AgainstSymbol,
432-
/// The resulting dynamic relocation references symbol #sym from the dynamic
433-
/// symbol table and uses InputSection::getRelocTargetVA() + #addend for the
434-
/// final addend. It can be used for relocations that write the symbol VA as
435-
// the addend (e.g. R_MIPS_TLS_TPREL64) but still reference the symbol.
436-
AgainstSymbolWithTargetVA,
437433
/// This is used by the MIPS multi-GOT implementation. It relocates
438434
/// addresses of 64kb pages that lie inside the output section.
439435
MipsMultiGotPage,
@@ -463,7 +459,7 @@ class DynamicReloc {
463459
uint32_t getSymIndex(SymbolTableBaseSection *symTab) const;
464460
bool needsDynSymIndex() const {
465461
assert(kind != Computed && "cannot check kind after computeRaw");
466-
return kind == AgainstSymbol || kind == AgainstSymbolWithTargetVA;
462+
return kind == AgainstSymbol;
467463
}
468464

469465
/// Computes the addend of the dynamic relocation. Note that this is not the

0 commit comments

Comments
 (0)