@@ -408,6 +408,7 @@ pub(crate) fn save_cov_data_to_mod<'ll, 'tcx>(
408
408
409
409
pub ( crate ) fn save_func_record_to_mod < ' ll , ' tcx > (
410
410
cx : & CodegenCx < ' ll , ' tcx > ,
411
+ covfun_section_name : & str ,
411
412
func_name_hash : u64 ,
412
413
func_record_val : & ' ll llvm:: Value ,
413
414
is_used : bool ,
@@ -423,20 +424,33 @@ pub(crate) fn save_func_record_to_mod<'ll, 'tcx>(
423
424
let func_record_var_name =
424
425
format ! ( "__covrec_{:X}{}" , func_name_hash, if is_used { "u" } else { "" } ) ;
425
426
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) ;
432
428
433
429
let llglobal = llvm:: add_global ( cx. llmod , cx. val_ty ( func_record_val) , & func_record_var_name) ;
434
430
llvm:: set_initializer ( llglobal, func_record_val) ;
435
431
llvm:: set_global_constant ( llglobal, true ) ;
436
432
llvm:: set_linkage ( llglobal, llvm:: Linkage :: LinkOnceODRLinkage ) ;
437
433
llvm:: set_visibility ( llglobal, llvm:: Visibility :: Hidden ) ;
438
- llvm:: set_section ( llglobal, & func_record_section_name ) ;
434
+ llvm:: set_section ( llglobal, covfun_section_name ) ;
439
435
llvm:: set_alignment ( llglobal, VAR_ALIGN_BYTES ) ;
440
436
llvm:: set_comdat ( cx. llmod , llglobal, & func_record_var_name) ;
441
437
cx. add_used_global ( llglobal) ;
442
438
}
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