Skip to content

Commit dd65332

Browse files
committed
Fix reading IMAGE_REL_PPC_REFHI/REFLO without PAIR
1 parent f5d3d5f commit dd65332

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

objdiff-core/src/arch/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,13 +462,15 @@ impl Arch for ArchDummy {
462462
fn data_reloc_size(&self, _flags: RelocationFlags) -> usize { 0 }
463463
}
464464

465+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
465466
pub enum RelocationOverrideTarget {
466467
Keep,
467468
Skip,
468469
Symbol(object::SymbolIndex),
469470
Section(object::SectionIndex),
470471
}
471472

473+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
472474
pub struct RelocationOverride {
473475
pub target: RelocationOverrideTarget,
474476
pub addend: i64,

objdiff-core/src/arch/ppc/mod.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,13 +229,19 @@ impl Arch for ArchPpc {
229229
typ: pe::IMAGE_REL_PPC_PAIR
230230
})
231231
})
232-
.map_or(Ok(None), |(_, reloc)| match reloc.target() {
233-
object::RelocationTarget::Symbol(index) => Ok(Some(RelocationOverride {
232+
.map_or(
233+
Ok(Some(RelocationOverride {
234234
target: RelocationOverrideTarget::Keep,
235-
addend: index.0 as u16 as i16 as i64,
235+
addend: 0,
236236
})),
237-
target => Err(anyhow!("Unsupported IMAGE_REL_PPC_PAIR target {target:?}")),
238-
}),
237+
|(_, reloc)| match reloc.target() {
238+
object::RelocationTarget::Symbol(index) => Ok(Some(RelocationOverride {
239+
target: RelocationOverrideTarget::Keep,
240+
addend: index.0 as u16 as i16 as i64,
241+
})),
242+
target => Err(anyhow!("Unsupported IMAGE_REL_PPC_PAIR target {target:?}")),
243+
},
244+
),
239245
// Skip PAIR relocations as they are handled by the previous case
240246
object::RelocationFlags::Coff { typ: pe::IMAGE_REL_PPC_PAIR } => {
241247
Ok(Some(RelocationOverride { target: RelocationOverrideTarget::Skip, addend: 0 }))

objdiff-core/src/obj/read.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,8 @@ fn map_section_relocations(
361361
None => {
362362
ensure!(
363363
!reloc.has_implicit_addend(),
364-
"Unsupported implicit relocation {:?}",
364+
"Unsupported {:?} implicit relocation {:?}",
365+
obj_file.architecture(),
365366
reloc.flags()
366367
);
367368
}

0 commit comments

Comments
 (0)