fix(relinker): reject a second PT_DYNAMIC segment #10403

Merged
roboterspinne merged 1 commit from upstream-pr/10403 into main 2026-10-26 01:15:53 +00:00
roboterspinne commented 2026-10-23 21:34:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by roboterspinne on 2026-10-23T21:34:52Z.


What

The PT_DYNAMIC loop in RelinkerPipeline::Relink() took the first header and stopped (break, RelinkerPipeline.cpp:109 on main), so Linux output silently ignored a second PT_DYNAMIC and converted with exit 0. The other readers already refuse it: RelativeRelocationIndex.cpp:172 throws Multiple PT_DYNAMIC segments and guest modules fail with Duplicate dynamic segment (GuestImageReader.cpp:52).

  • A second PT_DYNAMIC now fails with Multiple PT_DYNAMIC segments at its file offset (RelinkerPipeline.cpp:106-107), the wording RelativeRelocationIndex.cpp:172 already uses. The check is in the pipeline, so all targets report it.
  • On main, Windows and macOS failed later with Code analysis: invalid dynamic segment (CodeInstructionCollector.cpp:74) and now report the pipeline message.
  • Unchanged: a single PT_DYNAMIC is read as before, and a missing one still fails with No PT_DYNAMIC segment found.

Tested

Ubuntu 24.04.5 x86_64, GCC 13.3, CMake 3.28, Python 3.13. Relinker-only Release build (-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON, Ninja). Synthetic fixtures only, no title or homebrew.

  • test_dynamic_segment.py: a new duplicate case copies the fixture's PT_DYNAMIC into a second program header. It expects exit 2, Multiple PT_DYNAMIC segments and no output on Linux, --windows and --macos. convert() takes the modes as a parameter so this case also covers --macos; the existing cases keep Linux and --windows.
  • Red on main (11e8ad2934): dynamic_segment fails at duplicate. Linux exits 0, while --windows and --macos exit 2 with Code analysis: invalid dynamic segment.
  • Green on this branch: ctest --test-dir build -R '^(elf_header|dynamic_segment|input_magic)$' 3/3 passed (dynamic_segment 0.1 s). ctest --test-dir build -j2 240/240 passed.
  • Merged with my other open pull requests (#10357, #10390, #10391) and the branches fix/relinker-elf-type-allowlist and fix/relinker-linux-load-bounds: no conflicts, ctest 241/241 passed. #10017 and #8076 also edit RelinkerPipeline.cpp, at line 346 and later; this patch applies cleanly on top of both PR heads.
  • python3 tools/check_conventions.py --base upstream/main with this title and description passed.

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 (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4989538465 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10403). Originally posted by [roboterspinne](https://github.com/roboterspinne) on 2026-10-23T21:34:52Z. --- ### What The `PT_DYNAMIC` loop in `RelinkerPipeline::Relink()` took the first header and stopped (`break`, `RelinkerPipeline.cpp:109` on `main`), so Linux output silently ignored a second `PT_DYNAMIC` and converted with exit 0. The other readers already refuse it: `RelativeRelocationIndex.cpp:172` throws `Multiple PT_DYNAMIC segments` and guest modules fail with `Duplicate dynamic segment` (`GuestImageReader.cpp:52`). - A second `PT_DYNAMIC` now fails with `Multiple PT_DYNAMIC segments` at its file offset (`RelinkerPipeline.cpp:106-107`), the wording `RelativeRelocationIndex.cpp:172` already uses. The check is in the pipeline, so all targets report it. - On `main`, Windows and macOS failed later with `Code analysis: invalid dynamic segment` (`CodeInstructionCollector.cpp:74`) and now report the pipeline message. - Unchanged: a single `PT_DYNAMIC` is read as before, and a missing one still fails with `No PT_DYNAMIC segment found`. ### 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. --> Ubuntu 24.04.5 x86_64, GCC 13.3, CMake 3.28, Python 3.13. Relinker-only Release build (`-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON`, Ninja). Synthetic fixtures only, no title or homebrew. - `test_dynamic_segment.py`: a new `duplicate` case copies the fixture's `PT_DYNAMIC` into a second program header. It expects exit 2, `Multiple PT_DYNAMIC segments` and no output on Linux, `--windows` and `--macos`. `convert()` takes the modes as a parameter so this case also covers `--macos`; the existing cases keep Linux and `--windows`. - Red on `main` (11e8ad2934): `dynamic_segment` fails at `duplicate`. Linux exits 0, while `--windows` and `--macos` exit 2 with `Code analysis: invalid dynamic segment`. - Green on this branch: `ctest --test-dir build -R '^(elf_header|dynamic_segment|input_magic)$'` 3/3 passed (`dynamic_segment` 0.1 s). `ctest --test-dir build -j2` 240/240 passed. - Merged with my other open pull requests (#10357, #10390, #10391) and the branches `fix/relinker-elf-type-allowlist` and `fix/relinker-linux-load-bounds`: no conflicts, `ctest` 241/241 passed. #10017 and #8076 also edit `RelinkerPipeline.cpp`, at line 346 and later; this patch applies cleanly on top of both PR heads. - `python3 tools/check_conventions.py --base upstream/main` with this title and description passed. ### 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 (Claude Code)
MarcZX10 commented 2026-10-23 21:59:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T21:59:13Z.

Review: APPROVED


Reviewed the three-line guard and the duplicate-header fixture. The pipeline now applies the same multiple-segment rejection already used for PT_SCE_DYNLIBDATA, and the test checks Linux, Windows, and macOS diagnostics plus no output. The hosted relinker matrix and conventions checks pass; full Linux and Windows product jobs are skipped by the repository workflow. No blocking issue found.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5634896706 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10403#pullrequestreview-5634896706). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T21:59:13Z. **Review:** APPROVED --- Reviewed the three-line guard and the duplicate-header fixture. The pipeline now applies the same multiple-segment rejection already used for PT_SCE_DYNLIBDATA, and the test checks Linux, Windows, and macOS diagnostics plus no output. The hosted relinker matrix and conventions checks pass; full Linux and Windows product jobs are skipped by the repository workflow. No blocking issue found.
MarcZX10 commented 2026-10-23 22:07:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T22:07:42Z.

Review: APPROVED


Reviewed the duplicate-header check and its regression fixture. The loop now rejects a second PT_DYNAMIC with the existing diagnostic before replacing the first segment’s tags, and the new fixture exercises Linux, Windows, and macOS output modes. The reported 240/240 focused suite and 241/241 combined suite cover the change; hosted relinker jobs for Linux, Windows, macOS arm64, macOS x86_64, and ASan also pass. I found no blocking issue.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5634954807 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10403#pullrequestreview-5634954807). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T22:07:42Z. **Review:** APPROVED --- Reviewed the duplicate-header check and its regression fixture. The loop now rejects a second PT_DYNAMIC with the existing diagnostic before replacing the first segment’s tags, and the new fixture exercises Linux, Windows, and macOS output modes. The reported 240/240 focused suite and 241/241 combined suite cover the change; hosted relinker jobs for Linux, Windows, macOS arm64, macOS x86_64, and ASan also pass. I found no blocking issue.
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!10403
No description provided.