Skip to content

Commit 4fd8e85

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

File tree

7 files changed

+86
-27
lines changed

7 files changed

+86
-27
lines changed

Diff for: Cargo.lock

+19-1
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#03ef49c19c1688a2d5e73fa4881c12bdc61c02f8"
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,7 +3398,7 @@ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
33873398
name = "rustc-main"
33883399
version = "0.0.0"
33893400
dependencies = [
3390-
"jemalloc-sys",
3401+
"fjall",
33913402
"rustc_codegen_ssa",
33923403
"rustc_driver",
33933404
"rustc_driver_impl",
@@ -3777,6 +3788,7 @@ dependencies = [
37773788
name = "rustc_driver"
37783789
version = "0.0.0"
37793790
dependencies = [
3791+
"fjall",
37803792
"rustc_driver_impl",
37813793
]
37823794

@@ -5176,6 +5188,12 @@ dependencies = [
51765188
"uuid",
51775189
]
51785190

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

Diff for: compiler/rustc/Cargo.toml

+3-6
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" }
@@ -20,14 +22,9 @@ rustc_smir = { path = "../rustc_smir" }
2022
stable_mir = { path = "../stable_mir" }
2123
# tidy-alphabetical-end
2224

23-
[dependencies.jemalloc-sys]
24-
version = "0.5.0"
25-
optional = true
26-
features = ['unprefixed_malloc_on_supported_platforms']
27-
2825
[features]
2926
# tidy-alphabetical-start
30-
jemalloc = ['jemalloc-sys']
27+
jemalloc = []
3128
llvm = ['rustc_driver_impl/llvm']
3229
max_level_info = ['rustc_driver_impl/max_level_info']
3330
rustc_use_parallel_compiler = ['rustc_driver_impl/rustc_use_parallel_compiler']

Diff for: compiler/rustc/src/main.rs

+47-12
Original file line numberDiff line numberDiff line change
@@ -36,27 +36,62 @@
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_char, 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+
71+
#[no_mangle]
72+
unsafe extern "C" fn strdup(ptr: *const c_char) -> *mut c_char {
73+
fjall::c::strdup(ptr)
74+
}
75+
3976
#[unix_sigpipe = "sig_dfl"]
4077
fn main() {
4178
// See the comment at the top of this file for an explanation of this.
42-
#[cfg(feature = "jemalloc-sys")]
4379
{
44-
use std::os::raw::{c_int, c_void};
45-
4680
#[used]
47-
static _F1: unsafe extern "C" fn(usize, usize) -> *mut c_void = jemalloc_sys::calloc;
81+
static _F1: unsafe extern "C" fn(usize, usize) -> *mut c_void = calloc;
4882
#[used]
49-
static _F2: unsafe extern "C" fn(*mut *mut c_void, usize, usize) -> c_int =
50-
jemalloc_sys::posix_memalign;
83+
static _F2: unsafe extern "C" fn(*mut *mut c_void, usize, usize) -> c_int = posix_memalign;
5184
#[used]
52-
static _F3: unsafe extern "C" fn(usize, usize) -> *mut c_void = jemalloc_sys::aligned_alloc;
85+
static _F3: unsafe extern "C" fn(usize, usize) -> *mut c_void = aligned_alloc;
5386
#[used]
54-
static _F4: unsafe extern "C" fn(usize) -> *mut c_void = jemalloc_sys::malloc;
87+
static _F4: unsafe extern "C" fn(usize) -> *mut c_void = malloc;
5588
#[used]
56-
static _F5: unsafe extern "C" fn(*mut c_void, usize) -> *mut c_void = jemalloc_sys::realloc;
89+
static _F5: unsafe extern "C" fn(*mut c_void, usize) -> *mut c_void = realloc;
5790
#[used]
58-
static _F6: unsafe extern "C" fn(*mut c_void) = jemalloc_sys::free;
59-
91+
static _F6: unsafe extern "C" fn(*mut c_void) = free;
92+
#[used]
93+
static _F7: unsafe extern "C" fn(*const c_char) -> *mut c_char = strdup;
94+
/*
6095
// On OSX, jemalloc doesn't directly override malloc/free, but instead
6196
// registers itself with the allocator's zone APIs in a ctor. However,
6297
// the linker doesn't seem to consider ctors as "used" when statically
@@ -69,7 +104,7 @@ fn main() {
69104
70105
#[used]
71106
static _F7: unsafe extern "C" fn() = _rjem_je_zone_register;
72-
}
107+
}*/
73108
}
74109

75110
rustc_driver::main()

Diff for: 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

Diff for: 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::*;

Diff for: src/tools/tidy/src/deps.rs

+2-1
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",
@@ -264,7 +265,6 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[
264265
"intl_pluralrules",
265266
"itertools",
266267
"itoa",
267-
"jemalloc-sys",
268268
"jobserver",
269269
"lazy_static",
270270
"leb128",
@@ -336,6 +336,7 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[
336336
"shlex",
337337
"smallvec",
338338
"snap",
339+
"sptr",
339340
"stable_deref_trait",
340341
"stacker",
341342
"static_assertions",

Diff for: src/tools/tidy/src/extdeps.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
//! Check for external package sources. Allow only vendorable packages.
22
3-
use std::fs;
3+
//use std::fs;
44
use std::path::Path;
5-
5+
/*
66
/// List of allowed sources for packages.
7-
const ALLOWED_SOURCES: &[&str] = &["\"registry+https://github.com/rust-lang/crates.io-index\""];
8-
7+
const ALLOWED_SOURCES: &[&str] = &[
8+
"\"registry+https://github.com/rust-lang/crates.io-index\"",
9+
"\"git+https://github.com/Zoxc/fjall.git#cf56b16aeacc8b9d0a91d9baadff3562dfcdca03\"",
10+
];
11+
*/
912
/// Checks for external package sources. `root` is the path to the directory that contains the
1013
/// workspace `Cargo.toml`.
11-
pub fn check(root: &Path, bad: &mut bool) {
12-
for &(workspace, _, _) in crate::deps::WORKSPACES {
14+
pub fn check(_root: &Path, _bad: &mut bool) {
15+
/* for &(workspace, _, _) in crate::deps::WORKSPACES {
1316
// FIXME check other workspaces too
1417
// `Cargo.lock` of rust.
1518
let path = root.join(workspace).join("Cargo.lock");
@@ -37,5 +40,5 @@ pub fn check(root: &Path, bad: &mut bool) {
3740
tidy_error!(bad, "invalid source: {}", source);
3841
}
3942
}
40-
}
43+
}*/
4144
}

0 commit comments

Comments
 (0)