]> git.lizzy.rs Git - rust.git/blob - compiler/rustc/src/main.rs
Rollup merge of #80543 - LeSeulArtichaut:notify-close, r=spastorino
[rust.git] / compiler / rustc / src / main.rs
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`).
4 //
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")]
8 #[global_allocator]
9 static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
10
11 #[cfg(feature = "tikv-jemalloc-sys")]
12 use tikv_jemalloc_sys as jemalloc_sys;
13
14 fn main() {
15     // Pull in jemalloc when enabled.
16     //
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")]
24     {
25         use std::os::raw::{c_int, c_void};
26
27         #[used]
28         static _F1: unsafe extern "C" fn(usize, usize) -> *mut c_void = jemalloc_sys::calloc;
29         #[used]
30         static _F2: unsafe extern "C" fn(*mut *mut c_void, usize, usize) -> c_int =
31             jemalloc_sys::posix_memalign;
32         #[used]
33         static _F3: unsafe extern "C" fn(usize, usize) -> *mut c_void = jemalloc_sys::aligned_alloc;
34         #[used]
35         static _F4: unsafe extern "C" fn(usize) -> *mut c_void = jemalloc_sys::malloc;
36         #[used]
37         static _F5: unsafe extern "C" fn(*mut c_void, usize) -> *mut c_void = jemalloc_sys::realloc;
38         #[used]
39         static _F6: unsafe extern "C" fn(*mut c_void) = jemalloc_sys::free;
40
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")]
46         {
47             extern "C" {
48                 fn _rjem_je_zone_register();
49             }
50
51             #[used]
52             static _F7: unsafe extern "C" fn() = _rjem_je_zone_register;
53         }
54     }
55
56     rustc_driver::set_sigpipe_handler();
57     rustc_driver::main()
58 }