relinker: masked_store_lowering flakes under Rosetta with "Masked store stub changed the flags" #12284

Open
opened 2026-10-28 07:13:17 +00:00 by B-Howell · 0 comments
B-Howell commented 2026-10-28 07:13:17 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by B-Howell on 2026-10-28T07:13:17Z.


What happens

masked_store_lowering sometimes fails in the relinker (macos-latest, clang++, x86_64) job with only:

Masked store stub changed the flags

The same test passes on main and on other pull requests run at about the same time. Two occurrences on unrelated PRs, both on head commits that don't touch the relinker's masked-store code:

Run PR branch Head Date
40216485859 fix/relinker-windows-gs-trap-entry-roots 33b48ba39f 2026-10-25
40438653738 codex/libc-strmode (#11664) 1185982eff 2026-10-27

I listed every failed pull-request run of build.yml from 2026-10-24 to 2026-10-28 (200 runs) and read the failed macOS relinker jobs. These are the only two masked_store_lowering failures. Every other macOS relinker failure in that window is a different test or a stale-head abort.

What the data shows

  • Only Rosetta runs the execution part. The execution checks (1,728 stub runs) are compiled only for __x86_64__ on Linux and macOS. On macos-latest, the x86_64 job runs under Rosetta 2 (its log shows "Install of Rosetta 2 finished successfully"). The arm64 macOS job skips the execution part, Windows skips it, and the Linux job runs it natively and has not failed.
  • Only the flags differ. The test checks, in this order: the stored bytes, the inactive bytes, the fault count, the red zone, the vector registers, the general registers, then the flags. Everything before the flags check matched in both failures:
    • the masked store wrote the right elements;
    • exactly the expected number of faults reached the handler;
    • RAX and RCX, which the stub pushes next to RFLAGS, came back intact.
  • The stub has no path that leaves the flags changed. From EmitMaskedStore:
    • it runs lea -0x80(%rsp), pushfq, push rax, push rcx;
    • then, per element, test cl, bit; jz and lock orb $0, off(%rax) on the first and last byte;
    • then pop rcx, pop rax, popfq, lea +0x80(%rsp), and the original VMASKMOV* store.
    • After popfq, nothing writes RFLAGS: lea, VMASKMOV and the patched ret leave them alone.
    • The stub bytes for a case are deterministic.
  • The native run never fails. Relinker-only Release build, WSL Ubuntu 22.04, GCC 11.4, Ryzen 7 7800X3D:
    • 1,000 runs of masked_store_lowering_tests idle and 1,000 with 14 busy loops pinning the CPU: 3,456,000 stub executions, 0 failures;
    • 300 more runs of the diagnostic version: 0 failures.

Analysis (not measured on macOS)

A flags-only difference that comes and goes, with the general registers and memory intact, points at how Rosetta 2 carries RFLAGS across the probe's SIGSEGV delivery and sigreturn, or across a retranslation of the code page the test rewrites before each case. It does not point at the stub bytes.

Rosetta already treats faults inside these instructions specially: the debt entry records unexpectedly need to EmulateForward on a synchronous exception for faulting masked stores.

Which flag changes, and whether the failing execution took a fault, isn't known. The current message prints neither.

If Rosetta does lose RFLAGS across a fault, that matters beyond this test. Guest code that faults on a write-watched page under --to-rosetta could resume with different flags.

Next step

A test-only PR makes the failure message print the form, width, addressing mode, offset, mask pattern, fault count, and the flags before and after. The next occurrence then says which flag changes and whether a fault was involved. Whether to make the check tolerant under Rosetta can be decided from that data.

AI-assisted: yes (Claude Code). The CI data and the native runs are measured; the Rosetta explanation is analysis, not a measurement.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:6074380920 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/12284). Originally posted by [B-Howell](https://github.com/B-Howell) on 2026-10-28T07:13:17Z. --- ### What happens `masked_store_lowering` sometimes fails in the `relinker (macos-latest, clang++, x86_64)` job with only: ``` Masked store stub changed the flags ``` The same test passes on `main` and on other pull requests run at about the same time. Two occurrences on unrelated PRs, both on head commits that don't touch the relinker's masked-store code: | Run | PR branch | Head | Date | |---|---|---|---| | [40216485859](https://github.com/boykopovar/AnyPS5/actions/runs/40216485859) | `fix/relinker-windows-gs-trap-entry-roots` | `33b48ba39f` | 2026-10-25 | | [40438653738](https://github.com/boykopovar/AnyPS5/actions/runs/40438653738) | `codex/libc-strmode` (#11664) | `1185982eff` | 2026-10-27 | I listed every failed pull-request run of `build.yml` from 2026-10-24 to 2026-10-28 (200 runs) and read the failed macOS relinker jobs. These are the only two `masked_store_lowering` failures. Every other macOS relinker failure in that window is a different test or a stale-head abort. ### What the data shows - **Only Rosetta runs the execution part.** The execution checks (1,728 stub runs) are compiled only for `__x86_64__` on Linux and macOS. On `macos-latest`, the `x86_64` job runs under Rosetta 2 (its log shows "Install of Rosetta 2 finished successfully"). The arm64 macOS job skips the execution part, Windows skips it, and the Linux job runs it natively and has not failed. - **Only the flags differ.** The test checks, in this order: the stored bytes, the inactive bytes, the fault count, the red zone, the vector registers, the general registers, then the flags. Everything before the flags check matched in both failures: - the masked store wrote the right elements; - exactly the expected number of faults reached the handler; - RAX and RCX, which the stub pushes next to RFLAGS, came back intact. - **The stub has no path that leaves the flags changed.** From `EmitMaskedStore`: - it runs `lea -0x80(%rsp)`, `pushfq`, `push rax`, `push rcx`; - then, per element, `test cl, bit; jz` and `lock orb $0, off(%rax)` on the first and last byte; - then `pop rcx`, `pop rax`, `popfq`, `lea +0x80(%rsp)`, and the original `VMASKMOV*` store. - After `popfq`, nothing writes RFLAGS: `lea`, `VMASKMOV` and the patched `ret` leave them alone. - The stub bytes for a case are deterministic. - **The native run never fails.** Relinker-only Release build, WSL Ubuntu 22.04, GCC 11.4, Ryzen 7 7800X3D: - 1,000 runs of `masked_store_lowering_tests` idle and 1,000 with 14 busy loops pinning the CPU: 3,456,000 stub executions, 0 failures; - 300 more runs of the diagnostic version: 0 failures. ### Analysis (not measured on macOS) A flags-only difference that comes and goes, with the general registers and memory intact, points at how Rosetta 2 carries RFLAGS across the probe's `SIGSEGV` delivery and `sigreturn`, or across a retranslation of the code page the test rewrites before each case. It does not point at the stub bytes. Rosetta already treats faults inside these instructions specially: the debt entry records `unexpectedly need to EmulateForward on a synchronous exception` for faulting masked stores. Which flag changes, and whether the failing execution took a fault, isn't known. The current message prints neither. If Rosetta does lose RFLAGS across a fault, that matters beyond this test. Guest code that faults on a write-watched page under `--to-rosetta` could resume with different flags. ### Next step A test-only PR makes the failure message print the form, width, addressing mode, offset, mask pattern, fault count, and the flags before and after. The next occurrence then says which flag changes and whether a fault was involved. Whether to make the check tolerant under Rosetta can be decided from that data. AI-assisted: yes (Claude Code). The CI data and the native runs are measured; the Rosetta explanation is analysis, not a measurement.
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5#12284
No description provided.