Skip to content

Commit dbd1971

Browse files
committed
[ELF] Pass Ctx & to Symbol
1 parent a62768c commit dbd1971

12 files changed

+104
-100
lines changed

lld/ELF/Arch/ARM.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1466,7 +1466,7 @@ template <typename ELFT> void elf::writeARMCmseImportLib(Ctx &ctx) {
14661466
for (auto &p : ctx.symtab->cmseSymMap) {
14671467
Defined *d = cast<Defined>(p.second.sym);
14681468
impSymTab->addSymbol(makeDefined(
1469-
ctx.internalFile, d->getName(), d->computeBinding(),
1469+
ctx.internalFile, d->getName(), d->computeBinding(ctx),
14701470
/*stOther=*/0, STT_FUNC, d->getVA(), d->getSize(), nullptr));
14711471
}
14721472

lld/ELF/Arch/PPC64.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,9 @@ static bool addOptional(Ctx &ctx, StringRef name, uint64_t value,
254254
Symbol *sym = ctx.symtab->find(name);
255255
if (!sym || sym->isDefined())
256256
return false;
257-
sym->resolve(Defined{ctx.internalFile, StringRef(), STB_GLOBAL, STV_HIDDEN,
258-
STT_FUNC, value,
259-
/*size=*/0, /*section=*/nullptr});
257+
sym->resolve(ctx, Defined{ctx.internalFile, StringRef(), STB_GLOBAL,
258+
STV_HIDDEN, STT_FUNC, value,
259+
/*size=*/0, /*section=*/nullptr});
260260
defined.push_back(cast<Defined>(sym));
261261
return true;
262262
}

lld/ELF/Driver.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2186,7 +2186,7 @@ static void handleUndefined(Ctx &ctx, Symbol *sym, const char *option) {
21862186

21872187
if (!sym->isLazy())
21882188
return;
2189-
sym->extract();
2189+
sym->extract(ctx);
21902190
if (!ctx.arg.whyExtract.empty())
21912191
ctx.whyExtractRecords.emplace_back(option, sym->file, *sym);
21922192
}
@@ -2217,7 +2217,7 @@ static void handleLibcall(Ctx &ctx, StringRef name) {
22172217
if (sym && sym->isLazy() && isa<BitcodeFile>(sym->file)) {
22182218
if (!ctx.arg.whyExtract.empty())
22192219
ctx.whyExtractRecords.emplace_back("<libcall>", sym->file, *sym);
2220-
sym->extract();
2220+
sym->extract(ctx);
22212221
}
22222222
}
22232223

@@ -2416,7 +2416,7 @@ static void findKeepUniqueSections(Ctx &ctx, opt::InputArgList &args) {
24162416
// or DSOs, so we conservatively mark them as address-significant.
24172417
bool icfSafe = ctx.arg.icf == ICFLevel::Safe;
24182418
for (Symbol *sym : ctx.symtab->getSymbols())
2419-
if (sym->includeInDynsym())
2419+
if (sym->includeInDynsym(ctx))
24202420
markAddrsig(icfSafe, sym);
24212421

24222422
// Visit the address-significance table in each object file and mark each
@@ -2465,7 +2465,7 @@ static void readSymbolPartitionSection(Ctx &ctx, InputSectionBase *s) {
24652465
sym = readEntry(s->file, rels.rels);
24662466
else
24672467
sym = readEntry(s->file, rels.relas);
2468-
if (!isa_and_nonnull<Defined>(sym) || !sym->includeInDynsym())
2468+
if (!isa_and_nonnull<Defined>(sym) || !sym->includeInDynsym(ctx))
24692469
return;
24702470

24712471
StringRef partName = reinterpret_cast<const char *>(s->content().data());
@@ -2551,7 +2551,7 @@ void LinkerDriver::compileBitcodeFiles(bool skipLinkedOutput) {
25512551
if (!ctx.arg.relocatable)
25522552
for (Symbol *sym : obj->getGlobalSymbols())
25532553
if (sym->hasVersionSuffix)
2554-
sym->parseSymbolVersion();
2554+
sym->parseSymbolVersion(ctx);
25552555
ctx.objectFiles.push_back(obj);
25562556
}
25572557
}
@@ -2648,12 +2648,12 @@ static void combineVersionedSymbol(Ctx &ctx, Symbol &sym,
26482648
// If both foo@v1 and foo@@v1 are defined and non-weak, report a
26492649
// duplicate definition error.
26502650
if (sym.isDefined()) {
2651-
sym2->checkDuplicate(cast<Defined>(sym));
2652-
sym2->resolve(cast<Defined>(sym));
2651+
sym2->checkDuplicate(ctx, cast<Defined>(sym));
2652+
sym2->resolve(ctx, cast<Defined>(sym));
26532653
} else if (sym.isUndefined()) {
2654-
sym2->resolve(cast<Undefined>(sym));
2654+
sym2->resolve(ctx, cast<Undefined>(sym));
26552655
} else {
2656-
sym2->resolve(cast<SharedSymbol>(sym));
2656+
sym2->resolve(ctx, cast<SharedSymbol>(sym));
26572657
}
26582658
// Eliminate foo@v1 from the symbol table.
26592659
sym.symbolKind = Symbol::PlaceholderKind;

lld/ELF/InputFiles.cpp

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,14 +1156,14 @@ void ObjFile<ELFT>::initializeSymbols(const object::ELFFile<ELFT> &obj) {
11561156
fatal(toString(this) + ": common symbol '" + sym->getName() +
11571157
"' has invalid alignment: " + Twine(value));
11581158
hasCommonSyms = true;
1159-
sym->resolve(
1160-
CommonSymbol{this, StringRef(), binding, stOther, type, value, size});
1159+
sym->resolve(ctx, CommonSymbol{this, StringRef(), binding, stOther, type,
1160+
value, size});
11611161
continue;
11621162
}
11631163

11641164
// Handle global defined symbols. Defined::section will be set in postParse.
1165-
sym->resolve(Defined{this, StringRef(), binding, stOther, type, value, size,
1166-
nullptr});
1165+
sym->resolve(ctx, Defined{this, StringRef(), binding, stOther, type, value,
1166+
size, nullptr});
11671167
}
11681168

11691169
// Undefined symbols (excluding those defined relative to non-prevailing
@@ -1175,8 +1175,8 @@ void ObjFile<ELFT>::initializeSymbols(const object::ELFFile<ELFT> &obj) {
11751175
for (unsigned i : undefineds) {
11761176
const Elf_Sym &eSym = eSyms[i];
11771177
Symbol *sym = symbols[i];
1178-
sym->resolve(Undefined{this, StringRef(), eSym.getBinding(), eSym.st_other,
1179-
eSym.getType()});
1178+
sym->resolve(ctx, Undefined{this, StringRef(), eSym.getBinding(),
1179+
eSym.st_other, eSym.getType()});
11801180
sym->isUsedInRegularObj = true;
11811181
sym->referenced = true;
11821182
}
@@ -1759,20 +1759,20 @@ static void createBitcodeSymbol(Ctx &ctx, Symbol *&sym,
17591759
int c = objSym.getComdatIndex();
17601760
if (objSym.isUndefined() || (c != -1 && !keptComdats[c])) {
17611761
Undefined newSym(&f, StringRef(), binding, visibility, type);
1762-
sym->resolve(newSym);
1762+
sym->resolve(ctx, newSym);
17631763
sym->referenced = true;
17641764
return;
17651765
}
17661766

17671767
if (objSym.isCommon()) {
1768-
sym->resolve(CommonSymbol{&f, StringRef(), binding, visibility, STT_OBJECT,
1769-
objSym.getCommonAlignment(),
1770-
objSym.getCommonSize()});
1768+
sym->resolve(ctx, CommonSymbol{&f, StringRef(), binding, visibility,
1769+
STT_OBJECT, objSym.getCommonAlignment(),
1770+
objSym.getCommonSize()});
17711771
} else {
17721772
Defined newSym(&f, StringRef(), binding, visibility, type, 0, 0, nullptr);
17731773
if (objSym.canBeOmittedFromSymbolTable())
17741774
newSym.exportDynamic = false;
1775-
sym->resolve(newSym);
1775+
sym->resolve(ctx, newSym);
17761776
}
17771777
}
17781778

@@ -1813,7 +1813,7 @@ void BitcodeFile::parseLazy() {
18131813
irSym.Name = uniqueSaver().save(irSym.getName());
18141814
if (!irSym.isUndefined()) {
18151815
auto *sym = ctx.symtab->insert(irSym.getName());
1816-
sym->resolve(LazySymbol{*this});
1816+
sym->resolve(ctx, LazySymbol{*this});
18171817
symbols[i] = sym;
18181818
}
18191819
}
@@ -1849,15 +1849,15 @@ void BinaryFile::parse() {
18491849

18501850
llvm::StringSaver &saver = lld::saver();
18511851

1852-
ctx.symtab->addAndCheckDuplicate(Defined{this, saver.save(s + "_start"),
1853-
STB_GLOBAL, STV_DEFAULT, STT_OBJECT,
1854-
0, 0, section});
1855-
ctx.symtab->addAndCheckDuplicate(Defined{this, saver.save(s + "_end"),
1856-
STB_GLOBAL, STV_DEFAULT, STT_OBJECT,
1857-
data.size(), 0, section});
1858-
ctx.symtab->addAndCheckDuplicate(Defined{this, saver.save(s + "_size"),
1859-
STB_GLOBAL, STV_DEFAULT, STT_OBJECT,
1860-
data.size(), 0, nullptr});
1852+
ctx.symtab->addAndCheckDuplicate(ctx, Defined{this, saver.save(s + "_start"),
1853+
STB_GLOBAL, STV_DEFAULT,
1854+
STT_OBJECT, 0, 0, section});
1855+
ctx.symtab->addAndCheckDuplicate(
1856+
ctx, Defined{this, saver.save(s + "_end"), STB_GLOBAL, STV_DEFAULT,
1857+
STT_OBJECT, data.size(), 0, section});
1858+
ctx.symtab->addAndCheckDuplicate(
1859+
ctx, Defined{this, saver.save(s + "_size"), STB_GLOBAL, STV_DEFAULT,
1860+
STT_OBJECT, data.size(), 0, nullptr});
18611861
}
18621862

18631863
InputFile *elf::createInternalFile(Ctx &ctx, StringRef name) {
@@ -1906,7 +1906,7 @@ template <class ELFT> void ObjFile<ELFT>::parseLazy() {
19061906
if (eSyms[i].st_shndx == SHN_UNDEF)
19071907
continue;
19081908
symbols[i] = symtab->insert(CHECK(eSyms[i].getName(stringTable), this));
1909-
symbols[i]->resolve(LazySymbol{*this});
1909+
symbols[i]->resolve(ctx, LazySymbol{*this});
19101910
if (!lazy)
19111911
break;
19121912
}

lld/ELF/LTO.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,12 +249,12 @@ void BitcodeCompiler::add(BitcodeFile &f) {
249249
// 5) Symbols that will be referenced after linker wrapping is performed.
250250
r.VisibleToRegularObj = ctx.arg.relocatable || sym->isUsedInRegularObj ||
251251
sym->referencedAfterWrap ||
252-
(r.Prevailing && sym->includeInDynsym()) ||
252+
(r.Prevailing && sym->includeInDynsym(ctx)) ||
253253
usedStartStop.count(objSym.getSectionName());
254254
// Identify symbols exported dynamically, and that therefore could be
255255
// referenced by a shared library not visible to the linker.
256256
r.ExportDynamic =
257-
sym->computeBinding() != STB_LOCAL &&
257+
sym->computeBinding(ctx) != STB_LOCAL &&
258258
(ctx.arg.exportDynamic || sym->exportDynamic || sym->inDynamicList);
259259
const auto *dr = dyn_cast<Defined>(sym);
260260
r.FinalDefinitionInLinkageUnit =

lld/ELF/MarkLive.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ template <class ELFT> void MarkLive<ELFT>::run() {
221221
// Preserve externally-visible symbols if the symbols defined by this
222222
// file can interpose other ELF file's symbols at runtime.
223223
for (Symbol *sym : ctx.symtab->getSymbols())
224-
if (sym->includeInDynsym() && sym->partition == partition)
224+
if (sym->includeInDynsym(ctx) && sym->partition == partition)
225225
markSymbol(sym);
226226

227227
// If this isn't the main partition, that's all that we need to preserve.

lld/ELF/SymbolTable.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,11 @@ Symbol *SymbolTable::insert(StringRef name) {
9898

9999
// This variant of addSymbol is used by BinaryFile::parse to check duplicate
100100
// symbol errors.
101-
Symbol *SymbolTable::addAndCheckDuplicate(const Defined &newSym) {
101+
Symbol *SymbolTable::addAndCheckDuplicate(Ctx &ctx, const Defined &newSym) {
102102
Symbol *sym = insert(newSym.getName());
103103
if (sym->isDefined())
104-
sym->checkDuplicate(newSym);
105-
sym->resolve(newSym);
104+
sym->checkDuplicate(ctx, newSym);
105+
sym->resolve(ctx, newSym);
106106
sym->isUsedInRegularObj = true;
107107
return sym;
108108
}
@@ -227,7 +227,7 @@ bool SymbolTable::assignExactVersion(SymbolVersion ver, uint16_t versionId,
227227
for (Symbol *sym : syms) {
228228
// For a non-local versionId, skip symbols containing version info because
229229
// symbol versions specified by symbol names take precedence over version
230-
// scripts. See parseSymbolVersion().
230+
// scripts. See parseSymbolVersion(ctx).
231231
if (!includeNonDefault && versionId != VER_NDX_LOCAL &&
232232
sym->getName().contains('@'))
233233
continue;
@@ -353,10 +353,10 @@ void SymbolTable::scanVersionScript() {
353353
// Let them parse and update their names to exclude version suffix.
354354
for (Symbol *sym : symVector)
355355
if (sym->hasVersionSuffix)
356-
sym->parseSymbolVersion();
356+
sym->parseSymbolVersion(ctx);
357357

358358
// isPreemptible is false at this point. To correctly compute the binding of a
359-
// Defined (which is used by includeInDynsym()), we need to know if it is
359+
// Defined (which is used by includeInDynsym(ctx)), we need to know if it is
360360
// VER_NDX_LOCAL or not. Compute symbol versions before handling
361361
// --dynamic-list.
362362
handleDynamicList();

lld/ELF/SymbolTable.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ class SymbolTable {
4747

4848
template <typename T> Symbol *addSymbol(const T &newSym) {
4949
Symbol *sym = insert(newSym.getName());
50-
sym->resolve(newSym);
50+
sym->resolve(ctx, newSym);
5151
return sym;
5252
}
53-
Symbol *addAndCheckDuplicate(const Defined &newSym);
53+
Symbol *addAndCheckDuplicate(Ctx &, const Defined &newSym);
5454

5555
void scanVersionScript();
5656

0 commit comments

Comments
 (0)