Skip to content

Commit 58e6bc8

Browse files
authored
[ELF] Add a dummySym member to Ctx
This ensures subsequent calls to elf::postScanRelocations with a new Ctx will correctly use an instance with the right internalFile (with the old one presumably deleted, even). It also avoids having to create a new instance in elf::getErrorPlace, and will allow more uses of such a dummy symbol in future commits. Reviewers: MaskRay Reviewed By: MaskRay Pull Request: #150796
1 parent 75e5a70 commit 58e6bc8

File tree

4 files changed

+5
-4
lines changed

4 files changed

+5
-4
lines changed

lld/ELF/Config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,8 @@ struct Ctx : CommonLinkerContext {
702702
std::unique_ptr<llvm::TarWriter> tar;
703703
// InputFile for linker created symbols with no source ___location.
704704
InputFile *internalFile = nullptr;
705+
// Dummy Undefined for relocations without a symbol.
706+
Undefined *dummySym = nullptr;
705707
// True if symbols can be exported (isExported) or preemptible.
706708
bool hasDynsym = false;
707709
// 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
@@ -3140,6 +3140,7 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &args) {
31403140
ctx.symtab->insert(arg->getValue())->traced = true;
31413141

31423142
ctx.internalFile = createInternalFile(ctx, "<internal>");
3143+
ctx.dummySym = make<Undefined>(ctx.internalFile, "", STB_LOCAL, 0, 0);
31433144

31443145
// Handle -u/--undefined before input files. If both a.a and b.so define foo,
31453146
// -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/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)