fix(libc): find a relinked module by stem when the exact name misses (carries #6226) #8626

Merged
xXPBSXx merged 4 commits from upstream-pr/8626 into main 2026-10-21 06:52:46 +00:00
xXPBSXx commented 2026-10-20 18:53:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-20T18:53:18Z.


What

Carries #6226 (@lendinglibrary) onto current main, keeping the original commit and its author (a3c4cdcdbb), and adds one commit that addresses the review points on #6226 (the author has not pushed since 15 October). The problem and the Unity IL2CPP evidence are those described in #6226: a title asks for a module by its console name, the relinker names the converted module after the ELF it was built from, so RelinkedModulePath misses and sceKernelLoadStartModule fails with 0x80020002; after the exact <name>.guest.prx and the case-insensitive lookup both miss, the lookup takes the sibling with the same stem that ends with .guest.prx.

Changes on top of the original commit:

  • The stem is the name without its last extension only (Engine.Render.prx no longer matches Engine.Core.prx.guest.prx); the review on #6226 asked for this (cut at the first dot before).
  • The variant-names test requests a dotted name that must not load the sibling fixture (guest_module_fixture.other.prx).
  • Lookup order as discussed for #6544: exact, same directory ignoring case, nested, stem last.
  • Rebased onto main b85d972f42; the only conflict was the shared line in docs/dev/debt/libc.md (the original addition is kept).

Fixes: none. #6226 stays open so its author can answer; if the author prefers to push the review fixes there, this PR can be closed.

Tested

Windows 10 (19045), MinGW-w64 GCC 15.2.0, Release, on main + this branch:

  • guest_dynamic_loader_variant_names: fails (failed at GuestDynamicLoaderVariants.cpp:22, exit 0xc0000409) with the cut at the first dot (new case kept) and passes with the last extension; guest_dynamic_loader and guest_filesystem pass, 3 of 3 runs.
  • python tools/check_conventions.py --base upstream/main: 0 errors, 1 warning (debt-length: the libc.md entry over 1000 characters comes from the original commit).
  • Overlap: git merge-tree of this branch with #6226 has three conflicts (the same code, expected); with upstream/main it is clean. pr_overlap was not run.
  • Not tested: Linux/macOS, a title run (the Unity run is the evidence in #6226).

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; no silent stubs added
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none (carries #6226)
  • Unblocks: none
  • AI-assisted: yes

AI-assisted (Claude Code).

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4940772198 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8626). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-20T18:53:18Z. --- ### What Carries #6226 (@lendinglibrary) onto current `main`, keeping the original commit and its author (`a3c4cdcdbb`), and adds one commit that addresses the review points on #6226 (the author has not pushed since 15 October). The problem and the Unity IL2CPP evidence are those described in #6226: a title asks for a module by its console name, the relinker names the converted module after the ELF it was built from, so `RelinkedModulePath` misses and `sceKernelLoadStartModule` fails with `0x80020002`; after the exact `<name>.guest.prx` and the case-insensitive lookup both miss, the lookup takes the sibling with the same stem that ends with `.guest.prx`. Changes on top of the original commit: - The stem is the name without its **last** extension only (`Engine.Render.prx` no longer matches `Engine.Core.prx.guest.prx`); the review on #6226 asked for this (cut at the first dot before). - The variant-names test requests a dotted name that must not load the sibling fixture (`guest_module_fixture.other.prx`). - Lookup order as discussed for #6544: exact, same directory ignoring case, nested, stem last. - Rebased onto `main` `b85d972f42`; the only conflict was the shared line in `docs/dev/debt/libc.md` (the original addition is kept). Fixes: none. `#6226` stays open so its author can answer; if the author prefers to push the review fixes there, this PR can be closed. ### Tested Windows 10 (19045), MinGW-w64 GCC 15.2.0, Release, on `main` + this branch: - `guest_dynamic_loader_variant_names`: fails (`failed at GuestDynamicLoaderVariants.cpp:22`, exit 0xc0000409) with the cut at the first dot (new case kept) and passes with the last extension; `guest_dynamic_loader` and `guest_filesystem` pass, 3 of 3 runs. - `python tools/check_conventions.py --base upstream/main`: 0 errors, 1 warning (`debt-length`: the libc.md entry over 1000 characters comes from the original commit). - Overlap: `git merge-tree` of this branch with #6226 has three conflicts (the same code, expected); with `upstream/main` it is clean. `pr_overlap` was not run. - Not tested: Linux/macOS, a title run (the Unity run is the evidence in #6226). ### 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; no silent stubs added - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source (none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: none (carries #6226) - [x] Unblocks: none - [x] AI-assisted: yes AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-20 19:07:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-20T19:07:59Z.


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 6226 core/libs/tests/GuestDynamicLoaderVariants.cpp
PR 6544 core/libs/prx/libc/src/General.cpp L677-680

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 docs/dev/debt/libc.md
PR 5021 core/libs/prx/libc/src/General.cpp
core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libc.md
PR 6044 core/libs/prx/libkernel/CMakeLists.txt
PR 6226 core/libs/prx/libc/src/General.cpp
core/libs/prx/libkernel/CMakeLists.txt
core/libs/tests/GuestDynamicLoaderVariants.cpp
docs/dev/debt/libc.md
PR 6469 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libc.md
PR 6819 docs/dev/debt/libc.md
PR 6936 core/libs/prx/libkernel/CMakeLists.txt
PR 6977 core/libs/prx/libkernel/CMakeLists.txt
PR 7081 docs/dev/debt/libc.md
PR 7192 core/libs/prx/libkernel/CMakeLists.txt
PR 7201 core/libs/prx/libc/src/General.cpp
core/libs/prx/libkernel/CMakeLists.txt
PR 7532 core/libs/prx/libkernel/CMakeLists.txt
PR 7648 docs/dev/debt/libc.md
PR 7715 docs/dev/debt/libc.md
PR 8150 docs/dev/debt/libc.md
PR 8520 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libc.md
PR 8711 docs/dev/debt/libc.md
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6298978968 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8626#issuecomment-6298978968). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-20T19:07:59Z. --- <!-- 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 6226](https://www.github.com/boykopovar/AnyPS5/pull/6226) | | | `core/libs/tests/GuestDynamicLoaderVariants.cpp` | | [PR 6544](https://www.github.com/boykopovar/AnyPS5/pull/6544) | `core/libs/prx/libc/src/General.cpp` [L677-680](https://github.com/boykopovar/AnyPS5/blob/eb9f904d32ece402660286aed2cecf465094da07/core/libs/prx/libc/src/General.cpp#L677-L680) | | | 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) | `docs/dev/debt/libc.md` | | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/libs/prx/libc/src/General.cpp`<br>`core/libs/prx/libkernel/CMakeLists.txt`<br>`docs/dev/debt/libc.md` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/prx/libkernel/CMakeLists.txt` | | [PR 6226](https://www.github.com/boykopovar/AnyPS5/pull/6226) | `core/libs/prx/libc/src/General.cpp`<br>`core/libs/prx/libkernel/CMakeLists.txt`<br>`core/libs/tests/GuestDynamicLoaderVariants.cpp`<br>`docs/dev/debt/libc.md` | | [PR 6469](https://www.github.com/boykopovar/AnyPS5/pull/6469) | `core/libs/prx/libkernel/CMakeLists.txt`<br>`docs/dev/debt/libc.md` | | [PR 6819](https://www.github.com/boykopovar/AnyPS5/pull/6819) | `docs/dev/debt/libc.md` | | [PR 6936](https://www.github.com/boykopovar/AnyPS5/pull/6936) | `core/libs/prx/libkernel/CMakeLists.txt` | | [PR 6977](https://www.github.com/boykopovar/AnyPS5/pull/6977) | `core/libs/prx/libkernel/CMakeLists.txt` | | [PR 7081](https://www.github.com/boykopovar/AnyPS5/pull/7081) | `docs/dev/debt/libc.md` | | [PR 7192](https://www.github.com/boykopovar/AnyPS5/pull/7192) | `core/libs/prx/libkernel/CMakeLists.txt` | | [PR 7201](https://www.github.com/boykopovar/AnyPS5/pull/7201) | `core/libs/prx/libc/src/General.cpp`<br>`core/libs/prx/libkernel/CMakeLists.txt` | | [PR 7532](https://www.github.com/boykopovar/AnyPS5/pull/7532) | `core/libs/prx/libkernel/CMakeLists.txt` | | [PR 7648](https://www.github.com/boykopovar/AnyPS5/pull/7648) | `docs/dev/debt/libc.md` | | [PR 7715](https://www.github.com/boykopovar/AnyPS5/pull/7715) | `docs/dev/debt/libc.md` | | [PR 8150](https://www.github.com/boykopovar/AnyPS5/pull/8150) | `docs/dev/debt/libc.md` | | [PR 8520](https://www.github.com/boykopovar/AnyPS5/pull/8520) | `core/libs/prx/libkernel/CMakeLists.txt`<br>`docs/dev/debt/libc.md` | | [PR 8711](https://www.github.com/boykopovar/AnyPS5/pull/8711) | `docs/dev/debt/libc.md` |
MarcZX10 commented 2026-10-20 19:30:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T19:30:53Z.

Code review location: core/libs/prx/libkernel/CMakeLists.txt; line 278

@@ -274,6 +274,30 @@ if(BUILD_TESTING)
         set_tests_properties(guest_dynamic_loader_fixed_base PROPERTIES
             WORKING_DIRECTORY "$<TARGET_FILE_DIR:guest_module_fixture>" RESOURCE_LOCK guest_dynamic_loader_files)
     endif()
+    file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/variant_names")
+    file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/variant_names/guest_module_fixture.sprx.elf.GUEST.PRX" "not a module\n")

This fixture no longer exercises the shortest-match or dangling-symlink-before-valid-candidate paths after the last-extension change. For the request guest_module_fixture.prx, SameRelinkedStem strips .GUEST.PRX and then only the last extension: guest_module_fixture.sprx.elf.GUEST.PRX yields stem guest_module_fixture.sprx, and the symlink name ending in .zprx.elf.GUEST.PRX yields guest_module_fixture.zprx. Neither matches guest_module_fixture; only the copied .elf.GUEST.PRX file matches. Could the decoy and symlink instead be named e.g. guest_module_fixture.sprx.GUEST.PRX and guest_module_fixture.zprx.GUEST.PRX? Those share the requested stem under this rule and would make the selection/error-path coverage real.

<!-- greyfinch-sync:boykopovar/AnyPS5:review-comment:4329361590 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8626#discussion_r4329361590). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-20T19:30:53Z. **Code review location:** `core/libs/prx/libkernel/CMakeLists.txt`; line 278 ~~~~diff @@ -274,6 +274,30 @@ if(BUILD_TESTING) set_tests_properties(guest_dynamic_loader_fixed_base PROPERTIES WORKING_DIRECTORY "$<TARGET_FILE_DIR:guest_module_fixture>" RESOURCE_LOCK guest_dynamic_loader_files) endif() + file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/variant_names") + file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/variant_names/guest_module_fixture.sprx.elf.GUEST.PRX" "not a module\n") ~~~~ --- This fixture no longer exercises the shortest-match or dangling-symlink-before-valid-candidate paths after the last-extension change. For the request `guest_module_fixture.prx`, `SameRelinkedStem` strips `.GUEST.PRX` and then only the last extension: `guest_module_fixture.sprx.elf.GUEST.PRX` yields stem `guest_module_fixture.sprx`, and the symlink name ending in `.zprx.elf.GUEST.PRX` yields `guest_module_fixture.zprx`. Neither matches `guest_module_fixture`; only the copied `.elf.GUEST.PRX` file matches. Could the decoy and symlink instead be named e.g. `guest_module_fixture.sprx.GUEST.PRX` and `guest_module_fixture.zprx.GUEST.PRX`? Those share the requested stem under this rule and would make the selection/error-path coverage real.
xXPBSXx commented 2026-10-20 20:18:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-20T20:18:02Z.


Good catch, thank you. After the cut at the last extension the decoy and the dangling link no longer had the request's stem, so the shortest-name rule was not exercised any more. I renamed them as you suggested (guest_module_fixture.sprx.GUEST.PRX, guest_module_fixture.zprx.GUEST.PRX; commit c98377710f). To check that they compete again I flipped the length comparison in RelinkedModulePath's stem lookup: guest_dynamic_loader_variant_names then fails at the first dlopen, and it passes with the real comparison (Windows 10, MinGW-w64 GCC 15.2, Release). The dangling-link variant only exists on non-Windows hosts and I did not run it.
AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6300566930 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8626#issuecomment-6300566930). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-20T20:18:02Z. --- Good catch, thank you. After the cut at the last extension the decoy and the dangling link no longer had the request's stem, so the shortest-name rule was not exercised any more. I renamed them as you suggested (`guest_module_fixture.sprx.GUEST.PRX`, `guest_module_fixture.zprx.GUEST.PRX`; commit c98377710f). To check that they compete again I flipped the length comparison in `RelinkedModulePath`'s stem lookup: `guest_dynamic_loader_variant_names` then fails at the first `dlopen`, and it passes with the real comparison (Windows 10, MinGW-w64 GCC 15.2, Release). The dangling-link variant only exists on non-Windows hosts and I did not run it. AI-assisted (Claude Code).
oneandonlydean commented 2026-10-21 01:22:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-21T01:22:52Z.


@xXPBSXx I merged current main into this branch (2de93860ab). Besides a keep-both in General.cpp, the merge commit adds one guard in MatchNames.

#7467 added an early return to MatchNamesWindows for case-insensitive directories (the NTFS default). That path looks up each name exactly and never reaches SameRelinkedStem, so on Windows this PR's stem fallback would never run. The merge now takes the Windows fast path only when no requested name has stem set:

bool stem = false;
for (const auto& name : names) stem = stem || name.stem;
if (!stem && CaseInsensitiveDirectoryWindows(directory)) return MatchNamesWindows(directory, names);

ResolveHostPath never sets stem, so #7467's fast path is unchanged for ordinary lookups. Only RelinkedModulePath goes back to the iterator. guest_dynamic_loader_variant_names passing on Windows CI will confirm it.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6305668678 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8626#issuecomment-6305668678). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-21T01:22:52Z. --- @xXPBSXx I merged current `main` into this branch (2de93860ab). Besides a keep-both in `General.cpp`, the merge commit adds one guard in `MatchNames`. #7467 added an early return to `MatchNamesWindows` for case-insensitive directories (the NTFS default). That path looks up each name exactly and never reaches `SameRelinkedStem`, so on Windows this PR's stem fallback would never run. The merge now takes the Windows fast path only when no requested name has `stem` set: ```cpp bool stem = false; for (const auto& name : names) stem = stem || name.stem; if (!stem && CaseInsensitiveDirectoryWindows(directory)) return MatchNamesWindows(directory, names); ``` `ResolveHostPath` never sets `stem`, so #7467's fast path is unchanged for ordinary lookups. Only `RelinkedModulePath` goes back to the iterator. `guest_dynamic_loader_variant_names` passing on Windows CI will confirm it.
oneandonlydean commented 2026-10-21 06:29:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-21T06:29:26Z.


Note: I force-pushed the merge commit as 8cb7251b2e to correct its committer identity. The tree is identical to the previous head 2de93860ab, so nothing in the code changed. CI on the new head is next.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6309628965 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8626#issuecomment-6309628965). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-21T06:29:26Z. --- Note: I force-pushed the merge commit as `8cb7251b2e` to correct its committer identity. The tree is identical to the previous head `2de93860ab`, so nothing in the code changed. CI on the new head is next.
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!8626
No description provided.