Mercurial > hg > CbC > CbC_gcc
annotate config/tls.m4 @ 60:bd49c42ec43e
remove unnecessary files
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 15 Feb 2010 17:39:45 +0900 |
parents | 77e2b8dfacca |
children | f6334be47118 |
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, [ | |
7 AC_RUN_IFELSE([__thread int a; int b; int main() { return a = b; }], | |
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" | |
13 AC_LINK_IFELSE([int main() { return 0; }], | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
14 [AC_RUN_IFELSE([__thread int a; int b; int main() { return a = b; }], |
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" | |
41 AC_RUN_IFELSE( | |
42 [AC_LANG_PROGRAM( | |
43 [#include <pthread.h> | |
44 __thread int a; | |
45 static int *a_in_other_thread; | |
46 static void * | |
47 thread_func (void *arg) | |
48 { | |
49 a_in_other_thread = &a; | |
50 return (void *)0; | |
51 }], | |
52 [pthread_t thread; | |
53 void *thread_retval; | |
54 int *a_in_main_thread; | |
55 if (pthread_create (&thread, (pthread_attr_t *)0, | |
56 thread_func, (void *)0)) | |
57 return 0; | |
58 a_in_main_thread = &a; | |
59 if (pthread_join (thread, &thread_retval)) | |
60 return 0; | |
61 return (a_in_other_thread == a_in_main_thread);])], | |
62 [gcc_cv_have_tls=yes], [gcc_cv_have_tls=no], []) | |
63 CFLAGS="$chktls_save_CFLAGS" | |
64 fi | |
65 fi], | |
66 [gcc_cv_have_tls=no], | |
67 [dnl This is the cross-compiling case. Assume libc supports TLS if the | |
68 dnl binutils and the compiler do. | |
69 AC_LINK_IFELSE([__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
|
70 [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
|
71 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
|
72 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
|
73 case $host in |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
74 *-*-linux*) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
75 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
|
76 ;; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
77 esac |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
78 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
|
79 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
|
80 dnl If -shared works, test if TLS works in a shared library. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
81 AC_LINK_IFELSE([int f() { return 0; }], |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
82 [AC_LINK_IFELSE([__thread int a; int b; int f() { return a = b; }], |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
83 [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
|
84 [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
|
85 [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
|
86 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
|
87 LDFLAGS="$chktls_save_LDFLAGS"], [gcc_cv_have_tls=no]) |
0 | 88 ] |
89 )]) | |
90 if test "$enable_tls $gcc_cv_have_tls" = "yes yes"; then | |
91 AC_DEFINE(HAVE_TLS, 1, | |
92 [Define to 1 if the target supports thread-local storage.]) | |
93 fi]) | |
94 | |
95 dnl Check whether the target assembler supports TLS. | |
96 AC_DEFUN([GCC_CHECK_CC_TLS], [ | |
97 GCC_ENABLE(tls, yes, [], [Use thread-local storage]) | |
98 AC_CACHE_CHECK([whether the target assembler supports thread-local storage], | |
99 gcc_cv_have_cc_tls, [ | |
100 AC_COMPILE_IFELSE([__thread int a; int b; int main() { return a = b; }], | |
101 [gcc_cv_have_cc_tls=yes], [gcc_cv_have_cc_tls=no])] | |
102 )]) | |
103 if test "$enable_tls $gcc_cv_have_cc_tls" = "yes yes"; then | |
104 AC_DEFINE(HAVE_CC_TLS, 1, | |
105 [Define to 1 if the target assembler supports thread-local storage.]) | |
106 fi]) | |
107 | |
108 dnl Check whether TLS is emulated. | |
109 AC_DEFUN([GCC_CHECK_EMUTLS], [ | |
110 AC_CACHE_CHECK([whether the thread-local storage support is from emutls], | |
111 gcc_cv_use_emutls, [ | |
112 gcc_cv_use_emutls=no | |
113 echo '__thread int a; int b; int main() { return a = b; }' > conftest.c | |
114 if AC_TRY_COMMAND(${CC-cc} -Werror -S -o conftest.s conftest.c 1>&AS_MESSAGE_LOG_FD); then | |
115 if grep __emutls_get_address conftest.s > /dev/null; then | |
116 gcc_cv_use_emutls=yes | |
117 fi | |
118 fi | |
119 rm -f conftest.* | |
120 ]) | |
121 if test "$gcc_cv_use_emutls" = "yes" ; then | |
122 AC_DEFINE(USE_EMUTLS, 1, | |
123 [Define to 1 if the target use emutls for thread-local storage.]) | |
124 fi]) |