1 dnl Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2001, 2004
2 dnl Copyright 2005, 2006, 2007, 2008, 2009, 2010, 2011
3 dnl Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
8 dnl This program is distributed in the hope that it will be useful,
9 dnl but WITHOUT ANY WARRANTY, to the extent permitted by law; without
10 dnl even the implied warranty of MERCHANTABILITY or FITNESS FOR A
11 dnl PARTICULAR PURPOSE.
14 dnl LIBGUPC_GCC_TLS_SUPPORTED
16 AC_DEFUN([LIBGUPC_GCC_TLS_SUPPORTED], [
17 AC_CACHE_CHECK([whether the GCC __threads extension is supported.],
18 upc_cv_gcc_tls_supported,
20 LIBS="$LIBS -lpthread"
31 pthread_t p[NTHREADS];
33 pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
35 __thread long tlocal = 0;
38 thread_start (void *arg)
40 int id = *((int *)arg);
41 int *return_val = malloc(sizeof(int));
42 if (pthread_mutex_lock (&lock))
44 /* if the value is truly thread-local, this assignment
45 will yield the value 1, for each thread. If tlocal
46 is instead a process global static value then tlocal
47 will be incremented by each thread, and its final
48 value will be the number of threads. */
50 if (pthread_mutex_unlock (&lock))
60 for (i = 0; i < NTHREADS; ++i)
62 int *id = (int *)malloc(sizeof(int));
64 if (pthread_create(&p[i], NULL, thread_start, id))
67 for (i = 0; i < NTHREADS; ++i)
70 if (pthread_join (p[i], (void **)&rc))
79 [upc_cv_gcc_tls_supported="yes"],
80 [upc_cv_gcc_tls_supported="no"],
81 [upc_cv_gcc_tls_supported="no"])
84 dnl if test "$upc_cv_gcc_tls_supported"x = "yes"x ; then
85 dnl AC_DEFINE([HAVE_GCC_TLS_SUPPORT], 1)
89 dnl ----------------------------------------------------------------------
90 dnl The following (to the end of file) is copied from libgomp.
91 dnl ----------------------------------------------------------------------
92 dnl This whole bit snagged from libgfortran.
94 dnl Check whether the target supports __sync_*_compare_and_swap.
95 AC_DEFUN([LIBGUPC_CHECK_SYNC_BUILTINS], [
96 AC_CACHE_CHECK([whether the target supports __sync_*_compare_and_swap],
97 libgupc_cv_have_sync_builtins, [
98 AC_TRY_LINK([], [int foo; (void) __sync_val_compare_and_swap(&foo, 0, 1);],
99 libgupc_cv_have_sync_builtins=yes,
100 libgupc_cv_have_sync_builtins=no)])
101 if test $libgupc_cv_have_sync_builtins = yes; then
102 AC_DEFINE(HAVE_SYNC_BUILTINS, 1,
103 [Define to 1 if the target supports __sync_*_compare_and_swap.])
106 dnl Check whether the target supports hidden visibility.
107 AC_DEFUN([LIBGUPC_CHECK_ATTRIBUTE_VISIBILITY], [
108 AC_CACHE_CHECK([whether the target supports hidden visibility],
109 libgupc_cv_have_attribute_visibility, [
110 save_CFLAGS="$CFLAGS"
111 CFLAGS="$CFLAGS -Werror"
112 AC_TRY_COMPILE([void __attribute__((visibility("hidden"))) foo(void) { }],
113 [], libgupc_cv_have_attribute_visibility=yes,
114 libgupc_cv_have_attribute_visibility=no)
115 CFLAGS="$save_CFLAGS"])
116 if test $libgupc_cv_have_attribute_visibility = yes; then
117 AC_DEFINE(HAVE_ATTRIBUTE_VISIBILITY, 1,
118 [Define to 1 if the target supports __attribute__((visibility(...))).])
121 dnl Check whether the target supports dllexport
122 AC_DEFUN([LIBGUPC_CHECK_ATTRIBUTE_DLLEXPORT], [
123 AC_CACHE_CHECK([whether the target supports dllexport],
124 libgupc_cv_have_attribute_dllexport, [
125 save_CFLAGS="$CFLAGS"
126 CFLAGS="$CFLAGS -Werror"
127 AC_TRY_COMPILE([void __attribute__((dllexport)) foo(void) { }],
128 [], libgupc_cv_have_attribute_dllexport=yes,
129 libgupc_cv_have_attribute_dllexport=no)
130 CFLAGS="$save_CFLAGS"])
131 if test $libgupc_cv_have_attribute_dllexport = yes; then
132 AC_DEFINE(HAVE_ATTRIBUTE_DLLEXPORT, 1,
133 [Define to 1 if the target supports __attribute__((dllexport)).])
136 dnl Check whether the target supports symbol aliases.
137 AC_DEFUN([LIBGUPC_CHECK_ATTRIBUTE_ALIAS], [
138 AC_CACHE_CHECK([whether the target supports symbol aliases],
139 libgupc_cv_have_attribute_alias, [
142 extern void bar(void) __attribute__((alias("foo")));],
143 [bar();], libgupc_cv_have_attribute_alias=yes, libgupc_cv_have_attribute_alias=no)])
144 if test $libgupc_cv_have_attribute_alias = yes; then
145 AC_DEFINE(HAVE_ATTRIBUTE_ALIAS, 1,
146 [Define to 1 if the target supports __attribute__((alias(...))).])
149 sinclude(../libtool.m4)
150 dnl The lines below arrange for aclocal not to bring an installed
151 dnl libtool.m4 into aclocal.m4, while still arranging for automake to
152 dnl add a definition of LIBTOOL to Makefile.in.
153 ifelse(,,,[AC_SUBST(LIBTOOL)
154 AC_DEFUN([AM_PROG_LIBTOOL])
155 AC_DEFUN([AC_LIBTOOL_DLOPEN])
156 AC_DEFUN([AC_PROG_LD])
159 dnl ----------------------------------------------------------------------
160 dnl This whole bit snagged from libstdc++-v3.
164 dnl (FEATURE, DEFAULT, HELP-ARG, HELP-STRING)
165 dnl (FEATURE, DEFAULT, HELP-ARG, HELP-STRING, permit a|b|c)
166 dnl (FEATURE, DEFAULT, HELP-ARG, HELP-STRING, SHELL-CODE-HANDLER)
168 dnl See docs/html/17_intro/configury.html#enable for documentation.
170 m4_define([LIBGUPC_ENABLE],[dnl
171 m4_define([_g_switch],[--enable-$1])dnl
172 m4_define([_g_help],[AC_HELP_STRING(_g_switch$3,[$4 @<:@default=$2@:>@])])dnl
173 AC_ARG_ENABLE($1,_g_help,
178 m4_bpatsubst([$5],[permit ])) ;;
179 *) AC_MSG_ERROR(Unknown argument to enable/disable $1) ;;
180 dnl Idea for future: generate a URL pointing to
181 dnl "onlinedocs/configopts.html#whatever"
188 *) AC_MSG_ERROR(Argument to enable/disable $1 must be yes or no) ;;
192 [enable_]m4_bpatsubst([$1],-,_)[=][$2])
193 m4_undefine([_g_switch])dnl
194 m4_undefine([_g_help])dnl
199 dnl If GNU ld is in use, check to see if tricky linker opts can be used. If
200 dnl the native linker is in use, all variables will be defined to something
201 dnl safe (like an empty string).
204 dnl SECTION_LDFLAGS='-Wl,--gc-sections' if possible
205 dnl OPT_LDFLAGS='-Wl,-O1' if possible
206 dnl LD (as a side effect of testing)
209 dnl libgupc_ld_is_gold (possibly)
210 dnl libgupc_gnu_ld_version (possibly)
212 dnl The last will be a single integer, e.g., version 1.23.45.0.67.89 will
213 dnl set libgupc_gnu_ld_version to 12345. Zeros cause problems.
215 AC_DEFUN([LIBGUPC_CHECK_LINKER_FEATURES], [
216 # If we're not using GNU ld, then there's no point in even trying these
217 # tests. Check for that first. We should have already tested for gld
218 # by now (in libtool), but require it now just to be safe...
219 test -z "$SECTION_LDFLAGS" && SECTION_LDFLAGS=''
220 test -z "$OPT_LDFLAGS" && OPT_LDFLAGS=''
221 AC_REQUIRE([AC_PROG_LD])
222 AC_REQUIRE([AC_PROG_AWK])
224 # The name set by libtool depends on the version of libtool. Shame on us
225 # for depending on an impl detail, but c'est la vie. Older versions used
226 # ac_cv_prog_gnu_ld, but now it's lt_cv_prog_gnu_ld, and is copied back on
227 # top of with_gnu_ld (which is also set by --with-gnu-ld, so that actually
228 # makes sense). We'll test with_gnu_ld everywhere else, so if that isn't
229 # set (hence we're using an older libtool), then set it.
230 if test x${with_gnu_ld+set} != xset; then
231 if test x${ac_cv_prog_gnu_ld+set} != xset; then
232 # We got through "ac_require(ac_prog_ld)" and still not set? Huh?
235 with_gnu_ld=$ac_cv_prog_gnu_ld
239 # Start by getting the version number. I think the libtool test already
240 # does some of this, but throws away the result.
241 libgupc_ld_is_gold=no
242 if $LD --version 2>/dev/null | grep 'GNU gold'> /dev/null 2>&1; then
243 libgupc_ld_is_gold=yes
246 ldver=`$LD --version 2>/dev/null |
247 sed -e 's/GNU gold /GNU ld /;s/GNU ld version /GNU ld /;s/GNU ld ([^)]*) /GNU ld /;s/GNU ld \([0-9.][0-9.]*\).*/\1/; q'`
249 libgupc_gnu_ld_version=`echo $ldver | \
250 $AWK -F. '{ if (NF<3) [$]3=0; print ([$]1*100+[$]2)*100+[$]3 }'`
253 if test "$with_gnu_ld" = "notbroken"; then
254 # GNU ld it is! Joy and bunny rabbits!
256 # All these tests are for C++; save the language and the compiler flags.
257 # Need to do this so that g++ won't try to link in libstdc++
258 ac_test_CFLAGS="${CFLAGS+set}"
259 ac_save_CFLAGS="$CFLAGS"
260 CFLAGS='-x c++ -Wl,--gc-sections'
262 # Check for -Wl,--gc-sections
263 # XXX This test is broken at the moment, as symbols required for linking
264 # are now in libsupc++ (not built yet). In addition, this test has
265 # cored on solaris in the past. In addition, --gc-sections doesn't
266 # really work at the moment (keeps on discarding used sections, first
267 # .eh_frame and now some of the glibc sections for iconv).
268 # Bzzzzt. Thanks for playing, maybe next time.
269 AC_MSG_CHECKING([for ld that supports -Wl,--gc-sections])
277 ], [ac_sectionLDflags=yes],[ac_sectionLDflags=no], [ac_sectionLDflags=yes])
278 if test "$ac_test_CFLAGS" = set; then
279 CFLAGS="$ac_save_CFLAGS"
281 # this is the suspicious part
284 if test "$ac_sectionLDflags" = "yes"; then
285 SECTION_LDFLAGS="-Wl,--gc-sections $SECTION_LDFLAGS"
287 AC_MSG_RESULT($ac_sectionLDflags)
290 # Set linker optimization flags.
291 if test x"$with_gnu_ld" = x"yes"; then
292 OPT_LDFLAGS="-Wl,-O1 $OPT_LDFLAGS"
295 AC_SUBST(SECTION_LDFLAGS)
296 AC_SUBST(OPT_LDFLAGS)
301 dnl Add version tags to symbols in shared library (or not), additionally
302 dnl marking other symbols as private/local (or not).
304 dnl --enable-symvers=style adds a version script to the linker call when
305 dnl creating the shared library. The choice of version script is
306 dnl controlled by 'style'.
307 dnl --disable-symvers does not.
308 dnl + Usage: LIBGUPC_ENABLE_SYMVERS[(DEFAULT)]
309 dnl Where DEFAULT is either 'yes' or 'no'. Passing `yes' tries to
310 dnl choose a default style based on linker characteristics. Passing
311 dnl 'no' disables versioning.
313 AC_DEFUN([LIBGUPC_ENABLE_SYMVERS], [
315 LIBGUPC_ENABLE(symvers,yes,[=STYLE],
316 [enables symbol versioning of the shared library],
319 # If we never went through the LIBGUPC_CHECK_LINKER_FEATURES macro, then we
320 # don't know enough about $LD to do tricks...
321 AC_REQUIRE([LIBGUPC_CHECK_LINKER_FEATURES])
322 # FIXME The following test is too strict, in theory.
323 if test $enable_shared = no ||
325 test x$libgupc_gnu_ld_version = x; then
329 # Check to see if libgcc_s exists, indicating that shared libgcc is possible.
330 if test $enable_symvers != no; then
331 AC_MSG_CHECKING([for shared libgcc])
332 ac_save_CFLAGS="$CFLAGS"
334 AC_TRY_LINK(, [return 0;], libgupc_shared_libgcc=yes, libgupc_shared_libgcc=no)
335 CFLAGS="$ac_save_CFLAGS"
336 if test $libgupc_shared_libgcc = no; then
337 cat > conftest.c <<EOF
338 int main (void) { return 0; }
341 libgupc_libgcc_s_suffix=`${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS \
342 -shared -shared-libgcc -o conftest.so \
343 conftest.c -v 2>&1 >/dev/null \
344 | sed -n 's/^.* -lgcc_s\([^ ]*\) .*$/\1/p'`
346 rm -f conftest.c conftest.so
347 if test x${libgupc_libgcc_s_suffix+set} = xset; then
348 CFLAGS=" -lgcc_s$libgupc_libgcc_s_suffix"
349 AC_TRY_LINK(, [return 0;], libgupc_shared_libgcc=yes)
350 CFLAGS="$ac_save_CFLAGS"
353 AC_MSG_RESULT($libgupc_shared_libgcc)
356 # For GNU ld, we need at least this version. The format is described in
357 # LIBGUPC_CHECK_LINKER_FEATURES above.
358 libgupc_min_gnu_ld_version=21400
359 # XXXXXXXXXXX libgupc_gnu_ld_version=21390
361 # Check to see if unspecified "yes" value can win, given results above.
362 # Change "yes" into either "no" or a style name.
363 if test $enable_symvers = yes; then
364 if test $with_gnu_ld = yes &&
365 test $libgupc_shared_libgcc = yes;
367 if test $libgupc_gnu_ld_version -ge $libgupc_min_gnu_ld_version ; then
369 elif test $libgupc_ld_is_gold = yes ; then
372 # The right tools, the right setup, but too old. Fallbacks?
373 AC_MSG_WARN(=== Linker version $libgupc_gnu_ld_version is too old for)
374 AC_MSG_WARN(=== full symbol versioning support in this release of GCC.)
375 AC_MSG_WARN(=== You would need to upgrade your binutils to version)
376 AC_MSG_WARN(=== $libgupc_min_gnu_ld_version or later and rebuild GCC.)
377 if test $libgupc_gnu_ld_version -ge 21200 ; then
378 # Globbing fix is present, proper block support is not.
379 dnl AC_MSG_WARN([=== Dude, you are soooo close. Maybe we can fake it.])
380 dnl enable_symvers=???
381 AC_MSG_WARN([=== Symbol versioning will be disabled.])
385 AC_MSG_WARN([=== Symbol versioning will be disabled.])
391 AC_MSG_WARN([=== You have requested some kind of symbol versioning, but])
392 AC_MSG_WARN([=== either you are not using a supported linker, or you are])
393 AC_MSG_WARN([=== not building a shared libgcc_s (which is required).])
394 AC_MSG_WARN([=== Symbol versioning will be disabled.])
399 AC_CACHE_CHECK([whether the target supports .symver directive],
400 libgupc_cv_have_as_symver_directive, [
401 AC_TRY_COMPILE([void foo (void); __asm (".symver foo, bar@SYMVER");],
402 [], libgupc_cv_have_as_symver_directive=yes,
403 libgupc_cv_have_as_symver_directive=no)])
404 if test $libgupc_cv_have_as_symver_directive = yes; then
405 AC_DEFINE(HAVE_AS_SYMVER_DIRECTIVE, 1,
406 [Define to 1 if the target assembler supports .symver directive.])
409 AM_CONDITIONAL(LIBGUPC_BUILD_VERSIONED_SHLIB, test $enable_symvers != no)
410 AC_MSG_NOTICE(versioning on shared library symbols is $enable_symvers)