Skip to content
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

MSVC ZEND_FASTCALL incompatible with JIT and not portable? #17497

Open
cmb69 opened this issue Jan 17, 2025 · 1 comment
Open

MSVC ZEND_FASTCALL incompatible with JIT and not portable? #17497

cmb69 opened this issue Jan 17, 2025 · 1 comment

Comments

@cmb69
Copy link
Member

cmb69 commented Jan 17, 2025

Description

When building with MSVC (or clang-cl), ZEND_FASTCALL is defined as __vectorcall. While __vectorcall is similar to the default x64 calling convention, and __fastcall on x86, respectively, there are notable differences. It seems to me that our JIT does not cater to these. That may still not be relevant to core functions, but could be an issue with external extensions which declare function as ZEND_FASTCALL.

Furthermore, there is definitely an issue regarding portability, since GCC doesn't support __vectorcall at all. While we do not necessarily support GCC on Windows, compatibility still seems to be a good thing.

Note that even __fastcall appears to be slightly different to the Windows __fastcall convention:

On x86-32 targets, the fastcall attribute causes the compiler to pass the first argument (if of integral type) in the register ECX and the second argument (if of integral type) in the register EDX. Subsequent and other typed arguments are passed on the stack.

The first two DWORD or smaller arguments that are found in the argument list from left to right are passed in ECX and EDX registers; all other arguments are passed on the stack from right to left.

This is possibly just a documentation issue (I haven't checked).

Anyhow, I suggest to change ZEND_FASTCALL with MSVC to use the default x64 calling convention for the x64 ABI; not sure what to suggest regarding x86.

cc @dstogov, @nielsdos, @arnaud-lb

PHP Version

PHP 8.4 (likely older)

Operating System

Windows

@arnaud-lb
Copy link
Member

Note that even __fastcall appears to be slightly different to the Windows __fastcall convention:
[...]
This is possibly just a documentation issue (I haven't checked).

According to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=41013, they are not compatible. Checked on https://godbolt.org/z/4j753foYa, and indeed GCC differs at least when passing integers larger than int32 or structs (see calls to f4_3, f4_4, f4_7).

Anyhow, I suggest to change ZEND_FASTCALL with MSVC to use the default x64 calling convention for the x64 ABI; not sure what to suggest regarding x86.

This seems sensible to me. The alternative is to add __vectorcall support to IR and to the the frontend, but I'm not sure this is worth it.

For x86, the frontend already tells IR to use the fastcall convention when needed, so we should probably switch to fastcall on x86/Windows. I'm not sure whether IR is consistent with either GCC or MSVC, but I think it would make sense if IR added full compatibility with both.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants