Skip to content

Fix GH-18136: tracing JIT floating point register clobbering on Windows and ARM64 #18352

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: PHP-8.4
Choose a base branch
from

Conversation

nielsdos
Copy link
Member

@nielsdos nielsdos commented Apr 18, 2025

On win64, xmm6-xmm15 are preserved registers, but the prologues and epilogues of JITted code don't handle these. The issue occurs when calling into the JIT code again via an internal handler (like call_user_func). Therefore, we want to save/restore xmm registers upon entering/leaving execute_ex. Since MSVC x64 does not support inline assembly, we create an assembly wrapper around the real execute_ex function.
The alternative is to always save/restore these xmm registers into the fixed call frame, but this causes unnecessary overhead.
The same issue occurs for ARM64 platforms for floating point register 8 to 15. However, there we can use inline asm to fix this.

@nielsdos
Copy link
Member Author

nielsdos commented Apr 18, 2025

Just when I thought it was finished, turns out the same issue exists on macOS+arm64 (or on more arm64 platforms as well?)... That will be fun without access to the native hardware, but I suppose it's gonna be the same principle but easier since those platforms do support inline asm. In fact it looks like we already do an explicit preserve for arm64 via HYBRID_JIT_GUARD. i.e. probably it would work if we add v8..v15 in there? Will need to test this.
EDIT: needs to be at the start, but can be done indeed via inline asm.

@nielsdos nielsdos changed the title Fix GH-18136: tracing JIT XMM clobbering on Windows Fix GH-18136: tracing JIT floating point register clobbering on Windows and ARM64 Apr 19, 2025
…ndows and ARM64

On win64, xmm6-xmm15 are preserved registers, but the prologues and
epilogues of JITted code don't handle these. The issue occurs when
calling into the JIT code again via an internal handler
(like call_user_func). Therefore, we want to save/restore xmm registers
upon entering/leaving execute_ex. Since MSVC x64 does not support inline
assembly, we create an assembly wrapper around the real execute_ex
function.
The alternative is to always save/restore these xmm registers into the
fixed call frame, but this causes unnecessary overhead.
The same issue occurs for ARM64 platforms for floating point register
8 to 15. However, there we can use inline asm to fix this.
@nielsdos nielsdos marked this pull request as ready for review April 19, 2025 12:23
@nielsdos nielsdos requested a review from dstogov as a code owner April 19, 2025 12:23
@nielsdos nielsdos requested review from arnaud-lb and iluuu1994 April 19, 2025 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tracing JIT floating point register clobbering on Windows and ARM64
1 participant