Skip to content

Commit b8b5a82

Browse files
committed
Fix JIT
1 parent 17a54ad commit b8b5a82

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

src/driver/jit.rs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,23 @@ use crate::prelude::*;
1111
pub(super) fn run_jit(tcx: TyCtxt<'_>) -> ! {
1212
use cranelift_simplejit::{SimpleJITBackend, SimpleJITBuilder};
1313

14-
// Rustc opens us without the RTLD_GLOBAL flag, so __cg_clif_global_atomic_mutex will not be
15-
// exported. We fix this by opening ourself again as global.
16-
// FIXME remove once atomic_shim is gone
17-
let cg_dylib = std::ffi::OsString::from(
18-
&tcx.sess
19-
.opts
20-
.debugging_opts
21-
.codegen_backend
22-
.as_ref()
23-
.unwrap(),
24-
);
25-
std::mem::forget(
26-
libloading::os::unix::Library::open(Some(cg_dylib), libc::RTLD_NOW | libc::RTLD_GLOBAL)
27-
.unwrap(),
28-
);
14+
#[cfg(unix)]
15+
unsafe {
16+
// When not using our custom driver rustc will open us without the RTLD_GLOBAL flag, so
17+
// __cg_clif_global_atomic_mutex will not be exported. We fix this by opening ourself again
18+
// as global.
19+
// FIXME remove once atomic_shim is gone
20+
21+
let mut dl_info: libc::Dl_info = std::mem::zeroed();
22+
assert_ne!(
23+
libc::dladdr(run_jit as *const libc::c_void, &mut dl_info),
24+
0
25+
);
26+
assert_ne!(
27+
libc::dlopen(dl_info.dli_fname, libc::RTLD_NOW | libc::RTLD_GLOBAL),
28+
std::ptr::null_mut(),
29+
);
30+
}
2931

3032
let imported_symbols = load_imported_symbols_for_jit(tcx);
3133

0 commit comments

Comments
 (0)