Skip to content

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

Merged
adriadam10 merged 2 commits into
boykopovar:mainfrom
jweidenh:codex/fix-linux-program-header-count
Oct 10, 2026
Merged

adriadam10 merged 2 commits into
boykopovar:mainfrom
jweidenh:codex/fix-linux-program-header-count

Conversation

@jweidenh

@jweidenh jweidenh commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

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 fix(relinker): reject truncated EH frame headers #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

@Dextroid17 Dextroid17 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 10, 2026
@jweidenh
jweidenh force-pushed the codex/fix-linux-program-header-count branch from b25c767 to c95101f Compare October 10, 2026 01:36
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 10, 2026
@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 10, 2026
@oneandonlydean

Copy link
Copy Markdown
Collaborator

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.

@jweidenh
jweidenh force-pushed the codex/fix-linux-program-header-count branch from c95101f to c8a23b1 Compare October 10, 2026 05:41
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 10, 2026
@adriadam10

Copy link
Copy Markdown
Collaborator

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.

@adriadam10
adriadam10 merged commit 8f693fc into boykopovar:main Oct 10, 2026
10 checks passed
SleglJan pushed a commit to SleglJan/AnyPS5 that referenced this pull request Oct 10, 2026
…ram-header-count

fix(relinker): count all synthetic Linux program headers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants