Skip to content

Commit

Permalink
Align virtual address base
Browse files Browse the repository at this point in the history
This fixes a bug where we were calculating incorrect address offsets.
  • Loading branch information
andrewjcg committed Nov 1, 2024
1 parent 593d6d8 commit c317de7
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 @@ -31,6 +31,7 @@ lru = "0.10"
num-traits = "0.2"
regex = ">=1.6.0"
tempfile = "3.6.0"
page_size = "0.6.0"
proc-maps = "0.4.0"
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 @@ -150,9 +150,11 @@ pub fn parse_binary(filename: &Path, addr: u64, size: u64) -> Result<BinaryInfo,
)
})?;

// 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;

let mut bss_addr = 0;
let mut bss_size = 0;
Expand Down

0 comments on commit c317de7

Please sign in to comment.