Skip to content

Commit e5d853b

Browse files
Ericson2314jsm28
authored andcommitted
Factor out thread model detection with new GCC_AC_THREAD_MODEL macro
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.
1 parent 1dd44eb commit e5d853b

File tree

12 files changed

+129
-51
lines changed

12 files changed

+129
-51
lines changed

config/gthr.m4

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,26 @@ dnl Public License, this file may be distributed as part of a program
55
dnl that contains a configuration script generated by Autoconf, under
66
dnl the same distribution terms as the rest of that program.
77

8+
dnl Define thread model
9+
10+
dnl usage: GCC_AC_THREAD_MODEL
11+
AC_DEFUN([GCC_AC_THREAD_MODEL],
12+
[
13+
# Specify the threading model for this GCC runtime library
14+
# Pass with no value to take from compiler's metadata
15+
# Pass with a value to specify a thread package
16+
# 'single' means single threaded -- without threads.
17+
AC_CACHE_CHECK([for the threading model used by GCC], [gcc_cv_target_thread_file], [
18+
# Set new cache variable
19+
gcc_cv_target_thread_file=`$CC -v 2>&1 | sed -n 's/^Thread model: //p'`
20+
])
21+
# Set variable name (not prefixed enough to be a good cache variable
22+
# name) traditionally used for this purpose, to avoid having to change
23+
# a bunch of configure scripts.
24+
target_thread_file="$gcc_cv_target_thread_file"
25+
])
26+
27+
828
dnl Define header location by thread model
929

1030
dnl usage: GCC_AC_THREAD_HEADER([thread_model])
@@ -23,6 +43,9 @@ case $1 in
2343
vxworks) thread_header=config/gthr-vxworks.h ;;
2444
win32) thread_header=config/i386/gthr-win32.h ;;
2545
mcf) thread_header=config/i386/gthr-mcf.h ;;
46+
*)
47+
AC_MSG_ERROR([No known header for threading model '$1'.])
48+
;;
2649
esac
2750
AC_SUBST(thread_header)
2851
])

libatomic/Makefile.in

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
108108
$(top_srcdir)/../config/clang-plugin.m4 \
109109
$(top_srcdir)/../config/depstand.m4 \
110110
$(top_srcdir)/../config/gcc-plugin.m4 \
111+
$(top_srcdir)/../config/gthr.m4 \
111112
$(top_srcdir)/../config/lead-dot.m4 \
112113
$(top_srcdir)/../config/lthostflags.m4 \
113114
$(top_srcdir)/../config/multi.m4 \
@@ -171,7 +172,7 @@ libatomic_la_OBJECTS = $(am_libatomic_la_OBJECTS)
171172
AM_V_lt = $(am__v_lt_@AM_V@)
172173
am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
173174
am__v_lt_0 = --silent
174-
am__v_lt_1 =
175+
am__v_lt_1 =
175176
libatomic_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
176177
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
177178
$(libatomic_la_LDFLAGS) $(LDFLAGS) -o $@
@@ -192,11 +193,11 @@ am__v_P_1 = :
192193
AM_V_GEN = $(am__v_GEN_@AM_V@)
193194
am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
194195
am__v_GEN_0 = @echo " GEN " $@;
195-
am__v_GEN_1 =
196+
am__v_GEN_1 =
196197
AM_V_at = $(am__v_at_@AM_V@)
197198
am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
198199
am__v_at_0 = @
199-
am__v_at_1 =
200+
am__v_at_1 =
200201
depcomp = $(SHELL) $(top_srcdir)/../depcomp
201202
am__depfiles_maybe = depfiles
202203
am__mv = mv -f
@@ -209,7 +210,7 @@ LTCPPASCOMPILE = $(LIBTOOL) $(AM_V_lt) $(AM_LIBTOOLFLAGS) \
209210
AM_V_CPPAS = $(am__v_CPPAS_@AM_V@)
210211
am__v_CPPAS_ = $(am__v_CPPAS_@AM_DEFAULT_V@)
211212
am__v_CPPAS_0 = @echo " CPPAS " $@;
212-
am__v_CPPAS_1 =
213+
am__v_CPPAS_1 =
213214
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
214215
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
215216
LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
@@ -219,15 +220,15 @@ LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
219220
AM_V_CC = $(am__v_CC_@AM_V@)
220221
am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@)
221222
am__v_CC_0 = @echo " CC " $@;
222-
am__v_CC_1 =
223+
am__v_CC_1 =
223224
CCLD = $(CC)
224225
LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
225226
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
226227
$(AM_LDFLAGS) $(LDFLAGS) -o $@
227228
AM_V_CCLD = $(am__v_CCLD_@AM_V@)
228229
am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
229230
am__v_CCLD_0 = @echo " CCLD " $@;
230-
am__v_CCLD_1 =
231+
am__v_CCLD_1 =
231232
SOURCES = $(libatomic_la_SOURCES) $(EXTRA_libatomic_la_SOURCES) \
232233
$(libatomic_convenience_la_SOURCES)
233234
RECURSIVE_TARGETS = all-recursive check-recursive cscopelist-recursive \
@@ -422,10 +423,10 @@ AM_CCASFLAGS = $(XCFLAGS)
422423
AM_LDFLAGS = $(XLDFLAGS) $(SECTION_LDFLAGS) $(OPT_LDFLAGS)
423424
toolexeclib_LTLIBRARIES = libatomic.la
424425
noinst_LTLIBRARIES = libatomic_convenience.la
425-
@LIBAT_BUILD_VERSIONED_SHLIB_FALSE@libatomic_version_script =
426+
@LIBAT_BUILD_VERSIONED_SHLIB_FALSE@libatomic_version_script =
426427
@LIBAT_BUILD_VERSIONED_SHLIB_GNU_TRUE@@LIBAT_BUILD_VERSIONED_SHLIB_TRUE@libatomic_version_script = -Wl,--version-script,$(top_srcdir)/libatomic.map
427428
@LIBAT_BUILD_VERSIONED_SHLIB_SUN_TRUE@@LIBAT_BUILD_VERSIONED_SHLIB_TRUE@libatomic_version_script = -Wl,-M,libatomic.map-sun
428-
@LIBAT_BUILD_VERSIONED_SHLIB_FALSE@libatomic_version_dep =
429+
@LIBAT_BUILD_VERSIONED_SHLIB_FALSE@libatomic_version_dep =
429430
@LIBAT_BUILD_VERSIONED_SHLIB_GNU_TRUE@@LIBAT_BUILD_VERSIONED_SHLIB_TRUE@libatomic_version_dep = $(top_srcdir)/libatomic.map
430431
@LIBAT_BUILD_VERSIONED_SHLIB_SUN_TRUE@@LIBAT_BUILD_VERSIONED_SHLIB_TRUE@libatomic_version_dep = libatomic.map-sun
431432
libatomic_version_info = -version-info $(libtool_VERSION)
@@ -443,7 +444,7 @@ libatomic_la_LDFLAGS = $(libatomic_version_info) $(libatomic_version_script) \
443444
@PARTIAL_VXWORKS_FALSE@SIZEOBJS = load store cas exch fadd fsub fand fior fxor fnand tas
444445
@PARTIAL_VXWORKS_FALSE@EXTRA_libatomic_la_SOURCES = $(addsuffix _n.c,$(SIZEOBJS))
445446
@PARTIAL_VXWORKS_FALSE@libatomic_la_DEPENDENCIES = $(libatomic_la_LIBADD) $(libatomic_version_dep)
446-
@PARTIAL_VXWORKS_FALSE@empty =
447+
@PARTIAL_VXWORKS_FALSE@empty =
447448
@PARTIAL_VXWORKS_FALSE@space = $(empty) $(empty)
448449
@PARTIAL_VXWORKS_FALSE@PAT_SPLIT = $(subst _,$(space),$(*F))
449450
@PARTIAL_VXWORKS_FALSE@PAT_BASE = $(word 1,$(PAT_SPLIT))
@@ -452,7 +453,7 @@ libatomic_la_LDFLAGS = $(libatomic_version_info) $(libatomic_version_script) \
452453
@PARTIAL_VXWORKS_FALSE@IFUNC_DEF = -DIFUNC_ALT=$(PAT_S)
453454
@PARTIAL_VXWORKS_FALSE@IFUNC_OPT = $(subst |,$(space),$(word $(PAT_S),$(IFUNC_OPTIONS)))
454455
@PARTIAL_VXWORKS_FALSE@@AMDEP_TRUE@M_DEPS = -MT $@ -MD -MP -MF $(DEPDIR)/$(@F).Ppo
455-
@PARTIAL_VXWORKS_FALSE@@AMDEP_FALSE@M_DEPS =
456+
@PARTIAL_VXWORKS_FALSE@@AMDEP_FALSE@M_DEPS =
456457
@PARTIAL_VXWORKS_FALSE@M_SIZE = -DN=$(PAT_N)
457458
@PARTIAL_VXWORKS_FALSE@M_IFUNC = $(if $(PAT_S),$(IFUNC_DEF) $(IFUNC_OPT))
458459
@PARTIAL_VXWORKS_FALSE@M_FILE = $(PAT_BASE)_n.c
@@ -485,10 +486,10 @@ libatomic_convenience_la_LIBADD = $(libatomic_la_LIBADD)
485486
# built after libatomic, which makes RPATH insecure. Removing libatomic.la
486487
# from $gcc_objdir seems to fix the issue.
487488
gcc_objdir = `pwd`/$(MULTIBUILDTOP)../../gcc/
488-
MULTISRCTOP =
489-
MULTIBUILDTOP =
490-
MULTIDIRS =
491-
MULTISUBDIR =
489+
MULTISRCTOP =
490+
MULTIBUILDTOP =
491+
MULTIDIRS =
492+
MULTISUBDIR =
492493
MULTIDO = true
493494
MULTICLEAN = true
494495
all: auto-config.h
@@ -538,7 +539,7 @@ auto-config.h: stamp-h1
538539
stamp-h1: $(srcdir)/auto-config.h.in $(top_builddir)/config.status
539540
@rm -f stamp-h1
540541
cd $(top_builddir) && $(SHELL) ./config.status auto-config.h
541-
$(srcdir)/auto-config.h.in: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
542+
$(srcdir)/auto-config.h.in: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
542543
($(am__cd) $(top_srcdir) && $(AUTOHEADER))
543544
rm -f stamp-h1
544545
touch $@
@@ -592,10 +593,10 @@ clean-toolexeclibLTLIBRARIES:
592593
rm -f $${locs}; \
593594
}
594595

595-
libatomic.la: $(libatomic_la_OBJECTS) $(libatomic_la_DEPENDENCIES) $(EXTRA_libatomic_la_DEPENDENCIES)
596+
libatomic.la: $(libatomic_la_OBJECTS) $(libatomic_la_DEPENDENCIES) $(EXTRA_libatomic_la_DEPENDENCIES)
596597
$(AM_V_CCLD)$(libatomic_la_LINK) -rpath $(toolexeclibdir) $(libatomic_la_OBJECTS) $(libatomic_la_LIBADD) $(LIBS)
597598

598-
libatomic_convenience.la: $(libatomic_convenience_la_OBJECTS) $(libatomic_convenience_la_DEPENDENCIES) $(EXTRA_libatomic_convenience_la_DEPENDENCIES)
599+
libatomic_convenience.la: $(libatomic_convenience_la_OBJECTS) $(libatomic_convenience_la_DEPENDENCIES) $(EXTRA_libatomic_convenience_la_DEPENDENCIES)
599600
$(AM_V_CCLD)$(LINK) $(libatomic_convenience_la_OBJECTS) $(libatomic_convenience_la_LIBADD) $(LIBS)
600601

601602
mostlyclean-compile:

libatomic/aclocal.m4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,6 +1191,7 @@ m4_include([../config/acx.m4])
11911191
m4_include([../config/clang-plugin.m4])
11921192
m4_include([../config/depstand.m4])
11931193
m4_include([../config/gcc-plugin.m4])
1194+
m4_include([../config/gthr.m4])
11941195
m4_include([../config/lead-dot.m4])
11951196
m4_include([../config/lthostflags.m4])
11961197
m4_include([../config/multi.m4])

libatomic/configure

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12254,11 +12254,28 @@ libtool_VERSION=3:0:2
1225412254

1225512255

1225612256
# Check for used threading-model
12257-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for thread model used by GCC" >&5
12258-
$as_echo_n "checking for thread model used by GCC... " >&6; }
12259-
target_thread_file=`$CC -v 2>&1 | sed -n 's/^Thread model: //p'`
12260-
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $target_thread_file" >&5
12261-
$as_echo "$target_thread_file" >&6; }
12257+
12258+
# Specify the threading model for this GCC runtime library
12259+
# Pass with no value to take from compiler's metadata
12260+
# Pass with a value to specify a thread package
12261+
# 'single' means single threaded -- without threads.
12262+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for the threading model used by GCC" >&5
12263+
$as_echo_n "checking for the threading model used by GCC... " >&6; }
12264+
if ${gcc_cv_target_thread_file+:} false; then :
12265+
$as_echo_n "(cached) " >&6
12266+
else
12267+
12268+
# Set new cache variable
12269+
gcc_cv_target_thread_file=`$CC -v 2>&1 | sed -n 's/^Thread model: //p'`
12270+
12271+
fi
12272+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_target_thread_file" >&5
12273+
$as_echo "$gcc_cv_target_thread_file" >&6; }
12274+
# Set variable name (not prefixed enough to be a good cache variable
12275+
# name) traditionally used for this purpose, to avoid having to change
12276+
# a bunch of configure scripts.
12277+
target_thread_file="$gcc_cv_target_thread_file"
12278+
1226212279

1226312280
case "$target" in
1226412281
*aarch64*)

libatomic/configure.ac

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,7 @@ libtool_VERSION=3:0:2
177177
AC_SUBST(libtool_VERSION)
178178

179179
# Check for used threading-model
180-
AC_MSG_CHECKING([for thread model used by GCC])
181-
target_thread_file=`$CC -v 2>&1 | sed -n 's/^Thread model: //p'`
182-
AC_MSG_RESULT([$target_thread_file])
180+
GCC_AC_THREAD_MODEL
183181

184182
case "$target" in
185183
*aarch64*)

libatomic/testsuite/Makefile.in

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
9494
$(top_srcdir)/../config/clang-plugin.m4 \
9595
$(top_srcdir)/../config/depstand.m4 \
9696
$(top_srcdir)/../config/gcc-plugin.m4 \
97+
$(top_srcdir)/../config/gthr.m4 \
9798
$(top_srcdir)/../config/lead-dot.m4 \
9899
$(top_srcdir)/../config/lthostflags.m4 \
99100
$(top_srcdir)/../config/multi.m4 \
@@ -120,11 +121,11 @@ am__v_P_1 = :
120121
AM_V_GEN = $(am__v_GEN_@AM_V@)
121122
am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
122123
am__v_GEN_0 = @echo " GEN " $@;
123-
am__v_GEN_1 =
124+
am__v_GEN_1 =
124125
AM_V_at = $(am__v_at_@AM_V@)
125126
am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
126127
am__v_at_0 = @
127-
am__v_at_1 =
128+
am__v_at_1 =
128129
SOURCES =
129130
am__can_run_installinfo = \
130131
case $$AM_UPDATE_INFO_DIR in \

libgcc/configure

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5046,11 +5046,28 @@ $as_echo "$acl_cv_prog_gnu_ld" >&6; }
50465046
with_gnu_ld=$acl_cv_prog_gnu_ld
50475047
50485048
5049-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for thread model used by GCC" >&5
5050-
$as_echo_n "checking for thread model used by GCC... " >&6; }
5051-
target_thread_file=`$CC -v 2>&1 | sed -n 's/^Thread model: //p'`
5052-
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $target_thread_file" >&5
5053-
$as_echo "$target_thread_file" >&6; }
5049+
5050+
# Specify the threading model for this GCC runtime library
5051+
# Pass with no value to take from compiler's metadata
5052+
# Pass with a value to specify a thread package
5053+
# 'single' means single threaded -- without threads.
5054+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for the threading model used by GCC" >&5
5055+
$as_echo_n "checking for the threading model used by GCC... " >&6; }
5056+
if ${gcc_cv_target_thread_file+:} false; then :
5057+
$as_echo_n "(cached) " >&6
5058+
else
5059+
5060+
# Set new cache variable
5061+
gcc_cv_target_thread_file=`$CC -v 2>&1 | sed -n 's/^Thread model: //p'`
5062+
5063+
fi
5064+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_target_thread_file" >&5
5065+
$as_echo "$gcc_cv_target_thread_file" >&6; }
5066+
# Set variable name (not prefixed enough to be a good cache variable
5067+
# name) traditionally used for this purpose, to avoid having to change
5068+
# a bunch of configure scripts.
5069+
target_thread_file="$gcc_cv_target_thread_file"
5070+
50545071
50555072
# Check for assembler CFI support.
50565073
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether assembler supports CFI directives" >&5
@@ -5737,6 +5754,9 @@ case $target_thread_file in
57375754
vxworks) thread_header=config/gthr-vxworks.h ;;
57385755
win32) thread_header=config/i386/gthr-win32.h ;;
57395756
mcf) thread_header=config/i386/gthr-mcf.h ;;
5757+
*)
5758+
as_fn_error $? "No known header for threading model '$target_thread_file'." "$LINENO" 5
5759+
;;
57405760
esac
57415761
57425762

libgcc/configure.ac

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,9 +305,7 @@ AC_SUBST([use_tm_clone_registry])
305305

306306
AC_LIB_PROG_LD_GNU
307307

308-
AC_MSG_CHECKING([for thread model used by GCC])
309-
target_thread_file=`$CC -v 2>&1 | sed -n 's/^Thread model: //p'`
310-
AC_MSG_RESULT([$target_thread_file])
308+
GCC_AC_THREAD_MODEL
311309

312310
# Check for assembler CFI support.
313311
AC_CACHE_CHECK([whether assembler supports CFI directives], [libgcc_cv_cfi],

libphobos/configure

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14920,7 +14920,7 @@ case $d_thread_model in
1492014920
# TODO: These targets need porting.
1492114921
dce|mipssde|rtems|tpf|vxworks)
1492214922
DCFG_THREAD_MODEL="Single" ;;
14923-
*) as_fn_error "Thread implementation '$d_thread_model' not recognised" "$LINENO" 5 ;;
14923+
*) as_fn_error $? "Thread implementation '$d_thread_model' not recognised" "$LINENO" 5 ;;
1492414924
esac
1492514925

1492614926

libphobos/m4/druntime/os.m4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ case $1 in
3232
# TODO: These targets need porting.
3333
dce|mipssde|rtems|tpf|vxworks)
3434
DCFG_THREAD_MODEL="Single" ;;
35-
*) as_fn_error "Thread implementation '$1' not recognised" "$LINENO" 5 ;;
35+
*) AC_MSG_ERROR([Thread implementation '$1' not recognised]) ;;
3636
esac
3737
AC_SUBST(DCFG_THREAD_MODEL)
3838
])

0 commit comments

Comments
 (0)