@@ -11,6 +11,27 @@ use crate::{
1111 obj:: { ObjInfo , ObjSection , SymbolRef } ,
1212} ;
1313
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+
1435pub fn diff_bss_symbol (
1536 left_obj : & ObjInfo ,
1637 right_obj : & ObjInfo ,
@@ -40,14 +61,19 @@ pub fn no_diff_symbol(_obj: &ObjInfo, symbol_ref: SymbolRef) -> ObjSymbolDiff {
4061 ObjSymbolDiff { symbol_ref, diff_symbol : None , instructions : vec ! [ ] , match_percent : None }
4162}
4263
43- pub fn diff_data (
64+ /// Compare the data sections of two object files.
65+ pub fn diff_data_section (
4466 left : & ObjSection ,
4567 right : & ObjSection ,
4668) -> Result < ( ObjSectionDiff , ObjSectionDiff ) > {
4769 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 ] ;
4874 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 ;
5177
5278 let mut left_diff = Vec :: < ObjDataDiff > :: new ( ) ;
5379 let mut right_diff = Vec :: < ObjDataDiff > :: new ( ) ;
@@ -168,3 +194,24 @@ pub fn diff_data_symbol(
168194 } ,
169195 ) )
170196}
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