1
1
use std:: cell:: RefCell ;
2
+ use std:: ffi:: CString ;
2
3
3
4
use libc:: c_uint;
4
5
use rustc_codegen_ssa:: traits:: {
@@ -12,6 +13,7 @@ use rustc_middle::mir::coverage::CoverageKind;
12
13
use rustc_middle:: ty:: Instance ;
13
14
use rustc_middle:: ty:: layout:: HasTyCtxt ;
14
15
use rustc_target:: abi:: { Align , Size } ;
16
+ use rustc_target:: spec:: HasTargetSpec ;
15
17
use tracing:: { debug, instrument} ;
16
18
17
19
use crate :: builder:: Builder ;
@@ -284,10 +286,10 @@ pub(crate) fn save_cov_data_to_mod<'ll, 'tcx>(
284
286
cx : & CodegenCx < ' ll , ' tcx > ,
285
287
cov_data_val : & ' ll llvm:: Value ,
286
288
) {
287
- let covmap_var_name = llvm:: build_string ( |s| unsafe {
289
+ let covmap_var_name = CString :: new ( llvm:: build_byte_buffer ( |s| unsafe {
288
290
llvm:: LLVMRustCoverageWriteMappingVarNameToString ( s) ;
289
- } )
290
- . expect ( "Rust Coverage Mapping var name failed UTF-8 conversion" ) ;
291
+ } ) )
292
+ . unwrap ( ) ;
291
293
debug ! ( "covmap var name: {:?}" , covmap_var_name) ;
292
294
293
295
let covmap_section_name = llvm:: build_string ( |s| unsafe {
@@ -322,7 +324,8 @@ pub(crate) fn save_func_record_to_mod<'ll, 'tcx>(
322
324
// of descriptions play distinct roles in LLVM IR; therefore, assign them different names (by
323
325
// appending "u" to the end of the function record var name, to prevent `linkonce_odr` merging.
324
326
let func_record_var_name =
325
- format ! ( "__covrec_{:X}{}" , func_name_hash, if is_used { "u" } else { "" } ) ;
327
+ CString :: new ( format ! ( "__covrec_{:X}{}" , func_name_hash, if is_used { "u" } else { "" } ) )
328
+ . unwrap ( ) ;
326
329
debug ! ( "function record var name: {:?}" , func_record_var_name) ;
327
330
debug ! ( "function record section name: {:?}" , covfun_section_name) ;
328
331
@@ -334,7 +337,9 @@ pub(crate) fn save_func_record_to_mod<'ll, 'tcx>(
334
337
llvm:: set_section ( llglobal, covfun_section_name) ;
335
338
// LLVM's coverage mapping format specifies 8-byte alignment for items in this section.
336
339
llvm:: set_alignment ( llglobal, Align :: EIGHT ) ;
337
- llvm:: set_comdat ( cx. llmod , llglobal, & func_record_var_name) ;
340
+ if cx. target_spec ( ) . supports_comdat ( ) {
341
+ llvm:: set_comdat ( cx. llmod , llglobal, & func_record_var_name) ;
342
+ }
338
343
cx. add_used_global ( llglobal) ;
339
344
}
340
345
0 commit comments