Skip to content

Commit 8aa9267

Browse files
committed
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.
2 parents 65e485d + 3d27aca commit 8aa9267

File tree

7 files changed

+28
-22
lines changed

7 files changed

+28
-22
lines changed

src/bootstrap/bin/rustc.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,9 @@ fn main() {
232232
// flesh out rpath support more fully in the future.
233233
cmd.arg("-Z").arg("osx-rpath-install-name");
234234
Some("-Wl,-rpath,@loader_path/../lib")
235-
} else if !target.contains("windows") && !target.contains("wasm32") {
235+
} else if !target.contains("windows") &&
236+
!target.contains("wasm32") &&
237+
!target.contains("fuchsia") {
236238
Some("-Wl,-rpath,$ORIGIN/../lib")
237239
} else {
238240
None

src/bootstrap/configure.py

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ def v(*args):
6868
o("profiler", "build.profiler", "build the profiler runtime")
6969
o("emscripten", None, "compile the emscripten backend as well as LLVM")
7070
o("full-tools", None, "enable all tools")
71+
o("lld", "rust.lld", "build lld")
7172
o("lldb", "rust.lldb", "build lldb")
7273
o("missing-tools", "dist.missing-tools", "allow failures when building tools")
7374

src/bootstrap/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,8 @@ impl Build {
837837
} else if target != self.config.build &&
838838
!target.contains("msvc") &&
839839
!target.contains("emscripten") &&
840-
!target.contains("wasm32") {
840+
!target.contains("wasm32") &&
841+
!target.contains("fuchsia") {
841842
Some(self.cc(target))
842843
} else {
843844
None

src/ci/docker/dist-various-2/Dockerfile

+12-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@ ENV \
4747
CC_x86_64_sun_solaris=x86_64-sun-solaris2.10-gcc \
4848
CXX_x86_64_sun_solaris=x86_64-sun-solaris2.10-g++
4949

50+
ENV CARGO_TARGET_X86_64_FUCHSIA_AR /usr/local/bin/llvm-ar
51+
ENV CARGO_TARGET_X86_64_FUCHSIA_RUSTFLAGS \
52+
-C link-arg=--sysroot=/usr/local/x86_64-fuchsia \
53+
-C link-arg=-L/usr/local/x86_64-fuchsia/lib \
54+
-C link-arg=-L/usr/local/lib/x86_64-fuchsia/lib
55+
ENV CARGO_TARGET_AARCH64_FUCHSIA_AR /usr/local/bin/llvm-ar
56+
ENV CARGO_TARGET_AARCH64_FUCHSIA_RUSTFLAGS \
57+
-C link-arg=--sysroot=/usr/local/aarch64-fuchsia \
58+
-C link-arg=-L/usr/local/aarch64-fuchsia/lib \
59+
-C link-arg=-L/usr/local/lib/aarch64-fuchsia/lib
60+
5061
ENV TARGETS=x86_64-fuchsia
5162
ENV TARGETS=$TARGETS,aarch64-fuchsia
5263
ENV TARGETS=$TARGETS,sparcv9-sun-solaris
@@ -55,5 +66,5 @@ ENV TARGETS=$TARGETS,x86_64-sun-solaris
5566
ENV TARGETS=$TARGETS,x86_64-unknown-linux-gnux32
5667
ENV TARGETS=$TARGETS,x86_64-unknown-cloudabi
5768

58-
ENV RUST_CONFIGURE_ARGS --enable-extended --disable-docs
69+
ENV RUST_CONFIGURE_ARGS --enable-extended --enable-lld --disable-docs
5970
ENV SCRIPT python2.7 ../x.py dist --target $TARGETS

src/librustc_target/spec/aarch64_fuchsia.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use spec::{LinkerFlavor, Target, TargetOptions, TargetResult};
11+
use spec::{LldFlavor, LinkerFlavor, Target, TargetOptions, TargetResult};
1212

1313
pub fn target() -> TargetResult {
1414
let mut base = super::fuchsia_base::opts();
@@ -24,7 +24,7 @@ pub fn target() -> TargetResult {
2424
target_os: "fuchsia".to_string(),
2525
target_env: String::new(),
2626
target_vendor: String::new(),
27-
linker_flavor: LinkerFlavor::Gcc,
27+
linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld),
2828
options: TargetOptions {
2929
abi_blacklist: super::arm_base::abi_blacklist(),
3030
.. base

src/librustc_target/spec/fuchsia_base.rs

+6-14
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,19 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use spec::{LinkArgs, LinkerFlavor, TargetOptions};
11+
use spec::{LldFlavor, LinkArgs, LinkerFlavor, TargetOptions};
1212
use std::default::Default;
1313

1414
pub fn opts() -> TargetOptions {
1515
let mut args = LinkArgs::new();
16-
args.insert(LinkerFlavor::Gcc, vec![
17-
// We want to be able to strip as much executable code as possible
18-
// from the linker command line, and this flag indicates to the
19-
// linker that it can avoid linking in dynamic libraries that don't
20-
// actually satisfy any symbols up to that point (as with many other
21-
// resolutions the linker does). This option only applies to all
22-
// following libraries so we're sure to pass it as one of the first
23-
// arguments.
24-
// FIXME: figure out whether these linker args are desirable
25-
//"-Wl,--as-needed".to_string(),
26-
27-
// Always enable NX protection when it is available
28-
//"-Wl,-z,noexecstack".to_string(),
16+
args.insert(LinkerFlavor::Lld(LldFlavor::Ld), vec![
17+
"--build-id".to_string(), "--hash-style=gnu".to_string(),
18+
"-z".to_string(), "rodynamic".to_string(),
2919
]);
3020

3121
TargetOptions {
22+
linker: Some("rust-lld".to_owned()),
23+
lld_flavor: LldFlavor::Ld,
3224
dynamic_linking: true,
3325
executables: true,
3426
target_family: Some("unix".to_string()),

src/librustc_target/spec/x86_64_fuchsia.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use spec::{LinkerFlavor, Target, TargetResult};
11+
use spec::{LldFlavor, LinkerFlavor, Target, TargetResult};
1212

1313
pub fn target() -> TargetResult {
1414
let mut base = super::fuchsia_base::opts();
1515
base.cpu = "x86-64".to_string();
1616
base.max_atomic_width = Some(64);
17-
base.pre_link_args.get_mut(&LinkerFlavor::Gcc).unwrap().push("-m64".to_string());
1817
base.stack_probes = true;
1918

2019
Ok(Target {
@@ -27,7 +26,7 @@ pub fn target() -> TargetResult {
2726
target_os: "fuchsia".to_string(),
2827
target_env: String::new(),
2928
target_vendor: String::new(),
30-
linker_flavor: LinkerFlavor::Gcc,
29+
linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld),
3130
options: base,
3231
})
3332
}

0 commit comments

Comments
 (0)