Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#114711 - lqd:linker-inference, r=petrochenkov
Infer `Lld::No` linker hint when the linker stem is a generic compiler driver This PR basically reverts the temporary solution in rust-lang#113631 to a more long-term solution. r? ``@petrochenkov`` In [this comment](rust-lang#113631 (comment)), you had ideas about a long-term solution: > I wonder what a good non-temporary solution for the inference would look like. > > * If the default is `(Cc::No, Lld::Yes)` (e.g. `rust-lld`) > > * and we switch to some specific platform compiler (e.g. `-C linker=arm-none-eabi-gcc`), should we change to `Lld::No`? Maybe yes? > * and we switch to some non-default but generic compiler `-C linker=clang`? Then maybe not? > > * If the default is `(Cc::Yes, Lld::Yes)` (e.g. future x86_64 linux with default LLD) > > * and we switch to some specific platform compiler (e.g. `-C linker=arm-none-eabi-gcc`), should we change to `Lld::No`? Maybe yes? > * and we switch to some non-default but generic compiler `-C linker=clang`? Then maybe not? > I believe that we should infer the `Lld::No` linker hint for any `-Clinker` override, and all the cases above: - the linker drivers have their own defaults, so in my mind `-Clinker` is a signal to use its default linker / flavor, rather than ours or the target's. In the case of generic compilers, it's more likely than not going to be `Lld::No`. I would expect this to be the case in general, even when including platform-specific compilers. - the guess will be wrong if the linker driver uses lld by default (and we also don't want to search for `-fuse-ld` link args), but will work in the more common cases. And the minority of other cases can fix the wrong guess by opting into the precise linker flavor. - this also ensures backwards-compatibility: today, even on targets with an lld default and overriding the linker, rustc will not use lld. That includes `thumbv6m-none-eabi` where issue rust-lang#113597 happened. It looks like the simplest option, and the one with least churn: we maintain the current behavior in ambiguous cases. I've tested that this works on rust-lang#113597, as expected from the failure. (I also have a no-std `run-make` test using a custom target json spec: basically simulating a future `x86_64-unknown-linux-gnu` using an lld flavor by default, to check that e.g. `-Clinker=clang` doesn't use lld. I could add that test to this PR, but IIUC such a custom target requires `cargo -Z build-std` and we have no tests depending on this cargo feature yet. Let me know if you want to add this test of the linker inference for such targets.) What do you think ?
- Loading branch information