diff options
| -rw-r--r-- | lld/ELF/InputFiles.cpp | 6 | ||||
| -rw-r--r-- | lld/test/ELF/invalid/linkorder-invalid-sec2.test | 16 |
2 files changed, 20 insertions, 2 deletions
diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp index 5610498432c..e3036428de5 100644 --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -478,11 +478,13 @@ void ObjFile<ELFT>::initializeSections( // .ARM.exidx sections have a reverse dependency on the InputSection they // have a SHF_LINK_ORDER dependency, this is identified by the sh_link. if (Sec.sh_flags & SHF_LINK_ORDER) { - if (Sec.sh_link >= this->Sections.size()) + InputSectionBase *LinkSec = nullptr; + if (Sec.sh_link < this->Sections.size()) + LinkSec = this->Sections[Sec.sh_link]; + if (!LinkSec) fatal(toString(this) + ": invalid sh_link index: " + Twine(Sec.sh_link)); - InputSectionBase *LinkSec = this->Sections[Sec.sh_link]; InputSection *IS = cast<InputSection>(this->Sections[I]); LinkSec->DependentSections.push_back(IS); if (!isa<InputSection>(LinkSec)) diff --git a/lld/test/ELF/invalid/linkorder-invalid-sec2.test b/lld/test/ELF/invalid/linkorder-invalid-sec2.test new file mode 100644 index 00000000000..f78df3fb089 --- /dev/null +++ b/lld/test/ELF/invalid/linkorder-invalid-sec2.test @@ -0,0 +1,16 @@ +# REQUIRES: x86 +# RUN: yaml2obj %s -o %t.o +# RUN: not ld.lld %t.o -o /dev/null 2>&1 | FileCheck %s +# CHECK: invalid sh_link index: 0 + +--- !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: 0 |

