Skip to content

Add -Zllvm-target-feature target *modifier* to directly set LLVM-level target features, and deprecate doing that with -Ctarget-feature #994

@RalfJung

Description

@RalfJung

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:

  • File an issue describing the proposal.
  • A compiler team member who is knowledgeable in the area can second by writing @rustbot second or kickoff a team FCP with @rfcbot fcp $RESOLUTION.
  • Once an MCP is seconded, the Final Comment Period begins.
    • Final Comment Period lasts for 10 days after all outstanding concerns are solved.
    • Outstanding concerns will block the Final Comment Period from finishing. Once all concerns are resolved, the 10 day countdown is restarted.
    • If no concerns are raised after 10 days since the resolution of the last outstanding concern, the MCP is considered approved.

You can read more about Major Change Proposals on forge.

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-compilerAdd this label so rfcbot knows to poll the compiler teammajor-changeA proposal to make a major change to rustcmajor-change-acceptedA major change proposal that was accepted

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions