From a9d37bb2a2e30c84043bb099fead9e810d94ac92 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Wed, 4 Jun 2025 08:58:46 +0700 Subject: [PATCH] add source patch for ffi on centos 7 --- src/SPC/store/SourcePatcher.php | 10 ++++++ .../patch/ffi_centos7_fix_O3_strncmp.patch | 31 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 src/globals/patch/ffi_centos7_fix_O3_strncmp.patch diff --git a/src/SPC/store/SourcePatcher.php b/src/SPC/store/SourcePatcher.php index f78928de..6f6c7d45 100644 --- a/src/SPC/store/SourcePatcher.php +++ b/src/SPC/store/SourcePatcher.php @@ -22,6 +22,7 @@ class SourcePatcher FileSystem::addSourceExtractHook('swoole', [SourcePatcher::class, 'patchSwoole']); FileSystem::addSourceExtractHook('php-src', [SourcePatcher::class, 'patchPhpLibxml212']); FileSystem::addSourceExtractHook('php-src', [SourcePatcher::class, 'patchGDWin32']); + FileSystem::addSourceExtractHook('php-src', [SourcePatcher::class, 'patchFfiCentos7FixO3strncmp']); FileSystem::addSourceExtractHook('sqlsrv', [SourcePatcher::class, 'patchSQLSRVWin32']); FileSystem::addSourceExtractHook('pdo_sqlsrv', [SourcePatcher::class, 'patchSQLSRVWin32']); FileSystem::addSourceExtractHook('yaml', [SourcePatcher::class, 'patchYamlWin32']); @@ -451,6 +452,15 @@ class SourcePatcher return false; } + public static function patchFfiCentos7FixO3strncmp(): bool + { + if (PHP_OS_FAMILY === 'Linux' && SystemUtil::getLibcVersionIfExists() === '2.17') { + SourcePatcher::patchFile('ffi_centos7_fix_O3_strncmp.patch', SOURCE_PATH . '/php-src'); + return true; + } + return false; + } + public static function patchLibaomForAlpine(): bool { if (PHP_OS_FAMILY === 'Linux' && SystemUtil::isMuslDist()) { diff --git a/src/globals/patch/ffi_centos7_fix_O3_strncmp.patch b/src/globals/patch/ffi_centos7_fix_O3_strncmp.patch new file mode 100644 index 00000000..815170be --- /dev/null +++ b/src/globals/patch/ffi_centos7_fix_O3_strncmp.patch @@ -0,0 +1,31 @@ +--- a/ext/ffi/ffi.c 2025-01-17 10:37:37 ++++ a/ext/ffi/ffi.c 2025-01-17 10:39:17 +@@ -57,6 +57,8 @@ + /* XXX need something better, perhaps with regard to SIMD, etc. */ + # define __BIGGEST_ALIGNMENT__ sizeof(size_t) + #endif ++ ++#define ZEND_STRNCMP(s,str) strncmp((s),(str),(sizeof(str)-1)) + + ZEND_DECLARE_MODULE_GLOBALS(ffi) + +@@ -5046,16 +5048,16 @@ static char *zend_ffi_parse_directives(const char *fil + *scope_name = NULL; + *lib = NULL; + while (*code_pos == '#') { +- if (strncmp(code_pos, ZEND_STRL("#define")) == 0) { ++ if (ZEND_STRNCMP(code_pos, "#define") == 0) { + p = zend_ffi_skip_ws_and_comments(code_pos + sizeof("#define") - 1, false); + + char **target = NULL; + const char *target_name = NULL; +- if (strncmp(p, ZEND_STRL("FFI_SCOPE")) == 0) { ++ if (ZEND_STRNCMP(p, "FFI_SCOPE") == 0) { + p = zend_ffi_skip_ws_and_comments(p + sizeof("FFI_SCOPE") - 1, false); + target = scope_name; + target_name = "FFI_SCOPE"; +- } else if (strncmp(p, ZEND_STRL("FFI_LIB")) == 0) { ++ } else if (ZEND_STRNCMP(p, "FFI_LIB") == 0) { + p = zend_ffi_skip_ws_and_comments(p + sizeof("FFI_LIB") - 1, false); + target = lib; + target_name = "FFI_LIB";