fix(libc): export __cxa_thread_atexit #5065
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5065"
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 MarcZX10 on 2026-10-13T10:19:03Z.
What
Export libc's
__cxa_thread_atexitNID (BKSCW2bCACA) by forwarding to the existing guest-ABI-aware thread destructor registration implementation. Extendguest_thread_callback_abito register through this export alias and verify destructor LIFO order.Tested
Linux, GCC 12.2, Release: built
guest_thread_callback_abi_tests;ctest -R '^guest_thread_callback_abi$'passed (1/1).Built
libc.prx;nm -Dconfirms the patched exportBKSCW2bCACA.python3 tools/check_conventions.py --base upstream/main --head HEADandgit diff --checkpassed.Not run: Void Terrarium on Windows or Linux.
Checklist
main; checked open PRs for overlap. PR #5027 changes a separate function in the same source file.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T10:25:01Z.
Progress report (
e152ba8→1ab578a)➖ System libraries: 88.01% (+0.0%, +1 implemented functions)
✅ 1 implemented
__cxa_thread_atexit_nid_postfixImported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T10:37:48Z.
Checked the export hashes to
BKSCW2bCACA(__cxa_thread_atexit), forwards to the existing guest-ABI implementation, and the extendedguest_thread_callback_abipasses (LIFO order with the new alias) and fails to link without the change. Scoped ctest green (90/90); merging once the full build is green.Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-13T11:13:20Z.
Review note (static): the export name checks out: SHA-1 of
__cxa_thread_atexitwith the NID suffix givesBKSCW2bCACA(and__cxa_thread_atexit_implgives6Q-K18Jt5q8, a different NID), and the forwarding keeps the guest-ABI handling of the_implpath. The description lists only a Linux run;guest_thread_callback_abihas not been reported on Windows, where the thread-exit destructor path differs (_WIN32branch ofLibcInternalExtCxaThreadAtexit). We can run it there if useful.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-13T11:22:44Z.
Windows build of this, since the description covers Linux only: Windows 11 (26300), WinLibs GCC 15.2.0, Release. Head
927d874famerged ontomain5d50886eewith a clean merge.ctest -R '^guest_thread_callback_abi$': 1/1 passed.objdump -p core/libs/libs/libc.prxlistsBKSCW2bCACAin the export table, next to6Q-K18Jt5q8(__cxa_thread_atexit_impl). So the Windowslibc.prxcan satisfy the import that #5055 reports asGetLastError: 127.I don't have Void Terrarium, so I didn't run the title itself.
Imported from boykopovar/AnyPS5. Originally posted by nikowolf123 on 2026-10-13T13:04:10Z.
Review note on Windows, from reading the code and the MinGW source (not run on Windows here):
On Windows this export passes the guest's
dsothrough__cxa_thread_atexit_impl_nid_postfixto MinGW's__cxa_thread_atexit, which asserts!dso || dso == &__dso_handle(tls_atexit.c#L70). A guest passes its own module's__dso_handle, so the assertion fires. With this change applied, the Void Terrarium report in #5055 hits exactly this assertion, and gets past it by passingnullptras the DSO.mainalready does this for the other export:LibcInternalExtCxaThreadAtexit_nid_postfixpassesnullptron_WIN32(CxxAbiSupport.cpp#L86-L92,9f81bddf6). Fix options:_WIN32null-DSO rule into__cxa_thread_atexit_impl_nid_postfixitself. That also covers a guest that calls the existing__cxa_thread_atexit_implexport with its own DSO.The Windows run of
guest_thread_callback_abican't show this. The test setsdirectDso = nullptron_WIN32(GuestThreadCallbackAbi.cpp#L57-L60), so on Windows the new export is only ever called with a null DSO. A Windows case with a non-null pointer that is not the host's__dso_handlewould cover it.AI-assisted: written with Claude Code; I checked the code paths and the MinGW source linked above.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T13:08:08Z.
Rebased on
mainand pushed one commit on top, after the review note by @nikowolf123:dsoreached MinGW's__cxa_thread_atexit, which asserts!dso || dso == &__dso_handle, so the new export would hit the assertion reported in #5055. The_WIN32null-DSO rule now lives in__cxa_thread_atexit_impl_nid_postfix, so__cxa_thread_atexit,__cxa_thread_atexit_implandLibcInternalExtCxaThreadAtexitall get it.GuestThreadCallbackAbi.cppno longer setsdirectDso = nullptron Windows, so the test passes a non-host DSO there too.Scoped Linux run green (92/92). Merging once the full Windows run is green.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T13:51:28Z.
The full Windows build failed
prx_thread_local_destructors: the new__cxa_thread_atexit_nid_postfixcalls MinGW's__cxa_thread_atexit, and the allow-list incore/libs/tests/ThreadLocalDestructors.cmakeonly named__cxa_thread_atexit_impl_nid_postfixandLibcInternalExtCxaThreadAtexit_nid_postfix.Pushed one commit on top adding
__cxa_thread_atexit_nid_postfixto that list (an explicit guest registration, like the other two). Merging once the full Windows run is green.