fix(relinker): accept an identical duplicate pointer relocation in the strict filter #11923

Merged
rooklz merged 1 commit from upstream-pr/11923 into main 2026-10-28 09:31:02 +00:00
rooklz commented 2026-10-27 12:40:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-27T12:40:51Z.


What

9673868d5f (fix(relinker): accept an identical duplicate relocation in Windows executables) settled the semantics of a RELA entry repeated with the same target, type and addend: it writes the same value twice, so applying it once is equivalent. The Windows relocation builder and the code analysis accept such a duplicate, distinct entries at one target are still refused, and the Linux output already passed it through (measured trigger: Forever Launcher's game-child.bin, PPSA99030, repeats one RELATIVE entry).

The strict unused-NID filter (unused-filter=2) re-reads DT_RELA on its own and was missed by that fix: StrictNidFilter refuses a second pointer relocation at a slot unconditionally, so the same ELF converts with unused-filter=0 and unused-filter=1 but fails with unused-filter=2 on "Strict filter: overlapping pointer relocations".

Build() now records a pointer relocation only when its slot is new or its target is identical to the recorded one — the same comparison 9673868d5f added to CodeInstructionCollector — and still refuses a distinct entry at one slot and a slot that an import relocation already owns.

Tested

macOS 26.2, Apple M5 (arm64), CMake/Ninja, ANYPS5_RELINKER_ONLY=ON, BUILD_TESTING=ON (Python 3.13). Base: eece5da035 (upstream/main), tested head: 0f75fd0662.

End-to-end against the relinker binary on this Mac, before/after:

  • an executable with an import GLOB_DAT plus two identical RELATIVE entries at one slot: unused-filter=1 converts; unused-filter=2 failed before with Strict filter: overlapping pointer relocations (offset 0x4e08) and converts after, with the same Strict filtering total and Function graph reports as the single-entry image — the duplicate changes no reachability outcome;
  • two entries with different addends at the same slot: still refused at both levels (Conflicting relative relocation targets at 1, Strict filter: overlapping pointer relocations at 2).

Tests, red on the base source with only the tests applied, green at head:

  • core/relinker/relinker/tests/test_duplicate_relocations.py: the strict-filter duplicate now converts and reports identically to the single-entry image; a conflicting duplicate is still refused;
  • StrictNidFilterTests.cpp duplicatePointerRelocations: an identical duplicate pointer relocation keeps its import through Filter(); a conflicting duplicate and a pointer relocation at an import slot are refused.

Full relinker ctest 361/361; check_conventions and pr_overlap clean. Host-only change to the relinker; no title, GPU or console involved. No performance claim.

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:5034058548 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11923). Originally posted by [rooklz](https://github.com/rooklz) on 2026-10-27T12:40:51Z. --- ### What 9673868d5f (fix(relinker): accept an identical duplicate relocation in Windows executables) settled the semantics of a RELA entry repeated with the same target, type and addend: it writes the same value twice, so applying it once is equivalent. The Windows relocation builder and the code analysis accept such a duplicate, distinct entries at one target are still refused, and the Linux output already passed it through (measured trigger: Forever Launcher's game-child.bin, PPSA99030, repeats one RELATIVE entry). The strict unused-NID filter (`unused-filter=2`) re-reads `DT_RELA` on its own and was missed by that fix: `StrictNidFilter` refuses a second pointer relocation at a slot unconditionally, so the same ELF converts with `unused-filter=0` and `unused-filter=1` but fails with `unused-filter=2` on "Strict filter: overlapping pointer relocations". `Build()` now records a pointer relocation only when its slot is new or its target is identical to the recorded one — the same comparison 9673868d5f added to `CodeInstructionCollector` — and still refuses a distinct entry at one slot and a slot that an import relocation already owns. ### 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. --> macOS 26.2, Apple M5 (arm64), CMake/Ninja, `ANYPS5_RELINKER_ONLY=ON`, `BUILD_TESTING=ON` (Python 3.13). Base: `eece5da035` (`upstream/main`), tested head: `0f75fd0662`. End-to-end against the relinker binary on this Mac, before/after: - an executable with an import `GLOB_DAT` plus two identical `RELATIVE` entries at one slot: `unused-filter=1` converts; `unused-filter=2` failed before with `Strict filter: overlapping pointer relocations (offset 0x4e08)` and converts after, with the same `Strict filtering total` and `Function graph` reports as the single-entry image — the duplicate changes no reachability outcome; - two entries with different addends at the same slot: still refused at both levels (`Conflicting relative relocation targets` at 1, `Strict filter: overlapping pointer relocations` at 2). Tests, red on the base source with only the tests applied, green at head: - `core/relinker/relinker/tests/test_duplicate_relocations.py`: the strict-filter duplicate now converts and reports identically to the single-entry image; a conflicting duplicate is still refused; - `StrictNidFilterTests.cpp` `duplicatePointerRelocations`: an identical duplicate pointer relocation keeps its import through `Filter()`; a conflicting duplicate and a pointer relocation at an import slot are refused. Full relinker ctest 361/361; `check_conventions` and `pr_overlap` clean. Host-only change to the relinker; no title, GPU or console involved. No performance claim. ### 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-27 12:45:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-27T12:45:57Z.

Review: COMMENTED


I reviewed the duplicate-slot condition and the added C++/end-to-end cases. The filter now keeps a repeated RELATIVE relocation only when the recorded addend matches, while still rejecting conflicting duplicates and import-slot overlap. Locally on Linux with GCC 12.2 Release, strict_nid_filter_tests passed and CTest passed duplicate_relocations plus strict_nid_filter (2/2). Hosted Ubuntu and ASan are also green; Windows and both macOS relinker jobs were still running/queued when I checked. I will revisit the final status before approval.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5667236797 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11923#pullrequestreview-5667236797). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-27T12:45:57Z. **Review:** COMMENTED --- I reviewed the duplicate-slot condition and the added C++/end-to-end cases. The filter now keeps a repeated RELATIVE relocation only when the recorded addend matches, while still rejecting conflicting duplicates and import-slot overlap. Locally on Linux with GCC 12.2 Release, `strict_nid_filter_tests` passed and CTest passed `duplicate_relocations` plus `strict_nid_filter` (2/2). Hosted Ubuntu and ASan are also green; Windows and both macOS relinker jobs were still running/queued when I checked. I will revisit the final status before approval.
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!11923
No description provided.