11use std:: cell:: RefCell ;
2- use std:: ffi:: CString ;
2+ use std:: ffi:: { CStr , CString } ;
33
44use libc:: c_uint;
55use rustc_codegen_ssa:: traits:: {
@@ -292,10 +292,10 @@ pub(crate) fn save_cov_data_to_mod<'ll, 'tcx>(
292292 . unwrap ( ) ;
293293 debug ! ( "covmap var name: {:?}" , covmap_var_name) ;
294294
295- let covmap_section_name = llvm:: build_string ( |s| unsafe {
295+ let covmap_section_name = CString :: new ( llvm:: build_byte_buffer ( |s| unsafe {
296296 llvm:: LLVMRustCoverageWriteMapSectionNameToString ( cx. llmod , s) ;
297- } )
298- . expect ( "Rust Coverage section name failed UTF-8 conversion " ) ;
297+ } ) )
298+ . expect ( "covmap section name should not contain NUL " ) ;
299299 debug ! ( "covmap section name: {:?}" , covmap_section_name) ;
300300
301301 let llglobal = llvm:: add_global ( cx. llmod , cx. val_ty ( cov_data_val) , & covmap_var_name) ;
@@ -310,7 +310,7 @@ pub(crate) fn save_cov_data_to_mod<'ll, 'tcx>(
310310
311311pub ( crate ) fn save_func_record_to_mod < ' ll , ' tcx > (
312312 cx : & CodegenCx < ' ll , ' tcx > ,
313- covfun_section_name : & str ,
313+ covfun_section_name : & CStr ,
314314 func_name_hash : u64 ,
315315 func_record_val : & ' ll llvm:: Value ,
316316 is_used : bool ,
@@ -354,9 +354,9 @@ pub(crate) fn save_func_record_to_mod<'ll, 'tcx>(
354354/// - `__llvm_covfun` on Linux
355355/// - `__LLVM_COV,__llvm_covfun` on macOS (includes `__LLVM_COV,` segment prefix)
356356/// - `.lcovfun$M` on Windows (includes `$M` sorting suffix)
357- pub ( crate ) fn covfun_section_name ( cx : & CodegenCx < ' _ , ' _ > ) -> String {
358- llvm:: build_string ( |s| unsafe {
357+ pub ( crate ) fn covfun_section_name ( cx : & CodegenCx < ' _ , ' _ > ) -> CString {
358+ CString :: new ( llvm:: build_byte_buffer ( |s| unsafe {
359359 llvm:: LLVMRustCoverageWriteFuncSectionNameToString ( cx. llmod , s) ;
360- } )
361- . expect ( "Rust Coverage function record section name failed UTF-8 conversion " )
360+ } ) )
361+ . expect ( "covfun section name should not contain NUL " )
362362}
0 commit comments