fix(relinker): count all synthetic Linux program headers #2274

Merged
jweidenh merged 2 commits from upstream-pr/2274 into main 2026-10-10 06:32:53 +00:00
jweidenh commented 2026-10-09 14:13:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jweidenh on 2026-10-09T14:13:08Z.


What

Linux conversion writes five synthetic program headers but budgets for four. With one retained load and five input slots, the relinker reports success while overwriting 56 bytes immediately after the input header table. With enough slots, PT_PHDR and the header load still describe a table one entry too short.

Count all five synthetic headers, retain PT_GNU_EH_FRAME when it fits exactly, and keep capacity arithmetic wide enough to reject an unrepresentable output count. Extend the existing regression for full header coverage, exact-fit retention, frame removal, adjacent-byte preservation, insufficient capacity, and a count above uint16. Adjust synthetic fixtures that depended on the undercount; the registry fixture also starts its executable load at its code instead of scanning ELF metadata as instructions.

Rebased onto main c9da0f93 after #1559 merged. Preserve its vector-based layout, PHDR/INTERP placement and sorted load headers; retain all five synthetic headers, exact-fit EH-frame retention, and wide capacity arithmetic before narrowing the result.

Rebased again onto main 691c0c3b after #2256 merged. Retain its unchanged header_bounds(...) helper and invocation before this PR's capacity-test loop; both truncated-header and header-capacity coverage remain enabled.

Tested

Current head c8a23b1a, based on main 691c0c3b:

  • Native Linux x86-64 Release relinker build and all 60 CTest groups passed on a locally managed self-hosted runner, zero failures or skips. linux_eh_frame_header (including #2256 bounds cases) passed in 0.102 s; linux_program_header_order passed in 0.026 s.
  • Local macOS arm64 relinker build and all 53 CTest groups passed, zero failures or skips, in 1.79 s total.
  • Test registration, conventions and git diff --check passed. Tests retain the 30-second timeout. Private validation run 38028298449 pins the exact source commit c8a23b1ad5daa1127b589324538491afde0e7f83; its logs are not publicly accessible.

Earlier rebase validation at c95101f5, based on main c9da0f93:

  • Native Linux x86-64 Release relinker build, test-registration check and all 56 CTest groups passed on a locally managed self-hosted runner, with zero failures or skips. This includes both linux_eh_frame_header and upstream linux_program_header_order, plus native execution tests; timeout remains 30 seconds.
  • Local macOS arm64 relinker rebuild and all 49 CTest groups passed, with zero failures or skips, using the existing AppleClang/Python 3.12 toolchain.
  • Independent conflict-resolution review, conventions and git diff --check passed. The private Linux workflow pins this exact reviewed source commit.

Earlier validation before the rebase:

macOS arm64, AppleClang 21, CMake 4.4.4, Ninja 1.13.2, Python 3.12.14. Relinker-only Release build with BUILD_TESTING=ON:

  • All 38 registered CTest groups passed.
  • The new regression fails on the original main binary because PT_PHDR covers 336 bytes for seven 56-byte headers.
  • A separate five-slot reproducer returns success and overwrites all 56 marker bytes on main. The fixed binary exits 2 with the required/available counts and creates no executable.
  • Test registration check: all six built test executables are registered.
  • Conventions checker against origin/main and git diff --check passed.
  • Independent code review completed with no blockers.

Ubuntu 24.04 x86-64, GCC 13.3.0, CMake 3.28.3, Ninja 1.11.1, Python 3.12.3 on a locally managed self-hosted runner, head b25c767b:

  • All 43 registered CTest groups passed, including to_intel_linux_stubs and guest_intel_trampolines_execution, in 15.69 seconds total.
  • The first Linux run exposed two native-only consumers of ElfFixture.hpp that also needed the corrected header capacity; the shared fixture now reserves four spare slots. Both conversion and x86-64 trampoline execution pass.
  • Test registration verification passed. The private validation workflow fetches this exact reviewed commit and uses only self-hosted Linux x64 runners; its logs are not publicly accessible.

No game, system-library runtime, GPU or Windows-native execution was tested for this relinker change. The Apple Python 3.9 baseline has an unrelated private-subprocess-API test failure; Python 3.12 passes the unchanged baseline and this contribution. Upstream full CI still requires a maintainer's manual Build workflow dispatch under the repository's contribution policy.

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; no silent stubs added
  • No notes, investigation files or images added to the repository
  • New third-party code is a submodule built from source; none added
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes, Codex
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4801613157 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2274). Originally posted by [jweidenh](https://github.com/jweidenh) on 2026-10-09T14:13:08Z. --- ### What Linux conversion writes five synthetic program headers but budgets for four. With one retained load and five input slots, the relinker reports success while overwriting 56 bytes immediately after the input header table. With enough slots, PT_PHDR and the header load still describe a table one entry too short. Count all five synthetic headers, retain PT_GNU_EH_FRAME when it fits exactly, and keep capacity arithmetic wide enough to reject an unrepresentable output count. Extend the existing regression for full header coverage, exact-fit retention, frame removal, adjacent-byte preservation, insufficient capacity, and a count above uint16. Adjust synthetic fixtures that depended on the undercount; the registry fixture also starts its executable load at its code instead of scanning ELF metadata as instructions. Rebased onto `main` `c9da0f93` after #1559 merged. Preserve its vector-based layout, PHDR/INTERP placement and sorted load headers; retain all five synthetic headers, exact-fit EH-frame retention, and wide capacity arithmetic before narrowing the result. Rebased again onto `main` `691c0c3b` after #2256 merged. Retain its unchanged `header_bounds(...)` helper and invocation before this PR's capacity-test loop; both truncated-header and header-capacity coverage remain enabled. ### Tested Current head `c8a23b1a`, based on `main` `691c0c3b`: - Native Linux x86-64 Release relinker build and all **60 CTest groups** passed on a locally managed self-hosted runner, zero failures or skips. `linux_eh_frame_header` (including #2256 bounds cases) passed in 0.102 s; `linux_program_header_order` passed in 0.026 s. - Local macOS arm64 relinker build and all **53 CTest groups** passed, zero failures or skips, in 1.79 s total. - Test registration, conventions and `git diff --check` passed. Tests retain the 30-second timeout. Private validation run `38028298449` pins the exact source commit `c8a23b1ad5daa1127b589324538491afde0e7f83`; its logs are not publicly accessible. Earlier rebase validation at `c95101f5`, based on `main` `c9da0f93`: - Native Linux x86-64 Release relinker build, test-registration check and all **56 CTest groups** passed on a locally managed self-hosted runner, with zero failures or skips. This includes both `linux_eh_frame_header` and upstream `linux_program_header_order`, plus native execution tests; timeout remains 30 seconds. - Local macOS arm64 relinker rebuild and all **49 CTest groups** passed, with zero failures or skips, using the existing AppleClang/Python 3.12 toolchain. - Independent conflict-resolution review, conventions and `git diff --check` passed. The private Linux workflow pins this exact reviewed source commit. Earlier validation before the rebase: macOS arm64, AppleClang 21, CMake 4.4.4, Ninja 1.13.2, Python 3.12.14. Relinker-only Release build with BUILD_TESTING=ON: - All 38 registered CTest groups passed. - The new regression fails on the original main binary because PT_PHDR covers 336 bytes for seven 56-byte headers. - A separate five-slot reproducer returns success and overwrites all 56 marker bytes on main. The fixed binary exits 2 with the required/available counts and creates no executable. - Test registration check: all six built test executables are registered. - Conventions checker against origin/main and git diff --check passed. - Independent code review completed with no blockers. Ubuntu 24.04 x86-64, GCC 13.3.0, CMake 3.28.3, Ninja 1.11.1, Python 3.12.3 on a locally managed self-hosted runner, head `b25c767b`: - All 43 registered CTest groups passed, including `to_intel_linux_stubs` and `guest_intel_trampolines_execution`, in 15.69 seconds total. - The first Linux run exposed two native-only consumers of `ElfFixture.hpp` that also needed the corrected header capacity; the shared fixture now reserves four spare slots. Both conversion and x86-64 trampoline execution pass. - Test registration verification passed. The private validation workflow fetches this exact reviewed commit and uses only self-hosted Linux x64 runners; its logs are not publicly accessible. No game, system-library runtime, GPU or Windows-native execution was tested for this relinker change. The Apple Python 3.9 baseline has an unrelated private-subprocess-API test failure; Python 3.12 passes the unchanged baseline and this contribution. Upstream full CI still requires a maintainer's manual Build workflow dispatch under the repository's contribution policy. ### Checklist - [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 - [x] Unimplemented paths throw; no silent stubs added - [x] No notes, investigation files or images added to the repository - [x] New third-party code is a submodule built from source; none added - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes, Codex
Dextroid17 commented 2026-10-09 14:49:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-09T14:49:00Z.

Review: COMMENTED


Verified on Linux — the platform the description says was not exercised (it lists macOS arm64 only, and no hosted CI). This is where the missing half is.

  • base d70b8998 (upstream/main) + head 5bf4c32b, merged clean.

  • Arm A (PR head): linux_eh_frame_header, linux_load_alignment, dynamic_segment, call_registry — 4/4 pass; amd64_only_converter passes. I removed and rebuilt the converter test binary first, because a --target relinker build alone leaves that binary stale and its pass would have meant nothing.

  • Arm B (only ProgramHeaderLayoutBuilder.cpp + ElfConstants.hpp reverted to main, all tests kept): linux_eh_frame_header fails, with exactly the symptom in the description —

    AssertionError: ('PT_PHDR must cover every output header', (6, 4, 64, 16448, 16448, 336, 336, 8), 7)

    i.e. PT_PHDR covers 336 bytes for seven 56-byte headers (392 expected). call_registry passes, so this test is the one that bites.

  • Independent of the test harness, read straight out of a real conversion (/bin/true, which yields 15 output program headers):

    PT_PHDR p_filesz table (phnum x phentsize = 15 x 56 = 840 B)
    main 0x310 = 784 B short by exactly one 56-byte entry
    PR 0x348 = 840 B exact

    So the "five synthetic headers, budget of four" defect is visible in the produced file, not only through a test assertion — 784 vs 840, one header's worth.

Overlap claims, checked rather than taken on trust: #1943's diff mentions kSyntheticProgramHeaderCount and keepFrames zero times, so "leaves this count defect out of scope" holds. #1559 does rewrite this region (keptCount -> kept.size()) but keeps < and does not raise the count to 5, so it is ordering-only as described. Worth noting for whoever merges: #1559 and this PR now edit the same lines of ProgramHeaderLayoutBuilder.cpp, so the second to land will need a rebase — not a defect here, just sequencing.

What I could not verify: a Windows host; the exact-fit PT_GNU_EH_FRAME retention half in isolation, because on main the count assertion above fires before that case is reached (it is exercised on the PR, where the suite is green); and no game or system-library runtime, as the description also states.

This is a relinker fix, so it carries no named-title bar — it is provable against the output it produces, which is what the numbers above do.

Written with AI assistance.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5471640903 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2274#pullrequestreview-5471640903). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-09T14:49:00Z. **Review:** COMMENTED --- Verified on **Linux** — the platform the description says was not exercised (it lists macOS arm64 only, and no hosted CI). This is where the missing half is. - base `d70b8998` (upstream/main) + head `5bf4c32b`, merged clean. - **Arm A (PR head):** `linux_eh_frame_header`, `linux_load_alignment`, `dynamic_segment`, `call_registry` — **4/4 pass**; `amd64_only_converter` passes. I removed and rebuilt the converter test binary first, because a `--target relinker` build alone leaves that binary stale and its pass would have meant nothing. - **Arm B (only `ProgramHeaderLayoutBuilder.cpp` + `ElfConstants.hpp` reverted to `main`, all tests kept):** `linux_eh_frame_header` **fails**, with exactly the symptom in the description — `AssertionError: ('PT_PHDR must cover every output header', (6, 4, 64, 16448, 16448, 336, 336, 8), 7)` i.e. PT_PHDR covers **336** bytes for **seven** 56-byte headers (392 expected). `call_registry` passes, so this test is the one that bites. - **Independent of the test harness**, read straight out of a real conversion (`/bin/true`, which yields 15 output program headers): | | PT_PHDR `p_filesz` | table (`phnum x phentsize` = 15 x 56 = 840 B) | |---|---|---| | `main` | `0x310` = **784 B** | short by **exactly one 56-byte entry** | | PR | `0x348` = **840 B** | exact | So the "five synthetic headers, budget of four" defect is visible in the produced file, not only through a test assertion — 784 vs 840, one header's worth. **Overlap claims, checked rather than taken on trust:** `#1943`'s diff mentions `kSyntheticProgramHeaderCount` and `keepFrames` **zero** times, so "leaves this count defect out of scope" holds. `#1559` does rewrite this region (`keptCount` -> `kept.size()`) but keeps `<` and does not raise the count to 5, so it is ordering-only as described. Worth noting for whoever merges: `#1559` and this PR now edit the same lines of `ProgramHeaderLayoutBuilder.cpp`, so the second to land will need a rebase — not a defect here, just sequencing. What I could **not** verify: a Windows host; the exact-fit `PT_GNU_EH_FRAME` retention half in isolation, because on `main` the count assertion above fires before that case is reached (it is exercised on the PR, where the suite is green); and no game or system-library runtime, as the description also states. This is a relinker fix, so it carries no named-title bar — it is provable against the output it produces, which is what the numbers above do. Written with AI assistance.
oneandonlydean commented 2026-10-10 05:18:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-10T05:18:22Z.


test_linux_eh_frame_header.py conflicts with main again now that #2256 is in; please rebase and keep its header_bounds(...) check, as you described.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6094141425 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2274#issuecomment-6094141425). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-10T05:18:22Z. --- `test_linux_eh_frame_header.py` conflicts with main again now that #2256 is in; please rebase and keep its `header_bounds(...)` check, as you described.
adriadam10 commented 2026-10-10 06:32:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T06:32:50Z.


Checked on current main: merges cleanly, header_bounds(...) from #2256 is kept in test_linux_eh_frame_header.py; relinker build and ctest (linux_eh_frame_header, linux_program_header_order, linux_load_alignment, dynamic_segment, call_registry, amd64_only_converter) pass, and linux_eh_frame_header fails without the fix. Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6094686808 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2274#issuecomment-6094686808). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T06:32:50Z. --- Checked on current `main`: merges cleanly, `header_bounds(...)` from #2256 is kept in `test_linux_eh_frame_header.py`; relinker build and ctest (`linux_eh_frame_header`, `linux_program_header_order`, `linux_load_alignment`, `dynamic_segment`, `call_registry`, `amd64_only_converter`) pass, and `linux_eh_frame_header` fails without the fix. Merging.
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!2274
No description provided.