fix(libs): spell inline assembly symbols for Mach-O hosts #4628

Merged
mugurc merged 1 commit from upstream-pr/4628 into main 2026-10-14 04:26:03 +00:00
mugurc commented 2026-10-12 17:03:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by mugurc on 2026-10-12T17:03:08Z.


What

C symbols in Mach-O carry a leading underscore, and the Mach-O assembler has no .type or .size. The inline assembly of libSceFiber, the signal mask helpers, getcontext and their tests spells every symbol the ELF way, so they do not link on macOS.

  • APS5_ASM_SYMBOL(name) names a symbol the way the host assembler expects it.
  • APS5_ASM_FUNCTION_END(name) closes a function: .size on ELF, nothing elsewhere.
  • APS5_ASM_FUNCTION(name) has a macOS definition.
  • libSceFiber, SignalSets.cpp, UserContext.cpp, GuestSignalSets.cpp and GuestUserContext.cpp use them instead of writing the spelling out. The signal helpers still call name@PLT on Linux.

Part of the macOS series announced on #1 (https://github.com/boykopovar/AnyPS5/issues/1#issuecomment-6124344298).

Tested

  • macOS 26.5.1, Apple M5 Max, Apple clang 21, x86-64 build under Rosetta 2. The macOS pull requests are meant to be taken together (https://github.com/boykopovar/AnyPS5/issues/1#issuecomment-6124344298); with all of them applied on current main, ninja, ninja libs and ctest -j4 on macOS ran 940 tests in the last full run (main 2a5eca11c): 582 passed, 357 were skipped (no Vulkan loader in the environment, no guest address-space arena on macOS) and 1 failed. The failure is guest_socket_read_write, an existing test this series does not touch: after the peer has closed, the write that it expects to fail with EPIPE fails with ECONNRESET or EAGAIN on macOS, in 8 of 60 runs of the test alone.
  • This pull request alone: the five files compile on macOS.
  • Linux and Windows: the full build and tests of this pull request merged with the other macOS pull requests of the series (seventeen of them, on main 33ae282e4), run on my fork: 960 tests on Linux and 966 on Windows pass (https://github.com/mugurc/AnyPS5/actions/runs/38256280627). I preprocessed the five files for Linux (-D__linux__ -U__APPLE__) from main and from this branch and compared the text of every asm(...) block: identical for SignalSets.cpp, UserContext.cpp, GuestSignalSets.cpp and GuestUserContext.cpp; libSceFiber/Export.cpp differs only in whitespace and in where the directives sit, with the same directives and instructions.

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 in TechnicalDebt
  • 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 (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4832574645 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4628). Originally posted by [mugurc](https://github.com/mugurc) on 2026-10-12T17:03:08Z. --- ### What C symbols in Mach-O carry a leading underscore, and the Mach-O assembler has no `.type` or `.size`. The inline assembly of libSceFiber, the signal mask helpers, `getcontext` and their tests spells every symbol the ELF way, so they do not link on macOS. - `APS5_ASM_SYMBOL(name)` names a symbol the way the host assembler expects it. - `APS5_ASM_FUNCTION_END(name)` closes a function: `.size` on ELF, nothing elsewhere. - `APS5_ASM_FUNCTION(name)` has a macOS definition. - libSceFiber, `SignalSets.cpp`, `UserContext.cpp`, `GuestSignalSets.cpp` and `GuestUserContext.cpp` use them instead of writing the spelling out. The signal helpers still `call name@PLT` on Linux. Part of the macOS series announced on #1 (https://github.com/boykopovar/AnyPS5/issues/1#issuecomment-6124344298). ### Tested - macOS 26.5.1, Apple M5 Max, Apple clang 21, x86-64 build under Rosetta 2. The macOS pull requests are meant to be taken together (https://github.com/boykopovar/AnyPS5/issues/1#issuecomment-6124344298); with all of them applied on current `main`, `ninja`, `ninja libs` and `ctest -j4` on macOS ran 940 tests in the last full run (`main` 2a5eca11c): 582 passed, 357 were skipped (no Vulkan loader in the environment, no guest address-space arena on macOS) and 1 failed. The failure is `guest_socket_read_write`, an existing test this series does not touch: after the peer has closed, the write that it expects to fail with `EPIPE` fails with `ECONNRESET` or `EAGAIN` on macOS, in 8 of 60 runs of the test alone. - This pull request alone: the five files compile on macOS. - Linux and Windows: the full build and tests of this pull request merged with the other macOS pull requests of the series (seventeen of them, on `main` 33ae282e4), run on my fork: 960 tests on Linux and 966 on Windows pass (https://github.com/mugurc/AnyPS5/actions/runs/38256280627). I preprocessed the five files for Linux (`-D__linux__ -U__APPLE__`) from main and from this branch and compared the text of every `asm(...)` block: identical for `SignalSets.cpp`, `UserContext.cpp`, `GuestSignalSets.cpp` and `GuestUserContext.cpp`; `libSceFiber/Export.cpp` differs only in whitespace and in where the directives sit, with the same directives and instructions. ### Checklist - [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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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 (none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: none - [x] AI-assisted: yes
thuanquang commented 2026-10-14 02:44:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by thuanquang on 2026-10-14T02:44:21Z.


Checked core/libs/prx/libSceFiber/Export.cpp on macOS 27.0.1 (Apple clang 21.0.0, SDK 27.0), xcrun clang++ -arch x86_64 -std=c++20 -fexperimental-library -c -I core/libs, against main a21d73733:

Tree Result
main, -DMAP_STACK=0 <inline asm>:4:5: error: unknown directive (also lines 27, 30)
main + this PR, -DMAP_STACK=0 compiles; nm -m shows _Aps5FiberSwitchStack_nid_no_patch, _Aps5FiberTrampoline_nid_no_patch and _Aps5FiberMain_nid_no_patch external in __TEXT,__text
main + this PR Export.cpp:300:112: error: use of undeclared identifier 'MAP_STACK'

The asm change works on current main, but the file still does not compile on macOS for a reason outside this diff: #4265 (merged 2026-10-13) maps fiber host stacks with MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE | MAP_STACK, and the macOS SDK's sys/mman.h has no MAP_STACK. macos-port and the ci/macos-series* branches predate #4265.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6159718967 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4628#issuecomment-6159718967). Originally posted by [thuanquang](https://github.com/thuanquang) on 2026-10-14T02:44:21Z. --- Checked `core/libs/prx/libSceFiber/Export.cpp` on macOS 27.0.1 (Apple clang 21.0.0, SDK 27.0), `xcrun clang++ -arch x86_64 -std=c++20 -fexperimental-library -c -I core/libs`, against `main` a21d73733: | Tree | Result | |---|---| | `main`, `-DMAP_STACK=0` | `<inline asm>:4:5: error: unknown directive` (also lines 27, 30) | | `main` + this PR, `-DMAP_STACK=0` | compiles; `nm -m` shows `_Aps5FiberSwitchStack_nid_no_patch`, `_Aps5FiberTrampoline_nid_no_patch` and `_Aps5FiberMain_nid_no_patch` external in `__TEXT,__text` | | `main` + this PR | `Export.cpp:300:112: error: use of undeclared identifier 'MAP_STACK'` | The asm change works on current `main`, but the file still does not compile on macOS for a reason outside this diff: #4265 (merged 2026-10-13) maps fiber host stacks with `MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE | MAP_STACK`, and the macOS SDK's `sys/mman.h` has no `MAP_STACK`. `macos-port` and the `ci/macos-series*` branches predate #4265. AI-assisted: yes (Claude Code)
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!4628
No description provided.