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

Function diff_generic_section

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

Compares a section of two object files. This essentially adds up the match percentage of each symbol in the section.

(
    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

504/// Compares a section of two object files.
505/// This essentially adds up the match percentage of each symbol in the section.
506pub fn diff_generic_section(
507 left_obj: &Object,
508 _right_obj: &Object,
509 left_diff: &ObjectDiff,
510 _right_diff: &ObjectDiff,
511 left_section_idx: usize,
512 _right_section_idx: usize,
513) -> Result<(SectionDiff, SectionDiff)> {
514 let match_percent = if symbols_matching_section(&left_obj.symbols, left_section_idx)
515 .map(|(i, _)| &left_diff.symbols[i])
516 .all(|d| d.match_percent == Some(100.0))
517 {
518 100.0 // Avoid fp precision issues
519 } else {
520 let (matched, total) = symbols_matching_section(&left_obj.symbols, left_section_idx)
521 .map(|(i, s)| (s, &left_diff.symbols[i]))
522 .fold((0.0, 0.0), |(matched, total), (s, d)| {
523 (matched + d.match_percent.unwrap_or(0.0) * s.size as f32, total + s.size as f32)
524 });
525 if total == 0.0 { 100.0 } else { matched / total }
526 };
527 Ok((
528 SectionDiff { match_percent: Some(match_percent), data_diff: vec![], reloc_diff: vec![] },
529 SectionDiff { match_percent: None, data_diff: vec![], reloc_diff: vec![] },
530 ))
531}
532
533pub fn no_diff_bss_section() -> Result<SectionDiff> {
534 Ok(SectionDiff { match_percent: Some(0.0), data_diff: vec![], reloc_diff: vec![] })

Callers 3

diff_objsFunction · 0.85
diff_data_sectionFunction · 0.85
diff_bss_sectionFunction · 0.85

Calls 1

symbols_matching_sectionFunction · 0.85

Tested by

no test coverage detected