diff options
author | Marat Safin <jeizsm@gmail.com> | 2017-10-23 22:18:55 +0300 |
---|---|---|
committer | Jakub Jirutka <jakub@jirutka.cz> | 2017-10-28 13:06:08 +0200 |
commit | eb064c8d0fafe5b638f0fb1f487acfa80c8d777b (patch) | |
tree | 3d80b62246e29dcd1d636569c0fcda95518f3914 /community | |
parent | 0a6875fd87508400ae23cc57e63f51a81fac9214 (diff) | |
download | aports-eb064c8d0fafe5b638f0fb1f487acfa80c8d777b.tar.bz2 aports-eb064c8d0fafe5b638f0fb1f487acfa80c8d777b.tar.xz |
community/rust: upgrade to 1.21
Diffstat (limited to 'community')
-rw-r--r-- | community/rust/APKBUILD | 24 | ||||
-rw-r--r-- | community/rust/alpine-target.patch | 64 | ||||
-rw-r--r-- | community/rust/musl-fix-linux_musl_base.patch | 4 | ||||
-rw-r--r-- | community/rust/musl-fix-static-linking.patch | 146 | ||||
-rw-r--r-- | community/rust/musl-support-dynamic-linking.patch | 336 | ||||
-rw-r--r-- | community/rust/need-rpath.patch | 2 | ||||
-rw-r--r-- | community/rust/static-pie.patch | 19 |
7 files changed, 46 insertions, 549 deletions
diff --git a/community/rust/APKBUILD b/community/rust/APKBUILD index b528cbbb14..eca58eb739 100644 --- a/community/rust/APKBUILD +++ b/community/rust/APKBUILD @@ -3,9 +3,9 @@ # Contributor: Jeizsm <jeizsm@gmail.com> # Maintainer: Jakub Jirutka <jakub@jirutka.cz> pkgname=rust -pkgver=1.20.0 +pkgver=1.21.0 _llvmver=3.9 -_bootver=1.19.0 +_bootver=1.20.0 pkgrel=0 pkgdesc="The Rust Programming Language (compiler)" url="http://www.rust-lang.org" @@ -27,7 +27,6 @@ makedepends="rust>=$_bootver cargo subpackages="$pkgname-dbg $pkgname-stdlib $pkgname-gdb::noarch $pkgname-lldb::noarch $pkgname-doc" source="https://static.rust-lang.org/dist/rustc-$pkgver-src.tar.gz - musl-support-dynamic-linking.patch musl-fix-static-linking.patch musl-fix-linux_musl_base.patch llvm-with-ffi.patch @@ -55,7 +54,7 @@ prepare() { rm -Rf src/llvm/ # Make sure to use the system LLVM. - printf '[target.%s]\nllvm_config = "/usr/lib/llvm%s/bin/llvm-config"\n' \ + printf '[target.%s]\nllvm-config = "/usr/lib/llvm%s/bin/llvm-config"\n' \ "$CTARGET" "$_llvmver" > config.toml } @@ -81,7 +80,7 @@ build() { --disable-docs RUST_BACKTRACE=1 \ - RUST_CRT_STATIC="false" \ + RUSTC_CRT_STATIC="false" \ ./x.py build -v } @@ -101,7 +100,7 @@ package() { cd "$builddir" RUST_BACKTRACE=1 \ - RUST_CRT_STATIC="false" \ + RUSTC_CRT_STATIC="false" \ ./x.py dist -v local component; for component in rustc rust-std; do @@ -166,15 +165,14 @@ _mv() { mv $@ } -sha512sums="bc7dc78f4d81b7d35309d81fae2aac1f5f157eb3350e533911e79e3323a6ea056483ff0b6c63148bd8c3d070df7172374a669fbc4554e77889cfbacb5dbb46c3 rustc-1.20.0-src.tar.gz -e797d4a21ffe5087e6a7c4d22302f0fbd8fdc2074195d7a0d22a8c52a1abe3269e14a3b865f26e13a4f70362922dd0dc5279d8a3d70617199705cc452181d889 musl-support-dynamic-linking.patch -d4d39514eca638852307f470250fd12a21781e1e7944377744b7d50290d3a2ab3776fbdfccb7a9221f5da00ca694ac3a5b8c05f72c5e1a0c8711b684b16b1084 musl-fix-static-linking.patch -9ebfb10abb50d74ff08d257d85257ce70ac3ce834aa95a8901808497b14acf3ea898fb197de64d13554eb5feedabe9fd04fec2cc6a7bea9b1335684bfcdcd88b musl-fix-linux_musl_base.patch +sha512sums="47f29a5c9c926c1b209516a8546c67a24c1c6ee15c6302c8c6d340047b3e1f713cc6d09e568b67ae4b47b08cbb0befd95fc0d7a72f2ce21a5224d4e5da03b4f5 rustc-1.21.0-src.tar.gz +e4675fb78920a31c2c6b0ffdf812b127d3c585557eba904d3aeb690362b06697cbd3cf307bb4bebaec2bfaa1057c5e3738b33437f53db0eae9836ae18d36a880 musl-fix-static-linking.patch +360b0c1b6374cb356989b6f254da2dfc2ab2390c8251f0151492206b908ebf85c6ff57405394b3f46f1fc3e26f7c986bb9e924065f4c4dfa1d50fff2a99b5cd0 musl-fix-linux_musl_base.patch dc6432293bd060d5e3a73f25870867654fae61995dcd919e244a2dc686b6107556deed8c59ca6002182bfeff5ebc1ca2b89c4028ab0fbfb79e65defe47c9b4b0 llvm-with-ffi.patch -5aaf6715b27b8b786740a55b91216d47985fbef3ccb0ef7e6a81696a2823671f8306143f7ecf77e66af91ef1500072524b9b4c7569508922ad5268df6080fda1 static-pie.patch -ff633f2a46c683ad698d1c09c98c06ce9ee9b8d55fa5593cdd485b439ebca3273794d29b5ff32b887be8666f52913a23af6e133c782bd0c4e2c88e306dd3a494 need-rpath.patch +936ddccb357307b3f7f3c10aadcdc3dfbbe0ccb8cc5675969a87b7cf1a8e72f73ed5118c6cd6a1a36a377457ead998cc8c71f4176361acb4416ec16673b4c597 static-pie.patch +b5c8a4faf3571b5c79b052103639ea3b14f094ec0999963602111608afa1159219f958decf0b45dd409124b318f5e17af47b4e74207a9f1c9648a9572dc68cca need-rpath.patch d352614e7c774e181decae210140e789de7fc090327ff371981ad28a11ce51c8c01b27c1101a24bb84d75ed2f706f67868f7dbc52196d4ccdf4ebd2d6d6b6b5e minimize-rpath.patch 498f4649163974afc4f042c43cd0c15d36784031514201a2962061f288a9336c2bc9749f8d2308b8ce3656f8097b5fc5bef505f61e2a6ed422ef4153f5339d77 alpine-move-py-scripts-to-share.patch 0542e8ffeb7ff6017aeec84d99c14802c6536433b41dafe7c8fc0c40908548228f34ef142ad6ad94235115b05f02ce157553b470b0f242292f90f3125b249e94 alpine-change-rpath-to-rustlib.patch -3df3fc5a8d32b47489939e1f2d8277914cea6f3cd5cacf68373d7ab97b2552356f8121e2a134b473bb4715e189ddf03a7bda95cd5f05230bdeb33a5150177d68 alpine-target.patch +509de3e39f5f38ab56a20c37e72f97e326027a59de0f7899eaef2940c56daa6330fba09a8c20d323e34aed42bfcdc977acf9d0239887bbb229a590a598aec08f alpine-target.patch 79549055dea81379c890b495c82456ab497a9179ec6702c59e11d0748bc668f47fc3d6a69c27a0545bb87c01318631dffc69260bf2d4badc75f53cbf7fad7528 check-rustc" diff --git a/community/rust/alpine-target.patch b/community/rust/alpine-target.patch index 90bf453f32..fccbafc07e 100644 --- a/community/rust/alpine-target.patch +++ b/community/rust/alpine-target.patch @@ -94,67 +94,3 @@ and distribution-specific quirks instead of polluting the main musl target of + options: base, + }) +} ---- /dev/null -+++ b/mk/cfg/i586-alpine-linux-musl.mk -@@ -0,0 +1,29 @@ -+# i586-alpine-linux-musl configuration -+CC_i586-alpine-linux-musl=$(CC) -+CXX_i586-alpine-linux-musl=$(CXX) -+CPP_i586-alpine-linux-musl=$(CPP) -+AR_i586-alpine-linux-musl=$(AR) -+CFG_INSTALL_ONLY_RLIB_i586-alpine-linux-musl = 0 -+CFG_LIB_NAME_i586-alpine-linux-musl=lib$(1).so -+CFG_STATIC_LIB_NAME_i586-alpine-linux-musl=lib$(1).a -+CFG_LIB_GLOB_i586-alpine-linux-musl=lib$(1)-*.so -+CFG_JEMALLOC_CFLAGS_i586-alpine-linux-musl := -+CFG_GCCISH_CFLAGS_i586-alpine-linux-musl := -g -fPIC -+CFG_GCCISH_CXXFLAGS_i586-alpine-linux-musl := -+CFG_GCCISH_LINK_FLAGS_i586-alpine-linux-musl := -+CFG_GCCISH_DEF_FLAG_i586-alpine-linux-musl := -+CFG_LLC_FLAGS_i586-alpine-linux-musl := -+CFG_INSTALL_NAME_i586-alpine-linux-musl = -+CFG_EXE_SUFFIX_i586-alpine-linux-musl = -+CFG_WINDOWSY_i586-alpine-linux-musl := -+CFG_UNIXY_i586-alpine-linux-musl := 1 -+CFG_LDPATH_i586-alpine-linux-musl := -+CFG_RUN_i586-alpine-linux-musl=$(2) -+CFG_RUN_TARG_i586-alpine-linux-musl=$(call CFG_RUN_i586-alpine-linux-musl,,$(2)) -+CFG_GNU_TRIPLE_i586-alpine-linux-musl := i586-alpine-linux-musl -+CFG_THIRD_PARTY_OBJECTS_i586-alpine-linux-musl := -+CFG_INSTALLED_OBJECTS_i586-alpine-linux-musl := -+ -+NATIVE_DEPS_libc_T_i586-alpine-linux-musl += libc.a -+NATIVE_DEPS_std_T_i586-alpine-linux-musl += -+NATIVE_DEPS_unwind_T_i586-alpine-linux-musl += libunwind.a ---- /dev/null -+++ b/mk/cfg/x86_64-alpine-linux-musl.mk -@@ -0,0 +1,29 @@ -+# x86_64-alpine-linux-musl configuration -+CC_x86_64-alpine-linux-musl=$(CC) -+CXX_x86_64-alpine-linux-musl=$(CXX) -+CPP_x86_64-alpine-linux-musl=$(CPP) -+AR_x86_64-alpine-linux-musl=$(AR) -+CFG_INSTALL_ONLY_RLIB_x86_64-alpine-linux-musl = 0 -+CFG_LIB_NAME_x86_64-alpine-linux-musl=lib$(1).so -+CFG_STATIC_LIB_NAME_x86_64-alpine-linux-musl=lib$(1).a -+CFG_LIB_GLOB_x86_64-alpine-linux-musl=lib$(1)-*.so -+CFG_JEMALLOC_CFLAGS_x86_64-alpine-linux-musl := -+CFG_GCCISH_CFLAGS_x86_64-alpine-linux-musl := -g -fPIC -+CFG_GCCISH_CXXFLAGS_x86_64-alpine-linux-musl := -+CFG_GCCISH_LINK_FLAGS_x86_64-alpine-linux-musl := -+CFG_GCCISH_DEF_FLAG_x86_64-alpine-linux-musl := -+CFG_LLC_FLAGS_x86_64-alpine-linux-musl := -+CFG_INSTALL_NAME_x86_64-alpine-linux-musl = -+CFG_EXE_SUFFIX_x86_64-alpine-linux-musl = -+CFG_WINDOWSY_x86_64-alpine-linux-musl := -+CFG_UNIXY_x86_64-alpine-linux-musl := 1 -+CFG_LDPATH_x86_64-alpine-linux-musl := -+CFG_RUN_x86_64-alpine-linux-musl=$(2) -+CFG_RUN_TARG_x86_64-alpine-linux-musl=$(call CFG_RUN_x86_64-alpine-linux-musl,,$(2)) -+CFG_GNU_TRIPLE_x86_64-alpine-linux-musl := x86_64-alpine-linux-musl -+CFG_THIRD_PARTY_OBJECTS_x86_64-alpine-linux-musl := -+CFG_INSTALLED_OBJECTS_x86_64-alpine-linux-musl := -+ -+NATIVE_DEPS_libc_T_x86_64-alpine-linux-musl += libc.a -+NATIVE_DEPS_std_T_x86_64-alpine-linux-musl += -+NATIVE_DEPS_unwind_T_x86_64-alpine-linux-musl += libunwind.a diff --git a/community/rust/musl-fix-linux_musl_base.patch b/community/rust/musl-fix-linux_musl_base.patch index f2efb065e0..7b2f26895c 100644 --- a/community/rust/musl-fix-linux_musl_base.patch +++ b/community/rust/musl-fix-linux_musl_base.patch @@ -56,8 +56,10 @@ See https://github.com/rust-lang/rust/pull/40113 - base.pre_link_objects_exe.push("crti.o".to_string()); - base.post_link_objects.push("crtn.o".to_string()); - - // Except for on MIPS, these targets statically link libc by default. + // These targets statically link libc by default base.crt_static_default = true; + // These targets allow the user to choose between static and dynamic linking. + base.crt_static_respected = true; base } diff --git a/community/rust/musl-fix-static-linking.patch b/community/rust/musl-fix-static-linking.patch index 93fe79d15f..1e228a0307 100644 --- a/community/rust/musl-fix-static-linking.patch +++ b/community/rust/musl-fix-static-linking.patch @@ -2,16 +2,7 @@ From: Shiz <hi@shiz.me> Date: Fri, 21 Apr 2017 01:04:46 +0200 Subject: [PATCH] Support fully static linking on *nix targets -This patch adds support for full static linking on *nix targets. - -It adds `Session::fully_static()` to determine whether full static linking -should be utilised. By default, this is the case if the target is not -MSVC-like and the `crt-static` target feature is requested, as for *nix -targets this implies a fully static result. In the future, a target feature -or other compile option could perhaps be added to have the invoker decide -this more flexibly at run-time. - -It also adds the proper linker argument for static result objects to `Linker` +It adds the proper linker argument for static result objects to `Linker` and implements them for `GnuLinker` and `MsvcLinker`. Additionally, when statically linking, all the objects are linked in a group (-Wl,-( and -Wl,-) on GNU-compatible linkers) to resolve dependency and order issues that may @@ -22,61 +13,6 @@ Finally, if no linking preference is given for native libraries (`NativeLibraryKind::NativeUnknown`), they are linked statically if full static linking is requested, instead of dynamically as before. ---- a/src/librustc/session/mod.rs -+++ b/src/librustc/session/mod.rs -@@ -409,6 +409,11 @@ - return crt_static; - } - -+ pub fn fully_static(&self) -> bool { -+ // TODO: figure out better semantics for this, possibly a target option? -+ return self.crt_static() && !self.target.target.options.is_like_msvc -+ } -+ - pub fn must_not_eliminate_frame_pointers(&self) -> bool { - self.opts.debuginfo != DebugInfoLevel::NoDebugInfo || - !self.target.target.options.eliminate_frame_pointer ---- a/src/librustc_trans/back/link.rs -+++ b/src/librustc_trans/back/link.rs -@@ -239,8 +239,8 @@ - /// Checks if target supports crate_type as output - pub fn invalid_output_for_target(sess: &Session, - crate_type: config::CrateType) -> bool { -- match (sess.target.target.options.dynamic_linking, -- sess.target.target.options.executables, crate_type) { -+ let dynamic_linking = sess.target.target.options.dynamic_linking && !sess.fully_static(); -+ match (dynamic_linking, sess.target.target.options.executables, crate_type) { - (false, _, config::CrateTypeCdylib) | - (false, _, config::CrateTypeProcMacro) | - (false, _, config::CrateTypeDylib) => true, -@@ -840,6 +840,10 @@ - - let used_link_args = sess.cstore.used_link_args(); - -+ if crate_type == config::CrateTypeExecutable && sess.fully_static() { -+ cmd.static_executable(); -+ } -+ - if crate_type == config::CrateTypeExecutable && - t.options.position_independent_executables { - let empty_vec = Vec::new(); -@@ -870,15 +870,8 @@ - cmd.no_default_libraries(); - } - -- // Take careful note of the ordering of the arguments we pass to the linker -- // here. Linkers will assume that things on the left depend on things to the -- // right. Things on the right cannot depend on things on the left. This is -- // all formally implemented in terms of resolving symbols (libs on the right -- // resolve unknown symbols of libs on the left, but not vice versa). -+ // We have organized the arguments we pass to the linker as such: - // -- // For this reason, we have organized the arguments we pass to the linker as -- // such: -- // - // 1. The local object that LLVM just generated - // 2. Local native libraries - // 3. Upstream rust libraries --- a/src/librustc_trans/back/link.rs +++ b/src/librustc_trans/back/link.rs @@ -951,17 +951,12 @@ @@ -109,7 +45,7 @@ static linking is requested, instead of dynamically as before. for lib in relevant_libs { match lib.kind { - NativeLibraryKind::NativeUnknown => cmd.link_dylib(&lib.name.as_str()), -+ NativeLibraryKind::NativeUnknown => if sess.fully_static() { cmd.link_staticlib(&lib.name.as_str()) } else { cmd.link_dylib(&lib.name.as_str()) }, ++ NativeLibraryKind::NativeUnknown => if sess.crt_static() { cmd.link_staticlib(&lib.name.as_str()) } else { cmd.link_dylib(&lib.name.as_str()) }, NativeLibraryKind::NativeFramework => cmd.link_framework(&lib.name.as_str()), NativeLibraryKind::NativeStaticNobundle => cmd.link_staticlib(&lib.name.as_str()), NativeLibraryKind::NativeStatic => cmd.link_whole_staticlib(&lib.name.as_str(), @@ -117,17 +53,7 @@ static linking is requested, instead of dynamically as before. } --- a/src/librustc_trans/back/linker.rs +++ b/src/librustc_trans/back/linker.rs -@@ -82,6 +82,7 @@ - fn add_object(&mut self, path: &Path); - fn gc_sections(&mut self, keep_metadata: bool); - fn position_independent_executable(&mut self); -+ fn static_executable(&mut self); - fn optimize(&mut self); - fn debuginfo(&mut self); - fn no_default_libraries(&mut self); -@@ -93,8 +93,10 @@ - fn no_whole_archives(&mut self); - fn export_symbols(&mut self, tmpdir: &Path, crate_type: CrateType); +@@ -116,6 +116,8 @@ pub trait Linker { fn subsystem(&mut self, subsystem: &str); // Should have been finalize(self), but we don't support self-by-value on trait objects (yet?). fn finalize(&mut self) -> Command; @@ -136,75 +62,43 @@ static linking is requested, instead of dynamically as before. } pub struct GccLinker<'a> { -@@ -116,6 +117,9 @@ +@@ -178,6 +180,8 @@ impl<'a> Linker for GccLinker<'a> { fn output_filename(&mut self, path: &Path) { self.cmd.arg("-o").arg(path); } fn add_object(&mut self, path: &Path) { self.cmd.arg(path); } fn position_independent_executable(&mut self) { self.cmd.arg("-pie"); } -+ fn static_executable(&mut self) { self.cmd.arg("-static"); } + fn start_group(&mut self) { self.cmd.arg("-Wl,-("); } + fn end_group(&mut self) { self.cmd.arg("-Wl,-)"); } - fn args(&mut self, args: &[String]) { self.cmd.args(args); } - - fn link_rust_dylib(&mut self, lib: &str, _path: &Path) { -@@ -359,6 +361,10 @@ - - fn position_independent_executable(&mut self) { - // noop -+ } -+ -+ fn static_executable(&mut self) { -+ self.cmd.arg("-MT"); + fn partial_relro(&mut self) { self.linker_arg("-z,relro"); } + fn full_relro(&mut self) { self.linker_arg("-z,relro,-z,now"); } + fn build_static_executable(&mut self) { self.cmd.arg("-static"); } +@@ -577,6 +581,15 @@ impl<'a> Linker for MsvcLinker<'a> { + } } - fn no_default_libraries(&mut self) { -@@ -484,6 +488,14 @@ - if subsystem == "windows" { - self.cmd.arg("/ENTRY:mainCRTStartup"); - } -+ } + + fn start_group(&mut self) { + // Not needed + } -+ ++ + fn end_group(&mut self) { + // Not needed - } - } - -@@ -562,6 +562,10 @@ - // noop - } - -+ fn static_executable(&mut self) { -+ // noop + } + - fn args(&mut self, args: &[String]) { - self.cmd.args(args); + fn finalize(&mut self) -> Command { + let mut cmd = Command::new(""); + ::std::mem::swap(&mut cmd, &mut self.cmd); +@@ -727,6 +740,14 @@ impl<'a> Linker for EmLinker<'a> { + // noop } -@@ -657,6 +661,14 @@ - fn subsystem(&mut self, _subsystem: &str) { - // noop -+ } -+ + fn start_group(&mut self) { + self.cmd.arg("-Wl,-("); + } + + fn end_group(&mut self) { + self.cmd.arg("-Wl,-)"); - } - } - ---- a/src/librustc_trans/back/linker.rs -+++ b/src/librustc_trans/back/linker.rs -@@ -158,6 +158,7 @@ impl<'a> GccLinker<'a> { - } - - fn hint_dynamic(&mut self) { -+ if self.sess.fully_static() { return } - if !self.takes_hints() { return } - if self.hinted_static { - self.linker_arg("-Bdynamic"); ++ } ++ + fn finalize(&mut self) -> Command { + let mut cmd = Command::new(""); + ::std::mem::swap(&mut cmd, &mut self.cmd); diff --git a/community/rust/musl-support-dynamic-linking.patch b/community/rust/musl-support-dynamic-linking.patch deleted file mode 100644 index c6441272bb..0000000000 --- a/community/rust/musl-support-dynamic-linking.patch +++ /dev/null @@ -1,336 +0,0 @@ -From 3abd1f5e2f31b1c95535ef8c3b4bef6ff78b3fa9 Mon Sep 17 00:00:00 2001 -From: Samuel Holland <samuel@sholland.org> -From: Shiz <hi@shiz.me> -Date: Wed, 12 Apr 2017 22:31:06 +0200 -Subject: [PATCH] Support dynamically-linked and/or native musl targets - -These changes allow native compilation on musl-based distributions and the -use of dynamic libraries on linux-musl targets. This is intended to remove -limitations based on past assumptions about musl targets, while -maintaining existing behavior by default. - -Upstream-Issue: https://github.com/rust-lang/rust/pull/40113 -See-Also: https://internals.rust-lang.org/t/refining-cross-platform-crt-static-semantics/5085 - -diff --git a/src/bootstrap/bin/rustc.rs b/src/bootstrap/bin/rustc.rs -index 90fd31ecbd..28520a2c60 100644 ---- a/src/bootstrap/bin/rustc.rs -+++ b/src/bootstrap/bin/rustc.rs -@@ -205,6 +205,15 @@ fn main() { - } - } - } -+ -+ if let Ok(s) = env::var("RUST_CRT_STATIC") { -+ if s == "true" { -+ cmd.arg("-C").arg("target-feature=+crt-static"); -+ } -+ if s == "false" { -+ cmd.arg("-C").arg("target-feature=-crt-static"); -+ } -+ } - } - - if verbose > 1 { -diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs -index 7c35151a6d..c83b6cc24c 100644 ---- a/src/bootstrap/compile.rs -+++ b/src/bootstrap/compile.rs -@@ -94,21 +94,24 @@ pub fn std_link(build: &Build, - let libdir = build.sysroot_libdir(target_compiler, target); - add_to_sysroot(&libdir, &libstd_stamp(build, compiler, target)); - -- if target.contains("musl") && !target.contains("mips") { -+ if target.contains("musl") { - copy_musl_third_party_objects(build, target, &libdir); - } - - if build.config.sanitizers && compiler.stage != 0 && target == "x86_64-apple-darwin" { - // The sanitizers are only built in stage1 or above, so the dylibs will - // be missing in stage0 and causes panic. See the `std()` function above - // for reason why the sanitizers are not built in stage0. - copy_apple_sanitizer_dylibs(&build.native_dir(target), "osx", &libdir); - } - } - - /// Copies the crt(1,i,n).o startup objects - /// --/// Only required for musl targets that statically link to libc -+/// 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(build: &Build, target: &str, into: &Path) { - for &obj in &["crt1.o", "crti.o", "crtn.o"] { - copy(&build.musl_root(target).unwrap().join("lib").join(obj), &into.join(obj)); -diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs -index 6e077691b3..8d9be38959 100644 ---- a/src/bootstrap/config.rs -+++ b/src/bootstrap/config.rs -@@ -113,6 +113,7 @@ pub struct Target { - pub cc: Option<PathBuf>, - pub cxx: Option<PathBuf>, - pub ndk: Option<PathBuf>, -+ pub crt_static: Option<bool>, - pub musl_root: Option<PathBuf>, - } - -@@ -221,6 +222,7 @@ struct TomlTarget { - cc: Option<String>, - cxx: Option<String>, - android_ndk: Option<String>, -+ crt_static: Option<bool>, - musl_root: Option<String>, - } - -@@ -359,6 +361,7 @@ impl Config { - } - target.cxx = cfg.cxx.clone().map(PathBuf::from); - target.cc = cfg.cc.clone().map(PathBuf::from); -+ target.crt_static = cfg.crt_static.clone(); - target.musl_root = cfg.musl_root.clone().map(PathBuf::from); - - config.target_config.insert(triple.clone(), target); -diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs -index c98dd4751f..e7ee9511d8 100644 ---- a/src/bootstrap/lib.rs -+++ b/src/bootstrap/lib.rs -@@ -500,6 +500,10 @@ impl Build { - .env("RUSTDOC_REAL", self.rustdoc(compiler)) - .env("RUSTC_FLAGS", self.rustc_flags(target).join(" ")); - -+ if let Some(x) = self.crt_static(target) { -+ cargo.env("RUST_CRT_STATIC", x.to_string()); -+ } -+ - // Enable usage of unstable features - cargo.env("RUSTC_BOOTSTRAP", "1"); - self.add_rust_test_threads(&mut cargo); -@@ -883,6 +887,16 @@ impl Build { - return base - } - -+ /// Returns if this target should statically link the C runtime, if specified -+ fn crt_static(&self, target: &str) -> Option<bool> { -+ if target.contains("pc-windows-msvc") { -+ Some(true) -+ } else { -+ self.config.target_config.get(target) -+ .and_then(|t| t.crt_static) -+ } -+ } -+ - /// Returns the "musl root" for this `target`, if defined - fn musl_root(&self, target: &str) -> Option<&Path> { - self.config.target_config.get(target) -diff --git a/src/bootstrap/sanity.rs b/src/bootstrap/sanity.rs -index bc439d6f78..3ee1113516 100644 ---- a/src/bootstrap/sanity.rs -+++ b/src/bootstrap/sanity.rs -@@ -157,8 +157,15 @@ pub fn check(build: &mut Build) { - panic!("the iOS target is only supported on OSX"); - } - -- // Make sure musl-root is valid if specified -- if target.contains("musl") && !target.contains("mips") { -+ // 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() { -diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs -index 36a887e062..1075e4f0cf 100644 ---- a/src/librustc/session/mod.rs -+++ b/src/librustc/session/mod.rs -@@ -380,6 +381,24 @@ impl Session { - self.opts.debugging_opts.enable_nonzeroing_move_hints - } - -+ pub fn crt_static(&self) -> bool { -+ let requested_features = self.opts.cg.target_feature.split(','); -+ let found_negative = requested_features.clone().any(|r| r == "-crt-static"); -+ let found_positive = requested_features.clone().any(|r| r == "+crt-static"); -+ -+ // If the target we're compiling for requests a static crt by default, -+ // then see if the `-crt-static` feature was passed to disable that. -+ // Otherwise if we don't have a static crt by default then see if the -+ // `+crt-static` feature was passed. -+ let crt_static = if self.target.target.options.crt_static_default { -+ !found_negative -+ } else { -+ found_positive -+ }; -+ -+ return crt_static; -+ } -+ - pub fn must_not_eliminate_frame_pointers(&self) -> bool { - self.opts.debuginfo != DebugInfoLevel::NoDebugInfo || - !self.target.target.options.eliminate_frame_pointer -diff --git a/src/librustc_back/target/linux_musl_base.rs b/src/librustc_back/target/linux_musl_base.rs -index 18cca425a3..076bbe7193 100644 ---- a/src/librustc_back/target/linux_musl_base.rs -+++ b/src/librustc_back/target/linux_musl_base.rs -@@ -59,14 +59,7 @@ pub fn opts() -> TargetOptions { - 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; -- -- // These targets statically link libc by default -+ // Except for on MIPS, these targets statically link libc by default. - base.crt_static_default = true; - - base -diff --git a/src/librustc_back/target/mips_unknown_linux_musl.rs b/src/librustc_back/target/mips_unknown_linux_musl.rs -index e4a6d2a55d..77fcf9770d 100644 ---- a/src/librustc_back/target/mips_unknown_linux_musl.rs -+++ b/src/librustc_back/target/mips_unknown_linux_musl.rs -@@ -25,6 +25,7 @@ pub fn target() -> TargetResult { - features: "+mips32r2,+soft-float".to_string(), - max_atomic_width: Some(32), - -+ crt_static_default: false, - // see #36994 - exe_allocation_crate: "alloc_system".to_string(), - -diff --git a/src/librustc_back/target/mipsel_unknown_linux_musl.rs b/src/librustc_back/target/mipsel_unknown_linux_musl.rs -index 5693bddd04..6339e719e1 100644 ---- a/src/librustc_back/target/mipsel_unknown_linux_musl.rs -+++ b/src/librustc_back/target/mipsel_unknown_linux_musl.rs -@@ -25,6 +25,7 @@ pub fn target() -> TargetResult { - features: "+mips32,+soft-float".to_string(), - max_atomic_width: Some(32), - -+ crt_static_default: false, - // see #36994 - exe_allocation_crate: "alloc_system".to_string(), - -diff --git a/src/librustc_driver/target_features.rs b/src/librustc_driver/target_features.rs -index 124e7aafcc..492ceecaf1 100644 ---- a/src/librustc_driver/target_features.rs -+++ b/src/librustc_driver/target_features.rs -@@ -25,21 +25,7 @@ pub fn add_configuration(cfg: &mut ast::CrateConfig, sess: &Session) { - cfg.insert((tf, Some(feat))); - } - -- let requested_features = sess.opts.cg.target_feature.split(','); -- let found_negative = requested_features.clone().any(|r| r == "-crt-static"); -- let found_positive = requested_features.clone().any(|r| r == "+crt-static"); -- -- // If the target we're compiling for requests a static crt by default, -- // then see if the `-crt-static` feature was passed to disable that. -- // Otherwise if we don't have a static crt by default then see if the -- // `+crt-static` feature was passed. -- let crt_static = if sess.target.target.options.crt_static_default { -- !found_negative -- } else { -- found_positive -- }; -- -- if crt_static { -+ if sess.crt_static() { - cfg.insert((tf, Some(Symbol::intern("crt-static")))); - } - } -diff --git a/src/librustc_trans/back/link.rs b/src/librustc_trans/back/link.rs -index defbb44448..f10c7d5c83 100644 ---- a/src/librustc_trans/back/link.rs -+++ b/src/librustc_trans/back/link.rs -@@ -703,13 +703,15 @@ fn link_natively(sess: &Session, - let root = sess.target_filesearch(PathKind::Native).get_lib_path(); - cmd.args(&sess.target.target.options.pre_link_args); - -- let pre_link_objects = if crate_type == config::CrateTypeExecutable { -- &sess.target.target.options.pre_link_objects_exe -- } else { -- &sess.target.target.options.pre_link_objects_dll -- }; -- for obj in pre_link_objects { -- cmd.arg(root.join(obj)); -+ if sess.crt_static() { -+ let pre_link_objects = if crate_type == config::CrateTypeExecutable { -+ &sess.target.target.options.pre_link_objects_exe -+ } else { -+ &sess.target.target.options.pre_link_objects_dll -+ }; -+ for obj in pre_link_objects { -+ cmd.arg(root.join(obj)); -+ } - } - - { -@@ -718,12 +720,14 @@ fn link_natively(sess: &Session, - cmd = linker.finalize(); - } - if let Some(args) = sess.target.target.options.late_link_args.get(&flavor) { - cmd.args(args); - } -- for obj in &sess.target.target.options.post_link_objects { -- cmd.arg(root.join(obj)); -+ if sess.crt_static() { -+ for obj in &sess.target.target.options.post_link_objects { -+ cmd.arg(root.join(obj)); -+ } - } - if let Some(args) = sess.target.target.options.post_link_args.get(&flavor) { - cmd.args(args); - } - -diff --git a/src/libstd/build.rs b/src/libstd/build.rs -index 9504194393..dd2008c206 100644 ---- a/src/libstd/build.rs -+++ b/src/libstd/build.rs -@@ -35,7 +35,7 @@ fn main() { - println!("cargo:rustc-link-lib=dl"); - println!("cargo:rustc-link-lib=log"); - println!("cargo:rustc-link-lib=gcc"); -- } else if !target.contains("musl") || target.contains("mips") { -+ } else if !target.contains("musl") { - println!("cargo:rustc-link-lib=dl"); - println!("cargo:rustc-link-lib=rt"); - println!("cargo:rustc-link-lib=pthread"); -diff --git a/src/libunwind/build.rs b/src/libunwind/build.rs -index db41a368a1..b1a86f04ef 100644 ---- a/src/libunwind/build.rs -+++ b/src/libunwind/build.rs -@@ -16,8 +16,8 @@ fn main() { - let target = env::var("TARGET").expect("TARGET was not set"); - - if target.contains("linux") { -- if target.contains("musl") && !target.contains("mips") { -- println!("cargo:rustc-link-lib=static=unwind"); -+ if target.contains("musl") { -+ println!("cargo:rustc-link-lib=unwind"); - } else if !target.contains("android") { - println!("cargo:rustc-link-lib=gcc_s"); - } -diff --git a/src/liblibc/src/unix/mod.rs b/src/liblibc/src/unix/mod.rs ---- a/src/liblibc/src/unix/mod.rs -+++ b/src/liblibc/src/unix/mod.rs -@@ -210,8 +210,7 @@ cfg_if! { - // cargo build, don't pull in anything extra as the libstd dep - // already pulls in all libs. -- } else if #[cfg(any(all(target_env = "musl", not(target_arch = "mips"))))] { -+ } else if #[cfg(target_env = "musl")] { -- #[link(name = "c", kind = "static", cfg(target_feature = "crt-static"))] -- #[link(name = "c", cfg(not(target_feature = "crt-static")))] -+ #[link(name = "c")] - extern {} - } else if #[cfg(target_os = "emscripten")] { - #[link(name = "c")] --- -2.12.2 - diff --git a/community/rust/need-rpath.patch b/community/rust/need-rpath.patch index b345d27d92..88cc9d8882 100644 --- a/community/rust/need-rpath.patch +++ b/community/rust/need-rpath.patch @@ -55,7 +55,7 @@ Hacky hacky! - if sess.opts.cg.rpath { + // XXX: hacky hacky + let bootstrap = env::var("RUSTC_BOOTSTRAP").is_ok(); -+ if !bootstrap && !sess.fully_static() && ++ if !bootstrap && !sess.crt_static() && + (sess.opts.cg.rpath || sess.target.target.options.need_rpath) { let sysroot = sess.sysroot(); let target_triple = &sess.opts.target_triple; diff --git a/community/rust/static-pie.patch b/community/rust/static-pie.patch index 4c4e4b77c1..daee42f286 100644 --- a/community/rust/static-pie.patch +++ b/community/rust/static-pie.patch @@ -59,14 +59,15 @@ library, just like static binaries, but more secure. pub position_independent_executables: bool, + /// As above, but also support for static position independent executables. + pub static_position_independent_executables: bool, - /// Format that archives should be emitted in. This affects whether we use - /// LLVM to assemble an archive or fall back to the system linker, and - /// currently only "gnu" is used to fall into LLVM. Unknown strings cause -@@ -434,6 +436,7 @@ + /// Either partial, full, or off. Full RELRO makes the dynamic linker + /// resolve all symbols at startup and marks the GOT read-only before + /// starting the program, preventing overwriting the GOT. +@@ -434,7 +436,8 @@ has_rpath: false, no_default_libraries: true, position_independent_executables: false, + static_position_independent_executables: false, + relro_level: RelroLevel::Off, pre_link_objects_exe: Vec::new(), pre_link_objects_dll: Vec::new(), post_link_objects: Vec::new(), @@ -83,26 +84,28 @@ library, just like static binaries, but more secure. - + let static_pie = t.options.static_position_independent_executables; if get_reloc_model(sess) == llvm::RelocMode::PIC -- && !args.any(|x| *x == "-static") { -+ && (!sess.fully_static() || static_pie) { +- && !sess.crt_static() && !args.any(|x| *x == "-static") { ++ && (!sess.crt_static() || static_pie) { cmd.position_independent_executable(); } } --- a/src/librustc_back/target/mod.rs +++ b/src/librustc_back/target/mod.rs -@@ -612,6 +612,7 @@ +@@ -612,7 +612,8 @@ key!(has_rpath, bool); key!(no_default_libraries, bool); key!(position_independent_executables, bool); + key!(static_position_independent_executables, bool); + try!(key!(relro_level, RelroLevel)); key!(archive_format); key!(allow_asm, bool); key!(custom_unwind_resume, bool); -@@ -776,6 +777,7 @@ +@@ -776,7 +777,8 @@ target_option_val!(has_rpath); target_option_val!(no_default_libraries); target_option_val!(position_independent_executables); + target_option_val!(static_position_independent_executables); + target_option_val!(relro_level); target_option_val!(archive_format); target_option_val!(allow_asm); target_option_val!(custom_unwind_resume); |