From 3d27aca841273c710414f81655c7f2cdf184e562 Mon Sep 17 00:00:00 2001 From: Petr Hosek Date: Mon, 15 Oct 2018 17:27:07 -0700 Subject: [PATCH] Use lld directly for Fuchsia target Fuchsia already uses lld as the default linker, so there's no reason to always invoke it through Clang, instead we can simply invoke lld directly and pass the set of flags that matches Clang. --- src/bootstrap/bin/rustc.rs | 4 +++- src/bootstrap/configure.py | 1 + src/bootstrap/lib.rs | 3 ++- src/ci/docker/dist-various-2/Dockerfile | 13 ++++++++++++- src/librustc_target/spec/aarch64_fuchsia.rs | 4 ++-- src/librustc_target/spec/fuchsia_base.rs | 20 ++++++-------------- src/librustc_target/spec/x86_64_fuchsia.rs | 5 ++--- 7 files changed, 28 insertions(+), 22 deletions(-) diff --git a/src/bootstrap/bin/rustc.rs b/src/bootstrap/bin/rustc.rs index b6764c1aaeab6..a97c88336e427 100644 --- a/src/bootstrap/bin/rustc.rs +++ b/src/bootstrap/bin/rustc.rs @@ -232,7 +232,9 @@ fn main() { // flesh out rpath support more fully in the future. cmd.arg("-Z").arg("osx-rpath-install-name"); Some("-Wl,-rpath,@loader_path/../lib") - } else if !target.contains("windows") && !target.contains("wasm32") { + } else if !target.contains("windows") && + !target.contains("wasm32") && + !target.contains("fuchsia") { Some("-Wl,-rpath,$ORIGIN/../lib") } else { None diff --git a/src/bootstrap/configure.py b/src/bootstrap/configure.py index ddb894eb1f659..58525d0fc1a92 100755 --- a/src/bootstrap/configure.py +++ b/src/bootstrap/configure.py @@ -68,6 +68,7 @@ def v(*args): o("profiler", "build.profiler", "build the profiler runtime") o("emscripten", None, "compile the emscripten backend as well as LLVM") o("full-tools", None, "enable all tools") +o("lld", "rust.lld", "build lld") o("lldb", "rust.lldb", "build lldb") o("missing-tools", "dist.missing-tools", "allow failures when building tools") diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index ba601249ea895..ea9d5bf3fa05c 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -843,7 +843,8 @@ impl Build { } else if target != self.config.build && !target.contains("msvc") && !target.contains("emscripten") && - !target.contains("wasm32") { + !target.contains("wasm32") && + !target.contains("fuchsia") { Some(self.cc(target)) } else { None diff --git a/src/ci/docker/dist-various-2/Dockerfile b/src/ci/docker/dist-various-2/Dockerfile index 7adb32efa1d41..944c2a51b8d1f 100644 --- a/src/ci/docker/dist-various-2/Dockerfile +++ b/src/ci/docker/dist-various-2/Dockerfile @@ -47,6 +47,17 @@ ENV \ CC_x86_64_sun_solaris=x86_64-sun-solaris2.10-gcc \ CXX_x86_64_sun_solaris=x86_64-sun-solaris2.10-g++ +ENV CARGO_TARGET_X86_64_FUCHSIA_AR /usr/local/bin/llvm-ar +ENV CARGO_TARGET_X86_64_FUCHSIA_RUSTFLAGS \ +-C link-arg=--sysroot=/usr/local/x86_64-fuchsia \ +-C link-arg=-L/usr/local/x86_64-fuchsia/lib \ +-C link-arg=-L/usr/local/lib/x86_64-fuchsia/lib +ENV CARGO_TARGET_AARCH64_FUCHSIA_AR /usr/local/bin/llvm-ar +ENV CARGO_TARGET_AARCH64_FUCHSIA_RUSTFLAGS \ +-C link-arg=--sysroot=/usr/local/aarch64-fuchsia \ +-C link-arg=-L/usr/local/aarch64-fuchsia/lib \ +-C link-arg=-L/usr/local/lib/aarch64-fuchsia/lib + ENV TARGETS=x86_64-fuchsia ENV TARGETS=$TARGETS,aarch64-fuchsia ENV TARGETS=$TARGETS,sparcv9-sun-solaris @@ -55,5 +66,5 @@ ENV TARGETS=$TARGETS,x86_64-sun-solaris ENV TARGETS=$TARGETS,x86_64-unknown-linux-gnux32 ENV TARGETS=$TARGETS,x86_64-unknown-cloudabi -ENV RUST_CONFIGURE_ARGS --enable-extended --disable-docs +ENV RUST_CONFIGURE_ARGS --enable-extended --enable-lld --disable-docs ENV SCRIPT python2.7 ../x.py dist --target $TARGETS diff --git a/src/librustc_target/spec/aarch64_fuchsia.rs b/src/librustc_target/spec/aarch64_fuchsia.rs index 8f7ee11d575ee..9ef4fe3b3af4b 100644 --- a/src/librustc_target/spec/aarch64_fuchsia.rs +++ b/src/librustc_target/spec/aarch64_fuchsia.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use spec::{LinkerFlavor, Target, TargetOptions, TargetResult}; +use spec::{LldFlavor, LinkerFlavor, Target, TargetOptions, TargetResult}; pub fn target() -> TargetResult { let mut base = super::fuchsia_base::opts(); @@ -24,7 +24,7 @@ pub fn target() -> TargetResult { target_os: "fuchsia".to_string(), target_env: String::new(), target_vendor: String::new(), - linker_flavor: LinkerFlavor::Gcc, + linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld), options: TargetOptions { abi_blacklist: super::arm_base::abi_blacklist(), .. base diff --git a/src/librustc_target/spec/fuchsia_base.rs b/src/librustc_target/spec/fuchsia_base.rs index b593b83532614..8c20755492e31 100644 --- a/src/librustc_target/spec/fuchsia_base.rs +++ b/src/librustc_target/spec/fuchsia_base.rs @@ -8,27 +8,19 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use spec::{LinkArgs, LinkerFlavor, TargetOptions}; +use spec::{LldFlavor, LinkArgs, LinkerFlavor, TargetOptions}; use std::default::Default; pub fn opts() -> TargetOptions { let mut args = LinkArgs::new(); - args.insert(LinkerFlavor::Gcc, vec![ - // We want to be able to strip as much executable code as possible - // from the linker command line, and this flag indicates to the - // linker that it can avoid linking in dynamic libraries that don't - // actually satisfy any symbols up to that point (as with many other - // resolutions the linker does). This option only applies to all - // following libraries so we're sure to pass it as one of the first - // arguments. - // FIXME: figure out whether these linker args are desirable - //"-Wl,--as-needed".to_string(), - - // Always enable NX protection when it is available - //"-Wl,-z,noexecstack".to_string(), + args.insert(LinkerFlavor::Lld(LldFlavor::Ld), vec![ + "--build-id".to_string(), "--hash-style=gnu".to_string(), + "-z".to_string(), "rodynamic".to_string(), ]); TargetOptions { + linker: Some("rust-lld".to_owned()), + lld_flavor: LldFlavor::Ld, dynamic_linking: true, executables: true, target_family: Some("unix".to_string()), diff --git a/src/librustc_target/spec/x86_64_fuchsia.rs b/src/librustc_target/spec/x86_64_fuchsia.rs index 62148a740dff5..08df78d0db05d 100644 --- a/src/librustc_target/spec/x86_64_fuchsia.rs +++ b/src/librustc_target/spec/x86_64_fuchsia.rs @@ -8,13 +8,12 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use spec::{LinkerFlavor, Target, TargetResult}; +use spec::{LldFlavor, LinkerFlavor, Target, TargetResult}; pub fn target() -> TargetResult { let mut base = super::fuchsia_base::opts(); base.cpu = "x86-64".to_string(); base.max_atomic_width = Some(64); - base.pre_link_args.get_mut(&LinkerFlavor::Gcc).unwrap().push("-m64".to_string()); base.stack_probes = true; Ok(Target { @@ -27,7 +26,7 @@ pub fn target() -> TargetResult { target_os: "fuchsia".to_string(), target_env: String::new(), target_vendor: String::new(), - linker_flavor: LinkerFlavor::Gcc, + linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld), options: base, }) }