fix(relinker): count all synthetic Linux program headers #2274
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2274"
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 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
mainc9da0f93after #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
main691c0c3bafter #2256 merged. Retain its unchangedheader_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 onmain691c0c3b:linux_eh_frame_header(including #2256 bounds cases) passed in 0.102 s;linux_program_header_orderpassed in 0.026 s.git diff --checkpassed. Tests retain the 30-second timeout. Private validation run38028298449pins the exact source commitc8a23b1ad5daa1127b589324538491afde0e7f83; its logs are not publicly accessible.Earlier rebase validation at
c95101f5, based onmainc9da0f93:linux_eh_frame_headerand upstreamlinux_program_header_order, plus native execution tests; timeout remains 30 seconds.git diff --checkpassed. 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:
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:to_intel_linux_stubsandguest_intel_trampolines_execution, in 15.69 seconds total.ElfFixture.hppthat also needed the corrected header capacity; the shared fixture now reserves four spare slots. Both conversion and x86-64 trampoline execution pass.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
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) + head5bf4c32b, merged clean.Arm A (PR head):
linux_eh_frame_header,linux_load_alignment,dynamic_segment,call_registry— 4/4 pass;amd64_only_converterpasses. I removed and rebuilt the converter test binary first, because a--target relinkerbuild alone leaves that binary stale and its pass would have meant nothing.Arm B (only
ProgramHeaderLayoutBuilder.cpp+ElfConstants.hppreverted tomain, all tests kept):linux_eh_frame_headerfails, 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_registrypasses, 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):p_fileszphnum x phentsize= 15 x 56 = 840 B)main0x310= 784 B0x348= 840 BSo 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 mentionskSyntheticProgramHeaderCountandkeepFrameszero times, so "leaves this count defect out of scope" holds.#1559does 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:#1559and this PR now edit the same lines ofProgramHeaderLayoutBuilder.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_FRAMEretention half in isolation, because onmainthe 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.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-10T05:18:22Z.
test_linux_eh_frame_header.pyconflicts with main again now that #2256 is in; please rebase and keep itsheader_bounds(...)check, as you described.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 intest_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, andlinux_eh_frame_headerfails without the fix. Merging.