From e3ecc6a91241affd1d93615e0c9569794b016a00 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Thu, 29 Sep 2022 00:50:19 -0700 Subject: [PATCH] [ELF] Make symAux[0] a sentinel And default auxIdx to 0. --- lld/ELF/Driver.cpp | 2 ++ lld/ELF/InputFiles.cpp | 1 - lld/ELF/Relocations.cpp | 2 +- lld/ELF/SymbolTable.cpp | 1 - lld/ELF/Symbols.h | 19 +++++-------------- lld/ELF/SyntheticSections.cpp | 4 ++-- 6 files changed, 10 insertions(+), 19 deletions(-) diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index 74b16e0..d5e9e8f 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -118,6 +118,8 @@ bool elf::link(ArrayRef args, llvm::raw_ostream &stdoutOS, script = std::make_unique(); symtab = std::make_unique(); + symAux.emplace_back(); + partitions.clear(); partitions.emplace_back(); diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp index 2f2d40b..d5faefe 100644 --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -1131,7 +1131,6 @@ void ObjFile::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 6590d91..e2e7a5e 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 baa085c..7852127 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 6e8f0a0..5ef08a6 100644 --- a/lld/ELF/Symbols.h +++ b/lld/ELF/Symbols.h @@ -201,18 +201,10 @@ public: // 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 @@ public: 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 Defined *makeDefined(T &&...args) { auto *sym = getSpecificAllocSingleton().Allocate(); memset(sym, 0, sizeof(Symbol)); auto &s = *new (reinterpret_cast(sym)) Defined(std::forward(args)...); - s.auxIdx = -1; return &s; } diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index eb70c1d..24336fd 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; } -- 2.7.4