Skip to content

Commit 755d9c8

Browse files
committed
Use fjall as global_allocator for rustc_driver and C allocator for rustc-main
1 parent 8f5e879 commit 755d9c8

File tree

7 files changed

+72
-10
lines changed

7 files changed

+72
-10
lines changed

Cargo.lock

+19
Original file line numberDiff line numberDiff line change
@@ -1319,6 +1319,17 @@ dependencies = [
13191319
"windows-sys 0.52.0",
13201320
]
13211321

1322+
[[package]]
1323+
name = "fjall"
1324+
version = "0.1.0"
1325+
source = "git+https://github.com/Zoxc/fjall.git#06440ceeb3dfd4b6c2c4191f16651fbf02e7a983"
1326+
dependencies = [
1327+
"bitflags 2.4.2",
1328+
"libc",
1329+
"sptr",
1330+
"windows-sys 0.52.0",
1331+
]
1332+
13221333
[[package]]
13231334
name = "flate2"
13241335
version = "1.0.28"
@@ -3387,6 +3398,7 @@ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
33873398
name = "rustc-main"
33883399
version = "0.0.0"
33893400
dependencies = [
3401+
"fjall",
33903402
"jemalloc-sys",
33913403
"rustc_codegen_ssa",
33923404
"rustc_driver",
@@ -3777,6 +3789,7 @@ dependencies = [
37773789
name = "rustc_driver"
37783790
version = "0.0.0"
37793791
dependencies = [
3792+
"fjall",
37803793
"rustc_driver_impl",
37813794
]
37823795

@@ -5176,6 +5189,12 @@ dependencies = [
51765189
"uuid",
51775190
]
51785191

5192+
[[package]]
5193+
name = "sptr"
5194+
version = "0.3.2"
5195+
source = "registry+https://github.com/rust-lang/crates.io-index"
5196+
checksum = "3b9b39299b249ad65f3b7e96443bad61c02ca5cd3589f46cb6d610a0fd6c0d6a"
5197+
51795198
[[package]]
51805199
name = "stable_deref_trait"
51815200
version = "1.2.0"

compiler/rustc/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ edition = "2021"
66
[dependencies]
77
# tidy-alphabetical-start
88

9+
fjall = { git = "https://github.com/Zoxc/fjall.git" }
10+
911
# Make sure rustc_codegen_ssa ends up in the sysroot, because this
1012
# crate is intended to be used by codegen backends, which may not be in-tree.
1113
rustc_codegen_ssa = { path = "../rustc_codegen_ssa" }

compiler/rustc/src/main.rs

+40-9
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,38 @@
3636
// https://github.com/rust-lang/rust/commit/b90cfc887c31c3e7a9e6d462e2464db1fe506175#diff-43914724af6e464c1da2171e4a9b6c7e607d5bc1203fa95c0ab85be4122605ef
3737
// for an example of how to do so.
3838

39+
use std::os::raw::{c_int, c_void};
40+
41+
#[no_mangle]
42+
unsafe extern "C" fn calloc(items: usize, size: usize) -> *mut c_void {
43+
fjall::c::calloc(items, size)
44+
}
45+
46+
#[no_mangle]
47+
unsafe extern "C" fn posix_memalign(ptr: *mut *mut c_void, size: usize, align: usize) -> c_int {
48+
fjall::c::posix_memalign(ptr, size, align)
49+
}
50+
51+
#[no_mangle]
52+
unsafe extern "C" fn aligned_alloc(size: usize, align: usize) -> *mut c_void {
53+
fjall::c::aligned_alloc(size, align)
54+
}
55+
56+
#[no_mangle]
57+
unsafe extern "C" fn malloc(size: usize) -> *mut c_void {
58+
fjall::c::malloc(size)
59+
}
60+
61+
#[no_mangle]
62+
unsafe extern "C" fn realloc(ptr: *mut c_void, size: usize) -> *mut c_void {
63+
fjall::c::realloc(ptr, size)
64+
}
65+
66+
#[no_mangle]
67+
unsafe extern "C" fn free(ptr: *mut c_void) {
68+
fjall::c::free(ptr);
69+
}
70+
3971
#[unix_sigpipe = "sig_dfl"]
4072
fn main() {
4173
// See the comment at the top of this file for an explanation of this.
@@ -44,19 +76,18 @@ fn main() {
4476
use std::os::raw::{c_int, c_void};
4577

4678
#[used]
47-
static _F1: unsafe extern "C" fn(usize, usize) -> *mut c_void = jemalloc_sys::calloc;
79+
static _F1: unsafe extern "C" fn(usize, usize) -> *mut c_void = calloc;
4880
#[used]
49-
static _F2: unsafe extern "C" fn(*mut *mut c_void, usize, usize) -> c_int =
50-
jemalloc_sys::posix_memalign;
81+
static _F2: unsafe extern "C" fn(*mut *mut c_void, usize, usize) -> c_int = posix_memalign;
5182
#[used]
52-
static _F3: unsafe extern "C" fn(usize, usize) -> *mut c_void = jemalloc_sys::aligned_alloc;
83+
static _F3: unsafe extern "C" fn(usize, usize) -> *mut c_void = aligned_alloc;
5384
#[used]
54-
static _F4: unsafe extern "C" fn(usize) -> *mut c_void = jemalloc_sys::malloc;
85+
static _F4: unsafe extern "C" fn(usize) -> *mut c_void = malloc;
5586
#[used]
56-
static _F5: unsafe extern "C" fn(*mut c_void, usize) -> *mut c_void = jemalloc_sys::realloc;
87+
static _F5: unsafe extern "C" fn(*mut c_void, usize) -> *mut c_void = realloc;
5788
#[used]
58-
static _F6: unsafe extern "C" fn(*mut c_void) = jemalloc_sys::free;
59-
89+
static _F6: unsafe extern "C" fn(*mut c_void) = free;
90+
/*
6091
// On OSX, jemalloc doesn't directly override malloc/free, but instead
6192
// registers itself with the allocator's zone APIs in a ctor. However,
6293
// the linker doesn't seem to consider ctors as "used" when statically
@@ -69,7 +100,7 @@ fn main() {
69100
70101
#[used]
71102
static _F7: unsafe extern "C" fn() = _rjem_je_zone_register;
72-
}
103+
}*/
73104
}
74105

75106
rustc_driver::main()

compiler/rustc_driver/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ crate-type = ["dylib"]
88

99
[dependencies]
1010
# tidy-alphabetical-start
11+
fjall = { git = "https://github.com/Zoxc/fjall.git" }
1112
rustc_driver_impl = { path = "../rustc_driver_impl" }
1213
# tidy-alphabetical-end

compiler/rustc_driver/src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@
55
#![feature(rustdoc_internals)]
66
#![doc(rust_logo)]
77

8+
#[cfg(not(bootstrap))]
9+
#[global_allocator]
10+
static GLOBAL: fjall::Alloc = fjall::Alloc;
11+
812
pub use rustc_driver_impl::*;

src/tools/tidy/src/deps.rs

+2
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[
237237
"fallible-iterator", // dependency of `thorin`
238238
"fastrand",
239239
"field-offset",
240+
"fjall",
240241
"flate2",
241242
"fluent-bundle",
242243
"fluent-langneg",
@@ -336,6 +337,7 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[
336337
"shlex",
337338
"smallvec",
338339
"snap",
340+
"sptr",
339341
"stable_deref_trait",
340342
"stacker",
341343
"static_assertions",

src/tools/tidy/src/extdeps.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ use std::fs;
44
use std::path::Path;
55

66
/// List of allowed sources for packages.
7-
const ALLOWED_SOURCES: &[&str] = &["\"registry+https://github.com/rust-lang/crates.io-index\""];
7+
const ALLOWED_SOURCES: &[&str] = &[
8+
"\"registry+https://github.com/rust-lang/crates.io-index\"",
9+
"\"git+https://github.com/Zoxc/fjall.git#06440ceeb3dfd4b6c2c4191f16651fbf02e7a983\"",
10+
];
811

912
/// Checks for external package sources. `root` is the path to the directory that contains the
1013
/// workspace `Cargo.toml`.

0 commit comments

Comments
 (0)