Index: ELF/Writer.cpp =================================================================== --- ELF/Writer.cpp +++ ELF/Writer.cpp @@ -1351,6 +1351,13 @@ for (BaseCommand *Base : Sec->SectionCommands) if (auto *ISD = dyn_cast(Base)) llvm::erase_if(ISD->Sections, [](InputSection *IS) { return !IS; }); + + // In theory, there should not make sense to have this flag in the + // non-relocatable output because the flag is used by linker only. + // Binutils strip tool reports a warning when sh_link is not set for + // SHT_ARM_EXIDX though. So we have to keep it to workaround warning. + if (!Config->Relocatable && Sec->Type != SHT_ARM_EXIDX) + Sec->Flags &= ~SHF_LINK_ORDER; } } Index: test/ELF/link-order-flag.s =================================================================== --- test/ELF/link-order-flag.s +++ test/ELF/link-order-flag.s @@ -0,0 +1,31 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o + +## Check we keep SHF_LINK_ORDER flag for -r +# RUN: ld.lld -r %t.o -o %t +# RUN: llvm-readobj -s %t | FileCheck %s --check-prefix=NODROP +# NODROP: Section { +# NODROP: Index: +# NODROP: Name: .bar +# NODROP-NEXT: Type: SHT_PROGBITS +# NODROP-NEXT: Flags [ +# NODROP-NEXT: SHF_ALLOC +# NODROP-NEXT: SHF_LINK_ORDER +# NODROP-NEXT: ] + +## Check we drop SHF_LINK_ORDER flag for regular output. +# RUN: ld.lld %t.o -o %t +# RUN: llvm-readobj -s %t | FileCheck %s --check-prefix=DROP +# DROP: Section { +# DROP: Index: +# DROP: Name: .bar +# DROP-NEXT: Type: SHT_PROGBITS +# DROP-NEXT: Flags [ +# DROP-NEXT: SHF_ALLOC +# DROP-NEXT: ] + +.section .foo,"a" +.quad 0 + +.section .bar,"ao",@progbits,.foo +.quad 0