Skip to content

Commit 6fc21e5

Browse files
committed
Auto merge of #51936 - japaric:rust-lld, r=alexcrichton
rename rustc's lld to rust-lld to not shadow the system installed LLD when linking with LLD. Before: - `-C linker=lld -Z linker-flavor=ld.lld` uses rustc's LLD - It's not possible to use a system installed LLD that's named `lld` With this commit: - `-C linker=rust-lld -Z linker-flavor=ld.lld` uses rustc's LLD - `-C linker=lld -Z linker-flavor=ld.lld` uses the system installed LLD we don't offer guarantees about the availability of LLD in the rustc sysroot so we can rename the tool as long as we don't break the wasm32-unknown-unknown target which depends on it. r? @alexcrichton we discussed this before
2 parents c865d39 + 31ed5c7 commit 6fc21e5

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

src/bootstrap/compile.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -821,8 +821,11 @@ fn copy_lld_to_sysroot(builder: &Builder,
821821
.join("bin");
822822
t!(fs::create_dir_all(&dst));
823823

824-
let exe = exe("lld", &target);
825-
builder.copy(&lld_install_root.join("bin").join(&exe), &dst.join(&exe));
824+
let src_exe = exe("lld", &target);
825+
let dst_exe = exe("rust-lld", &target);
826+
// we prepend this bin directory to the user PATH when linking Rust binaries. To
827+
// avoid shadowing the system LLD we rename the LLD we provide to `rust-lld`.
828+
builder.copy(&lld_install_root.join("bin").join(&src_exe), &dst.join(&dst_exe));
826829
}
827830

828831
/// Cargo's output path for the standard library in a given stage, compiled

src/bootstrap/dist.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -493,12 +493,13 @@ impl Step for Rustc {
493493

494494
// Copy over lld if it's there
495495
if builder.config.lld_enabled {
496-
let exe = exe("lld", &compiler.host);
496+
let exe = exe("rust-lld", &compiler.host);
497497
let src = builder.sysroot_libdir(compiler, host)
498498
.parent()
499499
.unwrap()
500500
.join("bin")
501501
.join(&exe);
502+
// for the rationale about this rename check `compile::copy_lld_to_sysroot`
502503
let dst = image.join("lib/rustlib")
503504
.join(&*host)
504505
.join("bin")

src/librustc_target/spec/wasm32_unknown_unknown.rs

+3
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ pub fn target() -> Result<Target, String> {
5151
// no dynamic linking, no need for default visibility!
5252
default_hidden_visibility: true,
5353

54+
// we use the LLD shipped with the Rust toolchain by default
55+
linker: Some("rust-lld".to_owned()),
56+
5457
.. Default::default()
5558
};
5659
Ok(Target {

0 commit comments

Comments
 (0)