From 0f657ac3706935687aec5a04e9922ae001fe244f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20K=C3=A5re=20Alsaker?= Date: Mon, 11 Mar 2024 06:04:56 +0100 Subject: [PATCH] Redirect `__rust_dealloc` to `sdallocx` --- compiler/rustc/src/main.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/compiler/rustc/src/main.rs b/compiler/rustc/src/main.rs index 434b978ae3151..28d861abfd1e7 100644 --- a/compiler/rustc/src/main.rs +++ b/compiler/rustc/src/main.rs @@ -34,6 +34,15 @@ // https://github.com/rust-lang/rust/commit/b90cfc887c31c3e7a9e6d462e2464db1fe506175#diff-43914724af6e464c1da2171e4a9b6c7e607d5bc1203fa95c0ab85be4122605ef // for an example of how to do so. +/// This redirects `__rust_dealloc` to jemalloc so it can make use of the size of the allocation. +#[cfg(feature = "jemalloc-sys")] +#[no_mangle] +pub unsafe extern "C" fn __rust_dealloc(ptr: *mut u8, size: usize, _align: usize) { + unsafe { jemalloc_sys::sdallocx(ptr.cast(), size, 0) } + #[used] + static _USED: unsafe extern "C" fn(*mut u8, usize, usize) = __rust_dealloc; +} + #[unix_sigpipe = "sig_dfl"] fn main() { // See the comment at the top of this file for an explanation of this.