-
Notifications
You must be signed in to change notification settings - Fork 8k
Description
Description
Description
Building our PHP extension with MSVC (VS Build Tools 2019 + Windows 10 SDK) fails with the linker unable to find _tsrm_ls_cache
symbol. We are linking against the php8ts.lib
in our cmake configuration.
The PHP runtime is built with ZTS enabled and our extension is also being built with the same compilation flags (ZTS=1
). We have this flag enabled: ZEND_ENABLE_STATIC_TSRMLS_CACHE=1
which seems to be causing this problem. Removing this TSRM flag makes these linker errors go away. This flag works fine when we compile our extension on Linux with Clang.
MSVC linker errors:
[build] Starting build
[proc] Executing command: "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" --build c:/path/build --config Release --target ALL_BUILD -j 22 --
[build] Microsoft (R) Build Engine version 16.11.2+f32259642 for .NET Framework
[build] Copyright (C) Microsoft Corporation. All rights reserved.
[build] C:\work\PHP_ENV\php-sdk\php-src-build-dir\vs16\x64\php-src\Zend\zend_gc.h(155,22): warning C4244: '=': conversion from '__int64' to 'int', possible loss of data [C:\workspace\abc.vcxproj]
[build] Creating library C:/abc.lib and object C:/abc.exp
[build] file1.cpp.obj : error LNK2001: unresolved external symbol "void * _tsrm_ls_cache" (?_tsrm_ls_cache@@3PEAXEA) [C:\workspace\abc.vcxproj]
[build] file2.obj : error LNK2001: unresolved external symbol "void * _tsrm_ls_cache" (?_tsrm_ls_cache@@3PEAXEA) [C:\workspace\abc.vcxproj]
[build] file3.obj : error LNK2001: unresolved external symbol "void * _tsrm_ls_cache" (?_tsrm_ls_cache@@3PEAXEA) [C:\workspace\abc.vcxproj]
[build] file4.obj : error LNK2001: unresolved external symbol "void * _tsrm_ls_cache" (?_tsrm_ls_cache@@3PEAXEA) [C:\workspace\abc.vcxproj]
[build] file5.obj : error LNK2001: unresolved external symbol "void * _tsrm_ls_cache" (?_tsrm_ls_cache@@3PEAXEA) [C:\workspace\abc.vcxproj]
[build] Hint on symbols that are defined and could potentially match:
[build] _tsrm_ls_cache
[build] C:\workspace\Release\abc.dll : fatal error LNK1120: 1 unresolved externals [C:\workspace\abc.vcxproj]
[proc] The command: "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" --build c:/path/build --config Release --target ALL_BUILD -j 22 -- exited with code: 1
[driver] Build completed: 00:00:30.345
[build] Build finished with exit code 1
PHP SDK & MSVC version
PHP SDK 2.3.0
ARCH x64
Visual C++: 14.29.30156.0
PHP version:
PS > php -v
PHP 8.3.12-dev (cli) (built: Dec 2 2024 17:43:09) (ZTS Visual C++ 2019 x64)
Copyright (c) The PHP Group
Zend Engine v4.3.12-dev, Copyright (c) Zend Technologies
configure
command used to build PHP runtime:
configure --disable-phpdbg --enable-intl --enable-mbstring --enable-opcache --enable-pdo --enable-soap --enable-sockets --with-curl --with-mysqli --with-openssl --with-pdo-mysql --with-pdo-sqlite --with-sqlite3 --enable-fileinfo --enable-embed --enable-zts
We are using these flags on Windows when building our extension:
_CRT_SECURE_NO_WARNINGS
NOMINMAX
PHP_WIN32=1
ZEND_WIN32=1
ZTS=1 # ZTS may not always be on, but main\config.w32.h doesn't seem to carry it unlike main/php_config.h on Linux
ZEND_ENABLE_STATIC_TSRMLS_CACHE=1
I looked into the symbols inside php8ts.lib
library file using dumpbin /SYMBOLS php8ts.lib
command, there is no _tsrm_ls_cache
symbol in it. But I do find a symbol for it in php8embed.lib
library. So, I tried disabling embed extension and rebuild PHP but the php8ts.lib
still does not seem to have _tsrm_ls_cache
.
I'm not sure what's going wrong here. We are not doing anything special w.r.t TSRM. We have ZEND_TSRMLS_CACHE_DEFINE()
if ZTS is enabled in our main extension source code and then in PHP_GINIT_FUNCTION
of our extension, we do ZEND_TSRMLS_CACHE_UPDATE()
. This works fine on Linux.
To rule out any misconfiguration of my env, I tried this multiple times - with Debug/Release variants, but I see the same result. Could you please help us understand this issue with linking against PHP libraries. Thanks in advance!
PHP Version
PHP 8.3.12-dev
Operating System
Windows 10 SDK (10.0.22631.4460)
Note: Edited the description to keep all observations and printouts from release build to avoid confusion. It happens both for debug & release builds.