@@ -67,25 +67,12 @@ impl CoverageInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
67
67
let mut pgo_func_name_var_map = coverage_context. pgo_func_name_var_map . borrow_mut ( ) ;
68
68
pgo_func_name_var_map
69
69
. entry ( instance)
70
- . or_insert_with ( || self . create_pgo_func_name_var ( instance) )
70
+ . or_insert_with ( || create_pgo_func_name_var ( self , instance) )
71
71
} else {
72
72
bug ! ( "Could not get the `coverage_context`" ) ;
73
73
}
74
74
}
75
75
76
- /// Calls llvm::createPGOFuncNameVar() with the given function instance's
77
- /// mangled function name. The LLVM API returns an llvm::GlobalVariable
78
- /// containing the function name, with the specific variable name and
79
- /// linkage required by LLVM InstrProf source-based coverage
80
- /// instrumentation. Use `bx.get_pgo_func_name_var()` to ensure the variable
81
- /// is only created once per `Instance`.
82
- fn create_pgo_func_name_var ( & self , instance : Instance < ' tcx > ) -> & ' ll llvm:: Value {
83
- let mangled_fn_name = CString :: new ( self . tcx . symbol_name ( instance) . name )
84
- . expect ( "error converting function name to C string" ) ;
85
- let llfn = self . get_fn ( instance) ;
86
- unsafe { llvm:: LLVMRustCoverageCreatePGOFuncNameVar ( llfn, mangled_fn_name. as_ptr ( ) ) }
87
- }
88
-
89
76
fn define_unused_fn ( & self , def_id : DefId ) {
90
77
let instance = declare_unused_fn ( self , & def_id) ;
91
78
codegen_unused_fn_and_counter ( self , instance) ;
@@ -210,10 +197,8 @@ fn declare_unused_fn(cx: &CodegenCx<'ll, 'tcx>, def_id: &DefId) -> Instance<'tcx
210
197
) ,
211
198
) ;
212
199
213
- unsafe {
214
- llvm:: LLVMRustSetLinkage ( llfn, llvm:: Linkage :: ExternalLinkage ) ;
215
- llvm:: LLVMRustSetVisibility ( llfn, llvm:: Visibility :: Hidden ) ;
216
- }
200
+ llvm:: set_linkage ( llfn, llvm:: Linkage :: WeakAnyLinkage ) ;
201
+ llvm:: set_visibility ( llfn, llvm:: Visibility :: Hidden ) ;
217
202
218
203
cx. instances . borrow_mut ( ) . insert ( instance, llfn) ;
219
204
@@ -261,6 +246,22 @@ fn add_function_coverage(cx: &CodegenCx<'ll, 'tcx>, instance: Instance<'tcx>, de
261
246
}
262
247
}
263
248
249
+ /// Calls llvm::createPGOFuncNameVar() with the given function instance's
250
+ /// mangled function name. The LLVM API returns an llvm::GlobalVariable
251
+ /// containing the function name, with the specific variable name and linkage
252
+ /// required by LLVM InstrProf source-based coverage instrumentation. Use
253
+ /// `bx.get_pgo_func_name_var()` to ensure the variable is only created once per
254
+ /// `Instance`.
255
+ fn create_pgo_func_name_var (
256
+ cx : & CodegenCx < ' ll , ' tcx > ,
257
+ instance : Instance < ' tcx > ,
258
+ ) -> & ' ll llvm:: Value {
259
+ let mangled_fn_name = CString :: new ( cx. tcx . symbol_name ( instance) . name )
260
+ . expect ( "error converting function name to C string" ) ;
261
+ let llfn = cx. get_fn ( instance) ;
262
+ unsafe { llvm:: LLVMRustCoverageCreatePGOFuncNameVar ( llfn, mangled_fn_name. as_ptr ( ) ) }
263
+ }
264
+
264
265
pub ( crate ) fn write_filenames_section_to_buffer < ' a > (
265
266
filenames : impl IntoIterator < Item = & ' a CString > ,
266
267
buffer : & RustString ,
0 commit comments