[Object][ELF] Handle files with no section header string table.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@242839 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Michael J. Spencer 2015-07-21 21:40:33 +00:00
parent 68a4b41648
commit 3f6881efa5
3 changed files with 23 additions and 7 deletions

View File

@ -629,14 +629,18 @@ ELFFile<ELFT>::ELFFile(StringRef Object, std::error_code &EC)
}
// Get string table sections.
ErrorOr<const Elf_Shdr *> StrTabSecOrErr = getSection(getStringTableIndex());
if ((EC = StrTabSecOrErr.getError()))
return;
uintX_t StringTableIndex = getStringTableIndex();
if (StringTableIndex) {
ErrorOr<const Elf_Shdr *> StrTabSecOrErr =
getSection(getStringTableIndex());
if ((EC = StrTabSecOrErr.getError()))
return;
ErrorOr<StringRef> SymtabOrErr = getStringTable(*StrTabSecOrErr);
if ((EC = SymtabOrErr.getError()))
return;
DotShstrtab = *SymtabOrErr;
ErrorOr<StringRef> SymtabOrErr = getStringTable(*StrTabSecOrErr);
if ((EC = SymtabOrErr.getError()))
return;
DotShstrtab = *SymtabOrErr;
}
// Build symbol name side-mapping if there is one.
if (SymbolTableSectionHeaderIndex) {
@ -746,6 +750,8 @@ template <class ELFT>
ErrorOr<StringRef>
ELFFile<ELFT>::getSectionName(const Elf_Shdr *Section) const {
uint32_t Offset = Section->sh_name;
if (Offset == 0)
return StringRef();
if (Offset >= DotShstrtab.size())
return object_error::parse_failed;
return StringRef(DotShstrtab.data() + Offset);

View File

@ -0,0 +1,10 @@
RUN: llvm-readobj %p/Inputs/no-section-header-string-table.elf-x86-64 --sections \
RUN: | FileCheck %s
CHECK: Type: SHT_PROGBITS (0x1)
CHECK: Type: SHT_PROGBITS (0x1)
CHECK: Type: SHT_PROGBITS (0x1)
CHECK: Type: SHT_RELA (0x4)
CHECK: Type: SHT_SYMTAB (0x2)
CHECK: Type: SHT_STRTAB (0x3)
CHECK: Type: SHT_STRTAB (0x3)