fix(tools): handle zero-size segments in unbacked PT_LOAD ranges in unwrap_self #8543

Merged
tkcm01 merged 1 commit from upstream-pr/8543 into main 2026-10-21 04:31:54 +00:00
tkcm01 commented 2026-10-20 16:01:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by tkcm01 on 2026-10-20T16:01:15Z.


What

Treat zero-size non-PT_LOAD segments (such as pure-.tbss PT_TLS segments with p_filesz == 0) that fall inside a file-empty PT_LOAD segment (p_filesz == 0) or in the unbacked .bss tail (offset > host["size"]) as having no file backing (source = 0), instead of adding their virtual offset to the host segment's file offset and failing bounds checks or emitting a stale p_offset.

Tested

macOS (ctest --test-dir build-relinker -R unwrap_self --output-on-failure).

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:4938600588 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8543). Originally posted by [tkcm01](https://github.com/tkcm01) on 2026-10-20T16:01:15Z. --- ### What Treat zero-size non-`PT_LOAD` segments (such as pure-`.tbss` `PT_TLS` segments with `p_filesz == 0`) that fall inside a file-empty `PT_LOAD` segment (`p_filesz == 0`) or in the unbacked `.bss` tail (`offset > host["size"]`) as having no file backing (`source = 0`), instead of adding their virtual offset to the host segment's file offset and failing bounds checks or emitting a stale `p_offset`. ### Tested macOS (`ctest --test-dir build-relinker -R unwrap_self --output-on-failure`). ### 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] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
xXPBSXx commented 2026-10-20 22:35:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-20T22:35:07Z.


Windows data point for 7679fbd657: Windows 10.0.19045, Python 3.12.10, python -I -m unittest discover -s tools/tests -p test_unwrap_self.py, PR head checked out (not merged onto main).

  • With the PR: 30 tests, OK.
  • Same tree with tools/unwrap_self.py restored to main (new test kept): 30 tests, 10 failures, all sub-cases of test_zero_size_segment_in_unbacked_load_range_is_accepted (segment 3/4 does not fit the file and a wrong source offset).
    Not tested: other platforms, a merge onto current main.
    AI-assisted (Claude Code).
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6303298076 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8543#issuecomment-6303298076). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-20T22:35:07Z. --- Windows data point for `7679fbd657`: Windows 10.0.19045, Python 3.12.10, `python -I -m unittest discover -s tools/tests -p test_unwrap_self.py`, PR head checked out (not merged onto `main`). - With the PR: 30 tests, OK. - Same tree with `tools/unwrap_self.py` restored to `main` (new test kept): 30 tests, 10 failures, all sub-cases of `test_zero_size_segment_in_unbacked_load_range_is_accepted` (`segment 3/4 does not fit the file` and a wrong source offset). Not tested: other platforms, a merge onto current `main`. AI-assisted (Claude Code).
xXPBSXx commented 2026-10-21 03:11:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-21T03:11:54Z.


Linux data point for 7679fbd657 (WSL2, Ubuntu 24.04, kernel 6.18 - a virtualised kernel, not bare-metal Linux; Python 3.12.3), this head merged onto main 5d10ea9ea (clean merge), python3 -I tools/tests/test_unwrap_self.py:

  • With the PR: 30 tests OK.
  • Without it (the PR's test_unwrap_self.py on top of main without the PR's source change): FAILED (10 failures).
    Not tested: macOS, Windows (Windows data from another run is not part of this comment).

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6307086710 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8543#issuecomment-6307086710). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-21T03:11:54Z. --- Linux data point for `7679fbd657` (WSL2, Ubuntu 24.04, kernel 6.18 - a virtualised kernel, not bare-metal Linux; Python 3.12.3), this head merged onto `main` `5d10ea9ea` (clean merge), `python3 -I tools/tests/test_unwrap_self.py`: - With the PR: 30 tests OK. - Without it (the PR's `test_unwrap_self.py` on top of `main` without the PR's source change): FAILED (10 failures). Not tested: macOS, Windows (Windows data from another run is not part of this comment). AI-assisted (Claude Code).
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!8543
No description provided.