Skip to content

Commit 1fe16c1

Browse files
committed
PPC: Fix extern relocations not having their addend copied
1 parent e5cba3e commit 1fe16c1

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

objdiff-core/src/arch/ppc.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -477,15 +477,17 @@ fn clear_overwritten_gprs(ins: Ins, gpr_pool_relocs: &mut HashMap<u8, ObjReloc>)
477477
fn make_fake_pool_reloc(offset: i16, cur_addr: u32, pool_reloc: &ObjReloc) -> Option<ObjReloc> {
478478
let offset_from_pool = pool_reloc.addend + offset as i64;
479479
let target_address = pool_reloc.target.address.checked_add_signed(offset_from_pool)?;
480-
let target_symbol = if pool_reloc.target.orig_section_index.is_some() {
480+
let target;
481+
let addend;
482+
if pool_reloc.target.orig_section_index.is_some() {
481483
// If the target symbol is within this current object, then we also need to create a fake
482484
// target symbol to go inside our fake relocation. This is because we don't have access to
483485
// list of all symbols in this section, so we can't find the real symbol within the pool
484486
// based on its address yet. Instead we make a placeholder that has the correct
485487
// `orig_section_index` and `address` fields, and then later on when this information is
486488
// displayed to the user, we can find the real symbol by searching through the object's
487489
// section's symbols for one that contains this address.
488-
ObjSymbol {
490+
target = ObjSymbol {
489491
name: "".to_string(),
490492
demangled_name: None,
491493
address: target_address,
@@ -498,7 +500,10 @@ fn make_fake_pool_reloc(offset: i16, cur_addr: u32, pool_reloc: &ObjReloc) -> Op
498500
virtual_address: None,
499501
original_index: None,
500502
bytes: vec![],
501-
}
503+
};
504+
// The addend is also fake because we don't know yet if the `target_address` here is the exact
505+
// start of the symbol or if it's in the middle of it.
506+
addend = 0;
502507
} else {
503508
// But if the target symbol is in a different object (extern), then we simply copy the pool
504509
// relocation's target. This is because it won't be possible to locate the actual symbol
@@ -509,16 +514,14 @@ fn make_fake_pool_reloc(offset: i16, cur_addr: u32, pool_reloc: &ObjReloc) -> Op
509514
// something like a vtable for a class with multiple inheritance (for example, dCcD_Cyl in
510515
// The Wind Waker). So just showing that vtable symbol plus an addend to represent the
511516
// offset into it works fine in this case, no fake symbol to hold an address is necessary.
512-
pool_reloc.target.clone()
517+
target = pool_reloc.target.clone();
518+
addend = pool_reloc.addend;
513519
};
514-
// The addend is also fake because we don't know yet if the `target_address` here is the exact
515-
// start of the symbol or if it's in the middle of it.
516-
let fake_addend = 0;
517520
Some(ObjReloc {
518521
flags: RelocationFlags::Elf { r_type: elf::R_PPC_NONE },
519522
address: cur_addr as u64,
520-
target: target_symbol,
521-
addend: fake_addend,
523+
target,
524+
addend,
522525
})
523526
}
524527

0 commit comments

Comments
 (0)