[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:18:27 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rLLD333054: ELF: Do not ICF sections named with a C identifier. (authored by pcc, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D47242?vs=148146&id=148147#toc

Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D47242

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


Index: test/ELF/icf-c-identifier.s
===================================================================
--- test/ELF/icf-c-identifier.s
+++ test/ELF/icf-c-identifier.s
@@ -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
Index: test/ELF/icf-different-output-sections.s
===================================================================
--- test/ELF/icf-different-output-sections.s
+++ 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: ELF/ICF.cpp
===================================================================
--- ELF/ICF.cpp
+++ 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.148147.patch
Type: text/x-patch
Size: 1377 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180523/3f444ca2/attachment.bin>


More information about the llvm-commits mailing list