@@ -30,6 +30,7 @@ extern crate tracing;
30
30
// So if `rustc` was specified in Cargo.toml, this would spuriously rebuild crates.
31
31
//
32
32
// Dependencies listed in Cargo.toml do not need `extern crate`.
33
+
33
34
extern crate rustc_ast;
34
35
extern crate rustc_ast_lowering;
35
36
extern crate rustc_ast_pretty;
@@ -60,6 +61,15 @@ extern crate rustc_trait_selection;
60
61
extern crate rustc_typeck;
61
62
extern crate test as testing;
62
63
64
+ #[ cfg( feature = "jemalloc" ) ]
65
+ extern crate tikv_jemalloc_sys;
66
+ #[ cfg( feature = "jemalloc" ) ]
67
+ use tikv_jemalloc_sys as jemalloc_sys;
68
+ #[ cfg( feature = "jemalloc" ) ]
69
+ extern crate tikv_jemallocator;
70
+ #[ cfg( feature = "jemalloc" ) ]
71
+ use tikv_jemallocator as jemallocator;
72
+
63
73
use std:: default:: Default ;
64
74
use std:: env;
65
75
use std:: process;
@@ -113,7 +123,48 @@ mod theme;
113
123
mod visit_ast;
114
124
mod visit_lib;
115
125
126
+ // See docs in https://github.com/rust-lang/rust/blob/master/compiler/rustc/src/main.rs
127
+ // about jemallocator
128
+ #[ cfg( feature = "jemalloc" ) ]
129
+ #[ global_allocator]
130
+ static ALLOC : jemallocator:: Jemalloc = jemallocator:: Jemalloc ;
131
+
116
132
pub fn main ( ) {
133
+ // See docs in https://github.com/rust-lang/rust/blob/master/compiler/rustc/src/main.rs
134
+ // about jemalloc-sys
135
+ #[ cfg( feature = "jemalloc" ) ]
136
+ {
137
+ use std:: os:: raw:: { c_int, c_void} ;
138
+
139
+ #[ used]
140
+ static _F1: unsafe extern "C" fn ( usize , usize ) -> * mut c_void = jemalloc_sys:: calloc;
141
+ #[ used]
142
+ static _F2: unsafe extern "C" fn ( * mut * mut c_void , usize , usize ) -> c_int =
143
+ jemalloc_sys:: posix_memalign;
144
+ #[ used]
145
+ static _F3: unsafe extern "C" fn ( usize , usize ) -> * mut c_void = jemalloc_sys:: aligned_alloc;
146
+ #[ used]
147
+ static _F4: unsafe extern "C" fn ( usize ) -> * mut c_void = jemalloc_sys:: malloc;
148
+ #[ used]
149
+ static _F5: unsafe extern "C" fn ( * mut c_void , usize ) -> * mut c_void = jemalloc_sys:: realloc;
150
+ #[ used]
151
+ static _F6: unsafe extern "C" fn ( * mut c_void ) = jemalloc_sys:: free;
152
+
153
+ // On OSX, jemalloc doesn't directly override malloc/free, but instead
154
+ // registers itself with the allocator's zone APIs in a ctor. However,
155
+ // the linker doesn't seem to consider ctors as "used" when statically
156
+ // linking, so we need to explicitly depend on the function.
157
+ #[ cfg( target_os = "macos" ) ]
158
+ {
159
+ extern "C" {
160
+ fn _rjem_je_zone_register ( ) ;
161
+ }
162
+
163
+ #[ used]
164
+ static _F7: unsafe extern "C" fn ( ) = _rjem_je_zone_register;
165
+ }
166
+ }
167
+
117
168
rustc_driver:: set_sigpipe_handler ( ) ;
118
169
rustc_driver:: install_ice_hook ( ) ;
119
170
0 commit comments