From ae704a54729d0a6e2c72b7fd7e364c33a7989f57 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Wed, 9 Aug 2017 21:32:38 +0000 Subject: [PATCH] Add --icf=none option. --icf=none negates --icf=all. llvm-svn: 310526 --- lld/ELF/Driver.cpp | 2 +- lld/ELF/Options.td | 4 +++- lld/test/ELF/icf-none.s | 22 ++++++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 lld/test/ELF/icf-none.s diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index a52693b05375..78b3ed90c303 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -637,7 +637,7 @@ void LinkerDriver::readConfigs(opt::InputArgList &Args) { Config->Fini = Args.getLastArgValue(OPT_fini, "_fini"); Config->GcSections = getArg(Args, OPT_gc_sections, OPT_no_gc_sections, false); Config->GdbIndex = Args.hasArg(OPT_gdb_index); - Config->ICF = Args.hasArg(OPT_icf); + Config->ICF = getArg(Args, OPT_icf_all, OPT_icf_none, false); Config->Init = Args.getLastArgValue(OPT_init, "_init"); Config->LTOAAPipeline = Args.getLastArgValue(OPT_lto_aa_pipeline); Config->LTONewPmPasses = Args.getLastArgValue(OPT_lto_newpm_passes); diff --git a/lld/ELF/Options.td b/lld/ELF/Options.td index 0de0d739fc2e..c047b75d11ab 100644 --- a/lld/ELF/Options.td +++ b/lld/ELF/Options.td @@ -139,7 +139,9 @@ defm hash_style: Eq<"hash-style">, def help: F<"help">, HelpText<"Print option help">; -def icf: F<"icf=all">, HelpText<"Enable identical code folding">; +def icf_all: F<"icf=all">, HelpText<"Enable identical code folding">; + +def icf_none: F<"icf=none">, HelpText<"Disable identical code folding">; defm image_base : Eq<"image-base">, HelpText<"Set the base address">; diff --git a/lld/test/ELF/icf-none.s b/lld/test/ELF/icf-none.s new file mode 100644 index 000000000000..671f2085f669 --- /dev/null +++ b/lld/test/ELF/icf-none.s @@ -0,0 +1,22 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t +# RUN: ld.lld %t -o %t2 --icf=all --icf=none --verbose | FileCheck %s + +# CHECK-NOT: selected .text.f1 + +.globl _start, f1, f2 +_start: + ret + +.section .text.f1, "ax" +f1: + mov $60, %rax + mov $42, %rdi + syscall + +.section .text.f2, "ax" +f2: + mov $60, %rax + mov $42, %rdi + syscall