Skip to content

fix(relinker): validate Windows trampoline section placement and sites - #7993

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
MarrasFederico:fix/relinker-windows-trampoline-builder-guards
Oct 20, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
MarrasFederico:fix/relinker-windows-trampoline-builder-guards

Conversation

@MarrasFederico

Copy link
Copy Markdown
Contributor

What

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.

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 under Silent stubs in their library's technical debt file
  • 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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

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.

Pull request Shared files not compared
PR 5021 core/relinker/CMakeLists.txt
PR 6044 core/relinker/CMakeLists.txt
PR 6618 core/relinker/CMakeLists.txt
PR 6977 core/relinker/CMakeLists.txt
PR 7417 core/relinker/CMakeLists.txt
PR 7996 core/relinker/CMakeLists.txt

@DProkos

DProkos commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

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.

Not run: titles or homebrew.

AI-assisted: yes

@oneandonlydean oneandonlydean self-assigned this Oct 20, 2026
@oneandonlydean
oneandonlydean merged commit 892a4f1 into boykopovar:main Oct 20, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants