1 // Configure jemalloc as the `global_allocator` when configured. This is
2 // so that we use the sized deallocation apis jemalloc provides
3 // (namely `sdallocx`).
5 // The symbol overrides documented below are also performed so that we can
6 // ensure that we use a consistent allocator across the rustc <-> llvm boundary
7 #[cfg(feature = "jemalloc")]
9 static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
11 #[cfg(feature = "tikv-jemalloc-sys")]
12 use tikv_jemalloc_sys as jemalloc_sys;
15 // Pull in jemalloc when enabled.
17 // Note that we're pulling in a static copy of jemalloc which means that to
18 // pull it in we need to actually reference its symbols for it to get
19 // linked. The two crates we link to here, std and rustc_driver, are both
20 // dynamic libraries. That means to pull in jemalloc we actually need to
21 // reference allocation symbols one way or another (as this file is the only
22 // object code in the rustc executable).
23 #[cfg(feature = "tikv-jemalloc-sys")]
25 use std::os::raw::{c_int, c_void};
28 static _F1: unsafe extern "C" fn(usize, usize) -> *mut c_void = jemalloc_sys::calloc;
30 static _F2: unsafe extern "C" fn(*mut *mut c_void, usize, usize) -> c_int =
31 jemalloc_sys::posix_memalign;
33 static _F3: unsafe extern "C" fn(usize, usize) -> *mut c_void = jemalloc_sys::aligned_alloc;
35 static _F4: unsafe extern "C" fn(usize) -> *mut c_void = jemalloc_sys::malloc;
37 static _F5: unsafe extern "C" fn(*mut c_void, usize) -> *mut c_void = jemalloc_sys::realloc;
39 static _F6: unsafe extern "C" fn(*mut c_void) = jemalloc_sys::free;
41 // On OSX, jemalloc doesn't directly override malloc/free, but instead
42 // registers itself with the allocator's zone APIs in a ctor. However,
43 // the linker doesn't seem to consider ctors as "used" when statically
44 // linking, so we need to explicitly depend on the function.
45 #[cfg(target_os = "macos")]
48 fn _rjem_je_zone_register();
52 static _F7: unsafe extern "C" fn() = _rjem_je_zone_register;
56 rustc_driver::set_sigpipe_handler();