@@ -408,6 +408,7 @@ pub(crate) fn save_cov_data_to_mod<'ll, 'tcx>(
408408
409409pub ( crate ) fn save_func_record_to_mod < ' ll , ' tcx > (
410410 cx : & CodegenCx < ' ll , ' tcx > ,
411+ covfun_section_name : & str ,
411412 func_name_hash : u64 ,
412413 func_record_val : & ' ll llvm:: Value ,
413414 is_used : bool ,
@@ -423,20 +424,33 @@ pub(crate) fn save_func_record_to_mod<'ll, 'tcx>(
423424 let func_record_var_name =
424425 format ! ( "__covrec_{:X}{}" , func_name_hash, if is_used { "u" } else { "" } ) ;
425426 debug ! ( "function record var name: {:?}" , func_record_var_name) ;
426-
427- let func_record_section_name = llvm:: build_string ( |s| unsafe {
428- llvm:: LLVMRustCoverageWriteFuncSectionNameToString ( cx. llmod , s) ;
429- } )
430- . expect ( "Rust Coverage function record section name failed UTF-8 conversion" ) ;
431- debug ! ( "function record section name: {:?}" , func_record_section_name) ;
427+ debug ! ( "function record section name: {:?}" , covfun_section_name) ;
432428
433429 let llglobal = llvm:: add_global ( cx. llmod , cx. val_ty ( func_record_val) , & func_record_var_name) ;
434430 llvm:: set_initializer ( llglobal, func_record_val) ;
435431 llvm:: set_global_constant ( llglobal, true ) ;
436432 llvm:: set_linkage ( llglobal, llvm:: Linkage :: LinkOnceODRLinkage ) ;
437433 llvm:: set_visibility ( llglobal, llvm:: Visibility :: Hidden ) ;
438- llvm:: set_section ( llglobal, & func_record_section_name ) ;
434+ llvm:: set_section ( llglobal, covfun_section_name ) ;
439435 llvm:: set_alignment ( llglobal, VAR_ALIGN_BYTES ) ;
440436 llvm:: set_comdat ( cx. llmod , llglobal, & func_record_var_name) ;
441437 cx. add_used_global ( llglobal) ;
442438}
439+
440+ /// Returns the section name string to pass through to the linker when embedding
441+ /// per-function coverage information in the object file, according to the target
442+ /// platform's object file format.
443+ ///
444+ /// LLVM's coverage tools read coverage mapping details from this section when
445+ /// producing coverage reports.
446+ ///
447+ /// Typical values are:
448+ /// - `__llvm_covfun` on Linux
449+ /// - `__LLVM_COV,__llvm_covfun` on macOS (includes `__LLVM_COV,` segment prefix)
450+ /// - `.lcovfun$M` on Windows (includes `$M` sorting suffix)
451+ pub ( crate ) fn covfun_section_name ( cx : & CodegenCx < ' _ , ' _ > ) -> String {
452+ llvm:: build_string ( |s| unsafe {
453+ llvm:: LLVMRustCoverageWriteFuncSectionNameToString ( cx. llmod , s) ;
454+ } )
455+ . expect ( "Rust Coverage function record section name failed UTF-8 conversion" )
456+ }
0 commit comments