This commit is contained in:
klensy 2023-04-05 15:08:17 +03:00
parent f41e711b7e
commit c0bc00174f
4 changed files with 16 additions and 31 deletions

View File

@ -7,7 +7,6 @@ use crate::type_::Type;
use crate::type_of::LayoutLlvmExt; use crate::type_of::LayoutLlvmExt;
use crate::value::Value; use crate::value::Value;
use cstr::cstr; use cstr::cstr;
use libc::c_uint;
use rustc_codegen_ssa::traits::*; use rustc_codegen_ssa::traits::*;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs}; use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs};
@ -486,10 +485,10 @@ impl<'ll> StaticMethods for CodegenCx<'ll, '_> {
// go into custom sections of the wasm executable. // go into custom sections of the wasm executable.
if self.tcx.sess.target.is_like_wasm { if self.tcx.sess.target.is_like_wasm {
if let Some(section) = attrs.link_section { if let Some(section) = attrs.link_section {
let section = llvm::LLVMMDStringInContext( let section = llvm::LLVMMDStringInContext2(
self.llcx, self.llcx,
section.as_str().as_ptr().cast(), section.as_str().as_ptr().cast(),
section.as_str().len() as c_uint, section.as_str().len(),
); );
assert!(alloc.provenance().ptrs().is_empty()); assert!(alloc.provenance().ptrs().is_empty());
@ -498,17 +497,15 @@ impl<'ll> StaticMethods for CodegenCx<'ll, '_> {
// as part of the interpreter execution). // as part of the interpreter execution).
let bytes = let bytes =
alloc.inspect_with_uninit_and_ptr_outside_interpreter(0..alloc.len()); alloc.inspect_with_uninit_and_ptr_outside_interpreter(0..alloc.len());
let alloc = llvm::LLVMMDStringInContext( let alloc =
self.llcx, llvm::LLVMMDStringInContext2(self.llcx, bytes.as_ptr().cast(), bytes.len());
bytes.as_ptr().cast(),
bytes.len() as c_uint,
);
let data = [section, alloc]; let data = [section, alloc];
let meta = llvm::LLVMMDNodeInContext(self.llcx, data.as_ptr(), 2); let meta = llvm::LLVMMDNodeInContext2(self.llcx, data.as_ptr(), data.len());
let val = llvm::LLVMMetadataAsValue(self.llcx, meta);
llvm::LLVMAddNamedMetadataOperand( llvm::LLVMAddNamedMetadataOperand(
self.llmod, self.llmod,
"wasm.custom_sections\0".as_ptr().cast(), "wasm.custom_sections\0".as_ptr().cast(),
meta, val,
); );
} }
} else { } else {

View File

@ -881,8 +881,6 @@ pub fn build_compile_unit_di_node<'ll, 'tcx>(
); );
if tcx.sess.opts.unstable_opts.profile { if tcx.sess.opts.unstable_opts.profile {
let cu_desc_metadata =
llvm::LLVMMetadataAsValue(debug_context.llcontext, unit_metadata);
let default_gcda_path = &output_filenames.with_extension("gcda"); let default_gcda_path = &output_filenames.with_extension("gcda");
let gcda_path = let gcda_path =
tcx.sess.opts.unstable_opts.profile_emit.as_ref().unwrap_or(default_gcda_path); tcx.sess.opts.unstable_opts.profile_emit.as_ref().unwrap_or(default_gcda_path);
@ -890,20 +888,17 @@ pub fn build_compile_unit_di_node<'ll, 'tcx>(
let gcov_cu_info = [ let gcov_cu_info = [
path_to_mdstring(debug_context.llcontext, &output_filenames.with_extension("gcno")), path_to_mdstring(debug_context.llcontext, &output_filenames.with_extension("gcno")),
path_to_mdstring(debug_context.llcontext, gcda_path), path_to_mdstring(debug_context.llcontext, gcda_path),
cu_desc_metadata, unit_metadata,
]; ];
let gcov_metadata = llvm::LLVMMDNodeInContext( let gcov_metadata = llvm::LLVMMDNodeInContext2(
debug_context.llcontext, debug_context.llcontext,
gcov_cu_info.as_ptr(), gcov_cu_info.as_ptr(),
gcov_cu_info.len() as c_uint, gcov_cu_info.len(),
); );
let val = llvm::LLVMMetadataAsValue(debug_context.llcontext, gcov_metadata);
let llvm_gcov_ident = cstr!("llvm.gcov"); let llvm_gcov_ident = cstr!("llvm.gcov");
llvm::LLVMAddNamedMetadataOperand( llvm::LLVMAddNamedMetadataOperand(debug_context.llmod, llvm_gcov_ident.as_ptr(), val);
debug_context.llmod,
llvm_gcov_ident.as_ptr(),
gcov_metadata,
);
} }
// Insert `llvm.ident` metadata on the wasm targets since that will // Insert `llvm.ident` metadata on the wasm targets since that will
@ -924,15 +919,9 @@ pub fn build_compile_unit_di_node<'ll, 'tcx>(
return unit_metadata; return unit_metadata;
}; };
fn path_to_mdstring<'ll>(llcx: &'ll llvm::Context, path: &Path) -> &'ll Value { fn path_to_mdstring<'ll>(llcx: &'ll llvm::Context, path: &Path) -> &'ll llvm::Metadata {
let path_str = path_to_c_string(path); let path_str = path_to_c_string(path);
unsafe { unsafe { llvm::LLVMMDStringInContext2(llcx, path_str.as_ptr(), path_str.as_bytes().len()) }
llvm::LLVMMDStringInContext(
llcx,
path_str.as_ptr(),
path_str.as_bytes().len() as c_uint,
)
}
} }
} }

View File

@ -1075,7 +1075,6 @@ extern "C" {
// FIXME: deprecated, replace with LLVMMDStringInContext2 // FIXME: deprecated, replace with LLVMMDStringInContext2
pub fn LLVMMDStringInContext(C: &Context, Str: *const c_char, SLen: c_uint) -> &Value; pub fn LLVMMDStringInContext(C: &Context, Str: *const c_char, SLen: c_uint) -> &Value;
// LLVMMDStringInContext but don't own string
pub fn LLVMMDStringInContext2(C: &Context, Str: *const c_char, SLen: size_t) -> &Metadata; pub fn LLVMMDStringInContext2(C: &Context, Str: *const c_char, SLen: size_t) -> &Metadata;
// FIXME: deprecated, replace with LLVMMDNodeInContext2 // FIXME: deprecated, replace with LLVMMDNodeInContext2
@ -1117,7 +1116,7 @@ extern "C" {
Packed: Bool, Packed: Bool,
) -> &'a Value; ) -> &'a Value;
// FIXME: replace with LLVMConstArray2 // FIXME: replace with LLVMConstArray2 when bumped minimal version to llvm-17
// https://github.com/llvm/llvm-project/commit/35276f16e5a2cae0dfb49c0fbf874d4d2f177acc // https://github.com/llvm/llvm-project/commit/35276f16e5a2cae0dfb49c0fbf874d4d2f177acc
pub fn LLVMConstArray<'a>( pub fn LLVMConstArray<'a>(
ElementTy: &'a Type, ElementTy: &'a Type,

View File

@ -1137,7 +1137,7 @@ extern "C" void LLVMRustWriteValueToString(LLVMValueRef V,
} }
// LLVMArrayType function does not support 64-bit ElementCount // LLVMArrayType function does not support 64-bit ElementCount
// FIXME: replace with LLVMArrayType2 // FIXME: replace with LLVMArrayType2 when bumped minimal version to llvm-17
// https://github.com/llvm/llvm-project/commit/35276f16e5a2cae0dfb49c0fbf874d4d2f177acc // https://github.com/llvm/llvm-project/commit/35276f16e5a2cae0dfb49c0fbf874d4d2f177acc
extern "C" LLVMTypeRef LLVMRustArrayType(LLVMTypeRef ElementTy, extern "C" LLVMTypeRef LLVMRustArrayType(LLVMTypeRef ElementTy,
uint64_t ElementCount) { uint64_t ElementCount) {