Re: [PATCH] x86/build/64: Prevent native builds from generating APX instructions

"Chang S. Bae" <[email protected]> Fri, 31 Jul 2026 13:46:03 -0700
Newsgroups org.kernel.vger.rust-for-linux,org.kernel.vger.linux-kernel,org.kernel.vger.stable
Message-ID <[email protected]>
Hi Miguel,

First, sorry for my delayed response.

On 7/15/2026 3:30 AM, Miguel Ojeda wrote:
> 
> I think that warning may be coming from LLVM, not Rust, so it may
> depend not on the Rust version, but on the LLVM backend being used
> (Rust compilers support several major LLVM versions).
> 
> So I would recommend double-checking that -- and if so, perhaps you
> may need to restrict the LLVM backend version. In case you need them,
> we have nowadays e.g.
> 
>      CONFIG_RUSTC_LLVM_VERSION
>      CONFIG_RUSTC_LLVM_MAJOR_VERSION

The backend LLVM does not recognize apxf in the target attribute. OTOH, 
Clang appears to translate -mapxf into the backend readables [1]:

   egpr,push2pop2,ppx,ndd,ccmp,nf,cf,zu,jmpabs

Support for the apxf attribute looks to be merged about two weeks ago 
[2], and which is also found in the LLVM 23 RC tree.

Given that one option would be relax the rustc version while tightening 
the backend like:

  Option 1: RUSTC_VERSION >= 108800 && RUSTC_LLVM_MAJOR_VERSION >= 23

Or, simply like the previous:

  Option2: RUSTC_VERSION >= 109301

Since the rustc front does no longer emits the `apxf` attribute starting 
from 1.93. Also, 1.93 requires at least LLVM 21 which already supports APX.

[1] 
https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Options/Options.td#L7483
[2] https://github.com/llvm/llvm-project/pull/184078


> Also, from that
> https://github.com/intel/apx/blob/study_rust-apxf/study_rust-apxf.md,
> I notice you checked object files, which is a good check, but what I
> meant is to check the LLVM module attributes in the LLVM IR emitted
> from the Rust compiler.
> 
> For instance, if I do:
> 
>    https://godbolt.org/z/sMaajjYao
> 
> I see:
> 
>      +egpr,+push2pop2,+ppx,+ndd,+ccmp,+cf,+nf,+zu
> 
> being added to the LLVM module attributes when I pass a `+apxf`.

I see. --emit=llvm-ir looks to generate .ll files where target-features= 
is readable. Thanks for the clarification!

> anyway, I would suggest checking others. In fact, you could even
> inspect all and filter them out by the language DWARF tag. Or perhaps
> you can just do it for every single object, since the C ones are
> expected to behave the same, no?
> 

Yeah, I could check obj files running the below for example. Both LLVM 
and GCC builds appear free from EGPR use when with Option 2 above.

$ find . -type f -name "*.o" -print0 | xargs -0 -n 1 ./check_egprs.sh
$ cat check_egprs.sh
   egpr_refs=$(objdump -d --no-show-raw-insn $1 | \
     sed -E 's/^[[:space:]]+[0-9a-fA-F]+:[[:space:]]+//' | \
     grep -E 
'%r16|%r17|%r18|%r19|%r20|%r21|%r22|%r23|%r24|%r25|%r26|%r27|%r28|%r29|%r30|%r31' 
| \
     wc -l)

   if [ $egpr_refs != 0 ] ; then
     echo "Fail: $1, $egpr_refs EGPRs"
   fi

Thanks,
Chang