File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -343,6 +343,15 @@ impl Arch for ArchArm {
343343 // Handle ELF implicit relocations
344344 object:: RelocationFlags :: Elf { r_type } => {
345345 if relocation. has_implicit_addend ( ) {
346+ // R_ARM_V4BX marks a `bx` instruction so the linker can optionally
347+ // rewrite it for ARMv4 interworking. Drops the addend since it's meaningless.
348+ if r_type == elf:: R_ARM_V4BX {
349+ return Ok ( Some ( RelocationOverride {
350+ target : RelocationOverrideTarget :: Skip ,
351+ addend : 0 ,
352+ } ) ) ;
353+ }
354+
346355 let section_data = section. data ( ) ?;
347356 let address = address as usize ;
348357 let addend = match r_type {
@@ -419,6 +428,7 @@ impl Arch for ArchArm {
419428 elf:: R_ARM_CALL => Some ( "R_ARM_CALL" ) ,
420429 elf:: R_ARM_THM_PC11 => Some ( "R_ARM_THM_PC11" ) ,
421430 elf:: R_ARM_THM_PC9 => Some ( "R_ARM_THM_PC9" ) ,
431+ elf:: R_ARM_V4BX => Some ( "R_ARM_V4BX" ) ,
422432 _ => None ,
423433 } ,
424434 _ => None ,
Original file line number Diff line number Diff line change @@ -82,6 +82,22 @@ fn thumb_short_data_mapping() {
8282 ) ;
8383}
8484
85+ #[ test]
86+ #[ cfg( feature = "arm" ) ]
87+ fn read_arm_v4bx ( ) {
88+ // R_ARM_V4BX relocations mark `bx` instructions so the linker can optionally
89+ // rewrite them for ARMv4 interworking.
90+ let diff_config = diff:: DiffObjConfig :: default ( ) ;
91+ let obj =
92+ obj:: read:: parse ( include_object ! ( "data/arm/v4bx.o" ) , & diff_config, diff:: DiffSide :: Base )
93+ . unwrap ( ) ;
94+ let symbol_idx = obj. symbols . iter ( ) . position ( |s| s. name == "v4bx_func" ) . unwrap ( ) ;
95+ let diff = diff:: code:: no_diff_code ( & obj, symbol_idx, & diff_config) . unwrap ( ) ;
96+ let output = common:: display_diff ( & obj, & diff, symbol_idx, & diff_config) ;
97+ // The `bx lr` still disassembles normally; the V4BX hint is simply dropped.
98+ assert ! ( output. contains( "bx" ) , "expected a `bx` instruction, got:\n {output}" ) ;
99+ }
100+
85101#[ test]
86102#[ cfg( feature = "arm" ) ]
87103fn trim_trailing_hword ( ) {
You can’t perform that action at this time.
0 commit comments