From 7219ba1c9accbad9b530d312fd9a9f69330c93da Mon Sep 17 00:00:00 2001 From: Samuel Holland Date: Sun, 3 May 2020 17:53:33 +0200 Subject: [PATCH 02/15] Remove -nostdlib and musl_root from musl targets extended by various void contributors to match our musl setup diff --git a/bootstrap.example.toml b/bootstrap.example.toml index 1371fd644..dfd7e17fd 100644 --- a/bootstrap.example.toml +++ b/bootstrap.example.toml @@ -658,14 +658,6 @@ # If using tarball sources, default value is "auto-detect", otherwise, it's "dev". #channel = if "is a tarball source" { "auto-detect" } else { "dev" } -# 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. -# -# Defaults to /usr on musl hosts. Has no default otherwise. -#musl-root = (path) - # By default the `rustc` executable is built with `-Wl,-rpath` flags on Unix # platforms to ensure that the compiler is usable by default from the build # directory (as it links to a number of dynamic libraries). This may not be diff --git a/compiler/rustc_target/src/spec/base/linux_musl.rs b/compiler/rustc_target/src/spec/base/linux_musl.rs index 1bef60240..f81dbfa0e 100644 --- a/compiler/rustc_target/src/spec/base/linux_musl.rs +++ b/compiler/rustc_target/src/spec/base/linux_musl.rs @@ -1,11 +1,8 @@ -use crate::spec::{LinkSelfContainedDefault, TargetOptions, base, crt_objects}; +use crate::spec::{base, TargetOptions}; pub(crate) fn opts() -> TargetOptions { TargetOptions { env: "musl".into(), - pre_link_objects_self_contained: crt_objects::pre_musl_self_contained(), - post_link_objects_self_contained: crt_objects::post_musl_self_contained(), - link_self_contained: LinkSelfContainedDefault::InferredForMusl, ..base::linux::opts() } } diff --git a/compiler/rustc_target/src/spec/crt_objects.rs b/compiler/rustc_target/src/spec/crt_objects.rs index e3b6430a4..13a96e2cb 100644 --- a/compiler/rustc_target/src/spec/crt_objects.rs +++ b/compiler/rustc_target/src/spec/crt_objects.rs @@ -62,28 +62,6 @@ pub(super) fn all(obj: &'static str) -> CrtObjects { ]) } -pub(super) fn pre_musl_self_contained() -> CrtObjects { - new(&[ - (LinkOutputKind::DynamicNoPicExe, &["crt1.o", "crti.o", "crtbegin.o"]), - (LinkOutputKind::DynamicPicExe, &["Scrt1.o", "crti.o", "crtbeginS.o"]), - (LinkOutputKind::StaticNoPicExe, &["crt1.o", "crti.o", "crtbegin.o"]), - (LinkOutputKind::StaticPicExe, &["rcrt1.o", "crti.o", "crtbeginS.o"]), - (LinkOutputKind::DynamicDylib, &["crti.o", "crtbeginS.o"]), - (LinkOutputKind::StaticDylib, &["crti.o", "crtbeginS.o"]), - ]) -} - -pub(super) fn post_musl_self_contained() -> CrtObjects { - new(&[ - (LinkOutputKind::DynamicNoPicExe, &["crtend.o", "crtn.o"]), - (LinkOutputKind::DynamicPicExe, &["crtendS.o", "crtn.o"]), - (LinkOutputKind::StaticNoPicExe, &["crtend.o", "crtn.o"]), - (LinkOutputKind::StaticPicExe, &["crtendS.o", "crtn.o"]), - (LinkOutputKind::DynamicDylib, &["crtendS.o", "crtn.o"]), - (LinkOutputKind::StaticDylib, &["crtendS.o", "crtn.o"]), - ]) -} - pub(super) fn pre_mingw_self_contained() -> CrtObjects { new(&[ (LinkOutputKind::DynamicNoPicExe, &["crt2.o", "rsbegin.o"]), diff --git a/compiler/rustc_target/src/spec/targets/aarch64_unknown_linux_musl.rs b/compiler/rustc_target/src/spec/targets/aarch64_unknown_linux_musl.rs index 58ba06e12..da6487ae6 100644 --- a/compiler/rustc_target/src/spec/targets/aarch64_unknown_linux_musl.rs +++ b/compiler/rustc_target/src/spec/targets/aarch64_unknown_linux_musl.rs @@ -12,9 +12,6 @@ pub(crate) fn target() -> Target { | SanitizerSet::MEMORY | SanitizerSet::THREAD; - // FIXME(compiler-team#422): musl targets should be dynamically linked by default. - base.crt_static_default = true; - Target { llvm_target: "aarch64-unknown-linux-musl".into(), metadata: TargetMetadata { diff --git a/compiler/rustc_target/src/spec/targets/arm_unknown_linux_musleabihf.rs b/compiler/rustc_target/src/spec/targets/arm_unknown_linux_musleabihf.rs index ca52e5b3c..1012b5b1a 100644 --- a/compiler/rustc_target/src/spec/targets/arm_unknown_linux_musleabihf.rs +++ b/compiler/rustc_target/src/spec/targets/arm_unknown_linux_musleabihf.rs @@ -20,8 +20,6 @@ pub(crate) fn target() -> Target { features: "+strict-align,+v6,+vfp2,-d32".into(), max_atomic_width: Some(64), mcount: "\u{1}mcount".into(), - // FIXME(compiler-team#422): musl targets should be dynamically linked by default. - crt_static_default: true, ..base::linux_musl::opts() }, } diff --git a/compiler/rustc_target/src/spec/targets/armv7_unknown_linux_musleabihf.rs b/compiler/rustc_target/src/spec/targets/armv7_unknown_linux_musleabihf.rs index a3ac0223c..ec43eebfc 100644 --- a/compiler/rustc_target/src/spec/targets/armv7_unknown_linux_musleabihf.rs +++ b/compiler/rustc_target/src/spec/targets/armv7_unknown_linux_musleabihf.rs @@ -23,8 +23,6 @@ pub(crate) fn target() -> Target { features: "+v7,+vfp3,-d32,+thumb2,-neon".into(), max_atomic_width: Some(64), mcount: "\u{1}mcount".into(), - // FIXME(compiler-team#422): musl targets should be dynamically linked by default. - crt_static_default: true, ..base::linux_musl::opts() }, } diff --git a/compiler/rustc_target/src/spec/targets/i686_unknown_linux_musl.rs b/compiler/rustc_target/src/spec/targets/i686_unknown_linux_musl.rs index 47a7eb3d5..da1026485 100644 --- a/compiler/rustc_target/src/spec/targets/i686_unknown_linux_musl.rs +++ b/compiler/rustc_target/src/spec/targets/i686_unknown_linux_musl.rs @@ -11,8 +11,6 @@ pub(crate) fn target() -> Target { base.max_atomic_width = Some(64); base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m32", "-Wl,-melf_i386"]); base.stack_probes = StackProbeType::Inline; - // FIXME(compiler-team#422): musl targets should be dynamically linked by default. - base.crt_static_default = true; // The unwinder used by i686-unknown-linux-musl, the LLVM libunwind // implementation, apparently relies on frame pointers existing... somehow. diff --git a/compiler/rustc_target/src/spec/targets/x86_64_unknown_linux_musl.rs b/compiler/rustc_target/src/spec/targets/x86_64_unknown_linux_musl.rs index cc5f88862..0203c776a 100644 --- a/compiler/rustc_target/src/spec/targets/x86_64_unknown_linux_musl.rs +++ b/compiler/rustc_target/src/spec/targets/x86_64_unknown_linux_musl.rs @@ -16,8 +16,6 @@ pub(crate) fn target() -> Target { | SanitizerSet::MEMORY | SanitizerSet::THREAD; base.supports_xray = true; - // FIXME(compiler-team#422): musl targets should be dynamically linked by default. - base.crt_static_default = true; Target { llvm_target: "x86_64-unknown-linux-musl".into(), diff --git a/src/bootstrap/configure.py b/src/bootstrap/configure.py index 0d4d6e0ff..0f5a6d1c1 100755 --- a/src/bootstrap/configure.py +++ b/src/bootstrap/configure.py @@ -179,76 +179,6 @@ v("llvm-config", None, "set path to llvm-config") v("llvm-filecheck", None, "set path to LLVM's FileCheck utility") v("python", "build.python", "set path to python") v("android-ndk", "build.android-ndk", "set path to Android NDK") -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( "musl-root-powerpc64", "target.powerpc64-unknown-linux-musl.musl-root", diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs index 2e5865e50..b9cc1ad1e 100644 --- a/src/bootstrap/src/core/build_steps/compile.rs +++ b/src/bootstrap/src/core/build_steps/compile.rs @@ -372,53 +372,7 @@ fn copy_self_contained_objects( let mut target_deps = vec![]; // Copies the libc and 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.needs_crt_begin_end() { - let srcdir = builder.musl_libdir(target).unwrap_or_else(|| { - panic!("Target {:?} does not have a \"musl-libdir\" key", target.triple) - }); - if !target.starts_with("wasm32") { - for &obj in &["libc.a", "crt1.o", "Scrt1.o", "rcrt1.o", "crti.o", "crtn.o"] { - copy_and_stamp( - builder, - &libdir_self_contained, - &srcdir, - obj, - &mut target_deps, - DependencyType::TargetSelfContained, - ); - } - let crt_path = builder.ensure(llvm::CrtBeginEnd { target }); - for &obj in &["crtbegin.o", "crtbeginS.o", "crtend.o", "crtendS.o"] { - let src = crt_path.join(obj); - let target = libdir_self_contained.join(obj); - builder.copy_link(&src, &target, FileType::NativeLibrary); - target_deps.push((target, DependencyType::TargetSelfContained)); - } - } else { - // For wasm32 targets, we need to copy the libc.a and crt1-command.o files from the - // musl-libdir, but we don't need the other files. - for &obj in &["libc.a", "crt1-command.o"] { - copy_and_stamp( - builder, - &libdir_self_contained, - &srcdir, - obj, - &mut target_deps, - DependencyType::TargetSelfContained, - ); - } - } - if !target.starts_with("s390x") { - let libunwind_path = copy_llvm_libunwind(builder, target, &libdir_self_contained); - target_deps.push((libunwind_path, DependencyType::TargetSelfContained)); - } - } else if target.contains("-wasi") { + if target.contains("-wasi") { let srcdir = builder.wasi_libdir(target).unwrap_or_else(|| { panic!( "Target {:?} does not have a \"wasi-root\" key in bootstrap.toml \ @@ -626,15 +580,6 @@ pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, stage: u32, car .arg("--manifest-path") .arg(builder.src.join("library/sysroot/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.contains("-wasi") { if let Some(dir) = builder.wasi_libdir(target) { let root = format!("native={}", dir.to_str().unwrap()); diff --git a/src/bootstrap/src/core/config/config.rs b/src/bootstrap/src/core/config/config.rs index 65a3e7667..2a6a22fbb 100644 --- a/src/bootstrap/src/core/config/config.rs +++ b/src/bootstrap/src/core/config/config.rs @@ -372,7 +372,6 @@ pub struct Config { pub print_step_rusage: bool, // Fallback musl-root for all targets - pub musl_root: Option, pub prefix: Option, pub sysconfdir: Option, pub datadir: Option, @@ -665,8 +664,6 @@ pub struct Target { pub profiler: Option, pub rpath: Option, pub crt_static: Option, - pub musl_root: Option, - pub musl_libdir: Option, pub wasi_root: Option, pub qemu_rootfs: Option, pub runner: Option, @@ -1296,7 +1293,6 @@ define_config! { channel: Option = "channel", // FIXME: Remove this field at Q2 2025, it has been replaced by build.description description: Option = "description", - musl_root: Option = "musl-root", rpath: Option = "rpath", strip: Option = "strip", frame_pointers: Option = "frame-pointers", @@ -1351,8 +1347,6 @@ define_config! { profiler: Option = "profiler", rpath: Option = "rpath", crt_static: Option = "crt-static", - musl_root: Option = "musl-root", - musl_libdir: Option = "musl-libdir", wasi_root: Option = "wasi-root", qemu_rootfs: Option = "qemu-rootfs", no_std: Option = "no-std", @@ -2018,7 +2012,6 @@ impl Config { default_linker, channel: _, // already handled above description: rust_description, - musl_root, rpath, verbose_tests, optimize_tests, @@ -2132,7 +2125,6 @@ impl Config { config.llvm_enzyme = llvm_enzyme.unwrap_or(config.channel == "dev" || config.channel == "nightly"); config.rustc_default_linker = default_linker; - config.musl_root = musl_root.map(PathBuf::from); config.save_toolstates = save_toolstates.map(PathBuf::from); set( &mut config.deny_warnings, @@ -2364,8 +2356,6 @@ impl Config { 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); target.runner = cfg.runner; @@ -3583,7 +3573,6 @@ fn check_incompatible_options_for_ci_rustc( debuginfo_level_tools: _, debuginfo_level_tests: _, backtrace: _, - musl_root: _, verbose_tests: _, optimize_tests: _, codegen_tests: _, diff --git a/src/bootstrap/src/core/sanity.rs b/src/bootstrap/src/core/sanity.rs index eb0bf1d16..b85cfedd6 100644 --- a/src/bootstrap/src/core/sanity.rs +++ b/src/bootstrap/src/core/sanity.rs @@ -11,7 +11,7 @@ use std::collections::{HashMap, HashSet}; use std::ffi::{OsStr, OsString}; use std::path::PathBuf; -use std::{env, fs}; +use std::env; use crate::Build; #[cfg(not(test))] @@ -322,28 +322,6 @@ than building it. continue; } - // Make sure musl-root is valid. - if target.contains("musl") && !target.contains("unikraft") { - // 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.is_host_target(*target) { - let target = build.config.target_config.entry(*target).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 bootstrap.toml" - ), - } - } - if need_cmake && target.is_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/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs index 1e6acad5c..923904111 100644 --- a/src/bootstrap/src/lib.rs +++ b/src/bootstrap/src/lib.rs @@ -1360,25 +1360,6 @@ Executed at: {executed_at}"#, } } - /// 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(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 `lib` directory for the WASI target specified, if /// configured. /// diff --git a/src/bootstrap/src/utils/cc_detect.rs b/src/bootstrap/src/utils/cc_detect.rs index ceac24d43..49bcb7b3a 100644 --- a/src/bootstrap/src/utils/cc_detect.rs +++ b/src/bootstrap/src/utils/cc_detect.rs @@ -226,30 +226,6 @@ fn default_compiler( } } - "mips-unknown-linux-musl" if compiler == Language::C => { - if cfg.get_compiler().path().to_str() == Some("gcc") { - Some(PathBuf::from("mips-linux-musl-gcc")) - } else { - None - } - } - "mipsel-unknown-linux-musl" if compiler == Language::C => { - if cfg.get_compiler().path().to_str() == Some("gcc") { - Some(PathBuf::from("mipsel-linux-musl-gcc")) - } else { - None - } - } - - t if t.contains("musl") && compiler == Language::C => { - if let Some(root) = build.musl_root(target) { - let guess = root.join("bin/musl-gcc"); - if guess.exists() { Some(guess) } else { None } - } else { - None - } - } - t if t.contains("-wasi") => { let root = PathBuf::from(std::env::var_os("WASI_SDK_PATH")?); let compiler = match compiler {