fix(relinker): skip jump tables placed after a function's code #6618
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6618"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by Get-fix on 2026-10-15T23:13:24Z.
What
PS4 titles built with Sony's toolchain place a switch statement's jump table in the code segment, after the last instruction of the function that indexes it and inside the function's unwind range:
Code analysis decodes each function range from start to end, so it read these tables as instructions. The syscall scan and the call-site resolver sweep the whole executable segment, so they lost their instruction boundaries after each table. The conversion of two PS4 titles stopped on it (Windows,
--skip-sce-module). Bloodborne stops there onmain5d9dcc42d. Limbo first stops at a zero-length FDE, which #6619 handles, and then here:The new
FindInlineJumpTablesdecodes one function range. It follows the table address of each RIP-relativeleathrough 64-bit register moves, and records the address that amovsxdwith scale 4 indexes when it lies later in the same function. When decoding reaches the first such address, it checks that every dword from there to the end of the function is an offset, from the nearest table before it, to code before the first table. If so, the rest of the function is tables. Anything else is decoded as before, so code that only looks like a dispatch is still analysed.leato the table and decodes it.nops in the copies of the code that the syscall scan and the call-site resolver read. The output image is unchanged.The forms seen in the two titles are covered: the base in the register the
leawrites, in a register it was moved to, and inr13, whose SIB form carries an 8-bit displacement of 0. Limbo has 189 functions with such tables. Part of the PS4 work tracked in #3093.Tested
Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release,
BUILD_TESTING=ON, onmain5d9dcc42d:sce_inline_jump_tablestest converts PS4-layout fixtures for Windows and macOS, each with an unwind-covered function whose table entries begin with bytes no pass can decode (0f 79) or that carry anfsprefix (64). It covers four cases:r13form all convert, with the PLT call site still resolved;movsxdwhose base points 8 bytes before the table is not taken as a table, and the conversion fails as it does onmain;lea/movsxdwhose target is code that fails the check is still analysed: its unsupported TLS instruction is still reported.nopfill for the scans, code analysis decoding the tables, tables taken without the check, register moves not followed, ther13form rejected, the control-flow pass not kept out, table addresses kept in the instruction set.-DANYPS5_RELINKER_ONLY=ON): 178 of 178 tests pass. The relinker it builds converts Bloodborne. Limbo still stops at its zero-length FDE, which #6619 handles; with both, Limbo converts.libSceGnmDriver). The relinker's import audit reports Bloodborne with 180 of 686 imports absent and Limbo with 220 of 547.agc_driver_gpu_indirect_arguments_misaligned_writer_aheaddoes not compile with MinGW onmain(#6452 fixes it), andprx_thread_local_destructorsfails as it did onmain92cdc7b62on this machine without my changes.agc_driver_preparation_scope_settlefailed underctest -j8and passes when run alone.tools/check_conventions.pypasses.Not tested on Linux or macOS hosts.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-15T23:16:34Z.
I have open #6595, which carries the detector proposal attached to #3093 and includes synthetic detector/CFG cases. A local merge-tree check against your head reports conflicts in
CodeInstructionCollector.cppandRelinkerPipeline.cpp. The ranges differ: your detector scans inside an FDE range; #6595 also examines a bounded region after the FDE and requires decoded targets plus padding. I asked in #6595 whether we can combine these paths and keep both kinds of coverage. Your retail conversions add useful evidence for the in-FDE case.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T23:30:17Z.
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.
core/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/relinker/src/analysis/CodeInstructionCollector.cppcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/relinker/src/analysis/CodeInstructionCollector.cppcore/relinker/relinker/src/pipeline/RelinkerPipeline.cppcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/relinker/src/pipeline/RelinkerPipeline.cppcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtImported from boykopovar/AnyPS5. Originally posted by Get-fix on 2026-10-15T23:30:35Z.
@MarcZX100 Thanks. I replied on #6595 with what I found running it on the two titles: it leaves a trailing table in each, so neither converts with it yet. I also proposed a way to combine the two detectors there.
AI-assisted: yes (Claude Code).
🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-15T23:41:31Z.
Review: COMMENTED
Ran this on macOS, since the description lists no macOS host.
Setup: Apple M2 Max, macOS 27.2, Xcode 27 Apple Clang, relinker-only Release (
-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON). Headbf06a8e5conmain5d9dcc42d. Built natively for arm64 (Python 3.14), and as x86_64 under Rosetta with/usr/bin/python33.9.6.maina9fa0e8b0)The 3 x86_64 failures are the same on
main(pr_overlap_tools,release_package,linux_fixed_base, Python 3.10-only keyword arguments).sce_inline_jump_tablespasses on both builds, including under Python 3.9.Does the test catch the regression? I ran
test_sce_inline_jump_tables.pyagainst themainrelinker, case by case. Theplain,copyandr13cases fail for both--windowsand--macoswithCannot decode instruction: Unsupported 0F 79 opcode without SSE4A prefix (offset 0x9ff8). The two negative cases (r13-displacement,not-a-table) pass onmain, as they should. So the test does catch the regression on the macOS target too.Reduced layouts vs #6595. On #6595 you suggested a reduced copy of the Limbo and Bloodborne layouts. I tried some reductions on the test's fixture, with
--windowsand--macos:ret+ 2-bytenopbefore the table;cmp/jaguard to thatret;noploutside the FDE;ret,calland twonops;64 fbor65 fd.mainfails on each one, with the decode error orUnsupported Windows/macOS guest TLS instruction (bytes: 64 fb / 65 fd). #6595 (f25f22630) and #6618 convert all of them. So none of these features alone accounts for the retail stops. Whatever separates the two is something these reductions don't model, for example the real code and targets before the table.Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by savvaniss on 2026-10-18T20:46:19Z.
Windows data point from a second PS4 title: Hasbro Family Fun Pack (CUSA03312, my own dump) needs this PR for
--windows.Its bundled
libSceFios2.prxends the unwind function at0xe5d0–0xea98with a table of signed 32-bit offsets (54 fd ff ff,59 fd ff ff,64 fe ff ff, …), followed by NOP padding before the next function at0xeaa0. Without this PR, the Windows conversion stops on one of its entries:0x12a7cis the file offset of VA0xea7c(code at file0x4000, VA 0).Relinker-only Release build, Windows 11 Pro 26300, WinLibs GCC 15.2.0 r7, on
mainf3059421fwith #6619, #5138, #6357, #6684, #6381, #6354,3b158c1e4from #6977 and my gap-handling change for #3093. Adding this PR (bf06a8e5cmerged in; one conflict inRelinkerPipeline.cpp, kept both sides) makes the Linux and--windowsconversions of the eboot and its 9 modules complete, for both base 01.00 and patch 01.02.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T07:43:54Z.
Review: CHANGES_REQUESTED
#6595 is now merged and also detects relative jump tables inside and after a function's unwind range (
RelativeJumpTables.cpp: nop-filled scan copies inRelinkerPipeline.cpp,isDatahook in the CFG,tables/inTableinCodeInstructionCollector.cpp). This PR now conflicts inCodeInstructionCollector.cppandRelinkerPipeline.cpp, and keeping both would leave two detectors with two separate data-range mechanisms (inlineDatahere,tablesthere).Could you rebase on current
mainand:5d9dcc42d, before #6595;FindTrailingRelativeJumpTable/FindRelativeJumpTablesfor that case, with a fixture that fails on currentmain(the forms here: base moved to another register,r13with the 8-bit displacement, tables not followed by padding), instead of adding a second detector;Imported from boykopovar/AnyPS5. Originally posted by Get-fix on 2026-10-21T21:51:19Z.
@adriadam10 I re-ran everything on current
main(cecb540a6, with #6595, #8166 and #8168), with the relinker built frommainalone, on Windows 11 with WinLibs GCC 15.2:test_sce_inline_jump_tables.pyfrom this branch passes againstmain's relinker. That covers the plain table, the base copied to another register,r13, and the two forms that must still fail (the 8-bit displacement and code that isn't a table).--windows. Their bundledlibSceFios2.prxstops atInvalid guest TLS relocation, which isn't a table: the cause is a DTPMOD64 against a section symbol with index 0. With #9429 (that fix, split out of #6977), Bloodborne converts with all 7 of its modules and Limbo with both of its, and all 163 relinker tests pass.f3059421f, which predates #6595 (merged 19 Oct). @DealPotato closed #7620, the Second Son case built on this PR, because #6595 converts that eboot too.So
maincovers everything this PR was for, and I'm closing it as you suggested. @savvaniss, if Hasbro'slibSceFios2.prxtable still stops on currentmain, that case belongs inFindTrailingRelativeJumpTablewith a fixture, and I'm happy to help with it.AI-assisted: yes (Claude Code)
🤖 Generated with Claude Code
Pull request closed