summaryrefslogtreecommitdiff
path: root/configure.ac
diff options
context:
space:
mode:
authorLasse Collin <lasse.collin@tukaani.org>2022-11-14 16:00:52 +0200
committerLasse Collin <lasse.collin@tukaani.org>2022-11-14 16:00:52 +0200
commiteb0f1450ad9f23dac03050d9c8375980240aee21 (patch)
tree2ccb523dc0277999d3629bad18e0c2e819d33b64 /configure.ac
parent6553f49b11dafad35c73b05f12e14865ea1fd8a1 (diff)
downloadxz-eb0f1450ad9f23dac03050d9c8375980240aee21.tar.gz
liblzma: Use __attribute__((__constructor__)) if available.
This uses it for CRC table initializations when using --disable-small. It avoids mythread_once() overhead. It also means that then --disable-small --disable-threads is thread-safe if this attribute is supported.
Diffstat (limited to 'configure.ac')
-rw-r--r--configure.ac31
1 files changed, 28 insertions, 3 deletions
diff --git a/configure.ac b/configure.ac
index 15b4ba4..cf226b2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -768,6 +768,29 @@ AC_CHECK_MEMBERS([
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. If it works this should give no warnings, even
+# clang -Weverything should be fine.
+# dnl This doesn't need AC_LANG_SOURCE, minimal code is enough.
+AC_MSG_CHECKING([if __attribute__((__constructor__)) can be used])
+have_func_attribute_constructor=no
+OLD_CFLAGS="$CFLAGS"
+CFLAGS="$CFLAGS -Werror"
+AC_COMPILE_IFELSE([
+ __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"
+
###############################################################################
# Checks for library functions.
@@ -1005,9 +1028,11 @@ 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" = xnoyes; then
+if test "x$enable_threads$enable_small$have_func_attribute_constructor" \
+ = xnoyesno; then
echo
echo "NOTE:"
- echo "liblzma will be thread unsafe due the combination"
- echo "of --disable-threads --enable-small."
+ echo "liblzma will be thread-unsafe due to the combination"
+ echo "of --disable-threads --enable-small when using a compiler"
+ echo "that doesn't support __attribute__((__constructor__))."
fi