fix(relinker): keep unmapped gaps out of the Windows load image #6466

Merged
whamre merged 4 commits from upstream-pr/6466 into main 2026-10-19 01:00:54 +00:00
whamre commented 2026-10-15 16:27:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by whamre on 2026-10-15T16:27:00Z.


Requested by Werner · project thread

What

WindowsLoadImage kept one buffer covering everything from the first to the last PT_LOAD, and BuildSections copied the unmapped pages between segments into a section. An image with distant segments therefore allocated the whole gap twice: the 32 KiB linux_entry_argv far-load fixture (segment at 0x7ff00000) needs about 4 GiB and 30-40 s with --windows or --macos, against 0.03 s for Linux output. The web converter runs the same code.

Segment pages are now stored in blocks of contiguous page ranges. A gap that no segment maps becomes a section with an empty Data and a VirtualSize (new PeSection field, read through MemorySize() by the PE writer and the Mach-O writer). The PE section headers were already writing such gaps with a zero raw size, so the output does not change.

test_windows_sparse_load.py converts an image with a segment at 0x7fe00000 to Windows and macOS and checks the gap section has no file data; it takes 0.07 s, and on main it times out.

Tested

Ubuntu 24.04, GCC 13.3, relinker-only build: ctest 182/182 pass. -DANYPS5_ENABLE_ASAN=ON: no sanitizer reports; guest_module_args and guest_deferred_dependencies fail there on main as well ("ASan runtime does not come first"). The 810 ELF inputs the relinker tests generate, each converted for Linux, Windows and macOS with main and with this branch: all 2,430 outputs and exit codes are byte-identical. Far-load fixture: 4 GiB / 28 s before, 10 MiB / 0.01 s after. Not tested on Windows or macOS hosts.

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
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

https://claude.ai/code/session_01FU6SmPEEXPAj2ML4rNkdwV

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4876487767 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6466). Originally posted by [whamre](https://github.com/whamre) on 2026-10-15T16:27:00Z. --- <!-- claude-projects-attribution --> _Requested by **Werner** · [project thread](https://claude.ai/code/project/chan_01QbLbQHNGAqpvX8kwcxfdYu?thread=cmsg_01QbLbQHNGAqpvX8kwcxfdYuTvNXLtXNagR1Pf7ecbFBQX)_ ### What `WindowsLoadImage` kept one buffer covering everything from the first to the last PT_LOAD, and `BuildSections` copied the unmapped pages between segments into a section. An image with distant segments therefore allocated the whole gap twice: the 32 KiB `linux_entry_argv` far-load fixture (segment at 0x7ff00000) needs about 4 GiB and 30-40 s with `--windows` or `--macos`, against 0.03 s for Linux output. The web converter runs the same code. Segment pages are now stored in blocks of contiguous page ranges. A gap that no segment maps becomes a section with an empty `Data` and a `VirtualSize` (new `PeSection` field, read through `MemorySize()` by the PE writer and the Mach-O writer). The PE section headers were already writing such gaps with a zero raw size, so the output does not change. `test_windows_sparse_load.py` converts an image with a segment at 0x7fe00000 to Windows and macOS and checks the gap section has no file data; it takes 0.07 s, and on `main` it times out. ### Tested Ubuntu 24.04, GCC 13.3, relinker-only build: `ctest` 182/182 pass. `-DANYPS5_ENABLE_ASAN=ON`: no sanitizer reports; `guest_module_args` and `guest_deferred_dependencies` fail there on `main` as well ("ASan runtime does not come first"). The 810 ELF inputs the relinker tests generate, each converted for Linux, Windows and macOS with `main` and with this branch: all 2,430 outputs and exit codes are byte-identical. Far-load fixture: 4 GiB / 28 s before, 10 MiB / 0.01 s after. Not tested on Windows or macOS hosts. ### 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 - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01FU6SmPEEXPAj2ML4rNkdwV
github-actions[bot] commented 2026-10-15 16:37:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T16:37:24Z.


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 2780 core/relinker/CMakeLists.txt
PR 5021 core/relinker/CMakeLists.txt
PR 6044 core/relinker/CMakeLists.txt
PR 6802 core/relinker/CMakeLists.txt
core/relinker/elfpatcher/src/macos/MacOsImage.cpp
PR 6879 core/relinker/CMakeLists.txt
PR 6977 core/relinker/CMakeLists.txt
PR 7173 core/relinker/CMakeLists.txt
PR 7450 core/relinker/CMakeLists.txt
core/relinker/elfpatcher/src/macos/MacOsImage.cpp
PR 7531 core/relinker/CMakeLists.txt
PR 7594 core/relinker/CMakeLists.txt
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6197194264 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6466#issuecomment-6197194264). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-15T16:37:24Z. --- <!-- pr-overlap --> 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 2780](https://www.github.com/boykopovar/AnyPS5/pull/2780) | `core/relinker/CMakeLists.txt` | | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/relinker/CMakeLists.txt` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/relinker/CMakeLists.txt` | | [PR 6802](https://www.github.com/boykopovar/AnyPS5/pull/6802) | `core/relinker/CMakeLists.txt`<br>`core/relinker/elfpatcher/src/macos/MacOsImage.cpp` | | [PR 6879](https://www.github.com/boykopovar/AnyPS5/pull/6879) | `core/relinker/CMakeLists.txt` | | [PR 6977](https://www.github.com/boykopovar/AnyPS5/pull/6977) | `core/relinker/CMakeLists.txt` | | [PR 7173](https://www.github.com/boykopovar/AnyPS5/pull/7173) | `core/relinker/CMakeLists.txt` | | [PR 7450](https://www.github.com/boykopovar/AnyPS5/pull/7450) | `core/relinker/CMakeLists.txt`<br>`core/relinker/elfpatcher/src/macos/MacOsImage.cpp` | | [PR 7531](https://www.github.com/boykopovar/AnyPS5/pull/7531) | `core/relinker/CMakeLists.txt` | | [PR 7594](https://www.github.com/boykopovar/AnyPS5/pull/7594) | `core/relinker/CMakeLists.txt` |
jotitadev commented 2026-10-15 17:39:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-15T17:39:25Z.

Review: COMMENTED


Tested on a macOS host, which the description lists as not tested.

Machine: Apple M2 Max, macOS 27.2, Xcode 27, Rosetta 2. Head 5aa9af566 merged onto main 03c4cb5e7, relinker-only build, Release.

  • arm64: 174/174 pass, including windows_sparse_load.
  • x86_64 under Rosetta with /usr/bin/python3 (3.9.6): 171/174. The 3 failures (pr_overlap_tools, release_package, linux_fixed_base) fail the same way on main 03c4cb5e7.

I converted the sparse_fixture() image with --macos --skip-sce-module on the Mac:

relinker time max RSS output
main 03c4cb5e7 3.55 s 1.84 GB 73,784 bytes
this PR 0.01 s 6.5 MB 73,784 bytes, byte-identical

In the Mach-O, the gap is __ELF1 with vmsize 0x7fdff000, filesize 0 and protection 0. The far segment is mapped at +0x7fe00000.

The test only converts on macOS; it runs the output only on Windows. So I ran the Mach-O under Rosetta. I placed an x86_64 libs/libkernel.prx next to it, with a minimal Aps5StartGuest_nid_no_patch that calls the guest entry and prints rax. dyld maps the 2 GiB no-access gap without problems. The entry returns 0x2a, the 42 that the Windows branch of the test checks for, and the process stays at about 4 MB RSS.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5537434425 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6466#pullrequestreview-5537434425). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-15T17:39:25Z. **Review:** COMMENTED --- Tested on a macOS host, which the description lists as not tested. Machine: Apple M2 Max, macOS 27.2, Xcode 27, Rosetta 2. Head 5aa9af566 merged onto `main` 03c4cb5e7, relinker-only build, Release. - arm64: 174/174 pass, including `windows_sparse_load`. - x86_64 under Rosetta with `/usr/bin/python3` (3.9.6): 171/174. The 3 failures (`pr_overlap_tools`, `release_package`, `linux_fixed_base`) fail the same way on `main` 03c4cb5e7. I converted the `sparse_fixture()` image with `--macos --skip-sce-module` on the Mac: | relinker | time | max RSS | output | |---|---|---|---| | `main` 03c4cb5e7 | 3.55 s | 1.84 GB | 73,784 bytes | | this PR | 0.01 s | 6.5 MB | 73,784 bytes, byte-identical | In the Mach-O, the gap is `__ELF1` with `vmsize 0x7fdff000`, `filesize 0` and protection 0. The far segment is mapped at `+0x7fe00000`. The test only converts on macOS; it runs the output only on Windows. So I ran the Mach-O under Rosetta. I placed an x86_64 `libs/libkernel.prx` next to it, with a minimal `Aps5StartGuest_nid_no_patch` that calls the guest entry and prints `rax`. dyld maps the 2 GiB no-access gap without problems. The entry returns `0x2a`, the 42 that the Windows branch of the test checks for, and the process stays at about 4 MB RSS. Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
simonbronk commented 2026-10-15 19:46:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by simonbronk on 2026-10-15T19:46:12Z.


Independent Windows verification of head 5aa9af5665 found a test portability issue, alongside confirming the memory reduction.

The original windows_sparse_load CTest fails here at CreateProcess with WinError 193 for the near-2-GiB fixture (SizeOfImage 0x7fe3e000). I rebuilt the parent production code, 0029e62f97: it produces byte-identical PE output and the same launch error. This is not a new execution regression caused by the sparse representation. The exact Windows loader constraint remains undetermined.

The attached test-only patch retains the original 0x7fe00000-gap PE layout/file-size checks and Mach-O conversion, then converts an additional 64-MiB-gap fixture for native Windows execution and requires exit 42. It does not skip execution or alter production code. The original test fails on this host; the adjusted test passes against the same PR production binary.

Native Windows 11, WinLibs GCC 15.2r7 UCRT, Release relinker-only, Python 3.12.14:

Same 32-KiB synthetic input, 64-MiB gap Parent control This PR
PE conversion, median time / peak working set 94.6 ms / 135.04 MiB 44.1 ms / 7.02 MiB
Mach-O conversion, median time / peak working set 103.6 ms / 134.50 MiB 44.2 ms / 6.67 MiB

Three conversions per variant/format. Timing includes process startup and 2-ms sampling; memory uses Windows GetProcessMemoryInfo. Outputs are byte-identical between variants in each format, all six small Windows outputs execute with exit 42, and input bytes stay unchanged. This is a synthetic conversion measurement, not an emulator/FPS claim. The parent control restores all five changed C++ files to the parent; PR CMake/test registration is retained, other production files are identical.

Validation:

  • Untouched PR full CTest: 175/177 pass, 372.23 s. Failures: windows_sparse_load (WinError 193 above), windows_icon (CreateProcess WinError 5, unresolved on this host).
  • After the test-only patch: 5/5 focused CTests pass, 2.40 s: sparse load, BSS, TLS thread pointer, fixed base and Mach-O output. Full suite was not rerun after that test-only change.
  • Incremental conventions check of the complete candidate tree against this PR head passes using the pinned main checker 44df2163. Patch application and diff checks pass. This is not PR-vs-current-main validation.

The bundle contains the applicable patch, original/candidate test, comparison scripts, hashes, results and logs. Some passing test entries contain platform skips; several original-suite tests exceed the 30-s budget. No full system-library/emulator build, GPU/title/FPS test, Linux/macOS host execution or composition with current main. AI-assisted investigation, patch and verification.
sparse-load-windows-review-pr6466.zip

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6200851843 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6466#issuecomment-6200851843). Originally posted by [simonbronk](https://github.com/simonbronk) on 2026-10-15T19:46:12Z. --- Independent Windows verification of head 5aa9af566506d6f9b8eed245522643081eaac655 found a test portability issue, alongside confirming the memory reduction. The original `windows_sparse_load` CTest fails here at CreateProcess with WinError 193 for the near-2-GiB fixture (SizeOfImage 0x7fe3e000). I rebuilt the parent production code, 0029e62f974c453a5f6c7333f3bdb13e770e3903: it produces byte-identical PE output and the same launch error. This is not a new execution regression caused by the sparse representation. The exact Windows loader constraint remains undetermined. The attached **test-only patch** retains the original 0x7fe00000-gap PE layout/file-size checks and Mach-O conversion, then converts an additional 64-MiB-gap fixture for native Windows execution and requires exit 42. It does not skip execution or alter production code. The original test fails on this host; the adjusted test passes against the same PR production binary. Native Windows 11, WinLibs GCC 15.2r7 UCRT, Release relinker-only, Python 3.12.14: | Same 32-KiB synthetic input, 64-MiB gap | Parent control | This PR | | --- | --- | --- | | PE conversion, median time / peak working set | 94.6 ms / 135.04 MiB | 44.1 ms / 7.02 MiB | | Mach-O conversion, median time / peak working set | 103.6 ms / 134.50 MiB | 44.2 ms / 6.67 MiB | Three conversions per variant/format. Timing includes process startup and 2-ms sampling; memory uses Windows GetProcessMemoryInfo. Outputs are byte-identical between variants in each format, all six small Windows outputs execute with exit 42, and input bytes stay unchanged. This is a synthetic conversion measurement, not an emulator/FPS claim. The parent control restores all five changed C++ files to the parent; PR CMake/test registration is retained, other production files are identical. Validation: - Untouched PR full CTest: **175/177 pass**, 372.23 s. Failures: windows_sparse_load (WinError 193 above), windows_icon (CreateProcess WinError 5, unresolved on this host). - After the test-only patch: **5/5 focused CTests pass**, 2.40 s: sparse load, BSS, TLS thread pointer, fixed base and Mach-O output. Full suite was not rerun after that test-only change. - Incremental conventions check of the complete candidate tree against this PR head passes using the pinned main checker 44df2163. Patch application and diff checks pass. This is not PR-vs-current-main validation. The bundle contains the applicable patch, original/candidate test, comparison scripts, hashes, results and logs. Some passing test entries contain platform skips; several original-suite tests exceed the 30-s budget. No full system-library/emulator build, GPU/title/FPS test, Linux/macOS host execution or composition with current main. AI-assisted investigation, patch and verification. [sparse-load-windows-review-pr6466.zip](https://github.com/user-attachments/files/33512101/sparse-load-windows-review-pr6466.zip)
whamre commented 2026-10-18 10:30:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by whamre on 2026-10-18T10:30:01Z.


Thanks @jotitadev and @simonbronk for testing on macOS and Windows.

@simonbronk, good catch: Windows refuses to start the image with the 0x7fe00000 gap, on main as well. 24e5819 keeps that image for the PE layout and macOS checks and runs a 64 MiB-gap image for native Windows execution, as in your patch. The production code is unchanged.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6248770559 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6466#issuecomment-6248770559). Originally posted by [whamre](https://github.com/whamre) on 2026-10-18T10:30:01Z. --- Thanks @jotitadev and @simonbronk for testing on macOS and Windows. @simonbronk, good catch: Windows refuses to start the image with the 0x7fe00000 gap, on `main` as well. 24e5819 keeps that image for the PE layout and macOS checks and runs a 64 MiB-gap image for native Windows execution, as in your patch. The production code is unchanged.
simonbronk commented 2026-10-18 13:35:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by simonbronk on 2026-10-18T13:35:57Z.


Windows check of 24e5819, merged onto current main (b66d2dad3 = PR head + upstream/main, clean merge).

Windows 11 Pro 26200, WinLibs GCC (MinGW-w64), Ninja, Release, ANYPS5_RELINKER_ONLY=ON, BUILD_TESTING=ON.

  • windows_sparse_load: passed. The 64 MiB-gap image now runs natively and exits with 42.
  • Full relinker suite: 193/193 passed.

Negative control: I reverted the production part of 5aa9af566 (WindowsLoadImage, WindowsPeWriter, WindowsPeFormat.hpp, MacOsImage.cpp), kept the new test and rebuilt. windows_sparse_load still passes. On current main, 6158444f7 (fix(relinker): leave zero-filled PT_LOAD memory out of Windows files) already trims the zero raw data. Both relinkers produce the same 243,200-byte .exe for the 0x7fe00000-gap fixture, so the size and raw-section assertions no longer tell the two apart.

The change still has a measurable effect on the relinker's memory use. Same fixture, relinker --skip-sce-module --windows, sampled peak working set:

relinker peak working set wall time output
this PR with the fix reverted (current main behaviour) 4,099 MiB 686 ms 243,200 B
this PR 4 MiB 128 ms 243,200 B

So the fix is still worth having, but the test does not cover it on main any more. Something that fails without the fix would close that gap, for example a memory-bounded relinker run or a check on the load image.

Not run: Onimusha or other titles. One run each way.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6250554511 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6466#issuecomment-6250554511). Originally posted by [simonbronk](https://github.com/simonbronk) on 2026-10-18T13:35:57Z. --- Windows check of 24e5819, merged onto current `main` (`b66d2dad3` = PR head + `upstream/main`, clean merge). Windows 11 Pro 26200, WinLibs GCC (MinGW-w64), Ninja, Release, `ANYPS5_RELINKER_ONLY=ON`, `BUILD_TESTING=ON`. - `windows_sparse_load`: passed. The 64 MiB-gap image now runs natively and exits with 42. - Full relinker suite: 193/193 passed. **Negative control:** I reverted the production part of 5aa9af566 (`WindowsLoadImage`, `WindowsPeWriter`, `WindowsPeFormat.hpp`, `MacOsImage.cpp`), kept the new test and rebuilt. **`windows_sparse_load` still passes.** On current `main`, 6158444f7 (`fix(relinker): leave zero-filled PT_LOAD memory out of Windows files`) already trims the zero raw data. Both relinkers produce the same 243,200-byte `.exe` for the 0x7fe00000-gap fixture, so the size and raw-section assertions no longer tell the two apart. The change still has a measurable effect on the relinker's memory use. Same fixture, `relinker --skip-sce-module --windows`, sampled peak working set: | relinker | peak working set | wall time | output | |---|---|---|---| | this PR with the fix reverted (current `main` behaviour) | 4,099 MiB | 686 ms | 243,200 B | | this PR | 4 MiB | 128 ms | 243,200 B | So the fix is still worth having, but the test does not cover it on `main` any more. Something that fails without the fix would close that gap, for example a memory-bounded relinker run or a check on the load image. Not run: Onimusha or other titles. One run each way. AI-assisted: yes
whamre commented 2026-10-18 13:44:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by whamre on 2026-10-18T13:44:44Z.


@simonbronk thanks, you're right: since 6158444 the size checks pass with or without the fix.

3c84815 merges current main and makes the test also check the peak memory of the Windows and macOS conversions (resource.getrusage, so Linux and macOS hosts; Windows skips that check). With the production change reverted it fails with 4296777728 bytes of memory for a 0x7fe00000 byte address gap; with it, it passes. Full relinker suite: 198/198 on Linux.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6250643999 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6466#issuecomment-6250643999). Originally posted by [whamre](https://github.com/whamre) on 2026-10-18T13:44:44Z. --- @simonbronk thanks, you're right: since 6158444 the size checks pass with or without the fix. 3c84815 merges current main and makes the test also check the peak memory of the Windows and macOS conversions (`resource.getrusage`, so Linux and macOS hosts; Windows skips that check). With the production change reverted it fails with `4296777728 bytes of memory for a 0x7fe00000 byte address gap`; with it, it passes. Full relinker suite: 198/198 on Linux.
jotitadev commented 2026-10-19 01:00:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-19T01:00:34Z.

Review: COMMENTED


Ran 3c84815d9 on macOS, since the new peak-memory check has a darwin branch and the description lists macOS as not tested.

Machine: Apple M2 Max, macOS 27.2, Xcode 27 clang, relinker-only Release builds. Head merged onto main a373e85e5 (clean merge). Native arm64, and x86_64 under Rosetta with Xcode's /usr/bin/python3 3.9.6.

  • Full ctest: 197/197 on both. main passes 196/196 on both.
  • The new check catches the regression on macOS. Running this head's test_windows_sparse_load.py against main's relinker fails with 4296491008 bytes of memory for a 0x7fe00000 byte address gap (arm64; 4297785344 under Rosetta).

Peak RSS of one conversion of the test's fixture (ru_maxrss from RUSAGE_CHILDREN, one process per conversion):

Relinker --windows --macos
main, arm64 4097 MiB 4097 MiB
PR, arm64 5.2 MiB 4.7 MiB
main, x86_64 under Rosetta 4099 MiB 4098 MiB
PR, x86_64 under Rosetta 6.8 MiB 6.1 MiB
  • The darwin branch is right. macOS reports ru_maxrss in bytes, as the 4296491008 above shows. Multiplying by 1024 there would turn the PR's ~5 MiB into ~5 GiB and fail the check (I worked that out from the numbers; I didn't run it).
  • The Mach-O output is byte-identical to main's for both the 0x7fe00000 fixture and the 0x4000000 runnable one. I ran both under Rosetta, with an x86_64 libs/libkernel.prx whose Aps5StartGuest_nid_no_patch calls the entry and exits with its result. Both exit with 42. The 0x7fe00000 gap loads as a 2 GiB __ELF1 segment with no access and no file data.

The macOS half of the test doesn't cover the MacOsImage.cpp change. I put main's MacOsImage.cpp back on top of this head, which sizes segments by Data.size() again. windows_sparse_load and the rest of the suite still pass, 197/197 on arm64. But the gap segment's vmsize drops from 0x7fdff000 to 0, so the image no longer reserves the 2 GiB between the two PT_LOADs. The executable still runs, so a size or exit-code check can't see it. If you want that covered, an assert on the gap segment's vmsize in the Mach-O, or a byte comparison with main's output, would do it.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5565956169 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6466#pullrequestreview-5565956169). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-19T01:00:34Z. **Review:** COMMENTED --- <!-- head: 3c84815d9 --> Ran `3c84815d9` on macOS, since the new peak-memory check has a `darwin` branch and the description lists macOS as not tested. Machine: Apple M2 Max, macOS 27.2, Xcode 27 clang, relinker-only Release builds. Head merged onto `main` `a373e85e5` (clean merge). Native arm64, and x86_64 under Rosetta with Xcode's `/usr/bin/python3` 3.9.6. - Full ctest: 197/197 on both. `main` passes 196/196 on both. - The new check catches the regression on macOS. Running this head's `test_windows_sparse_load.py` against `main`'s relinker fails with `4296491008 bytes of memory for a 0x7fe00000 byte address gap` (arm64; 4297785344 under Rosetta). Peak RSS of one conversion of the test's fixture (`ru_maxrss` from `RUSAGE_CHILDREN`, one process per conversion): | Relinker | `--windows` | `--macos` | |---|---|---| | `main`, arm64 | 4097 MiB | 4097 MiB | | PR, arm64 | 5.2 MiB | 4.7 MiB | | `main`, x86_64 under Rosetta | 4099 MiB | 4098 MiB | | PR, x86_64 under Rosetta | 6.8 MiB | 6.1 MiB | - The `darwin` branch is right. macOS reports `ru_maxrss` in bytes, as the 4296491008 above shows. Multiplying by 1024 there would turn the PR's ~5 MiB into ~5 GiB and fail the check (I worked that out from the numbers; I didn't run it). - The Mach-O output is byte-identical to `main`'s for both the `0x7fe00000` fixture and the `0x4000000` runnable one. I ran both under Rosetta, with an x86_64 `libs/libkernel.prx` whose `Aps5StartGuest_nid_no_patch` calls the entry and exits with its result. Both exit with 42. The `0x7fe00000` gap loads as a 2 GiB `__ELF1` segment with no access and no file data. **The macOS half of the test doesn't cover the `MacOsImage.cpp` change.** I put `main`'s `MacOsImage.cpp` back on top of this head, which sizes segments by `Data.size()` again. `windows_sparse_load` and the rest of the suite still pass, 197/197 on arm64. But the gap segment's `vmsize` drops from `0x7fdff000` to 0, so the image no longer reserves the 2 GiB between the two `PT_LOAD`s. The executable still runs, so a size or exit-code check can't see it. If you want that covered, an assert on the gap segment's `vmsize` in the Mach-O, or a byte comparison with `main`'s output, would do it. Written with AI assistance (Claude Code). I ran the builds and tests above on my 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!6466
No description provided.