Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/elf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down Expand Up @@ -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;
}

Expand Down
32 changes: 32 additions & 0 deletions tests/elf/unnamed_symbol.test
Original file line number Diff line number Diff line change
@@ -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