Skip to content

Commit

Permalink
Don't populate the symbol table with symbols that don't belong to a s…
Browse files Browse the repository at this point in the history
…ection with the flag SHF_ALLOC

When populating the symbol table for an ELF object file, don't insert any symbols that come from ELF sections which don't have runtime allocated memory (typically debugging symbols).

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D133795
  • Loading branch information
George Wright authored and dwblaikie committed Sep 13, 2022
1 parent 7886505 commit 13f1bc4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
5 changes: 5 additions & 0 deletions llvm/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ Error SymbolizableObjectFile::addSymbol(const SymbolRef &Symbol,
return SymbolTypeOrErr.takeError();
SymbolRef::Type SymbolType = *SymbolTypeOrErr;
if (Obj.isELF()) {
// Ignore any symbols coming from sections that don't have runtime
// allocated memory.
if ((elf_section_iterator(*Sec)->getFlags() & ELF::SHF_ALLOC) == 0)
return Error::success();

// Allow function and data symbols. Additionally allow STT_NONE, which are
// common for functions defined in assembly.
uint8_t Type = ELFSymbolRef(Symbol).getELFType();
Expand Down
36 changes: 36 additions & 0 deletions llvm/test/DebugInfo/Symbolize/ELF/symtab-file2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,39 @@ Symbols:
Index: SHN_ABS
- Name: local
Section: .text

# RUN: yaml2obj --docnum=3 %s -o %t3
# RUN: llvm-symbolizer --obj=%t3 'DATA 0x1001' 2>&1 | FileCheck %s --check-prefix=CHECK3

# CHECK3: code
# CHECK3-NEXT: 4096 2
# CHECK3-NEXT: ??:?
# CHECK3-EMPTY:

--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_X86_64
Sections:
- Name: .text
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
Address: 0x1000
Size: 1
- Name: .debug
Type: SHT_PROGBITS
Address: 0x0000
Size: 0xFFFF
Symbols:
- Name: debug
Section: .debug
Binding: STB_WEAK
Value: 0x1001
Size: 0
- Name: code
Section: .text
Binding: STB_WEAK
Value: 0x1000
Size: 2

0 comments on commit 13f1bc4

Please sign in to comment.