Fix Windows ZTS shared-build LNK2001 on _tsrm_ls_cache#1674
Merged
Conversation
Drop /DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 from the sqlsrv and pdo_sqlsrv EXTENSION() calls in config.w32. On thread-safe (ZTS) shared builds this define made init.cpp / pdo_init.cpp define _tsrm_ls_cache with C linkage (php_sqlsrv.h / php_pdo_sqlsrv.h are included inside an extern "C" block), while the shared core_*.cpp translation units reference it with C++ linkage (core_sqlsrv.h includes php.h outside extern "C"). The linkage mismatch produced: core_stmt.obj : error LNK2001: unresolved external symbol "void * _tsrm_ls_cache" (?_tsrm_ls_cache@@3PEAXEA) fatal error LNK1120: 1 unresolved externals Removing the define makes the Windows shared build resolve the TSRM cache through the engine (tsrm_get_ls_cache()), matching the Linux/macOS config.m4 builds and the Windows static build. NTS builds are unaffected.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #1674 +/- ##
=======================================
Coverage 85.80% 85.80%
=======================================
Files 23 23
Lines 7247 7247
=======================================
Hits 6218 6218
Misses 1029 1029 🚀 New features to boost your workflow:
|
gargsaumya
approved these changes
Jul 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Windows thread-safe (ZTS) shared builds fail to link:
NTS builds and all Linux/macOS builds are unaffected.
Root cause
A C vs C++ language-linkage mismatch on
_tsrm_ls_cache, exposed only whenZEND_ENABLE_STATIC_TSRMLS_CACHEis defined (config.w32 defines it; config.m4 does not):init.cpp/pdo_init.cppincludephp_*sqlsrv.h(->php.h->zend.h) insidean
extern "C"block, sozend.h's file-scopeZEND_TSRMLS_CACHE_EXTERN()gives_tsrm_ls_cacheC linkage, andZEND_TSRMLS_CACHE_DEFINE()defines the unmangled symbol.shared/core_sqlsrv.hincludesphp.houtsideextern "C", socore_stmt.cpp(via
SQLSRV_G->ZEND_MODULE_GLOBALS_ACCESSOR->TSRMG_STATIC->_tsrm_ls_cache)references the C++-mangled
?_tsrm_ls_cache@@3PEAXEA.The define is applied consistently to every sqlsrv/pdo_sqlsrv translation unit, so the
failure is a linkage mismatch rather than a missing define. Merely relocating the define
within
config.w32is a no-op; removing it is what changes the outcome.Fix
Remove
/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1from bothEXTENSION()calls. The Windowsshared build then resolves the TSRM cache through the engine (
tsrm_get_ls_cache()),matching the Linux/macOS
config.m4builds and the Windows static build.