diff --git a/src/elf.cc b/src/elf.cc index 5acfc8c..c6ebab2 100644 --- a/src/elf.cc +++ b/src/elf.cc @@ -377,7 +377,7 @@ string_view ElfFile::Section::GetName() const { string_view ElfFile::Section::ReadString(Elf64_Word index) const { assert(header().sh_type == SHT_STRTAB); - if (index == SHN_UNDEF || index >= contents_.size()) { + if (index >= contents_.size()) { THROWF("can't read index $0 from strtab, total size is $1", index, contents_.size()); } @@ -972,8 +972,7 @@ static void ReadELFSymbolTableEntries(const ElfFile& elf, section.ReadSymbol(i, &sym, &sym_range); if (ELF64_ST_TYPE(sym.st_info) == STT_SECTION || - sym.st_shndx == STN_UNDEF || - sym.st_name == SHN_UNDEF) { + sym.st_shndx == STN_UNDEF) { continue; } diff --git a/tests/elf/unnamed_symbol.test b/tests/elf/unnamed_symbol.test new file mode 100644 index 0000000..1f7fa35 --- /dev/null +++ b/tests/elf/unnamed_symbol.test @@ -0,0 +1,32 @@ +# Test that bloaty handles symbols with no name (st_name == 0) by creating a +# synthetic name. + +# RUN: %yaml2obj %s -o %t.obj +# RUN: %bloaty %t.obj -d symbols | %FileCheck %s + +# CHECK: named_symbol +# CHECK: [Anonymous symbol #1] + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x10 + Content: '9090909090909090909090909090909090909090909090909090909090909090' +Symbols: + - StName: 0 + Type: STT_FUNC + Section: .text + Value: 0x0 + Size: 0x10 + - Name: named_symbol + Type: STT_FUNC + Section: .text + Value: 0x10 + Size: 0x10