fix(relinker): drop input Linux PT_PHDR and PT_INTERP #2885

Merged
MarcZX10 merged 1 commit from upstream-pr/2885 into main 2026-10-10 23:13:32 +00:00
MarcZX10 commented 2026-10-10 17:35:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-10T17:35:59Z.


What

The Linux patcher wrote its generated PT_PHDR and PT_INTERP alongside copies from the input ELF. The stale input PT_PHDR can give glibc the pre-relink load bias and crash before main; copying both headers also consumes program-header slots. Filter the input headers and let the Linux writer emit its own entries.

This carries ctj01's fix and regression test from danzaio's #2877, which closed at the intake gate before review. The original commit author is preserved.

Tested

Linux x86-64, GCC 12.2, Release relinker-only build. All 99 relinker CTests passed, including linux_input_program_headers, which checks inputs with neither, either, or both headers; exact program-header slot counts; and execution through the generated entry stub. Conventions and git diff --check passed.

Danzaio also reported a MinGW 15.2 relinker-only build and structural checks passing on Windows; the test's execution check runs only on Linux. Full project builds were not run.

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 in TechnicalDebt
  • 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
  • AI-assisted: yes

Fixes #2816

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4813171866 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2885). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-10T17:35:59Z. --- ### What The Linux patcher wrote its generated `PT_PHDR` and `PT_INTERP` alongside copies from the input ELF. The stale input `PT_PHDR` can give glibc the pre-relink load bias and crash before `main`; copying both headers also consumes program-header slots. Filter the input headers and let the Linux writer emit its own entries. This carries ctj01's fix and regression test from danzaio's #2877, which closed at the intake gate before review. The original commit author is preserved. ### Tested Linux x86-64, GCC 12.2, Release relinker-only build. All 99 relinker CTests passed, including `linux_input_program_headers`, which checks inputs with neither, either, or both headers; exact program-header slot counts; and execution through the generated entry stub. Conventions and `git diff --check` passed. Danzaio also reported a MinGW 15.2 relinker-only build and structural checks passing on Windows; the test's execution check runs only on Linux. Full project builds were not run. ### 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](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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: none - [x] AI-assisted: yes Fixes #2816
Dextroid17 commented 2026-10-10 22:16:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-10T22:16:51Z.

Review: COMMENTED


The relinker is the part of this project I would most want a second pair of eyes on, so: the change reads right, and I checked the one thing that would have worried me.

The filter is Linux-only in practice. SegmentFilter is constructed in main.cpp for the LinuxElfPatcher branch, so adding PT_PHDR and PT_INTERP to ShouldSkip cannot silently drop those entries for a target whose writer does not emit its own, and the existing test_linux_program_header_order already pins that the Linux writer places both ahead of the PT_LOAD entries. That is the cross-target risk I went looking for and did not find.

One question about intent, since the input's interpreter is now ignored. With PT_INTERP filtered, the writer's own entry always wins. For a relink aimed at the host that is what you want; if the Linux writer is ever pointed at input naming a different interpreter, that distinction would be lost. Worth a word in the commit only if the case is reachable at all.

The provenance is handled the way it should be — ctj01's fix and test, danzaio's PR closed at the intake gate, authorship preserved here. And the test is the right shape for this change: neither / either / both input headers, the exact program-header slot counts, and execution through the generated entry stub.

Written with AI assistance.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5481001278 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2885#pullrequestreview-5481001278). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-10T22:16:51Z. **Review:** COMMENTED --- The relinker is the part of this project I would most want a second pair of eyes on, so: the change reads right, and I checked the one thing that would have worried me. **The filter is Linux-only in practice.** `SegmentFilter` is constructed in `main.cpp` for the `LinuxElfPatcher` branch, so adding `PT_PHDR` and `PT_INTERP` to `ShouldSkip` cannot silently drop those entries for a target whose writer does not emit its own, and the existing `test_linux_program_header_order` already pins that the Linux writer places both ahead of the `PT_LOAD` entries. That is the cross-target risk I went looking for and did not find. **One question about intent, since the input's interpreter is now ignored.** With `PT_INTERP` filtered, the writer's own entry always wins. For a relink aimed at the host that is what you want; if the Linux writer is ever pointed at input naming a different interpreter, that distinction would be lost. Worth a word in the commit only if the case is reachable at all. The provenance is handled the way it should be — ctj01's fix and test, danzaio's PR closed at the intake gate, authorship preserved here. And the test is the right shape for this change: neither / either / both input headers, the exact program-header slot counts, and execution through the generated entry stub. Written with AI assistance.
adriadam10 commented 2026-10-10 23:13:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T23:13:30Z.


Checked on Linux x86-64: relinker build + ctest (94/94, incl. linux_input_program_headers); the new test fails when the SegmentFilter change is reverted and passes with it. No overlap with other open PRs; CI green on the current head. Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6103204401 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2885#issuecomment-6103204401). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T23:13:30Z. --- Checked on Linux x86-64: relinker build + ctest (94/94, incl. `linux_input_program_headers`); the new test fails when the `SegmentFilter` change is reverted and passes with it. No overlap with other open PRs; CI green on the current head. 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!2885
No description provided.