Make llvm::set_section
take a &CStr
This commit is contained in:
parent
d68c327796
commit
3310419d35
3 changed files with 14 additions and 13 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
use std::ffi::CStr;
|
||||||
|
|
||||||
use itertools::Itertools as _;
|
use itertools::Itertools as _;
|
||||||
use rustc_codegen_ssa::traits::{BaseTypeCodegenMethods, ConstCodegenMethods};
|
use rustc_codegen_ssa::traits::{BaseTypeCodegenMethods, ConstCodegenMethods};
|
||||||
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
|
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
|
||||||
|
@ -305,7 +307,7 @@ fn generate_coverage_map<'ll>(
|
||||||
/// specific, well-known section and name.
|
/// specific, well-known section and name.
|
||||||
fn save_function_record(
|
fn save_function_record(
|
||||||
cx: &CodegenCx<'_, '_>,
|
cx: &CodegenCx<'_, '_>,
|
||||||
covfun_section_name: &str,
|
covfun_section_name: &CStr,
|
||||||
mangled_function_name: &str,
|
mangled_function_name: &str,
|
||||||
source_hash: u64,
|
source_hash: u64,
|
||||||
filenames_ref: u64,
|
filenames_ref: u64,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::ffi::CString;
|
use std::ffi::{CStr, CString};
|
||||||
|
|
||||||
use libc::c_uint;
|
use libc::c_uint;
|
||||||
use rustc_codegen_ssa::traits::{
|
use rustc_codegen_ssa::traits::{
|
||||||
|
@ -292,10 +292,10 @@ pub(crate) fn save_cov_data_to_mod<'ll, 'tcx>(
|
||||||
.unwrap();
|
.unwrap();
|
||||||
debug!("covmap var name: {:?}", covmap_var_name);
|
debug!("covmap var name: {:?}", covmap_var_name);
|
||||||
|
|
||||||
let covmap_section_name = llvm::build_string(|s| unsafe {
|
let covmap_section_name = CString::new(llvm::build_byte_buffer(|s| unsafe {
|
||||||
llvm::LLVMRustCoverageWriteMapSectionNameToString(cx.llmod, s);
|
llvm::LLVMRustCoverageWriteMapSectionNameToString(cx.llmod, s);
|
||||||
})
|
}))
|
||||||
.expect("Rust Coverage section name failed UTF-8 conversion");
|
.expect("covmap section name should not contain NUL");
|
||||||
debug!("covmap section name: {:?}", covmap_section_name);
|
debug!("covmap section name: {:?}", covmap_section_name);
|
||||||
|
|
||||||
let llglobal = llvm::add_global(cx.llmod, cx.val_ty(cov_data_val), &covmap_var_name);
|
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>(
|
||||||
|
|
||||||
pub(crate) fn save_func_record_to_mod<'ll, 'tcx>(
|
pub(crate) fn save_func_record_to_mod<'ll, 'tcx>(
|
||||||
cx: &CodegenCx<'ll, 'tcx>,
|
cx: &CodegenCx<'ll, 'tcx>,
|
||||||
covfun_section_name: &str,
|
covfun_section_name: &CStr,
|
||||||
func_name_hash: u64,
|
func_name_hash: u64,
|
||||||
func_record_val: &'ll llvm::Value,
|
func_record_val: &'ll llvm::Value,
|
||||||
is_used: bool,
|
is_used: bool,
|
||||||
|
@ -354,9 +354,9 @@ pub(crate) fn save_func_record_to_mod<'ll, 'tcx>(
|
||||||
/// - `__llvm_covfun` on Linux
|
/// - `__llvm_covfun` on Linux
|
||||||
/// - `__LLVM_COV,__llvm_covfun` on macOS (includes `__LLVM_COV,` segment prefix)
|
/// - `__LLVM_COV,__llvm_covfun` on macOS (includes `__LLVM_COV,` segment prefix)
|
||||||
/// - `.lcovfun$M` on Windows (includes `$M` sorting suffix)
|
/// - `.lcovfun$M` on Windows (includes `$M` sorting suffix)
|
||||||
pub(crate) fn covfun_section_name(cx: &CodegenCx<'_, '_>) -> String {
|
pub(crate) fn covfun_section_name(cx: &CodegenCx<'_, '_>) -> CString {
|
||||||
llvm::build_string(|s| unsafe {
|
CString::new(llvm::build_byte_buffer(|s| unsafe {
|
||||||
llvm::LLVMRustCoverageWriteFuncSectionNameToString(cx.llmod, s);
|
llvm::LLVMRustCoverageWriteFuncSectionNameToString(cx.llmod, s);
|
||||||
})
|
}))
|
||||||
.expect("Rust Coverage function record section name failed UTF-8 conversion")
|
.expect("covfun section name should not contain NUL")
|
||||||
}
|
}
|
||||||
|
|
|
@ -210,10 +210,9 @@ impl MemoryEffects {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_section(llglobal: &Value, section_name: &str) {
|
pub fn set_section(llglobal: &Value, section_name: &CStr) {
|
||||||
let section_name_cstr = CString::new(section_name).expect("unexpected CString error");
|
|
||||||
unsafe {
|
unsafe {
|
||||||
LLVMSetSection(llglobal, section_name_cstr.as_ptr());
|
LLVMSetSection(llglobal, section_name.as_ptr());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue