]> git.ipfire.org Git - thirdparty/xz.git/commitdiff
Build: Conditionally allow win95 threads and --enable-small.
authorJia Tan <jiat0218@gmail.com>
Wed, 9 Aug 2023 12:35:16 +0000 (20:35 +0800)
committerJia Tan <jiat0218@gmail.com>
Wed, 9 Aug 2023 12:35:16 +0000 (20:35 +0800)
When the compiler supports __attribute__((__constructor__))
mythread_once() is never used, even with --enable-small. A configuration
with win95 threads and --enable-small will compile and be thread safe so
it can be allowed.

This isn't a very common configuration since MSVC does not support
__attribute__((__constructor__)), but MINGW32 and CLANG32 environments
for MSYS2 can use win95 threads and have
__attribute__((__constructor__)) support.

configure.ac

index 8470e3e87acdfa1abbba07f1ba877e6f833cafc6..905d717f0f478edb52ee31b704f26118018bc590 100644 (file)
@@ -437,14 +437,6 @@ case $enable_threads in
                ;;
 esac
 
-# The Win95 threading lacks thread-safe one-time initialization function.
-# It's better to disallow it instead of allowing threaded but thread-unsafe
-# build.
-if test "x$enable_small$enable_threads" = xyeswin95; then
-       AC_MSG_ERROR([--enable-threads=win95 and --enable-small cannot be
-               used at the same time])
-fi
-
 # We use the actual result a little later.
 
 
@@ -861,6 +853,19 @@ AC_COMPILE_IFELSE([
 ])
 CFLAGS="$OLD_CFLAGS"
 
+# 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
+# create the CRC tables. So if small mode is enabled, the threading mode is
+# 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"\
+               = 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
+               __attribute__((__constructor__))])
+fi
+
 # __attribute__((__ifunc__())) can be used to choose between different
 # implementations of the same function at runtime. This is slightly more
 # efficient than using __attribute__((__constructor__)) and setting