From 57cad5722db3043804bc4c38ec3b456e9ff497be Mon Sep 17 00:00:00 2001 From: Timon Van Overveldt Date: Wed, 27 Apr 2016 18:02:31 -0700 Subject: [PATCH 1/9] Update gcc crate dependency to 0.3.27. This is to pull in changes to support ARM MUSL targets. This change also commits a couple of other cargo-generated changes to other dependencies in the various Cargo.toml files. --- src/bootstrap/Cargo.lock | 12 ++++++------ src/liballoc_jemalloc/Cargo.toml | 2 +- src/libflate/Cargo.toml | 2 +- src/librustc_llvm/Cargo.toml | 2 +- src/librustdoc/Cargo.toml | 2 +- src/libstd/Cargo.toml | 2 +- src/rustc/std_shim/Cargo.lock | 6 +++--- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/bootstrap/Cargo.lock b/src/bootstrap/Cargo.lock index 1290f2a404b22..02698d6f7a123 100644 --- a/src/bootstrap/Cargo.lock +++ b/src/bootstrap/Cargo.lock @@ -7,8 +7,8 @@ dependencies = [ "filetime 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "gcc 0.3.31 (git+https://github.com/alexcrichton/gcc-rs)", "getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", - "kernel32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", + "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", "md5 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", @@ -33,7 +33,7 @@ name = "filetime" version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -53,7 +53,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "kernel32-sys" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "winapi 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -62,7 +62,7 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.9" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -75,7 +75,7 @@ name = "num_cpus" version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] diff --git a/src/liballoc_jemalloc/Cargo.toml b/src/liballoc_jemalloc/Cargo.toml index 768a0c2c0a54d..25b3c8a3a0a83 100644 --- a/src/liballoc_jemalloc/Cargo.toml +++ b/src/liballoc_jemalloc/Cargo.toml @@ -16,7 +16,7 @@ libc = { path = "../rustc/libc_shim" } [build-dependencies] build_helper = { path = "../build_helper" } -gcc = "0.3.17" +gcc = "0.3.27" [features] debug = [] diff --git a/src/libflate/Cargo.toml b/src/libflate/Cargo.toml index 52aa6bb86ef90..5423da9c81c02 100644 --- a/src/libflate/Cargo.toml +++ b/src/libflate/Cargo.toml @@ -11,4 +11,4 @@ crate-type = ["dylib"] [build-dependencies] build_helper = { path = "../build_helper" } -gcc = "0.3" +gcc = "0.3.27" diff --git a/src/librustc_llvm/Cargo.toml b/src/librustc_llvm/Cargo.toml index 05d20911a5dc3..f97daa22ff662 100644 --- a/src/librustc_llvm/Cargo.toml +++ b/src/librustc_llvm/Cargo.toml @@ -17,4 +17,4 @@ rustc_bitflags = { path = "../librustc_bitflags" } [build-dependencies] build_helper = { path = "../build_helper" } -gcc = "0.3" +gcc = "0.3.27" diff --git a/src/librustdoc/Cargo.toml b/src/librustdoc/Cargo.toml index a41d3b0253a36..3e510bdc9002e 100644 --- a/src/librustdoc/Cargo.toml +++ b/src/librustdoc/Cargo.toml @@ -28,4 +28,4 @@ log = { path = "../liblog" } [build-dependencies] build_helper = { path = "../build_helper" } -gcc = "0.3" +gcc = "0.3.27" diff --git a/src/libstd/Cargo.toml b/src/libstd/Cargo.toml index b442d21b72ba9..3ce6841fdd4c6 100644 --- a/src/libstd/Cargo.toml +++ b/src/libstd/Cargo.toml @@ -24,7 +24,7 @@ unwind = { path = "../libunwind" } [build-dependencies] build_helper = { path = "../build_helper" } -gcc = "0.3" +gcc = "0.3.27" [features] backtrace = [] diff --git a/src/rustc/std_shim/Cargo.lock b/src/rustc/std_shim/Cargo.lock index bad46966ffa6b..70aef55d799c1 100644 --- a/src/rustc/std_shim/Cargo.lock +++ b/src/rustc/std_shim/Cargo.lock @@ -18,7 +18,7 @@ version = "0.0.0" dependencies = [ "build_helper 0.1.0", "core 0.0.0", - "gcc 0.3.26 (registry+https://github.com/rust-lang/crates.io-index)", + "gcc 0.3.27 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.0.0", ] @@ -49,7 +49,7 @@ version = "0.0.0" [[package]] name = "gcc" -version = "0.3.26" +version = "0.3.27" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -101,7 +101,7 @@ dependencies = [ "build_helper 0.1.0", "collections 0.0.0", "core 0.0.0", - "gcc 0.3.26 (registry+https://github.com/rust-lang/crates.io-index)", + "gcc 0.3.27 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.0.0", "panic_abort 0.0.0", "panic_unwind 0.0.0", From f7247d1071206db45103c994b0077fcb0d8f75cf Mon Sep 17 00:00:00 2001 From: Timon Van Overveldt Date: Wed, 27 Apr 2016 18:02:31 -0700 Subject: [PATCH 2/9] Add ARM MUSL targets. The targets are: - `arm-unknown-linux-musleabi` - `arm-unknown-linux-musleabihf` - `armv7-unknown-linux-musleabihf` These mirror the existing `gnueabi` targets. All of these targets produce fully static binaries, similar to the x86 MUSL targets. For now these targets can only be used with `--rustbuild` builds, as https://github.com/rust-lang/compiler-rt/pull/22 only made the necessary compiler-rt changes in the CMake configs, not the plain GNU Make configs. I've tested these targets GCC 5.3.0 compiled again musl-1.1.12 (downloaded from http://musl.codu.org/). An example `./configure` invocation is: ``` ./configure \ --enable-rustbuild --target=arm-unknown-linux-musleabi \ --musl-root="$MUSL_ROOT" ``` where `MUSL_ROOT` points to the `arm-linux-musleabi` prefix. Usually that path will be of the form `/foobar/arm-linux-musleabi/arm-linux-musleabi`. Usually the cross-compile toolchain will live under `/foobar/arm-linux-musleabi/bin`. That path should either by added to your `PATH` variable, or you should add a section to your `config.toml` as follows: ``` [target.arm-unknown-linux-musleabi] cc = "/foobar/arm-linux-musleabi/bin/arm-linux-musleabi-gcc" cxx = "/foobar/arm-linux-musleabi/bin/arm-linux-musleabi-g++" ``` As a prerequisite you'll also have to put a cross-compiled static `libunwind.a` library in `$MUSL_ROOT/lib`. This is similar to [how the x86_64 MUSL targets are built] (https://doc.rust-lang.org/book/advanced-linking.html). --- configure | 2 +- mk/cfg/arm-unknown-linux-musleabi.mk | 3 + mk/cfg/arm-unknown-linux-musleabihf.mk | 3 + mk/cfg/armv7-unknown-linux-musleabihf.mk | 3 + src/bootstrap/compile.rs | 3 +- src/bootstrap/sanity.rs | 2 +- src/liballoc_jemalloc/build.rs | 11 ++- src/liballoc_jemalloc/lib.rs | 4 +- .../target/arm_unknown_linux_musleabi.rs | 33 +++++++++ .../target/arm_unknown_linux_musleabihf.rs | 33 +++++++++ .../target/armv7_unknown_linux_musleabihf.rs | 34 +++++++++ src/librustc_back/target/mod.rs | 4 ++ src/librustc_back/target/musl_base.rs | 72 +++++++++++++++++++ src/libstd/rtdeps.rs | 4 +- src/libstd/sys/unix/thread.rs | 8 ++- 15 files changed, 210 insertions(+), 9 deletions(-) create mode 100644 mk/cfg/arm-unknown-linux-musleabi.mk create mode 100644 mk/cfg/arm-unknown-linux-musleabihf.mk create mode 100644 mk/cfg/armv7-unknown-linux-musleabihf.mk create mode 100644 src/librustc_back/target/arm_unknown_linux_musleabi.rs create mode 100644 src/librustc_back/target/arm_unknown_linux_musleabihf.rs create mode 100644 src/librustc_back/target/armv7_unknown_linux_musleabihf.rs create mode 100644 src/librustc_back/target/musl_base.rs diff --git a/configure b/configure index d2ec457a1c8bc..a7e24a506fbef 100755 --- a/configure +++ b/configure @@ -1192,7 +1192,7 @@ do ;; - x86_64-*-musl) + x86_64-*-musl | arm-*-musleabi) if [ ! -f $CFG_MUSL_ROOT/lib/libc.a ] then err "musl libc $CFG_MUSL_ROOT/lib/libc.a not found" diff --git a/mk/cfg/arm-unknown-linux-musleabi.mk b/mk/cfg/arm-unknown-linux-musleabi.mk new file mode 100644 index 0000000000000..8120250150d43 --- /dev/null +++ b/mk/cfg/arm-unknown-linux-musleabi.mk @@ -0,0 +1,3 @@ +# This file is intentially left empty to indicate that, while this target is +# supported, it's not supported using plain GNU Make builds. Use a --rustbuild +# instead. \ No newline at end of file diff --git a/mk/cfg/arm-unknown-linux-musleabihf.mk b/mk/cfg/arm-unknown-linux-musleabihf.mk new file mode 100644 index 0000000000000..8120250150d43 --- /dev/null +++ b/mk/cfg/arm-unknown-linux-musleabihf.mk @@ -0,0 +1,3 @@ +# This file is intentially left empty to indicate that, while this target is +# supported, it's not supported using plain GNU Make builds. Use a --rustbuild +# instead. \ No newline at end of file diff --git a/mk/cfg/armv7-unknown-linux-musleabihf.mk b/mk/cfg/armv7-unknown-linux-musleabihf.mk new file mode 100644 index 0000000000000..8120250150d43 --- /dev/null +++ b/mk/cfg/armv7-unknown-linux-musleabihf.mk @@ -0,0 +1,3 @@ +# This file is intentially left empty to indicate that, while this target is +# supported, it's not supported using plain GNU Make builds. Use a --rustbuild +# instead. \ No newline at end of file diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index 8ec9c7f0109f3..061192ebd1340 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -92,8 +92,7 @@ pub fn std_link(build: &Build, } add_to_sysroot(&out_dir, &libdir); - if target.contains("musl") && - (target.contains("x86_64") || target.contains("i686")) { + if target.contains("musl") && !target.contains("mips") { copy_third_party_objects(build, target, &libdir); } } diff --git a/src/bootstrap/sanity.rs b/src/bootstrap/sanity.rs index 7374924675894..09f96782e7184 100644 --- a/src/bootstrap/sanity.rs +++ b/src/bootstrap/sanity.rs @@ -109,7 +109,7 @@ pub fn check(build: &mut Build) { } // Make sure musl-root is valid if specified - if target.contains("musl") && (target.contains("x86_64") || target.contains("i686")) { + if target.contains("musl") && !target.contains("mips") { match build.config.musl_root { Some(ref root) => { if fs::metadata(root.join("lib/libc.a")).is_err() { diff --git a/src/liballoc_jemalloc/build.rs b/src/liballoc_jemalloc/build.rs index d1b3583d256b6..dc1b8d6ea9835 100644 --- a/src/liballoc_jemalloc/build.rs +++ b/src/liballoc_jemalloc/build.rs @@ -73,7 +73,16 @@ fn main() { .replace("\\", "/")) .current_dir(&build_dir) .env("CC", compiler.path()) - .env("EXTRA_CFLAGS", cflags) + .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())); diff --git a/src/liballoc_jemalloc/lib.rs b/src/liballoc_jemalloc/lib.rs index 347e97e6ffc0a..ccf3d978fe434 100644 --- a/src/liballoc_jemalloc/lib.rs +++ b/src/liballoc_jemalloc/lib.rs @@ -36,7 +36,9 @@ use libc::{c_int, c_void, size_t}; #[cfg_attr(target_os = "android", link(name = "gcc"))] #[cfg_attr(all(not(windows), not(target_os = "android"), - not(target_env = "musl")), + not(target_env = "musl"), + not(target_env = "musleabi"), + not(target_env = "musleabihf")), link(name = "pthread"))] #[cfg(not(cargobuild))] extern "C" {} diff --git a/src/librustc_back/target/arm_unknown_linux_musleabi.rs b/src/librustc_back/target/arm_unknown_linux_musleabi.rs new file mode 100644 index 0000000000000..906f60f1c9a18 --- /dev/null +++ b/src/librustc_back/target/arm_unknown_linux_musleabi.rs @@ -0,0 +1,33 @@ +// Copyright 2016 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. + +use target::Target; + +pub fn target() -> Target { + let mut base = super::musl_base::opts(); + + // Most of these settings are copied from the arm_unknown_linux_gnueabi + // target. + base.features = "+v6".to_string(); + Target { + // It's important we use "gnueabi" and not "musleabi" here. LLVM uses it + // to determine the calling convention and float ABI, and it doesn't + // support the "musleabi" value. + llvm_target: "arm-unknown-linux-gnueabi".to_string(), + target_endian: "little".to_string(), + target_pointer_width: "32".to_string(), + data_layout: "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), + arch: "arm".to_string(), + target_os: "linux".to_string(), + target_env: "musleabi".to_string(), + target_vendor: "unknown".to_string(), + options: base, + } +} diff --git a/src/librustc_back/target/arm_unknown_linux_musleabihf.rs b/src/librustc_back/target/arm_unknown_linux_musleabihf.rs new file mode 100644 index 0000000000000..3051721b8c21f --- /dev/null +++ b/src/librustc_back/target/arm_unknown_linux_musleabihf.rs @@ -0,0 +1,33 @@ +// Copyright 2016 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. + +use target::Target; + +pub fn target() -> Target { + let mut base = super::musl_base::opts(); + + // Most of these settings are copied from the arm_unknown_linux_gnueabihf + // target. + base.features = "+v6,+vfp2".to_string(); + Target { + // It's important we use "gnueabihf" and not "musleabihf" here. LLVM + // uses it to determine the calling convention and float ABI, and it + // doesn't support the "musleabihf" value. + llvm_target: "arm-unknown-linux-gnueabihf".to_string(), + target_endian: "little".to_string(), + target_pointer_width: "32".to_string(), + data_layout: "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), + arch: "arm".to_string(), + target_os: "linux".to_string(), + target_env: "musleabi".to_string(), + target_vendor: "unknown".to_string(), + options: base, + } +} diff --git a/src/librustc_back/target/armv7_unknown_linux_musleabihf.rs b/src/librustc_back/target/armv7_unknown_linux_musleabihf.rs new file mode 100644 index 0000000000000..8732681fb4929 --- /dev/null +++ b/src/librustc_back/target/armv7_unknown_linux_musleabihf.rs @@ -0,0 +1,34 @@ +// Copyright 2016 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. + +use target::Target; + +pub fn target() -> Target { + let mut base = super::musl_base::opts(); + + // Most of these settings are copied from the armv7_unknown_linux_gnueabihf + // target. + base.features = "+v7,+vfp3,+neon".to_string(); + base.cpu = "cortex-a8".to_string(); + Target { + // It's important we use "gnueabihf" and not "musleabihf" here. LLVM + // uses it to determine the calling convention and float ABI, and LLVM + // doesn't support the "musleabihf" value. + llvm_target: "armv7-unknown-linux-gnueabihf".to_string(), + target_endian: "little".to_string(), + target_pointer_width: "32".to_string(), + data_layout: "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), + arch: "arm".to_string(), + target_os: "linux".to_string(), + target_env: "musleabi".to_string(), + target_vendor: "unknown".to_string(), + options: base, + } +} diff --git a/src/librustc_back/target/mod.rs b/src/librustc_back/target/mod.rs index f5314809228b5..694b1340bbbf1 100644 --- a/src/librustc_back/target/mod.rs +++ b/src/librustc_back/target/mod.rs @@ -59,6 +59,7 @@ mod freebsd_base; mod linux_base; mod linux_musl_base; mod openbsd_base; +mod musl_base; mod netbsd_base; mod solaris_base; mod windows_base; @@ -134,7 +135,10 @@ supported_targets! { ("powerpc64le-unknown-linux-gnu", powerpc64le_unknown_linux_gnu), ("arm-unknown-linux-gnueabi", arm_unknown_linux_gnueabi), ("arm-unknown-linux-gnueabihf", arm_unknown_linux_gnueabihf), + ("arm-unknown-linux-musleabi", arm_unknown_linux_musleabi), + ("arm-unknown-linux-musleabihf", arm_unknown_linux_musleabihf), ("armv7-unknown-linux-gnueabihf", armv7_unknown_linux_gnueabihf), + ("armv7-unknown-linux-musleabihf", armv7_unknown_linux_musleabihf), ("aarch64-unknown-linux-gnu", aarch64_unknown_linux_gnu), ("x86_64-unknown-linux-musl", x86_64_unknown_linux_musl), ("i686-unknown-linux-musl", i686_unknown_linux_musl), diff --git a/src/librustc_back/target/musl_base.rs b/src/librustc_back/target/musl_base.rs new file mode 100644 index 0000000000000..77cf015e1d9b3 --- /dev/null +++ b/src/librustc_back/target/musl_base.rs @@ -0,0 +1,72 @@ +// Copyright 2016 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. + +use target::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.push("-nostdlib".to_string()); + base.pre_link_args.push("-static".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.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.push("-Wl,-(".to_string()); + base.post_link_args.push("-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.push("crt1.o".to_string()); + base.pre_link_objects_exe.push("crti.o".to_string()); + base.post_link_objects.push("crtn.o".to_string()); + + // MUSL support doesn't currently include dynamic linking, so there's no + // need for dylibs or rpath business. Additionally `-pie` is incompatible + // with `-static`, so we can't pass `-pie`. + base.dynamic_linking = false; + base.has_rpath = false; + base.position_independent_executables = false; + + return base; +} + diff --git a/src/libstd/rtdeps.rs b/src/libstd/rtdeps.rs index a11200873d500..f23ac32f51c39 100644 --- a/src/libstd/rtdeps.rs +++ b/src/libstd/rtdeps.rs @@ -19,7 +19,9 @@ // // On Linux, librt and libdl are indirect dependencies via std, // and binutils 2.22+ won't add them automatically -#[cfg(all(target_os = "linux", not(target_env = "musl")))] +#[cfg(all(target_os = "linux", not(any(target_env = "musl", + target_env = "musleabi", + target_env = "musleabihf"))))] #[link(name = "dl")] #[link(name = "pthread")] extern {} diff --git a/src/libstd/sys/unix/thread.rs b/src/libstd/sys/unix/thread.rs index 1061ca87f6470..7f05aec4e6ea9 100644 --- a/src/libstd/sys/unix/thread.rs +++ b/src/libstd/sys/unix/thread.rs @@ -171,7 +171,9 @@ impl Drop for Thread { } } -#[cfg(all(not(all(target_os = "linux", not(target_env = "musl"))), +#[cfg(all(not(all(target_os = "linux", not(any(target_env = "musl", + target_env = "musleabi", + target_env = "musleabihf")))), not(target_os = "freebsd"), not(target_os = "macos"), not(target_os = "bitrig"), @@ -185,7 +187,9 @@ pub mod guard { } -#[cfg(any(all(target_os = "linux", not(target_env = "musl")), +#[cfg(any(all(target_os = "linux", not(any(target_env = "musl", + target_env = "musleabi", + target_env = "musleabihf"))), target_os = "freebsd", target_os = "macos", target_os = "bitrig", From 9ffd0fe5a75b8eb640f0bd94385c7b5f675c7e95 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Tue, 26 Jul 2016 16:17:14 -0500 Subject: [PATCH 3/9] arm-musl targets now use cfg(env = "musl") --- .gitmodules | 2 +- src/liballoc_jemalloc/lib.rs | 4 +--- src/liblibc | 2 +- src/librustc_back/target/arm_unknown_linux_musleabi.rs | 2 +- src/librustc_back/target/arm_unknown_linux_musleabihf.rs | 2 +- .../target/armv7_unknown_linux_musleabihf.rs | 2 +- src/libstd/rtdeps.rs | 4 +--- src/libstd/sys/unix/thread.rs | 8 ++------ 8 files changed, 9 insertions(+), 17 deletions(-) diff --git a/.gitmodules b/.gitmodules index 39288a7ae4907..61697a37960eb 100644 --- a/.gitmodules +++ b/.gitmodules @@ -16,4 +16,4 @@ url = https://github.com/rust-lang/rust-installer.git [submodule "src/liblibc"] path = src/liblibc - url = https://github.com/rust-lang/libc.git + url = https://github.com/japaric/libc.git diff --git a/src/liballoc_jemalloc/lib.rs b/src/liballoc_jemalloc/lib.rs index ccf3d978fe434..347e97e6ffc0a 100644 --- a/src/liballoc_jemalloc/lib.rs +++ b/src/liballoc_jemalloc/lib.rs @@ -36,9 +36,7 @@ use libc::{c_int, c_void, size_t}; #[cfg_attr(target_os = "android", link(name = "gcc"))] #[cfg_attr(all(not(windows), not(target_os = "android"), - not(target_env = "musl"), - not(target_env = "musleabi"), - not(target_env = "musleabihf")), + not(target_env = "musl")), link(name = "pthread"))] #[cfg(not(cargobuild))] extern "C" {} diff --git a/src/liblibc b/src/liblibc index b0d62534d48b7..23a5092adcecc 160000 --- a/src/liblibc +++ b/src/liblibc @@ -1 +1 @@ -Subproject commit b0d62534d48b711c8978d1bbe8cca0558ae7b1cb +Subproject commit 23a5092adcecc8c755e7887337e52f357353cad7 diff --git a/src/librustc_back/target/arm_unknown_linux_musleabi.rs b/src/librustc_back/target/arm_unknown_linux_musleabi.rs index 906f60f1c9a18..f2dff16a2842f 100644 --- a/src/librustc_back/target/arm_unknown_linux_musleabi.rs +++ b/src/librustc_back/target/arm_unknown_linux_musleabi.rs @@ -26,7 +26,7 @@ pub fn target() -> Target { data_layout: "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), arch: "arm".to_string(), target_os: "linux".to_string(), - target_env: "musleabi".to_string(), + target_env: "musl".to_string(), target_vendor: "unknown".to_string(), options: base, } diff --git a/src/librustc_back/target/arm_unknown_linux_musleabihf.rs b/src/librustc_back/target/arm_unknown_linux_musleabihf.rs index 3051721b8c21f..89da0213198b7 100644 --- a/src/librustc_back/target/arm_unknown_linux_musleabihf.rs +++ b/src/librustc_back/target/arm_unknown_linux_musleabihf.rs @@ -26,7 +26,7 @@ pub fn target() -> Target { data_layout: "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), arch: "arm".to_string(), target_os: "linux".to_string(), - target_env: "musleabi".to_string(), + target_env: "musl".to_string(), target_vendor: "unknown".to_string(), options: base, } diff --git a/src/librustc_back/target/armv7_unknown_linux_musleabihf.rs b/src/librustc_back/target/armv7_unknown_linux_musleabihf.rs index 8732681fb4929..3b9ac8e21f2e7 100644 --- a/src/librustc_back/target/armv7_unknown_linux_musleabihf.rs +++ b/src/librustc_back/target/armv7_unknown_linux_musleabihf.rs @@ -27,7 +27,7 @@ pub fn target() -> Target { data_layout: "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), arch: "arm".to_string(), target_os: "linux".to_string(), - target_env: "musleabi".to_string(), + target_env: "musl".to_string(), target_vendor: "unknown".to_string(), options: base, } diff --git a/src/libstd/rtdeps.rs b/src/libstd/rtdeps.rs index f23ac32f51c39..c2572dfa5e152 100644 --- a/src/libstd/rtdeps.rs +++ b/src/libstd/rtdeps.rs @@ -19,9 +19,7 @@ // // On Linux, librt and libdl are indirect dependencies via std, // and binutils 2.22+ won't add them automatically -#[cfg(all(target_os = "linux", not(any(target_env = "musl", - target_env = "musleabi", - target_env = "musleabihf"))))] +#[cfg(all(target_os = "linux", not(any(target_env = "musl"))))] #[link(name = "dl")] #[link(name = "pthread")] extern {} diff --git a/src/libstd/sys/unix/thread.rs b/src/libstd/sys/unix/thread.rs index 7f05aec4e6ea9..65ebce0baa28b 100644 --- a/src/libstd/sys/unix/thread.rs +++ b/src/libstd/sys/unix/thread.rs @@ -171,9 +171,7 @@ impl Drop for Thread { } } -#[cfg(all(not(all(target_os = "linux", not(any(target_env = "musl", - target_env = "musleabi", - target_env = "musleabihf")))), +#[cfg(all(not(all(target_os = "linux", not(any(target_env = "musl")))), not(target_os = "freebsd"), not(target_os = "macos"), not(target_os = "bitrig"), @@ -187,9 +185,7 @@ pub mod guard { } -#[cfg(any(all(target_os = "linux", not(any(target_env = "musl", - target_env = "musleabi", - target_env = "musleabihf"))), +#[cfg(any(all(target_os = "linux", not(any(target_env = "musl"))), target_os = "freebsd", target_os = "macos", target_os = "bitrig", From e50bcf340423f1c738c4781cd5c5df4f404a9169 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Tue, 26 Jul 2016 19:27:43 -0500 Subject: [PATCH 4/9] arm-musl: set max_atomic_width --- src/librustc_back/target/arm_unknown_linux_musleabi.rs | 1 + src/librustc_back/target/arm_unknown_linux_musleabihf.rs | 1 + src/librustc_back/target/armv7_unknown_linux_musleabihf.rs | 1 + 3 files changed, 3 insertions(+) diff --git a/src/librustc_back/target/arm_unknown_linux_musleabi.rs b/src/librustc_back/target/arm_unknown_linux_musleabi.rs index f2dff16a2842f..825fc45f2be6f 100644 --- a/src/librustc_back/target/arm_unknown_linux_musleabi.rs +++ b/src/librustc_back/target/arm_unknown_linux_musleabi.rs @@ -16,6 +16,7 @@ pub fn target() -> Target { // Most of these settings are copied from the arm_unknown_linux_gnueabi // target. base.features = "+v6".to_string(); + base.max_atomic_width = 64; Target { // It's important we use "gnueabi" and not "musleabi" here. LLVM uses it // to determine the calling convention and float ABI, and it doesn't diff --git a/src/librustc_back/target/arm_unknown_linux_musleabihf.rs b/src/librustc_back/target/arm_unknown_linux_musleabihf.rs index 89da0213198b7..6694c6a2795b7 100644 --- a/src/librustc_back/target/arm_unknown_linux_musleabihf.rs +++ b/src/librustc_back/target/arm_unknown_linux_musleabihf.rs @@ -16,6 +16,7 @@ pub fn target() -> Target { // Most of these settings are copied from the arm_unknown_linux_gnueabihf // target. base.features = "+v6,+vfp2".to_string(); + base.max_atomic_width = 64; Target { // It's important we use "gnueabihf" and not "musleabihf" here. LLVM // uses it to determine the calling convention and float ABI, and it diff --git a/src/librustc_back/target/armv7_unknown_linux_musleabihf.rs b/src/librustc_back/target/armv7_unknown_linux_musleabihf.rs index 3b9ac8e21f2e7..a7ef70edf4811 100644 --- a/src/librustc_back/target/armv7_unknown_linux_musleabihf.rs +++ b/src/librustc_back/target/armv7_unknown_linux_musleabihf.rs @@ -17,6 +17,7 @@ pub fn target() -> Target { // target. base.features = "+v7,+vfp3,+neon".to_string(); base.cpu = "cortex-a8".to_string(); + base.max_atomic_width = 64; Target { // It's important we use "gnueabihf" and not "musleabihf" here. LLVM // uses it to determine the calling convention and float ABI, and LLVM From f0ec906d186a87b4b4c08b71a82f0e8803a110df Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Tue, 26 Jul 2016 20:09:50 -0500 Subject: [PATCH 5/9] arm-musl: statically link to libunwind --- src/libunwind/build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libunwind/build.rs b/src/libunwind/build.rs index ebe6fd54799ee..fd446f5a4f942 100644 --- a/src/libunwind/build.rs +++ b/src/libunwind/build.rs @@ -16,7 +16,7 @@ fn main() { let target = env::var("TARGET").unwrap(); if target.contains("linux") { - if target.contains("musl") && (target.contains("x86_64") || target.contains("i686")) { + if target.contains("musl") && !target.contains("mips") { println!("cargo:rustc-link-lib=static=unwind"); } else if !target.contains("android") { println!("cargo:rustc-link-lib=gcc_s"); From b38953709d75178db30020c29be0cb4ff2e4be5b Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Tue, 26 Jul 2016 21:30:02 -0500 Subject: [PATCH 6/9] rustc_back/target: remove musl_base it's the same as linux_musl_base --- .../target/arm_unknown_linux_musleabi.rs | 2 +- .../target/arm_unknown_linux_musleabihf.rs | 2 +- .../target/armv7_unknown_linux_musleabihf.rs | 2 +- src/librustc_back/target/mod.rs | 1 - src/librustc_back/target/musl_base.rs | 72 ------------------- 5 files changed, 3 insertions(+), 76 deletions(-) delete mode 100644 src/librustc_back/target/musl_base.rs diff --git a/src/librustc_back/target/arm_unknown_linux_musleabi.rs b/src/librustc_back/target/arm_unknown_linux_musleabi.rs index 825fc45f2be6f..4bc363d0ffda1 100644 --- a/src/librustc_back/target/arm_unknown_linux_musleabi.rs +++ b/src/librustc_back/target/arm_unknown_linux_musleabi.rs @@ -11,7 +11,7 @@ use target::Target; pub fn target() -> Target { - let mut base = super::musl_base::opts(); + let mut base = super::linux_musl_base::opts(); // Most of these settings are copied from the arm_unknown_linux_gnueabi // target. diff --git a/src/librustc_back/target/arm_unknown_linux_musleabihf.rs b/src/librustc_back/target/arm_unknown_linux_musleabihf.rs index 6694c6a2795b7..d96f7443dd9c6 100644 --- a/src/librustc_back/target/arm_unknown_linux_musleabihf.rs +++ b/src/librustc_back/target/arm_unknown_linux_musleabihf.rs @@ -11,7 +11,7 @@ use target::Target; pub fn target() -> Target { - let mut base = super::musl_base::opts(); + let mut base = super::linux_musl_base::opts(); // Most of these settings are copied from the arm_unknown_linux_gnueabihf // target. diff --git a/src/librustc_back/target/armv7_unknown_linux_musleabihf.rs b/src/librustc_back/target/armv7_unknown_linux_musleabihf.rs index a7ef70edf4811..6cb75cbf04cbf 100644 --- a/src/librustc_back/target/armv7_unknown_linux_musleabihf.rs +++ b/src/librustc_back/target/armv7_unknown_linux_musleabihf.rs @@ -11,7 +11,7 @@ use target::Target; pub fn target() -> Target { - let mut base = super::musl_base::opts(); + let mut base = super::linux_musl_base::opts(); // Most of these settings are copied from the armv7_unknown_linux_gnueabihf // target. diff --git a/src/librustc_back/target/mod.rs b/src/librustc_back/target/mod.rs index 694b1340bbbf1..ecfbeaca35172 100644 --- a/src/librustc_back/target/mod.rs +++ b/src/librustc_back/target/mod.rs @@ -59,7 +59,6 @@ mod freebsd_base; mod linux_base; mod linux_musl_base; mod openbsd_base; -mod musl_base; mod netbsd_base; mod solaris_base; mod windows_base; diff --git a/src/librustc_back/target/musl_base.rs b/src/librustc_back/target/musl_base.rs deleted file mode 100644 index 77cf015e1d9b3..0000000000000 --- a/src/librustc_back/target/musl_base.rs +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright 2016 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. - -use target::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.push("-nostdlib".to_string()); - base.pre_link_args.push("-static".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.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.push("-Wl,-(".to_string()); - base.post_link_args.push("-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.push("crt1.o".to_string()); - base.pre_link_objects_exe.push("crti.o".to_string()); - base.post_link_objects.push("crtn.o".to_string()); - - // MUSL support doesn't currently include dynamic linking, so there's no - // need for dylibs or rpath business. Additionally `-pie` is incompatible - // with `-static`, so we can't pass `-pie`. - base.dynamic_linking = false; - base.has_rpath = false; - base.position_independent_executables = false; - - return base; -} - From ea009939904021aaba59f9ca8038b646a65a27d6 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Wed, 27 Jul 2016 11:37:15 -0500 Subject: [PATCH 7/9] remove some `any`s that are no longer necessary --- src/libstd/rtdeps.rs | 2 +- src/libstd/sys/unix/thread.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libstd/rtdeps.rs b/src/libstd/rtdeps.rs index c2572dfa5e152..a11200873d500 100644 --- a/src/libstd/rtdeps.rs +++ b/src/libstd/rtdeps.rs @@ -19,7 +19,7 @@ // // On Linux, librt and libdl are indirect dependencies via std, // and binutils 2.22+ won't add them automatically -#[cfg(all(target_os = "linux", not(any(target_env = "musl"))))] +#[cfg(all(target_os = "linux", not(target_env = "musl")))] #[link(name = "dl")] #[link(name = "pthread")] extern {} diff --git a/src/libstd/sys/unix/thread.rs b/src/libstd/sys/unix/thread.rs index 65ebce0baa28b..1061ca87f6470 100644 --- a/src/libstd/sys/unix/thread.rs +++ b/src/libstd/sys/unix/thread.rs @@ -171,7 +171,7 @@ impl Drop for Thread { } } -#[cfg(all(not(all(target_os = "linux", not(any(target_env = "musl")))), +#[cfg(all(not(all(target_os = "linux", not(target_env = "musl"))), not(target_os = "freebsd"), not(target_os = "macos"), not(target_os = "bitrig"), @@ -185,7 +185,7 @@ pub mod guard { } -#[cfg(any(all(target_os = "linux", not(any(target_env = "musl"))), +#[cfg(any(all(target_os = "linux", not(target_env = "musl")), target_os = "freebsd", target_os = "macos", target_os = "bitrig", From 87fa075dbae4496c94559f4009c58938e7affc4b Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Wed, 27 Jul 2016 11:39:58 -0500 Subject: [PATCH 8/9] point the libc submodule back to rust-lang/libc --- .gitmodules | 2 +- src/liblibc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitmodules b/.gitmodules index 61697a37960eb..39288a7ae4907 100644 --- a/.gitmodules +++ b/.gitmodules @@ -16,4 +16,4 @@ url = https://github.com/rust-lang/rust-installer.git [submodule "src/liblibc"] path = src/liblibc - url = https://github.com/japaric/libc.git + url = https://github.com/rust-lang/libc.git diff --git a/src/liblibc b/src/liblibc index 23a5092adcecc..5066b7dcab7e7 160000 --- a/src/liblibc +++ b/src/liblibc @@ -1 +1 @@ -Subproject commit 23a5092adcecc8c755e7887337e52f357353cad7 +Subproject commit 5066b7dcab7e700844b0e2ba71b8af9dc627a59b From eb6173806d972b839711139ae107dda690febe3a Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sat, 30 Jul 2016 15:44:59 -0500 Subject: [PATCH 9/9] return TargetResult --- src/librustc_back/target/arm_unknown_linux_musleabi.rs | 8 ++++---- src/librustc_back/target/arm_unknown_linux_musleabihf.rs | 8 ++++---- .../target/armv7_unknown_linux_musleabihf.rs | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/librustc_back/target/arm_unknown_linux_musleabi.rs b/src/librustc_back/target/arm_unknown_linux_musleabi.rs index 4bc363d0ffda1..028c91eadaeb3 100644 --- a/src/librustc_back/target/arm_unknown_linux_musleabi.rs +++ b/src/librustc_back/target/arm_unknown_linux_musleabi.rs @@ -8,16 +8,16 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use target::Target; +use target::{Target, TargetResult}; -pub fn target() -> Target { +pub fn target() -> TargetResult { let mut base = super::linux_musl_base::opts(); // Most of these settings are copied from the arm_unknown_linux_gnueabi // target. base.features = "+v6".to_string(); base.max_atomic_width = 64; - Target { + Ok(Target { // It's important we use "gnueabi" and not "musleabi" here. LLVM uses it // to determine the calling convention and float ABI, and it doesn't // support the "musleabi" value. @@ -30,5 +30,5 @@ pub fn target() -> Target { target_env: "musl".to_string(), target_vendor: "unknown".to_string(), options: base, - } + }) } diff --git a/src/librustc_back/target/arm_unknown_linux_musleabihf.rs b/src/librustc_back/target/arm_unknown_linux_musleabihf.rs index d96f7443dd9c6..c7dda186f4258 100644 --- a/src/librustc_back/target/arm_unknown_linux_musleabihf.rs +++ b/src/librustc_back/target/arm_unknown_linux_musleabihf.rs @@ -8,16 +8,16 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use target::Target; +use target::{Target, TargetResult}; -pub fn target() -> Target { +pub fn target() -> TargetResult { let mut base = super::linux_musl_base::opts(); // Most of these settings are copied from the arm_unknown_linux_gnueabihf // target. base.features = "+v6,+vfp2".to_string(); base.max_atomic_width = 64; - Target { + Ok(Target { // It's important we use "gnueabihf" and not "musleabihf" here. LLVM // uses it to determine the calling convention and float ABI, and it // doesn't support the "musleabihf" value. @@ -30,5 +30,5 @@ pub fn target() -> Target { target_env: "musl".to_string(), target_vendor: "unknown".to_string(), options: base, - } + }) } diff --git a/src/librustc_back/target/armv7_unknown_linux_musleabihf.rs b/src/librustc_back/target/armv7_unknown_linux_musleabihf.rs index 6cb75cbf04cbf..e40704e5d4997 100644 --- a/src/librustc_back/target/armv7_unknown_linux_musleabihf.rs +++ b/src/librustc_back/target/armv7_unknown_linux_musleabihf.rs @@ -8,9 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use target::Target; +use target::{Target, TargetResult}; -pub fn target() -> Target { +pub fn target() -> TargetResult { let mut base = super::linux_musl_base::opts(); // Most of these settings are copied from the armv7_unknown_linux_gnueabihf @@ -18,7 +18,7 @@ pub fn target() -> Target { base.features = "+v7,+vfp3,+neon".to_string(); base.cpu = "cortex-a8".to_string(); base.max_atomic_width = 64; - Target { + Ok(Target { // It's important we use "gnueabihf" and not "musleabihf" here. LLVM // uses it to determine the calling convention and float ABI, and LLVM // doesn't support the "musleabihf" value. @@ -31,5 +31,5 @@ pub fn target() -> Target { target_env: "musl".to_string(), target_vendor: "unknown".to_string(), options: base, - } + }) }