Index: lld/ELF/ICF.cpp =================================================================== --- lld/ELF/ICF.cpp +++ lld/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: lld/test/ELF/icf-c-identifier.s =================================================================== --- lld/test/ELF/icf-c-identifier.s +++ lld/test/ELF/icf-c-identifier.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",@progbits,unique,0 .byte 42 -.section bar,"ax" +.section foo,"ax",@progbits,unique,1 .byte 42 Index: lld/test/ELF/icf-different-output-sections.s =================================================================== --- lld/test/ELF/icf-different-output-sections.s +++ lld/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