jemallocator icon indicating copy to clipboard operation
jemallocator copied to clipboard

Make unprefixed consistently override the system allocator

Open madsmtm opened this issue 11 months ago • 1 comments

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()
}

madsmtm avatar Dec 15 '24 02:12 madsmtm

Welcome @madsmtm! It looks like this is your first PR to tikv/jemallocator 🎉

ti-chi-bot[bot] avatar Dec 15 '24 02:12 ti-chi-bot[bot]

Ping @BusyJay, could you take a look? This would be nice to get in, it'd simplify rustc's main function quite a bit.

madsmtm avatar Sep 16 '25 09:09 madsmtm

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.

madsmtm avatar Sep 17 '25 02:09 madsmtm

Rest LGTM

BusyJay avatar Sep 22 '25 06:09 BusyJay

I think I've fixed the things you requested now

madsmtm avatar Sep 22 '25 10:09 madsmtm

Fixed CI

madsmtm avatar Sep 22 '25 11:09 madsmtm

Thank you!

BusyJay avatar Sep 23 '25 06:09 BusyJay

Would it be possible to get this published as v0.6.1? I can make a PR for it if you want?

madsmtm avatar Oct 07 '25 08:10 madsmtm