test(libkernel): name the exception fault test's assembly symbols for Mach-O #16441

Merged
evanrk merged 2 commits from upstream-pr/16441 into main 2026-11-10 14:09:38 +00:00
evanrk commented 2026-11-06 18:07:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by evanrk on 2026-11-06T18:07:34Z.


What

GuestExceptionFault.cpp defines its fault sites (FaultTestRead, FaultTestDivideSite, FaultTestJump and the rest) in top-level asm under their bare names. Mach-O prefixes C symbols with an underscore, so on macOS the C++ declarations refer to _FaultTestRead while the assembly defines FaultTestRead, and guest_exception_fault_tests does not link.

Each .globl and label now goes through APS5_ASM_SYMBOL from general/AsmMacros.hpp, which adds the underscore on Apple and expands to the bare name on Linux and Windows. The instructions are unchanged, and the assembly Linux and Windows see is the same as before. This applies the macro f818d5e introduced for inline assembly on Mach-O hosts to a test file it did not cover.

Compiling the asm block with clang for x86_64-pc-linux-gnu and x86_64-pc-windows-msvc, before and after this change, gives identical assembly; for x86_64-apple-macos the only difference is the leading underscore.

macOS has no host fault delivery yet: Exception.cpp installs it only for Windows and Linux, and the libkernel debt file already says other hosts do not deliver host faults. Once it links, the test segfaults there, so guest_exception_fault is now registered with CTest only when the host is not Apple. The executable still builds on macOS, the test is registered on Linux and Windows as before, and the debt entry now says it is not registered on macOS.

Tested

macOS 26.6.2, Apple M4 Pro, Apple clang 21.0.0, x86-64 build with -DBUILD_TESTING=ON. libkernel does not link on macOS from main alone, so the test was built on a local branch that adds #7804 and #4630; the file is identical to this PR's. nm on the object shows _FaultTestRead, _FaultTestDivideSite and the other sites defined, and guest_exception_fault_tests links.

Run directly, the test still fails on macOS (ctest -R guest_exception_fault: SEGFAULT), as expected without host fault delivery. On a macOS build configured with the CMake change, guest_exception_fault_tests is still built, guest_exception_fault is absent from the generated CTestTestfile.cmake, and guest_exception_handler and guest_raise_exception are still registered.

python3 tools/check_conventions.py --base upstream/main passes, and python3 tools/pr_overlap.py reports two overlaps: #16070 adds a line inside the block this PR wraps in if(NOT APPLE), and #4630 changes the sceKernelRaiseException entry on the line after the debt entry this PR extends. Whichever merges second keeps both changes, a one-line rebase. Its other reports share the two files but none changes these lines. Not run on Linux or Windows.

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:5192431617 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16441). Originally posted by [evanrk](https://github.com/evanrk) on 2026-11-06T18:07:34Z. --- ### What `GuestExceptionFault.cpp` defines its fault sites (`FaultTestRead`, `FaultTestDivideSite`, `FaultTestJump` and the rest) in top-level `asm` under their bare names. Mach-O prefixes C symbols with an underscore, so on macOS the C++ declarations refer to `_FaultTestRead` while the assembly defines `FaultTestRead`, and `guest_exception_fault_tests` does not link. Each `.globl` and label now goes through `APS5_ASM_SYMBOL` from `general/AsmMacros.hpp`, which adds the underscore on Apple and expands to the bare name on Linux and Windows. The instructions are unchanged, and the assembly Linux and Windows see is the same as before. This applies the macro f818d5e introduced for inline assembly on Mach-O hosts to a test file it did not cover. Compiling the `asm` block with clang for `x86_64-pc-linux-gnu` and `x86_64-pc-windows-msvc`, before and after this change, gives identical assembly; for `x86_64-apple-macos` the only difference is the leading underscore. macOS has no host fault delivery yet: `Exception.cpp` installs it only for Windows and Linux, and the libkernel debt file already says other hosts do not deliver host faults. Once it links, the test segfaults there, so `guest_exception_fault` is now registered with CTest only when the host is not Apple. The executable still builds on macOS, the test is registered on Linux and Windows as before, and the debt entry now says it is not registered on macOS. ### Tested macOS 26.6.2, Apple M4 Pro, Apple clang 21.0.0, x86-64 build with `-DBUILD_TESTING=ON`. libkernel does not link on macOS from `main` alone, so the test was built on a local branch that adds #7804 and #4630; the file is identical to this PR's. `nm` on the object shows `_FaultTestRead`, `_FaultTestDivideSite` and the other sites defined, and `guest_exception_fault_tests` links. Run directly, the test still fails on macOS (`ctest -R guest_exception_fault`: SEGFAULT), as expected without host fault delivery. On a macOS build configured with the CMake change, `guest_exception_fault_tests` is still built, `guest_exception_fault` is absent from the generated `CTestTestfile.cmake`, and `guest_exception_handler` and `guest_raise_exception` are still registered. `python3 tools/check_conventions.py --base upstream/main` passes, and `python3 tools/pr_overlap.py` reports two overlaps: #16070 adds a line inside the block this PR wraps in `if(NOT APPLE)`, and #4630 changes the `sceKernelRaiseException` entry on the line after the debt entry this PR extends. Whichever merges second keeps both changes, a one-line rebase. Its other reports share the two files but none changes these lines. Not run on Linux or Windows. ### 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
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!16441
No description provided.