Skip to content

Commit 016eaf8

Browse files
committed
Use jemalloc-sys on Linux and OSX compilers
This commit adds opt-in support to the compiler to link to `jemalloc` in the compiler. When activated the compiler will depend on `jemalloc-sys`, instruct jemalloc to unprefix its symbols, and then link to it. The feature is activated by default on Linux/OSX compilers for x86_64/i686 platforms, and it's not enabled anywhere else for now. We may be able to opt-in other platforms in the future! Also note that the opt-in only happens on CI, it's otherwise unconditionally turned off by default. Closes rust-lang#36963
1 parent 61e8944 commit 016eaf8

File tree

12 files changed

+58
-11
lines changed

12 files changed

+58
-11
lines changed

.travis.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ matrix:
3030

3131
- env: >
3232
RUST_CHECK_TARGET=dist
33-
RUST_CONFIGURE_ARGS="--enable-extended --enable-profiler --enable-lldb"
33+
RUST_CONFIGURE_ARGS="--enable-extended --enable-profiler --enable-lldb --set rust.jemalloc"
3434
SRC=.
3535
DEPLOY_ALT=1
3636
RUSTC_RETRY_LINKER_ON_SEGFAULT=1
@@ -53,7 +53,7 @@ matrix:
5353
# version that we're using, 8.2, cannot compile LLVM for OSX 10.7.
5454
- env: >
5555
RUST_CHECK_TARGET=check
56-
RUST_CONFIGURE_ARGS="--build=x86_64-apple-darwin --enable-sanitizers --enable-profiler"
56+
RUST_CONFIGURE_ARGS="--build=x86_64-apple-darwin --enable-sanitizers --enable-profiler --set rust.jemalloc"
5757
SRC=.
5858
RUSTC_RETRY_LINKER_ON_SEGFAULT=1
5959
MACOSX_DEPLOYMENT_TARGET=10.8
@@ -67,7 +67,7 @@ matrix:
6767
6868
- env: >
6969
RUST_CHECK_TARGET=check
70-
RUST_CONFIGURE_ARGS=--build=i686-apple-darwin
70+
RUST_CONFIGURE_ARGS="--build=i686-apple-darwin --set rust.jemalloc"
7171
SRC=.
7272
RUSTC_RETRY_LINKER_ON_SEGFAULT=1
7373
MACOSX_DEPLOYMENT_TARGET=10.8
@@ -87,7 +87,7 @@ matrix:
8787
# OSX 10.7 and `xcode7` is the latest Xcode able to compile LLVM for 10.7.
8888
- env: >
8989
RUST_CHECK_TARGET=dist
90-
RUST_CONFIGURE_ARGS="--build=i686-apple-darwin --enable-full-tools --enable-profiler --enable-lldb"
90+
RUST_CONFIGURE_ARGS="--build=i686-apple-darwin --enable-full-tools --enable-profiler --enable-lldb --set rust.jemalloc"
9191
SRC=.
9292
DEPLOY=1
9393
RUSTC_RETRY_LINKER_ON_SEGFAULT=1
@@ -102,7 +102,7 @@ matrix:
102102
103103
- env: >
104104
RUST_CHECK_TARGET=dist
105-
RUST_CONFIGURE_ARGS="--target=aarch64-apple-ios,armv7-apple-ios,armv7s-apple-ios,i386-apple-ios,x86_64-apple-ios --enable-full-tools --enable-sanitizers --enable-profiler --enable-lldb"
105+
RUST_CONFIGURE_ARGS="--target=aarch64-apple-ios,armv7-apple-ios,armv7s-apple-ios,i386-apple-ios,x86_64-apple-ios --enable-full-tools --enable-sanitizers --enable-profiler --enable-lldb --set rust.jemalloc"
106106
SRC=.
107107
DEPLOY=1
108108
RUSTC_RETRY_LINKER_ON_SEGFAULT=1

config.toml.example

+4
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,10 @@
396396
# generally only set for releases
397397
#remap-debuginfo = false
398398

399+
# Link the compiler against `jemalloc`, where on Linux and OSX it should
400+
# override the default allocator for rustc and LLVM.
401+
#jemalloc = false
402+
399403
# =============================================================================
400404
# Options for specific targets
401405
#

src/Cargo.lock

+18
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,11 @@ dependencies = [
785785
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
786786
]
787787

788+
[[package]]
789+
name = "fs_extra"
790+
version = "1.1.0"
791+
source = "registry+https://github.com/rust-lang/crates.io-index"
792+
788793
[[package]]
789794
name = "fst"
790795
version = "0.3.0"
@@ -996,6 +1001,16 @@ name = "itoa"
9961001
version = "0.4.3"
9971002
source = "registry+https://github.com/rust-lang/crates.io-index"
9981003

1004+
[[package]]
1005+
name = "jemalloc-sys"
1006+
version = "0.1.8"
1007+
source = "registry+https://github.com/rust-lang/crates.io-index"
1008+
dependencies = [
1009+
"cc 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)",
1010+
"fs_extra 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
1011+
"libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
1012+
]
1013+
9991014
[[package]]
10001015
name = "jobserver"
10011016
version = "0.1.11"
@@ -2181,6 +2196,7 @@ dependencies = [
21812196
"arena 0.0.0",
21822197
"env_logger 0.5.12 (registry+https://github.com/rust-lang/crates.io-index)",
21832198
"graphviz 0.0.0",
2199+
"jemalloc-sys 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
21842200
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
21852201
"rustc 0.0.0",
21862202
"rustc-rayon 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -3237,6 +3253,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
32373253
"checksum foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1"
32383254
"checksum foreign-types-shared 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
32393255
"checksum fs2 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "9564fc758e15025b46aa6643b1b77d047d1a56a1aea6e01002ac0c7026876213"
3256+
"checksum fs_extra 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5f2a4a2034423744d2cc7ca2068453168dcdb82c438419e639a26bd87839c674"
32403257
"checksum fst 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d94485a00b1827b861dd9d1a2cc9764f9044d4c535514c0760a5a2012ef3399f"
32413258
"checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82"
32423259
"checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
@@ -3259,6 +3276,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
32593276
"checksum is-match 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7e5b386aef33a1c677be65237cb9d32c3f3ef56bd035949710c4bb13083eb053"
32603277
"checksum itertools 0.7.8 (registry+https://github.com/rust-lang/crates.io-index)" = "f58856976b776fedd95533137617a02fb25719f40e7d9b01c7043cd65474f450"
32613278
"checksum itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1306f3464951f30e30d12373d31c79fbd52d236e5e896fd92f96ec7babbbe60b"
3279+
"checksum jemalloc-sys 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "bfc62c8e50e381768ce8ee0428ee53741929f7ebd73e4d83f669bcf7693e00ae"
32623280
"checksum jobserver 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "60af5f849e1981434e4a31d3d782c4774ae9b434ce55b101a96ecfd09147e8be"
32633281
"checksum json 0.11.13 (registry+https://github.com/rust-lang/crates.io-index)" = "9ad0485404155f45cce53a40d4b2d6ac356418300daed05273d9e26f91c390be"
32643282
"checksum jsonrpc-core 8.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ddf83704f4e79979a424d1082dd2c1e52683058056c9280efa19ac5f6bc9033c"

src/bootstrap/config.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ pub struct Config {
116116
pub hosts: Vec<Interned<String>>,
117117
pub targets: Vec<Interned<String>>,
118118
pub local_rebuild: bool,
119+
pub jemalloc: bool,
119120

120121
// dist misc
121122
pub dist_sign_folder: Option<PathBuf>,
@@ -260,7 +261,7 @@ struct Llvm {
260261
link_jobs: Option<u32>,
261262
link_shared: Option<bool>,
262263
version_suffix: Option<String>,
263-
clang_cl: Option<String>
264+
clang_cl: Option<String>,
264265
}
265266

266267
#[derive(Deserialize, Default, Clone)]
@@ -324,6 +325,7 @@ struct Rust {
324325
backtrace_on_ice: Option<bool>,
325326
verify_llvm_ir: Option<bool>,
326327
remap_debuginfo: Option<bool>,
328+
jemalloc: Option<bool>,
327329
}
328330

329331
/// TOML representation of how each build target is configured.
@@ -537,6 +539,7 @@ impl Config {
537539
set(&mut config.rust_debuginfo_tests, rust.debuginfo_tests);
538540
set(&mut config.codegen_tests, rust.codegen_tests);
539541
set(&mut config.rust_rpath, rust.rpath);
542+
set(&mut config.jemalloc, rust.jemalloc);
540543
set(&mut config.backtrace, rust.backtrace);
541544
set(&mut config.channel, rust.channel.clone());
542545
set(&mut config.rust_dist_src, rust.dist_src);

src/bootstrap/lib.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,11 @@ impl Build {
530530

531531
/// Get the space-separated set of activated features for the compiler.
532532
fn rustc_features(&self) -> String {
533-
String::new()
533+
let mut features = String::new();
534+
if self.config.jemalloc {
535+
features.push_str("jemalloc");
536+
}
537+
features
534538
}
535539

536540
/// Component directory that Cargo will produce output into (e.g.

src/ci/docker/dist-i686-linux/Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ ENV RUST_CONFIGURE_ARGS \
9898
--enable-sanitizers \
9999
--enable-profiler \
100100
--set target.i686-unknown-linux-gnu.linker=clang \
101-
--build=i686-unknown-linux-gnu
101+
--build=i686-unknown-linux-gnu \
102+
--set rust.jemalloc
102103
ENV SCRIPT python2.7 ../x.py dist --build $HOSTS --host $HOSTS --target $HOSTS
103104
ENV CARGO_TARGET_I686_UNKNOWN_LINUX_GNU_LINKER=clang
104105

src/ci/docker/dist-x86_64-linux/Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ ENV RUST_CONFIGURE_ARGS \
101101
--set target.x86_64-unknown-linux-gnu.linker=clang \
102102
--set target.x86_64-unknown-linux-gnu.ar=/rustroot/bin/llvm-ar \
103103
--set target.x86_64-unknown-linux-gnu.ranlib=/rustroot/bin/llvm-ranlib \
104-
--set llvm.thin-lto=true
104+
--set llvm.thin-lto=true \
105+
--set rust.jemalloc
105106
ENV SCRIPT python2.7 ../x.py dist --host $HOSTS --target $HOSTS
106107
ENV CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=clang
107108

src/librustc_driver/Cargo.toml

+5
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,8 @@ syntax = { path = "../libsyntax" }
3838
smallvec = { version = "0.6.5", features = ["union"] }
3939
syntax_ext = { path = "../libsyntax_ext" }
4040
syntax_pos = { path = "../libsyntax_pos" }
41+
42+
[dependencies.jemalloc-sys]
43+
version = '0.1.8'
44+
optional = true
45+
features = ['unprefixed_malloc_on_supported_platforms']

src/librustc_driver/lib.rs

+8
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ extern crate syntax;
6464
extern crate syntax_ext;
6565
extern crate syntax_pos;
6666

67+
// Note that the linkage here should be all that we need, on Linux we're not
68+
// prefixing the symbols here so this should naturally override our default
69+
// allocator. On OSX it should override via the zone allocator. We shouldn't
70+
// enable this by default on other platforms, so other platforms aren't handled
71+
// here yet.
72+
#[cfg(feature = "jemalloc-sys")]
73+
extern crate jemalloc_sys;
74+
6775
use driver::CompileController;
6876
use pretty::{PpMode, UserIdentifiedItem};
6977

src/librustc_target/spec/arm_linux_androideabi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub fn target() -> TargetResult {
1414
let mut base = super::android_base::opts();
1515
// https://developer.android.com/ndk/guides/abis.html#armeabi
1616
base.features = "+strict-align,+v5te".to_string();
17-
base.max_atomic_width = Some(64);
17+
base.max_atomic_width = Some(32);
1818

1919
Ok(Target {
2020
llvm_target: "arm-linux-androideabi".to_string(),

src/rustc/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ path = "rustc.rs"
1010
[dependencies]
1111
rustc_target = { path = "../librustc_target" }
1212
rustc_driver = { path = "../librustc_driver" }
13+
14+
[features]
15+
jemalloc = ['rustc_driver/jemalloc-sys']

src/tools/tidy/src/cargo.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ fn verify(tomlfile: &Path, libfile: &Path, bad: &mut bool) {
8484

8585
// This is intentional, this dependency just makes the crate available
8686
// for others later on. Cover cases
87-
let whitelisted = whitelisted || krate.starts_with("panic");
87+
let whitelisted = krate.starts_with("panic");
8888
if toml.contains("name = \"std\"") && whitelisted {
8989
continue
9090
}

0 commit comments

Comments
 (0)