Skip to content

feat(relinker): support fixed Windows guest image bases - #4140

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
veosett:fix/relinker-windows-fixed-base
Oct 13, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
veosett:fix/relinker-windows-fixed-base

Conversation

@veosett

@veosett veosett commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

What

Addresses the Windows side of #4013. Executables that read imports.txt offsets through offset + 0x400000 fault because the relinker normally places their ELF image elsewhere.

Add --windows-fixed-base <address> to map the lowest ELF load page at a requested, 64 KiB-aligned address. For example:

relinker --windows --windows-fixed-base 0x400000 source/input.elf app.exe

The PE headers occupy the preceding 64 KiB. Relative ELF pointers, TLS directory/template addresses and lazy-import GOT stubs use the selected image base. Fixed executables omit PE base relocations, clear DYNAMIC_BASE, retain NX_COMPAT, and set RELOCS_STRIPPED, so a conflicting mapping fails to load. Invalid, unaligned or overflowing addresses throw. Bundled guest DLLs keep their normal placement; output without this option is unchanged. The option requires --windows and does not implement fixed Linux or macOS placement.

Tested

Windows 11 x64 (build 26100), WinLibs GCC 15.2.0 / MinGW-w64 14.0.0, Release relinker-only build with Python tests enabled.

  • cmake -S . -B build-relinker -G Ninja -DCMAKE_BUILD_TYPE=Release -DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON, then cmake --build build-relinker --parallel 4: passed.
  • ctest --test-dir build-relinker --output-on-failure --parallel 4: 120/120 passed, 76.23 s total; no individual test exceeded 30 s.
  • New native regression fixture uses ET_SCE_DYNEXEC, a zero-based PT_LOAD, and the reported cmp QWORD PTR [rax+0x400000], 0 instruction. Built separately from unmodified main bca7a29, it exits with 0xc0000005; converted with the new option, it exits with 42.
  • Regression coverage: default behavior, absolute GOT reads at 4/8 MiB and 16 GiB, relative function pointers, relocated TLS template pointers and TLS directory addresses, bundled guest imports, eager and lazy native imports, and CLI rejection of missing/duplicate/unaligned/overflowing addresses. Guest DLL ImageBase remains unchanged.
  • A real process with its ELF page placed at Windows SharedUserData (0x7ffe0000) fails with 0xc0000018 / STATUS_CONFLICTING_ADDRESSES, rather than silently relocating. User-address-space overflow fails conversion without writing an executable.
  • Default PE outputs are byte-identical to unmodified main for relative-pointer, eager-import and lazy-import fixtures.
  • python tools/check_test_registration.py build-relinker: passed, 18 registered native test executables.
  • python tools/check_conventions.py --base origin/main: passed.

The same commit, d8f73c2, was also built and tested on Ubuntu 24.04.5 LTS x86-64 under WSL2 (kernel 6.18.33.2), using GCC 13.3.0, CMake 3.28.3 and Python 3.12.3:

  • Release relinker-only build with ANYPS5_RELINKER_ONLY=ON and BUILD_TESTING=ON: passed.
  • ctest --test-dir build-relinker --output-on-failure --parallel 4: 125/125 passed, 6.34 s total, including native Linux ELF execution tests.
  • python3 tools/check_test_registration.py build-relinker: passed, 23 registered native test executables.
  • On Linux, windows_fixed_base validates PE generation and addresses; native Windows EXE execution and loader-collision checks were exercised in the Windows run above.

Ruffle, VLC and XPSemu themselves were not run. Full system-library/GPU builds and macOS native runtime tests were not run. This PR provides the Windows loader behavior and a synthetic reproduction; it does not close the remaining Linux part of #4013.

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 in TechnicalDebt
  • 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
  • AI-assisted: yes

@LeandroLP23

Copy link
Copy Markdown
Contributor

Ruffle runs with this on Windows. Windows 11 (26300), AMD Radeon 860M, WinLibs GCC 15.2.0, Release, head d8f73c257 merged onto main 2f4cc8983.

Tests: ctest under core/relinker: 115/115, including test_windows_fixed_base.py and the CliArgs cases.

Ruffle (PPSA68091, catalog 1.2.0), 60 s runs:

Relink Result
--windows FATAL: unhandled exception 0xc0000005, rip PPSA68091.exe+0x11d4f, the fault #4013 describes
--windows --windows-fixed-base 0x400000 runs the full 60 s, window title Ruffle Flash | FPS: 57.00, closes with exit 0

The same holds with #3635 and #3980 also merged: the default relink faults, and the fixed base runs 60 s at about 55 FPS.

The other two #4013 titles don't get far enough to show anything, even with #3635 and #3980:

  • VLC (PPSA85300) stops at unresolved ELF import sZuwaDPATKs from libkernel.prx.
  • XPSemu (PPSA97358) stops at unresolved ELF import x7g7Ebeo8-U from libkernel.prx.

Both stops are the same with and without the fixed base, so they say nothing about this PR.

AI-assisted: yes (Claude Code)

@adriadam10

Copy link
Copy Markdown
Collaborator

Rebased onto current main (conflicts with the WindowsPePatcher/Conversion refactor): --windows-fixed-base now goes through ConversionOptions.WindowsFixedBase and applies to the main executable only, as --windows-diagnostics does. Relinker build + ctest 124/124; the new tests fail without the change. Ruffle on Windows confirmed by @LeandroLP23 (fault without the option, 60 s run with 0x400000). Merging once the full Build is green.

@adriadam10
adriadam10 force-pushed the fix/relinker-windows-fixed-base branch from d8f73c2 to 319fa57 Compare October 13, 2026 11:06
@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#4593 core/relinker/cli/include/Cli.hpp L7, L24
core/relinker/cli/src/CliArgs.cpp L2-3, L6, L11, L23, L110
core/relinker/cli/tests/CliArgsTests.cpp L208, L235
docs/user/USAGE.md L52, L77
#5052 core/relinker/cli/src/CliArgs.cpp L11

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 13, 2026
@adriadam10
adriadam10 merged commit afbc22f into boykopovar:main Oct 13, 2026
7 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