fix(relinker): keep FS and GS accesses out of AMD-only sites on Windows #27649
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/27649"
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 GiannisG1 on 2026-11-26T21:40:27Z.
What
On Windows,
WindowsPePatcher(andWindowsGuestModuleWriterfor guest modules) runsWindowsTlsBuilder::BuildbeforeWindowsTrampolineBuilder::Build. The TLS builder rewrites guestfs:/gs:accesses in the section bytes, and the trampoline builder then checks that each AMD-only site still has its original bytes. The AMD-only converter only stays clear of segment-prefixed instructions when it is created withkeepSegmentAccesses.Conversion.cppandGuestModuleBuilder.cpppassed that for macOS only (options.Target == TargetSystem::MacOs,macos). So on Windows, an AMD-only instruction too short for its jump could absorb thefs:access after it. The TLS builder then rewrote that access inside the site, and the conversion failed:This is the failure @akkadbakkad89 dumped for PPSA38500 in #27564 (issuecomment-7202722298): a 13-byte site of
vrcpps xmm4, xmm2(c5 f8 53 e2, the optional RCPPS lowering) and the followingmov rax, fs:[0], whose bytes had become the TLS builder'se9 … 90 90 90 90. The converter is now created with segment accesses kept on Windows as on macOS, for the executable and for the guest modules. A short site then does not take thefs:access, soWindowsTlsBuilderalone owns it. An optional lowering without room is kept, as RCPPS already is wherever its neighbours cannot move. Linux, which does not rewrite segment accesses, is unchanged. The same collision in the--frame-red-zonepath (a frame stub spanning anfs:/gs:access) is #27668. It touchesRedZoneFramer.cpponly, so the two are independent.Tested
Linux Mint 22.3, kernel 7.0.0, GCC 13.3, relinker-only build (
-DANYPS5_RELINKER_ONLY=ON). Head onmain7c5d920df6; it merges cleanly withmain00b15fcbb0.fsAccessAfterShortAmdOnlySiteinConversionTests.cpp. It converts an executable whose code isvrcpps xmm4, xmm2; mov rax, fs:[0]; ret(with aPT_TLSheader) with--to-intel, for Windows and for Linux. RED onmain: the Windows conversion throwsAMD-only site bytes changed before patching, the PPSA38500 error. GREEN 3/3 with the change.check_skips.py).--to-intelrelink A/B of all 223 ps5-homebrew-catalog titles, from the same build tree withmain'sConversion.cpp/GuestModuleBuilder.cppand with this change, outputs compared byte for byte. 222 are identical. PPSA99193 fails on both with the branch-entry failure that #27560 fixes. So no catalog title has a short AMD-only site next to anfs:/gs:access, and the change only affects conversions like PPSA38500's.e269ebc5d5and relinked PPSA38500 on Windows. Its eboot now converts completely with--to-intel(full instruction scan, PRX conversion, output image written, no FAIL; #27564, issuecomment-7206089884). Before, it stopped atAMD-only site bytes changed before patchingat RVA0xfe10fd. Booted on the same machine with a warm shader cache, the converted title runs at 29.97 fps, against 0.90-0.92 fps when its AMD-only instructions are trapped and emulated at run time instead (issuecomment-7206202354): same boot depth, no new crashes.check_conventions.py,check_test_registration.py(relinker build),check_compile.py(3 translation units) andcheck_main_sync.pyare clean.pr_overlap.py --branch: #24915 adds lines next to the same twoMakeAmd64OnlyConvertercalls (GuestModuleBuilder.cppL522,Conversion.cppL75) to record host CPU features. That is a textual conflict only, and whoever lands second keeps both. It could not compare #10861, #11525, #12678, #15245, #20389, #21877 and #24152, which conflict withmain. Of these, #11525, #12678 and #20389 rewrite those call lines from older bases, and none of them changes which targets keep segment accesses.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-intelconversion past this site (with #27560), as reported in #27564 and Game bring-up #27523🤖 Generated with Claude Code
Summary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-26T22:29:52Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this; the points below are optional.
What I ran
Reviewed head
9df408a0e57943ab5024dbb1377e337cb4dbb1ab. No test or build commands were run; the test results in the PR description are author-reported.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The full 1141-test run, Windows behavior, guest-module behavior, and reported catalog comparison were not independently verified. All three changed files were read:
core/relinker/relinker/src/guest/GuestModuleBuilder.cpp,core/relinker/relinker/src/pipeline/Conversion.cpp, andcore/relinker/relinker/tests/ConversionTests.cpp. The manifest lists three reviewed files; none were excluded. Relevant converter code incore/relinker/codegen/src/Amd64OnlyConverter.cppwas also read for context.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by fromthemoonx on 2026-11-26T22:35:30Z.
Review: APPROVED
Windows-host run, since the Tested section is a Linux build:
mainacf3fee1e5.ConversionTests.cpponmain,relinker_conversionfails withAMD-only site bytes changed before patching.relinker_conversionpasses, then passes again on 3 repeats.tools/check_conventions.pypasses on the head.The two changed lines match:
Conversion.cppnow uses its existingwindows || macoslocals (lines 55–56), andGuestModuleBuilder.cppuses the same expression.AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-11-27T05:17:36Z.
Review: APPROVED
Checked head
9df408a0e5. I applied it tomainad7582bad4together with #27680, #27668 and #27560, which touch different files. On Windows 11 with WinLibs GCC 15.2 (Release),tools/check_conventions.py --headon each head andtools/debt_fold.py --checkpassed, the build succeeded, and all 4,930 CPU tests passed (I left out the GPU tests). The ten relinker and codegen tests I ran for these four (amd64_only_converter,amd64_only_windows,red_zone_framer,red_zone_framer_execution,lane_split_lowering,relinker_conversionand four more) passed. Applied alone tomain, it also passes the seven conversion tests (amd64_only_converter,amd64_only_windows,relinker_conversion,conversion_diagnostics,mulx_conversion,relr_conversionandreplaced_plt_stubs_conversion).With
main'sGuestModuleBuilder.cppandConversion.cpp,relinker_conversionfails.Both
MakeAmd64OnlyConvertercall sites (GuestModuleBuilder.cppandConversion.cpp) now passwindows || macosaskeepSegmentAccesses, which wasmacosonly before. So Windows keeps FS and GS accesses out of AMD-only sites, as macOS already did.fsAccessAfterShortAmdOnlySiteconverts the same code for Windows and Linux.AI-assisted: yes (Claude Code)