Skip to content

Commit

Permalink
Don't include undefined symbols in symbol index (benfred#629)
Browse files Browse the repository at this point in the history
Don't count undefined symbols in the index of symbols that py-spy builds.
This can causes 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 authored Nov 1, 2024
1 parent 593d6d8 commit 1fa3a6d
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 @@ -185,6 +185,10 @@ pub fn parse_binary(filename: &Path, addr: u64, size: u64) -> Result<BinaryInfo,
}

for sym in elf.syms.iter() {
// Skip undefined symbols.
if sym.st_shndx == goblin::elf::section_header::SHN_UNDEF as usize {
continue;
}
// Skip imported symbols
if sym.is_import()
|| (bss_end != 0
Expand All @@ -203,6 +207,10 @@ pub fn parse_binary(filename: &Path, addr: u64, size: u64) -> Result<BinaryInfo,
}
}
for dynsym in elf.dynsyms.iter() {
// Skip undefined symbols.
if dynsym.st_shndx == goblin::elf::section_header::SHN_UNDEF as usize {
continue;
}
// Skip imported symbols
if dynsym.is_import()
|| (bss_end != 0
Expand Down

0 comments on commit 1fa3a6d

Please sign in to comment.