Auto merge of #55106 - petrhosek:fuchsia-lld, r=alexcrichton

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.
This commit is contained in:
bors 2018-11-06 01:20:58 +00:00
commit 8aa926729e
7 changed files with 28 additions and 22 deletions

View File

@ -232,7 +232,9 @@ fn main() {
// flesh out rpath support more fully in the future. // flesh out rpath support more fully in the future.
cmd.arg("-Z").arg("osx-rpath-install-name"); cmd.arg("-Z").arg("osx-rpath-install-name");
Some("-Wl,-rpath,@loader_path/../lib") 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") Some("-Wl,-rpath,$ORIGIN/../lib")
} else { } else {
None None

View File

@ -68,6 +68,7 @@ o("cargo-native-static", "build.cargo-native-static", "static native libraries i
o("profiler", "build.profiler", "build the profiler runtime") o("profiler", "build.profiler", "build the profiler runtime")
o("emscripten", None, "compile the emscripten backend as well as LLVM") o("emscripten", None, "compile the emscripten backend as well as LLVM")
o("full-tools", None, "enable all tools") o("full-tools", None, "enable all tools")
o("lld", "rust.lld", "build lld")
o("lldb", "rust.lldb", "build lldb") o("lldb", "rust.lldb", "build lldb")
o("missing-tools", "dist.missing-tools", "allow failures when building tools") o("missing-tools", "dist.missing-tools", "allow failures when building tools")

View File

@ -837,7 +837,8 @@ impl Build {
} else if target != self.config.build && } else if target != self.config.build &&
!target.contains("msvc") && !target.contains("msvc") &&
!target.contains("emscripten") && !target.contains("emscripten") &&
!target.contains("wasm32") { !target.contains("wasm32") &&
!target.contains("fuchsia") {
Some(self.cc(target)) Some(self.cc(target))
} else { } else {
None None

View File

@ -47,6 +47,17 @@ ENV \
CC_x86_64_sun_solaris=x86_64-sun-solaris2.10-gcc \ CC_x86_64_sun_solaris=x86_64-sun-solaris2.10-gcc \
CXX_x86_64_sun_solaris=x86_64-sun-solaris2.10-g++ 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=x86_64-fuchsia
ENV TARGETS=$TARGETS,aarch64-fuchsia ENV TARGETS=$TARGETS,aarch64-fuchsia
ENV TARGETS=$TARGETS,sparcv9-sun-solaris 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-linux-gnux32
ENV TARGETS=$TARGETS,x86_64-unknown-cloudabi 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 ENV SCRIPT python2.7 ../x.py dist --target $TARGETS

View File

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use spec::{LinkerFlavor, Target, TargetOptions, TargetResult}; use spec::{LldFlavor, LinkerFlavor, Target, TargetOptions, TargetResult};
pub fn target() -> TargetResult { pub fn target() -> TargetResult {
let mut base = super::fuchsia_base::opts(); let mut base = super::fuchsia_base::opts();
@ -24,7 +24,7 @@ pub fn target() -> TargetResult {
target_os: "fuchsia".to_string(), target_os: "fuchsia".to_string(),
target_env: String::new(), target_env: String::new(),
target_vendor: String::new(), target_vendor: String::new(),
linker_flavor: LinkerFlavor::Gcc, linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld),
options: TargetOptions { options: TargetOptions {
abi_blacklist: super::arm_base::abi_blacklist(), abi_blacklist: super::arm_base::abi_blacklist(),
.. base .. base

View File

@ -8,27 +8,19 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use spec::{LinkArgs, LinkerFlavor, TargetOptions}; use spec::{LldFlavor, LinkArgs, LinkerFlavor, TargetOptions};
use std::default::Default; use std::default::Default;
pub fn opts() -> TargetOptions { pub fn opts() -> TargetOptions {
let mut args = LinkArgs::new(); let mut args = LinkArgs::new();
args.insert(LinkerFlavor::Gcc, vec![ args.insert(LinkerFlavor::Lld(LldFlavor::Ld), vec![
// We want to be able to strip as much executable code as possible "--build-id".to_string(), "--hash-style=gnu".to_string(),
// from the linker command line, and this flag indicates to the "-z".to_string(), "rodynamic".to_string(),
// 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(),
]); ]);
TargetOptions { TargetOptions {
linker: Some("rust-lld".to_owned()),
lld_flavor: LldFlavor::Ld,
dynamic_linking: true, dynamic_linking: true,
executables: true, executables: true,
target_family: Some("unix".to_string()), target_family: Some("unix".to_string()),

View File

@ -8,13 +8,12 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use spec::{LinkerFlavor, Target, TargetResult}; use spec::{LldFlavor, LinkerFlavor, Target, TargetResult};
pub fn target() -> TargetResult { pub fn target() -> TargetResult {
let mut base = super::fuchsia_base::opts(); let mut base = super::fuchsia_base::opts();
base.cpu = "x86-64".to_string(); base.cpu = "x86-64".to_string();
base.max_atomic_width = Some(64); base.max_atomic_width = Some(64);
base.pre_link_args.get_mut(&LinkerFlavor::Gcc).unwrap().push("-m64".to_string());
base.stack_probes = true; base.stack_probes = true;
Ok(Target { Ok(Target {
@ -27,7 +26,7 @@ pub fn target() -> TargetResult {
target_os: "fuchsia".to_string(), target_os: "fuchsia".to_string(),
target_env: String::new(), target_env: String::new(),
target_vendor: String::new(), target_vendor: String::new(),
linker_flavor: LinkerFlavor::Gcc, linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld),
options: base, options: base,
}) })
} }