Don't read CG_CLIF_JIT from init_global_lock

In preparation to moving away from an env var
This commit is contained in:
bjorn3 2020-09-29 18:12:23 +02:00
parent 787d078fb6
commit 838dd17a67
4 changed files with 14 additions and 7 deletions

View File

@ -10,10 +10,14 @@ use crate::prelude::*;
pub static mut __cg_clif_global_atomic_mutex: libc::pthread_mutex_t =
libc::PTHREAD_MUTEX_INITIALIZER;
pub(crate) fn init_global_lock(module: &mut Module<impl Backend>, bcx: &mut FunctionBuilder<'_>) {
if std::env::var("CG_CLIF_JIT").is_ok() {
pub(crate) fn init_global_lock(
module: &mut Module<impl Backend>,
bcx: &mut FunctionBuilder<'_>,
use_jit: bool,
) {
if use_jit {
// When using JIT, dylibs won't find the __cg_clif_global_atomic_mutex data object defined here,
// so instead define it in the cg_clif dylib.
// so instead we define it in the cg_clif dylib.
return;
}
@ -80,7 +84,7 @@ pub(crate) fn init_global_lock_constructor(
let block = bcx.create_block();
bcx.switch_to_block(block);
crate::atomic_shim::init_global_lock(module, &mut bcx);
crate::atomic_shim::init_global_lock(module, &mut bcx, false);
bcx.ins().return_(&[]);
bcx.seal_all_blocks();

View File

@ -150,7 +150,7 @@ fn module_codegen(tcx: TyCtxt<'_>, cgu_name: rustc_span::Symbol) -> ModuleCodege
super::codegen_mono_items(&mut cx, mono_items);
let (mut module, global_asm, debug, mut unwind_context) =
tcx.sess.time("finalize CodegenCx", || cx.finalize());
crate::main_shim::maybe_create_entry_wrapper(tcx, &mut module, &mut unwind_context);
crate::main_shim::maybe_create_entry_wrapper(tcx, &mut module, &mut unwind_context, false);
let codegen_result = emit_module(
tcx,

View File

@ -76,7 +76,7 @@ pub(super) fn run_jit(tcx: TyCtxt<'_>) -> ! {
if !global_asm.is_empty() {
tcx.sess.fatal("Global asm is not supported in JIT mode");
}
crate::main_shim::maybe_create_entry_wrapper(tcx, &mut jit_module, &mut unwind_context);
crate::main_shim::maybe_create_entry_wrapper(tcx, &mut jit_module, &mut unwind_context, true);
crate::allocator::codegen(tcx, &mut jit_module, &mut unwind_context);
jit_module.finalize_definitions();

View File

@ -9,6 +9,7 @@ pub(crate) fn maybe_create_entry_wrapper(
tcx: TyCtxt<'_>,
module: &mut Module<impl Backend + 'static>,
unwind_context: &mut UnwindContext<'_>,
use_jit: bool,
) {
let (main_def_id, use_start_lang_item) = match tcx.entry_fn(LOCAL_CRATE) {
Some((def_id, entry_ty)) => (
@ -32,6 +33,7 @@ pub(crate) fn maybe_create_entry_wrapper(
unwind_context,
main_def_id,
use_start_lang_item,
use_jit,
);
fn create_entry_fn(
@ -40,6 +42,7 @@ pub(crate) fn maybe_create_entry_wrapper(
unwind_context: &mut UnwindContext<'_>,
rust_main_def_id: DefId,
use_start_lang_item: bool,
use_jit: bool,
) {
let main_ret_ty = tcx.fn_sig(rust_main_def_id).output();
// Given that `main()` has no arguments,
@ -83,7 +86,7 @@ pub(crate) fn maybe_create_entry_wrapper(
let arg_argc = bcx.append_block_param(block, m.target_config().pointer_type());
let arg_argv = bcx.append_block_param(block, m.target_config().pointer_type());
crate::atomic_shim::init_global_lock(m, &mut bcx);
crate::atomic_shim::init_global_lock(m, &mut bcx, use_jit);
let main_func_ref = m.declare_func_in_func(main_func_id, &mut bcx.func);