Skip to content

Commit 3c7b5b7

Browse files
committed
Add support for R_ARM_V4BX
1 parent 73917c1 commit 3c7b5b7

3 files changed

Lines changed: 26 additions & 0 deletions

File tree

objdiff-core/src/arch/arm.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff 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,

objdiff-core/tests/arch_arm.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff 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")]
87103
fn trim_trailing_hword() {

objdiff-core/tests/data/arm/v4bx.o

644 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)