@@ -11,7 +11,7 @@ use object::{Endian as _, Object as _, ObjectSection as _, ObjectSymbol as _, el
11
11
use unarm:: { args, arm, thumb} ;
12
12
13
13
use crate :: {
14
- arch:: Arch ,
14
+ arch:: { Arch , RelocationOverride , RelocationOverrideTarget } ,
15
15
diff:: { ArmArchVersion , ArmR9Usage , DiffObjConfig , display:: InstructionPart } ,
16
16
obj:: {
17
17
InstructionRef , Relocation , RelocationFlags , ResolvedInstructionRef , ResolvedRelocation ,
@@ -356,47 +356,57 @@ impl Arch for ArchArm {
356
356
Ok ( ( ) )
357
357
}
358
358
359
- fn implcit_addend (
359
+ fn relocation_override (
360
360
& self ,
361
361
_file : & object:: File < ' _ > ,
362
362
section : & object:: Section ,
363
363
address : u64 ,
364
- _relocation : & object:: Relocation ,
365
- flags : RelocationFlags ,
366
- ) -> Result < i64 > {
367
- let section_data = section. data ( ) ?;
368
- let address = address as usize ;
369
- Ok ( match flags {
370
- // ARM calls
371
- RelocationFlags :: Elf ( elf:: R_ARM_PC24 )
372
- | RelocationFlags :: Elf ( elf:: R_ARM_XPC25 )
373
- | RelocationFlags :: Elf ( elf:: R_ARM_CALL ) => {
374
- let data = section_data[ address..address + 4 ] . try_into ( ) ?;
375
- let addend = self . endianness . read_i32_bytes ( data) ;
376
- let imm24 = addend & 0xffffff ;
377
- ( imm24 << 2 ) << 8 >> 8
378
- }
364
+ relocation : & object:: Relocation ,
365
+ ) -> Result < Option < RelocationOverride > > {
366
+ match relocation. flags ( ) {
367
+ // Handle ELF implicit relocations
368
+ object:: RelocationFlags :: Elf { r_type } => {
369
+ if relocation. has_implicit_addend ( ) {
370
+ let section_data = section. data ( ) ?;
371
+ let address = address as usize ;
372
+ let addend = match r_type {
373
+ // ARM calls
374
+ elf:: R_ARM_PC24 | elf:: R_ARM_XPC25 | elf:: R_ARM_CALL => {
375
+ let data = section_data[ address..address + 4 ] . try_into ( ) ?;
376
+ let addend = self . endianness . read_i32_bytes ( data) ;
377
+ let imm24 = addend & 0xffffff ;
378
+ ( imm24 << 2 ) << 8 >> 8
379
+ }
379
380
380
- // Thumb calls
381
- RelocationFlags :: Elf ( elf:: R_ARM_THM_PC22 )
382
- | RelocationFlags :: Elf ( elf:: R_ARM_THM_XPC22 ) => {
383
- let data = section_data[ address..address + 2 ] . try_into ( ) ?;
384
- let high = self . endianness . read_i16_bytes ( data) as i32 ;
385
- let data = section_data[ address + 2 ..address + 4 ] . try_into ( ) ?;
386
- let low = self . endianness . read_i16_bytes ( data) as i32 ;
381
+ // Thumb calls
382
+ elf:: R_ARM_THM_PC22 | elf:: R_ARM_THM_XPC22 => {
383
+ let data = section_data[ address..address + 2 ] . try_into ( ) ?;
384
+ let high = self . endianness . read_i16_bytes ( data) as i32 ;
385
+ let data = section_data[ address + 2 ..address + 4 ] . try_into ( ) ?;
386
+ let low = self . endianness . read_i16_bytes ( data) as i32 ;
387
387
388
- let imm22 = ( ( high & 0x7ff ) << 11 ) | ( low & 0x7ff ) ;
389
- ( imm22 << 1 ) << 9 >> 9
390
- }
388
+ let imm22 = ( ( high & 0x7ff ) << 11 ) | ( low & 0x7ff ) ;
389
+ ( imm22 << 1 ) << 9 >> 9
390
+ }
391
391
392
- // Data
393
- RelocationFlags :: Elf ( elf:: R_ARM_ABS32 ) => {
394
- let data = section_data[ address..address + 4 ] . try_into ( ) ?;
395
- self . endianness . read_i32_bytes ( data)
396
- }
392
+ // Data
393
+ elf:: R_ARM_ABS32 => {
394
+ let data = section_data[ address..address + 4 ] . try_into ( ) ?;
395
+ self . endianness . read_i32_bytes ( data)
396
+ }
397
397
398
- flags => bail ! ( "Unsupported ARM implicit relocation {flags:?}" ) ,
399
- } as i64 )
398
+ flags => bail ! ( "Unsupported ARM implicit relocation {flags:?}" ) ,
399
+ } ;
400
+ Ok ( Some ( RelocationOverride {
401
+ target : RelocationOverrideTarget :: Keep ,
402
+ addend : addend as i64 ,
403
+ } ) )
404
+ } else {
405
+ Ok ( None )
406
+ }
407
+ }
408
+ _ => Ok ( None ) ,
409
+ }
400
410
}
401
411
402
412
fn demangle ( & self , name : & str ) -> Option < String > {
@@ -575,7 +585,7 @@ fn push_args(
575
585
arg_cb ( InstructionPart :: basic ( "}" ) ) ?;
576
586
}
577
587
args:: Argument :: CoprocNum ( value) => {
578
- arg_cb ( InstructionPart :: opaque ( format ! ( "p{}" , value ) ) ) ?;
588
+ arg_cb ( InstructionPart :: opaque ( format ! ( "p{value}" ) ) ) ?;
579
589
}
580
590
args:: Argument :: ShiftImm ( shift) => {
581
591
arg_cb ( InstructionPart :: opaque ( shift. op . to_string ( ) ) ) ?;
0 commit comments