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