fix(libc): export __cxa_thread_atexit through the existing callback b… #5090

Closed
MrMha wants to merge 1 commit from upstream-pr/5090 into main
MrMha commented 2026-10-13 11:18:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MrMha on 2026-10-13T11:18:14Z.


What

Void Terrarium (PPSA03061) reports an unresolved libc.prx import, BKSCW2bCACA, when using the host libc (#5055). This is the NID of __cxa_thread_atexit.

Add the missing export as a forwarding wrapper to the existing __cxa_thread_atexit_impl callback bridge. The wrapper forwards the destructor, object and DSO arguments unchanged and returns the registration result. Extend GuestThreadCallbackAbi.cpp to register through the new export and verify that four destructors execute once, in reverse registration order, with the original object pointers and after the worker exits.
Addresses #5055. Resolution of the missing import does not establish further title compatibility.

Tested

Prior local validation recorded for head bda3cda2c7eee5eb9f242a08dc4732729f5693b3: Linux x86-64, GCC 13.3, Python 3.12.

  • A focused C++20 build of the production translation unit and extended callback test passed with -Wall -Wextra -Werror, function/data sections and linker garbage collection.
  • The same check passed with AddressSanitizer and UndefinedBehaviorSanitizer; LeakSanitizer was disabled because thread inspection was unavailable.
  • The repository NID calculation returned BKSCW2bCACA.
  • Local code-convention and whitespace checks were reported as passing.

These results were supplied in the attached work record and were not rerun in this description review. No full runtime build/CTest, patched-library loading, Windows/macOS execution or Void Terrarium run is claimed. The inspected GitHub full Linux/Windows runtime jobs were skipped; passing relinker jobs do not validate this libc change.

Outstanding work

  • This implementation duplicates open PR #5065, which adds the same export and substantially the same callback regression. It is an alternative implementation, not a dependency. The repository requires avoiding duplicate implementations; coordinate which PR will proceed before review readiness.
  • At inspected main 5d50886ee4045dc2a081d8d93bf8e667f6d82325, this branch was 43 main commits behind, with merge base ae244d527ab201f56e43c664f81e145d57370eba. Update the branch and validate the resulting head.
  • The first checklist item remains unchecked because those conditions are not yet satisfied.

Checklist

  • Based on current main; no other open PR implements the same functions (see outstanding work above)
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw; no silent stubs added
  • No notes, investigation files or images added to the repository
  • No new third-party code
  • Generic behaviour, not specific to one title
  • Depends on: none (implementation dependency; overlap coordination is outstanding)
  • Unblocks: none (no locally verified title progress or Game bring-up discussion)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4842399708 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5090). Originally posted by [MrMha](https://github.com/MrMha) on 2026-10-13T11:18:14Z. --- ### What Void Terrarium (PPSA03061) reports an unresolved `libc.prx` import, `BKSCW2bCACA`, when using the host libc (#5055). This is the NID of `__cxa_thread_atexit`. Add the missing export as a forwarding wrapper to the existing `__cxa_thread_atexit_impl` callback bridge. The wrapper forwards the destructor, object and DSO arguments unchanged and returns the registration result. Extend `GuestThreadCallbackAbi.cpp` to register through the new export and verify that four destructors execute once, in reverse registration order, with the original object pointers and after the worker exits. Addresses #5055. Resolution of the missing import does not establish further title compatibility. ### Tested Prior local validation recorded for head `bda3cda2c7eee5eb9f242a08dc4732729f5693b3`: Linux x86-64, GCC 13.3, Python 3.12. - A focused C++20 build of the production translation unit and extended callback test passed with `-Wall -Wextra -Werror`, function/data sections and linker garbage collection. - The same check passed with AddressSanitizer and UndefinedBehaviorSanitizer; LeakSanitizer was disabled because thread inspection was unavailable. - The repository NID calculation returned `BKSCW2bCACA`. - Local code-convention and whitespace checks were reported as passing. These results were supplied in the attached work record and were not rerun in this description review. No full runtime build/CTest, patched-library loading, Windows/macOS execution or Void Terrarium run is claimed. The inspected GitHub full Linux/Windows runtime jobs were skipped; passing relinker jobs do not validate this libc change. ### Outstanding work - This implementation duplicates open PR #5065, which adds the same export and substantially the same callback regression. It is an alternative implementation, not a dependency. The repository requires avoiding duplicate implementations; coordinate which PR will proceed before review readiness. - At inspected main `5d50886ee4045dc2a081d8d93bf8e667f6d82325`, this branch was 43 main commits behind, with merge base `ae244d527ab201f56e43c664f81e145d57370eba`. Update the branch and validate the resulting head. - The first checklist item remains unchecked because those conditions are not yet satisfied. ### Checklist - [ ] Based on current `main`; no other open PR implements the same functions (see outstanding work above) - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw; no silent stubs added - [x] No notes, investigation files or images added to the repository - [x] No new third-party code - [x] Generic behaviour, not specific to one title - [x] Depends on: none (implementation dependency; overlap coordination is outstanding) - [x] Unblocks: none (no locally verified title progress or Game bring-up discussion) - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-13 11:25:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T11:25:20Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#5065 core/libs/prx/libc/src/CxxAbiSupport.cpp L85
core/libs/tests/GuestThreadCallbackAbi.cpp L16, L27, L39, L64, L71, L87
__cxa_thread_atexit_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6144474400 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5090#issuecomment-6144474400). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-13T11:25:20Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #5065 | `core/libs/prx/libc/src/CxxAbiSupport.cpp` [L85](https://github.com/boykopovar/AnyPS5/blob/0f2683cb7daf0d92a2b38c8ed2a00e03e12380a0/core/libs/prx/libc/src/CxxAbiSupport.cpp#L85)<br>`core/libs/tests/GuestThreadCallbackAbi.cpp` [L16](https://github.com/boykopovar/AnyPS5/blob/0f2683cb7daf0d92a2b38c8ed2a00e03e12380a0/core/libs/tests/GuestThreadCallbackAbi.cpp#L16), [L27](https://github.com/boykopovar/AnyPS5/blob/0f2683cb7daf0d92a2b38c8ed2a00e03e12380a0/core/libs/tests/GuestThreadCallbackAbi.cpp#L27), [L39](https://github.com/boykopovar/AnyPS5/blob/0f2683cb7daf0d92a2b38c8ed2a00e03e12380a0/core/libs/tests/GuestThreadCallbackAbi.cpp#L39), [L64](https://github.com/boykopovar/AnyPS5/blob/0f2683cb7daf0d92a2b38c8ed2a00e03e12380a0/core/libs/tests/GuestThreadCallbackAbi.cpp#L64), [L71](https://github.com/boykopovar/AnyPS5/blob/0f2683cb7daf0d92a2b38c8ed2a00e03e12380a0/core/libs/tests/GuestThreadCallbackAbi.cpp#L71), [L87](https://github.com/boykopovar/AnyPS5/blob/0f2683cb7daf0d92a2b38c8ed2a00e03e12380a0/core/libs/tests/GuestThreadCallbackAbi.cpp#L87) | `__cxa_thread_atexit_nid_postfix` | |
github-actions[bot] commented 2026-10-13 11:36:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T11:36:03Z.


Progress report (5d50886 → bda3cda)

➖ System libraries: 87.86% (+0.0%, +1 implemented functions)

✅ 1 implemented
Library Name
libc __cxa_thread_atexit_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6144650697 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5090#issuecomment-6144650697). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-13T11:36:03Z. --- <!-- progress-report --> ### Progress report (5d50886 → bda3cda) ➖ **System libraries**: 87.86% (+0.0%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libc | `__cxa_thread_atexit_nid_postfix` | </details>
xXPBSXx commented 2026-10-13 11:44:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-13T11:44:57Z.


Review note (static): this adds the same function as the older open #5065 (opened 10:19Z; this one 11:18Z): a forwarding __cxa_thread_atexit_nid_postfix to __cxa_thread_atexit_impl_nid_postfix plus an extension of GuestThreadCallbackAbi.cpp. git merge-tree of the two heads reports conflicts in CxxAbiSupport.cpp and GuestThreadCallbackAbi.cpp, so only one can land. This PR has the better text (it names the issue it fixes, Void Terrarium #5055, and checks that the destructors run only at thread exit); maybe the two authors can agree on one PR. The export name is right: SHA-1 of __cxa_thread_atexit gives BKSCW2bCACA.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6144799958 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5090#issuecomment-6144799958). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-13T11:44:57Z. --- Review note (static): this adds the same function as the older open #5065 (opened 10:19Z; this one 11:18Z): a forwarding `__cxa_thread_atexit_nid_postfix` to `__cxa_thread_atexit_impl_nid_postfix` plus an extension of `GuestThreadCallbackAbi.cpp`. `git merge-tree` of the two heads reports conflicts in `CxxAbiSupport.cpp` and `GuestThreadCallbackAbi.cpp`, so only one can land. This PR has the better text (it names the issue it fixes, Void Terrarium #5055, and checks that the destructors run only at thread exit); maybe the two authors can agree on one PR. The export name is right: SHA-1 of `__cxa_thread_atexit` gives `BKSCW2bCACA`. AI-assisted (Claude Code).
nikowolf123 commented 2026-10-13 13:04:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by nikowolf123 on 2026-10-13T13:04:12Z.


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:6146190386 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5090#issuecomment-6146190386). Originally posted by [nikowolf123](https://github.com/nikowolf123) on 2026-10-13T13:04:12Z. --- 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:07:04 +00:00 (Migrated from github.com)

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


Closing as a duplicate: #5065 (opened an hour earlier) adds the same __cxa_thread_atexit forwarding wrapper and the same extension of guest_thread_callback_abi, and the two conflict in CxxAbiSupport.cpp and GuestThreadCallbackAbi.cpp, so only one can land. CONTRIBUTING asks for a single open PR per function, and the first checklist item here is unchecked for that reason.

Both PRs also share the Windows problem reported by @nikowolf123: the guest's dso goes unchanged to MinGW's __cxa_thread_atexit, which asserts !dso || dso == &__dso_handle (this is the assertion hit in #5055). LibcInternalExtCxaThreadAtexit_nid_postfix already passes nullptr on _WIN32; the export should do the same (or __cxa_thread_atexit_impl_nid_postfix should), with a Windows test case using a non-null DSO.

Please continue on #5065 with that fix. You're welcome to reopen this one if #5065 is dropped.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6146244497 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5090#issuecomment-6146244497). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-13T13:07:04Z. --- Closing as a duplicate: #5065 (opened an hour earlier) adds the same `__cxa_thread_atexit` forwarding wrapper and the same extension of `guest_thread_callback_abi`, and the two conflict in `CxxAbiSupport.cpp` and `GuestThreadCallbackAbi.cpp`, so only one can land. CONTRIBUTING asks for a single open PR per function, and the first checklist item here is unchecked for that reason. Both PRs also share the Windows problem reported by @nikowolf123: the guest's `dso` goes unchanged to MinGW's `__cxa_thread_atexit`, which asserts `!dso || dso == &__dso_handle` (this is the assertion hit in #5055). `LibcInternalExtCxaThreadAtexit_nid_postfix` already passes `nullptr` on `_WIN32`; the export should do the same (or `__cxa_thread_atexit_impl_nid_postfix` should), with a Windows test case using a non-null DSO. Please continue on #5065 with that fix. You're welcome to reopen this one if #5065 is dropped.

Pull request closed

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!5090
No description provided.