Skip to content

Commit 1fa3a6d

Browse files
authored
Don't include undefined symbols in symbol index (benfred#629)
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.
1 parent 593d6d8 commit 1fa3a6d

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/binary_parser.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ pub fn parse_binary(filename: &Path, addr: u64, size: u64) -> Result<BinaryInfo,
185185
}
186186

187187
for sym in elf.syms.iter() {
188+
// Skip undefined symbols.
189+
if sym.st_shndx == goblin::elf::section_header::SHN_UNDEF as usize {
190+
continue;
191+
}
188192
// Skip imported symbols
189193
if sym.is_import()
190194
|| (bss_end != 0
@@ -203,6 +207,10 @@ pub fn parse_binary(filename: &Path, addr: u64, size: u64) -> Result<BinaryInfo,
203207
}
204208
}
205209
for dynsym in elf.dynsyms.iter() {
210+
// Skip undefined symbols.
211+
if dynsym.st_shndx == goblin::elf::section_header::SHN_UNDEF as usize {
212+
continue;
213+
}
206214
// Skip imported symbols
207215
if dynsym.is_import()
208216
|| (bss_end != 0

0 commit comments

Comments
 (0)