Repository navigation
fix(libkernel): keep dlerror messages whole - #10627
Conversation
dlerror returned the last loader error from a 512-byte buffer, so a longer message was cut off. On macOS the reason dyld gives for a failed dlopen lists every path it tried, and the message for a module that was not relinked runs to over 1,000 characters; the end of it, the hint to relink with --module-dir, was lost, and guest_dynamic_loader failed. Keep the message in a host thread-local string, through HostThreadLocal so MinGW does not run its destructor on freed thread-local storage. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The body identifies an actual shared hunk with open #10552: both modify |
MarcZX10
left a comment
There was a problem hiding this comment.
The PR body acknowledges the shared loaderError hunk with open #10552 and says the later merge must drop it, but the checklist still says Depends 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.
|
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.
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.
|
MarcZX10
left a comment
There was a problem hiding this comment.
Follow-up on the new overlap warnings at head 4bf9853dbfa2eb98b87194852394f6998847298e. In addition to #10552's loaderError conflict already noted, I manually compared the other DynamicLoader.cpp overlaps:
- #9415 changes the Windows
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. - #7201 changes the non-Windows
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.cpp diff: its Apple guest-image detection change merges cleanly with this head under git merge-tree, so I found no additional conflict there. Please coordinate the actual conflicts with #9415, #7201, and #10552 and update Depends on to 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.
|
Windows run of Not run: a title. AI-assisted: yes (Claude Code) |
Test report: #10627 (dynamic loader keeps the full dlerror)Tested on: Apple M2 MacBook Air, macOS 27.2 (26B118), x86_64 Release build under Rosetta 2, AppleClang 21.0.0, Ninja. Conflict: one, trivial.
Broad run: Not checked: other platforms; behaviour with very long dlerror strings beyond the test's. AI-assisted: yes (Claude Code) |
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, 27e9689) merged withmainat 1e20650, 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 test(libkernel): describe the flexible memory fixture's segment on macOS #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 (fix(libkernel): build the file, module and rtld calls on macOS hosts #10552 (comment)). Asked on feat(libkernel): add fallback search paths and loaded handle lookup i… #9415 (feat(libkernel): add fallback search paths and loaded handle lookup i… #9415 (comment)) and Macos port #7201 (Macos port #7201 (comment)); if one of them merges first, I rebase this one🤖 Generated with Claude Code