diff --git a/Cargo.toml b/Cargo.toml index 5341b3a486..8bb4f1c160 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,8 +33,8 @@ serde_json = { version = "1.0", optional = true } # But only for some targets, it fails for others. Rustc configures this in its CI, but we can't # easily use that since we support of-tree builds. [target.'cfg(any(target_os = "linux", target_os = "macos"))'.dependencies.tikv-jemalloc-sys] -version = "0.6.1" -features = ['override_allocator_on_supported_platforms'] +version = "0.6.0" +features = ['unprefixed_malloc_on_supported_platforms'] [target.'cfg(unix)'.dependencies] libc = "0.2" diff --git a/rust-version b/rust-version index 7dde150d1e..06a5970646 100644 --- a/rust-version +++ b/rust-version @@ -1 +1 @@ -0b329f801a09004dacb19aaf09d5cb8b4c51d3f8 +7a72c5459dd58f81b0e1a0e5436d145485889375 diff --git a/src/bin/miri.rs b/src/bin/miri.rs index 8b4445e379..920fc29481 100644 --- a/src/bin/miri.rs +++ b/src/bin/miri.rs @@ -20,11 +20,6 @@ extern crate rustc_middle; extern crate rustc_session; extern crate rustc_span; -/// See docs in https://github.com/rust-lang/rust/blob/HEAD/compiler/rustc/src/main.rs -/// and https://github.com/rust-lang/rust/pull/146627 for why we need this `use` statement. -#[cfg(any(target_os = "linux", target_os = "macos"))] -use tikv_jemalloc_sys as _; - mod log; use std::env; @@ -397,7 +392,48 @@ fn parse_range(val: &str) -> Result, &'static str> { Ok(from..to) } +#[cfg(any(target_os = "linux", target_os = "macos"))] +fn jemalloc_magic() { + // These magic runes are copied from + // . + // See there for further comments. + use std::os::raw::{c_int, c_void}; + + use tikv_jemalloc_sys as jemalloc_sys; + + #[used] + static _F1: unsafe extern "C" fn(usize, usize) -> *mut c_void = jemalloc_sys::calloc; + #[used] + static _F2: unsafe extern "C" fn(*mut *mut c_void, usize, usize) -> c_int = + jemalloc_sys::posix_memalign; + #[used] + static _F3: unsafe extern "C" fn(usize, usize) -> *mut c_void = jemalloc_sys::aligned_alloc; + #[used] + static _F4: unsafe extern "C" fn(usize) -> *mut c_void = jemalloc_sys::malloc; + #[used] + static _F5: unsafe extern "C" fn(*mut c_void, usize) -> *mut c_void = jemalloc_sys::realloc; + #[used] + static _F6: unsafe extern "C" fn(*mut c_void) = jemalloc_sys::free; + + // On OSX, jemalloc doesn't directly override malloc/free, but instead + // registers itself with the allocator's zone APIs in a ctor. However, + // the linker doesn't seem to consider ctors as "used" when statically + // linking, so we need to explicitly depend on the function. + #[cfg(target_os = "macos")] + { + unsafe extern "C" { + fn _rjem_je_zone_register(); + } + + #[used] + static _F7: unsafe extern "C" fn() = _rjem_je_zone_register; + } +} + fn main() { + #[cfg(any(target_os = "linux", target_os = "macos"))] + jemalloc_magic(); + let early_dcx = EarlyDiagCtxt::new(ErrorOutputType::default()); // Snapshot a copy of the environment before `rustc` starts messing with it. diff --git a/src/lib.rs b/src/lib.rs index 4a48672660..3137cfc833 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,7 +17,7 @@ #![feature(derive_coerce_pointee)] #![feature(arbitrary_self_types)] #![feature(iter_advance_by)] -#![feature(duration_from_nanos_u128)] +#![cfg_attr(bootstrap, feature(duration_from_nanos_u128))] // Configure clippy and other lints #![allow( clippy::collapsible_else_if,