[PATCH] D41060: Add an option for ICFing data

Rafael Ávila de Espíndola via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 10 17:15:05 PST 2017


rafael created this revision.
Herald added a subscriber: emaste.

An internal linker has support for merging identical data and in some cases it can be a significant win.

This is behind an off by default flag so it has to be requested explicitly.


https://reviews.llvm.org/D41060

Files:
  ELF/Config.h
  ELF/Driver.cpp
  ELF/ICF.cpp
  ELF/Options.td
  test/ELF/icf9.s


Index: test/ELF/icf9.s
===================================================================
--- test/ELF/icf9.s
+++ test/ELF/icf9.s
@@ -10,14 +10,23 @@
 # CHECK-NOT: selected .rodata.d1
 # CHECK-NOT: selected .rodata.d2
 
+# We do merge rodata if passed --icf-data
+# RUN: ld.lld %t -o %t2 --icf=all --verbose --icf-data | FileCheck --check-prefix=DATA %s
+# RUN: llvm-readelf -S -W %t2 | FileCheck --check-prefix=DATA-SEC %s
+
+# DATA: selected .rodata.d1
+# DATA: removed .rodata.d2
+
+# DATA-SEC:  .rodata      PROGBITS  0000000000200120 000120 000001 00 A 0 0 1
+
 .globl _start, d1, d2
 _start:
   ret
 
-.section .rodata.f1, "a"
+.section .rodata.d1, "a"
 d1:
   .byte 1
 
-.section .rodata.f2, "a"
+.section .rodata.d2, "a"
 d2:
   .byte 1
Index: ELF/Options.td
===================================================================
--- ELF/Options.td
+++ ELF/Options.td
@@ -143,6 +143,8 @@
 
 def icf_all: F<"icf=all">, HelpText<"Enable identical code folding">;
 
+def icf_data: F<"icf-data">, HelpText<"Also fold identical data">;
+
 def icf_none: F<"icf=none">, HelpText<"Disable identical code folding">;
 
 defm image_base : Eq<"image-base">, HelpText<"Set the base address">;
Index: ELF/ICF.cpp
===================================================================
--- ELF/ICF.cpp
+++ ELF/ICF.cpp
@@ -161,11 +161,15 @@
 
 // Returns true if section S is subject of ICF.
 static bool isEligible(InputSection *S) {
+  // Don't merge read only data sections unless --icf-data was passed.
+  if (!(S->Flags & SHF_EXECINSTR) && !Config->ICFData)
+    return false;
+
   // .init and .fini contains instructions that must be executed to
   // initialize and finalize the process. They cannot and should not
   // be merged.
-  return S->Live && (S->Flags & SHF_ALLOC) && (S->Flags & SHF_EXECINSTR) &&
-         !(S->Flags & SHF_WRITE) && S->Name != ".init" && S->Name != ".fini";
+  return S->Live && (S->Flags & SHF_ALLOC) && !(S->Flags & SHF_WRITE) &&
+         S->Name != ".init" && S->Name != ".fini";
 }
 
 // Split an equivalence class into smaller classes.
Index: ELF/Driver.cpp
===================================================================
--- ELF/Driver.cpp
+++ ELF/Driver.cpp
@@ -618,6 +618,7 @@
   Config->GcSections = Args.hasFlag(OPT_gc_sections, OPT_no_gc_sections, false);
   Config->GdbIndex = Args.hasFlag(OPT_gdb_index, OPT_no_gdb_index, false);
   Config->ICF = Args.hasFlag(OPT_icf_all, OPT_icf_none, false);
+  Config->ICFData = Args.hasArg(OPT_icf_data);
   Config->Init = Args.getLastArgValue(OPT_init, "_init");
   Config->LTOAAPipeline = Args.getLastArgValue(OPT_lto_aa_pipeline);
   Config->LTONewPmPasses = Args.getLastArgValue(OPT_lto_newpm_passes);
Index: ELF/Config.h
===================================================================
--- ELF/Config.h
+++ ELF/Config.h
@@ -126,6 +126,7 @@
   bool HasDynamicList = false;
   bool HasDynSymTab;
   bool ICF;
+  bool ICFData;
   bool MipsN32Abi = false;
   bool NoGnuUnique;
   bool NoUndefinedVersion;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41060.126304.patch
Type: text/x-patch
Size: 2989 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171211/7646622f/attachment.bin>


More information about the llvm-commits mailing list