Skip to content

Commit e19453f

Browse files
committed
[𝘀𝗽𝗿] changes introduced through rebase
Created using spr 1.3.5 [skip ci]
1 parent dd36a69 commit e19453f

File tree

7 files changed

+44
-48
lines changed

7 files changed

+44
-48
lines changed

lld/ELF/Config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,8 @@ struct Ctx : CommonLinkerContext {
701701
std::unique_ptr<llvm::TarWriter> tar;
702702
// InputFile for linker created symbols with no source location.
703703
InputFile *internalFile = nullptr;
704+
// Dummy Undefined for relocations without a symbol.
705+
Undefined *dummySym = nullptr;
704706
// True if symbols can be exported (isExported) or preemptible.
705707
bool hasDynsym = false;
706708
// True if SHT_LLVM_SYMPART is used.

lld/ELF/Driver.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3138,6 +3138,7 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &args) {
31383138
ctx.symtab->insert(arg->getValue())->traced = true;
31393139

31403140
ctx.internalFile = createInternalFile(ctx, "<internal>");
3141+
ctx.dummySym = make<Undefined>(ctx.internalFile, "", STB_LOCAL, 0, 0);
31413142

31423143
// Handle -u/--undefined before input files. If both a.a and b.so define foo,
31433144
// -u foo a.a b.so will extract a.a.

lld/ELF/Relocations.cpp

Lines changed: 13 additions & 12 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::AddendOnlyWithTargetVA,
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,14 +923,14 @@ 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

928930
// Signed GOT requires dynamic relocation.
929931
ctx.in.got->getPartition(ctx).relaDyn->addReloc(
930-
{R_AARCH64_AUTH_RELATIVE, ctx.in.got.get(), off,
931-
DynamicReloc::AddendOnlyWithTargetVA, sym, 0, R_ABS});
932+
{R_AARCH64_AUTH_RELATIVE, ctx.in.got.get(), off, DynamicReloc::AddendOnly,
933+
sym, 0, R_ABS});
932934
}
933935

934936
static void addTpOffsetGotEntry(Ctx &ctx, Symbol &sym) {
@@ -1160,8 +1162,8 @@ void RelocationScanner::processAux(RelExpr expr, RelType type, uint64_t offset,
11601162
part.relrAuthDyn->relocs.push_back({sec, sec->relocs().size() - 1});
11611163
} else {
11621164
part.relaDyn->addReloc({R_AARCH64_AUTH_RELATIVE, sec, offset,
1163-
DynamicReloc::AddendOnlyWithTargetVA, sym,
1164-
addend, R_ABS});
1165+
DynamicReloc::AddendOnly, sym, addend,
1166+
R_ABS});
11651167
}
11661168
return;
11671169
}
@@ -1948,13 +1950,12 @@ void elf::postScanRelocations(Ctx &ctx) {
19481950

19491951
GotSection *got = ctx.in.got.get();
19501952
if (ctx.needsTlsLd.load(std::memory_order_relaxed) && got->addTlsIndex()) {
1951-
static Undefined dummy(ctx.internalFile, "", STB_LOCAL, 0, 0);
19521953
if (ctx.arg.shared)
19531954
ctx.mainPart->relaDyn->addReloc(
19541955
{ctx.target->tlsModuleIndexRel, got, got->getTlsIndexOff()});
19551956
else
19561957
got->addConstant({R_ADDEND, ctx.target->symbolicRel,
1957-
got->getTlsIndexOff(), 1, &dummy});
1958+
got->getTlsIndexOff(), 1, ctx.dummySym});
19581959
}
19591960

19601961
assert(ctx.symAux.size() == 1);

lld/ELF/SyntheticSections.cpp

Lines changed: 12 additions & 16 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;
@@ -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
}
@@ -1647,14 +1647,10 @@ uint64_t DynamicReloc::getOffset() const {
16471647

16481648
int64_t DynamicReloc::computeAddend(Ctx &ctx) const {
16491649
switch (kind) {
1650+
case Computed:
1651+
llvm_unreachable("addend already computed");
16501652
case AddendOnly:
1651-
assert(sym == nullptr);
1652-
return addend;
1653-
case AgainstSymbol:
1654-
assert(sym != nullptr);
1655-
return addend;
1656-
case AddendOnlyWithTargetVA:
1657-
case AgainstSymbolWithTargetVA: {
1653+
case AgainstSymbol: {
16581654
uint64_t ca = inputSec->getRelocTargetVA(
16591655
ctx, Relocation{expr, type, 0, addend, sym}, getOffset());
16601656
return ctx.arg.is64 ? ca : SignExtend64<32>(ca);
@@ -1701,10 +1697,10 @@ void RelocationBaseSection::addAddendOnlyRelocIfNonPreemptible(
17011697
// No need to write an addend to the section for preemptible symbols.
17021698
if (sym.isPreemptible)
17031699
addReloc({dynType, &isec, offsetInSec, DynamicReloc::AgainstSymbol, sym, 0,
1704-
R_ABS});
1700+
R_ADDEND});
17051701
else
1706-
addReloc(DynamicReloc::AddendOnlyWithTargetVA, dynType, isec, offsetInSec,
1707-
sym, 0, R_ABS, addendRelType);
1702+
addReloc(DynamicReloc::AddendOnly, dynType, isec, offsetInSec, sym, 0,
1703+
R_ABS, addendRelType);
17081704
}
17091705

17101706
void RelocationBaseSection::mergeRels() {
@@ -1748,7 +1744,7 @@ void DynamicReloc::computeRaw(Ctx &ctx, SymbolTableBaseSection *symt) {
17481744
r_offset = getOffset();
17491745
r_sym = getSymIndex(symt);
17501746
addend = computeAddend(ctx);
1751-
kind = AddendOnly; // Catch errors
1747+
kind = Computed; // Catch errors
17521748
}
17531749

17541750
void RelocationBaseSection::computeRels() {

lld/ELF/SyntheticSections.h

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -419,26 +419,22 @@ class StringTableSection final : public SyntheticSection {
419419
class DynamicReloc {
420420
public:
421421
enum Kind {
422-
/// The resulting dynamic relocation does not reference a symbol (#sym must
423-
/// be nullptr) and uses #addend as the result of computeAddend(ctx).
424-
AddendOnly,
422+
/// The resulting dynamic relocation has already had its addend computed.
423+
/// Calling computeAddend() is an error. Only for internal use.
424+
Computed,
425425
/// The resulting dynamic relocation will not reference a symbol: #sym is
426426
/// only used to compute the addend with InputSection::getRelocTargetVA().
427427
/// Useful for various relative and TLS relocations (e.g. R_X86_64_TPOFF64).
428-
AddendOnlyWithTargetVA,
428+
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,
440436
};
441-
/// This constructor records a relocation against a symbol.
437+
/// This constructor records a normal relocation.
442438
DynamicReloc(RelType type, const InputSectionBase *inputSec,
443439
uint64_t offsetInSec, Kind kind, Symbol &sym, int64_t addend,
444440
RelExpr expr)
@@ -447,8 +443,9 @@ class DynamicReloc {
447443
/// This constructor records a relative relocation with no symbol.
448444
DynamicReloc(RelType type, const InputSectionBase *inputSec,
449445
uint64_t offsetInSec, int64_t addend = 0)
450-
: sym(nullptr), inputSec(inputSec), offsetInSec(offsetInSec), type(type),
451-
addend(addend), kind(AddendOnly), expr(R_ADDEND) {}
446+
: sym(inputSec->getCtx().dummySym), inputSec(inputSec),
447+
offsetInSec(offsetInSec), type(type), addend(addend), kind(AddendOnly),
448+
expr(R_ADDEND) {}
452449
/// This constructor records dynamic relocation settings used by the MIPS
453450
/// multi-GOT implementation.
454451
DynamicReloc(RelType type, const InputSectionBase *inputSec,
@@ -461,7 +458,8 @@ class DynamicReloc {
461458
uint64_t getOffset() const;
462459
uint32_t getSymIndex(SymbolTableBaseSection *symTab) const;
463460
bool needsDynSymIndex() const {
464-
return kind == AgainstSymbol || kind == AgainstSymbolWithTargetVA;
461+
assert(kind != Computed && "cannot check kind after computeRaw");
462+
return kind == AgainstSymbol;
465463
}
466464

467465
/// Computes the addend of the dynamic relocation. Note that this is not the
@@ -528,8 +526,8 @@ class RelocationBaseSection : public SyntheticSection {
528526
uint64_t offsetInSec, Symbol &sym, int64_t addend,
529527
RelType addendRelType, RelExpr expr) {
530528
assert(expr != R_ADDEND && "expected non-addend relocation expression");
531-
addReloc<shard>(DynamicReloc::AddendOnlyWithTargetVA, dynType, isec,
532-
offsetInSec, sym, addend, expr, addendRelType);
529+
addReloc<shard>(DynamicReloc::AddendOnly, dynType, isec, offsetInSec, sym,
530+
addend, expr, addendRelType);
533531
}
534532
/// Add a dynamic relocation using the target address of \p sym as the addend
535533
/// if \p sym is non-preemptible. Otherwise add a relocation against \p sym.

lld/ELF/Target.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,9 @@ ErrorPlace elf::getErrorPlace(Ctx &ctx, const uint8_t *loc) {
105105
if (isecLoc <= loc && loc < isecLoc + isec->getSize()) {
106106
std::string objLoc = isec->getLocation(loc - isecLoc);
107107
// Return object file location and source file location.
108-
Undefined dummy(ctx.internalFile, "", STB_LOCAL, 0, 0);
109108
ELFSyncStream msg(ctx, DiagLevel::None);
110109
if (isec->file)
111-
msg << isec->getSrcMsg(dummy, loc - isecLoc);
110+
msg << isec->getSrcMsg(*ctx.dummySym, loc - isecLoc);
112111
return {isec, objLoc + ": ", std::string(msg.str())};
113112
}
114113
}

lld/ELF/Writer.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,8 +1573,7 @@ template <class ELFT> void Writer<ELFT>::finalizeAddressDependentContent() {
15731573
if (isInt<32>(reloc.sym->getVA(ctx, reloc.addend)))
15741574
return false;
15751575
part.relaDyn->addReloc({R_AARCH64_AUTH_RELATIVE, elem.inputSec,
1576-
reloc.offset,
1577-
DynamicReloc::AddendOnlyWithTargetVA,
1576+
reloc.offset, DynamicReloc::AddendOnly,
15781577
*reloc.sym, reloc.addend, R_ABS});
15791578
return true;
15801579
});

0 commit comments

Comments
 (0)