fix(relinker): move in-place AMD-only replacements into a short instruction's stub #7999
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7999"
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 mopga on 2026-10-19T17:15:15Z.
What
A short AMD-only instruction lowered through a stub takes the following instructions with it until its site fits a jump. When one of them is an AMD-only instruction that is replaced in place (MOVNTSS, MOVNTSD, MONITORX, MWAITX, and RDSEED and CLWB for Rosetta),
MatchSequencefound no out-of-line lowering for it and the whole conversion failed withAMD-only instruction sequence has no out-of-line lowering.Reproduced with
relinker --to-intelon currentmainfor these code sequences, each followed byret;extrqalone converts:66 0F 79 C1 F3 0F 2B 07(extrq xmm0,xmm1; movntss [rdi],xmm0)0F 38 CC CA F2 0F 2B 0D <disp32>(sha256msg1 xmm1,xmm2; movntsd [rip+disp],xmm1)66 0F 79 C1 0F 01 FA(extrq xmm0,xmm1; monitorx)A following instruction with an in-place replacement now has that replacement moved into the stub, with a RIP-relative displacement relocated like any moved instruction. This applies only to
MatchSequencefollowers; out-of-line emission for 256-bit store windows (EmitOutOfLine) is unchanged, so a 256-bit store still does not take a following CLWB.Tested
Windows 11, AMD Ryzen 7 7800X3D (Zen 4), MinGW-w64 GCC 15.2.0 (WinLibs r7), relinker-only build of this branch on current
main:converterInPlaceFollowerinAmd64OnlyConverterTests.cpp(one trampoline each; MOVSS store bytes, the MOVNTSD relocation, and the MONITORX NOP before the return jump) fails onmainwithAMD-only instruction sequence has no out-of-line loweringand passes with the fix.relinker --to-intel.ctest: 211/211 passed.python3 tools/check_conventions.py --base origin/mainpasses. A trial merge with the open PRs that change these files (#2780, #7173, #7332, #7363, #7531, #7651, #7660) shows no conflict caused by this change.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 wachi35676 on 2026-10-19T23:18:05Z.
Verdict: confirmed on Windows and Linux. It merges and works together with #8001.
Environment: Windows 11 Home 10.0.26300, Ryzen 5 9600X (Zen 5), WinLibs GCC 15.2.0 r7, relinker-only Release build. This PR was merged onto
main9127ea36d, alone and together with #8001.Through the CLI: each sequence is the body of a
test_tls_function_coverage.pymake_imageimage, converted withrelinker --skip-sce-module.extrq/sha256msg1mainf3 0f 2b 07movntss--to-intelAMD-only instruction sequence has no out-of-line lowering (offset 0x1240)f2 0f 2b 0d 00 01 00 00movntsd [rip]--to-intel0f 01 famonitorx--to-intel0f 01 fbmwaitx--to-intel0f c7 f8rdseed--to-rosetta66 0f ae 37clwb--to-rosettaNegative control: with only
Amd64OnlyInstructionMatcher.cppreverted tomain,amd64_only_converter_testsfails withAMD-only instruction sequence has no out-of-line lowering.RIP-relative handling:
_emitInPlacepassesoffset + info.Length + displacementas the target relative to the instruction start. That matches the conventionScalarCompareOperands/WideStoreOperandsuse forRipRelative, and is correct here because each in-place replacement has the original length and keeps the original displacement.The moved follower is added to
consumed, so its own pending in-place item is skipped and it is not patched twice.ctest:-j4because of host load.shader_cache_runtime_sources, fails intermittently onmaintoo.Homebrew: PS5 OpenGL Showcase 1.0.2 (PPSA99005), PPSA47402, PS5LM Plus 0.8.4 (PPSA99581), and Prospero Win v0.2.0 (PPSA99995) with its 16 Wine modules, relinked with
--windows --to-intel,--macos --to-rosettaand Linux--to-intel. These produce up to 51131 Rosetta stubs. All 12 output sets are byte-identical tomain, so no existing lowering changed.Minor: a follower moved this way is not listed in
Reportsand is not counted inReplacedCount, so the summary line counts only the stub. This matches how other consumed followers are handled.AI-assisted: yes (Claude Code); results above were run on this machine.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-20T03:35:29Z.
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/codegen/tests/Amd64OnlyConverterTests.cpp