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 clean up struct layout code 2023-07-06 13:04:13 +00:00
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 Lint against misplaced where-clauses on assoc tys in traits 2023-07-11 01:19:11 +02:00
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 Rename adjustment::PointerCast and variants using it to PointerCoercion 2023-07-07 18:17:16 +02:00
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 Dynamically size sigaltstk in rustc 2023-07-10 12:05:16 -07:00
rustc_error_codes
rustc_error_messages Require TAITs to be mentioned in the signatures of functions that register hidden types for them 2023-07-07 13:13:18 +00:00
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 Lint against misplaced where-clauses on assoc tys in traits 2023-07-11 01:19:11 +02:00
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 Replace RPITIT current impl with new strategy that lowers as a GAT 2023-07-08 18:21:34 -03:00
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 Replace RPITIT current impl with new strategy that lowers as a GAT 2023-07-08 18:21:34 -03:00
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 Auto merge of #112988 - spastorino:new-rpitit-24, r=compiler-errors 2023-07-10 19:01:30 +00:00
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 get rid of a bit more calls to poly_select 2023-07-06 16:50:12 +00:00
rustc_transmute
rustc_ty_utils Re-format let-else per rustfmt update 2023-07-12 21:49:27 -04:00
rustc_type_ir Add a new trait to Debug things with an infcx available 2023-07-06 11:36:39 +01:00