rust-lang / rust-lang/rust

It is unclear what combination of CPU features is safe.

Open
#124,949 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-docs A-target-feature C-discussion T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Location

https://doc.rust-lang.org/rustc/targets/known-issues.html

Summary

The linked page says:

Most target-feature problems arise, when mixing code that have the target-feature enabled with code that have it disabled. If you want to avoid undefined behavior, it is recommended to build all code (including the standard library and imported crates) with a common set of target-features.

By default, compiling your code with the -C target-feature flag will not recompile the entire standard library and/or imported crates with matching target features. Therefore, target features are generally considered as unsafe. Using #[target_feature] on individual functions makes the function unsafe.

Since this guide only provides examples of what's not okay (and calls them out explicitly as incomplete), and doesn't provide any guarantees about what is okay, a strict reading suggests that it's basically never okay to use target features at all (unless you are an expert on all the possible variations of your platform's ABI). A normal user who is not an expert has no way of knowing that any given feature is okay to enable so if they see these docs, they will have to be conservative and enable nothing.

I think this is an oversight, because I can't imagine that e.g. it's unacceptable/UB to enable mainstream SIMD features like AVX .

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 with the target-feature section in rustc/targets/known-issues.html and review the quoted guidance about mixing enabled and disabled code. The work is complete when the page explains which CPU-feature combinations are safe or provides clear guarantees beyond the current examples of unsafe usage.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers, documentation
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.