Skip to content

Commit fe8af49

Browse files
committed
[ELF] Pass Ctx & to Defined & CommonSymbol
1 parent 2deb3a2 commit fe8af49

File tree

9 files changed

+43
-41
lines changed

9 files changed

+43
-41
lines changed

lld/ELF/Arch/ARM.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,8 +1439,8 @@ void ArmCmseSGSection::finalizeContents() {
14391439
for (size_t i = 0; i < sgVeneers.size(); ++i) {
14401440
ArmCmseSGVeneer *s = sgVeneers[i];
14411441
s->offset = i * s->size;
1442-
Defined(file, StringRef(), s->sym->binding, s->sym->stOther, s->sym->type,
1443-
s->offset | 1, s->size, this)
1442+
Defined(ctx, file, StringRef(), s->sym->binding, s->sym->stOther,
1443+
s->sym->type, s->offset | 1, s->size, this)
14441444
.overwrite(*s->sym);
14451445
}
14461446
}
@@ -1474,7 +1474,7 @@ template <typename ELFT> void elf::writeARMCmseImportLib(Ctx &ctx) {
14741474
for (auto &p : ctx.symtab->cmseSymMap) {
14751475
Defined *d = cast<Defined>(p.second.sym);
14761476
impSymTab->addSymbol(makeDefined(
1477-
ctx.internalFile, d->getName(), d->computeBinding(ctx),
1477+
ctx, ctx.internalFile, d->getName(), d->computeBinding(ctx),
14781478
/*stOther=*/0, STT_FUNC, d->getVA(), d->getSize(), nullptr));
14791479
}
14801480

lld/ELF/Arch/PPC64.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ 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(ctx, Defined{ctx.internalFile, StringRef(), STB_GLOBAL,
257+
sym->resolve(ctx, Defined{ctx, ctx.internalFile, StringRef(), STB_GLOBAL,
258258
STV_HIDDEN, STT_FUNC, value,
259259
/*size=*/0, /*section=*/nullptr});
260260
defined.push_back(cast<Defined>(sym));

lld/ELF/Driver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2375,7 +2375,7 @@ static void replaceCommonSymbols(Ctx &ctx) {
23752375
auto *bss = make<BssSection>(ctx, "COMMON", s->size, s->alignment);
23762376
bss->file = s->file;
23772377
ctx.inputSections.push_back(bss);
2378-
Defined(s->file, StringRef(), s->binding, s->stOther, s->type,
2378+
Defined(ctx, s->file, StringRef(), s->binding, s->stOther, s->type,
23792379
/*value=*/0, s->size, bss)
23802380
.overwrite(*s);
23812381
}

lld/ELF/InputFiles.cpp

Lines changed: 13 additions & 12 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(ctx, CommonSymbol{this, StringRef(), binding, stOther, type,
1160-
value, size});
1159+
sym->resolve(ctx, CommonSymbol{ctx, this, StringRef(), binding, stOther,
1160+
type, value, size});
11611161
continue;
11621162
}
11631163

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

11691169
// Undefined symbols (excluding those defined relative to non-prevailing
@@ -1219,7 +1219,7 @@ void ObjFile<ELFT>::initSectionsAndLocalSyms(bool ignoreComdats) {
12191219
new (symbols[i]) Undefined(this, name, STB_LOCAL, eSym.st_other, type,
12201220
/*discardedSecIdx=*/secIdx);
12211221
else
1222-
new (symbols[i]) Defined(this, name, STB_LOCAL, eSym.st_other, type,
1222+
new (symbols[i]) Defined(ctx, this, name, STB_LOCAL, eSym.st_other, type,
12231223
eSym.st_value, eSym.st_size, sec);
12241224
symbols[i]->partition = 1;
12251225
symbols[i]->isUsedInRegularObj = true;
@@ -1765,11 +1765,12 @@ static void createBitcodeSymbol(Ctx &ctx, Symbol *&sym,
17651765
}
17661766

17671767
if (objSym.isCommon()) {
1768-
sym->resolve(ctx, CommonSymbol{&f, StringRef(), binding, visibility,
1768+
sym->resolve(ctx, CommonSymbol{ctx, &f, StringRef(), binding, visibility,
17691769
STT_OBJECT, objSym.getCommonAlignment(),
17701770
objSym.getCommonSize()});
17711771
} else {
1772-
Defined newSym(&f, StringRef(), binding, visibility, type, 0, 0, nullptr);
1772+
Defined newSym(ctx, &f, StringRef(), binding, visibility, type, 0, 0,
1773+
nullptr);
17731774
if (objSym.canBeOmittedFromSymbolTable())
17741775
newSym.exportDynamic = false;
17751776
sym->resolve(ctx, newSym);
@@ -1849,14 +1850,14 @@ void BinaryFile::parse() {
18491850

18501851
llvm::StringSaver &saver = lld::saver();
18511852

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

lld/ELF/LinkerScript.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,8 @@ void LinkerScript::addSymbol(SymbolAssignment *cmd) {
227227
// write expressions like this: `alignment = 16; . = ALIGN(., alignment)`.
228228
uint64_t symValue = value.sec ? 0 : value.getValue();
229229

230-
Defined newSym(createInternalFile(ctx, cmd->location), cmd->name, STB_GLOBAL,
231-
visibility, value.type, symValue, 0, sec);
230+
Defined newSym(ctx, createInternalFile(ctx, cmd->location), cmd->name,
231+
STB_GLOBAL, visibility, value.type, symValue, 0, sec);
232232

233233
Symbol *sym = ctx.symtab->insert(cmd->name);
234234
sym->mergeProperties(newSym);
@@ -244,7 +244,7 @@ void LinkerScript::declareSymbol(SymbolAssignment *cmd) {
244244
return;
245245

246246
uint8_t visibility = cmd->hidden ? STV_HIDDEN : STV_DEFAULT;
247-
Defined newSym(ctx.internalFile, cmd->name, STB_GLOBAL, visibility,
247+
Defined newSym(ctx, ctx.internalFile, cmd->name, STB_GLOBAL, visibility,
248248
STT_NOTYPE, 0, 0, nullptr);
249249

250250
// If the symbol is already defined, its order is 0 (with absence indicating

lld/ELF/Relocations.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -315,10 +315,10 @@ static SmallSet<SharedSymbol *, 4> getSymbolsAt(Ctx &ctx, SharedSymbol &ss) {
315315
// in .bss and in the case of a canonical plt entry it is in .plt. This function
316316
// replaces the existing symbol with a Defined pointing to the appropriate
317317
// location.
318-
static void replaceWithDefined(Symbol &sym, SectionBase &sec, uint64_t value,
319-
uint64_t size) {
318+
static void replaceWithDefined(Ctx &ctx, Symbol &sym, SectionBase &sec,
319+
uint64_t value, uint64_t size) {
320320
Symbol old = sym;
321-
Defined(sym.file, StringRef(), sym.binding, sym.stOther, sym.type, value,
321+
Defined(ctx, sym.file, StringRef(), sym.binding, sym.stOther, sym.type, value,
322322
size, &sec)
323323
.overwrite(sym);
324324

@@ -398,7 +398,7 @@ template <class ELFT> static void addCopyRelSymbol(Ctx &ctx, SharedSymbol &ss) {
398398
// dynamic symbol for each one. This causes the copy relocation to correctly
399399
// interpose any aliases.
400400
for (SharedSymbol *sym : getSymbolsAt<ELFT>(ctx, ss))
401-
replaceWithDefined(*sym, *sec, 0, sym->size);
401+
replaceWithDefined(ctx, *sym, *sec, 0, sym->size);
402402

403403
ctx.mainPart->relaDyn->addSymbolReloc(ctx.target->copyRel, *sec, 0, ss);
404404
}
@@ -1807,7 +1807,7 @@ void elf::postScanRelocations(Ctx &ctx) {
18071807
} else {
18081808
assert(sym.isFunc() && sym.hasFlag(NEEDS_PLT));
18091809
if (!sym.isDefined()) {
1810-
replaceWithDefined(sym, *ctx.in.plt,
1810+
replaceWithDefined(ctx, sym, *ctx.in.plt,
18111811
ctx.target->pltHeaderSize +
18121812
ctx.target->pltEntrySize * sym.getPltIdx(ctx),
18131813
0);

lld/ELF/Symbols.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,9 @@ class Symbol {
363363
// Represents a symbol that is defined in the current output file.
364364
class Defined : public Symbol {
365365
public:
366-
Defined(InputFile *file, StringRef name, uint8_t binding, uint8_t stOther,
367-
uint8_t type, uint64_t value, uint64_t size, SectionBase *section)
366+
Defined(Ctx &ctx, InputFile *file, StringRef name, uint8_t binding,
367+
uint8_t stOther, uint8_t type, uint64_t value, uint64_t size,
368+
SectionBase *section)
368369
: Symbol(DefinedKind, file, name, binding, stOther, type), value(value),
369370
size(size), section(section) {
370371
exportDynamic = ctx.arg.exportDynamic;
@@ -401,7 +402,7 @@ class Defined : public Symbol {
401402
// section. (Therefore, the later passes don't see any CommonSymbols.)
402403
class CommonSymbol : public Symbol {
403404
public:
404-
CommonSymbol(InputFile *file, StringRef name, uint8_t binding,
405+
CommonSymbol(Ctx &ctx, InputFile *file, StringRef name, uint8_t binding,
405406
uint8_t stOther, uint8_t type, uint64_t alignment, uint64_t size)
406407
: Symbol(CommonKind, file, name, binding, stOther, type),
407408
alignment(alignment), size(size) {

lld/ELF/SyntheticSections.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,8 @@ InputSection *elf::createInterpSection(Ctx &ctx) {
276276
Defined *elf::addSyntheticLocal(Ctx &ctx, StringRef name, uint8_t type,
277277
uint64_t value, uint64_t size,
278278
InputSectionBase &section) {
279-
Defined *s = makeDefined(section.file, name, STB_LOCAL, STV_DEFAULT, type,
280-
value, size, &section);
279+
Defined *s = makeDefined(ctx, section.file, name, STB_LOCAL, STV_DEFAULT,
280+
type, value, size, &section);
281281
if (ctx.in.symTab)
282282
ctx.in.symTab->addSymbol(s);
283283

@@ -4681,8 +4681,8 @@ static Defined *addOptionalRegular(Ctx &ctx, StringRef name, SectionBase *sec,
46814681
if (!s || s->isDefined() || s->isCommon())
46824682
return nullptr;
46834683

4684-
s->resolve(ctx, Defined{ctx.internalFile, StringRef(), STB_GLOBAL, stOther,
4685-
STT_NOTYPE, val,
4684+
s->resolve(ctx, Defined{ctx, ctx.internalFile, StringRef(), STB_GLOBAL,
4685+
stOther, STT_NOTYPE, val,
46864686
/*size=*/0, sec});
46874687
s->isUsedInRegularObj = true;
46884688
return cast<Defined>(s);

lld/ELF/Writer.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ static Defined *addOptionalRegular(Ctx &ctx, StringRef name, SectionBase *sec,
145145
if (!s || s->isDefined() || s->isCommon())
146146
return nullptr;
147147

148-
s->resolve(ctx, Defined{ctx.internalFile, StringRef(), STB_GLOBAL, stOther,
149-
STT_NOTYPE, val,
148+
s->resolve(ctx, Defined{ctx, ctx.internalFile, StringRef(), STB_GLOBAL,
149+
stOther, STT_NOTYPE, val,
150150
/*size=*/0, sec});
151151
s->isUsedInRegularObj = true;
152152
return cast<Defined>(s);
@@ -158,7 +158,7 @@ void elf::addReservedSymbols(Ctx &ctx) {
158158
if (ctx.arg.emachine == EM_MIPS) {
159159
auto addAbsolute = [&](StringRef name) {
160160
Symbol *sym =
161-
ctx.symtab->addSymbol(Defined{ctx.internalFile, name, STB_GLOBAL,
161+
ctx.symtab->addSymbol(Defined{ctx, ctx.internalFile, name, STB_GLOBAL,
162162
STV_HIDDEN, STT_NOTYPE, 0, 0, nullptr});
163163
sym->isUsedInRegularObj = true;
164164
return cast<Defined>(sym);
@@ -211,9 +211,9 @@ void elf::addReservedSymbols(Ctx &ctx) {
211211
if (ctx.arg.emachine == EM_PPC64)
212212
gotOff = 0x8000;
213213

214-
s->resolve(ctx,
215-
Defined{ctx.internalFile, StringRef(), STB_GLOBAL, STV_HIDDEN,
216-
STT_NOTYPE, gotOff, /*size=*/0, ctx.out.elfHeader});
214+
s->resolve(ctx, Defined{ctx, ctx.internalFile, StringRef(), STB_GLOBAL,
215+
STV_HIDDEN, STT_NOTYPE, gotOff, /*size=*/0,
216+
ctx.out.elfHeader});
217217
ctx.sym.globalOffsetTable = cast<Defined>(s);
218218
}
219219

@@ -534,7 +534,7 @@ template <class ELFT> void Writer<ELFT>::addSectionSymbols() {
534534
// Set the symbol to be relative to the output section so that its st_value
535535
// equals the output section address. Note, there may be a gap between the
536536
// start of the output section and isec.
537-
ctx.in.symTab->addSymbol(makeDefined(isec->file, "", STB_LOCAL,
537+
ctx.in.symTab->addSymbol(makeDefined(ctx, isec->file, "", STB_LOCAL,
538538
/*stOther=*/0, STT_SECTION,
539539
/*value=*/0, /*size=*/0, &osec));
540540
}
@@ -1734,7 +1734,7 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
17341734
// https://sourceware.org/ml/binutils/2002-03/msg00360.html
17351735
if (ctx.mainPart->dynamic->parent) {
17361736
Symbol *s = ctx.symtab->addSymbol(Defined{
1737-
ctx.internalFile, "_DYNAMIC", STB_WEAK, STV_HIDDEN, STT_NOTYPE,
1737+
ctx, ctx.internalFile, "_DYNAMIC", STB_WEAK, STV_HIDDEN, STT_NOTYPE,
17381738
/*value=*/0, /*size=*/0, ctx.mainPart->dynamic.get()});
17391739
s->isUsedInRegularObj = true;
17401740
}
@@ -1775,7 +1775,7 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
17751775
// define _TLS_MODULE_BASE_ relative to the first TLS section.
17761776
Symbol *s = ctx.symtab->find("_TLS_MODULE_BASE_");
17771777
if (s && s->isUndefined()) {
1778-
s->resolve(ctx, Defined{ctx.internalFile, StringRef(), STB_GLOBAL,
1778+
s->resolve(ctx, Defined{ctx, ctx.internalFile, StringRef(), STB_GLOBAL,
17791779
STV_HIDDEN, STT_TLS, /*value=*/0, 0,
17801780
/*section=*/nullptr});
17811781
ctx.sym.tlsModuleBase = cast<Defined>(s);

0 commit comments

Comments
 (0)