fix(relinker): skip jump tables placed right after a function's unwind range #7620

Closed
DealPotato wants to merge 2 commits from upstream-pr/7620 into main
DealPotato commented 2026-10-18 17:36:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DealPotato on 2026-10-18T17:36:34Z.


What

Some PS4 executables put a switch jump table right after the FDE of the function that reads it. #6618 only finds tables inside the function's unwind range, so code analysis decodes such a table's entries as instructions and the conversion stops.

inFAMOUS Second Son (CUSA00004) does this:

  • The function at 0x64c870 has an FDE ending at 0x64d0c3. It ends with a call to a noreturn function (call 0x984360) and a nop.
  • Its switch loads a table at 0x64d0c4: lea rcx, [rip+0x6dd] at 0x64c9e0, then movslq (%rcx,%rax,4),%rax.
  • The lea adds 0x64d0c4 as a code root, and the conversion fails:
FAIL: Unsupported Windows guest TLS instruction (bytes: 65 ff ff) (offset 0x6510cc)

The change:

  • FindTrailingJumpTables tracks the same lea and movsxd table loads as FindInlineJumpTables, now shared through one helper. It does this for table bases between the function's end and the next function, or the end of the code segment.
  • A table ends at its first entry whose target falls outside the function.
  • CodeInstructionCollector adds these tables to inlineData, so the CFG neither enters them as roots nor reaches them by fall-through.
  • RelinkerPipeline fills them with nop before the syscall scan, as it already does for tables inside the function.

test_sce_inline_jump_tables.py gains a trailing fixture: the plain table with the FDE ending at the table. Without the change, it fails with Cannot decode instruction at the table.

Tested

  • Build and tests: Windows 11 Pro, WinLibs GCC 15.2.0, relinker-only build. All 193 relinker tests pass.
  • Second Son eboot: converted with --windows --skip-sce-module. On this branch without the last commit, i.e. main + #6618, it fails with the error above. With it, it converts.
  • Second Son with modules: with the rest of the PS4 relinker fixes (#6977's branch), the eboot and its bundled libc.prx and libSceFios2.prx convert.
  • Not tested: Linux, macOS.

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 (none added)
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: #6618 (its commit is the first one on this branch)
  • Fixes: none
  • Unblocks: none (CUSA00004 conversion; reported in #6977, no bring-up discussion yet)
  • GPUs tested: n/a
  • AI-assisted: yes (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4911276359 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7620). Originally posted by [DealPotato](https://github.com/DealPotato) on 2026-10-18T17:36:34Z. --- ### What Some PS4 executables put a switch jump table right after the FDE of the function that reads it. #6618 only finds tables inside the function's unwind range, so code analysis decodes such a table's entries as instructions and the conversion stops. inFAMOUS Second Son (CUSA00004) does this: - The function at `0x64c870` has an FDE ending at `0x64d0c3`. It ends with a call to a noreturn function (`call 0x984360`) and a `nop`. - Its switch loads a table at `0x64d0c4`: `lea rcx, [rip+0x6dd]` at `0x64c9e0`, then `movslq (%rcx,%rax,4),%rax`. - The `lea` adds `0x64d0c4` as a code root, and the conversion fails: ``` FAIL: Unsupported Windows guest TLS instruction (bytes: 65 ff ff) (offset 0x6510cc) ``` The change: - `FindTrailingJumpTables` tracks the same `lea` and `movsxd` table loads as `FindInlineJumpTables`, now shared through one helper. It does this for table bases between the function's end and the next function, or the end of the code segment. - A table ends at its first entry whose target falls outside the function. - `CodeInstructionCollector` adds these tables to `inlineData`, so the CFG neither enters them as roots nor reaches them by fall-through. - `RelinkerPipeline` fills them with `nop` before the syscall scan, as it already does for tables inside the function. `test_sce_inline_jump_tables.py` gains a `trailing` fixture: the `plain` table with the FDE ending at the table. Without the change, it fails with `Cannot decode instruction` at the table. ### Tested - **Build and tests:** Windows 11 Pro, WinLibs GCC 15.2.0, relinker-only build. All 193 relinker tests pass. - **Second Son eboot:** converted with `--windows --skip-sce-module`. On this branch without the last commit, i.e. `main` + #6618, it fails with the error above. With it, it converts. - **Second Son with modules:** with the rest of the PS4 relinker fixes (#6977's branch), the eboot and its bundled `libc.prx` and `libSceFios2.prx` convert. - **Not tested:** Linux, macOS. ### 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 (none added) - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source (none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: #6618 (its commit is the first one on this branch) - [x] Fixes: none - [x] Unblocks: none (CUSA00004 conversion; reported in #6977, no bring-up discussion yet) - [x] GPUs tested: n/a - [x] AI-assisted: yes (Claude Code)
github-actions[bot] commented 2026-10-18 17:52:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-18T17:52:54Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 6595 core/relinker/relinker/src/analysis/CodeInstructionCollector.cpp L4, L116-117
core/relinker/relinker/src/pipeline/RelinkerPipeline.cpp L6, L366
PR 6977 core/relinker/relinker/include/relinker/analysis/InlineJumpTables.hpp
core/relinker/relinker/src/analysis/InlineJumpTables.cpp
core/relinker/relinker/tests/test_sce_inline_jump_tables.py

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 2780 core/relinker/CMakeLists.txt
PR 5021 core/relinker/CMakeLists.txt
PR 6044 core/relinker/CMakeLists.txt
PR 6879 core/relinker/CMakeLists.txt
PR 6974 core/relinker/relinker/src/analysis/CodeInstructionCollector.cpp
PR 6977 core/relinker/CMakeLists.txt
core/relinker/relinker/include/relinker/analysis/InlineJumpTables.hpp
core/relinker/relinker/src/analysis/CodeInstructionCollector.cpp
core/relinker/relinker/src/analysis/InlineJumpTables.cpp
core/relinker/relinker/src/pipeline/RelinkerPipeline.cpp
core/relinker/relinker/tests/test_sce_inline_jump_tables.py
PR 7173 core/relinker/CMakeLists.txt
PR 7332 core/relinker/CMakeLists.txt
PR 7531 core/relinker/CMakeLists.txt
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6253168036 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7620#issuecomment-6253168036). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-18T17:52:54Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | [PR 6595](https://www.github.com/boykopovar/AnyPS5/pull/6595) | `core/relinker/relinker/src/analysis/CodeInstructionCollector.cpp` [L4](https://github.com/boykopovar/AnyPS5/blob/8d17389a73852ee0e462c640589b47d49c68e8d6/core/relinker/relinker/src/analysis/CodeInstructionCollector.cpp#L4), [L116-117](https://github.com/boykopovar/AnyPS5/blob/8d17389a73852ee0e462c640589b47d49c68e8d6/core/relinker/relinker/src/analysis/CodeInstructionCollector.cpp#L116-L117)<br>`core/relinker/relinker/src/pipeline/RelinkerPipeline.cpp` [L6](https://github.com/boykopovar/AnyPS5/blob/8d17389a73852ee0e462c640589b47d49c68e8d6/core/relinker/relinker/src/pipeline/RelinkerPipeline.cpp#L6), [L366](https://github.com/boykopovar/AnyPS5/blob/8d17389a73852ee0e462c640589b47d49c68e8d6/core/relinker/relinker/src/pipeline/RelinkerPipeline.cpp#L366) | | | | [PR 6977](https://www.github.com/boykopovar/AnyPS5/pull/6977) | | | `core/relinker/relinker/include/relinker/analysis/InlineJumpTables.hpp`<br>`core/relinker/relinker/src/analysis/InlineJumpTables.cpp`<br>`core/relinker/relinker/tests/test_sce_inline_jump_tables.py` | 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 2780](https://www.github.com/boykopovar/AnyPS5/pull/2780) | `core/relinker/CMakeLists.txt` | | [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 6879](https://www.github.com/boykopovar/AnyPS5/pull/6879) | `core/relinker/CMakeLists.txt` | | [PR 6974](https://www.github.com/boykopovar/AnyPS5/pull/6974) | `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/include/relinker/analysis/InlineJumpTables.hpp`<br>`core/relinker/relinker/src/analysis/CodeInstructionCollector.cpp`<br>`core/relinker/relinker/src/analysis/InlineJumpTables.cpp`<br>`core/relinker/relinker/src/pipeline/RelinkerPipeline.cpp`<br>`core/relinker/relinker/tests/test_sce_inline_jump_tables.py` | | [PR 7173](https://www.github.com/boykopovar/AnyPS5/pull/7173) | `core/relinker/CMakeLists.txt` | | [PR 7332](https://www.github.com/boykopovar/AnyPS5/pull/7332) | `core/relinker/CMakeLists.txt` | | [PR 7531](https://www.github.com/boykopovar/AnyPS5/pull/7531) | `core/relinker/CMakeLists.txt` |
DealPotato commented 2026-10-18 18:07:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DealPotato on 2026-10-18T18:07:09Z.


Closing in favour of #6595, which handles the same case and converts the Second Son eboot that motivated this PR.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6253316412 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7620#issuecomment-6253316412). Originally posted by [DealPotato](https://github.com/DealPotato) on 2026-10-18T18:07:09Z. --- Closing in favour of #6595, which handles the same case and converts the Second Son eboot that motivated this PR.

Pull request closed

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!7620
No description provided.