aboutsummaryrefslogtreecommitdiffstats
path: root/testing/rust
diff options
context:
space:
mode:
authorShiz <hi@shiz.me>2017-04-16 15:56:18 +0000
committerJakub Jirutka <jakub@jirutka.cz>2017-04-21 01:44:33 +0200
commit3db351aa5647eb4a482e9e008bedcf1a5be51302 (patch)
treefe64ea58b55936fc2da3f78eaa48c1703ec6bcf6 /testing/rust
parente4cc4b79b548e043d635ff35c3e9f2e832be1202 (diff)
downloadaports-3db351aa5647eb4a482e9e008bedcf1a5be51302.tar.bz2
aports-3db351aa5647eb4a482e9e008bedcf1a5be51302.tar.xz
testing/rust: reorganize patches
This divides up the patches in three logical categories: - musl-*.patch: musl support patches intended for upstreaming; - alpine-*.patch: Alpine-specific patches that are likely not upstreamable; - *.patch: functionality patch that may make it upstream.
Diffstat (limited to 'testing/rust')
-rw-r--r--testing/rust/APKBUILD42
-rw-r--r--testing/rust/alpine-allow-crt-static.patch (renamed from testing/rust/allow-crt-static-on-stable.patch)0
-rw-r--r--testing/rust/alpine-change-rpath-to-rustlib.patch (renamed from testing/rust/change-rpath-to-rustlib.patch)0
-rw-r--r--testing/rust/alpine-dont-require-filecheck.patch (renamed from testing/rust/dont-require-filecheck.patch)0
-rw-r--r--testing/rust/alpine-force-rpath-on-prefer-dynamic.patch (renamed from testing/rust/force-rpath-on-prefer-dynamic.patch)0
-rw-r--r--testing/rust/alpine-move-py-scripts-to-share.patch (renamed from testing/rust/move-py-scripts-to-share.patch)2
-rw-r--r--testing/rust/alpine-musl-dynamic-linking-by-default.patch (renamed from testing/rust/musl-dynamic-linking-by-default.patch)0
-rw-r--r--testing/rust/llvm-with-ffi.patch2
-rw-r--r--testing/rust/musl-fix-jemalloc.patch (renamed from testing/rust/fix-jemalloc-musl.patch)4
-rw-r--r--testing/rust/musl-fix-linux_musl_base.patch (renamed from testing/rust/fix-linux_musl_base.patch)0
-rw-r--r--testing/rust/musl-fix-static-linking.patch134
-rw-r--r--testing/rust/musl-support-dynamic-linking.patch (renamed from testing/rust/support-dynamically-linked-musl.patch)0
-rw-r--r--testing/rust/static-pie.patch149
13 files changed, 161 insertions, 172 deletions
diff --git a/testing/rust/APKBUILD b/testing/rust/APKBUILD
index 3dc03e7aba..537dd2f7bf 100644
--- a/testing/rust/APKBUILD
+++ b/testing/rust/APKBUILD
@@ -28,17 +28,18 @@ source="https://static.rust-lang.org/dist/rustc-$pkgver-src.tar.gz
https://repo.voidlinux.eu/distfiles/rustc-$pkgver-x86_64-unknown-linux-musl.tar.gz
https://repo.voidlinux.eu/distfiles/rust-std-$pkgver-x86_64-unknown-linux-musl.tar.gz
cargo-$_cargo_gitrev-x86_64-unknown-linux-musl.tar.gz::https://s3.amazonaws.com/rust-lang-ci/cargo-builds/$_cargo_gitrev/cargo-nightly-x86_64-unknown-linux-musl.tar.gz
- dont-require-filecheck.patch
- support-dynamically-linked-musl.patch
- allow-crt-static-on-stable.patch
+ musl-support-dynamic-linking.patch
+ musl-fix-static-linking.patch
+ musl-fix-linux_musl_base.patch
+ musl-fix-jemalloc.patch
static-pie.patch
- fix-linux_musl_base.patch
- musl-dynamic-linking-by-default.patch
llvm-with-ffi.patch
- move-py-scripts-to-share.patch
- change-rpath-to-rustlib.patch
- force-rpath-on-prefer-dynamic.patch
- fix-jemalloc-musl.patch
+ alpine-musl-dynamic-linking-by-default.patch
+ alpine-allow-crt-static.patch
+ alpine-dont-require-filecheck.patch
+ alpine-move-py-scripts-to-share.patch
+ alpine-change-rpath-to-rustlib.patch
+ alpine-force-rpath-on-prefer-dynamic.patch
check-rustc
"
builddir="$srcdir/rustc-$pkgver-src"
@@ -184,15 +185,16 @@ sha512sums="096b1b7406be9bc61161bb7cdd2061f2bc2174c161a31f4ed6ceecf7fc379f315fc2
e9b10d58ae5b51b09dd31a1dbf7367917bd40a05ecb4ba3e0e7ac229a0352d3ceb77de80f7c0120f553bd7904644da6bf973dbc32850b12dc91f3974846d4164 rustc-1.16.0-x86_64-unknown-linux-musl.tar.gz
54467213b2824112dec6d5a132ab01d69617a5ccaa9db15e5c8fad55dea5eb31b1b7c9ca07878901d75edd45dc84c726913bf651f3435c480a79703c074b5d90 rust-std-1.16.0-x86_64-unknown-linux-musl.tar.gz
4df33353b6be1af822220ca03f9ec5a3b6421c9b10ec17b864be586ba495c6210bac70d904b0e0b35eff62ef2c9a681ded526e5cbd37e326dc3146742aa659de cargo-6e0c18cccc8b0c06fba8a8d76486f81a792fb420-x86_64-unknown-linux-musl.tar.gz
-2002faf08cca3be702f25618bc17453c5e76644a6ff6b0739b642c2c0f8536ec7f09c98182aff6b2dcc87c77b0929f2f8f732b8242a8f80d94b3824c8cd0d0fe dont-require-filecheck.patch
-b0a8883e4469b60edd150c84486ab950396d757220f97bd271529576614c6c3b49456098507503832c20619d4bd74246dbc99c78116634a68a6df994793e9a94 support-dynamically-linked-musl.patch
-b00997c65d1a451fafae8b547893c5cbf03f028d2d70f6971aa670f34c2d6fc82728c740ac4a9909fc1999925ff300e4525cfec745cb9c9521e564eb166872a2 allow-crt-static-on-stable.patch
-81fe34aa8e2edacacef63c6a0105da05205b86ae76535f8f9359607f10f6de96c48dc8e160cc8f96dc4a4291f1172290cb11ea5993eba023eb393d8fad6fe0c7 static-pie.patch
-f436fddf7ab70ca5f1424081f5b75450270b200b3d997231323863e11addf76e1d65831a7ca09e3a5b7904ce828766c1f70b08326a175890298f28e5bc8646ef fix-linux_musl_base.patch
-44f3104f506531778fede64034ff5b86f782744d7fed26b393cd88590c22b7fd1df441e2c14bb44c660c54140a4093686aa35f53357f9cd795af6cfa6df1cec4 musl-dynamic-linking-by-default.patch
-37416e1fa0bc0c8651cd060a645d6245ff7e2082279ab5e13495c5ee412c71915469019cfbec95a0fd9a7fc144475079a3ad16f0eba7a2f5c8dd99e0002f3225 llvm-with-ffi.patch
-19cc2725d68db3e359e0e3016028374e5818a97fdba24d0103f7d1706601c8b17c4dd95a3152e64f982f98e95ad3e949acddbea8a39ed0ba8dd4f702acc2704d move-py-scripts-to-share.patch
-8d6206f8c50856724cf7b4c1854ec82547f040358a1c7d44abeacc27a5c205a963b1fec51e58ec06c68d85bd2f68a9e6e27ebe457f39e8dd043de17758f5063f change-rpath-to-rustlib.patch
-f230239d8de1b69536353e5735d3bf32f42a2715aefe4863622d9ab2b25d010209ed0bb38976eaa9302bce2eca6bd162abc8cefd71f689b65b3800920a50967b force-rpath-on-prefer-dynamic.patch
-a330fa913faeadb98cb95e644f434ddef4fbbea32bcd11b6621fb9e08f7b0d8c71fae702207465489af3cf793eade0af694a8c515fc1bed49624da25103a4862 fix-jemalloc-musl.patch
+b0a8883e4469b60edd150c84486ab950396d757220f97bd271529576614c6c3b49456098507503832c20619d4bd74246dbc99c78116634a68a6df994793e9a94 musl-support-dynamic-linking.patch
+7365da739aa03f8b8b3421311b0d4807a2481d38ed259d92f09dd65c831e3e1d25002c012e1c43363fa53462e240b29217e7d429dfa9ae33390e4f7c7cca6227 musl-fix-static-linking.patch
+f436fddf7ab70ca5f1424081f5b75450270b200b3d997231323863e11addf76e1d65831a7ca09e3a5b7904ce828766c1f70b08326a175890298f28e5bc8646ef musl-fix-linux_musl_base.patch
+c913d04ef419b2b6d8e453f72894070f263c9292abf97114a51884d475d03ce5b032053f1676ba9364800b4b35e394f707995058530ad5e4122c60f65ddd3db7 musl-fix-jemalloc.patch
+636eb3e1646c362851dccc850a13aa0911df74981a324738be32b333dfb8782da4ad98d164a34564d66983effaeb5b0b447057d0c974563110fa29df6384a023 static-pie.patch
+dc6432293bd060d5e3a73f25870867654fae61995dcd919e244a2dc686b6107556deed8c59ca6002182bfeff5ebc1ca2b89c4028ab0fbfb79e65defe47c9b4b0 llvm-with-ffi.patch
+44f3104f506531778fede64034ff5b86f782744d7fed26b393cd88590c22b7fd1df441e2c14bb44c660c54140a4093686aa35f53357f9cd795af6cfa6df1cec4 alpine-musl-dynamic-linking-by-default.patch
+b00997c65d1a451fafae8b547893c5cbf03f028d2d70f6971aa670f34c2d6fc82728c740ac4a9909fc1999925ff300e4525cfec745cb9c9521e564eb166872a2 alpine-allow-crt-static.patch
+2002faf08cca3be702f25618bc17453c5e76644a6ff6b0739b642c2c0f8536ec7f09c98182aff6b2dcc87c77b0929f2f8f732b8242a8f80d94b3824c8cd0d0fe alpine-dont-require-filecheck.patch
+498f4649163974afc4f042c43cd0c15d36784031514201a2962061f288a9336c2bc9749f8d2308b8ce3656f8097b5fc5bef505f61e2a6ed422ef4153f5339d77 alpine-move-py-scripts-to-share.patch
+8d6206f8c50856724cf7b4c1854ec82547f040358a1c7d44abeacc27a5c205a963b1fec51e58ec06c68d85bd2f68a9e6e27ebe457f39e8dd043de17758f5063f alpine-change-rpath-to-rustlib.patch
+f230239d8de1b69536353e5735d3bf32f42a2715aefe4863622d9ab2b25d010209ed0bb38976eaa9302bce2eca6bd162abc8cefd71f689b65b3800920a50967b alpine-force-rpath-on-prefer-dynamic.patch
79549055dea81379c890b495c82456ab497a9179ec6702c59e11d0748bc668f47fc3d6a69c27a0545bb87c01318631dffc69260bf2d4badc75f53cbf7fad7528 check-rustc"
diff --git a/testing/rust/allow-crt-static-on-stable.patch b/testing/rust/alpine-allow-crt-static.patch
index 5e81671f60..5e81671f60 100644
--- a/testing/rust/allow-crt-static-on-stable.patch
+++ b/testing/rust/alpine-allow-crt-static.patch
diff --git a/testing/rust/change-rpath-to-rustlib.patch b/testing/rust/alpine-change-rpath-to-rustlib.patch
index 4be0f9d0a6..4be0f9d0a6 100644
--- a/testing/rust/change-rpath-to-rustlib.patch
+++ b/testing/rust/alpine-change-rpath-to-rustlib.patch
diff --git a/testing/rust/dont-require-filecheck.patch b/testing/rust/alpine-dont-require-filecheck.patch
index 6556d82a46..6556d82a46 100644
--- a/testing/rust/dont-require-filecheck.patch
+++ b/testing/rust/alpine-dont-require-filecheck.patch
diff --git a/testing/rust/force-rpath-on-prefer-dynamic.patch b/testing/rust/alpine-force-rpath-on-prefer-dynamic.patch
index 3c3aced9bd..3c3aced9bd 100644
--- a/testing/rust/force-rpath-on-prefer-dynamic.patch
+++ b/testing/rust/alpine-force-rpath-on-prefer-dynamic.patch
diff --git a/testing/rust/move-py-scripts-to-share.patch b/testing/rust/alpine-move-py-scripts-to-share.patch
index 4afbb1f696..dcab4abd81 100644
--- a/testing/rust/move-py-scripts-to-share.patch
+++ b/testing/rust/alpine-move-py-scripts-to-share.patch
@@ -11,7 +11,7 @@
PYTHONPATH="$PYTHONPATH:$GDB_PYTHON_MODULE_DIRECTORY" gdb \
--- a/src/etc/rust-lldb
+++ b/src/etc/rust-lldb
-@@ -22,7 +22,7 @@
+@@ -33,7 +33,7 @@
RUSTC_SYSROOT=`rustc --print sysroot`
# Write the LLDB script to the tempfile
diff --git a/testing/rust/musl-dynamic-linking-by-default.patch b/testing/rust/alpine-musl-dynamic-linking-by-default.patch
index 225fc2df06..225fc2df06 100644
--- a/testing/rust/musl-dynamic-linking-by-default.patch
+++ b/testing/rust/alpine-musl-dynamic-linking-by-default.patch
diff --git a/testing/rust/llvm-with-ffi.patch b/testing/rust/llvm-with-ffi.patch
index f8c9cdf13a..42b0895e75 100644
--- a/testing/rust/llvm-with-ffi.patch
+++ b/testing/rust/llvm-with-ffi.patch
@@ -7,7 +7,7 @@ https://github.com/rust-lang/rust/issues/34486.
--- a/src/librustc_llvm/lib.rs
+++ b/src/librustc_llvm/lib.rs
-@@ -481,3 +481,6 @@
+@@ -432,3 +432,6 @@
mod llvmdeps {
include! { env!("CFG_LLVM_LINKAGE_FILE") }
}
diff --git a/testing/rust/fix-jemalloc-musl.patch b/testing/rust/musl-fix-jemalloc.patch
index d832ad255b..345398a301 100644
--- a/testing/rust/fix-jemalloc-musl.patch
+++ b/testing/rust/musl-fix-jemalloc.patch
@@ -17,7 +17,7 @@ diff --git a/src/liballoc_jemalloc/build.rs b/src/liballoc_jemalloc/build.rs
index ae040a2..f3a0eeb 100644
--- a/src/liballoc_jemalloc/build.rs
+++ b/src/liballoc_jemalloc/build.rs
-@@ -129,7 +129,7 @@ fn main() {
+@@ -138,7 +138,7 @@ fn main() {
// should be good to go!
cmd.arg("--with-jemalloc-prefix=je_");
cmd.arg("--disable-tls");
@@ -30,7 +30,7 @@ diff --git a/src/liballoc_jemalloc/lib.rs b/src/liballoc_jemalloc/lib.rs
index a7a67ef..83cc1ef 100644
--- a/src/liballoc_jemalloc/lib.rs
+++ b/src/liballoc_jemalloc/lib.rs
-@@ -35,23 +35,23 @@ mod imp {
+@@ -51,23 +51,23 @@ mod imp {
// request it as unprefixing cause segfaults (mismatches in allocators).
extern "C" {
#[cfg_attr(any(target_os = "macos", target_os = "android", target_os = "ios",
diff --git a/testing/rust/fix-linux_musl_base.patch b/testing/rust/musl-fix-linux_musl_base.patch
index 38194290cb..38194290cb 100644
--- a/testing/rust/fix-linux_musl_base.patch
+++ b/testing/rust/musl-fix-linux_musl_base.patch
diff --git a/testing/rust/musl-fix-static-linking.patch b/testing/rust/musl-fix-static-linking.patch
new file mode 100644
index 0000000000..a0a7c1bc6f
--- /dev/null
+++ b/testing/rust/musl-fix-static-linking.patch
@@ -0,0 +1,134 @@
+--- 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.crt_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.crt_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
+@@ -888,17 +881,12 @@
+ // list can't depend on items higher up in the list. For example nothing can
+ // depend on what we just generated (e.g. that'd be a circular dependency).
+ // Upstream rust libraries are not allowed to depend on our local native
+- // libraries as that would violate the structure of the DAG, in that
+- // scenario they are required to link to them as well in a shared fashion.
+- //
+- // Note that upstream rust libraries may contain native dependencies as
+- // well, but they also can't depend on what we just started to add to the
+- // link line. And finally upstream native libraries can't depend on anything
+- // in this DAG so far because they're only dylibs and dylibs can only depend
+- // on other dylibs (e.g. other native deps).
++ // libraries as that would violate the structure of the DAG.
++ cmd.start_group();
+ add_local_native_libraries(cmd, sess);
+ add_upstream_rust_crates(cmd, sess, crate_type, tmpdir);
+ add_upstream_native_libraries(cmd, sess);
++ cmd.end_group();
+
+ // # Telling the linker what we're doing
+
+@@ -983,11 +983,14 @@
+ cmd.link_whole_staticlib(&l.name.as_str(), &search_path);
+ }
+
+- cmd.hint_dynamic();
++ let crt_static = sess.crt_static();
++ if !crt_static {
++ cmd.hint_dynamic();
++ }
+
+ for lib in others {
+ match lib.kind {
+- NativeLibraryKind::NativeUnknown => cmd.link_dylib(&lib.name.as_str()),
++ NativeLibraryKind::NativeUnknown => if 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::NativeStatic => bug!(),
+ }
+--- 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,6 +93,8 @@
+ fn no_whole_archives(&mut self);
+ fn export_symbols(&mut self, tmpdir: &Path, crate_type: CrateType);
+ fn subsystem(&mut self, subsystem: &str);
++ fn start_group(&mut self);
++ fn end_group(&mut self);
+ }
+
+ pub struct GnuLinker<'a> {
+@@ -116,6 +117,9 @@
+ 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 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
+ }
+ }
+
diff --git a/testing/rust/support-dynamically-linked-musl.patch b/testing/rust/musl-support-dynamic-linking.patch
index 7c4e93681b..7c4e93681b 100644
--- a/testing/rust/support-dynamically-linked-musl.patch
+++ b/testing/rust/musl-support-dynamic-linking.patch
diff --git a/testing/rust/static-pie.patch b/testing/rust/static-pie.patch
index 8ac8a76653..90d8496ecd 100644
--- a/testing/rust/static-pie.patch
+++ b/testing/rust/static-pie.patch
@@ -72,18 +72,7 @@ library, just like static binaries, but more secure.
post_link_objects: Vec::new(),
--- a/src/librustc_trans/back/link.rs
+++ b/src/librustc_trans/back/link.rs
-@@ -840,6 +840,10 @@
-
- let used_link_args = sess.cstore.used_link_args();
-
-+ if crate_type == config::CrateTypeExecutable && sess.crt_static() {
-+ cmd.static_executable();
-+ }
-+
- if crate_type == config::CrateTypeExecutable &&
- t.options.position_independent_executables {
- let empty_vec = Vec::new();
-@@ -850,7 +854,7 @@
+@@ -854,7 +854,7 @@
let relocation_model = sess.opts.cg.relocation_model.as_ref()
.unwrap_or(&empty_str);
if (t.options.relocation_model == "pic" || *relocation_model == "pic")
@@ -92,139 +81,3 @@ library, just like static binaries, but more secure.
cmd.position_independent_executable();
}
}
---- 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);
-@@ -116,6 +117,7 @@
- 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 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 no_default_libraries(&mut self) {
---- a/src/librustc_trans/back/link.rs
-+++ b/src/librustc_trans/back/link.rs
-@@ -987,11 +987,14 @@
- cmd.link_whole_staticlib(&l.name.as_str(), &search_path);
- }
-
-- cmd.hint_dynamic();
-+ let crt_static = sess.crt_static();
-+ if !crt_static {
-+ cmd.hint_dynamic();
-+ }
-
- for lib in others {
- match lib.kind {
-- NativeLibraryKind::NativeUnknown => cmd.link_dylib(&lib.name.as_str()),
-+ NativeLibraryKind::NativeUnknown => if 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::NativeStatic => bug!(),
- }
---- a/src/librustc_trans/back/link.rs
-+++ b/src/librustc_trans/back/link.rs
-@@ -874,15 +874,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
-@@ -892,17 +885,12 @@
- // list can't depend on items higher up in the list. For example nothing can
- // depend on what we just generated (e.g. that'd be a circular dependency).
- // Upstream rust libraries are not allowed to depend on our local native
-- // libraries as that would violate the structure of the DAG, in that
-- // scenario they are required to link to them as well in a shared fashion.
-- //
-- // Note that upstream rust libraries may contain native dependencies as
-- // well, but they also can't depend on what we just started to add to the
-- // link line. And finally upstream native libraries can't depend on anything
-- // in this DAG so far because they're only dylibs and dylibs can only depend
-- // on other dylibs (e.g. other native deps).
-+ // libraries as that would violate the structure of the DAG.
-+ cmd.start_group();
- add_local_native_libraries(cmd, sess);
- add_upstream_rust_crates(cmd, sess, crate_type, tmpdir);
- add_upstream_native_libraries(cmd, sess);
-+ cmd.end_group();
-
- // # Telling the linker what we're doing
-
---- a/src/librustc_trans/back/linker.rs
-+++ b/src/librustc_trans/back/linker.rs
-@@ -94,6 +94,8 @@
- fn no_whole_archives(&mut self);
- fn export_symbols(&mut self, tmpdir: &Path, crate_type: CrateType);
- fn subsystem(&mut self, subsystem: &str);
-+ fn start_group(&mut self);
-+ fn end_group(&mut self);
- }
-
- pub struct GnuLinker<'a> {
-@@ -118,6 +120,8 @@
- 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) {
-@@ -490,6 +494,14 @@
- if subsystem == "windows" {
- self.cmd.arg("/ENTRY:mainCRTStartup");
- }
-+ }
-+
-+ fn start_group(&mut self) {
-+ // Not needed
-+ }
-+
-+ fn end_group(&mut self) {
-+ // Not needed
- }
- }
-
---- 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.crt_static();
-+ match (dynamic_linking, sess.target.target.options.executables, crate_type) {
- (false, _, config::CrateTypeCdylib) |
- (false, _, config::CrateTypeProcMacro) |
- (false, _, config::CrateTypeDylib) => true,