Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions objdiff-core/src/arch/arm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
16 changes: 16 additions & 0 deletions objdiff-core/tests/arch_arm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Binary file added objdiff-core/tests/data/arm/v4bx.o
Binary file not shown.
Loading