fix(libc): build the host-facing libc code on macOS #4627

Merged
mugurc merged 1 commit from upstream-pr/4627 into main 2026-10-23 22:50:46 +00:00
mugurc commented 2026-10-12 17:03:06 +00:00 (Migrated from github.com)

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


What

The parts of libc that talk to the host and do not build with Darwin's headers and libSystem. Part of the macOS series announced on #1 (https://github.com/boykopovar/AnyPS5/issues/1#issuecomment-6124344298).

  • feof_unlocked, ferror_unlocked, getc_unlocked and putc_unlocked are macros on macOS, so they are called without the :: qualifier.
  • CLOCK_REALTIME_COARSE and st_mtim do not exist on macOS: the write mark of General.cpp uses CLOCK_REALTIME and st_mtimespec.
  • tm_zone is a char*, not a const char*.
  • libSystem's __cxa_thread_atexit returns void; the wrapper returns 0.
  • Darwin's stack protector reads __stack_chk_guard from libSystem, and the library's own definition under that name would be bound by every other library's host code. On macOS the guard has the name __stack_chk_guard_nid_postfix, which the NID patcher gives the NID of the original.
  • APS5_EXPORT spells its symbols with the leading underscore of Mach-O.
  • The fclose failure check of GuestFiopen fills /dev/full, which exists on Linux only.
  • exception_runtime is registered everywhere but macOS (the follow-up I promised on #927). It expects a host throw to go through libc's exception runtime, which libc takes over on Linux by exporting the host runtime names; on macOS it does not export them, and the system libc++abi handles the throw.
  • The formatting test names GCC's __builtin_sysv_va_list, which clang does not have; for clang it is va_list, the System V one on the hosts where it is used.

Tested

  • macOS 26.5.1, Apple M5 Max, Apple clang 21, x86-64 build under Rosetta 2. main 7e2ba73e4 with the rest of the macOS series (ci/macos-series-2 on my fork, which now includes #7937) and the libSceSsl change of #7332. The libraries do not link on macOS without the series. ninja, ninja libs and ctest -j4: 1798 tests, 1123 passed, 25 failed, the rest skipped (no Vulkan loader in the environment); guest_formatting, guest_fiopen and guest_fopen_errors pass.
  • Rebased on main 7e2ba73e4. The conflict was getc_unlocked_nid_postfix, which #8226 now reads through a local native; the call stays unqualified. The GuestArena.cpp change is gone from this pull request, because #6124 builds the same code on macOS.
  • Earlier, with this pull request alone on main: the changed libc sources and the formatting and file stream tests compiled on macOS, and they did not compile without it.
  • Linux and Windows: not run for this version. The only edits outside __APPLE__ are the four unqualified calls (the functions are declared in the global namespace by glibc), the moved test registration (the test is still registered on Linux), the va_list mapping in the test for clang, and #ifdef __linux__ in place of #ifndef _WIN32 around the /dev/full check (Windows skipped it already). An earlier version ran on my fork's CI with the rest of the series: 960 tests on Linux and 966 on Windows pass (https://github.com/mugurc/AnyPS5/actions/runs/38256280627).

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:4832574235 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4627). Originally posted by [mugurc](https://github.com/mugurc) on 2026-10-12T17:03:06Z. --- ### What The parts of libc that talk to the host and do not build with Darwin's headers and libSystem. Part of the macOS series announced on #1 (https://github.com/boykopovar/AnyPS5/issues/1#issuecomment-6124344298). - `feof_unlocked`, `ferror_unlocked`, `getc_unlocked` and `putc_unlocked` are macros on macOS, so they are called without the `::` qualifier. - `CLOCK_REALTIME_COARSE` and `st_mtim` do not exist on macOS: the write mark of `General.cpp` uses `CLOCK_REALTIME` and `st_mtimespec`. - `tm_zone` is a `char*`, not a `const char*`. - libSystem's `__cxa_thread_atexit` returns `void`; the wrapper returns 0. - Darwin's stack protector reads `__stack_chk_guard` from libSystem, and the library's own definition under that name would be bound by every other library's host code. On macOS the guard has the name `__stack_chk_guard_nid_postfix`, which the NID patcher gives the NID of the original. - `APS5_EXPORT` spells its symbols with the leading underscore of Mach-O. - The `fclose` failure check of `GuestFiopen` fills `/dev/full`, which exists on Linux only. - `exception_runtime` is registered everywhere but macOS (the follow-up I promised on #927). It expects a host `throw` to go through libc's exception runtime, which libc takes over on Linux by exporting the host runtime names; on macOS it does not export them, and the system libc++abi handles the `throw`. - The formatting test names GCC's `__builtin_sysv_va_list`, which clang does not have; for clang it is `va_list`, the System V one on the hosts where it is used. ### Tested - macOS 26.5.1, Apple M5 Max, Apple clang 21, x86-64 build under Rosetta 2. `main` 7e2ba73e4 with the rest of the macOS series (`ci/macos-series-2` on my fork, which now includes #7937) and the libSceSsl change of #7332. The libraries do not link on macOS without the series. `ninja`, `ninja libs` and `ctest -j4`: 1798 tests, 1123 passed, 25 failed, the rest skipped (no Vulkan loader in the environment); `guest_formatting`, `guest_fiopen` and `guest_fopen_errors` pass. - Rebased on `main` 7e2ba73e4. The conflict was `getc_unlocked_nid_postfix`, which #8226 now reads through a local `native`; the call stays unqualified. The `GuestArena.cpp` change is gone from this pull request, because #6124 builds the same code on macOS. - Earlier, with this pull request alone on `main`: the changed libc sources and the formatting and file stream tests compiled on macOS, and they did not compile without it. - Linux and Windows: not run for this version. The only edits outside `__APPLE__` are the four unqualified calls (the functions are declared in the global namespace by glibc), the moved test registration (the test is still registered on Linux), the `va_list` mapping in the test for clang, and `#ifdef __linux__` in place of `#ifndef _WIN32` around the `/dev/full` check (Windows skipped it already). An earlier version ran on my fork's CI with the rest of the series: 960 tests on Linux and 966 on Windows pass (https://github.com/mugurc/AnyPS5/actions/runs/38256280627). ### 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
MarcZX10 commented 2026-10-13 18:42:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T18:42:11Z.


I opened #5394 to carry the Windows line-buffering fix from #5391. It touches putc_unlocked_nid_postfix for newline flushing; I listed #4627 as a dependency so the macOS portability change can land first, then I can rebase and resolve the shared lines. If you prefer a different merge order, please say so.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6152629701 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4627#issuecomment-6152629701). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-13T18:42:11Z. --- I opened #5394 to carry the Windows line-buffering fix from #5391. It touches `putc_unlocked_nid_postfix` for newline flushing; I listed #4627 as a dependency so the macOS portability change can land first, then I can rebase and resolve the shared lines. If you prefer a different merge order, please say so.
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!4627
No description provided.