Skip to content

Commit 7994722

Browse files
tekknolagiclaude
andcommitted
ZJIT: Use absolute addresses in jitdump debug entries
samply computes lookup addresses as debug_info.code_addr + offset_relative_to_symbol, so the individual debug entry addr fields must be absolute addresses, not relative to function start. Also deduplicate entries at the same offset, keeping the first (the instruction that actually starts emitting code there). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 3e121f9 commit 7994722

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

zjit/src/codegen.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,15 +213,22 @@ fn emit_jitdump_for_function(
213213
// Append HIR text to the shared file and get the starting line offset
214214
let line_offset = append_hir_to_file(hir_file_path, &hir_text);
215215

216-
// Build debug entries: map each pos_marker's code offset to the HIR line
216+
// Build debug entries: map each pos_marker's code offset to the HIR line.
217+
// When multiple instructions share the same offset (e.g. Const that emits no code),
218+
// keep only the first — the profiler attributes all code between two offsets to
219+
// the entry at the lower offset.
217220
let mut debug_entries: Vec<DebugEntry> = Vec::new();
221+
let mut seen_offsets: std::collections::HashSet<u64> = std::collections::HashSet::new();
218222
for &(code_ptr, insn_id) in pos_markers {
219223
if let Some(&line) = insn_id_to_line.get(&insn_id) {
220-
debug_entries.push(DebugEntry {
221-
code_addr: code_ptr.raw_addr(cb) as u64 - start_addr,
222-
line: line_offset + line,
223-
filename: hir_file_path,
224-
});
224+
let addr = code_ptr.raw_addr(cb) as u64;
225+
if seen_offsets.insert(addr) {
226+
debug_entries.push(DebugEntry {
227+
code_addr: addr,
228+
line: line_offset + line,
229+
filename: hir_file_path,
230+
});
231+
}
225232
}
226233
}
227234

0 commit comments

Comments
 (0)