rust/compiler
Matthias Krüger fc1cb0459d
Rollup merge of #113631 - lqd:fix-113597, r=petrochenkov
make MCP510 behavior opt-in to avoid conflicts between the CLI and target flavors

Fixes #113597, which contains more details on how this happens through the code, and showcases an unexpected `Gnu(Cc::Yes, Lld::Yes)` flavor.

#112910 added support to use `lld` when the flavor requests it, but didn't explicitly do so only when using `-Clink-self-contained=+linker` or one of the unstable `-Clinker-flavor`s.

The problem: some targets have a `lld` linker and flavor, e.g. `thumbv6m-none-eabi` from that issue. Users can override the linker but there are no linker flavors precise enough to describe the linker opting out of lld: when using `-Clinker=arm-none-eabi-gcc`, we infer this is a `Cc::Yes` linker flavor, but the `lld` component is unknown and therefore defaulted to the target's linker flavor, `Lld::Yes`.

<details>
<summary>Walkthrough of how this happens</summary>

The linker flavor used is a mix between what can be inferred from the CLI (`-C linker`) and the target's default linker flavor:

- there is no linker flavor on the CLI (and that also offers another workaround on nightly: `-C linker-flavor=gnu-cc -Zunstable-options`), so it will have to be inferred [from here](5dac6b320b/compiler/rustc_codegen_ssa/src/back/link.rs (L1334-L1336)) to [here](5dac6b320b/compiler/rustc_codegen_ssa/src/back/link.rs (L1321-L1327)).
- in [`infer_linker_hints`](5dac6b320b/compiler/rustc_target/src/spec/mod.rs (L320-L352)) `-C linker=arm-none-eabi-gcc` infers a `Some(Cc::Yes)` cc hint, and no hint about lld.
- the target's `linker_flavor` is combined in `with_cli_hints` with these hints. We have our `Cc::Yes`, but there is no hint about lld, [so the target's flavor `lld` component is used](5dac6b320b/compiler/rustc_target/src/spec/mod.rs (L356-L358)). It's [`Gnu(Cc::No, Lld::Yes)`](993deaa0bf/compiler/rustc_target/src/spec/thumb_base.rs (L35)).
- so we now have our `Gnu(Cc::Yes, Lld::Yes)` flavor

</details>

This results in a `Gnu(Cc::Yes, Lld::Yes)` flavor on a non-lld linker, causing an additional unexpected `-fuse-ld=lld` argument to be passed.

I don't know if this target defaulting to `rust-lld` is expected, but until MCP510's new linker flavor are stable, when people will be able to describe their linker/flavor accurately, this PR keeps the stable behavior of not doing anything when the linker/flavor on the CLI unexpectedly conflict with the target's.

I've tested this on a `no_std` `-C linker=arm-none-eabi-gcc -C link-arg=-nostartfiles --target thumbv6m-none-eabi` example, trying to simulate one of `cortex-m`'s test mentioned in issue #113597 (I don't know how to build a local complete  `thumbv6m-none-eabi` toolchain to run the exact test), and checked that `-fuse-lld` was indeed gone and the error disappeared.

r? `````@petrochenkov`````
2023-07-13 22:33:25 +02:00
..
rustc
rustc_abi
rustc_apfloat
rustc_arena
rustc_ast Flip cfg's for bootstrap bump 2023-07-12 21:38:55 -04:00
rustc_ast_lowering Re-format let-else per rustfmt update 2023-07-12 21:49:27 -04:00
rustc_ast_passes
rustc_ast_pretty
rustc_attr
rustc_baked_icu_data
rustc_borrowck Re-format let-else per rustfmt update 2023-07-12 21:49:27 -04:00
rustc_builtin_macros Re-format let-else per rustfmt update 2023-07-12 21:49:27 -04:00
rustc_codegen_cranelift
rustc_codegen_gcc
rustc_codegen_llvm Re-format let-else per rustfmt update 2023-07-12 21:49:27 -04:00
rustc_codegen_ssa Rollup merge of #113631 - lqd:fix-113597, r=petrochenkov 2023-07-13 22:33:25 +02:00
rustc_const_eval Re-format let-else per rustfmt update 2023-07-12 21:49:27 -04:00
rustc_data_structures Re-format let-else per rustfmt update 2023-07-12 21:49:27 -04:00
rustc_driver
rustc_driver_impl
rustc_error_codes
rustc_error_messages
rustc_errors Re-format let-else per rustfmt update 2023-07-12 21:49:27 -04:00
rustc_expand Re-format let-else per rustfmt update 2023-07-12 21:49:27 -04:00
rustc_feature Replace version placeholder to 1.72 2023-07-12 21:24:05 -04:00
rustc_fluent_macro
rustc_fs_util
rustc_graphviz
rustc_hir Re-format let-else per rustfmt update 2023-07-12 21:49:27 -04:00
rustc_hir_analysis Re-format let-else per rustfmt update 2023-07-12 21:49:27 -04:00
rustc_hir_pretty
rustc_hir_typeck Auto merge of #113637 - Mark-Simulacrum:bootstrap-bump, r=ozkanonur 2023-07-13 18:15:14 +00:00
rustc_incremental Re-format let-else per rustfmt update 2023-07-12 21:49:27 -04:00
rustc_index Re-format let-else per rustfmt update 2023-07-12 21:49:27 -04:00
rustc_infer Re-format let-else per rustfmt update 2023-07-12 21:49:27 -04:00
rustc_interface Re-format let-else per rustfmt update 2023-07-12 21:49:27 -04:00
rustc_lexer
rustc_lint Re-format let-else per rustfmt update 2023-07-12 21:49:27 -04:00
rustc_lint_defs
rustc_llvm llvm-wrapper: adapt for LLVM API change 2023-07-12 09:30:31 +00:00
rustc_log
rustc_macros Re-format let-else per rustfmt update 2023-07-12 21:49:27 -04:00
rustc_metadata Re-format let-else per rustfmt update 2023-07-12 21:49:27 -04:00
rustc_middle Rollup merge of #113570 - lcnr:inspect-format, r=BoxyUwU 2023-07-13 22:33:24 +02:00
rustc_mir_build Re-format let-else per rustfmt update 2023-07-12 21:49:27 -04:00
rustc_mir_dataflow Re-format let-else per rustfmt update 2023-07-12 21:49:27 -04:00
rustc_mir_transform Re-format let-else per rustfmt update 2023-07-12 21:49:27 -04:00
rustc_monomorphize
rustc_parse Re-format let-else per rustfmt update 2023-07-12 21:49:27 -04:00
rustc_parse_format
rustc_passes Re-format let-else per rustfmt update 2023-07-12 21:49:27 -04:00
rustc_plugin_impl
rustc_privacy
rustc_query_impl
rustc_query_system
rustc_resolve Re-format let-else per rustfmt update 2023-07-12 21:49:27 -04:00
rustc_serialize
rustc_session
rustc_smir Rollup merge of #113629 - spastorino:smir-types-3, r=oli-obk 2023-07-13 22:33:25 +02:00
rustc_span Re-format let-else per rustfmt update 2023-07-12 21:49:27 -04:00
rustc_symbol_mangling
rustc_target
rustc_trait_selection Rollup merge of #113536 - lcnr:proof-tree-select, r=BoxyUwU 2023-07-13 22:33:23 +02:00
rustc_traits
rustc_transmute
rustc_ty_utils Re-format let-else per rustfmt update 2023-07-12 21:49:27 -04:00
rustc_type_ir