From 278cc2212b628f3afb342014029cd15fc42aca49 Mon Sep 17 00:00:00 2001 From: Peter Kokot Date: Wed, 10 Jul 2024 14:03:54 +0200 Subject: [PATCH 1/3] Fix GH-14443: Cross-compiling with external GD library This enables cross-compiling simplifications when using external GD library as requested in GH-14443 using cache variables: * php_cv_lib_gd_gdImageCreateFromPng * php_cv_lib_gd_gdImageCreateFromAvif * php_cv_lib_gd_gdImageCreateFromWebp * php_cv_lib_gd_gdImageCreateFromJpeg * php_cv_lib_gd_gdImageCreateFromXpm * php_cv_lib_gd_gdImageCreateFromBmp * php_cv_lib_gd_gdImageCreateFromTga For example: ./configure --host=... --build=... --enable-gd --with-external-gd \ php_cv_lib_gd_gdImageCreateFromPng=yes --- NEWS | 1 + ext/gd/config.m4 | 39 ++++++++++++++++++++------------------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/NEWS b/NEWS index db78d1404db09..077c7aa0ce681 100644 --- a/NEWS +++ b/NEWS @@ -10,6 +10,7 @@ PHP NEWS (nielsdos) . Fixed OSS-Fuzz #69765. (nielsdos) . Fixed bug GH-14741 (Segmentation fault in Zend/zend_types.h). (nielsdos) + . Fixed bug GH-14443 (Cross-compiling with external GD library). (Peter Kokot) - Dom: . Fixed bug GH-14702 (DOMDocument::xinclude() crash). (nielsdos) diff --git a/ext/gd/config.m4 b/ext/gd/config.m4 index 42bb64578ce0a..ad038b697c1d1 100644 --- a/ext/gd/config.m4 +++ b/ext/gd/config.m4 @@ -147,14 +147,15 @@ dnl that gd defines "junk" versions of each gdImageCreateFromFoo function dnl even when it does not support the Foo format. Those junk functions dnl display a warning but eventually return normally, making a simple link dnl or run test insufficient. -AC_DEFUN([PHP_GD_CHECK_FORMAT],[ - old_LIBS="${LIBS}" - LIBS="${LIBS} ${GD_SHARED_LIBADD}" - old_CFLAGS="${CFLAGS}" - CFLAGS="${CFLAGS} ${GDLIB_CFLAGS}" - AC_MSG_CHECKING([for working gdImageCreateFrom$1 in libgd]) - AC_LANG_PUSH([C]) - AC_RUN_IFELSE([AC_LANG_SOURCE([ +AC_DEFUN([PHP_GD_CHECK_FORMAT], +[AS_VAR_PUSHDEF([php_var], [php_cv_lib_gd_gdImageCreateFrom$1]) +old_LIBS=$LIBS +LIBS="$LIBS $GD_SHARED_LIBADD" +old_CFLAGS=$CFLAGS +CFLAGS="$CFLAGS $GDLIB_CFLAGS" +AC_LANG_PUSH([C]) +AC_CACHE_CHECK([for working gdImageCreateFrom$1 in libgd], [php_var], + [AC_RUN_IFELSE([AC_LANG_SOURCE([ #include #include #include @@ -173,17 +174,17 @@ int main(int argc, char** argv) { gdSetErrorMethod(exit1); gdImagePtr p = gdImageCreateFrom$1(f); return 0; -}])],[ - AC_MSG_RESULT([yes]) - AC_DEFINE($2, 1, [Does gdImageCreateFrom$1 work?]) - ],[ - AC_MSG_RESULT([no]) - ],[ - AC_MSG_RESULT([no]) - ]) - AC_LANG_POP([C]) - CFLAGS="${old_CFLAGS}" - LIBS="${old_LIBS}" +}])], + [AS_VAR_SET([php_var], [yes])], + [AS_VAR_SET([php_var], [no])], + [AS_VAR_SET([php_var], [no])])]) +AS_VAR_IF([php_var], [yes], + [AC_DEFINE_UNQUOTED([$2], [1], + [Define to 1 if GD library has the 'gdImageCreateFrom$1' function.])]) +AC_LANG_POP([C]) +CFLAGS=$old_CFLAGS +LIBS=$old_LIBS +AS_VAR_POPDEF([php_var]) ]) AC_DEFUN([PHP_GD_CHECK_VERSION],[ From f68a919c4513a58b672288b8bfaca1a3be07e944 Mon Sep 17 00:00:00 2001 From: Peter Kokot Date: Wed, 10 Jul 2024 19:17:36 +0200 Subject: [PATCH 2/3] Fix also unused variable and parameter warnings This also reduces the warnings on more strict compiler settings. --- ext/gd/config.m4 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ext/gd/config.m4 b/ext/gd/config.m4 index ad038b697c1d1..039b36b961e48 100644 --- a/ext/gd/config.m4 +++ b/ext/gd/config.m4 @@ -162,17 +162,21 @@ AC_CACHE_CHECK([for working gdImageCreateFrom$1 in libgd], [php_var], /* A custom gdErrorMethod */ void exit1(int priority, const char *format, va_list args) { + (void)priority; + (void)format; + (void)args; _exit(1); } /* Override the default gd_error_method with one that actually causes the program to return an error. */ -int main(int argc, char** argv) { +int main(void) { m4_if([$1],[Xpm], [char* f = "test.xpm"], [FILE* f = NULL]); gdSetErrorMethod(exit1); gdImagePtr p = gdImageCreateFrom$1(f); + (void)p; return 0; }])], [AS_VAR_SET([php_var], [yes])], From 727329569cf863ea47174a99b9a1d50380974605 Mon Sep 17 00:00:00 2001 From: Peter Kokot Date: Wed, 10 Jul 2024 19:27:56 +0200 Subject: [PATCH 3/3] [skip ci] Make CPP macros help texts more sensible to the context --- ext/gd/config.m4 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/gd/config.m4 b/ext/gd/config.m4 index 039b36b961e48..02b571b607764 100644 --- a/ext/gd/config.m4 +++ b/ext/gd/config.m4 @@ -184,7 +184,7 @@ int main(void) { [AS_VAR_SET([php_var], [no])])]) AS_VAR_IF([php_var], [yes], [AC_DEFINE_UNQUOTED([$2], [1], - [Define to 1 if GD library has the 'gdImageCreateFrom$1' function.])]) + [Define to 1 if GD library has a working 'gdImageCreateFrom$1' function.])]) AC_LANG_POP([C]) CFLAGS=$old_CFLAGS LIBS=$old_LIBS