diff --git a/objdiff-core/src/arch/arm.rs b/objdiff-core/src/arch/arm.rs index 35416c9f..184b26bc 100644 --- a/objdiff-core/src/arch/arm.rs +++ b/objdiff-core/src/arch/arm.rs @@ -343,6 +343,15 @@ impl Arch for ArchArm { // Handle ELF implicit relocations object::RelocationFlags::Elf { r_type } => { if relocation.has_implicit_addend() { + // R_ARM_V4BX marks a `bx` instruction so the linker can optionally + // rewrite it for ARMv4 interworking. Drops the addend since it's meaningless. + if r_type == elf::R_ARM_V4BX { + return Ok(Some(RelocationOverride { + target: RelocationOverrideTarget::Skip, + addend: 0, + })); + } + let section_data = section.data()?; let address = address as usize; let addend = match r_type { @@ -419,6 +428,7 @@ impl Arch for ArchArm { elf::R_ARM_CALL => Some("R_ARM_CALL"), elf::R_ARM_THM_PC11 => Some("R_ARM_THM_PC11"), elf::R_ARM_THM_PC9 => Some("R_ARM_THM_PC9"), + elf::R_ARM_V4BX => Some("R_ARM_V4BX"), _ => None, }, _ => None, diff --git a/objdiff-core/tests/arch_arm.rs b/objdiff-core/tests/arch_arm.rs index 9c507e1d..37cc8386 100644 --- a/objdiff-core/tests/arch_arm.rs +++ b/objdiff-core/tests/arch_arm.rs @@ -82,6 +82,22 @@ fn thumb_short_data_mapping() { ); } +#[test] +#[cfg(feature = "arm")] +fn read_arm_v4bx() { + // R_ARM_V4BX relocations mark `bx` instructions so the linker can optionally + // rewrite them for ARMv4 interworking. + let diff_config = diff::DiffObjConfig::default(); + let obj = + obj::read::parse(include_object!("data/arm/v4bx.o"), &diff_config, diff::DiffSide::Base) + .unwrap(); + let symbol_idx = obj.symbols.iter().position(|s| s.name == "v4bx_func").unwrap(); + let diff = diff::code::no_diff_code(&obj, symbol_idx, &diff_config).unwrap(); + let output = common::display_diff(&obj, &diff, symbol_idx, &diff_config); + // The `bx lr` still disassembles normally; the V4BX hint is simply dropped. + assert!(output.contains("bx"), "expected a `bx` instruction, got:\n{output}"); +} + #[test] #[cfg(feature = "arm")] fn trim_trailing_hword() { diff --git a/objdiff-core/tests/data/arm/v4bx.o b/objdiff-core/tests/data/arm/v4bx.o new file mode 100644 index 00000000..11271151 Binary files /dev/null and b/objdiff-core/tests/data/arm/v4bx.o differ