fix(relinker): ignore direct branch targets inside an instruction past its prefixes #7651
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7651"
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 DavidSamir on 2026-10-18T20:14:49Z.
What
With
--macos --to-rosetta, SuperTuxKart (PPSA69421) and Mortalfin (PPSA99141) stop during instruction conversion:The branch is not real. Both titles link OpenSSL's x86-64 SHA-1 assembly, which keeps its signature string in the code segment, right before
sha1_block_data_order_avx2:The converter collects branch targets from a linear scan of the segment, so the string's
jaelands one byte into the store's VEX prefix and the store is refused. In both titles the only branch to that address is this one: a search of every rel8, rel32 and Jcc rel32 encoding in the file finds no other.Jump-table entries already count as targets only where a scanned instruction starts. This applies a narrower form of that rule to direct branches. A target inside a scanned instruction still counts where every byte before it is a legacy prefix or REX, so a branch that skips a
lockprefix, or the INSERTQ prefixes the existing test uses, still keeps the instruction in place. A target in a VEX prefix, opcode or operand bytes is ignored: executing from there does not run the instruction the scan decoded, and the conversion of that instruction already relies on that decode.Three commits:
fix(relinker): ignore direct branch targets inside an instruction past its prefixestest(relinker): a branch into a 256-bit store and into the instruction moved with it no longer keeps the store. The existing "branch into the compare keeps it native" case now uses the legacycmpsswith a branch past itsF3prefix, which still keeps it native; a new case shows that a branch past the VEX prefix ofvcmpssno longer does (it would executec2 ca 03,ret 0x3ca).docs(debt): the relinker debt file records the rule and what it gives up: a real branch into the middle of an instruction, as overlapping hand-written code can do, is not seen.Tested
macOS 26 on an Apple M2 (MoltenVK 1.4.x, Vulkan SDK 1.4.363), x86-64 build under Rosetta 2, Release, relinker-only build (
-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON).amd64_only_converter_tests: the new cases fail onmain(No room for a jump to the stub of 256-bit store within its neighbours or a nearby islandin the small fixture, where the false target also blocks the neighbour placement) and pass with this change. All other converter cases pass, the INSERTQ "Branch into an AMD-only instruction was accepted" check included.ctest: 192 of 192 pass.hardware_oracle_comparetimed out at 20 s once under-j8and passed alone in 5.6 s.--macos --to-rosettaand theirsce_module:mainBranch enters an AMD-only instructionForbidden syscall instruction at code offset 0xe2c3a7Branch enters an AMD-only instructionUnsupported macOS guest TLS instruction (bytes: 65 6e)libc.prxaborts withThread destructor callback is already registered, #7636) and @mugurc's macOS library series: the title starts, probes its video decoders, and on this M2 reportsNo device with Vulkan support found. That is the unhinted direct-memory placement in #1 (comment 6254181383). With that placement worked around locally, it selects the Apple M2 and stops at the MoltenVK pipeline error that #6235 covers (output of type float4 is not compatible with a MTLPixelFormatR8Uint color attachment). Nothing past that point is tested.--to-intel, but neither title reaches it there.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)--to-rosetta(no bring-up discussion)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-18T20:21:14Z.
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.
main)docs/dev/debt/relinker.mdL16Some 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.
docs/dev/debt/relinker.mddocs/dev/debt/relinker.mdImported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-18T20:52:07Z.
Windows host run, since the description covers macOS only. Radeon 860M (RDNA 3.5, driver 32.0.13058.8001), Windows 11 26300, WinLibs GCC 15.2.0 r7, Release,
BUILD_TESTING=ON. Build:maine8ad642fewith #7651, #7650, #7647, #7655 and #7648 merged together (each merge clean, built once).amd64_only_converterpasses 3 runs of 3.tools/title_run.py(#7264): SuperTuxKart (PPSA69421) reachesrenderingat 6.0 FPS and Mortalfin (PPSA99141) at 87.5 FPS, both runs. On thismainboth first abort at start-up withThread destructor callback is already registered(#7636, from #6112), so the title runs had #7646 merged as well.AI-assisted
Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-19T22:43:42Z.
Windows check,
main0929be5e8dagainstmainplus this head (clean merge). Windows 11 Pro 26300, WinLibs GCC 15.2.0, Ninja, Release.amd64_only_converterincluded.--trap-sdk-syscall-stubsand--windows, and again with--windows --to-intel. All eight relinks exit 0. The fourapp.exepairs are byte-identical betweenmainand this PR (md57a7a91a79d01,4f4cc5fcf4ae,b514585484ac,e4fbb3035d04).--to-intelruns make the same ones on both:INSERTQ at 0x352688in PPSA69421 andEXTRQ at 0x109d7ein PPSA99141.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-20T00:18:41Z.
Checked the branch-target rule against
DecodedInstruction::OpcodeOffset()(legacy/REX prefixes only, so VEX/opcode/operand targets are ignored and prefix-skipping branches still keep the instruction native), the new and changed converter tests, the debt line and the relinker CI jobs (Linux, Windows, macOS incl. x86_64, asan); merged.