fix(relinker): move a Linux PT_LOAD whose file offset is not page-congruent with its address #11487

Merged
roboterspinne merged 6 commits from upstream-pr/11487 into main 2026-11-02 10:28:42 +00:00
roboterspinne commented 2026-10-26 17:07:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by roboterspinne on 2026-10-26T17:07:35Z.


What

The Linux patcher kept a PT_LOAD whose p_offset and p_vaddr differ modulo the 4 KiB page at its input offset, so the output cannot be mapped: elf_map in fs/binfmt_elf.c passes p_offset - ELF_PAGEOFFSET(p_vaddr) to vm_mmap, and vm_mmap in mm/util.c returns -EINVAL when that offset is not page aligned. On untouched 4017310678, test_linux_fixed_base.fixture() with the segment bytes moved from offset 0x4000 to 0x4010 (vaddr 0, p_align 0x10 or 0x4000) relinks with exit 0 to an output PT_LOAD (offset 0x4010, vaddr 0x400000), and to (0x4010, 0x0) with --lazy-binding. tools/unwrap_self.py produces such input: it places each region at the next offset congruent to its vaddr modulo p_align (when that is a power of two), starting at 0x400 or the end of the program header table, so a first segment with p_align 0x10 at vaddr 0 lands at offset 0x400.

  • Rule. In SeparateSharedLoadPages a PT_LOAD with file bytes whose p_offset % 0x1000 != p_vaddr % 0x1000 is copied to the end of the file, together with the bytes lower segments place in its first page, through the path that already moves a segment whose shared first page would read other bytes. That path now places the segment at the next offset congruent to its address modulo the page size, with one resize instead of a byte loop, and sets its p_align to min(p_align, 0x1000), so for a power-of-two p_align the file honours the congruence its header states: fs/binfmt_elf.c maps every segment from p_offset - (p_vaddr % 0x1000) (elf_map) and reads p_align only in maximum_alignment, which skips a value that is not a power of two and aligns the ET_DYN load bias to the largest remaining value among all PT_LOAD headers; for ET_EXEC it is never called. The output therefore no longer grows with p_align: on the merge 277ffb4d7c, before 5890fc1820, an incongruent segment with p_align 0x80000000 produced a 2,147,488,432-byte --lazy-binding output and 0x8000000000000000 ended in std::bad_alloc, and the same padding, on main since #6681, gave a 2,147,496,368-byte --lazy-binding output on the merge 277ffb4d7c, whose path for a congruent segment is the one on main, for a segment with p_align 0x80000000 whose shared first page would read other bytes; now each of these outputs is at most three pages larger than the input. At a fixed base, every input PT_LOAD p_align is checked against the base before any segment is moved, in RequireBaseAlignment with the message RebaseProgramHeaders already uses, so a p_align the base is not a multiple of fails before padding and the set of accepted inputs is unchanged. The gABI requires p_offset and p_vaddr to be congruent modulo the page size. Congruent segments take the same path as before; segments without file bytes are not moved; other program headers that point into a moved segment keep their file offsets, as on the existing path. The default base 0x400000 and every --linux-fixed-base value are 64 KiB aligned, so the lowered p_align passes after rebasing. The header block PT_LOAD that the patcher adds at offset 0 has carried the largest power-of-two p_align of the kept PT_LOADs since 06b3413961; SeparateSharedLoadPages now also returns the largest power-of-two p_align above the page that it lowered, Patch passes it in the new field MovedLoadAlignment of ProgramHeaderLayoutRequest, and WriteLayout aligns the header block to at least that value. The output's maximum_alignment, and with it the ET_DYN load bias alignment, is therefore that of the input whether or not a segment moved, while the moved copy itself honours only the page; the padding before the copy stays below a page for every alignment. In --lazy-binding output, as for a kept segment on main, a p_align of 0x8000000000000000 puts the header block at that address, where Linux cannot map it; default and fixed-base output refuse such a p_align before any segment moves. docs/dev/debt/relinker.md records that the moved segment's own p_align is the page. The fix is not in the reader: the --windows output of the moved input is byte-identical to that of the congruent input, and --macos converts it; neither output changes with this PR.
  • Tests. LinuxLoadPageTests.cpp (linux_load_pages) gets seven cases, each with a code segment at 0x400. Three check the move: a segment at a page start with its offset 0x10 into a page, a segment at 0x1220 with offset 0x1210 whose first page a lower data and bss segment shares, and a segment at 0x2300 whose offset 0x100 lies below its page offset. Each maps the output as the kernel does and compares every byte of every input segment, with distinct fill bytes so a copy from the wrong offset shows; on untouched code each of them alone fails with linux load pages: PT_LOAD offset and address differ within a page. Four check p_align: LargeAlignmentMovesToThePage moves an incongruent segment with p_align 0x80000000, 0x4000 and 0x8000000000000000 under --lazy-binding, and LargeAlignmentOnASharedPage moves a segment with p_align 0x80000000 whose shared first page would read other bytes; both require an output at most three pages larger than the input, the same mapped bytes, a moved p_align of 0x1000 and, computed as the kernel's maximum_alignment does, a largest output p_align equal to the input's, with every output PT_LOAD congruent modulo its own p_align. CongruentLargeAlignmentOnASharedPage uses the three loads from oneandonlydean's review: code at 0x400, data at 0x1000 whose bss ends at 0x5c20, and a read-only segment at 0x5c20 with offset 0x1c20 and p_align 0x4000, congruent modulo that alignment, whose first page would read the data segment's file bytes. Under --lazy-binding it requires the same, the moved segment at an offset congruent to 0x5c20 modulo the page, and the header block PT_LOAD at an address that is a multiple of 0x4000 with p_align 0x4000; at base 0x400000 it requires a largest output p_align of 0x4000 as well. LargeAlignmentAtAFixedBaseIsRefused requires that base 0x400000 refuses p_align 0x80000000 and 0x8000000000000000 with is not a multiple of the PT_LOAD alignment.
  • Overlap. pr_overlap.py reports no shared lines with open pull requests that merge with main, among them #10917 and #7532, which also change LinuxElfPatcher.cpp, and #10662, which also changes ProgramHeaderLayoutBuilder.cpp. It cannot compare this branch with #5021, #10518, #10861, #11628, #11661, #11689, #11698, #11991, #12678, #12910, #14107 and #14212 (docs/dev/debt/relinker.md), because those do not merge with main; checked by hand at their current heads, a trial merge of this head with each of them conflicts only in files where the trial merge of main at ed1e0ed08f with it also conflicts, except with #14212, and the trial merges of this head and of main with #5021 or #10861 conflict in the same single block of docs/dev/debt/relinker.md. #14212 puts a blank line between debt entries; its trial merge with this head conflicts only where this PR adds its entry, as it did with ffa036cbec, and whichever of the two merges second keeps the entry and the blank line. git merge-tree of this head is also clean against #10479, #10518 and the author's open pull requests #11479, #11488, #11583, #11883, #12341, #13861, #13862, #13914, #13915, #13916, #13977 and #14134. #10564 and #12591, both merged, check and trim overlapping PT_LOAD ranges at lines 139 to 176 of SeparateSharedLoadPages (line 128 of core/relinker/elfpatcher/src/linux/LinuxElfPatcher.cpp); that runs before the loop this PR changes and is unchanged here. In that function this PR changes the skip condition at line 180 and the start of differs at line 195 on main (lines 181 to 182 and 197 here), replaces the padding loop at lines 200 to 202 on main with one Io::AlignBuffer call (line 202 here), and lowers the moved p_align and returns the largest power-of-two value above the page that it lowered (lines 128, 177 and 208 to 212 here). Outside it, the fixed-base p_align check of RebaseProgramHeaders (lines 329 to 331 on main) moves into RequireBaseAlignment (lines 324 to 327 here), which Patch also calls for every input PT_LOAD just before SeparateSharedLoadPages (lines 632 to 635 here), and Patch passes the returned value to the layout (lines 636 and 650 here). ProgramHeaderLayoutRequest.hpp gains the last field MovedLoadAlignment (line 22), which only LinuxElfPatcher sets; ProgramLayoutRangeTests.cpp initialises the struct by position and leaves it 0. ProgramHeaderLayoutBuilder.cpp reads it just before the loop that 06b3413961 added (lines 232 to 233 here). These line numbers refer to main at ed1e0ed08f and to this head. #10518, still open, rejects a p_align that is not a power of two in ElfReader::ReadProgramHeaders; this PR no longer relies on it to bound the output size, because the move path no longer pads to p_align. Its debt entry in docs/dev/debt/relinker.md describes the byte-by-byte padding of the move path to max(p_align, 0x1000), which this PR removes, so that entry will need rewording after whichever of the two merges second; git merge-tree of this branch with #10518 (b77442817d) is clean. #10923, merged since, changed only tools/unwrap_self.py and its test. It aligns a region to the largest power-of-two p_align among the headers it contains, not to its own alone. It still never aligns to the page, so a first segment with p_align 0x10 at vaddr 0 and no stricter header inside still lands at offset 0x400. #12307, merged on 30 Oct, changes the rel32 displacement arithmetic of TracePrologue and _appendTrampoline in LinuxElfPatcher.cpp and appends two trampoline cases to LinuxLoadPageTests.cpp; it touches none of the lines this PR changes, and the merge ffa036cbec keeps both sets of tests.

Tested

Windows 11, GCC 15.2.0 (WinLibs UCRT), relinker-only Release build (-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON); synthetic fixtures only, no title or homebrew.

  • Counter-check (ran on 4017310678; no relinker changes up to e05ba6feeb, where the change was first tested): on untouched 4017310678 the three existing linux_load_pages cases pass; each new case run alone, and all three together, fail with linux load pages: PT_LOAD offset and address differ within a page. With the change on e05ba6feeb linux_load_pages passes in 0.03 s.
  • Counter-check of the three p_align cases that 5890fc1820 added (LargeAlignmentMovesToThePage, LargeAlignmentOnASharedPage and LargeAlignmentAtAFixedBaseIsRefused) on the merge 277ffb4d7c without 5890fc1820, in that order in one process: linux_load_pages fails after 13 s at the first of them with linux load pages: output grew to 2147488432 bytes for alignment 2147483648; with LargeAlignmentOnASharedPage run first it fails with linux load pages: output grew to 2147496368 bytes on the shared page path. LargeAlignmentAtAFixedBaseIsRefused was not run on that code, whose padding for its 0x8000000000000000 case would run until std::bad_alloc; on that code path its 0x80000000 case is padded in SeparateSharedLoadPages and then refused by RebaseProgramHeaders with the same message, so the case checks that the set of accepted inputs stays the same. With the fix (5890fc1820) linux_load_pages passes in 0.26 s.
  • Counter-check of the tests of 94e4031147 on the code of ffa036cbec: linux_load_pages fails at LargeAlignmentMovesToThePage with linux load pages: the largest PT_LOAD alignment is 4096, not 2147483648, and CongruentLargeAlignmentOnASharedPage run alone fails with linux load pages: the largest PT_LOAD alignment fell to 4096. With the change both pass.
  • Relinker CLI on test_linux_fixed_base.fixture() with p_align 0x10 and 0x4000 and on the same input with its segment bytes and PT_DYNAMIC moved up by 0x10 (segment offset 0x4010), each with --skip-sce-module as default Linux, --lazy-binding, --windows and --macos output, on main at ed1e0ed08f, on ffa036cbec and on 94e4031147: the congruent inputs and all --windows and --macos outputs have the same SHA-256 on all three. For the moved inputs main leaves the Linux and --lazy-binding PT_LOAD at offset 0x4010, and both heads copy it to offset 0x9000 (output 0xa1b0 bytes instead of 0x8488 and 0x8478); the 0x1000 bytes mapped at the segment's address are the same in every Linux and --lazy-binding output of the four inputs on all three. With p_align 0x10 the two heads give identical outputs. With p_align 0x4000 ffa036cbec lowered the segment to p_align 0x1000 and the header block PT_LOAD with it (vaddr 0x402000 with p_align 0x1000, 0x2000 with --lazy-binding), so the largest output p_align fell to 0x1000; 94e4031147 keeps the segment at p_align 0x1000 and puts the header block back at vaddr 0x404000 (0x4000 with --lazy-binding) with p_align 0x4000, as on main.
  • Before/after over a corpus: the 52 executables that images() in tools/relinker_fuzz_seeds.py builds from the relinker's Python tests, plus test_linux_fixed_base.fixture() with its PT_LOAD p_align set to 0x10, 0x4000 and 0x10000, each relinked with --skip-sce-module as default Linux and --lazy-binding output (110 runs) by main at ed1e0ed08f, by ffa036cbec and by 94e4031147: all 110 runs have the same exit code, failure text and output SHA-256 on all three (108 outputs; test_guest_own_tls_relocations fails on all three with Unnamed import symbol is not a null symbol entry). None of these inputs moves a segment.
  • Merged main at 88795ed448 into the branch without conflicts (277ffb4d7c), and main at ed1e0ed08f in ffa036cbec: the only conflict was in LinuxLoadPageTests.cpp, where #12307 and this PR both append test functions and their calls in main(); both are kept, main's first. LinuxElfPatcher.cpp and docs/dev/debt/relinker.md merged automatically. Both trampoline cases of #12307 pass on ffa036cbec, and TrampolineDisplacementAcrossInt64Max runs against the move path of this PR: it uses a PT_LOAD at offset 0x400 and vaddr 0x7FFFFFFFFFFFE000, which this PR now copies to the end of the file; the site is rewritten at its input offset before the copy, so the case reads the same bytes.
  • Full suite on 94e4031147: ctest --test-dir build-relinker -j 5: 534 tests, 529 passed, among them linux_load_pages (0.20 s), program_layout_ranges, linux_load_alignment and linux_fixed_base; long_paths skipped; select_tests and its three parts select_tests_SelectGraphStateTests, select_tests_SelectBuildTests and select_tests_SelectArgumentTests fail with the Windows symlink fixture's FileExistsError, as in a full-build run on main at 73f4f7e06e on this machine; this PR changes nothing under tools/.
  • python tools/check_conventions.py --base eb5b2c13df (main) with this title and description passed on 94e4031147.
  • Not tested on Linux or macOS; CI runs the tests on all three 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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5021524829 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11487). Originally posted by [roboterspinne](https://github.com/roboterspinne) on 2026-10-26T17:07:35Z. --- ### What The Linux patcher kept a `PT_LOAD` whose `p_offset` and `p_vaddr` differ modulo the 4 KiB page at its input offset, so the output cannot be mapped: `elf_map` in `fs/binfmt_elf.c` passes `p_offset - ELF_PAGEOFFSET(p_vaddr)` to `vm_mmap`, and `vm_mmap` in `mm/util.c` returns `-EINVAL` when that offset is not page aligned. On untouched 4017310678, `test_linux_fixed_base.fixture()` with the segment bytes moved from offset 0x4000 to 0x4010 (vaddr 0, `p_align` 0x10 or 0x4000) relinks with exit 0 to an output `PT_LOAD` (offset 0x4010, vaddr 0x400000), and to (0x4010, 0x0) with `--lazy-binding`. `tools/unwrap_self.py` produces such input: it places each region at the next offset congruent to its vaddr modulo `p_align` (when that is a power of two), starting at 0x400 or the end of the program header table, so a first segment with `p_align` 0x10 at vaddr 0 lands at offset 0x400. - **Rule.** In `SeparateSharedLoadPages` a `PT_LOAD` with file bytes whose `p_offset % 0x1000 != p_vaddr % 0x1000` is copied to the end of the file, together with the bytes lower segments place in its first page, through the path that already moves a segment whose shared first page would read other bytes. That path now places the segment at the next offset congruent to its address modulo the page size, with one resize instead of a byte loop, and sets its `p_align` to `min(p_align, 0x1000)`, so for a power-of-two `p_align` the file honours the congruence its header states: `fs/binfmt_elf.c` maps every segment from `p_offset - (p_vaddr % 0x1000)` (`elf_map`) and reads `p_align` only in `maximum_alignment`, which skips a value that is not a power of two and aligns the `ET_DYN` load bias to the largest remaining value among all `PT_LOAD` headers; for `ET_EXEC` it is never called. The output therefore no longer grows with `p_align`: on the merge 277ffb4d7c, before 5890fc1820, an incongruent segment with `p_align` 0x80000000 produced a 2,147,488,432-byte `--lazy-binding` output and 0x8000000000000000 ended in `std::bad_alloc`, and the same padding, on `main` since #6681, gave a 2,147,496,368-byte `--lazy-binding` output on the merge 277ffb4d7c, whose path for a congruent segment is the one on `main`, for a segment with `p_align` 0x80000000 whose shared first page would read other bytes; now each of these outputs is at most three pages larger than the input. At a fixed base, every input `PT_LOAD` `p_align` is checked against the base before any segment is moved, in `RequireBaseAlignment` with the message `RebaseProgramHeaders` already uses, so a `p_align` the base is not a multiple of fails before padding and the set of accepted inputs is unchanged. The gABI requires `p_offset` and `p_vaddr` to be congruent modulo the page size. Congruent segments take the same path as before; segments without file bytes are not moved; other program headers that point into a moved segment keep their file offsets, as on the existing path. The default base 0x400000 and every `--linux-fixed-base` value are 64 KiB aligned, so the lowered `p_align` passes after rebasing. The header block `PT_LOAD` that the patcher adds at offset 0 has carried the largest power-of-two `p_align` of the kept `PT_LOAD`s since 06b3413961; `SeparateSharedLoadPages` now also returns the largest power-of-two `p_align` above the page that it lowered, `Patch` passes it in the new field `MovedLoadAlignment` of `ProgramHeaderLayoutRequest`, and `WriteLayout` aligns the header block to at least that value. The output's `maximum_alignment`, and with it the `ET_DYN` load bias alignment, is therefore that of the input whether or not a segment moved, while the moved copy itself honours only the page; the padding before the copy stays below a page for every alignment. In `--lazy-binding` output, as for a kept segment on `main`, a `p_align` of 0x8000000000000000 puts the header block at that address, where Linux cannot map it; default and fixed-base output refuse such a `p_align` before any segment moves. `docs/dev/debt/relinker.md` records that the moved segment's own `p_align` is the page. The fix is not in the reader: the `--windows` output of the moved input is byte-identical to that of the congruent input, and `--macos` converts it; neither output changes with this PR. - **Tests.** `LinuxLoadPageTests.cpp` (`linux_load_pages`) gets seven cases, each with a code segment at 0x400. Three check the move: a segment at a page start with its offset 0x10 into a page, a segment at 0x1220 with offset 0x1210 whose first page a lower data and bss segment shares, and a segment at 0x2300 whose offset 0x100 lies below its page offset. Each maps the output as the kernel does and compares every byte of every input segment, with distinct fill bytes so a copy from the wrong offset shows; on untouched code each of them alone fails with `linux load pages: PT_LOAD offset and address differ within a page`. Four check `p_align`: `LargeAlignmentMovesToThePage` moves an incongruent segment with `p_align` 0x80000000, 0x4000 and 0x8000000000000000 under `--lazy-binding`, and `LargeAlignmentOnASharedPage` moves a segment with `p_align` 0x80000000 whose shared first page would read other bytes; both require an output at most three pages larger than the input, the same mapped bytes, a moved `p_align` of 0x1000 and, computed as the kernel's `maximum_alignment` does, a largest output `p_align` equal to the input's, with every output `PT_LOAD` congruent modulo its own `p_align`. `CongruentLargeAlignmentOnASharedPage` uses the three loads from oneandonlydean's review: code at 0x400, data at 0x1000 whose bss ends at 0x5c20, and a read-only segment at 0x5c20 with offset 0x1c20 and `p_align` 0x4000, congruent modulo that alignment, whose first page would read the data segment's file bytes. Under `--lazy-binding` it requires the same, the moved segment at an offset congruent to 0x5c20 modulo the page, and the header block `PT_LOAD` at an address that is a multiple of 0x4000 with `p_align` 0x4000; at base 0x400000 it requires a largest output `p_align` of 0x4000 as well. `LargeAlignmentAtAFixedBaseIsRefused` requires that base 0x400000 refuses `p_align` 0x80000000 and 0x8000000000000000 with `is not a multiple of the PT_LOAD alignment`. - **Overlap.** `pr_overlap.py` reports no shared lines with open pull requests that merge with `main`, among them #10917 and #7532, which also change `LinuxElfPatcher.cpp`, and #10662, which also changes `ProgramHeaderLayoutBuilder.cpp`. It cannot compare this branch with #5021, #10518, #10861, #11628, #11661, #11689, #11698, #11991, #12678, #12910, #14107 and #14212 (`docs/dev/debt/relinker.md`), because those do not merge with `main`; checked by hand at their current heads, a trial merge of this head with each of them conflicts only in files where the trial merge of `main` at ed1e0ed08f with it also conflicts, except with #14212, and the trial merges of this head and of `main` with #5021 or #10861 conflict in the same single block of `docs/dev/debt/relinker.md`. #14212 puts a blank line between debt entries; its trial merge with this head conflicts only where this PR adds its entry, as it did with ffa036cbec, and whichever of the two merges second keeps the entry and the blank line. `git merge-tree` of this head is also clean against #10479, #10518 and the author's open pull requests #11479, #11488, #11583, #11883, #12341, #13861, #13862, #13914, #13915, #13916, #13977 and #14134. #10564 and #12591, both merged, check and trim overlapping `PT_LOAD` ranges at lines 139 to 176 of `SeparateSharedLoadPages` (line 128 of `core/relinker/elfpatcher/src/linux/LinuxElfPatcher.cpp`); that runs before the loop this PR changes and is unchanged here. In that function this PR changes the skip condition at line 180 and the start of `differs` at line 195 on main (lines 181 to 182 and 197 here), replaces the padding loop at lines 200 to 202 on main with one `Io::AlignBuffer` call (line 202 here), and lowers the moved `p_align` and returns the largest power-of-two value above the page that it lowered (lines 128, 177 and 208 to 212 here). Outside it, the fixed-base `p_align` check of `RebaseProgramHeaders` (lines 329 to 331 on main) moves into `RequireBaseAlignment` (lines 324 to 327 here), which `Patch` also calls for every input `PT_LOAD` just before `SeparateSharedLoadPages` (lines 632 to 635 here), and `Patch` passes the returned value to the layout (lines 636 and 650 here). `ProgramHeaderLayoutRequest.hpp` gains the last field `MovedLoadAlignment` (line 22), which only `LinuxElfPatcher` sets; `ProgramLayoutRangeTests.cpp` initialises the struct by position and leaves it 0. `ProgramHeaderLayoutBuilder.cpp` reads it just before the loop that 06b3413961 added (lines 232 to 233 here). These line numbers refer to `main` at ed1e0ed08f and to this head. #10518, still open, rejects a `p_align` that is not a power of two in `ElfReader::ReadProgramHeaders`; this PR no longer relies on it to bound the output size, because the move path no longer pads to `p_align`. Its debt entry in `docs/dev/debt/relinker.md` describes the byte-by-byte padding of the move path to `max(p_align, 0x1000)`, which this PR removes, so that entry will need rewording after whichever of the two merges second; `git merge-tree` of this branch with #10518 (b77442817d) is clean. #10923, merged since, changed only `tools/unwrap_self.py` and its test. It aligns a region to the largest power-of-two `p_align` among the headers it contains, not to its own alone. It still never aligns to the page, so a first segment with `p_align` 0x10 at vaddr 0 and no stricter header inside still lands at offset 0x400. #12307, merged on 30 Oct, changes the rel32 displacement arithmetic of `TracePrologue` and `_appendTrampoline` in `LinuxElfPatcher.cpp` and appends two trampoline cases to `LinuxLoadPageTests.cpp`; it touches none of the lines this PR changes, and the merge ffa036cbec keeps both sets of tests. ### Tested <!-- 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. --> Windows 11, GCC 15.2.0 (WinLibs UCRT), relinker-only Release build (`-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON`); synthetic fixtures only, no title or homebrew. - Counter-check (ran on 4017310678; no relinker changes up to e05ba6feeb, where the change was first tested): on untouched 4017310678 the three existing `linux_load_pages` cases pass; each new case run alone, and all three together, fail with `linux load pages: PT_LOAD offset and address differ within a page`. With the change on e05ba6feeb `linux_load_pages` passes in 0.03 s. - Counter-check of the three `p_align` cases that 5890fc1820 added (`LargeAlignmentMovesToThePage`, `LargeAlignmentOnASharedPage` and `LargeAlignmentAtAFixedBaseIsRefused`) on the merge 277ffb4d7c without 5890fc1820, in that order in one process: `linux_load_pages` fails after 13 s at the first of them with `linux load pages: output grew to 2147488432 bytes for alignment 2147483648`; with `LargeAlignmentOnASharedPage` run first it fails with `linux load pages: output grew to 2147496368 bytes on the shared page path`. `LargeAlignmentAtAFixedBaseIsRefused` was not run on that code, whose padding for its 0x8000000000000000 case would run until `std::bad_alloc`; on that code path its 0x80000000 case is padded in `SeparateSharedLoadPages` and then refused by `RebaseProgramHeaders` with the same message, so the case checks that the set of accepted inputs stays the same. With the fix (5890fc1820) `linux_load_pages` passes in 0.26 s. - Counter-check of the tests of 94e4031147 on the code of ffa036cbec: `linux_load_pages` fails at `LargeAlignmentMovesToThePage` with `linux load pages: the largest PT_LOAD alignment is 4096, not 2147483648`, and `CongruentLargeAlignmentOnASharedPage` run alone fails with `linux load pages: the largest PT_LOAD alignment fell to 4096`. With the change both pass. - Relinker CLI on `test_linux_fixed_base.fixture()` with `p_align` 0x10 and 0x4000 and on the same input with its segment bytes and `PT_DYNAMIC` moved up by 0x10 (segment offset 0x4010), each with `--skip-sce-module` as default Linux, `--lazy-binding`, `--windows` and `--macos` output, on `main` at ed1e0ed08f, on ffa036cbec and on 94e4031147: the congruent inputs and all `--windows` and `--macos` outputs have the same SHA-256 on all three. For the moved inputs `main` leaves the Linux and `--lazy-binding` `PT_LOAD` at offset 0x4010, and both heads copy it to offset 0x9000 (output 0xa1b0 bytes instead of 0x8488 and 0x8478); the 0x1000 bytes mapped at the segment's address are the same in every Linux and `--lazy-binding` output of the four inputs on all three. With `p_align` 0x10 the two heads give identical outputs. With `p_align` 0x4000 ffa036cbec lowered the segment to `p_align` 0x1000 and the header block `PT_LOAD` with it (vaddr 0x402000 with `p_align` 0x1000, 0x2000 with `--lazy-binding`), so the largest output `p_align` fell to 0x1000; 94e4031147 keeps the segment at `p_align` 0x1000 and puts the header block back at vaddr 0x404000 (0x4000 with `--lazy-binding`) with `p_align` 0x4000, as on `main`. - Before/after over a corpus: the 52 executables that `images()` in `tools/relinker_fuzz_seeds.py` builds from the relinker's Python tests, plus `test_linux_fixed_base.fixture()` with its `PT_LOAD` `p_align` set to 0x10, 0x4000 and 0x10000, each relinked with `--skip-sce-module` as default Linux and `--lazy-binding` output (110 runs) by `main` at ed1e0ed08f, by ffa036cbec and by 94e4031147: all 110 runs have the same exit code, failure text and output SHA-256 on all three (108 outputs; `test_guest_own_tls_relocations` fails on all three with `Unnamed import symbol is not a null symbol entry`). None of these inputs moves a segment. - Merged `main` at 88795ed448 into the branch without conflicts (277ffb4d7c), and `main` at ed1e0ed08f in ffa036cbec: the only conflict was in `LinuxLoadPageTests.cpp`, where #12307 and this PR both append test functions and their calls in `main()`; both are kept, `main`'s first. `LinuxElfPatcher.cpp` and `docs/dev/debt/relinker.md` merged automatically. Both trampoline cases of #12307 pass on ffa036cbec, and `TrampolineDisplacementAcrossInt64Max` runs against the move path of this PR: it uses a `PT_LOAD` at offset 0x400 and vaddr 0x7FFFFFFFFFFFE000, which this PR now copies to the end of the file; the site is rewritten at its input offset before the copy, so the case reads the same bytes. - Full suite on 94e4031147: `ctest --test-dir build-relinker -j 5`: 534 tests, 529 passed, among them `linux_load_pages` (0.20 s), `program_layout_ranges`, `linux_load_alignment` and `linux_fixed_base`; `long_paths` skipped; `select_tests` and its three parts `select_tests_SelectGraphStateTests`, `select_tests_SelectBuildTests` and `select_tests_SelectArgumentTests` fail with the Windows symlink fixture's `FileExistsError`, as in a full-build run on `main` at 73f4f7e06e on this machine; this PR changes nothing under `tools/`. - `python tools/check_conventions.py --base eb5b2c13df` (`main`) with this title and description passed on 94e4031147. - Not tested on Linux or macOS; CI runs the tests on all three 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: <!-- #PR, or none --> none - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> none - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> n/a - [x] AI-assisted: <!-- yes / no --> yes (Claude Code)
MarcZX10 commented 2026-10-26 17:12:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T17:12:06Z.

Review: CHANGES_REQUESTED


I reviewed the loader-mapping change and its three new byte-preservation cases. The targeted tests are detailed, but the new padding path has an unbounded case that needs handling before merge.

When !congruent, differs is now forced true and this reaches the byte-at-a-time loop below using max(p_align, 0x1000). For a page-incongruent segment with a large power-of-two p_align (for example, 0x80000000), this can append nearly 2 GiB before the later fixed-base validation rejects the image; with the lazy path it can still produce a multi-gigabyte output. This is the same padding-before-rebase failure documented in open #10518, whose current proposed validation rejects non-power-of-two values but explicitly leaves large power-of-two alignments unresolved. The new trigger makes the padding path run for every page-incongruent segment, even if no lower segment shares its page.

Please make this new path reject or otherwise bound unsupported alignment values before padding, and add a regression proving a large alignment fails promptly without allocating a huge output. If the intended protection is to rely on #10518 for non-power-of-two values, declare that merge dependency; it does not cover the large power-of-two case above.

I also checked synchronization: the PR head is 37 commits behind current main (check_main_sync.py --strict), although the current-main commits since its merge base do not touch the two changed files and the merge preview is clean. Please sync the branch and rerun the focused relinker tests after the guard is addressed. Hosted relinker checks for this head are still pending; product jobs are skipped by path policy.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5656070239 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11487#pullrequestreview-5656070239). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-26T17:12:06Z. **Review:** CHANGES_REQUESTED --- I reviewed the loader-mapping change and its three new byte-preservation cases. The targeted tests are detailed, but the new padding path has an unbounded case that needs handling before merge. When `!congruent`, `differs` is now forced true and this reaches the byte-at-a-time loop below using `max(p_align, 0x1000)`. For a page-incongruent segment with a large power-of-two `p_align` (for example, 0x80000000), this can append nearly 2 GiB before the later fixed-base validation rejects the image; with the lazy path it can still produce a multi-gigabyte output. This is the same padding-before-rebase failure documented in open #10518, whose current proposed validation rejects non-power-of-two values but explicitly leaves large power-of-two alignments unresolved. The new trigger makes the padding path run for every page-incongruent segment, even if no lower segment shares its page. Please make this new path reject or otherwise bound unsupported alignment values before padding, and add a regression proving a large alignment fails promptly without allocating a huge output. If the intended protection is to rely on #10518 for non-power-of-two values, declare that merge dependency; it does not cover the large power-of-two case above. I also checked synchronization: the PR head is 37 commits behind current `main` (`check_main_sync.py --strict`), although the current-main commits since its merge base do not touch the two changed files and the merge preview is clean. Please sync the branch and rerun the focused relinker tests after the guard is addressed. Hosted relinker checks for this head are still pending; product jobs are skipped by path policy.
MarcZX10 commented 2026-10-28 22:06:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-28T22:06:54Z.

Review: APPROVED


Reviewing exact head 5890fc1820ffd074850a2ecf376ababb3a95e567.

What I ran

  • Inspected both commits, the Linux load-page production logic and regression cases, review discussion, and current hosted checks.
  • Confirmed current main has not changed the touched Linux patcher, load-page test, or debt files since the PR's clean merge of 88795ed448.
  • Hosted relinker checks pass on macOS arm64/x86_64, Linux, and Windows; ASan, conventions, labels, and eligibility pass.
  • I did not run a local build or tests.

Results

Check Result Evidence
Page-congruence and alignment logic Reviewed Exact current two-commit diff
Focused Linux relinker tests Pass, author-reported 18/18 on the synced head
Full relinker suite Pass with known failures, author-reported 307/310; two failures reproduced on main and one skipped
Large-alignment regression Pass, author-reported Red/green checks cover huge alignments, fixed-base rejection, bounded output and byte mapping
Hosted relinker platform matrix Pass macOS arm64/x86_64, Linux, Windows
Hosted ASan and policy checks Pass GitHub Actions
Local build and CTest Not run This review

Findings

Blocking

None.

Non-blocking

  • The move now appends at a page-congruent offset, carries the shared first-page bytes, and lowers the moved segment's p_align to the page bound. Fixed-base alignment is validated against each original input header before this normalization, preserving the prior accept/reject behavior. The regression suite covers mismatched offsets, shared pages, byte-for-byte mapped results, huge alignments, and fixed-base refusal.
  • The overlap workflow reports that #12307 edits nearby lines in LinuxLoadPageTests.cpp. Coordinate the merge order and retain both sets of regression cases.

Sources

Not verified

  • I did not execute the Linux relinker build or CTest locally; test results are from hosted checks and PR participants.

To get this to a good state

No blocking issue remains in the reviewed head. Retain the test coverage when resolving #12307's overlapping test edits.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5690327240 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11487#pullrequestreview-5690327240). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-28T22:06:54Z. **Review:** APPROVED --- Reviewing exact head `5890fc1820ffd074850a2ecf376ababb3a95e567`. ## What I ran - Inspected both commits, the Linux load-page production logic and regression cases, review discussion, and current hosted checks. - Confirmed current `main` has not changed the touched Linux patcher, load-page test, or debt files since the PR's clean merge of `88795ed448`. - Hosted relinker checks pass on macOS arm64/x86_64, Linux, and Windows; ASan, conventions, labels, and eligibility pass. - I did not run a local build or tests. ## Results | Check | Result | Evidence | |---|---|---| | Page-congruence and alignment logic | Reviewed | Exact current two-commit diff | | Focused Linux relinker tests | Pass, author-reported | 18/18 on the synced head | | Full relinker suite | Pass with known failures, author-reported | 307/310; two failures reproduced on main and one skipped | | Large-alignment regression | Pass, author-reported | Red/green checks cover huge alignments, fixed-base rejection, bounded output and byte mapping | | Hosted relinker platform matrix | Pass | macOS arm64/x86_64, Linux, Windows | | Hosted ASan and policy checks | Pass | GitHub Actions | | Local build and CTest | Not run | This review | ## Findings ### Blocking None. ### Non-blocking - The move now appends at a page-congruent offset, carries the shared first-page bytes, and lowers the moved segment's `p_align` to the page bound. Fixed-base alignment is validated against each original input header before this normalization, preserving the prior accept/reject behavior. The regression suite covers mismatched offsets, shared pages, byte-for-byte mapped results, huge alignments, and fixed-base refusal. - The overlap workflow reports that #12307 edits nearby lines in `LinuxLoadPageTests.cpp`. Coordinate the merge order and retain both sets of regression cases. ## Sources - [Repository relinker build and test rules](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/BUILD.md) - [Current pull request and red/green test report](https://github.com/boykopovar/AnyPS5/pull/11487) ## Not verified - I did not execute the Linux relinker build or CTest locally; test results are from hosted checks and PR participants. ## To get this to a good state No blocking issue remains in the reviewed head. Retain the test coverage when resolving #12307's overlapping test edits.
MarcZX10 commented 2026-10-30 16:21:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-30T16:21:19Z.

Review: APPROVED


Re-checked — new head, looks good

The updated head merges current main, retains the approved loader fix, and preserves the added regression cases.

What I ran

Re-checked head ffa036cbecc3516dcb0e3f2dcf7cc0b1065a4585 against PR base ed1e0ed08fc2452192df91793a33dd0cc7ad5212. The read-only preview onto current main 9304896d89f070f65b8f38bd3a8024d5c19f8fe1 merged cleanly (tree 5ef694b110e8da4508a6c842cb449a607f7b3619). The updated diff retains the six page-alignment cases and incorporates the upstream #12307 test additions. Environment: Linux x86_64, Python 3.11.2, GCC 12.2.0.

git diff --check ed1e0ed08fc2452192df91793a33dd0cc7ad5212...ffa036cbecc3516dcb0e3f2dcf7cc0b1065a4585
python3 tools/check_conventions.py --base ed1e0ed08fc2452192df91793a33dd0cc7ad5212 --head ffa036cbecc3516dcb0e3f2dcf7cc0b1065a4585
git merge-tree --write-tree refs/remotes/upstream/main refs/remotes/review/pr-11487

Results

Check Result
Diff check Passed
Conventions Passed
Current-main merge preview Clean
Unedited command output
All conventions checks passed.
5ef694b110e8da4508a6c842cb449a607f7b3619
git diff --check produced no output.

Negative control

I did not rerun the negative controls on this merge head. The author reports that the relinker tests and counter-checks passed on ffa036cbecc3516dcb0e3f2dcf7cc0b1065a4585; I did not independently reproduce them.

Not verified

I did not build or run CTest locally. At final refresh, the hosted conventions check was queued and eligibility and labels were in progress. I did not test Linux or macOS behavior.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5715280980 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11487#pullrequestreview-5715280980). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-30T16:21:19Z. **Review:** APPROVED --- # Re-checked — new head, looks good The updated head merges current main, retains the approved loader fix, and preserves the added regression cases. ## What I ran Re-checked head `ffa036cbecc3516dcb0e3f2dcf7cc0b1065a4585` against PR base `ed1e0ed08fc2452192df91793a33dd0cc7ad5212`. The read-only preview onto current main `9304896d89f070f65b8f38bd3a8024d5c19f8fe1` merged cleanly (tree `5ef694b110e8da4508a6c842cb449a607f7b3619`). The updated diff retains the six page-alignment cases and incorporates the upstream #12307 test additions. Environment: Linux x86_64, Python 3.11.2, GCC 12.2.0. ```sh git diff --check ed1e0ed08fc2452192df91793a33dd0cc7ad5212...ffa036cbecc3516dcb0e3f2dcf7cc0b1065a4585 python3 tools/check_conventions.py --base ed1e0ed08fc2452192df91793a33dd0cc7ad5212 --head ffa036cbecc3516dcb0e3f2dcf7cc0b1065a4585 git merge-tree --write-tree refs/remotes/upstream/main refs/remotes/review/pr-11487 ``` ## Results | Check | Result | | --- | --- | | Diff check | Passed | | Conventions | Passed | | Current-main merge preview | Clean | <details> <summary>Unedited command output</summary> ```text All conventions checks passed. 5ef694b110e8da4508a6c842cb449a607f7b3619 git diff --check produced no output. ``` </details> ## Negative control I did not rerun the negative controls on this merge head. The author reports that the relinker tests and counter-checks passed on `ffa036cbecc3516dcb0e3f2dcf7cc0b1065a4585`; I did not independently reproduce them. ## Not verified I did not build or run CTest locally. At final refresh, the hosted conventions check was queued and eligibility and labels were in progress. I did not test Linux or macOS behavior.
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!11487
No description provided.