Skip to content

Commit 7d53619

Browse files
committed
Force the allocator to be looked up from the perspective of the rustc binary
Fixes #1303
1 parent 8494882 commit 7d53619

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

.github/workflows/main.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
fail-fast: false
3535
matrix:
3636
include:
37-
- os: ubuntu-20.04 # FIXME switch to ubuntu-22.04 once #1303 is fixed
37+
- os: ubuntu-latest
3838
env:
3939
TARGET_TRIPLE: x86_64-unknown-linux-gnu
4040
- os: macos-latest
@@ -226,7 +226,8 @@ jobs:
226226
fail-fast: false
227227
matrix:
228228
include:
229-
- os: ubuntu-20.04 # FIXME switch to ubuntu-22.04 once #1303 is fixed
229+
# FIXME update at some point in the future once most distros use a newer glibc
230+
- os: ubuntu-20.04
230231
env:
231232
TARGET_TRIPLE: x86_64-unknown-linux-gnu
232233
- os: macos-latest

src/compiler_builtins.rs

+35-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,33 @@
1+
#[cfg(all(unix, feature = "jit"))]
2+
use std::ffi::c_int;
3+
#[cfg(feature = "jit")]
4+
use std::ffi::c_void;
5+
6+
// FIXME replace with core::ffi::c_size_t once stablized
7+
#[allow(non_camel_case_types)]
8+
#[cfg(feature = "jit")]
9+
type size_t = usize;
10+
111
macro_rules! builtin_functions {
2-
($register:ident; $(fn $name:ident($($arg_name:ident: $arg_ty:ty),*) -> $ret_ty:ty;)*) => {
12+
(
13+
$register:ident;
14+
$(
15+
$(#[$attr:meta])?
16+
fn $name:ident($($arg_name:ident: $arg_ty:ty),*) -> $ret_ty:ty;
17+
)*
18+
) => {
319
#[cfg(feature = "jit")]
420
#[allow(improper_ctypes)]
521
extern "C" {
6-
$(fn $name($($arg_name: $arg_ty),*) -> $ret_ty;)*
22+
$(
23+
$(#[$attr])?
24+
fn $name($($arg_name: $arg_ty),*) -> $ret_ty;
25+
)*
726
}
827

928
#[cfg(feature = "jit")]
1029
pub(crate) fn $register(builder: &mut cranelift_jit::JITBuilder) {
11-
for (name, val) in [$((stringify!($name), $name as *const u8)),*] {
30+
for (name, val) in [$($(#[$attr])? (stringify!($name), $name as *const u8)),*] {
1231
builder.symbol(name, val);
1332
}
1433
}
@@ -40,4 +59,17 @@ builtin_functions! {
4059
fn __fixdfti(f: f64) -> i128;
4160
fn __fixunssfti(f: f32) -> u128;
4261
fn __fixunsdfti(f: f64) -> u128;
62+
63+
// allocator
64+
// NOTE: These need to be mentioned here despite not being part of compiler_builtins because
65+
// newer glibc resolve dlsym("malloc") to libc.so despite the override in the rustc binary to
66+
// use jemalloc. Libraries opened with dlopen still get the jemalloc version, causing multiple
67+
// allocators to be mixed, resulting in a crash.
68+
fn calloc(nobj: size_t, size: size_t) -> *mut c_void;
69+
#[cfg(unix)]
70+
fn posix_memalign(memptr: *mut *mut c_void, align: size_t, size: size_t) -> c_int;
71+
fn malloc(size: size_t) -> *mut c_void;
72+
fn realloc(p: *mut c_void, size: size_t) -> *mut c_void;
73+
fn free(p: *mut c_void) -> ();
74+
4375
}

0 commit comments

Comments
 (0)