feat(libc): throw bad_optional_access like bad_weak_ptr #6079

Closed
notaxeltv wants to merge 1 commit from upstream-pr/6079 into main
notaxeltv commented 2026-10-14 21:27:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by notaxeltv on 2026-10-14T21:27:13Z.


What

tools/import_audit.py on PPSA34015 lists absent libc.prx import KwzEip7m6TM (_ZSt26_Throw_bad_optional_accessv). The type, vtable and _Throw helper now follow bad_weak_ptr: plain exception, what() returns bad optional access.

Tested

Windows 10, WinLibs GCC 15.2.0, guest_bad_optional_access passes. tools/check_conventions.py --base upstream/main passes.

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
  • 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 (none)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: PPSA34015 (absent libc import)
  • GPUs tested: n/a
  • AI-assisted: yes

Made with Cursor

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4864772785 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6079). Originally posted by [notaxeltv](https://github.com/notaxeltv) on 2026-10-14T21:27:13Z. --- ### What `tools/import_audit.py` on PPSA34015 lists absent `libc.prx` import `KwzEip7m6TM` (`_ZSt26_Throw_bad_optional_accessv`). The type, vtable and `_Throw` helper now follow `bad_weak_ptr`: plain exception, `what()` returns `bad optional access`. ### Tested Windows 10, WinLibs GCC 15.2.0, `guest_bad_optional_access` passes. `tools/check_conventions.py --base upstream/main` passes. ### Checklist - [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 - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's technical 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 (none) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: PPSA34015 (absent libc import) - [x] GPUs tested: n/a - [x] AI-assisted: yes Made with [Cursor](https://cursor.com)
github-actions[bot] commented 2026-10-14 21:27:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-14T21:27:54Z.


Progress report (4808d9c → ec03143)

📈 System libraries: 88.71% (+0.02%, +7 implemented functions)

✅ 7 implemented
Library Name
libc _ZNKSt19bad_optional_access4whatEv_nid_postfix
libc _ZNSt19bad_optional_accessC1Ev_nid_postfix
libc _ZNSt19bad_optional_accessC2Ev_nid_postfix
libc _ZNSt19bad_optional_accessD0Ev_nid_postfix
libc _ZNSt19bad_optional_accessD1Ev_nid_postfix
libc _ZNSt19bad_optional_accessD2Ev_nid_postfix
libc _ZSt26_Throw_bad_optional_accessv_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6178891412 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6079#issuecomment-6178891412). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-14T21:27:54Z. --- <!-- progress-report --> ### Progress report (4808d9c → ec03143) 📈 **System libraries**: 88.71% (+0.02%, +7 implemented functions) <details> <summary>✅ 7 implemented</summary> | Library | Name | | - | - | | libc | `_ZNKSt19bad_optional_access4whatEv_nid_postfix` | | libc | `_ZNSt19bad_optional_accessC1Ev_nid_postfix` | | libc | `_ZNSt19bad_optional_accessC2Ev_nid_postfix` | | libc | `_ZNSt19bad_optional_accessD0Ev_nid_postfix` | | libc | `_ZNSt19bad_optional_accessD1Ev_nid_postfix` | | libc | `_ZNSt19bad_optional_accessD2Ev_nid_postfix` | | libc | `_ZSt26_Throw_bad_optional_accessv_nid_postfix` | </details>
github-actions[bot] commented 2026-10-15 12:14:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T12:14:19Z.


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
PR 7872 _ZNKSt19bad_optional_access4whatEv_nid_postfix
_ZNSt19bad_optional_accessC1Ev_nid_postfix
_ZNSt19bad_optional_accessC2Ev_nid_postfix
_ZNSt19bad_optional_accessD0Ev_nid_postfix
_ZNSt19bad_optional_accessD1Ev_nid_postfix
_ZNSt19bad_optional_accessD2Ev_nid_postfix
_ZSt26_Throw_bad_optional_accessv_nid_postfix
core/libs/tests/GuestBadOptionalAccess.cpp

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 3965 core/libs/prx/libc/CMakeLists.txt
PR 4627 core/libs/prx/libc/CMakeLists.txt
PR 5021 core/libs/prx/libc/CMakeLists.txt
PR 6044 core/libs/prx/libc/CMakeLists.txt
PR 6713 core/libs/prx/libc/CMakeLists.txt
PR 6819 core/libs/prx/libc/CMakeLists.txt
PR 7081 core/libs/prx/libc/CMakeLists.txt
PR 7201 core/libs/prx/libc/CMakeLists.txt
PR 7332 core/libs/prx/libc/CMakeLists.txt
PR 7411 core/libs/prx/libc/CMakeLists.txt
PR 7417 core/libs/prx/libc/CMakeLists.txt
PR 7447 core/libs/prx/libc/CMakeLists.txt
PR 7470 core/libs/prx/libc/CMakeLists.txt
PR 7525 core/libs/prx/libc/CMakeLists.txt
PR 7715 core/libs/prx/libc/CMakeLists.txt
PR 7839 core/libs/prx/libc/CMakeLists.txt
PR 7841 core/libs/prx/libc/CMakeLists.txt
PR 7851 core/libs/prx/libc/CMakeLists.txt
PR 7872 core/libs/prx/libc/CMakeLists.txt
core/libs/prx/libc/src/exception/StandardExceptions.cpp
core/libs/tests/GuestBadOptionalAccess.cpp
PR 7897 core/libs/prx/libc/CMakeLists.txt
PR 7998 core/libs/prx/libc/CMakeLists.txt
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6191788311 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6079#issuecomment-6191788311). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-15T12:14:19Z. --- <!-- 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 | |---|---|---|---| | [PR 7872](https://www.github.com/boykopovar/AnyPS5/pull/7872) | | `_ZNKSt19bad_optional_access4whatEv_nid_postfix`<br>`_ZNSt19bad_optional_accessC1Ev_nid_postfix`<br>`_ZNSt19bad_optional_accessC2Ev_nid_postfix`<br>`_ZNSt19bad_optional_accessD0Ev_nid_postfix`<br>`_ZNSt19bad_optional_accessD1Ev_nid_postfix`<br>`_ZNSt19bad_optional_accessD2Ev_nid_postfix`<br>`_ZSt26_Throw_bad_optional_accessv_nid_postfix` | `core/libs/tests/GuestBadOptionalAccess.cpp` | Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 3965](https://www.github.com/boykopovar/AnyPS5/pull/3965) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 4627](https://www.github.com/boykopovar/AnyPS5/pull/4627) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 6713](https://www.github.com/boykopovar/AnyPS5/pull/6713) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 6819](https://www.github.com/boykopovar/AnyPS5/pull/6819) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 7081](https://www.github.com/boykopovar/AnyPS5/pull/7081) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 7201](https://www.github.com/boykopovar/AnyPS5/pull/7201) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 7332](https://www.github.com/boykopovar/AnyPS5/pull/7332) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 7411](https://www.github.com/boykopovar/AnyPS5/pull/7411) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 7417](https://www.github.com/boykopovar/AnyPS5/pull/7417) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 7447](https://www.github.com/boykopovar/AnyPS5/pull/7447) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 7470](https://www.github.com/boykopovar/AnyPS5/pull/7470) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 7525](https://www.github.com/boykopovar/AnyPS5/pull/7525) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 7715](https://www.github.com/boykopovar/AnyPS5/pull/7715) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 7839](https://www.github.com/boykopovar/AnyPS5/pull/7839) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 7841](https://www.github.com/boykopovar/AnyPS5/pull/7841) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 7851](https://www.github.com/boykopovar/AnyPS5/pull/7851) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 7872](https://www.github.com/boykopovar/AnyPS5/pull/7872) | `core/libs/prx/libc/CMakeLists.txt`<br>`core/libs/prx/libc/src/exception/StandardExceptions.cpp`<br>`core/libs/tests/GuestBadOptionalAccess.cpp` | | [PR 7897](https://www.github.com/boykopovar/AnyPS5/pull/7897) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 7998](https://www.github.com/boykopovar/AnyPS5/pull/7998) | `core/libs/prx/libc/CMakeLists.txt` |
coltken95 commented 2026-10-15 21:24:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by coltken95 on 2026-10-15T21:24:36Z.


Tested on Linux x86-64 (Release build), with ec031436b merged into main e16b2bcce:

  • With the PR: guest_bad_optional_access passes.
  • With main's libc sources (keeping this PR's test and its CMake registration): the test doesn't link, missing the std::bad_optional_access constructor, destructor, typeinfo and std::_Throw_bad_optional_access exports.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6202595292 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6079#issuecomment-6202595292). Originally posted by [coltken95](https://github.com/coltken95) on 2026-10-15T21:24:36Z. --- Tested on Linux x86-64 (Release build), with ec031436b merged into main e16b2bcce: - With the PR: `guest_bad_optional_access` passes. - With main's libc sources (keeping this PR's test and its CMake registration): the test doesn't link, missing the `std::bad_optional_access` constructor, destructor, typeinfo and `std::_Throw_bad_optional_access` exports. AI-assisted: yes (Claude Code)
isnisk commented 2026-10-16 00:13:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by isnisk on 2026-10-16T00:13:56Z.


Checked on Linux: Ubuntu 26.04 (WSL2), GCC 15.2.0, Release, this head (ec031436b) merged onto main 489466d3f (clean merge).

  • With the change: guest_bad_optional_access passes, 3 rounds; no compiler warnings. So on Linux the exception is thrown inside libc and caught in the test.
  • Without it (main's StandardExceptions.cpp): the test does not link (undefined reference to _ZTISt19bad_optional_access_nid_postfix, _ZTVSt19bad_optional_access_nid_postfix, _ZNSt19bad_optional_accessC1Ev_nid_postfix).
  • check_conventions.py --base origin/main passes.

Not checked: macOS, the title.

AI-assisted: yes (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6205012603 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6079#issuecomment-6205012603). Originally posted by [isnisk](https://github.com/isnisk) on 2026-10-16T00:13:56Z. --- Checked on Linux: Ubuntu 26.04 (WSL2), GCC 15.2.0, Release, this head (`ec031436b`) merged onto `main` `489466d3f` (clean merge). - With the change: `guest_bad_optional_access` passes, 3 rounds; no compiler warnings. So on Linux the exception is thrown inside libc and caught in the test. - Without it (`main`'s `StandardExceptions.cpp`): the test does not link (`undefined reference to _ZTISt19bad_optional_access_nid_postfix`, `_ZTVSt19bad_optional_access_nid_postfix`, `_ZNSt19bad_optional_accessC1Ev_nid_postfix`). - `check_conventions.py --base origin/main` passes. Not checked: macOS, the title. AI-assisted: yes (Claude Code).
adriadam10 commented 2026-10-16 22:14:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-16T22:14:47Z.

Review: CHANGES_REQUESTED


Thanks for the PR; the vtable/typeinfo/throw plumbing mirrors bad_weak_ptr correctly, guest_bad_optional_access passes here, and without the change it fails to link as expected.

One point to fix:

  • core/libs/prx/libc/src/exception/StandardExceptions.cpp:95: what() returns "bad optional access" (the libstdc++/MSVC text). The other plain exceptions in this file follow libc++ ("bad_weak_ptr", "std::bad_function_call", "std::bad_array_new_length"), and libc++'s bad_optional_access::what() returns "bad_optional_access". Please cite where the string comes from for the PS5 libc (disassembly of a libc.prx that has the symbol, or another source). If it can't be verified, use the libc++ text and add a line under "Unknown function info" in the libc technical debt file saying the string is unverified. The test at GuestBadOptionalAccess.cpp:30 then pins that value.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5554271879 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6079#pullrequestreview-5554271879). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-16T22:14:47Z. **Review:** CHANGES_REQUESTED --- Thanks for the PR; the vtable/typeinfo/throw plumbing mirrors `bad_weak_ptr` correctly, `guest_bad_optional_access` passes here, and without the change it fails to link as expected. One point to fix: - `core/libs/prx/libc/src/exception/StandardExceptions.cpp:95`: `what()` returns `"bad optional access"` (the libstdc++/MSVC text). The other plain exceptions in this file follow libc++ (`"bad_weak_ptr"`, `"std::bad_function_call"`, `"std::bad_array_new_length"`), and libc++'s `bad_optional_access::what()` returns `"bad_optional_access"`. Please cite where the string comes from for the PS5 libc (disassembly of a `libc.prx` that has the symbol, or another source). If it can't be verified, use the libc++ text and add a line under "Unknown function info" in the libc technical debt file saying the string is unverified. The test at `GuestBadOptionalAccess.cpp:30` then pins that value.
oneandonlydean commented 2026-10-19 18:21:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-19T18:21:59Z.


Thanks @notaxeltv. Closing this as covered by #7872, which has merged with your exports and guest_bad_optional_access test plus the what() text and debt note that @adriadam10 asked for in review. Your work is what landed, and the credit is on #7872.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6274200184 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6079#issuecomment-6274200184). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-19T18:21:59Z. --- Thanks @notaxeltv. Closing this as covered by #7872, which has merged with your exports and `guest_bad_optional_access` test plus the `what()` text and debt note that @adriadam10 asked for in review. Your work is what landed, and the credit is on #7872.

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