jemallocator
jemallocator copied to clipboard
Make unprefixed consistently override the system allocator
The goal is to move the various workarounds for this feature in rustc to the jemalloc-sys crate instead.
I'm not entirely sure of the history here, but it is possible this was not done in the past because #[used] used to not work in libraries? In any case, we should be able to do it now.
Note that due to https://github.com/rust-lang/rust/issues/133491, #[used] in libraries still doesn't work on macOS.
I tried to write a test for this, but it's just a very platform-specific issue, and I found it hard to exercise properly. You should be able to test it in rustc with something like the following:
#[cfg(feature = "jemalloc")]
use tikv_jemalloc_sys as _;
#[cfg(feature = "jemalloc")]
#[cfg(target_vendor = "apple")]
#[used]
static USED_ZONE_REGISTER: unsafe extern "C" fn() = {
extern "C" {
fn _rjem_je_zone_register();
}
_rjem_je_zone_register
};
fn main() {
rustc_driver::main()
}
Welcome @madsmtm! It looks like this is your first PR to tikv/jemallocator 🎉
Ping @BusyJay, could you take a look? This would be nice to get in, it'd simplify rustc's main function quite a bit.
I tested this a bit more thoroughly together with mimalloc in https://github.com/madsmtm/test-malloc-overriding btw, have updated the test included in this PR based on that.
Rest LGTM
I think I've fixed the things you requested now
Fixed CI
Thank you!
Would it be possible to get this published as v0.6.1? I can make a PR for it if you want?