Skip to content

Commit

Permalink
Auto merge of #55106 - petrhosek:fuchsia-lld, r=alexcrichton
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed Nov 6, 2018
2 parents 65e485d + 3d27aca commit 8aa9267
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 22 deletions.
4 changes: 3 additions & 1 deletion src/bootstrap/bin/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/bootstrap/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
3 changes: 2 additions & 1 deletion src/bootstrap/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,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
Expand Down
13 changes: 12 additions & 1 deletion src/ci/docker/dist-various-2/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
4 changes: 2 additions & 2 deletions src/librustc_target/spec/aarch64_fuchsia.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
Expand Down
20 changes: 6 additions & 14 deletions src/librustc_target/spec/fuchsia_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down
5 changes: 2 additions & 3 deletions src/librustc_target/spec/x86_64_fuchsia.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
})
}

0 comments on commit 8aa9267

Please sign in to comment.