Skip to content

Commit c7cf54f

Browse files
committed
Create fake data section symbols to allow diffing entire sections again
1 parent cb0f24b commit c7cf54f

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

objdiff-core/src/obj/read.rs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,30 @@ fn map_symbol(
4949
{
5050
let section_name = section.name().context("Failed to process section name")?;
5151
name = format!("[{section_name}]");
52-
// For section symbols, set the size to zero. If the size is non-zero, it will be included
53-
// in the diff. Most of the time, this is duplicative, given that we'll have function or
54-
// object symbols that cover the same range. In the case of an empty section, the size
55-
// inference logic below will set the size back to the section size, thus acting as a
56-
// placeholder symbol.
57-
size = 0;
52+
53+
let section_kind = map_section_kind(&section);
54+
if section_kind == SectionKind::Data {
55+
// For section symbols, the size would normally be zero and excluded from the diff.
56+
// Instead we make them the size of all the data in the section so that the user can diff
57+
// entire sections by clicking on the section symbol at the top of the section.
58+
// We only do this for data sections, as there would be no point for code or bss sections.
59+
if let Some(last_symbol) = file
60+
.symbols()
61+
.filter(|s| {
62+
s.section_index() == Some(section.index())
63+
&& s.kind() == object::SymbolKind::Data
64+
&& s.size() > 0
65+
})
66+
.max_by_key(|s| s.address())
67+
{
68+
// Use the address that the last symbol ends at as the section size.
69+
size = last_symbol.address() + last_symbol.size();
70+
} else {
71+
// `section.size()` can include extra padding that doesn't correspond to any symbol,
72+
// so only fall back to it if there are no symbols to look at.
73+
size = section.size();
74+
}
75+
}
5876
}
5977

6078
let mut flags = arch.extra_symbol_flags(symbol);

0 commit comments

Comments
 (0)