fix(libc): find a relinked module by stem when the exact name misses #6226
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6226"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by lendinglibrary on 2026-10-15T05:22:21Z.
What
A title asks for a module by its console name, and the relinker names the converted module after the ELF it was built from. Unity titles load
Media/Modules/<name>.prxandMedia/Plugins/<name>.prxwhile the dump holds<name>.elf.guest.prx, soRelinkedModulePathmisses andsceKernelLoadStartModulefails with 0x80020002. A Unity IL2CPP title stopped 3 s after start withunable to load /app0/Media/Modules/Il2CppUserAssemblies.prx, error:0x80020002.After the exact
<name>.guest.prxand the case-insensitive lookup (#5892's predecessorf0c3a5c85) both miss, the lookup now takes the sibling whose stem (name up to the first dot, ASCII case ignored) equals the requested stem and that ends with.guest.prx, shortest name first. The test loadsguest_module_fixture.prxfrom a directory holding onlyguest_module_fixture.elf.GUEST.PRX. The assumption about the console's module namespace is recorded indocs/dev/debt/libc.md.Tested
Linux (Ubuntu, i5-12400, RTX 5070 Ti).
guest_dynamic_loader_variant_namesand the loader tests pass. A Unity IL2CPP title whose dump holds only<name>.elf.guest.prx: loadsIl2CppUserAssemblies.prxandPS5Util.prx, plays its intro videos, reaches the main menu and starts a game. A title whose dump already has<name>.prx.guest.prxcopies: unchanged. Windows: not tested.Checklist
main; no other open PR implements the same functions.mdfiles or images added to the repositoryImported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-15T09:24:35Z.
Review: COMMENTED
Static check on macOS (Apple M2 Max, macOS 27.2, APFS, Apple clang 21 / libc++), head
7b2385aa0. Not built:maindoes not link on macOS yet. I compiledRelinkedSiblingByStemverbatim from the PR in a small driver.With libc++, the shortest-name-first rule does not hold when two or more siblings match the stem. The loop shares one
std::error_codebetweendirectory_iterator,is_regular_fileandequivalent. libc++ implements LWG 2937, soequivalent(existing, missing, ec)setsectoENOTSUPwhen the requested path does not exist, which is always the case on this fallback path. On the next iteration,if (error || ...) continue;sees that stale value and skips every remaining entry, so the first stem match in directory order wins.Directory with
Il2CppUserAssemblies.{elf,prx.elf,sprx.elf}.guest.prx, requestIl2CppUserAssemblies.prx. arm64 and x86_64 under Rosetta give the same result:equivalent(<existing file>, <missing file>, ec)alone giveseq=0 err=45 Operation not supported.I did not check libstdc++. With a single candidate the result is right, so the new test would not catch this. A local
std::error_codefor theequivalentcall, or clearingerrorat the top of each iteration, keeps the shortest-name rule thatdocs/dev/debt/libc.mddescribes.Written with AI assistance (Claude Code). I ran the snippets above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by simonbbby on 2026-10-15T10:25:46Z.
The same shared-error issue is present on Linux/libstdc++, not only libc++. Checked exact head
7b2385aa00814baeb5d63344f61f3e2710293357, Ubuntu 24.04 / GCC 13.3, by compiling the unchangedFoldCase,NameStemandRelinkedSiblingByStembodies against the real filesystem.For
Il2CppUserAssemblies.prx(absent), with the three regular sibling files:Here
equivalent(existing, missing, ec)leaves ENOENT (2). The next iteration sees that stale error before it can examine the shorter sibling. Each of the three candidates is selected correctly when it is the only sibling, ruling out the stem/suffix filter. The filename-length comparison does not need changing.The review's clear-at-the-top option also covers another per-entry error:
equivalenterror.clear()at the top of each iterationThe remaining failure in the middle row comes from
is_regular_file(error)on the dangling symlink: that error also leaks into the next entry. So either reset per iteration as suggested, or keep every per-entry status/identity error separate from directory enumeration.Tested minimal change:
The 30-run cases are five processes for each of six directories populated in different creation orders. This filesystem enumerated the same longest-first order in all six; these are not six different observed enumeration orders. An empty-directory control returns no candidate with the patch.
Scope: standalone execution of the actual helper bodies with ordinary test files and a real dangling symlink. No full runtime/library build, module loading or title result is claimed. No repository source was changed.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T12:17:01Z.
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.
docs/dev/debt/libc.mddocs/dev/debt/libc.mdcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libc/src/General.cppcore/libs/prx/libc/src/General.cppcore/libs/prx/libkernel/CMakeLists.txtdocs/dev/debt/libc.mddocs/dev/debt/libc.mdcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/CMakeLists.txtdocs/dev/debt/libc.mdcore/libs/prx/libc/src/General.cppdocs/dev/debt/libc.mdcore/libs/prx/libkernel/CMakeLists.txtdocs/dev/debt/libc.mddocs/dev/debt/libc.mdcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libc/src/General.cppdocs/dev/debt/libc.mdcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/CMakeLists.txtdocs/dev/debt/libc.mdcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libc/src/General.cppcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/CMakeLists.txtdocs/dev/debt/libc.mddocs/dev/debt/libc.mdcore/libs/prx/libkernel/CMakeLists.txtdocs/dev/debt/libc.mdcore/libs/prx/libkernel/CMakeLists.txtdocs/dev/debt/libc.mddocs/dev/debt/libc.mddocs/dev/debt/libc.mddocs/dev/debt/libc.mdcore/libs/prx/libkernel/CMakeLists.txtdocs/dev/debt/libc.mdcore/libs/prx/libkernel/CMakeLists.txtdocs/dev/debt/libc.mddocs/dev/debt/libc.mddocs/dev/debt/libc.mddocs/dev/debt/libc.mddocs/dev/debt/libc.mddocs/dev/debt/libc.mddocs/dev/debt/libc.mddocs/dev/debt/libc.mddocs/dev/debt/libc.mddocs/dev/debt/libc.mddocs/dev/debt/libc.mdcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/CMakeLists.txtdocs/dev/debt/libc.mdcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/CMakeLists.txtdocs/dev/debt/libc.mddocs/dev/debt/libc.mddocs/dev/debt/libc.mdcore/libs/prx/libc/src/General.cppcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/CMakeLists.txtdocs/dev/debt/libc.mdcore/libs/prx/libkernel/CMakeLists.txtdocs/dev/debt/libc.mdcore/libs/prx/libkernel/CMakeLists.txtdocs/dev/debt/libc.mddocs/dev/debt/libc.mddocs/dev/debt/libc.mddocs/dev/debt/libc.mddocs/dev/debt/libc.mddocs/dev/debt/libc.mdcore/libs/prx/libkernel/CMakeLists.txtdocs/dev/debt/libc.mdcore/libs/prx/libkernel/CMakeLists.txtdocs/dev/debt/libc.mddocs/dev/debt/libc.mdImported from boykopovar/AnyPS5. Originally posted by lendinglibrary on 2026-10-15T16:21:07Z.
Fixed in the amended commit: the shared error code is cleared at the top of each iteration, so a stale result from
equivalentor fromis_regular_fileon a dangling symlink no longer skips the remaining siblings. The test directory now holds three stem matches: the real module (shortest name), a longer non-module file and, on non-Windows, a longer dangling symlink; the load succeeds only when the shortest valid one is picked. Thanks both for the reproductions.Imported from boykopovar/AnyPS5. Originally posted by lendinglibrary on 2026-10-15T16:51:44Z.
Rebased on current main after
eac8bfcfc. The stem rule is now a secondNameMatchpattern (stem = true) in the same single directory listing: a sibling ending in.guest.prxwhose stem matches the request, regular files only, shortest name wins; the exact case-insensitive match keeps precedence. No extra listing and no separate loop any more. Test and conventions pass on Linux.Imported from boykopovar/AnyPS5. Originally posted by simonbbby on 2026-10-15T18:25:40Z.
Retested the rewritten
NameMatchpath at exact head138a74ca5a701d1a52063702e434ec6e99a5b13d. The two filesystem failures from my earlier report are resolved on Linux, and the unchanged selector bodies also pass native macOS/libc++ checks.Linux — Ubuntu 24.04, GCC 13.3. Compiled the complete unchanged production
General.cppwith function/data sections, linked with garbage collection, and called the actual exportedRelinkedModulePath_nid_no_patch:dlopen, resolveGuestModuleAdd, requireadd(19,23) == 42, and close it. The longer decoy files contain invalid-module text.Matched original-head control: rebuilding only
General.cppfrom7b2385aa0against the same probe still selects the longest sibling in the first case and returns the unresolved request after the broken symlink in the second. Both fail; the rewritten object passes.macOS 27.2 arm64 / Apple clang 21 / libc++ — the complete translation unit still fails on unrelated
CLOCK_REALTIME_COARSEandstat::st_mtimuses. I instead compiled the unchanged selector/helper bodies from this head. 43 cases pass, including the 30 shortest-name calls, five broken-symlink-first calls and native synthetic-library loading. The two Linux case-collision/uppercase-only cases were excluded from this macOS run.No repository source changed. This verifies filesystem selection and native loading of a synthetic library, not guest
dlopen_nid_postfix, the full runtime, Windows, or a title replay. The previously reported stale-error blocker is no longer reproduced at this head.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T10:38:33Z.
Thanks. One fix is needed before merge, and the branch needs a rebase:
The stem is cut at the first dot, not the last. For a request like
Engine.Render.prxthat misses, the stem becomesEngine, so the lookup can quietly loadEngine.Core.prx.guest.prx, a different module. Please strip only the last extension (std::filesystem::path::stem()does this), and add a test with a dotted name that would load the wrong module with the current code.Also, #6544 changes the same function (
RelinkedModulePath) for a different layout (a converted copy in aprx/orsce_module/subdirectory). When both land, the lookup order should be: exact match, then same directory ignoring case, then nested, then stem. Please keep the stem match last.The branch is about 600 commits behind main, so please rebase onto current main before we run CI.
Imported from boykopovar/AnyPS5. Originally posted by TheTerr4 on 2026-10-18T14:59:37Z.
Windows runtime check. Windows 11 Pro 10.0.26200, Ryzen 7 7800X3D, WinLibs GCC 15.2.0 r7 (UCRT), Release.
This PR's head
138a74ca5merged cleanly intomain385ed71f2; the full build andlibsboth exit 0.guest_dynamic_loaderandguest_dynamic_loader_variant_namespass, three repeated-j1runs.libc/src/General.cpprestored tomain's version,guest_dynamic_loader_variant_namesaborts (exit 0xc0000409);guest_dynamic_loaderstill passes.AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-20T18:53:21Z.
I carried this onto current
mainin 8626: it keeps your original commit and author and adds one commit for the review points (the stem now drops only the last extension, plus a test with a dotted name). I did not close this PR; if you prefer to push those changes here, 8626 can be closed. Branch:https://github.com/xXPBSXx/AnyPS5/tree/carry/6226-relinker-stem.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-21T07:22:53Z.
@lendinglibrary thanks for this. Your stem fallback has landed on
mainthrough #8626, which carries your commit with your authorship, together with a guard that only uses the stem when the exact name neither matched nor was ambiguous. Closing this one as superseded by #8626.Pull request closed