rustc_driver_impl/allocator.rs
1/// This macro overrides the C allocator (i.e., `malloc`) in final binaries by linking
2/// jemalloc with the override feature enabled. The C allocator is used by the default
3/// Rust allocator (`alloc::System`) on Unix targets but not on Windows targets.
4#[cfg(feature = "jemalloc")]
5#[macro_export]
6macro_rules! override_c_allocator_in_binary {
7 () => {
8 // NOTE: even though Cargo passes `--extern` for this in rustc-main, the crate still has
9 // to be named for the compiler to see the `#[used]` inside it, see
10 // <https://github.com/rust-lang/rust/issues/64402>.
11 //
12 // FIXME(madsmtm): for the rustc-private tools this is loaded from the sysroot that was
13 // built with the other `rustc` crates, instead of via Cargo as you'd normally do. This is
14 // currently needed for LTO due to <https://github.com/rust-lang/cc-rs/issues/1613>.
15 extern crate tikv_jemalloc_sys as _;
16 };
17}
18
19/// This macro does nothing when no allocator features are enabled.
20#[cfg(not(feature = "jemalloc"))]
21#[macro_export]
22macro_rules! override_c_allocator_in_binary {
23 () => {};
24}