Skip to content

fix(relinker): exclude trailing PS4 relative jump tables - #6595

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
MarcZX10:codex/ps4-relative-jump-tables-3093
Oct 19, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
MarcZX10:codex/ps4-relative-jump-tables-3093

Conversation

@MarcZX10

@MarcZX10 MarcZX10 commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

What

Carry the relative jump-table proposal attached to #3093, preserving the original author as co-author. On PS4 SCE executables, a trailing signed-relative jump table in or immediately after an unwind function can be decoded as instructions by the syscall scan, call-site scan, or code collector. This change detects the table from an RIP-relative LEA followed by an indirect jump, requires at least two entries targeting decoded instruction starts, and requires only padding after the table.

The pipeline scans a copy with detected table bytes replaced by NOPs. The code collector trims the unwind function at the table, excludes table addresses from roots, and stops CFG traversal at table ranges. This is limited to SCE dynamic executables/modules.

The implementation follows the proposal from @SuperCatElvis in #3093; that contributor requested carrying it with a co-author credit. Their issue report says the affected eboot passed the syscall and call-site scans with the patch applied and advanced to the next conversion stop. I did not run that eboot locally. This PR adds synthetic detector coverage because the original patch had no tests.

Related: #3093. This is separate from #6354, which finds the PLT before unwind code and changes code extent calculation.

Tested

Checklist

Co-authored-by: SuperCatElvis <39642318+SuperCatElvis@users.noreply.github.com>
@MarcZX10

Copy link
Copy Markdown
Contributor Author

CI follow-up: the relinker CTest suite now passes on Ubuntu (2m29s), Windows and macOS (2m57s). Eligibility, conventions and intake also pass. The AGC build jobs were skipped by the changed-path filter and do not cover this relinker-only change.

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

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 6618 core/relinker/relinker/src/analysis/CodeInstructionCollector.cpp L4, L116-117
core/relinker/relinker/src/pipeline/RelinkerPipeline.cpp L5
PR 7453 core/relinker/relinker/src/analysis/UnusedNidFilter/ControlFlowGraph.cpp L71
PR 7660 core/relinker/relinker/src/pipeline/RelinkerPipeline.cpp L374, L376-377, L385-386, L548-549, L551

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 6802 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/src/analysis/CodeInstructionCollector.cpp
core/relinker/relinker/src/pipeline/RelinkerPipeline.cpp
PR 7332 core/relinker/CMakeLists.txt

@MarcZX10

Copy link
Copy Markdown
Contributor Author

Manual check of the overlap warning for #6447: its CodeInstructionCollector.cpp change adds overflow validation to the existing fileOffset lambda. This PR adds the trailing jump-table scan/filter in Collect and the CFG data predicate. The edits are in separate logic, neither depends on the other, and I found no semantic overlap or merge dependency.

@jotitadev jotitadev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on Apple M2 Max, macOS 27.2, Xcode 27 clang, CMake 4.4.4 + Ninja, relinker-only Release.

Head f25f22630, merged onto main 5d9dcc42d (clean merge, no warnings).

Build main this PR
arm64 173/173 173/173
x86_64 under Rosetta, /usr/bin/python3 3.9 170/173 170/173

The 3 x86_64 failures are the same on main (pr_overlap_tools, release_package, linux_fixed_base) and are unrelated. control_flow_graph passes on both architectures.

Coverage note: the new test only reaches the detector (FindTrailingRelativeJumpTable / FindRelativeJumpTables). I disabled each integration point on top of the PR, one at a time, and the full suite still passed 173/173 every time:

  1. RelinkerPipeline.cpp: no table ranges filled with NOPs in the scan copy (the syscall and call-site scans see the original table bytes again).
  2. CodeInstructionCollector.cpp: no table ranges recorded and the unwind function not trimmed.
  3. ControlFlowGraph.cpp: the isData checks in enqueue and the decode loop removed.

So a regression in the part that fixes #3093 (the scans decoding the table) would not be caught. A small synthetic SCE input whose trailing table bytes contain a 0F 05 or a call-like pattern, run through the syscall scan path, would cover case 1.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

@MarcZX10

Copy link
Copy Markdown
Contributor Author

Good catch. The current test exercises detector output and CFG exclusion, but it does not verify the pipeline scan copy or code-collector trimming; disabling those integration points still leaves the suite green. A synthetic SCE fixture that puts a syscall/call-like pattern in the table would cover the path you describe. I will track that as a separate follow-up test PR, consistent with the repository rule to keep follow-up work on a new branch.

@MarcZX10

Copy link
Copy Markdown
Contributor Author

The new #6618/#6619 results on #3093 are useful. I compared #6595 with #6618: #6618 detects a table within an FDE range from its LEA/MOVSXD pattern, while #6595 searches the end of an FDE and a bounded range after it, requiring decoded targets and padding. They cover related table layouts, but both change CodeInstructionCollector.cpp and RelinkerPipeline.cpp; git merge-tree reports content conflicts in both. Could we coordinate a combined detector and integration so we keep the distinct range coverage and tests without carrying two competing scans? #6619 zero-length-FDE handling appears separate.

@Get-fix

Get-fix commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Thanks for comparing them, @MarcZX100, and for the offer to combine. I ran #6595 (f25f22630, relinker-only Release build, Windows, --skip-sce-module) on the two retail titles from #6618, using dumps of my own copies:

relinker Limbo (CUSA01664) Bloodborne (CUSA00900)
#6595 stops at the zero-length FDE (#6619) Unsupported Windows guest TLS instruction (bytes: 64 fb), file offset 0x11e26fc
#6595 + #6619 Unsupported Windows guest TLS instruction (bytes: 65 fd), file offset 0x1c829c same as above
#6618 (+ #6619 for Limbo) converts converts

Both stops are in trailing tables that #6595 leaves in the code:

  • Limbo: the stop is in the table at 0x1c427c of the function [0x1c3da0, 0x1c42c8).
    • Dispatch at 0x1c3de1: lea rcx, movsxd rax, [rcx+rax*4], add, jmp rax, behind cmp eax, 0x12; ja.
    • The table has 19 entries and ends at the FDE end. Before it are a ret at 0x1c4279 and a 2-byte nop. After it come an 8-byte nopl and the next function at 0x1c42d0.
  • Bloodborne: the stop is in the second of two consecutive tables at the end of the function [0x11ddcc0, 0x11de994).
    • The tables start at 0x11de674 and 0x11de804, with 100 entries each, and run to the FDE end.
    • Before them are a ret at 0x11de66c, a call at 0x11de66d and two nops.

I haven't pinned down where #6595 rejects them. In a debug build its TableEntries does count all 19 entries of the Limbo table in one pass, so a reduced copy of these two layouts may be the quickest way to find it. #6595 passes every case of the sce_inline_jump_tables test in #6618 (I ran that script against its relinker), so the synthetic fixtures don't separate the two; the titles do.

In the other direction, #6618 only looks inside the FDE range, so it does not handle tables in the gap after it, as in the Until Dawn report.

A proposal for one change:

I'm happy to do the combining on #6618 with you and @SuperCatElvis as co-authors. Or I can bring the in-range detection, its fixture and the title results to #6595, whichever you prefer.

AI-assisted: yes (Claude Code). The conversions above ran on my machine; no game files leave it.

🤖 Generated with Claude Code

@MarcZX10

Copy link
Copy Markdown
Contributor Author

Thanks for testing both detectors on the two titles and for sharing the layouts. This confirms #6618 covers the in-FDE trailing tables, while #6595 is aimed at the distinct bounded gap after an FDE (including the Until Dawn report). I suggest keeping the detector cases distinct for now; if #6618 lands first, I can rebase #6595 on it and resolve the shared integration points while preserving each change’s attribution. I will add the reduced in-FDE fixtures as a separate follow-up only if the current review needs that coverage.

@DealPotato

DealPotato commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Tested this branch (head f25f22630) on a real PS4 eboot: inFAMOUS Second Son (CUSA00004, my own dump). Windows 11 Pro, WinLibs GCC 15.2.0, relinker-only build, relinker --windows --skip-sce-module eboot.elf app.exe.

The eboot has the case this PR describes:

  • The function at 0x64c870 has an FDE ending at 0x64d0c3, after a call to a noreturn function and a nop.
  • Its switch table sits right after the FDE, at 0x64d0c4–0x64d104. It is loaded by lea rcx, [rip+0x6dd] at 0x64c9e0 and movslq (%rcx,%rax,4),%rax.
  • Multi-byte NOP padding follows the table up to the next function at 0x64d110.

Results:

AI-assisted: yes (Claude Code).

@MarcZX10

Copy link
Copy Markdown
Contributor Author

Thanks for testing the current head on inFAMOUS Second Son. This directly confirms the post-FDE, NOP-padded table case converts under Windows, and the comparison with #6618 helps distinguish it from the in-FDE detector. I added your reported setup and result to the PR’s Tested section with credit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants