Skip to content

target_features: sse (or at least avx2) is incompatible with soft-float ABI - #160302

Open
RalfJung wants to merge 3 commits into
rust-lang:mainfrom
RalfJung:soft-float-no-avx2
Open

target_features: sse (or at least avx2) is incompatible with soft-float ABI#160302
RalfJung wants to merge 3 commits into
rust-lang:mainfrom
RalfJung:soft-float-no-avx2

Conversation

@RalfJung

@RalfJung RalfJung commented Jul 31, 2026

Copy link
Copy Markdown
Member

View all comments

Fixes #117938

Enabling both the avx2 and soft-float target features is not supported by LLVM and can crash the backend. Let's preempt that with rust-level checks. (I still think there's also an LLVM bug here, it shouldn't just SIGILL on unexpected target feature configurations, but that's a different discussion.)

What is not clear to me is whether this just affects just avx2 or also avx or even sse (we don't support mmx/3dnow separately). @dianqk do you know more about this? To be safe, let's reject "sse" and therefore by implication also all other x86 vector target features.

This PR turns #[target_feature(enable = "sse")] on a softfloat target into an FCW similar to what we do on aarch64 (see #135160). The FCW only affects people building for soft-float targets which is a fairly small percentage of our overall users (and which means we cannot meaningfully crater this). I hence went for "report in deps" immediately so that the people building the actual binaries see these warnings that their upstreams probably will never see.

@rustbot rustbot added 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 31, 2026
@rustbot

rustbot commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator

r? @khyperia

rustbot has assigned @khyperia.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

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

@RalfJung RalfJung changed the title target_featurs: avx2 is incompatible with soft-float ABI target_features: avx2 is incompatible with soft-float ABI Jul 31, 2026
@RalfJung

Copy link
Copy Markdown
Member Author

r? @workingjubilee or @dianqk

@rustbot

rustbot commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator

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

@RalfJung

Copy link
Copy Markdown
Member Author

Hm unfortunately it seems like LLVM does not crash on all functions with #[target_feature(enable = "avx2")]. This one for example works fine:

#[unsafe(no_mangle)]
#[target_feature(enable = "avx2")]
pub fn foobar(x: __m256i, y: __m256i) -> __m256i {
    _mm256_or_si256(x, y)
}

So we may have to add an FCW for this after all.

@tarcieri do you know which function is causing the trouble in dalek-cryptography/curve25519-dalek#601? All we know is that it's somewhere in poly1305...

@RalfJung

Copy link
Copy Markdown
Member Author

Okay I have a reproducer:

#![no_std]

use core::arch::x86_64::*;

#[unsafe(no_mangle)]
#[target_feature(enable = "avx2")]
pub fn foobar(ptr: *const __m256i) -> __m256i { unsafe {
    let key = _mm256_loadu_si256(ptr);
    _mm256_and_si256(
        _mm256_permutevar8x32_epi32(key, _mm256_set_epi32(3, 7, 2, 6, 1, 5, 0, 4)),
        _mm256_set_epi32(0, -1, 0, -1, 0, -1, 0, -1),
    )
}}

@RalfJung
RalfJung force-pushed the soft-float-no-avx2 branch 2 times, most recently from 58062d1 to 21a23e9 Compare July 31, 2026 20:47
@RalfJung RalfJung added the I-lang-nominated Nominated for discussion during a lang team meeting. label Jul 31, 2026
@RalfJung RalfJung changed the title target_features: avx2 is incompatible with soft-float ABI target_features: sse (or at least avx2) is incompatible with soft-float ABI Jul 31, 2026
@dianqk

dianqk commented Aug 1, 2026

Copy link
Copy Markdown
Member

I don't know these features on x86, but the PR seems reasonable to me.

@RalfJung

RalfJung commented Aug 1, 2026

Copy link
Copy Markdown
Member Author

With Nikita on vacation, who might know which features LLVM supports on x86 in combination with +soft-float?

But I guess we can also just warn about all vector features (as this PR does now) and if we get issues saying sse actually works fine we can always adjust. 🤷

@RalfJung

RalfJung commented Aug 1, 2026

Copy link
Copy Markdown
Member Author

FWIW the s390x target also has a "soft-float" target feature and there we already mark "vector" as incompatible.

ARM also has "soft-float" and there we don't mark anything. ARM also has much more explicit ABI control so maybe setting FloatABIType to "soft" and enabling neon actually works fine there? No idea.

@rust-bors

This comment has been minimized.

@RalfJung
RalfJung force-pushed the soft-float-no-avx2 branch from 21a23e9 to 5594310 Compare August 5, 2026 06:30
@rustbot

This comment has been minimized.

@traviscross traviscross added I-lang-radar Items that are on lang's radar and will need eventual work or consideration. P-lang-drag-1 Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang labels Aug 5, 2026
Comment thread compiler/rustc_lint_defs/src/builtin.rs
@traviscross traviscross added the T-lang Relevant to the language team label Aug 5, 2026
@traviscross

Copy link
Copy Markdown
Contributor

Makes sense to me. Thanks @RalfJung.

@rfcbot fcp merge lang

@rust-rfcbot

rust-rfcbot commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

@traviscross has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns.
See this document for info about what commands tagged team members can give me.

@rust-rfcbot rust-rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Aug 5, 2026
@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 22, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 22, 2026
…kingjubilee

target_features: sse (or at least avx2) is incompatible with soft-float ABI

Fixes rust-lang#117938

Enabling both the avx2 and soft-float target features is [not supported by LLVM](rust-lang#117938 (comment)) and can crash the backend. Let's preempt that with rust-level checks. (I still think there's also an LLVM bug here, it shouldn't just SIGILL on unexpected target feature configurations, but that's a different discussion.)

What is not clear to me is whether this just affects just avx2 or also avx or even sse (we don't support mmx/3dnow separately).  @dianqk do you know more about this? To be safe, let's reject "sse" and therefore by implication also all other x86 vector target features.

This PR turns `#[target_feature(enable = "sse")]` on a softfloat target into an FCW similar to what we do on aarch64 (see rust-lang#135160). The FCW only affects people building for soft-float targets which is a fairly small percentage of our overall users (and which means we cannot meaningfully crater this). I hence went for "report in deps" immediately so that the people building the actual binaries see these warnings that their upstreams probably will never see.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 22, 2026
…kingjubilee

target_features: sse (or at least avx2) is incompatible with soft-float ABI

Fixes rust-lang#117938

Enabling both the avx2 and soft-float target features is [not supported by LLVM](rust-lang#117938 (comment)) and can crash the backend. Let's preempt that with rust-level checks. (I still think there's also an LLVM bug here, it shouldn't just SIGILL on unexpected target feature configurations, but that's a different discussion.)

What is not clear to me is whether this just affects just avx2 or also avx or even sse (we don't support mmx/3dnow separately).  @dianqk do you know more about this? To be safe, let's reject "sse" and therefore by implication also all other x86 vector target features.

This PR turns `#[target_feature(enable = "sse")]` on a softfloat target into an FCW similar to what we do on aarch64 (see rust-lang#135160). The FCW only affects people building for soft-float targets which is a fairly small percentage of our overall users (and which means we cannot meaningfully crater this). I hence went for "report in deps" immediately so that the people building the actual binaries see these warnings that their upstreams probably will never see.
rust-bors Bot pushed a commit that referenced this pull request Aug 22, 2026
…uwer

Rollup of 7 pull requests

Successful merges:

 - #157513 (Reject non-constructor self types in const-arg tuple-call lowering)
 - #159887 (compiletest: forward disable-minification from bootstrap)
 - #160949 (Add floating point inline ASM support for SPARC)
 - #156160 (feat: add symmetric PartialEq impls for Vec, &[T], &mut [T] versus Cow<'_, [T]>)
 - #160302 (target_features: sse (or at least avx2) is incompatible with soft-float ABI)
 - #160914 (Derive `GenericTypeVisitable` for `RegionConstraint` _correctly_)
 - #161341 (be more permissive wrt overflow and and improve diagnostics)
@jhpratt

jhpratt commented Aug 22, 2026

Copy link
Copy Markdown
Member

@bors r- #161559 (comment)

@rust-bors rust-bors Bot 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Aug 22, 2026
@rust-bors

rust-bors Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

This pull request was unapproved.

This PR was contained in a rollup (#161559), which was unapproved.

View changes since this unapproval

@RalfJung
RalfJung force-pushed the soft-float-no-avx2 branch from 2c87740 to a6aa523 Compare August 23, 2026 11:57
@rustbot

rustbot commented Aug 23, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@RalfJung

Copy link
Copy Markdown
Member Author

Ah, hm, this is tricky... stdarch no longer builds on x86_64-unknown-none because it enables target features that must not be enabled on that target.

For now we can allow the lint. But we'll need something better long-term, something like #160301.

@rustbot

rustbot commented Aug 23, 2026

Copy link
Copy Markdown
Collaborator

stdarch is developed in its own repository. If possible, consider making this change to rust-lang/stdarch instead.

cc @Amanieu, @folkertdev, @sayantn

@RalfJung
RalfJung force-pushed the soft-float-no-avx2 branch from 85e8fea to 68c66e8 Compare August 23, 2026 12:10
@rustbot

rustbot commented Aug 23, 2026

Copy link
Copy Markdown
Collaborator

portable-simd is developed in its own repository. If possible, consider making this change to rust-lang/portable-simd instead.

cc @calebzulawski, @programmerjake

@RalfJung

Copy link
Copy Markdown
Member Author

@bors try jobs=dist-various*
@bors rollup=iffy

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Aug 23, 2026
target_features: sse (or at least avx2) is incompatible with soft-float ABI


try-job: dist-various*
@rust-bors

rust-bors Bot commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 58729dd (58729dd2855f18195fd476b08899b00a57ff537c)
Base parent: be0ea33 (be0ea33bba5000ac134e58acde780af83d908e44)

@RalfJung

Copy link
Copy Markdown
Member Author

@bors r=workingjubilee

@rust-bors

rust-bors Bot commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 68c66e8 has been approved by workingjubilee

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 23, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 23, 2026
…kingjubilee

target_features: sse (or at least avx2) is incompatible with soft-float ABI

Fixes rust-lang#117938

Enabling both the avx2 and soft-float target features is [not supported by LLVM](rust-lang#117938 (comment)) and can crash the backend. Let's preempt that with rust-level checks. (I still think there's also an LLVM bug here, it shouldn't just SIGILL on unexpected target feature configurations, but that's a different discussion.)

What is not clear to me is whether this just affects just avx2 or also avx or even sse (we don't support mmx/3dnow separately).  @dianqk do you know more about this? To be safe, let's reject "sse" and therefore by implication also all other x86 vector target features.

This PR turns `#[target_feature(enable = "sse")]` on a softfloat target into an FCW similar to what we do on aarch64 (see rust-lang#135160). The FCW only affects people building for soft-float targets which is a fairly small percentage of our overall users (and which means we cannot meaningfully crater this). I hence went for "report in deps" immediately so that the people building the actual binaries see these warnings that their upstreams probably will never see.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. I-lang-radar Items that are on lang's radar and will need eventual work or consideration. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team to-announce Announce this issue on triage meeting

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LLVM produces SIGILL when enabling avx2 target feature on x86_64-unknown-none