fix(relinker): resolve a needed module on the executable that exports its imports #15245
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15245"
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 simnJS on 2026-11-02T22:04:56Z.
What
Builds on #11432, which is in
main; only the commits after it are new here.A converted module can name the executable of its title as a dependency, under a module name the image does not record. Trackmania (PPSA02195) has such a module: the Windows entry stub then looks for a library of that name in
libs/and stops with error 126.--executable-module <name>(repeatable) names the needed libraries to resolve on the executable. For a named library the Windows entry stub takes the image handle withGetModuleHandleW(NULL)when there is nolibs/<name>.dll; alibs/<name>.dllthat is present but fails to load stops start-up with its load error. Linux and macOS leave a named library out ofDT_NEEDEDandLC_LOAD_DYLIBat conversion.GetProcAddressresolution stays on the export table #11432 adds. Conversion fails when the executable does not export a symbol imported from a named library, and prints a line for each library resolved this way.The name is given explicitly because the image does not keep the executable's module name, and overlapping export names do not show that a library is the executable. A library that is not named loads as before, and a bundled module of the same name is still loaded. The debt file records how the provider is chosen and the remaining gaps: on Windows the name stays in
.needed.json, and a TLS import from the executable fails at conversion.Tested
Linux x86-64, relinker-only build (
-DANYPS5_RELINKER_ONLY=ON), Release:executable_module_imports(a named library, an unnamed library whose imports the executable exports, and a named library with an import the executable does not export, converted for Windows, Linux and macOS),windows_executable_exports,cli_args,cli_helpand the guest module tests pass. With the named binding disabled,executable_module_importsfails. The native Windows cases ofexecutable_module_importsrun only on Windows and were not run on this head; on Linux the test checks that the generated PE holds the.dllpath only for a named library. On Linux and macOS only the converted dependency lists were checked; nothing was executed there. Trackmania (PPSA02195) was not converted with--executable-module.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-02T22:58:00Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
The change builds, the relinker tests it reaches pass, and the negative control fails as it should. One problem blocks it: the Windows stub checks for the file
libs/<name>, but the loader openslibs/<name>.dll. So alibs/<name>.dllthat is present but fails to load for any reason is silently replaced by the executable, and the debt entry and the test do not show this.What I ran
Head
16b292dab4a936dc9737b79357e62f481a62baee,main5cb015caaaaf83f8ee431414ee6a457b5b307d49, merged treedf336d6a6cf8b23a2340d3104e49dad981fe4576, on Debian 13 with GCC 14.2.0 (Release, Ninja).Results
git diff --checkcheck_conventions.pylibs(script)windows_executable_exports,executable_module_importslinux_executable_exports,macos_executable_exports,guest_module_*,windows_import_modules,macos_output,windows_fixed_baseagc_driver_image_sample_lod_clamp_shader_lane(new failure in build.json)unwrap_self_..._destination_directory_group(new failure in build.json)git status --porcelainemptyAbout the two failures build.json lists as new:
agc_driver_image_sample_lod_clamp_shader_lane: the failure baseline is from096c45570f, 227 commits behindmain. Since thenmainhas merged AGC changes to the same feature (#12980,4e2a028e43 fix(agc): bind a T# minimum LOD through an S# that holds the LOD at 0). This PR changes only files undercore/relinker, its tests and a debt doc, and nothing of the AGC driver or the shader recompiler. The failure comes frommain, not this PR. I did not rebuild the AGC test with the PR's files reverted.unwrap_self_UnwrapTest_test_new_output_inherits_the_destination_directory_group: fails withos.chown(...)→EINVALinside the sandbox. This PR does not touchtools/, so the failure comes from the test environment.Failing AGC test, last line
Negative control
I set the production files of commit
4807af4ff254back to their state at67d34af2df49, which keeps only #11432's export table:WindowsEntryStubBuilder.{hpp,cpp},WindowsExportBuilder.{hpp,cpp},WindowsPePatcher.cppandGuestModuleBuilder.cpp. After rebuildingrelinker,executable_module_importsfails incheck_linux, andwindows_executable_exportsstill passes, as expected:output
I then also restored
WindowsElfPatcher.hpp,WindowsPePatcher.cppandConversion.cppfrommain, which unhooks the executable export table.windows_executable_exportsfails withAssertionError: {}.I restored the merged files and rebuilt. Both tests pass again, and the worktree matches the merged tree.
On Linux this control covers only the Linux and macOS dependency lists and the presence of the PE export. The Windows parts of
executable_module_importsrun only whenos.name == 'nt', so this machine does not run the new entry-stub code (see "Not verified").Findings
Blocking
The file probe checks a different file than the one
LoadLibraryExWopens, so a brokenlibs/<name>.dllsilently falls back to the executableWindowsEntryStubBuilder.cpp#L656-L676,#L705-L711rsiispath + libraries[index](L150-L152). An executable provider has no module suffix, so that path has no extension.LoadLibraryExWadds.dllto such a path. The PR's ownwindows-librarycase depends on that: it puts the provider atlibs/SyntheticMain.dlland expects it to load (test L90-L99).GetFileAttributesWdoes not add anything, soprobeMissingFilecheckslibs\SyntheticMain.libs/<name>.dllcan be present and still fail to load: missing dependency, corrupt file, wrong architecture, failingDllMain. The probe then finds nolibs\<name>, takes themissingOptionalbranch, and resolves every import against the executable. It prints a message only with--windows-diagnostics, and that message says the module was "not found".libs/<name>.dllwhose own dependency is missing", and the gap covers every load failure.libs/SyntheticMainwith no extension (test L66-L69). The loader never opens that file, so the case fails for the wrong reason. A broken.dllis not tested at all.<path>.dll. A trailing.would also do if you prefer to keep the bare name: then add.to theLoadLibraryExWpath for these names instead.libs/SyntheticMain.dlland expect the load to fail.libs/<name>.dllto what is still open, or drop it once the probe matches.Non-blocking
.dllfile are not told apart. The same mismatch affects the existing optional-library probe onmain(the!imported[index]path). After the fix, a straylibs/<name>with no extension would still make the stub fail instead of falling back. That is safe, but worth keeping consistent with whatever fix you choose.67d34af2df49, as the description says. Its executable export table is only checked here throughwindows_executable_exportsand negative control 2, and I did not review it beyond its interaction with this change.Not verified
nativecases (GetModuleHandleW(NULL), the diagnostics text, the partial, suffix and library cases) execute only on Windows, and this machine is Linux. The blocking finding rests on the code and on the PR's ownwindows-librarycase, which needs the.dlladded; I did not reproduce it on Windows.--macosdependency-list check ran; nothing was executed on macOS.mainby rebuilding the AGC test with this PR's relinker files reverted. My conclusion that it comes frommainrests on the PR touching no AGC files and on recentmaincommits to the same feature.To get this to a good state
LoadLibraryExWopens (<name>.dll), so a present but broken library stops startup with the load error.libs/SyntheticMain.dll, and rerun the Windows tests on Windows.libs/<name>.dllsentence to whatever remains open.Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T06:46:31Z.
Review: APPROVED
Re-checked — approved
The new commit
c547f5e845adds.dllto the path of an executable-provider library. TheGetFileAttributesWprobe andLoadLibraryExWnow check the samelibs\<name>.dll, so a present but broken library stops startup with its load error. The commit also changes the test and the debt entry to match.What changed since my last review
1:1through4:4are identical).c547f5e845 fix(relinker): probe the .dll file the loader opens for an executable module:WindowsEntryStubBuilder.cpp: theexecutableProviderscomputation moves before the path table, andname += ".dll"is added for providers (L148-L166). The probe after a failed load (L671-L678) therefore checks the file the loader opened.libs/SyntheticMain.dll(test L66-L70).libs/<name>.dllbeing passed over for the executable is removed.What I ran
Head
c547f5e8457d3b76619883caf2de85884dac1b98,maind1ae628bc2f62459cce1e9872ba5632c938c71f2, merged treedb181f9d5678bf0a557f330da16bff08c0678a21, on Debian 13 (GCC 14.2.0, Release, Ninja).git diff --checkcheck_conventions.pylibs(script)unwrap_self_..._destination_directory_groupfails, and it fails onmaintoo (known failure)windows-resolved)libs\SyntheticMain.dllpresent, barelibs\SyntheticMainabsentwindows-absent)libs\SyntheticMain, unchanged; the loader still appends.dllitselfgit status --porcelainemptyThe AGC failure I reported last time as coming from
mainno longer appears. The baseline is now currentmain.Previous findings
libs/<name>while the loader openedlibs/<name>.dll. Resolved..dll(L163-L164), and I confirmed the converted PE embedslibs\SyntheticMain.dllfor the provider case.LoadLibraryExW, the probe at L678 sees the existing file and branches to the failure path instead ofmissingOptional.libs/SyntheticMain.dll..dllwere not told apart. No longer applies to this PR's path: a stray extensionlesslibs/<name>is now ignored for providers. The same mismatch remains in the optional-library probe that is already onmain(the!imported[index]path at L671), but this PR does not change it.67d34af2df49was reviewed only through its interaction with this change. Still open as a scope note. The commit is unchanged;windows_executable_exportspasses.New findings
Blocking
None.
Non-blocking
None.
Negative control
The only test line that changed runs only when
os.name == 'nt'. Reverting the production change on this Linux machine would leave the test's result unchanged, so a ctest-based control would prove nothing. Instead, I checked the effect on the converted PE (table above): the provider path carries.dlland the non-provider path does not. The earlier negative controls for the Linux/macOS dependency lists and the export table still apply, because those files did not change.Not verified
nativecases (GetModuleHandleW(NULL)fallback, the brokenlibs/SyntheticMain.dllfailing startup, diagnostics text) execute only on Windows. The author reports that they pass on Windows 11 with WinLibs GCC 15.2.0.--macosdependency-list check ran.Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T10:27:34Z.
Review: APPROVED
Re-checked — approved
The only new commit is
ccb32747bb, a merge ofmain4f41f4c375into the branch. The PR's five commits are unchanged, the merged tree builds and passes the PR's tests, and the Windows-only cases I could not run now have an independent Windows report.What changed since my last review
Commits:
ccb32747bbmergesmain4f41f4c375into the branch. The range-diff shows the five PR commits as=, so the PR's own content is the same as inc547f5e845, which I reviewed last time.Overlap with
main: betweend1ae628bc2and4f41f4c375,mainchanged two files this PR also changes.GuestModuleBuilder.cppgainedunavailableUnusedand--omit-unavailable-dependencies.Conversion.cppchanged too.unavailableUnusedreturns false whenever a module imports a symbol from the dependency. A name the executable provides always has at least one import, sounavailableUnusednever removes it. The two filters chain without conflict:unavailableUnusedruns first, thenloadsHost, at theaddHostandneededLibrariescall sites.New comment by bunbeans2-arch (Windows 11, MSYS2 UCRT64 GCC 16.1.0):
executable_module_importsfails atexpect_entrywith error 126..dllprobe change reverted, it fails atexpect_load_failure.This covers the Windows execution and the Windows negative control that I listed under "Not verified". I accept these results as reported by that reviewer; I did not reproduce them.
The description is unchanged.
What I ran
Head
ccb32747bbae78d7d83363658dc9229133fc31a5,main4f41f4c375f5abb487dbd184fbc150f31994d762, merged tree3272c5e643371d626caef780118bd8d54b3557b7, on Debian 13 (GCC 14.2.0, Release, Ninja).git diff --checkcheck_conventions.pylibs(script)unwrap_self_..._destination_directory_groupfails, and it also fails onmain(known failure).git status --porcelainemptyPrevious findings
67d34af2df49was reviewed only through its interaction with this change. Still open, as a scope note. The commit is unchanged, andwindows_executable_exportspasses here and in the new Windows report.All other earlier findings were resolved or no longer applied in my last review, and nothing has changed them since.
New findings
Blocking
None.
Non-blocking
None.
Not verified
os.name == 'nt'.--macosdependency-list check ran.Imported from boykopovar/AnyPS5. Originally posted by Superseabas on 2026-11-06T10:35:30Z.
Review: APPROVED
Windows run of the
--executable-modulehead,068fccf2bb, the first on Windows since the change @oneandonlydean asked for. The native Windows cases ofexecutable_module_importspass, and nothing else in the Windows relinker and entry-stub tests changes.Head merged onto
maine64c194c43(clean merge, local only). Windows 11 Home 10.0.26200, WinLibs GCC 16.2.0 (x86_64-ucrt-posix-seh, r3), Python 3.13, Release,BUILD_TESTING=ON, run from PowerShell so that the WinLibs runtime DLLs come first onPATH.Tests.
ctest -R '^(windows_|entry_stub|guest_zero_finalizer|cli_|linux_executable_exports|macos_executable_exports|executable_module)' -j 4, 3 runs:mainexecutable_module_importsThe one failure on both trees is
windows_crash_thread_name(#15578).guest_zero_finalizer,entry_stub,windows_entry_stub_bounds,windows_import_modules,windows_dependency_diagnostics,windows_executable_exports,cli_argsandcli_helppass in every run.executable_module_importsruns its native cases here (os.name == 'nt'): the resolved entry, a brokenlibs/SyntheticMain.dllstopping startup withFailed to load module:, the diagnostics line, the unnamed load failure and the provider copied into place.Red check. With
executableProviders[index] = false;inWindowsEntryStubBuilder.cpp,executable_module_importsfails 3 of 3, atassert PROBED in output.read_bytes()(line 91).The resolved line.
WindowsPePatcherandGuestModuleBuilderboth print it, so I checked whether a Windows conversion prints it twice. It doesn't. Converting the test'sconsumer.prxfixture with--executable-module SyntheticMainprintsNeeded module SyntheticMain is resolved on the executable (--executable-module)once with--windows, once for Linux and once with--macos.Non-blocking. A name that matches no needed library is ignored without a word. The same fixture converted with
--executable-module SyntheticMianexits 0 with no resolved line and nothing on stderr, soSyntheticMainis then loaded as an unnamed library and fails at startup. A warning for a name that matches no needed library would make a typo show up at conversion time.check_conventions.py --base mainpasses. No title was converted.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by gabichuuuuu on 2026-11-07T23:30:20Z.
Review: COMMENTED
Read
8675703f06againstmain.The changed files match
mainexcept for this PR's lines, so this is the code that would merge. The.dllprobe and the explicit option asked for earlier are both in, and unnamed libraries keep the oldfindGuestcheck inloadsHost, so titles that load today aren't affected.A named library can be dropped without a word. On Linux and macOS, the "is resolved on the executable" line comes only from
noteHostImport(GuestModuleBuilder.cpp:222-227), which runs for a referenced import.loadsHost(:383-386, used at:421,:431and:554) still removes a named library fromDT_NEEDED/LC_LOAD_DYLIBwhen nothing imports from it, and prints nothing; on WindowsWindowsPePatcher.cpp:108-110prints the line for every named library. The debt entry and USAGE say a line is printed for each library resolved this way. Printing it whereverloadsHostdrops a name, and warning for a name that matches no needed library (the typo case raised in the last review, still ignored on all three targets), would make the option say what it did.Not covered. As the description says, PPSA02195 hasn't been converted with the option, and on Linux and macOS only the dependency lists are checked.
Not run here; this is from reading the code.
AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by gabichuuuuu on 2026-11-08T02:03:35Z.
Review: COMMENTED
Follow-up to my read-only review: this time I ran
8675703f06, merged ontomain676fb61acc(clean merge).Setup: Windows 11, WinLibs GCC 15.2, Release, relinker-only.
executable_module_imports(the brokenlibs/SyntheticMain.dllcase fails to load as it should):executable_module_imports,windows_executable_exports,linux_executable_exports,macos_executable_exports,cli_args,entry_stub,windows_entry_stub_bounds,windows_import_modules,windows_guest_export_aliases,guest_needed_modules,guest_module_identity,guest_module_directories,needed_libraries.The two points from my last review, now reproduced. I used the test's own fixtures (
importer(), plus the same consumer without its relocation table, so its import ofSyntheticMainis not referenced):SyntheticMaindropped fromDT_NEEDED; line printedSyntheticMaindropped from bothDT_NEEDEDlists; nothing printed--executable-module SyntheticMainX(typo)SyntheticMainstill needed; no warningSo on Linux, and on macOS, which uses the same
loadsHostpath (not run), a named library that nothing references leaves the dependency lists without the line that the debt entry and USAGE promise. A misspelled name is ignored on every target, and the mistake only shows when the program fails to load the library. Printing the line whereverloadsHostdrops a name, and warning when a name matches no needed library, would close both gaps.These are diagnostics only: everything that loads today still loads the same way.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T21:22:48Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; I reviewed all changed files, and the inspected code supports the documented behavior.
What I ran
8a5e0a362f1bc5cb2edc3113d72fbe7f7cc350ca.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
core/relinker/CMakeLists.txt,core/relinker/cli/include/Cli.hpp,core/relinker/cli/src/CliArgs.cpp,core/relinker/cli/tests/CliArgsTests.cpp,core/relinker/elfpatcher/include/elfpatcher/windows/WindowsElfPatcher.hpp,core/relinker/elfpatcher/include/elfpatcher/windows/WindowsEntryStubBuilder.hpp,core/relinker/elfpatcher/include/elfpatcher/windows/WindowsExportBuilder.hpp,core/relinker/elfpatcher/src/windows/WindowsEntryStubBuilder.cpp,core/relinker/elfpatcher/src/windows/WindowsExportBuilder.cpp,core/relinker/elfpatcher/src/windows/WindowsPePatcher.cpp,core/relinker/main.cpp,core/relinker/relinker/include/relinker/guest/GuestImage.hpp,core/relinker/relinker/include/relinker/pipeline/Conversion.hpp,core/relinker/relinker/src/guest/GuestModuleBuilder.cpp,core/relinker/relinker/src/pipeline/Conversion.cpp,core/relinker/relinker/tests/test_executable_module_imports.py,docs/dev/debt/relinker.md, anddocs/user/USAGE.md.To get this to a good state
Nothing is required. Optional: run the described tests on the pinned head and exercise the native Windows startup cases on Windows.
Pull request closed