fix(relinker): keep the interpreter path out of the scanned code #8599

Merged
javierUDP merged 2 commits from upstream-pr/8599 into main 2026-10-20 18:12:33 +00:00
javierUDP commented 2026-10-20 17:59:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by javierUDP on 2026-10-20T17:59:17Z.


Reopens #7996, which closed when I republished its branch to rebase it. Same two commits, rebased onto current main as @oneandonlydean asked, with the conflict in CodeInstructionCollector.cpp resolved to keep both rules.

What

The code analysis trims an interpreter path from the start of an executable segment only for images that have a PT_SCE_DYNLIBDATA block. An executable without one keeps that path in the scanned range.

/libexec/ld-elf.so.1 then gets walked as code: a R_X86_64_RELATIVE relocation with addend 0 roots the control flow graph at the first byte of the segment, and the 0x64 of ld-elf decodes as an FS-prefixed instruction, which the Windows and macOS TLS rewriters refuse:

FAIL: Unsupported Windows guest TLS instruction (bytes: 64 2d 65 6c 66 2e) (offset 0x400a)

Linux output is unaffected because it keeps the guest %fs accesses. The trim now runs for both layouts, ending at the segment for an image without the block, and it takes an interpreter only when it starts the segment, so an interpreter that follows the code leaves the code in front of it alone. This is the PT_INTERP item of the remaining PS4 work in #3093.

The rebase keeps sceFunctions and the merged unwind ranges that #8166 added, and the SCE path still takes any interpreter inside the scanned range, as it did before this change.

Tested

Apple M5, macOS 26.4, AppleClang 21.0.0, relinker-only build, after the rebase onto main:

  • Native arm64: 225/225.
  • The 17 OpenOrbis homebrew executables (samples-elf-llvm-18.zip, v0.5.3) convert with --windows; on main they are refused with the message above. The 3 modules convert as before.
  • The edge case @wachi35676 found on the previous head still passes: an image whose PT_INTERP follows the code converts (rc 0), as it does on main.
  • interpreter_in_code covers three images: interpreter at the segment start, no interpreter, and interpreter after the code.
  • python3 tools/check_conventions.py --base origin/main passes.

On the previous head, @wachi35676 also ran Windows 11 and WSL (214/214 and 219/219) and checked that 4 PS5 homebrew titles relink byte-identically to main with --to-intel and --to-rosetta. Those runs predate this rebase.

No Linux or Windows host was available here.

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: n/a
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source: n/a
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4940105091 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8599). Originally posted by [javierUDP](https://github.com/javierUDP) on 2026-10-20T17:59:17Z. --- Reopens #7996, which closed when I republished its branch to rebase it. Same two commits, rebased onto current `main` as @oneandonlydean asked, with the conflict in `CodeInstructionCollector.cpp` resolved to keep both rules. ### What The code analysis trims an interpreter path from the start of an executable segment only for images that have a `PT_SCE_DYNLIBDATA` block. An executable without one keeps that path in the scanned range. `/libexec/ld-elf.so.1` then gets walked as code: a `R_X86_64_RELATIVE` relocation with addend 0 roots the control flow graph at the first byte of the segment, and the `0x64` of `ld-elf` decodes as an FS-prefixed instruction, which the Windows and macOS TLS rewriters refuse: ``` FAIL: Unsupported Windows guest TLS instruction (bytes: 64 2d 65 6c 66 2e) (offset 0x400a) ``` Linux output is unaffected because it keeps the guest `%fs` accesses. The trim now runs for both layouts, ending at the segment for an image without the block, and it takes an interpreter only when it starts the segment, so an interpreter that follows the code leaves the code in front of it alone. This is the `PT_INTERP` item of the remaining PS4 work in #3093. The rebase keeps `sceFunctions` and the merged unwind ranges that #8166 added, and the SCE path still takes any interpreter inside the scanned range, as it did before this change. ### Tested Apple M5, macOS 26.4, AppleClang 21.0.0, relinker-only build, after the rebase onto `main`: - Native arm64: 225/225. - The 17 OpenOrbis homebrew executables (`samples-elf-llvm-18.zip`, [v0.5.3](https://github.com/OpenOrbis/OpenOrbis-PS4-Toolchain/releases/tag/v0.5.3)) convert with `--windows`; on `main` they are refused with the message above. The 3 modules convert as before. - The edge case @wachi35676 found on the previous head still passes: an image whose `PT_INTERP` follows the code converts (rc 0), as it does on `main`. - `interpreter_in_code` covers three images: interpreter at the segment start, no interpreter, and interpreter after the code. - `python3 tools/check_conventions.py --base origin/main` passes. On the previous head, @wachi35676 also ran Windows 11 and WSL (214/214 and 219/219) and checked that 4 PS5 homebrew titles relink byte-identically to `main` with `--to-intel` and `--to-rosetta`. Those runs predate this rebase. No Linux or Windows host was available here. ### 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 - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's technical debt file: n/a - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source: n/a - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-20 18:15:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-20T18:15:27Z.


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
PR 6977 core/relinker/CMakeLists.txt
core/relinker/relinker/src/analysis/CodeInstructionCollector.cpp
PR 8076 core/relinker/relinker/src/analysis/CodeInstructionCollector.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6297905912 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8599#issuecomment-6297905912). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-20T18:15:27Z. --- <!-- 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` | | [PR 6977](https://www.github.com/boykopovar/AnyPS5/pull/6977) | `core/relinker/CMakeLists.txt`<br>`core/relinker/relinker/src/analysis/CodeInstructionCollector.cpp` | | [PR 8076](https://www.github.com/boykopovar/AnyPS5/pull/8076) | `core/relinker/relinker/src/analysis/CodeInstructionCollector.cpp` |
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!8599
No description provided.