Make all compiler-builtins symbols hidden
This matches cg_llvm Fixes #1152
This commit is contained in:
parent
f3e8f6dc08
commit
94b51d14e6
@ -8,11 +8,7 @@ use rustc_target::abi::call::FnAbi;
|
|||||||
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
pub(crate) fn codegen_fn<'tcx>(
|
pub(crate) fn codegen_fn<'tcx>(cx: &mut crate::CodegenCx<'_, 'tcx>, instance: Instance<'tcx>) {
|
||||||
cx: &mut crate::CodegenCx<'_, 'tcx>,
|
|
||||||
instance: Instance<'tcx>,
|
|
||||||
linkage: Linkage,
|
|
||||||
) {
|
|
||||||
let tcx = cx.tcx;
|
let tcx = cx.tcx;
|
||||||
|
|
||||||
let _inst_guard =
|
let _inst_guard =
|
||||||
@ -24,7 +20,7 @@ pub(crate) fn codegen_fn<'tcx>(
|
|||||||
// Declare function
|
// Declare function
|
||||||
let name = tcx.symbol_name(instance).name.to_string();
|
let name = tcx.symbol_name(instance).name.to_string();
|
||||||
let sig = get_function_sig(tcx, cx.module.isa().triple(), instance);
|
let sig = get_function_sig(tcx, cx.module.isa().triple(), instance);
|
||||||
let func_id = cx.module.declare_function(&name, linkage, &sig).unwrap();
|
let func_id = cx.module.declare_function(&name, Linkage::Local, &sig).unwrap();
|
||||||
|
|
||||||
cx.cached_context.clear();
|
cx.cached_context.clear();
|
||||||
|
|
||||||
|
41
src/compiler_builtins.rs
Normal file
41
src/compiler_builtins.rs
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
macro builtin_functions($register:ident; $(fn $name:ident($($arg_name:ident: $arg_ty:ty),*) -> $ret_ty:ty;)*) {
|
||||||
|
#[cfg(feature = "jit")]
|
||||||
|
#[allow(improper_ctypes)]
|
||||||
|
extern "C" {
|
||||||
|
$(fn $name($($arg_name: $arg_ty),*) -> $ret_ty;)*
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "jit")]
|
||||||
|
pub(crate) fn $register(builder: &mut cranelift_jit::JITBuilder) {
|
||||||
|
for &(name, val) in &[$((stringify!($name), $name as *const u8)),*] {
|
||||||
|
builder.symbol(name, val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
builtin_functions! {
|
||||||
|
register_functions_for_jit;
|
||||||
|
|
||||||
|
// integers
|
||||||
|
fn __multi3(a: i128, b: i128) -> i128;
|
||||||
|
fn __udivti3(n: u128, d: u128) -> u128;
|
||||||
|
fn __divti3(n: i128, d: i128) -> i128;
|
||||||
|
fn __umodti3(n: u128, d: u128) -> u128;
|
||||||
|
fn __modti3(n: i128, d: i128) -> i128;
|
||||||
|
fn __rust_u128_addo(a: u128, b: u128) -> (u128, bool);
|
||||||
|
fn __rust_i128_addo(a: i128, b: i128) -> (i128, bool);
|
||||||
|
fn __rust_u128_subo(a: u128, b: u128) -> (u128, bool);
|
||||||
|
fn __rust_i128_subo(a: i128, b: i128) -> (i128, bool);
|
||||||
|
fn __rust_u128_mulo(a: u128, b: u128) -> (u128, bool);
|
||||||
|
fn __rust_i128_mulo(a: i128, b: i128) -> (i128, bool);
|
||||||
|
|
||||||
|
// floats
|
||||||
|
fn __floattisf(i: i128) -> f32;
|
||||||
|
fn __floattidf(i: i128) -> f64;
|
||||||
|
fn __floatuntisf(i: u128) -> f32;
|
||||||
|
fn __floatuntidf(i: u128) -> f64;
|
||||||
|
fn __fixsfti(f: f32) -> i128;
|
||||||
|
fn __fixdfti(f: f64) -> i128;
|
||||||
|
fn __fixunssfti(f: f32) -> u128;
|
||||||
|
fn __fixunsdfti(f: f64) -> u128;
|
||||||
|
}
|
@ -119,11 +119,10 @@ fn module_codegen(
|
|||||||
tcx.sess.opts.debuginfo != DebugInfo::None,
|
tcx.sess.opts.debuginfo != DebugInfo::None,
|
||||||
);
|
);
|
||||||
super::predefine_mono_items(&mut cx, &mono_items);
|
super::predefine_mono_items(&mut cx, &mono_items);
|
||||||
for (mono_item, (linkage, visibility)) in mono_items {
|
for (mono_item, _) in mono_items {
|
||||||
let linkage = crate::linkage::get_clif_linkage(mono_item, linkage, visibility);
|
|
||||||
match mono_item {
|
match mono_item {
|
||||||
MonoItem::Fn(inst) => {
|
MonoItem::Fn(inst) => {
|
||||||
cx.tcx.sess.time("codegen fn", || crate::base::codegen_fn(&mut cx, inst, linkage));
|
cx.tcx.sess.time("codegen fn", || crate::base::codegen_fn(&mut cx, inst));
|
||||||
}
|
}
|
||||||
MonoItem::Static(def_id) => {
|
MonoItem::Static(def_id) => {
|
||||||
crate::constant::codegen_static(&mut cx.constants_cx, def_id)
|
crate::constant::codegen_static(&mut cx.constants_cx, def_id)
|
||||||
|
@ -30,6 +30,7 @@ pub(super) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! {
|
|||||||
let mut jit_builder =
|
let mut jit_builder =
|
||||||
JITBuilder::with_isa(crate::build_isa(tcx.sess), cranelift_module::default_libcall_names());
|
JITBuilder::with_isa(crate::build_isa(tcx.sess), cranelift_module::default_libcall_names());
|
||||||
jit_builder.hotswap(matches!(backend_config.codegen_mode, CodegenMode::JitLazy));
|
jit_builder.hotswap(matches!(backend_config.codegen_mode, CodegenMode::JitLazy));
|
||||||
|
crate::compiler_builtins::register_functions_for_jit(&mut jit_builder);
|
||||||
jit_builder.symbols(imported_symbols);
|
jit_builder.symbols(imported_symbols);
|
||||||
let mut jit_module = JITModule::new(jit_builder);
|
let mut jit_module = JITModule::new(jit_builder);
|
||||||
assert_eq!(pointer_ty(tcx), jit_module.target_config().pointer_type());
|
assert_eq!(pointer_ty(tcx), jit_module.target_config().pointer_type());
|
||||||
@ -47,15 +48,12 @@ pub(super) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! {
|
|||||||
|
|
||||||
super::time(tcx, "codegen mono items", || {
|
super::time(tcx, "codegen mono items", || {
|
||||||
super::predefine_mono_items(&mut cx, &mono_items);
|
super::predefine_mono_items(&mut cx, &mono_items);
|
||||||
for (mono_item, (linkage, visibility)) in mono_items {
|
for (mono_item, _) in mono_items {
|
||||||
let linkage = crate::linkage::get_clif_linkage(mono_item, linkage, visibility);
|
|
||||||
match mono_item {
|
match mono_item {
|
||||||
MonoItem::Fn(inst) => match backend_config.codegen_mode {
|
MonoItem::Fn(inst) => match backend_config.codegen_mode {
|
||||||
CodegenMode::Aot => unreachable!(),
|
CodegenMode::Aot => unreachable!(),
|
||||||
CodegenMode::Jit => {
|
CodegenMode::Jit => {
|
||||||
cx.tcx
|
cx.tcx.sess.time("codegen fn", || crate::base::codegen_fn(&mut cx, inst));
|
||||||
.sess
|
|
||||||
.time("codegen fn", || crate::base::codegen_fn(&mut cx, inst, linkage));
|
|
||||||
}
|
}
|
||||||
CodegenMode::JitLazy => codegen_shim(&mut cx, inst),
|
CodegenMode::JitLazy => codegen_shim(&mut cx, inst),
|
||||||
},
|
},
|
||||||
@ -175,8 +173,7 @@ extern "C" fn __clif_jit_fn(instance_ptr: *const Instance<'static>) -> *const u8
|
|||||||
jit_module.prepare_for_function_redefine(func_id).unwrap();
|
jit_module.prepare_for_function_redefine(func_id).unwrap();
|
||||||
|
|
||||||
let mut cx = crate::CodegenCx::new(tcx, backend_config, jit_module, false);
|
let mut cx = crate::CodegenCx::new(tcx, backend_config, jit_module, false);
|
||||||
tcx.sess
|
tcx.sess.time("codegen fn", || crate::base::codegen_fn(&mut cx, instance));
|
||||||
.time("codegen fn", || crate::base::codegen_fn(&mut cx, instance, Linkage::Export));
|
|
||||||
|
|
||||||
let (global_asm, _debug_context, unwind_context) = cx.finalize();
|
let (global_asm, _debug_context, unwind_context) = cx.finalize();
|
||||||
assert!(global_asm.is_empty());
|
assert!(global_asm.is_empty());
|
||||||
|
@ -44,13 +44,19 @@ fn predefine_mono_items<'tcx>(
|
|||||||
mono_items: &[(MonoItem<'tcx>, (RLinkage, Visibility))],
|
mono_items: &[(MonoItem<'tcx>, (RLinkage, Visibility))],
|
||||||
) {
|
) {
|
||||||
cx.tcx.sess.time("predefine functions", || {
|
cx.tcx.sess.time("predefine functions", || {
|
||||||
|
let is_compiler_builtins = cx.tcx.is_compiler_builtins(LOCAL_CRATE);
|
||||||
for &(mono_item, (linkage, visibility)) in mono_items {
|
for &(mono_item, (linkage, visibility)) in mono_items {
|
||||||
match mono_item {
|
match mono_item {
|
||||||
MonoItem::Fn(instance) => {
|
MonoItem::Fn(instance) => {
|
||||||
let name = cx.tcx.symbol_name(instance).name.to_string();
|
let name = cx.tcx.symbol_name(instance).name.to_string();
|
||||||
let _inst_guard = crate::PrintOnPanic(|| format!("{:?} {}", instance, name));
|
let _inst_guard = crate::PrintOnPanic(|| format!("{:?} {}", instance, name));
|
||||||
let sig = get_function_sig(cx.tcx, cx.module.isa().triple(), instance);
|
let sig = get_function_sig(cx.tcx, cx.module.isa().triple(), instance);
|
||||||
let linkage = crate::linkage::get_clif_linkage(mono_item, linkage, visibility);
|
let linkage = crate::linkage::get_clif_linkage(
|
||||||
|
mono_item,
|
||||||
|
linkage,
|
||||||
|
visibility,
|
||||||
|
is_compiler_builtins,
|
||||||
|
);
|
||||||
cx.module.declare_function(&name, linkage, &sig).unwrap();
|
cx.module.declare_function(&name, linkage, &sig).unwrap();
|
||||||
}
|
}
|
||||||
MonoItem::Static(_) | MonoItem::GlobalAsm(_) => {}
|
MonoItem::Static(_) | MonoItem::GlobalAsm(_) => {}
|
||||||
|
@ -48,6 +48,7 @@ mod base;
|
|||||||
mod cast;
|
mod cast;
|
||||||
mod codegen_i128;
|
mod codegen_i128;
|
||||||
mod common;
|
mod common;
|
||||||
|
mod compiler_builtins;
|
||||||
mod constant;
|
mod constant;
|
||||||
mod debuginfo;
|
mod debuginfo;
|
||||||
mod discriminant;
|
mod discriminant;
|
||||||
|
@ -6,8 +6,10 @@ pub(crate) fn get_clif_linkage(
|
|||||||
mono_item: MonoItem<'_>,
|
mono_item: MonoItem<'_>,
|
||||||
linkage: RLinkage,
|
linkage: RLinkage,
|
||||||
visibility: Visibility,
|
visibility: Visibility,
|
||||||
|
is_compiler_builtins: bool,
|
||||||
) -> Linkage {
|
) -> Linkage {
|
||||||
match (linkage, visibility) {
|
match (linkage, visibility) {
|
||||||
|
(RLinkage::External, Visibility::Default) if is_compiler_builtins => Linkage::Hidden,
|
||||||
(RLinkage::External, Visibility::Default) => Linkage::Export,
|
(RLinkage::External, Visibility::Default) => Linkage::Export,
|
||||||
(RLinkage::Internal, Visibility::Default) => Linkage::Local,
|
(RLinkage::Internal, Visibility::Default) => Linkage::Local,
|
||||||
(RLinkage::External, Visibility::Hidden) => Linkage::Hidden,
|
(RLinkage::External, Visibility::Hidden) => Linkage::Hidden,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user