Build: Use AX_GCC_FUNC_ATTRIBUTE to detect __attribute__ support.

This way -Werror isn't needed for these checks as
AX_GCC_FUNC_ATTRIBUTE looks at compiler's warning messages to see
if an unsupported attribute was present. Both methods have their
own problems but I'm hoping that this is the better method.

It is known that the check for the ifunc attribute this doesn't
work with CompCert 3.12. It silently ignores unknown attributes
in function declarations and in static functions if the function
appears unused (even though the unknown attribute would make it used).
This commit is contained in:
Lasse Collin 2023-10-16 17:54:15 +03:00
parent 8a8b8042e7
commit 146664519f
1 changed files with 4 additions and 57 deletions

View File

@ -820,32 +820,7 @@ AC_SYS_LARGEFILE
AC_C_BIGENDIAN
# __attribute__((__constructor__)) can be used for one-time initializations.
# Use -Werror because some compilers accept unknown attributes and just
# give a warning.
#
# FIXME? Unfortunately -Werror can cause trouble if CFLAGS contains options
# that produce warnings for unrelated reasons. For example, GCC and Clang
# support -Wunused-macros which will warn about "#define _GNU_SOURCE 1"
# which will be among the #defines that Autoconf inserts to the beginning of
# the test program. There seems to be no nice way to prevent Autoconf from
# inserting the any defines to the test program.
AC_MSG_CHECKING([if __attribute__((__constructor__)) can be used])
have_func_attribute_constructor=no
OLD_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -Werror"
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
__attribute__((__constructor__))
static void my_constructor_func(void) { return; }
]])], [
AC_DEFINE([HAVE_FUNC_ATTRIBUTE_CONSTRUCTOR], [1],
[Define to 1 if __attribute__((__constructor__))
is supported for functions.])
have_func_attribute_constructor=yes
AC_MSG_RESULT([yes])
], [
AC_MSG_RESULT([no])
])
CFLAGS="$OLD_CFLAGS"
AX_GCC_FUNC_ATTRIBUTE([constructor])
# The Win95 threading lacks a thread-safe one-time initialization function.
# The one-time initialization is needed for crc32_small.c and crc64_small.c
@ -853,7 +828,7 @@ CFLAGS="$OLD_CFLAGS"
# win95, and the compiler does not support attribute constructor, then we
# would end up with a multithreaded build that is thread-unsafe. As a
# result this configuration is not allowed.
if test "x$enable_small$enable_threads$have_func_attribute_constructor"\
if test "x$enable_small$enable_threads$ax_cv_have_func_attribute_constructor" \
= xyeswin95no; then
AC_MSG_ERROR([--enable-threads=win95 and --enable-small cannot be
used at the same time with a compiler that doesn't support
@ -867,35 +842,7 @@ fi
AC_ARG_ENABLE([ifunc], [AS_HELP_STRING([--disable-ifunc],
[do not use __attribute__((__ifunc__()))])],
[], [enable_ifunc=yes])
if test "x$enable_ifunc" = xyes ; then
OLD_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -Werror"
AC_MSG_CHECKING([if __attribute__((__ifunc__())) can be used])
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
static void func(void) { return; }
static void (*resolve_func (void)) (void) { return func; }
void func_ifunc (void)
__attribute__((__ifunc__("resolve_func")));
/*
* 'clang -Wall' incorrectly warns that resolve_func is
* unused (-Wunused-function). Correct assembly output is
* still produced. This problem exists at least in Clang
* versions 4 to 17. The following silences the bogus warning:
*/
void make_clang_quiet(void);
void make_clang_quiet(void) { resolve_func()(); }
]])], [
AC_DEFINE([HAVE_FUNC_ATTRIBUTE_IFUNC], [1],
[Define to 1 if __attribute__((__ifunc__()))
is supported for functions.])
AC_MSG_RESULT([yes])
], [
AC_MSG_RESULT([no])
])
CFLAGS="$OLD_CFLAGS"
fi
AS_IF([test "x$enable_ifunc" = xyes], [AX_GCC_FUNC_ATTRIBUTE([ifunc])])
###############################################################################
@ -1223,7 +1170,7 @@ if test x$tuklib_cv_cpucores_method = xunknown; then
echo "No supported method to detect the number of CPU cores."
fi
if test "x$enable_threads$enable_small$have_func_attribute_constructor" \
if test "x$enable_threads$enable_small$ax_cv_have_func_attribute_constructor" \
= xnoyesno; then
echo
echo "NOTE:"