aports/community/rust/minimize-rpath.patch
Rasmus Thomsen 6af1d32896 community/rust: upgrade to 1.36.0
* Update alpine-target.patch to fix the triplet on armhf and add the armv7 and ppc64le
  triplets. This should have been done in 69851bdae1177246337f51a35734e93f1fd7e3d3,
  but has been forgotten.
* Remove the following patches:
  	* llvm-with-ffi.patch -> only required when statically linking LLVM
	* bootstrap-tool-respect-tool-config.patch -> plain outdated, not required anymore
2019-07-07 17:29:18 -03:00

100 lines
4.3 KiB
Diff

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_codegen_ssa/back/rpath.rs
+++ b/src/librustc_codegen_ssa/back/rpath.rs
@@ -59,13 +59,14 @@
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);
-
- // And a final backup rpath to the global library location.
- let fallback_rpaths = vec![get_install_prefix_rpath(config)];
+ let rel_rpaths = get_rpaths_relative_to_output(config, libs, &fallback_rpaths);
fn log_rpaths(desc: &str, rpaths: &[String]) {
debug!("{} rpaths:", desc);
@@ -87,11 +88,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"
@@ -105,10 +108,16 @@
let mut output = cwd.join(&config.out_filename);
output.pop(); // strip filename
let output = fs::canonicalize(&output).unwrap_or(output);
- let relative = path_relative_from(&lib, &output).unwrap_or_else(||
- panic!("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`
@@ -227,6 +236,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,
@@ -236,9 +246,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"),
@@ -248,7 +260,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");
}
}