Auto merge of #101792 - lqd:rust-lld, r=petrochenkov

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` argument is not needed on our current targets with a vanilla config to do so, but may be in some cases ?

That is, things look to be different and more subtle than suggested in https://github.com/rust-lang/rust/issues/97402#issuecomment-1147404520.

Specifying this argument unconditionally currently breaks `-Zgcc-ld=lld` on the 10.7+ targets on x64 macOS. Vanilla configs on x64 and aarch64 don't seem to need it to be able to find `rust-lld`.

This fixes #101653 on macOS (I've tried on x64 and aarch64: vanilla installs with the most recent command line tools available for each of the OS versions I have access to, `run-make/issue-71519` passes).

I didn't expect the previous PRs to fail because of the existing tests, but CI does not actually run those tests yet, which explains the regressions. I was hoping to fix those in this PR but it's more involved (building lld is required for the tests to run, llvm/lld is not built on the test builders but on the dist builders, the dist builders don't run tests). This PR is just to unblock current users on macOS who have reported issues, but a regression could happen in the future by mistake until then.

r? `@petrochenkov`
This commit is contained in:
bors 2023-01-03 14:05:44 +00:00
commit 312c9a37f2

View file

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