Skip to content

Commit

Permalink
[third-party/py-spy/0.3.14] Align virtual address base
Browse files Browse the repository at this point in the history
Summary:
This fixes a bug where we were calculating incorrect address offsets.

This tool now works on our Python binaries.

Test Plan:
```
$  buck2 run fbsource//third-party/py-spy/0.3.14:py-spy -- dump -p 1245593
```

Reviewers: bmaurer, itamaro, lisroach

Reviewed By: bmaurer

Subscribers: mzlee

Differential Revision: https://phabricator.intern.facebook.com/D50649635
  • Loading branch information
andrewjcg committed Sep 3, 2024
1 parent 643d5c6 commit de2b90a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ log = "0.4"
lru = "0.10"
regex = ">=1.6.0"
tempfile = "3.6.0"
page_size = "0.6.0"
proc-maps = "0.3.2"
memmap2 = "0.9.4"
cpp_demangle = "0.4"
Expand Down
8 changes: 5 additions & 3 deletions src/binary_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,11 @@ pub fn parse_binary(filename: &Path, addr: u64) -> Result<BinaryInfo, Error> {
)
})?;

// p_vaddr may be larger than the map address in case when the header has an offset and
// the map address is relatively small. In this case we can default to 0.
let offset = offset.saturating_sub(program_header.p_vaddr);
// Align the virtual address offset, then subtract it from the offset
// to get real offset for symbol addresses in the file.
let aligned_vaddr =
program_header.p_vaddr - (program_header.p_vaddr % page_size::get() as u64);
let offset = offset - aligned_vaddr;

for sym in elf.syms.iter() {
let name = elf.strtab[sym.st_name].to_string();
Expand Down

0 comments on commit de2b90a

Please sign in to comment.