Index: test/tools/llvm-readobj/elf-invalid-sechdr-strtab-index.test =================================================================== --- /dev/null +++ test/tools/llvm-readobj/elf-invalid-sechdr-strtab-index.test @@ -0,0 +1,46 @@ +## Check the case when e_shstrndx contains an invalid section header table index. + +# RUN: yaml2obj --docnum=1 %s -o %t1 +# RUN: not llvm-readelf --headers -S 2>&1 %t1 | FileCheck %s -DFILE=%t1 --check-prefixes=GNU,GNU-SHSTRNDX +# RUN: not llvm-readobj --headers -S 2>&1 %t1 | FileCheck %s -DFILE=%t1 --check-prefixes=LLVM,LLVM-SHSTRNDX + +# GNU: ELF Header: +# GNU-SHSTRNDX: Section header string table index: 255 +# GNU-LINK: Section header string table index: 65535 (255) +# GNU-NEXT: There are 4 section headers, starting at offset 0x40: +# GNU: Section Headers: +# GNU-NEXT: [Nr] Name +# GNU-EMPTY: +# GNU-NEXT: error: '[[FILE]]': section header string table index 255 does not exist + +# LLVM: ElfHeader { +# LLVM-SHSTRNDX: StringTableSectionIndex: 255 +# LLVM-LINK: StringTableSectionIndex: 65535 (255) +# LLVM-NEXT: } +# LLVM-NEXT: Sections [ +# LLVM-EMPTY: +# LLVM-NEXT: error: '[[FILE]]': section header string table index 255 does not exist + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 + SHStrNdx: 0xFF + +# RUN: yaml2obj --docnum=2 %s -o %t2 +# RUN: not llvm-readelf --headers -S 2>&1 %t2 | FileCheck %s -DFILE=%t2 --check-prefixes=GNU,GNU-LINK +# RUN: not llvm-readobj --headers -S 2>&1 %t2 | FileCheck %s -DFILE=%t2 --check-prefixes=LLVM,LLVM-LINK + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 +## SHN_XINDEX == 0xffff. + SHStrNdx: 0xffff +Sections: + - Type: SHT_NULL + Link: 0xff Index: test/tools/llvm-readobj/elf-invalid-shstrndx.test =================================================================== --- test/tools/llvm-readobj/elf-invalid-shstrndx.test +++ /dev/null @@ -1,26 +0,0 @@ -# RUN: yaml2obj %s -o %t -# RUN: not llvm-readelf --headers -S 2>&1 %t | FileCheck %s -DFILE=%t --check-prefix=GNU -# RUN: not llvm-readobj --headers -S 2>&1 %t | FileCheck %s -DFILE=%t --check-prefix=LLVM - -# GNU: ELF Header: -# GNU: Section header string table index: 255 -# GNU-NEXT: There are 4 section headers, starting at offset 0x40: -# GNU: Section Headers: -# GNU-NEXT: [Nr] Name -# GNU-EMPTY: -# GNU-NEXT: error: '[[FILE]]': section header string table index 255 does not exist - -# LLVM: ElfHeader { -# LLVM: StringTableSectionIndex: 255 -# LLVM-NEXT: } -# LLVM-NEXT: Sections [ -# LLVM-EMPTY: -# LLVM-NEXT: error: '[[FILE]]': section header string table index 255 does not exist - ---- !ELF -FileHeader: - Class: ELFCLASS64 - Data: ELFDATA2LSB - Type: ET_REL - Machine: EM_X86_64 - SHStrNdx: 0xFF Index: tools/llvm-readobj/ELFDumper.cpp =================================================================== --- tools/llvm-readobj/ELFDumper.cpp +++ tools/llvm-readobj/ELFDumper.cpp @@ -3015,7 +3015,6 @@ Index = Sections[0].sh_link; 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()) reportError(ElfObj.getFileName(), createError("section header string table index " +