diff options
-rw-r--r-- | testing/rust/APKBUILD | 8 | ||||
-rw-r--r-- | testing/rust/alpine-force-rpath-on-prefer-dynamic.patch | 36 | ||||
-rw-r--r-- | testing/rust/alpine-need-rpath.patch | 11 | ||||
-rw-r--r-- | testing/rust/minimize-rpath.patch | 102 | ||||
-rw-r--r-- | testing/rust/need-rpath.patch | 62 |
5 files changed, 181 insertions, 38 deletions
diff --git a/testing/rust/APKBUILD b/testing/rust/APKBUILD index a8e6c4f2cf..c90428ed08 100644 --- a/testing/rust/APKBUILD +++ b/testing/rust/APKBUILD @@ -35,10 +35,12 @@ source="https://static.rust-lang.org/dist/rustc-$pkgver-src.tar.gz static-pie.patch llvm-with-ffi.patch alpine-musl-dynamic-linking-by-default.patch + need-rpath.patch + minimize-rpath.patch alpine-allow-crt-static.patch alpine-move-py-scripts-to-share.patch alpine-change-rpath-to-rustlib.patch - alpine-force-rpath-on-prefer-dynamic.patch + alpine-need-rpath.patch check-rustc " builddir="$srcdir/rustc-$pkgver-src" @@ -191,8 +193,10 @@ c913d04ef419b2b6d8e453f72894070f263c9292abf97114a51884d475d03ce5b032053f1676ba93 5881cb63c77a566aab80428084297fa278c04aeb5fe4e7a3a32655f2b97cdb5b0712fe859662392393dbbb4b2723be543a0207f6b75961a5fb79351c02c107a9 static-pie.patch dc6432293bd060d5e3a73f25870867654fae61995dcd919e244a2dc686b6107556deed8c59ca6002182bfeff5ebc1ca2b89c4028ab0fbfb79e65defe47c9b4b0 llvm-with-ffi.patch 44f3104f506531778fede64034ff5b86f782744d7fed26b393cd88590c22b7fd1df441e2c14bb44c660c54140a4093686aa35f53357f9cd795af6cfa6df1cec4 alpine-musl-dynamic-linking-by-default.patch +ff633f2a46c683ad698d1c09c98c06ce9ee9b8d55fa5593cdd485b439ebca3273794d29b5ff32b887be8666f52913a23af6e133c782bd0c4e2c88e306dd3a494 need-rpath.patch +d352614e7c774e181decae210140e789de7fc090327ff371981ad28a11ce51c8c01b27c1101a24bb84d75ed2f706f67868f7dbc52196d4ccdf4ebd2d6d6b6b5e minimize-rpath.patch b00997c65d1a451fafae8b547893c5cbf03f028d2d70f6971aa670f34c2d6fc82728c740ac4a9909fc1999925ff300e4525cfec745cb9c9521e564eb166872a2 alpine-allow-crt-static.patch 498f4649163974afc4f042c43cd0c15d36784031514201a2962061f288a9336c2bc9749f8d2308b8ce3656f8097b5fc5bef505f61e2a6ed422ef4153f5339d77 alpine-move-py-scripts-to-share.patch 8d6206f8c50856724cf7b4c1854ec82547f040358a1c7d44abeacc27a5c205a963b1fec51e58ec06c68d85bd2f68a9e6e27ebe457f39e8dd043de17758f5063f alpine-change-rpath-to-rustlib.patch -f230239d8de1b69536353e5735d3bf32f42a2715aefe4863622d9ab2b25d010209ed0bb38976eaa9302bce2eca6bd162abc8cefd71f689b65b3800920a50967b alpine-force-rpath-on-prefer-dynamic.patch +816068be3ef92b3a67dedc3c4cf80b647f4a40743dc06a50801ba3a1bd3194f244bd7498f57db781f625a0c0da9605ef42e6dae6b781ad6c7f73ec5b45242e98 alpine-need-rpath.patch 79549055dea81379c890b495c82456ab497a9179ec6702c59e11d0748bc668f47fc3d6a69c27a0545bb87c01318631dffc69260bf2d4badc75f53cbf7fad7528 check-rustc" diff --git a/testing/rust/alpine-force-rpath-on-prefer-dynamic.patch b/testing/rust/alpine-force-rpath-on-prefer-dynamic.patch deleted file mode 100644 index 3c3aced9bd..0000000000 --- a/testing/rust/alpine-force-rpath-on-prefer-dynamic.patch +++ /dev/null @@ -1,36 +0,0 @@ -From: Shiz <hi@shiz.me> -From: Jakub Jirutka <jakub@jirutka.cz> -Date: Wed, 12 Apr 2017 23:28:09 +0200 -Subject: [PATCH] Force rpath on prefer-dynamic - -When you build a dynamic binary with `-C prefer-dynamic`, rustc links -dynamically even Rust libraries, built as shared objects. These are -installed in /usr/lib/rustlib/<TARGET>/lib/, the location that is not -on standard LD path, at least on Alpine. - -Therefore such binary would be unusable when not built with `-C rpath` -(or manually specifying LD_LIBRARY_PATH). For that reason we implicitly -enable rpath when `prefer-dynamic` is enabled. - -Also note that Rust normally installs identical copy of *.so files from -/usr/lib/rustlib/<TARGET>/lib/, where <TARGET> equals host triple, to -/usr/lib. That's why such fully dynamic binary may work on other -systems even without rpath or having rustlib on the LD path. However, -since these *.so libraries don't keep stable ABI, they should not be on -LD path, and thus we do not install them here (see -change-rpath-to-rustlib.patch). - ---- a/src/librustc/session/config.rs -+++ b/src/librustc/session/config.rs -@@ -1368,6 +1368,11 @@ - - let mut cg = build_codegen_options(matches, error_format); - -+ // Force rpath addition on prefer-dynamic output. -+ if cg.prefer_dynamic { -+ cg.rpath = true; -+ } -+ - // Issue #30063: if user requests llvm-related output to one - // particular path, disable codegen-units. - if matches.opt_present("o") && cg.codegen_units != 1 { diff --git a/testing/rust/alpine-need-rpath.patch b/testing/rust/alpine-need-rpath.patch new file mode 100644 index 0000000000..8710f0254b --- /dev/null +++ b/testing/rust/alpine-need-rpath.patch @@ -0,0 +1,11 @@ +--- a/src/librustc_back/target/linux_musl_base.rs ++++ b/src/librustc_back/target/linux_musl_base.rs +@@ -22,5 +22,8 @@ + // Static position-independent executables are supported. + base.static_position_independent_executables = true; + ++ // We need an RPATH. ++ base.need_rpath = true; ++ + base + } diff --git a/testing/rust/minimize-rpath.patch b/testing/rust/minimize-rpath.patch new file mode 100644 index 0000000000..1fc0e1b722 --- /dev/null +++ b/testing/rust/minimize-rpath.patch @@ -0,0 +1,102 @@ +From: Shiz <hi@shiz.me> +Date: Thu, 20 Aug 2017 01:44:12 +0200 +Subject: [PATCH] Minimize generated RPATH in end products + +By default, RPATH generation adds both the install prefix and the generated +relative path to the install prefix. This is unnecessary, so we add the install +prefix to a list of absolute paths to omit in the relative path generation, +and skip it there. + +--- a/src/librustc_trans/back/rpath.rs ++++ b/src/librustc_trans/back/rpath.rs +@@ -69,14 +69,15 @@ + debug!(" {:?}", libpath.display()); + } + ++ // The backup rpath is the global library location. ++ // We also omit this path from the relative rpaths. ++ let fallback_rpaths = vec![get_install_prefix_rpath(config)]; ++ + // Use relative paths to the libraries. Binaries can be moved + // as long as they maintain the relative relationship to the + // crates they depend on. +- let rel_rpaths = get_rpaths_relative_to_output(config, libs); ++ let rel_rpaths = get_rpaths_relative_to_output(config, libs, &fallback_rpaths); + +- // And a final backup rpath to the global library location. +- let fallback_rpaths = vec![get_install_prefix_rpath(config)]; +- + fn log_rpaths(desc: &str, rpaths: &[String]) { + debug!("{} rpaths:", desc); + for rpath in rpaths { +@@ -96,11 +97,13 @@ + } + + fn get_rpaths_relative_to_output(config: &mut RPathConfig, +- libs: &[PathBuf]) -> Vec<String> { +- libs.iter().map(|a| get_rpath_relative_to_output(config, a)).collect() ++ libs: &[PathBuf], ++ omit: &Vec<String>) -> Vec<String> { ++ libs.iter().filter_map(|a| get_rpath_relative_to_output(config, a, omit)).collect() + } + +-fn get_rpath_relative_to_output(config: &mut RPathConfig, lib: &Path) -> String { ++fn get_rpath_relative_to_output(config: &mut RPathConfig, lib: &Path, ++ omit: &Vec<String>) -> Option<String> { + // Mac doesn't appear to support $ORIGIN + let prefix = if config.is_like_osx { + "@loader_path" +@@ -114,11 +117,18 @@ + let mut output = cwd.join(&config.out_filename); + output.pop(); + let output = fs::canonicalize(&output).unwrap_or(output); +- let relative = path_relative_from(&lib, &output) +- .expect(&format!("couldn't create relative path from {:?} to {:?}", output, lib)); ++ + // FIXME (#9639): This needs to handle non-utf8 paths +- format!("{}/{}", prefix, +- relative.to_str().expect("non-utf8 component in path")) ++ let libpath = lib.to_str().expect("non-utf8 component in path").to_string(); ++ if omit.contains(&libpath) { ++ None ++ } else { ++ let relative = path_relative_from(&lib, &output) ++ .expect(&format!("couldn't create relative path from {:?} to {:?}", output, lib)); ++ // FIXME (#9639): This needs to handle non-utf8 paths ++ Some(format!("{}/{}", prefix, ++ relative.to_str().expect("non-utf8 component in path"))) ++ } + } + + // This routine is adapted from the *old* Path's `path_relative_from` +@@ -239,6 +249,7 @@ + #[test] + fn test_rpath_relative() { + if cfg!(target_os = "macos") { ++ let omit = Vec::new(); + let config = &mut RPathConfig { + used_crates: Vec::new(), + has_rpath: true, +@@ -248,9 +259,11 @@ + get_install_prefix_lib_path: &mut || panic!(), + }; + let res = get_rpath_relative_to_output(config, +- Path::new("lib/libstd.so")); ++ Path::new("lib/libstd.so"), ++ &omit); + assert_eq!(res, "@loader_path/../lib"); + } else { ++ let omit = Vec::new(); + let config = &mut RPathConfig { + used_crates: Vec::new(), + out_filename: PathBuf::from("bin/rustc"), +@@ -260,7 +273,8 @@ + linker_is_gnu: true, + }; + let res = get_rpath_relative_to_output(config, +- Path::new("lib/libstd.so")); ++ Path::new("lib/libstd.so"), ++ &omit); + assert_eq!(res, "$ORIGIN/../lib"); + } + } diff --git a/testing/rust/need-rpath.patch b/testing/rust/need-rpath.patch new file mode 100644 index 0000000000..b345d27d92 --- /dev/null +++ b/testing/rust/need-rpath.patch @@ -0,0 +1,62 @@ +From: Shiz <hi@shiz.me> +Date: Thu, 20 Aug 2017 01:48:22 +0200 +Subject: [PATCH] Add need_rpath target option to force RPATH generation + +This adds a `need_rpath` option to the target options in order to implicitly +have the equivalent of `-C rpath` specified by default for final products +(executables and dynamic libraries), so that RPATHs are always added. + +We have to skip this step in the bootstrap phase as it does its own manual +RPATH additions, but unfortunately there's no clean way to detect this. +As such, we have to resort to checking the `RUSTC_BOOTSTRAP` variable. +Hacky hacky! + +--- a/src/librustc_back/target/mod.rs ++++ b/src/librustc_back/target/mod.rs +@@ -341,6 +341,8 @@ + pub allows_weak_linkage: bool, + /// Whether the linker support rpaths or not. Defaults to false. + pub has_rpath: bool, ++ /// Whether to force rpath support on by default. Defaults to false. ++ pub need_rpath: bool, + /// Whether to disable linking to the default libraries, typically corresponds + /// to `-nodefaultlibs`. Defaults to true. + pub no_default_libraries: bool, +@@ -434,6 +436,7 @@ + linker_is_gnu: false, + allows_weak_linkage: true, + has_rpath: false, ++ need_rpath: false, + no_default_libraries: true, + position_independent_executables: false, + static_position_independent_executables: false, +@@ -616,6 +616,7 @@ + key!(linker_is_gnu, bool); + key!(allows_weak_linkage, bool); + key!(has_rpath, bool); ++ key!(need_rpath, bool); + key!(no_default_libraries, bool); + key!(position_independent_executables, bool); + key!(static_position_independent_executables, bool); +@@ -781,6 +782,7 @@ + target_option_val!(linker_is_gnu); + target_option_val!(allows_weak_linkage); + target_option_val!(has_rpath); ++ target_option_val!(need_rpath); + target_option_val!(no_default_libraries); + target_option_val!(position_independent_executables); + target_option_val!(static_position_independent_executables); +--- a/src/librustc_trans/back/link.rs ++++ b/src/librustc_trans/back/link.rs +@@ -901,7 +901,10 @@ + // FIXME (#2397): At some point we want to rpath our guesses as to + // where extern libraries might live, based on the + // addl_lib_search_paths +- if sess.opts.cg.rpath { ++ // XXX: hacky hacky ++ let bootstrap = env::var("RUSTC_BOOTSTRAP").is_ok(); ++ if !bootstrap && !sess.fully_static() && ++ (sess.opts.cg.rpath || sess.target.target.options.need_rpath) { + let sysroot = sess.sysroot(); + let target_triple = &sess.opts.target_triple; + let mut get_install_prefix_lib_path = || { |