fix(relinker): resync the syscall scan past undecodable data regions #8042
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8042"
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 plokmklo on 2026-10-19T18:39:54Z.
What
The syscall scan walks each executable segment linearly and any single undecodable byte failed the whole conversion with
Cannot decode instruction. Real PRXs carry data inside executable segments — jump tables, constants, handler tables — soubiservices.prxof The Rogue Prince of Persia (PPSA28155) stops dead at bare0F 78(offset 0xF72B9B), which is data, not an instruction: bare0F 78has no SSE4A meaning (EXTRQ needs 66, INSERTQ needs F2) and AMD64 has no VMREAD.CodeInstructionCollector's padded scan already treats such regions as data; the discovery walk now does the same behind an explicit opt-in:MakeInstructionScanner(progress, resyncUndecodable). Resync prefers the next 16-byte boundary preceded by two0xCCbytes (a genuine instruction boundary after function padding) and advances one byte when none remains.SyscallScanneropts in — it only discovers and refuses, it never rewrites.The default stays STRICT:
Amd64OnlyConverter's rewrite walk must keep failing loudly on an undecodable byte, because silently leaving one unconverted would corrupt the output binary.converterFailureOffsetspasses unchanged.Tested
Ubuntu 24.04:
amd64_only_converter(newscannerEmbeddedDataResynccase: embedded data no longer fails the resyncing scan, surrounding instructions still reported, truncated non-zero tail resyncs, strict default still refuses both),relinker_conversion,sdk_mman_syscall,call_site_resolver,conversion_diagnosticsall pass. Cannot reproduce the PPSA28155 module itself (binary not available); the failing pattern is covered byte-for-byte in the new test.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)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-19T20:08:00Z.
I reproduced the Linux CI test failure on this head: the relinker-only build succeeds, but
ctest --test-dir build-relinker --output-on-failureis 215/216, withexecutable_segmentsfailing itsrex-syscallcase. That fixture expects a truncated nonzero instruction tail to fail with exit code 2 and produce no output; becauseSyscallScanneropts into resync for every segment, conversion now succeeds. The new scanner test checks that the defaultMakeInstructionScanner()stays strict, but it does not cover the production syscall scanner's opt-in path. Please preserve the rejection of a truncated nonzero tail while allowing the embedded-data case, and cover both throughSyscallScanner.The conventions check also fails because the
Depends onandUnblockschecklist boxes are left unchecked. Please mark the dependency as none and fill the Unblocks item in the required format.Validation here: Ubuntu Linux, GCC 12.2, Release;
cmake --build build-relinker --parallel 4passes. Full CTest: 215/216, onlyexecutable_segmentsfails as described. I have not run the target module because its binary was not supplied.Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-19T23:17:49Z.
Verdict: defect. With resync on, a forbidden syscall that follows undecodable bytes is skipped and the conversion succeeds.
SyscallScanneris the only check that refuses forbiddensyscallinstructions, and with this change it resyncs to the next 16-byte boundary preceded bycc cc. Any code between the undecodable byte and that boundary is never decoded. Probe image:make_image("register", "unwind", body=c3)fromtest_tls_function_coverage.py, with these bytes at file/vaddr 0x1600 outside the unwind function:mainmain9127ea36d)Cannot decode instruction: Unsupported 0F 78 opcode without SSE4A prefix (offset 0x1600)0f 0590(control)Forbidden syscall instruction at code offset 0x1606Both results are the same for the Linux default and
--windows. A refusal therefore turns into an output that runs the rawsyscall. Only a scan with nocc ccboundary before the end of the segment falls back to+1stepping.Also reproduced on Windows:
executable_segmentsfails on therex-syscallcase, as @MarcZX10 reported for Linux. The truncated nonzero tail now converts (assert result.returncode == 2 and not output.exists(), caserex-syscall). Results:ctest211/212, with onlyexecutable_segmentsfailing.executable_segmentsandshader_cache_runtime_sourcesfailing. The second also fails onmainthere.executable_segmentsstill fails on Linux.On the four homebrew titles I have (PPSA99005, PPSA47402, PPSA99581, and PPSA99995 with its Wine modules), relinked for Windows, macOS/Rosetta and Linux, the outputs are byte-identical to
main. None of them hit an undecodable byte, so they don't exercise the change.AI-assisted: yes (Claude Code); results above were run on this machine.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-19T23:21:19Z.
I reproduced the Linux CI test failure on this head: the relinker-only build succeeds, but
ctest --test-dir build-relinker --output-on-failureis 215/216, withexecutable_segmentsfailing itsrex-syscallcase. That fixture expects a truncated nonzero instruction tail to fail with exit code 2 and produce no output; becauseSyscallScanneropts into resync for every segment, conversion now succeeds. The new scanner test checks that the defaultMakeInstructionScanner()stays strict, but it does not cover the production syscall scanner's opt-in path. Please preserve the rejection of a truncated nonzero tail while allowing the embedded-data case, and cover both throughSyscallScanner.The conventions check also fails because the
Depends onandUnblockschecklist boxes are left unchecked. Please mark the dependency as none and fill the Unblocks item in the required format.Validation here: Ubuntu Linux, GCC 12.2, Release;
cmake --build build-relinker --parallel 4passes. Full CTest: 215/216, onlyexecutable_segmentsfails as described. I have not run the target module because its binary was not supplied.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T01:43:42Z.
Thanks for this. #8076 targets the same crash, and we're going to carry the fix there: its remaining issue is narrower, and both PRs can't land together because they break executable_segments. Your review on #8076 is very welcome. We'll close this once #8076 merges.
Pull request closed