Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement diffing relocations within data sections #154

Merged
merged 9 commits into from
Jan 18, 2025
13 changes: 13 additions & 0 deletions objdiff-core/src/arch/arm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,19 @@ impl ObjArch for ObjArchArm {
fn display_reloc(&self, flags: RelocationFlags) -> Cow<'static, str> {
Cow::Owned(format!("<{flags:?}>"))
}

fn get_reloc_byte_size(&self, flags: RelocationFlags) -> usize {
match flags {
RelocationFlags::Elf { r_type } => match r_type {
elf::R_ARM_ABS32 => 4,
elf::R_ARM_REL32 => 4,
elf::R_ARM_ABS16 => 2,
elf::R_ARM_ABS8 => 1,
_ => 1,
},
_ => 1,
}
}
}

#[derive(Clone, Copy, Debug)]
Expand Down
15 changes: 15 additions & 0 deletions objdiff-core/src/arch/arm64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,21 @@ impl ObjArch for ObjArchArm64 {
_ => Cow::Owned(format!("<{flags:?}>")),
}
}

fn get_reloc_byte_size(&self, flags: RelocationFlags) -> usize {
match flags {
RelocationFlags::Elf { r_type } => match r_type {
elf::R_AARCH64_ABS64 => 8,
elf::R_AARCH64_ABS32 => 4,
elf::R_AARCH64_ABS16 => 2,
elf::R_AARCH64_PREL64 => 8,
elf::R_AARCH64_PREL32 => 4,
elf::R_AARCH64_PREL16 => 2,
_ => 1,
},
_ => 1,
}
}
}

struct DisplayCtx<'a> {
Expand Down
11 changes: 11 additions & 0 deletions objdiff-core/src/arch/mips.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,17 @@ impl ObjArch for ObjArchMips {
_ => Cow::Owned(format!("<{flags:?}>")),
}
}

fn get_reloc_byte_size(&self, flags: RelocationFlags) -> usize {
match flags {
RelocationFlags::Elf { r_type } => match r_type {
elf::R_MIPS_16 => 2,
elf::R_MIPS_32 => 4,
_ => 1,
},
_ => 1,
}
}
}

fn push_reloc(args: &mut Vec<ObjInsArg>, reloc: &ObjReloc) -> Result<()> {
Expand Down
2 changes: 2 additions & 0 deletions objdiff-core/src/arch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ pub trait ObjArch: Send + Sync {

fn display_reloc(&self, flags: RelocationFlags) -> Cow<'static, str>;

fn get_reloc_byte_size(&self, flags: RelocationFlags) -> usize;

fn symbol_address(&self, symbol: &Symbol) -> u64 { symbol.address() }

fn guess_data_type(&self, _instruction: &ObjIns) -> Option<DataType> { None }
Expand Down
11 changes: 11 additions & 0 deletions objdiff-core/src/arch/ppc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,17 @@ impl ObjArch for ObjArchPpc {
}
}

fn get_reloc_byte_size(&self, flags: RelocationFlags) -> usize {
match flags {
RelocationFlags::Elf { r_type } => match r_type {
elf::R_PPC_ADDR32 => 4,
elf::R_PPC_UADDR32 => 4,
_ => 1,
},
_ => 1,
}
}

fn guess_data_type(&self, instruction: &ObjIns) -> Option<super::DataType> {
if instruction.reloc.as_ref().is_some_and(|r| r.target.name.starts_with("@stringBase")) {
return Some(DataType::String);
Expand Down
13 changes: 13 additions & 0 deletions objdiff-core/src/arch/x86.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,19 @@ impl ObjArch for ObjArchX86 {
_ => Cow::Owned(format!("<{flags:?}>")),
}
}

fn get_reloc_byte_size(&self, flags: RelocationFlags) -> usize {
match flags {
RelocationFlags::Coff { typ } => match typ {
pe::IMAGE_REL_I386_DIR16 => 2,
pe::IMAGE_REL_I386_REL16 => 2,
pe::IMAGE_REL_I386_DIR32 => 4,
pe::IMAGE_REL_I386_REL32 => 4,
_ => 1,
},
_ => 1,
}
}
}

fn replace_arg(
Expand Down
2 changes: 1 addition & 1 deletion objdiff-core/src/diff/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ fn address_eq(left: &ObjReloc, right: &ObjReloc) -> bool {
left.target.address as i64 + left.addend == right.target.address as i64 + right.addend
}

fn section_name_eq(
pub fn section_name_eq(
left_obj: &ObjInfo,
right_obj: &ObjInfo,
left_orig_section_index: usize,
Expand Down
Loading
Loading