[lld] e3ecc6a - [ELF] Make symAux[0] a sentinel
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 29 00:50:27 PDT 2022
Author: Fangrui Song
Date: 2022-09-29T00:50:19-07:00
New Revision: e3ecc6a91241affd1d93615e0c9569794b016a00
URL: https://github.com/llvm/llvm-project/commit/e3ecc6a91241affd1d93615e0c9569794b016a00
DIFF: https://github.com/llvm/llvm-project/commit/e3ecc6a91241affd1d93615e0c9569794b016a00.diff
LOG: [ELF] Make symAux[0] a sentinel
And default auxIdx to 0.
Added:
Modified:
lld/ELF/Driver.cpp
lld/ELF/InputFiles.cpp
lld/ELF/Relocations.cpp
lld/ELF/SymbolTable.cpp
lld/ELF/Symbols.h
lld/ELF/SyntheticSections.cpp
Removed:
################################################################################
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 74b16e016791a..d5e9e8f017d25 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -118,6 +118,8 @@ bool elf::link(ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS,
script = std::make_unique<LinkerScript>();
symtab = std::make_unique<SymbolTable>();
+ symAux.emplace_back();
+
partitions.clear();
partitions.emplace_back();
diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp
index 2f2d40ba800dc..d5faefe64fde6 100644
--- a/lld/ELF/InputFiles.cpp
+++ b/lld/ELF/InputFiles.cpp
@@ -1131,7 +1131,6 @@ void ObjFile<ELFT>::initSectionsAndLocalSyms(bool ignoreComdats) {
eSym.st_value, eSym.st_size, sec);
symbols[i]->partition = 1;
symbols[i]->isUsedInRegularObj = true;
- symbols[i]->auxIdx = -1;
}
}
diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index 6590d9184802a..e2e7a5ee79eb8 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -1748,7 +1748,7 @@ void elf::postScanRelocations() {
{R_ADDEND, target->symbolicRel, in.got->getTlsIndexOff(), 1, &dummy});
}
- assert(symAux.empty());
+ assert(symAux.size() == 1);
for (Symbol *sym : symtab->getSymbols())
fn(*sym);
diff --git a/lld/ELF/SymbolTable.cpp b/lld/ELF/SymbolTable.cpp
index baa085c9c7133..7852127c895da 100644
--- a/lld/ELF/SymbolTable.cpp
+++ b/lld/ELF/SymbolTable.cpp
@@ -91,7 +91,6 @@ Symbol *SymbolTable::insert(StringRef name) {
memset(sym, 0, sizeof(Symbol));
sym->setName(name);
sym->partition = 1;
- sym->auxIdx = -1;
sym->verdefIndex = -1;
sym->versionId = VER_NDX_GLOBAL;
if (pos != StringRef::npos)
diff --git a/lld/ELF/Symbols.h b/lld/ELF/Symbols.h
index 6e8f0a0414e36..5ef08a6fa6808 100644
--- a/lld/ELF/Symbols.h
+++ b/lld/ELF/Symbols.h
@@ -201,18 +201,10 @@ class Symbol {
// truncated by Symbol::parseSymbolVersion().
const char *getVersionSuffix() const { return nameData + nameSize; }
- uint32_t getGotIdx() const {
- return auxIdx == uint32_t(-1) ? uint32_t(-1) : symAux[auxIdx].gotIdx;
- }
- uint32_t getPltIdx() const {
- return auxIdx == uint32_t(-1) ? uint32_t(-1) : symAux[auxIdx].pltIdx;
- }
- uint32_t getTlsDescIdx() const {
- return auxIdx == uint32_t(-1) ? uint32_t(-1) : symAux[auxIdx].tlsDescIdx;
- }
- uint32_t getTlsGdIdx() const {
- return auxIdx == uint32_t(-1) ? uint32_t(-1) : symAux[auxIdx].tlsGdIdx;
- }
+ 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; }
bool isInGot() const { return getGotIdx() != uint32_t(-1); }
bool isInPlt() const { return getPltIdx() != uint32_t(-1); }
@@ -328,7 +320,7 @@ class Symbol {
NEEDS_TLSGD_TO_IE | NEEDS_GOT_DTPREL | NEEDS_TLSIE);
}
void allocateAux() {
- assert(auxIdx == uint32_t(-1));
+ assert(auxIdx == 0);
auxIdx = symAux.size();
symAux.emplace_back();
}
@@ -548,7 +540,6 @@ template <typename... T> Defined *makeDefined(T &&...args) {
auto *sym = getSpecificAllocSingleton<SymbolUnion>().Allocate();
memset(sym, 0, sizeof(Symbol));
auto &s = *new (reinterpret_cast<Defined *>(sym)) Defined(std::forward<T>(args)...);
- s.auxIdx = -1;
return &s;
}
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index eb70c1d5504f1..24336fd50b51a 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -960,12 +960,12 @@ void MipsGotSection::build() {
// Update SymbolAux::gotIdx field to use this
// value later in the `sortMipsSymbols` function.
for (auto &p : primGot->global) {
- if (p.first->auxIdx == uint32_t(-1))
+ if (p.first->auxIdx == 0)
p.first->allocateAux();
symAux.back().gotIdx = p.second;
}
for (auto &p : primGot->relocs) {
- if (p.first->auxIdx == uint32_t(-1))
+ if (p.first->auxIdx == 0)
p.first->allocateAux();
symAux.back().gotIdx = p.second;
}
More information about the llvm-commits
mailing list