Skip to content

Commit 7770b06

Browse files
committed
only specify --target by default for -Zgcc-ld=lld on wasm
On macOS, it's not yet clear which cases of clang/OS/target/SDK version impact how to find ld/lld/rust-lld. The --target is not needed on our current targets with a vanilla config, but may be in some cases. Specifying it all the time breaks the 10.7+ targets on x64 macOS. We try to only specify it on macOS if the linker flavors are different, for possible cases of cross-compilation with `-Zgcc-ld=lld` but the expectation is that it should be passed manually when needed in these situations.
1 parent d6f99e5 commit 7770b06

File tree

1 file changed

+20
-1
lines changed
  • compiler/rustc_codegen_ssa/src/back

1 file changed

+20
-1
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+20-1
Original file line numberDiff line numberDiff line change
@@ -2822,11 +2822,30 @@ fn add_gcc_ld_path(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
28222822
// Implement the "linker flavor" part of -Zgcc-ld
28232823
// by asking cc to use some kind of lld.
28242824
cmd.arg("-fuse-ld=lld");
2825+
28252826
if !flavor.is_gnu() {
28262827
// Tell clang to use a non-default LLD flavor.
28272828
// Gcc doesn't understand the target option, but we currently assume
28282829
// that gcc is not used for Apple and Wasm targets (#97402).
2829-
cmd.arg(format!("--target={}", sess.target.llvm_target));
2830+
//
2831+
// Note that we don't want to do that by default on macOS: e.g. passing a
2832+
// 10.7 target to LLVM works, but not to recent versions of clang/macOS, as
2833+
// shown in issue #101653 and the discussion in PR #101792.
2834+
//
2835+
// It could be required in some cases of cross-compiling with
2836+
// `-Zgcc-ld=lld`, but this is generally unspecified, and we don't know
2837+
// which specific versions of clang, macOS SDK, host and target OS
2838+
// combinations impact us here.
2839+
//
2840+
// So we do a simple first-approximation until we know more of what the
2841+
// Apple targets require (and which would be handled prior to hitting this
2842+
// `-Zgcc-ld=lld` codepath anyway), but the expectation is that until then
2843+
// this should be manually passed if needed. We specify the target when
2844+
// targeting a different linker flavor on macOS, and that's also always
2845+
// the case when targeting WASM.
2846+
if sess.target.linker_flavor != sess.host.linker_flavor {
2847+
cmd.arg(format!("--target={}", sess.target.llvm_target));
2848+
}
28302849
}
28312850
}
28322851
}

0 commit comments

Comments
 (0)