Skip to content

Commit 0f7702e

Browse files
committed
Pass -fuse-ld=/path/to/ld64 if -Z gcc-ld and the lld_flavor for the target is Ld64
1 parent a519095 commit 0f7702e

File tree

1 file changed

+33
-14
lines changed
  • compiler/rustc_codegen_ssa/src/back

1 file changed

+33
-14
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+33-14
Original file line numberDiff line numberDiff line change
@@ -2485,20 +2485,39 @@ fn add_gcc_ld_path(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
24852485
if let LinkerFlavor::Gcc = flavor {
24862486
match ld_impl {
24872487
LdImpl::Lld => {
2488-
let tools_path =
2489-
sess.host_filesearch(PathKind::All).get_tools_search_paths(false);
2490-
let lld_path = tools_path
2491-
.into_iter()
2492-
.map(|p| p.join("gcc-ld"))
2493-
.find(|p| {
2494-
p.join(if sess.host.is_like_windows { "ld.exe" } else { "ld" }).exists()
2495-
})
2496-
.unwrap_or_else(|| sess.fatal("rust-lld (as ld) not found"));
2497-
cmd.cmd().arg({
2498-
let mut arg = OsString::from("-B");
2499-
arg.push(lld_path);
2500-
arg
2501-
});
2488+
if sess.target.lld_flavor == LldFlavor::Ld64 {
2489+
let tools_path =
2490+
sess.host_filesearch(PathKind::All).get_tools_search_paths(false);
2491+
let ld64_exe = tools_path
2492+
.into_iter()
2493+
.map(|p| p.join("gcc-ld"))
2494+
.map(|p| {
2495+
p.join(if sess.host.is_like_windows { "ld64.exe" } else { "ld64" })
2496+
})
2497+
.find(|p| p.exists())
2498+
.unwrap_or_else(|| sess.fatal("rust-lld (as ld64) not found"));
2499+
cmd.cmd().arg({
2500+
let mut arg = OsString::from("-fuse-ld=");
2501+
arg.push(ld64_exe);
2502+
arg
2503+
});
2504+
} else {
2505+
let tools_path =
2506+
sess.host_filesearch(PathKind::All).get_tools_search_paths(false);
2507+
let lld_path = tools_path
2508+
.into_iter()
2509+
.map(|p| p.join("gcc-ld"))
2510+
.find(|p| {
2511+
p.join(if sess.host.is_like_windows { "ld.exe" } else { "ld" })
2512+
.exists()
2513+
})
2514+
.unwrap_or_else(|| sess.fatal("rust-lld (as ld) not found"));
2515+
cmd.cmd().arg({
2516+
let mut arg = OsString::from("-B");
2517+
arg.push(lld_path);
2518+
arg
2519+
});
2520+
}
25022521
}
25032522
}
25042523
} else {

0 commit comments

Comments
 (0)