Skip to content

feat(libc): throw bad_optional_access like bad_weak_ptr - #6079

Closed
notaxeltv wants to merge 1 commit into
boykopovar:mainfrom
notaxeltv:feat/libc-bad-optional-access-ppsa34015
Closed

notaxeltv wants to merge 1 commit into
boykopovar:mainfrom
notaxeltv:feat/libc-bad-optional-access-ppsa34015

Conversation

@notaxeltv

Copy link
Copy Markdown
Contributor

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

Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions

Copy link
Copy Markdown

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

This was referenced Oct 15, 2026
@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

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

@coltken95

Copy link
Copy Markdown

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

  • 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

isnisk commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

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 adriadam10 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build libc needs rebase Conflicts with main, rebase needed unblocks title Names a title ID on the Unblocks line

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants