This macro deduplicates the
$CC -v 2>&1 | sed -n 's/^Thread model: //p'
check that was occurring in various runtime libs.
Additionally, as a bit of an Easter egg, this also allows overriding
what the compiler would return by setting the
`gcc_cv_target_thread_file` cache variable first. I admit that it is in
fact this Easter egg that led me to write the patch. The use-case for it
is for making multilib builds where the library sets do not all share
the same thread model easier. See also `THREAD_MODEL_SPEC` for more
about the varying thread models use-case.
Arguably one could could try to define on `THREAD_MODEL_SPEC` on more
platforms (besides e.g. AIX) but the ramifications of this are a bit
unclear. Setting `gcc_cv_target_thread_file` directly is a "low tech"
solution that will work for now for sure. Of course, since setting a
cache variable like this a hacky trick, I will not expect this to be at
all stable/guaranteed to work, going forward.
Thanks to Arsen who on IRC discussed these things with me, including in
particular making it a cache var not `--with-model` flag, to not
prematurely foster expectations that this is stable.
Suggested-by: Arsen Arsenović <[email protected]>
config/ChangeLog:
* gthr.m4: Create new GCC_AC_THREAD_MODEL macro
libatomic/ChangeLog:
* Makefile.in: Regenerate.
* aclocal.m4: Regenerate.
* configure: Regenerate.
* configure.ac: Use GCC_AC_THREAD_MODEL instead of hand-rolled
* testsuite/Makefile.in: Regenerate.
libgcc/ChangeLog:
* configure: Regenerate.
* configure.ac: Use GCC_AC_THREAD_MODEL instead of hand-rolled
libphobos/ChangeLog:
* configure: Regenerate.
* m4/druntime/os.m4: Use AC_MSG_ERROR, not private as_fn_error
libstdc++-v3/ChangeLog:
* acinclude.m4: Use GCC_AC_THREAD_MODEL instead, via AC_REQUIRE
* configure: Regenerate.
---
config/gthr.m4 | 23 ++++++++++++++++++
libatomic/Makefile.in | 1 +
libatomic/aclocal.m4 | 1 +
libatomic/configure | 27 ++++++++++++++++++----
libatomic/configure.ac | 4 +---
libatomic/testsuite/Makefile.in | 1 +
libgcc/configure | 30 ++++++++++++++++++++----
libgcc/configure.ac | 4 +---
libphobos/configure | 2 +-
libphobos/m4/druntime/os.m4 | 2 +-
libstdc++-v3/acinclude.m4 | 6 ++---
libstdc++-v3/configure | 41 +++++++++++++++++++++++++--------
12 files changed, 110 insertions(+), 32 deletions(-)
diff --git a/config/gthr.m4 b/config/gthr.m4
index 11996247f15..e8fac4a5721 100644
--- a/config/gthr.m4
+++ b/config/gthr.m4
@@ -5,6 +5,26 @@ dnl Public License, this file may be distributed as part of a
program
dnl that contains a configuration script generated by Autoconf, under
dnl the same distribution terms as the rest of that program.
+dnl Define thread model
+
+dnl usage: GCC_AC_THREAD_MODEL
+AC_DEFUN([GCC_AC_THREAD_MODEL],
+[
+# Specify the threading model for this GCC runtime library
+# Pass with no value to take from compiler's metadata
+# Pass with a value to specify a thread package
+# 'single' means single threaded -- without threads.
+AC_CACHE_CHECK([for the threading model used by GCC],
[gcc_cv_target_thread_file], [
+ # Set new cache variable
+ gcc_cv_target_thread_file=`$CC -v 2>&1 | sed -n 's/^Thread model: //p'`
+])
+# Set variable name (not prefixed enough to be a good cache variable
+# name) traditionally used for this purpose, to avoid having to change
+# a bunch of configure scripts.
+target_thread_file="$gcc_cv_target_thread_file"
+])
+
+
dnl Define header location by thread model
dnl usage: GCC_AC_THREAD_HEADER([thread_model])
@@ -23,6 +43,9 @@ case $1 in
vxworks) thread_header=config/gthr-vxworks.h ;;
win32) thread_header=config/i386/gthr-win32.h ;;
mcf) thread_header=config/i386/gthr-mcf.h ;;
+ *)
+ AC_MSG_ERROR([No known header for threading model '$1'.])
+ ;;
esac
AC_SUBST(thread_header)
])
diff --git a/libatomic/Makefile.in b/libatomic/Makefile.in
index 4344ac4a2e8..d4f8234a6ce 100644
--- a/libatomic/Makefile.in
+++ b/libatomic/Makefile.in
@@ -105,6 +105,7 @@ subdir = .
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
$(top_srcdir)/../config/depstand.m4 \
+ $(top_srcdir)/../config/gthr.m4 \
$(top_srcdir)/../config/lead-dot.m4 \
$(top_srcdir)/../config/lthostflags.m4 \
$(top_srcdir)/../config/multi.m4 \
diff --git a/libatomic/aclocal.m4 b/libatomic/aclocal.m4
index 80e24219d7d..581fedcfe13 100644
--- a/libatomic/aclocal.m4
+++ b/libatomic/aclocal.m4
@@ -1189,6 +1189,7 @@ AC_SUBST([am__untar])
m4_include([../config/acx.m4])
m4_include([../config/depstand.m4])
+m4_include([../config/gthr.m4])
m4_include([../config/lead-dot.m4])
m4_include([../config/lthostflags.m4])
m4_include([../config/multi.m4])
diff --git a/libatomic/configure b/libatomic/configure
index 67b3a6388d7..27863ae4378 100755
--- a/libatomic/configure
+++ b/libatomic/configure
@@ -11863,11 +11863,28 @@ libtool_VERSION=3:0:2
# Check for used threading-model
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for thread model used by
GCC" >&5
-$as_echo_n "checking for thread model used by GCC... " >&6; }
-target_thread_file=`$CC -v 2>&1 | sed -n 's/^Thread model: //p'`
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $target_thread_file" >&5
-$as_echo "$target_thread_file" >&6; }
+
+# Specify the threading model for this GCC runtime library
+# Pass with no value to take from compiler's metadata
+# Pass with a value to specify a thread package
+# 'single' means single threaded -- without threads.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for the threading model used
by GCC" >&5
+$as_echo_n "checking for the threading model used by GCC... " >&6; }
+if ${gcc_cv_target_thread_file+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+
+ # Set new cache variable
+ gcc_cv_target_thread_file=`$CC -v 2>&1 | sed -n 's/^Thread model: //p'`
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_target_thread_file"
>&5
+$as_echo "$gcc_cv_target_thread_file" >&6; }
+# Set variable name (not prefixed enough to be a good cache variable
+# name) traditionally used for this purpose, to avoid having to change
+# a bunch of configure scripts.
+target_thread_file="$gcc_cv_target_thread_file"
+
case "$target" in
*aarch64*)
diff --git a/libatomic/configure.ac b/libatomic/configure.ac
index 01141f64376..205d126e6f3 100644
--- a/libatomic/configure.ac
+++ b/libatomic/configure.ac
@@ -162,9 +162,7 @@ libtool_VERSION=3:0:2
AC_SUBST(libtool_VERSION)
# Check for used threading-model
-AC_MSG_CHECKING([for thread model used by GCC])
-target_thread_file=`$CC -v 2>&1 | sed -n 's/^Thread model: //p'`
-AC_MSG_RESULT([$target_thread_file])
+GCC_AC_THREAD_MODEL
case "$target" in
*aarch64*)
diff --git a/libatomic/testsuite/Makefile.in b/libatomic/testsuite/Makefile.in
index 247268f1949..01195af96a4 100644
--- a/libatomic/testsuite/Makefile.in
+++ b/libatomic/testsuite/Makefile.in
@@ -92,6 +92,7 @@ subdir = testsuite
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
$(top_srcdir)/../config/depstand.m4 \
+ $(top_srcdir)/../config/gthr.m4 \
$(top_srcdir)/../config/lead-dot.m4 \
$(top_srcdir)/../config/lthostflags.m4 \
$(top_srcdir)/../config/multi.m4 \
diff --git a/libgcc/configure b/libgcc/configure
index 18418336c9b..bdd3d74be15 100755
--- a/libgcc/configure
+++ b/libgcc/configure
@@ -5043,11 +5043,28 @@ $as_echo "$acl_cv_prog_gnu_ld" >&6; }
with_gnu_ld=$acl_cv_prog_gnu_ld
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for thread model used by
GCC" >&5
-$as_echo_n "checking for thread model used by GCC... " >&6; }
-target_thread_file=`$CC -v 2>&1 | sed -n 's/^Thread model: //p'`
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $target_thread_file" >&5
-$as_echo "$target_thread_file" >&6; }
+
+# Specify the threading model for this GCC runtime library
+# Pass with no value to take from compiler's metadata
+# Pass with a value to specify a thread package
+# 'single' means single threaded -- without threads.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for the threading model used
by GCC" >&5
+$as_echo_n "checking for the threading model used by GCC... " >&6; }
+if ${gcc_cv_target_thread_file+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+
+ # Set new cache variable
+ gcc_cv_target_thread_file=`$CC -v 2>&1 | sed -n 's/^Thread model: //p'`
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_target_thread_file"
>&5
+$as_echo "$gcc_cv_target_thread_file" >&6; }
+# Set variable name (not prefixed enough to be a good cache variable
+# name) traditionally used for this purpose, to avoid having to change
+# a bunch of configure scripts.
+target_thread_file="$gcc_cv_target_thread_file"
+
# Check for assembler CFI support.
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether assembler supports
CFI directives" >&5
@@ -5734,6 +5751,9 @@ case $target_thread_file in
vxworks) thread_header=config/gthr-vxworks.h ;;
win32) thread_header=config/i386/gthr-win32.h ;;
mcf) thread_header=config/i386/gthr-mcf.h ;;
+ *)
+ as_fn_error $? "No known header for threading model
'$target_thread_file'." "$LINENO" 5
+ ;;
esac
diff --git a/libgcc/configure.ac b/libgcc/configure.ac
index 85e4f1bc48b..d44493f9653 100644
--- a/libgcc/configure.ac
+++ b/libgcc/configure.ac
@@ -305,9 +305,7 @@ AC_SUBST([use_tm_clone_registry])
AC_LIB_PROG_LD_GNU
-AC_MSG_CHECKING([for thread model used by GCC])
-target_thread_file=`$CC -v 2>&1 | sed -n 's/^Thread model: //p'`
-AC_MSG_RESULT([$target_thread_file])
+GCC_AC_THREAD_MODEL
# Check for assembler CFI support.
AC_CACHE_CHECK([whether assembler supports CFI directives], [libgcc_cv_cfi],
diff --git a/libphobos/configure b/libphobos/configure
index 4f5be7d4ff4..02c49ec52e0 100755
--- a/libphobos/configure
+++ b/libphobos/configure
@@ -14546,7 +14546,7 @@ case $d_thread_model in
# TODO: These targets need porting.
dce|mipssde|rtems|tpf|vxworks)
DCFG_THREAD_MODEL="Single" ;;
- *) as_fn_error "Thread implementation '$d_thread_model' not
recognised" "$LINENO" 5 ;;
+ *) as_fn_error $? "Thread implementation '$d_thread_model' not
recognised" "$LINENO" 5 ;;
esac
diff --git a/libphobos/m4/druntime/os.m4 b/libphobos/m4/druntime/os.m4
index ef8ca434407..7bb91362dbe 100644
--- a/libphobos/m4/druntime/os.m4
+++ b/libphobos/m4/druntime/os.m4
@@ -32,7 +32,7 @@ case $1 in
# TODO: These targets need porting.
dce|mipssde|rtems|tpf|vxworks)
DCFG_THREAD_MODEL="Single" ;;
- *) as_fn_error "Thread implementation '$1' not recognised" "$LINENO" 5
;;
+ *) AC_MSG_ERROR([Thread implementation '$1' not recognised]) ;;
esac
AC_SUBST(DCFG_THREAD_MODEL)
])
diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4
index 080a4fca9b5..7f4b011e4a3 100644
--- a/libstdc++-v3/acinclude.m4
+++ b/libstdc++-v3/acinclude.m4
@@ -4187,9 +4187,7 @@ dnl Substs:
dnl thread_header
dnl
AC_DEFUN([GLIBCXX_ENABLE_THREADS], [
- AC_MSG_CHECKING([for thread model used by GCC])
- target_thread_file=`$CXX -v 2>&1 | sed -n 's/^Thread model: //p'`
- AC_MSG_RESULT([$target_thread_file])
+ AC_REQUIRE([GCC_AC_THREAD_MODEL])
GCC_AC_THREAD_HEADER([$target_thread_file])
])
@@ -4202,6 +4200,7 @@ dnl
dnl GLIBCXX_ENABLE_SYMVERS must be done before this.
dnl
AC_DEFUN([GLIBCXX_CHECK_GTHREADS], [
+ AC_REQUIRE([GCC_AC_THREAD_MODEL])
GLIBCXX_ENABLE(libstdcxx-threads,auto,,[enable C++11 threads support])
if test x$enable_libstdcxx_threads = xauto ||
@@ -4214,7 +4213,6 @@ AC_DEFUN([GLIBCXX_CHECK_GTHREADS], [
CXXFLAGS="$CXXFLAGS -fno-exceptions \
-I${toplevel_srcdir}/libgcc -I${toplevel_builddir}/libgcc"
- target_thread_file=`$CXX -v 2>&1 | sed -n 's/^Thread model: //p'`
case $target_thread_file in
posix)
CXXFLAGS="$CXXFLAGS -DSUPPORTS_WEAK -DGTHREAD_USE_WEAK -D_PTHREADS"
diff --git a/libstdc++-v3/configure b/libstdc++-v3/configure
index 69aa246ec7f..d41e2e2395b 100755
--- a/libstdc++-v3/configure
+++ b/libstdc++-v3/configure
@@ -15956,11 +15956,29 @@ $as_echo "$enable_libstdcxx_pch" >&6; }
- { $as_echo "$as_me:${as_lineno-$LINENO}: checking for thread model used by
GCC" >&5
-$as_echo_n "checking for thread model used by GCC... " >&6; }
- target_thread_file=`$CXX -v 2>&1 | sed -n 's/^Thread model: //p'`
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: $target_thread_file" >&5
-$as_echo "$target_thread_file" >&6; }
+# Specify the threading model for this GCC runtime library
+# Pass with no value to take from compiler's metadata
+# Pass with a value to specify a thread package
+# 'single' means single threaded -- without threads.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for the threading model used
by GCC" >&5
+$as_echo_n "checking for the threading model used by GCC... " >&6; }
+if ${gcc_cv_target_thread_file+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+
+ # Set new cache variable
+ gcc_cv_target_thread_file=`$CC -v 2>&1 | sed -n 's/^Thread model: //p'`
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_target_thread_file"
>&5
+$as_echo "$gcc_cv_target_thread_file" >&6; }
+# Set variable name (not prefixed enough to be a good cache variable
+# name) traditionally used for this purpose, to avoid having to change
+# a bunch of configure scripts.
+target_thread_file="$gcc_cv_target_thread_file"
+
+
+
case $target_thread_file in
aix) thread_header=config/rs6000/gthr-aix.h ;;
@@ -15975,6 +15993,9 @@ case $target_thread_file in
vxworks) thread_header=config/gthr-vxworks.h ;;
win32) thread_header=config/i386/gthr-win32.h ;;
mcf) thread_header=config/i386/gthr-mcf.h ;;
+ *)
+ as_fn_error $? "No known header for threading model
'$target_thread_file'." "$LINENO" 5
+ ;;
esac
@@ -16048,7 +16069,7 @@ $as_echo "$glibcxx_cv_atomic_word" >&6; }
# Fake what AC_TRY_COMPILE does.
cat > conftest.$ac_ext << EOF
-#line 16051 "configure"
+#line 16072 "configure"
#include "${glibcxx_srcdir}/config/$atomic_word_dir/atomic_word.h"
int main()
{
@@ -16194,7 +16215,7 @@ $as_echo "mutex" >&6; }
# unnecessary for this test.
cat > conftest.$ac_ext << EOF
-#line 16197 "configure"
+#line 16218 "configure"
int main()
{
_Decimal32 d1;
@@ -16236,7 +16257,7 @@ ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
# unnecessary for this test.
cat > conftest.$ac_ext << EOF
-#line 16239 "configure"
+#line 16260 "configure"
template<typename T1, typename T2>
struct same
{ typedef T2 type; };
@@ -51826,6 +51847,7 @@ done
# For gthread support. Depends on GLIBCXX_ENABLE_SYMVERS.
+
# Check whether --enable-libstdcxx-threads was given.
if test "${enable_libstdcxx_threads+set}" = set; then :
enableval=$enable_libstdcxx_threads;
@@ -51855,7 +51877,6 @@ ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
CXXFLAGS="$CXXFLAGS -fno-exceptions \
-I${toplevel_srcdir}/libgcc -I${toplevel_builddir}/libgcc"
- target_thread_file=`$CXX -v 2>&1 | sed -n 's/^Thread model: //p'`
case $target_thread_file in
posix)
CXXFLAGS="$CXXFLAGS -DSUPPORTS_WEAK -DGTHREAD_USE_WEAK -D_PTHREADS"
@@ -53543,7 +53564,7 @@ $as_echo "$glibcxx_cv_libbacktrace_atomics" >&6; }
CXXFLAGS='-O0 -S'
cat > conftest.$ac_ext << EOF
-#line 53546 "configure"
+#line 53567 "configure"
#include <stddef.h>
int main()
{
--
2.49.0