@@ -83,33 +83,56 @@ impl<'tcx> PreDefineCodegenMethods<'tcx> for CodegenCx<'_, 'tcx> {
8383
8484 let symbol_name = self . tcx . symbol_name ( instance) ;
8585 if symbol_name. name . contains ( "__rdl_alloc" ) {
86- self . weak_alias ( lldecl, & mangle_internal_symbol ( self . tcx , "__rust_alloc" ) ) ;
86+ self . weak_alias (
87+ lldecl,
88+ symbol_name. name ,
89+ & mangle_internal_symbol ( self . tcx , "__rust_alloc" ) ,
90+ ) ;
8791 }
8892 if symbol_name. name . contains ( "__rdl_dealloc" ) {
89- self . weak_alias ( lldecl, & mangle_internal_symbol ( self . tcx , "__rust_dealloc" ) ) ;
93+ self . weak_alias (
94+ lldecl,
95+ symbol_name. name ,
96+ & mangle_internal_symbol ( self . tcx , "__rust_dealloc" ) ,
97+ ) ;
9098 }
9199 if symbol_name. name . contains ( "__rdl_realloc" ) {
92- self . weak_alias ( lldecl, & mangle_internal_symbol ( self . tcx , "__rust_realloc" ) ) ;
100+ self . weak_alias (
101+ lldecl,
102+ symbol_name. name ,
103+ & mangle_internal_symbol ( self . tcx , "__rust_realloc" ) ,
104+ ) ;
93105 }
94106 if symbol_name. name . contains ( "__rdl_alloc_zeroed" ) {
95- self . weak_alias ( lldecl, & mangle_internal_symbol ( self . tcx , "__rust_alloc_zeroed" ) ) ;
107+ self . weak_alias (
108+ lldecl,
109+ symbol_name. name ,
110+ & mangle_internal_symbol ( self . tcx , "__rust_alloc_zeroed" ) ,
111+ ) ;
96112 }
97113
98114 self . instances . borrow_mut ( ) . insert ( instance, lldecl) ;
99115 }
100116
101- fn weak_alias ( & self , aliasee : Self :: Function , name : & str ) {
102- let ty = self . get_type_of_global ( aliasee) ;
103- let alias = llvm:: add_alias (
104- self . llmod ,
105- ty,
106- AddressSpace :: DATA ,
107- aliasee,
108- & CString :: new ( name) . unwrap ( ) ,
109- ) ;
110-
111- llvm:: set_linkage ( alias, llvm:: Linkage :: WeakAnyLinkage ) ;
112- self . add_compiler_used_global ( alias) ;
117+ fn weak_alias ( & self , aliasee : Self :: Function , aliasee_name : & str , name : & str ) {
118+ if self . tcx . sess . target . is_like_msvc {
119+ llvm:: add_module_linker_option (
120+ self . llmod ,
121+ & format ! ( "/alternatename:{name}={aliasee_name}" ) ,
122+ ) ;
123+ } else {
124+ let ty = self . get_type_of_global ( aliasee) ;
125+ let alias = llvm:: add_alias (
126+ self . llmod ,
127+ ty,
128+ AddressSpace :: DATA ,
129+ aliasee,
130+ & CString :: new ( name) . unwrap ( ) ,
131+ ) ;
132+
133+ llvm:: set_linkage ( alias, llvm:: Linkage :: WeakAnyLinkage ) ;
134+ self . add_compiler_used_global ( alias) ;
135+ }
113136 }
114137}
115138
0 commit comments