From 6e52b23fa94ed967daed38cb3796d0874ec705a7 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Sun, 28 Feb 2021 14:50:03 -0500 Subject: [PATCH 1/2] Fix jemalloc usage on OSX Closes #82423 --- compiler/rustc/src/main.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/compiler/rustc/src/main.rs b/compiler/rustc/src/main.rs index 6bc5aa6382c..3f03d1b6869 100644 --- a/compiler/rustc/src/main.rs +++ b/compiler/rustc/src/main.rs @@ -24,6 +24,20 @@ fn main() { 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")] + { + extern "C" { + fn _rjem_je_zone_register(); + } + + #[used] + static _F7: unsafe extern "C" fn() = _rjem_je_zone_register(); + } } rustc_driver::set_sigpipe_handler(); From 1b4860ab2a70c4bc76661aa3f87d0ad09655a2f6 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Fri, 5 Mar 2021 07:12:02 -0500 Subject: [PATCH 2/2] Update compiler/rustc/src/main.rs --- compiler/rustc/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc/src/main.rs b/compiler/rustc/src/main.rs index 3f03d1b6869..8c5447a91cd 100644 --- a/compiler/rustc/src/main.rs +++ b/compiler/rustc/src/main.rs @@ -36,7 +36,7 @@ fn main() { } #[used] - static _F7: unsafe extern "C" fn() = _rjem_je_zone_register(); + static _F7: unsafe extern "C" fn() = _rjem_je_zone_register; } }