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

Merged
veosett merged 1 commit from upstream-pr/4140 into main 2026-10-13 12:26:55 +00:00
veosett commented 2026-10-11 23:55:00 +00:00 (Migrated from github.com)

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.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 bca7a29d2, 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, 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:

  • 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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4823335745 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4140). Originally posted by [veosett](https://github.com/veosett) on 2026-10-11T23:55:00Z. --- ### 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: ```sh 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` bca7a29d2, 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, 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: - 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 - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
LeandroLP23 commented 2026-10-12 20:08:06 +00:00 (Migrated from github.com)

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 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)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6131762920 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4140#issuecomment-6131762920). Originally posted by [LeandroLP23](https://github.com/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 `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 commented 2026-10-13 11:06:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T11:06:08Z.


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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6144161112 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4140#issuecomment-6144161112). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-13T11:06:08Z. --- 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.
github-actions[bot] commented 2026-10-13 11:13:39 +00:00 (Migrated from github.com)

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.

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
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6144285579 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4140#issuecomment-6144285579). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-13T11:13:39Z. --- <!-- pr-overlap --> 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](https://github.com/boykopovar/AnyPS5/blob/398ccaaf96a26fd67384fa86dc10ef504367cf2a/core/relinker/cli/include/Cli.hpp#L7), [L24](https://github.com/boykopovar/AnyPS5/blob/398ccaaf96a26fd67384fa86dc10ef504367cf2a/core/relinker/cli/include/Cli.hpp#L24)<br>`core/relinker/cli/src/CliArgs.cpp` [L2-3](https://github.com/boykopovar/AnyPS5/blob/398ccaaf96a26fd67384fa86dc10ef504367cf2a/core/relinker/cli/src/CliArgs.cpp#L2-L3), [L6](https://github.com/boykopovar/AnyPS5/blob/398ccaaf96a26fd67384fa86dc10ef504367cf2a/core/relinker/cli/src/CliArgs.cpp#L6), [L11](https://github.com/boykopovar/AnyPS5/blob/398ccaaf96a26fd67384fa86dc10ef504367cf2a/core/relinker/cli/src/CliArgs.cpp#L11), [L23](https://github.com/boykopovar/AnyPS5/blob/398ccaaf96a26fd67384fa86dc10ef504367cf2a/core/relinker/cli/src/CliArgs.cpp#L23), [L110](https://github.com/boykopovar/AnyPS5/blob/398ccaaf96a26fd67384fa86dc10ef504367cf2a/core/relinker/cli/src/CliArgs.cpp#L110)<br>`core/relinker/cli/tests/CliArgsTests.cpp` [L208](https://github.com/boykopovar/AnyPS5/blob/398ccaaf96a26fd67384fa86dc10ef504367cf2a/core/relinker/cli/tests/CliArgsTests.cpp#L208), [L235](https://github.com/boykopovar/AnyPS5/blob/398ccaaf96a26fd67384fa86dc10ef504367cf2a/core/relinker/cli/tests/CliArgsTests.cpp#L235)<br>`docs/user/USAGE.md` [L52](https://github.com/boykopovar/AnyPS5/blob/398ccaaf96a26fd67384fa86dc10ef504367cf2a/docs/user/USAGE.md#L52), [L77](https://github.com/boykopovar/AnyPS5/blob/398ccaaf96a26fd67384fa86dc10ef504367cf2a/docs/user/USAGE.md#L77) | | | | #5052 | `core/relinker/cli/src/CliArgs.cpp` [L11](https://github.com/boykopovar/AnyPS5/blob/398ccaaf96a26fd67384fa86dc10ef504367cf2a/core/relinker/cli/src/CliArgs.cpp#L11) | | |
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!4140
No description provided.