fix(relinker): initialize main guest MXCSR at entry #7594
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7594"
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 MarcZX10 on 2026-10-18T16:19:06Z.
What
The main guest ELF entry runs directly from the relinker startup stubs and bypasses
Aps5CallGuestEntry_nid_no_patch, which is covered separately by #7565. This change initializes MXCSR to the measured PS5 payload value0x9fc0immediately before the main guest entry on the Linux and Windows startup stubs, then restores the host MXCSR after the entry returns. It leaves the existing frame record intact and preserves stack alignment. It complements #7565 and does not close #7548; the macOS launcher path is outside this change.Tested
entry_stubchecks emitted Linux and Windows startup stub instructions, including setting guest MXCSR and restoring host MXCSR.linux_entry_argvexercises the Linux entry stub, including its rel32 call range and argument handling.python3 tools/check_conventions.py --base upstream/mainpassed;git diff --checkpassed.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 oneandonlydean on 2026-10-18T16:52:21Z.
The stubs look right. One question before merge: with the main thread (here) and created guest threads (#7565) at 0x9fc0, host code called from the guest, and host threads created from a guest thread on Linux (which inherit MXCSR), will run with FTZ/DAZ. Which host work runs in that context, especially the shader recompiler's constant folding and the driver workers? Should host-owned worker threads set the host default MXCSR when they start, so console FP semantics stay on guest code?
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T17:30:56Z.
You're right to flag this. Once guest entry installs
0x9fc0, host calls made synchronously on that guest thread also execute with FTZ/DAZ set. On Linux, astd::threadcreated from that context inherits its creator's floating-point environment unless its entry explicitly resets it. The code has lazily created host workers in graphics/pipeline paths, so the worker-entry boundary needs an audit too. I have not established that every such worker performs floating-point recompiler or driver work, and I do not want to claim that the current setting is harmless. This PR only sets the required MXCSR around the main guest entry; isolating host work is a separate follow-up concern.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T17:41:33Z.
I opened follow-up #7622 for host-owned worker startup. It resets MXCSR to 0x1f80 at native worker entry, including the shader registration pool trampoline, and adds a focused regression checking worker and caller MXCSR independently. The change covers native std::thread creation sites; guest-created threads remain under guest MXCSR semantics. Linux focused test and conventions pass. Full project configuration is blocked in this checkout by the missing SDL2 submodule and XRandR development support, so broader CI is still needed.
Imported from boykopovar/AnyPS5. Originally posted by hugodearaujo on 2026-10-18T17:42:00Z.
#7532 changes the same Linux entry stub: when
libkernel.prxis in DT_NEEDED, the stub callsEnterGuestMainStack_nid_no_patchthrough a GLOB_DAT slot instead of calling the entry directly, so the title's main thread runs on a stack at the console's address. The two changes conflict only inEntryStubBuilder.cppand fit together:EnterGuestMainStack_nid_no_patchdoes not touch MXCSR, so the value this PR sets before the call reaches the entry unchanged. Whichever lands second can be rebased onto the other; I'm fine either way. Which order do you prefer?Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T17:50:36Z.
I recommend merging #7532 first, then rebasing #7594 onto it and checking the combined Linux entry path. #7532 changes the startup call target to EnterGuestMainStack_nid_no_patch, which switches stacks and calls the ELF entry itself. With #7594 layered outside that helper, MXCSR 0x9fc0 does reach the ELF entry, but the outer stub’s restore-after-call instruction is unreachable on that route because the helper ends with ud2 after the guest entry returns. The combined code should either restore host MXCSR inside the helper after the entry returns, or explicitly document why the Linux path cannot return; its test should assert the composed call shape. Windows remains independent. This is an integration/rebase concern, not a reason to hold either change if the owners are ready to coordinate.
Imported from boykopovar/AnyPS5. Originally posted by DProkos on 2026-10-18T19:33:45Z.
Windows check of eae903496 merged onto current
main(c4c2b3aa7, clean merge).Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7 UCRT, Ninja, Release,
ANYPS5_RELINKER_ONLY=ON,BUILD_TESTING=ON, Python 3.11.0.entry_stub: passed.Negative control: with
EntryStubBuilder.cppandWindowsEntryStubBuilder.cpprestored tomainand the new test kept,entry_stubfails withthe stub does not initialize MXCSR before guest entry.Not run: titles or homebrew, so MXCSR at guest entry was only checked through the emitted stub, not in a running title.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T22:09:28Z.
Thanks for the Windows recheck on
eae903496. Theentry_stubpass, 196/196 relinker tests, and negative control confirm the emitted MXCSR setup on Windows. This is a Windows stub result; the title-level MXCSR value is still not measured. The separate #7532 Linux call path remains an integration point to resolve when that dependency lands.Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-19T07:42:40Z.
Rebase handoff — rebased onto current
main(authorship unchanged). Conflicts resolved: the CMake registration inmain's single-line form, the test includes unioned, andmain's helper forms kept where both sides had evolved the same helpers.Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release,
BUILD_TESTING=ON, AMD RX 9070 XT / RADV): builds; the entry-stub tests pass; conventions pass; full suite green apart from the four knownmainregressions (#5444 Mesa, #7584 BDA, #7766, #7784), none from this PR.To pick it up:
Head is
86a6d668c.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-19T08:22:13Z.
Thanks for the rebase, @blawesom. The production changes carry over line for line, and keeping
main's single-line CMake registration is right.One thing got lost in the conflict resolution: the Windows test
windowsStubInitializesMxcsrBeforeGuestEntry()incore/relinker/elfpatcher/tests/EntryStubTests.cpp(and its call inmain(), afterwindowsStubRejectsAnOverlongAllocatorPath();) isn't in86a6d668c. Only itsWindowsImportBuilder.hppinclude survived. Without it, theWindowsEntryStubBuilder.cppchange has no test. We restored it verbatim on top of your rebase:entry_stubpasses, and withmain'sWindowsEntryStubBuilder.cppit fails with "the Windows stub does not initialize MXCSR immediately before guest entry", so it still catches the regression it was written for.Also, the pick-up steps won't work as written:
86a6d668cisn't a descendant of the PR headeae903496, sogit merge --ff-only FETCH_HEADwill refuse. Either of these works:cc @MarcZX10: whichever route you prefer, please keep the Windows test. Merge order is unchanged: #7532 first, then this PR's combined Linux entry path gets re-checked.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-19T16:00:03Z.
Thanks for the rebase review. I checked the current PR head
9ebc1073381bed08382b368f8926438984781fab: it containswindowsStubInitializesMxcsrBeforeGuestEntry()and calls it frommain()immediately afterwindowsStubRejectsAnOverlongAllocatorPath(), so the Windows regression test is present. The hosted relinker matrix and conventions checks on this head are green; Linux/Windows full Build jobs are skipped by the workflow.Imported from boykopovar/AnyPS5. Originally posted by DProkos on 2026-10-19T19:11:57Z.
Windows re-check of the rebased head
9ebc10733merged onto currentmain(585075cb7, clean merge).Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7 UCRT, Ninja, Release,
ANYPS5_RELINKER_ONLY=ON,BUILD_TESTING=ON, Python 3.11.0.entry_stub: passed.Negative control, Windows part only: with only
WindowsEntryStubBuilder.cpprestored tomain,entry_stubfails withthe Windows stub does not initialize MXCSR immediately before guest entry. So the restoredwindowsStubInitializesMxcsrBeforeGuestEntry()runs and catches the Windows change on its own.Not run: titles or homebrew.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-19T20:27:06Z.
Thanks for the Windows re-check and negative control. The full relinker suite passes 212/212 on the rebased head, and restoring the Windows stub to main makes the new focused assertion fail as expected. That confirms the regression test detects the Windows entry-stub change. I’ll keep the validation claim scoped to the relinker tests; no title or homebrew run was made.
Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-20T14:05:04Z.
Windows title-level check of
9ebc10733, stacked with #7622 (50c1efcf5) onmain1d4164552(clean merge; also merges cleanly ontod50ec76da).Windows 11 Pro 26220, NVIDIA GeForce RTX 4070 (driver 596.21), Ryzen 7 5700X, WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release,
BUILD_TESTING=ON. Builtrelinker, the relinker tests andlibs(not the fullalltarget).Tests
entry_stubandlinux_entry_argv: 3/3 each.core/relinker, serial): one serial pass, 152/154. The other 2 (tls_function_coverage_register_address_loads,windows_diagnostic_fixture_isolation) hit their hard 30 s limit on my loaded host and pass when run directly (14.2 s and 2.9 s). I did not finish a 3x repeat of the whole suite.WindowsEntryStubBuilder.cppfrommain,entry_stubfails withthe Windows stub does not initialize MXCSR immediately before guest entry. With both stub builders frommainit fails withthe stub does not initialize MXCSR before guest entry. With the PR files back: 3/3 pass.Relink of my local titles (
--windows, main relinker vs this PR): 50 relink on both sides, PPSA99360 fails identically (Base relocation target crosses a page boundary). All 50app.exediffer. All*.registry.json,*.needed.jsonand guest.prxoutputs are byte-identical. The relinker is deterministic: same sha256 over repeated runs. For PPSA99005 the diff is the PE checksum, four displacement bytes and one run starting at the newldmxcsrsequence, which occurs exactly once.MXCSR in running titles. I read
CONTEXT.MxCsrfrom every thread withGetThreadContextat 15 s and 40 s:0x1fa30x9fe10x1fa30x9fe10x1fa00x9fe00x9fc0)0x1fa30x1fa3So on Windows the guest main thread does run with FTZ/DAZ (
0x9fc0plus sticky flags), and on Showcase and Ping Pong no other thread does. The RetroArch picker resets MXCSR itself after entry, even though its relinked exe has the new stub. A byte scan findsldmxcsrencodings inpicker.binand none in the Showcase or Ping Pong eboots. I did not trace which code does it.Titles, 60 s each, main vs PR (same harness, display on):
QUAKE ERROR: W_LoadWadFile: couldn't load gfx.wad(missing data).FAILED after 18.24 s/14.68 s: Fatal : VkResult is ERROR_DEVICE_LOST. That picker device loss also shows up in older main-only runs I have, and 2 of 6 vs 0 of 6 is not significant (p ≈ 0.45). So I am not counting it for or against this PR.There is no
FAIL:,FATAL:,not implementedorwhat()line in any run. Frame dumps are not time-aligned, so they cannot show a float difference: 2 of 12 Ping Pong dump pairs are bit-identical and the rest differ by animation phase.check_conventions.py --base origin/mainpasses andgit diff --checkis clean.Not checked: Linux and the composed #7532 entry path, macOS, the full test suite and GPU tests, and the MXCSR value at the exact entry instruction (I sampled at 15 s and 40 s).
Written with Claude Code assistance (validation by a subagent, reviewed in this session).
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T21:48:07Z.
Thanks for the detailed Windows title-level comparison. The negative controls establish the MXCSR setup difference, and the title results distinguish the entry-stub behavior from the RetroArch picker resetting MXCSR later. I’ve noted the two serial timeout cases passed directly, and that Linux, macOS and exact-entry sampling remain untested.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-02T04:56:58Z.
Review: COMMENTED
Replies checked — MXCSR value matches the code, console log is external
The entry stub at this head writes MXCSR 0x9fc0 before guest entry, which is the value the reviewers' evidence points to, and the console figure they cite was not checked here.
What I ran
58581509c5d1cdda8164287688525e542483f465(OPEN, unchanged from batch).gh apicomments and reviews on #7594, newer than 2026-10-20T21:48:07Z, excluding MarcZX10 and bots.gh pr view 7594 --json statusCheckRollup.git show 58581509:core/relinker/elfpatcher/src/general/EntryStubBuilder.cpp;git grepfor MXCSR in the head and upstream/main.git merge-tree --write-tree upstream/main 58581509(exit 0).Results
merge-treevs upstream/mainwindowsaggregate,linux,register-context,write-watchSKIPPEDFindings
0x9fc0atEntryStubBuilder.cppL26-L32 before the call, and restores the host value at L44-L48. Main has no MXCSR code in this file. Not reproduced.Sources
github.com/boykopovar/AnyPS5@58581509c5/core/relinker/elfpatcher/src/general/EntryStubBuilder.cpp (L26-L32)github.com/boykopovar/AnyPS5@58581509c5/core/relinker/elfpatcher/src/general/EntryStubBuilder.cpp (L44-L48)Not verified
HARDWARE_FINDINGS.md) cited by p3n1cillin.