Index: include/llvm/Object/ELF.h =================================================================== --- include/llvm/Object/ELF.h +++ include/llvm/Object/ELF.h @@ -327,7 +327,7 @@ if (Index == ELF::SHN_XINDEX) Index = Sections[0].sh_link; - if (!Index) // no section string table. + if (Index == ELF::SHN_UNDEF) // no section string table. return ""; if (Index >= Sections.size()) return createError("invalid section index"); @@ -491,6 +491,8 @@ auto Table = getSectionStringTable(*SectionsOrErr); if (!Table) return Table.takeError(); + if (Table->empty()) + return ""; return getSectionName(Section, *Table); } Index: test/Object/elf-no-section-header-table.test =================================================================== --- test/Object/elf-no-section-header-table.test +++ test/Object/elf-no-section-header-table.test @@ -0,0 +1,8 @@ +## elf-no-section-header-table.elf-x86-64 is a simple ELF with e_shstrndx filed set +## to SHN_UNDEF, what means file has no section name string table. +# RUN: llvm-objdump -section-headers \ +# RUN: %p/Inputs/elf-no-section-header-table.elf-x86-64 2>&1 | FileCheck %s + +# CHECK: Sections: +# CHECK-NEXT: Idx Name Size Address Type +# CHECK-NEXT: 0 00000000 0000000000000000