fix(libkernel): keep dlerror messages whole #10627
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10627"
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 maximilianfv on 2026-10-24T13:32:43Z.
What
dlerror_nid_postfixreturned the last loader error from a thread-localstd::array<char, 512>filled withsnprintf, so any message longer than 511 bytes was cut off. The message is now kept in a host thread-localstd::stringobtained throughHostThreadLocal(fiber-local storage on Windows, so MinGW never runs its destructor on thread-local storage it has already freed, seedocs/dev/BUILD.md), anddlerrorreturns itsdata(). The pointer stays valid until the next loader error on the same thread, as before; a longer message then replaces the buffer.Why it matters: since #9832 (johandavidcm), a failed
dlopenof a module that was not relinked reportsdlopen: <path> was not relinked: no <file>.guest.prx was found (<reason>); relink its directory with the relinker's --module-dir <dir> option, andguest_dynamic_loader(FailsAsUnrelinked) requires the stored text to contain the file name and--module-dir.<reason>is the host loader's own error. On macOS, dyld's message lists every path it tried, so for the test'sanyps5-relinked-module-for-test.prxthe full message is over 1,000 characters in this tree (its length depends on the checkout path and on which paths dyld tries). The stored copy lost its end,--module-dirincluded, and the test failed atGuestDynamicLoader.cpp:66. The 512-byte buffer dates from #3 (SamG-Coder).The change applies to every host, but only macOS has been seen to produce a message over 511 bytes. On Linux and Windows it removes the limit; on Windows the string lives in the same fiber-local storage other libkernel per-thread objects use. The message text is generated by the host, so nothing here depends on how the console sizes its errors.
Prior art: the closed whole-port PR #8658 (iamthehimansh, commit "fix(libkernel): keep the whole dlopen failure message on macOS", 2026-10-23) fixed the same truncation with a different approach: a 4096-byte buffer on macOS only, with 512 bytes kept elsewhere. This PR keeps one code path for every host and has no fixed limit. Apart from #10552 (below), I found no other PR, open or closed, that changes this buffer. That includes #7201 (marion909), #7332 (ycarogabriel-lgtm), and #10419 and #10362, which were split out of #8658.
Open #10552 (krishalivaibhav), a larger macOS build fix, also changes this buffer: it raises it to 4096 bytes on macOS. This PR instead removes the limit on every host, so whichever of the two merges first, the other should drop its
loaderErrorhunk.Tested
Apple M1 Pro, macOS 27.0.1, x86_64 build under Rosetta 2.
mainalone does not build on macOS. I tested in a tree made of mugurc's macOS series (ci/macos-series-2, 27e968974) merged withmainat1e20650e84, plus other macOS fixes that are not open as PRs yet. The only thing that changed between the two runs is this change.ctestof 13 module-loader tests:guest_kernel_sys_module_internal,guest_sysmodule,guest_dynamic_loader,guest_dynamic_loader_variant_names,guest_needed_modules,guest_module_dir,guest_module_directories,sce_module_path,guest_module_args,guest_module_identity,guest_module_fini,guest_needed_nested_modules,sce_module_code_extent.guest_dynamic_loaderfails with "failed at GuestDynamicLoader.cpp:66", andguest_kernel_sys_module_internalaborts.guest_dynamic_loader.guest_kernel_sys_module_internalstill aborts, which is a separate gap: on macOS,sceKernelGetModuleListreturns a count of 0 (GuestKernelSysModuleInternal.cpp:25). The test executable is not relinked and has no__APS5DATA,__metasection, so the macOSdl_iterate_phdremulation skips it. This is a similar kind of gap to the one the open #9972 (tkcm01) handles.After switching the storage to
HostThreadLocalI rebuilt and reran the same 13 tests:guest_dynamic_loaderpasses, and all 13 pass in that run because an unopened module-list fix for macOS was also applied by then.Not tested on Linux or Windows.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)loaderErrorhunk (https://github.com/boykopovar/AnyPS5/pull/10552#issuecomment-6385252108). Asked on #9415 (https://github.com/boykopovar/AnyPS5/pull/9415#issuecomment-6385132551) and #7201 (https://github.com/boykopovar/AnyPS5/pull/7201#issuecomment-6385132825); if one of them merges first, I rebase this one🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T13:40:40Z.
Review: COMMENTED
The PR body acknowledges the shared
loaderErrorhunk with open #10552 and says the later merge must drop it, but the checklist still saysDepends on: none. CONTRIBUTING requires the overlapping authors to agree on merge order and record the dependency. I left the specific coordination request in this comment; no author response or body update is present at this head. I have not approved pending that rule-required coordination.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T13:52:14Z.
Review: CHANGES_REQUESTED
Follow-up on the new overlap warnings at head
4bf9853dbfa2eb98b87194852394f6998847298e. In addition to #10552'sloaderErrorconflict already noted, I manually compared the otherDynamicLoader.cppoverlaps:dlopenblock to search existing modules and fallback paths; this PR changes the same block to useLoadWithoutErrorDialogand construct the fullLoadFailurediagnostic.git merge-tree --write-tree upstream/pr/9415 upstream/pr/10627reports a content conflict in that block. The combined result needs to preserve both the fallback behavior and the no-dialog/error-report behavior, so please agree on an order and record the dependency.dlopenblock for macOS image tracking, while this PR changes failure handling and Linux guest-module initialization in that same block.git merge-tree --write-tree upstream/pr/7201 upstream/pr/10627conflicts there; the combined code needs to retain the platform-specific image tracking and Linux initialization while keeping the improved error text. Please coordinate this order too.I checked #5021's
DynamicLoader.cppdiff: its Apple guest-image detection change merges cleanly with this head undergit merge-tree, so I found no additional conflict there. Please coordinate the actual conflicts with #9415, #7201, and #10552 and updateDepends onto the agreed prerequisite(s). This follow-up requests changes for unresolved merge coordination; it does not identify a new defect in the string-based error buffer itself.