@@ -293,13 +293,51 @@ fn run_compiler(
293
293
}
294
294
295
295
/// Parses a comma separated list of `T` from the given string:
296
- ///
297
296
/// `<value1>,<value2>,<value3>,...`
298
297
fn parse_comma_list < T : FromStr > ( input : & str ) -> Result < Vec < T > , T :: Err > {
299
298
input. split ( ',' ) . map ( str:: parse :: < T > ) . collect ( )
300
299
}
301
300
301
+ #[ cfg( unix) ]
302
+ fn jemalloc_magic ( ) {
303
+ // These magic runes are copied from
304
+ // <https://github.com/rust-lang/rust/blob/e89bd9428f621545c979c0ec686addc6563a394e/compiler/rustc/src/main.rs#L39>.
305
+ // See there for further comments.
306
+ use std:: os:: raw:: { c_int, c_void} ;
307
+
308
+ #[ used]
309
+ static _F1: unsafe extern "C" fn ( usize , usize ) -> * mut c_void = jemalloc_sys:: calloc;
310
+ #[ used]
311
+ static _F2: unsafe extern "C" fn ( * mut * mut c_void , usize , usize ) -> c_int =
312
+ jemalloc_sys:: posix_memalign;
313
+ #[ used]
314
+ static _F3: unsafe extern "C" fn ( usize , usize ) -> * mut c_void = jemalloc_sys:: aligned_alloc;
315
+ #[ used]
316
+ static _F4: unsafe extern "C" fn ( usize ) -> * mut c_void = jemalloc_sys:: malloc;
317
+ #[ used]
318
+ static _F5: unsafe extern "C" fn ( * mut c_void , usize ) -> * mut c_void = jemalloc_sys:: realloc;
319
+ #[ used]
320
+ static _F6: unsafe extern "C" fn ( * mut c_void ) = jemalloc_sys:: free;
321
+
322
+ // On OSX, jemalloc doesn't directly override malloc/free, but instead
323
+ // registers itself with the allocator's zone APIs in a ctor. However,
324
+ // the linker doesn't seem to consider ctors as "used" when statically
325
+ // linking, so we need to explicitly depend on the function.
326
+ #[ cfg( target_os = "macos" ) ]
327
+ {
328
+ extern "C" {
329
+ fn _rjem_je_zone_register ( ) ;
330
+ }
331
+
332
+ #[ used]
333
+ static _F7: unsafe extern "C" fn ( ) = _rjem_je_zone_register;
334
+ }
335
+ }
336
+
302
337
fn main ( ) {
338
+ #[ cfg( unix) ]
339
+ jemalloc_magic ( ) ;
340
+
303
341
let early_dcx = EarlyDiagCtxt :: new ( ErrorOutputType :: default ( ) ) ;
304
342
305
343
// Snapshot a copy of the environment before `rustc` starts messing with it.
0 commit comments