about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbjorn3 <17426603+bjorn3@users.noreply.github.com>2023-02-06 19:27:27 +0100
committerbjorn3 <17426603+bjorn3@users.noreply.github.com>2023-02-07 15:37:49 +0100
commit7d53619064ab7045c383644cb445052d2a3d46db (patch)
treec7e189a8b6eb62bd513785a083482edc48cdca05
parent8494882773392b461e9609e4f4a60818b26e964c (diff)
downloadrust-7d53619064ab7045c383644cb445052d2a3d46db.tar.gz
rust-7d53619064ab7045c383644cb445052d2a3d46db.zip
Force the allocator to be looked up from the perspective of the rustc binary
Fixes #1303
-rw-r--r--.github/workflows/main.yml5
-rw-r--r--src/compiler_builtins.rs38
2 files changed, 38 insertions, 5 deletions
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 9d67886ba86..9d3ed3ac5d0 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -34,7 +34,7 @@ jobs:
       fail-fast: false
       matrix:
         include:
-          - os: ubuntu-20.04 # FIXME switch to ubuntu-22.04 once #1303 is fixed
+          - os: ubuntu-latest
             env:
               TARGET_TRIPLE: x86_64-unknown-linux-gnu
           - os: macos-latest
@@ -226,7 +226,8 @@ jobs:
       fail-fast: false
       matrix:
         include:
-          - os: ubuntu-20.04 # FIXME switch to ubuntu-22.04 once #1303 is fixed
+          # FIXME update at some point in the future once most distros use a newer glibc
+          - os: ubuntu-20.04
             env:
               TARGET_TRIPLE: x86_64-unknown-linux-gnu
           - os: macos-latest
diff --git a/src/compiler_builtins.rs b/src/compiler_builtins.rs
index c6a247cf59e..8a53baa763a 100644
--- a/src/compiler_builtins.rs
+++ b/src/compiler_builtins.rs
@@ -1,14 +1,33 @@
+#[cfg(all(unix, feature = "jit"))]
+use std::ffi::c_int;
+#[cfg(feature = "jit")]
+use std::ffi::c_void;
+
+// FIXME replace with core::ffi::c_size_t once stablized
+#[allow(non_camel_case_types)]
+#[cfg(feature = "jit")]
+type size_t = usize;
+
 macro_rules! builtin_functions {
-    ($register:ident; $(fn $name:ident($($arg_name:ident: $arg_ty:ty),*) -> $ret_ty:ty;)*) => {
+    (
+        $register:ident;
+        $(
+            $(#[$attr:meta])?
+            fn $name:ident($($arg_name:ident: $arg_ty:ty),*) -> $ret_ty:ty;
+        )*
+    ) => {
         #[cfg(feature = "jit")]
         #[allow(improper_ctypes)]
         extern "C" {
-            $(fn $name($($arg_name: $arg_ty),*) -> $ret_ty;)*
+            $(
+                $(#[$attr])?
+                fn $name($($arg_name: $arg_ty),*) -> $ret_ty;
+            )*
         }
 
         #[cfg(feature = "jit")]
         pub(crate) fn $register(builder: &mut cranelift_jit::JITBuilder) {
-            for (name, val) in [$((stringify!($name), $name as *const u8)),*] {
+            for (name, val) in [$($(#[$attr])? (stringify!($name), $name as *const u8)),*] {
                 builder.symbol(name, val);
             }
         }
@@ -40,4 +59,17 @@ builtin_functions! {
     fn __fixdfti(f: f64) -> i128;
     fn __fixunssfti(f: f32) -> u128;
     fn __fixunsdfti(f: f64) -> u128;
+
+    // allocator
+    // NOTE: These need to be mentioned here despite not being part of compiler_builtins because
+    // newer glibc resolve dlsym("malloc") to libc.so despite the override in the rustc binary to
+    // use jemalloc. Libraries opened with dlopen still get the jemalloc version, causing multiple
+    // allocators to be mixed, resulting in a crash.
+    fn calloc(nobj: size_t, size: size_t) -> *mut c_void;
+    #[cfg(unix)]
+    fn posix_memalign(memptr: *mut *mut c_void, align: size_t, size: size_t) -> c_int;
+    fn malloc(size: size_t) -> *mut c_void;
+    fn realloc(p: *mut c_void, size: size_t) -> *mut c_void;
+    fn free(p: *mut c_void) -> ();
+
 }