diff --git a/Cargo.lock b/Cargo.lock index f226a03672c..30e9627c48d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -228,6 +228,12 @@ dependencies = [ "memchr", ] +[[package]] +name = "once_cell" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9" + [[package]] name = "regalloc" version = "0.0.34" @@ -272,6 +278,7 @@ dependencies = [ "indexmap", "libloading", "object", + "once_cell", "smallvec", "target-lexicon", ] diff --git a/Cargo.toml b/Cargo.toml index 02a67d18441..dbe370d9f01 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,6 +21,7 @@ object = { version = "0.27.0", default-features = false, features = ["std", "rea ar = { git = "https://github.com/bjorn3/rust-ar.git", branch = "do_not_remove_cg_clif_ranlib" } indexmap = "1.8.0" libloading = { version = "0.6.0", optional = true } +once_cell = { version = "1.10.0", optional = true } smallvec = "1.6.1" [patch.crates-io] @@ -37,7 +38,7 @@ smallvec = "1.6.1" [features] # Enable features not ready to be enabled when compiling as part of rustc unstable-features = ["jit", "inline_asm"] -jit = ["cranelift-jit", "libloading"] +jit = ["cranelift-jit", "libloading", "once_cell"] inline_asm = [] # Disable optimizations and debuginfo of build scripts and some of the heavy build deps, as the diff --git a/src/debuginfo/unwind.rs b/src/debuginfo/unwind.rs index cc9ccbaf43f..d26392c4913 100644 --- a/src/debuginfo/unwind.rs +++ b/src/debuginfo/unwind.rs @@ -81,6 +81,8 @@ pub(crate) unsafe fn register_jit(self, _jit_module: &cranelift_jit::JITModule) #[cfg(all(feature = "jit", not(windows)))] pub(crate) unsafe fn register_jit(self, jit_module: &cranelift_jit::JITModule) { + use std::mem::ManuallyDrop; + let mut eh_frame = EhFrame::from(super::emit::WriterRelocate::new(self.endian)); self.frame_table.write_eh_frame(&mut eh_frame).unwrap(); @@ -95,8 +97,7 @@ pub(crate) unsafe fn register_jit(self, jit_module: &cranelift_jit::JITModule) { // FIXME support unregistering unwind tables once cranelift-jit supports deallocating // individual functions - #[allow(unused_variables)] - let (eh_frame, eh_frame_len, _) = Vec::into_raw_parts(eh_frame); + let eh_frame = ManuallyDrop::new(eh_frame); // ======================================================================= // Everything after this line up to the end of the file is loosely based on @@ -104,8 +105,8 @@ pub(crate) unsafe fn register_jit(self, jit_module: &cranelift_jit::JITModule) { #[cfg(target_os = "macos")] { // On macOS, `__register_frame` takes a pointer to a single FDE - let start = eh_frame; - let end = start.add(eh_frame_len); + let start = eh_frame.as_ptr(); + let end = start.add(eh_frame.len()); let mut current = start; // Walk all of the entries in the frame table and register them @@ -124,7 +125,7 @@ pub(crate) unsafe fn register_jit(self, jit_module: &cranelift_jit::JITModule) { #[cfg(not(target_os = "macos"))] { // On other platforms, `__register_frame` will walk the FDEs until an entry of length 0 - __register_frame(eh_frame); + __register_frame(eh_frame.as_ptr()); } } } diff --git a/src/driver/jit.rs b/src/driver/jit.rs index 9e07528313d..6c22296db71 100644 --- a/src/driver/jit.rs +++ b/src/driver/jit.rs @@ -3,7 +3,6 @@ use std::cell::RefCell; use std::ffi::CString; -use std::lazy::SyncOnceCell; use std::os::raw::{c_char, c_int}; use std::sync::{mpsc, Mutex}; @@ -14,6 +13,9 @@ use cranelift_jit::{JITBuilder, JITModule}; +// FIXME use std::lazy::SyncOnceCell once it stabilizes +use once_cell::sync::OnceCell; + use crate::{prelude::*, BackendConfig}; use crate::{CodegenCx, CodegenMode}; @@ -27,8 +29,7 @@ struct JitState { } /// The Sender owned by the rustc thread -static GLOBAL_MESSAGE_SENDER: SyncOnceCell>> = - SyncOnceCell::new(); +static GLOBAL_MESSAGE_SENDER: OnceCell>> = OnceCell::new(); /// A message that is sent from the jitted runtime to the rustc thread. /// Senders are responsible for upholding `Send` semantics. diff --git a/src/lib.rs b/src/lib.rs index 8b517104df2..a3c794fb156 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,5 @@ #![feature(rustc_private)] -#![cfg_attr(feature = "jit", feature(never_type, vec_into_raw_parts, once_cell))] +// Note: please avoid adding other feature gates where possible #![warn(rust_2018_idioms)] #![warn(unused_lifetimes)] #![warn(unreachable_pub)] @@ -196,7 +196,7 @@ fn codegen_crate( CodegenMode::Aot => driver::aot::run_aot(tcx, config, metadata, need_metadata_module), CodegenMode::Jit | CodegenMode::JitLazy => { #[cfg(feature = "jit")] - let _: ! = driver::jit::run_jit(tcx, config); + driver::jit::run_jit(tcx, config); #[cfg(not(feature = "jit"))] tcx.sess.fatal("jit support was disabled when compiling rustc_codegen_cranelift");