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 @@ -606,3 +606,23 @@ Type: ET_REL Machine: EM_X86_64 SHOffset: 0xffffffffffffffff + +## Check the case when e_shstrndx == SHN_XINDEX, but null section's sh_link contains +## index of section header string table that is larger than number of the sections. + +# RUN: yaml2obj --docnum=29 %s -o %t29 +# RUN: not llvm-objcopy %t29 2>&1 | FileCheck %s -DFILE=%t29 --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