fix(relinker): ignore empty guest load ranges in overlap checks #13818

Merged
Ninot1Quyi merged 1 commit from upstream-pr/13818 into main 2026-11-01 02:02:31 +00:00
Ninot1Quyi commented 2026-10-31 07:58:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Ninot1Quyi on 2026-10-31T07:58:23Z.


What

A guest PRX containing an empty PT_LOAD inside another load segment, or before a nonempty segment at the same address, currently fails with Overlapping load segments. The ELF program-header specification permits a zero p_memsz; that segment contributes no bytes to the memory-range overlap check.

Exclude empty memory ranges from the overlap index after validating their file bounds, sizes, flags and alignment. Keep the program headers intact for output writers. Windows output retains its existing explicit rejection of empty PT_LOAD segments.

Add parser regressions for empty segments before and after real segments, at starts, interiors and ends; malformed empty segments and actual nonempty overlaps still fail. A Linux conversion regression loads every generated guest module and calls its exported function on Linux x86-64.

The repository overlap checker scanned all 1,603 open PRs and exited 2 for shared-file conflicts. Each reported change was reviewed manually: #10518, #11628, #11661, #11689 and #11698 edit the adjacent alignment validation; #12495 and the seven base-conflicting CMake entries add other tests or targets. None implements empty-load exclusion; these are mechanical conflicts, not dependencies.

Tested

  • Linux x86-64, GCC 13.3.0, synthetic ELF/PRX fixtures; ANYPS5_RELINKER_ONLY=ON, Release, BUILD_TESTING=ON.
  • guest_load_ranges and guest_empty_loads: 2/2 passed. The parser test exercises 35 cases; all 12 converted guest modules load through the native ELF loader and return 42 from their exported function.
  • Negative control against main 828ac0b2ae: the final parser test fails eight valid empty-segment cases with Overlapping load segments; its all-empty case also reaches the old later diagnostic. The final conversion test exits 1 when the empty segment at 0x1080 is incorrectly rejected. Both tests compile/run against main; no implementation declarations need to be removed.
  • Full relinker-only CTest: 539/542 passed, 0 skipped. Three unchanged failures were reproduced separately with source files taken from the same main revision: pad_input fails when this environment rejects chown to nobody with EINVAL; file_writer_binary and file_writer_text report The previous executable did not start in their existing running-file replacement harness. Their implementation and tests are unchanged by this PR.
  • python3 tools/check_conventions.py --base origin/main: passed. git diff --check: passed.
  • No console or commercial title tested; native Windows/macOS execution was not tested.

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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5095750361 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13818). Originally posted by [Ninot1Quyi](https://github.com/Ninot1Quyi) on 2026-10-31T07:58:23Z. --- ### What A guest PRX containing an empty `PT_LOAD` inside another load segment, or before a nonempty segment at the same address, currently fails with `Overlapping load segments`. The [ELF program-header specification](https://gabi.xinuos.com/elf/07-pheader.html) permits a zero `p_memsz`; that segment contributes no bytes to the memory-range overlap check. Exclude empty memory ranges from the overlap index after validating their file bounds, sizes, flags and alignment. Keep the program headers intact for output writers. Windows output retains its existing explicit rejection of empty `PT_LOAD` segments. Add parser regressions for empty segments before and after real segments, at starts, interiors and ends; malformed empty segments and actual nonempty overlaps still fail. A Linux conversion regression loads every generated guest module and calls its exported function on Linux x86-64. The repository overlap checker scanned all 1,603 open PRs and exited 2 for shared-file conflicts. Each reported change was reviewed manually: #10518, #11628, #11661, #11689 and #11698 edit the adjacent alignment validation; #12495 and the seven base-conflicting CMake entries add other tests or targets. None implements empty-load exclusion; these are mechanical conflicts, not dependencies. ### Tested - Linux x86-64, GCC 13.3.0, synthetic ELF/PRX fixtures; `ANYPS5_RELINKER_ONLY=ON`, Release, `BUILD_TESTING=ON`. - `guest_load_ranges` and `guest_empty_loads`: 2/2 passed. The parser test exercises 35 cases; all 12 converted guest modules load through the native ELF loader and return 42 from their exported function. - Negative control against `main` `828ac0b2ae`: the final parser test fails eight valid empty-segment cases with `Overlapping load segments`; its all-empty case also reaches the old later diagnostic. The final conversion test exits 1 when the empty segment at `0x1080` is incorrectly rejected. Both tests compile/run against main; no implementation declarations need to be removed. - Full relinker-only CTest: 539/542 passed, 0 skipped. Three unchanged failures were reproduced separately with source files taken from the same main revision: `pad_input` fails when this environment rejects `chown` to `nobody` with `EINVAL`; `file_writer_binary` and `file_writer_text` report `The previous executable did not start` in their existing running-file replacement harness. Their implementation and tests are unchanged by this PR. - `python3 tools/check_conventions.py --base origin/main`: passed. `git diff --check`: passed. - No console or commercial title tested; native Windows/macOS execution was not 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. --> ### 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: none <!-- 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 -->
MarcZX10 commented 2026-10-31 08:07:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-31T08:07:26Z.

Review: APPROVED


Reviewed — looks good

The exact-head change excludes zero-sized load ranges only after validating them, and the added regressions cover malformed ranges, real overlaps, and Linux conversion.

What I ran

Reviewed head 134b6cf0be5d9060f3958780f5e80c295b88afbe against PR base 828ac0b2ae74aac181ba128fb59b08a1534f2041; current main is e8c25dd3baa6e78531d5eee067fec5cbe8af3dcf, and the merge preview is clean. The relevant parser, CMake, fixture, and test paths have not changed between the PR base and current main. Environment: Debian 12 x86_64, Python 3.11.2, GCC 12.2.0. I did not build or run C++ tests locally.

python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 13818
python3 -m py_compile /tmp/pr13818-test_guest_empty_loads.py
git diff --name-only 828ac0b2ae74aac181ba128fb59b08a1534f2041 e8c25dd3baa6e78531d5eee067fec5cbe8af3dcf -- core/relinker/CMakeLists.txt core/relinker/relinker/src/guest/GuestImageReader.cpp core/relinker/relinker/tests/GuestLoadRangesTests.cpp core/relinker/relinker/tests/ElfFixture.hpp core/relinker/relinker/tests/test_guest_empty_loads.py core/relinker/relinker/tests/test_guest_intel_trampolines.py core/relinker/relinker/tests/test_guest_module_directories.py

Results

Check Result
Diff and conventions Passed on the exact head
Python syntax Passed on the exact-head regression script
Test registration The precheck passed; CMake explicitly registers guest_load_ranges and guest_empty_loads
Current-main freshness Current main advanced from the PR base, but none of the affected parser, CMake, fixture, or test paths changed
Main merge preview Clean against current main
Author-reported tests 2/2 focused tests passed; full relinker suite 539/542, with three unchanged failures reportedly reproduced from main
Author-reported negative control The new parser test reportedly fails on main for eight valid empty-segment cases; the conversion regression also reportedly fails on main
Hosted CI Relinker Ubuntu and ASan passed; Windows was in progress and macOS jobs queued at the latest check. Product Linux/Windows and specialized jobs were skipped
Local C++ build/tests Not run
Unedited precheck output
All conventions checks passed.
231 test script(s), each run by an add_test or a workflow
/usr/bin/python3: can't open file '/tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-13818-134b6cf0be5d/head-134b6cf0be5d-a56107b1/tools/pr_test_quality.py': [Errno 2] No such file or directory

Negative control

Assertion Change tested Result
Valid zero-sized PT_LOAD ranges are accepted, and conversion loads Author ran the new tests against base 828ac0b2ae74aac181ba128fb59b08a1534f2041 Author reports both regressions failed on base as intended; not independently reproduced

Sources

Not verified

I did not independently reproduce the C++ or conversion tests. The author-reported full-suite run and negative control are not local results; Windows and macOS relinker jobs were not complete at review time.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5721927461 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13818#pullrequestreview-5721927461). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-31T08:07:26Z. **Review:** APPROVED --- # Reviewed — looks good The exact-head change excludes zero-sized load ranges only after validating them, and the added regressions cover malformed ranges, real overlaps, and Linux conversion. ## What I ran Reviewed head `134b6cf0be5d9060f3958780f5e80c295b88afbe` against PR base `828ac0b2ae74aac181ba128fb59b08a1534f2041`; current `main` is `e8c25dd3baa6e78531d5eee067fec5cbe8af3dcf`, and the merge preview is clean. The relevant parser, CMake, fixture, and test paths have not changed between the PR base and current `main`. Environment: Debian 12 x86_64, Python 3.11.2, GCC 12.2.0. I did not build or run C++ tests locally. ```sh python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 13818 python3 -m py_compile /tmp/pr13818-test_guest_empty_loads.py git diff --name-only 828ac0b2ae74aac181ba128fb59b08a1534f2041 e8c25dd3baa6e78531d5eee067fec5cbe8af3dcf -- core/relinker/CMakeLists.txt core/relinker/relinker/src/guest/GuestImageReader.cpp core/relinker/relinker/tests/GuestLoadRangesTests.cpp core/relinker/relinker/tests/ElfFixture.hpp core/relinker/relinker/tests/test_guest_empty_loads.py core/relinker/relinker/tests/test_guest_intel_trampolines.py core/relinker/relinker/tests/test_guest_module_directories.py ``` ## Results | Check | Result | |---|---| | Diff and conventions | Passed on the exact head | | Python syntax | Passed on the exact-head regression script | | Test registration | The precheck passed; CMake explicitly registers `guest_load_ranges` and `guest_empty_loads` | | Current-main freshness | Current main advanced from the PR base, but none of the affected parser, CMake, fixture, or test paths changed | | Main merge preview | Clean against current main | | Author-reported tests | 2/2 focused tests passed; full relinker suite 539/542, with three unchanged failures reportedly reproduced from main | | Author-reported negative control | The new parser test reportedly fails on main for eight valid empty-segment cases; the conversion regression also reportedly fails on main | | Hosted CI | Relinker Ubuntu and ASan passed; Windows was in progress and macOS jobs queued at the latest check. Product Linux/Windows and specialized jobs were skipped | | Local C++ build/tests | Not run | <details><summary>Unedited precheck output</summary> ```text All conventions checks passed. ``` ```text 231 test script(s), each run by an add_test or a workflow ``` ```text /usr/bin/python3: can't open file '/tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-13818-134b6cf0be5d/head-134b6cf0be5d-a56107b1/tools/pr_test_quality.py': [Errno 2] No such file or directory ``` </details> ## Negative control | Assertion | Change tested | Result | |---|---|---| | Valid zero-sized `PT_LOAD` ranges are accepted, and conversion loads | Author ran the new tests against base `828ac0b2ae74aac181ba128fb59b08a1534f2041` | Author reports both regressions failed on base as intended; not independently reproduced | ## Sources - [Zero-sized range validation and skip at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/134b6cf0be5d9060f3958780f5e80c295b88afbe/core/relinker/relinker/src/guest/GuestImageReader.cpp#L43-L53) - [Malformed-range and overlap regressions at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/134b6cf0be5d9060f3958780f5e80c295b88afbe/core/relinker/relinker/tests/GuestLoadRangesTests.cpp#L47-L95) - [CMake registration at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/134b6cf0be5d9060f3958780f5e80c295b88afbe/core/relinker/CMakeLists.txt#L97-L101) - [Current main revision used for freshness comparison](https://github.com/boykopovar/AnyPS5/commit/e8c25dd3baa6e78531d5eee067fec5cbe8af3dcf) ## Not verified I did not independently reproduce the C++ or conversion tests. The author-reported full-suite run and negative control are not local results; Windows and macOS relinker jobs were not complete at review time.
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!13818
No description provided.