@@ -8,12 +8,13 @@ use alloc::{
8
8
use anyhow:: { anyhow, ensure, Context , Result } ;
9
9
10
10
use 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 ,
13
14
} ;
14
15
use crate :: obj:: {
15
- InstructionArg , InstructionArgValue , InstructionRef , Object , ResolvedRelocation ,
16
- ScannedInstruction , SymbolFlag , SymbolKind ,
16
+ InstructionArg , InstructionArgValue , InstructionRef , Object , ResolvedInstructionRef ,
17
+ ResolvedRelocation , ScannedInstruction , SymbolFlag , SymbolKind ,
17
18
} ;
18
19
19
20
pub fn no_diff_code (
@@ -291,12 +292,12 @@ pub(crate) fn section_name_eq(
291
292
fn reloc_eq (
292
293
left_obj : & Object ,
293
294
right_obj : & Object ,
294
- left_reloc : Option < ResolvedRelocation > ,
295
- right_reloc : Option < ResolvedRelocation > ,
295
+ left_ins : ResolvedInstructionRef ,
296
+ right_ins : ResolvedInstructionRef ,
296
297
diff_config : & DiffObjConfig ,
297
298
) -> bool {
298
299
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 ) {
300
301
( Some ( left_reloc) , Some ( right_reloc) ) => ( left_reloc, right_reloc) ,
301
302
// If relocations are relaxed, match if left is missing a reloc
302
303
( None , Some ( _) ) => return relax_reloc_diffs,
@@ -319,13 +320,10 @@ fn reloc_eq(
319
320
&& ( diff_config. function_reloc_diffs == FunctionRelocDiffs :: DataValue
320
321
|| symbol_name_addend_matches
321
322
|| 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) )
329
327
}
330
328
( Some ( _) , None ) => false ,
331
329
( None , Some ( _) ) => {
@@ -343,8 +341,8 @@ fn arg_eq(
343
341
right_row : & InstructionDiffRow ,
344
342
left_arg : & InstructionArg ,
345
343
right_arg : & InstructionArg ,
346
- left_reloc : Option < ResolvedRelocation > ,
347
- right_reloc : Option < ResolvedRelocation > ,
344
+ left_ins : ResolvedInstructionRef ,
345
+ right_ins : ResolvedInstructionRef ,
348
346
diff_config : & DiffObjConfig ,
349
347
) -> bool {
350
348
match left_arg {
@@ -357,7 +355,7 @@ fn arg_eq(
357
355
} ,
358
356
InstructionArg :: Reloc => {
359
357
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)
361
359
}
362
360
InstructionArg :: BranchDest ( _) => match right_arg {
363
361
// Compare dest instruction idx after diffing
@@ -434,8 +432,10 @@ fn diff_instruction(
434
432
. resolve_instruction_ref ( right_symbol_idx, r)
435
433
. context ( "Failed to resolve right instruction" ) ?;
436
434
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
439
439
let left_ins = left_obj. arch . process_instruction ( left_resolved, diff_config) ?;
440
440
let right_ins = left_obj. arch . process_instruction ( right_resolved, diff_config) ?;
441
441
if left_ins. args . len ( ) != right_ins. args . len ( ) {
@@ -455,8 +455,8 @@ fn diff_instruction(
455
455
right_row,
456
456
a,
457
457
b,
458
- left_resolved. relocation ,
459
- right_resolved. relocation ,
458
+ left_resolved,
459
+ right_resolved,
460
460
diff_config,
461
461
) {
462
462
result. left_args_diff . push ( InstructionArgDiffIndex :: NONE ) ;
@@ -500,19 +500,6 @@ fn diff_instruction(
500
500
return Ok ( result) ;
501
501
}
502
502
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
-
516
503
Ok ( InstructionDiffResult :: new ( InstructionDiffKind :: None ) )
517
504
}
518
505
0 commit comments