summaryrefslogtreecommitdiff
path: root/user/rust/0005-Remove-nostdlib-and-musl_root-from-musl-targets.patch
diff options
context:
space:
mode:
Diffstat (limited to 'user/rust/0005-Remove-nostdlib-and-musl_root-from-musl-targets.patch')
-rw-r--r--user/rust/0005-Remove-nostdlib-and-musl_root-from-musl-targets.patch444
1 files changed, 444 insertions, 0 deletions
diff --git a/user/rust/0005-Remove-nostdlib-and-musl_root-from-musl-targets.patch b/user/rust/0005-Remove-nostdlib-and-musl_root-from-musl-targets.patch
new file mode 100644
index 000000000..eda99398c
--- /dev/null
+++ b/user/rust/0005-Remove-nostdlib-and-musl_root-from-musl-targets.patch
@@ -0,0 +1,444 @@
+From 1b47e0a7cfc3fd6572d939aa894e3a23522ed4c0 Mon Sep 17 00:00:00 2001
+From: Samuel Holland <samuel@sholland.org>
+Date: Fri, 8 Sep 2017 22:11:14 -0500
+Subject: [PATCH 05/29] Remove -nostdlib and musl_root from musl targets
+
+---
+ config.toml.example | 6 ---
+ src/bootstrap/bin/rustc.rs | 10 -----
+ src/bootstrap/cc_detect.rs | 27 ++----------
+ src/bootstrap/compile.rs | 31 --------------
+ src/bootstrap/config.rs | 7 ----
+ src/bootstrap/configure.py | 22 ----------
+ src/bootstrap/lib.rs | 8 ----
+ src/bootstrap/sanity.rs | 30 +-------------
+ .../dist-i586-gnu-i586-i686-musl/Dockerfile | 2 -
+ src/ci/docker/dist-various-1/Dockerfile | 7 ----
+ src/ci/docker/dist-x86_64-musl/Dockerfile | 1 -
+ src/librustc_target/spec/linux_musl_base.rs | 41 -------------------
+ 12 files changed, 4 insertions(+), 188 deletions(-)
+
+diff --git a/config.toml.example b/config.toml.example
+index 9907341633..6f8b52e235 100644
+--- a/config.toml.example
++++ b/config.toml.example
+@@ -409,12 +409,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 = "..."
+-
+ # Used in testing for configuring where the QEMU images are located, you
+ # probably don't want to use this.
+ #qemu-rootfs = "..."
+diff --git a/src/bootstrap/bin/rustc.rs b/src/bootstrap/bin/rustc.rs
+index 7192cae895..71435f9306 100644
+--- a/src/bootstrap/bin/rustc.rs
++++ b/src/bootstrap/bin/rustc.rs
+@@ -30,7 +30,6 @@
+ extern crate bootstrap;
+
+ use std::env;
+-use std::ffi::OsString;
+ use std::io;
+ use std::path::PathBuf;
+ use std::process::Command;
+@@ -126,15 +125,6 @@ fn main() {
+ cmd.arg("-Cprefer-dynamic");
+ }
+
+- // Help the libc crate compile by assisting it in finding the MUSL
+- // native libraries.
+- if let Some(s) = env::var_os("MUSL_ROOT") {
+- let mut root = OsString::from("native=");
+- root.push(&s);
+- root.push("/lib");
+- cmd.arg("-L").arg(&root);
+- }
+-
+ // Override linker if necessary.
+ if let Ok(target_linker) = env::var("RUSTC_TARGET_LINKER") {
+ cmd.arg(format!("-Clinker={}", target_linker));
+diff --git a/src/bootstrap/cc_detect.rs b/src/bootstrap/cc_detect.rs
+index 698903f128..629cedf019 100644
+--- a/src/bootstrap/cc_detect.rs
++++ b/src/bootstrap/cc_detect.rs
+@@ -95,7 +95,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();
+@@ -124,7 +124,7 @@ pub fn find(build: &mut Build) {
+ if let Some(cxx) = config.and_then(|c| c.cxx.as_ref()) {
+ cfg.compiler(cxx);
+ } else {
+- set_compiler(&mut cfg, Language::CPlusPlus, host, config, build);
++ set_compiler(&mut cfg, Language::CPlusPlus, host, config);
+ }
+ let compiler = cfg.get_compiler();
+ build.verbose(&format!("CXX_{} = {:?}", host, compiler.path()));
+@@ -135,8 +135,7 @@ pub fn find(build: &mut Build) {
+ fn set_compiler(cfg: &mut cc::Build,
+ compiler: Language,
+ target: Interned<String>,
+- config: Option<&Target>,
+- build: &Build) {
++ config: Option<&Target>) {
+ match &*target {
+ // When compiling for android we may have the NDK configured in the
+ // config.toml in which case we look there. Otherwise the default
+@@ -173,26 +172,6 @@ fn set_compiler(cfg: &mut cc::Build,
+ }
+ }
+
+- "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 04e8e133b0..7767956cd8 100644
+--- a/src/bootstrap/compile.rs
++++ b/src/bootstrap/compile.rs
+@@ -87,13 +87,6 @@ impl Step for Std {
+ });
+ builder.info(&format!("Uplifting stage1 std ({} -> {})", from.host, target));
+
+- // Even if we're not building std this stage, the new sysroot must
+- // still contain the musl startup objects.
+- if target.contains("musl") {
+- let libdir = builder.sysroot_libdir(compiler, target);
+- copy_musl_third_party_objects(builder, target, &libdir);
+- }
+-
+ builder.ensure(StdLink {
+ compiler: from,
+ target_compiler: compiler,
+@@ -102,11 +95,6 @@ impl Step for Std {
+ return;
+ }
+
+- if target.contains("musl") {
+- let libdir = builder.sysroot_libdir(compiler, target);
+- copy_musl_third_party_objects(builder, target, &libdir);
+- }
+-
+ let out_dir = builder.cargo_out(compiler, Mode::Std, target);
+ builder.clear_if_dirty(&out_dir, &builder.rustc(compiler));
+ let mut cargo = builder.cargo(compiler, Mode::Std, target, "build");
+@@ -128,20 +116,6 @@ impl Step for Std {
+ }
+ }
+
+-/// Copies the crt(1,i,n).o startup objects
+-///
+-/// Since musl supports fully static linking, we can cross link for it even
+-/// with a glibc-targeting toolchain, given we have the appropriate startup
+-/// files. As those shipped with glibc won't work, copy the ones provided by
+-/// musl so we have them on linux-gnu hosts.
+-fn copy_musl_third_party_objects(builder: &Builder,
+- target: Interned<String>,
+- into: &Path) {
+- for &obj in &["crt1.o", "crti.o", "crtn.o"] {
+- builder.copy(&builder.musl_root(target).unwrap().join("lib").join(obj), &into.join(obj));
+- }
+-}
+-
+ /// Configure cargo to compile the standard library, adding appropriate env vars
+ /// and such.
+ pub fn std_cargo(builder: &Builder,
+@@ -196,11 +170,6 @@ pub fn std_cargo(builder: &Builder,
+ cargo.env("JEMALLOC_OVERRIDE", jemalloc);
+ }
+ }
+- if target.contains("musl") {
+- if let Some(p) = builder.musl_root(target) {
+- cargo.env("MUSL_ROOT", p);
+- }
+- }
+ }
+ }
+
+diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs
+index 0a8a5c87d0..9fdf8690c5 100644
+--- a/src/bootstrap/config.rs
++++ b/src/bootstrap/config.rs
+@@ -131,8 +131,6 @@ pub struct Config {
+ pub save_toolstates: Option<PathBuf>,
+ pub print_step_timings: bool,
+
+- // Fallback musl-root for all targets
+- pub musl_root: Option<PathBuf>,
+ pub prefix: Option<PathBuf>,
+ pub sysconfdir: Option<PathBuf>,
+ pub datadir: Option<PathBuf>,
+@@ -165,7 +163,6 @@ pub struct Target {
+ pub linker: Option<PathBuf>,
+ pub ndk: Option<PathBuf>,
+ pub crt_static: Option<bool>,
+- pub musl_root: Option<PathBuf>,
+ pub qemu_rootfs: Option<PathBuf>,
+ pub no_std: bool,
+ }
+@@ -294,7 +291,6 @@ struct Rust {
+ backtrace: Option<bool>,
+ default_linker: Option<String>,
+ channel: Option<String>,
+- musl_root: Option<String>,
+ rpath: Option<bool>,
+ optimize_tests: Option<bool>,
+ debuginfo_tests: Option<bool>,
+@@ -328,7 +324,6 @@ struct TomlTarget {
+ linker: Option<String>,
+ android_ndk: Option<String>,
+ crt_static: Option<bool>,
+- musl_root: Option<String>,
+ qemu_rootfs: Option<String>,
+ }
+
+@@ -541,7 +536,6 @@ impl Config {
+ set(&mut config.llvm_tools_enabled, rust.llvm_tools);
+ config.rustc_parallel_queries = rust.experimental_parallel_queries.unwrap_or(false);
+ config.rustc_default_linker = rust.default_linker.clone();
+- config.musl_root = rust.musl_root.clone().map(PathBuf::from);
+ config.save_toolstates = rust.save_toolstates.clone().map(PathBuf::from);
+ set(&mut config.deny_warnings, rust.deny_warnings.or(flags.warnings));
+ set(&mut config.backtrace_on_ice, rust.backtrace_on_ice);
+@@ -580,7 +574,6 @@ impl Config {
+ target.ar = cfg.ar.clone().map(PathBuf::from);
+ target.linker = cfg.linker.clone().map(PathBuf::from);
+ target.crt_static = cfg.crt_static.clone();
+- target.musl_root = cfg.musl_root.clone().map(PathBuf::from);
+ target.qemu_rootfs = cfg.qemu_rootfs.clone().map(PathBuf::from);
+
+ config.target_config.insert(INTERNER.intern_string(triple.clone()), target);
+diff --git a/src/bootstrap/configure.py b/src/bootstrap/configure.py
+index 9fdba044f4..513935e4c8 100755
+--- a/src/bootstrap/configure.py
++++ b/src/bootstrap/configure.py
+@@ -108,28 +108,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-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("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",
+diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs
+index e6ac847afe..dd785124d2 100644
+--- a/src/bootstrap/lib.rs
++++ b/src/bootstrap/lib.rs
+@@ -803,14 +803,6 @@ impl Build {
+ }
+ }
+
+- /// Returns the "musl root" for this `target`, if defined
+- fn musl_root(&self, target: Interned<String>) -> 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 true if this is a no-std `target`, if defined
+ fn no_std(&self, target: Interned<String>) -> Option<bool> {
+ self.config.target_config.get(&target)
+diff --git a/src/bootstrap/sanity.rs b/src/bootstrap/sanity.rs
+index c7f514da93..617a3c2399 100644
+--- a/src/bootstrap/sanity.rs
++++ b/src/bootstrap/sanity.rs
+@@ -21,7 +21,7 @@
+ use std::collections::HashMap;
+ use std::env;
+ use std::ffi::{OsString, OsStr};
+-use std::fs::{self, File};
++use std::fs::File;
+ use std::io::Read;
+ use std::path::PathBuf;
+ use std::process::Command;
+@@ -186,34 +186,6 @@ pub fn check(build: &mut Build) {
+ }
+ }
+
+- // 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_insert(Default::default());
+- target.musl_root = Some("/usr".into());
+- }
+- match build.musl_root(*target) {
+- Some(root) => {
+- if fs::metadata(root.join("lib/libc.a")).is_err() {
+- panic!("couldn't find libc.a in musl dir: {}",
+- root.join("lib").display());
+- }
+- if fs::metadata(root.join("lib/libunwind.a")).is_err() {
+- panic!("couldn't find libunwind.a in musl dir: {}",
+- root.join("lib").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/ci/docker/dist-i586-gnu-i586-i686-musl/Dockerfile b/src/ci/docker/dist-i586-gnu-i586-i686-musl/Dockerfile
+index ba2d32a929..412c37fdd1 100644
+--- a/src/ci/docker/dist-i586-gnu-i586-i686-musl/Dockerfile
++++ b/src/ci/docker/dist-i586-gnu-i586-i686-musl/Dockerfile
+@@ -30,8 +30,6 @@ COPY scripts/sccache.sh /scripts/
+ RUN sh /scripts/sccache.sh
+
+ ENV RUST_CONFIGURE_ARGS \
+- --musl-root-i586=/musl-i586 \
+- --musl-root-i686=/musl-i686 \
+ --enable-extended \
+ --disable-docs
+
+diff --git a/src/ci/docker/dist-various-1/Dockerfile b/src/ci/docker/dist-various-1/Dockerfile
+index 6302f55009..e04fdaa226 100644
+--- a/src/ci/docker/dist-various-1/Dockerfile
++++ b/src/ci/docker/dist-various-1/Dockerfile
+@@ -109,13 +109,6 @@ ENV CC_mipsel_unknown_linux_musl=mipsel-openwrt-linux-gcc \
+ CC_x86_64_unknown_redox=x86_64-unknown-redox-gcc
+
+ ENV RUST_CONFIGURE_ARGS \
+- --musl-root-armv5te=/musl-armv5te \
+- --musl-root-arm=/musl-arm \
+- --musl-root-armhf=/musl-armhf \
+- --musl-root-armv7=/musl-armv7 \
+- --musl-root-aarch64=/musl-aarch64 \
+- --musl-root-mips=/musl-mips \
+- --musl-root-mipsel=/musl-mipsel \
+ --enable-emscripten \
+ --disable-docs
+
+diff --git a/src/ci/docker/dist-x86_64-musl/Dockerfile b/src/ci/docker/dist-x86_64-musl/Dockerfile
+index 06f8a2fbba..f5dd379528 100644
+--- a/src/ci/docker/dist-x86_64-musl/Dockerfile
++++ b/src/ci/docker/dist-x86_64-musl/Dockerfile
+@@ -30,7 +30,6 @@ COPY scripts/sccache.sh /scripts/
+ RUN sh /scripts/sccache.sh
+
+ ENV RUST_CONFIGURE_ARGS \
+- --musl-root-x86_64=/musl-x86_64 \
+ --enable-extended \
+ --disable-docs
+
+diff --git a/src/librustc_target/spec/linux_musl_base.rs b/src/librustc_target/spec/linux_musl_base.rs
+index 7a3f3c2a51..32fe2f880a 100644
+--- a/src/librustc_target/spec/linux_musl_base.rs
++++ b/src/librustc_target/spec/linux_musl_base.rs
+@@ -13,53 +13,12 @@ use spec::{LinkerFlavor, TargetOptions};
+ pub fn opts() -> TargetOptions {
+ let mut base = super::linux_base::opts();
+
+- // Make sure that the linker/gcc really don't pull in anything, including
+- // default objects, libs, etc.
+- base.pre_link_args_crt.insert(LinkerFlavor::Gcc, Vec::new());
+- base.pre_link_args_crt.get_mut(&LinkerFlavor::Gcc).unwrap().push("-nostdlib".to_string());
+-
+ // At least when this was tested, the linker would not add the
+ // `GNU_EH_FRAME` program header to executables generated, which is required
+ // when unwinding to locate the unwinding information. I'm not sure why this
+ // 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());
+
+- // There's a whole bunch of circular dependencies when dealing with MUSL
+- // unfortunately. To put this in perspective libc is statically linked to
+- // liblibc and libunwind is statically linked to libstd:
+- //
+- // * libcore depends on `fmod` which is in libc (transitively in liblibc).
+- // liblibc, however, depends on libcore.
+- // * compiler-rt has personality symbols that depend on libunwind, but
+- // libunwind is in libstd which depends on compiler-rt.
+- //
+- // Recall that linkers discard libraries and object files as much as
+- // possible, and with all the static linking and archives flying around with
+- // MUSL the linker is super aggressively stripping out objects. For example
+- // the first case has fmod stripped from liblibc (it's in its own object
+- // file) so it's not there when libcore needs it. In the second example all
+- // the unused symbols from libunwind are stripped (each is in its own object
+- // file in libstd) before we end up linking compiler-rt which depends on
+- // those symbols.
+- //
+- // To deal with these circular dependencies we just force the compiler to
+- // link everything as a group, not stripping anything out until everything
+- // is processed. The linker will still perform a pass to strip out object
+- // files but it won't do so until all objects/archives have been processed.
+- base.pre_link_args.get_mut(&LinkerFlavor::Gcc).unwrap().push("-Wl,-(".to_string());
+- base.post_link_args.insert(LinkerFlavor::Gcc, vec!["-Wl,-)".to_string()]);
+-
+- // When generating a statically linked executable there's generally some
+- // small setup needed which is listed in these files. These are provided by
+- // a musl toolchain and are linked by default by the `musl-gcc` script. Note
+- // that `gcc` also does this by default, it just uses some different files.
+- //
+- // Each target directory for musl has these object files included in it so
+- // they'll be included from there.
+- base.pre_link_objects_exe_crt.push("crt1.o".to_string());
+- base.pre_link_objects_exe_crt.push("crti.o".to_string());
+- base.post_link_objects_crt.push("crtn.o".to_string());
+-
+ // These targets statically link libc by default
+ base.crt_static_default = true;
+ // These targets allow the user to choose between static and dynamic linking.
+--
+2.18.0
+