Skip to content

Commit 25cf38d

Browse files
committed
Move is_name_compiler_generated into SymbolFlag & filter out File symbols
1 parent e296ec9 commit 25cf38d

29 files changed

Lines changed: 1883 additions & 2714 deletions

objdiff-core/src/diff/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ fn find_symbol(
699699

700700
// Match compiler-generated symbols against each other (e.g. @251 -> @60)
701701
// If they are in the same section and have the same value
702-
if in_symbol.is_name_compiler_generated
702+
if in_symbol.flags.contains(SymbolFlag::CompilerGenerated)
703703
&& matches!(section_kind, SectionKind::Code | SectionKind::Data | SectionKind::Bss)
704704
{
705705
let mut closest_match_symbol_idx = None;
@@ -711,7 +711,7 @@ fn find_symbol(
711711
if obj.sections[section_index].name != section_name {
712712
continue;
713713
}
714-
if !symbol.is_name_compiler_generated {
714+
if !symbol.flags.contains(SymbolFlag::CompilerGenerated) {
715715
continue;
716716
}
717717
match section_kind {

objdiff-core/src/obj/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub enum SectionKind {
3737

3838
flags! {
3939
#[derive(Hash)]
40-
pub enum SymbolFlag: u8 {
40+
pub enum SymbolFlag: u16 {
4141
Global,
4242
Local,
4343
Weak,
@@ -50,6 +50,8 @@ flags! {
5050
SizeInferred,
5151
/// Symbol should be ignored by any diffing
5252
Ignored,
53+
/// Symbol name is compiler-generated; compare by value instead of name
54+
CompilerGenerated,
5355
}
5456
}
5557

@@ -265,7 +267,6 @@ pub struct Symbol {
265267
pub name: String,
266268
pub demangled_name: Option<String>,
267269
pub normalized_name: Option<String>,
268-
pub is_name_compiler_generated: bool,
269270
pub address: u64,
270271
pub size: u64,
271272
pub kind: SymbolKind,
@@ -406,7 +407,6 @@ static DUMMY_SYMBOL: Symbol = Symbol {
406407
name: String::new(),
407408
demangled_name: None,
408409
normalized_name: None,
409-
is_name_compiler_generated: false,
410410
address: 0,
411411
size: 0,
412412
kind: SymbolKind::Unknown,

objdiff-core/src/obj/read.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use alloc::{
33
collections::BTreeMap,
44
format,
55
string::{String, ToString},
6+
vec,
67
vec::Vec,
78
};
89
use core::{cmp::Ordering, num::NonZeroU64};
@@ -138,13 +139,14 @@ fn map_symbol(
138139
.and_then(|v| v.get(symbol.index().0).cloned());
139140
let section = symbol.section_index().and_then(|i| section_indices.get(i.0).copied());
140141
let normalized_name = get_normalized_symbol_name(&name);
141-
let is_name_compiler_generated = is_symbol_name_compiler_generated(&name);
142+
if is_symbol_name_compiler_generated(&name) {
143+
flags |= SymbolFlag::CompilerGenerated;
144+
}
142145

143146
Ok(Symbol {
144147
name,
145148
demangled_name,
146149
normalized_name,
147-
is_name_compiler_generated,
148150
address,
149151
size,
150152
kind,
@@ -169,6 +171,7 @@ fn map_symbols(
169171
let mut max_index = 0;
170172
let mut obj_symbols = obj_file
171173
.symbols()
174+
.filter(|s| s.kind() != object::SymbolKind::File)
172175
.inspect(|sym| max_index = max_index.max(sym.index().0))
173176
.collect::<Vec<_>>();
174177
obj_symbols.sort_by(|a, b| {
@@ -241,7 +244,6 @@ fn add_section_symbols(sections: &[Section], symbols: &mut Vec<Symbol>) {
241244
name,
242245
demangled_name: None,
243246
normalized_name: None,
244-
is_name_compiler_generated: false,
245247
address: 0,
246248
size,
247249
kind: SymbolKind::Section,

objdiff-core/src/obj/snapshots/objdiff_core__obj__read__test__combine_sections.snap

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ expression: "(sections, symbols)"
115115
name: ".data",
116116
demangled_name: None,
117117
normalized_name: None,
118-
is_name_compiler_generated: false,
119118
address: 0,
120119
size: 0,
121120
kind: Section,
@@ -130,7 +129,6 @@ expression: "(sections, symbols)"
130129
name: "symbol",
131130
demangled_name: None,
132131
normalized_name: None,
133-
is_name_compiler_generated: false,
134132
address: 4,
135133
size: 4,
136134
kind: Object,
@@ -145,7 +143,6 @@ expression: "(sections, symbols)"
145143
name: "function",
146144
demangled_name: None,
147145
normalized_name: None,
148-
is_name_compiler_generated: false,
149146
address: 0,
150147
size: 8,
151148
kind: Function,
@@ -160,7 +157,6 @@ expression: "(sections, symbols)"
160157
name: ".data",
161158
demangled_name: None,
162159
normalized_name: None,
163-
is_name_compiler_generated: false,
164160
address: 0,
165161
size: 0,
166162
kind: Unknown,

objdiff-core/tests/snapshots/arch_arm__combine_text_sections-2.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ expression: output
44
---
55
[(Line(90), Dim, 5), (Address(0), Dim, 5), (Spacing(4), Normal, 0), (Opcode("ldr", 32792), Normal, 10), (Argument(Opaque("r12")), Normal, 0), (Basic(", "), Normal, 0), (Basic("["), Normal, 0), (Argument(Opaque("pc")), Normal, 0), (Basic(", "), Normal, 0), (Basic("#"), Normal, 0), (Argument(Signed(0)), Normal, 0), (Basic("]"), Normal, 0), (Basic(" (->"), Normal, 0), (BranchDest(8), Normal, 0), (Basic(")"), Normal, 0), (Eol, Normal, 0)]
66
[(Line(90), Dim, 5), (Address(4), Dim, 5), (Spacing(4), Normal, 0), (Opcode("bx", 32777), Normal, 10), (Argument(Opaque("r12")), Normal, 0), (Eol, Normal, 0)]
7-
[(Line(90), Dim, 5), (Address(8), Dim, 5), (Spacing(4), Normal, 0), (Opcode(".word", 65534), Normal, 10), (Symbol(Symbol { name: "esEnemyDraw", demangled_name: None, normalized_name: None, is_name_compiler_generated: false, address: 0, size: 0, kind: Unknown, section: None, flags: FlagSet(Global), align: None, virtual_address: None }), Bright, 0), (Eol, Normal, 0)]
7+
[(Line(90), Dim, 5), (Address(8), Dim, 5), (Spacing(4), Normal, 0), (Opcode(".word", 65534), Normal, 10), (Symbol(Symbol { name: "esEnemyDraw", demangled_name: None, normalized_name: None, address: 0, size: 0, kind: Unknown, section: None, flags: FlagSet(Global), align: None, virtual_address: None }), Bright, 0), (Eol, Normal, 0)]

0 commit comments

Comments
 (0)