Repository navigation
fix(relinker): initialize MXCSR in macOS guest entry - #7741
Conversation
jotitadev
left a comment
There was a problem hiding this comment.
Native macOS run of the new stub, since the description has none. Apple M2 Max, macOS 27.2, Apple clang 21, head b5d55bd80 merged on main 4ffb0cd12.
-
Relinker-only Release, Python 3.9.6:
ctest201/201 on arm64 and on x86_64 under Rosetta 2. On the base relinker,macos_outputwith the new check fails withentry stub does not save host MXCSR and load guest MXCSR 0x9fc0, and it passes with the fix. -
Rosetta 2 runtime: an x86_64 probe that runs the exact stub bytes (
mov rsi, rsp,sub rsp, 0x10/stmxcsr/mov dword [rsp+4], 0x9fc0/ldmxcsr,call [rip+slot],ldmxcsr [rsp]/add rsp, 0x10) around a C callee:- the callee reads MXCSR
0x9fc0; - DAZ takes effect: a denormal f32 input times 1.0 gives 0, and the host gives 1e-39;
- FTZ takes effect: 1.5e-38 * 0.5 gives 0;
- after the call returns, the host MXCSR (
0x1f80plus its sticky flags) is restored.
So Rosetta 2 accepts the DAZ bit in
ldmxcsrwithout a fault and applies both modes. - the callee reads MXCSR
Not tested: a full relinked title through LC_MAIN.
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
…est entry (@MarcZX10) This branch gathers the open macOS work, and this PR is part of it: it is merged here with its author credited, so the integration carries it now and merging it first in main only shrinks this branch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for the native macOS and Rosetta validation. The relinker-only suite passes 201/201 on both arm64 and x86_64, and the negative control fails with the expected missing guest MXCSR setup. The runtime probe also confirms the stub restores host MXCSR on return. This fills the native macOS evidence gap for the current change; I’ll keep the exact tested head and scope in the PR record. |
|
Manual overlap check for #8658 against #7741, using the current GitHub heads ( |
|
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.
|
|
Checked the stub bytes on current |
What
The macOS Mach-O
LC_MAINentry stub calls the bound guest-start routine without applying the measured PS5 payload MXCSR to the main guest thread. Save the host MXCSR in aligned stack storage, load guest MXCSR0x9fc0immediately before the start call, and restore the host value if the call returns. The guest stack pointer is captured before the temporary slot is allocated. This complements #7594's Linux and Windows main-entry paths and #7565's created-thread path.Tested
Linux x86_64, GCC 12.2.0, relinker-only Release build. Full CTest: 210/210 passed. The
macos_outputtest checks the emitted setup and restore instructions, the guest entry target, and the bound start slot.python3 tools/check_conventions.py --base upstream/mainpassed.python3 tools/pr_overlap.py --branch codex/macos-main-thread-mxcsrreported no overlap. No native macOS runtime test was run.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)