Skip to content

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

Merged
oneandonlydean merged 2 commits into
boykopovar:mainfrom
mugurc:fix/libc-dwarf-unwind-macos
Oct 26, 2026
Merged

oneandonlydean merged 2 commits into
boykopovar:mainfrom
mugurc:fix/libc-dwarf-unwind-macos

Conversation

@mugurc

@mugurc mugurc commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

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 (#1 (comment)).

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 3fd1cc3 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

_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: _Unwind_Backtrace returned _URC_END_OF_STACK without calling
its callback, and _Unwind_ForcedUnwind returned _URC_FATAL_PHASE2_ERROR
without calling the stop function. libc and the unwind callback test 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. The system unwinder reads the same FDEs for host exceptions
thrown through libc.
@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 5021 core/libs/CMakeLists.txt
core/libs/prx/libc/CMakeLists.txt
PR 6713 core/libs/prx/libc/CMakeLists.txt
PR 7081 core/libs/prx/libc/CMakeLists.txt
PR 7201 core/libs/CMakeLists.txt
core/libs/prx/libc/CMakeLists.txt
PR 7275 core/libs/CMakeLists.txt
PR 7447 core/libs/prx/libc/CMakeLists.txt
PR 7715 core/libs/prx/libc/CMakeLists.txt
PR 7851 core/libs/prx/libc/CMakeLists.txt
PR 8150 core/libs/prx/libc/CMakeLists.txt
PR 8285 core/libs/CMakeLists.txt
PR 8650 core/libs/CMakeLists.txt
PR 9156 core/libs/CMakeLists.txt
PR 9284 core/libs/CMakeLists.txt
PR 9293 core/libs/CMakeLists.txt
PR 9297 core/libs/CMakeLists.txt
PR 9302 core/libs/CMakeLists.txt
PR 9383 core/libs/CMakeLists.txt
PR 9536 core/libs/CMakeLists.txt
PR 9571 core/libs/CMakeLists.txt
PR 9772 core/libs/CMakeLists.txt
core/libs/prx/libc/CMakeLists.txt
PR 9775 core/libs/prx/libc/CMakeLists.txt
PR 9929 core/libs/prx/libc/CMakeLists.txt

…on macOS

guest_bad_optional_access throws through libc's
_Throw_bad_optional_access and catches in the test's own frame. libc's
unwinder walks that frame with its DWARF FDE, which macOS leaves out in
favour of compact unwind, so the exception reached terminate there. The
test now keeps its FDEs on macOS, as the unwind callback test does, and
the two options move into configure_macos_unwind, next to
configure_windows_unwind, for libc and both tests.
@ycbuzi

ycbuzi commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Windows run of 16e6ee8 merged onto main 7ce3b1d (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 up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants