fix(relinker): preserve load failures of present optional providers #3579
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3579"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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
LoadLibraryExWcall 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.dllmust 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
main0f863c102. Windows 11, MinGW-w64 GCC 15.2.0, -DBUILD_TESTING=ON: the 65 relinker tests pass.windows_import_modulesnow checks the generated PE on every host: each optional provider must callGetFileAttributesWthrough its IAT slot beforeLoadLibraryExW, and the success branch must reach the load. It fails onmainon Windows and Linux. On Windows the stub also runs: an absent provider is skipped, and a present one importingAPS5MISS.dllfails with error 126. Linux, merged with main: 71/71 relinker tests pass. Not tested: title behavior.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/65main: 935/936 pass;agc_driver_depth_compare_copyalso fails onmain; relinker tests 71/71The Windows failures (
windows_exceptions,agc_driver_bda_device,agc_driver_flat_apertures_{0,2,3,4,5}) don't involve the relinker; Linuxagc_driver_depth_compare_copyalso fails onmain.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)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 everyLoadLibraryExWfailure 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 insideif os.name == 'nt', so on Linux the test only writes the brokenunused.prxand 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 aGetFileAttributesWcall through its IAT slot, then theLoadLibraryExWcall. Please also show that this assertion fails with the pre-fixWindowsEntryStubBuilder.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.
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_pathsnow also looks up theGetFileAttributesWIAT slot, and for each optional provider it requires that the path reference is followed by exactly onecall [rip+...]through that slot before theLoadLibraryExWcall, withrcxset from the path (mov rcx, rsi). It also checks that thecmp eax, -1; jneafter the probe jumps straight to theLoadLibraryExWsetup, so a present provider always gets loaded. The runtime check on Windows is still there.With main's
WindowsEntryStubBuilder.cppand the new test, it fails on both Windows and Linux (WSL, gcc 13.3) withavailable.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):Pre-fix, Linux (WSL, only the new test on main
2ccbd376):With the fix (
67ddb36):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.cppas you asked (the output is in my comment above). CI is green on67ddb36and it still merges cleanly.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.
from test_guest_tls import data_directory, guest_with_tlstotest_windows_import_modules.py.from test_windows_import_modules import dynamic, executabletotest_guest_tls.py.Linux (Arch, Python 3.14, Release),
main7e181fcc3with both merged:guest_tls,guest_symbol_names,windows_import_modulesandweak_importsfail withand 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_tlsandwindows_import_modulespass. Whichever lands second will need to move the shared helpers (for example into a small common test module) instead of importing across.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 reachesLoadLibraryExW, the original error is kept) and the PE assertions intest_windows_import_modules.py, which now run on every host.windows_import_modulesandguest_tlspass 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_tlsandtest_windows_import_modules; whichever merges second needs to resolve it.