[PATCH] D47234: ELF: Allow ICF on .data.rel.ro sections.

Peter Collingbourne via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 22 15:55:00 PDT 2018


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

https://reviews.llvm.org/D47234

Files:
  lld/ELF/ICF.cpp
  lld/test/ELF/icf-relro.s


Index: lld/test/ELF/icf-relro.s
===================================================================
--- /dev/null
+++ lld/test/ELF/icf-relro.s
@@ -0,0 +1,12 @@
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
+# RUN: ld.lld %t -o %t2 --icf=all --ignore-data-address-equality --print-icf-sections | FileCheck %s
+
+# CHECK: selected section {{.*}}:(.data.rel.ro)
+# CHECK:   removing identical section {{.*}}:(.data.rel.ro.foo)
+
+.section .data.rel.ro,"aw"
+.quad foo
+
+.section .data.rel.ro.foo,"aw"
+foo:
+.quad foo
Index: lld/ELF/ICF.cpp
===================================================================
--- lld/ELF/ICF.cpp
+++ lld/ELF/ICF.cpp
@@ -163,7 +163,8 @@
 // Returns true if section S is subject of ICF.
 static bool isEligible(InputSection *S) {
   if (!S->Live || S->KeepUnique || !(S->Flags & SHF_ALLOC) ||
-      (S->Flags & SHF_WRITE))
+      ((S->Flags & SHF_WRITE) && S->Name != ".data.rel.ro" &&
+       !S->Name.startswith(".data.rel.ro.")))
     return false;
 
   // Don't merge read only data sections unless


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47234.148120.patch
Type: text/x-patch
Size: 1055 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180522/ec5c4a92/attachment.bin>


More information about the llvm-commits mailing list