fix(libc): keep DWARF unwind tables in libc on macOS hosts #8311

Merged
mugurc merged 2 commits from upstream-pr/8311 into main 2026-10-26 19:53:43 +00:00
mugurc commented 2026-10-20 09:44:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by mugurc on 2026-10-20T09:44:20Z.


What

unwind_callback_abi_backtrace and unwind_callback_abi_forced_unwind (#6851) fail on macOS. _Unwind_Backtrace and _Unwind_ForcedUnwind start in their own libc frame and step out of it with that frame's DWARF FDE. On macOS the compiler and the linker describe every frame they can with compact unwind (__unwind_info) and leave no __eh_frame, so libc.prx had no FDE for its own frames, and both functions failed at that first step, for a title as for the test:

  • _Unwind_Backtrace returned _URC_END_OF_STACK without calling its callback.
  • _Unwind_ForcedUnwind returned _URC_FATAL_PHASE2_ERROR without calling the stop function.

guest_bad_optional_access (#7872) fails on macOS for the same reason. It throws through libc's _Throw_bad_optional_access and catches in its own frame, which libc's unwinder could not walk, so the exception reached terminate.

libc, the unwind callback test and guest_bad_optional_access are now compiled with -femit-dwarf-unwind=always and linked with -no_compact_unwind on macOS, so their frames keep their FDEs in __eh_frame. configure_macos_unwind sets the two options, next to configure_windows_unwind, which keeps the same tables on Windows. The system unwinder reads these FDEs for the host exceptions thrown through libc. 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 libraries do not link on macOS without the rest of the macOS series, so the run is on main 3fd1cc393 with the series (ci/macos-series-2 on my fork), #8279, #8284, #8287, #8288, the open macOS fixes #7524 and #7937, and three changes from #7332.

  • Before: libc.prx has a 7,832-byte __unwind_info and no __eh_frame, and the test binary has no __eh_frame either. With the return codes printed, _Unwind_Backtrace returns 5 with no callback, and _Unwind_ForcedUnwind returns 2 with no stop call.
  • After: libc.prx has an 86,904-byte __eh_frame and no __unwind_info. All five unwind_callback_abi tests, exception_personality and guest_bad_optional_access pass, 3 runs of 3. Before, guest_bad_optional_access ended with "[libc] unhandled exception 'St19bad_optional_access'".
  • Cost for a host exception inside libc: stat of a 256-byte name throws and catches a filesystem_error in libc. 20,000 calls take 9.8 to 10.1 µs each with compact unwind and 11.6 to 13.2 µs each with the DWARF tables, over three runs each.
  • ninja, ninja libs and ctest -j4 with the first commit: 1648 tests, 1015 passed, 18 failed, the rest skipped (no Vulkan loader in the environment). No test fails that passed before this change. The 18 failed in my run before this PR too, guest_bad_optional_access among them, which the second commit fixes. The other failing tests do not end in an unhandled libc exception.
  • exception_runtime and exception_c_cleanup are still not registered on macOS. With the DWARF tables they fail as before: their host throw goes to the system libc++abi, because libc does not export the host runtime names on macOS as it does on Linux.
  • Linux and Windows: not run. configure_macos_unwind does nothing outside macOS, so nothing changes there.

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 under Silent stubs in their library's technical debt file
  • 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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4933959035 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8311). Originally posted by [mugurc](https://github.com/mugurc) on 2026-10-20T09:44:20Z. --- ### What `unwind_callback_abi_backtrace` and `unwind_callback_abi_forced_unwind` (#6851) fail on macOS. `_Unwind_Backtrace` and `_Unwind_ForcedUnwind` start in their own libc frame and step out of it with that frame's DWARF FDE. On macOS the compiler and the linker describe every frame they can with compact unwind (`__unwind_info`) and leave no `__eh_frame`, so `libc.prx` had no FDE for its own frames, and both functions failed at that first step, for a title as for the test: - `_Unwind_Backtrace` returned `_URC_END_OF_STACK` without calling its callback. - `_Unwind_ForcedUnwind` returned `_URC_FATAL_PHASE2_ERROR` without calling the stop function. `guest_bad_optional_access` (#7872) fails on macOS for the same reason. It throws through libc's `_Throw_bad_optional_access` and catches in its own frame, which libc's unwinder could not walk, so the exception reached `terminate`. `libc`, the unwind callback test and `guest_bad_optional_access` are now compiled with `-femit-dwarf-unwind=always` and linked with `-no_compact_unwind` on macOS, so their frames keep their FDEs in `__eh_frame`. `configure_macos_unwind` sets the two options, next to `configure_windows_unwind`, which keeps the same tables on Windows. The system unwinder reads these FDEs for the host exceptions thrown through libc. 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 libraries do not link on macOS without the rest of the macOS series, so the run is on `main` 3fd1cc393 with the series (`ci/macos-series-2` on my fork), #8279, #8284, #8287, #8288, the open macOS fixes #7524 and #7937, and three changes from #7332. - Before: `libc.prx` has a 7,832-byte `__unwind_info` and no `__eh_frame`, and the test binary has no `__eh_frame` either. With the return codes printed, `_Unwind_Backtrace` returns 5 with no callback, and `_Unwind_ForcedUnwind` returns 2 with no stop call. - After: `libc.prx` has an 86,904-byte `__eh_frame` and no `__unwind_info`. All five `unwind_callback_abi` tests, `exception_personality` and `guest_bad_optional_access` pass, 3 runs of 3. Before, `guest_bad_optional_access` ended with "[libc] unhandled exception 'St19bad_optional_access'". - Cost for a host exception inside libc: `stat` of a 256-byte name throws and catches a `filesystem_error` in libc. 20,000 calls take 9.8 to 10.1 µs each with compact unwind and 11.6 to 13.2 µs each with the DWARF tables, over three runs each. - `ninja`, `ninja libs` and `ctest -j4` with the first commit: 1648 tests, 1015 passed, 18 failed, the rest skipped (no Vulkan loader in the environment). No test fails that passed before this change. The 18 failed in my run before this PR too, `guest_bad_optional_access` among them, which the second commit fixes. The other failing tests do not end in an unhandled libc exception. - `exception_runtime` and `exception_c_cleanup` are still not registered on macOS. With the DWARF tables they fail as before: their host `throw` goes to the system libc++abi, because libc does not export the host runtime names on macOS as it does on Linux. - Linux and Windows: not run. `configure_macos_unwind` does nothing outside macOS, so nothing changes there. ### 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 under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [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] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
ycbuzi commented 2026-10-21 07:03:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ycbuzi on 2026-10-21T07:03:09Z.


Windows run of 16e6ee8224 merged onto main 7ce3b1df3e (1e02689671, clean), one of the hosts the description lists as not run. Windows 11 Home 10.0.26200, MinGW-w64 GCC 15.2.0 (ucrt-posix-seh r7), Release, BUILD_TESTING=ON.

Built libc, guest_bad_optional_access_tests and unwind_callback_abi_tests with no errors or warnings; ctest --repeat until-fail:2 on the five unwind_callback_abi_* tests and guest_bad_optional_access: all pass on both repeats. Not run: Linux.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6310132770 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8311#issuecomment-6310132770). Originally posted by [ycbuzi](https://github.com/ycbuzi) on 2026-10-21T07:03:09Z. --- Windows run of 16e6ee8224 merged onto `main` 7ce3b1df3e (1e02689671, clean), one of the hosts the description lists as not run. Windows 11 Home 10.0.26200, MinGW-w64 GCC 15.2.0 (ucrt-posix-seh r7), Release, `BUILD_TESTING=ON`. Built `libc`, `guest_bad_optional_access_tests` and `unwind_callback_abi_tests` with no errors or warnings; `ctest --repeat until-fail:2` on the five `unwind_callback_abi_*` tests and `guest_bad_optional_access`: all pass on both repeats. Not run: Linux.
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!8311
No description provided.