Skip to content

Commit cc1e288

Browse files
chouquettejwakely
authored andcommitted
libstdc++: Check for TLS support on mingw cross-compilers
Native mingw builds enable TLS, but crosses don't because we don't use GCC_CHECK_TLS in the cross-compiler config. libstdc++-v3/ChangeLog: * crossconfig.m4: Check for TLS support on mingw. * configure: Regenerate.
1 parent 243e0a5 commit cc1e288

File tree

2 files changed

+209
-0
lines changed

2 files changed

+209
-0
lines changed

libstdc++-v3/configure

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60242,6 +60242,214 @@ _ACEOF
6024260242
fi
6024360243
done
6024460244

60245+
60246+
60247+
# Check whether --enable-tls was given.
60248+
if test "${enable_tls+set}" = set; then :
60249+
enableval=$enable_tls;
60250+
case "$enableval" in
60251+
yes|no) ;;
60252+
*) as_fn_error $? "Argument to enable/disable tls must be yes or no" "$LINENO" 5 ;;
60253+
esac
60254+
60255+
else
60256+
enable_tls=yes
60257+
fi
60258+
60259+
60260+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the target supports thread-local storage" >&5
60261+
$as_echo_n "checking whether the target supports thread-local storage... " >&6; }
60262+
if ${gcc_cv_have_tls+:} false; then :
60263+
$as_echo_n "(cached) " >&6
60264+
else
60265+
60266+
if test "$cross_compiling" = yes; then :
60267+
if test x$gcc_no_link = xyes; then
60268+
as_fn_error $? "Link tests are not allowed after GCC_NO_EXECUTABLES." "$LINENO" 5
60269+
fi
60270+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
60271+
/* end confdefs.h. */
60272+
__thread int a; int b; int main() { return a = b; }
60273+
_ACEOF
60274+
if ac_fn_c_try_link "$LINENO"; then :
60275+
chktls_save_LDFLAGS="$LDFLAGS"
60276+
case $host in
60277+
*-*-linux* | -*-uclinuxfdpic*)
60278+
LDFLAGS="-shared -Wl,--no-undefined $LDFLAGS"
60279+
;;
60280+
esac
60281+
chktls_save_CFLAGS="$CFLAGS"
60282+
CFLAGS="-fPIC $CFLAGS"
60283+
if test x$gcc_no_link = xyes; then
60284+
as_fn_error $? "Link tests are not allowed after GCC_NO_EXECUTABLES." "$LINENO" 5
60285+
fi
60286+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
60287+
/* end confdefs.h. */
60288+
int f() { return 0; }
60289+
_ACEOF
60290+
if ac_fn_c_try_link "$LINENO"; then :
60291+
if test x$gcc_no_link = xyes; then
60292+
as_fn_error $? "Link tests are not allowed after GCC_NO_EXECUTABLES." "$LINENO" 5
60293+
fi
60294+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
60295+
/* end confdefs.h. */
60296+
__thread int a; int b; int f() { return a = b; }
60297+
_ACEOF
60298+
if ac_fn_c_try_link "$LINENO"; then :
60299+
gcc_cv_have_tls=yes
60300+
else
60301+
gcc_cv_have_tls=no
60302+
fi
60303+
rm -f core conftest.err conftest.$ac_objext \
60304+
conftest$ac_exeext conftest.$ac_ext
60305+
else
60306+
gcc_cv_have_tls=yes
60307+
fi
60308+
rm -f core conftest.err conftest.$ac_objext \
60309+
conftest$ac_exeext conftest.$ac_ext
60310+
CFLAGS="$chktls_save_CFLAGS"
60311+
LDFLAGS="$chktls_save_LDFLAGS"
60312+
else
60313+
gcc_cv_have_tls=no
60314+
fi
60315+
rm -f core conftest.err conftest.$ac_objext \
60316+
conftest$ac_exeext conftest.$ac_ext
60317+
60318+
60319+
else
60320+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
60321+
/* end confdefs.h. */
60322+
__thread int a; int b; int main() { return a = b; }
60323+
_ACEOF
60324+
if ac_fn_c_try_run "$LINENO"; then :
60325+
chktls_save_LDFLAGS="$LDFLAGS"
60326+
LDFLAGS="-static $LDFLAGS"
60327+
if test x$gcc_no_link = xyes; then
60328+
as_fn_error $? "Link tests are not allowed after GCC_NO_EXECUTABLES." "$LINENO" 5
60329+
fi
60330+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
60331+
/* end confdefs.h. */
60332+
int main() { return 0; }
60333+
_ACEOF
60334+
if ac_fn_c_try_link "$LINENO"; then :
60335+
if test "$cross_compiling" = yes; then :
60336+
{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
60337+
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
60338+
as_fn_error $? "cannot run test program while cross compiling
60339+
See \`config.log' for more details" "$LINENO" 5; }
60340+
else
60341+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
60342+
/* end confdefs.h. */
60343+
__thread int a; int b; int main() { return a = b; }
60344+
_ACEOF
60345+
if ac_fn_c_try_run "$LINENO"; then :
60346+
gcc_cv_have_tls=yes
60347+
else
60348+
gcc_cv_have_tls=no
60349+
fi
60350+
rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
60351+
conftest.$ac_objext conftest.beam conftest.$ac_ext
60352+
fi
60353+
60354+
else
60355+
gcc_cv_have_tls=yes
60356+
fi
60357+
rm -f core conftest.err conftest.$ac_objext \
60358+
conftest$ac_exeext conftest.$ac_ext
60359+
LDFLAGS="$chktls_save_LDFLAGS"
60360+
if test $gcc_cv_have_tls = yes; then
60361+
chktls_save_CFLAGS="$CFLAGS"
60362+
thread_CFLAGS=failed
60363+
for flag in '' '-pthread' '-lpthread'; do
60364+
CFLAGS="$flag $chktls_save_CFLAGS"
60365+
if test x$gcc_no_link = xyes; then
60366+
as_fn_error $? "Link tests are not allowed after GCC_NO_EXECUTABLES." "$LINENO" 5
60367+
fi
60368+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
60369+
/* end confdefs.h. */
60370+
#include <pthread.h>
60371+
void *g(void *d) { return NULL; }
60372+
int
60373+
main ()
60374+
{
60375+
pthread_t t; pthread_create(&t,NULL,g,NULL);
60376+
;
60377+
return 0;
60378+
}
60379+
_ACEOF
60380+
if ac_fn_c_try_link "$LINENO"; then :
60381+
thread_CFLAGS="$flag"
60382+
fi
60383+
rm -f core conftest.err conftest.$ac_objext \
60384+
conftest$ac_exeext conftest.$ac_ext
60385+
if test "X$thread_CFLAGS" != Xfailed; then
60386+
break
60387+
fi
60388+
done
60389+
CFLAGS="$chktls_save_CFLAGS"
60390+
if test "X$thread_CFLAGS" != Xfailed; then
60391+
CFLAGS="$thread_CFLAGS $chktls_save_CFLAGS"
60392+
if test "$cross_compiling" = yes; then :
60393+
{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
60394+
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
60395+
as_fn_error $? "cannot run test program while cross compiling
60396+
See \`config.log' for more details" "$LINENO" 5; }
60397+
else
60398+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
60399+
/* end confdefs.h. */
60400+
#include <pthread.h>
60401+
__thread int a;
60402+
static int *volatile a_in_other_thread;
60403+
static void *
60404+
thread_func (void *arg)
60405+
{
60406+
a_in_other_thread = &a;
60407+
return (void *)0;
60408+
}
60409+
int
60410+
main ()
60411+
{
60412+
pthread_t thread;
60413+
void *thread_retval;
60414+
int *volatile a_in_main_thread;
60415+
a_in_main_thread = &a;
60416+
if (pthread_create (&thread, (pthread_attr_t *)0,
60417+
thread_func, (void *)0))
60418+
return 0;
60419+
if (pthread_join (thread, &thread_retval))
60420+
return 0;
60421+
return (a_in_other_thread == a_in_main_thread);
60422+
;
60423+
return 0;
60424+
}
60425+
_ACEOF
60426+
if ac_fn_c_try_run "$LINENO"; then :
60427+
gcc_cv_have_tls=yes
60428+
else
60429+
gcc_cv_have_tls=no
60430+
fi
60431+
rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
60432+
conftest.$ac_objext conftest.beam conftest.$ac_ext
60433+
fi
60434+
60435+
CFLAGS="$chktls_save_CFLAGS"
60436+
fi
60437+
fi
60438+
else
60439+
gcc_cv_have_tls=no
60440+
fi
60441+
rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
60442+
conftest.$ac_objext conftest.beam conftest.$ac_ext
60443+
fi
60444+
60445+
fi
60446+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_have_tls" >&5
60447+
$as_echo "$gcc_cv_have_tls" >&6; }
60448+
if test "$enable_tls $gcc_cv_have_tls" = "yes yes"; then
60449+
60450+
$as_echo "#define HAVE_TLS 1" >>confdefs.h
60451+
60452+
fi
6024560453
;;
6024660454
*-netbsd* | *-openbsd*)
6024760455
SECTION_FLAGS='-ffunction-sections -fdata-sections'

libstdc++-v3/crossconfig.m4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ case "${host}" in
204204
GLIBCXX_CHECK_STDLIB_SUPPORT
205205
AC_CHECK_FUNCS(aligned_alloc posix_memalign memalign _aligned_malloc)
206206
AC_CHECK_FUNCS(_wfopen)
207+
GCC_CHECK_TLS
207208
;;
208209
*-netbsd* | *-openbsd*)
209210
SECTION_FLAGS='-ffunction-sections -fdata-sections'

0 commit comments

Comments
 (0)