Fix reading IMAGE_REL_PPC_REFHI/REFLO without PAIR

This commit is contained in:
Luke Street 2025-07-29 20:58:34 -06:00
parent f5d3d5f10a
commit dd653329f5
3 changed files with 15 additions and 6 deletions

View File

@ -462,6 +462,7 @@ impl Arch for ArchDummy {
fn data_reloc_size(&self, _flags: RelocationFlags) -> usize { 0 }
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum RelocationOverrideTarget {
Keep,
Skip,
@ -469,6 +470,7 @@ pub enum RelocationOverrideTarget {
Section(object::SectionIndex),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct RelocationOverride {
pub target: RelocationOverrideTarget,
pub addend: i64,

View File

@ -229,13 +229,19 @@ impl Arch for ArchPpc {
typ: pe::IMAGE_REL_PPC_PAIR
})
})
.map_or(Ok(None), |(_, reloc)| match reloc.target() {
object::RelocationTarget::Symbol(index) => Ok(Some(RelocationOverride {
.map_or(
Ok(Some(RelocationOverride {
target: RelocationOverrideTarget::Keep,
addend: index.0 as u16 as i16 as i64,
addend: 0,
})),
target => Err(anyhow!("Unsupported IMAGE_REL_PPC_PAIR target {target:?}")),
}),
|(_, reloc)| match reloc.target() {
object::RelocationTarget::Symbol(index) => Ok(Some(RelocationOverride {
target: RelocationOverrideTarget::Keep,
addend: index.0 as u16 as i16 as i64,
})),
target => Err(anyhow!("Unsupported IMAGE_REL_PPC_PAIR target {target:?}")),
},
),
// Skip PAIR relocations as they are handled by the previous case
object::RelocationFlags::Coff { typ: pe::IMAGE_REL_PPC_PAIR } => {
Ok(Some(RelocationOverride { target: RelocationOverrideTarget::Skip, addend: 0 }))

View File

@ -361,7 +361,8 @@ fn map_section_relocations(
None => {
ensure!(
!reloc.has_implicit_addend(),
"Unsupported implicit relocation {:?}",
"Unsupported {:?} implicit relocation {:?}",
obj_file.architecture(),
reloc.flags()
);
}