Skip to content

Commit e027b92

Browse files
authored
[NFCI][ELF] Merge AddendOnly and AddendOnlyWithTargetVA
The former is just a special case of the latter, ignoring the expr and always just using the addend, allowing (and enforcing) the sym is null. If we just use dummySym then we don't need to maintain this as a separate case, since R_ADDEND will return the addend unmodified for the call to getRelocTargetVA. Reviewers: MaskRay, arichardson Reviewed By: MaskRay, arichardson Pull Request: #150797
1 parent 0d81d3c commit e027b92

File tree

4 files changed

+20
-26
lines changed

4 files changed

+20
-26
lines changed

lld/ELF/Relocations.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,7 @@ static void addPltEntry(Ctx &ctx, PltSection &plt, GotPltSection &gotPlt,
887887
gotPlt.addEntry(sym);
888888
rel.addReloc({type, &gotPlt, sym.getGotPltOffset(ctx),
889889
sym.isPreemptible ? DynamicReloc::AgainstSymbol
890-
: DynamicReloc::AddendOnlyWithTargetVA,
890+
: DynamicReloc::AddendOnly,
891891
sym, 0, R_ABS});
892892
}
893893

@@ -927,8 +927,8 @@ static void addGotAuthEntry(Ctx &ctx, Symbol &sym) {
927927

928928
// Signed GOT requires dynamic relocation.
929929
ctx.in.got->getPartition(ctx).relaDyn->addReloc(
930-
{R_AARCH64_AUTH_RELATIVE, ctx.in.got.get(), off,
931-
DynamicReloc::AddendOnlyWithTargetVA, sym, 0, R_ABS});
930+
{R_AARCH64_AUTH_RELATIVE, ctx.in.got.get(), off, DynamicReloc::AddendOnly,
931+
sym, 0, R_ABS});
932932
}
933933

934934
static void addTpOffsetGotEntry(Ctx &ctx, Symbol &sym) {
@@ -1160,8 +1160,8 @@ void RelocationScanner::processAux(RelExpr expr, RelType type, uint64_t offset,
11601160
part.relrAuthDyn->relocs.push_back({sec, sec->relocs().size() - 1});
11611161
} else {
11621162
part.relaDyn->addReloc({R_AARCH64_AUTH_RELATIVE, sec, offset,
1163-
DynamicReloc::AddendOnlyWithTargetVA, sym,
1164-
addend, R_ABS});
1163+
DynamicReloc::AddendOnly, sym, addend,
1164+
R_ABS});
11651165
}
11661166
return;
11671167
}

lld/ELF/SyntheticSections.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,8 +1122,8 @@ void MipsGotSection::build() {
11221122
for (const std::pair<GotEntry, size_t> &p : got.local16) {
11231123
uint64_t offset = p.second * ctx.arg.wordsize;
11241124
ctx.mainPart->relaDyn->addReloc({ctx.target->relativeRel, this, offset,
1125-
DynamicReloc::AddendOnlyWithTargetVA,
1126-
*p.first.first, p.first.second, R_ABS});
1125+
DynamicReloc::AddendOnly, *p.first.first,
1126+
p.first.second, R_ABS});
11271127
}
11281128
}
11291129
}
@@ -1650,17 +1650,14 @@ int64_t DynamicReloc::computeAddend(Ctx &ctx) const {
16501650
case Computed:
16511651
llvm_unreachable("addend already computed");
16521652
case AddendOnly:
1653-
assert(sym == nullptr);
1654-
return addend;
1655-
case AgainstSymbol:
1656-
assert(sym != nullptr);
1657-
return addend;
1658-
case AddendOnlyWithTargetVA:
16591653
case AgainstSymbolWithTargetVA: {
16601654
uint64_t ca = inputSec->getRelocTargetVA(
16611655
ctx, Relocation{expr, type, 0, addend, sym}, getOffset());
16621656
return ctx.arg.is64 ? ca : SignExtend64<32>(ca);
16631657
}
1658+
case AgainstSymbol:
1659+
assert(sym != nullptr);
1660+
return addend;
16641661
case MipsMultiGotPage:
16651662
assert(sym == nullptr);
16661663
return getMipsPageAddr(outputSec->addr) + addend;
@@ -1705,8 +1702,8 @@ void RelocationBaseSection::addAddendOnlyRelocIfNonPreemptible(
17051702
addReloc({dynType, &isec, offsetInSec, DynamicReloc::AgainstSymbol, sym, 0,
17061703
R_ABS});
17071704
else
1708-
addReloc(DynamicReloc::AddendOnlyWithTargetVA, dynType, isec, offsetInSec,
1709-
sym, 0, R_ABS, addendRelType);
1705+
addReloc(DynamicReloc::AddendOnly, dynType, isec, offsetInSec, sym, 0,
1706+
R_ABS, addendRelType);
17101707
}
17111708

17121709
void RelocationBaseSection::mergeRels() {

lld/ELF/SyntheticSections.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -422,13 +422,10 @@ class DynamicReloc {
422422
/// The resulting dynamic relocation has already had its addend computed.
423423
/// Calling computeAddend() is an error. Only for internal use.
424424
Computed,
425-
/// The resulting dynamic relocation does not reference a symbol (#sym must
426-
/// be nullptr) and uses #addend as the result of computeAddend(ctx).
427-
AddendOnly,
428425
/// The resulting dynamic relocation will not reference a symbol: #sym is
429426
/// only used to compute the addend with InputSection::getRelocTargetVA().
430427
/// Useful for various relative and TLS relocations (e.g. R_X86_64_TPOFF64).
431-
AddendOnlyWithTargetVA,
428+
AddendOnly,
432429
/// The resulting dynamic relocation references symbol #sym from the dynamic
433430
/// symbol table and uses #addend as the value of computeAddend(ctx).
434431
AgainstSymbol,
@@ -441,7 +438,7 @@ class DynamicReloc {
441438
/// addresses of 64kb pages that lie inside the output section.
442439
MipsMultiGotPage,
443440
};
444-
/// This constructor records a relocation against a symbol.
441+
/// This constructor records a normal relocation.
445442
DynamicReloc(RelType type, const InputSectionBase *inputSec,
446443
uint64_t offsetInSec, Kind kind, Symbol &sym, int64_t addend,
447444
RelExpr expr)
@@ -450,8 +447,9 @@ class DynamicReloc {
450447
/// This constructor records a relative relocation with no symbol.
451448
DynamicReloc(RelType type, const InputSectionBase *inputSec,
452449
uint64_t offsetInSec, int64_t addend = 0)
453-
: sym(nullptr), inputSec(inputSec), offsetInSec(offsetInSec), type(type),
454-
addend(addend), kind(AddendOnly), expr(R_ADDEND) {}
450+
: sym(inputSec->getCtx().dummySym), inputSec(inputSec),
451+
offsetInSec(offsetInSec), type(type), addend(addend), kind(AddendOnly),
452+
expr(R_ADDEND) {}
455453
/// This constructor records dynamic relocation settings used by the MIPS
456454
/// multi-GOT implementation.
457455
DynamicReloc(RelType type, const InputSectionBase *inputSec,
@@ -532,8 +530,8 @@ class RelocationBaseSection : public SyntheticSection {
532530
uint64_t offsetInSec, Symbol &sym, int64_t addend,
533531
RelType addendRelType, RelExpr expr) {
534532
assert(expr != R_ADDEND && "expected non-addend relocation expression");
535-
addReloc<shard>(DynamicReloc::AddendOnlyWithTargetVA, dynType, isec,
536-
offsetInSec, sym, addend, expr, addendRelType);
533+
addReloc<shard>(DynamicReloc::AddendOnly, dynType, isec, offsetInSec, sym,
534+
addend, expr, addendRelType);
537535
}
538536
/// Add a dynamic relocation using the target address of \p sym as the addend
539537
/// if \p sym is non-preemptible. Otherwise add a relocation against \p sym.

lld/ELF/Writer.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,8 +1586,7 @@ template <class ELFT> void Writer<ELFT>::finalizeAddressDependentContent() {
15861586
if (isInt<32>(reloc.sym->getVA(ctx, reloc.addend)))
15871587
return false;
15881588
part.relaDyn->addReloc({R_AARCH64_AUTH_RELATIVE, elem.inputSec,
1589-
reloc.offset,
1590-
DynamicReloc::AddendOnlyWithTargetVA,
1589+
reloc.offset, DynamicReloc::AddendOnly,
15911590
*reloc.sym, reloc.addend, R_ABS});
15921591
return true;
15931592
});

0 commit comments

Comments
 (0)