fix(relinker): load needed providers for unscoped Windows imports #3365

Merged
MathiasDevelopes merged 4 commits from upstream-pr/3365 into main 2026-10-11 09:40:05 +00:00
MathiasDevelopes commented 2026-10-11 09:07:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MathiasDevelopes on 2026-10-11T09:07:45Z.


What

Windows startup skips needed host libraries unless an import identifies them as a provider. Imports without a recorded library name search across dependencies, but their provider can consequently remain unloaded.

When unscoped imports exist, attempt to load the needed host libraries so their exports participate in resolution. Missing libraries without explicitly scoped imports remain optional; unresolved symbols still fail startup with an error. Explicitly scoped imports retain their existing behavior.

Adds a regression where an unscoped import resolves through an available native library while another optional dependency is missing.

Tested

Windows, WinLibs MinGW-w64 GCC 15.2.0 r7, CMake 3.31.12, Python 3.13.16, Release.

  • Based on upstream main 4f8d4017c.
  • Relinker-only build with BUILD_TESTING=ON: 105/105 tests passed.
  • windows_import_modules, including the new regression: passed in 3.44 seconds.
  • tools/check_conventions.py --base origin/main and whitespace checks passed.
  • Earlier Windows integration with two separate missing-export patches: Planet Coaster (PPSA01736) previously failed resolving 99b82IKXpH4; this fix allowed startup and rendering. It later stopped at unsupported depth-plane sampling. Gameplay is unverified.
  • Linux and macOS builds were not run locally.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw; no silent stubs added
  • No notes, investigation .md files or images added to the repository
  • No new third-party dependencies
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes, OpenAI Codex
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4817945074 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3365). Originally posted by [MathiasDevelopes](https://github.com/MathiasDevelopes) on 2026-10-11T09:07:45Z. --- ### What Windows startup skips needed host libraries unless an import identifies them as a provider. Imports without a recorded library name search across dependencies, but their provider can consequently remain unloaded. When unscoped imports exist, attempt to load the needed host libraries so their exports participate in resolution. Missing libraries without explicitly scoped imports remain optional; unresolved symbols still fail startup with an error. Explicitly scoped imports retain their existing behavior. Adds a regression where an unscoped import resolves through an available native library while another optional dependency is missing. ### Tested Windows, WinLibs MinGW-w64 GCC 15.2.0 r7, CMake 3.31.12, Python 3.13.16, Release. - Based on upstream main `4f8d4017c`. - Relinker-only build with `BUILD_TESTING=ON`: 105/105 tests passed. - `windows_import_modules`, including the new regression: passed in 3.44 seconds. - `tools/check_conventions.py --base origin/main` and whitespace checks passed. - Earlier Windows integration with two separate missing-export patches: Planet Coaster (PPSA01736) previously failed resolving `99b82IKXpH4`; this fix allowed startup and rendering. It later stopped at unsupported depth-plane sampling. Gameplay is unverified. - Linux and macOS builds were not run locally. ### Checklist - [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 - [x] Unimplemented paths throw; no silent stubs added - [x] No notes, investigation `.md` files or images added to the repository - [x] No new third-party dependencies - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes, OpenAI Codex
copilot-pull-request-reviewer[bot] commented 2026-10-11 09:07:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by copilot-pull-request-reviewer[bot] on 2026-10-11T09:07:51Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5482694099 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3365#pullrequestreview-5482694099). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-10-11T09:07:51Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
adriadam10 commented 2026-10-11 09:12:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T09:12:19Z.

Review: CHANGES_REQUESTED


Thanks, the stub change looks right to me: the load path, the ERROR_MOD_NOT_FOUND skip and the cleared handle behave like the previous "not imported" case. Relinker tests pass locally (99/99).

One thing to fix:

  • core/relinker/relinker/tests/test_windows_import_modules.py:245-247: the regression only runs the output when os.name == 'nt'. On Linux it just checks that the conversion succeeds, which also holds without the change (reverting WindowsEntryStubBuilder.cpp leaves windows_import_modules green). Please show that the test fails on main on Windows (log of the run without the fix), or add an assertion that also fails on Linux, e.g. inspect the generated stub/output for the LoadLibraryExW path of the unscoped provider.

Not verified on our side: Windows execution and Planet Coaster.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5482706144 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3365#pullrequestreview-5482706144). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T09:12:19Z. **Review:** CHANGES_REQUESTED --- Thanks, the stub change looks right to me: the load path, the `ERROR_MOD_NOT_FOUND` skip and the cleared handle behave like the previous "not imported" case. Relinker tests pass locally (99/99). One thing to fix: - `core/relinker/relinker/tests/test_windows_import_modules.py:245-247`: the regression only runs the output when `os.name == 'nt'`. On Linux it just checks that the conversion succeeds, which also holds without the change (reverting `WindowsEntryStubBuilder.cpp` leaves `windows_import_modules` green). Please show that the test fails on `main` on Windows (log of the run without the fix), or add an assertion that also fails on Linux, e.g. inspect the generated stub/output for the `LoadLibraryExW` path of the unscoped provider. Not verified on our side: Windows execution and Planet Coaster.
MathiasDevelopes commented 2026-10-11 09:23:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MathiasDevelopes on 2026-10-11T09:23:38Z.


Fixed in 116b98a76.

The regression now inspects the generated PE outside the Windows execution guard, checking that both available.prx and unused.prx have a path reference followed by a call through the LoadLibraryExW IAT slot.

Rebuilding with the pre-fix WindowsEntryStubBuilder.cpp makes the new assertion fail:
AssertionError: available.prx: expected a loader path reference, found 0

With the inspection bypassed, Windows execution also fails with 0xc0000139 and FAIL: unresolved ELF import shared. Both checks pass with the fix restored.

All 105 checks passed, including three rerun outside the sandbox. The inspection was verified with Windows execution disabled; it wasn’t run on a Linux host. Planet Coaster remains untested.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6107552782 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3365#issuecomment-6107552782). Originally posted by [MathiasDevelopes](https://github.com/MathiasDevelopes) on 2026-10-11T09:23:38Z. --- Fixed in 116b98a76. The regression now inspects the generated PE outside the Windows execution guard, checking that both available.prx and unused.prx have a path reference followed by a call through the LoadLibraryExW IAT slot. Rebuilding with the pre-fix WindowsEntryStubBuilder.cpp makes the new assertion fail: AssertionError: available.prx: expected a loader path reference, found 0 With the inspection bypassed, Windows execution also fails with 0xc0000139 and FAIL: unresolved ELF import shared. Both checks pass with the fix restored. All 105 checks passed, including three rerun outside the sandbox. The inspection was verified with Windows execution disabled; it wasn’t run on a Linux host. Planet Coaster remains untested.
adriadam10 commented 2026-10-11 09:36:52 +00:00 (Migrated from github.com)

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

Review: APPROVED


Checked: relinker build + ctest green (110/110 on the rebased tree), and windows_import_modules fails when WindowsEntryStubBuilder.cpp is reverted, so the regression is real.

Added one commit on your branch: drop the leftover docstring in check_native_load_paths (test_windows_import_modules.py:15, no code comments). Merging once CI is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5482776984 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3365#pullrequestreview-5482776984). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T09:36:52Z. **Review:** APPROVED --- Checked: relinker build + ctest green (110/110 on the rebased tree), and `windows_import_modules` fails when `WindowsEntryStubBuilder.cpp` is reverted, so the regression is real. Added one commit on your branch: drop the leftover docstring in `check_native_load_paths` (`test_windows_import_modules.py:15`, no code comments). Merging once CI 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!3365
No description provided.