Mercurial > hg > CbC > CbC_gcc
annotate config/tls.m4 @ 158:494b0b89df80 default tip
...
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 25 May 2020 18:13:55 +0900 |
parents | 1830386684a0 |
children |
rev | line source |
---|---|
0 | 1 dnl Check whether the target supports TLS. |
2 AC_DEFUN([GCC_CHECK_TLS], [ | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
3 AC_REQUIRE([AC_CANONICAL_HOST]) |
0 | 4 GCC_ENABLE(tls, yes, [], [Use thread-local storage]) |
5 AC_CACHE_CHECK([whether the target supports thread-local storage], | |
6 gcc_cv_have_tls, [ | |
145 | 7 AC_RUN_IFELSE([AC_LANG_SOURCE([__thread int a; int b; int main() { return a = b; }])], |
0 | 8 [dnl If the test case passed with dynamic linking, try again with |
9 dnl static linking, but only if static linking is supported (not | |
10 dnl on Solaris 10). This fails with some older Red Hat releases. | |
11 chktls_save_LDFLAGS="$LDFLAGS" | |
12 LDFLAGS="-static $LDFLAGS" | |
145 | 13 AC_LINK_IFELSE([AC_LANG_SOURCE([int main() { return 0; }])], |
14 [AC_RUN_IFELSE([AC_LANG_SOURCE([__thread int a; int b; int main() { return a = b; }])], | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
15 [gcc_cv_have_tls=yes], [gcc_cv_have_tls=no],[])], |
0 | 16 [gcc_cv_have_tls=yes]) |
17 LDFLAGS="$chktls_save_LDFLAGS" | |
18 if test $gcc_cv_have_tls = yes; then | |
19 dnl So far, the binutils and the compiler support TLS. | |
20 dnl Also check whether the libc supports TLS, i.e. whether a variable | |
21 dnl with __thread linkage has a different address in different threads. | |
22 dnl First, find the thread_CFLAGS necessary for linking a program that | |
23 dnl calls pthread_create. | |
24 chktls_save_CFLAGS="$CFLAGS" | |
25 thread_CFLAGS=failed | |
26 for flag in '' '-pthread' '-lpthread'; do | |
27 CFLAGS="$flag $chktls_save_CFLAGS" | |
28 AC_LINK_IFELSE( | |
29 [AC_LANG_PROGRAM( | |
30 [#include <pthread.h> | |
31 void *g(void *d) { return NULL; }], | |
32 [pthread_t t; pthread_create(&t,NULL,g,NULL);])], | |
33 [thread_CFLAGS="$flag"]) | |
34 if test "X$thread_CFLAGS" != Xfailed; then | |
35 break | |
36 fi | |
37 done | |
38 CFLAGS="$chktls_save_CFLAGS" | |
39 if test "X$thread_CFLAGS" != Xfailed; then | |
40 CFLAGS="$thread_CFLAGS $chktls_save_CFLAGS" | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
41 dnl Test for an old glibc bug that violated the __thread property. |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
42 dnl Use volatile to ensure the compiler won't optimize away pointer |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
43 dnl accesses it might otherwise assume to be redundant, or reorder |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
44 dnl them and reuse storage, which might lead to them pointing to |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
45 dnl the same location. |
0 | 46 AC_RUN_IFELSE( |
47 [AC_LANG_PROGRAM( | |
48 [#include <pthread.h> | |
49 __thread int a; | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
50 static int *volatile a_in_other_thread; |
0 | 51 static void * |
52 thread_func (void *arg) | |
53 { | |
54 a_in_other_thread = &a; | |
55 return (void *)0; | |
56 }], | |
57 [pthread_t thread; | |
58 void *thread_retval; | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
59 int *volatile a_in_main_thread; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
60 a_in_main_thread = &a; |
0 | 61 if (pthread_create (&thread, (pthread_attr_t *)0, |
62 thread_func, (void *)0)) | |
63 return 0; | |
64 if (pthread_join (thread, &thread_retval)) | |
65 return 0; | |
66 return (a_in_other_thread == a_in_main_thread);])], | |
67 [gcc_cv_have_tls=yes], [gcc_cv_have_tls=no], []) | |
68 CFLAGS="$chktls_save_CFLAGS" | |
69 fi | |
70 fi], | |
71 [gcc_cv_have_tls=no], | |
72 [dnl This is the cross-compiling case. Assume libc supports TLS if the | |
73 dnl binutils and the compiler do. | |
145 | 74 AC_LINK_IFELSE([AC_LANG_SOURCE([__thread int a; int b; int main() { return a = b; }])], |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
75 [chktls_save_LDFLAGS="$LDFLAGS" |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
76 dnl Shared library options may depend on the host; this check |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
77 dnl is only known to be needed for GNU/Linux. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
78 case $host in |
145 | 79 *-*-linux* | -*-uclinuxfdpic*) |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
80 LDFLAGS="-shared -Wl,--no-undefined $LDFLAGS" |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
81 ;; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
82 esac |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
83 chktls_save_CFLAGS="$CFLAGS" |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
84 CFLAGS="-fPIC $CFLAGS" |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
85 dnl If -shared works, test if TLS works in a shared library. |
145 | 86 AC_LINK_IFELSE([AC_LANG_SOURCE([int f() { return 0; }])], |
87 [AC_LINK_IFELSE([AC_LANG_SOURCE([__thread int a; int b; int f() { return a = b; }])], | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
88 [gcc_cv_have_tls=yes], |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
89 [gcc_cv_have_tls=no])], |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
90 [gcc_cv_have_tls=yes]) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
91 CFLAGS="$chktls_save_CFLAGS" |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
92 LDFLAGS="$chktls_save_LDFLAGS"], [gcc_cv_have_tls=no]) |
0 | 93 ] |
94 )]) | |
95 if test "$enable_tls $gcc_cv_have_tls" = "yes yes"; then | |
96 AC_DEFINE(HAVE_TLS, 1, | |
97 [Define to 1 if the target supports thread-local storage.]) | |
98 fi]) | |
99 | |
100 dnl Check whether the target assembler supports TLS. | |
101 AC_DEFUN([GCC_CHECK_CC_TLS], [ | |
102 GCC_ENABLE(tls, yes, [], [Use thread-local storage]) | |
103 AC_CACHE_CHECK([whether the target assembler supports thread-local storage], | |
104 gcc_cv_have_cc_tls, [ | |
145 | 105 AC_COMPILE_IFELSE([AC_LANG_SOURCE([__thread int a; int b; int main() { return a = b; }])], |
0 | 106 [gcc_cv_have_cc_tls=yes], [gcc_cv_have_cc_tls=no])] |
107 )]) | |
108 if test "$enable_tls $gcc_cv_have_cc_tls" = "yes yes"; then | |
109 AC_DEFINE(HAVE_CC_TLS, 1, | |
110 [Define to 1 if the target assembler supports thread-local storage.]) | |
111 fi]) | |
112 | |
113 dnl Check whether TLS is emulated. | |
114 AC_DEFUN([GCC_CHECK_EMUTLS], [ | |
115 AC_CACHE_CHECK([whether the thread-local storage support is from emutls], | |
116 gcc_cv_use_emutls, [ | |
117 gcc_cv_use_emutls=no | |
118 echo '__thread int a; int b; int main() { return a = b; }' > conftest.c | |
119 if AC_TRY_COMMAND(${CC-cc} -Werror -S -o conftest.s conftest.c 1>&AS_MESSAGE_LOG_FD); then | |
120 if grep __emutls_get_address conftest.s > /dev/null; then | |
121 gcc_cv_use_emutls=yes | |
122 fi | |
123 fi | |
124 rm -f conftest.* | |
125 ]) | |
126 if test "$gcc_cv_use_emutls" = "yes" ; then | |
127 AC_DEFINE(USE_EMUTLS, 1, | |
128 [Define to 1 if the target use emutls for thread-local storage.]) | |
129 fi]) |