[lld] r333054 - ELF: Do not ICF sections named with a C identifier.
Peter Collingbourne via llvm-commits
llvm-commits at lists.llvm.org
Tue May 22 19:14:28 PDT 2018
Author: pcc
Date: Tue May 22 19:14:28 2018
New Revision: 333054
URL: http://llvm.org/viewvc/llvm-project?rev=333054&view=rev
Log:
ELF: Do not ICF sections named with a C identifier.
A user program may enumerate sections named with a C identifier using
__start_* and __stop_* symbols. We cannot ICF any such sections because
that could change program semantics.
Differential Revision: https://reviews.llvm.org/D47242
Added:
lld/trunk/test/ELF/icf-c-identifier.s
Modified:
lld/trunk/ELF/ICF.cpp
lld/trunk/test/ELF/icf-different-output-sections.s
Modified: lld/trunk/ELF/ICF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/ICF.cpp?rev=333054&r1=333053&r2=333054&view=diff
==============================================================================
--- lld/trunk/ELF/ICF.cpp (original)
+++ lld/trunk/ELF/ICF.cpp Tue May 22 19:14:28 2018
@@ -188,6 +188,12 @@ static bool isEligible(InputSection *S)
if (S->Name == ".init" || S->Name == ".fini")
return false;
+ // A user program may enumerate sections named with a C identifier using
+ // __start_* and __stop_* symbols. We cannot ICF any such sections because
+ // that could change program semantics.
+ if (isValidCIdentifier(S->Name))
+ return false;
+
return true;
}
Added: lld/trunk/test/ELF/icf-c-identifier.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/icf-c-identifier.s?rev=333054&view=auto
==============================================================================
--- lld/trunk/test/ELF/icf-c-identifier.s (added)
+++ lld/trunk/test/ELF/icf-c-identifier.s Tue May 22 19:14:28 2018
@@ -0,0 +1,9 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
+# RUN: ld.lld %t -o %t2 --icf=all --print-icf-sections | count 0
+
+.section foo,"ax", at progbits,unique,0
+.byte 42
+
+.section foo,"ax", at progbits,unique,1
+.byte 42
Modified: lld/trunk/test/ELF/icf-different-output-sections.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/icf-different-output-sections.s?rev=333054&r1=333053&r2=333054&view=diff
==============================================================================
--- lld/trunk/test/ELF/icf-different-output-sections.s (original)
+++ lld/trunk/test/ELF/icf-different-output-sections.s Tue May 22 19:14:28 2018
@@ -2,8 +2,8 @@
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
# RUN: ld.lld %t -o %t2 --icf=all --print-icf-sections | count 0
-.section foo,"ax"
+.section .foo,"ax"
.byte 42
-.section bar,"ax"
+.section .bar,"ax"
.byte 42
More information about the llvm-commits
mailing list