From 3fe5dd32fb7114132ea2fd43bdd0e26319ddd11a Mon Sep 17 00:00:00 2001 From: Shiz Date: Sun, 20 Aug 2017 01:48:22 +0200 Subject: [PATCH 06/10] 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! Signed-off-by: Achill Gilgenast --- compiler/rustc_codegen_ssa/src/back/link.rs | 5 ++++- compiler/rustc_target/src/spec/json.rs | 3 +++ compiler/rustc_target/src/spec/mod.rs | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index 162fbf3d6e24..46e4db8ef3fd 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -2148,7 +2148,10 @@ fn add_rpath_args( // FIXME (#2397): At some point we want to rpath our guesses as to // where extern libraries might live, based on the // add_lib_search_paths - if sess.opts.cg.rpath { + // XXX: hacky hacky + let bootstrap = env::var("RUSTC_BOOTSTRAP").is_ok(); + if !bootstrap && !sess.crt_static(None) && + (sess.opts.cg.rpath || sess.target.options.need_rpath) { let libs = codegen_results .crate_info .used_crates diff --git a/compiler/rustc_target/src/spec/json.rs b/compiler/rustc_target/src/spec/json.rs index d27c1929aef7..34e745aa30c5 100644 --- a/compiler/rustc_target/src/spec/json.rs +++ b/compiler/rustc_target/src/spec/json.rs @@ -157,6 +157,7 @@ macro_rules! forward_opt { forward!(default_dwarf_version); forward!(allows_weak_linkage); forward!(has_rpath); + forward!(need_rpath); forward!(no_default_libraries); forward!(position_independent_executables); forward!(static_position_independent_executables); @@ -349,6 +350,7 @@ macro_rules! target_option_val { target_option_val!(default_dwarf_version); 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); @@ -542,6 +544,7 @@ struct TargetSpecJson { default_dwarf_version: Option, allows_weak_linkage: Option, has_rpath: Option, + need_rpath: Option, no_default_libraries: Option, position_independent_executables: Option, static_position_independent_executables: Option, diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index ab8437d73565..53ae44db2a2c 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -2597,6 +2597,8 @@ pub struct TargetOptions { 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, @@ -2969,6 +2971,7 @@ fn default() -> TargetOptions { default_dwarf_version: 4, allows_weak_linkage: true, has_rpath: false, + need_rpath: false, no_default_libraries: true, position_independent_executables: false, static_position_independent_executables: false, -- 2.51.0