Skip to content

Commit 7c4f1c5

Browse files
committed
Fix left/right arch mismatches in diff code
1 parent fa4a6ca commit 7c4f1c5

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

objdiff-core/src/diff/code.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pub fn diff_code(
9191
left_section_idx,
9292
diff_config,
9393
)?;
94-
let right_ops = left_obj.arch.scan_instructions(
94+
let right_ops = right_obj.arch.scan_instructions(
9595
right_symbol.address,
9696
right_data,
9797
right_section_idx,
@@ -437,7 +437,7 @@ fn diff_instruction(
437437
{
438438
// If either the raw code bytes or relocations don't match, process instructions and compare args
439439
let left_ins = left_obj.arch.process_instruction(left_resolved, diff_config)?;
440-
let right_ins = left_obj.arch.process_instruction(right_resolved, diff_config)?;
440+
let right_ins = right_obj.arch.process_instruction(right_resolved, diff_config)?;
441441
if left_ins.args.len() != right_ins.args.len() {
442442
state.diff_score += PENALTY_REPLACE;
443443
return Ok(InstructionDiffResult::new(InstructionDiffKind::Replace));

objdiff-core/tests/arch_mips.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,26 @@ fn read_mips() {
1414
let output = common::display_diff(&obj, &diff, symbol_idx, &diff_config);
1515
insta::assert_snapshot!(output);
1616
}
17+
18+
#[test]
19+
#[cfg(feature = "mips")]
20+
fn cross_endian_diff() {
21+
let diff_config = diff::DiffObjConfig::default();
22+
let obj_be = obj::read::parse(include_object!("data/mips/code_be.o"), &diff_config).unwrap();
23+
assert_eq!(obj_be.endianness, object::Endianness::Big);
24+
let obj_le = obj::read::parse(include_object!("data/mips/code_le.o"), &diff_config).unwrap();
25+
assert_eq!(obj_le.endianness, object::Endianness::Little);
26+
let left_symbol_idx = obj_be.symbols.iter().position(|s| s.name == "func_00000000").unwrap();
27+
let right_symbol_idx =
28+
obj_le.symbols.iter().position(|s| s.name == "func_00000000__FPcPc").unwrap();
29+
let (left_diff, right_diff) =
30+
diff::code::diff_code(&obj_be, &obj_le, left_symbol_idx, right_symbol_idx, &diff_config)
31+
.unwrap();
32+
// Although the objects differ in endianness, the instructions should match.
33+
assert_eq!(left_diff.instruction_rows[0].kind, diff::InstructionDiffKind::None);
34+
assert_eq!(right_diff.instruction_rows[0].kind, diff::InstructionDiffKind::None);
35+
assert_eq!(left_diff.instruction_rows[1].kind, diff::InstructionDiffKind::None);
36+
assert_eq!(right_diff.instruction_rows[1].kind, diff::InstructionDiffKind::None);
37+
assert_eq!(left_diff.instruction_rows[2].kind, diff::InstructionDiffKind::None);
38+
assert_eq!(right_diff.instruction_rows[2].kind, diff::InstructionDiffKind::None);
39+
}
2 KB
Binary file not shown.
5.21 KB
Binary file not shown.

0 commit comments

Comments
 (0)