@@ -132,6 +132,9 @@ pub struct ApplyArgs {
132
132
#[ argp( positional, from_str_fn( native_path) ) ]
133
133
/// linked ELF
134
134
elf_file : Utf8NativePathBuf ,
135
+ #[ argp( switch) ]
136
+ /// always update anonymous local symbol names, even if they are similar
137
+ full : bool ,
135
138
}
136
139
137
140
#[ derive( FromArgs , PartialEq , Eq , Debug ) ]
@@ -1841,6 +1844,31 @@ fn diff(args: DiffArgs) -> Result<()> {
1841
1844
Ok ( ( ) )
1842
1845
}
1843
1846
1847
+ fn are_local_anonymous_names_similar < ' a > ( left : & ' a ObjSymbol , right : & ' a ObjSymbol ) -> bool {
1848
+ if left. flags . scope ( ) != ObjSymbolScope :: Local || right. flags . scope ( ) != ObjSymbolScope :: Local {
1849
+ return false ;
1850
+ }
1851
+
1852
+ let is_at_symbol =
1853
+ |name : & str | name. starts_with ( '@' ) && name[ 1 ..] . chars ( ) . all ( |c| c. is_numeric ( ) ) ;
1854
+
1855
+ if is_at_symbol ( & left. name ) && is_at_symbol ( & right. name ) {
1856
+ // consider e.g. @8280 -> @8536 equal
1857
+ return true ;
1858
+ }
1859
+
1860
+ let split_dollar_symbol = |name : & ' a str | -> Option < & ' a str > {
1861
+ name. rsplit_once ( '$' )
1862
+ . and_then ( |( prefix, suffix) | suffix. chars ( ) . all ( |c| c. is_numeric ( ) ) . then_some ( prefix) )
1863
+ } ;
1864
+
1865
+ // consider e.g. __arraydtor$3926 -> __arraydtor$7669 equal
1866
+ match ( split_dollar_symbol ( & left. name ) , split_dollar_symbol ( & right. name ) ) {
1867
+ ( Some ( left_prefix) , Some ( right_prefix) ) => left_prefix == right_prefix,
1868
+ _ => false ,
1869
+ }
1870
+ }
1871
+
1844
1872
fn apply ( args : ApplyArgs ) -> Result < ( ) > {
1845
1873
log:: info!( "Loading {}" , args. config) ;
1846
1874
let mut config_file = open_file ( & args. config , true ) ?;
@@ -1891,7 +1919,9 @@ fn apply(args: ApplyArgs) -> Result<()> {
1891
1919
let mut updated_sym = orig_sym. clone ( ) ;
1892
1920
let is_globalized = linked_sym. name . ends_with ( & format ! ( "_{:08X}" , linked_sym. address) ) ;
1893
1921
if ( is_globalized && !linked_sym. name . starts_with ( & orig_sym. name ) )
1894
- || ( !is_globalized && linked_sym. name != orig_sym. name )
1922
+ || ( !is_globalized
1923
+ && ( linked_sym. name != orig_sym. name
1924
+ && ( args. full || !are_local_anonymous_names_similar ( linked_sym, orig_sym) ) ) )
1895
1925
{
1896
1926
log:: info!(
1897
1927
"Changing name of {} (type {:?}) to {}" ,
0 commit comments