Proposal
-Ctarget-feature is currently used for two somewhat different roles:
- To set Rust target features (i.e. target features listed in this table). These often but not always have the same name as LLVM target features.
- To directly set LLVM target features. Any feature not recognized by that table is forwarded verbatim to the backend with a warning.
Things work this way because a long time ago we decided that LLVM target features should be exposed by rustc even if we haven't officially stabilized them -- there's just too many of them to have everyone wait until we slowly stabilize. However, the problem with this approach is that we allow mixing different values for -Ctarget-feature in the same binary, which can be unsound as LLVM target features can affect the ABI. Consequently, we emit a warning. That warning is a no-go for the Linux kernel folks so they use a JSON target spec to configure their x86 target features. JSON target specs are incredibly unstable and having the kernel rely on that is Suboptimal, which motivates the introduction of an alternative mechanism for setting LLVM-level target features.
So, I propose we add a new flag, initially -Zllvm-target-feature (and eventually -Mllvm-target-feature or -Tllvm-target-feature if we go with one of those conventions for target modifiers), that just directly forwards target features to LLVM. We register this flag as a target modifier to avoid potential ABI issues. We also change the warning emitted for unknown features in -Ctarget-feature to be explicitly a future-compat warning, and eventually we make unknown features in -Ctarget-feature a hard error.
The main thing to figure out / bikeshed is the name of the flag. As-is, it ignores the existence of other codegen backends. OTOH, that is consistent with -Cllvm-args. Also, the names of target features differ across backends (that's one reason why we now have a concept of "Rust feature names"). So while we could call it -Zcodegen-target-feature, the value would have to be adjusted to match the active codegen backend (and when mixing different codegen backends in the same binary, we'd still force the same string to be used for all of them).
Process
The main points of the Major Change Process are as follows:
You can read more about Major Change Proposals on forge.
Proposal
-Ctarget-featureis currently used for two somewhat different roles:Things work this way because a long time ago we decided that LLVM target features should be exposed by rustc even if we haven't officially stabilized them -- there's just too many of them to have everyone wait until we slowly stabilize. However, the problem with this approach is that we allow mixing different values for
-Ctarget-featurein the same binary, which can be unsound as LLVM target features can affect the ABI. Consequently, we emit a warning. That warning is a no-go for the Linux kernel folks so they use a JSON target spec to configure their x86 target features. JSON target specs are incredibly unstable and having the kernel rely on that is Suboptimal, which motivates the introduction of an alternative mechanism for setting LLVM-level target features.So, I propose we add a new flag, initially
-Zllvm-target-feature(and eventually-Mllvm-target-featureor-Tllvm-target-featureif we go with one of those conventions for target modifiers), that just directly forwards target features to LLVM. We register this flag as a target modifier to avoid potential ABI issues. We also change the warning emitted for unknown features in-Ctarget-featureto be explicitly a future-compat warning, and eventually we make unknown features in-Ctarget-featurea hard error.The main thing to figure out / bikeshed is the name of the flag. As-is, it ignores the existence of other codegen backends. OTOH, that is consistent with
-Cllvm-args. Also, the names of target features differ across backends (that's one reason why we now have a concept of "Rust feature names"). So while we could call it-Zcodegen-target-feature, the value would have to be adjusted to match the active codegen backend (and when mixing different codegen backends in the same binary, we'd still force the same string to be used for all of them).Process
The main points of the Major Change Process are as follows:
@rustbot secondor kickoff a team FCP with@rfcbot fcp $RESOLUTION.You can read more about Major Change Proposals on forge.