Skip to content

Commit c9870a4

Browse files
authored
Rollup merge of #56154 - petrhosek:fuchsia-linker-args, r=alexcrichton
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.
2 parents bf72971 + f41423c commit c9870a4

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

src/librustc_codegen_llvm/back/link.rs

Lines changed: 9 additions & 1 deletion
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

Lines changed: 10 additions & 4 deletions
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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,8 @@ pub struct TargetOptions {
560560
/// Emscripten toolchain.
561561
/// Defaults to false.
562562
pub is_like_emscripten: bool,
563+
/// Whether the target toolchain is like Fuchsia's.
564+
pub is_like_fuchsia: bool,
563565
/// Whether the linker support GNU-like arguments such as -O. Defaults to false.
564566
pub linker_is_gnu: bool,
565567
/// The MinGW toolchain has a known issue that prevents it from correctly
@@ -729,6 +731,7 @@ impl Default for TargetOptions {
729731
is_like_android: false,
730732
is_like_emscripten: false,
731733
is_like_msvc: false,
734+
is_like_fuchsia: false,
732735
linker_is_gnu: false,
733736
allows_weak_linkage: true,
734737
has_rpath: false,
@@ -1028,6 +1031,7 @@ impl Target {
10281031
key!(is_like_msvc, bool);
10291032
key!(is_like_emscripten, bool);
10301033
key!(is_like_android, bool);
1034+
key!(is_like_fuchsia, bool);
10311035
key!(linker_is_gnu, bool);
10321036
key!(allows_weak_linkage, bool);
10331037
key!(has_rpath, bool);
@@ -1238,6 +1242,7 @@ impl ToJson for Target {
12381242
target_option_val!(is_like_msvc);
12391243
target_option_val!(is_like_emscripten);
12401244
target_option_val!(is_like_android);
1245+
target_option_val!(is_like_fuchsia);
12411246
target_option_val!(linker_is_gnu);
12421247
target_option_val!(allows_weak_linkage);
12431248
target_option_val!(has_rpath);

0 commit comments

Comments
 (0)