Re: [PATCH] x86/build/64: Prevent native builds from generating APX instructions
From: Chang S. Bae
Date: Tue Jul 14 2026 - 18:15:54 EST
On 7/9/2026 5:36 AM, Miguel Ojeda wrote:
On Wed, Jul 8, 2026 at 11:40 PM Chang S. Bae <chang.seok.bae@xxxxxxxxx> wrote:
+ KBUILD_RUSTFLAGS += -Ctarget-cpu=native $(if $(call rust-min-version,109100),-Ctarget-feature=-apxf,)
Hmm... I don't think this was tested?
There is a missing `c` there -- the flag is never going to get passed.
Ouch. :(
And while it is true that `rustc` knows about the target feature since
1.88.0, it will (sadly) still loudly warn about it:
warning: unstable feature specified for `-Ctarget-feature`: `apxf`
|
= note: this feature is not stably supported; its behavior can
change in the future
Instead, we should be able to do it in the custom target spec, i.e. in
`scripts/generate_rust_target.rs`, assuming `-Ctarget-cpu=native`
enables it and we need to override it. But please double-check the
interaction between those and test that LLVM is actually getting the
right set of features you want.
I did some investigation [*] into the APX code generation across Rust versions. A few notable observations:
* Rust 1.88 is the first release to recognizes the apxf target feature.
Prior to that, when LLVM supports APX, target-cpu=native appears to
allow APX code generation.
* Starting with Rust 1.95, target-cpu=native no longer appears to
enable APX instruction generation even without explicitly disabling
apxf. However, this seems to be implementation-specific and could
change in future releases.
* Passing target-feature=-apxf currently emits the warning you quoted
because the feature is still unstable. Using the generated target
JSON avoids the warning but Rust versions prior to 1.93 instead
produce another noise:
'-apxf' is not a recognized feature for this target ...
Given that, the goal here is to disable APX without build warnings. Rust
1.93 needs to be the minimum version via the generated target JSON.
Indeed. This is very helpful!
Finally, we are trying to get rid of the custom target and instead use
flags as soon as possible, so if the flag will be eventually needed,
then it should be stabilized.
To help with that, I have tagged the tracking issue with our Rust for
Linux tag and will raise it to them in our next meeting, but it is
even better if the actual company pings as well:
https://github.com/rust-lang/rust/issues/139284
I have also added it to our usual live list of features:
https://github.com/Rust-for-Linux/linux/issues/2
Link: https://github.com/rust-lang/rust/issues/139284
Link: https://github.com/rust-lang/rust/pull/139534
Also Cc'ing rust-for-linux and the maintainers and reviewers.
I hope this helps.
Thanks,
Chang
[*]:
https://github.com/intel/apx/blob/study_rust-apxf/study_rust-apxf.md