@@ -11,6 +11,27 @@ 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
+
14
35
pub fn diff_bss_symbol (
15
36
left_obj : & ObjInfo ,
16
37
right_obj : & ObjInfo ,
@@ -40,14 +61,19 @@ pub fn no_diff_symbol(_obj: &ObjInfo, symbol_ref: SymbolRef) -> ObjSymbolDiff {
40
61
ObjSymbolDiff { symbol_ref, diff_symbol : None , instructions : vec ! [ ] , match_percent : None }
41
62
}
42
63
43
- pub fn diff_data (
64
+ /// Compare the data sections of two object files.
65
+ pub fn diff_data_section (
44
66
left : & ObjSection ,
45
67
right : & ObjSection ,
46
68
) -> Result < ( ObjSectionDiff , ObjSectionDiff ) > {
47
69
let deadline = Instant :: now ( ) + Duration :: from_secs ( 5 ) ;
70
+ let left_max = left. symbols . iter ( ) . map ( |s| s. section_address + s. size ) . max ( ) . unwrap_or ( 0 ) ;
71
+ let right_max = right. symbols . iter ( ) . map ( |s| s. section_address + s. size ) . max ( ) . unwrap_or ( 0 ) ;
72
+ let left_data = & left. data [ ..left_max as usize ] ;
73
+ let right_data = & right. data [ ..right_max as usize ] ;
48
74
let ops =
49
- capture_diff_slices_deadline ( Algorithm :: Patience , & left . data , & right . data , Some ( deadline) ) ;
50
- let match_percent = get_diff_ratio ( & ops, left . data . len ( ) , right . data . len ( ) ) * 100.0 ;
75
+ 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 ;
51
77
52
78
let mut left_diff = Vec :: < ObjDataDiff > :: new ( ) ;
53
79
let mut right_diff = Vec :: < ObjDataDiff > :: new ( ) ;
@@ -168,3 +194,24 @@ pub fn diff_data_symbol(
168
194
} ,
169
195
) )
170
196
}
197
+
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 (
201
+ left : & ObjSection ,
202
+ _right : & ObjSection ,
203
+ left_diff : & ObjSectionDiff ,
204
+ _right_diff : & ObjSectionDiff ,
205
+ ) -> 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 ;
213
+ Ok ( (
214
+ ObjSectionDiff { symbols : vec ! [ ] , data_diff : vec ! [ ] , match_percent : Some ( match_percent) } ,
215
+ ObjSectionDiff { symbols : vec ! [ ] , data_diff : vec ! [ ] , match_percent : Some ( match_percent) } ,
216
+ ) )
217
+ }
0 commit comments