Skip to content

Commit a533f97

Browse files
committed
[𝘀𝗽𝗿] changes to main this commit is based on
Created using spr 1.3.5 [skip ci]
1 parent dd36a69 commit a533f97

File tree

7 files changed

+25
-30
lines changed

7 files changed

+25
-30
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: 6 additions & 7 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
}
@@ -1948,13 +1948,12 @@ void elf::postScanRelocations(Ctx &ctx) {
19481948

19491949
GotSection *got = ctx.in.got.get();
19501950
if (ctx.needsTlsLd.load(std::memory_order_relaxed) && got->addTlsIndex()) {
1951-
static Undefined dummy(ctx.internalFile, "", STB_LOCAL, 0, 0);
19521951
if (ctx.arg.shared)
19531952
ctx.mainPart->relaDyn->addReloc(
19541953
{ctx.target->tlsModuleIndexRel, got, got->getTlsIndexOff()});
19551954
else
19561955
got->addConstant({R_ADDEND, ctx.target->symbolicRel,
1957-
got->getTlsIndexOff(), 1, &dummy});
1956+
got->getTlsIndexOff(), 1, ctx.dummySym});
19581957
}
19591958

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

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
}
@@ -1648,17 +1648,14 @@ uint64_t DynamicReloc::getOffset() const {
16481648
int64_t DynamicReloc::computeAddend(Ctx &ctx) const {
16491649
switch (kind) {
16501650
case AddendOnly:
1651-
assert(sym == nullptr);
1652-
return addend;
1653-
case AgainstSymbol:
1654-
assert(sym != nullptr);
1655-
return addend;
1656-
case AddendOnlyWithTargetVA:
16571651
case AgainstSymbolWithTargetVA: {
16581652
uint64_t ca = inputSec->getRelocTargetVA(
16591653
ctx, Relocation{expr, type, 0, addend, sym}, getOffset());
16601654
return ctx.arg.is64 ? ca : SignExtend64<32>(ca);
16611655
}
1656+
case AgainstSymbol:
1657+
assert(sym != nullptr);
1658+
return addend;
16621659
case MipsMultiGotPage:
16631660
assert(sym == nullptr);
16641661
return getMipsPageAddr(outputSec->addr) + addend;
@@ -1703,8 +1700,8 @@ void RelocationBaseSection::addAddendOnlyRelocIfNonPreemptible(
17031700
addReloc({dynType, &isec, offsetInSec, DynamicReloc::AgainstSymbol, sym, 0,
17041701
R_ABS});
17051702
else
1706-
addReloc(DynamicReloc::AddendOnlyWithTargetVA, dynType, isec, offsetInSec,
1707-
sym, 0, R_ABS, addendRelType);
1703+
addReloc(DynamicReloc::AddendOnly, dynType, isec, offsetInSec, sym, 0,
1704+
R_ABS, addendRelType);
17081705
}
17091706

17101707
void RelocationBaseSection::mergeRels() {

lld/ELF/SyntheticSections.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -419,13 +419,10 @@ 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,
425422
/// The resulting dynamic relocation will not reference a symbol: #sym is
426423
/// only used to compute the addend with InputSection::getRelocTargetVA().
427424
/// Useful for various relative and TLS relocations (e.g. R_X86_64_TPOFF64).
428-
AddendOnlyWithTargetVA,
425+
AddendOnly,
429426
/// The resulting dynamic relocation references symbol #sym from the dynamic
430427
/// symbol table and uses #addend as the value of computeAddend(ctx).
431428
AgainstSymbol,
@@ -438,7 +435,7 @@ class DynamicReloc {
438435
/// addresses of 64kb pages that lie inside the output section.
439436
MipsMultiGotPage,
440437
};
441-
/// This constructor records a relocation against a symbol.
438+
/// This constructor records a normal relocation.
442439
DynamicReloc(RelType type, const InputSectionBase *inputSec,
443440
uint64_t offsetInSec, Kind kind, Symbol &sym, int64_t addend,
444441
RelExpr expr)
@@ -447,8 +444,9 @@ class DynamicReloc {
447444
/// This constructor records a relative relocation with no symbol.
448445
DynamicReloc(RelType type, const InputSectionBase *inputSec,
449446
uint64_t offsetInSec, int64_t addend = 0)
450-
: sym(nullptr), inputSec(inputSec), offsetInSec(offsetInSec), type(type),
451-
addend(addend), kind(AddendOnly), expr(R_ADDEND) {}
447+
: sym(inputSec->getCtx().dummySym), inputSec(inputSec),
448+
offsetInSec(offsetInSec), type(type), addend(addend), kind(AddendOnly),
449+
expr(R_ADDEND) {}
452450
/// This constructor records dynamic relocation settings used by the MIPS
453451
/// multi-GOT implementation.
454452
DynamicReloc(RelType type, const InputSectionBase *inputSec,
@@ -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)