Skip to content

Add -Zllvm-target-feature to pass features directly to LLVM - #159545

Draft
fo40225 wants to merge 1 commit into
rust-lang:mainfrom
fo40225:Zllvm-target-feature
Draft

Add -Zllvm-target-feature to pass features directly to LLVM#159545
fo40225 wants to merge 1 commit into
rust-lang:mainfrom
fo40225:Zllvm-target-feature

Conversation

@fo40225

@fo40225 fo40225 commented Jul 19, 2026

Copy link
Copy Markdown

-Ctarget-feature passes unrecognized features through to LLVM with a warning.

Users who need LLVM-only features (e.g. the Linux kernel) must either tolerate the warning or resort to JSON target specs.

This flag provides a dedicated mechanism, registered as a target modifier.

Tracking issue: #157753

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 19, 2026
@rustbot

rustbot commented Jul 19, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust Project is excited to review your changes, and you should hear from @nnethercote (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue
Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 74 candidates
  • Random selection from 17 candidates

@workingjubilee workingjubilee left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The warning-based passthrough is unsound to rely on

I do not understand what you mean by "unsound" here, @fo40225.

It is undesirable to rely on.

Passing target features at all, however, is simply prone to being unsound, because LLVM can have arbitrary semantics for "target features" that do not accord with the model adopted for Rust target features. It is not relying on the passthrough that is unsound.

Anyways, please rewrite your entire PR description for conciseness. Or, if you had something else "write" it, then actually do so for the first time. Either way, I do not need to be regaled with the minutiae of every test if I can read the code. That entire PR description will become a commit in our repo, so please account for people staring at it in their terminal window after tapping out git status.

Also, please split out the addition of the future compatibility warning. This does not need to, and should not, all happen in one PR. Make this add -Zllvm-target-feature only.

View changes since this review

features in the form `+feat` or `-feat`, for example:

```sh
rustc -Zllvm-target-feature=+prefer-256-bit main.rs

@workingjubilee workingjubilee Jul 19, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example should exemplify the multi-feature case (either in the same invocation or in another).

```

Each feature string is forwarded verbatim to LLVM. This allows using LLVM target features
that are not (or not yet) part of Rust's target feature system, for example to match the

@workingjubilee workingjubilee Jul 19, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be less ambiguous: some things LLVM calls "target features" should never be part of ours, because they e.g. are incoherent with target_feature(enable), which allows adding them on a per-function basis, and only make sense as whole-program modifiers.

@fo40225
fo40225 marked this pull request as draft July 19, 2026 23:35
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 19, 2026
@nnethercote

Copy link
Copy Markdown
Contributor

r? @workingjubilee

@rustbot

rustbot commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator

workingjubilee is currently at their maximum review capacity.
They may take a while to respond.

Tracking issue: 157753
@fo40225
fo40225 force-pushed the Zllvm-target-feature branch from b9d5330 to 3f5cc28 Compare July 25, 2026 14:38
@fo40225

fo40225 commented Jul 25, 2026

Copy link
Copy Markdown
Author

I've found it difficult to implement this functionality reasonably. My thoughts are as follows:

Scenario 1: -Zllvm-target-feature does not affect target-feature.

This completely breaks the functionality of target-feature, making its behavior completely unpredictable. The compiler frontend and backend will not be able to cooperate.

Scenario 2: -Zllvm-target-feature affects target-feature.

Design A: Maintain a mapping table between Rust target-feature and compiler target-feature. However, this requires a separate table for each compiler. Updates or additions to the backend by the compiler will require significant maintenance, especially if designed as -Zcodegen-target-feature.

Design B: Directly change target-feature to the compiler name. However, different compilers (llvm, gcc, and even others) may have different target-feature names. This would make the source code incompatible with cross-compiler backends.

Unless there are other new design guidelines, I will abandon this PR.

@RalfJung

RalfJung commented Aug 3, 2026

Copy link
Copy Markdown
Member

I only just saw this, after already implementing the same thing myself in #160457. Please post in the tracking issue when a PR is opened to avoid duplicate work.

I am not sure which problem you are talking about in your last comment.

Scenario 1: -Zllvm-target-feature does not affect target-feature.

What's target-feature?

a mapping table between Rust target-feature and compiler target-feature

Rust is the compiler, so what are you talking about?

@rust-bors

rust-bors Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #160517) made this pull request unmergeable. Please resolve the merge conflicts by rebasing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants