feat(libSceLibcInternal): implement collate<char> compare, hash and do_* members #15711

Merged
B-Howell merged 7 commits from upstream-pr/15711 into main 2026-11-07 15:36:52 +00:00
B-Howell commented 2026-11-04 09:07:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by B-Howell on 2026-11-04T09:07:26Z.


What

Implements five std::collate<char> members in libSceLibcInternal that used to throw through NotImplemented_nid_no_patch (sceLibcInternalPending3_043..047 in Err.cpp):

Symbol NID Implementation
_ZNKSt7collateIcE10do_compareEPKcS2_S2_S2_ 1eEXfeW6wrI collate<char> vtable slot 6 (libc CollateCompare)
_ZNKSt7collateIcE12do_transformEPKcS2_ gYlF567r3-A slot 7 (libc CollateTransform)
_ZNKSt7collateIcE7do_hashEPKcS2_ GSAXi4F1SlM slot 8 (libc CollateHash)
_ZNKSt7collateIcE7compareEPKcS2_S2_S2_ Q-8lQCGMj4g virtual do_compare through the facet's vtable (offset 0x20)
_ZNKSt7collateIcE4hashEPKcS2_ 6vYXzFD-mrk virtual do_hash through the facet's vtable (offset 0x30)

These are the C++ standard members. [locale.collate.members] says compare "Returns: do_compare(low1, high1, low2, high2)" and hash "Returns: do_hash(low, high)". libc's _ZNKSt7collateIcE9transformEPKcS2_ already does the same thing for transform, through GuestLocale::CollateVtable (static_assert(offsetof(CollateVtable, compare) == 0x20) and hash == 0x30 in GuestLocale.hpp). The do_* members are the collate<char> base implementations. They call the functions held in slots 6 to 8 of libc's exported _ZTVSt7collateIcE, which are the same CollateCompare, CollateTransform and CollateHash that g_collateVtable uses. Because they never look at the facet's vtable, a derived facet that overrides do_compare still reaches the base member here. Their rules and known gaps come from libc unchanged: C-locale byte order, the FNV-1a hash, and do_transform throwing on embedded nulls. A null facet or a facet with no vtable makes compare and hash throw.

Changes:

  • New file core/libs/prx/libSceLibcInternal/Collate.cpp. The five stubs are removed from Err.cpp.
  • _ZTVSt7collateIcE_nid_postfix is declared in prx/libc/include/Api.hpp, and the five entry points in prx/libSceLibcInternal/include/Api.hpp.
  • New guest test guest_libc_internal_collate (core/libs/tests/GuestLibcInternalCollate.cpp). It covers ordering, prefix and unsigned-byte cases, embedded nulls, null empty ranges, rejection of reversed ranges, the hash value and its offset basis, inline and heap do_transform results, virtual dispatch to an overriding facet, and the base do_* members ignoring that override.
  • docs/dev/debt/libSceLibcInternal.md: the five "prototype and behavior are unverified" lines are removed and a Functional entry is added.

tools/progress.py collect_libraries(): origin/main has 9913 done of 37146 (libSceLibcInternal 92 done, 1045 todo). This branch has 9918 done (libSceLibcInternal 97 done, 1040 todo), so done goes up by 5 and no new todo appears.

Tested

Only the focused test target and the library were built. No title was run.

  • Windows 11, WinLibs GCC 15.2.0 (MinGW-w64), Release: ctest -R '^(guest_libc_internal_collate|conventions_unknown_nids|conventions_debt_length|conventions_doc_links|debt_split)$' ran 3 times, and each run passed 5 of 5 tests with 0 failures.
  • WSL Ubuntu 22.04, GCC 11.4.0, Release: the same 5 tests ran 3 times, and each run passed 5 of 5 with 0 failures.
  • guest_libc_internal_collate is the new guest test. conventions_unknown_nids, conventions_debt_length, conventions_doc_links and debt_split are the repository's checker self-tests for the conventions and the debt-file split, and were run because the debt file changed.
  • Negative control on both platforms: main's production Err.cpp plus the new test, with no collate implementation, fails to link guest_libc_internal_collate_tests. The undefined references are to sceLibcInternalCollateDoCompare_nid_no_patch, DoTransform, DoHash, Compare and Hash.
  • python3 tools/check_conventions.py --base origin/main printed "All conventions checks passed."
  • python3 tools/pr_overlap.py --branch feat/r2-collate-char found no PR exporting the same functions and no PR adding the same new files. Its only matches are neighbouring lines in libSceLibcInternal/CMakeLists.txt and the debt file (#10749, #14158, #15692). I grepped the diffs of every PR it could not compare (#5021, #10780, #11831, #13486, #13778, #13782, #13881, #14085, #14212, #14401, #14837, #14936) and none of them contains these NIDs or files.

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

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5151795126 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15711). Originally posted by [B-Howell](https://github.com/B-Howell) on 2026-11-04T09:07:26Z. --- ### What Implements five `std::collate<char>` members in libSceLibcInternal that used to throw through `NotImplemented_nid_no_patch` (`sceLibcInternalPending3_043`..`047` in `Err.cpp`): | Symbol | NID | Implementation | | --- | --- | --- | | `_ZNKSt7collateIcE10do_compareEPKcS2_S2_S2_` | `1eEXfeW6wrI` | `collate<char>` vtable slot 6 (libc `CollateCompare`) | | `_ZNKSt7collateIcE12do_transformEPKcS2_` | `gYlF567r3-A` | slot 7 (libc `CollateTransform`) | | `_ZNKSt7collateIcE7do_hashEPKcS2_` | `GSAXi4F1SlM` | slot 8 (libc `CollateHash`) | | `_ZNKSt7collateIcE7compareEPKcS2_S2_S2_` | `Q-8lQCGMj4g` | virtual `do_compare` through the facet's vtable (offset 0x20) | | `_ZNKSt7collateIcE4hashEPKcS2_` | `6vYXzFD-mrk` | virtual `do_hash` through the facet's vtable (offset 0x30) | These are the C++ standard members. [locale.collate.members] says `compare` "Returns: `do_compare(low1, high1, low2, high2)`" and `hash` "Returns: `do_hash(low, high)`". libc's `_ZNKSt7collateIcE9transformEPKcS2_` already does the same thing for `transform`, through `GuestLocale::CollateVtable` (`static_assert(offsetof(CollateVtable, compare) == 0x20)` and `hash == 0x30` in `GuestLocale.hpp`). The `do_*` members are the `collate<char>` base implementations. They call the functions held in slots 6 to 8 of libc's exported `_ZTVSt7collateIcE`, which are the same `CollateCompare`, `CollateTransform` and `CollateHash` that `g_collateVtable` uses. Because they never look at the facet's vtable, a derived facet that overrides `do_compare` still reaches the base member here. Their rules and known gaps come from libc unchanged: C-locale byte order, the FNV-1a hash, and `do_transform` throwing on embedded nulls. A null facet or a facet with no vtable makes `compare` and `hash` throw. Changes: - New file `core/libs/prx/libSceLibcInternal/Collate.cpp`. The five stubs are removed from `Err.cpp`. - `_ZTVSt7collateIcE_nid_postfix` is declared in `prx/libc/include/Api.hpp`, and the five entry points in `prx/libSceLibcInternal/include/Api.hpp`. - New guest test `guest_libc_internal_collate` (`core/libs/tests/GuestLibcInternalCollate.cpp`). It covers ordering, prefix and unsigned-byte cases, embedded nulls, null empty ranges, rejection of reversed ranges, the hash value and its offset basis, inline and heap `do_transform` results, virtual dispatch to an overriding facet, and the base `do_*` members ignoring that override. - `docs/dev/debt/libSceLibcInternal.md`: the five "prototype and behavior are unverified" lines are removed and a Functional entry is added. `tools/progress.py` `collect_libraries()`: origin/main has 9913 done of 37146 (libSceLibcInternal 92 done, 1045 todo). This branch has 9918 done (libSceLibcInternal 97 done, 1040 todo), so done goes up by 5 and no new todo appears. ### 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. --> Only the focused test target and the library were built. No title was run. - Windows 11, WinLibs GCC 15.2.0 (MinGW-w64), Release: `ctest -R '^(guest_libc_internal_collate|conventions_unknown_nids|conventions_debt_length|conventions_doc_links|debt_split)$'` ran 3 times, and each run passed 5 of 5 tests with 0 failures. - WSL Ubuntu 22.04, GCC 11.4.0, Release: the same 5 tests ran 3 times, and each run passed 5 of 5 with 0 failures. - `guest_libc_internal_collate` is the new guest test. `conventions_unknown_nids`, `conventions_debt_length`, `conventions_doc_links` and `debt_split` are the repository's checker self-tests for the conventions and the debt-file split, and were run because the debt file changed. - Negative control on both platforms: main's production `Err.cpp` plus the new test, with no collate implementation, fails to link `guest_libc_internal_collate_tests`. The undefined references are to `sceLibcInternalCollateDoCompare_nid_no_patch`, `DoTransform`, `DoHash`, `Compare` and `Hash`. - `python3 tools/check_conventions.py --base origin/main` printed "All conventions checks passed." - `python3 tools/pr_overlap.py --branch feat/r2-collate-char` found no PR exporting the same functions and no PR adding the same new files. Its only matches are neighbouring lines in `libSceLibcInternal/CMakeLists.txt` and the debt file (#10749, #14158, #15692). I grepped the diffs of every PR it could not compare (#5021, #10780, #11831, #13486, #13778, #13782, #13881, #14085, #14212, #14401, #14837, #14936) and none of them contains these NIDs or files. ### 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) - [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 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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!15711
No description provided.