@@ -48,13 +48,12 @@ impl ObjArch for ObjArchPpc {
4848 relocations : & [ ObjReloc ] ,
4949 line_info : & BTreeMap < u64 , u32 > ,
5050 config : & DiffObjConfig ,
51- sections : & [ ObjSection ] ,
5251 ) -> Result < ProcessCodeResult > {
5352 let ins_count = code. len ( ) / 4 ;
5453 let mut ops = Vec :: < u16 > :: with_capacity ( ins_count) ;
5554 let mut insts = Vec :: < ObjIns > :: with_capacity ( ins_count) ;
5655 let fake_pool_reloc_for_addr =
57- generate_fake_pool_reloc_for_addr_mapping ( address, code, relocations, sections ) ;
56+ generate_fake_pool_reloc_for_addr_mapping ( address, code, relocations) ;
5857 for ( cur_addr, mut ins) in InsIter :: new ( code, address as u32 ) {
5958 let reloc = relocations. iter ( ) . find ( |r| ( r. address as u32 & !3 ) == cur_addr) ;
6059 if let Some ( reloc) = reloc {
@@ -453,26 +452,38 @@ fn get_offset_and_addr_gpr_for_possible_pool_reference(
453452// there isn't really a relocation here, as copying the pool relocation's type wouldn't make sense.
454453// Also, if this instruction is accessing the middle of a symbol instead of the start, we add an
455454// addend to indicate that.
456- fn make_fake_pool_reloc (
457- offset : i16 ,
458- cur_addr : u32 ,
459- pool_reloc : & ObjReloc ,
460- sections : & [ ObjSection ] ,
461- ) -> Option < ObjReloc > {
455+ fn make_fake_pool_reloc ( offset : i16 , cur_addr : u32 , pool_reloc : & ObjReloc ) -> Option < ObjReloc > {
462456 let offset_from_pool = pool_reloc. addend + offset as i64 ;
463457 let target_address = pool_reloc. target . address . checked_add_signed ( offset_from_pool) ?;
464458 let orig_section_index = pool_reloc. target . orig_section_index ?;
465- let section = sections. iter ( ) . find ( |s| s. orig_index == orig_section_index) ?;
466- let target_symbol = section
467- . symbols
468- . iter ( )
469- . find ( |s| s. size > 0 && ( s. address ..s. address + s. size ) . contains ( & target_address) ) ?;
470- let addend = ( target_address - target_symbol. address ) as i64 ;
459+ // We also need to create a fake target symbol to go inside our fake relocation.
460+ // This is because we don't have access to list of all symbols in this section, so we can't find
461+ // the real symbol yet. Instead we make a placeholder that has the correct `orig_section_index`
462+ // and `address` fields, and then later on when this information is displayed to the user, we
463+ // can find the real symbol by searching through the object's section's symbols for one that
464+ // contains this address.
465+ let fake_target_symbol = ObjSymbol {
466+ name : "" . to_string ( ) ,
467+ demangled_name : None ,
468+ address : target_address,
469+ section_address : 0 ,
470+ size : 0 ,
471+ size_known : false ,
472+ kind : Default :: default ( ) ,
473+ flags : Default :: default ( ) ,
474+ orig_section_index : Some ( orig_section_index) ,
475+ virtual_address : None ,
476+ original_index : None ,
477+ bytes : vec ! [ ] ,
478+ } ;
479+ // The addend is also fake because we don't know yet if the `target_address` here is the exact
480+ // start of the symbol or if it's in the middle of it.
481+ let fake_addend = 0 ;
471482 Some ( ObjReloc {
472483 flags : RelocationFlags :: Elf { r_type : elf:: R_PPC_NONE } ,
473484 address : cur_addr as u64 ,
474- target : target_symbol . clone ( ) ,
475- addend,
485+ target : fake_target_symbol ,
486+ addend : fake_addend ,
476487 } )
477488}
478489
@@ -491,7 +502,6 @@ fn generate_fake_pool_reloc_for_addr_mapping(
491502 address : u64 ,
492503 code : & [ u8 ] ,
493504 relocations : & [ ObjReloc ] ,
494- sections : & [ ObjSection ] ,
495505) -> HashMap < u32 , ObjReloc > {
496506 let mut active_pool_relocs = HashMap :: new ( ) ;
497507 let mut pool_reloc_for_addr = HashMap :: new ( ) ;
@@ -538,9 +548,7 @@ fn generate_fake_pool_reloc_for_addr_mapping(
538548 // This instruction doesn't have a real relocation, so it may be a reference to one of
539549 // the already-loaded pools.
540550 if let Some ( pool_reloc) = active_pool_relocs. get ( & addr_src_gpr. 0 ) {
541- if let Some ( fake_pool_reloc) =
542- make_fake_pool_reloc ( offset, cur_addr, pool_reloc, sections)
543- {
551+ if let Some ( fake_pool_reloc) = make_fake_pool_reloc ( offset, cur_addr, pool_reloc) {
544552 pool_reloc_for_addr. insert ( cur_addr, fake_pool_reloc) ;
545553 }
546554 if let Some ( addr_dst_gpr) = addr_dst_gpr {
0 commit comments