Skip to content

PHP 8.3.16 build fails with older glibcΒ #17498

@vpalm001

Description

@vpalm001

Description

Building on RHEL7 with glibc 2.17:

./configure --disable-all --with-ffi
make

Resulted in this output:

/php-8.3.16/ext/ffi/ffi.c: In function 'zend_ffi_parse_directives':
/php-8.3.16/ext/ffi/ffi.c:5047:45: error: macro "strncmp" requires 3 arguments, but only 2 given
   if (strncmp(code_pos, ZEND_STRL("#define")) == 0) {
                                             ^
/php-8.3.16/ext/ffi/ffi.c:5047:47: warning: the comparison will always evaluate as 'false' for the address of 'strncmp' will never be NULL [-Waddress]
   if (strncmp(code_pos, ZEND_STRL("#define")) == 0) {
                                               ^
/php-8.3.16/ext/ffi/ffi.c:5052:41: error: macro "strncmp" requires 3 arguments, but only 2 given
    if (strncmp(p, ZEND_STRL("FFI_SCOPE")) == 0) {
                                         ^
/php-8.3.16/ext/ffi/ffi.c:5052:43: warning: the comparison will always evaluate as 'false' for the address of 'strncmp' will never be NULL [-Waddress]
    if (strncmp(p, ZEND_STRL("FFI_SCOPE")) == 0) {
                                           ^
/php-8.3.16/ext/ffi/ffi.c:5056:46: error: macro "strncmp" requires 3 arguments, but only 2 given
    } else if (strncmp(p, ZEND_STRL("FFI_LIB")) == 0) {
                                              ^
/php-8.3.16/ext/ffi/ffi.c:5056:48: warning: the comparison will always evaluate as 'false' for the address of 'strncmp' will never be NULL [-Waddress]
    } else if (strncmp(p, ZEND_STRL("FFI_LIB")) == 0) {
                                                ^

Optimized compilation uses macro for strncmp. Macro-within-macro ends up as an error as it processes strncmp macro first and expects to get 3 arguments for it.

Applied the following patch and got it built:

--- 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";

PHP Version

PHP 8.3.16

Operating System

RHEL 7

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions