fix(tools): preserve contained segment alignment when unwrapping SELF #10923
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10923"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by 1whythef2 on 2026-10-25T10:23:11Z.
What
SELF unwrapping can emit a contained segment with
p_offset % p_align != p_vaddr % p_alignwhen that segment requires stronger alignment than its containing output region. For example, aPT_LOADat virtual address0x4000with alignment0x100is placed at file offset0x400; itsPT_TLSat0x4040, requiring alignment0x1000, is then placed at0x440instead of an offset congruent to0x40.Combine the alignment constraints of every header assigned to an output region before placing that region. Keep each header's declared alignment, payload and offset relative to its containing region. Refuse incompatible constraints before staging output, and count any additional padding against the existing limit. Sort the regions before constraint collection and keep that order through header emission, so both phases choose the same region for recorded segments inside overlapping loads. Inferred segments retain their explicit load host.
This follows the ELF program-header alignment rule. No title compatibility or performance improvement is claimed.
Tested
python -m unittest discover -s tools/tests -p test_unwrap_self.py: 61 tests, 57 passed and 4 skipped for platform or symlink availability. The run used a writable temporary directory and allowed the existing hardlink test.python tools/check_conventions.py --base origin/main: passed.git diff --check origin/main HEAD: passed.python tools/pr_overlap.py --repo boykopovar/AnyPS5 --branch fix/unwrap-contained-segment-alignment: completed, with no confirmed conflicts. It listed nine uncompleted comparisons because those PRs conflict withmain: #6612, #9508, #9588, #9881, #10113, #10226, #10324, #10487 and #10513. Manually checked both shared files in all nine PR heads against the checkedmain: their blob IDs are identical tomain, so none contains this alignment change.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T10:29:50Z.
Review: COMMENTED
Reviewed exact head
d5635e5728769f18a19166db249dd29864133ed4.I ran
python3 -m unittest discover -s tools/tests -p test_unwrap_self.pyfrom a complete archive of that exact head: 59 tests passed, 1 platform-dependent test skipped.git diff --check upstream/main...upstream/pr-10923andpython3 tools/check_conventions.py --base upstream/main --head upstream/pr-10923also pass. Hosted conventions, intake, and labels checks pass; the product build checks are not present on this tools-only path.The new placement rule uses one shared region resolver for constraint collection and final header emission, retains each segment's own
p_align, and refuses incompatible congruences before creating the output. I additionally exercised a containedPT_TLSat offset/address residue0x40, and a region containingPT_DYNAMIC/PT_TLSconstraints with residues0x40and0x80; both emitted headers satisfyp_offset % p_align == p_vaddr % p_align. The overlap checker could not compare #9826/#9827 because they conflict withmain, but I inspected both heads: their changed files are exclusively undercore/libs/...; neither changestools/unwrap_self.pyor its tests.I found no blocking issue in this diff. These results cover the focused Python tool and synthetic fixtures only; I did not run an AnyPS5 product build or test a real SELF/title.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T10:29:58Z.
Review: COMMENTED
Reviewed exact head
d5635e5728769f18a19166db249dd29864133ed4.I ran
python3 -m unittest discover -s tools/tests -p test_unwrap_self.pyfrom a complete archive of that exact head: 59 tests passed, 1 platform-dependent test skipped.git diff --check upstream/main...upstream/pr-10923andpython3 tools/check_conventions.py --base upstream/main --head upstream/pr-10923also pass. Hosted conventions, intake, and labels checks pass; the product build checks are not present on this tools-only path.The new placement rule uses one shared region resolver for constraint collection and final header emission, retains each segment's own
p_align, and refuses incompatible congruences before creating the output. I additionally exercised a containedPT_TLSat offset/address residue0x40, and a region containingPT_DYNAMIC/PT_TLSconstraints with residues0x40and0x80; both emitted headers satisfyp_offset % p_align == p_vaddr % p_align. The overlap checker could not compare #9826/#9827 because they conflict withmain, but I inspected both heads: their changed files are exclusively undercore/libs/...; neither changestools/unwrap_self.pyor its tests.I found no blocking issue in this diff. These results cover the focused Python tool and synthetic fixtures only; I did not run an AnyPS5 product build or test a real SELF/title.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T10:30:17Z.
Review: COMMENTED
No blocking findings after focused review; #10923 is an isolated tools-only change, so the PR should be mergeable independently.
Imported from boykopovar/AnyPS5. Originally posted by roboterspinne on 2026-10-25T11:32:23Z.
Review: COMMENTED
Reviewed head
d5635e572merged ontoupstream/main63a863d3b0, which is its base; the merge is clean.Environment: Windows 11 Home 10.0.26200, Python 3.13.9, TEMP on a path without the 8.3 short name.
Results
python -m unittest discover -s tools/tests -p test_unwrap_self.pyon the merged tree: 59 tests, OK, with 4 skipped. Three of those are POSIX-only, and the symlink test needs a privilege on Windows.main'sunwrap_self.pyunder this test file, 13 subtests fail:test_contained_segments_keep_stronger_alignment_than_their_load, which encodes the 0x4000/0x4040 example from the description;test_contained_alignment_obeys_the_padding_limit;PT_TLS/PT_DYNAMIC, recorded or inferred, with random power-of-two alignments. I kept only inputs whose headers are all congruent: 1,684 inputs over two seeds. This branch writes congruent output with the payload intact for all of them, whilemainmisplaces 63. So the change does what it says for the cases these generators reach. They did not produce the two overlapping-load shapes from the inline comment.output_regionwithregion_forat line 285 still passes all 59 tests. This inferred input catches it: It uses no records and the payload at 0x1000.mainwrites the TLS at 0x590 (misaligned), and this branch writes it at 0x1090 (correct).check_conventions.py --base upstream/mainpasses with this title and body. Since you are a first-time contributor, the hosted relinker jobs were skipped; this file's tests are plain Python and don't need them.Not checked: whether real PS5 SELF files have overlapping recorded loads of either shape above; Linux and macOS; Python 3.12, the version you ran.
The approach is right and fixes the single-load case it targets. I would settle the region choice for overlapping loads before merge, since one shape now refuses a container
mainhandled. For disclosure: I have open relinker PRs and #10667 ontools/tests/test_suggest_patches.py; none touchestools/unwrap_self.pyor its tests.Written with AI assistance (Claude Code). I ran the tests, the counter-check, the property check and the inputs above on my Windows 11 machine.
Imported from boykopovar/AnyPS5. Originally posted by THEMANnt on 2026-10-25T12:11:00Z.
Review: COMMENTED
Reviewed head
2a45d721f62d99c660694c446fec7239daf4919e. No actionable finding in this focused SELF layout review. Upstream Build authorization is still pending, so this is a comment rather than an approval.The new alignment pass uses the same output-region selection as the final header rewrite. It combines compatible power-of-two alignment constraints, rejects incompatible residues before publication, and preserves the existing output-padding limit. The added synthetic containers cover stronger TLS/dynamic alignment, empty contained segments, both header orders, and recorded/inferred overlapping source regions, while checking payload bytes and input preservation.
Validation: Windows/Python 3.11.9:
tools/tests/test_unwrap_self.py -vruns 61 tests: 57 passed, 4 skipped. Baseline has 51 passed, 4 skipped. New tests against baseline production produce 15 expected assertion failures exposing alignment/layout defects. Conventions, whitespace and script registration pass. The latest Conventions rerun succeeds; Build 40190220485 remainsaction_required.Next step: authorize and complete the upstream Build. Synthetic conversion tests do not establish commercial-title or console compatibility.
Imported from boykopovar/AnyPS5. Originally posted by roboterspinne on 2026-10-25T12:56:14Z.
Review: APPROVED
@1whythef2 Thanks, checked
2a45d721fmerged ontoupstream/maina5a780eaa(2026-10-25); the merge is clean. Windows 11, Python 3.13.9.test_unwrap_self.py: 61 tests, OK, with the same 4 skipped as before.Counter-check against the new tests:
unwrap_self.pyfails both subtests oftest_recorded_overlaps_use_the_same_region_for_constraints_and_output.main, 15 subtests fail: the 13 from my review, the second recorded-overlap input andtest_inferred_overlaps_apply_stronger_alignment_to_the_host. The first recorded-overlap input passes there, sincemainconverted it correctly.Mutants against the new tests:
regions.sortfails the recorded-overlap test.region_forin the constraint loop fails both new tests.So the sort position and the host choice are both pinned now.
The random congruent containers from my review, 1,684 over two seeds, still all come out congruent with their payload intact.
check_conventions.py --base upstream/mainpasses with the updated description, andgit diff --checkis clean.That settles the point from my review; I found nothing else to change.
Written with AI assistance (Claude Code). I ran the checks above on my Windows 11 machine.