From 5e12acf95d452366770f28781e3f24d81a035d13 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Mon, 26 Aug 2024 20:29:12 +0200 Subject: [PATCH] Fix ZEND_EXT_API wrt accessibility of OPcache symbols on Windows When building a DLL which exports symbols these need to be explicitly exported like on other platforms. When building a DLL which accesses these symbols, they should be imported for performance reasons if the symbols are referring to functions, and *have* *to* be imported if the symbols are referring to data.[1] So we do the common dllexport/dllimport "dance" depending on a macro which is only set when building OPcache. [1] --- ext/opcache/ZendAccelerator.h | 6 +++++- ext/opcache/config.w32 | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ext/opcache/ZendAccelerator.h b/ext/opcache/ZendAccelerator.h index 682677441e41..66658886d45a 100644 --- a/ext/opcache/ZendAccelerator.h +++ b/ext/opcache/ZendAccelerator.h @@ -65,7 +65,11 @@ #ifndef ZEND_EXT_API # ifdef ZEND_WIN32 -# define ZEND_EXT_API __declspec(dllexport) +# ifdef ZEND_EXT_EXPORTS +# define ZEND_EXT_API __declspec(dllexport) +# else +# define ZEND_EXT_API __declspec(dllimport) +# endif # elif defined(__GNUC__) && __GNUC__ >= 4 # define ZEND_EXT_API __attribute__ ((visibility("default"))) # else diff --git a/ext/opcache/config.w32 b/ext/opcache/config.w32 index d0af7258ac66..9824c76fedbe 100644 --- a/ext/opcache/config.w32 +++ b/ext/opcache/config.w32 @@ -62,7 +62,7 @@ if (PHP_OPCACHE != "no") { } } - ADD_FLAG('CFLAGS_OPCACHE', "/I " + configure_module_dirname); + ADD_FLAG('CFLAGS_OPCACHE', "/I " + configure_module_dirname + " /D ZEND_EXT_EXPORTS"); }