|
1 | | -#![feature(rustc_private)] |
2 | 1 | #![feature(link_args)] |
3 | 2 |
|
4 | 3 | // Set the stack size at link time on Windows. See rustc_driver::in_rustc_thread |
|
11 | 10 | // Also, don't forget to set this for rustdoc. |
12 | 11 | extern {} |
13 | 12 |
|
14 | | -extern crate rustc_driver; |
15 | | - |
16 | | -// Note that the linkage here should be all that we need, on Linux we're not |
17 | | -// prefixing the symbols here so this should naturally override our default |
18 | | -// allocator. On OSX it should override via the zone allocator. We shouldn't |
19 | | -// enable this by default on other platforms, so other platforms aren't handled |
20 | | -// here yet. |
21 | | -#[cfg(feature = "jemalloc-sys")] |
22 | | -extern crate jemalloc_sys; |
23 | | - |
24 | 13 | fn main() { |
| 14 | + // Pull in jemalloc when enabled. |
| 15 | + // |
| 16 | + // Note that we're pulling in a static copy of jemalloc which means that to |
| 17 | + // pull it in we need to actually reference its symbols for it to get |
| 18 | + // linked. The two crates we link to here, std and rustc_driver, are both |
| 19 | + // dynamic libraries. That means to pull in jemalloc we need to actually |
| 20 | + // reference allocation symbols one way or another (as this file is the only |
| 21 | + // object code in the rustc executable). |
| 22 | + // |
| 23 | + // As such, here's an interprative dance to slip under LLVM's radar yet |
| 24 | + // please the linker. |
| 25 | + #[cfg(feature = "jemalloc-sys")] { |
| 26 | + if std::env::var("__RUSTC_NEVER_PRESENT_ENV_VAR").is_ok() { |
| 27 | + unsafe { |
| 28 | + jemalloc_sys::calloc(1, 4); |
| 29 | + jemalloc_sys::posix_memalign(&mut std::ptr::null_mut(), 1, 10); |
| 30 | + jemalloc_sys::aligned_alloc(1, 10); |
| 31 | + let a = jemalloc_sys::malloc(3); |
| 32 | + let b = jemalloc_sys::realloc(a, 100); |
| 33 | + println!("{:?}", b); |
| 34 | + jemalloc_sys::free(b); |
| 35 | + } |
| 36 | + } |
| 37 | + } |
| 38 | + |
25 | 39 | rustc_driver::set_sigpipe_handler(); |
26 | 40 | rustc_driver::main() |
27 | 41 | } |
0 commit comments