[PATCH] D47242: ELF: Do not ICF sections named with a C identifier.

Peter Collingbourne via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 22 19:09:36 PDT 2018


pcc created this revision.
pcc added a reviewer: ruiu.
Herald added subscribers: arichardson, emaste.
Herald added a reviewer: espindola.

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.


https://reviews.llvm.org/D47242

Files:
  lld/ELF/ICF.cpp
  lld/test/ELF/icf-c-identifier.s
  lld/test/ELF/icf-different-output-sections.s


Index: lld/test/ELF/icf-different-output-sections.s
===================================================================
--- lld/test/ELF/icf-different-output-sections.s
+++ lld/test/ELF/icf-different-output-sections.s
@@ -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
Index: lld/test/ELF/icf-c-identifier.s
===================================================================
--- lld/test/ELF/icf-c-identifier.s
+++ lld/test/ELF/icf-c-identifier.s
@@ -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", at progbits,unique,0
 .byte 42
 
-.section bar,"ax"
+.section foo,"ax", at progbits,unique,1
 .byte 42
Index: lld/ELF/ICF.cpp
===================================================================
--- lld/ELF/ICF.cpp
+++ lld/ELF/ICF.cpp
@@ -188,6 +188,12 @@
   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;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47242.148146.patch
Type: text/x-patch
Size: 1434 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180523/1e522fb3/attachment.bin>


More information about the llvm-commits mailing list