feat(libc): exception runtime on macOS hosts #927
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/927"
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-06T17:47:44Z.
What
Exception support for the macOS port, opened first as suggested in #1. Two commits:
fix(libc): export the C personality to guest code. This is the only change that reaches Linux and Windows. Guest C built with-fexceptionsimports__gcc_personality_v0for its cleanup frames, and libc.prx did not export it. The routine becomes__gcc_personality_v0_nid_postfix. The host__gcc_personality_v0forwards to it, as__gxx_personality_v0already does, andCallPersonalityrecognizes both names.feat(libc): exception runtime on macOS hosts. On macOS the host keeps libc++abi, because libc++ binds__cxa_throwtwo-level. libc.prx serves guest code:std::exception_ptris modelled directly, and the Itaniumtype_infolayouts that libc++abi keeps private are declared. Both are compiled only under_LIBCPP_VERSION/_LIBCPPABI_VERSION.PT_GNU_EH_FRAME, using adl_iterate_phdremulation over the ELF program headers that relinked images keep in__APS5DATA,__meta.__TEXT,__eh_frame.sceKernelGetModuleInfoForUnwindgets a macOS branch that uses the same emulation and falls back todladdrfor host images. #904 changes the Windows branch of the same function; whichever lands second will be rebased.exception_c_cleanupis not built on macOS, because it throws from host code.Everything in the second commit is
__APPLE__or libc++ only, so it stays inert until the macOS build andrelinker --macos(which writes__APS5DATA,__meta) come in the next pull requests.Tested
exception_runtimeandexception_c_cleanup; Windows passed 357/357.main:exception_runtimepasses;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 github-actions[bot] on 2026-10-07T13:57:03Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)_ZNSt15__exception_ptr13exception_ptrC1EPv_nid_postfix_ZNSt15__exception_ptr13exception_ptrC2EPv_nid_postfix_ZSt17current_exceptionv_nid_postfixcore/libs/prx/libc/CMakeLists.txtL246-250Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-08T09:48:50Z.
Progress report (
30e89cc→0ae0bbf)➖ System libraries: 85.4% (+0.0%, +1 implemented functions)
✅ 1 implemented
__gcc_personality_v0_nid_postfixImported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-08T09:56:10Z.
Review: CHANGES_REQUESTED
Build + ctest on this PR merged onto current
main: 433/433 pass. Findings:__gcc_personality_v0_nid_postfixexported to guest code,core/libs/prx/libc/src/exception/Personality.cpp:74) has no test that fails without it.exception_c_cleanuplinks the host__gcc_personality_v0, and it already passed onmain, so it doesn't show the guest export orCallPersonalitymatching__gcc_personality_v0_nid_postfix(Unwind.cpp:31). Please add a test that reaches the personality through the_nid_postfixsymbol (the way a guest binds it) and fails onmain.GuestImages.cpp, the__eh_framescan inUnwind.cpp:150-171, theModule.cpp:114-158branch): inert on Linux/Windows, and I can't run it here (no macOS, no macOS CI). It also depends onMetaVersion = 2and the__APS5DATA,__metaoffsets (GuestImages.cpp:11-14), which the relinker side doesn't have in this repo yet. Please attach the macOS test output (exception_runtimeand the relinked guest fixtures) to the PR, and keep the layout constants in sync with therelinker --macosPR when it lands.The overlap bot's #1128 and #1176 hits don't apply (formatting-only / already merged).
Imported from boykopovar/AnyPS5. Originally posted by Zheorgyan on 2026-10-08T10:15:48Z.
ran this on Linux since you only have the Mac. merged onto current main at
6e037e98, Ubuntu 24.04 in Docker with GCC 14.2. the only conflict iscore/libs/prx/libc/CMakeLists.txt, where main added theguest_image_anonymousandguest_collatetests right after the block you wrap inif(NOT APPLE). keeping main's lines and wrapping just theexception_c_cleanuppart resolves itwith that the build is clean and
exception_runtime,exception_c_cleanupandguest_image_anonymouspass. the full suite has 26 failures, but every one of them fails the same way on main in that container, which is x86-64 emulated on Apple Silicon, so none come from this PR. I can't test WindowsImported from boykopovar/AnyPS5. Originally posted by mugurc on 2026-10-08T10:20:17Z.
Thanks for the review. I pushed an update rebased on current
main, with one new commit.Test for the guest export.
test(libc): reach the C personality through its guest exportaddsexception_personality(core/libs/tests/ExceptionPersonality.cpp). It builds a call-site table by hand and drives the routine the way the unwinder does, through__gcc_personality_v0_nid_postfixand throughCallPersonality: cleanup phase installs the landing pad, search phase continues, ranges before and after the call site, no landing pad, no LSDA, signal frame, unsupported version, unknown personality. Onmainit does not link, since the export does not exist. With the_nid_postfixcomparison removed fromCallPersonality(Unwind.cpp:31) the test aborts.macOS output. Run on macOS under Rosetta with the libc files of this PR on top of my port branch, which is based on
5895ea72, not currentmain; the port's build changes are not in this PR yet.ctest: 357 tests, 216 passed, 141 skipped (GPU tests, no Vulkan environment), 0 failed. Passing:exception_runtime,exception_personality, andmacos_fixtures(argv, import, tls, exception, c-cleanup, threads, module, tls-modules, intel-unconverted, intel).Layout constants. Noted.
MetaVersion = 2and the__APS5DATA,__metaoffsets inGuestImages.cppwill be kept in sync with therelinker --macosPR.Split. The export and its test are self-contained in the first and last commits, so I can move them into their own PR if you prefer.
Thanks also to @Zheorgyan for running this on Linux. In the
CMakeLists.txtconflict I wrappedguest_image_anonymousin the sameif(NOT APPLE)asexception_c_cleanup, because it reads/proc/self/exeand would fail on macOS; on Linux the result is the same.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-08T10:35:48Z.
Review: APPROVED
Checked on this PR merged onto current
main: build + ctest 439/439,exception_personalitypasses; linux, windows, conventions and report CI green. Without the__gcc_personality_v0_nid_postfixcomparison inCallPersonality(Unwind.cpp:31) the new test aborts, and onmainit doesn't link, so it covers the guest export. The macOS half is inert on Linux/Windows; we can't run it here, so it's merged on code review plus the macOS output you attached. Please keepMetaVersionand the__APS5DATA,__metaoffsets (GuestImages.cpp:11-14) in sync with therelinker --macosPR. Merging.Imported from boykopovar/AnyPS5. Originally posted by mugurc on 2026-10-08T11:02:23Z.
A correction to the macOS output above:
exception_runtimepassed in that run only because the test's assertions were compiled out in Release at the time (742fa2e3later added#undef NDEBUG). With assertions on it does not pass on macOS, because host code there keeps libc++abi while the test expects the project's runtime to serve hostthrows. The guest side is covered by the relinkedexceptionandc-cleanupfixtures and byexception_personality, which do pass. I will registerexception_runtimeonly outside macOS in the macOS build PR.