rust/compiler/rustc_codegen_ssa/src
Guillaume Gomez f92974189b
Rollup merge of #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 https://github.com/rust-lang/rust/pull/113631 to a more long-term solution.

r? ``@petrochenkov``

In [this comment](https://github.com/rust-lang/rust/pull/113631#issuecomment-1634598238), 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 #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 #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 ?
2023-08-15 14:29:45 +02:00
..
back Rollup merge of #114711 - lqd:linker-inference, r=petrochenkov 2023-08-15 14:29:45 +02:00
debuginfo inline format!() args up to and including rustc_codegen_llvm 2023-07-30 14:22:50 +02:00
mir Rollup merge of #114505 - ouz-a:cleanup_mir, r=RalfJung 2023-08-06 17:26:29 +02:00
traits Auto merge of #105545 - erikdesjardins:ptrclean, r=bjorn3 2023-08-01 19:44:17 +00:00
base.rs rustc: Move crate_types from Session to GlobalCtxt 2023-08-09 14:17:54 +08:00
codegen_attrs.rs Add separate feature gate for async fn track caller 2023-08-02 14:18:21 -07:00
common.rs Promote unchecked_add/sub/mul/shl/shr to mir::BinOp 2023-06-19 01:47:03 -07:00
errors.rs inline format!() args up to and including rustc_codegen_llvm 2023-07-30 14:22:50 +02:00
glue.rs
lib.rs Remove unnecessary feature gates 2023-08-12 00:21:04 -04:00
meth.rs cg_ssa: remove pointee types and pointercast/bitcast-of-ptr 2023-07-29 13:18:20 -04:00
mono_item.rs inline format!() args up to and including rustc_codegen_llvm 2023-07-30 14:22:50 +02:00
target_features.rs add details for csky-unknown-linux-gnuabiv2 and add docs 2023-08-14 23:02:37 +08:00