Skip to content

Commit 8e2476e

Browse files
committed
[ELF] Move SymbolAux into Ctx. NFC
The number of uses is modest.
1 parent 0953fb4 commit 8e2476e

File tree

6 files changed

+39
-39
lines changed

6 files changed

+39
-39
lines changed

lld/ELF/Config.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,15 @@ struct ConfigWrapper {
459459

460460
LLVM_LIBRARY_VISIBILITY extern ConfigWrapper config;
461461

462+
// Some index properties of a symbol are stored separately in this auxiliary
463+
// struct to decrease sizeof(SymbolUnion) in the majority of cases.
464+
struct SymbolAux {
465+
uint32_t gotIdx = -1;
466+
uint32_t pltIdx = -1;
467+
uint32_t tlsDescIdx = -1;
468+
uint32_t tlsGdIdx = -1;
469+
};
470+
462471
struct DuplicateSymbol {
463472
const Symbol *sym;
464473
const InputFile *file;
@@ -476,6 +485,8 @@ struct Ctx {
476485
SmallVector<BitcodeFile *, 0> lazyBitcodeFiles;
477486
SmallVector<InputSectionBase *, 0> inputSections;
478487
SmallVector<EhInputSection *, 0> ehInputSections;
488+
489+
SmallVector<SymbolAux, 0> symAux;
479490
// Duplicate symbol candidates.
480491
SmallVector<DuplicateSymbol, 0> duplicates;
481492
// Symbols in a non-prevailing COMDAT group which should be changed to an

lld/ELF/Driver.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ void Ctx::reset() {
101101
lazyBitcodeFiles.clear();
102102
inputSections.clear();
103103
ehInputSections.clear();
104+
105+
symAux.clear();
104106
duplicates.clear();
105107
nonPrevailingSyms.clear();
106108
whyExtractRecords.clear();
@@ -137,7 +139,6 @@ bool link(ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS,
137139
symtab = SymbolTable();
138140

139141
outputSections.clear();
140-
symAux.clear();
141142

142143
in.reset();
143144

@@ -153,7 +154,7 @@ bool link(ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS,
153154
config = ConfigWrapper();
154155
script = ScriptWrapper();
155156

156-
symAux.emplace_back();
157+
elf::ctx.symAux.emplace_back();
157158

158159
partitions.clear();
159160
partitions.emplace_back();

lld/ELF/Relocations.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1716,7 +1716,7 @@ static bool handleNonPreemptibleIfunc(Symbol &sym, uint16_t flags) {
17161716
auto &dyn = config->androidPackDynRelocs ? *in.relaPlt : *mainPart->relaDyn;
17171717
addPltEntry(*in.iplt, *in.igotPlt, dyn, target->iRelativeRel, *directSym);
17181718
sym.allocateAux();
1719-
symAux.back().pltIdx = symAux[directSym->auxIdx].pltIdx;
1719+
ctx.symAux.back().pltIdx = ctx.symAux[directSym->auxIdx].pltIdx;
17201720

17211721
if (flags & HAS_DIRECT_RELOC) {
17221722
// Change the value to the IPLT and redirect all references to it.
@@ -1834,7 +1834,7 @@ void elf::postScanRelocations() {
18341834
{R_ADDEND, target->symbolicRel, got->getTlsIndexOff(), 1, &dummy});
18351835
}
18361836

1837-
assert(symAux.size() == 1);
1837+
assert(ctx.symAux.size() == 1);
18381838
for (Symbol *sym : symtab.getSymbols())
18391839
fn(*sym);
18401840

lld/ELF/Symbols.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ Defined *ElfSym::riscvGlobalPointer;
7373
Defined *ElfSym::relaIpltStart;
7474
Defined *ElfSym::relaIpltEnd;
7575
Defined *ElfSym::tlsModuleBase;
76-
SmallVector<SymbolAux, 0> elf::symAux;
7776

7877
static uint64_t getSymVA(const Symbol &sym, int64_t addend) {
7978
switch (sym.kind()) {

lld/ELF/Symbols.h

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,6 @@ enum {
5656
NEEDS_TLSIE = 1 << 8,
5757
};
5858

59-
// Some index properties of a symbol are stored separately in this auxiliary
60-
// struct to decrease sizeof(SymbolUnion) in the majority of cases.
61-
struct SymbolAux {
62-
uint32_t gotIdx = -1;
63-
uint32_t pltIdx = -1;
64-
uint32_t tlsDescIdx = -1;
65-
uint32_t tlsGdIdx = -1;
66-
};
67-
68-
LLVM_LIBRARY_VISIBILITY extern SmallVector<SymbolAux, 0> symAux;
69-
7059
// The base class for real symbol classes.
7160
class Symbol {
7261
public:
@@ -211,10 +200,10 @@ class Symbol {
211200
// truncated by Symbol::parseSymbolVersion().
212201
const char *getVersionSuffix() const { return nameData + nameSize; }
213202

214-
uint32_t getGotIdx() const { return symAux[auxIdx].gotIdx; }
215-
uint32_t getPltIdx() const { return symAux[auxIdx].pltIdx; }
216-
uint32_t getTlsDescIdx() const { return symAux[auxIdx].tlsDescIdx; }
217-
uint32_t getTlsGdIdx() const { return symAux[auxIdx].tlsGdIdx; }
203+
uint32_t getGotIdx() const { return ctx.symAux[auxIdx].gotIdx; }
204+
uint32_t getPltIdx() const { return ctx.symAux[auxIdx].pltIdx; }
205+
uint32_t getTlsDescIdx() const { return ctx.symAux[auxIdx].tlsDescIdx; }
206+
uint32_t getTlsGdIdx() const { return ctx.symAux[auxIdx].tlsGdIdx; }
218207

219208
bool isInGot() const { return getGotIdx() != uint32_t(-1); }
220209
bool isInPlt() const { return getPltIdx() != uint32_t(-1); }
@@ -325,8 +314,8 @@ class Symbol {
325314
// entries during postScanRelocations();
326315
std::atomic<uint16_t> flags;
327316

328-
// A symAux index used to access GOT/PLT entry indexes. This is allocated in
329-
// postScanRelocations().
317+
// A ctx.symAux index used to access GOT/PLT entry indexes. This is allocated
318+
// in postScanRelocations().
330319
uint32_t auxIdx;
331320
uint32_t dynsymIndex;
332321

@@ -357,8 +346,8 @@ class Symbol {
357346
}
358347
void allocateAux() {
359348
assert(auxIdx == 0);
360-
auxIdx = symAux.size();
361-
symAux.emplace_back();
349+
auxIdx = ctx.symAux.size();
350+
ctx.symAux.emplace_back();
362351
}
363352

364353
bool isSection() const { return type == llvm::ELF::STT_SECTION; }

lld/ELF/SyntheticSections.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -653,20 +653,20 @@ GotSection::GotSection()
653653

654654
void GotSection::addConstant(const Relocation &r) { relocations.push_back(r); }
655655
void GotSection::addEntry(const Symbol &sym) {
656-
assert(sym.auxIdx == symAux.size() - 1);
657-
symAux.back().gotIdx = numEntries++;
656+
assert(sym.auxIdx == ctx.symAux.size() - 1);
657+
ctx.symAux.back().gotIdx = numEntries++;
658658
}
659659

660660
bool GotSection::addTlsDescEntry(const Symbol &sym) {
661-
assert(sym.auxIdx == symAux.size() - 1);
662-
symAux.back().tlsDescIdx = numEntries;
661+
assert(sym.auxIdx == ctx.symAux.size() - 1);
662+
ctx.symAux.back().tlsDescIdx = numEntries;
663663
numEntries += 2;
664664
return true;
665665
}
666666

667667
bool GotSection::addDynTlsEntry(const Symbol &sym) {
668-
assert(sym.auxIdx == symAux.size() - 1);
669-
symAux.back().tlsGdIdx = numEntries;
668+
assert(sym.auxIdx == ctx.symAux.size() - 1);
669+
ctx.symAux.back().tlsGdIdx = numEntries;
670670
// Global Dynamic TLS entries take two GOT slots.
671671
numEntries += 2;
672672
return true;
@@ -997,12 +997,12 @@ void MipsGotSection::build() {
997997
for (auto &p : primGot->global) {
998998
if (p.first->auxIdx == 0)
999999
p.first->allocateAux();
1000-
symAux.back().gotIdx = p.second;
1000+
ctx.symAux.back().gotIdx = p.second;
10011001
}
10021002
for (auto &p : primGot->relocs) {
10031003
if (p.first->auxIdx == 0)
10041004
p.first->allocateAux();
1005-
symAux.back().gotIdx = p.second;
1005+
ctx.symAux.back().gotIdx = p.second;
10061006
}
10071007

10081008
// Create dynamic relocations.
@@ -1171,8 +1171,8 @@ GotPltSection::GotPltSection()
11711171
}
11721172

11731173
void GotPltSection::addEntry(Symbol &sym) {
1174-
assert(sym.auxIdx == symAux.size() - 1 &&
1175-
symAux.back().pltIdx == entries.size());
1174+
assert(sym.auxIdx == ctx.symAux.size() - 1 &&
1175+
ctx.symAux.back().pltIdx == entries.size());
11761176
entries.push_back(&sym);
11771177
}
11781178

@@ -1217,7 +1217,7 @@ IgotPltSection::IgotPltSection()
12171217
target->gotEntrySize, getIgotPltName()) {}
12181218

12191219
void IgotPltSection::addEntry(Symbol &sym) {
1220-
assert(symAux.back().pltIdx == entries.size());
1220+
assert(ctx.symAux.back().pltIdx == entries.size());
12211221
entries.push_back(&sym);
12221222
}
12231223

@@ -2566,8 +2566,8 @@ void PltSection::writeTo(uint8_t *buf) {
25662566
}
25672567

25682568
void PltSection::addEntry(Symbol &sym) {
2569-
assert(sym.auxIdx == symAux.size() - 1);
2570-
symAux.back().pltIdx = entries.size();
2569+
assert(sym.auxIdx == ctx.symAux.size() - 1);
2570+
ctx.symAux.back().pltIdx = entries.size();
25712571
entries.push_back(&sym);
25722572
}
25732573

@@ -2613,8 +2613,8 @@ size_t IpltSection::getSize() const {
26132613
}
26142614

26152615
void IpltSection::addEntry(Symbol &sym) {
2616-
assert(sym.auxIdx == symAux.size() - 1);
2617-
symAux.back().pltIdx = entries.size();
2616+
assert(sym.auxIdx == ctx.symAux.size() - 1);
2617+
ctx.symAux.back().pltIdx = entries.size();
26182618
entries.push_back(&sym);
26192619
}
26202620

0 commit comments

Comments
 (0)