|
| 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 | + |
1 | 11 | 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 | + ) => { |
3 | 19 | #[cfg(feature = "jit")]
|
4 | 20 | #[allow(improper_ctypes)]
|
5 | 21 | extern "C" {
|
6 |
| - $(fn $name($($arg_name: $arg_ty),*) -> $ret_ty;)* |
| 22 | + $( |
| 23 | + $(#[$attr])? |
| 24 | + fn $name($($arg_name: $arg_ty),*) -> $ret_ty; |
| 25 | + )* |
7 | 26 | }
|
8 | 27 |
|
9 | 28 | #[cfg(feature = "jit")]
|
10 | 29 | 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)),*] { |
12 | 31 | builder.symbol(name, val);
|
13 | 32 | }
|
14 | 33 | }
|
@@ -40,4 +59,17 @@ builtin_functions! {
|
40 | 59 | fn __fixdfti(f: f64) -> i128;
|
41 | 60 | fn __fixunssfti(f: f32) -> u128;
|
42 | 61 | 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 | + |
43 | 75 | }
|
0 commit comments