fix(libc): export __cxa_thread_atexit #5065

Merged
MarcZX10 merged 3 commits from upstream-pr/5065 into main 2026-10-13 14:03:20 +00:00
MarcZX10 commented 2026-10-13 10:19:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T10:19:03Z.


What

Export libc's __cxa_thread_atexit NID (BKSCW2bCACA) by forwarding to the existing guest-ABI-aware thread destructor registration implementation. Extend guest_thread_callback_abi to 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 -D confirms the patched export BKSCW2bCACA.
python3 tools/check_conventions.py --base upstream/main --head HEAD and git diff --check passed.
Not run: Void Terrarium on Windows or Linux.

Checklist

  • Based on current main; checked open PRs for overlap. PR #5027 changes a separate function in the same source file.
  • One topic per PR; follow-ups go in a new PR
  • No comments except technical debt (no code comments added)
  • Unimplemented paths throw (this forwards to the existing implementation)
  • No notes/investigation artifacts added
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not title-specific
  • Depends on: none
  • Unblocks: Void Terrarium (PPSA03061), issue #5055
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4841753377 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5065). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-13T10:19:03Z. --- ### What Export libc's `__cxa_thread_atexit` NID (`BKSCW2bCACA`) by forwarding to the existing guest-ABI-aware thread destructor registration implementation. Extend `guest_thread_callback_abi` to 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 -D` confirms the patched export `BKSCW2bCACA`. `python3 tools/check_conventions.py --base upstream/main --head HEAD` and `git diff --check` passed. Not run: Void Terrarium on Windows or Linux. ### Checklist - [x] Based on current `main`; checked open PRs for overlap. PR #5027 changes a separate function in the same source file. - [x] One topic per PR; follow-ups go in a new PR - [x] No comments except technical debt (no code comments added) - [x] Unimplemented paths throw (this forwards to the existing implementation) - [x] No notes/investigation artifacts added - [x] New third-party code is a submodule built from source (none added) - [x] Generic behaviour, not title-specific - [x] Depends on: none - [x] Unblocks: Void Terrarium (PPSA03061), issue #5055 - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-13 10:25:01 +00:00 (Migrated from github.com)

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
Library Name
libc __cxa_thread_atexit_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6143484935 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5065#issuecomment-6143484935). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-13T10:25:01Z. --- <!-- progress-report --> ### Progress report (e152ba8 → 1ab578a) ➖ **System libraries**: 88.01% (+0.0%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libc | `__cxa_thread_atexit_nid_postfix` | </details>
adriadam10 commented 2026-10-13 10:37:48 +00:00 (Migrated from github.com)

Imported 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 extended guest_thread_callback_abi passes (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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6143693832 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5065#issuecomment-6143693832). Originally posted by [adriadam10](https://github.com/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 extended `guest_thread_callback_abi` passes (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.
xXPBSXx commented 2026-10-13 11:13:20 +00:00 (Migrated from github.com)

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_atexit with the NID suffix gives BKSCW2bCACA (and __cxa_thread_atexit_impl gives 6Q-K18Jt5q8, a different NID), and the forwarding keeps the guest-ABI handling of the _impl path. The description lists only a Linux run; guest_thread_callback_abi has not been reported on Windows, where the thread-exit destructor path differs (_WIN32 branch of LibcInternalExtCxaThreadAtexit). We can run it there if useful.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6144280663 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5065#issuecomment-6144280663). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-13T11:13:20Z. --- Review note (static): the export name checks out: SHA-1 of `__cxa_thread_atexit` with the NID suffix gives `BKSCW2bCACA` (and `__cxa_thread_atexit_impl` gives `6Q-K18Jt5q8`, a different NID), and the forwarding keeps the guest-ABI handling of the `_impl` path. The description lists only a Linux run; `guest_thread_callback_abi` has not been reported on Windows, where the thread-exit destructor path differs (`_WIN32` branch of `LibcInternalExtCxaThreadAtexit`). We can run it there if useful. AI-assisted (Claude Code).
LeandroLP23 commented 2026-10-13 11:22:44 +00:00 (Migrated from github.com)

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 927d874fa merged onto main 5d50886ee with a clean merge.

  • ctest -R '^guest_thread_callback_abi$': 1/1 passed.
  • objdump -p core/libs/libs/libc.prx lists BKSCW2bCACA in the export table, next to 6Q-K18Jt5q8 (__cxa_thread_atexit_impl). So the Windows libc.prx can satisfy the import that #5055 reports as GetLastError: 127.

I don't have Void Terrarium, so I didn't run the title itself.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6144432870 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5065#issuecomment-6144432870). Originally posted by [LeandroLP23](https://github.com/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 `927d874fa` merged onto `main` `5d50886ee` with a clean merge. - `ctest -R '^guest_thread_callback_abi$'`: 1/1 passed. - `objdump -p core/libs/libs/libc.prx` lists `BKSCW2bCACA` in the export table, next to `6Q-K18Jt5q8` (`__cxa_thread_atexit_impl`). So the Windows `libc.prx` can satisfy the import that #5055 reports as `GetLastError: 127`. I don't have Void Terrarium, so I didn't run the title itself.
nikowolf123 commented 2026-10-13 13:04:10 +00:00 (Migrated from github.com)

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 dso through __cxa_thread_atexit_impl_nid_postfix to 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 passing nullptr as the DSO.

main already does this for the other export: LibcInternalExtCxaThreadAtexit_nid_postfix passes nullptr on _WIN32 (CxxAbiSupport.cpp#L86-L92, 9f81bddf6). Fix options:

  • give the new export the same rule; or
  • move the _WIN32 null-DSO rule into __cxa_thread_atexit_impl_nid_postfix itself. That also covers a guest that calls the existing __cxa_thread_atexit_impl export with its own DSO.

The Windows run of guest_thread_callback_abi can't show this. The test sets directDso = nullptr on _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_handle would cover it.

AI-assisted: written with Claude Code; I checked the code paths and the MinGW source linked above.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6146189942 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5065#issuecomment-6146189942). Originally posted by [nikowolf123](https://github.com/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 `dso` through `__cxa_thread_atexit_impl_nid_postfix` to MinGW's `__cxa_thread_atexit`, which asserts `!dso || dso == &__dso_handle` ([tls_atexit.c#L70](https://github.com/mingw-w64/mingw-w64/blob/b7f5cd3bbb51e03dd1f8a90dcc9f7c632b5e1054/mingw-w64-crt/crt/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](https://github.com/boykopovar/AnyPS5/issues/5055#issuecomment-6144520809), and [gets past it by passing `nullptr`](https://github.com/boykopovar/AnyPS5/issues/5055#issuecomment-6144650053) as the DSO. `main` already does this for the other export: `LibcInternalExtCxaThreadAtexit_nid_postfix` passes `nullptr` on `_WIN32` ([CxxAbiSupport.cpp#L86-L92](https://github.com/boykopovar/AnyPS5/blob/0f2683cb7daf0d92a2b38c8ed2a00e03e12380a0/core/libs/prx/libc/src/CxxAbiSupport.cpp#L86-L92), 9f81bddf6). Fix options: - give the new export the same rule; or - move the `_WIN32` null-DSO rule into `__cxa_thread_atexit_impl_nid_postfix` itself. That also covers a guest that calls the existing `__cxa_thread_atexit_impl` export with its own DSO. The Windows run of `guest_thread_callback_abi` can't show this. The test sets `directDso = nullptr` on `_WIN32` ([GuestThreadCallbackAbi.cpp#L57-L60](https://github.com/boykopovar/AnyPS5/blob/0f2683cb7daf0d92a2b38c8ed2a00e03e12380a0/core/libs/tests/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_handle` would cover it. AI-assisted: written with Claude Code; I checked the code paths and the MinGW source linked above.
adriadam10 commented 2026-10-13 13:08:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T13:08:08Z.


Rebased on main and pushed one commit on top, after the review note by @nikowolf123:

  • On Windows the guest's dso reached MinGW's __cxa_thread_atexit, which asserts !dso || dso == &__dso_handle, so the new export would hit the assertion reported in #5055. The _WIN32 null-DSO rule now lives in __cxa_thread_atexit_impl_nid_postfix, so __cxa_thread_atexit, __cxa_thread_atexit_impl and LibcInternalExtCxaThreadAtexit all get it.
  • GuestThreadCallbackAbi.cpp no longer sets directDso = nullptr on 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6146263899 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5065#issuecomment-6146263899). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-13T13:08:08Z. --- Rebased on `main` and pushed one commit on top, after the review note by @nikowolf123: - On Windows the guest's `dso` reached MinGW's `__cxa_thread_atexit`, which asserts `!dso || dso == &__dso_handle`, so the new export would hit the assertion reported in #5055. The `_WIN32` null-DSO rule now lives in `__cxa_thread_atexit_impl_nid_postfix`, so `__cxa_thread_atexit`, `__cxa_thread_atexit_impl` and `LibcInternalExtCxaThreadAtexit` all get it. - `GuestThreadCallbackAbi.cpp` no longer sets `directDso = nullptr` on 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.
adriadam10 commented 2026-10-13 13:51:28 +00:00 (Migrated from github.com)

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_postfix calls MinGW's __cxa_thread_atexit, and the allow-list in core/libs/tests/ThreadLocalDestructors.cmake only named __cxa_thread_atexit_impl_nid_postfix and LibcInternalExtCxaThreadAtexit_nid_postfix.

Pushed one commit on top adding __cxa_thread_atexit_nid_postfix to that list (an explicit guest registration, like the other two). Merging once the full Windows run is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6147105662 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5065#issuecomment-6147105662). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-13T13:51:28Z. --- The full Windows build failed `prx_thread_local_destructors`: the new `__cxa_thread_atexit_nid_postfix` calls MinGW's `__cxa_thread_atexit`, and the allow-list in `core/libs/tests/ThreadLocalDestructors.cmake` only named `__cxa_thread_atexit_impl_nid_postfix` and `LibcInternalExtCxaThreadAtexit_nid_postfix`. Pushed one commit on top adding `__cxa_thread_atexit_nid_postfix` to that list (an explicit guest registration, like the other two). Merging once the full Windows run is green.
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!5065
No description provided.