@@ -11,27 +11,6 @@ use crate::{
11
11
obj:: { ObjInfo , ObjSection , SymbolRef } ,
12
12
} ;
13
13
14
- /// Compare the addresses and sizes of each symbol in the BSS sections.
15
- pub fn diff_bss_section (
16
- left : & ObjSection ,
17
- right : & ObjSection ,
18
- ) -> Result < ( ObjSectionDiff , ObjSectionDiff ) > {
19
- let deadline = Instant :: now ( ) + Duration :: from_secs ( 5 ) ;
20
- let left_sizes = left. symbols . iter ( ) . map ( |s| ( s. section_address , s. size ) ) . collect :: < Vec < _ > > ( ) ;
21
- let right_sizes = right. symbols . iter ( ) . map ( |s| ( s. section_address , s. size ) ) . collect :: < Vec < _ > > ( ) ;
22
- let ops = capture_diff_slices_deadline (
23
- Algorithm :: Patience ,
24
- & left_sizes,
25
- & right_sizes,
26
- Some ( deadline) ,
27
- ) ;
28
- let match_percent = get_diff_ratio ( & ops, left_sizes. len ( ) , right_sizes. len ( ) ) * 100.0 ;
29
- Ok ( (
30
- ObjSectionDiff { symbols : vec ! [ ] , data_diff : vec ! [ ] , match_percent : Some ( match_percent) } ,
31
- ObjSectionDiff { symbols : vec ! [ ] , data_diff : vec ! [ ] , match_percent : Some ( match_percent) } ,
32
- ) )
33
- }
34
-
35
14
pub fn diff_bss_symbol (
36
15
left_obj : & ObjInfo ,
37
16
right_obj : & ObjInfo ,
@@ -65,6 +44,8 @@ pub fn no_diff_symbol(_obj: &ObjInfo, symbol_ref: SymbolRef) -> ObjSymbolDiff {
65
44
pub fn diff_data_section (
66
45
left : & ObjSection ,
67
46
right : & ObjSection ,
47
+ left_section_diff : & ObjSectionDiff ,
48
+ right_section_diff : & ObjSectionDiff ,
68
49
) -> Result < ( ObjSectionDiff , ObjSectionDiff ) > {
69
50
let deadline = Instant :: now ( ) + Duration :: from_secs ( 5 ) ;
70
51
let left_max = left. symbols . iter ( ) . map ( |s| s. section_address + s. size ) . max ( ) . unwrap_or ( 0 ) ;
@@ -73,7 +54,6 @@ pub fn diff_data_section(
73
54
let right_data = & right. data [ ..right_max as usize ] ;
74
55
let ops =
75
56
capture_diff_slices_deadline ( Algorithm :: Patience , left_data, right_data, Some ( deadline) ) ;
76
- let match_percent = get_diff_ratio ( & ops, left_data. len ( ) , right_data. len ( ) ) * 100.0 ;
77
57
78
58
let mut left_diff = Vec :: < ObjDataDiff > :: new ( ) ;
79
59
let mut right_diff = Vec :: < ObjDataDiff > :: new ( ) ;
@@ -143,18 +123,11 @@ pub fn diff_data_section(
143
123
}
144
124
}
145
125
146
- Ok ( (
147
- ObjSectionDiff {
148
- symbols : vec ! [ ] ,
149
- data_diff : left_diff,
150
- match_percent : Some ( match_percent) ,
151
- } ,
152
- ObjSectionDiff {
153
- symbols : vec ! [ ] ,
154
- data_diff : right_diff,
155
- match_percent : Some ( match_percent) ,
156
- } ,
157
- ) )
126
+ let ( mut left_section_diff, mut right_section_diff) =
127
+ diff_generic_section ( left, right, left_section_diff, right_section_diff) ?;
128
+ left_section_diff. data_diff = left_diff;
129
+ right_section_diff. data_diff = right_diff;
130
+ Ok ( ( left_section_diff, right_section_diff) )
158
131
}
159
132
160
133
pub fn diff_data_symbol (
@@ -195,21 +168,24 @@ pub fn diff_data_symbol(
195
168
) )
196
169
}
197
170
198
- /// Compare the text sections of two object files.
199
- /// This essentially adds up the match percentage of each symbol in the text section.
200
- pub fn diff_text_section (
171
+ /// Compares a section of two object files.
172
+ /// This essentially adds up the match percentage of each symbol in the section.
173
+ pub fn diff_generic_section (
201
174
left : & ObjSection ,
202
175
_right : & ObjSection ,
203
176
left_diff : & ObjSectionDiff ,
204
177
_right_diff : & ObjSectionDiff ,
205
178
) -> Result < ( ObjSectionDiff , ObjSectionDiff ) > {
206
- let match_percent = left
207
- . symbols
208
- . iter ( )
209
- . zip ( left_diff. symbols . iter ( ) )
210
- . map ( |( s, d) | d. match_percent . unwrap_or ( 0.0 ) * s. size as f32 )
211
- . sum :: < f32 > ( )
212
- / left. size as f32 ;
179
+ let match_percent = if left_diff. symbols . iter ( ) . all ( |d| d. match_percent == Some ( 100.0 ) ) {
180
+ 100.0 // Avoid fp precision issues
181
+ } else {
182
+ left. symbols
183
+ . iter ( )
184
+ . zip ( left_diff. symbols . iter ( ) )
185
+ . map ( |( s, d) | d. match_percent . unwrap_or ( 0.0 ) * s. size as f32 )
186
+ . sum :: < f32 > ( )
187
+ / left. size as f32
188
+ } ;
213
189
Ok ( (
214
190
ObjSectionDiff { symbols : vec ! [ ] , data_diff : vec ! [ ] , match_percent : Some ( match_percent) } ,
215
191
ObjSectionDiff { symbols : vec ! [ ] , data_diff : vec ! [ ] , match_percent : Some ( match_percent) } ,
0 commit comments