Skip to content

Commit 420a6d7

Browse files
committed
Implement automatic symbol pairing for MSVC generated static functions
1 parent fb1d434 commit 420a6d7

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

objdiff-core/src/diff/mod.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -680,16 +680,16 @@ fn symbol_section_kind(obj: &Object, symbol: &Symbol) -> SectionKind {
680680
}
681681
}
682682

683-
/// Check if a symbol is a compiler-generated literal like @1234.
683+
/// Check if a symbol is a compiler-generated symbol like @1234 or _$E1234.
684684
fn is_symbol_compiler_generated_literal(symbol: &Symbol) -> bool {
685-
if !symbol.name.starts_with('@') {
686-
return false;
685+
if symbol.name.starts_with("_$E") && symbol.name[3..].chars().all(char::is_numeric) {
686+
return true;
687687
}
688-
if !symbol.name[1..].chars().all(char::is_numeric) {
688+
if symbol.name.starts_with('@') && symbol.name[1..].chars().all(char::is_numeric) {
689689
// Exclude @stringBase0, @GUARD@, etc.
690-
return false;
690+
return true;
691691
}
692-
true
692+
false
693693
}
694694

695695
fn find_symbol(
@@ -706,7 +706,7 @@ fn find_symbol(
706706
// Match compiler-generated symbols against each other (e.g. @251 -> @60)
707707
// If they are in the same section and have the same value
708708
if is_symbol_compiler_generated_literal(in_symbol)
709-
&& matches!(section_kind, SectionKind::Data | SectionKind::Bss)
709+
&& matches!(section_kind, SectionKind::Code | SectionKind::Data | SectionKind::Bss)
710710
{
711711
let mut closest_match_symbol_idx = None;
712712
let mut closest_match_percent = 0.0;
@@ -721,8 +721,8 @@ fn find_symbol(
721721
continue;
722722
}
723723
match section_kind {
724-
SectionKind::Data => {
725-
// For data, pick the first symbol with exactly matching bytes and relocations.
724+
SectionKind::Data | SectionKind::Code => {
725+
// For code or data, pick the first symbol with exactly matching bytes and relocations.
726726
// If no symbols match exactly, and `fuzzy_literals` is true, pick the closest
727727
// plausible match instead.
728728
if let Ok((left_diff, _right_diff)) =

0 commit comments

Comments
 (0)