Index: lld/ELF/ICF.cpp =================================================================== --- lld/ELF/ICF.cpp +++ lld/ELF/ICF.cpp @@ -163,8 +163,8 @@ // .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_WRITE) && - S->Name != ".init" && S->Name != ".fini"; + return S->Live && (S->Flags & SHF_ALLOC) && (S->Flags & SHF_EXECINSTR) && + !(S->Flags & SHF_WRITE) && S->Name != ".init" && S->Name != ".fini"; } // Split an equivalence class into smaller classes. Index: lld/test/ELF/icf8.s =================================================================== --- /dev/null +++ lld/test/ELF/icf8.s @@ -0,0 +1,23 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t +# RUN: ld.lld %t -o %t2 --icf=all --verbose | FileCheck %s + +# CHECK-NOT: selected .text.f1 +# CHECK-NOT: selected .text.f2 + +.globl _start, f1, f2 +_start: + ret + +.section .text.f1, "a" +f1: + mov $60, %rax + mov $42, %rdi + syscall + +.section .text.f2, "a" +f2: + mov $60, %rax + mov $42, %rdi + syscall