@@ -48,13 +48,12 @@ impl ObjArch for ObjArchPpc {
48
48
relocations : & [ ObjReloc ] ,
49
49
line_info : & BTreeMap < u64 , u32 > ,
50
50
config : & DiffObjConfig ,
51
- sections : & [ ObjSection ] ,
52
51
) -> Result < ProcessCodeResult > {
53
52
let ins_count = code. len ( ) / 4 ;
54
53
let mut ops = Vec :: < u16 > :: with_capacity ( ins_count) ;
55
54
let mut insts = Vec :: < ObjIns > :: with_capacity ( ins_count) ;
56
55
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) ;
58
57
for ( cur_addr, mut ins) in InsIter :: new ( code, address as u32 ) {
59
58
let reloc = relocations. iter ( ) . find ( |r| ( r. address as u32 & !3 ) == cur_addr) ;
60
59
if let Some ( reloc) = reloc {
@@ -453,26 +452,38 @@ fn get_offset_and_addr_gpr_for_possible_pool_reference(
453
452
// there isn't really a relocation here, as copying the pool relocation's type wouldn't make sense.
454
453
// Also, if this instruction is accessing the middle of a symbol instead of the start, we add an
455
454
// 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 > {
462
456
let offset_from_pool = pool_reloc. addend + offset as i64 ;
463
457
let target_address = pool_reloc. target . address . checked_add_signed ( offset_from_pool) ?;
464
458
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 ;
471
482
Some ( ObjReloc {
472
483
flags : RelocationFlags :: Elf { r_type : elf:: R_PPC_NONE } ,
473
484
address : cur_addr as u64 ,
474
- target : target_symbol . clone ( ) ,
475
- addend,
485
+ target : fake_target_symbol ,
486
+ addend : fake_addend ,
476
487
} )
477
488
}
478
489
@@ -491,7 +502,6 @@ fn generate_fake_pool_reloc_for_addr_mapping(
491
502
address : u64 ,
492
503
code : & [ u8 ] ,
493
504
relocations : & [ ObjReloc ] ,
494
- sections : & [ ObjSection ] ,
495
505
) -> HashMap < u32 , ObjReloc > {
496
506
let mut active_pool_relocs = HashMap :: new ( ) ;
497
507
let mut pool_reloc_for_addr = HashMap :: new ( ) ;
@@ -538,9 +548,7 @@ fn generate_fake_pool_reloc_for_addr_mapping(
538
548
// This instruction doesn't have a real relocation, so it may be a reference to one of
539
549
// the already-loaded pools.
540
550
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) {
544
552
pool_reloc_for_addr. insert ( cur_addr, fake_pool_reloc) ;
545
553
}
546
554
if let Some ( addr_dst_gpr) = addr_dst_gpr {
0 commit comments