Skip to content

Commit

Permalink
PPC: Fix extern relocations not having their addend copied
Browse files Browse the repository at this point in the history
  • Loading branch information
LagoLunatic committed Jan 5, 2025
1 parent e5cba3e commit 1fe16c1
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions objdiff-core/src/arch/ppc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,15 +477,17 @@ fn clear_overwritten_gprs(ins: Ins, gpr_pool_relocs: &mut HashMap<u8, ObjReloc>)
fn make_fake_pool_reloc(offset: i16, cur_addr: u32, pool_reloc: &ObjReloc) -> Option<ObjReloc> {
let offset_from_pool = pool_reloc.addend + offset as i64;
let target_address = pool_reloc.target.address.checked_add_signed(offset_from_pool)?;
let target_symbol = if pool_reloc.target.orig_section_index.is_some() {
let target;
let addend;
if pool_reloc.target.orig_section_index.is_some() {
// If the target symbol is within this current object, then we also need to create a fake
// target symbol to go inside our fake relocation. This is because we don't have access to
// list of all symbols in this section, so we can't find the real symbol within the pool
// based on its address yet. Instead we make a placeholder that has the correct
// `orig_section_index` and `address` fields, and then later on when this information is
// displayed to the user, we can find the real symbol by searching through the object's
// section's symbols for one that contains this address.
ObjSymbol {
target = ObjSymbol {
name: "".to_string(),
demangled_name: None,
address: target_address,
Expand All @@ -498,7 +500,10 @@ fn make_fake_pool_reloc(offset: i16, cur_addr: u32, pool_reloc: &ObjReloc) -> Op
virtual_address: None,
original_index: None,
bytes: vec![],
}
};
// The addend is also fake because we don't know yet if the `target_address` here is the exact
// start of the symbol or if it's in the middle of it.
addend = 0;
} else {
// But if the target symbol is in a different object (extern), then we simply copy the pool
// relocation's target. This is because it won't be possible to locate the actual symbol
Expand All @@ -509,16 +514,14 @@ fn make_fake_pool_reloc(offset: i16, cur_addr: u32, pool_reloc: &ObjReloc) -> Op
// something like a vtable for a class with multiple inheritance (for example, dCcD_Cyl in
// The Wind Waker). So just showing that vtable symbol plus an addend to represent the
// offset into it works fine in this case, no fake symbol to hold an address is necessary.
pool_reloc.target.clone()
target = pool_reloc.target.clone();
addend = pool_reloc.addend;
};
// The addend is also fake because we don't know yet if the `target_address` here is the exact
// start of the symbol or if it's in the middle of it.
let fake_addend = 0;
Some(ObjReloc {
flags: RelocationFlags::Elf { r_type: elf::R_PPC_NONE },
address: cur_addr as u64,
target: target_symbol,
addend: fake_addend,
target,
addend,
})
}

Expand Down

0 comments on commit 1fe16c1

Please sign in to comment.