Repository navigation
fix(libc): build the host-facing libc code on macOS - #4627
Conversation
|
I opened #5394 to carry the Windows line-buffering fix from #5391. It touches |
feof_unlocked, ferror_unlocked, getc_unlocked and putc_unlocked are macros on macOS, so they are called without the global scope qualifier. The remaining differences are the ones Darwin's headers and libSystem have: - CLOCK_REALTIME_COARSE and st_mtim do not exist; the write mark uses CLOCK_REALTIME and st_mtimespec. - tm_zone is a non-const char*. - __cxa_thread_atexit returns void, so the wrapper reports success. - Darwin's stack protector reads __stack_chk_guard from libSystem; the guard of the guest libc has the postfixed name, which receives the NID of the original. - APS5_EXPORT spells the symbols with the leading underscore of Mach-O. - GuestArenaSetProtection and PosixProtection are built on macOS as on Linux. - The fclose failure test fills /dev/full, which exists on Linux only. exception_runtime relies on the Itanium unwinder of libc, which is not registered on macOS (the host libc++abi is used), so its test is only registered elsewhere.
dba6a02 to
c27787a
Compare
|
Code review: the portability changes read correctly. The macros behind |
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 (#1 (comment)).
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 feat(libc): exception runtime on macOS hosts #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
main7e2ba73 with the rest of the macOS series (ci/macos-series-2on my fork, which now includes feat(libkernel): JIT shared memory on macOS hosts #7937) and the libSceSsl change of feat: macOS on Apple Silicon host support (Rosetta 2 and MoltenVK) #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.main7e2ba73. The conflict wasgetc_unlocked_nid_postfix, which fix(libc): switch update streams to reading as FreeBSD does #8226 now reads through a localnative; the call stays unqualified. TheGuestArena.cppchange is gone from this pull request, because feat(libc): reserve the guest arena on macOS #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)