-
Notifications
You must be signed in to change notification settings - Fork 7.8k
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
MinGW linker call php8ts.dll php8embed.dll that compiled out by MSVC. #17476
Comments
👍
Hmm, really? Are there limitations regarding the FFI? Could these be resolved otherwise (e.g. patching the FFI)? Is it using libffi?
Right. Clang support is basically available (I'm working on some improvements); don't know about ICC support (might be completely broken). But of course, you could try to build with MinGW/MSYS via the autotools build chain (as far as I know, the swoole developers do that with Cygwin). I've tried that recently, but besides that this is super slow, it doesn't work; I think a lot of adjustments would have to be made to php-src to properly support this.
I understand that
In my opinion, being able to build embed as shared library makes generally sense. We already do this with for phpdbg ( For reference: dunglas/frankenphp#420. It seems there was some progress using https://github.com/crazywhalecc/static-php-cli. But it looks like you've managed to get a step further. |
Possibly a first step: #17480. |
Next baby step: #17482. |
Yep, I surely have tried those ways.
In addition to what you said, I'm also having problems compiling libphp.so with linking libs/libphp.bundle: $(PHP_GLOBAL_OBJS) $(PHP_SAPI_OBJS)
$(CC) $(MH_BUNDLE_FLAGS) $(CFLAGS_CLEAN) $(EXTRA_CFLAGS) $(LDFLAGS) $(EXTRA_LDFLAGS) $(PHP_GLOBAL_OBJS:.lo=.o) $(PHP_SAPI_OBJS:.lo=.o) $(PHP_FRAMEWORKS) $(EXTRA_LIBS) $(ZEND_EXTRA_LIBS) -o $@ && cp $@ libs/libphp.so |
I' ve tried
Could it be like that? # elif defined(_MSC_VER) && defined(_A_MACRO)
# define zend_always_inline inline
# define zend_never_inline __declspec(noinline)
# elif defined(_MSC_VER) && !defined(_A_MACRO)
# define zend_always_inline __forceinline
# define zend_never_inline __declspec(noinline)
# else It seems like |
Hmm, just checked again, this time with
Did you get any relevant errors during Also check the generated Makefile; the value of the variable
Hm, I don't quite understand why it wouldn't work as is; shouldn't the following be chosen by MinGW GCC (it is for me): php-src/Zend/zend_portability.h Lines 361 to 365 in 39f1d25
And Regarding the general build issues with MinGW: I think this is generally broken. The Windows build chain (based on confutils.js) only supports MSVC and native Clang (and maybe ICC), while the autotools toolchain likely falls about our C code, where we sometimes use Mixing the tooling, like you did with using an MSVC build with MinGW, seems easier on the surface, but I would expect issues down the road (stability and security related, at least). Not sure what to do about that. Isn't there a way to build FrankenPHP with native Windows tooling (MSVC or Clang)? Looking at https://frankenphp.dev/docs/compile/, I fail to understand where https://github.com/crazywhalecc/static-php-cli would even be helpful. |
It's been compiled out. It should compile out stably, which is no problem. Definitely there was a mistake in my previous step, not sure which one though, deleted and redid it once and it was fine.
On this point I was completely wrong, bittersweet haha. The error about
Surely a lot of effort to and it doesnt worth till now.
I've done some testing at this point and found that this approach is not that unreliable. The methodology for the tests done earlier was to run the .phpt under php-src using frankenphp's cli mode. It turned out surprisingly well. Since the previous report wasn't saved, I was thinking of compiling the php cli api through MinGW-w64 for executing these .phpt to get the passing rate. Since the main functions of php are in php8ts.dll, there shouldn't be a big problem if there's no problem with the calls. As for security I don't know where to look. |
Thank you for further checking! I had a closer look at building FrankenPHP, and found that lack of "native" building is a general issue of CGO, which assumes a MinGW environment on Windows. It doesn't look like there is a way around; might be able to use a cl.exe wrapper for compilation, but linking is unlikely to be fixable. So I've tried to build FrankenPHP using Windows Go binaries and MinGW binaries without using MSYS, and finally succeeded to get a frankenphp.exe. However, apparently it doesn't work; might be me; had serious issues with Caddy already. Such a build chain might be beneficial, since it could more easily use the same dependencies as possibly some other PHP extensions. Anyhow, I had issues with the included zend_atomic.h; didn't compile because of
I'll try to look into this further. One point to watch out are the calling conventions. The need to remove/replace |
I've managed to get a basically working frankenphp.exe (only minimal testing with The zend_atomic.h issues still give me a head-ache. The And there is missing support for zend_max_execution_timers on Windows. Not sure how relevant that would be for FrankenPHP. |
Ugh, there appears to be a pretty serious issue that I had ignored so far:
Since we're building with MinGW gcc Lines 145 to 149 in dd42ebe
to go with A simple fix: TSRM/TSRM.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/TSRM/TSRM.h b/TSRM/TSRM.h
index 80d6cbad04..7837c04201 100644
--- a/TSRM/TSRM.h
+++ b/TSRM/TSRM.h
@@ -142,7 +142,7 @@ TSRM_API bool tsrm_is_shutdown(void);
TSRM_API const char *tsrm_api_name(void);
TSRM_API bool tsrm_is_managed_thread(void);
-#ifdef TSRM_WIN32
+#if defined(TSRM_WIN32) && defined(_MSC_VER)
# define TSRM_TLS __declspec(thread)
#else
# define TSRM_TLS __thread might be sufficient, but I'm not sure. Obviously, the warning is gone this way, but mixing Windows threads and pthreads might not be the best idea. |
The #if !__has_builtin(_InterlockedExchange)
__INTRINSICS_USEINLINE
__LONG32 _InterlockedExchange(__LONG32 volatile *Target, __LONG32 Value) {
return __sync_lock_test_and_set(Target, Value);
}
#endif I'm having trouble understanding that it implements #if !__has_builtin(_InterlockedExchange8)
__INTRINSICS_USEINLINE
char _InterlockedExchange8(char volatile *Target, char Value) {
return __sync_fetch_and_store_1(Target, Value);
}
#endif But MinGW-w64 not implements char _InterlockedExchange8(volatile char *Target, char Value) {
__asm__ __volatile__(
"lock xchgl %%eax, (%1)\n"
: "=a" (Value), "+m" (*Target) : "1" (Value) : "memory"
);
return Value;
} But |
Description
Recently I was porting FrankenPHP to windows. It is a web server code in GO and C. GO can only call GNU C code. On Windows its MinGW.
I've tried to compile PHP on Windows with MinGW, and find it out that it even have no rules for organise a compilation.
Cause PHP on Windows only support for MSVC officially. Of course there's also Clang and ICC, but MSVC is main stream. And I find that MinGW-w64 linker could link the .dll that MSVC out. It's pretty versatile, except for some MSVC features that lead compile-time-error.
So, I've tried to change code in php-8.3.0, get rid of somethings like “__vectorcall” "__forceinline", and change the Makefile to make php8embed.dll out. And then, MinGW-w64 gcc could link the php8ts.dll and php8embed.dll that MSVC out. That makes FrankenPHP could be port to windows.
I don't know the feature that make the dll compiled by MSVC callable by MinGW, will this be accepted by the mainline.
Here is changes on php-8.3.0, see it as a demo. changes
The text was updated successfully, but these errors were encountered: