Skip to content

Pass additional linker flags when targeting Fuchsia #56154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/librustc_codegen_llvm/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use super::rpath::RPathConfig;
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;
Expand Down Expand Up @@ -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 {
Expand Down
14 changes: 10 additions & 4 deletions src/librustc_target/spec/fuchsia_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ use spec::{LldFlavor, LinkArgs, LinkerFlavor, TargetOptions};
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(),
]);

Expand All @@ -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()
Copy link
Member

@cramertj cramertj Nov 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@petrhosek @alexcrichton This is causing Scrt1.o to be looked for inside lib/rustlib/x86_64-fuchisa/lib (the Rust sysroot) which is where liballoc, libcore, libcompiler_builtins, etc. live, not in the system sysroot where Scrt1.o lives.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is because of some windows support, see src/rtstartup.

],
position_independent_executables: true,
has_elf_tls: true,
.. Default::default()
Expand Down
5 changes: 5 additions & 0 deletions src/librustc_target/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -723,6 +725,7 @@ impl Default for 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,
Expand Down Expand Up @@ -1013,6 +1016,7 @@ impl Target {
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);
Expand Down Expand Up @@ -1222,6 +1226,7 @@ impl ToJson for Target {
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);
Expand Down