relinker: --to-rosetta output can mis-execute a scalar compare followed by a 128-bit load (Rosetta 2 bug) #5642
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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 RINNECODER on 2026-10-14T02:37:24Z.
Found while porting to macOS: under Rosetta 2,
--to-rosettaoutput can mis-execute a scalar compare.What happens
The compare must be:
CMPSS/VCMPSS(and someVCMPSD);vmovaps/vmovups/vmovdqa) into the compare's destination register.A later scalar FP read of that register (
vucomiss,vaddss) then sees the compare mask instead of the loaded value. clang emits this shape forfmaxffollowed by a reload. In a title's layout code it made309.0 == 309.0compare as "below", so flex items never grew.Minimal repro
An x86-64 binary run under Rosetta 2 on Apple silicon:
jmpputs the compare in its own block.Where
On
main,core/relinker/codegen/src/x86/Amd64OnlyInstructionMatcher.cpp,_matchRosettalowers only RDSEED, RDPID, CLWB and CPUID. Scalar compares reach Rosetta unchanged.Suggested fix
For the Rosetta target, move each such compare out of line, unchanged, through the existing trampoline path (stub = the instruction + a jump back). The compare then runs in its own translated block, with exact semantics.
ssandsd; register, memory and RIP-relative operands) under Rosetta. As written, 68 of 80 sequences lose the load. Split out of line, none do.Imported from boykopovar/AnyPS5. Originally posted by LeandroSSB on 2026-10-14T03:15:41Z.
Taken:
LeandroSSB/AnyPS5:fix/relinker-rosetta-scalar-compare(one commit,a76950dd5, on currentmain). Your approach applied: VEX scalar compares (VCMPSS/VCMPSD, VEX2/VEX3 map 0F) with predicate not in {EQ_OQ, LT_OS, LE_OS} are moved out-of-line through the existing trampoline path (stub = instruction + return jump, RIP-relative sources relocated), asOptionalsubstitutions so unplaceable sites are kept. Predicates 0/1/2 and all packed/legacy/EVEX forms stay inline.One scope note: legacy (non-VEX) CMPSS/CMPSD are not covered —
X64InstructionDecoderhas a pre-existing gap (two-byte0F C2missing from the ModRM+imm8 tables), so legacy compares never reach the matcher intact. The repro is VEX-only; I recommend a separate issue for the decoder gap if it matters.Validated on Linux (GCC 13.3, relinker-only build,
BUILD_TESTING=ON): 156/156 tests pass, including the new Rosetta out-of-line test cases;tools/check_conventions.py --base origin/mainpasses. Not opened as a PR because of the intake pause; a maintainer is welcome to carry the commit.AI-assisted (Claude Code); I ran the validation above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-14T06:22:12Z.
Opened #5683 with Leandro Soares' tested fix, preserving his commit authorship. The Linux relinker-only build succeeded;
amd64_only_converterpasses. Full CTest is 157/158: the only failure is the unrelatedprogress_historyPython 3.11tarfile.extractall(filter=...)compatibility error. Conventions pass. I could not run macOS Rosetta locally, so the Rosetta reproduction remains supported by the reporter's tested matrix.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-14T18:16:02Z.
Independent Apple Silicon validation has now been added to PR #5683: on an M2 Max under Rosetta 2, the reported compare/load sequence fails as described for 24/64 VCMPSS cases and 4/64 VCMPSD cases; only false-result masks fail, and predicates 0, 1 and 2 did not fail. The hand-written out-of-line form passed the predicate checks. The reviewer did not execute the relinker's converted output on macOS, so this is confirmation of the Rosetta behavior and trampoline shape, not an end-to-end converted-title run.
The PR's latest hosted conventions, eligibility, intake, and Ubuntu/Windows/macOS relinker checks pass. Its overlap with #5784 is only in relinker test registration; the two PRs cover independent instructions and no functional dependency is declared.