Skip to content

Commit 34220a8

Browse files
committed
Add address to ReportItem, stabilize sections/functions ordering
1 parent 0c9e552 commit 34220a8

File tree

5 files changed

+29
-21
lines changed

5 files changed

+29
-21
lines changed

objdiff-cli/src/cmd/report.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ fn report_object(
228228
demangled_name: None,
229229
virtual_address: section.virtual_address,
230230
}),
231+
address: None,
231232
});
232233

233234
match section.kind {
@@ -273,13 +274,24 @@ fn report_object(
273274
demangled_name: symbol.demangled_name.clone(),
274275
virtual_address: symbol.virtual_address,
275276
}),
277+
address: symbol.address.checked_sub(section.address),
276278
});
277279
if match_percent == 100.0 {
278280
measures.matched_functions += 1;
279281
}
280282
measures.total_functions += 1;
281283
}
282284
}
285+
sections.sort_by(|a, b| a.name.cmp(&b.name));
286+
let reverse_fn_order = object.metadata.reverse_fn_order.unwrap_or(false);
287+
functions.sort_by(|a, b| {
288+
if reverse_fn_order {
289+
b.address.unwrap_or(0).cmp(&a.address.unwrap_or(0))
290+
} else {
291+
a.address.unwrap_or(u64::MAX).cmp(&b.address.unwrap_or(u64::MAX))
292+
}
293+
.then_with(|| a.size.cmp(&b.size))
294+
});
283295
if metadata.complete.unwrap_or(false) {
284296
measures.complete_code = measures.total_code;
285297
measures.complete_data = measures.total_data;
161 Bytes
Binary file not shown.

objdiff-core/protos/report.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ message ReportItem {
9999
float fuzzy_match_percent = 3;
100100
// Extra metadata for this item
101101
optional ReportItemMetadata metadata = 4;
102+
// Address of the item (section-relative offset)
103+
optional uint64 address = 5;
102104
}
103105

104106
// Extra metadata for an item

objdiff-core/src/bindings/report.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ impl From<LegacyReportItem> for ReportItem {
434434
demangled_name: value.demangled_name,
435435
virtual_address: value.address,
436436
}),
437+
address: None,
437438
}
438439
}
439440
}

objdiff-core/src/diff/display.rs

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -687,19 +687,20 @@ pub fn display_sections(
687687
continue;
688688
}
689689
let section_diff = &diff.sections[section_idx];
690-
if section.kind == SectionKind::Code && reverse_fn_order {
691-
symbols.sort_by(|a, b| {
692-
let a_symbol = &obj.symbols[a.symbol];
693-
let b_symbol = &obj.symbols[b.symbol];
694-
symbol_sort_reverse(a_symbol, b_symbol)
695-
});
696-
} else {
697-
symbols.sort_by(|a, b| {
698-
let a_symbol = &obj.symbols[a.symbol];
699-
let b_symbol = &obj.symbols[b.symbol];
700-
symbol_sort(a_symbol, b_symbol)
701-
});
702-
}
690+
let reverse_fn_order = section.kind == SectionKind::Code && reverse_fn_order;
691+
symbols.sort_by(|a, b| {
692+
let a = &obj.symbols[a.symbol];
693+
let b = &obj.symbols[b.symbol];
694+
section_symbol_sort(a, b)
695+
.then_with(|| {
696+
if reverse_fn_order {
697+
b.address.cmp(&a.address)
698+
} else {
699+
a.address.cmp(&b.address)
700+
}
701+
})
702+
.then_with(|| a.size.cmp(&b.size))
703+
});
703704
sections.push(SectionDisplay {
704705
id: section.id.clone(),
705706
name: if section.flags.contains(SectionFlag::Combined) {
@@ -737,14 +738,6 @@ fn section_symbol_sort(a: &Symbol, b: &Symbol) -> Ordering {
737738
Ordering::Equal
738739
}
739740

740-
fn symbol_sort(a: &Symbol, b: &Symbol) -> Ordering {
741-
section_symbol_sort(a, b).then(a.address.cmp(&b.address)).then(a.size.cmp(&b.size))
742-
}
743-
744-
fn symbol_sort_reverse(a: &Symbol, b: &Symbol) -> Ordering {
745-
section_symbol_sort(a, b).then(b.address.cmp(&a.address)).then(b.size.cmp(&a.size))
746-
}
747-
748741
pub fn display_ins_data_labels(obj: &Object, resolved: ResolvedInstructionRef) -> Vec<String> {
749742
let Some(reloc) = resolved.relocation else {
750743
return Vec::new();

0 commit comments

Comments
 (0)