fix(exceptions): interpose libstdc++ ABI on Linux so the project's own unwinder drives it #14

Merged
obelisk-complex merged 2 commits from upstream-pr/14 into main 2026-09-27 08:27:37 +00:00
obelisk-complex commented 2026-09-26 20:10:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by obelisk-complex on 2026-09-26T20:10:36Z.


Closes #13.

On native Linux, these .prx shared libraries and their test executables dynamically link real libstdc++/libgcc, so a plain throw went through the system's __cxa_throw/_Unwind_RaiseException. That still invoked this project's own __gxx_personality_v0_nid_postfix (the CIE's personality pointer is a raw function address, agnostic to which unwinder is walking the stack), but handed it libgcc's incompatible private _Unwind_Context layout, corrupting every field Personality.cpp reads and aborting with no exception message.

Changes

  • OwnPersonality() in Unwind.cpp now recognises the bare __gxx_personality_v0 wrapper on Linux too (previously Windows-only).
  • Exports.cpp exports the real ABI names (__cxa_throw, __cxa_begin_catch/end_catch, __cxa_rethrow, __cxa_allocate/free_exception, __cxa_call_terminate, __cxa_get_exception_ptr, __cxa_current_exception_type, __cxa_init_primary_exception, the std::terminate/uncaught_exception(s) mangled names, and the core _Unwind_* entry points) through the existing GCC_GLOBAL_ALIAS assembler-alias macro rather than new C++ definitions (a plain redefinition under these names conflicts with <cxxabi.h>'s own declarations). This lets ELF symbol interposition make this project's own implementation win process-wide over libgcc_s.so.1/libstdc++.so.6.
  • __cxa_init_primary_exception_nid_postfix is new: GCC 13's inline std::make_exception_ptr calls __cxa_init_primary_exception, and nothing implemented it before.
  • Deliberately did not alias __dynamic_cast, __cxa_pure_virtual or __cxa_deleted_virtual. Nothing in core/libs/prx needs them rerouted, and doing so would divert every RTTI cast in libstdc++ and third-party code (SDL2, glslang) through this project's slower walker for no benefit.

Testing (Linux, GCC)

  • Full build succeeds.
  • ctest: 23/30 -> 30/30. Fixes guest_rendering_wait, guest_buffer_reuse, guest_shader_link, guest_system_exit_parameters, guest_once, guest_memory, guest_search; six of these seven are the same pre-existing failures #7 named.
  • Built a standalone reproduction outside the test suite (a plain throw std::runtime_error, linked against real libstdc++) and confirmed with gdb that it crashes the old way on the commit before this fix, and reaches the documented terminate path after it.
  • Not tested on Windows; that path is untouched, guarded by #ifdef __linux__ / #if defined(_WIN32) || defined(__linux__).

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4649389475 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14). Originally posted by [obelisk-complex](https://github.com/obelisk-complex) on 2026-09-26T20:10:36Z. --- Closes #13. On native Linux, these `.prx` shared libraries and their test executables dynamically link real libstdc++/libgcc, so a plain `throw` went through the system's `__cxa_throw`/`_Unwind_RaiseException`. That still invoked this project's own `__gxx_personality_v0_nid_postfix` (the CIE's personality pointer is a raw function address, agnostic to which unwinder is walking the stack), but handed it libgcc's incompatible private `_Unwind_Context` layout, corrupting every field `Personality.cpp` reads and aborting with no exception message. Changes - `OwnPersonality()` in `Unwind.cpp` now recognises the bare `__gxx_personality_v0` wrapper on Linux too (previously Windows-only). - `Exports.cpp` exports the real ABI names (`__cxa_throw`, `__cxa_begin_catch`/`end_catch`, `__cxa_rethrow`, `__cxa_allocate`/`free_exception`, `__cxa_call_terminate`, `__cxa_get_exception_ptr`, `__cxa_current_exception_type`, `__cxa_init_primary_exception`, the `std::terminate`/`uncaught_exception(s)` mangled names, and the core `_Unwind_*` entry points) through the existing `GCC_GLOBAL_ALIAS` assembler-alias macro rather than new C++ definitions (a plain redefinition under these names conflicts with `<cxxabi.h>`'s own declarations). This lets ELF symbol interposition make this project's own implementation win process-wide over `libgcc_s.so.1`/`libstdc++.so.6`. - `__cxa_init_primary_exception_nid_postfix` is new: GCC 13's inline `std::make_exception_ptr` calls `__cxa_init_primary_exception`, and nothing implemented it before. - Deliberately did not alias `__dynamic_cast`, `__cxa_pure_virtual` or `__cxa_deleted_virtual`. Nothing in `core/libs/prx` needs them rerouted, and doing so would divert every RTTI cast in libstdc++ and third-party code (SDL2, glslang) through this project's slower walker for no benefit. Testing (Linux, GCC) - Full build succeeds. - `ctest`: 23/30 -> 30/30. Fixes `guest_rendering_wait`, `guest_buffer_reuse`, `guest_shader_link`, `guest_system_exit_parameters`, `guest_once`, `guest_memory`, `guest_search`; six of these seven are the same pre-existing failures #7 named. - Built a standalone reproduction outside the test suite (a plain `throw std::runtime_error`, linked against real libstdc++) and confirmed with `gdb` that it crashes the old way on the commit before this fix, and reaches the documented terminate path after it. - Not tested on Windows; that path is untouched, guarded by `#ifdef __linux__` / `#if defined(_WIN32) || defined(__linux__)`. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Pacuka commented 2026-09-26 20:59:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Pacuka on 2026-09-26T20:59:05Z.


Tested on Linux with The Smurfs Dreams (Unreal Engine, on top of #5, see #12). I had worked around the same mixed-runtime problem the opposite way, by making the native __cxa_* aliases Windows-only. Replacing that with this PR gets the game exactly as far (same draws, first 4 frames presented). Host catches also work now: the GPU worker's catch handles a VideoOut "window was closed" exception that previously ended in std::terminate. I've switched #12 to build on this PR.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5849831612 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14#issuecomment-5849831612). Originally posted by [Pacuka](https://github.com/Pacuka) on 2026-09-26T20:59:05Z. --- Tested on Linux with The Smurfs Dreams (Unreal Engine, on top of #5, see #12). I had worked around the same mixed-runtime problem the opposite way, by making the native `__cxa_*` aliases Windows-only. Replacing that with this PR gets the game exactly as far (same draws, first 4 frames presented). Host catches also work now: the GPU worker's `catch` handles a VideoOut "window was closed" exception that previously ended in `std::terminate`. I've switched #12 to build on this PR.
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!14
No description provided.