feat(relinker): support fixed Windows guest image bases #4140
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4140"
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 veosett on 2026-10-11T23:55:00Z.
What
Addresses the Windows side of #4013. Executables that read
imports.txtoffsets throughoffset + 0x400000fault 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: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, retainNX_COMPAT, and setRELOCS_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--windowsand 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, thencmake --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.ET_SCE_DYNEXEC, a zero-basedPT_LOAD, and the reportedcmp QWORD PTR [rax+0x400000], 0instruction. Built separately from unmodifiedmainbca7a29d2, it exits with 0xc0000005; converted with the new option, it exits with 42.0x7ffe0000) fails with 0xc0000018 / STATUS_CONFLICTING_ADDRESSES, rather than silently relocating. User-address-space overflow fails conversion without writing an executable.mainfor 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, d8f73c257, 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:
ANYPS5_RELINKER_ONLY=ONandBUILD_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.windows_fixed_basevalidates 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
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)Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-12T20:08:06Z.
Ruffle runs with this on Windows. Windows 11 (26300), AMD Radeon 860M, WinLibs GCC 15.2.0, Release, head
d8f73c257merged ontomain2f4cc8983.Tests:
ctestundercore/relinker: 115/115, includingtest_windows_fixed_base.pyand theCliArgscases.Ruffle (PPSA68091, catalog 1.2.0), 60 s runs:
--windowsFATAL: unhandled exception 0xc0000005, ripPPSA68091.exe+0x11d4f, the fault #4013 describes--windows --windows-fixed-base 0x400000Ruffle Flash | FPS: 57.00, closes with exit 0The 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:
unresolved ELF import sZuwaDPATKs from libkernel.prx.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)
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T11:06:08Z.
Rebased onto current
main(conflicts with theWindowsPePatcher/Conversionrefactor):--windows-fixed-basenow goes throughConversionOptions.WindowsFixedBaseand applies to the main executable only, as--windows-diagnosticsdoes. 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 with0x400000). Merging once the full Build is green.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T11:13:39Z.
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.
main)core/relinker/cli/include/Cli.hppL7, L24core/relinker/cli/src/CliArgs.cppL2-3, L6, L11, L23, L110core/relinker/cli/tests/CliArgsTests.cppL208, L235docs/user/USAGE.mdL52, L77core/relinker/cli/src/CliArgs.cppL11