fix(libc): run the cleanups of frames that use the C personality #478
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/478"
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 oneandonlydean on 2026-10-03T19:32:24Z.
What
libc's unwinder called only its own C++ personality. A frame whose CIE names any other personality made
_Unwind_RaiseExceptionreturn_URC_FATAL_PHASE1_ERROR(or phase 2 fail), so the exception reachedterminate("[libc] unhandled exception") even with a matchingcatchabove.GCC gives such frames the C personality,
__gcc_personality_v0:-fexceptionsthat has cleanups (__attribute__((cleanup)));libSceAgcDriverand its recompiler, where 11 tests failed this way.Under the Itanium C++ ABI the C personality never catches. In the search phase it continues unwinding; in the cleanup phase it installs the call site's landing pad, if there is one, with the exception in the first data register and 0 in the second, and continues otherwise. The landing pad ends in
_Unwind_Resume. This is what libgcc'sunwind-c.cdoes.Personality.cpp: libc defines__gcc_personality_v0with that behaviour, reading the same LSDA layout as the C++ personality. Like__gxx_personality_v0, it is a host symbol, so code linked against libc binds to it.Unwind.cpp:OwnPersonalitybecomesCallPersonality, which calls the C++ or the C personality for the frame and still fails the phase for any other personality.Tested
BUILD_TESTING=ON;ctestpasses (146/146).exception_c_cleanuptest (tests/ExceptionCCleanup.cbuilt with-fexceptions, driven fromtests/ExceptionCCleanup.cpp): anintthrown from C++ through C frames with cleanups is caught in C++ with the cleanups run (one frame, two nested frames, a C++ destructor frame mixed in), a call made before the cleanup's scope leaves it unrun, and a throw with no handler still terminates without running the C cleanup. Without the change the test aborts with "[libc] unhandled exception" on the first case.libSceAgcDriverandshader_recompiler_agc_driveronly (INTERPROCEDURAL_OPTIMIZATION, not part of this PR): both then import__gcc_personality_v0. With this changectestpasses 146/146; withmain's unwinder 12 tests abort, the new one and 11 driver tests (agc_driver,agc_driver_graphics,agc_shader_memory,guest_indexed_drawand others).exception_runtime, since it forks for the terminate case.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)