Skip to content

Commit 40f7791

Browse files
committed
Only pair up literals that match perfectly
1 parent f8e7478 commit 40f7791

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

objdiff-core/src/diff/mod.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -687,8 +687,7 @@ fn find_symbol(
687687
if is_symbol_compiler_generated_literal(in_symbol)
688688
&& matches!(section_kind, SectionKind::Data | SectionKind::Bss)
689689
{
690-
let mut closest_match_symbol_idx = None;
691-
let mut closest_match_percent = 0.0;
690+
let mut matching_symbol_idx = None;
692691
for (symbol_idx, symbol) in unmatched_symbols(obj, used) {
693692
let Some(section_index) = symbol.section else {
694693
continue;
@@ -701,31 +700,27 @@ fn find_symbol(
701700
}
702701
match section_kind {
703702
SectionKind::Data => {
704-
// For data, we try to pick the first symbol that matches 100%.
705-
// If no symbol is a perfect match, pick whichever matches the closest.
703+
// For data, pick the first symbol that has the exact matching bytes and relocations.
706704
if let Ok((left_diff, _right_diff)) =
707705
diff_data_symbol(in_obj, obj, in_symbol_idx, symbol_idx)
708706
&& let Some(match_percent) = left_diff.match_percent
709-
&& match_percent > closest_match_percent
707+
&& match_percent == 100.0
710708
{
711-
closest_match_symbol_idx = Some(symbol_idx);
712-
closest_match_percent = match_percent;
713-
if match_percent == 100.0 {
714-
break;
715-
}
709+
matching_symbol_idx = Some(symbol_idx);
710+
break;
716711
}
717712
}
718713
SectionKind::Bss => {
719-
// For BSS, we simply pick the first symbol that has the exact matching size.
714+
// For BSS, pick the first symbol that has the exact matching size.
720715
if in_symbol.size == symbol.size {
721-
closest_match_symbol_idx = Some(symbol_idx);
716+
matching_symbol_idx = Some(symbol_idx);
722717
break;
723718
}
724719
}
725720
_ => unreachable!(),
726721
}
727722
}
728-
return closest_match_symbol_idx;
723+
return matching_symbol_idx;
729724
}
730725

731726
// Try to find an exact name match

0 commit comments

Comments
 (0)