(obj: &mut Object, config: &DiffObjConfig)
| 638 | } |
| 639 | |
| 640 | fn perform_data_flow_analysis(obj: &mut Object, config: &DiffObjConfig) -> Result<()> { |
| 641 | // If neither of these settings are on, no flow analysis to perform |
| 642 | if !config.analyze_data_flow && !config.ppc_calculate_pool_relocations { |
| 643 | return Ok(()); |
| 644 | } |
| 645 | |
| 646 | let mut generated_relocations = Vec::<(usize, Vec<Relocation>)>::new(); |
| 647 | let mut generated_flow_results = Vec::<(Symbol, Box<dyn FlowAnalysisResult>)>::new(); |
| 648 | for (section_index, section) in obj.sections.iter().enumerate() { |
| 649 | if section.kind != SectionKind::Code { |
| 650 | continue; |
| 651 | } |
| 652 | for symbol in obj.symbols.iter() { |
| 653 | if symbol.section != Some(section_index) { |
| 654 | continue; |
| 655 | } |
| 656 | if symbol.kind != SymbolKind::Function { |
| 657 | continue; |
| 658 | } |
| 659 | let code = |
| 660 | section.data_range(symbol.address, symbol.size as usize).ok_or_else(|| { |
| 661 | anyhow!( |
| 662 | "Symbol data out of bounds: {:#x}..{:#x}", |
| 663 | symbol.address, |
| 664 | symbol.address + symbol.size |
| 665 | ) |
| 666 | })?; |
| 667 | |
| 668 | // Optional pooled relocation computation |
| 669 | // Long view: This could be replaced by the full data flow analysis |
| 670 | // once that feature has stabilized. |
| 671 | if config.ppc_calculate_pool_relocations { |
| 672 | let relocations = obj.arch.generate_pooled_relocations( |
| 673 | symbol.address, |
| 674 | code, |
| 675 | §ion.relocations, |
| 676 | &obj.symbols, |
| 677 | ); |
| 678 | generated_relocations.push((section_index, relocations)); |
| 679 | } |
| 680 | |
| 681 | // Optional full data flow analysis |
| 682 | if config.analyze_data_flow |
| 683 | && let Some(flow_result) = |
| 684 | obj.arch.data_flow_analysis(obj, symbol, code, §ion.relocations) |
| 685 | { |
| 686 | generated_flow_results.push((symbol.clone(), flow_result)); |
| 687 | } |
| 688 | } |
| 689 | } |
| 690 | for (symbol, flow_result) in generated_flow_results { |
| 691 | obj.add_flow_analysis_result(&symbol, flow_result); |
| 692 | } |
| 693 | for (section_index, mut relocations) in generated_relocations { |
| 694 | obj.sections[section_index].relocations.append(&mut relocations); |
| 695 | } |
| 696 | for section in obj.sections.iter_mut() { |
| 697 | section.relocations.sort_by_key(|r| r.address); |
no test coverage detected