diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -652,6 +652,12 @@ default: this->sections[i] = createInputSection(sec); } + } + + for (size_t i = 0, e = objSections.size(); i < e; i++) { + if (this->sections[i] == &InputSection::discarded) + continue; + const Elf_Shdr &sec = objSections[i]; // .ARM.exidx sections have a reverse dependency on the InputSection they // have a SHF_LINK_ORDER dependency, this is identified by the sh_link. diff --git a/lld/test/ELF/linkorder-forward-ref.test b/lld/test/ELF/linkorder-forward-ref.test new file mode 100644 --- /dev/null +++ b/lld/test/ELF/linkorder-forward-ref.test @@ -0,0 +1,24 @@ +# REQUIRES: x86 +# RUN: yaml2obj %s -o %t.o +# RUN: ld.lld %t.o -o %t +# RUN: llvm-readelf -S %t | FileCheck %s + +# Test that we accept forward sh_link references. + +# CHECK: .linkorder +# CHECK: .text + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .linkorder + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR, SHF_LINK_ORDER ] + Link: 2 + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ]