From 4654172e942b5b9250aff70101d54bc880060073 Mon Sep 17 00:00:00 2001 From: Samuel Holland Date: Sun, 3 May 2020 17:53:33 +0200 Subject: [PATCH 04/15] Remove -nostdlib and musl_root from musl targets --- config.toml.example | 3 --- src/bootstrap/cc_detect.rs | 25 ++---------------- src/bootstrap/compile.rs | 22 +--------------- src/bootstrap/config.rs | 7 ------ src/bootstrap/configure.py | 28 --------------------- src/bootstrap/lib.rs | 10 -------- src/bootstrap/sanity.rs | 22 ---------------- src/librustc_target/spec/linux_musl_base.rs | 16 ------------ 8 files changed, 3 insertions(+), 130 deletions(-) --- a/config.toml.example +++ b/config.toml.example @@ -525,15 +525,6 @@ # only use static libraries. If unset, the target's default linkage is used. #crt-static = false -# The root location of the musl installation directory. The library directory -# will also need to contain libunwind.a for an unwinding implementation. Note -# that this option only makes sense for musl targets that produce statically -# linked binaries -#musl-root = "..." - -# The full path to the musl libdir. -#musl-libdir = musl-root/lib - # The root location of the `wasm32-wasi` sysroot. #wasi-root = "..." diff --git a/src/bootstrap/cc_detect.rs b/src/bootstrap/cc_detect.rs index a236edf9..54c3cc64 100644 --- a/src/bootstrap/cc_detect.rs +++ b/src/bootstrap/cc_detect.rs @@ -97,7 +97,7 @@ pub fn find(build: &mut Build) { if let Some(cc) = config.and_then(|c| c.cc.as_ref()) { cfg.compiler(cc); } else { - set_compiler(&mut cfg, Language::C, target, config, build); + set_compiler(&mut cfg, Language::C, target, config); } let compiler = cfg.get_compiler(); @@ -125,7 +125,7 @@ pub fn find(build: &mut Build) { cfg.compiler(cxx); true } else if build.hosts.contains(&target) || build.build == target { - set_compiler(&mut cfg, Language::CPlusPlus, target, config, build); + set_compiler(&mut cfg, Language::CPlusPlus, target, config); true } else { false @@ -154,7 +154,6 @@ fn set_compiler( compiler: Language, target: Interned, config: Option<&Target>, - build: &Build, ) { match &*target { // When compiling for android we may have the NDK configured in the @@ -196,26 +195,6 @@ fn set_compiler( } } - "mips-unknown-linux-musl" => { - if cfg.get_compiler().path().to_str() == Some("gcc") { - cfg.compiler("mips-linux-musl-gcc"); - } - } - "mipsel-unknown-linux-musl" => { - if cfg.get_compiler().path().to_str() == Some("gcc") { - cfg.compiler("mipsel-linux-musl-gcc"); - } - } - - t if t.contains("musl") => { - if let Some(root) = build.musl_root(target) { - let guess = root.join("bin/musl-gcc"); - if guess.exists() { - cfg.compiler(guess); - } - } - } - _ => {} } } diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index 65a00db3..01fd2cf3 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -169,26 +169,7 @@ t!(fs::create_dir_all(&libdir_self_contained)); let mut target_deps = vec![]; - // Copies the CRT objects. - // - // rustc historically provides a more self-contained installation for musl targets - // not requiring the presence of a native musl toolchain. For example, it can fall back - // to using gcc from a glibc-targeting toolchain for linking. - // To do that we have to distribute musl startup objects as a part of Rust toolchain - // and link with them manually in the self-contained mode. - if target.contains("musl") { - let srcdir = builder.musl_libdir(target).unwrap(); - for &obj in &["crt1.o", "Scrt1.o", "rcrt1.o", "crti.o", "crtn.o"] { - copy_and_stamp( - builder, - &libdir_self_contained, - &srcdir, - obj, - &mut target_deps, - DependencyType::TargetSelfContained, - ); - } - } else if target.ends_with("-wasi") { + if target.ends_with("-wasi") { let srcdir = builder.wasi_root(target).unwrap().join("lib/wasm32-wasi"); copy_and_stamp( builder, @@ -263,15 +244,6 @@ .arg("--manifest-path") .arg(builder.src.join("src/libtest/Cargo.toml")); - // Help the libc crate compile by assisting it in finding various - // sysroot native libraries. - if target.contains("musl") { - if let Some(p) = builder.musl_libdir(target) { - let root = format!("native={}", p.to_str().unwrap()); - cargo.rustflag("-L").rustflag(&root); - } - } - if target.ends_with("-wasi") { if let Some(p) = builder.wasi_root(target) { let root = format!("native={}/lib/wasm32-wasi", p.to_str().unwrap()); diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index 56164b74..8c46334a 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -154,8 +154,6 @@ pub print_step_timings: bool, pub missing_tools: bool, - // Fallback musl-root for all targets - pub musl_root: Option, pub prefix: Option, pub sysconfdir: Option, pub datadir: Option, @@ -252,8 +250,6 @@ pub linker: Option, pub ndk: Option, pub crt_static: Option, - pub musl_root: Option, - pub musl_libdir: Option, pub wasi_root: Option, pub qemu_rootfs: Option, pub no_std: bool, @@ -438,7 +434,6 @@ parallel_compiler: Option, default_linker: Option, channel: Option, - musl_root: Option, rpath: Option, verbose_tests: Option, optimize_tests: Option, @@ -475,8 +470,6 @@ llvm_filecheck: Option, android_ndk: Option, crt_static: Option, - musl_root: Option, - musl_libdir: Option, wasi_root: Option, qemu_rootfs: Option, no_std: Option, @@ -806,7 +799,6 @@ set(&mut config.llvm_tools_enabled, rust.llvm_tools); config.rustc_parallel = rust.parallel_compiler.unwrap_or(false); config.rustc_default_linker = rust.default_linker; - config.musl_root = rust.musl_root.map(PathBuf::from); config.save_toolstates = rust.save_toolstates.map(PathBuf::from); set(&mut config.deny_warnings, flags.deny_warnings.or(rust.deny_warnings)); set(&mut config.backtrace_on_ice, rust.backtrace_on_ice); @@ -846,8 +838,6 @@ target.ranlib = cfg.ranlib.map(PathBuf::from); target.linker = cfg.linker.map(PathBuf::from); target.crt_static = cfg.crt_static; - target.musl_root = cfg.musl_root.map(PathBuf::from); - target.musl_libdir = cfg.musl_libdir.map(PathBuf::from); target.wasi_root = cfg.wasi_root.map(PathBuf::from); target.qemu_rootfs = cfg.qemu_rootfs.map(PathBuf::from); diff --git a/src/bootstrap/configure.py b/src/bootstrap/configure.py index 2a46c563..025928b9 100755 --- a/src/bootstrap/configure.py +++ b/src/bootstrap/configure.py @@ -110,34 +110,6 @@ v("aarch64-linux-android-ndk", "target.aarch64-linux-android.android-ndk", "aarch64-linux-android NDK standalone path") v("x86_64-linux-android-ndk", "target.x86_64-linux-android.android-ndk", "x86_64-linux-android NDK standalone path") -v("musl-root", "target.x86_64-unknown-linux-musl.musl-root", - "MUSL root installation directory (deprecated)") -v("musl-root-x86_64", "target.x86_64-unknown-linux-musl.musl-root", - "x86_64-unknown-linux-musl install directory") -v("musl-root-i586", "target.i586-unknown-linux-musl.musl-root", - "i586-unknown-linux-musl install directory") -v("musl-root-i686", "target.i686-unknown-linux-musl.musl-root", - "i686-unknown-linux-musl install directory") -v("musl-root-arm", "target.arm-unknown-linux-musleabi.musl-root", - "arm-unknown-linux-musleabi install directory") -v("musl-root-armhf", "target.arm-unknown-linux-musleabihf.musl-root", - "arm-unknown-linux-musleabihf install directory") -v("musl-root-armv5te", "target.armv5te-unknown-linux-musleabi.musl-root", - "armv5te-unknown-linux-musleabi install directory") -v("musl-root-armv7", "target.armv7-unknown-linux-musleabi.musl-root", - "armv7-unknown-linux-musleabi install directory") -v("musl-root-armv7hf", "target.armv7-unknown-linux-musleabihf.musl-root", - "armv7-unknown-linux-musleabihf install directory") -v("musl-root-aarch64", "target.aarch64-unknown-linux-musl.musl-root", - "aarch64-unknown-linux-musl install directory") -v("musl-root-mips", "target.mips-unknown-linux-musl.musl-root", - "mips-unknown-linux-musl install directory") -v("musl-root-mipsel", "target.mipsel-unknown-linux-musl.musl-root", - "mipsel-unknown-linux-musl install directory") -v("musl-root-mips64", "target.mips64-unknown-linux-muslabi64.musl-root", - "mips64-unknown-linux-muslabi64 install directory") -v("musl-root-mips64el", "target.mips64el-unknown-linux-muslabi64.musl-root", - "mips64el-unknown-linux-muslabi64 install directory") v("qemu-armhf-rootfs", "target.arm-unknown-linux-gnueabihf.qemu-rootfs", "rootfs in qemu testing, you probably don't want to use this") v("qemu-aarch64-rootfs", "target.aarch64-unknown-linux-gnu.qemu-rootfs", --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -876,25 +876,6 @@ } } - /// Returns the "musl root" for this `target`, if defined - fn musl_root(&self, target: TargetSelection) -> Option<&Path> { - self.config - .target_config - .get(&target) - .and_then(|t| t.musl_root.as_ref()) - .or_else(|| self.config.musl_root.as_ref()) - .map(|p| &**p) - } - - /// Returns the "musl libdir" for this `target`. - fn musl_libdir(&self, target: TargetSelection) -> Option { - let t = self.config.target_config.get(&target)?; - if let libdir @ Some(_) = &t.musl_libdir { - return libdir.clone(); - } - self.musl_root(target).map(|root| root.join("lib")) - } - /// Returns the sysroot for the wasi target, if defined fn wasi_root(&self, target: TargetSelection) -> Option<&Path> { self.config.target_config.get(&target).and_then(|t| t.wasi_root.as_ref()).map(|p| &**p) diff --git a/src/bootstrap/sanity.rs b/src/bootstrap/sanity.rs index 530e74da..8ec9f046 100644 --- a/src/bootstrap/sanity.rs +++ b/src/bootstrap/sanity.rs @@ -191,28 +191,6 @@ } } - // Make sure musl-root is valid - if target.contains("musl") { - // If this is a native target (host is also musl) and no musl-root is given, - // fall back to the system toolchain in /usr before giving up - if build.musl_root(*target).is_none() && build.config.build == *target { - let target = build.config.target_config.entry(target.clone()).or_default(); - target.musl_root = Some("/usr".into()); - } - match build.musl_libdir(*target) { - Some(libdir) => { - if fs::metadata(libdir.join("libc.a")).is_err() { - panic!("couldn't find libc.a in musl libdir: {}", libdir.display()); - } - } - None => panic!( - "when targeting MUSL either the rust.musl-root \ - option or the target.$TARGET.musl-root option must \ - be specified in config.toml" - ), - } - } - if target.contains("msvc") { // There are three builds of cmake on windows: MSVC, MinGW, and // Cygwin. The Cygwin build does not have generators for Visual diff --git a/src/librustc_target/spec/linux_musl_base.rs b/src/librustc_target/spec/linux_musl_base.rs index e294e639..58ae91a9 100644 --- a/compiler/rustc_target/src/spec/linux_musl_base.rs +++ b/compiler/rustc_target/src/spec/linux_musl_base.rs @@ -10,10 +10,6 @@ // argument is *not* necessary for normal builds, but it can't hurt! base.pre_link_args.get_mut(&LinkerFlavor::Gcc).unwrap().push("-Wl,--eh-frame-hdr".to_string()); - base.pre_link_objects_fallback = crt_objects::pre_musl_fallback(); - base.post_link_objects_fallback = crt_objects::post_musl_fallback(); - base.crt_objects_fallback = Some(CrtObjectsFallback::Musl); - // These targets statically link libc by default base.crt_static_default = true; // These targets allow the user to choose between static and dynamic linking. --- a/compiler/rustc_target/src/spec/crt_objects.rs.orig 2020-08-07 01:01:58.142394507 +0200 +++ b/compiler/rustc_target/src/spec/crt_objects.rs 2020-08-07 01:02:25.030392771 +0200 @@ -61,21 +61,6 @@ ]) } -pub(super) fn pre_musl_fallback() -> CrtObjects { - new(&[ - (LinkOutputKind::DynamicNoPicExe, &["crt1.o", "crti.o"]), - (LinkOutputKind::DynamicPicExe, &["Scrt1.o", "crti.o"]), - (LinkOutputKind::StaticNoPicExe, &["crt1.o", "crti.o"]), - (LinkOutputKind::StaticPicExe, &["rcrt1.o", "crti.o"]), - (LinkOutputKind::DynamicDylib, &["crti.o"]), - (LinkOutputKind::StaticDylib, &["crti.o"]), - ]) -} - -pub(super) fn post_musl_fallback() -> CrtObjects { - all("crtn.o") -} - pub(super) fn pre_mingw_fallback() -> CrtObjects { new(&[ (LinkOutputKind::DynamicNoPicExe, &["crt2.o", "rsbegin.o"]), -- 2.26.2