diff --git a/Cargo.lock b/Cargo.lock index b0ffa716ccfe4..8b860ad636c4e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -839,6 +839,12 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "cty" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b365fabc795046672053e29c954733ec3b05e4be654ab130fe8f1f94d7051f35" + [[package]] name = "curl" version = "0.4.46" @@ -2000,6 +2006,17 @@ version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" +[[package]] +name = "libmimalloc-sys" +version = "0.1.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23aa6811d3bd4deb8a84dde645f943476d13b248d818edcf8ce0b2f37f036b44" +dependencies = [ + "cc", + "cty", + "libc", +] + [[package]] name = "libredox" version = "0.1.3" @@ -3153,7 +3170,7 @@ checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" name = "rustc-main" version = "0.0.0" dependencies = [ - "jemalloc-sys", + "libmimalloc-sys", "rustc_codegen_ssa", "rustc_driver", "rustc_driver_impl", diff --git a/compiler/rustc/Cargo.toml b/compiler/rustc/Cargo.toml index a2fc9d5c408e3..78c991f0a53e1 100644 --- a/compiler/rustc/Cargo.toml +++ b/compiler/rustc/Cargo.toml @@ -20,16 +20,17 @@ rustc_smir = { path = "../rustc_smir" } stable_mir = { path = "../stable_mir" } # tidy-alphabetical-end -[dependencies.jemalloc-sys] -version = "0.5.0" +[dependencies.libmimalloc-sys] +version = "0.1.39" optional = true -features = ['unprefixed_malloc_on_supported_platforms'] +default-features = false +features = ['extended', 'override'] [features] # tidy-alphabetical-start -jemalloc = ['dep:jemalloc-sys'] llvm = ['rustc_driver_impl/llvm'] max_level_info = ['rustc_driver_impl/max_level_info'] +mimalloc = ['dep:libmimalloc-sys'] rustc_randomized_layouts = ['rustc_driver_impl/rustc_randomized_layouts'] rustc_use_parallel_compiler = ['rustc_driver_impl/rustc_use_parallel_compiler'] # tidy-alphabetical-end diff --git a/compiler/rustc/src/main.rs b/compiler/rustc/src/main.rs index ccf88d8ff4bc8..80157ba8f59f7 100644 --- a/compiler/rustc/src/main.rs +++ b/compiler/rustc/src/main.rs @@ -39,36 +39,38 @@ fn main() { // See the comment at the top of this file for an explanation of this. - #[cfg(feature = "jemalloc")] + #[cfg(feature = "mimalloc")] { use std::os::raw::{c_int, c_void}; #[used] - static _F1: unsafe extern "C" fn(usize, usize) -> *mut c_void = jemalloc_sys::calloc; + static _F1: unsafe extern "C" fn(usize, usize) -> *mut c_void = libmimalloc_sys::calloc; #[used] static _F2: unsafe extern "C" fn(*mut *mut c_void, usize, usize) -> c_int = - jemalloc_sys::posix_memalign; + libmimalloc_sys::posix_memalign; #[used] - static _F3: unsafe extern "C" fn(usize, usize) -> *mut c_void = jemalloc_sys::aligned_alloc; + static _F3: unsafe extern "C" fn(usize, usize) -> *mut c_void = + libmimalloc_sys::aligned_alloc; #[used] - static _F4: unsafe extern "C" fn(usize) -> *mut c_void = jemalloc_sys::malloc; + static _F4: unsafe extern "C" fn(usize) -> *mut c_void = libmimalloc_sys::malloc; #[used] - static _F5: unsafe extern "C" fn(*mut c_void, usize) -> *mut c_void = jemalloc_sys::realloc; + static _F5: unsafe extern "C" fn(*mut c_void, usize) -> *mut c_void = + libmimalloc_sys::realloc; #[used] - static _F6: unsafe extern "C" fn(*mut c_void) = jemalloc_sys::free; + static _F6: unsafe extern "C" fn(*mut c_void) = libmimalloc_sys::free; - // On OSX, jemalloc doesn't directly override malloc/free, but instead + // On OSX, mimalloc 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")] { extern "C" { - fn _rjem_je_zone_register(); + fn _mi_macros_override_malloc(); } #[used] - static _F7: unsafe extern "C" fn() = _rjem_je_zone_register; + static _F7: unsafe extern "C" fn() = _mi_macros_override_malloc; } } diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs index 3394f2a84a047..569d6ad78356c 100644 --- a/src/bootstrap/src/core/build_steps/compile.rs +++ b/src/bootstrap/src/core/build_steps/compile.rs @@ -2094,11 +2094,11 @@ pub fn run_cargo( // During check builds we need to keep crate metadata keep = true; } else if rlib_only_metadata { - if filename.contains("jemalloc_sys") + if filename.contains("libmimalloc_sys") || filename.contains("rustc_smir") || filename.contains("stable_mir") { - // jemalloc_sys and rustc_smir are not linked into librustc_driver.so, + // libmimalloc_sys and rustc_smir are not linked into librustc_driver.so, // so we need to distribute them as rlib to be able to use them. keep |= filename.ends_with(".rlib"); } else { diff --git a/src/bootstrap/src/core/build_steps/tool.rs b/src/bootstrap/src/core/build_steps/tool.rs index 3cfbef27f87ad..5e3ac89bb425b 100644 --- a/src/bootstrap/src/core/build_steps/tool.rs +++ b/src/bootstrap/src/core/build_steps/tool.rs @@ -636,8 +636,8 @@ impl Step for Rustdoc { // to build rustdoc. // let mut features = Vec::new(); - if builder.config.jemalloc { - features.push("jemalloc".to_string()); + if builder.config.mimalloc { + features.push("mimalloc".to_string()); } // NOTE: Never modify the rustflags here, it breaks the build cache for other tools! diff --git a/src/bootstrap/src/core/config/config.rs b/src/bootstrap/src/core/config/config.rs index f977c285a74c1..0e5c8054c31ca 100644 --- a/src/bootstrap/src/core/config/config.rs +++ b/src/bootstrap/src/core/config/config.rs @@ -304,7 +304,7 @@ pub struct Config { pub hosts: Vec, pub targets: Vec, pub local_rebuild: bool, - pub jemalloc: bool, + pub mimalloc: bool, pub control_flow_guard: bool, pub ehcont_guard: bool, @@ -1155,7 +1155,7 @@ define_config! { verify_llvm_ir: Option = "verify-llvm-ir", thin_lto_import_instr_limit: Option = "thin-lto-import-instr-limit", remap_debuginfo: Option = "remap-debuginfo", - jemalloc: Option = "jemalloc", + mimalloc: Option = "mimalloc", test_compare_mode: Option = "test-compare-mode", llvm_libunwind: Option = "llvm-libunwind", control_flow_guard: Option = "control-flow-guard", @@ -1711,7 +1711,7 @@ impl Config { verify_llvm_ir, thin_lto_import_instr_limit, remap_debuginfo, - jemalloc, + mimalloc, test_compare_mode, llvm_libunwind, control_flow_guard, @@ -1758,7 +1758,7 @@ impl Config { set(&mut config.rust_strip, strip); set(&mut config.rust_frame_pointers, frame_pointers); config.rust_stack_protector = stack_protector; - set(&mut config.jemalloc, jemalloc); + set(&mut config.mimalloc, mimalloc); set(&mut config.test_compare_mode, test_compare_mode); set(&mut config.backtrace, backtrace); config.description = description; @@ -3064,7 +3064,7 @@ fn check_incompatible_options_for_ci_rustc( stack_protector, strip, lld_mode, - jemalloc, + mimalloc, rpath, channel, description, @@ -3128,7 +3128,7 @@ fn check_incompatible_options_for_ci_rustc( err!(current_rust_config.lld_mode, lld_mode); err!(current_rust_config.llvm_tools, llvm_tools); err!(current_rust_config.llvm_bitcode_linker, llvm_bitcode_linker); - err!(current_rust_config.jemalloc, jemalloc); + err!(current_rust_config.mimalloc, mimalloc); err!(current_rust_config.default_linker, default_linker); err!(current_rust_config.stack_protector, stack_protector); err!(current_rust_config.lto, lto); diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs index ba74cabcd306a..df09e20a78fdb 100644 --- a/src/bootstrap/src/lib.rs +++ b/src/bootstrap/src/lib.rs @@ -688,8 +688,8 @@ impl Build { crates.is_empty() || possible_features_by_crates.contains(feature) }; let mut features = vec![]; - if self.config.jemalloc && check("jemalloc") { - features.push("jemalloc"); + if self.config.mimalloc && check("mimalloc") { + features.push("mimalloc"); } if (self.config.llvm_enabled(target) || kind == Kind::Check) && check("llvm") { features.push("llvm"); diff --git a/src/tools/tidy/src/deps.rs b/src/tools/tidy/src/deps.rs index 8e12db409ecf8..25c21cb593245 100644 --- a/src/tools/tidy/src/deps.rs +++ b/src/tools/tidy/src/deps.rs @@ -259,6 +259,7 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[ "crossbeam-utils", "crypto-common", "ctrlc", + "cty", "darling", "darling_core", "darling_macro", @@ -304,12 +305,12 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[ "intl_pluralrules", "itertools", "itoa", - "jemalloc-sys", "jobserver", "lazy_static", "leb128", "libc", "libloading", + "libmimalloc-sys", "linux-raw-sys", "litemap", "lock_api",