fix(loader): resolve sceKernelDlsym on the main module #2786

Merged
tototomate123 merged 2 commits from upstream-pr/2786 into main 2026-10-11 10:10:04 +00:00
tototomate123 commented 2026-10-10 15:00:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by tototomate123 on 2026-10-10T15:00:31Z.


What

Split from #1616, following its review. Resolve handle 0 through the main executable for sceKernelDlsym, retaining the existing error behavior. The regression calls an executable-only export; Windows exports it through a generated .def, with a plain extern "C" definition instead of __declspec.

Tested

Linux x86-64, GCC 16.2.1, Release. guest_dynamic_loader passes, including main-module calls and missing-symbol errors. MinGW C++20 syntax check passes; Windows runtime/CI has not been run locally. Conventions and whitespace checks pass on current main (5edae353).

Depends on

None for build. HFW integration also needs #2785 (relinker), #2787 (filesystem), #2788 (http), #2789 (apr), #2790 (shader). #1269 (media), #1339 (VRR), #1586 (unwind) and #1436 (imports) are now on main. Local image-table experiments are excluded; open #757 → #758 overlaps them, and #920 is closed without merging. Earlier combined integration reached menu/loading UI; these isolated branches have not been game-tested and gameplay is unverified.

Checklist

  • Based on current main; no duplicate implementation found beyond superseded #1616
  • One topic per PR
  • No code comments except technical debt
  • Unimplemented paths throw; offline HTTP limitations documented
  • No investigation notes, logs or images committed
  • No new third-party dependencies
  • Generic behavior; no title-specific dispatch
  • Depends on: none for build; HFW integration requirements listed above
  • AI-assisted: yes, Codex
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4812129724 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2786). Originally posted by [tototomate123](https://github.com/tototomate123) on 2026-10-10T15:00:31Z. --- ### What Split from #1616, following its review. Resolve handle 0 through the main executable for `sceKernelDlsym`, retaining the existing error behavior. The regression calls an executable-only export; Windows exports it through a generated `.def`, with a plain `extern "C"` definition instead of `__declspec`. ### Tested Linux x86-64, GCC 16.2.1, Release. `guest_dynamic_loader` passes, including main-module calls and missing-symbol errors. MinGW C++20 syntax check passes; Windows runtime/CI has not been run locally. Conventions and whitespace checks pass on current main (`5edae353`). ### Depends on None for build. HFW integration also needs #2785 (relinker), #2787 (filesystem), #2788 (http), #2789 (apr), #2790 (shader). #1269 (media), #1339 (VRR), #1586 (unwind) and #1436 (imports) are now on main. Local image-table experiments are excluded; open #757 → #758 overlaps them, and #920 is closed without merging. Earlier combined integration reached menu/loading UI; these isolated branches have not been game-tested and gameplay is unverified. ### Checklist - [x] Based on current `main`; no duplicate implementation found beyond superseded #1616 - [x] One topic per PR - [x] No code comments except technical debt - [x] Unimplemented paths throw; offline HTTP limitations documented - [x] No investigation notes, logs or images committed - [x] No new third-party dependencies - [x] Generic behavior; no title-specific dispatch - [x] Depends on: none for build; HFW integration requirements listed above - [x] AI-assisted: yes, Codex
github-actions[bot] commented 2026-10-10 15:00:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-10T15:00:40Z.


Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6098832283 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2786#issuecomment-6098832283). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-10T15:00:40Z. --- Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.
adriadam10 commented 2026-10-11 07:06:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T07:06:35Z.

Review: CHANGES_REQUESTED


Thanks for splitting this out. Checked on Linux (GCC, Release, PR merged onto current main): the build and the area's ctest (94 tests) pass, including guest_dynamic_loader.

  • The new regression does not fail without the change on Linux. With Module.cpp reverted, guest_dynamic_loader still passes: dlsym_nid_postfix(nullptr, ...) already falls back to DefaultScopeSymbol (DynamicLoader.cpp:164), so sceKernelDlsym(0, ...) finds the executable's export there. The fix only changes behaviour on Windows, where there is no such fallback and the only global module is the one dlopen(nullptr) registers.
  • The Windows part can't be checked from Linux and the PR says it wasn't run. Please post evidence from a Windows build (MinGW or MSVC): the guest_dynamic_loader output on main (failing at the new sceKernelDlsym(0, "GuestDefaultScopeOnly", ...) check) and with this PR (passing), and that the generated .def links.

The change itself looks right (handle 0 only, same ESRCH on a missing symbol, module handle closed after the lookup). Once the Windows before/after is in, this is ready from my side.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5482276502 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2786#pullrequestreview-5482276502). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T07:06:35Z. **Review:** CHANGES_REQUESTED --- Thanks for splitting this out. Checked on Linux (GCC, Release, PR merged onto current main): the build and the area's ctest (94 tests) pass, including `guest_dynamic_loader`. - The new regression does not fail without the change on Linux. With `Module.cpp` reverted, `guest_dynamic_loader` still passes: `dlsym_nid_postfix(nullptr, ...)` already falls back to `DefaultScopeSymbol` (`DynamicLoader.cpp:164`), so `sceKernelDlsym(0, ...)` finds the executable's export there. The fix only changes behaviour on Windows, where there is no such fallback and the only global module is the one `dlopen(nullptr)` registers. - The Windows part can't be checked from Linux and the PR says it wasn't run. Please post evidence from a Windows build (MinGW or MSVC): the `guest_dynamic_loader` output on `main` (failing at the new `sceKernelDlsym(0, "GuestDefaultScopeOnly", ...)` check) and with this PR (passing), and that the generated `.def` links. The change itself looks right (handle 0 only, same ESRCH on a missing symbol, module handle closed after the lookup). Once the Windows before/after is in, this is ready from my side.
Mouhand-Kaddo commented 2026-10-11 07:27:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Mouhand-Kaddo on 2026-10-11T07:27:53Z.


Additional platform validation of standalone PR head 43110f8ed73e386396efdd34aaccb6c34e002393 (2026-10-11):

Windows: failed tests — Windows 11, WinLibs GCC 15.2.0 UCRT/POSIX/SEH r7; CMake 4.3.1 / Ninja; Release, BUILD_TESTING=ON.

1 checks, 1 failures, 0 CTest skips. Built the selected targets and dependencies; this is focused validation, not a full build or full-suite run.

Checks: guest_dynamic_loader.

Command after building: ctest --test-dir <build> --verbose --no-tests=error --timeout 30 -R "^guest_dynamic_loader$".

Diagnostic-only rebuild (same assertions, added failure printing): sceKernelDlsym(0, "GuestDefaultScopeOnly", &mainSymbol) == 0 && mainSymbol != nullptr. The PE export table does not contain GuestDefaultScopeOnly. Pristine parent 5edae35361 passes guest_dynamic_loader.

Failed cases: guest_dynamic_loader.

No title/gameplay validation. These results cover the standalone head, not a merge with current main.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6106675184 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2786#issuecomment-6106675184). Originally posted by [Mouhand-Kaddo](https://github.com/Mouhand-Kaddo) on 2026-10-11T07:27:53Z. --- <!-- anyps5-platform-validation:43110f8ed73e386396efdd34aaccb6c34e002393 --> Additional platform validation of standalone PR head `43110f8ed73e386396efdd34aaccb6c34e002393` (2026-10-11): **Windows: failed tests** — Windows 11, WinLibs GCC 15.2.0 UCRT/POSIX/SEH r7; CMake 4.3.1 / Ninja; Release, `BUILD_TESTING=ON`. 1 checks, 1 failures, 0 CTest skips. Built the selected targets and dependencies; this is focused validation, not a full build or full-suite run. Checks: `guest_dynamic_loader`. Command after building: `ctest --test-dir <build> --verbose --no-tests=error --timeout 30 -R "^guest_dynamic_loader$"`. Diagnostic-only rebuild (same assertions, added failure printing): sceKernelDlsym(0, "GuestDefaultScopeOnly", &mainSymbol) == 0 && mainSymbol != nullptr. The PE export table does not contain GuestDefaultScopeOnly. Pristine parent 5edae35361 passes guest_dynamic_loader. Failed cases: `guest_dynamic_loader`. No title/gameplay validation. These results cover the standalone head, not a merge with current main.
tototomate123 commented 2026-10-11 09:52:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by tototomate123 on 2026-10-11T09:52:26Z.


@adriadam10 Fixed the Windows export configuration and rebased onto current main. I’m on Linux, so I cant test native Windows directly, but the MinGW-built test under Wine fails without the loader change and passes with it; Linux also passes, so looks fixed.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6107766014 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2786#issuecomment-6107766014). Originally posted by [tototomate123](https://github.com/tototomate123) on 2026-10-11T09:52:26Z. --- @adriadam10 Fixed the Windows export configuration and rebased onto current main. I’m on Linux, so I cant test native Windows directly, but the MinGW-built test under Wine fails without the loader change and passes with it; Linux also passes, so looks fixed.
adriadam10 commented 2026-10-11 10:10:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T10:10:01Z.

Review: APPROVED


Thanks for the update. Checked on Linux (GCC, Release, PR merged onto current main): build and the area's ctest (106 tests) pass, guest_dynamic_loader included. As expected, the regression passes on Linux without the loader change (the default-scope fallback already resolves it); it only discriminates on Windows, where the .def export now makes GuestDefaultScopeOnly visible. The main-module path (GetModuleHandleW(nullptr) → registered handle → GetProcAddress) and the error return look right. Merging once the Windows build job is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5482880313 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2786#pullrequestreview-5482880313). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T10:10:01Z. **Review:** APPROVED --- Thanks for the update. Checked on Linux (GCC, Release, PR merged onto current main): build and the area's ctest (106 tests) pass, `guest_dynamic_loader` included. As expected, the regression passes on Linux without the loader change (the default-scope fallback already resolves it); it only discriminates on Windows, where the `.def` export now makes `GuestDefaultScopeOnly` visible. The main-module path (`GetModuleHandleW(nullptr)` → registered handle → `GetProcAddress`) and the error return look right. Merging once the Windows build job is green.
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!2786
No description provided.