fix(libc): sort with FreeBSD 11.4's merge.c in mergesort #12271

Merged
B-Howell merged 12 commits from upstream-pr/12271 into main 2026-11-04 05:34:20 +00:00
B-Howell commented 2026-10-28 06:20:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by B-Howell on 2026-10-28T06:20:32Z.


What

mergesort (libSceLibcInternal, implemented in libc) now sorts with FreeBSD 11.4's merge.c. Before this, it was a plain bottom-up merge, so it called the comparator in a different order and a different number of times than the FreeBSD/libbsd reference.

The existing debt entry records argument checks from libSceLibcInternal.sprx (SDK 4.5x build of J03950001, 0x762D0) that match merge.c's checks:

  • an element size under PSIZE / 2 (4) sets EINVAL and returns -1;
  • an empty array returns 0;
  • the scratch block is count * size + PSIZE bytes.

Those argument checks motivate using the FreeBSD reference; they do not establish the console algorithm or its comparator-call sequence. Comparator ordering here is verified against FreeBSD/libbsd and remains unmeasured on a console.

What the implementation does, all from merge.c:

  • The first pass is merge.c's setup, natural and pairwise. The last 4 or 5 elements (all of them when there are 5 or fewer) go through its insertion sort. A run of THRESHOLD (16) same-sense pairs becomes a natural run, and a descending one is reversed in place.
  • The run list lives inside the two buffers, at the pointer-aligned position of each run's start (EVAL). The buffers swap roles each pass.
  • Each merge searches linearly and switches to exponential search after six linear wins, then binary. It keeps the big state across merges and passes, as merge.c does.
  • The final copy back into base, the frees and the return values are merge.c's.

It moves out of FileAndHeap.cpp into libc/src/Mergesort.cpp. A null base or comparator, and a size product that overflows, still throw: the console does not check them. The debt entry is cut to those cases.

Tested

Main refresh at 5e2b3e76f254 (2026-11-02)

Head 5e2b3e76f2547fa667ed040d84b5a5ec7d670d0e ordinarily merges previous head 8d08bd4a1071f259f88c66cda26022a81e201f3f with upstream main a2583610de95e4bfdcaaa4d8ef0f1546c9ae5c6a. #11833 has landed (merge f5d6f8d82b); it added heapsort tests to core/libs/tests/GuestQsort.cpp at the same place this PR adds CheckMergesortComparisons and CheckMergesortUnalignedElements. That file was the only conflict, and it keeps both: this PR's tests followed by #11833's, with main() calling all three checks. The diff against main is the same five owned files, with added and removed lines identical to the previous head's. tools/check_conventions.py from this main passed, and the three merged C++ files (GuestQsort.cpp, FileAndHeap.cpp, Mergesort.cpp) pass a syntax-only g++ 11 compile. No local build or test run is claimed for this head; hosted CI at this head is pending after push.

Main refresh at 8d08bd4a1071 (2026-11-01)

Head 8d08bd4a1071f259f88c66cda26022a81e201f3f / tree ebfd71cb9ff388c9f457e9b9334c22c7101c2e33 ordinarily merges previous public head 25d9d7b9f71ec609d98d7e766029336b2fb5de19 with upstream main b6e3f68173c767f692f6c04eef04c73eab424e04. #13220 has landed: its original commit e9f09f54fabb6408d3e2711b8df10c10112ab00e is an ancestor of that main, so the write-watch registration fix now comes from main and this PR no longer changes core/libs/tests/write_watch/CMakeLists.txt. The remaining diff against main is the five owned files (libc/CMakeLists.txt, FileAndHeap.cpp, Mergesort.cpp, GuestQsort.cpp, docs/dev/debt/libc.md); its added and removed lines in those files are identical to the previous head's changes. Git's three-way merge was clean; GitHub reported the previous head as conflicting, and a merge using only the older main base conflicts on that shared CMake file. tools/check_conventions.py from this main passed against this head. No new local build or runtime result is claimed for this head; hosted CI at this head is pending after push. Earlier results below keep their original pins.

Frozen f776 refresh pair - Windows: the ordinary merge candidate 25d9d7b9f71ec609d98d7e766029336b2fb5de19 (tree f4a5a7733bae8777f2657025dbc9aed3921ef72a) passed the existing guest_qsort CTest once (1/1) after the matching frozen-main f776fddcffd1cfece220ecdd894371988b164f6a control also passed once (1/1). Both arms used Windows native Release/Ninja, WinLibs GCC 15.2.0 r7, BUILD_TESTING=ON, at most two build jobs, and the same ImageOneDimensionalArray CMake selection; each built guest_qsort_tests and libc before running CTest ^guest_qsort$. Conventions passed against origin/main with 0 errors and two pre-existing debt-length warnings. This is a focused Windows libc test pair only; it does not claim Linux, GPU, console, full-suite, or hosted-CI results. Historical results below remain pinned to their stated commits and were not retargeted.

Frozen-main refresh qualification: 3483366e8300fd3c06c711026e7f7c15ae76e6a9 on main 3d19f3fed31be38d7196ea1bd74e29ab6cc3c9a4.

Windows/MSYS2 UCRT64 GCC 16.2.0 Rev6 and Linux/WSL GCC 11.4, Release, separate new build directories, at most two jobs, serial arms/platforms. The isolated PR candidate passed the existing guest_qsort CTest once on each OS. All four frozen arms passed:

Arm Commit Windows Linux
Main 3d19f3fed31be38d7196ea1bd74e29ab6cc3c9a4 1 pass 1 pass
Heapsort fixture PR 66b4ecb13df784ba4a49c777d054bed39c260650 1 pass 1 pass
Mergesort PR 3483366e8300fd3c06c711026e7f7c15ae76e6a9 1 pass 1 pass
Private combined check 9741133de15e810cc06b4cc69fec378bdd053b04 1 pass 1 pass

Eight native executions total, zero failures/skips; one registered test per arm, 20-second test timeout. Source groups differ as the PRs add their regressions. Every arm built production libc and its own fixture; Windows PE/CTest search paths and Linux ldd resolve the corresponding module. Recorded conventions checks passed on all eight arms. Independent source and result reviews passed.

The Mergesort implementation blob and FreeBSD notice remain identical to the previously qualified topic; main qsort_r ordering and validation coverage is retained. The private combined check preserves both helper groups and calls; its result is separate from either public PR and does not establish landing order. Historical algorithm, corpus, negative-control and hosted results below retain their original pins and were not repeated by this refresh. Dependency agreements, current-tip follow-through, human/hosted-CI review, remaining overlap obligations and verified main landing remain open.

Earlier verification — original pins retained:

Latest integration verification: 71e256be573e11d1e59d5ba8b4b0d6cefbcd4eff, preserving published history and integrating main snapshot 4c8cff191609bc5f28bf9ee2f93672b531285aa4.

  • The committed source tree f215ab2e48acec003def2a008340fa54d041bec6 exactly matches the isolated comparison that was rebuilt and tested on Windows with MSYS2 UCRT64 GCC 16.2.0, Ninja Release, BUILD_TESTING=ON.
  • cmake --build build-compare --target guest_qsort_tests --parallel 2 succeeds; ctest --test-dir build-compare -R '^guest_qsort$' --repeat until-fail:3 -V passes all three executions, with no skips. CTest uses the rebuilt unpatched libc.prx. The five-file PR implementation/test diff is preserved; current-main environment and other debt entries are retained, with only the mergesort entry replaced.
  • Conventions pass against the fetched main. Independent review verifies the integration tree and source/log/binary evidence.
  • The build uses CMAKE_SKIP_INSTALL_RULES=ON because the normal configuration encounters an nghttp2 installation/export-set dependency error. Installation/export generation is unverified. No fresh Linux/macOS, title, GPU or performance result is claimed.
  • #12054 is now merged and its merge commit is verified reachable from the pinned main. #11621 and #11833 remain open prerequisites; this update does not clear their order, new-head CI, human re-review or upstream landing requirements.

Earlier verification retained below:

Earlier integration commit fa5b07684d1be2a632b7e60fed67744dc1080bf2 (verified tree 478ba5f7e2c2c45375f627a8e08b8d29d3d42dff), merging frozen main 319621ba2e578bd053b0baba2877fe70520e0737 without rewriting the published history:

  • Windows 11, MSYS2 UCRT64 GCC 16.2.0, Release: cmake --build build-focused --target guest_qsort_tests --parallel 2 passed; ctest --test-dir build-focused -R '^guest_qsort$' --repeat until-fail:3 -V passed all three executions (test491: 0.03/0.01/0.01sec).
  • The five-file contribution and the complete Mergesort.cpp blob are unchanged from the published source. The original 1680-byte FreeBSD notice is preserved byte-for-byte. Independent source/preservation review and conventions passed.
  • This fresh native run does not rerun the reference corpus, historical controls, Linux or console tests. Comparator ordering remains verified against the FreeBSD/libbsd reference rather than measured on a console. The #12054 author-order proposal remains unconfirmed; that branch is not combined here.

Earlier published-source reference and native evidence follows:

  • Reference: libbsd 0.11.5 ships a copy of FreeBSD's merge.c. In WSL Ubuntu 22.04, I loaded its mergesort with dlopen and compared it with this implementation, compiled with ASan and UBSan.
    • The inputs were 7,224 arrays: sizes 8, 9, 12 and 16 bytes, 0 to 300 elements, random, sorted, reversed, few-key and blocked inputs, some on a base 3 bytes off alignment.
    • The comparator call sequences, return values and sorted bytes were identical in every case.
  • New test guest_qsort, CheckMergesortComparisons: it compares the comparator call sequence against libbsd's for four inputs:
    • 5 elements: insertion sort only;
    • 21 elements: pairwise setup;
    • 26 elements: a natural run, then exponential search;
    • 34 elements: interleaved blocks.
  • New test CheckMergesortUnalignedElements: 1,000 12-byte elements on a base 4 bytes off alignment.
  • Linux (WSL Ubuntu 22.04, GCC 11.4, Release): guest_qsort passes 3 of 3 runs.
  • Windows 11 (WinLibs GCC 15.2.0 r7, Release, libs built): guest_qsort passes 3 of 3 runs.
  • Control: main's FileAndHeap.cpp and CMakeLists.txt restored, new tests kept. guest_qsort fails on both OSes: the four inputs make 9, 78, 73 and 107 comparisons, where merge.c makes 6, 84, 42 and 60, in a different order.
  • Not tested: a console. The order of comparator calls is checked against libbsd's merge.c, not measured on a PS5.
  • python tools/check_conventions.py --base origin/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
  • Generic behaviour, not specific to one title
  • Depends on: #11621 (mine and older; this PR still conflicts with it in FileAndHeap.cpp and will be updated with main after it lands)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

CI configuration prerequisite — 2026-10-30

CI-only integration 4980f2197d7db42783f599b5776b25105ad48405 (tree c1d2e4c2f70bb8b867a0d505deed4bebd1c206b8) retains original #13220 commit e9f09f54fabb6408d3e2711b8df10c10112ab00e as its second merge parent, after 3483366e8300fd3c06c711026e7f7c15ae76e6a9. Whole-tree and source-pin verification confirms only core/libs/tests/write_watch/CMakeLists.txt changes: five lines deleting the repeated execute-fault/read-fault registration. No libc implementation or fixture source changes.

#13220 landed in upstream main on 2026-11-01. Earlier heads carried its original commit e9f09f54fabb6408d3e2711b8df10c10112ab00e as a second parent; after the 2026-11-01 main refresh above, the fix comes from main and this PR no longer changes the write-watch CMake file. The historical configure-only comparison and the pins recorded here are unchanged.

Configuration-only comparison used the exact exported four-file graphs: the old graphs match across #11831/#12271, the fixed graphs match across both integrations, and all three companion C++ files are unchanged. Two shared arms per OS were configured serially: Windows CMake 4.4.4 / WinLibs GCC 15.2.0 r7 / Ninja 1.13.2 and WSL CMake 3.22.1 / GCC 11.4 / Ninja 1.10.1. Both old arms failed on both duplicate names after genuine native compiler/Threads probes; both fixed arms configured/generated successfully. Each fixed generated inventory contains exactly 18 unique name/executable/mode mappings with 30-second timeouts. These are four configure checks (two expected RED, two GREEN), not 18 runtime passes. No fixture build or CTest execution occurred.

The isolated two native sort passes remain pinned to 3483366e8300fd3c06c711026e7f7c15ae76e6a9; the earlier four-arm/eight-execution group retains all four original pins on frozen 3d19f3fed31be38d7196ea1bd74e29ab6cc3c9a4. Those executions were not repeated or retargeted. Existing #11621/#11833 dependencies, landing order, current-tip follow-through, human/bot review and verified main landing remain open.

New-head hosted CI qualification remains pending after publication. No macOS tests were run locally; the earlier hosted failure and all historical results retain their original heads. This configuration result does not establish platform/runtime, whole-product or dependency-order clearance.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5046146379 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12271). Originally posted by [B-Howell](https://github.com/B-Howell) on 2026-10-28T06:20:32Z. --- ### What `mergesort` (libSceLibcInternal, implemented in libc) now sorts with FreeBSD 11.4's [`merge.c`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/lib/libc/stdlib/merge.c). Before this, it was a plain bottom-up merge, so it called the comparator in a different order and a different number of times than the FreeBSD/libbsd reference. The existing debt entry records argument checks from `libSceLibcInternal.sprx` (SDK 4.5x build of `J03950001`, 0x762D0) that match merge.c's checks: - an element size under `PSIZE / 2` (4) sets `EINVAL` and returns -1; - an empty array returns 0; - the scratch block is `count * size + PSIZE` bytes. Those argument checks motivate using the FreeBSD reference; they do not establish the console algorithm or its comparator-call sequence. Comparator ordering here is verified against FreeBSD/libbsd and remains unmeasured on a console. What the implementation does, all from merge.c: - The first pass is merge.c's `setup`, natural and pairwise. The last 4 or 5 elements (all of them when there are 5 or fewer) go through its insertion sort. A run of `THRESHOLD` (16) same-sense pairs becomes a natural run, and a descending one is reversed in place. - The run list lives inside the two buffers, at the pointer-aligned position of each run's start (`EVAL`). The buffers swap roles each pass. - Each merge searches linearly and switches to exponential search after six linear wins, then binary. It keeps the `big` state across merges and passes, as merge.c does. - The final copy back into `base`, the frees and the return values are merge.c's. It moves out of `FileAndHeap.cpp` into `libc/src/Mergesort.cpp`. A null base or comparator, and a size product that overflows, still throw: the console does not check them. The debt entry is cut to those cases. ### Tested #### Main refresh at `5e2b3e76f254` (2026-11-02) Head `5e2b3e76f2547fa667ed040d84b5a5ec7d670d0e` ordinarily merges previous head `8d08bd4a1071f259f88c66cda26022a81e201f3f` with upstream main `a2583610de95e4bfdcaaa4d8ef0f1546c9ae5c6a`. #11833 has landed (merge `f5d6f8d82b`); it added heapsort tests to `core/libs/tests/GuestQsort.cpp` at the same place this PR adds `CheckMergesortComparisons` and `CheckMergesortUnalignedElements`. That file was the only conflict, and it keeps both: this PR's tests followed by #11833's, with `main()` calling all three checks. The diff against main is the same five owned files, with added and removed lines identical to the previous head's. `tools/check_conventions.py` from this main passed, and the three merged C++ files (`GuestQsort.cpp`, `FileAndHeap.cpp`, `Mergesort.cpp`) pass a syntax-only g++ 11 compile. No local build or test run is claimed for this head; hosted CI at this head is pending after push. #### Main refresh at `8d08bd4a1071` (2026-11-01) Head `8d08bd4a1071f259f88c66cda26022a81e201f3f` / tree `ebfd71cb9ff388c9f457e9b9334c22c7101c2e33` ordinarily merges previous public head `25d9d7b9f71ec609d98d7e766029336b2fb5de19` with upstream main `b6e3f68173c767f692f6c04eef04c73eab424e04`. #13220 has landed: its original commit `e9f09f54fabb6408d3e2711b8df10c10112ab00e` is an ancestor of that main, so the write-watch registration fix now comes from main and this PR no longer changes `core/libs/tests/write_watch/CMakeLists.txt`. The remaining diff against main is the five owned files (`libc/CMakeLists.txt`, `FileAndHeap.cpp`, `Mergesort.cpp`, `GuestQsort.cpp`, `docs/dev/debt/libc.md`); its added and removed lines in those files are identical to the previous head's changes. Git's three-way merge was clean; GitHub reported the previous head as conflicting, and a merge using only the older main base conflicts on that shared CMake file. `tools/check_conventions.py` from this main passed against this head. No new local build or runtime result is claimed for this head; hosted CI at this head is pending after push. Earlier results below keep their original pins. **Frozen f776 refresh pair - Windows:** the ordinary merge candidate `25d9d7b9f71ec609d98d7e766029336b2fb5de19` (tree `f4a5a7733bae8777f2657025dbc9aed3921ef72a`) passed the existing `guest_qsort` CTest once (1/1) after the matching frozen-main `f776fddcffd1cfece220ecdd894371988b164f6a` control also passed once (1/1). Both arms used Windows native Release/Ninja, WinLibs GCC 15.2.0 r7, `BUILD_TESTING=ON`, at most two build jobs, and the same `ImageOneDimensionalArray` CMake selection; each built `guest_qsort_tests` and libc before running CTest `^guest_qsort$`. Conventions passed against `origin/main` with 0 errors and two pre-existing debt-length warnings. This is a focused Windows libc test pair only; it does not claim Linux, GPU, console, full-suite, or hosted-CI results. Historical results below remain pinned to their stated commits and were not retargeted. Frozen-main refresh qualification: `3483366e8300fd3c06c711026e7f7c15ae76e6a9` on main `3d19f3fed31be38d7196ea1bd74e29ab6cc3c9a4`. Windows/MSYS2 UCRT64 GCC 16.2.0 Rev6 and Linux/WSL GCC 11.4, Release, separate new build directories, at most two jobs, serial arms/platforms. The isolated PR candidate passed the existing `guest_qsort` CTest once on each OS. All four frozen arms passed: | Arm | Commit | Windows | Linux | |---|---|---|---| | Main | `3d19f3fed31be38d7196ea1bd74e29ab6cc3c9a4` | 1 pass | 1 pass | | Heapsort fixture PR | `66b4ecb13df784ba4a49c777d054bed39c260650` | 1 pass | 1 pass | | Mergesort PR | `3483366e8300fd3c06c711026e7f7c15ae76e6a9` | 1 pass | 1 pass | | Private combined check | `9741133de15e810cc06b4cc69fec378bdd053b04` | 1 pass | 1 pass | Eight native executions total, zero failures/skips; one registered test per arm, 20-second test timeout. Source groups differ as the PRs add their regressions. Every arm built production libc and its own fixture; Windows PE/CTest search paths and Linux ldd resolve the corresponding module. Recorded conventions checks passed on all eight arms. Independent source and result reviews passed. The Mergesort implementation blob and FreeBSD notice remain identical to the previously qualified topic; main qsort_r ordering and validation coverage is retained. The private combined check preserves both helper groups and calls; its result is separate from either public PR and does not establish landing order. Historical algorithm, corpus, negative-control and hosted results below retain their original pins and were not repeated by this refresh. Dependency agreements, current-tip follow-through, human/hosted-CI review, remaining overlap obligations and verified main landing remain open. **Earlier verification — original pins retained:** Latest integration verification: `71e256be573e11d1e59d5ba8b4b0d6cefbcd4eff`, preserving published history and integrating main snapshot `4c8cff191609bc5f28bf9ee2f93672b531285aa4`. - The committed source tree `f215ab2e48acec003def2a008340fa54d041bec6` exactly matches the isolated comparison that was rebuilt and tested on Windows with MSYS2 UCRT64 GCC 16.2.0, Ninja Release, `BUILD_TESTING=ON`. - `cmake --build build-compare --target guest_qsort_tests --parallel 2` succeeds; `ctest --test-dir build-compare -R '^guest_qsort$' --repeat until-fail:3 -V` passes all three executions, with no skips. CTest uses the rebuilt unpatched `libc.prx`. The five-file PR implementation/test diff is preserved; current-main environment and other debt entries are retained, with only the mergesort entry replaced. - Conventions pass against the fetched main. Independent review verifies the integration tree and source/log/binary evidence. - The build uses `CMAKE_SKIP_INSTALL_RULES=ON` because the normal configuration encounters an nghttp2 installation/export-set dependency error. Installation/export generation is unverified. No fresh Linux/macOS, title, GPU or performance result is claimed. - #12054 is now merged and its merge commit is verified reachable from the pinned main. #11621 and #11833 remain open prerequisites; this update does not clear their order, new-head CI, human re-review or upstream landing requirements. Earlier verification retained below: Earlier integration commit `fa5b07684d1be2a632b7e60fed67744dc1080bf2` (verified tree `478ba5f7e2c2c45375f627a8e08b8d29d3d42dff`), merging frozen main `319621ba2e578bd053b0baba2877fe70520e0737` without rewriting the published history: - Windows 11, MSYS2 UCRT64 GCC 16.2.0, Release: `cmake --build build-focused --target guest_qsort_tests --parallel 2` passed; `ctest --test-dir build-focused -R '^guest_qsort$' --repeat until-fail:3 -V` passed all three executions (test491: 0.03/0.01/0.01sec). - The five-file contribution and the complete Mergesort.cpp blob are unchanged from the published source. The original 1680-byte FreeBSD notice is preserved byte-for-byte. Independent source/preservation review and conventions passed. - This fresh native run does not rerun the reference corpus, historical controls, Linux or console tests. Comparator ordering remains verified against the FreeBSD/libbsd reference rather than measured on a console. The #12054 author-order proposal remains unconfirmed; that branch is not combined here. Earlier published-source reference and native evidence follows: - **Reference:** libbsd 0.11.5 ships a copy of FreeBSD's `merge.c`. In WSL Ubuntu 22.04, I loaded its `mergesort` with `dlopen` and compared it with this implementation, compiled with ASan and UBSan. - The inputs were 7,224 arrays: sizes 8, 9, 12 and 16 bytes, 0 to 300 elements, random, sorted, reversed, few-key and blocked inputs, some on a base 3 bytes off alignment. - The comparator call sequences, return values and sorted bytes were identical in every case. - **New test** `guest_qsort`, `CheckMergesortComparisons`: it compares the comparator call sequence against libbsd's for four inputs: - 5 elements: insertion sort only; - 21 elements: pairwise setup; - 26 elements: a natural run, then exponential search; - 34 elements: interleaved blocks. - **New test** `CheckMergesortUnalignedElements`: 1,000 12-byte elements on a base 4 bytes off alignment. - **Linux** (WSL Ubuntu 22.04, GCC 11.4, Release): `guest_qsort` passes 3 of 3 runs. - **Windows 11** (WinLibs GCC 15.2.0 r7, Release, `libs` built): `guest_qsort` passes 3 of 3 runs. - **Control:** `main`'s `FileAndHeap.cpp` and `CMakeLists.txt` restored, new tests kept. `guest_qsort` fails on both OSes: the four inputs make 9, 78, 73 and 107 comparisons, where merge.c makes 6, 84, 42 and 60, in a different order. - **Not tested:** a console. The order of comparator calls is checked against libbsd's `merge.c`, not measured on a PS5. - `python tools/check_conventions.py --base origin/main` passes. ### 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: #11621 (mine and older; this PR still conflicts with it in `FileAndHeap.cpp` and will be updated with main after it lands) <!-- #PR, or 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) ### CI configuration prerequisite — 2026-10-30 CI-only integration `4980f2197d7db42783f599b5776b25105ad48405` (tree `c1d2e4c2f70bb8b867a0d505deed4bebd1c206b8`) retains original #13220 commit `e9f09f54fabb6408d3e2711b8df10c10112ab00e` as its second merge parent, after `3483366e8300fd3c06c711026e7f7c15ae76e6a9`. Whole-tree and source-pin verification confirms only `core/libs/tests/write_watch/CMakeLists.txt` changes: five lines deleting the repeated execute-fault/read-fault registration. No libc implementation or fixture source changes. #13220 landed in upstream main on 2026-11-01. Earlier heads carried its original commit `e9f09f54fabb6408d3e2711b8df10c10112ab00e` as a second parent; after the 2026-11-01 main refresh above, the fix comes from main and this PR no longer changes the write-watch CMake file. The historical configure-only comparison and the pins recorded here are unchanged. Configuration-only comparison used the exact exported four-file graphs: the old graphs match across #11831/#12271, the fixed graphs match across both integrations, and all three companion C++ files are unchanged. Two shared arms per OS were configured serially: Windows CMake 4.4.4 / WinLibs GCC 15.2.0 r7 / Ninja 1.13.2 and WSL CMake 3.22.1 / GCC 11.4 / Ninja 1.10.1. Both old arms failed on both duplicate names after genuine native compiler/Threads probes; both fixed arms configured/generated successfully. Each fixed generated inventory contains exactly 18 unique name/executable/mode mappings with 30-second timeouts. These are four configure checks (two expected RED, two GREEN), not 18 runtime passes. No fixture build or CTest execution occurred. The isolated two native sort passes remain pinned to `3483366e8300fd3c06c711026e7f7c15ae76e6a9`; the earlier four-arm/eight-execution group retains all four original pins on frozen `3d19f3fed31be38d7196ea1bd74e29ab6cc3c9a4`. Those executions were not repeated or retargeted. Existing #11621/#11833 dependencies, landing order, current-tip follow-through, human/bot review and verified main landing remain open. New-head hosted CI qualification remains pending after publication. No macOS tests were run locally; the earlier hosted failure and all historical results retain their original heads. This configuration result does not establish platform/runtime, whole-product or dependency-order clearance.
MarcZX10 commented 2026-10-28 08:55:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-28T08:55:56Z.

Review: CHANGES_REQUESTED


The algorithm is explicitly adapted from FreeBSD 11.4 merge.c, and the new implementation closely follows that file, but core/libs/prx/libc/src/Mergesort.cpp has no source attribution/license notice. FreeBSD’s source license requires source redistributions to retain its copyright notice, conditions and disclaimer. Please add the applicable notice (including the Regents of the University of California / Peter McIlroy attribution) to the new source file, or document the permitted provenance if this is an independent clean-room implementation. I checked the exact 11.4 source header; this is the only blocking finding from this pass. The algorithm comparison and reported Linux/Windows tests are otherwise detailed, and current hosted build, relinker, sanitizer, conventions and registration checks pass.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5680044826 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12271#pullrequestreview-5680044826). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-28T08:55:56Z. **Review:** CHANGES_REQUESTED --- The algorithm is explicitly adapted from FreeBSD 11.4 `merge.c`, and the new implementation closely follows that file, but `core/libs/prx/libc/src/Mergesort.cpp` has no source attribution/license notice. FreeBSD’s source license requires source redistributions to retain its copyright notice, conditions and disclaimer. Please add the applicable notice (including the Regents of the University of California / Peter McIlroy attribution) to the new source file, or document the permitted provenance if this is an independent clean-room implementation. I checked the exact 11.4 source header; this is the only blocking finding from this pass. The algorithm comparison and reported Linux/Windows tests are otherwise detailed, and current hosted build, relinker, sanitizer, conventions and registration checks pass.
MarcZX10 commented 2026-10-29 06:06:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T06:06:08Z.

Review: CHANGES_REQUESTED


Re-checked — changes requested

License finding resolved

I compared the notice in exact head fa5b07684d1be2a632b7e60fed67744dc1080bf2 with the 11.4.0 merge.c source. The 1,680-byte copyright, Peter McIlroy attribution, three redistribution conditions, and disclaimer are byte-for-byte identical to FreeBSD's source. The SPDX identifier and source link are also present. My earlier missing-attribution finding is resolved.

The author reports the exact-head Windows guest_qsort run passing three times; hosted Windows, relinker, conventions, and eligibility checks pass. I did not rerun tests locally. The reported runtime integration used main 319621ba2e; current fetched main is 2960e9a6e7, 232 commits ahead. The current-main merge preview is clean, but the focused runtime check has not been reported on that current integration.

Remaining repository blockers

  • The shared docs/dev/debt/libc.md edit with open #12054 still has no author agreement on order. Your proposal is #12054 first, but #12054's author has not confirmed it and its checklist still says Depends on: none. Please get agreement and declare the dependency on the second PR; the declared #11621 and #11833 prerequisites remain open as stated in this PR.
  • Please refresh onto current main and rerun guest_qsort on the integration that preserves the ordered debt edits and open prerequisites.

I am requesting changes only for the unresolved order and current integration validation; the license notice is accepted.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5693537465 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12271#pullrequestreview-5693537465). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-29T06:06:08Z. **Review:** CHANGES_REQUESTED --- # Re-checked — changes requested ## License finding resolved I compared the notice in exact head `fa5b07684d1be2a632b7e60fed67744dc1080bf2` with the 11.4.0 `merge.c` source. The 1,680-byte copyright, Peter McIlroy attribution, three redistribution conditions, and disclaimer are byte-for-byte identical to [FreeBSD's source](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/lib/libc/stdlib/merge.c). The SPDX identifier and source link are also present. My earlier missing-attribution finding is resolved. The author reports the exact-head Windows `guest_qsort` run passing three times; hosted Windows, relinker, conventions, and eligibility checks pass. I did not rerun tests locally. The reported runtime integration used main `319621ba2e`; current fetched `main` is `2960e9a6e7`, 232 commits ahead. The current-main merge preview is clean, but the focused runtime check has not been reported on that current integration. ## Remaining repository blockers - The shared `docs/dev/debt/libc.md` edit with open #12054 still has no author agreement on order. Your proposal is #12054 first, but #12054's author has not confirmed it and its checklist still says `Depends on: none`. Please get agreement and declare the dependency on the second PR; the declared #11621 and #11833 prerequisites remain open as stated in this PR. - Please refresh onto current `main` and rerun `guest_qsort` on the integration that preserves the ordered debt edits and open prerequisites. I am requesting changes only for the unresolved order and current integration validation; the license notice is accepted.
MarcZX10 commented 2026-10-29 22:42:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T22:42:40Z.

Review: APPROVED


Re-checked — new head, looks good

The license notice is now present and matches the FreeBSD 11.4 source; the remaining order and current-integration points are addressed or correctly tracked as dependencies.

What I ran

Reviewed exact head 71e256be573e11d1e59d5ba8b4b0d6cefbcd4eff, PR base 4c8cff191609bc5f28bf9ee2f93672b531285aa4, and current main fdd1753204a4732e1011539cc9d3bb69f70b27a6. The merge preview is clean. On Linux, without building, I ran:

git diff --check upstream/main...refs/review/pr-12271
python3 tools/check_conventions.py --base upstream/main --head refs/review/pr-12271
git merge-tree --write-tree upstream/main refs/review/pr-12271
cmp -s /tmp/anyps5-merge-license.txt /tmp/freebsd-merge-license.txt

The cmp compares the 31-line BSD notice from the exact PR head with the corresponding notice from FreeBSD merge.c at commit 8c639945a44588f6cfdddfb057bb5aad88735da0. I also confirmed Mergesort.cpp is byte-identical to the previously reviewed source. I did not build or run tests locally.

Results

Check Result
Diff whitespace check Passed.
Repository conventions Passed.
Current-main merge preview Clean; tree eb3ff54249f8134c5aab963bde0a05ba3d2a2a45. The only PR-touched path changed on main since the PR's base is the debt document; the merged preview preserves both the mergesort and existing debt entries.
BSD notice comparison Passed; both 31-line files have SHA-256 ea45247eefad9ad1bc05d4c8fc96a80fcda304a01ed54e570ffeceb7bb75ec36.
Author-reported tests The author reports the tested tree f215ab2e48acec003def2a008340fa54d041bec6 matches this head and guest_qsort passed 3/3 on Windows 11/MSYS2 GCC 16.2.0.
Hosted CI Windows, Ubuntu register-context, relinker, ASan, conventions, eligibility and report passed; Linux product tests were skipped; macOS jobs were pending.
Raw output from local checks
diff_check_exit:0
All conventions checks passed.
eb3ff54249f8134c5aab963bde0a05ba3d2a2a45
license_cmp_exit:0
ea45247eefad9ad1bc05d4c8fc96a80fcda304a01ed54e570ffeceb7bb75ec36  /tmp/anyps5-merge-license.txt
ea45247eefad9ad1bc05d4c8fc96a80fcda304a01ed54e570ffeceb7bb75ec36  /tmp/freebsd-merge-license.txt

Sources

Not verified

I did not independently run the Windows guest_qsort test or verify console behavior. The Windows results are author-reported; macOS jobs were still pending when checked. #11621 and #11833 remain open and are declared prerequisites; this review does not approve their changes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5705927757 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12271#pullrequestreview-5705927757). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-29T22:42:40Z. **Review:** APPROVED --- # Re-checked — new head, looks good The license notice is now present and matches the FreeBSD 11.4 source; the remaining order and current-integration points are addressed or correctly tracked as dependencies. ## What I ran Reviewed exact head `71e256be573e11d1e59d5ba8b4b0d6cefbcd4eff`, PR base `4c8cff191609bc5f28bf9ee2f93672b531285aa4`, and current `main` `fdd1753204a4732e1011539cc9d3bb69f70b27a6`. The merge preview is clean. On Linux, without building, I ran: ```sh git diff --check upstream/main...refs/review/pr-12271 python3 tools/check_conventions.py --base upstream/main --head refs/review/pr-12271 git merge-tree --write-tree upstream/main refs/review/pr-12271 cmp -s /tmp/anyps5-merge-license.txt /tmp/freebsd-merge-license.txt ``` The `cmp` compares the 31-line BSD notice from the exact PR head with the corresponding notice from FreeBSD `merge.c` at commit `8c639945a44588f6cfdddfb057bb5aad88735da0`. I also confirmed `Mergesort.cpp` is byte-identical to the previously reviewed source. I did not build or run tests locally. ## Results | Check | Result | |---|---| | Diff whitespace check | Passed. | | Repository conventions | Passed. | | Current-main merge preview | Clean; tree `eb3ff54249f8134c5aab963bde0a05ba3d2a2a45`. The only PR-touched path changed on main since the PR's base is the debt document; the merged preview preserves both the mergesort and existing debt entries. | | BSD notice comparison | Passed; both 31-line files have SHA-256 `ea45247eefad9ad1bc05d4c8fc96a80fcda304a01ed54e570ffeceb7bb75ec36`. | | Author-reported tests | The author reports the tested tree `f215ab2e48acec003def2a008340fa54d041bec6` matches this head and `guest_qsort` passed 3/3 on Windows 11/MSYS2 GCC 16.2.0. | | Hosted CI | Windows, Ubuntu register-context, relinker, ASan, conventions, eligibility and report passed; Linux product tests were skipped; macOS jobs were pending. | <details> <summary>Raw output from local checks</summary> ```text diff_check_exit:0 All conventions checks passed. eb3ff54249f8134c5aab963bde0a05ba3d2a2a45 license_cmp_exit:0 ea45247eefad9ad1bc05d4c8fc96a80fcda304a01ed54e570ffeceb7bb75ec36 /tmp/anyps5-merge-license.txt ea45247eefad9ad1bc05d4c8fc96a80fcda304a01ed54e570ffeceb7bb75ec36 /tmp/freebsd-merge-license.txt ``` </details> ## Sources - [FreeBSD 11.4 `merge.c` notice at pinned commit](https://github.com/freebsd/freebsd-src/blob/8c639945a44588f6cfdddfb057bb5aad88735da0/lib/libc/stdlib/merge.c#L1-L31) - [PR source and notice at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/71e256be573e11d1e59d5ba8b4b0d6cefbcd4eff/core/libs/prx/libc/src/Mergesort.cpp#L1-L31) ## Not verified I did not independently run the Windows `guest_qsort` test or verify console behavior. The Windows results are author-reported; macOS jobs were still pending when checked. #11621 and #11833 remain open and are declared prerequisites; this review does not approve their changes.
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!12271
No description provided.