@@ -15,7 +15,7 @@ use crate::{
15
15
diff:: { ArmArchVersion , ArmR9Usage , DiffObjConfig , display:: InstructionPart } ,
16
16
obj:: {
17
17
InstructionRef , Relocation , RelocationFlags , ResolvedInstructionRef , ResolvedRelocation ,
18
- ScannedInstruction , SymbolFlag , SymbolFlagSet , SymbolKind ,
18
+ ScannedInstruction , Section , SectionKind , Symbol , SymbolFlag , SymbolFlagSet , SymbolKind ,
19
19
} ,
20
20
} ;
21
21
@@ -32,7 +32,8 @@ impl ArchArm {
32
32
let endianness = file. endianness ( ) ;
33
33
match file {
34
34
object:: File :: Elf32 ( _) => {
35
- let disasm_modes = Self :: elf_get_mapping_symbols ( file) ;
35
+ // The disasm_modes mapping is populated later in the post_init step so that we have access to merged sections.
36
+ let disasm_modes = BTreeMap :: new ( ) ;
36
37
let detected_version = Self :: elf_detect_arm_version ( file) ?;
37
38
Ok ( Self { disasm_modes, detected_version, endianness } )
38
39
}
@@ -73,18 +74,22 @@ impl ArchArm {
73
74
Ok ( None )
74
75
}
75
76
76
- fn elf_get_mapping_symbols ( file : & object:: File ) -> BTreeMap < usize , Vec < DisasmMode > > {
77
- file. sections ( )
78
- . filter ( |s| s. kind ( ) == object:: SectionKind :: Text )
79
- . map ( |s| {
80
- let index = s. index ( ) ;
81
- let mut mapping_symbols: Vec < _ > = file
82
- . symbols ( )
83
- . filter ( |s| s. section_index ( ) . map ( |i| i == index) . unwrap_or ( false ) )
84
- . filter_map ( |s| DisasmMode :: from_symbol ( & s) )
77
+ fn get_mapping_symbols (
78
+ sections : & [ Section ] ,
79
+ symbols : & [ Symbol ] ,
80
+ ) -> BTreeMap < usize , Vec < DisasmMode > > {
81
+ sections
82
+ . iter ( )
83
+ . enumerate ( )
84
+ . filter ( |( _, section) | section. kind == SectionKind :: Code )
85
+ . map ( |( index, _) | {
86
+ let mut mapping_symbols: Vec < _ > = symbols
87
+ . iter ( )
88
+ . filter ( |s| s. section . map ( |i| i == index) . unwrap_or ( false ) )
89
+ . filter_map ( DisasmMode :: from_symbol)
85
90
. collect ( ) ;
86
91
mapping_symbols. sort_unstable_by_key ( |x| x. address ) ;
87
- ( s . index ( ) . 0 - 1 , mapping_symbols)
92
+ ( index, mapping_symbols)
88
93
} )
89
94
. collect ( )
90
95
}
@@ -178,6 +183,10 @@ impl ArchArm {
178
183
}
179
184
180
185
impl Arch for ArchArm {
186
+ fn post_init ( & mut self , sections : & [ Section ] , symbols : & [ Symbol ] ) {
187
+ self . disasm_modes = Self :: get_mapping_symbols ( sections, symbols) ;
188
+ }
189
+
181
190
fn scan_instructions (
182
191
& self ,
183
192
address : u64 ,
@@ -441,7 +450,7 @@ impl Arch for ArchArm {
441
450
442
451
fn extra_symbol_flags ( & self , symbol : & object:: Symbol ) -> SymbolFlagSet {
443
452
let mut flags = SymbolFlagSet :: default ( ) ;
444
- if DisasmMode :: from_symbol ( symbol) . is_some ( ) {
453
+ if DisasmMode :: from_object_symbol ( symbol) . is_some ( ) {
445
454
flags |= SymbolFlag :: Hidden ;
446
455
}
447
456
flags
@@ -455,12 +464,17 @@ struct DisasmMode {
455
464
}
456
465
457
466
impl DisasmMode {
458
- fn from_symbol < ' a > ( sym : & object:: Symbol < ' a , ' _ , & ' a [ u8 ] > ) -> Option < Self > {
467
+ fn from_object_symbol < ' a > ( sym : & object:: Symbol < ' a , ' _ , & ' a [ u8 ] > ) -> Option < Self > {
459
468
sym. name ( )
460
469
. ok ( )
461
470
. and_then ( unarm:: ParseMode :: from_mapping_symbol)
462
471
. map ( |mapping| DisasmMode { address : sym. address ( ) as u32 , mapping } )
463
472
}
473
+
474
+ fn from_symbol ( sym : & Symbol ) -> Option < Self > {
475
+ unarm:: ParseMode :: from_mapping_symbol ( & sym. name )
476
+ . map ( |mapping| DisasmMode { address : sym. address as u32 , mapping } )
477
+ }
464
478
}
465
479
466
480
fn push_args (
0 commit comments