You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(relinker): validate Windows trampoline section placement and sites - #7993
WindowsTrampolineBuilder::Build patched each AMD-only site as soon as it had checked that site, and trusted the section RVA it was given. A bad site list or placement left a half-patched image or a wrong one:
Two sites that overlap: the first is patched, then the second's original bytes no longer match and the build throws site bytes changed, which names the wrong cause. A site that starts where another ends is still accepted.
A site in a non-executable section was patched into a data section.
A nextRva below LoadRva, not aligned to SectionAlignment, or inside the preceding section, and a second .amdstub section, were accepted and produced overlapping or duplicate PE sections.
A failure on a later site left the earlier sites already patched in the caller's sections.
The builder now rejects each case with its own RelinkerException message, as WindowsIconResourceBuilder has done for its section since a7374e2. It checks every site before it writes any of them, so a rejected build leaves the sections unchanged. A valid site list produces the same bytes as before.
The existing builder tests are in amd64_only_windows_tests, which builds only on Windows. The new windows_trampoline_builder test does not execute the stubs, so it builds and runs on every host.
Tested
Ubuntu 26.04.1, kernel 7.0.0-38, GCC 15.2.0, Release, relinker-only build (-DANYPS5_RELINKER_ONLY=ON) with BUILD_TESTING=ON. Windows was not compiled. No title was run.
windows_trampoline_builder: two valid sites are patched with a jump followed by NOPs, and the .amdstub section and the next RVA follow the image. Each of these is rejected with its own message and leaves the sections and nextRva unchanged: overlapping sites in either order, the same site twice, a site in the data segment, a changed site after a valid one, a misaligned nextRva, one below LoadRva, one inside the preceding section, and a second .amdstub. An empty site list changes nothing.
On main the test fails, on the first overlapping case. Removing each new check in turn makes it fail.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
Windows check of b336f0c merged onto current main (585075cb7, clean merge), since the description says Windows was not compiled.
Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7 UCRT, Ninja, Release, ANYPS5_RELINKER_ONLY=ON, BUILD_TESTING=ON, Python 3.11.0.
windows_trampoline_builder: passed.
amd64_only_windows (the existing builder tests, built only on Windows): passed, so valid site lists still work with the new checks.
Full relinker suite: 213/213 passed.
Negative control: with WindowsTrampolineBuilder.cpp restored to main and the new test kept, windows_trampoline_builder fails on the overlapping-sites case: Unexpected error 'AMD-only site bytes changed before patching', expected 'Overlapping AMD-only trampoline sites'. That is the wrong-cause message the description reports.
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
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
WindowsTrampolineBuilder::Buildpatched each AMD-only site as soon as it had checked that site, and trusted the section RVA it was given. A bad site list or placement left a half-patched image or a wrong one:site bytes changed, which names the wrong cause. A site that starts where another ends is still accepted.nextRvabelowLoadRva, not aligned toSectionAlignment, or inside the preceding section, and a second.amdstubsection, were accepted and produced overlapping or duplicate PE sections.The builder now rejects each case with its own
RelinkerExceptionmessage, asWindowsIconResourceBuilderhas done for its section since a7374e2. It checks every site before it writes any of them, so a rejected build leaves the sections unchanged. A valid site list produces the same bytes as before.The existing builder tests are in
amd64_only_windows_tests, which builds only on Windows. The newwindows_trampoline_buildertest does not execute the stubs, so it builds and runs on every host.Tested
Ubuntu 26.04.1, kernel 7.0.0-38, GCC 15.2.0, Release, relinker-only build (
-DANYPS5_RELINKER_ONLY=ON) withBUILD_TESTING=ON. Windows was not compiled. No title was run.windows_trampoline_builder: two valid sites are patched with a jump followed by NOPs, and the.amdstubsection and the next RVA follow the image. Each of these is rejected with its own message and leaves the sections andnextRvaunchanged: overlapping sites in either order, the same site twice, a site in the data segment, a changed site after a valid one, a misalignednextRva, one belowLoadRva, one inside the preceding section, and a second.amdstub. An empty site list changes nothing.mainthe test fails, on the first overlapping case. Removing each new check in turn makes it fail.tools/check_conventions.py --base origin/mainpasses.tools/pr_overlap.pyfinds no conflicting lines; it could not compare feat(relinker): lower MCOMMIT and RDPRU for Intel with execution tests #2780, feat(aot): consolidate native ARM64 compiler, runtime and consumers #5021, test: organize library tests and label CTest suites #6044, fix(relinker): skip jump tables placed after a function's code #6618, feat(wasm): run relinked titles in the browser with WebGPU #6879, feat: run PS4 games on the AGC driver — Limbo (CUSA01664) in game (integration branch) #6977, feat: macOS on Apple Silicon host support (Rosetta 2 and MoltenVK) #7332 and feat(relinker): support --trace-imports for Linux output #7417, which conflict withmainand change other parts ofcore/relinker/CMakeLists.txt.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)