@@ -20,6 +20,11 @@ extern crate rustc_middle;
2020extern crate rustc_session;
2121extern crate rustc_span;
2222
23+ /// See docs in https://github.com/rust-lang/rust/blob/HEAD/compiler/rustc/src/main.rs
24+ /// and https://github.com/rust-lang/rust/pull/146627 for why we need this `use` statement.
25+ #[ cfg( any( target_os = "linux" , target_os = "macos" ) ) ]
26+ use tikv_jemalloc_sys as _;
27+
2328mod log;
2429
2530use std:: env;
@@ -395,48 +400,7 @@ fn parse_range(val: &str) -> Result<Range<u32>, &'static str> {
395400 Ok ( from..to)
396401}
397402
398- #[ cfg( any( target_os = "linux" , target_os = "macos" ) ) ]
399- fn jemalloc_magic ( ) {
400- // These magic runes are copied from
401- // <https://github.com/rust-lang/rust/blob/e89bd9428f621545c979c0ec686addc6563a394e/compiler/rustc/src/main.rs#L39>.
402- // See there for further comments.
403- use std:: os:: raw:: { c_int, c_void} ;
404-
405- use tikv_jemalloc_sys as jemalloc_sys;
406-
407- #[ used]
408- static _F1: unsafe extern "C" fn ( usize , usize ) -> * mut c_void = jemalloc_sys:: calloc;
409- #[ used]
410- static _F2: unsafe extern "C" fn ( * mut * mut c_void , usize , usize ) -> c_int =
411- jemalloc_sys:: posix_memalign;
412- #[ used]
413- static _F3: unsafe extern "C" fn ( usize , usize ) -> * mut c_void = jemalloc_sys:: aligned_alloc;
414- #[ used]
415- static _F4: unsafe extern "C" fn ( usize ) -> * mut c_void = jemalloc_sys:: malloc;
416- #[ used]
417- static _F5: unsafe extern "C" fn ( * mut c_void , usize ) -> * mut c_void = jemalloc_sys:: realloc;
418- #[ used]
419- static _F6: unsafe extern "C" fn ( * mut c_void ) = jemalloc_sys:: free;
420-
421- // On OSX, jemalloc doesn't directly override malloc/free, but instead
422- // registers itself with the allocator's zone APIs in a ctor. However,
423- // the linker doesn't seem to consider ctors as "used" when statically
424- // linking, so we need to explicitly depend on the function.
425- #[ cfg( target_os = "macos" ) ]
426- {
427- unsafe extern "C" {
428- fn _rjem_je_zone_register ( ) ;
429- }
430-
431- #[ used]
432- static _F7: unsafe extern "C" fn ( ) = _rjem_je_zone_register;
433- }
434- }
435-
436403fn main ( ) {
437- #[ cfg( any( target_os = "linux" , target_os = "macos" ) ) ]
438- jemalloc_magic ( ) ;
439-
440404 let early_dcx = EarlyDiagCtxt :: new ( ErrorOutputType :: default ( ) ) ;
441405
442406 // Snapshot a copy of the environment before `rustc` starts messing with it.
0 commit comments