[lld] r320448 - Add an option for ICFing data.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 11 17:36:25 PST 2017
Author: rafael
Date: Mon Dec 11 17:36:24 2017
New Revision: 320448
URL: http://llvm.org/viewvc/llvm-project?rev=320448&view=rev
Log:
Add an option for ICFing data.
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.
Modified:
lld/trunk/ELF/Config.h
lld/trunk/ELF/Driver.cpp
lld/trunk/ELF/ICF.cpp
lld/trunk/ELF/Options.td
lld/trunk/test/ELF/icf9.s
Modified: lld/trunk/ELF/Config.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Config.h?rev=320448&r1=320447&r2=320448&view=diff
==============================================================================
--- lld/trunk/ELF/Config.h (original)
+++ lld/trunk/ELF/Config.h Mon Dec 11 17:36:24 2017
@@ -126,6 +126,7 @@ struct Configuration {
bool HasDynamicList = false;
bool HasDynSymTab;
bool ICF;
+ bool ICFData;
bool MipsN32Abi = false;
bool NoGnuUnique;
bool NoUndefinedVersion;
Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=320448&r1=320447&r2=320448&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Mon Dec 11 17:36:24 2017
@@ -618,6 +618,7 @@ void LinkerDriver::readConfigs(opt::Inpu
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);
Modified: lld/trunk/ELF/ICF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/ICF.cpp?rev=320448&r1=320447&r2=320448&view=diff
==============================================================================
--- lld/trunk/ELF/ICF.cpp (original)
+++ lld/trunk/ELF/ICF.cpp Mon Dec 11 17:36:24 2017
@@ -161,11 +161,15 @@ template <class ELFT> static uint32_t ge
// 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.
Modified: lld/trunk/ELF/Options.td
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Options.td?rev=320448&r1=320447&r2=320448&view=diff
==============================================================================
--- lld/trunk/ELF/Options.td (original)
+++ lld/trunk/ELF/Options.td Mon Dec 11 17:36:24 2017
@@ -143,6 +143,9 @@ def help: F<"help">, HelpText<"Print opt
def icf_all: F<"icf=all">, HelpText<"Enable identical code folding">;
+def icf_data: F<"icf-data">,
+ HelpText<"Enable ICF to also fold identical read only data">;
+
def icf_none: F<"icf=none">, HelpText<"Disable identical code folding">;
defm image_base : Eq<"image-base">, HelpText<"Set the base address">;
Modified: lld/trunk/test/ELF/icf9.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/icf9.s?rev=320448&r1=320447&r2=320448&view=diff
==============================================================================
--- lld/trunk/test/ELF/icf9.s (original)
+++ lld/trunk/test/ELF/icf9.s Mon Dec 11 17:36:24 2017
@@ -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 2>&1 | 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
More information about the llvm-commits
mailing list