MCPcopy Index your code
hub / github.com/encounter/objdiff / perform_data_flow_analysis

Function perform_data_flow_analysis

objdiff-core/src/obj/read.rs:640–700  ·  view source on GitHub ↗
(obj: &mut Object, config: &DiffObjConfig)

Source from the content-addressed store, hash-verified

638}
639
640fn 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 &section.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, &section.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);

Callers 1

parseFunction · 0.85

Calls 6

data_rangeMethod · 0.80
pushMethod · 0.80
iter_mutMethod · 0.80
data_flow_analysisMethod · 0.45

Tested by

no test coverage detected