fix(libc): declare the __sub_kind values on libc++abi hosts #26739

Open
Romannachwievor wants to merge 2 commits from upstream-pr/26739 into main
Romannachwievor commented 2026-11-24 18:24:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Romannachwievor on 2026-11-24T18:24:57Z.


What

libc no longer compiles on macOS since #10416. The RTTI cast callbacks it added to core/libs/prx/libc/src/exception/Runtime.cpp use the __class_type_info::__sub_kind enumerators (__not_contained, __contained_ambig, __contained_virtual_mask, __contained_public_mask, __contained_public). libstdc++ declares them in cxxabi.h. libc++abi does not, and the declaration this repo supplies for it in core/libs/prx/libc/include/specifics/itanium/CxxAbi.hpp (the #ifdef _LIBCPPABI_VERSION branch) only had __unknown:

../core/libs/prx/libc/src/exception/Runtime.cpp:296:91: error: no member named '__contained_virtual_mask' in '__cxxabiv1::__class_type_info'

This adds the missing enumerators with the values libstdc++ uses. I checked them against GCC 15.2 cxxabi.h: __virtual_mask 1, __public_mask 2 and __hwm_bit 2 give __contained_mask 4, __contained_private 4 and __contained_public 6. Only the libc++abi branch changes, so Linux and Windows, which use libstdc++, compile the same code as before. Emscripten also defines _LIBCPPABI_VERSION and gets the same enumerators.

main CI has no macOS job, which is probably why this went unnoticed.

tools/pr_overlap.py --branch found no overlap with the 2482 open pull requests. --names UpcastTypeInfoResult DynamicCastTypeInfo found them implemented on main only.

Tested

Apple M1, macOS 26.5, x86_64 build under Rosetta, AppleClang.

  • Building libc on main at 17220db6a3 fails with the error above. With this change it builds.
  • ctest --test-dir build -R '^guest_dynamic_cast$': passed in 3 of 3 runs. core/libs/tests/GuestDynamicCast.cpp compares the callback results against the literal path values 1, 2, 4, 6 and 7, so each enumerator Runtime.cpp uses is checked by value.
  • After merging current main (6d85fbf66b): libc builds and guest_dynamic_cast passes 3 of 3.
  • Mutation: with __contained_public = 4, guest_dynamic_cast fails.
  • The 160 tests from 25 exception, unwind, __cxa_*, RTTI and JSON test executables: 157 of 160 pass with this change. A main build from before #10416 (adacf0bd83) on the same machine also passes 157 of 160, with the same three failures (guest_libc_internal_exception_virtuals, guest_libcxx_exception_pointer, guest_throw_bad_array_new_length).

Not run: Linux, Windows, Emscripten.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt and the licence notice of code adapted from upstream (see AGENTS.md)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5477952282 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/26739). Originally posted by [Romannachwievor](https://github.com/Romannachwievor) on 2026-11-24T18:24:57Z. --- ### What libc no longer compiles on macOS since #10416. The RTTI cast callbacks it added to `core/libs/prx/libc/src/exception/Runtime.cpp` use the `__class_type_info::__sub_kind` enumerators (`__not_contained`, `__contained_ambig`, `__contained_virtual_mask`, `__contained_public_mask`, `__contained_public`). libstdc++ declares them in `cxxabi.h`. libc++abi does not, and the declaration this repo supplies for it in `core/libs/prx/libc/include/specifics/itanium/CxxAbi.hpp` (the `#ifdef _LIBCPPABI_VERSION` branch) only had `__unknown`: ``` ../core/libs/prx/libc/src/exception/Runtime.cpp:296:91: error: no member named '__contained_virtual_mask' in '__cxxabiv1::__class_type_info' ``` This adds the missing enumerators with the values libstdc++ uses. I checked them against GCC 15.2 `cxxabi.h`: `__virtual_mask` 1, `__public_mask` 2 and `__hwm_bit` 2 give `__contained_mask` 4, `__contained_private` 4 and `__contained_public` 6. Only the libc++abi branch changes, so Linux and Windows, which use libstdc++, compile the same code as before. Emscripten also defines `_LIBCPPABI_VERSION` and gets the same enumerators. main CI has no macOS job, which is probably why this went unnoticed. `tools/pr_overlap.py --branch` found no overlap with the 2482 open pull requests. `--names UpcastTypeInfoResult DynamicCastTypeInfo` found them implemented on `main` only. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Apple M1, macOS 26.5, x86_64 build under Rosetta, AppleClang. - Building `libc` on `main` at 17220db6a3 fails with the error above. With this change it builds. - `ctest --test-dir build -R '^guest_dynamic_cast$'`: passed in 3 of 3 runs. `core/libs/tests/GuestDynamicCast.cpp` compares the callback results against the literal path values 1, 2, 4, 6 and 7, so each enumerator Runtime.cpp uses is checked by value. - After merging current `main` (6d85fbf66b): `libc` builds and `guest_dynamic_cast` passes 3 of 3. - Mutation: with `__contained_public = 4`, `guest_dynamic_cast` fails. - The 160 tests from 25 exception, unwind, `__cxa_*`, RTTI and JSON test executables: 157 of 160 pass with this change. A main build from before #10416 (adacf0bd83) on the same machine also passes 157 of 160, with the same three failures (`guest_libc_internal_exception_virtuals`, `guest_libcxx_exception_pointer`, `guest_throw_bad_array_new_length`). Not run: Linux, Windows, Emscripten. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [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) and the licence notice of code adapted from upstream (see AGENTS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes (Claude Code)
kripotker commented 2026-11-24 18:51:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by kripotker on 2026-11-24T18:51:20Z.

Review: APPROVED


Review: fix(libc): declare the __sub_kind values on libc++abi hosts

Approve. The values match libstdc++, and giving libc++abi hosts the same values is the right choice.

What I checked

  • Every enumerator matches GCC 15.2 libsupc++/cxxabi.h. There, __virtual_mask = 0x1, __public_mask = 0x2 and __hwm_bit = 2, which gives:
    • __not_contained 1;
    • __contained_ambig 2;
    • __contained_virtual_mask 1;
    • __contained_public_mask 2;
    • __contained_mask = 1 << 2 = 4;
    • __contained_private 4;
    • __contained_public 6.
  • These values aren't passed to the host's libc++abi. Runtime.cpp defines its own __upcast_result and __dyncast_result, and UpcastTypeInfoResult / DynamicCastTypeInfo write the values into them for the guest. So the guest sees the same part2dst, whole2dst, whole2src and dst2src values whether the host uses libstdc++ or libc++abi. libc++abi's own internal constants don't matter here.
  • Only the #ifdef _LIBCPPABI_VERSION branch of CxxAbi.hpp changes, so libstdc++ hosts (Linux, Windows) compile the same code as before.

What I ran

python3 tools/check_conventions.py

All conventions checks passed. (Windows 11, PR head 6d85fbf66b.)

Not checked

I have no macOS or Emscripten host here, so I didn't compile the libc++abi branch myself.

AI-assisted: yes (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6045359627 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/26739#pullrequestreview-6045359627). Originally posted by [kripotker](https://github.com/kripotker) on 2026-11-24T18:51:20Z. **Review:** APPROVED --- ## Review: fix(libc): declare the __sub_kind values on libc++abi hosts **Approve.** The values match libstdc++, and giving libc++abi hosts the same values is the right choice. ### What I checked - Every enumerator matches [GCC 15.2 `libsupc++/cxxabi.h`](https://github.com/gcc-mirror/gcc/blob/releases/gcc-15.2.0/libstdc%2B%2B-v3/libsupc%2B%2B/cxxabi.h). There, `__virtual_mask = 0x1`, `__public_mask = 0x2` and `__hwm_bit = 2`, which gives: - `__not_contained` 1; - `__contained_ambig` 2; - `__contained_virtual_mask` 1; - `__contained_public_mask` 2; - `__contained_mask` = `1 << 2` = 4; - `__contained_private` 4; - `__contained_public` 6. - These values aren't passed to the host's libc++abi. `Runtime.cpp` defines its own `__upcast_result` and `__dyncast_result`, and `UpcastTypeInfoResult` / `DynamicCastTypeInfo` write the values into them for the guest. So the guest sees the same `part2dst`, `whole2dst`, `whole2src` and `dst2src` values whether the host uses libstdc++ or libc++abi. libc++abi's own internal constants don't matter here. - Only the `#ifdef _LIBCPPABI_VERSION` branch of `CxxAbi.hpp` changes, so libstdc++ hosts (Linux, Windows) compile the same code as before. ### What I ran ``` python3 tools/check_conventions.py ``` `All conventions checks passed.` (Windows 11, PR head 6d85fbf66b.) ### Not checked I have no macOS or Emscripten host here, so I didn't compile the libc++abi branch myself. AI-assisted: yes (Claude Code).
MarcZX10 commented 2026-11-25 14:21:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T14:21:44Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this; the points below are optional.

What I ran

Reviewed head 6d85fbf66b6d14d32b788cb4b8e5ee122df1c05a. Read description.md, commits.md, manifest.json, diff.patch, and the complete changed header. No tests or builds were run during this review.

Results

Check Result Note
Diff review passed One changed header
Build and tests not run Author-reported results only

Findings

Blocking

None.

Non-blocking

None.

Not verified

No programmatic checks were run. The author's reported macOS build and test results were not independently verified. files.json was unavailable through the provided reader, so excluded files were not confirmed; the manifest lists one changed file and it was read in full.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6059374381 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/26739#pullrequestreview-6059374381). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-25T14:21:44Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this; the points below are optional. ## What I ran Reviewed head `6d85fbf66b6d14d32b788cb4b8e5ee122df1c05a`. Read `description.md`, `commits.md`, `manifest.json`, `diff.patch`, and the complete changed header. No tests or builds were run during this review. ## Results | Check | Result | Note | |---|---|---| | Diff review | passed | One changed header | | Build and tests | not run | Author-reported results only | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified No programmatic checks were run. The author's reported macOS build and test results were not independently verified. `files.json` was unavailable through the provided reader, so excluded files were not confirmed; the manifest lists one changed file and it was read in full. ## To get this to a good state Nothing is required.
Quimera996 commented 2026-11-25 21:16:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Quimera996 on 2026-11-25T21:16:29Z.

Review: COMMENTED


Tested on a second Mac.

Setup: Apple M5, macOS 27.2.1, Apple clang 21.0.0 (Xcode 27.2), x86-64 Release under Rosetta 2. Head 6d85fbf66b applied on main ff5b409dda with git apply, which is clean. The control is that main without it.

Check main This PR
ninja libc fails with 14 errors, all in exception/Runtime.cpp: no member named '__contained_virtual_mask' in '__cxxabiv1::__class_type_info' and the same for the other enumerators builds
guest_dynamic_cast cannot be built passed, 5 of 5 runs
Full build (ninja -k 0) builds, except three targets this PR does not touch: libcurl.prx (#17425), GuestLibcxxRegexError.cpp and PipelinedFlushReadOrder.cpp

Values. I compared them with libstdc++-v3/libsupc++/cxxabi.h at the releases/gcc-15.2.0 tag: __virtual_mask 0x1, __public_mask 0x2 and __hwm_bit 2 give 0, 1, 2, 1, 2, 4, 4 and 6, as declared here.

Wrong values. I changed one value at a time and rebuilt libc and the test. guest_dynamic_cast aborts with each of __not_contained = 3, __contained_ambig = 3, __contained_virtual_mask = 0, __contained_public_mask = 4 and __contained_public = 4, and passes again (3 of 3) with the PR's values back. Those are the five new enumerators Runtime.cpp uses. Nothing uses __contained_mask or __contained_private, so no test covers those two.

Full suite. ctest --parallel 8 --timeout 120 with SDL_VIDEODRIVER=dummy SDL_AUDIODRIVER=dummy, 6635 tests: 5009 passed, 1573 skipped, 18 failed, and 35 did not run because their executables are behind the three targets above.

  • Of the 180 tests with exception, unwind, cxa, rtti, dynamic_cast, typeinfo, type_info, throw, catch or terminate in their name, 176 pass. Three of the four that fail are the ones the description lists. The fourth is guest_exception_pointer, which #25087 added to main after this head was made. It aborts at current_exception inside catch returned wrong pointer, in a block that throws and catches in the test itself and has no cast.
  • The other 14 are agc_unit_flags_allocation_failure_populated, agc_write_tracking, file_streams, guest_audio_propagation, guest_kernel_sys, guest_kernel_sys_execve, guest_math, guest_math_exact, guest_poll, guest_sce_net, guest_socket_options, guest_socket_port_zero, guest_udp and run_report. I have no control run for them, because main does not build here without this PR. The new enumerators are used only in Runtime.cpp.

#27201, opened a day later, declares the same eight values.

No title was run. Linux and Windows were not built.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6065097676 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/26739#pullrequestreview-6065097676). Originally posted by [Quimera996](https://github.com/Quimera996) on 2026-11-25T21:16:29Z. **Review:** COMMENTED --- Tested on a second Mac. **Setup:** Apple M5, macOS 27.2.1, Apple clang 21.0.0 (Xcode 27.2), x86-64 Release under Rosetta 2. Head `6d85fbf66b` applied on `main` `ff5b409dda` with `git apply`, which is clean. The control is that `main` without it. | Check | `main` | This PR | |---|---|---| | `ninja libc` | fails with 14 errors, all in `exception/Runtime.cpp`: `no member named '__contained_virtual_mask' in '__cxxabiv1::__class_type_info'` and the same for the other enumerators | builds | | `guest_dynamic_cast` | cannot be built | passed, 5 of 5 runs | | Full build (`ninja -k 0`) | | builds, except three targets this PR does not touch: `libcurl.prx` (#17425), `GuestLibcxxRegexError.cpp` and `PipelinedFlushReadOrder.cpp` | **Values.** I compared them with `libstdc++-v3/libsupc++/cxxabi.h` at the `releases/gcc-15.2.0` tag: `__virtual_mask` 0x1, `__public_mask` 0x2 and `__hwm_bit` 2 give 0, 1, 2, 1, 2, 4, 4 and 6, as declared here. **Wrong values.** I changed one value at a time and rebuilt `libc` and the test. `guest_dynamic_cast` aborts with each of `__not_contained = 3`, `__contained_ambig = 3`, `__contained_virtual_mask = 0`, `__contained_public_mask = 4` and `__contained_public = 4`, and passes again (3 of 3) with the PR's values back. Those are the five new enumerators `Runtime.cpp` uses. Nothing uses `__contained_mask` or `__contained_private`, so no test covers those two. **Full suite.** `ctest --parallel 8 --timeout 120` with `SDL_VIDEODRIVER=dummy SDL_AUDIODRIVER=dummy`, 6635 tests: 5009 passed, 1573 skipped, 18 failed, and 35 did not run because their executables are behind the three targets above. - Of the 180 tests with `exception`, `unwind`, `cxa`, `rtti`, `dynamic_cast`, `typeinfo`, `type_info`, `throw`, `catch` or `terminate` in their name, 176 pass. Three of the four that fail are the ones the description lists. The fourth is `guest_exception_pointer`, which #25087 added to `main` after this head was made. It aborts at `current_exception inside catch returned wrong pointer`, in a block that throws and catches in the test itself and has no cast. - The other 14 are `agc_unit_flags_allocation_failure_populated`, `agc_write_tracking`, `file_streams`, `guest_audio_propagation`, `guest_kernel_sys`, `guest_kernel_sys_execve`, `guest_math`, `guest_math_exact`, `guest_poll`, `guest_sce_net`, `guest_socket_options`, `guest_socket_port_zero`, `guest_udp` and `run_report`. I have no control run for them, because `main` does not build here without this PR. The new enumerators are used only in `Runtime.cpp`. #27201, opened a day later, declares the same eight values. No title was run. Linux and Windows were not built. AI-assisted: yes (Claude Code)
ligmaSec commented 2026-12-03 13:36:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T13:36:24Z.

Review: COMMENTED


Compiled the exact header with Clang 19 and libc++abi and with GCC and libstdc++. Both compile-time probes verified all eight enum values.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6170836343 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/26739#pullrequestreview-6170836343). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T13:36:24Z. **Review:** COMMENTED --- Compiled the exact header with Clang 19 and libc++abi and with GCC and libstdc++. Both compile-time probes verified all eight enum values. AI-assisted: yes.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/26739:upstream-pr/26739'
git switch 'upstream-pr/26739'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/26739'
git switch 'upstream-pr/26739'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/26739'
git switch 'upstream-pr/26739'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/26739'
git switch 'main'
git merge --squash 'upstream-pr/26739'
git switch 'main'
git merge --ff-only 'upstream-pr/26739'
git switch 'main'
git merge 'upstream-pr/26739'
git push origin 'main'
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!26739
No description provided.