[lld] c12d49c - [ELF] Remove .strtab deduplication
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 18 14:54:18 PST 2022
Author: Fangrui Song
Date: 2022-02-18T14:54:10-08:00
New Revision: c12d49c4e286fa108d4d69f1c6d2b8d691993ffd
URL: https://github.com/llvm/llvm-project/commit/c12d49c4e286fa108d4d69f1c6d2b8d691993ffd
DIFF: https://github.com/llvm/llvm-project/commit/c12d49c4e286fa108d4d69f1c6d2b8d691993ffd.diff
LOG: [ELF] Remove .strtab deduplication
D118577: the 0.1~1.1% .strtab size reduction does not justify the 3~6%
link time increase. Just remove it even for -O2. release/14.x
has D118577 and the release note mentioned that this may be removed.
Fix https://github.com/ClangBuiltLinux/linux/issues/1578
caused by D118577 (empty string not in stringMap).
Added:
lld/test/ELF/strtab-nodedup.s
Modified:
lld/ELF/SyntheticSections.cpp
Removed:
lld/test/ELF/strtab-dedup.s
################################################################################
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index 0cc2cfb62b2ca..37b6877d699d1 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -1230,6 +1230,7 @@ StringTableSection::StringTableSection(StringRef name, bool dynamic)
dynamic(dynamic) {
// ELF string tables start with a NUL byte.
strings.push_back("");
+ stringMap.try_emplace(CachedHashStringRef(""), 0);
size = 1;
}
@@ -2156,9 +2157,7 @@ void SymbolTableBaseSection::sortSymTabSymbols() {
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() && config->optimize >= 2;
- symbols.push_back({b, strTabSec.addString(b->getName(), hashIt)});
+ symbols.push_back({b, strTabSec.addString(b->getName(), false)});
}
size_t SymbolTableBaseSection::getSymbolIndex(Symbol *sym) {
diff --git a/lld/test/ELF/strtab-dedup.s b/lld/test/ELF/strtab-dedup.s
deleted file mode 100644
index e7c36a4e2489b..0000000000000
--- a/lld/test/ELF/strtab-dedup.s
+++ /dev/null
@@ -1,33 +0,0 @@
-# REQUIRES: x86
-# RUN: split-file %s %t
-# RUN: llvm-mc -filetype=obj -triple=x86_64 %t/a.s -o %t/a.o
-# RUN: llvm-mc -filetype=obj -triple=x86_64 %t/b.s -o %t/b.o
-
-## By default local symbol names are not deduplicated.
-# RUN: ld.lld %t/a.o %t/b.o -o %t/a
-# RUN: llvm-readelf -p .strtab %t/a | FileCheck %s --check-prefix=NODEDUP
-
-# NODEDUP: [ 1] local
-# NODEDUP-NEXT: [ 7] local
-# NODEDUP-NEXT: [ d] foo
-# NODEDUP-EMPTY:
-
-## -O2 deduplicates local symbol names.
-# RUN: ld.lld -O2 %t/a.o %t/b.o -o %t/a
-# RUN: llvm-readelf -p .strtab %t/a | FileCheck %s --check-prefix=DEDUP
-
-# DEDUP: [ 1] local
-# DEDUP-NEXT: [ 7] foo
-# DEDUP-EMPTY:
-
-#--- a.s
-.global foo
-foo:
-local:
- ret
-
-#--- b.s
-.weak foo
-foo:
-local:
- ret
diff --git a/lld/test/ELF/strtab-nodedup.s b/lld/test/ELF/strtab-nodedup.s
new file mode 100644
index 0000000000000..b20e738de0679
--- /dev/null
+++ b/lld/test/ELF/strtab-nodedup.s
@@ -0,0 +1,36 @@
+# REQUIRES: x86
+# RUN: split-file %s %t
+# RUN: llvm-mc -filetype=obj -triple=x86_64 %t/a.s -o %t/a.o
+# RUN: llvm-mc -filetype=obj -triple=x86_64 %t/b.s -o %t/b.o
+
+## Non-empty local symbol names are not deduplicated. This helps parallel
+## .symtab write. We used to perform deduplication at -O2.
+# RUN: ld.lld %t/a.o %t/b.o -o %t/a
+# RUN: llvm-readelf -p .strtab %t/a | FileCheck %s --check-prefix=NODEDUP
+# RUN: ld.lld -r -O2 %t/a.o %t/b.o -o %t/a.ro
+# RUN: llvm-readelf -p .strtab %t/a.ro | FileCheck %s --check-prefix=NODEDUP
+
+# NODEDUP: [ 1] local
+# NODEDUP-NEXT: [ 7] local
+# NODEDUP-NEXT: [ d] foo
+# NODEDUP-EMPTY:
+
+# RUN: llvm-readelf -s %t/a.ro | FileCheck %s --check-prefix=SYMTAB
+
+# SYMTAB: 0: {{0+}} 0 NOTYPE LOCAL DEFAULT UND
+# SYMTAB-NEXT: NOTYPE LOCAL DEFAULT [[#]] local
+# SYMTAB-NEXT: SECTION LOCAL DEFAULT [[#]] .text
+# SYMTAB-NEXT: NOTYPE LOCAL DEFAULT [[#]] local
+# SYMTAB-NEXT: NOTYPE GLOBAL DEFAULT [[#]] foo
+
+#--- a.s
+.global foo
+foo:
+local:
+ ret
+
+#--- b.s
+.weak foo
+foo:
+local:
+ ret
More information about the llvm-commits
mailing list