Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Page-align offset before calculating virtual addresses for ELF #626

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let offset = offset - aligned_vaddr;
let offset = offset.saturating_sub(aligned_vaddr);


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