Index: ELF/ICF.cpp =================================================================== --- ELF/ICF.cpp +++ ELF/ICF.cpp @@ -188,6 +188,12 @@ if (S->Name == ".init" || S->Name == ".fini") return false; + // A user program may enumerate sections named with a C identifier using + // __start_* and __stop_* symbols. We cannot ICF any such sections because + // that could change program semantics. + if (isValidCIdentifier(S->Name)) + return false; + return true; } Index: test/ELF/icf-c-identifier.s =================================================================== --- test/ELF/icf-c-identifier.s +++ test/ELF/icf-c-identifier.s @@ -0,0 +1,9 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t +# RUN: ld.lld %t -o %t2 --icf=all --print-icf-sections | count 0 + +.section foo,"ax",@progbits,unique,0 +.byte 42 + +.section foo,"ax",@progbits,unique,1 +.byte 42 Index: test/ELF/icf-different-output-sections.s =================================================================== --- test/ELF/icf-different-output-sections.s +++ test/ELF/icf-different-output-sections.s @@ -2,8 +2,8 @@ # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t # RUN: ld.lld %t -o %t2 --icf=all --print-icf-sections | count 0 -.section foo,"ax" +.section .foo,"ax" .byte 42 -.section bar,"ax" +.section .bar,"ax" .byte 42