Skip to content

It is unclear what combination of CPU features is safe. #124949

Open
@umanwizard

Description

@umanwizard

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 .

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsA-target-featureArea: Enabling/disabling target features like AVX, Neon, etc.C-discussionCategory: Discussion or questions that doesn't represent real issues.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions