[PATCH] D118577: [ELF] Deduplicate names of local symbols only with -O2
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Jan 30 18:23:37 PST 2022
MaskRay created this revision.
MaskRay added reviewers: bd1976llvm, ikudrin, peter.smith.
Herald added subscribers: arichardson, emaste.
MaskRay requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
The deduplication requires a DenseMap of the same size of the local part of
.strtab . I optimized it in e20544543478b259eb09fa0a253d4fb1a5525d9e <https://reviews.llvm.org/rGe20544543478b259eb09fa0a253d4fb1a5525d9e> 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).
---
I will fix other tests if this looks good.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D118577
Files:
lld/ELF/SyntheticSections.cpp
lld/test/ELF/strtab-dedup.s
Index: lld/test/ELF/strtab-dedup.s
===================================================================
--- /dev/null
+++ lld/test/ELF/strtab-dedup.s
@@ -0,0 +1,20 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o
+
+## By default local symbol names are not deduplicated.
+# RUN: ld.lld %t.o %t.o -o %t
+# RUN: llvm-readelf -p .strtab %t | FileCheck %s --check-prefix=NODEDUP
+
+# NODEDUP: [ 1] local
+# NODEDUP-NEXT: [ 7] local
+# NODEDUP-EMPTY:
+
+## -O2 deduplicates local symbol names.
+# RUN: ld.lld -O2 %t.o %t.o -o %t
+# RUN: llvm-readelf -p .strtab %t | FileCheck %s --check-prefix=DEDUP
+
+# DEDUP: [ 1] local
+# DEDUP-EMPTY:
+
+local:
+ ret
Index: lld/ELF/SyntheticSections.cpp
===================================================================
--- lld/ELF/SyntheticSections.cpp
+++ lld/ELF/SyntheticSections.cpp
@@ -2155,7 +2155,7 @@
// 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)});
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D118577.404417.patch
Type: text/x-patch
Size: 1172 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220131/35228511/attachment.bin>
More information about the llvm-commits
mailing list