Index: lld/ELF/Writer.cpp =================================================================== --- lld/ELF/Writer.cpp +++ lld/ELF/Writer.cpp @@ -1229,6 +1229,9 @@ return A->kind() != InputSectionBase::Synthetic; InputSection *LA = A->getLinkOrderDep(); InputSection *LB = B->getLinkOrderDep(); + // Non-SHF_LINK_ORDER sections go last. + if (!LA || !LB) + return LA; OutputSection *AOut = LA->getParent(); OutputSection *BOut = LB->getParent(); if (AOut != BOut) Index: lld/test/ELF/link-order-mixed.s =================================================================== --- /dev/null +++ lld/test/ELF/link-order-mixed.s @@ -0,0 +1,13 @@ +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: ld.lld %t.o -o %t +# RUN: llvm-nm %t | FileCheck %s + +# CHECK: 0000000000201004 N _start +.globl _start +_start: +.byte 1 + +# CHECK: 0000000000201000 n sec2 +.section .text,"ao",@progbits,_start,unique,1 +sec2: +.byte 2