mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
Fix cross-compilation for musl C library
This adds a PHP_C_STANDARD_LIBRARY Autoconf macro to detect glibc/musl more accurately and fixes "cross-compilation" with musl-libc on glibc systems. Co-authored-by: Peter Kokot <peterkokot@gmail.com> Closes GH-19352
This commit is contained in:
2
NEWS
2
NEWS
@@ -15,6 +15,8 @@ PHP NEWS
|
||||
. Fixed bug GH-19480 (error_log php.ini cannot be unset when open_basedir is
|
||||
configured). (nielsdos)
|
||||
. Fixed bug GH-20002 (Broken build on *BSD with MSAN). (outtersg)
|
||||
. Fixed bug GH-19352 (Cross-compilation with musl C library).
|
||||
(henderkes, Peter Kokot)
|
||||
|
||||
- Curl:
|
||||
. Fix cloning of CURLOPT_POSTFIELDS when using the clone operator instead
|
||||
|
||||
40
build/php.m4
40
build/php.m4
@@ -2502,3 +2502,43 @@ AC_DEFUN([PHP_REMOVE_OPTIMIZATION_FLAGS], [
|
||||
CFLAGS=$(echo "$CFLAGS" | $SED -e "$sed_script")
|
||||
CXXFLAGS=$(echo "$CXXFLAGS" | $SED -e "$sed_script")
|
||||
])
|
||||
|
||||
dnl
|
||||
dnl PHP_C_STANDARD_LIBRARY
|
||||
dnl
|
||||
dnl Determine the C standard library used for the build. The uclibc is checked
|
||||
dnl first because it also defines the __GLIBC__ and could otherwise be detected
|
||||
dnl as glibc. Musl C library is determined heuristically.
|
||||
dnl
|
||||
AC_DEFUN([PHP_C_STANDARD_LIBRARY],
|
||||
[AC_CACHE_CHECK([C standard library implementation],
|
||||
[php_cv_c_standard_library],
|
||||
[php_cv_c_standard_library=unknown
|
||||
dnl Check if C standard library is uclibc.
|
||||
AS_VAR_IF([php_cv_c_standard_library], [unknown],
|
||||
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <features.h>],
|
||||
[#ifndef __UCLIBC__
|
||||
(void) __UCLIBC__;
|
||||
#endif])],
|
||||
[php_cv_c_standard_library=uclibc],
|
||||
[php_cv_c_standard_library=unknown])])
|
||||
dnl Check if C standard library is GNU C.
|
||||
AS_VAR_IF([php_cv_c_standard_library], [unknown],
|
||||
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <features.h>],
|
||||
[#ifndef __GLIBC__
|
||||
(void) __GLIBC__;
|
||||
#endif])],
|
||||
[php_cv_c_standard_library=glibc],
|
||||
[php_cv_c_standard_library=unknown])])
|
||||
dnl Check if C standard library is musl libc.
|
||||
AS_VAR_IF([php_cv_c_standard_library], [unknown],
|
||||
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <stdarg.h>],
|
||||
[#ifndef __DEFINED_va_list
|
||||
(void) __DEFINED_va_list;
|
||||
#endif])],
|
||||
[php_cv_c_standard_library=musl],
|
||||
[AS_IF([command -v ldd >/dev/null && ldd --version 2>&1 | grep ^musl >/dev/null 2>&1],
|
||||
[php_cv_c_standard_library=musl],
|
||||
[php_cv_c_standard_library=unknown])])])
|
||||
])
|
||||
])
|
||||
|
||||
13
configure.ac
13
configure.ac
@@ -250,15 +250,10 @@ case $host_alias in
|
||||
;;
|
||||
esac
|
||||
|
||||
dnl Detect musl libc
|
||||
AC_MSG_CHECKING([whether we are using musl libc])
|
||||
if command -v ldd >/dev/null && ldd --version 2>&1 | grep ^musl >/dev/null 2>&1
|
||||
then
|
||||
AC_MSG_RESULT([yes])
|
||||
AC_DEFINE([__MUSL__], [1], [Define to 1 when using musl libc.])
|
||||
else
|
||||
AC_MSG_RESULT([no])
|
||||
fi
|
||||
dnl Detect C library.
|
||||
PHP_C_STANDARD_LIBRARY
|
||||
AS_VAR_IF([php_cv_c_standard_library], [musl],
|
||||
[AC_DEFINE([__MUSL__], [1], [Define to 1 when using musl libc.])])
|
||||
|
||||
dnl Add _GNU_SOURCE compile definition because the php_config.h with definitions
|
||||
dnl by AC_USE_SYSTEM_EXTENSIONS might be included after the system headers which
|
||||
|
||||
@@ -44,7 +44,8 @@ if test "$PHP_POSIX" = "yes"; then
|
||||
|
||||
dnl Skip pathconf and fpathconf check on musl libc due to limited implementation
|
||||
dnl (first argument is not validated and has different error).
|
||||
AS_IF([command -v ldd >/dev/null && ldd --version 2>&1 | grep ^musl >/dev/null 2>&1],
|
||||
PHP_C_STANDARD_LIBRARY
|
||||
AS_VAR_IF([php_cv_c_standard_library], [musl],
|
||||
[],
|
||||
[AC_CHECK_FUNCS([pathconf fpathconf])])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user