fix(relinker): reject a second PT_GNU_EH_FRAME segment #13914

Merged
roboterspinne merged 2 commits from upstream-pr/13914 into main 2026-11-01 09:40:26 +00:00
roboterspinne commented 2026-10-31 12:37:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by roboterspinne on 2026-10-31T12:37:31Z.


What

On b7d3fd3c52 (line numbers below refer to it) an executable or a guest module with two PT_GNU_EH_FRAME headers converts on every target. RelinkerPipeline::Relink rejects a second PT_DYNAMIC (Multiple PT_DYNAMIC segments, line 120) and a second PT_SCE_DYNLIBDATA, and the guest image reader rejects a second dynamic segment and a second SCE dynamic data header (GuestImageReader.cpp:55 and 59), but neither counts PT_GNU_EH_FRAME. Linux output keeps both headers, and the Windows writers add one .ehmeta section per header (WindowsPePatcher.cpp:76, WindowsGuestModuleWriter.cpp:106). The runtime then picks different tables per target: the Linux readers keep the last PT_GNU_EH_FRAME they see (core/libs/prx/libc/src/exception/Unwind.cpp:193, core/libs/prx/libkernel/Module/src/Module.cpp:223), while the Windows readers stop at the first .ehmeta of an image (Unwind.cpp:507, core/libs/prx/libkernel/Module/EhFrame.hpp:103). An executable and a bundled module with two identical PT_GNU_EH_FRAME headers converted with exit 0 for Linux, --windows and --macos, writing the output and the module.

  • Executables. After the PT_DYNAMIC check, the pipeline throws Multiple PT_GNU_EH_FRAME segments at the second segment's p_offset, before any analysis or output, on every target.
  • Guest modules. The guest image reader fails a module with a second header as Duplicate EH frame segment, next to its other duplicate-header checks, so a bundled module fails the same way for Linux, Windows and macOS.
  • Every PT_GNU_EH_FRAME header counts, as every PT_DYNAMIC header does for the existing check, also an identical repeat and one with p_filesz 0: the Linux writer would keep such a header, while the Windows writers already fail on it with Cannot map an empty ELF address range (WindowsLoadImage.cpp:97). A single header and modules or executables without one are unchanged. Real titles with two such headers are not known.

pr_overlap.py --branch finds no shared lines with the open pull requests it can compare and cannot compare #10792 and #10861, which also change RelinkerPipeline.cpp but do not merge with main. Checked by hand: a trial merge of this branch with each of them conflicts only in the files that main with it already conflicts in (SyscallScanner.cpp for #10792; CodeInstructionCollector.cpp and docs/dev/debt/relinker.md for #10861), and RelinkerPipeline.cpp merges cleanly.

Tested

Windows 11, WinLibs GCC 15.2.0, relinker-only build (-DANYPS5_RELINKER_ONLY=ON, Ninja, Release), on 3d5a51c470 (based on b7d3fd3c52; main at b8f0a6b202 changed none of these files and merges cleanly):

  • linux_eh_frame_header gains duplicate_headers: its executable fixture (entry 0x100) with a second PT_GNU_EH_FRAME header must fail with Multiple PT_GNU_EH_FRAME segments and write no output, and a bundled consumer.prx with two file-backed PT_GNU_EH_FRAME headers must fail with consumer.prx: Duplicate EH frame segment and write neither the output nor the module, each for Linux, --windows and --macos. Built with the pipeline and guest reader of b7d3fd3c52, all six cases convert with exit 0 and write their files; on 3d5a51c470 all six fail as expected and the test passes.
  • ctest --test-dir build-relinker -j 5 on 54f981f596 (3d5a51c470 changes only the fixtures of this test): 543 tests, 537 passed, long_paths skipped; annotate_module, a Python test of tools/annotate_module.py that does not run the relinker, timed out under the parallel load and passes alone in about 15.5 s (it sits close to its 20 s limit on this machine); select_tests and its three parts select_tests_SelectGraphStateTests, select_tests_SelectBuildTests and select_tests_SelectArgumentTests fail with the Windows symlink fixture's FileExistsError, as on main on this machine; this change touches nothing under tools/.
  • python tools/check_conventions.py --base b7d3fd3c52 with this title and description passed on 3d5a51c470.

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:5097563676 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13914). Originally posted by [roboterspinne](https://github.com/roboterspinne) on 2026-10-31T12:37:31Z. --- ### What On b7d3fd3c52 (line numbers below refer to it) an executable or a guest module with two `PT_GNU_EH_FRAME` headers converts on every target. `RelinkerPipeline::Relink` rejects a second `PT_DYNAMIC` (`Multiple PT_DYNAMIC segments`, line 120) and a second `PT_SCE_DYNLIBDATA`, and the guest image reader rejects a second dynamic segment and a second SCE dynamic data header (`GuestImageReader.cpp:55` and `59`), but neither counts `PT_GNU_EH_FRAME`. Linux output keeps both headers, and the Windows writers add one `.ehmeta` section per header (`WindowsPePatcher.cpp:76`, `WindowsGuestModuleWriter.cpp:106`). The runtime then picks different tables per target: the Linux readers keep the last `PT_GNU_EH_FRAME` they see (`core/libs/prx/libc/src/exception/Unwind.cpp:193`, `core/libs/prx/libkernel/Module/src/Module.cpp:223`), while the Windows readers stop at the first `.ehmeta` of an image (`Unwind.cpp:507`, `core/libs/prx/libkernel/Module/EhFrame.hpp:103`). An executable and a bundled module with two identical `PT_GNU_EH_FRAME` headers converted with exit 0 for Linux, `--windows` and `--macos`, writing the output and the module. - **Executables.** After the `PT_DYNAMIC` check, the pipeline throws `Multiple PT_GNU_EH_FRAME segments` at the second segment's `p_offset`, before any analysis or output, on every target. - **Guest modules.** The guest image reader fails a module with a second header as `Duplicate EH frame segment`, next to its other duplicate-header checks, so a bundled module fails the same way for Linux, Windows and macOS. - Every `PT_GNU_EH_FRAME` header counts, as every `PT_DYNAMIC` header does for the existing check, also an identical repeat and one with `p_filesz` 0: the Linux writer would keep such a header, while the Windows writers already fail on it with `Cannot map an empty ELF address range` (`WindowsLoadImage.cpp:97`). A single header and modules or executables without one are unchanged. Real titles with two such headers are not known. `pr_overlap.py --branch` finds no shared lines with the open pull requests it can compare and cannot compare #10792 and #10861, which also change `RelinkerPipeline.cpp` but do not merge with `main`. Checked by hand: a trial merge of this branch with each of them conflicts only in the files that `main` with it already conflicts in (`SyscallScanner.cpp` for #10792; `CodeInstructionCollector.cpp` and `docs/dev/debt/relinker.md` for #10861), and `RelinkerPipeline.cpp` merges cleanly. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Windows 11, WinLibs GCC 15.2.0, relinker-only build (`-DANYPS5_RELINKER_ONLY=ON`, Ninja, Release), on 3d5a51c470 (based on b7d3fd3c52; `main` at b8f0a6b202 changed none of these files and merges cleanly): - `linux_eh_frame_header` gains `duplicate_headers`: its executable fixture (entry 0x100) with a second `PT_GNU_EH_FRAME` header must fail with `Multiple PT_GNU_EH_FRAME segments` and write no output, and a bundled `consumer.prx` with two file-backed `PT_GNU_EH_FRAME` headers must fail with `consumer.prx: Duplicate EH frame segment` and write neither the output nor the module, each for Linux, `--windows` and `--macos`. Built with the pipeline and guest reader of b7d3fd3c52, all six cases convert with exit 0 and write their files; on 3d5a51c470 all six fail as expected and the test passes. - `ctest --test-dir build-relinker -j 5` on 54f981f596 (3d5a51c470 changes only the fixtures of this test): 543 tests, 537 passed, `long_paths` skipped; `annotate_module`, a Python test of `tools/annotate_module.py` that does not run the relinker, timed out under the parallel load and passes alone in about 15.5 s (it sits close to its 20 s limit on this machine); `select_tests` and its three parts `select_tests_SelectGraphStateTests`, `select_tests_SelectBuildTests` and `select_tests_SelectArgumentTests` fail with the Windows symlink fixture's `FileExistsError`, as on `main` on this machine; this change touches nothing under `tools/`. - `python tools/check_conventions.py --base b7d3fd3c52` with this title and description passed on 3d5a51c470. ### 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: <!-- #PR, or none --> none - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> none - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> n/a - [x] AI-assisted: <!-- yes / no --> yes
MarcZX10 commented 2026-10-31 12:38:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-31T12:38:16Z.

Review: APPROVED


Reviewed — looks good

The exact head 3d5a51c4707797d788391bdfe8716f110bf17bfa rejects duplicate PT_GNU_EH_FRAME headers before writing executable or guest-module outputs across the Linux, Windows, and macOS relinker modes.

I ran python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 13914 against base 60bdb061356db736928eee431cd8bd4c9ba68036: diff, conventions, Python syntax, test registration, and mergeability passed. The author reports that all six targeted duplicate-header cases fail as intended on this exact head after a Windows relinker-only build. I did not build or run CTests locally; the full-suite results in the PR description are from a different head and include unrelated existing failures. Hosted eligibility, conventions, intake, and label checks were still running at my last refresh.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5722734589 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13914#pullrequestreview-5722734589). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-31T12:38:16Z. **Review:** APPROVED --- # Reviewed — looks good The exact head `3d5a51c4707797d788391bdfe8716f110bf17bfa` rejects duplicate `PT_GNU_EH_FRAME` headers before writing executable or guest-module outputs across the Linux, Windows, and macOS relinker modes. I ran `python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 13914` against base `60bdb061356db736928eee431cd8bd4c9ba68036`: diff, conventions, Python syntax, test registration, and mergeability passed. The author reports that all six targeted duplicate-header cases fail as intended on this exact head after a Windows relinker-only build. I did not build or run CTests locally; the full-suite results in the PR description are from a different head and include unrelated existing failures. Hosted eligibility, conventions, intake, and label checks were still running at my last refresh.
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!13914
No description provided.