fix(libkernel): keep dlerror messages whole #10627

Merged
maximilianfv merged 1 commit from upstream-pr/10627 into main 2026-10-30 00:02:56 +00:00
maximilianfv commented 2026-10-24 13:32:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by maximilianfv on 2026-10-24T13:32:43Z.


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, 27e968974) merged with main at 1e20650e84, 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 #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

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4995818792 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10627). Originally posted by [maximilianfv](https://github.com/maximilianfv) on 2026-10-24T13:32:43Z. --- ### 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 <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> 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`, 27e968974) merged with `main` at 1e20650e84, 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 #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 <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: <!-- #PR, or none --> none. Merge order: #10552's author agreed this PR lands first and #10552 drops its `loaderError` hunk (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 - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: none <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: n/a <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no --> 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-10-24 13:40:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T13:40:40Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5638445754 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10627#pullrequestreview-5638445754). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T13:40:40Z. **Review:** COMMENTED --- 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](https://github.com/boykopovar/AnyPS5/pull/10627#issuecomment-6384872846); no author response or body update is present at this head. I have not approved pending that rule-required coordination.
MarcZX10 commented 2026-10-24 13:52:14 +00:00 (Migrated from github.com)

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'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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5638483197 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10627#pullrequestreview-5638483197). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T13:52:14Z. **Review:** CHANGES_REQUESTED --- 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.
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!10627
No description provided.