}
// 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) {
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);
--- /dev/null
+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)