]> git.lizzy.rs Git - rust.git/commitdiff
Pass additional linker flags when targeting Fuchsia
authorPetr Hosek <phosek@google.com>
Thu, 22 Nov 2018 08:59:37 +0000 (00:59 -0800)
committerPetr Hosek <phosek@google.com>
Thu, 22 Nov 2018 08:59:37 +0000 (00:59 -0800)
This is a follow up to 8aa9267 which changed the driver to use lld
directly rather than invoking it through Clang. This change ensures
we pass all the necessary flags to lld.

src/librustc_codegen_llvm/back/link.rs
src/librustc_target/spec/fuchsia_base.rs
src/librustc_target/spec/mod.rs

index 20f05d110877a242184bbaa6a358a327ee0b21e9..8380b7136213882b905f4b43202ea2aacfe02419 100644 (file)
@@ -19,7 +19,7 @@
 use super::rpath;
 use metadata::METADATA_FILENAME;
 use rustc::session::config::{self, DebugInfo, OutputFilenames, OutputType, PrintRequest};
-use rustc::session::config::{RUST_CGU_EXT, Lto};
+use rustc::session::config::{RUST_CGU_EXT, Lto, Sanitizer};
 use rustc::session::filesearch;
 use rustc::session::search_paths::PathKind;
 use rustc::session::Session;
@@ -491,6 +491,14 @@ fn link_natively(sess: &Session,
     }
     cmd.args(&sess.opts.debugging_opts.pre_link_arg);
 
+    if sess.target.target.options.is_like_fuchsia {
+        let prefix = match sess.opts.debugging_opts.sanitizer {
+            Some(Sanitizer::Address) => "asan/",
+            _ => "",
+        };
+        cmd.arg(format!("--dynamic-linker={}ld.so.1", prefix));
+    }
+
     let pre_link_objects = if crate_type == config::CrateType::Executable {
         &sess.target.target.options.pre_link_objects_exe
     } else {
index 8c20755492e31569f67b086d12e69839e2949fbb..1d0474e1a9a90eb5bd5c82ca9da34cded9349a62 100644 (file)
 use std::default::Default;
 
 pub fn opts() -> TargetOptions {
-    let mut args = LinkArgs::new();
-    args.insert(LinkerFlavor::Lld(LldFlavor::Ld), vec![
-        "--build-id".to_string(), "--hash-style=gnu".to_string(),
+    let mut pre_link_args = LinkArgs::new();
+    pre_link_args.insert(LinkerFlavor::Lld(LldFlavor::Ld), vec![
+        "--build-id".to_string(),
+        "--eh-frame-hdr".to_string(),
+        "--hash-style=gnu".to_string(),
         "-z".to_string(), "rodynamic".to_string(),
     ]);
 
@@ -24,9 +26,13 @@ pub fn opts() -> TargetOptions {
         dynamic_linking: true,
         executables: true,
         target_family: Some("unix".to_string()),
+        is_like_fuchsia: true,
         linker_is_gnu: true,
         has_rpath: false,
-        pre_link_args: args,
+        pre_link_args: pre_link_args,
+        pre_link_objects_exe: vec![
+            "Scrt1.o".to_string()
+        ],
         position_independent_executables: true,
         has_elf_tls: true,
         .. Default::default()
index f67152ee90b7a0abcd9cd31b6291fd8fe4ad4f89..3cf843dc18cd0ebac8a27ca76a3b526e2e11c076 100644 (file)
@@ -558,6 +558,8 @@ pub struct TargetOptions {
     /// Emscripten toolchain.
     /// Defaults to false.
     pub is_like_emscripten: bool,
+    /// Whether the target toolchain is like Fuchsia's.
+    pub is_like_fuchsia: bool,
     /// Whether the linker support GNU-like arguments such as -O. Defaults to false.
     pub linker_is_gnu: bool,
     /// The MinGW toolchain has a known issue that prevents it from correctly
@@ -723,6 +725,7 @@ fn default() -> TargetOptions {
             is_like_android: false,
             is_like_emscripten: false,
             is_like_msvc: false,
+            is_like_fuchsia: false,
             linker_is_gnu: false,
             allows_weak_linkage: true,
             has_rpath: false,
@@ -1013,6 +1016,7 @@ macro_rules! key {
         key!(is_like_msvc, bool);
         key!(is_like_emscripten, bool);
         key!(is_like_android, bool);
+        key!(is_like_fuchsia, bool);
         key!(linker_is_gnu, bool);
         key!(allows_weak_linkage, bool);
         key!(has_rpath, bool);
@@ -1222,6 +1226,7 @@ macro_rules! target_option_val {
         target_option_val!(is_like_msvc);
         target_option_val!(is_like_emscripten);
         target_option_val!(is_like_android);
+        target_option_val!(is_like_fuchsia);
         target_option_val!(linker_is_gnu);
         target_option_val!(allows_weak_linkage);
         target_option_val!(has_rpath);