fix(libc): build the host-facing libc code on macOS #4627
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4627"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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_unlockedandputc_unlockedare macros on macOS, so they are called without the::qualifier.CLOCK_REALTIME_COARSEandst_mtimdo not exist on macOS: the write mark ofGeneral.cppusesCLOCK_REALTIMEandst_mtimespec.tm_zoneis achar*, not aconst char*.__cxa_thread_atexitreturnsvoid; the wrapper returns 0.__stack_chk_guardfrom 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_EXPORTspells its symbols with the leading underscore of Mach-O.fclosefailure check ofGuestFiopenfills/dev/full, which exists on Linux only.exception_runtimeis registered everywhere but macOS (the follow-up I promised on #927). It expects a hostthrowto 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 thethrow.__builtin_sysv_va_list, which clang does not have; for clang it isva_list, the System V one on the hosts where it is used.Tested
main7e2ba73e4with the rest of the macOS series (ci/macos-series-2on my fork, which now includes #7937) and the libSceSsl change of #7332. The libraries do not link on macOS without the series.ninja,ninja libsandctest -j4: 1798 tests, 1123 passed, 25 failed, the rest skipped (no Vulkan loader in the environment);guest_formatting,guest_fiopenandguest_fopen_errorspass.main7e2ba73e4. The conflict wasgetc_unlocked_nid_postfix, which #8226 now reads through a localnative; the call stays unqualified. TheGuestArena.cppchange is gone from this pull request, because #6124 builds the same code on macOS.main: the changed libc sources and the formatting and file stream tests compiled on macOS, and they did not compile without it.__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), theva_listmapping in the test for clang, and#ifdef __linux__in place of#ifndef _WIN32around the/dev/fullcheck (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
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)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_postfixfor 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.