Skip to content

Commit f1c729c

Browse files
committed
Add --enable-embed=static support on Windows
PHP's Unix build already documents and accepts --enable-embed=static (see sapi/embed/config.m4) for building php<N>embed as a static library with no DLL at runtime. The Windows config.w32 ignored the static value, leaving php_embed.c compiled as a DLL consumer regardless. When --enable-embed=static is passed on Windows: * Inject /D PHP_EXPORTS /D LIBZEND_EXPORTS /D SAPI_EXPORTS /D TSRM_EXPORTS into CFLAGS_EMBED so php_embed.c references PHP/ Zend/SAPI/TSRM symbols directly instead of through __declspec( dllimport) thunks (which would produce LNK2019 with no DLL). * Skip php_embed.c's ZEND_TSRMLS_CACHE_DEFINE() (gated on the new PHP_EMBED_STATIC define). In static mode zend.c is in the same link unit and already defines _tsrm_ls_cache; the duplicate from php_embed.c produced LNK4006 / corrupt binary. This patches only the source-side adjustments; producing a fat static lib (linking PHP_GLOBAL_OBJS + STATIC_EXT_OBJS into php<N>embed.lib) is a downstream Makefile concern.
1 parent 7260b27 commit f1c729c

3 files changed

Lines changed: 18 additions & 1 deletion

File tree

NEWS

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 8.5.8
44

5+
- Embed:
6+
. Added --enable-embed=static support on Windows: when selected, php_embed.c
7+
is compiled with PHP/Zend/SAPI/TSRM export defines so it references core
8+
symbols directly instead of through dllimport thunks, and its duplicate
9+
TSRMLS cache definition is skipped (zend.c provides it in the same
10+
link unit). (Luther Monson)
11+
512
- GD:
613
. Fixed bug GH-22121 (Double free in gdImageSetStyle() after
714
overflow-triggered early return). (iliaal)

sapi/embed/config.w32

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,15 @@ var PHP_EMBED_PGO = false;
66

77
if (PHP_EMBED != "no") {
88
SAPI('embed', 'php_embed.c', 'php' + PHP_VERSION + 'embed.lib', '/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1');
9+
if (PHP_EMBED == "static") {
10+
// Static embed mode: php<N>embed.lib is intended to contain PHP
11+
// core, extensions and the embed SAPI in a single static library
12+
// (no php<N>.dll at runtime). php_embed.c must reach PHP/Zend/
13+
// SAPI/TSRM symbols directly rather than through dllimport thunks.
14+
ADD_FLAG('CFLAGS_EMBED',
15+
'/D PHP_EMBED_STATIC' +
16+
' /D PHP_EXPORTS /D LIBZEND_EXPORTS' +
17+
' /D SAPI_EXPORTS /D TSRM_EXPORTS');
18+
}
919
PHP_INSTALL_HEADERS("sapi/embed", "php_embed.h");
1020
}

sapi/embed/php_embed.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ static const char HARDCODED_INI[] =
3030
"max_execution_time=0\n"
3131
"max_input_time=-1\n\0";
3232

33-
#if defined(PHP_WIN32) && defined(ZTS)
33+
#if defined(PHP_WIN32) && defined(ZTS) && !defined(PHP_EMBED_STATIC)
3434
ZEND_TSRMLS_CACHE_DEFINE()
3535
#endif
3636

0 commit comments

Comments
 (0)