Index: include/llvm/Object/ELF.h =================================================================== --- include/llvm/Object/ELF.h +++ include/llvm/Object/ELF.h @@ -466,7 +466,6 @@ if (!Index) // no section string table. return ""; - // TODO: Test a case when the sh_link of the section with index 0 is broken. if (Index >= Sections.size()) return createError("section header string table index " + Twine(Index) + " does not exist"); Index: test/Object/invalid.test =================================================================== --- test/Object/invalid.test +++ test/Object/invalid.test @@ -627,3 +627,23 @@ Content: "" Symbols: - Name: foo + +## Check the case when e_shstrndx == SHN_XINDEX, but sh_link in the section header at index 0 +## contains index of section header string table that is larger than number of the sections. + +# RUN: yaml2obj --docnum=30 %s -o %t30 +# RUN: not llvm-objcopy %t30 2>&1 | FileCheck %s -DFILE=%t30 --check-prefix=INVALID-SHSTRTAB-INDEX + +# INVALID-SHSTRTAB-INDEX: error: section header string table index 255 does not exist + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 +## SHN_XINDEX == 0xffff. + SHStrNdx: 0xffff +Sections: + - Type: SHT_NULL + Link: 0xff