[lld] r333040 - ELF: Allow ICF on .data.rel.ro sections.

Peter Collingbourne via llvm-commits llvm-commits at lists.llvm.org
Tue May 22 16:22:35 PDT 2018


Author: pcc
Date: Tue May 22 16:22:35 2018
New Revision: 333040

URL: http://llvm.org/viewvc/llvm-project?rev=333040&view=rev
Log:
ELF: Allow ICF on .data.rel.ro sections.

Differential Revision: https://reviews.llvm.org/D47234

Added:
    lld/trunk/test/ELF/icf-relro.s
Modified:
    lld/trunk/ELF/ICF.cpp

Modified: lld/trunk/ELF/ICF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/ICF.cpp?rev=333040&r1=333039&r2=333040&view=diff
==============================================================================
--- lld/trunk/ELF/ICF.cpp (original)
+++ lld/trunk/ELF/ICF.cpp Tue May 22 16:22:35 2018
@@ -162,8 +162,13 @@ template <class ELFT> static uint32_t ge
 
 // 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))
+  if (!S->Live || S->KeepUnique || !(S->Flags & SHF_ALLOC))
+    return false;
+
+  // Don't merge writable sections. .data.rel.ro sections are marked as writable
+  // but are semantically read-only.
+  if ((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

Added: lld/trunk/test/ELF/icf-relro.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/icf-relro.s?rev=333040&view=auto
==============================================================================
--- lld/trunk/test/ELF/icf-relro.s (added)
+++ lld/trunk/test/ELF/icf-relro.s Tue May 22 16:22:35 2018
@@ -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




More information about the llvm-commits mailing list