Skip to content

Commit 1f011ed

Browse files
committed
fix: adjust offset for symbols of module loaded at preferred base
1 parent d69ec6f commit 1f011ed

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

src/run/runner/wall_time/perf/perf_map.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,20 @@ impl ModuleSymbols {
5151
return Err(anyhow::anyhow!("No symbols found"));
5252
}
5353

54+
// The base_addr from the mapping is where the module is actually loaded in memory (See ProcessSymbols::add_mapping),
55+
// but the symbol addresses from the ELF file assume the module is loaded at its preferred virtual address. We need to:
56+
// 1. Find the module's preferred base address from the ELF file or symbols
57+
// 2. Calculate the offset: actual_base - preferred_base
58+
// 3. Apply this offset to the symbol addresses
59+
60+
// Find the preferred base address from the minimum symbol address
61+
let preferred_base = symbols.iter().map(|s| s.offset).min().unwrap_or(0) & !0xfff; // Align to page boundary
62+
63+
// Convert absolute addresses to relative offsets
64+
for symbol in &mut symbols {
65+
symbol.offset = symbol.offset.saturating_sub(preferred_base);
66+
}
67+
5468
Ok(Self {
5569
path: path.as_ref().to_path_buf(),
5670
symbols,

0 commit comments

Comments
 (0)