Skip to content

Commit c12d49c

Browse files
committed
[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 ClangBuiltLinux/linux#1578 caused by D118577 (empty string not in stringMap).
1 parent e3b9bb5 commit c12d49c

File tree

3 files changed

+38
-36
lines changed

3 files changed

+38
-36
lines changed

lld/ELF/SyntheticSections.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,6 +1230,7 @@ StringTableSection::StringTableSection(StringRef name, bool dynamic)
12301230
dynamic(dynamic) {
12311231
// ELF string tables start with a NUL byte.
12321232
strings.push_back("");
1233+
stringMap.try_emplace(CachedHashStringRef(""), 0);
12331234
size = 1;
12341235
}
12351236

@@ -2156,9 +2157,7 @@ void SymbolTableBaseSection::sortSymTabSymbols() {
21562157
void SymbolTableBaseSection::addSymbol(Symbol *b) {
21572158
// Adding a local symbol to a .dynsym is a bug.
21582159
assert(this->type != SHT_DYNSYM || !b->isLocal());
2159-
2160-
bool hashIt = b->isLocal() && config->optimize >= 2;
2161-
symbols.push_back({b, strTabSec.addString(b->getName(), hashIt)});
2160+
symbols.push_back({b, strTabSec.addString(b->getName(), false)});
21622161
}
21632162

21642163
size_t SymbolTableBaseSection::getSymbolIndex(Symbol *sym) {

lld/test/ELF/strtab-dedup.s

Lines changed: 0 additions & 33 deletions
This file was deleted.

lld/test/ELF/strtab-nodedup.s

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# REQUIRES: x86
2+
# RUN: split-file %s %t
3+
# RUN: llvm-mc -filetype=obj -triple=x86_64 %t/a.s -o %t/a.o
4+
# RUN: llvm-mc -filetype=obj -triple=x86_64 %t/b.s -o %t/b.o
5+
6+
## Non-empty local symbol names are not deduplicated. This helps parallel
7+
## .symtab write. We used to perform deduplication at -O2.
8+
# RUN: ld.lld %t/a.o %t/b.o -o %t/a
9+
# RUN: llvm-readelf -p .strtab %t/a | FileCheck %s --check-prefix=NODEDUP
10+
# RUN: ld.lld -r -O2 %t/a.o %t/b.o -o %t/a.ro
11+
# RUN: llvm-readelf -p .strtab %t/a.ro | FileCheck %s --check-prefix=NODEDUP
12+
13+
# NODEDUP: [ 1] local
14+
# NODEDUP-NEXT: [ 7] local
15+
# NODEDUP-NEXT: [ d] foo
16+
# NODEDUP-EMPTY:
17+
18+
# RUN: llvm-readelf -s %t/a.ro | FileCheck %s --check-prefix=SYMTAB
19+
20+
# SYMTAB: 0: {{0+}} 0 NOTYPE LOCAL DEFAULT UND
21+
# SYMTAB-NEXT: NOTYPE LOCAL DEFAULT [[#]] local
22+
# SYMTAB-NEXT: SECTION LOCAL DEFAULT [[#]] .text
23+
# SYMTAB-NEXT: NOTYPE LOCAL DEFAULT [[#]] local
24+
# SYMTAB-NEXT: NOTYPE GLOBAL DEFAULT [[#]] foo
25+
26+
#--- a.s
27+
.global foo
28+
foo:
29+
local:
30+
ret
31+
32+
#--- b.s
33+
.weak foo
34+
foo:
35+
local:
36+
ret

0 commit comments

Comments
 (0)