diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp index 2a385502cb92..828a0053bbd1 100644 --- a/lld/ELF/OutputSections.cpp +++ b/lld/ELF/OutputSections.cpp @@ -473,11 +473,11 @@ static bool includeInGnuHashTable(SymbolBody *B) { template void GnuHashTableSection::addSymbols( - std::vector> &Symbols) { - std::vector> NotHashed; + std::vector> &Symbols) { + std::vector> NotHashed; NotHashed.reserve(Symbols.size()); HashedSymbols.reserve(Symbols.size()); - for (const std::pair &P : Symbols) { + for (const std::pair &P : Symbols) { SymbolBody *B = P.first; if (includeInGnuHashTable(B)) HashedSymbols.push_back( @@ -1386,14 +1386,13 @@ template void SymbolTableSection::finalize() { else if (Config->EMachine == EM_MIPS) std::stable_sort(Symbols.begin(), Symbols.end(), sortMipsSymbols); size_t I = 0; - for (const std::pair &P : Symbols) + for (const std::pair &P : Symbols) P.first->DynsymIndex = ++I; } template -void SymbolTableSection::addSymbol(SymbolBody *Body) { - Symbols.push_back( - std::make_pair(Body, StrTabSec.addString(Body->getName(), false))); +void SymbolTableSection::addSymbol(SymbolBody *B) { + Symbols.push_back({B, StrTabSec.addString(B->getName(), false)}); } template void SymbolTableSection::writeTo(uint8_t *Buf) { @@ -1412,7 +1411,7 @@ void SymbolTableSection::writeLocalSymbols(uint8_t *&Buf) { // Iterate over all input object files to copy their local symbols // to the output symbol table pointed by Buf. for (const std::unique_ptr> &File : Table.getObjectFiles()) { - for (const std::pair &P : File->KeptLocalSyms) { + for (const std::pair &P : File->KeptLocalSyms) { const Elf_Sym *Sym = P.first; auto *ESym = reinterpret_cast(Buf); @@ -1454,9 +1453,9 @@ void SymbolTableSection::writeGlobalSymbols(uint8_t *Buf) { // Write the internal symbol table contents to the output symbol table // pointed by Buf. auto *ESym = reinterpret_cast(Buf); - for (const std::pair &P : Symbols) { + for (const std::pair &P : Symbols) { SymbolBody *Body = P.first; - unsigned SymIdx = P.second; + size_t StrOff = P.second; unsigned char Type = STT_NOTYPE; uintX_t Size = 0; @@ -1470,7 +1469,7 @@ void SymbolTableSection::writeGlobalSymbols(uint8_t *Buf) { ESym->setBindingAndType(getSymbolBinding(Body), Type); ESym->st_size = Size; - ESym->st_name = SymIdx; + ESym->st_name = StrOff; ESym->setVisibility(Body->getVisibility()); ESym->st_value = Body->getVA(); diff --git a/lld/ELF/OutputSections.h b/lld/ELF/OutputSections.h index ebaa3f559418..0911e5186d24 100644 --- a/lld/ELF/OutputSections.h +++ b/lld/ELF/OutputSections.h @@ -230,7 +230,7 @@ public: StringTableSection &getStrTabSec() const { return StrTabSec; } unsigned getNumSymbols() const { return NumLocals + Symbols.size() + 1; } - ArrayRef> getSymbols() const { + ArrayRef> getSymbols() const { return Symbols; } @@ -245,7 +245,9 @@ private: static uint8_t getSymbolBinding(SymbolBody *Body); SymbolTable &Table; - std::vector> Symbols; + + // A vector of symbols and their string table offsets. + std::vector> Symbols; }; template @@ -399,7 +401,7 @@ public: // Adds symbols to the hash table. // Sorts the input to satisfy GNU hash section requirements. - void addSymbols(std::vector> &Symbols); + void addSymbols(std::vector> &Symbols); private: static unsigned calcNBuckets(unsigned NumHashed); @@ -411,7 +413,7 @@ private: struct HashedSymbolData { SymbolBody *Body; - unsigned STName; + size_t STName; uint32_t Hash; };