rust-lang / rust-lang/rust

Tracking issue for turning unstable / incorrect `-Ctarget-feature` into a hard error

Open
#162,235 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-target-feature C-tracking-issue
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

When -Ctarget-feature was introduced, we allowed passing arbitrary LLVM target features. This turned out to be a mistake:

  • Some target features alter the ABI, so using them in -C flags is unsound as different crates with different values for those flags may be linked together.
  • LLVM can rename / remove target features, which is in conflict with our stability policy.

For #[target_feature] and cfg(target_feature), we were a lot more careful, and we only allow/expose explicitly stabilized target features. This issue is tracking our move towards doing the same with -Ctarget-feature. This means it will become a hard error to:

  • Use a target feature that we don't know at all.
  • Use a target feature that we know but is unstable.
  • Use a target feature that we know but is marked as "internal-only", i.e. it is not meant to be stabilized and just tracked for internal compiler purposes. This is usually done because the target feature alters the ABI or because LLVM chose to expose something as a target feature that rustc exposed via other knobs.
  • Use a target feature that we know and that is stable, but that would alter the ABI of the current target.

The intended immediate replacement for all of these is -Zllvm-target-feature. This is a target modifier, so we ensure that there are no ABI differences across crates that are being linked together. However, that also means it depends on -Zbuild-std to avoid ABI differences with the pre-built standard library. This means we will likely wait for both of those to stabilize before we turn this warning into a hard error.

The other possible replacement, at least for target features that actually are harmless on the ABI side, is to stabilize the relevant target features. If you cannot use nightly for some reason, this is the best way forward for you. Please let us know which target features are causing this FCW, and ideally help us stabilize them. :)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the behavior described for -Ctarget-feature, including the distinctions between unknown, unstable, internal-only, and ABI-affecting features. Review -Zllvm-target-feature and -Zbuild-std as the stated replacement path, along with the existing target_feature and cfg(target_feature) handling. Done means the transition plan is implemented so invalid or unsafe target features become hard errors without ABI differences across linked crates.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.