Index: ELF/ICF.cpp =================================================================== --- ELF/ICF.cpp +++ ELF/ICF.cpp @@ -429,14 +429,19 @@ } }); - // Mark ARM Exception Index table sections that refer to folded code + // Mark SHF_LINK_ORDER sections that refer to folded code // sections as not live. These sections have an implict dependency // via the link order dependency. - if (Config->EMachine == EM_ARM) - for (InputSectionBase *Sec : InputSections) - if (auto *S = dyn_cast(Sec)) - if (S->Flags & SHF_LINK_ORDER) - S->Live = S->getLinkOrderDep()->Live; + for (InputSectionBase *Sec : InputSections) { + auto *S = dyn_cast(Sec); + if (!S || !S->Live) + continue; + InputSection *Dep = S->getLinkOrderDep(); + if (Dep && !Dep->Live) { + log(" removed " + S->Name); + S->Live = false; + } + } } // ICF entry point function. Index: test/ELF/icf-link-order.s =================================================================== --- test/ELF/icf-link-order.s +++ test/ELF/icf-link-order.s @@ -0,0 +1,16 @@ +# 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: selected .text.foo +# CHECK: removed .text.bar +# CHECK: removed .order_bar + +.section .text.foo, "ax" +nop + +.section .text.bar, "ax" +nop + +.section .order_foo,"ao",@progbits,.text.foo + +.section .order_bar,"ao",@progbits,.text.bar