Skip to content

Commit 729f406

Browse files
committed
Diff reloc data by display string instead of raw bytes
This is to handle data symbols that contain multiple values in them at once, such as stringBase. If you compare the target symbol's bytes directly, then any part of the symbol having different bytes will cause *all* relocations to that symbol to show as a diff, even if the specific string being accessed is the same.
1 parent a191c1d commit 729f406

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

objdiff-core/src/arch/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,17 @@ pub trait ObjArch: Send + Sync {
156156
Some(format!("Bytes: {:#x?}", bytes))
157157
}
158158

159+
fn display_ins_data(&self, ins: &ObjIns) -> Option<String> {
160+
let reloc = ins.reloc.as_ref()?;
161+
if reloc.addend >= 0 && reloc.target.bytes.len() > reloc.addend as usize {
162+
self.guess_data_type(ins).and_then(|ty| {
163+
self.display_data_type(ty, &reloc.target.bytes[reloc.addend as usize..])
164+
})
165+
} else {
166+
None
167+
}
168+
}
169+
159170
// Downcast methods
160171
#[cfg(feature = "ppc")]
161172
fn ppc(&self) -> Option<&ppc::ObjArchPpc> { None }

objdiff-core/src/diff/code.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::{
1010
ObjSymbolDiff,
1111
},
1212
obj::{
13-
ObjInfo, ObjInsArg, ObjReloc, ObjSection, ObjSymbol, ObjSymbolFlags, ObjSymbolKind,
13+
ObjInfo, ObjIns, ObjInsArg, ObjReloc, ObjSection, ObjSymbol, ObjSymbolFlags, ObjSymbolKind,
1414
SymbolRef,
1515
},
1616
};
@@ -218,10 +218,13 @@ fn reloc_eq(
218218
config: &DiffObjConfig,
219219
left_obj: &ObjInfo,
220220
right_obj: &ObjInfo,
221-
left_reloc: Option<&ObjReloc>,
222-
right_reloc: Option<&ObjReloc>,
221+
left_ins: Option<&ObjIns>,
222+
right_ins: Option<&ObjIns>,
223223
) -> bool {
224-
let (Some(left), Some(right)) = (left_reloc, right_reloc) else {
224+
let (Some(left_ins), Some(right_ins)) = (left_ins, right_ins) else {
225+
return false;
226+
};
227+
let (Some(left), Some(right)) = (&left_ins.reloc, &right_ins.reloc) else {
225228
return false;
226229
};
227230
if left.flags != right.flags {
@@ -241,7 +244,8 @@ fn reloc_eq(
241244
|| config.relax_shifted_data_diffs)
242245
&& (left.target.kind != ObjSymbolKind::Object
243246
|| right.target.name.starts_with("...")
244-
|| left.target.bytes == right.target.bytes)
247+
|| left_obj.arch.display_ins_data(left_ins)
248+
== left_obj.arch.display_ins_data(right_ins))
245249
}
246250
(Some(_), None) => false,
247251
(None, Some(_)) => {
@@ -279,8 +283,8 @@ fn arg_eq(
279283
config,
280284
left_obj,
281285
right_obj,
282-
left_diff.ins.as_ref().and_then(|i| i.reloc.as_ref()),
283-
right_diff.ins.as_ref().and_then(|i| i.reloc.as_ref()),
286+
left_diff.ins.as_ref(),
287+
right_diff.ins.as_ref(),
284288
)
285289
}
286290
ObjInsArg::BranchDest(_) => match right {

objdiff-gui/src/views/function_diff.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,8 @@ fn ins_hover_ui(
149149
appearance.highlight_color,
150150
format!("Size: {:x}", reloc.target.size),
151151
);
152-
if reloc.addend >= 0 && reloc.target.bytes.len() > reloc.addend as usize {
153-
if let Some(s) = obj.arch.guess_data_type(ins).and_then(|ty| {
154-
obj.arch.display_data_type(ty, &reloc.target.bytes[reloc.addend as usize..])
155-
}) {
156-
ui.colored_label(appearance.highlight_color, s);
157-
}
152+
if let Some(s) = obj.arch.display_ins_data(ins) {
153+
ui.colored_label(appearance.highlight_color, s);
158154
}
159155
} else {
160156
ui.colored_label(appearance.highlight_color, "Extern".to_string());

0 commit comments

Comments
 (0)