@@ -256,14 +256,23 @@ public static function patchSwoole(): bool
256256 */
257257 public static function patchBeforeMake (BuilderBase $ builder ): void
258258 {
259- // Try to fix debian environment build lack HAVE_STRLCAT problem
260- if ($ builder instanceof LinuxBuilder) {
261- FileSystem::replaceFileRegex (SOURCE_PATH . '/php-src/main/php_config.h ' , '/^#define HAVE_STRLCPY 1$/m ' , '' );
262- FileSystem::replaceFileRegex (SOURCE_PATH . '/php-src/main/php_config.h ' , '/^#define HAVE_STRLCAT 1$/m ' , '' );
263- }
264259 if ($ builder instanceof UnixBuilderBase) {
265260 FileSystem::replaceFileStr (SOURCE_PATH . '/php-src/Makefile ' , 'install-micro ' , '' );
266261 }
262+ if (!SPCTarget::isStatic () && SPCTarget::getLibc () === 'musl ' ) {
263+ // we need to patch the symbol to global visibility, otherwise extensions with `initial-exec` TLS model will fail to load
264+ FileSystem::replaceFileStr (
265+ SOURCE_PATH . '/php-src/TSRM/TSRM.h ' ,
266+ '#define TSRMLS_MAIN_CACHE_DEFINE() TSRM_TLS void *TSRMLS_CACHE TSRM_TLS_MODEL_ATTR = NULL; ' ,
267+ '#define TSRMLS_MAIN_CACHE_DEFINE() TSRM_TLS __attribute__((visibility("default"))) void *TSRMLS_CACHE TSRM_TLS_MODEL_ATTR = NULL; ' ,
268+ );
269+ } else {
270+ FileSystem::replaceFileStr (
271+ SOURCE_PATH . '/php-src/TSRM/TSRM.h ' ,
272+ '#define TSRMLS_MAIN_CACHE_DEFINE() TSRM_TLS __attribute__((visibility("default"))) void *TSRMLS_CACHE TSRM_TLS_MODEL_ATTR = NULL; ' ,
273+ '#define TSRMLS_MAIN_CACHE_DEFINE() TSRM_TLS void *TSRMLS_CACHE TSRM_TLS_MODEL_ATTR = NULL; ' ,
274+ );
275+ }
267276
268277 // no asan
269278 // if (strpos(file_get_contents(SOURCE_PATH . '/php-src/Makefile'), 'CFLAGS_CLEAN = -g') === false) {
0 commit comments