Skip to content

fix(libkernel): keep dlerror messages whole - #10627

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
maximilianfv:fix/libkernel-dlerror-long-messages
Oct 30, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
maximilianfv:fix/libkernel-dlerror-long-messages

Conversation

@maximilianfv

@maximilianfv maximilianfv commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

What

dlerror_nid_postfix returned the last loader error from a thread-local std::array<char, 512> filled with snprintf, so any message longer than 511 bytes was cut off. The message is now kept in a host thread-local std::string obtained through HostThreadLocal (fiber-local storage on Windows, so MinGW never runs its destructor on thread-local storage it has already freed, see docs/dev/BUILD.md), and dlerror returns its data(). 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 dlopen of a module that was not relinked reports dlopen: <path> was not relinked: no <file>.guest.prx was found (<reason>); relink its directory with the relinker's --module-dir <dir> option, and guest_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's anyps5-relinked-module-for-test.prx the 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-dir included, and the test failed at GuestDynamicLoader.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 loaderError hunk.

Tested

Apple M1 Pro, macOS 27.0.1, x86_64 build under Rosetta 2. main alone does not build on macOS. I tested in a tree made of mugurc's macOS series (ci/macos-series-2, 27e9689) merged with main at 1e20650, plus other macOS fixes that are not open as PRs yet. The only thing that changed between the two runs is this change.

ctest of 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.

  • Without this change: 11 pass. guest_dynamic_loader fails with "failed at GuestDynamicLoader.cpp:66", and guest_kernel_sys_module_internal aborts.
  • With this change: 12 pass, including guest_dynamic_loader. guest_kernel_sys_module_internal still aborts, which is a separate gap: on macOS, sceKernelGetModuleList returns a count of 0 (GuestKernelSysModuleInternal.cpp:25). The test executable is not relinked and has no __APS5DATA,__meta section, so the macOS dl_iterate_phdr emulation 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 HostThreadLocal I rebuilt and reran the same 13 tests: guest_dynamic_loader passes, 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

🤖 Generated with Claude Code

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>
@MarcZX10

Copy link
Copy Markdown
Contributor

The body identifies an actual shared hunk with open #10552: both modify loaderError in core/libs/prx/libkernel/Module/src/DynamicLoader.cpp, and it says the second PR to merge must drop that hunk. CONTRIBUTING.md requires agreeing which goes first and declaring the prerequisite on the checklist (Depends on: #N); the checklist currently says Depends on: none. Please coordinate the order with #10552's author and update the dependency line. I have not approved because that merge-order requirement is unresolved.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

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 10552 core/libs/prx/libkernel/Module/src/DynamicLoader.cpp L31

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 5021 core/libs/prx/libkernel/Module/src/DynamicLoader.cpp

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 dlopen block to search existing modules and fallback paths; this PR changes the same block to use LoadWithoutErrorDialog and construct the full LoadFailure diagnostic. git merge-tree --write-tree upstream/pr/9415 upstream/pr/10627 reports 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 dlopen block 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/10627 conflicts 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.

@maximilianfv

Copy link
Copy Markdown
Contributor Author

Thanks. I asked the authors of the three overlapping PRs about the merge order: #10552, #9415 and #7201 (links in the checklist). Depends on now records that; if any of them merges first, I rebase this one and keep their behaviour in the merged block.

AI-assisted: yes

@ycbuzi

ycbuzi commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Windows run of 4bf9853dbf merged onto main 66e6772ca2 (7bd9c196fe, clean). Windows 11 Home 10.0.26200, WinLibs MinGW-w64 GCC 15.2.0 (ucrt-posix-seh r7), Release, BUILD_TESTING=ON. guest_dynamic_loader and guest_dynamic_loader_variant_names pass both runs of ctest --repeat until-fail:2. They pass with main's DynamicLoader.cpp too, so with no test change in this PR they confirm only that nothing regressed, not the longer dlerror messages themselves.

Not run: a title. AI-assisted: yes (Claude Code)

@krishalivaibhav

Copy link
Copy Markdown
Contributor

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.
Tree: origin/main a5a780e merged into a scratch branch holding our open macOS stack (integ8 029564a43: #10552, #10853 and their dependencies, plus the process-parameters, mlock-PROT_NONE and math-exact fixes). Base commit 1ddafb62d. PR head 4bf9853.

Conflict: one, trivial. core/libs/prx/libkernel/Module/src/DynamicLoader.cpp, include block: shared #endif context against the PR's new #include "prx/libc/include/HostThreadLocal.hpp". Kept both. PR otherwise unchanged.

test (3 runs each) without with
guest_dynamic_loader abort 3/3 pass 3/3
guest_dynamic_loader_variant_names pass 3/3 pass 3/3

Broad run: ctest -R "^(guest_|libc_|libkernel_)" = 678 tests. On the base 133 do not pass, 344 of them "Not Run" because their executables do not build here (AGC driver SpirvOptimizer.cpp needs pthread_getattr_np; guest_tls_get_addr and guest_memory test objects fail to compile). Those are Not Run both ways. With the PR: 132 do not pass. The only difference from base is guest_dynamic_loader now passing; nothing new fails.

Not checked: other platforms; behaviour with very long dlerror strings beyond the test's.

AI-assisted: yes (Claude Code)

@adriadam10 adriadam10 self-assigned this Oct 26, 2026
@AdnanKhan-ak47 AdnanKhan-ak47 mentioned this pull request Oct 29, 2026
@adriadam10
adriadam10 merged commit 5a3c1a2 into boykopovar:main Oct 30, 2026
18 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants