fix(relinker): prefer 0x400000 for Windows executables #9332

Merged
rooklz merged 1 commit from upstream-pr/9332 into main 2026-10-24 23:57:29 +00:00
rooklz commented 2026-10-21 18:41:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-21T18:41:27Z.


What

On Windows, Ruffle (PPSA68091), VLC (PPSA85300) and XPSemu (PPSA97358) only start when they're converted with --windows-fixed-base 0x400000. They read their GOT slots at 0x400000 plus the offsets in app0/imports.txt (#4013), but the default executable puts its lowest ELF load page at 0x140010000, so the first read faults. babyhuey on #5732, about VLC on main 64a9caa62: with the option it "runs the full 60 s at about 119 fps with no fault. Without --windows-fixed-base it still faults at start-up as before (#4013)". dantdmdarealguy measured the same for Ruffle on #4013. The web converter has no way to pass the option.

This makes 0x400000 the preferred address of the executable's lowest ELF load page, which is a PE image base of 0x3f0000, since the headers take the 64 KiB before it. Otherwise nothing changes:

  • The executable keeps its base relocations and still has no DYNAMIC_BASE, as since #4237. Windows maps the executable before anything else, so the range is normally free and it loads there. If the range were taken, the kept relocations let Windows move it; no run has shown that happen at either base. --windows-fixed-base is unchanged: an exact address, no relocations, and an occupied address fails to load.
  • It's still inside the 40-bit window that #4237 was about and below the guest arena at 0x200000000. No image can reach the shared user data page at 0x7ffe0000 from here: Windows refuses a SizeOfImage above 0x77000000 (@roboterspinne measured it), and the debt entry now says so.
  • Bundled modules keep DYNAMIC_BASE and their preferred base 0x140000000. macOS output is unchanged.
  • WindowsPeWriter::Write now takes the image base and whether it's fixed, instead of an optional fixed base, so the patcher can pass a preferred base. Its alignment and lower-bound check now applies to every image, secondary executables converted with --executable get the new preferred base too, and WindowsImportIdentityTests (added on main since) passes true, false to keep its fixed-base probe.

#8973 (merged) does the same on Linux.

Tested

  • Windows 11, Ryzen 7 5800X, WinLibs GCC 15.2, Release, by @babyhuey: PPSA99099 wiliwili (homebrew), which reads its own import table at its offset plus 0x400000, faults with 0xC0000005 at 2.5 s on main (0x140000000 base) and runs for the 45 s window with this head and with main plus --windows-fixed-base 0x400000.
    No title run on my side. These runs were on the pre-rebase head 14ffbf945 (same diff) unless noted. ycbuzi ran VLC (PPSA85300) on this head merged onto main a849f2516e (comment), Windows 11, RTX 4070 SUPER: on main the default conversion crashed at start-up with 0xc0000005 and 0 presents (2 runs); with this PR the default conversion rendered at 72.6 to 118.9 fps (4 of 5 runs; the fifth stopped presenting after about 20 s, which also happened once with --windows-fixed-base 0x400000). ccleste (PPSA59322) and DriftCheck (PPSA98766) render on the new default too. Ruffle and XPSemu weren't run.

  • windows_fixed_base now converts its imports.txt-style fixture without any option and runs it. The fixture reads the slot at 0x400300 and returns 42 when the slot is filled. With only that check added to main 950388bfd, the converted executable exits with 0xC0000005 on a GitHub-hosted Windows runner (verify run on my fork), which is the fault in #4013. With this change it passes. The header check there and in windows_tls_protected_entries now expects 0x3f0000.

  • Windows Server 2025 (GitHub-hosted), WinLibs GCC 15.2.0, relinker-only build, run on my fork: 233/233 with the change and 233/233 on its base 950388bfd. That includes windows_address_space, which runs the default executable 8 times and checks that its main thread stack stays below the arena.

  • macOS 26.2 (Apple M5), AppleClang 21, relinker-only build: 229/229.

  • Windows 11 Pro 10.0.26300, WinLibs GCC 15.2.0 r7, relinker-only build, by @BKlaasWerkman on 92fbd0adc1 merged into main 990f45e17d: 235 of 235 pass, windows_fixed_base and windows_tls_protected_entries with their changed expectations among them, and no result differs from main on the same machine.

  • check_conventions.py passes. pr_overlap.py against current main lists only shared docs files it could not compare.

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: PPSA85300 #5732, PPSA97358 #5600, PPSA99099 (homebrew)
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4956589256 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9332). Originally posted by [rooklz](https://github.com/rooklz) on 2026-10-21T18:41:27Z. --- ### What On Windows, Ruffle (PPSA68091), VLC (PPSA85300) and XPSemu (PPSA97358) only start when they're converted with `--windows-fixed-base 0x400000`. They read their GOT slots at `0x400000` plus the offsets in `app0/imports.txt` (#4013), but the default executable puts its lowest ELF load page at `0x140010000`, so the first read faults. babyhuey on #5732, about VLC on `main` `64a9caa62`: with the option it "runs the full 60 s at about 119 fps with no fault. Without `--windows-fixed-base` it still faults at start-up as before (#4013)". dantdmdarealguy measured the same for Ruffle on #4013. The web converter has no way to pass the option. This makes `0x400000` the preferred address of the executable's lowest ELF load page, which is a PE image base of `0x3f0000`, since the headers take the 64 KiB before it. Otherwise nothing changes: - The executable keeps its base relocations and still has no `DYNAMIC_BASE`, as since #4237. Windows maps the executable before anything else, so the range is normally free and it loads there. If the range were taken, the kept relocations let Windows move it; no run has shown that happen at either base. `--windows-fixed-base` is unchanged: an exact address, no relocations, and an occupied address fails to load. - It's still inside the 40-bit window that #4237 was about and below the guest arena at `0x200000000`. No image can reach the shared user data page at `0x7ffe0000` from here: Windows refuses a `SizeOfImage` above `0x77000000` (@roboterspinne measured it), and the debt entry now says so. - Bundled modules keep `DYNAMIC_BASE` and their preferred base `0x140000000`. macOS output is unchanged. - `WindowsPeWriter::Write` now takes the image base and whether it's fixed, instead of an optional fixed base, so the patcher can pass a preferred base. Its alignment and lower-bound check now applies to every image, secondary executables converted with `--executable` get the new preferred base too, and `WindowsImportIdentityTests` (added on `main` since) passes `true, false` to keep its fixed-base probe. #8973 (merged) does the same on Linux. ### Tested - Windows 11, Ryzen 7 5800X, WinLibs GCC 15.2, Release, by @babyhuey: PPSA99099 wiliwili (homebrew), which reads its own import table at its offset plus `0x400000`, faults with `0xC0000005` at 2.5 s on `main` (`0x140000000` base) and runs for the 45 s window with this head and with `main` plus `--windows-fixed-base 0x400000`. No title run on my side. These runs were on the pre-rebase head `14ffbf945` (same diff) unless noted. ycbuzi ran VLC (PPSA85300) on this head merged onto `main` `a849f2516e` ([comment](https://github.com/boykopovar/AnyPS5/pull/9332#issuecomment-6325558288)), Windows 11, RTX 4070 SUPER: on `main` the default conversion crashed at start-up with `0xc0000005` and 0 presents (2 runs); with this PR the default conversion rendered at 72.6 to 118.9 fps (4 of 5 runs; the fifth stopped presenting after about 20 s, which also happened once with `--windows-fixed-base 0x400000`). ccleste (PPSA59322) and DriftCheck (PPSA98766) render on the new default too. Ruffle and XPSemu weren't run. - `windows_fixed_base` now converts its `imports.txt`-style fixture without any option and runs it. The fixture reads the slot at `0x400300` and returns 42 when the slot is filled. With only that check added to `main` `950388bfd`, the converted executable exits with `0xC0000005` on a GitHub-hosted Windows runner (`verify` run on my fork), which is the fault in #4013. With this change it passes. The header check there and in `windows_tls_protected_entries` now expects `0x3f0000`. - Windows Server 2025 (GitHub-hosted), WinLibs GCC 15.2.0, relinker-only build, run on my fork: 233/233 with the change and 233/233 on its base `950388bfd`. That includes `windows_address_space`, which runs the default executable 8 times and checks that its main thread stack stays below the arena. - macOS 26.2 (Apple M5), AppleClang 21, relinker-only build: 229/229. - Windows 11 Pro 10.0.26300, WinLibs GCC 15.2.0 r7, relinker-only build, by @BKlaasWerkman on `92fbd0adc1` merged into `main` `990f45e17d`: 235 of 235 pass, `windows_fixed_base` and `windows_tls_protected_entries` with their changed expectations among them, and no result differs from `main` on the same machine. - `check_conventions.py` passes. `pr_overlap.py` against current `main` lists only shared docs files it could not compare. <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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 under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [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 <!-- #PR, or none --> - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: PPSA85300 #5732, PPSA97358 #5600, PPSA99099 (homebrew) <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: n/a <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no -->
ycbuzi commented 2026-10-21 20:14:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ycbuzi on 2026-10-21T20:14:19Z.


Windows run of 14ffbf9450 merged onto main a849f2516e (189a4bb233, clean), with #7264's tools/title_run.py merged on top to run the titles (it changes only tools/ and docs/dev/TRACING.md). Windows 11 Home 10.0.26200, MinGW-w64 GCC 15.2.0 (ucrt-posix-seh r7), Release, BUILD_TESTING=ON, RTX 4070 SUPER (NVIDIA 616.92), Ryzen 9 7900.

VLC (PPSA85300, 01.000.007), converted by title_run.py with --registry, 60 s per run:

Build Conversion Runs Outcome ImageBase Base relocations
main a849f2516e default 2 crashed at start-up, FATAL: unhandled exception 0xc0000005, 0 presents 0x140000000 kept
this PR default 5 4 rendering, 1 stalled (below); 72.6 to 118.9 fps 0x3f0000 kept
this PR --windows-fixed-base 0x400000 4 3 rendering, 1 stalled (below); 99.4 to 119.8 fps 0x3f0000 stripped

DllCharacteristics is 0x100 (NX_COMPAT only, no DYNAMIC_BASE) in all three. Three of the default runs and three of the fixed-base ones alternated (A B B A A B): 118.9, 116.2 and 106.8 fps against 119.8, 99.4 and 107.2, so no difference beyond the run-to-run spread on this machine. The last two of those, one of each, stopped presenting after about 20 and 30 s with no error line (the runner's "stalled"), so it happens with the existing option too.

ccleste (PPSA59322) and DriftCheck (PPSA98766) on the new default: 2 of 2 rendering each (116.5 and 117.1 fps; 54.3 and 58.5 fps).

ctest --test-dir core\relinker (162 tests here), --repeat until-fail:2, -j 4: 159 pass on both repeats, including windows_fixed_base, windows_tls_protected_entries and windows_address_space. guest_none_relocations, guest_relative_section_symbols and overlapping_relocations reached their 20 and 30 s timeouts under that load; run one at a time they pass on both repeats in 1 to 14 s, on this PR and on main alike.

Not run: Ruffle (PPSA68091) and XPSemu (PPSA97358), which I don't have.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6325558288 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9332#issuecomment-6325558288). Originally posted by [ycbuzi](https://github.com/ycbuzi) on 2026-10-21T20:14:19Z. --- Windows run of 14ffbf9450 merged onto `main` a849f2516e (189a4bb233, clean), with #7264's `tools/title_run.py` merged on top to run the titles (it changes only `tools/` and `docs/dev/TRACING.md`). Windows 11 Home 10.0.26200, MinGW-w64 GCC 15.2.0 (ucrt-posix-seh r7), Release, `BUILD_TESTING=ON`, RTX 4070 SUPER (NVIDIA 616.92), Ryzen 9 7900. VLC (PPSA85300, 01.000.007), converted by `title_run.py` with `--registry`, 60 s per run: | Build | Conversion | Runs | Outcome | `ImageBase` | Base relocations | |---|---|---|---|---|---| | `main` a849f2516e | default | 2 | crashed at start-up, `FATAL: unhandled exception 0xc0000005`, 0 presents | `0x140000000` | kept | | this PR | default | 5 | 4 rendering, 1 stalled (below); 72.6 to 118.9 fps | `0x3f0000` | kept | | this PR | `--windows-fixed-base 0x400000` | 4 | 3 rendering, 1 stalled (below); 99.4 to 119.8 fps | `0x3f0000` | stripped | `DllCharacteristics` is `0x100` (`NX_COMPAT` only, no `DYNAMIC_BASE`) in all three. Three of the default runs and three of the fixed-base ones alternated (A B B A A B): 118.9, 116.2 and 106.8 fps against 119.8, 99.4 and 107.2, so no difference beyond the run-to-run spread on this machine. The last two of those, one of each, stopped presenting after about 20 and 30 s with no error line (the runner's "stalled"), so it happens with the existing option too. ccleste (PPSA59322) and DriftCheck (PPSA98766) on the new default: 2 of 2 rendering each (116.5 and 117.1 fps; 54.3 and 58.5 fps). `ctest --test-dir core\relinker` (162 tests here), `--repeat until-fail:2`, `-j 4`: 159 pass on both repeats, including `windows_fixed_base`, `windows_tls_protected_entries` and `windows_address_space`. `guest_none_relocations`, `guest_relative_section_symbols` and `overlapping_relocations` reached their 20 and 30 s timeouts under that load; run one at a time they pass on both repeats in 1 to 14 s, on this PR and on `main` alike. Not run: Ruffle (PPSA68091) and XPSemu (PPSA97358), which I don't have.
rooklz commented 2026-10-21 20:17:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-21T20:17:03Z.


Thanks, that's the title run this PR was missing. Good to see the default and --windows-fixed-base 0x400000 land in the same fps range, and that the stall shows up with the existing option too, so it isn't from this change. I've added your run to the description.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6325611856 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9332#issuecomment-6325611856). Originally posted by [rooklz](https://github.com/rooklz) on 2026-10-21T20:17:03Z. --- Thanks, that's the title run this PR was missing. Good to see the default and `--windows-fixed-base 0x400000` land in the same fps range, and that the stall shows up with the existing option too, so it isn't from this change. I've added your run to the description.
wachi35676 commented 2026-10-21 23:44:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-21T23:44:38Z.


Windows and Linux run of 14ffbf945 merged onto main a6dcea927 (merges cleanly). Windows 11 Home 10.0.26300, Ryzen 5 9600X, WinLibs MinGW-w64 GCC 15.2.0, Release relinker-only BUILD_TESTING=ON; Linux: WSL Ubuntu 24.04, GCC 13.3.0, same configuration.

  • ctest (relinker-only): Windows 233/233 (performance_compare hit its 20 s timeout in the parallel pass and passed on rerun; it passed on main in the same setup). Linux 237/238, the one failure being shader_cache_runtime_sources (its internal 15 s CMake configure timed out), which fails the same way on main here.
  • Negative control: the PR's test_windows_fixed_base.py against main's relinker fails; main's version of the test plus only the new default-conversion run(...) line fails with the converted fixture exiting 3221225477 (0xC0000005) after Transferring control to ELF entry point. With this PR both pass.
  • Four homebrew (PPSA99005, PPSA47402, PPSA99581, PPSA99995), each converted for --windows --to-intel, --macos --to-rosetta and Linux --to-intel: macOS and Linux outputs are byte-identical to main. On Windows only app.exe changes; every bundled module is byte-identical. In app.exe only ImageBase changes (0x140000000 to 0x3f0000); SizeOfImage, the size of .reloc, DllCharacteristics 0x100 (no DYNAMIC_BASE) and Characteristics 0x22 (relocations not stripped) match main.
  • Where Windows actually maps the image: each app.exe started with CREATE_SUSPENDED and PEB.ImageBaseAddress read back, 3 times each. main: 0x140000000 for all four. This PR: 0x3f0000 for all four, including PPSA99581 (SizeOfImage 0x6bf1000, so it ends at 0x6fe1000).

Not run: the converted titles themselves (my build is relinker-only); ycbuzi's VLC runs above cover that.

AI-assisted: yes (Claude Code); results above were run on this machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6329078357 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9332#issuecomment-6329078357). Originally posted by [wachi35676](https://github.com/wachi35676) on 2026-10-21T23:44:38Z. --- Windows and Linux run of 14ffbf945 merged onto `main` a6dcea927 (merges cleanly). Windows 11 Home 10.0.26300, Ryzen 5 9600X, WinLibs MinGW-w64 GCC 15.2.0, Release relinker-only `BUILD_TESTING=ON`; Linux: WSL Ubuntu 24.04, GCC 13.3.0, same configuration. - `ctest` (relinker-only): Windows 233/233 (`performance_compare` hit its 20 s timeout in the parallel pass and passed on rerun; it passed on `main` in the same setup). Linux 237/238, the one failure being `shader_cache_runtime_sources` (its internal 15 s CMake configure timed out), which fails the same way on `main` here. - Negative control: the PR's `test_windows_fixed_base.py` against `main`'s relinker fails; `main`'s version of the test plus only the new default-conversion `run(...)` line fails with the converted fixture exiting `3221225477` (`0xC0000005`) after `Transferring control to ELF entry point`. With this PR both pass. - Four homebrew (PPSA99005, PPSA47402, PPSA99581, PPSA99995), each converted for `--windows --to-intel`, `--macos --to-rosetta` and Linux `--to-intel`: macOS and Linux outputs are byte-identical to `main`. On Windows only `app.exe` changes; every bundled module is byte-identical. In `app.exe` only `ImageBase` changes (`0x140000000` to `0x3f0000`); `SizeOfImage`, the size of `.reloc`, `DllCharacteristics` `0x100` (no `DYNAMIC_BASE`) and `Characteristics` `0x22` (relocations not stripped) match `main`. - Where Windows actually maps the image: each `app.exe` started with `CREATE_SUSPENDED` and `PEB.ImageBaseAddress` read back, 3 times each. `main`: `0x140000000` for all four. This PR: `0x3f0000` for all four, including PPSA99581 (`SizeOfImage` `0x6bf1000`, so it ends at `0x6fe1000`). Not run: the converted titles themselves (my build is relinker-only); ycbuzi's VLC runs above cover that. AI-assisted: yes (Claude Code); results above were run on this machine.
rooklz commented 2026-10-22 13:34:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-22T13:34:26Z.


Rebased onto current main (8b3e39832a): head 92fbd0adc1, same diff.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6342077406 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9332#issuecomment-6342077406). Originally posted by [rooklz](https://github.com/rooklz) on 2026-10-22T13:34:26Z. --- Rebased onto current `main` (`8b3e39832a`): head `92fbd0adc1`, same diff.
roboterspinne commented 2026-10-24 09:53:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by roboterspinne on 2026-10-24T09:53:24Z.

Review: COMMENTED


Reviewed head 92fbd0adc merged onto upstream/main aeeaefad9 (2026-10-24); the merge is clean (only the two docs files auto-merge).

Environment: Windows 11 Home 10.0.26200, WinLibs GCC 15.2.0 UCRT, CMake 4.3.1, Ninja 1.13.2, Python 3.13.9, -DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON, Release.

Results

  • Baseline main aeeaefad9: 238 tests, 0 failed, long_paths skipped. PR merged: 238 tests, 0 failed, long_paths skipped; windows_fixed_base 2.7 s, windows_tls_protected_entries 0.8 s, windows_address_space 0.5 s.
  • Red/green: with the four C++ changes reverted and the PR's tests kept, windows_fixed_base fails at the header assertion (line 71, 0x140000000 != 0x3f0000) and windows_tls_protected_entries fails at access-start (0x400210); restored, both pass.
  • Native header dump of the converted test_optional_plt fixture: main default ImageBase 0x140000000; PR default ImageBase 0x3f0000, Characteristics 0x22, DllCharacteristics 0x100, .reloc directory kept (size 0xc), SizeOfImage unchanged. The imports-offset fixture from the test exits 0xC0000005 with main's default and 42 with the PR's; started suspended, the PR output reports PEB.ImageBaseAddress = 0x3f0000. --windows-fixed-base 0x400000 output is identical on main and the PR (ImageBase 0x3f0000, Characteristics 0x23, no .reloc).
  • Byte comparison main vs PR: app.exe differs only in the ImageBase field (plus the one absolute GOT slot the fixture bakes in); a bundled module converted alongside it is byte-identical with ImageBase 0x140000000, and the executable with that module exits 42 on both.
  • check_conventions.py passes; pr_overlap.py against current main lists only the "could not compare" docs entries.

Should fix

  1. Rebase note (file is on main, not in this diff): core/relinker/elfpatcher/tests/WindowsImportIdentityTests.cpp:77, added by 2657a8121 after this branch's merge-base, calls WindowsPeWriter().Write(..., false, ImageBase, false). With the new signature those tokens mean imageBase=0x140000000, fixedBase=false, dynamicBase=true, so the probe loses IMAGE_FILE_RELOCS_STRIPPED (Characteristics 0x22 instead of 0x23). It compiles cleanly (-Wall -Wextra -Wconversion, no diagnostic), and the windows_import_identity target is only built without ANYPS5_RELINKER_ONLY (CMakeLists.txt:163), so the relinker matrix cannot notice. The test still passes (it only runs the probe, which has no relocation directory), but please change the call to Write(..., false, ImageBase, true, false) on rebase to keep its fixed-base intent.
  2. docs/dev/debt/relinker.md:11 and the body: the relocation example cannot occur. From 0x3f0000 an image needs SizeOfImage ≥ 0x7fbf0000 to reach 0x7ffe0000, but the loader refuses any converted image with SizeOfImage above 0x77000000: measured here with test_optional_plt.fixture and p_memsz patched, SizeOfImage 0x77000000 loads at 0x3f0000 and exits 42, 0x77001000 fails with CreateProcess error 193 (NtCreateSection → STATUS_INVALID_IMAGE_FORMAT), the same at main's 0x140000000 and with --windows-fixed-base. So the default executable ends below 0x773f0000 and never reaches the shared user data page. Also, I found no run in this PR, #4237 or #3043 that observed a relocation of the executable at either base (every reported PEB.ImageBaseAddress here was the preferred one, and the only occupancy test uses a fixed base and expects STATUS_CONFLICTING_ADDRESSES), while the entry drops its "Verified only on Windows 10" sentence. Suggested wording is in the inline comment; "as it did when 0x140000000 was taken" in the body would need a pointer to the run that showed it.

Nits

  • Body: #8973 was merged on 2026-10-22 (44661db26) and is an ancestor of this branch, so "the two don't depend on each other" reads as if it were still open. #8729 was closed unmerged on 2026-10-24, so the pr_overlap.py note no longer applies.
  • Body, Tested: ycbuzi's and wachi35676's runs were on the pre-rebase head 14ffbf945 (same diff), only BKlaasWerkman's on 92fbd0adc.
  • test_windows_fixed_base.py:84/88: the imports-offset fixture (cmp qword ptr [rax+0x400000], 0) only checks that the read at 0x400300 succeeds and is non-zero; it would also pass if any committed non-zero memory sat there. On the PR build the slot holds the resolved 0x400240; comparing against it, or jumping through it as absolute_jump() does, would make a wrong value fail too (same for the fixed-base variant on line 89).
  • The bundled module's ImageBase 0x140000000 is asserted only for the --windows-fixed-base 0x400000 conversion (line 128); test_windows_address_space.py checks the default module's DYNAMIC_BASE but not its base. A default convert(..., modules=True) with the same assertion would cover the first case where executable and module bases differ. Pre-existing gap.
  • Under Exploit Protection's "Force randomization for images (Mandatory ASLR)", off by default, Windows "will forcibly rebase DLLs and EXEs that haven't opted in to ASLR" (learn.microsoft.com, exploit-protection-reference). The default output (Characteristics 0x22, .reloc kept, no DYNAMIC_BASE) is such an image, so on such a machine the imports.txt titles fault again; --windows-fixed-base output is not rebased, but the sub-option "Do not allow stripped images" refuses it. Worth one sentence in USAGE.md's Runtime layout. main's default was rebased the same way, so this is not a regression.
  • "Otherwise nothing changes" also omits: secondary executables converted through --executable get the new preferred base too (main.cpp:67 passes no fixed base for them), the alignment/>= 0x10000 check in WindowsPeWriter::Write now applies to every image instead of only a fixed one, and the exception text changed. All harmless as far as I can see.
  • Note: on Windows "0x400000" is where the lowest ELF load page lands (WindowsLoadImage subtracts firstAddress), on Linux Conversion.cpp places virtual address 0 there; the two agree only for ELFs whose first PT_LOAD starts at vaddr 0, which PS5 executables do.

Not checked: no retail title (no dumps here, so oneandonlydean's request for a first-frame run at 0x3f0000 stands); no macOS or Linux execution; relocation of the default executable when 0x3f0000 is actually occupied could not be provoked; Mandatory ASLR was not enabled; the full (non relinker-only) build with windows_import_identity was not run; Windows 10 not measured.

I found no blocking issue; the code change is correct and complete as far as I can tell, the two should-fix items are a rebase hazard outside this diff and a documentation correction. For disclosure: I have open relinker PRs (#10390, #10391, #10401, #10402, #10403); none shares a file with this one.

Written with AI assistance (Claude Code). I ran the builds, tests and native checks above on my Windows 11 machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5637817593 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9332#pullrequestreview-5637817593). Originally posted by [roboterspinne](https://github.com/roboterspinne) on 2026-10-24T09:53:24Z. **Review:** COMMENTED --- Reviewed head 92fbd0adc merged onto `upstream/main` aeeaefad9 (2026-10-24); the merge is clean (only the two docs files auto-merge). **Environment:** Windows 11 Home 10.0.26200, WinLibs GCC 15.2.0 UCRT, CMake 4.3.1, Ninja 1.13.2, Python 3.13.9, `-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON`, Release. **Results** - Baseline `main` aeeaefad9: 238 tests, 0 failed, `long_paths` skipped. PR merged: 238 tests, 0 failed, `long_paths` skipped; `windows_fixed_base` 2.7 s, `windows_tls_protected_entries` 0.8 s, `windows_address_space` 0.5 s. - Red/green: with the four C++ changes reverted and the PR's tests kept, `windows_fixed_base` fails at the header assertion (line 71, `0x140000000 != 0x3f0000`) and `windows_tls_protected_entries` fails at `access-start` (`0x400210`); restored, both pass. - Native header dump of the converted `test_optional_plt` fixture: `main` default ImageBase `0x140000000`; PR default ImageBase `0x3f0000`, Characteristics `0x22`, DllCharacteristics `0x100`, `.reloc` directory kept (size `0xc`), SizeOfImage unchanged. The imports-offset fixture from the test exits `0xC0000005` with `main`'s default and 42 with the PR's; started suspended, the PR output reports `PEB.ImageBaseAddress` = `0x3f0000`. `--windows-fixed-base 0x400000` output is identical on `main` and the PR (ImageBase `0x3f0000`, Characteristics `0x23`, no `.reloc`). - Byte comparison `main` vs PR: `app.exe` differs only in the ImageBase field (plus the one absolute GOT slot the fixture bakes in); a bundled module converted alongside it is byte-identical with ImageBase `0x140000000`, and the executable with that module exits 42 on both. - `check_conventions.py` passes; `pr_overlap.py` against current `main` lists only the "could not compare" docs entries. **Should fix** 1. Rebase note (file is on `main`, not in this diff): `core/relinker/elfpatcher/tests/WindowsImportIdentityTests.cpp:77`, added by 2657a8121 after this branch's merge-base, calls `WindowsPeWriter().Write(..., false, ImageBase, false)`. With the new signature those tokens mean `imageBase=0x140000000, fixedBase=false, dynamicBase=true`, so the probe loses `IMAGE_FILE_RELOCS_STRIPPED` (Characteristics `0x22` instead of `0x23`). It compiles cleanly (`-Wall -Wextra -Wconversion`, no diagnostic), and the `windows_import_identity` target is only built without `ANYPS5_RELINKER_ONLY` (`CMakeLists.txt:163`), so the relinker matrix cannot notice. The test still passes (it only runs the probe, which has no relocation directory), but please change the call to `Write(..., false, ImageBase, true, false)` on rebase to keep its fixed-base intent. 2. `docs/dev/debt/relinker.md:11` and the body: the relocation example cannot occur. From `0x3f0000` an image needs SizeOfImage ≥ `0x7fbf0000` to reach `0x7ffe0000`, but the loader refuses any converted image with SizeOfImage above `0x77000000`: measured here with `test_optional_plt.fixture` and `p_memsz` patched, SizeOfImage `0x77000000` loads at `0x3f0000` and exits 42, `0x77001000` fails with CreateProcess error 193 (`NtCreateSection` → `STATUS_INVALID_IMAGE_FORMAT`), the same at `main`'s `0x140000000` and with `--windows-fixed-base`. So the default executable ends below `0x773f0000` and never reaches the shared user data page. Also, I found no run in this PR, #4237 or #3043 that observed a relocation of the executable at either base (every reported `PEB.ImageBaseAddress` here was the preferred one, and the only occupancy test uses a fixed base and expects `STATUS_CONFLICTING_ADDRESSES`), while the entry drops its "Verified only on Windows 10" sentence. Suggested wording is in the inline comment; "as it did when `0x140000000` was taken" in the body would need a pointer to the run that showed it. **Nits** - Body: #8973 was merged on 2026-10-22 (44661db26) and is an ancestor of this branch, so "the two don't depend on each other" reads as if it were still open. #8729 was closed unmerged on 2026-10-24, so the `pr_overlap.py` note no longer applies. - Body, Tested: ycbuzi's and wachi35676's runs were on the pre-rebase head 14ffbf945 (same diff), only BKlaasWerkman's on 92fbd0adc. - `test_windows_fixed_base.py:84/88`: the imports-offset fixture (`cmp qword ptr [rax+0x400000], 0`) only checks that the read at `0x400300` succeeds and is non-zero; it would also pass if any committed non-zero memory sat there. On the PR build the slot holds the resolved `0x400240`; comparing against it, or jumping through it as `absolute_jump()` does, would make a wrong value fail too (same for the fixed-base variant on line 89). - The bundled module's ImageBase `0x140000000` is asserted only for the `--windows-fixed-base 0x400000` conversion (line 128); `test_windows_address_space.py` checks the default module's `DYNAMIC_BASE` but not its base. A default `convert(..., modules=True)` with the same assertion would cover the first case where executable and module bases differ. Pre-existing gap. - Under Exploit Protection's "Force randomization for images (Mandatory ASLR)", off by default, Windows "will forcibly rebase DLLs and EXEs that haven't opted in to ASLR" (learn.microsoft.com, exploit-protection-reference). The default output (Characteristics `0x22`, `.reloc` kept, no `DYNAMIC_BASE`) is such an image, so on such a machine the imports.txt titles fault again; `--windows-fixed-base` output is not rebased, but the sub-option "Do not allow stripped images" refuses it. Worth one sentence in USAGE.md's Runtime layout. `main`'s default was rebased the same way, so this is not a regression. - "Otherwise nothing changes" also omits: secondary executables converted through `--executable` get the new preferred base too (`main.cpp:67` passes no fixed base for them), the alignment/`>= 0x10000` check in `WindowsPeWriter::Write` now applies to every image instead of only a fixed one, and the exception text changed. All harmless as far as I can see. - Note: on Windows "0x400000" is where the lowest ELF load page lands (`WindowsLoadImage` subtracts `firstAddress`), on Linux `Conversion.cpp` places virtual address 0 there; the two agree only for ELFs whose first `PT_LOAD` starts at vaddr 0, which PS5 executables do. **Not checked:** no retail title (no dumps here, so oneandonlydean's request for a first-frame run at `0x3f0000` stands); no macOS or Linux execution; relocation of the default executable when `0x3f0000` is actually occupied could not be provoked; Mandatory ASLR was not enabled; the full (non relinker-only) build with `windows_import_identity` was not run; Windows 10 not measured. I found no blocking issue; the code change is correct and complete as far as I can tell, the two should-fix items are a rebase hazard outside this diff and a documentation correction. For disclosure: I have open relinker PRs (#10390, #10391, #10401, #10402, #10403); none shares a file with this one. Written with AI assistance (Claude Code). I ran the builds, tests and native checks above on my Windows 11 machine.
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!9332
No description provided.