Skip to content

Commit f41423c

Browse files
committed
Pass additional linker flags when targeting Fuchsia
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.
1 parent 910ec6d commit f41423c

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

src/librustc_codegen_llvm/back/link.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use super::rpath::RPathConfig;
1919
use super::rpath;
2020
use metadata::METADATA_FILENAME;
2121
use rustc::session::config::{self, DebugInfo, OutputFilenames, OutputType, PrintRequest};
22-
use rustc::session::config::{RUST_CGU_EXT, Lto};
22+
use rustc::session::config::{RUST_CGU_EXT, Lto, Sanitizer};
2323
use rustc::session::filesearch;
2424
use rustc::session::search_paths::PathKind;
2525
use rustc::session::Session;
@@ -491,6 +491,14 @@ fn link_natively(sess: &Session,
491491
}
492492
cmd.args(&sess.opts.debugging_opts.pre_link_arg);
493493

494+
if sess.target.target.options.is_like_fuchsia {
495+
let prefix = match sess.opts.debugging_opts.sanitizer {
496+
Some(Sanitizer::Address) => "asan/",
497+
_ => "",
498+
};
499+
cmd.arg(format!("--dynamic-linker={}ld.so.1", prefix));
500+
}
501+
494502
let pre_link_objects = if crate_type == config::CrateType::Executable {
495503
&sess.target.target.options.pre_link_objects_exe
496504
} else {

src/librustc_target/spec/fuchsia_base.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ use spec::{LldFlavor, LinkArgs, LinkerFlavor, TargetOptions};
1212
use std::default::Default;
1313

1414
pub fn opts() -> TargetOptions {
15-
let mut args = LinkArgs::new();
16-
args.insert(LinkerFlavor::Lld(LldFlavor::Ld), vec![
17-
"--build-id".to_string(), "--hash-style=gnu".to_string(),
15+
let mut pre_link_args = LinkArgs::new();
16+
pre_link_args.insert(LinkerFlavor::Lld(LldFlavor::Ld), vec![
17+
"--build-id".to_string(),
18+
"--eh-frame-hdr".to_string(),
19+
"--hash-style=gnu".to_string(),
1820
"-z".to_string(), "rodynamic".to_string(),
1921
]);
2022

@@ -24,9 +26,13 @@ pub fn opts() -> TargetOptions {
2426
dynamic_linking: true,
2527
executables: true,
2628
target_family: Some("unix".to_string()),
29+
is_like_fuchsia: true,
2730
linker_is_gnu: true,
2831
has_rpath: false,
29-
pre_link_args: args,
32+
pre_link_args: pre_link_args,
33+
pre_link_objects_exe: vec![
34+
"Scrt1.o".to_string()
35+
],
3036
position_independent_executables: true,
3137
has_elf_tls: true,
3238
.. Default::default()

src/librustc_target/spec/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,8 @@ pub struct TargetOptions {
558558
/// Emscripten toolchain.
559559
/// Defaults to false.
560560
pub is_like_emscripten: bool,
561+
/// Whether the target toolchain is like Fuchsia's.
562+
pub is_like_fuchsia: bool,
561563
/// Whether the linker support GNU-like arguments such as -O. Defaults to false.
562564
pub linker_is_gnu: bool,
563565
/// The MinGW toolchain has a known issue that prevents it from correctly
@@ -723,6 +725,7 @@ impl Default for TargetOptions {
723725
is_like_android: false,
724726
is_like_emscripten: false,
725727
is_like_msvc: false,
728+
is_like_fuchsia: false,
726729
linker_is_gnu: false,
727730
allows_weak_linkage: true,
728731
has_rpath: false,
@@ -1013,6 +1016,7 @@ impl Target {
10131016
key!(is_like_msvc, bool);
10141017
key!(is_like_emscripten, bool);
10151018
key!(is_like_android, bool);
1019+
key!(is_like_fuchsia, bool);
10161020
key!(linker_is_gnu, bool);
10171021
key!(allows_weak_linkage, bool);
10181022
key!(has_rpath, bool);
@@ -1222,6 +1226,7 @@ impl ToJson for Target {
12221226
target_option_val!(is_like_msvc);
12231227
target_option_val!(is_like_emscripten);
12241228
target_option_val!(is_like_android);
1229+
target_option_val!(is_like_fuchsia);
12251230
target_option_val!(linker_is_gnu);
12261231
target_option_val!(allows_weak_linkage);
12271232
target_option_val!(has_rpath);

0 commit comments

Comments
 (0)