Skip to content

Commit

Permalink
Don't include undef sym refs when building map of symbol definitions
Browse files Browse the repository at this point in the history
Previously, we'd count undefined symbols references in the map of
symbols defined in a binary, which could cause e.g. py-spy to
misattribute an undefined ref to `_PyRuntime` in some location
other than libpython.so as the definition.
  • Loading branch information
andrewjcg committed Nov 9, 2023
1 parent 5102f8e commit 98cbcd3
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/binary_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,18 @@ pub fn parse_binary(filename: &Path, addr: u64, size: u64) -> Result<BinaryInfo,
let offset = offset.saturating_sub(program_header.p_vaddr);

for sym in elf.syms.iter() {
// Only count defined symbols.
if sym.st_shndx == goblin::elf::section_header::SHN_UNDEF as usize {
continue;
}
let name = elf.strtab[sym.st_name].to_string();
symbols.insert(name, sym.st_value + offset);
}
for dynsym in elf.dynsyms.iter() {
// Only count defined symbols.
if dynsym.st_shndx == goblin::elf::section_header::SHN_UNDEF as usize {
continue;
}
let name = elf.dynstrtab[dynsym.st_name].to_string();
symbols.insert(name, dynsym.st_value + offset);
}
Expand Down

0 comments on commit 98cbcd3

Please sign in to comment.