fix(relinker): preserve load failures of present optional providers #3579

Merged
Celegans12 merged 1 commit from upstream-pr/3579 into main 2026-10-13 09:53:02 +00:00
Celegans12 commented 2026-10-11 13:38:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-11T13:38:57Z.


What

Since #3365, the Windows startup stub can ignore error 126 from an optional host provider even when that file exists and one of its dependencies is missing. The stub now checks the provider path before loading it. Only direct file or path absence (errors 2 and 3) skips an optional provider; other path errors and every failed LoadLibraryExW call stop startup with the original error. Named imports and guest modules retain their existing behavior.

This follows #3365 without changing which providers unscoped imports search. The regression extends its native-provider case: the missing optional file succeeds, then a present provider importing APS5MISS.dll must fail. The earlier host-provider reproduction was based on xXPBSXx's test for #3367; this case reuses the repository's existing TLS fixture to supply a real DLL dependency.

Tested

Based on main 0f863c102. Windows 11, MinGW-w64 GCC 15.2.0, -DBUILD_TESTING=ON: the 65 relinker tests pass. windows_import_modules now checks the generated PE on every host: each optional provider must call GetFileAttributesW through its IAT slot before LoadLibraryExW, and the success branch must reach the load. It fails on main on Windows and Linux. On Windows the stub also runs: an absent provider is skipped, and a present one importing APS5MISS.dll fails with error 126. Linux, merged with main: 71/71 relinker tests pass. Not tested: title behavior.

  • Windows NVIDIA full ctest: 826/833 pass after a serial rerun; the 7 left (windows_exceptions, agc_driver_bda_device, agc_driver_flat_apertures_{0,2,3,4,5}) are outside the relinker and failed the same way in this PR's earlier run; relinker tests 65/65
  • Linux (upstream's job in WSL, GCC 13.3, llvmpipe), merged with current main: 935/936 pass; agc_driver_depth_compare_copy also fails on main; relinker tests 71/71

The Windows failures (windows_exceptions, agc_driver_bda_device, agc_driver_flat_apertures_{0,2,3,4,5}) don't involve the relinker; Linux agc_driver_depth_compare_copy also fails on main.

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 (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4819468050 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3579). Originally posted by [Celegans12](https://github.com/Celegans12) on 2026-10-11T13:38:57Z. --- ### What Since #3365, the Windows startup stub can ignore error 126 from an optional host provider even when that file exists and one of its dependencies is missing. The stub now checks the provider path before loading it. Only direct file or path absence (errors 2 and 3) skips an optional provider; other path errors and every failed `LoadLibraryExW` call stop startup with the original error. Named imports and guest modules retain their existing behavior. This follows #3365 without changing which providers unscoped imports search. The regression extends its native-provider case: the missing optional file succeeds, then a present provider importing `APS5MISS.dll` must fail. The earlier host-provider reproduction was based on xXPBSXx's [test for #3367](https://github.com/boykopovar/AnyPS5/commit/d5c087d21ff1430873d180326ad09f4ddbd6130c); this case reuses the repository's existing TLS fixture to supply a real DLL dependency. ### Tested Based on `main` 0f863c102. Windows 11, MinGW-w64 GCC 15.2.0, -DBUILD_TESTING=ON: the 65 relinker tests pass. `windows_import_modules` now checks the generated PE on every host: each optional provider must call `GetFileAttributesW` through its IAT slot before `LoadLibraryExW`, and the success branch must reach the load. It fails on `main` on Windows and Linux. On Windows the stub also runs: an absent provider is skipped, and a present one importing `APS5MISS.dll` fails with error 126. Linux, merged with main: 71/71 relinker tests pass. Not tested: title behavior. - Windows NVIDIA full ctest: 826/833 pass after a serial rerun; the 7 left (`windows_exceptions`, `agc_driver_bda_device`, `agc_driver_flat_apertures_{0,2,3,4,5}`) are outside the relinker and failed the same way in this PR's earlier run; relinker tests 65/65 - Linux (upstream's job in WSL, GCC 13.3, llvmpipe), merged with current `main`: 935/936 pass; `agc_driver_depth_compare_copy` also fails on `main`; relinker tests 71/71 The Windows failures (`windows_exceptions`, `agc_driver_bda_device`, `agc_driver_flat_apertures_{0,2,3,4,5}`) don't involve the relinker; Linux `agc_driver_depth_compare_copy` also fails on `main`. ### 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](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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: none - [x] AI-assisted: yes
adriadam10 commented 2026-10-11 13:41:35 +00:00 (Migrated from github.com)

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

Review: CHANGES_REQUESTED


Thanks, the approach (probe the path with GetFileAttributesW, skip only on errors 2/3, keep every LoadLibraryExW failure fatal) reads right to me. One thing to fix before merging:

  • core/relinker/relinker/tests/test_windows_import_modules.py:312-315: the new assertions are inside if os.name == 'nt', so on Linux the test only writes the broken unused.prx and checks nothing. A regression in the stub would pass Linux CI and the PR's Windows result can't be reproduced there. As in #3365, inspect the generated PE outside the Windows guard: the optional provider's path reference must be followed by a GetFileAttributesW call through its IAT slot, then the LoadLibraryExW call. Please also show that this assertion fails with the pre-fix WindowsEntryStubBuilder.cpp.

Build and the relinker ctest scope (101 tests) pass on Linux with the PR merged onto current main. Windows runtime behaviour is not something we can run here, hence the ask for the PE-level check.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5483518867 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3579#pullrequestreview-5483518867). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T13:41:35Z. **Review:** CHANGES_REQUESTED --- Thanks, the approach (probe the path with `GetFileAttributesW`, skip only on errors 2/3, keep every `LoadLibraryExW` failure fatal) reads right to me. One thing to fix before merging: - `core/relinker/relinker/tests/test_windows_import_modules.py:312-315`: the new assertions are inside `if os.name == 'nt'`, so on Linux the test only writes the broken `unused.prx` and checks nothing. A regression in the stub would pass Linux CI and the PR's Windows result can't be reproduced there. As in #3365, inspect the generated PE outside the Windows guard: the optional provider's path reference must be followed by a `GetFileAttributesW` call through its IAT slot, then the `LoadLibraryExW` call. Please also show that this assertion fails with the pre-fix `WindowsEntryStubBuilder.cpp`. Build and the relinker ctest scope (101 tests) pass on Linux with the PR merged onto current main. Windows runtime behaviour is not something we can run here, hence the ask for the PE-level check.
Celegans12 commented 2026-10-12 08:19:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-12T08:19:55Z.


You're right, on Linux that block only wrote the broken DLL and checked nothing. I've moved the stub check out of the Windows guard. check_native_load_paths now also looks up the GetFileAttributesW IAT slot, and for each optional provider it requires that the path reference is followed by exactly one call [rip+...] through that slot before the LoadLibraryExW call, with rcx set from the path (mov rcx, rsi). It also checks that the cmp eax, -1; jne after the probe jumps straight to the LoadLibraryExW setup, so a present provider always gets loaded. The runtime check on Windows is still there.

With main's WindowsEntryStubBuilder.cpp and the new test, it fails on both Windows and Linux (WSL, gcc 13.3) with available.prx: optional provider is not probed with GetFileAttributesW before LoadLibraryExW. With the fix, the relinker tests pass on Windows (65/65) and on Linux merged with current main (71/71). I amended the single commit and updated the Tested section.

Details

Pre-fix, Windows (main's WindowsEntryStubBuilder.cpp, new test):

1/1 Test #814: windows_import_modules ...........***Failed    0.25 sec
  File "C:/.../core/relinker/relinker/tests/test_windows_import_modules.py", line 73, in check_native_load_paths
    assert len(probes) == 1, f'{library}: optional provider is not probed with GetFileAttributesW before LoadLibraryExW'
AssertionError: available.prx: optional provider is not probed with GetFileAttributesW before LoadLibraryExW

Pre-fix, Linux (WSL, only the new test on main 2ccbd376):

  File "/home/omer/anyps5/core/relinker/relinker/tests/test_windows_import_modules.py", line 73, in check_native_load_paths
    assert len(probes) == 1, f'{library}: optional provider is not probed with GetFileAttributesW before LoadLibraryExW'
AssertionError: available.prx: optional provider is not probed with GetFileAttributesW before LoadLibraryExW
0% tests passed, 1 tests failed out of 1

With the fix (67ddb36):

Windows: 100% tests passed, 0 tests failed out of 65 (relinker tests)
Linux, merged with main 2ccbd376: 100% tests passed, 0 tests failed out of 71 (relinker tests)
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6120456680 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3579#issuecomment-6120456680). Originally posted by [Celegans12](https://github.com/Celegans12) on 2026-10-12T08:19:55Z. --- You're right, on Linux that block only wrote the broken DLL and checked nothing. I've moved the stub check out of the Windows guard. `check_native_load_paths` now also looks up the `GetFileAttributesW` IAT slot, and for each optional provider it requires that the path reference is followed by exactly one `call [rip+...]` through that slot before the `LoadLibraryExW` call, with `rcx` set from the path (`mov rcx, rsi`). It also checks that the `cmp eax, -1; jne` after the probe jumps straight to the `LoadLibraryExW` setup, so a present provider always gets loaded. The runtime check on Windows is still there. With main's `WindowsEntryStubBuilder.cpp` and the new test, it fails on both Windows and Linux (WSL, gcc 13.3) with `available.prx: optional provider is not probed with GetFileAttributesW before LoadLibraryExW`. With the fix, the relinker tests pass on Windows (65/65) and on Linux merged with current main (71/71). I amended the single commit and updated the Tested section. <details><summary>Details</summary> Pre-fix, Windows (main's `WindowsEntryStubBuilder.cpp`, new test): ``` 1/1 Test #814: windows_import_modules ...........***Failed 0.25 sec File "C:/.../core/relinker/relinker/tests/test_windows_import_modules.py", line 73, in check_native_load_paths assert len(probes) == 1, f'{library}: optional provider is not probed with GetFileAttributesW before LoadLibraryExW' AssertionError: available.prx: optional provider is not probed with GetFileAttributesW before LoadLibraryExW ``` Pre-fix, Linux (WSL, only the new test on main 2ccbd376): ``` File "/home/omer/anyps5/core/relinker/relinker/tests/test_windows_import_modules.py", line 73, in check_native_load_paths assert len(probes) == 1, f'{library}: optional provider is not probed with GetFileAttributesW before LoadLibraryExW' AssertionError: available.prx: optional provider is not probed with GetFileAttributesW before LoadLibraryExW 0% tests passed, 1 tests failed out of 1 ``` With the fix (67ddb36): ``` Windows: 100% tests passed, 0 tests failed out of 65 (relinker tests) Linux, merged with main 2ccbd376: 100% tests passed, 0 tests failed out of 71 (relinker tests) ``` </details>
Celegans12 commented 2026-10-13 00:51:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-13T00:51:16Z.


@adriadam10 when you have a moment, could you take another look? The PE check from your review now runs on every host, and it fails on Linux with main's WindowsEntryStubBuilder.cpp as you asked (the output is in my comment above). CI is green on 67ddb36 and it still merges cleanly.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6135605894 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3579#issuecomment-6135605894). Originally posted by [Celegans12](https://github.com/Celegans12) on 2026-10-13T00:51:16Z. --- @adriadam10 when you have a moment, could you take another look? The PE check from your review now runs on every host, and it fails on Linux with main's `WindowsEntryStubBuilder.cpp` as you asked (the output is in my comment above). CI is green on 67ddb36 and it still merges cleanly.
nicolasfalesy commented 2026-10-13 08:00:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by nicolasfalesy on 2026-10-13T08:00:57Z.


Heads-up for #3579 and #4739 (posting the same note on both): they merge without a textual conflict, but together they create a circular import between two relinker test modules.

  • #3579 adds from test_guest_tls import data_directory, guest_with_tls to test_windows_import_modules.py.
  • #4739 adds from test_windows_import_modules import dynamic, executable to test_guest_tls.py.

Linux (Arch, Python 3.14, Release), main 7e181fcc3 with both merged: guest_tls, guest_symbol_names, windows_import_modules and weak_imports fail with

ImportError: cannot import name 'dynamic' from 'test_windows_import_modules'

and the tests that import those modules fail the same way (guest_none_relocations, guest_gnu_hash, guest_module_identity, tls_diagnostics, ...). With either PR alone, guest_tls and windows_import_modules pass. Whichever lands second will need to move the shared helpers (for example into a small common test module) instead of importing across.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6141072743 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3579#issuecomment-6141072743). Originally posted by [nicolasfalesy](https://github.com/nicolasfalesy) on 2026-10-13T08:00:57Z. --- Heads-up for #3579 and #4739 (posting the same note on both): they merge without a textual conflict, but together they create a circular import between two relinker test modules. - #3579 adds `from test_guest_tls import data_directory, guest_with_tls` to `test_windows_import_modules.py`. - #4739 adds `from test_windows_import_modules import dynamic, executable` to `test_guest_tls.py`. Linux (Arch, Python 3.14, Release), `main` 7e181fcc3 with both merged: `guest_tls`, `guest_symbol_names`, `windows_import_modules` and `weak_imports` fail with ``` ImportError: cannot import name 'dynamic' from 'test_windows_import_modules' ``` and the tests that import those modules fail the same way (`guest_none_relocations`, `guest_gnu_hash`, `guest_module_identity`, `tls_diagnostics`, ...). With either PR alone, `guest_tls` and `windows_import_modules` pass. Whichever lands second will need to move the shared helpers (for example into a small common test module) instead of importing across.
adriadam10 commented 2026-10-13 09:27:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T09:27:21Z.

Review: APPROVED


Checked the new probe in WindowsEntryStubBuilder.cpp (only errors 2/3 skip an optional provider, a present file always reaches LoadLibraryExW, the original error is kept) and the PE assertions in test_windows_import_modules.py, which now run on every host. windows_import_modules and guest_tls pass here, and the new check fails with main's stub builder. Merging once the full Build is green.

Heads-up from @nicolasfalesy: together with #4739 this creates a circular import between test_guest_tls and test_windows_import_modules; whichever merges second needs to resolve it.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5501473515 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3579#pullrequestreview-5501473515). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-13T09:27:21Z. **Review:** APPROVED --- Checked the new probe in `WindowsEntryStubBuilder.cpp` (only errors 2/3 skip an optional provider, a present file always reaches `LoadLibraryExW`, the original error is kept) and the PE assertions in `test_windows_import_modules.py`, which now run on every host. `windows_import_modules` and `guest_tls` pass here, and the new check fails with main's stub builder. Merging once the full Build is green. Heads-up from @nicolasfalesy: together with #4739 this creates a circular import between `test_guest_tls` and `test_windows_import_modules`; whichever merges second needs to resolve it.
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!3579
No description provided.