Skip to content

Commit bc09cd2

Browse files
authored
Fix the aligned variable attribute check (#14211)
By default compilers may not treat attribute warnings as errors when encountering an unknown __attribute__, unless some error option is provided (-Werror=attributes, -Werror=unknown-attributes, -Werror...). This fixes the check and wraps it into a separate M4 macro to be extendable in the future if needed. It checks if conftest.err file was generated by the compilation check when warnings appear. Also, PHP check is a bit customized by using __alignof__ keyword, so it is left in there for now to not break existing checks.
1 parent 5276734 commit bc09cd2

File tree

3 files changed

+33
-16
lines changed

3 files changed

+33
-16
lines changed

build/php.m4

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2743,3 +2743,33 @@ AC_DEFUN([PHP_CHECK_AVX512_VBMI_SUPPORTS], [
27432743
AC_DEFINE_UNQUOTED([PHP_HAVE_AVX512_VBMI_SUPPORTS],
27442744
[$have_avx512_vbmi_supports], [Whether the compiler supports AVX512 VBMI])
27452745
])
2746+
2747+
dnl
2748+
dnl PHP_CHECK_VARIABLE_ATTRIBUTE(attribute)
2749+
dnl
2750+
dnl Check whether the compiler supports the GNU C variable attribute.
2751+
dnl
2752+
AC_DEFUN([PHP_CHECK_VARIABLE_ATTRIBUTE],
2753+
[AS_VAR_PUSHDEF([php_var], [php_cv_have_variable_attribute_$1])
2754+
AC_CACHE_CHECK([for variable __attribute__(($1))], [php_var],
2755+
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([m4_case([$1],
2756+
[aligned],
2757+
[unsigned char test[32] __attribute__(($1(__alignof__(int))));],
2758+
[
2759+
m4_warn([syntax], [Unsupported variable attribute $1, the test may fail])
2760+
int var __attribute__(($1));
2761+
])],
2762+
[])],
2763+
dnl By default, compilers may not classify attribute warnings as errors
2764+
dnl (-Werror=attributes) when encountering an unknown attribute. Accept the
2765+
dnl attribute only if no warnings were generated.
2766+
[AS_IF([test -s conftest.err],
2767+
[AS_VAR_SET([php_var], [no])],
2768+
[AS_VAR_SET([php_var], [yes])])],
2769+
[AS_VAR_SET([php_var], [no])])
2770+
])
2771+
AS_VAR_IF([php_var], [yes],
2772+
[AC_DEFINE_UNQUOTED(AS_TR_CPP([HAVE_ATTRIBUTE_$1]), [1],
2773+
[Define to 1 if the compiler supports the '$1' variable attribute.])])
2774+
AS_VAR_POPDEF([php_var])
2775+
])

configure.ac

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,9 @@ AS_CASE([$host_alias], [*-*-*android*|*-*-*uclibc*|*-*-*musl*|*openbsd*], [true]
568568
fi
569569
])
570570

571+
dnl Check for __attribute__ ((__aligned__)) support in the compiler.
572+
PHP_CHECK_VARIABLE_ATTRIBUTE([aligned])
573+
571574
dnl Check for IPv6 support.
572575
AC_CACHE_CHECK([for IPv6 support], ac_cv_ipv6_support,
573576
[AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>

ext/standard/config.m4

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -275,22 +275,6 @@ else
275275
PHP_ADD_SOURCES(PHP_EXT_DIR(standard), crypt_freesec.c crypt_blowfish.c crypt_sha512.c crypt_sha256.c php_crypt_r.c)
276276
fi
277277

278-
dnl
279-
dnl Check for __attribute__ ((__aligned__)) support in the compiler
280-
dnl
281-
AC_CACHE_CHECK(whether the compiler supports aligned attribute, ac_cv_attribute_aligned,[
282-
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
283-
]],[[
284-
unsigned char test[32] __attribute__ ((__aligned__ (__alignof__ (int))));
285-
]])],[
286-
ac_cv_attribute_aligned=yes
287-
],[
288-
ac_cv_attribute_aligned=no
289-
])])
290-
if test "$ac_cv_attribute_aligned" = "yes"; then
291-
AC_DEFINE([HAVE_ATTRIBUTE_ALIGNED], 1, [whether the compiler supports __attribute__ ((__aligned__))])
292-
fi
293-
294278
if test "$cross_compiling" = yes ; then
295279
case $host_alias in
296280
*linux*)

0 commit comments

Comments
 (0)