[PATCH] D118577: [ELF] Deduplicate names of local symbols only with -O2
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 31 14:43:00 PST 2022
MaskRay updated this revision to Diff 404738.
MaskRay added a comment.
add a release note
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D118577/new/
https://reviews.llvm.org/D118577
Files:
lld/ELF/SyntheticSections.cpp
lld/docs/ReleaseNotes.rst
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/docs/ReleaseNotes.rst
===================================================================
--- lld/docs/ReleaseNotes.rst
+++ lld/docs/ReleaseNotes.rst
@@ -33,6 +33,9 @@
(`D110014 <https://reviews.llvm.org/D110014>`_)
* If ``-Map`` is specified, ``--cref`` will be printed to the specified file.
(`D114663 <https://reviews.llvm.org/D114663>`_)
+* No longer deduplicate local symbol names at the default optimization level of ``-O1``.
+ This results in a larger ``.strtab`` (usually less than 1%) but a faster link
+ time. Use optimization level ``-O2`` to restore the deduplication.
Architecture specific changes:
Index: lld/ELF/SyntheticSections.cpp
===================================================================
--- lld/ELF/SyntheticSections.cpp
+++ lld/ELF/SyntheticSections.cpp
@@ -1230,7 +1230,8 @@
: 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 @@
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 @@
// 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.404738.patch
Type: text/x-patch
Size: 2337 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220131/6828becb/attachment.bin>
More information about the llvm-commits
mailing list