diff options
author | Fangrui Song <i@maskray.me> | 2022-01-09 13:43:26 -0800 |
---|---|---|
committer | Fangrui Song <i@maskray.me> | 2022-01-09 13:43:27 -0800 |
commit | 5d3bd7f36092c88265dc698a970078184425f67c (patch) | |
tree | 63099dd77adf86432a81462d7f9f20cef9b1e8ef /lld/ELF/SyntheticSections.cpp | |
parent | 2bcff220bf1e372e91491911fe0bb76c4c4bbef8 (diff) | |
download | llvm-5d3bd7f36092c88265dc698a970078184425f67c.zip llvm-5d3bd7f36092c88265dc698a970078184425f67c.tar.gz llvm-5d3bd7f36092c88265dc698a970078184425f67c.tar.bz2 |
[ELF] Move gotIndex/pltIndex/globalDynIndex to SymbolAux
to decrease sizeof(SymbolUnion) by 8 on ELF64 platforms.
Symbols needing such information are typically 1% or fewer (5134 out of 560520
when linking clang, 19898 out of 5550705 when linking chrome). Storing them
elsewhere can decrease memory usage and symbol initialization time.
There is a ~0.8% saving on max RSS when linking a large program.
Future direction:
* Move some of dynsymIndex/verdefIndex/versionId to SymbolAux
* Support mixed TLSDESC and TLS GD without increasing sizeof(SymbolUnion)
Reviewed By: peter.smith
Differential Revision: https://reviews.llvm.org/D116281
Diffstat (limited to 'lld/ELF/SyntheticSections.cpp')
-rw-r--r-- | lld/ELF/SyntheticSections.cpp | 42 |
1 files changed, 25 insertions, 17 deletions
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index f93c09b..6af1023 100644 --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -650,14 +650,13 @@ GotSection::GotSection() } void GotSection::addEntry(Symbol &sym) { - sym.gotIndex = numEntries; - ++numEntries; + assert(sym.auxIdx == symAux.size() - 1); + symAux.back().gotIdx = numEntries++; } bool GotSection::addDynTlsEntry(Symbol &sym) { - if (sym.globalDynIndex != -1U) - return false; - sym.globalDynIndex = numEntries; + assert(sym.auxIdx == symAux.size() - 1); + symAux.back().tlsGdIdx = numEntries; // Global Dynamic TLS entries take two GOT slots. numEntries += 2; return true; @@ -674,11 +673,11 @@ bool GotSection::addTlsIndex() { } uint64_t GotSection::getGlobalDynAddr(const Symbol &b) const { - return this->getVA() + b.globalDynIndex * config->wordsize; + return this->getVA() + b.getTlsGdIdx() * config->wordsize; } uint64_t GotSection::getGlobalDynOffset(const Symbol &b) const { - return b.globalDynIndex * config->wordsize; + return b.getTlsGdIdx() * config->wordsize; } void GotSection::finalizeContents() { @@ -972,12 +971,18 @@ void MipsGotSection::build() { } } - // Update Symbol::gotIndex field to use this + // Update SymbolAux::gotIdx field to use this // value later in the `sortMipsSymbols` function. - for (auto &p : primGot->global) - p.first->gotIndex = p.second; - for (auto &p : primGot->relocs) - p.first->gotIndex = p.second; + for (auto &p : primGot->global) { + if (p.first->auxIdx == uint32_t(-1)) + p.first->allocateAux(); + symAux.back().gotIdx = p.second; + } + for (auto &p : primGot->relocs) { + if (p.first->auxIdx == uint32_t(-1)) + p.first->allocateAux(); + symAux.back().gotIdx = p.second; + } // Create dynamic relocations. for (FileGot &got : gots) { @@ -1145,7 +1150,8 @@ GotPltSection::GotPltSection() } void GotPltSection::addEntry(Symbol &sym) { - assert(sym.pltIndex == entries.size()); + assert(sym.auxIdx == symAux.size() - 1 && + symAux.back().pltIdx == entries.size()); entries.push_back(&sym); } @@ -1190,7 +1196,7 @@ IgotPltSection::IgotPltSection() target->gotEntrySize, getIgotPltName()) {} void IgotPltSection::addEntry(Symbol &sym) { - assert(sym.pltIndex == entries.size()); + assert(symAux.back().pltIdx == entries.size()); entries.push_back(&sym); } @@ -2069,7 +2075,7 @@ static bool sortMipsSymbols(const SymbolTableEntry &l, // Sort entries related to non-local preemptible symbols by GOT indexes. // All other entries go to the beginning of a dynsym in arbitrary order. if (l.sym->isInGot() && r.sym->isInGot()) - return l.sym->gotIndex < r.sym->gotIndex; + return l.sym->getGotIdx() < r.sym->getGotIdx(); if (!l.sym->isInGot() && !r.sym->isInGot()) return false; return !l.sym->isInGot(); @@ -2546,7 +2552,8 @@ void PltSection::writeTo(uint8_t *buf) { } void PltSection::addEntry(Symbol &sym) { - sym.pltIndex = entries.size(); + assert(sym.auxIdx == symAux.size() - 1); + symAux.back().pltIdx = entries.size(); entries.push_back(&sym); } @@ -2592,7 +2599,8 @@ size_t IpltSection::getSize() const { } void IpltSection::addEntry(Symbol &sym) { - sym.pltIndex = entries.size(); + assert(sym.auxIdx == symAux.size() - 1); + symAux.back().pltIdx = entries.size(); entries.push_back(&sym); } |