MCPcopy Create free account
hub / github.com/encounter/objdiff / diff_bss_section

Function diff_bss_section

objdiff-core/src/diff/data.rs:538–576  ·  view source on GitHub ↗

Compare the addresses and sizes of each symbol in the BSS sections.

(
    left_obj: &Object,
    right_obj: &Object,
    left_diff: &ObjectDiff,
    right_diff: &ObjectDiff,
    left_section_idx: usize,
    right_section_idx: usize,
)

Source from the content-addressed store, hash-verified

536
537/// Compare the addresses and sizes of each symbol in the BSS sections.
538pub fn diff_bss_section(
539 left_obj: &Object,
540 right_obj: &Object,
541 left_diff: &ObjectDiff,
542 right_diff: &ObjectDiff,
543 left_section_idx: usize,
544 right_section_idx: usize,
545) -> Result<(SectionDiff, SectionDiff)> {
546 let left_section = &left_obj.sections[left_section_idx];
547 let left_sizes = symbols_matching_section(&left_obj.symbols, left_section_idx)
548 .filter_map(|(_, s)| s.address.checked_sub(left_section.address).map(|a| (a, s.size)))
549 .collect::<Vec<_>>();
550 let right_section = &right_obj.sections[right_section_idx];
551 let right_sizes = symbols_matching_section(&right_obj.symbols, right_section_idx)
552 .filter_map(|(_, s)| s.address.checked_sub(right_section.address).map(|a| (a, s.size)))
553 .collect::<Vec<_>>();
554 let ops = capture_diff_slices(Algorithm::Patience, &left_sizes, &right_sizes);
555 let mut match_percent = get_diff_ratio(&ops, left_sizes.len(), right_sizes.len()) * 100.0;
556
557 // Use the highest match percent between two options:
558 // - Left symbols matching right symbols by name
559 // - Diff of the addresses and sizes of each symbol
560 let (generic_diff, _) = diff_generic_section(
561 left_obj,
562 right_obj,
563 left_diff,
564 right_diff,
565 left_section_idx,
566 right_section_idx,
567 )?;
568 if generic_diff.match_percent.unwrap_or(-1.0) > match_percent {
569 match_percent = generic_diff.match_percent.unwrap();
570 }
571
572 Ok((
573 SectionDiff { match_percent: Some(match_percent), data_diff: vec![], reloc_diff: vec![] },
574 SectionDiff { match_percent: None, data_diff: vec![], reloc_diff: vec![] },
575 ))
576}
577
578fn symbols_matching_section(
579 symbols: &[Symbol],

Callers 1

diff_objsFunction · 0.85

Calls 2

symbols_matching_sectionFunction · 0.85
diff_generic_sectionFunction · 0.85

Tested by

no test coverage detected