fix(relinker): handle overlapping relocation tables #6607

Merged
jweidenh merged 1 commit from upstream-pr/6607 into main 2026-10-20 08:38:40 +00:00
jweidenh commented 2026-10-15 22:42:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jweidenh on 2026-10-15T22:42:05Z.


What

An ELF file can include its PLT relocations in the range described by DT_RELA and also name them through DT_JMPREL. The relinker currently reads those shared entries twice: executable conversion rejects them as duplicate JUMP_SLOT relocations, guest-module parsing rejects overlapping targets, and Windows/macOS code analysis rejects duplicate pointers to defined functions.

Process each shared source entry once, keeping it in the PLT pass to preserve slot ordering. Validate that intersecting tables share whole 24-byte entries; distinct entries that target the same location still encounter the existing conflict checks. This covers executable and guest-module inputs with SysV or SCE dynamic tags and Linux, Windows, and macOS output.

LLVM's x86-64 combined-relocation fixture generates the motivating layout with .rela.dyn : { *(.rela.dyn) *(.rela.plt) }; its linker implementation documents the overlapping ranges. No real-title compatibility claim is made.

Tested

  • Tested commit 185fa9687, rebased onto main at fcde2cf95. macOS arm64, Apple Clang, Release relinker-only build: all 202 tests pass. The nested CMake test required Ninja on PATH and passed on rerun.
  • The new regression covers 48 successful conversions and 24 rejection cases: disjoint, coincident, suffix and partial whole-entry overlaps; misaligned overlaps; and distinct-source conflicts. It checks emitted relocation tables, resolved local pointers, import registry ordering, and unchanged input files.
  • The regression fails against the original unmodified main relinker on the first coincident-table executable with Duplicate JUMP_SLOT relocation. An independent Windows validation also confirmed that reverting the fix makes the regression fail.
  • Upstream relinker CI on this head: all 211 Linux, 206 Windows, 202 macOS arm64, and 202 macOS x86-64 tests pass; the 32-test ASan suite also passes. The overlap regression passes on all four targets, including native Windows executable/module calls and native Linux execution.
  • The tests for optional RELA tables and section-relative guest-module relocations also pass after rebasing.
  • tools/check_conventions.py --base origin/main and git diff --check pass.

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:4880791652 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6607). Originally posted by [jweidenh](https://github.com/jweidenh) on 2026-10-15T22:42:05Z. --- ### What An ELF file can include its PLT relocations in the range described by `DT_RELA` and also name them through `DT_JMPREL`. The relinker currently reads those shared entries twice: executable conversion rejects them as duplicate `JUMP_SLOT` relocations, guest-module parsing rejects overlapping targets, and Windows/macOS code analysis rejects duplicate pointers to defined functions. Process each shared source entry once, keeping it in the PLT pass to preserve slot ordering. Validate that intersecting tables share whole 24-byte entries; distinct entries that target the same location still encounter the existing conflict checks. This covers executable and guest-module inputs with SysV or SCE dynamic tags and Linux, Windows, and macOS output. LLVM's [x86-64 combined-relocation fixture](https://github.com/llvm/llvm-project/blob/7dc5af75ae5b8bcfce269fbd21c893cc2e4a61f0/lld/test/ELF/x86-64-combined-dynrel.s) generates the motivating layout with `.rela.dyn : { *(.rela.dyn) *(.rela.plt) }`; its [linker implementation](https://github.com/llvm/llvm-project/blob/llvmorg-20.1.8/lld/ELF/SyntheticSections.cpp#L1347) documents the overlapping ranges. No real-title compatibility claim is made. ### 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. --> - Tested commit `185fa9687`, rebased onto main at `fcde2cf95`. macOS arm64, Apple Clang, Release relinker-only build: all 202 tests pass. The nested CMake test required Ninja on PATH and passed on rerun. - The new regression covers 48 successful conversions and 24 rejection cases: disjoint, coincident, suffix and partial whole-entry overlaps; misaligned overlaps; and distinct-source conflicts. It checks emitted relocation tables, resolved local pointers, import registry ordering, and unchanged input files. - The regression fails against the original unmodified main relinker on the first coincident-table executable with `Duplicate JUMP_SLOT relocation`. An [independent Windows validation](https://github.com/boykopovar/AnyPS5/pull/6607#issuecomment-6254315462) also confirmed that reverting the fix makes the regression fail. - [Upstream relinker CI](https://github.com/boykopovar/AnyPS5/actions/runs/39212164779) on this head: all 211 Linux, 206 Windows, 202 macOS arm64, and 202 macOS x86-64 tests pass; the 32-test ASan suite also passes. The overlap regression passes on all four targets, including native Windows executable/module calls and native Linux execution. - The tests for optional RELA tables and section-relative guest-module relocations also pass after rebasing. - `tools/check_conventions.py --base origin/main` and `git diff --check` pass. ### 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: none <!-- #PR, or none --> - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: none <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: n/a <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no -->
github-actions[bot] commented 2026-10-15 23:30:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T23:30:02Z.


Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 5021 core/relinker/CMakeLists.txt
PR 6044 core/relinker/CMakeLists.txt
PR 6618 core/relinker/CMakeLists.txt
core/relinker/relinker/src/analysis/CodeInstructionCollector.cpp
core/relinker/relinker/src/pipeline/RelinkerPipeline.cpp
PR 6879 core/relinker/CMakeLists.txt
PR 6977 core/relinker/CMakeLists.txt
core/relinker/relinker/src/analysis/CodeInstructionCollector.cpp
core/relinker/relinker/src/guest/GuestImageReader.cpp
core/relinker/relinker/src/pipeline/RelinkerPipeline.cpp
PR 7332 core/relinker/CMakeLists.txt
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6204440157 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6607#issuecomment-6204440157). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-15T23:30:02Z. --- <!-- pr-overlap --> Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/relinker/CMakeLists.txt` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/relinker/CMakeLists.txt` | | [PR 6618](https://www.github.com/boykopovar/AnyPS5/pull/6618) | `core/relinker/CMakeLists.txt`<br>`core/relinker/relinker/src/analysis/CodeInstructionCollector.cpp`<br>`core/relinker/relinker/src/pipeline/RelinkerPipeline.cpp` | | [PR 6879](https://www.github.com/boykopovar/AnyPS5/pull/6879) | `core/relinker/CMakeLists.txt` | | [PR 6977](https://www.github.com/boykopovar/AnyPS5/pull/6977) | `core/relinker/CMakeLists.txt`<br>`core/relinker/relinker/src/analysis/CodeInstructionCollector.cpp`<br>`core/relinker/relinker/src/guest/GuestImageReader.cpp`<br>`core/relinker/relinker/src/pipeline/RelinkerPipeline.cpp` | | [PR 7332](https://www.github.com/boykopovar/AnyPS5/pull/7332) | `core/relinker/CMakeLists.txt` |
DProkos commented 2026-10-18 19:43:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DProkos on 2026-10-18T19:43:59Z.


Windows check of af1a15622 merged onto current main (48d61f53b, clean merge).

Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7 UCRT, Ninja, Release, ANYPS5_RELINKER_ONLY=ON, BUILD_TESTING=ON, Python 3.11.0.

  • overlapping_relocations: passed (3.0 s).
  • Full relinker suite: 197/197 passed.

Negative control: with CodeInstructionCollector.cpp, GuestImageReader.cpp and RelinkerPipeline.cpp restored to main and the new test kept, overlapping_relocations fails on the first case (alias, non-SCE, executable, Linux output): FAIL: Duplicate JUMP_SLOT relocation for the same original .rela.plt slot (offset 0x740).

Not run: titles or homebrew.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6254315462 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6607#issuecomment-6254315462). Originally posted by [DProkos](https://github.com/DProkos) on 2026-10-18T19:43:59Z. --- Windows check of af1a15622 merged onto current `main` (`48d61f53b`, clean merge). Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7 UCRT, Ninja, Release, `ANYPS5_RELINKER_ONLY=ON`, `BUILD_TESTING=ON`, Python 3.11.0. - `overlapping_relocations`: passed (3.0 s). - Full relinker suite: 197/197 passed. **Negative control:** with `CodeInstructionCollector.cpp`, `GuestImageReader.cpp` and `RelinkerPipeline.cpp` restored to `main` and the new test kept, `overlapping_relocations` fails on the first case (`alias`, non-SCE, executable, Linux output): `FAIL: Duplicate JUMP_SLOT relocation for the same original .rela.plt slot (offset 0x740)`. Not run: titles or homebrew. AI-assisted: yes
DProkos commented 2026-10-19 19:12:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DProkos on 2026-10-19T19:12:03Z.


Windows re-check of the rebased head 185fa9687 merged onto current main (585075cb7, clean merge).

Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7 UCRT, Ninja, Release, ANYPS5_RELINKER_ONLY=ON, BUILD_TESTING=ON, Python 3.11.0.

  • overlapping_relocations: passed (3.3 s).
  • Full relinker suite: 213/213 passed.

Negative control: with CodeInstructionCollector.cpp, GuestImageReader.cpp and RelinkerPipeline.cpp restored to main, overlapping_relocations still fails on its first case (alias, non-SCE, executable, Linux output), as before the rebase.

Not run: titles or homebrew.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6275161168 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6607#issuecomment-6275161168). Originally posted by [DProkos](https://github.com/DProkos) on 2026-10-19T19:12:03Z. --- Windows re-check of the rebased head 185fa9687 merged onto current `main` (`585075cb7`, clean merge). Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7 UCRT, Ninja, Release, `ANYPS5_RELINKER_ONLY=ON`, `BUILD_TESTING=ON`, Python 3.11.0. - `overlapping_relocations`: passed (3.3 s). - Full relinker suite: 213/213 passed. **Negative control:** with `CodeInstructionCollector.cpp`, `GuestImageReader.cpp` and `RelinkerPipeline.cpp` restored to `main`, `overlapping_relocations` still fails on its first case (`alias`, non-SCE, executable, Linux output), as before the rebase. Not run: titles or homebrew. AI-assisted: yes
adriadam10 commented 2026-10-20 08:38:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-20T08:38:46Z.


Re-checked against current main (new null-symbol relocation handling and header cache in CodeInstructionCollector.cpp): the changes touch different regions from this PR's, the merge is clean and the code is the head I reviewed. Merged.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6286972011 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6607#issuecomment-6286972011). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-20T08:38:46Z. --- Re-checked against current main (new null-symbol relocation handling and header cache in `CodeInstructionCollector.cpp`): the changes touch different regions from this PR's, the merge is clean and the code is the head I reviewed. Merged.
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!6607
No description provided.