about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbjorn3 <bjorn3@users.noreply.github.com>2020-09-29 15:28:48 +0200
committerbjorn3 <bjorn3@users.noreply.github.com>2020-09-29 15:28:48 +0200
commitb8b5a824a689aea09f46c2f7b2f58f5f8051ea1d (patch)
treebbce65689bfd47822b30b2434db292902dd31af1
parent17a54ad62e217c1b6e3848efe522666f443809a2 (diff)
downloadrust-b8b5a824a689aea09f46c2f7b2f58f5f8051ea1d.tar.gz
rust-b8b5a824a689aea09f46c2f7b2f58f5f8051ea1d.zip
Fix JIT
-rw-r--r--src/driver/jit.rs32
1 files changed, 17 insertions, 15 deletions
diff --git a/src/driver/jit.rs b/src/driver/jit.rs
index edeeb7670e9..fd3a628922d 100644
--- a/src/driver/jit.rs
+++ b/src/driver/jit.rs
@@ -11,21 +11,23 @@ use crate::prelude::*;
 pub(super) fn run_jit(tcx: TyCtxt<'_>) -> ! {
     use cranelift_simplejit::{SimpleJITBackend, SimpleJITBuilder};
 
-    // Rustc opens us without the RTLD_GLOBAL flag, so __cg_clif_global_atomic_mutex will not be
-    // exported. We fix this by opening ourself again as global.
-    // FIXME remove once atomic_shim is gone
-    let cg_dylib = std::ffi::OsString::from(
-        &tcx.sess
-            .opts
-            .debugging_opts
-            .codegen_backend
-            .as_ref()
-            .unwrap(),
-    );
-    std::mem::forget(
-        libloading::os::unix::Library::open(Some(cg_dylib), libc::RTLD_NOW | libc::RTLD_GLOBAL)
-            .unwrap(),
-    );
+    #[cfg(unix)]
+    unsafe {
+        // When not using our custom driver rustc will open us without the RTLD_GLOBAL flag, so
+        // __cg_clif_global_atomic_mutex will not be exported. We fix this by opening ourself again
+        // as global.
+        // FIXME remove once atomic_shim is gone
+
+        let mut dl_info: libc::Dl_info = std::mem::zeroed();
+        assert_ne!(
+            libc::dladdr(run_jit as *const libc::c_void, &mut dl_info),
+            0
+        );
+        assert_ne!(
+            libc::dlopen(dl_info.dli_fname, libc::RTLD_NOW | libc::RTLD_GLOBAL),
+            std::ptr::null_mut(),
+        );
+    }
 
     let imported_symbols = load_imported_symbols_for_jit(tcx);