Repository navigation
fix(relinker): write Windows import diagnostics after the image is built - #4665
Closed
SandstromPL wants to merge 1 commit into
Closed
SandstromPL wants to merge 1 commit into
SandstromPL wants to merge 1 commit into
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 12, 2026
Contributor
Author
This was referenced Oct 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
With
--windows --windows-diagnostics, a relink that fails late inWindowsPePatcher::Patchstill replaceswindows-diagnostics-imports.txtin the working directory. It printsWrote Windows import diagnostics to …, thenFAIL:, and exits 2. The previous executable is kept, so the file beside it now lists the imports of an input that was never converted. Checks after the write that can fail include, for example:sce_sys/icon0.pngthat fails the Windows icon check (Invalid Windows icon PNG);--rpath '${ORIGIN}/libs'(Unsupported variable in Windows run path) or--rpath /opt/libs(Ambiguous Windows run path).Patchnow writes the file after the PE image is built, includingWindowsPeWriter::Write, which can also throw. A failed check therefore leaves the previous file untouched. This is the rule ofca330dfef(a malformed icon0.png leaves no output behind) and #4346, applied to the diagnostics file. The list itself is unchanged:relocations.Importsis only read in between, byWindowsEntryStubBuilder::Buildthrough a const reference.Tested
Ubuntu 24.04, GCC 13.3, relinker-only build with
BUILD_TESTING=ON: 134/134 tests pass.test_input_preservation.pygainscheck_diagnostics_after_failed_patch. It runs--windows --windows-diagnosticswith a previous executable and a previous diagnostics file, once with a malformedsce_sys/icon0.pngand once with--rpath '${ORIGIN}/libs'. Each run must exit 2 with its error, print noWroteline, and leave both files unchanged. On main the test fails: theWroteline is printed and the diagnostics file is overwritten.libc.prx/other.prxmodules fromtest_guest_registry.py(a non-empty import list), each with and without a valid icon. Successful relinks give byte-identical executables, guest modules, diagnostics files and output. On the failing inputs, only main replaces the diagnostics file.WindowsPePatcher.cpp. feat(relinker): add --trace-imports for Windows executables #4547 edits theBuildcall after the removed lines; it already needs a rebase on main. feat(relinker): support fixed Windows guest image bases #4140 and fix(relinker): load Windows executables at a fixed low base #4237 edit the finalreturn, where they already conflict with each other. None needs to go first: whichever merges second keeps the other's line, with the diagnostics call afterWrite.tools/check_conventions.pyfrom main passes with this title and body.Not covered: the file is still written before the guest modules and the executable, so a failed executable write leaves the new list beside the previous executable. Writing it after the executable would need the import list out of
Patch, which changes the patcher interface.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)