@@ -84,6 +84,42 @@ pub(super) fn mangle<'tcx>(
8484 std:: mem:: take ( & mut p. out )
8585}
8686
87+ pub fn mangle_cgu < ' tcx > ( tcx : TyCtxt < ' tcx > , krate : CrateNum , cgu_name : Result < u64 , & str > ) -> String {
88+ let prefix = "_R" ;
89+ let mut p: V0SymbolMangler < ' _ > = V0SymbolMangler {
90+ tcx,
91+ start_offset : prefix. len ( ) ,
92+ is_exportable : false ,
93+ paths : FxHashMap :: default ( ) ,
94+ types : FxHashMap :: default ( ) ,
95+ consts : FxHashMap :: default ( ) ,
96+ binders : vec ! [ ] ,
97+ out : String :: from ( prefix) ,
98+ } ;
99+
100+ match cgu_name {
101+ Ok ( cgu_index) => {
102+ // If we have a CGU index, we can easily encode this with the shim mechanism.
103+ p. path_append_ns ( |p| p. print_def_path ( krate. as_def_id ( ) , & [ ] ) , 'S' , cgu_index, "cgu" )
104+ . unwrap ( ) ;
105+ }
106+ Err ( name) => {
107+ // In incremental compilation we just have a name and no index. Encode this as a str-typed generic argument to cgu shim for now.
108+ p. out . push ( 'I' ) ;
109+ p. path_append_ns ( |p| p. print_def_path ( krate. as_def_id ( ) , & [ ] ) , 'S' , 0 , "cgu" ) . unwrap ( ) ;
110+ p. push ( "KRe" ) ;
111+
112+ for byte in name. as_bytes ( ) {
113+ let _ = write ! ( p. out, "{byte:02x}" ) ;
114+ }
115+
116+ p. push ( "_E" ) ;
117+ }
118+ }
119+
120+ std:: mem:: take ( & mut p. out )
121+ }
122+
87123pub fn mangle_internal_symbol < ' tcx > ( tcx : TyCtxt < ' tcx > , item_name : & str ) -> String {
88124 match item_name {
89125 // rust_eh_personality must not be renamed as LLVM hard-codes the name
0 commit comments