test(relinker): skip host instructions the CPU cannot execute #16236
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/16236"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by ycbuzi on 2026-11-05T21:38:34Z.
What
masked_store_lowering,amd64_only_converterandred_zone_framer_executiondie with SIGILL on an x86-64 host that cannot execute an instruction they run (reported on #1). This PR makes those execution cases skip on such a host instead.LoweringExecution::HostExecutes(core/relinker/codegen/tests/LoweringExecution.hpp) runs one instruction followed byreton an executable page, under a temporary SIGILL handler (sigsetjmp/siglongjmp), with RDI pointing at a 64-byte scratch buffer. It does not read CPUID, because Rosetta executes AVX2, FMA, BMI and others without reporting them there (docs/dev/debt/relinker.md). A CPUID check would drop these cases on Apple Silicon, where they run and pass today.masked_store_lowering: each form and width (VMASKMOVPS/PD, VPMASKMOVD/Q, 128 and 256-bit) runs its execution case only if the host executes that original instruction. Skipped forms are printed asskipped: ....amd64_only_converter:xsaveoptExecutioncleared YMM3 withvpxor %ymm3,%ymm3,%ymm3, which is AVX2. It now usesvxorps %ymm3,%ymm3,%ymm3(AVX), which clears the same 256 bits, so XRSTOR still has to restore the whole pattern for the check to pass.vxorps %ymm0,%ymm0,%ymm0.rdseedExecutionprobes the replacement itself (RDRAND, the Rosetta lowering of RDSEED).red_zone_framer_execution: the leaf whose widened exit carries a VEX ANDN is still framed and counted, but it is executed only when the host reports BMI1 (__builtin_cpu_supports("bmi")). Otherwise it printsframed but not executed, this CPU cannot execute an instruction in it. This test runs only on x86-64 Linux and Windows, never under Rosetta, so CPUID is reliable there.HostExecutesis not used because it is Linux-only, and this test also runs on Windows.The tests still pass when parts are skipped (exit 0, not ctest's skip code 77), because the rest of each test still runs. On a host that executes everything, nothing changes.
python3 tools/pr_overlap.pyfailed closed on #11192 and #13486, which conflict withmain, so I compared them by hand. #13486 does not change these files. #11192 adds scalar RCPSS/RSQRTSS cases after the VRSQRTPS unit check inreciprocalExecution, which is next to this change'sif (!avx) return;but not on the same lines. With both merged, its new cases run only where AVX executes, which its VEX sites need anyway. #15639 and #11525 also changeAmd64OnlyConverterTests.cpp, adding new cases and theirmain()calls elsewhere in the file, not these lines. #16432 adds leaves toRedZoneFramerExecutionTests.cppin other places. Its newvmovqleaf is AVX, so with both merged it would crash the same way on a host without AVX; whichever lands second can give it theHostRunsfield added here with a__builtin_cpu_supports("avx")check.Tested
Machine: MacBookPro8,1, Intel Core i5-2415M (Sandy Bridge, AVX1 only: no AVX2, BMI, FMA or RDRAND), macOS 13.7.8, LLVM clang 19.1.7 (official llvm.org macOS-X64 build) with the system libc++. Intel Mac, x86-64 native, no Rosetta. Commit 77d3a86021 on
main38fe81a14a.maind23df92b38): both tests ended with SIGILL (rc 132). lldb showedvpmaskmovdin the generated stub, the test's ownvpxor %ymm3, and the RDRAND replacement of RDSEED.masked_store_loweringprintsskipped: 128-bit VPMASKMOVD execution, the host does not execute it, and the same for 256-bit VPMASKMOVD and both VPMASKMOVQ widths. It runs 864 masked store executions of VMASKMOVPS/PD.amd64_only_converterprintsskipped: RDSEED replacement execution, the host does not execute RDRAND. The AVX cases run here, so the probe's success path is covered.mainon this Mac:shader_ir_use_rewriteandshader_ssa_pass_readsdon't link (the macOS 13 libc++ has nostd::pmr), and the twocheck_compile_modestests fail becauseclang/gccon PATH is Apple clang 14.python3 tools/check_conventions.py --base origin/main: all checks passed.Second machine, without AVX or BMI (11-06): Pentium Silver N6000 (Tremont, SSE4.2 only), Debian 13 in ChromeOS's Linux container, GCC 14.2.0, same relinker-only configure. Head
926bd92fae(this branch merged withmain7b7edf657b).main9f2b939606: all three tests end with SIGILL (red_zone_framer_executionrc 132,Illegal instruction).red_zone_framer_execution,masked_store_loweringandamd64_only_converterall pass (rc 0).red_zone_framer_executionprints the skip line for the ANDN leaf and runs every other leaf.masked_store_loweringskips all eight forms (skipped: 128-bit VMASKMOVPS execution, the host does not execute it, and so on), andamd64_only_converterskips the VRSQRTPS/VRCPPS stub, the XSAVEOPT replacement and the 256-bit store stub, because the host does not execute AVX.red_zone_framer_executionruns every leaf, ANDN included, and passes.AVX2 hosts are also covered by CI: there the probes succeed and every case runs as before.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code