mirror of
https://github.com/encounter/objdiff.git
synced 2025-06-07 15:13:47 +00:00
Fix left/right arch mismatches in diff code
This commit is contained in:
parent
fa4a6cadbb
commit
7c4f1c5d13
@ -91,7 +91,7 @@ pub fn diff_code(
|
|||||||
left_section_idx,
|
left_section_idx,
|
||||||
diff_config,
|
diff_config,
|
||||||
)?;
|
)?;
|
||||||
let right_ops = left_obj.arch.scan_instructions(
|
let right_ops = right_obj.arch.scan_instructions(
|
||||||
right_symbol.address,
|
right_symbol.address,
|
||||||
right_data,
|
right_data,
|
||||||
right_section_idx,
|
right_section_idx,
|
||||||
@ -437,7 +437,7 @@ fn diff_instruction(
|
|||||||
{
|
{
|
||||||
// If either the raw code bytes or relocations don't match, process instructions and compare args
|
// If either the raw code bytes or relocations don't match, process instructions and compare args
|
||||||
let left_ins = left_obj.arch.process_instruction(left_resolved, diff_config)?;
|
let left_ins = left_obj.arch.process_instruction(left_resolved, diff_config)?;
|
||||||
let right_ins = left_obj.arch.process_instruction(right_resolved, diff_config)?;
|
let right_ins = right_obj.arch.process_instruction(right_resolved, diff_config)?;
|
||||||
if left_ins.args.len() != right_ins.args.len() {
|
if left_ins.args.len() != right_ins.args.len() {
|
||||||
state.diff_score += PENALTY_REPLACE;
|
state.diff_score += PENALTY_REPLACE;
|
||||||
return Ok(InstructionDiffResult::new(InstructionDiffKind::Replace));
|
return Ok(InstructionDiffResult::new(InstructionDiffKind::Replace));
|
||||||
|
@ -14,3 +14,26 @@ fn read_mips() {
|
|||||||
let output = common::display_diff(&obj, &diff, symbol_idx, &diff_config);
|
let output = common::display_diff(&obj, &diff, symbol_idx, &diff_config);
|
||||||
insta::assert_snapshot!(output);
|
insta::assert_snapshot!(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[cfg(feature = "mips")]
|
||||||
|
fn cross_endian_diff() {
|
||||||
|
let diff_config = diff::DiffObjConfig::default();
|
||||||
|
let obj_be = obj::read::parse(include_object!("data/mips/code_be.o"), &diff_config).unwrap();
|
||||||
|
assert_eq!(obj_be.endianness, object::Endianness::Big);
|
||||||
|
let obj_le = obj::read::parse(include_object!("data/mips/code_le.o"), &diff_config).unwrap();
|
||||||
|
assert_eq!(obj_le.endianness, object::Endianness::Little);
|
||||||
|
let left_symbol_idx = obj_be.symbols.iter().position(|s| s.name == "func_00000000").unwrap();
|
||||||
|
let right_symbol_idx =
|
||||||
|
obj_le.symbols.iter().position(|s| s.name == "func_00000000__FPcPc").unwrap();
|
||||||
|
let (left_diff, right_diff) =
|
||||||
|
diff::code::diff_code(&obj_be, &obj_le, left_symbol_idx, right_symbol_idx, &diff_config)
|
||||||
|
.unwrap();
|
||||||
|
// Although the objects differ in endianness, the instructions should match.
|
||||||
|
assert_eq!(left_diff.instruction_rows[0].kind, diff::InstructionDiffKind::None);
|
||||||
|
assert_eq!(right_diff.instruction_rows[0].kind, diff::InstructionDiffKind::None);
|
||||||
|
assert_eq!(left_diff.instruction_rows[1].kind, diff::InstructionDiffKind::None);
|
||||||
|
assert_eq!(right_diff.instruction_rows[1].kind, diff::InstructionDiffKind::None);
|
||||||
|
assert_eq!(left_diff.instruction_rows[2].kind, diff::InstructionDiffKind::None);
|
||||||
|
assert_eq!(right_diff.instruction_rows[2].kind, diff::InstructionDiffKind::None);
|
||||||
|
}
|
||||||
|
BIN
objdiff-core/tests/data/mips/code_be.o
Normal file
BIN
objdiff-core/tests/data/mips/code_be.o
Normal file
Binary file not shown.
BIN
objdiff-core/tests/data/mips/code_le.o
Normal file
BIN
objdiff-core/tests/data/mips/code_le.o
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user