Apply patch provided by Meador Inge <meadori@codesourcery.com>.
[official-gcc.git] / libgupc / acinclude.m4
blobbd1845ca05f86b78a071c35a73104f97a8e5b9a6
1 dnl Copyright (C) 1994-2013 Free Software Foundation, Inc.
2 dnl This file is free software; the Free Software Foundation
3 dnl gives unlimited permission to copy and/or distribute it,
4 dnl with or without modifications, as long as this notice is preserved.
6 dnl This program is distributed in the hope that it will be useful,
7 dnl but WITHOUT ANY WARRANTY, to the extent permitted by law; without
8 dnl even the implied warranty of MERCHANTABILITY or FITNESS FOR A
9 dnl PARTICULAR PURPOSE.
11 dnl
12 dnl LIBGUPC_GCC_TLS_SUPPORTED
13 dnl
14 AC_DEFUN([LIBGUPC_GCC_TLS_SUPPORTED], [
15 AC_CACHE_CHECK([whether the GCC __threads extension is supported.],
16                upc_cv_gcc_tls_supported,
17 [SAVE_LIBS="$LIBS"
18 LIBS="$LIBS -lpthread"
19 AC_TRY_RUN(
20 changequote(<<,>>)dnl
21 <<#include <stdio.h>
22 #include <stddef.h>
23 #include <malloc.h>
24 #include <errno.h>
25 #include <pthread.h>
27 #define NTHREADS 5
29 pthread_t p[NTHREADS];
31 pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
33 __thread long tlocal = 0;
35 void *
36 thread_start (void *arg)
38   int id = *((int *)arg);
39   int *return_val = malloc(sizeof(int));
40   if (pthread_mutex_lock (&lock))
41     { exit (2); }
42   /* if the value is truly thread-local, this assignment
43      will yield the value 1, for each thread. If tlocal
44      is instead a process global static value then tlocal
45      will be incremented by each thread, and its final
46      value will be the number of threads. */
47   tlocal += 1;
48   if (pthread_mutex_unlock (&lock))
49     { exit (2); }
50   *return_val = tlocal;
51   return return_val;
54 int
55 main()
57   int i;
58   for (i = 0; i < NTHREADS; ++i)
59     {
60       int *id = (int *)malloc(sizeof(int));
61       *id = i;
62       if (pthread_create(&p[i], NULL, thread_start, id))
63         { exit (2); }
64     }
65   for (i = 0; i < NTHREADS; ++i)
66     {
67       int *rc;
68       if (pthread_join (p[i], (void **)&rc))
69         { exit (2); }
70       if (*rc != 1)
71         { exit (1); }
72     }
73   return 0;
75 >>,
76 changequote([, ])dnl
77   [upc_cv_gcc_tls_supported="yes"],
78   [upc_cv_gcc_tls_supported="no"],
79   [upc_cv_gcc_tls_supported="no"])
80   LIBS="$SAVE_LIBS"]
82 dnl if test "$upc_cv_gcc_tls_supported"x = "yes"x ; then
83 dnl   AC_DEFINE([HAVE_GCC_TLS_SUPPORT], 1)
84 dnl fi
87 dnl ----------------------------------------------------------------------
88 dnl The following (to the end of file) is copied from libgomp.
89 dnl ----------------------------------------------------------------------
90 dnl This whole bit snagged from libgfortran.
92 dnl Check whether the target supports __sync_*_compare_and_swap.
93 AC_DEFUN([LIBGUPC_CHECK_SYNC_BUILTINS], [
94   AC_CACHE_CHECK([whether the target supports __sync_*_compare_and_swap],
95                  libgupc_cv_have_sync_builtins, [
96   AC_TRY_LINK([], [int foo; (void) __sync_val_compare_and_swap(&foo, 0, 1);],
97               libgupc_cv_have_sync_builtins=yes,
98               libgupc_cv_have_sync_builtins=no)])
99   if test $libgupc_cv_have_sync_builtins = yes; then
100     AC_DEFINE(HAVE_SYNC_BUILTINS, 1,
101               [Define to 1 if the target supports __sync_*_compare_and_swap.])
102   fi])
104 dnl Check whether the target supports hidden visibility.
105 AC_DEFUN([LIBGUPC_CHECK_ATTRIBUTE_VISIBILITY], [
106   AC_CACHE_CHECK([whether the target supports hidden visibility],
107                  libgupc_cv_have_attribute_visibility, [
108   save_CFLAGS="$CFLAGS"
109   CFLAGS="$CFLAGS -Werror"
110   AC_TRY_COMPILE([void __attribute__((visibility("hidden"))) foo(void) { }],
111                  [], libgupc_cv_have_attribute_visibility=yes,
112                  libgupc_cv_have_attribute_visibility=no)
113   CFLAGS="$save_CFLAGS"])
114   if test $libgupc_cv_have_attribute_visibility = yes; then
115     AC_DEFINE(HAVE_ATTRIBUTE_VISIBILITY, 1,
116       [Define to 1 if the target supports __attribute__((visibility(...))).])
117   fi])
119 dnl Check whether the target supports dllexport
120 AC_DEFUN([LIBGUPC_CHECK_ATTRIBUTE_DLLEXPORT], [
121   AC_CACHE_CHECK([whether the target supports dllexport],
122                  libgupc_cv_have_attribute_dllexport, [
123   save_CFLAGS="$CFLAGS"
124   CFLAGS="$CFLAGS -Werror"
125   AC_TRY_COMPILE([void __attribute__((dllexport)) foo(void) { }],
126                  [], libgupc_cv_have_attribute_dllexport=yes,
127                  libgupc_cv_have_attribute_dllexport=no)
128   CFLAGS="$save_CFLAGS"])
129   if test $libgupc_cv_have_attribute_dllexport = yes; then
130     AC_DEFINE(HAVE_ATTRIBUTE_DLLEXPORT, 1,
131       [Define to 1 if the target supports __attribute__((dllexport)).])
132   fi])
134 dnl Check whether the target supports symbol aliases.
135 AC_DEFUN([LIBGUPC_CHECK_ATTRIBUTE_ALIAS], [
136   AC_CACHE_CHECK([whether the target supports symbol aliases],
137                  libgupc_cv_have_attribute_alias, [
138   AC_TRY_LINK([
139 void foo(void) { }
140 extern void bar(void) __attribute__((alias("foo")));],
141     [bar();], libgupc_cv_have_attribute_alias=yes, libgupc_cv_have_attribute_alias=no)])
142   if test $libgupc_cv_have_attribute_alias = yes; then
143     AC_DEFINE(HAVE_ATTRIBUTE_ALIAS, 1,
144       [Define to 1 if the target supports __attribute__((alias(...))).])
145   fi])
147 sinclude(../libtool.m4)
148 dnl The lines below arrange for aclocal not to bring an installed
149 dnl libtool.m4 into aclocal.m4, while still arranging for automake to
150 dnl add a definition of LIBTOOL to Makefile.in.
151 ifelse(,,,[AC_SUBST(LIBTOOL)
152 AC_DEFUN([AM_PROG_LIBTOOL])
153 AC_DEFUN([AC_LIBTOOL_DLOPEN])
154 AC_DEFUN([AC_PROG_LD])
157 dnl ----------------------------------------------------------------------
158 dnl This whole bit snagged from libstdc++-v3.
161 dnl LIBGUPC_ENABLE
162 dnl    (FEATURE, DEFAULT, HELP-ARG, HELP-STRING)
163 dnl    (FEATURE, DEFAULT, HELP-ARG, HELP-STRING, permit a|b|c)
164 dnl    (FEATURE, DEFAULT, HELP-ARG, HELP-STRING, SHELL-CODE-HANDLER)
166 dnl See docs/html/17_intro/configury.html#enable for documentation.
168 m4_define([LIBGUPC_ENABLE],[dnl
169 m4_define([_g_switch],[--enable-$1])dnl
170 m4_define([_g_help],[AC_HELP_STRING(_g_switch$3,[$4 @<:@default=$2@:>@])])dnl
171  AC_ARG_ENABLE($1,_g_help,
172   m4_bmatch([$5],
173    [^permit ],
174      [[
175       case "$enableval" in
176        m4_bpatsubst([$5],[permit ])) ;;
177        *) AC_MSG_ERROR(Unknown argument to enable/disable $1) ;;
178           dnl Idea for future:  generate a URL pointing to
179           dnl "onlinedocs/configopts.html#whatever"
180       esac
181      ]],
182    [^$],
183      [[
184       case "$enableval" in
185        yes|no) ;;
186        *) AC_MSG_ERROR(Argument to enable/disable $1 must be yes or no) ;;
187       esac
188      ]],
189    [[$5]]),
190   [enable_]m4_bpatsubst([$1],-,_)[=][$2])
191 m4_undefine([_g_switch])dnl
192 m4_undefine([_g_help])dnl
197 dnl If GNU ld is in use, check to see if tricky linker opts can be used.  If
198 dnl the native linker is in use, all variables will be defined to something
199 dnl safe (like an empty string).
201 dnl Defines:
202 dnl  SECTION_LDFLAGS='-Wl,--gc-sections' if possible
203 dnl  OPT_LDFLAGS='-Wl,-O1' if possible
204 dnl  LD (as a side effect of testing)
205 dnl Sets:
206 dnl  with_gnu_ld
207 dnl  libgupc_ld_is_gold (possibly)
208 dnl  libgupc_gnu_ld_version (possibly)
210 dnl The last will be a single integer, e.g., version 1.23.45.0.67.89 will
211 dnl set libgupc_gnu_ld_version to 12345.  Zeros cause problems.
213 AC_DEFUN([LIBGUPC_CHECK_LINKER_FEATURES], [
214   # If we're not using GNU ld, then there's no point in even trying these
215   # tests.  Check for that first.  We should have already tested for gld
216   # by now (in libtool), but require it now just to be safe...
217   test -z "$SECTION_LDFLAGS" && SECTION_LDFLAGS=''
218   test -z "$OPT_LDFLAGS" && OPT_LDFLAGS=''
219   AC_REQUIRE([AC_PROG_LD])
220   AC_REQUIRE([AC_PROG_AWK])
222   # The name set by libtool depends on the version of libtool.  Shame on us
223   # for depending on an impl detail, but c'est la vie.  Older versions used
224   # ac_cv_prog_gnu_ld, but now it's lt_cv_prog_gnu_ld, and is copied back on
225   # top of with_gnu_ld (which is also set by --with-gnu-ld, so that actually
226   # makes sense).  We'll test with_gnu_ld everywhere else, so if that isn't
227   # set (hence we're using an older libtool), then set it.
228   if test x${with_gnu_ld+set} != xset; then
229     if test x${ac_cv_prog_gnu_ld+set} != xset; then
230       # We got through "ac_require(ac_prog_ld)" and still not set?  Huh?
231       with_gnu_ld=no
232     else
233       with_gnu_ld=$ac_cv_prog_gnu_ld
234     fi
235   fi
237   # Start by getting the version number.  I think the libtool test already
238   # does some of this, but throws away the result.
239   libgupc_ld_is_gold=no
240   if $LD --version 2>/dev/null | grep 'GNU gold'> /dev/null 2>&1; then
241     libgupc_ld_is_gold=yes
242   fi
243   changequote(,)
244   ldver=`$LD --version 2>/dev/null |
245          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'`
246   changequote([,])
247   libgupc_gnu_ld_version=`echo $ldver | \
248          $AWK -F. '{ if (NF<3) [$]3=0; print ([$]1*100+[$]2)*100+[$]3 }'`
250   # Set --gc-sections.
251   if test "$with_gnu_ld" = "notbroken"; then
252     # GNU ld it is!  Joy and bunny rabbits!
254     # All these tests are for C++; save the language and the compiler flags.
255     # Need to do this so that g++ won't try to link in libstdc++
256     ac_test_CFLAGS="${CFLAGS+set}"
257     ac_save_CFLAGS="$CFLAGS"
258     CFLAGS='-x c++  -Wl,--gc-sections'
260     # Check for -Wl,--gc-sections
261     # XXX This test is broken at the moment, as symbols required for linking
262     # are now in libsupc++ (not built yet).  In addition, this test has
263     # cored on solaris in the past.  In addition, --gc-sections doesn't
264     # really work at the moment (keeps on discarding used sections, first
265     # .eh_frame and now some of the glibc sections for iconv).
266     # Bzzzzt.  Thanks for playing, maybe next time.
267     AC_MSG_CHECKING([for ld that supports -Wl,--gc-sections])
268     AC_TRY_RUN([
269      int main(void)
270      {
271        try { throw 1; }
272        catch (...) { };
273        return 0;
274      }
275     ], [ac_sectionLDflags=yes],[ac_sectionLDflags=no], [ac_sectionLDflags=yes])
276     if test "$ac_test_CFLAGS" = set; then
277       CFLAGS="$ac_save_CFLAGS"
278     else
279       # this is the suspicious part
280       CFLAGS=''
281     fi
282     if test "$ac_sectionLDflags" = "yes"; then
283       SECTION_LDFLAGS="-Wl,--gc-sections $SECTION_LDFLAGS"
284     fi
285     AC_MSG_RESULT($ac_sectionLDflags)
286   fi
288   # Set linker optimization flags.
289   if test x"$with_gnu_ld" = x"yes"; then
290     OPT_LDFLAGS="-Wl,-O1 $OPT_LDFLAGS"
291   fi
293   AC_SUBST(SECTION_LDFLAGS)
294   AC_SUBST(OPT_LDFLAGS)
299 dnl Add version tags to symbols in shared library (or not), additionally
300 dnl marking other symbols as private/local (or not).
302 dnl --enable-symvers=style adds a version script to the linker call when
303 dnl       creating the shared library.  The choice of version script is
304 dnl       controlled by 'style'.
305 dnl --disable-symvers does not.
306 dnl  +  Usage:  LIBGUPC_ENABLE_SYMVERS[(DEFAULT)]
307 dnl       Where DEFAULT is either 'yes' or 'no'.  Passing `yes' tries to
308 dnl       choose a default style based on linker characteristics.  Passing
309 dnl       'no' disables versioning.
311 AC_DEFUN([LIBGUPC_ENABLE_SYMVERS], [
313 LIBGUPC_ENABLE(symvers,yes,[=STYLE],
314   [enables symbol versioning of the shared library],
315   [permit yes|no|gnu])
317 # If we never went through the LIBGUPC_CHECK_LINKER_FEATURES macro, then we
318 # don't know enough about $LD to do tricks...
319 AC_REQUIRE([LIBGUPC_CHECK_LINKER_FEATURES])
320 # FIXME  The following test is too strict, in theory.
321 if test $enable_shared = no ||
322         test "x$LD" = x ||
323         test x$libgupc_gnu_ld_version = x; then
324   enable_symvers=no
327 # Check to see if libgcc_s exists, indicating that shared libgcc is possible.
328 if test $enable_symvers != no; then
329   AC_MSG_CHECKING([for shared libgcc])
330   ac_save_CFLAGS="$CFLAGS"
331   CFLAGS=' -lgcc_s'
332   AC_TRY_LINK(, [return 0;], libgupc_shared_libgcc=yes, libgupc_shared_libgcc=no)
333   CFLAGS="$ac_save_CFLAGS"
334   if test $libgupc_shared_libgcc = no; then
335     cat > conftest.c <<EOF
336 int main (void) { return 0; }
338 changequote(,)dnl
339     libgupc_libgcc_s_suffix=`${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS \
340                              -shared -shared-libgcc -o conftest.so \
341                              conftest.c -v 2>&1 >/dev/null \
342                              | sed -n 's/^.* -lgcc_s\([^ ]*\) .*$/\1/p'`
343 changequote([,])dnl
344     rm -f conftest.c conftest.so
345     if test x${libgupc_libgcc_s_suffix+set} = xset; then
346       CFLAGS=" -lgcc_s$libgupc_libgcc_s_suffix"
347       AC_TRY_LINK(, [return 0;], libgupc_shared_libgcc=yes)
348       CFLAGS="$ac_save_CFLAGS"
349     fi
350   fi
351   AC_MSG_RESULT($libgupc_shared_libgcc)
354 # For GNU ld, we need at least this version.  The format is described in
355 # LIBGUPC_CHECK_LINKER_FEATURES above.
356 libgupc_min_gnu_ld_version=21400
357 # XXXXXXXXXXX libgupc_gnu_ld_version=21390
359 # Check to see if unspecified "yes" value can win, given results above.
360 # Change "yes" into either "no" or a style name.
361 if test $enable_symvers = yes; then
362   if test $with_gnu_ld = yes &&
363      test $libgupc_shared_libgcc = yes;
364   then
365     if test $libgupc_gnu_ld_version -ge $libgupc_min_gnu_ld_version ; then
366       enable_symvers=gnu
367     elif test $libgupc_ld_is_gold = yes ; then
368       enable_symvers=gnu
369     else
370       # The right tools, the right setup, but too old.  Fallbacks?
371       AC_MSG_WARN(=== Linker version $libgupc_gnu_ld_version is too old for)
372       AC_MSG_WARN(=== full symbol versioning support in this release of GCC.)
373       AC_MSG_WARN(=== You would need to upgrade your binutils to version)
374       AC_MSG_WARN(=== $libgupc_min_gnu_ld_version or later and rebuild GCC.)
375       if test $libgupc_gnu_ld_version -ge 21200 ; then
376         # Globbing fix is present, proper block support is not.
377         dnl AC_MSG_WARN([=== Dude, you are soooo close.  Maybe we can fake it.])
378         dnl enable_symvers=???
379         AC_MSG_WARN([=== Symbol versioning will be disabled.])
380         enable_symvers=no
381       else
382         # 2.11 or older.
383         AC_MSG_WARN([=== Symbol versioning will be disabled.])
384         enable_symvers=no
385       fi
386     fi
387   else
388     # just fail for now
389     AC_MSG_WARN([=== You have requested some kind of symbol versioning, but])
390     AC_MSG_WARN([=== either you are not using a supported linker, or you are])
391     AC_MSG_WARN([=== not building a shared libgcc_s (which is required).])
392     AC_MSG_WARN([=== Symbol versioning will be disabled.])
393     enable_symvers=no
394   fi
397 AC_CACHE_CHECK([whether the target supports .symver directive],
398                libgupc_cv_have_as_symver_directive, [
399   AC_TRY_COMPILE([void foo (void); __asm (".symver foo, bar@SYMVER");],
400                  [], libgupc_cv_have_as_symver_directive=yes,
401                  libgupc_cv_have_as_symver_directive=no)])
402 if test $libgupc_cv_have_as_symver_directive = yes; then
403   AC_DEFINE(HAVE_AS_SYMVER_DIRECTIVE, 1,
404     [Define to 1 if the target assembler supports .symver directive.])
407 AM_CONDITIONAL(LIBGUPC_BUILD_VERSIONED_SHLIB, test $enable_symvers != no)
408 AC_MSG_NOTICE(versioning on shared library symbols is $enable_symvers)