about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDylan DPC <dylan.dpc@gmail.com>2021-03-08 13:13:22 +0100
committerGitHub <noreply@github.com>2021-03-08 13:13:22 +0100
commit7b78d86d6a084e714243f41c65b70517e93b1076 (patch)
tree161c5f886f03d08b24094549cef06df68170e4d1
parent06819512877bc65ee6571709a32ec26d42ad510e (diff)
parent1b4860ab2a70c4bc76661aa3f87d0ad09655a2f6 (diff)
downloadrust-7b78d86d6a084e714243f41c65b70517e93b1076.tar.gz
rust-7b78d86d6a084e714243f41c65b70517e93b1076.zip
Rollup merge of #82642 - sfackler:jemalloc-zone, r=pnkfelix
Fix jemalloc usage on OSX

Closes #82423
-rw-r--r--compiler/rustc/src/main.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/compiler/rustc/src/main.rs b/compiler/rustc/src/main.rs
index 0151973eccf..859028957db 100644
--- a/compiler/rustc/src/main.rs
+++ b/compiler/rustc/src/main.rs
@@ -24,6 +24,20 @@ fn main() {
         static _F5: unsafe extern "C" fn(*mut c_void, usize) -> *mut c_void = jemalloc_sys::realloc;
         #[used]
         static _F6: unsafe extern "C" fn(*mut c_void) = jemalloc_sys::free;
+
+        // On OSX, jemalloc doesn't directly override malloc/free, but instead
+        // registers itself with the allocator's zone APIs in a ctor. However,
+        // the linker doesn't seem to consider ctors as "used" when statically
+        // linking, so we need to explicitly depend on the function.
+        #[cfg(target_os = "macos")]
+        {
+            extern "C" {
+                fn _rjem_je_zone_register();
+            }
+
+            #[used]
+            static _F7: unsafe extern "C" fn() = _rjem_je_zone_register;
+        }
     }
 
     rustc_driver::set_sigpipe_handler();