diff options
author | Jakub Jirutka <jakub@jirutka.cz> | 2017-04-12 03:03:35 +0200 |
---|---|---|
committer | Jakub Jirutka <jakub@jirutka.cz> | 2017-04-12 14:14:01 +0200 |
commit | e6ca0848df365e43b19ecff2cca63e2ac4aebc76 (patch) | |
tree | e9d434dff3e084f98e0733c0c77e2e50d53b10ee | |
parent | e2345d3156f0f713623ab9265a931e780b2e9958 (diff) | |
download | aports-e6ca0848df365e43b19ecff2cca63e2ac4aebc76.tar.bz2 aports-e6ca0848df365e43b19ecff2cca63e2ac4aebc76.tar.xz |
testing/rust: fix multiple issues with static/dynamic linking
-rw-r--r-- | testing/rust/APKBUILD | 14 | ||||
-rw-r--r-- | testing/rust/allow-crt-static-on-stable.patch | 4 | ||||
-rwxr-xr-x | testing/rust/check-rustc | 20 | ||||
-rw-r--r-- | testing/rust/remove-crt-static-from-stdlibs.patch | 23 | ||||
-rw-r--r-- | testing/rust/static-pie.patch | 102 |
5 files changed, 151 insertions, 12 deletions
diff --git a/testing/rust/APKBUILD b/testing/rust/APKBUILD index 03db5a2b0e..d8d0bb84ab 100644 --- a/testing/rust/APKBUILD +++ b/testing/rust/APKBUILD @@ -5,7 +5,7 @@ pkgname=rust pkgver=1.16.0 # Git revision of prebuilt Cargo to use for bootstrapping, from src/stage0.txt. _cargo_gitrev=6e0c18cccc8b0c06fba8a8d76486f81a792fb420 -pkgrel=0 +pkgrel=1 pkgdesc="The Rust Programming Language (compiler)" url="http://www.rust-lang.org" arch="x86_64" @@ -13,9 +13,9 @@ license="ASL-2.0 BSD ISC MIT" # gcc is needed at runtime just for linking. Someday rustc might invoke # the linker directly, and then we'll only need binutils. # See: https://github.com/rust-lang/rust/issues/11937 -depends="$pkgname-stdlib=$pkgver-r$pkgrel gcc musl-dev" +depends="$pkgname-stdlib=$pkgver-r$pkgrel gcc llvm-libunwind-dev musl-dev" # libffi-dev is needed just because we compile llvm with LLVM_ENABLE_FFI. -makedepends="cmake file libffi-dev libunwind-dev llvm llvm-dev +makedepends="cmake file libffi-dev llvm-libunwind-dev llvm llvm-dev musl-dev python2 tar zlib-dev" subpackages="$pkgname-dbg $pkgname-stdlib $pkgname-gdb::noarch $pkgname-lldb::noarch $pkgname-doc" @@ -30,6 +30,7 @@ source="https://static.rust-lang.org/dist/rustc-$pkgver-src.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 + remove-crt-static-from-stdlibs.patch allow-crt-static-on-stable.patch static-pie.patch fix-linux_musl_base.patch @@ -184,11 +185,12 @@ e9b10d58ae5b51b09dd31a1dbf7367917bd40a05ecb4ba3e0e7ac229a0352d3ceb77de80f7c0120f 4df33353b6be1af822220ca03f9ec5a3b6421c9b10ec17b864be586ba495c6210bac70d904b0e0b35eff62ef2c9a681ded526e5cbd37e326dc3146742aa659de cargo-6e0c18cccc8b0c06fba8a8d76486f81a792fb420-x86_64-unknown-linux-musl.tar.gz 2002faf08cca3be702f25618bc17453c5e76644a6ff6b0739b642c2c0f8536ec7f09c98182aff6b2dcc87c77b0929f2f8f732b8242a8f80d94b3824c8cd0d0fe dont-require-filecheck.patch a87ffe129debcb9fa958c6d007ffa4a87927890030e0694ee5ab1929ea0c5a48dad86b4e8b71550dcfeda29b644dbb23d8b232bda62439f198a404cf658c68b0 support-dynamically-linked-musl.patch -7e2a282332d22d22a0d48da34cc9e83db7acbf38787bc3b18c49dd2cdc112ca76ebfa40e5b9629a80ae73632b4b0fea278b9ff4cdc56ddb7dd265958b509afab allow-crt-static-on-stable.patch -541aac679dfdbe5383f884e0493462dd33908308c7b294170b24339d6b9c1e723088c80764125116f24707a67eeeedadceaa9628ca6d2b8c7d0ca9253bf62135 static-pie.patch +027d9ddf70d48324b8d88760c0a9311c985139bf3309c21eb65d03ab776ddf2d557cf8dd90964a4f6a072e67dd88a335b1bc98ccb9211e00a208b3ef80a15bc0 remove-crt-static-from-stdlibs.patch +67f5933fd2da8f2b5eb0d62e05af52d161bd0602fe9353adc9a2128b9c9ba42578587d4963357a483638af3e5f74cef69a994c45ea20ce6c22f6016e5bcc3125 allow-crt-static-on-stable.patch +79d7eb79bb5219beab2fa8394e30b830275ce3062fd7c02077229ad1fdca492f55d321e0bc1015f62252fe4df3cc41c5168ff9d2e848ae06b14f807add7e193a static-pie.patch f436fddf7ab70ca5f1424081f5b75450270b200b3d997231323863e11addf76e1d65831a7ca09e3a5b7904ce828766c1f70b08326a175890298f28e5bc8646ef fix-linux_musl_base.patch 37416e1fa0bc0c8651cd060a645d6245ff7e2082279ab5e13495c5ee412c71915469019cfbec95a0fd9a7fc144475079a3ad16f0eba7a2f5c8dd99e0002f3225 llvm-with-ffi.patch 19cc2725d68db3e359e0e3016028374e5818a97fdba24d0103f7d1706601c8b17c4dd95a3152e64f982f98e95ad3e949acddbea8a39ed0ba8dd4f702acc2704d move-py-scripts-to-share.patch 8d6206f8c50856724cf7b4c1854ec82547f040358a1c7d44abeacc27a5c205a963b1fec51e58ec06c68d85bd2f68a9e6e27ebe457f39e8dd043de17758f5063f change-rpath-to-rustlib.patch a330fa913faeadb98cb95e644f434ddef4fbbea32bcd11b6621fb9e08f7b0d8c71fae702207465489af3cf793eade0af694a8c515fc1bed49624da25103a4862 fix-jemalloc-musl.patch -74911ab235e64ad297778786943f54cee397dfd7d199264f0aaea39f17942c03620047fa6ebe2c91d80713670c53c1a0474f2a55c1879e1982c4a0cdda7b0fbb check-rustc" +37ece048cc4efac0f66e3f6e4cbb37f08fc0f8fe7af474a96e2c1d7400df773d9e33601b09feddae2a716e14fb98f8d8386504c4e36f86c699b6b785115c6bdb check-rustc" diff --git a/testing/rust/allow-crt-static-on-stable.patch b/testing/rust/allow-crt-static-on-stable.patch index 2646b3ef94..df4c06bf79 100644 --- a/testing/rust/allow-crt-static-on-stable.patch +++ b/testing/rust/allow-crt-static-on-stable.patch @@ -12,8 +12,8 @@ allows to use it even on stable build. Build dynamically linked binary with rustc or cargo: - $ rustc -C target-feature=+crt-static hello_world.rs - $ RUSTFLAGS="-C target-feature=+crt-static" cargo build + $ rustc -C target-feature=-crt-static hello_world.rs + $ RUSTFLAGS="-C target-feature=-crt-static" cargo build --- a/src/librustc/session/mod.rs +++ b/src/librustc/session/mod.rs diff --git a/testing/rust/check-rustc b/testing/rust/check-rustc index 867666e503..3a375005f2 100755 --- a/testing/rust/check-rustc +++ b/testing/rust/check-rustc @@ -34,6 +34,12 @@ assert_ok() { "$1" || fail "$1 exited with status $?" } +assert_panic() { + local status=0 + "$1" || status=$? && [ "$status" = 101 ] \ + || fail "$1 exited with status $status, but expected 101" +} + assert_pie() { readelf -d "$1" | grep -Fw FLAGS_1 | grep -Fqw PIE || { fail "$1 is not a PIE executable!" @@ -83,4 +89,18 @@ assert_static hello_world assert_pie hello_world rm -f hello_world + +cat >> panic.rs <<-EOF + fn main() { + panic!("This should panic"); + } +EOF + +_rustc -C target-feature=-crt-static panic.rs +assert_panic ./panic + +_rustc -C target-feature=+crt-static panic.rs +assert_panic ./panic + + [ "$failed" -eq 0 ] || die "$failed assertion(s) has failed" diff --git a/testing/rust/remove-crt-static-from-stdlibs.patch b/testing/rust/remove-crt-static-from-stdlibs.patch new file mode 100644 index 0000000000..d27a0f74c1 --- /dev/null +++ b/testing/rust/remove-crt-static-from-stdlibs.patch @@ -0,0 +1,23 @@ +--- 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")] +--- a/src/libunwind/lib.rs ++++ b/src/libunwind/lib.rs +@@ -30,6 +30,5 @@ + pub use libunwind::*; + + #[cfg(target_env = "musl")] +-#[link(name = "unwind", kind = "static", cfg(target_feature = "crt-static"))] +-#[link(name = "gcc_s", cfg(not(target_feature = "crt-static")))] ++#[link(name = "unwind")] + extern {} diff --git a/testing/rust/static-pie.patch b/testing/rust/static-pie.patch index adc615f95f..5ae091f691 100644 --- a/testing/rust/static-pie.patch +++ b/testing/rust/static-pie.patch @@ -1,16 +1,16 @@ From: Shiz <hi@shiz.me> -Date: Sat, 8 Apr 2017 05:38:00 +0200 +Date: Tue, 11 Apr 2017 04:37:00 +0200 Subject: [PATCH] Add support for static PIE executables -Note that static PIE binaries are reported as dynamically linked by -the "file" utility: +Note that static PIE binaries are reported as dynamically linked by file(1): $ rustc -C target-feature=+crt-static hello_world.rb $ file hello_world ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically \ linked, not stripped, with debug_info -Also ldd reports that it's linked with ldd: +In addition, ldd(1) reports that it's linked with ldd, as it can't find any +dependencies except itself loaded into the process: $ ldd hello_world ldd (0x237fcc81000) @@ -121,3 +121,97 @@ library, just like static binaries, but more secure. } 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 + } + } + |