Skip to content

Commit 838dd17

Browse files
committed
Don't read CG_CLIF_JIT from init_global_lock
In preparation to moving away from an env var
1 parent 787d078 commit 838dd17

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

src/atomic_shim.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@ use crate::prelude::*;
1010
pub static mut __cg_clif_global_atomic_mutex: libc::pthread_mutex_t =
1111
libc::PTHREAD_MUTEX_INITIALIZER;
1212

13-
pub(crate) fn init_global_lock(module: &mut Module<impl Backend>, bcx: &mut FunctionBuilder<'_>) {
14-
if std::env::var("CG_CLIF_JIT").is_ok() {
13+
pub(crate) fn init_global_lock(
14+
module: &mut Module<impl Backend>,
15+
bcx: &mut FunctionBuilder<'_>,
16+
use_jit: bool,
17+
) {
18+
if use_jit {
1519
// When using JIT, dylibs won't find the __cg_clif_global_atomic_mutex data object defined here,
16-
// so instead define it in the cg_clif dylib.
20+
// so instead we define it in the cg_clif dylib.
1721

1822
return;
1923
}
@@ -80,7 +84,7 @@ pub(crate) fn init_global_lock_constructor(
8084
let block = bcx.create_block();
8185
bcx.switch_to_block(block);
8286

83-
crate::atomic_shim::init_global_lock(module, &mut bcx);
87+
crate::atomic_shim::init_global_lock(module, &mut bcx, false);
8488

8589
bcx.ins().return_(&[]);
8690
bcx.seal_all_blocks();

src/driver/aot.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ fn module_codegen(tcx: TyCtxt<'_>, cgu_name: rustc_span::Symbol) -> ModuleCodege
150150
super::codegen_mono_items(&mut cx, mono_items);
151151
let (mut module, global_asm, debug, mut unwind_context) =
152152
tcx.sess.time("finalize CodegenCx", || cx.finalize());
153-
crate::main_shim::maybe_create_entry_wrapper(tcx, &mut module, &mut unwind_context);
153+
crate::main_shim::maybe_create_entry_wrapper(tcx, &mut module, &mut unwind_context, false);
154154

155155
let codegen_result = emit_module(
156156
tcx,

src/driver/jit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pub(super) fn run_jit(tcx: TyCtxt<'_>) -> ! {
7676
if !global_asm.is_empty() {
7777
tcx.sess.fatal("Global asm is not supported in JIT mode");
7878
}
79-
crate::main_shim::maybe_create_entry_wrapper(tcx, &mut jit_module, &mut unwind_context);
79+
crate::main_shim::maybe_create_entry_wrapper(tcx, &mut jit_module, &mut unwind_context, true);
8080
crate::allocator::codegen(tcx, &mut jit_module, &mut unwind_context);
8181

8282
jit_module.finalize_definitions();

src/main_shim.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pub(crate) fn maybe_create_entry_wrapper(
99
tcx: TyCtxt<'_>,
1010
module: &mut Module<impl Backend + 'static>,
1111
unwind_context: &mut UnwindContext<'_>,
12+
use_jit: bool,
1213
) {
1314
let (main_def_id, use_start_lang_item) = match tcx.entry_fn(LOCAL_CRATE) {
1415
Some((def_id, entry_ty)) => (
@@ -32,6 +33,7 @@ pub(crate) fn maybe_create_entry_wrapper(
3233
unwind_context,
3334
main_def_id,
3435
use_start_lang_item,
36+
use_jit,
3537
);
3638

3739
fn create_entry_fn(
@@ -40,6 +42,7 @@ pub(crate) fn maybe_create_entry_wrapper(
4042
unwind_context: &mut UnwindContext<'_>,
4143
rust_main_def_id: DefId,
4244
use_start_lang_item: bool,
45+
use_jit: bool,
4346
) {
4447
let main_ret_ty = tcx.fn_sig(rust_main_def_id).output();
4548
// Given that `main()` has no arguments,
@@ -83,7 +86,7 @@ pub(crate) fn maybe_create_entry_wrapper(
8386
let arg_argc = bcx.append_block_param(block, m.target_config().pointer_type());
8487
let arg_argv = bcx.append_block_param(block, m.target_config().pointer_type());
8588

86-
crate::atomic_shim::init_global_lock(m, &mut bcx);
89+
crate::atomic_shim::init_global_lock(m, &mut bcx, use_jit);
8790

8891
let main_func_ref = m.declare_func_in_func(main_func_id, &mut bcx.func);
8992

0 commit comments

Comments
 (0)