test(libc): run the feupdateenv checks on macOS and under Rosetta 2 #10903

Merged
imellag merged 1 commit from upstream-pr/10903 into main 2026-10-27 11:00:20 +00:00
imellag commented 2026-10-25 08:45:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by imellag on 2026-10-25T08:45:11Z.


What

All 19 guest_update_env* tests fail on macOS. Two host differences cause it, and neither is in feupdateenv:

  1. errno after the null check. The test checks that feupdateenv(nullptr) throws without changing errno. On macOS it reads ENOENT afterwards. The first time a process builds a std::logic_error, Apple's libc++ looks up /usr/lib/libstdc++.6.dylib with a no-load dlopen, and that failed lookup leaves errno at ENOENT. Later ones don't touch it. A five-line program shows the same thing, both native arm64 and x86-64 under Rosetta 2: errno = 123; { std::invalid_argument e("x"); } leaves 2, and the second time it leaves 123. The test now builds one std::invalid_argument on macOS before the checks, so the null check sees only what feupdateenv does.

  2. Floating-point traps under Rosetta 2. Rosetta 2 keeps the six MXCSR exception masks set (_mm_setcsr with a mask cleared reads back 0x1f80) and raises no floating-point trap, x87 included. A program that unmasks the x87 divide-by-zero and runs fdiv by zero gets no SIGFPE. So:

    • the mask check in MasksAndThreads now expects the SSE masks the host keeps;
    • the 18 guest_update_env_pending_* tests exit 77 on such a host (SKIP_RETURN_CODE 77), because the trap they wait for can't come.

    Both use a copy of the probe GuestFloatingPoint.cpp has for the same Rosetta behaviour (HostKeepsSseTraps, which main got in mugurc's 100148f762). On a host that keeps an unmasked MXCSR exception, which includes every Linux and Windows x86-64 machine, the expectations and the pending tests are unchanged.

A new docs/dev/debt/libc.md entry for feupdateenv records that it raises no trap under Rosetta 2 and that the pending-trap tests are skipped there, next to the existing Rosetta entry for the trap-enable functions.

Tested

Apple M4 Pro, macOS 27.0.1, Apple clang 21, x86-64 Release under Rosetta 2 (-DCMAKE_OSX_ARCHITECTURES=x86_64, BUILD_TESTING=ON). main alone doesn't build libc's tests on macOS, so the tree is main 61fc572cee plus the open macOS build PRs and the parts of mugurc's series that #7201 also carries. ctest -R '^guest_update_env':

  • Without this change: 19 of 19 fail. guest_update_env fails with null rejected without state or errno change, and the pending_* tests fail because no trap comes (pending_0_0: enabled pending exception did not trap during feupdateenv).
  • With it: guest_update_env passes, including the 262144-combination matrix and the thread checks. The 18 pending_* tests are reported as skipped.
  • Printing the state at the null check before the change showed the exception caught, the x87 and MXCSR state unchanged, and errno 2 instead of 123.

Not run on Linux or Windows. There HostKeepsSseTraps is true and the __APPLE__ line isn't compiled, so the test runs as before.

check_conventions.py --base upstream/main passes. pr_overlap.py reports no conflicting lines. None of the pull requests it couldn't compare touches feupdateenv, its test or its debt entry.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5003215702 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10903). Originally posted by [imellag](https://github.com/imellag) on 2026-10-25T08:45:11Z. --- ### What All 19 `guest_update_env*` tests fail on macOS. Two host differences cause it, and neither is in `feupdateenv`: 1. **`errno` after the null check.** The test checks that `feupdateenv(nullptr)` throws without changing `errno`. On macOS it reads `ENOENT` afterwards. The first time a process builds a `std::logic_error`, Apple's libc++ looks up `/usr/lib/libstdc++.6.dylib` with a no-load `dlopen`, and that failed lookup leaves `errno` at `ENOENT`. Later ones don't touch it. A five-line program shows the same thing, both native arm64 and x86-64 under Rosetta 2: `errno = 123; { std::invalid_argument e("x"); }` leaves 2, and the second time it leaves 123. The test now builds one `std::invalid_argument` on macOS before the checks, so the null check sees only what `feupdateenv` does. 2. **Floating-point traps under Rosetta 2.** Rosetta 2 keeps the six MXCSR exception masks set (`_mm_setcsr` with a mask cleared reads back `0x1f80`) and raises no floating-point trap, x87 included. A program that unmasks the x87 divide-by-zero and runs `fdiv` by zero gets no `SIGFPE`. So: - the mask check in `MasksAndThreads` now expects the SSE masks the host keeps; - the 18 `guest_update_env_pending_*` tests exit 77 on such a host (`SKIP_RETURN_CODE 77`), because the trap they wait for can't come. Both use a copy of the probe `GuestFloatingPoint.cpp` has for the same Rosetta behaviour (`HostKeepsSseTraps`, which `main` got in mugurc's `100148f762`). On a host that keeps an unmasked MXCSR exception, which includes every Linux and Windows x86-64 machine, the expectations and the pending tests are unchanged. A new `docs/dev/debt/libc.md` entry for `feupdateenv` records that it raises no trap under Rosetta 2 and that the pending-trap tests are skipped there, next to the existing Rosetta entry for the trap-enable functions. ### Tested Apple M4 Pro, macOS 27.0.1, Apple clang 21, x86-64 Release under Rosetta 2 (`-DCMAKE_OSX_ARCHITECTURES=x86_64`, `BUILD_TESTING=ON`). `main` alone doesn't build libc's tests on macOS, so the tree is `main` `61fc572cee` plus the open macOS build PRs and the parts of mugurc's series that #7201 also carries. `ctest -R '^guest_update_env'`: - **Without this change:** 19 of 19 fail. `guest_update_env` fails with `null rejected without state or errno change`, and the `pending_*` tests fail because no trap comes (`pending_0_0`: `enabled pending exception did not trap during feupdateenv`). - **With it:** `guest_update_env` passes, including the 262144-combination matrix and the thread checks. The 18 `pending_*` tests are reported as skipped. - Printing the state at the null check before the change showed the exception caught, the x87 and MXCSR state unchanged, and `errno` 2 instead of 123. Not run on Linux or Windows. There `HostKeepsSseTraps` is true and the `__APPLE__` line isn't compiled, so the test runs as before. `check_conventions.py --base upstream/main` passes. `pr_overlap.py` reports no conflicting lines. None of the pull requests it couldn't compare touches `feupdateenv`, its test or its debt entry. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-25 09:26:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T09:26:46Z.

Review: APPROVED


Reviewed head 06cf0620906ee14689418941c036868fc524da9d. The macOS-only errno prime and the Rosetta trap-capability probe are scoped to the host differences described; the same HostKeepsSseTraps probe already exists in GuestFloatingPoint.cpp on main. The explicit test skip code is configured as SKIP_RETURN_CODE 77, so the 18 pending-trap cases report skipped on Rosetta instead of false failures. The independent M1 Pro report confirms guest_update_env passes 3/3 and the pending cases skip 3/3 under Rosetta, with the null-invalid_argument errno behavior reproduced natively and under Rosetta. Hosted enabled checks all pass, including macOS arm64/x86_64 relinker, register-context, write-watch and ASan; Linux/Windows product jobs are skipped by policy for this test-only diff. Locally, git diff --check and python3 tools/check_conventions.py --base upstream/main --head refs/remotes/upstream/pr-10903 pass. I did not run the guest test locally; the report’s full test run is contributor-provided. AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5642474983 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10903#pullrequestreview-5642474983). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T09:26:46Z. **Review:** APPROVED --- Reviewed head 06cf0620906ee14689418941c036868fc524da9d. The macOS-only errno prime and the Rosetta trap-capability probe are scoped to the host differences described; the same `HostKeepsSseTraps` probe already exists in `GuestFloatingPoint.cpp` on main. The explicit test skip code is configured as `SKIP_RETURN_CODE 77`, so the 18 pending-trap cases report skipped on Rosetta instead of false failures. The independent M1 Pro report confirms `guest_update_env` passes 3/3 and the pending cases skip 3/3 under Rosetta, with the null-`invalid_argument` errno behavior reproduced natively and under Rosetta. Hosted enabled checks all pass, including macOS arm64/x86_64 relinker, register-context, write-watch and ASan; Linux/Windows product jobs are skipped by policy for this test-only diff. Locally, `git diff --check` and `python3 tools/check_conventions.py --base upstream/main --head refs/remotes/upstream/pr-10903` pass. I did not run the guest test locally; the report’s full test run is contributor-provided. AI-assisted: yes.
maximilianfv commented 2026-10-26 23:36:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by maximilianfv on 2026-10-26T23:36:21Z.

Review: APPROVED


The changed lines are the same as at 06cf062090; the only difference is the rebase onto #11177, which takes care of the conflict @orezraey pointed out. On macOS under Rosetta 2, guest_update_env now passes, DefaultEnvironment included, and the 18 pending tests are skipped. Approving.

Tested on Apple M1 Pro, macOS 27.0.1 (x86_64 Release build under Rosetta 2, Apple clang 21)

Applied at 5556444f2b to mugurc's macOS series (27e968974) merged with main at 2742004ed2, plus main's #11177 (__fe_dfl_env, which this head is rebased on) and other open macOS fixes, then toggled only this PR. ctest -R '^guest_update_env', 3 runs each way:

guest_update_env 18 × guest_update_env_pending_*
Without this PR Failed 3/3: feupdateenv: null rejected without state or errno change (the 262144-combination matrix passes first) Failed 3/3: enabled pending exception did not trap during feupdateenv
With this PR Passed 3/3, including #11177's DefaultEnvironment (restored.mxcsr==0x9fc0, so Rosetta keeps FZ and DAZ) Skipped 3/3 (exit 77, the host keeps no unmasked floating-point exception)

The x87 claim that was unchecked in my last report now holds here too. A standalone x86_64 program unmasks the x87 divide-by-zero with fldcw, then runs fdiv by zero and fwait. Under Rosetta 2 it gets no SIGFPE, and the status word reads 0x0004.

Not checked here: Linux or Windows on this head (ycbuzi's Windows run was on 06cf062090).

Notes (none blocking)

  1. core/libs/tests/GuestUpdateEnv.cpp:244: all 18 pending tests wait for an x87 trap. Pending unmasks only x87[0] bit bit and keeps the MXCSR masks at 0x3f<<7 for every source, but the skip is decided by HostKeepsSseTraps, which probes MXCSR bit 7. On Rosetta 2 both properties fail together (see above), so the result is right here. A host that pins the MXCSR masks but delivers x87 traps would lose these tests without a failure, though. Probing what the tests need (an unmasked x87 flag raising SIGFPE at fwait) would close that gap. So would a skip message that names the SSE probe as the reason for the skip.

  2. docs/dev/debt/libc.md:30: the new bullet qualifies the feupdateenv, __fe_dfl_env bullet just above it ("an unmasked pending flag traps"). You could merge the Rosetta sentence into that bullet instead. A separate bullet also matches the Rosetta entry for the trap-enable functions on line 26, so it's fine either way.

  3. PR body, What item 2: "Both use the probe GuestFloatingPoint.cpp already has (HostKeepsSseTraps, from mugurc's 24d98f2e1a)". The PR adds a second copy of the probe at GuestUpdateEnv.cpp:45, next to GuestFloatingPoint.cpp:214, and 24d98f2e1a is not in main. The commit in main that added it is 100148f762. Something like "copies the probe from GuestFloatingPoint.cpp (mugurc, 100148f762)" would match the code.

AI-assisted: yes (Claude Code applied the PR, ran the tests, read the code and wrote this review).

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5660519679 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10903#pullrequestreview-5660519679). Originally posted by [maximilianfv](https://github.com/maximilianfv) on 2026-10-26T23:36:21Z. **Review:** APPROVED --- The changed lines are the same as at `06cf062090`; the only difference is the rebase onto #11177, which takes care of the conflict @orezraey pointed out. On macOS under Rosetta 2, `guest_update_env` now passes, `DefaultEnvironment` included, and the 18 pending tests are skipped. Approving. ### Tested on Apple M1 Pro, macOS 27.0.1 (x86_64 Release build under Rosetta 2, Apple clang 21) Applied at `5556444f2b` to mugurc's macOS series (`27e968974`) merged with `main` at `2742004ed2`, plus main's #11177 (`__fe_dfl_env`, which this head is rebased on) and other open macOS fixes, then toggled only this PR. `ctest -R '^guest_update_env'`, 3 runs each way: | | `guest_update_env` | 18 × `guest_update_env_pending_*` | |---|---|---| | Without this PR | Failed 3/3: `feupdateenv: null rejected without state or errno change` (the 262144-combination matrix passes first) | Failed 3/3: `enabled pending exception did not trap during feupdateenv` | | With this PR | Passed 3/3, including #11177's `DefaultEnvironment` (`restored.mxcsr==0x9fc0`, so Rosetta keeps FZ and DAZ) | Skipped 3/3 (exit 77, `the host keeps no unmasked floating-point exception`) | The x87 claim that was unchecked in my last report now holds here too. A standalone x86_64 program unmasks the x87 divide-by-zero with `fldcw`, then runs `fdiv` by zero and `fwait`. Under Rosetta 2 it gets no `SIGFPE`, and the status word reads `0x0004`. Not checked here: Linux or Windows on this head (ycbuzi's Windows run was on `06cf062090`). ### Notes (none blocking) 1. `core/libs/tests/GuestUpdateEnv.cpp:244`: all 18 pending tests wait for an x87 trap. `Pending` unmasks only `x87[0]` bit `bit` and keeps the MXCSR masks at `0x3f<<7` for every `source`, but the skip is decided by `HostKeepsSseTraps`, which probes MXCSR bit 7. On Rosetta 2 both properties fail together (see above), so the result is right here. A host that pins the MXCSR masks but delivers x87 traps would lose these tests without a failure, though. Probing what the tests need (an unmasked x87 flag raising `SIGFPE` at `fwait`) would close that gap. So would a skip message that names the SSE probe as the reason for the skip. 2. `docs/dev/debt/libc.md:30`: the new bullet qualifies the `feupdateenv, __fe_dfl_env` bullet just above it ("an unmasked pending flag traps"). You could merge the Rosetta sentence into that bullet instead. A separate bullet also matches the Rosetta entry for the trap-enable functions on line 26, so it's fine either way. 3. PR body, What item 2: "Both use the probe `GuestFloatingPoint.cpp` already has (`HostKeepsSseTraps`, from mugurc's `24d98f2e1a`)". The PR adds a second copy of the probe at `GuestUpdateEnv.cpp:45`, next to `GuestFloatingPoint.cpp:214`, and `24d98f2e1a` is not in `main`. The commit in `main` that added it is `100148f762`. Something like "copies the probe from `GuestFloatingPoint.cpp` (mugurc, `100148f762`)" would match the code. AI-assisted: yes (Claude Code applied the PR, ran the tests, read the code and wrote this review).
Sign in to join this conversation.
No reviewers
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!10903
No description provided.