aboutsummaryrefslogtreecommitdiff
path: root/lld/ELF/SyntheticSections.cpp
diff options
context:
space:
mode:
authorFangrui Song <i@maskray.me>2022-02-01 10:10:22 -0800
committerFangrui Song <i@maskray.me>2022-02-01 10:10:22 -0800
commit0c3704fdbd901e5f51acf11a85278bf9214ae7b2 (patch)
tree282687f9e8a3c9fc5d7028b28c628dc15bbbc3f1 /lld/ELF/SyntheticSections.cpp
parentceb9094a49134d21333150dd876fbb09a165eb3a (diff)
downloadllvm-0c3704fdbd901e5f51acf11a85278bf9214ae7b2.zip
llvm-0c3704fdbd901e5f51acf11a85278bf9214ae7b2.tar.gz
llvm-0c3704fdbd901e5f51acf11a85278bf9214ae7b2.tar.bz2
[ELF] Deduplicate names of local symbols only with -O2
The deduplication requires a DenseMap of the same size of the local part of .strtab . I optimized it in e20544543478b259eb09fa0a253d4fb1a5525d9e but it is still quite slow. For Release build of clang, deduplication makes .strtab 1.1% smaller and makes the link 3% slower. For chrome, deduplication makes .strtab 0.1% smaller and makes the link 6% slower. I suggest that we only perform the optimization with -O2 (default is -O1). Not deduplicating local symbol names will simplify parallel symbol table write. Reviewed By: peter.smith Differential Revision: https://reviews.llvm.org/D118577
Diffstat (limited to 'lld/ELF/SyntheticSections.cpp')
-rw-r--r--lld/ELF/SyntheticSections.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index 36a226c..986c130 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -1230,7 +1230,8 @@ StringTableSection::StringTableSection(StringRef name, bool dynamic)
: SyntheticSection(dynamic ? (uint64_t)SHF_ALLOC : 0, SHT_STRTAB, 1, name),
dynamic(dynamic) {
// ELF string tables start with a NUL byte.
- addString("");
+ strings.push_back("");
+ size = 1;
}
// Adds a string to the string table. If `hashIt` is true we hash and check for
@@ -1243,6 +1244,8 @@ unsigned StringTableSection::addString(StringRef s, bool hashIt) {
if (!r.second)
return r.first->second;
}
+ if (s.empty())
+ return 0;
unsigned ret = this->size;
this->size = this->size + s.size() + 1;
strings.push_back(s);
@@ -2155,7 +2158,7 @@ void SymbolTableBaseSection::addSymbol(Symbol *b) {
// Adding a local symbol to a .dynsym is a bug.
assert(this->type != SHT_DYNSYM || !b->isLocal());
- bool hashIt = b->isLocal();
+ bool hashIt = b->isLocal() && config->optimize >= 2;
symbols.push_back({b, strTabSec.addString(b->getName(), hashIt)});
}