Skip to content

Commit c917cad

Browse files
committed
Strip zeros from end of inferred function sizes
Resolves #3
1 parent dd65332 commit c917cad

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ authors = ["Luke Street <luke@street.dev>"]
1919
edition = "2024"
2020
license = "MIT OR Apache-2.0"
2121
repository = "https://github.com/encounter/objdiff"
22-
rust-version = "1.85"
22+
rust-version = "1.88"

objdiff-core/src/obj/read.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,18 @@ fn infer_symbol_sizes(symbols: &mut [Symbol], sections: &[Section]) {
205205
}
206206
iter_idx += 1;
207207
};
208-
let next_address = next_symbol.map(|s| s.address).unwrap_or_else(|| {
209-
let section = &sections[section_idx];
210-
section.address + section.size
211-
});
208+
let section = &sections[section_idx];
209+
let mut next_address =
210+
next_symbol.map(|s| s.address).unwrap_or_else(|| section.address + section.size);
211+
if section.kind == SectionKind::Code {
212+
// For functions, trim any trailing 4-byte zeroes from the end (padding, nops)
213+
while next_address > symbol.address + 4
214+
&& let Some(data) = section.data_range(next_address - 4, 4)
215+
&& data == [0u8; 4]
216+
{
217+
next_address -= 4;
218+
}
219+
}
212220
let new_size = next_address.saturating_sub(symbol.address);
213221
if new_size > 0 {
214222
let symbol = &mut symbols[symbol_idx];
@@ -218,7 +226,7 @@ fn infer_symbol_sizes(symbols: &mut [Symbol], sections: &[Section]) {
218226
}
219227
// Set symbol kind if unknown and size is non-zero
220228
if symbol.kind == SymbolKind::Unknown {
221-
symbol.kind = match sections[section_idx].kind {
229+
symbol.kind = match section.kind {
222230
SectionKind::Code => SymbolKind::Function,
223231
SectionKind::Data | SectionKind::Bss => SymbolKind::Object,
224232
_ => SymbolKind::Unknown,

0 commit comments

Comments
 (0)