fix(relinker): lower ANDN in Rosetta conversion #5784
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5784"
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 gguerra26 on 2026-10-14T10:43:26Z.
What
Balatro (PPSA21402, discussion #1142) stops in its bundled libc initializer on
andnq %rsi, %rcx, %raxunder Rosetta on an Apple M1 running macOS 15.3.1. A standalone x86-64 ANDN program reproduces SIGILL without game files.--to-rosettapreviously left ANDN unchanged.Lower 32- and 64-bit ANDN register and memory forms to scalar NOT/AND sequences. Preserve source and scratch registers, the caller's red zone, stack-relative addressing, RIP-relative operands, and the defined status flags. Plain conversion and
--to-intelkeep ANDN unchanged. Invalid VEX forms and a stack displacement that cannot accommodate the spill frame fail explicitly.Semantics follow the ANDN entry in Intel SDM volume 2A. The documentation now distinguishes the earlier M5 Max observations from the instruction support observed on this M1.
Tested
shlxq %rax, %rdx, %r8, another unsupported instruction. This PR does not establish playability or FPS.macos-portatb7eb6b6b515c6163b6a0a6dd09b630a0414a0149, with the local Apple SDK input-number parsing build fix. The relinker is built from this upstream-based branch.git diff --checkpass. Linux/Windows execution has not been run locally; their existing CI can exercise the portable conversion checks, and Linux x86-64 also executes the lowering test.Checklist
main; no other open PR implements the same functionsImported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-14T10:52:26Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)docs/dev/debt/relinker.mdL22Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/relinker/CMakeLists.txtdocs/dev/debt/libkernel.mddocs/dev/debt/relinker.mddocs/user/USAGE.mdcore/relinker/CMakeLists.txtdocs/dev/debt/libkernel.mddocs/dev/debt/relinker.mddocs/user/USAGE.mdcore/relinker/CMakeLists.txtdocs/dev/debt/libkernel.mddocs/dev/debt/relinker.mddocs/user/USAGE.mdcore/relinker/CMakeLists.txtdocs/dev/debt/libkernel.mddocs/dev/debt/relinker.mddocs/user/USAGE.mdcore/relinker/CMakeLists.txtdocs/dev/debt/libkernel.mddocs/dev/debt/relinker.mddocs/user/USAGE.mdcore/relinker/CMakeLists.txtdocs/dev/debt/libkernel.mddocs/dev/debt/relinker.mddocs/user/USAGE.mdcore/relinker/CMakeLists.txtdocs/dev/debt/libkernel.mddocs/dev/debt/relinker.mddocs/user/USAGE.mdcore/relinker/CMakeLists.txtdocs/dev/debt/libkernel.mddocs/dev/debt/relinker.mddocs/user/USAGE.mdcore/relinker/CMakeLists.txtdocs/dev/debt/libkernel.mddocs/dev/debt/relinker.mddocs/user/USAGE.mdcore/relinker/CMakeLists.txtdocs/dev/debt/libkernel.mddocs/dev/debt/relinker.mddocs/user/USAGE.mdcore/relinker/CMakeLists.txtdocs/dev/debt/libkernel.mddocs/dev/debt/relinker.mddocs/user/USAGE.mdcore/relinker/CMakeLists.txtdocs/dev/debt/libkernel.mddocs/dev/debt/relinker.mddocs/user/USAGE.mdcore/relinker/CMakeLists.txtdocs/dev/debt/libkernel.mddocs/dev/debt/relinker.mddocs/user/USAGE.mdcore/relinker/CMakeLists.txtdocs/dev/debt/libkernel.mddocs/dev/debt/relinker.mddocs/user/USAGE.mdcore/relinker/CMakeLists.txtdocs/dev/debt/libkernel.mddocs/dev/debt/relinker.mddocs/user/USAGE.mdcore/relinker/CMakeLists.txtdocs/dev/debt/libkernel.mddocs/dev/debt/relinker.mddocs/user/USAGE.mdcore/relinker/CMakeLists.txtdocs/dev/debt/libkernel.mddocs/dev/debt/relinker.mddocs/user/USAGE.mdcore/relinker/CMakeLists.txtdocs/dev/debt/libkernel.mddocs/dev/debt/relinker.mddocs/user/USAGE.mddocs/user/USAGE.mdcore/relinker/CMakeLists.txtdocs/dev/debt/libkernel.mddocs/dev/debt/relinker.mddocs/user/USAGE.mddocs/dev/debt/libkernel.mddocs/user/USAGE.mddocs/user/USAGE.mddocs/dev/debt/libkernel.mdcore/relinker/CMakeLists.txtcore/relinker/codegen/src/x86/Amd64OnlyInstructionMatcher.cppdocs/dev/debt/relinker.mddocs/user/USAGE.mdcore/relinker/CMakeLists.txtdocs/dev/debt/relinker.mddocs/dev/debt/libkernel.mdImported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-14T14:54:11Z.
Measured on a different Apple silicon machine: M2 Max, macOS 27.2 (26B5091g).
Relinker-only build of this branch (
9acd5dcc0)-DCMAKE_OSX_ARCHITECTURES=x86_64) under Rosetta: 150/150 tests pass with--timeout 30, includingandn_lowering.ANDN and the next stop (
shlxq) on this machineNeither stop reproduces here. A standalone x86-64 program runs each instruction in a child process and compares the result with a reference computed natively on arm64. The following run without SIGILL and return the reference result, with and without
ROSETTA_ADVERTISE_AVX=1:On this machine ADCX/ADOX, RDSEED, RDPID, CLWB, SHA, SSE4a, XSAVEOPT and XSAVEC raise SIGILL.
CPUID leaf 7 under Rosetta reports
BMI1=0,BMI2=0andAVX2=0by default, and all three as1withROSETTA_ADVERTISE_AVX=1. Whether these instructions execute therefore seems to depend on the macOS / Rosetta version rather than on what CPUID advertises: ANDN faults on M1 with macOS 15.3.1 and runs on M2 Max with macOS 27.2. The lowering stays correct on hosts that do execute ANDN.Written with AI assistance (Claude Code). I ran the builds, tests and measurements above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by 011010 on 2026-10-14T18:31:33Z.
Verified on macOS 27.0.1 (26A434), Apple M4, x86-64 under Rosetta 2, Apple clang 21: the relinker-only build passes
ctest150/150, includingandn_lowering, which mmaps and executes the lowered sequences. The ANDN lowering holds on macOS 27 as well as the 15.3.1 you reported.Imported from boykopovar/AnyPS5. Originally posted by simonbbby on 2026-10-14T22:24:15Z.
Independent Linux x86-64 execution coverage at exact head
9acd5dcc07d8149020bf50fbd5e09f7633a2613f, standalone on its recorded parent, no other PRs merged.Ubuntu 24.04, Ryzen 9 9950X, GCC 13.3, Ninja Release,
ANYPS5_RELINKER_ONLY=ON,BUILD_TESTING=ON:andn_lowering,amd64_only_converterandrelinker_conversionalso pass 3/3 each.Amd64OnlyInstructionMatcher.cppfrom this head's parent, retaining the PR fixture and lowering implementation, makesandn_lowering_testsexit 1 withRosetta mode did not require an ANDN trampoline. Restoring the PR matcher and the unmodified stock test, rebuilding, then rerunning all three focused fixtures passes; the checkout is clean.This fills Linux host execution/conversion coverage. No new title run or Rosetta execution claim; the reported title's SIGILL is not reproduced on this AMD host.
Imported from boykopovar/AnyPS5. Originally posted by JoaoPauloCMarra on 2026-10-15T10:05:37Z.
M4 Pro, macOS 27.0.1 (26A434), Apple clang 21, PR head 9acd5dcc0, relinker-only build
ctest 150/150 on arm64 and on an x86_64 build under Rosetta (--timeout 30), including andn_lowering
like the M2 Max run, plain ANDN doesnt fault here. a small x86_64 program that runs the 32 and 64-bit register forms gets the right result under Rosetta, no SIGILL (memory forms not tested)
so far only the M1 on macOS 15.3.1 faults. not sure if its the chip or the OS version, so it might be worth saying in the debt entry that macOS 27 doesnt need the lowering
AI-assisted (Claude Code), I ran all of the above on my machine
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-15T13:03:32Z.
Rebased onto current
main(conflict in thecore/relinker/CMakeLists.txtsource lists withScalarCompareOperands.cpp; kept both entries, no other change). Relinker scope builds and passes 135/135 ctest, includingandn_loweringandto_rosetta. Merging once the full Build is green.