[lld] 8e2476e - [ELF] Move SymbolAux into Ctx. NFC
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 28 20:51:38 PDT 2024
Author: Fangrui Song
Date: 2024-07-28T20:51:33-07:00
New Revision: 8e2476e102e8ce3ae496b293bacccb248787404d
URL: https://github.com/llvm/llvm-project/commit/8e2476e102e8ce3ae496b293bacccb248787404d
DIFF: https://github.com/llvm/llvm-project/commit/8e2476e102e8ce3ae496b293bacccb248787404d.diff
LOG: [ELF] Move SymbolAux into Ctx. NFC
The number of uses is modest.
Added:
Modified:
lld/ELF/Config.h
lld/ELF/Driver.cpp
lld/ELF/Relocations.cpp
lld/ELF/Symbols.cpp
lld/ELF/Symbols.h
lld/ELF/SyntheticSections.cpp
Removed:
################################################################################
diff --git a/lld/ELF/Config.h b/lld/ELF/Config.h
index 2f6758743c0d6..6abd929d2343d 100644
--- a/lld/ELF/Config.h
+++ b/lld/ELF/Config.h
@@ -459,6 +459,15 @@ struct ConfigWrapper {
LLVM_LIBRARY_VISIBILITY extern ConfigWrapper config;
+// Some index properties of a symbol are stored separately in this auxiliary
+// struct to decrease sizeof(SymbolUnion) in the majority of cases.
+struct SymbolAux {
+ uint32_t gotIdx = -1;
+ uint32_t pltIdx = -1;
+ uint32_t tlsDescIdx = -1;
+ uint32_t tlsGdIdx = -1;
+};
+
struct DuplicateSymbol {
const Symbol *sym;
const InputFile *file;
@@ -476,6 +485,8 @@ struct Ctx {
SmallVector<BitcodeFile *, 0> lazyBitcodeFiles;
SmallVector<InputSectionBase *, 0> inputSections;
SmallVector<EhInputSection *, 0> ehInputSections;
+
+ SmallVector<SymbolAux, 0> symAux;
// Duplicate symbol candidates.
SmallVector<DuplicateSymbol, 0> duplicates;
// Symbols in a non-prevailing COMDAT group which should be changed to an
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index cd85040a4ca73..7e0a5a1937c7f 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -101,6 +101,8 @@ void Ctx::reset() {
lazyBitcodeFiles.clear();
inputSections.clear();
ehInputSections.clear();
+
+ symAux.clear();
duplicates.clear();
nonPrevailingSyms.clear();
whyExtractRecords.clear();
@@ -137,7 +139,6 @@ bool link(ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS,
symtab = SymbolTable();
outputSections.clear();
- symAux.clear();
in.reset();
@@ -153,7 +154,7 @@ bool link(ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS,
config = ConfigWrapper();
script = ScriptWrapper();
- symAux.emplace_back();
+ elf::ctx.symAux.emplace_back();
partitions.clear();
partitions.emplace_back();
diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index 9a799cd286135..94ad7b3570820 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -1716,7 +1716,7 @@ static bool handleNonPreemptibleIfunc(Symbol &sym, uint16_t flags) {
auto &dyn = config->androidPackDynRelocs ? *in.relaPlt : *mainPart->relaDyn;
addPltEntry(*in.iplt, *in.igotPlt, dyn, target->iRelativeRel, *directSym);
sym.allocateAux();
- symAux.back().pltIdx = symAux[directSym->auxIdx].pltIdx;
+ ctx.symAux.back().pltIdx = ctx.symAux[directSym->auxIdx].pltIdx;
if (flags & HAS_DIRECT_RELOC) {
// Change the value to the IPLT and redirect all references to it.
@@ -1834,7 +1834,7 @@ void elf::postScanRelocations() {
{R_ADDEND, target->symbolicRel, got->getTlsIndexOff(), 1, &dummy});
}
- assert(symAux.size() == 1);
+ assert(ctx.symAux.size() == 1);
for (Symbol *sym : symtab.getSymbols())
fn(*sym);
diff --git a/lld/ELF/Symbols.cpp b/lld/ELF/Symbols.cpp
index 93653def328f8..263d4f35c5b9a 100644
--- a/lld/ELF/Symbols.cpp
+++ b/lld/ELF/Symbols.cpp
@@ -73,7 +73,6 @@ Defined *ElfSym::riscvGlobalPointer;
Defined *ElfSym::relaIpltStart;
Defined *ElfSym::relaIpltEnd;
Defined *ElfSym::tlsModuleBase;
-SmallVector<SymbolAux, 0> elf::symAux;
static uint64_t getSymVA(const Symbol &sym, int64_t addend) {
switch (sym.kind()) {
diff --git a/lld/ELF/Symbols.h b/lld/ELF/Symbols.h
index e764fe8d73633..ff825615658eb 100644
--- a/lld/ELF/Symbols.h
+++ b/lld/ELF/Symbols.h
@@ -56,17 +56,6 @@ enum {
NEEDS_TLSIE = 1 << 8,
};
-// Some index properties of a symbol are stored separately in this auxiliary
-// struct to decrease sizeof(SymbolUnion) in the majority of cases.
-struct SymbolAux {
- uint32_t gotIdx = -1;
- uint32_t pltIdx = -1;
- uint32_t tlsDescIdx = -1;
- uint32_t tlsGdIdx = -1;
-};
-
-LLVM_LIBRARY_VISIBILITY extern SmallVector<SymbolAux, 0> symAux;
-
// The base class for real symbol classes.
class Symbol {
public:
@@ -211,10 +200,10 @@ class Symbol {
// truncated by Symbol::parseSymbolVersion().
const char *getVersionSuffix() const { return nameData + nameSize; }
- uint32_t getGotIdx() const { return symAux[auxIdx].gotIdx; }
- uint32_t getPltIdx() const { return symAux[auxIdx].pltIdx; }
- uint32_t getTlsDescIdx() const { return symAux[auxIdx].tlsDescIdx; }
- uint32_t getTlsGdIdx() const { return symAux[auxIdx].tlsGdIdx; }
+ uint32_t getGotIdx() const { return ctx.symAux[auxIdx].gotIdx; }
+ uint32_t getPltIdx() const { return ctx.symAux[auxIdx].pltIdx; }
+ uint32_t getTlsDescIdx() const { return ctx.symAux[auxIdx].tlsDescIdx; }
+ uint32_t getTlsGdIdx() const { return ctx.symAux[auxIdx].tlsGdIdx; }
bool isInGot() const { return getGotIdx() != uint32_t(-1); }
bool isInPlt() const { return getPltIdx() != uint32_t(-1); }
@@ -325,8 +314,8 @@ class Symbol {
// entries during postScanRelocations();
std::atomic<uint16_t> flags;
- // A symAux index used to access GOT/PLT entry indexes. This is allocated in
- // postScanRelocations().
+ // A ctx.symAux index used to access GOT/PLT entry indexes. This is allocated
+ // in postScanRelocations().
uint32_t auxIdx;
uint32_t dynsymIndex;
@@ -357,8 +346,8 @@ class Symbol {
}
void allocateAux() {
assert(auxIdx == 0);
- auxIdx = symAux.size();
- symAux.emplace_back();
+ auxIdx = ctx.symAux.size();
+ ctx.symAux.emplace_back();
}
bool isSection() const { return type == llvm::ELF::STT_SECTION; }
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index b40ff0bc3cb03..b767392c4456c 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -653,20 +653,20 @@ GotSection::GotSection()
void GotSection::addConstant(const Relocation &r) { relocations.push_back(r); }
void GotSection::addEntry(const Symbol &sym) {
- assert(sym.auxIdx == symAux.size() - 1);
- symAux.back().gotIdx = numEntries++;
+ assert(sym.auxIdx == ctx.symAux.size() - 1);
+ ctx.symAux.back().gotIdx = numEntries++;
}
bool GotSection::addTlsDescEntry(const Symbol &sym) {
- assert(sym.auxIdx == symAux.size() - 1);
- symAux.back().tlsDescIdx = numEntries;
+ assert(sym.auxIdx == ctx.symAux.size() - 1);
+ ctx.symAux.back().tlsDescIdx = numEntries;
numEntries += 2;
return true;
}
bool GotSection::addDynTlsEntry(const Symbol &sym) {
- assert(sym.auxIdx == symAux.size() - 1);
- symAux.back().tlsGdIdx = numEntries;
+ assert(sym.auxIdx == ctx.symAux.size() - 1);
+ ctx.symAux.back().tlsGdIdx = numEntries;
// Global Dynamic TLS entries take two GOT slots.
numEntries += 2;
return true;
@@ -997,12 +997,12 @@ void MipsGotSection::build() {
for (auto &p : primGot->global) {
if (p.first->auxIdx == 0)
p.first->allocateAux();
- symAux.back().gotIdx = p.second;
+ ctx.symAux.back().gotIdx = p.second;
}
for (auto &p : primGot->relocs) {
if (p.first->auxIdx == 0)
p.first->allocateAux();
- symAux.back().gotIdx = p.second;
+ ctx.symAux.back().gotIdx = p.second;
}
// Create dynamic relocations.
@@ -1171,8 +1171,8 @@ GotPltSection::GotPltSection()
}
void GotPltSection::addEntry(Symbol &sym) {
- assert(sym.auxIdx == symAux.size() - 1 &&
- symAux.back().pltIdx == entries.size());
+ assert(sym.auxIdx == ctx.symAux.size() - 1 &&
+ ctx.symAux.back().pltIdx == entries.size());
entries.push_back(&sym);
}
@@ -1217,7 +1217,7 @@ IgotPltSection::IgotPltSection()
target->gotEntrySize, getIgotPltName()) {}
void IgotPltSection::addEntry(Symbol &sym) {
- assert(symAux.back().pltIdx == entries.size());
+ assert(ctx.symAux.back().pltIdx == entries.size());
entries.push_back(&sym);
}
@@ -2566,8 +2566,8 @@ void PltSection::writeTo(uint8_t *buf) {
}
void PltSection::addEntry(Symbol &sym) {
- assert(sym.auxIdx == symAux.size() - 1);
- symAux.back().pltIdx = entries.size();
+ assert(sym.auxIdx == ctx.symAux.size() - 1);
+ ctx.symAux.back().pltIdx = entries.size();
entries.push_back(&sym);
}
@@ -2613,8 +2613,8 @@ size_t IpltSection::getSize() const {
}
void IpltSection::addEntry(Symbol &sym) {
- assert(sym.auxIdx == symAux.size() - 1);
- symAux.back().pltIdx = entries.size();
+ assert(sym.auxIdx == ctx.symAux.size() - 1);
+ ctx.symAux.back().pltIdx = entries.size();
entries.push_back(&sym);
}
More information about the llvm-commits
mailing list