Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 78 additions & 14 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -493,8 +493,10 @@ checksum = "c469d952047f47f91b68d1cba3f10d63c11d73e4636f24f08daf0278abf01c4d"
dependencies = [
"android-tzdata",
"iana-time-zone",
"js-sys",
"num-traits",
"serde",
"wasm-bindgen",
"windows-link",
]

Expand Down Expand Up @@ -583,6 +585,7 @@ dependencies = [
"declare_clippy_lint",
"filetime",
"itertools",
"libtcmalloc-sys",
"pulldown-cmark",
"regex",
"rustc_tools_util 0.4.2",
Expand Down Expand Up @@ -1194,6 +1197,15 @@ version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8975ffdaa0ef3661bfe02dbdcc06c9f829dfafe6a3c474de366a8d5e44276921"

[[package]]
name = "document-features"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95249b50c6c185bee49034bcb378a49dc2b5dff0be90ff6616d31d64febab05d"
dependencies = [
"litrs",
]

[[package]]
name = "dyn-clone"
version = "1.0.19"
Expand Down Expand Up @@ -2161,6 +2173,18 @@ dependencies = [
"redox_syscall",
]

[[package]]
name = "libtcmalloc-sys"
version = "0.1.14"
source = "git+https://github.com/0xdeafbeef/tcmalloc-better.git?rev=781a440a0919#781a440a091933e35ecbfd082fc0393bea6481ad"
dependencies = [
"cc",
"document-features",
"libc",
"patch",
"strum 0.27.2",
]

[[package]]
name = "libz-sys"
version = "1.1.22"
Expand Down Expand Up @@ -2213,6 +2237,12 @@ version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "241eaef5fd12c88705a01fc1066c48c4b36e0dd4377dcdc7ec3942cea7a69956"

[[package]]
name = "litrs"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f5e54036fe321fd421e10d732f155734c4e4afd610dd556d9a82833ab3ee0bed"

[[package]]
name = "lld-wrapper"
version = "0.1.0"
Expand Down Expand Up @@ -2392,6 +2422,7 @@ dependencies = [
"libc",
"libffi",
"libloading",
"libtcmalloc-sys",
"measureme",
"nix",
"rand 0.9.2",
Expand All @@ -2401,7 +2432,6 @@ dependencies = [
"serde_json",
"smallvec",
"tempfile",
"tikv-jemalloc-sys",
"ui_test",
]

Expand Down Expand Up @@ -2437,6 +2467,17 @@ dependencies = [
"minimal-lexical",
]

[[package]]
name = "nom_locate"
version = "4.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e3c83c053b0713da60c5b8de47fe8e494fe3ece5267b2f23090a07a053ba8f3"
dependencies = [
"bytecount",
"memchr",
"nom",
]

[[package]]
name = "normpath"
version = "1.3.0"
Expand Down Expand Up @@ -2752,6 +2793,17 @@ dependencies = [
"windows-targets 0.52.6",
]

[[package]]
name = "patch"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "15c07fdcdd8b05bdcf2a25bc195b6c34cbd52762ada9dba88bf81e7686d14e7a"
dependencies = [
"chrono",
"nom",
"nom_locate",
]

[[package]]
name = "pathdiff"
version = "0.2.3"
Expand Down Expand Up @@ -3285,13 +3337,13 @@ checksum = "e4ee29da77c5a54f42697493cd4c9b9f31b74df666a6c04dfc4fde77abe0438b"
name = "rustc-main"
version = "0.0.0"
dependencies = [
"libtcmalloc-sys",
"rustc_codegen_ssa",
"rustc_driver",
"rustc_driver_impl",
"rustc_public",
"rustc_public_bridge",
"rustc_windows_rc",
"tikv-jemalloc-sys",
]

[[package]]
Expand Down Expand Up @@ -4781,6 +4833,7 @@ dependencies = [
"expect-test",
"indexmap",
"itertools",
"libtcmalloc-sys",
"minifier",
"pulldown-cmark-escape",
"regex",
Expand Down Expand Up @@ -5183,8 +5236,8 @@ dependencies = [
"nom",
"serde",
"spdx-expression",
"strum",
"strum_macros",
"strum 0.24.1",
"strum_macros 0.24.3",
"thiserror 1.0.69",
"uuid",
]
Expand Down Expand Up @@ -5260,6 +5313,15 @@ version = "0.24.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "063e6045c0e62079840579a7e47a355ae92f60eb74daaf156fb1e84ba164e63f"

[[package]]
name = "strum"
version = "0.27.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af23d6f6c1a224baef9d3f61e287d2761385a5b88fdab4eb4c6f11aeb54c4bcf"
dependencies = [
"strum_macros 0.27.2",
]

[[package]]
name = "strum_macros"
version = "0.24.3"
Expand All @@ -5273,6 +5335,18 @@ dependencies = [
"syn 1.0.109",
]

[[package]]
name = "strum_macros"
version = "0.27.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7695ce3845ea4b33927c055a39dc438a45b059f7c1b3d91d38d10355fb8cbca7"
dependencies = [
"heck 0.5.0",
"proc-macro2",
"quote",
"syn 2.0.106",
]

[[package]]
name = "syn"
version = "1.0.109"
Expand Down Expand Up @@ -5503,16 +5577,6 @@ dependencies = [
name = "tier-check"
version = "0.1.0"

[[package]]
name = "tikv-jemalloc-sys"
version = "0.6.0+5.3.0-1-ge13ca993e8ccb9ba9847cc330696e02839f328f7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd3c60906412afa9c2b5b5a48ca6a5abe5736aec9eb48ad05037a677e52e4e2d"
dependencies = [
"cc",
"libc",
]

[[package]]
name = "tinystr"
version = "0.8.1"
Expand Down
9 changes: 4 additions & 5 deletions compiler/rustc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ rustc_public = { path = "../rustc_public" }
rustc_public_bridge = { path = "../rustc_public_bridge" }
# tidy-alphabetical-end

[dependencies.tikv-jemalloc-sys]
version = "0.6.0"
optional = true
features = ['unprefixed_malloc_on_supported_platforms']

[target.'cfg(all(target_os = "linux", target_arch = "x86_64"))'.dependencies]
libtcmalloc-sys = { git = "https://github.com/0xdeafbeef/tcmalloc-better.git", rev = "781a440a0919", default-features = false, features = ["unprefixed_malloc_on_supported_platforms", "32k_pages", "override_cpp_operators"] }

[features]
# tidy-alphabetical-start
check_only = ['rustc_driver_impl/check_only']
jemalloc = ['dep:tikv-jemalloc-sys']
jemalloc = []
llvm = ['rustc_driver_impl/llvm']
llvm_enzyme = ['rustc_driver_impl/llvm_enzyme']
max_level_info = ['rustc_driver_impl/max_level_info']
Expand Down
41 changes: 17 additions & 24 deletions compiler/rustc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,39 +39,32 @@

fn main() {
// See the comment at the top of this file for an explanation of this.
#[cfg(feature = "jemalloc")]
#[cfg(all(target_os = "linux", target_arch = "x86_64"))]
{
use std::os::raw::{c_int, c_void};

use tikv_jemalloc_sys as jemalloc_sys;

#[used]
static _F1: unsafe extern "C" fn(usize, usize) -> *mut c_void = jemalloc_sys::calloc;
static _TCMALLOC_BRIDGE_ALLOC: unsafe extern "C" fn(usize, usize) -> *mut c_void =
libtcmalloc_sys::aligned_alloc;
#[used]
static _F2: unsafe extern "C" fn(*mut *mut c_void, usize, usize) -> c_int =
jemalloc_sys::posix_memalign;
static CALLOC: unsafe extern "C" fn(usize, usize) -> *mut c_void = libtcmalloc_sys::calloc;
#[used]
static _F3: unsafe extern "C" fn(usize, usize) -> *mut c_void = jemalloc_sys::aligned_alloc;
static TCMALLOC_POSIX_MEMALIGN: unsafe extern "C" fn(
*mut *mut c_void,
usize,
usize,
) -> c_int = libtcmalloc_sys::posix_memalign;
#[used]
static _F4: unsafe extern "C" fn(usize) -> *mut c_void = jemalloc_sys::malloc;
static _TCMALLOC_ALIGNED_ALLOC: unsafe extern "C" fn(usize, usize) -> *mut c_void =
libtcmalloc_sys::aligned_alloc;
#[used]
static _F5: unsafe extern "C" fn(*mut c_void, usize) -> *mut c_void = jemalloc_sys::realloc;
static _TCMALLOC_MALLOC: unsafe extern "C" fn(usize) -> *mut c_void =
libtcmalloc_sys::malloc;
#[used]
static _F6: unsafe extern "C" fn(*mut c_void) = jemalloc_sys::free;

// On OSX, jemalloc doesn't directly override malloc/free, but instead
// registers itself with the allocator's zone APIs in a ctor. However,
// the linker doesn't seem to consider ctors as "used" when statically
// linking, so we need to explicitly depend on the function.
#[cfg(target_os = "macos")]
{
unsafe extern "C" {
fn _rjem_je_zone_register();
}

#[used]
static _F7: unsafe extern "C" fn() = _rjem_je_zone_register;
}
static _TCMALLOC_REALLOC: unsafe extern "C" fn(*mut c_void, usize) -> *mut c_void =
libtcmalloc_sys::realloc;
#[used]
static _TCMALLOC_FREE: unsafe extern "C" fn(*mut c_void) = libtcmalloc_sys::free;
}

rustc_driver::main()
Expand Down
6 changes: 3 additions & 3 deletions src/librustdoc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ tracing-tree = "0.3.0"
unicode-segmentation = "1.9"
# tidy-alphabetical-end

[target.'cfg(all(target_os = "linux", target_arch = "x86_64"))'.dependencies]
libtcmalloc-sys = { git = "https://github.com/0xdeafbeef/tcmalloc-better.git", rev = "781a440a0919", default-features = false, features = ["unprefixed_malloc_on_supported_platforms", "32k_pages", "override_cpp_operators"] }

[dependencies.tracing-subscriber]
version = "0.3.3"
default-features = false
Expand All @@ -41,8 +44,5 @@ minifier = { version = "0.3.2", default-features = false }
[dev-dependencies]
expect-test = "1.4.0"

[features]
jemalloc = []

[package.metadata.rust-analyzer]
rustc_private = true
53 changes: 29 additions & 24 deletions src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@ extern crate rustc_target;
extern crate rustc_trait_selection;
extern crate test;

// See docs in https://github.com/rust-lang/rust/blob/master/compiler/rustc/src/main.rs
// about jemalloc.
#[cfg(feature = "jemalloc")]
extern crate tikv_jemalloc_sys as jemalloc_sys;

use std::env::{self, VarError};
use std::io::{self, IsTerminal};
use std::path::Path;
Expand Down Expand Up @@ -126,34 +121,44 @@ mod visit_lib;

pub fn main() {
// See docs in https://github.com/rust-lang/rust/blob/master/compiler/rustc/src/main.rs
// about jemalloc.
#[cfg(feature = "jemalloc")]
// about tcmalloc.
#[cfg(all(target_os = "linux", target_arch = "x86_64"))]
{
use std::os::raw::{c_int, c_void};

unsafe extern "C" {
fn calloc(count: usize, size: usize) -> *mut c_void;
fn posix_memalign(ptr: *mut *mut c_void, alignment: usize, size: usize) -> c_int;
fn aligned_alloc(alignment: usize, size: usize) -> *mut c_void;
fn malloc(size: usize) -> *mut c_void;
fn realloc(ptr: *mut c_void, size: usize) -> *mut c_void;
fn free(ptr: *mut c_void);
}

#[used]
static _F1: unsafe extern "C" fn(usize, usize) -> *mut c_void = jemalloc_sys::calloc;
static _TCMALLOC_BRIDGE_ALLOC: unsafe extern "C" fn(usize, usize) -> *mut c_void =
libtcmalloc_sys::BridgeTCMallocInternalNewAlignedNothrow;
#[used]
static _F2: unsafe extern "C" fn(*mut *mut c_void, usize, usize) -> c_int =
jemalloc_sys::posix_memalign;
static _TCMALLOC_BRIDGE_DELETE_ALIGNED: unsafe extern "C" fn(*mut c_void, usize) =
libtcmalloc_sys::TCMallocInternalDeleteAligned;

#[used]
static _F3: unsafe extern "C" fn(usize, usize) -> *mut c_void = jemalloc_sys::aligned_alloc;
static _TCMALLOC_CALLOC: unsafe extern "C" fn(usize, usize) -> *mut c_void = calloc;
#[used]
static _F4: unsafe extern "C" fn(usize) -> *mut c_void = jemalloc_sys::malloc;
static _TCMALLOC_POSIX_MEMALIGN: unsafe extern "C" fn(
*mut *mut c_void,
usize,
usize,
) -> c_int = posix_memalign;
#[used]
static _F5: unsafe extern "C" fn(*mut c_void, usize) -> *mut c_void = jemalloc_sys::realloc;
static _TCMALLOC_ALIGNED_ALLOC: unsafe extern "C" fn(usize, usize) -> *mut c_void =
aligned_alloc;
#[used]
static _F6: unsafe extern "C" fn(*mut c_void) = jemalloc_sys::free;

#[cfg(target_os = "macos")]
{
unsafe extern "C" {
fn _rjem_je_zone_register();
}

#[used]
static _F7: unsafe extern "C" fn() = _rjem_je_zone_register;
}
static _TCMALLOC_MALLOC: unsafe extern "C" fn(usize) -> *mut c_void = malloc;
#[used]
static _TCMALLOC_REALLOC: unsafe extern "C" fn(*mut c_void, usize) -> *mut c_void = realloc;
#[used]
static _TCMALLOC_FREE: unsafe extern "C" fn(*mut c_void) = free;
}

let mut early_dcx = EarlyDiagCtxt::new(ErrorOutputType::default());
Expand Down
4 changes: 3 additions & 1 deletion src/tools/clippy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ termize = "0.2"
color-print = "0.3.4"
anstream = "0.6.18"

[target.'cfg(all(target_os = "linux", target_arch = "x86_64"))'.dependencies]
libtcmalloc-sys = { git = "https://github.com/0xdeafbeef/tcmalloc-better.git", rev = "781a440a0919", default-features = false, features = ["unprefixed_malloc_on_supported_platforms", "32k_pages", "override_cpp_operators"] }

[dev-dependencies]
cargo_metadata = "0.18.1"
ui_test = "0.30.2"
Expand All @@ -51,7 +54,6 @@ rustc_tools_util = { path = "rustc_tools_util", version = "0.4.2" }
[features]
integration = ["dep:tempfile"]
internal = ["dep:clippy_lints_internal", "dep:tempfile"]
jemalloc = []

[package.metadata.rust-analyzer]
# This package uses #[feature(rustc_private)]
Expand Down
Loading
Loading