Index: lld/trunk/ELF/ICF.cpp =================================================================== --- lld/trunk/ELF/ICF.cpp +++ lld/trunk/ELF/ICF.cpp @@ -172,6 +172,11 @@ !S->Name.startswith(".data.rel.ro.")) return false; + // SHF_LINK_ORDER sections are ICF'd as a unit with their dependent sections, + // so we don't consider them for ICF individually. + if (S->Flags & SHF_LINK_ORDER) + return false; + // Don't merge synthetic sections as their Data member is not valid and empty. // The Data member needs to be valid for ICF as it is used by ICF to determine // the equality of section contents. Index: lld/trunk/test/ELF/icf-link-order.s =================================================================== --- lld/trunk/test/ELF/icf-link-order.s +++ lld/trunk/test/ELF/icf-link-order.s @@ -0,0 +1,18 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: ld.lld %t.o -o %t --icf=all --print-icf-sections | count 0 + +.section .foo,"a",@progbits,unique,1 +foo1: +.byte 1 + +.section .foo,"a",@progbits,unique,2 +foo2: +.byte 2 + +.section .bar,"ao",@progbits,foo1,unique,1 +.byte 3 + +.section .bar,"ao",@progbits,foo2,unique,2 +.byte 3