Skip to content

Commit 6f64af1

Browse files
committed
[𝘀𝗽𝗿] initial version
Created using spr 1.3.5
2 parents dd36a69 + 1308e1a commit 6f64af1

File tree

6 files changed

+12
-5
lines changed

6 files changed

+12
-5
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: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1647,6 +1647,8 @@ 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:
16511653
assert(sym == nullptr);
16521654
return addend;
@@ -1748,7 +1750,7 @@ void DynamicReloc::computeRaw(Ctx &ctx, SymbolTableBaseSection *symt) {
17481750
r_offset = getOffset();
17491751
r_sym = getSymIndex(symt);
17501752
addend = computeAddend(ctx);
1751-
kind = AddendOnly; // Catch errors
1753+
kind = Computed; // Catch errors
17521754
}
17531755

17541756
void RelocationBaseSection::computeRels() {

lld/ELF/SyntheticSections.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,9 @@ class StringTableSection final : public SyntheticSection {
419419
class DynamicReloc {
420420
public:
421421
enum Kind {
422+
/// The resulting dynamic relocation has already had its addend computed.
423+
/// Calling computeAddend() is an error. Only for internal use.
424+
Computed,
422425
/// The resulting dynamic relocation does not reference a symbol (#sym must
423426
/// be nullptr) and uses #addend as the result of computeAddend(ctx).
424427
AddendOnly,
@@ -461,6 +464,7 @@ class DynamicReloc {
461464
uint64_t getOffset() const;
462465
uint32_t getSymIndex(SymbolTableBaseSection *symTab) const;
463466
bool needsDynSymIndex() const {
467+
assert(kind != Computed && "cannot check kind after computeRaw");
464468
return kind == AgainstSymbol || kind == AgainstSymbolWithTargetVA;
465469
}
466470

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
}

0 commit comments

Comments
 (0)