Skip to content

Commit 7b78d86

Browse files
authored
Rollup merge of #82642 - sfackler:jemalloc-zone, r=pnkfelix
Fix jemalloc usage on OSX Closes #82423
2 parents 0681951 + 1b4860a commit 7b78d86

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

compiler/rustc/src/main.rs

+14
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,20 @@ fn main() {
2424
static _F5: unsafe extern "C" fn(*mut c_void, usize) -> *mut c_void = jemalloc_sys::realloc;
2525
#[used]
2626
static _F6: unsafe extern "C" fn(*mut c_void) = jemalloc_sys::free;
27+
28+
// On OSX, jemalloc doesn't directly override malloc/free, but instead
29+
// registers itself with the allocator's zone APIs in a ctor. However,
30+
// the linker doesn't seem to consider ctors as "used" when statically
31+
// linking, so we need to explicitly depend on the function.
32+
#[cfg(target_os = "macos")]
33+
{
34+
extern "C" {
35+
fn _rjem_je_zone_register();
36+
}
37+
38+
#[used]
39+
static _F7: unsafe extern "C" fn() = _rjem_je_zone_register;
40+
}
2741
}
2842

2943
rustc_driver::set_sigpipe_handler();

0 commit comments

Comments
 (0)