@@ -8,12 +8,13 @@ use alloc::{
88use anyhow:: { anyhow, ensure, Context , Result } ;
99
1010use super :: {
11- DiffObjConfig , FunctionRelocDiffs , InstructionArgDiffIndex , InstructionBranchFrom ,
12- InstructionBranchTo , InstructionDiffKind , InstructionDiffRow , SymbolDiff ,
11+ display:: display_ins_data_literals, DiffObjConfig , FunctionRelocDiffs , InstructionArgDiffIndex ,
12+ InstructionBranchFrom , InstructionBranchTo , InstructionDiffKind , InstructionDiffRow ,
13+ SymbolDiff ,
1314} ;
1415use crate :: obj:: {
15- InstructionArg , InstructionArgValue , InstructionRef , Object , ResolvedRelocation ,
16- ScannedInstruction , SymbolFlag , SymbolKind ,
16+ InstructionArg , InstructionArgValue , InstructionRef , Object , ResolvedInstructionRef ,
17+ ResolvedRelocation , ScannedInstruction , SymbolFlag , SymbolKind ,
1718} ;
1819
1920pub fn no_diff_code (
@@ -291,12 +292,12 @@ pub(crate) fn section_name_eq(
291292fn reloc_eq (
292293 left_obj : & Object ,
293294 right_obj : & Object ,
294- left_reloc : Option < ResolvedRelocation > ,
295- right_reloc : Option < ResolvedRelocation > ,
295+ left_ins : ResolvedInstructionRef ,
296+ right_ins : ResolvedInstructionRef ,
296297 diff_config : & DiffObjConfig ,
297298) -> bool {
298299 let relax_reloc_diffs = diff_config. function_reloc_diffs == FunctionRelocDiffs :: None ;
299- let ( left_reloc, right_reloc) = match ( left_reloc , right_reloc ) {
300+ let ( left_reloc, right_reloc) = match ( left_ins . relocation , right_ins . relocation ) {
300301 ( Some ( left_reloc) , Some ( right_reloc) ) => ( left_reloc, right_reloc) ,
301302 // If relocations are relaxed, match if left is missing a reloc
302303 ( None , Some ( _) ) => return relax_reloc_diffs,
@@ -319,13 +320,10 @@ fn reloc_eq(
319320 && ( diff_config. function_reloc_diffs == FunctionRelocDiffs :: DataValue
320321 || symbol_name_addend_matches
321322 || address_eq ( left_reloc, right_reloc) )
322- && (
323- diff_config. function_reloc_diffs == FunctionRelocDiffs :: NameAddress
324- || left_reloc. symbol . kind != SymbolKind :: Object
325- // TODO
326- // || left_obj.arch.display_ins_data_labels(left_ins)
327- // == left_obj.arch.display_ins_data_labels(right_ins))
328- )
323+ && ( diff_config. function_reloc_diffs == FunctionRelocDiffs :: NameAddress
324+ || left_reloc. symbol . kind != SymbolKind :: Object
325+ || display_ins_data_literals ( left_obj, left_ins)
326+ == display_ins_data_literals ( right_obj, right_ins) )
329327 }
330328 ( Some ( _) , None ) => false ,
331329 ( None , Some ( _) ) => {
@@ -343,8 +341,8 @@ fn arg_eq(
343341 right_row : & InstructionDiffRow ,
344342 left_arg : & InstructionArg ,
345343 right_arg : & InstructionArg ,
346- left_reloc : Option < ResolvedRelocation > ,
347- right_reloc : Option < ResolvedRelocation > ,
344+ left_ins : ResolvedInstructionRef ,
345+ right_ins : ResolvedInstructionRef ,
348346 diff_config : & DiffObjConfig ,
349347) -> bool {
350348 match left_arg {
@@ -357,7 +355,7 @@ fn arg_eq(
357355 } ,
358356 InstructionArg :: Reloc => {
359357 matches ! ( right_arg, InstructionArg :: Reloc )
360- && reloc_eq ( left_obj, right_obj, left_reloc , right_reloc , diff_config)
358+ && reloc_eq ( left_obj, right_obj, left_ins , right_ins , diff_config)
361359 }
362360 InstructionArg :: BranchDest ( _) => match right_arg {
363361 // Compare dest instruction idx after diffing
@@ -434,8 +432,10 @@ fn diff_instruction(
434432 . resolve_instruction_ref ( right_symbol_idx, r)
435433 . context ( "Failed to resolve right instruction" ) ?;
436434
437- if left_resolved. code != right_resolved. code {
438- // If data doesn't match, process instructions and compare args
435+ if left_resolved. code != right_resolved. code
436+ || !reloc_eq ( left_obj, right_obj, left_resolved, right_resolved, diff_config)
437+ {
438+ // 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) ?;
440440 let right_ins = left_obj. arch . process_instruction ( right_resolved, diff_config) ?;
441441 if left_ins. args . len ( ) != right_ins. args . len ( ) {
@@ -455,8 +455,8 @@ fn diff_instruction(
455455 right_row,
456456 a,
457457 b,
458- left_resolved. relocation ,
459- right_resolved. relocation ,
458+ left_resolved,
459+ right_resolved,
460460 diff_config,
461461 ) {
462462 result. left_args_diff . push ( InstructionArgDiffIndex :: NONE ) ;
@@ -500,19 +500,6 @@ fn diff_instruction(
500500 return Ok ( result) ;
501501 }
502502
503- // Compare relocations
504- if !reloc_eq (
505- left_obj,
506- right_obj,
507- left_resolved. relocation ,
508- right_resolved. relocation ,
509- diff_config,
510- ) {
511- state. diff_score += PENALTY_REG_DIFF ;
512- // TODO add relocation diff to args
513- return Ok ( InstructionDiffResult :: new ( InstructionDiffKind :: ArgMismatch ) ) ;
514- }
515-
516503 Ok ( InstructionDiffResult :: new ( InstructionDiffKind :: None ) )
517504}
518505
0 commit comments