From 6208fea802322db20851de535cb97e917850bbde Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Wed, 4 Jan 2017 09:18:20 -0500 Subject: [PATCH] move the alloc_jemalloc allocator out of tree, default to alloc_system See #36963 for rationale closes #36963 fixes #36488 (indirectly) closes #37975 --- .gitmodules | 3 - configure | 16 -- src/Cargo.lock | 11 -- src/bootstrap/check.rs | 8 +- src/bootstrap/compile.rs | 8 +- src/bootstrap/config.rs | 19 -- src/bootstrap/config.toml.example | 10 -- src/bootstrap/doc.rs | 3 +- src/bootstrap/lib.rs | 21 --- src/bootstrap/sanity.rs | 8 - src/jemalloc | 1 - src/liballoc_jemalloc/Cargo.toml | 23 --- src/liballoc_jemalloc/build.rs | 184 -------------------- src/liballoc_jemalloc/lib.rs | 193 --------------------- src/librustc_back/Cargo.toml | 3 - src/librustc_back/target/apple_base.rs | 2 +- src/librustc_back/target/dragonfly_base.rs | 2 +- src/librustc_back/target/freebsd_base.rs | 2 +- src/librustc_back/target/linux_base.rs | 2 +- src/librustc_back/target/mod.rs | 8 - src/librustc_back/target/solaris_base.rs | 2 +- src/libstd/Cargo.toml | 3 - src/rustc/Cargo.toml | 3 - src/rustc/std_shim/Cargo.toml | 2 - src/tools/tidy/src/cargo.rs | 3 +- src/tools/tidy/src/main.rs | 1 - src/tools/tidy/src/pal.rs | 2 - 27 files changed, 9 insertions(+), 534 deletions(-) delete mode 160000 src/jemalloc delete mode 100644 src/liballoc_jemalloc/Cargo.toml delete mode 100644 src/liballoc_jemalloc/build.rs delete mode 100644 src/liballoc_jemalloc/lib.rs diff --git a/.gitmodules b/.gitmodules index 39288a7ae4907..4d74a85192da4 100644 --- a/.gitmodules +++ b/.gitmodules @@ -8,9 +8,6 @@ [submodule "src/rt/hoedown"] path = src/rt/hoedown url = https://github.com/rust-lang/hoedown.git -[submodule "src/jemalloc"] - path = src/jemalloc - url = https://github.com/rust-lang/jemalloc.git [submodule "src/rust-installer"] path = src/rust-installer url = https://github.com/rust-lang/rust-installer.git diff --git a/configure b/configure index ee5922b1f142d..d8a88842f907f 100755 --- a/configure +++ b/configure @@ -647,7 +647,6 @@ opt_nosave debug-assertions 0 "build with debugging assertions" opt_nosave llvm-release-debuginfo 0 "build LLVM with debugger metadata" opt_nosave debuginfo 0 "build with debugger metadata" opt_nosave debuginfo-lines 0 "build with line number debugger metadata" -opt_nosave debug-jemalloc 0 "build jemalloc with --enable-debug --enable-fill" valopt localstatedir "/var/lib" "local state directory" valopt sysconfdir "/etc" "install system configuration files" @@ -656,7 +655,6 @@ valopt datadir "${CFG_PREFIX}/share" "install data" valopt infodir "${CFG_PREFIX}/share/info" "install additional info" valopt llvm-root "" "set LLVM root" valopt python "" "set path to python" -valopt jemalloc-root "" "set directory where libjemalloc_pic.a is located" valopt build "${DEFAULT_BUILD}" "GNUs ./configure syntax LLVM build triple" valopt android-cross-path "" "Android NDK standalone path (deprecated)" valopt i686-linux-android-ndk "" "i686-linux-android NDK standalone path" @@ -691,7 +689,6 @@ valopt default-ar "ar" "the default ar" # (others are conditionally saved). opt_nosave manage-submodules 1 "let the build manage the git submodules" opt_nosave clang 0 "prefer clang to gcc for building the runtime" -opt_nosave jemalloc 1 "build liballoc with jemalloc" opt elf-tls 1 "elf thread local storage on platforms where supported" opt full-bootstrap 0 "build three compilers instead of two" @@ -771,7 +768,6 @@ if [ -n "$CFG_ENABLE_DEBUG" ]; then # Set following variables to 1 unless setting already provided enable_if_not_disabled debug-assertions - enable_if_not_disabled debug-jemalloc enable_if_not_disabled debuginfo enable_if_not_disabled llvm-assertions fi @@ -785,7 +781,6 @@ if [ -n "$CFG_ENABLE_DEBUG_ASSERTIONS" ]; then putvar CFG_ENABLE_DEBUG_ASSERTION if [ -n "$CFG_ENABLE_LLVM_RELEASE_DEBUGINFO" ]; then putvar CFG_ENABLE_LLVM_RELEASE_DEBUGINFO; fi if [ -n "$CFG_ENABLE_DEBUGINFO" ]; then putvar CFG_ENABLE_DEBUGINFO; fi if [ -n "$CFG_ENABLE_DEBUGINFO_LINES" ]; then putvar CFG_ENABLE_DEBUGINFO_LINES; fi -if [ -n "$CFG_ENABLE_DEBUG_JEMALLOC" ]; then putvar CFG_ENABLE_DEBUG_JEMALLOC; fi step_msg "looking for build programs" @@ -1065,12 +1060,6 @@ else CFG_USING_LIBCPP="0" fi -# Same with jemalloc. save the setting here. -if [ -n "$CFG_DISABLE_JEMALLOC" ] -then - putvar CFG_DISABLE_JEMALLOC -fi - if [ -n "$CFG_LLVM_ROOT" -a -z "$CFG_DISABLE_LLVM_VERSION_CHECK" -a -e "$CFG_LLVM_ROOT/bin/llvm-config" ] then step_msg "using custom LLVM at $CFG_LLVM_ROOT" @@ -1415,7 +1404,6 @@ if [ -n "$CFG_DISABLE_RUSTBUILD" ]; then for s in 0 1 2 3 do make_dir $t/rt/stage$s - make_dir $t/rt/jemalloc make_dir $t/rt/compiler-rt for i in \ isaac sync test \ @@ -1503,10 +1491,6 @@ then msg "git: submodule deinit src/llvm" "${CFG_GIT}" submodule deinit src/llvm fi - if [ -n "${CFG_JEMALLOC_ROOT}" ]; then - msg "git: submodule deinit src/jemalloc" - "${CFG_GIT}" submodule deinit src/jemalloc - fi msg "git: submodule update" "${CFG_GIT}" submodule update diff --git a/src/Cargo.lock b/src/Cargo.lock index 3da29933c812e..f1a16d9f61bac 100644 --- a/src/Cargo.lock +++ b/src/Cargo.lock @@ -13,16 +13,6 @@ dependencies = [ "core 0.0.0", ] -[[package]] -name = "alloc_jemalloc" -version = "0.0.0" -dependencies = [ - "build_helper 0.1.0", - "core 0.0.0", - "gcc 0.3.40 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.0.0", -] - [[package]] name = "alloc_system" version = "0.0.0" @@ -595,7 +585,6 @@ name = "std" version = "0.0.0" dependencies = [ "alloc 0.0.0", - "alloc_jemalloc 0.0.0", "alloc_system 0.0.0", "build_helper 0.1.0", "collections 0.0.0", diff --git a/src/bootstrap/check.rs b/src/bootstrap/check.rs index 6db1afa54a625..53a426f5efb5f 100644 --- a/src/bootstrap/check.rs +++ b/src/bootstrap/check.rs @@ -338,7 +338,7 @@ pub fn krate(build: &Build, ("libtest", "src/rustc/test_shim", String::new(), "test_shim") } Mode::Librustc => { - ("librustc", "src/rustc", build.rustc_features(), "rustc-main") + ("librustc", "src/rustc", String::new(), "rustc-main") } _ => panic!("can only test libraries"), }; @@ -373,12 +373,6 @@ pub fn krate(build: &Build, let mut visited = HashSet::new(); let mut next = vec![root]; while let Some(name) = next.pop() { - // Right now jemalloc is our only target-specific crate in the sense - // that it's not present on all platforms. Custom skip it here for now, - // but if we add more this probably wants to get more generalized. - if !name.contains("jemalloc") { - cargo.arg("-p").arg(name); - } for dep in build.crates[name].deps.iter() { if visited.insert(dep) { next.push(dep); diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index a7633998aad8b..99ee1a405a14a 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -47,11 +47,6 @@ pub fn std(build: &Build, target: &str, compiler: &Compiler) { .arg("--manifest-path") .arg(build.src.join("src/rustc/std_shim/Cargo.toml")); - if let Some(target) = build.config.target_config.get(target) { - if let Some(ref jemalloc) = target.jemalloc { - cargo.env("JEMALLOC_OVERRIDE", jemalloc); - } - } if target.contains("musl") { if let Some(p) = build.musl_root(target) { cargo.env("MUSL_ROOT", p); @@ -177,8 +172,7 @@ pub fn rustc(build: &Build, target: &str, compiler: &Compiler) { build.clear_if_dirty(&out_dir, &libtest_stamp(build, compiler, target)); let mut cargo = build.cargo(compiler, Mode::Librustc, target, "build"); - cargo.arg("--features").arg(build.rustc_features()) - .arg("--manifest-path") + cargo.arg("--manifest-path") .arg(build.src.join("src/rustc/Cargo.toml")); // Set some configuration variables picked up by build scripts and diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index 11c5b374ed965..7be1e2a4bf337 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -77,8 +77,6 @@ pub struct Config { pub local_rebuild: bool, // libstd features - pub debug_jemalloc: bool, - pub use_jemalloc: bool, pub backtrace: bool, // support for RUST_BACKTRACE // misc @@ -101,7 +99,6 @@ pub struct Config { #[derive(Default)] pub struct Target { pub llvm_config: Option, - pub jemalloc: Option, pub cc: Option, pub cxx: Option, pub ndk: Option, @@ -179,8 +176,6 @@ struct Rust { debug_assertions: Option, debuginfo: Option, debuginfo_lines: Option, - debug_jemalloc: Option, - use_jemalloc: Option, backtrace: Option, default_linker: Option, default_ar: Option, @@ -196,7 +191,6 @@ struct Rust { #[derive(RustcDecodable, Default)] struct TomlTarget { llvm_config: Option, - jemalloc: Option, cc: Option, cxx: Option, android_ndk: Option, @@ -207,7 +201,6 @@ impl Config { pub fn parse(build: &str, file: Option) -> Config { let mut config = Config::default(); config.llvm_optimize = true; - config.use_jemalloc = true; config.backtrace = true; config.rust_optimize = true; config.rust_optimize_tests = true; @@ -303,8 +296,6 @@ impl Config { set(&mut config.rust_debuginfo_tests, rust.debuginfo_tests); set(&mut config.codegen_tests, rust.codegen_tests); set(&mut config.rust_rpath, rust.rpath); - set(&mut config.debug_jemalloc, rust.debug_jemalloc); - set(&mut config.use_jemalloc, rust.use_jemalloc); set(&mut config.backtrace, rust.backtrace); set(&mut config.channel, rust.channel.clone()); config.rustc_default_linker = rust.default_linker.clone(); @@ -325,9 +316,6 @@ impl Config { if let Some(ref s) = cfg.llvm_config { target.llvm_config = Some(env::current_dir().unwrap().join(s)); } - if let Some(ref s) = cfg.jemalloc { - target.jemalloc = Some(env::current_dir().unwrap().join(s)); - } if let Some(ref s) = cfg.android_ndk { target.ndk = Some(env::current_dir().unwrap().join(s)); } @@ -390,8 +378,6 @@ impl Config { ("DEBUG_ASSERTIONS", self.rust_debug_assertions), ("DEBUGINFO", self.rust_debuginfo), ("DEBUGINFO_LINES", self.rust_debuginfo_lines), - ("JEMALLOC", self.use_jemalloc), - ("DEBUG_JEMALLOC", self.debug_jemalloc), ("RPATH", self.rust_rpath), ("OPTIMIZE_TESTS", self.rust_optimize_tests), ("DEBUGINFO_TESTS", self.rust_debuginfo_tests), @@ -476,11 +462,6 @@ impl Config { let root = parse_configure_path(value); target.llvm_config = Some(push_exe_path(root, &["bin", "llvm-config"])); } - "CFG_JEMALLOC_ROOT" if value.len() > 0 => { - let target = self.target_config.entry(self.build.clone()) - .or_insert(Target::default()); - target.jemalloc = Some(parse_configure_path(value)); - } "CFG_ARM_LINUX_ANDROIDEABI_NDK" if value.len() > 0 => { let target = "arm-linux-androideabi".to_string(); let target = self.target_config.entry(target) diff --git a/src/bootstrap/config.toml.example b/src/bootstrap/config.toml.example index 69210c4959b92..e1a5f8d81c70f 100644 --- a/src/bootstrap/config.toml.example +++ b/src/bootstrap/config.toml.example @@ -149,12 +149,6 @@ # Whether or not line number debug information is emitted #debuginfo-lines = false -# Whether or not jemalloc is built and enabled -#use-jemalloc = true - -# Whether or not jemalloc is built with its debug option set -#debug-jemalloc = false - # Whether or not `panic!`s generate backtraces (RUST_BACKTRACE) #backtrace = true @@ -208,10 +202,6 @@ # target. #llvm-config = "../path/to/llvm/root/bin/llvm-config" -# Path to the custom jemalloc static library to link into the standard library -# by default. This is only used if jemalloc is still enabled above -#jemalloc = "/path/to/jemalloc/libjemalloc_pic.a" - # If this target is for Android, this option will be required to specify where # the NDK for the target lives. This is used to find the C compiler to link and # build native code. diff --git a/src/bootstrap/doc.rs b/src/bootstrap/doc.rs index bbbf5cba8a1ab..050fd844efd54 100644 --- a/src/bootstrap/doc.rs +++ b/src/bootstrap/doc.rs @@ -206,8 +206,7 @@ pub fn rustc(build: &Build, stage: u32, target: &str) { } let mut cargo = build.cargo(&compiler, Mode::Librustc, target, "doc"); cargo.arg("--manifest-path") - .arg(build.src.join("src/rustc/Cargo.toml")) - .arg("--features").arg(build.rustc_features()); + .arg(build.src.join("src/rustc/Cargo.toml")); build.run(&mut cargo); cp_r(&out_dir, &out) } diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index 6b2b6ad5c02b1..1d235662f1aeb 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -386,12 +386,6 @@ impl Build { continue } - if submodule.path.components().any(|c| c == Component::Normal("jemalloc".as_ref())) && - !self.config.use_jemalloc - { - continue - } - // `submodule.path` is the relative path to a submodule (from the repository root) // `submodule_path` is the path to a submodule from the cwd @@ -609,27 +603,12 @@ impl Build { /// library. fn std_features(&self) -> String { let mut features = "panic-unwind".to_string(); - if self.config.debug_jemalloc { - features.push_str(" debug-jemalloc"); - } - if self.config.use_jemalloc { - features.push_str(" jemalloc"); - } if self.config.backtrace { features.push_str(" backtrace"); } return features } - /// Get the space-separated set of activated features for the compiler. - fn rustc_features(&self) -> String { - let mut features = String::new(); - if self.config.use_jemalloc { - features.push_str(" jemalloc"); - } - return features - } - /// Component directory that Cargo will produce output into (e.g. /// release/debug) fn cargo_dir(&self) -> &'static str { diff --git a/src/bootstrap/sanity.rs b/src/bootstrap/sanity.rs index 66bdd5e00f43d..2649f43c52b34 100644 --- a/src/bootstrap/sanity.rs +++ b/src/bootstrap/sanity.rs @@ -136,14 +136,6 @@ pub fn check(build: &mut Build) { need_cmd(build.cxx(host).as_ref()); } - // The msvc hosts don't use jemalloc, turn it off globally to - // avoid packaging the dummy liballoc_jemalloc on that platform. - for host in build.config.host.iter() { - if host.contains("msvc") { - build.config.use_jemalloc = false; - } - } - // Externally configured LLVM requires FileCheck to exist let filecheck = build.llvm_filecheck(&build.config.build); if !filecheck.starts_with(&build.out) && !filecheck.exists() && build.config.codegen_tests { diff --git a/src/jemalloc b/src/jemalloc deleted file mode 160000 index e058ca661692a..0000000000000 --- a/src/jemalloc +++ /dev/null @@ -1 +0,0 @@ -Subproject commit e058ca661692a8d01f8cf9d35939dfe3105ce968 diff --git a/src/liballoc_jemalloc/Cargo.toml b/src/liballoc_jemalloc/Cargo.toml deleted file mode 100644 index 01393be9949ae..0000000000000 --- a/src/liballoc_jemalloc/Cargo.toml +++ /dev/null @@ -1,23 +0,0 @@ -[package] -authors = ["The Rust Project Developers"] -name = "alloc_jemalloc" -version = "0.0.0" -build = "build.rs" -links = "jemalloc" - -[lib] -name = "alloc_jemalloc" -path = "lib.rs" -test = false -doc = false - -[dependencies] -core = { path = "../libcore" } -libc = { path = "../rustc/libc_shim" } - -[build-dependencies] -build_helper = { path = "../build_helper" } -gcc = "0.3.27" - -[features] -debug = [] diff --git a/src/liballoc_jemalloc/build.rs b/src/liballoc_jemalloc/build.rs deleted file mode 100644 index 1edcb0b1f24de..0000000000000 --- a/src/liballoc_jemalloc/build.rs +++ /dev/null @@ -1,184 +0,0 @@ -// Copyright 2015 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![deny(warnings)] - -extern crate build_helper; -extern crate gcc; - -use std::env; -use std::path::PathBuf; -use std::process::Command; -use build_helper::run; - -fn main() { - println!("cargo:rustc-cfg=cargobuild"); - println!("cargo:rerun-if-changed=build.rs"); - - let target = env::var("TARGET").expect("TARGET was not set"); - let host = env::var("HOST").expect("HOST was not set"); - let build_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap()); - let src_dir = env::current_dir().unwrap(); - - // FIXME: This is a hack to support building targets that don't - // support jemalloc alongside hosts that do. The jemalloc build is - // controlled by a feature of the std crate, and if that feature - // changes between targets, it invalidates the fingerprint of - // std's build script (this is a cargo bug); so we must ensure - // that the feature set used by std is the same across all - // targets, which means we have to build the alloc_jemalloc crate - // for targets like emscripten, even if we don't use it. - if target.contains("rumprun") || target.contains("bitrig") || target.contains("openbsd") || - target.contains("msvc") || target.contains("emscripten") || target.contains("fuchsia") || - target.contains("redox") { - println!("cargo:rustc-cfg=dummy_jemalloc"); - return; - } - - if let Some(jemalloc) = env::var_os("JEMALLOC_OVERRIDE") { - let jemalloc = PathBuf::from(jemalloc); - println!("cargo:rustc-link-search=native={}", - jemalloc.parent().unwrap().display()); - let stem = jemalloc.file_stem().unwrap().to_str().unwrap(); - let name = jemalloc.file_name().unwrap().to_str().unwrap(); - let kind = if name.ends_with(".a") { - "static" - } else { - "dylib" - }; - println!("cargo:rustc-link-lib={}={}", kind, &stem[3..]); - return; - } - - let compiler = gcc::Config::new().get_compiler(); - // only msvc returns None for ar so unwrap is okay - let ar = build_helper::cc2ar(compiler.path(), &target).unwrap(); - let cflags = compiler.args() - .iter() - .map(|s| s.to_str().unwrap()) - .collect::>() - .join(" "); - - let mut stack = src_dir.join("../jemalloc") - .read_dir() - .unwrap() - .map(|e| e.unwrap()) - .filter(|e| &*e.file_name() != ".git") - .collect::>(); - while let Some(entry) = stack.pop() { - let path = entry.path(); - if entry.file_type().unwrap().is_dir() { - stack.extend(path.read_dir().unwrap().map(|e| e.unwrap())); - } else { - println!("cargo:rerun-if-changed={}", path.display()); - } - } - - let mut cmd = Command::new("sh"); - cmd.arg(src_dir.join("../jemalloc/configure") - .to_str() - .unwrap() - .replace("C:\\", "/c/") - .replace("\\", "/")) - .current_dir(&build_dir) - .env("CC", compiler.path()) - .env("EXTRA_CFLAGS", cflags.clone()) - // jemalloc generates Makefile deps using GCC's "-MM" flag. This means - // that GCC will run the preprocessor, and only the preprocessor, over - // jemalloc's source files. If we don't specify CPPFLAGS, then at least - // on ARM that step fails with a "Missing implementation for 32-bit - // atomic operations" error. This is because no "-march" flag will be - // passed to GCC, and then GCC won't define the - // "__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4" macro that jemalloc needs to - // select an atomic operation implementation. - .env("CPPFLAGS", cflags.clone()) - .env("AR", &ar) - .env("RANLIB", format!("{} s", ar.display())); - - if target.contains("windows") { - // A bit of history here, this used to be --enable-lazy-lock added in - // #14006 which was filed with jemalloc in jemalloc/jemalloc#83 which - // was also reported to MinGW: - // - // http://sourceforge.net/p/mingw-w64/bugs/395/ - // - // When updating jemalloc to 4.0, however, it was found that binaries - // would exit with the status code STATUS_RESOURCE_NOT_OWNED indicating - // that a thread was unlocking a mutex it never locked. Disabling this - // "lazy lock" option seems to fix the issue, but it was enabled by - // default for MinGW targets in 13473c7 for jemalloc. - // - // As a result of all that, force disabling lazy lock on Windows, and - // after reading some code it at least *appears* that the initialization - // of mutexes is otherwise ok in jemalloc, so shouldn't cause problems - // hopefully... - // - // tl;dr: make windows behave like other platforms by disabling lazy - // locking, but requires passing an option due to a historical - // default with jemalloc. - cmd.arg("--disable-lazy-lock"); - } else if target.contains("ios") { - cmd.arg("--disable-tls"); - } else if target.contains("android") { - // We force android to have prefixed symbols because apparently - // replacement of the libc allocator doesn't quite work. When this was - // tested (unprefixed symbols), it was found that the `realpath` - // function in libc would allocate with libc malloc (not jemalloc - // malloc), and then the standard library would free with jemalloc free, - // causing a segfault. - // - // If the test suite passes, however, without symbol prefixes then we - // should be good to go! - cmd.arg("--with-jemalloc-prefix=je_"); - cmd.arg("--disable-tls"); - } else if target.contains("dragonfly") { - cmd.arg("--with-jemalloc-prefix=je_"); - } - - if cfg!(feature = "debug-jemalloc") { - cmd.arg("--enable-debug"); - } - - // Turn off broken quarantine (see jemalloc/jemalloc#161) - cmd.arg("--disable-fill"); - cmd.arg(format!("--host={}", build_helper::gnu_target(&target))); - cmd.arg(format!("--build={}", build_helper::gnu_target(&host))); - - // for some reason, jemalloc configure doesn't detect this value - // automatically for this target - if target == "sparc64-unknown-linux-gnu" { - cmd.arg("--with-lg-quantum=4"); - } - - run(&mut cmd); - let mut make = Command::new(build_helper::make(&host)); - make.current_dir(&build_dir) - .arg("build_lib_static"); - - // mingw make seems... buggy? unclear... - if !host.contains("windows") { - make.arg("-j") - .arg(env::var("NUM_JOBS").expect("NUM_JOBS was not set")); - } - - run(&mut make); - - if target.contains("windows") { - println!("cargo:rustc-link-lib=static=jemalloc"); - } else { - println!("cargo:rustc-link-lib=static=jemalloc_pic"); - } - println!("cargo:rustc-link-search=native={}/lib", build_dir.display()); - if target.contains("android") { - println!("cargo:rustc-link-lib=gcc"); - } else if !target.contains("windows") && !target.contains("musl") { - println!("cargo:rustc-link-lib=pthread"); - } -} diff --git a/src/liballoc_jemalloc/lib.rs b/src/liballoc_jemalloc/lib.rs deleted file mode 100644 index f2df393ad777f..0000000000000 --- a/src/liballoc_jemalloc/lib.rs +++ /dev/null @@ -1,193 +0,0 @@ -// Copyright 2015 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![crate_name = "alloc_jemalloc"] -#![crate_type = "rlib"] -#![no_std] -#![allocator] -#![unstable(feature = "alloc_jemalloc", - reason = "this library is unlikely to be stabilized in its current \ - form or name", - issue = "27783")] -#![cfg_attr(not(stage0), deny(warnings))] -#![feature(allocator)] -#![feature(libc)] -#![feature(staged_api)] - -extern crate libc; - -pub use imp::*; - -// See comments in build.rs for why we sometimes build a crate that does nothing -#[cfg(not(dummy_jemalloc))] -mod imp { - use libc::{c_int, c_void, size_t}; - - // Linkage directives to pull in jemalloc and its dependencies. - // - // On some platforms we need to be sure to link in `pthread` which jemalloc - // depends on, and specifically on android we need to also link to libgcc. - // Currently jemalloc is compiled with gcc which will generate calls to - // intrinsics that are libgcc specific (e.g. those intrinsics aren't present in - // libcompiler-rt), so link that in to get that support. - #[link(name = "jemalloc", kind = "static")] - #[cfg_attr(target_os = "android", link(name = "gcc"))] - #[cfg_attr(all(not(windows), - not(target_os = "android"), - not(target_env = "musl")), - link(name = "pthread"))] - #[cfg(not(cargobuild))] - extern "C" {} - - // Note that the symbols here are prefixed by default on OSX and Windows (we - // don't explicitly request it), and on Android and DragonFly we explicitly - // request it as unprefixing cause segfaults (mismatches in allocators). - extern "C" { - #[cfg_attr(any(target_os = "macos", target_os = "android", target_os = "ios", - target_os = "dragonfly", target_os = "windows"), - link_name = "je_mallocx")] - fn mallocx(size: size_t, flags: c_int) -> *mut c_void; - #[cfg_attr(any(target_os = "macos", target_os = "android", target_os = "ios", - target_os = "dragonfly", target_os = "windows"), - link_name = "je_rallocx")] - fn rallocx(ptr: *mut c_void, size: size_t, flags: c_int) -> *mut c_void; - #[cfg_attr(any(target_os = "macos", target_os = "android", target_os = "ios", - target_os = "dragonfly", target_os = "windows"), - link_name = "je_xallocx")] - fn xallocx(ptr: *mut c_void, size: size_t, extra: size_t, flags: c_int) -> size_t; - #[cfg_attr(any(target_os = "macos", target_os = "android", target_os = "ios", - target_os = "dragonfly", target_os = "windows"), - link_name = "je_sdallocx")] - fn sdallocx(ptr: *mut c_void, size: size_t, flags: c_int); - #[cfg_attr(any(target_os = "macos", target_os = "android", target_os = "ios", - target_os = "dragonfly", target_os = "windows"), - link_name = "je_nallocx")] - fn nallocx(size: size_t, flags: c_int) -> size_t; - } - - // The minimum alignment guaranteed by the architecture. This value is used to - // add fast paths for low alignment values. In practice, the alignment is a - // constant at the call site and the branch will be optimized out. - #[cfg(all(any(target_arch = "arm", - target_arch = "mips", - target_arch = "powerpc")))] - const MIN_ALIGN: usize = 8; - #[cfg(all(any(target_arch = "x86", - target_arch = "x86_64", - target_arch = "aarch64", - target_arch = "powerpc64", - target_arch = "mips64", - target_arch = "s390x", - target_arch = "sparc64")))] - const MIN_ALIGN: usize = 16; - - // MALLOCX_ALIGN(a) macro - fn mallocx_align(a: usize) -> c_int { - a.trailing_zeros() as c_int - } - - fn align_to_flags(align: usize) -> c_int { - if align <= MIN_ALIGN { - 0 - } else { - mallocx_align(align) - } - } - - #[no_mangle] - pub extern "C" fn __rust_allocate(size: usize, align: usize) -> *mut u8 { - let flags = align_to_flags(align); - unsafe { mallocx(size as size_t, flags) as *mut u8 } - } - - #[no_mangle] - pub extern "C" fn __rust_reallocate(ptr: *mut u8, - _old_size: usize, - size: usize, - align: usize) - -> *mut u8 { - let flags = align_to_flags(align); - unsafe { rallocx(ptr as *mut c_void, size as size_t, flags) as *mut u8 } - } - - #[no_mangle] - pub extern "C" fn __rust_reallocate_inplace(ptr: *mut u8, - _old_size: usize, - size: usize, - align: usize) - -> usize { - let flags = align_to_flags(align); - unsafe { xallocx(ptr as *mut c_void, size as size_t, 0, flags) as usize } - } - - #[no_mangle] - pub extern "C" fn __rust_deallocate(ptr: *mut u8, old_size: usize, align: usize) { - let flags = align_to_flags(align); - unsafe { sdallocx(ptr as *mut c_void, old_size as size_t, flags) } - } - - #[no_mangle] - pub extern "C" fn __rust_usable_size(size: usize, align: usize) -> usize { - let flags = align_to_flags(align); - unsafe { nallocx(size as size_t, flags) as usize } - } - - // These symbols are used by jemalloc on android but the really old android - // we're building on doesn't have them defined, so just make sure the symbols - // are available. - #[no_mangle] - #[cfg(target_os = "android")] - pub extern "C" fn pthread_atfork(_prefork: *mut u8, - _postfork_parent: *mut u8, - _postfork_child: *mut u8) - -> i32 { - 0 - } -} - -#[cfg(dummy_jemalloc)] -mod imp { - fn bogus() -> ! { - panic!("jemalloc is not implemented for this platform"); - } - - #[no_mangle] - pub extern "C" fn __rust_allocate(_size: usize, _align: usize) -> *mut u8 { - bogus() - } - - #[no_mangle] - pub extern "C" fn __rust_reallocate(_ptr: *mut u8, - _old_size: usize, - _size: usize, - _align: usize) - -> *mut u8 { - bogus() - } - - #[no_mangle] - pub extern "C" fn __rust_reallocate_inplace(_ptr: *mut u8, - _old_size: usize, - _size: usize, - _align: usize) - -> usize { - bogus() - } - - #[no_mangle] - pub extern "C" fn __rust_deallocate(_ptr: *mut u8, _old_size: usize, _align: usize) { - bogus() - } - - #[no_mangle] - pub extern "C" fn __rust_usable_size(_size: usize, _align: usize) -> usize { - bogus() - } -} diff --git a/src/librustc_back/Cargo.toml b/src/librustc_back/Cargo.toml index 85e861b405a9f..d8a82a3d11d01 100644 --- a/src/librustc_back/Cargo.toml +++ b/src/librustc_back/Cargo.toml @@ -12,6 +12,3 @@ crate-type = ["dylib"] syntax = { path = "../libsyntax" } serialize = { path = "../libserialize" } log = { path = "../liblog" } - -[features] -jemalloc = [] diff --git a/src/librustc_back/target/apple_base.rs b/src/librustc_back/target/apple_base.rs index 21a2d4293df77..88cb9fdbef4e1 100644 --- a/src/librustc_back/target/apple_base.rs +++ b/src/librustc_back/target/apple_base.rs @@ -44,7 +44,7 @@ pub fn opts() -> TargetOptions { dll_suffix: ".dylib".to_string(), archive_format: "bsd".to_string(), pre_link_args: Vec::new(), - exe_allocation_crate: super::maybe_jemalloc(), + exe_allocation_crate: "alloc_system".to_owned(), has_elf_tls: version >= (10, 7), .. Default::default() } diff --git a/src/librustc_back/target/dragonfly_base.rs b/src/librustc_back/target/dragonfly_base.rs index dca33e45af7c7..b78fa6c303aed 100644 --- a/src/librustc_back/target/dragonfly_base.rs +++ b/src/librustc_back/target/dragonfly_base.rs @@ -29,7 +29,7 @@ pub fn opts() -> TargetOptions { "-Wl,-z,noexecstack".to_string(), ], position_independent_executables: true, - exe_allocation_crate: super::maybe_jemalloc(), + exe_allocation_crate: "alloc_system".to_owned(), .. Default::default() } } diff --git a/src/librustc_back/target/freebsd_base.rs b/src/librustc_back/target/freebsd_base.rs index dca33e45af7c7..b78fa6c303aed 100644 --- a/src/librustc_back/target/freebsd_base.rs +++ b/src/librustc_back/target/freebsd_base.rs @@ -29,7 +29,7 @@ pub fn opts() -> TargetOptions { "-Wl,-z,noexecstack".to_string(), ], position_independent_executables: true, - exe_allocation_crate: super::maybe_jemalloc(), + exe_allocation_crate: "alloc_system".to_owned(), .. Default::default() } } diff --git a/src/librustc_back/target/linux_base.rs b/src/librustc_back/target/linux_base.rs index 4b2ae9c8e699c..323e21da82fad 100644 --- a/src/librustc_back/target/linux_base.rs +++ b/src/librustc_back/target/linux_base.rs @@ -32,7 +32,7 @@ pub fn opts() -> TargetOptions { "-Wl,-z,noexecstack".to_string(), ], position_independent_executables: true, - exe_allocation_crate: super::maybe_jemalloc(), + exe_allocation_crate: "alloc_system".to_owned(), has_elf_tls: true, .. Default::default() } diff --git a/src/librustc_back/target/mod.rs b/src/librustc_back/target/mod.rs index 5afa85d155279..d533393532025 100644 --- a/src/librustc_back/target/mod.rs +++ b/src/librustc_back/target/mod.rs @@ -795,11 +795,3 @@ impl ToJson for Target { Json::Object(d) } } - -fn maybe_jemalloc() -> String { - if cfg!(feature = "jemalloc") { - "alloc_jemalloc".to_string() - } else { - "alloc_system".to_string() - } -} diff --git a/src/librustc_back/target/solaris_base.rs b/src/librustc_back/target/solaris_base.rs index 41323c9c26ba7..5e88ae41cdf3d 100644 --- a/src/librustc_back/target/solaris_base.rs +++ b/src/librustc_back/target/solaris_base.rs @@ -18,7 +18,7 @@ pub fn opts() -> TargetOptions { has_rpath: true, target_family: Some("unix".to_string()), is_like_solaris: true, - exe_allocation_crate: super::maybe_jemalloc(), + exe_allocation_crate: "alloc_system".to_owned(), .. Default::default() } diff --git a/src/libstd/Cargo.toml b/src/libstd/Cargo.toml index fcf84cb716917..4df788f624b52 100644 --- a/src/libstd/Cargo.toml +++ b/src/libstd/Cargo.toml @@ -11,7 +11,6 @@ crate-type = ["dylib", "rlib"] [dependencies] alloc = { path = "../liballoc" } -alloc_jemalloc = { path = "../liballoc_jemalloc", optional = true } alloc_system = { path = "../liballoc_system" } panic_unwind = { path = "../libpanic_unwind", optional = true } panic_abort = { path = "../libpanic_abort" } @@ -29,6 +28,4 @@ gcc = "0.3.27" [features] backtrace = [] -debug-jemalloc = ["alloc_jemalloc/debug"] -jemalloc = ["alloc_jemalloc"] panic-unwind = ["panic_unwind"] diff --git a/src/rustc/Cargo.toml b/src/rustc/Cargo.toml index dce1a0a8ec858..c808b03ab5d43 100644 --- a/src/rustc/Cargo.toml +++ b/src/rustc/Cargo.toml @@ -17,6 +17,3 @@ path = "rustdoc.rs" rustc_back = { path = "../librustc_back" } rustc_driver = { path = "../librustc_driver" } rustdoc = { path = "../librustdoc" } - -[features] -jemalloc = ["rustc_back/jemalloc"] diff --git a/src/rustc/std_shim/Cargo.toml b/src/rustc/std_shim/Cargo.toml index 1fa9177243536..9c11481813a5e 100644 --- a/src/rustc/std_shim/Cargo.toml +++ b/src/rustc/std_shim/Cargo.toml @@ -36,6 +36,4 @@ core = { path = "../../libcore" } # Reexport features from std [features] backtrace = ["std/backtrace"] -debug-jemalloc = ["std/debug-jemalloc"] -jemalloc = ["std/jemalloc"] panic-unwind = ["std/panic-unwind"] diff --git a/src/tools/tidy/src/cargo.rs b/src/tools/tidy/src/cargo.rs index 11acb64743a7a..561ba802b8585 100644 --- a/src/tools/tidy/src/cargo.rs +++ b/src/tools/tidy/src/cargo.rs @@ -85,8 +85,7 @@ fn verify(tomlfile: &Path, libfile: &Path, bad: &mut bool) { // This is intentional, this dependency just makes the crate available // for others later on. Cover cases - let whitelisted = krate == "alloc_jemalloc"; - let whitelisted = whitelisted || krate.starts_with("panic"); + let whitelisted = krate.starts_with("panic"); if toml.contains("name = \"std\"") && whitelisted { continue } diff --git a/src/tools/tidy/src/main.rs b/src/tools/tidy/src/main.rs index 7566580b1a5f2..3a9f301bf387c 100644 --- a/src/tools/tidy/src/main.rs +++ b/src/tools/tidy/src/main.rs @@ -58,7 +58,6 @@ fn main() { fn filter_dirs(path: &Path) -> bool { let skip = [ - "src/jemalloc", "src/llvm", "src/libbacktrace", "src/compiler-rt", diff --git a/src/tools/tidy/src/pal.rs b/src/tools/tidy/src/pal.rs index 3808c05c6b939..d5a0c59015407 100644 --- a/src/tools/tidy/src/pal.rs +++ b/src/tools/tidy/src/pal.rs @@ -28,7 +28,6 @@ //! - core may not have platform-specific code //! - libcompiler_builtins may have platform-specific code //! - liballoc_system may have platform-specific code -//! - liballoc_jemalloc may have platform-specific code //! - libpanic_abort may have platform-specific code //! - libpanic_unwind may have platform-specific code //! - libunwind may have platform-specific code @@ -52,7 +51,6 @@ use std::iter::Iterator; // Paths that may contain platform-specific code const EXCEPTION_PATHS: &'static [&'static str] = &[ // std crates - "src/liballoc_jemalloc", "src/liballoc_system", "src/libcompiler_builtins", "src/liblibc",