From 0b7fc0653bfd19f650a2fbad987b2fe03715e6b4 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 6 Mar 2016 08:19:51 -0500 Subject: [PATCH 1/2] rustbuild: fix cross compilation of libstd to i686-unknown-linux-musl - make sure we copy the third party objects (crt*.o) to the target stage directory. - apply the x86_64-musl logic also to the i686-musl target. --- src/bootstrap/build/compile.rs | 13 +++++++++++++ src/bootstrap/build/sanity.rs | 2 +- src/liballoc_jemalloc/build.rs | 2 +- src/libstd/build.rs | 2 +- src/libstd/sys/common/libunwind.rs | 10 ++++++++-- 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/bootstrap/build/compile.rs b/src/bootstrap/build/compile.rs index 3be4199352c..fb0a840bfa2 100644 --- a/src/bootstrap/build/compile.rs +++ b/src/bootstrap/build/compile.rs @@ -83,6 +83,19 @@ pub fn std_link(build: &Build, libdir.join(staticlib("compiler-rt", target)))); } add_to_sysroot(&out_dir, &libdir); + + if target.contains("musl") && (target.contains("x86_64") || target.contains("i686")) { + copy_third_party_objects(build, target, &libdir); + } +} + +/// Copies the crt(1,i,n).o startup objects +/// +/// Only required for musl targets that statically link to libc +fn copy_third_party_objects(build: &Build, target: &str, into: &Path) { + for &obj in &["crt1.o", "crti.o", "crtn.o"] { + t!(fs::copy(compiler_file(build.cc(target), obj), into.join(obj))); + } } /// Build and prepare startup objects like rsbegin.o and rsend.o diff --git a/src/bootstrap/build/sanity.rs b/src/bootstrap/build/sanity.rs index 6ac581a7c69..be4416c697c 100644 --- a/src/bootstrap/build/sanity.rs +++ b/src/bootstrap/build/sanity.rs @@ -79,7 +79,7 @@ pub fn check(build: &mut Build) { } // Make sure musl-root is valid if specified - if target.contains("musl") && target.contains("x86_64") { + if target.contains("musl") && (target.contains("x86_64") || target.contains("i686")) { 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 c9508322a31..9e2090c3246 100644 --- a/src/liballoc_jemalloc/build.rs +++ b/src/liballoc_jemalloc/build.rs @@ -111,7 +111,7 @@ fn main() { 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") { + } else if !target.contains("windows") && !target.contains("musl") { println!("cargo:rustc-link-lib=pthread"); } } diff --git a/src/libstd/build.rs b/src/libstd/build.rs index c60ec4d3655..1c8375479ca 100644 --- a/src/libstd/build.rs +++ b/src/libstd/build.rs @@ -28,7 +28,7 @@ fn main() { } if target.contains("unknown-linux") { - if target.contains("musl") && target.contains("x86_64") { + if target.contains("musl") && (target.contains("x86_64") || target.contains("i686")) { println!("cargo:rustc-link-lib=static=unwind"); } else { println!("cargo:rustc-link-lib=dl"); diff --git a/src/libstd/sys/common/libunwind.rs b/src/libstd/sys/common/libunwind.rs index 3f70afe6ad7..c1e9782852a 100644 --- a/src/libstd/sys/common/libunwind.rs +++ b/src/libstd/sys/common/libunwind.rs @@ -106,9 +106,15 @@ pub type _Unwind_Exception_Cleanup_Fn = #[cfg_attr(any(all(target_os = "linux", not(target_env = "musl")), target_os = "freebsd", target_os = "solaris", - all(target_os = "linux", target_env = "musl", not(target_arch = "x86_64"))), + all(target_os = "linux", + target_env = "musl", + not(target_arch = "x86"), + not(target_arch = "x86_64"))), link(name = "gcc_s"))] -#[cfg_attr(all(target_os = "linux", target_env = "musl", target_arch = "x86_64", not(test)), +#[cfg_attr(all(target_os = "linux", + target_env = "musl", + any(target_arch = "x86", target_arch = "x86_64"), + not(test)), link(name = "unwind", kind = "static"))] #[cfg_attr(any(target_os = "android", target_os = "openbsd"), link(name = "gcc"))] From f164433a11bda8b61276f501983462d5dac743aa Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 6 Mar 2016 15:34:20 -0500 Subject: [PATCH 2/2] update the src/liblibc submodule --- src/liblibc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/liblibc b/src/liblibc index 07a92067930..e19309c8b4e 160000 --- a/src/liblibc +++ b/src/liblibc @@ -1 +1 @@ -Subproject commit 07a92067930670473dc53300dfdda23ff486344d +Subproject commit e19309c8b4e8bbd11f4d84dfffd75e3d1ac477fe