diff --git a/objdiff-core/src/arch/arm.rs b/objdiff-core/src/arch/arm.rs index a8feea7..70374ff 100644 --- a/objdiff-core/src/arch/arm.rs +++ b/objdiff-core/src/arch/arm.rs @@ -162,7 +162,7 @@ impl ArchArm { } impl Arch for ArchArm { - fn post_init(&mut self, sections: &[Section], symbols: &[Symbol]) { + fn post_init(&mut self, sections: &[Section], symbols: &[Symbol], _symbol_indices: &[usize]) { self.disasm_modes = Self::get_mapping_symbols(sections, symbols); } diff --git a/objdiff-core/src/arch/mod.rs b/objdiff-core/src/arch/mod.rs index 30179fd..59da3cc 100644 --- a/objdiff-core/src/arch/mod.rs +++ b/objdiff-core/src/arch/mod.rs @@ -340,7 +340,8 @@ impl dyn Arch { pub trait Arch: Any + Debug + Send + Sync { /// Finishes arch-specific initialization that must be done after sections have been combined. - fn post_init(&mut self, _sections: &[Section], _symbols: &[Symbol]) {} + fn post_init(&mut self, _sections: &[Section], _symbols: &[Symbol], _symbol_indices: &[usize]) { + } /// Generate a list of instructions references (offset, size, opcode) from the given code. /// diff --git a/objdiff-core/src/arch/ppc/mod.rs b/objdiff-core/src/arch/ppc/mod.rs index 7f06f31..b8a6bab 100644 --- a/objdiff-core/src/arch/ppc/mod.rs +++ b/objdiff-core/src/arch/ppc/mod.rs @@ -472,12 +472,27 @@ impl Arch for ArchPpc { } Ok(next_address.saturating_sub(symbol.address)) } + + fn post_init(&mut self, _sections: &[Section], _symbols: &[Symbol], symbol_indices: &[usize]) { + // Change the indices used as keys from the original symbol indices to the new symbol array indices + self.extab = Self::convert_extab_map_indices(self, symbol_indices); + } } impl ArchPpc { pub fn extab_for_symbol(&self, symbol_index: usize) -> Option<&ExceptionInfo> { self.extab.as_ref()?.get(&symbol_index) } + + pub fn convert_extab_map_indices( + &self, + symbol_indices: &[usize], + ) -> Option> { + let new_map: BTreeMap = + self.extab.as_ref()?.iter().map(|e| (symbol_indices[*e.0 + 1], e.1.clone())).collect(); + + Some(new_map) + } } fn zero_reloc(code: u32, reloc: &Relocation) -> u32 { diff --git a/objdiff-core/src/obj/read.rs b/objdiff-core/src/obj/read.rs index e78e501..6046070 100644 --- a/objdiff-core/src/obj/read.rs +++ b/objdiff-core/src/obj/read.rs @@ -1089,7 +1089,7 @@ pub fn parse(data: &[u8], config: &DiffObjConfig, diff_side: DiffSide) -> Result combine_sections(&mut sections, &mut symbols, config)?; } add_section_symbols(§ions, &mut symbols); - arch.post_init(§ions, &symbols); + arch.post_init(§ions, &symbols, &symbol_indices); let mut obj = Object { arch, endianness: obj_file.endianness(), diff --git a/objdiff-core/tests/snapshots/arch_ppc__read_extab.snap b/objdiff-core/tests/snapshots/arch_ppc__read_extab.snap index 8f06216..4a2911a 100644 --- a/objdiff-core/tests/snapshots/arch_ppc__read_extab.snap +++ b/objdiff-core/tests/snapshots/arch_ppc__read_extab.snap @@ -9,7 +9,7 @@ Object { ), extab: Some( { - 10: ExceptionInfo { + 1: ExceptionInfo { eti_symbol: ExtabSymbolRef { original_index: 5, name: "@31", @@ -35,7 +35,7 @@ Object { }, dtors: [], }, - 11: ExceptionInfo { + 2: ExceptionInfo { eti_symbol: ExtabSymbolRef { original_index: 7, name: "@52", @@ -95,7 +95,7 @@ Object { }, ], }, - 12: ExceptionInfo { + 3: ExceptionInfo { eti_symbol: ExtabSymbolRef { original_index: 9, name: "@60",