[AArch64] PR target/84748: Mark *compare_cstore<mode>_insn as clobbering CC reg
[official-gcc.git] / libitm / acinclude.m4
blobcd8150ce95f2e51356b6286b24e67007c006794b
1 dnl ----------------------------------------------------------------------
2 dnl This whole bit snagged from libgfortran.
4 dnl Check whether the target supports __sync_*_compare_and_swap.
5 AC_DEFUN([LIBITM_CHECK_SYNC_BUILTINS], [
6   AC_CACHE_CHECK([whether the target supports __sync_*_compare_and_swap],
7                  libitm_cv_have_sync_builtins, [
8   AC_TRY_LINK([], [int foo, bar; bar = __sync_val_compare_and_swap(&foo, 0, 1);],
9               libitm_cv_have_sync_builtins=yes, libitm_cv_have_sync_builtins=no)])
10   if test $libitm_cv_have_sync_builtins = yes; then
11     AC_DEFINE(HAVE_SYNC_BUILTINS, 1,
12               [Define to 1 if the target supports __sync_*_compare_and_swap])
13   fi])
15 dnl Check whether the target supports 64-bit __sync_*_compare_and_swap.
16 AC_DEFUN([LIBITM_CHECK_64BIT_SYNC_BUILTINS], [
17   AC_CACHE_CHECK([whether the target supports 64-bit __sync_*_compare_and_swap],
18                  libitm_cv_have_64bit_sync_builtins, [
19   AC_TRY_LINK([#include <stdint.h>],
20     [uint64_t foo, bar;
21      bar = __sync_val_compare_and_swap(&foo, 0, 1);],
22     libitm_cv_have_64bit_sync_builtins=yes,
23     libitm_cv_have_64bit_sync_builtins=no)])
24     if test $libitm_cv_have_64bit_sync_builtins = yes; then
25       AC_DEFINE(HAVE_64BIT_SYNC_BUILTINS, 1,
26                 [Define to 1 if the target supports 64-bit __sync_*_compare_and_swap])
27   fi])
29 dnl Check whether the target supports hidden visibility.
30 AC_DEFUN([LIBITM_CHECK_ATTRIBUTE_VISIBILITY], [
31   AC_CACHE_CHECK([whether the target supports hidden visibility],
32                  libitm_cv_have_attribute_visibility, [
33   save_CFLAGS="$CFLAGS"
34   CFLAGS="$CFLAGS -Werror"
35   AC_TRY_COMPILE([void __attribute__((visibility("hidden"))) foo(void) { }],
36                  [], libitm_cv_have_attribute_visibility=yes,
37                  libitm_cv_have_attribute_visibility=no)
38   CFLAGS="$save_CFLAGS"])
39   if test $libitm_cv_have_attribute_visibility = yes; then
40     AC_DEFINE(HAVE_ATTRIBUTE_VISIBILITY, 1,
41       [Define to 1 if the target supports __attribute__((visibility(...))).])
42   fi])
44 dnl Check whether the target supports dllexport
45 AC_DEFUN([LIBITM_CHECK_ATTRIBUTE_DLLEXPORT], [
46   AC_CACHE_CHECK([whether the target supports dllexport],
47                  libitm_cv_have_attribute_dllexport, [
48   save_CFLAGS="$CFLAGS"
49   CFLAGS="$CFLAGS -Werror"
50   AC_TRY_COMPILE([void __attribute__((dllexport)) foo(void) { }],
51                  [], libitm_cv_have_attribute_dllexport=yes,
52                  libitm_cv_have_attribute_dllexport=no)
53   CFLAGS="$save_CFLAGS"])
54   if test $libitm_cv_have_attribute_dllexport = yes; then
55     AC_DEFINE(HAVE_ATTRIBUTE_DLLEXPORT, 1,
56       [Define to 1 if the target supports __attribute__((dllexport)).])
57   fi])
59 dnl Check whether the target supports symbol aliases.
60 AC_DEFUN([LIBITM_CHECK_ATTRIBUTE_ALIAS], [
61   AC_CACHE_CHECK([whether the target supports symbol aliases],
62                  libitm_cv_have_attribute_alias, [
63   AC_TRY_LINK([
64 void foo(void) { }
65 extern void bar(void) __attribute__((alias("foo")));],
66     [bar();], libitm_cv_have_attribute_alias=yes, libitm_cv_have_attribute_alias=no)])
67   if test $libitm_cv_have_attribute_alias = yes; then
68     AC_DEFINE(HAVE_ATTRIBUTE_ALIAS, 1,
69       [Define to 1 if the target supports __attribute__((alias(...))).])
70   fi])
72 dnl Check how size_t is mangled.
73 AC_DEFUN([LIBITM_CHECK_SIZE_T_MANGLING], [
74   AC_CACHE_CHECK([how size_t is mangled],
75                  libitm_cv_size_t_mangling, [
76     AC_TRY_COMPILE([], [extern __SIZE_TYPE__ x; extern unsigned long x;],
77                    [libitm_cv_size_t_mangling=m], [
78       AC_TRY_COMPILE([], [extern __SIZE_TYPE__ x; extern unsigned int x;],
79                      [libitm_cv_size_t_mangling=j], [
80         AC_TRY_COMPILE([],
81                        [extern __SIZE_TYPE__ x; extern unsigned long long x;],
82                        [libitm_cv_size_t_mangling=y], [
83           AC_TRY_COMPILE([],
84                          [extern __SIZE_TYPE__ x; extern unsigned short x;],
85                          [libitm_cv_size_t_mangling=t],
86                          [libitm_cv_size_t_mangling=x])
87         ])
88       ])
89     ])
90   ])
91   if test $libitm_cv_size_t_mangling = x; then
92     AC_MSG_ERROR([Unknown underlying type for size_t])
93   fi
94   AC_DEFINE_UNQUOTED(MANGLE_SIZE_T, [$libitm_cv_size_t_mangling],
95     [Define to the letter to which size_t is mangled.])
98 dnl Check if as supports AVX instructions.
99 AC_DEFUN([LIBITM_CHECK_AS_AVX], [
100 case "${target_cpu}" in
101 i[[34567]]86 | x86_64)
102   AC_CACHE_CHECK([if the assembler supports AVX], libitm_cv_as_avx, [
103     AC_TRY_COMPILE([], [asm("vzeroupper");],
104                    [libitm_cv_as_avx=yes], [libitm_cv_as_avx=no])
105   ])
106   if test x$libitm_cv_as_avx = xyes; then
107     AC_DEFINE(HAVE_AS_AVX, 1, [Define to 1 if the assembler supports AVX.])
108   fi
109   ;;
110 esac])
112 dnl Check if as supports RTM instructions.
113 AC_DEFUN([LIBITM_CHECK_AS_RTM], [
114 case "${target_cpu}" in
115 i[[34567]]86 | x86_64)
116   AC_CACHE_CHECK([if the assembler supports RTM], libitm_cv_as_rtm, [
117     AC_TRY_COMPILE([], [asm("1: xbegin 1b; xend");],
118                    [libitm_cv_as_rtm=yes], [libitm_cv_as_rtm=no])
119   ])
120   if test x$libitm_cv_as_rtm = xyes; then
121     AC_DEFINE(HAVE_AS_RTM, 1, [Define to 1 if the assembler supports RTM.])
122   fi
123   ;;
124 esac])
126 dnl Check if as supports HTM instructions.
127 AC_DEFUN([LIBITM_CHECK_AS_HTM], [
128 case "${target_cpu}" in
129 powerpc*)
130   AC_CACHE_CHECK([if the assembler supports HTM], libitm_cv_as_htm, [
131     AC_TRY_COMPILE([], [asm("tbegin. 0; tend. 0");],
132                    [libitm_cv_as_htm=yes], [libitm_cv_as_htm=no])
133   ])
134   if test x$libitm_cv_as_htm = xyes; then
135     AC_DEFINE(HAVE_AS_HTM, 1, [Define to 1 if the assembler supports HTM.])
136   fi
137   ;;
138 s390*)
139   AC_CACHE_CHECK([if the assembler supports HTM], libitm_cv_as_htm, [
140     save_CFLAGS="$CFLAGS"
141     CFLAGS="$CFLAGS -march=zEC12"
142     AC_TRY_COMPILE([], [asm("tbegin 0,0; tend");],
143                    [libitm_cv_as_htm=yes], [libitm_cv_as_htm=no])
144     CFLAGS="$save_CFLAGS"])
145   if test x$libitm_cv_as_htm = xyes; then
146     AC_DEFINE(HAVE_AS_HTM, 1, [Define to 1 if the assembler supports HTM.])
147   fi
148   ;;
149 esac])
151 sinclude(../libtool.m4)
152 sinclude(../config/cet.m4)
153 dnl The lines below arrange for aclocal not to bring an installed
154 dnl libtool.m4 into aclocal.m4, while still arranging for automake to
155 dnl add a definition of LIBTOOL to Makefile.in.
156 ifelse(,,,[AC_SUBST(LIBTOOL)
157 AC_DEFUN([AM_PROG_LIBTOOL])
158 AC_DEFUN([AC_LIBTOOL_DLOPEN])
159 AC_DEFUN([AC_PROG_LD])
162 dnl ----------------------------------------------------------------------
163 dnl This whole bit snagged from libstdc++-v3.
166 dnl LIBITM_ENABLE
167 dnl    (FEATURE, DEFAULT, HELP-ARG, HELP-STRING)
168 dnl    (FEATURE, DEFAULT, HELP-ARG, HELP-STRING, permit a|b|c)
169 dnl    (FEATURE, DEFAULT, HELP-ARG, HELP-STRING, SHELL-CODE-HANDLER)
171 dnl See docs/html/17_intro/configury.html#enable for documentation.
173 m4_define([LIBITM_ENABLE],[dnl
174 m4_define([_g_switch],[--enable-$1])dnl
175 m4_define([_g_help],[AC_HELP_STRING(_g_switch$3,[$4 @<:@default=$2@:>@])])dnl
176  AC_ARG_ENABLE($1,_g_help,
177   m4_bmatch([$5],
178    [^permit ],
179      [[
180       case "$enableval" in
181        m4_bpatsubst([$5],[permit ])) ;;
182        *) AC_MSG_ERROR(Unknown argument to enable/disable $1) ;;
183           dnl Idea for future:  generate a URL pointing to
184           dnl "onlinedocs/configopts.html#whatever"
185       esac
186      ]],
187    [^$],
188      [[
189       case "$enableval" in
190        yes|no) ;;
191        *) AC_MSG_ERROR(Argument to enable/disable $1 must be yes or no) ;;
192       esac
193      ]],
194    [[$5]]),
195   [enable_]m4_bpatsubst([$1],-,_)[=][$2])
196 m4_undefine([_g_switch])dnl
197 m4_undefine([_g_help])dnl
202 dnl If GNU ld is in use, check to see if tricky linker opts can be used.  If
203 dnl the native linker is in use, all variables will be defined to something
204 dnl safe (like an empty string).
206 dnl Defines:
207 dnl  SECTION_LDFLAGS='-Wl,--gc-sections' if possible
208 dnl  OPT_LDFLAGS='-Wl,-O1' if possible
209 dnl  LD (as a side effect of testing)
210 dnl Sets:
211 dnl  with_gnu_ld
212 dnl  libitm_ld_is_gold (possibly)
213 dnl  libitm_gnu_ld_version (possibly)
215 dnl The last will be a single integer, e.g., version 1.23.45.0.67.89 will
216 dnl set libitm_gnu_ld_version to 12345.  Zeros cause problems.
218 AC_DEFUN([LIBITM_CHECK_LINKER_FEATURES], [
219   # If we're not using GNU ld, then there's no point in even trying these
220   # tests.  Check for that first.  We should have already tested for gld
221   # by now (in libtool), but require it now just to be safe...
222   test -z "$SECTION_LDFLAGS" && SECTION_LDFLAGS=''
223   test -z "$OPT_LDFLAGS" && OPT_LDFLAGS=''
224   AC_REQUIRE([AC_PROG_LD])
225   AC_REQUIRE([AC_PROG_AWK])
227   # The name set by libtool depends on the version of libtool.  Shame on us
228   # for depending on an impl detail, but c'est la vie.  Older versions used
229   # ac_cv_prog_gnu_ld, but now it's lt_cv_prog_gnu_ld, and is copied back on
230   # top of with_gnu_ld (which is also set by --with-gnu-ld, so that actually
231   # makes sense).  We'll test with_gnu_ld everywhere else, so if that isn't
232   # set (hence we're using an older libtool), then set it.
233   if test x${with_gnu_ld+set} != xset; then
234     if test x${ac_cv_prog_gnu_ld+set} != xset; then
235       # We got through "ac_require(ac_prog_ld)" and still not set?  Huh?
236       with_gnu_ld=no
237     else
238       with_gnu_ld=$ac_cv_prog_gnu_ld
239     fi
240   fi
242   # Start by getting the version number.  I think the libtool test already
243   # does some of this, but throws away the result.
244   libitm_ld_is_gold=no
245   if $LD --version 2>/dev/null | grep 'GNU gold'> /dev/null 2>&1; then
246     libitm_ld_is_gold=yes
247   fi
248   changequote(,)
249   ldver=`$LD --version 2>/dev/null |
250          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'`
251   changequote([,])
252   libitm_gnu_ld_version=`echo $ldver | \
253          $AWK -F. '{ if (NF<3) [$]3=0; print ([$]1*100+[$]2)*100+[$]3 }'`
255   # Set --gc-sections.
256   if test "$with_gnu_ld" = "notbroken"; then
257     # GNU ld it is!  Joy and bunny rabbits!
259     # All these tests are for C++; save the language and the compiler flags.
260     # Need to do this so that g++ won't try to link in libstdc++
261     ac_test_CFLAGS="${CFLAGS+set}"
262     ac_save_CFLAGS="$CFLAGS"
263     CFLAGS='-x c++  -Wl,--gc-sections'
265     # Check for -Wl,--gc-sections
266     # XXX This test is broken at the moment, as symbols required for linking
267     # are now in libsupc++ (not built yet).  In addition, this test has
268     # cored on solaris in the past.  In addition, --gc-sections doesn't
269     # really work at the moment (keeps on discarding used sections, first
270     # .eh_frame and now some of the glibc sections for iconv).
271     # Bzzzzt.  Thanks for playing, maybe next time.
272     AC_MSG_CHECKING([for ld that supports -Wl,--gc-sections])
273     AC_TRY_RUN([
274      int main(void)
275      {
276        try { throw 1; }
277        catch (...) { };
278        return 0;
279      }
280     ], [ac_sectionLDflags=yes],[ac_sectionLDflags=no], [ac_sectionLDflags=yes])
281     if test "$ac_test_CFLAGS" = set; then
282       CFLAGS="$ac_save_CFLAGS"
283     else
284       # this is the suspicious part
285       CFLAGS=''
286     fi
287     if test "$ac_sectionLDflags" = "yes"; then
288       SECTION_LDFLAGS="-Wl,--gc-sections $SECTION_LDFLAGS"
289     fi
290     AC_MSG_RESULT($ac_sectionLDflags)
291   fi
293   # Set linker optimization flags.
294   if test x"$with_gnu_ld" = x"yes"; then
295     OPT_LDFLAGS="-Wl,-O1 $OPT_LDFLAGS"
296   fi
298   AC_SUBST(SECTION_LDFLAGS)
299   AC_SUBST(OPT_LDFLAGS)
304 dnl Add version tags to symbols in shared library (or not), additionally
305 dnl marking other symbols as private/local (or not).
307 dnl --enable-symvers=style adds a version script to the linker call when
308 dnl       creating the shared library.  The choice of version script is
309 dnl       controlled by 'style'.
310 dnl --disable-symvers does not.
311 dnl  +  Usage:  LIBITM_ENABLE_SYMVERS[(DEFAULT)]
312 dnl       Where DEFAULT is either 'yes' or 'no'.  Passing `yes' tries to
313 dnl       choose a default style based on linker characteristics.  Passing
314 dnl       'no' disables versioning.
316 AC_DEFUN([LIBITM_ENABLE_SYMVERS], [
318 LIBITM_ENABLE(symvers,yes,[=STYLE],
319   [enables symbol versioning of the shared library],
320   [permit yes|no|gnu*|sun])
322 # If we never went through the LIBITM_CHECK_LINKER_FEATURES macro, then we
323 # don't know enough about $LD to do tricks...
324 AC_REQUIRE([LIBITM_CHECK_LINKER_FEATURES])
326 # Turn a 'yes' into a suitable default.
327 if test x$enable_symvers = xyes ; then
328   # FIXME  The following test is too strict, in theory.
329   if test $enable_shared = no || test "x$LD" = x; then
330     enable_symvers=no
331   else
332     if test $with_gnu_ld = yes ; then
333       enable_symvers=gnu
334     else
335       case ${target_os} in
336         # Sun symbol versioning exists since Solaris 2.5.
337         solaris2.[[5-9]]* | solaris2.1[[0-9]]*)
338           enable_symvers=sun ;;
339         *)
340           enable_symvers=no ;;
341       esac
342     fi
343   fi
346 # Check if 'sun' was requested on non-Solaris 2 platforms.
347 if test x$enable_symvers = xsun ; then
348   case ${target_os} in
349     solaris2*)
350       # All fine.
351       ;;
352     *)
353       # Unlikely to work.
354       AC_MSG_WARN([=== You have requested Sun symbol versioning, but])
355       AC_MSG_WARN([=== you are not targetting Solaris 2.])
356       AC_MSG_WARN([=== Symbol versioning will be disabled.])
357       enable_symvers=no
358       ;;
359   esac
362 # Check to see if libgcc_s exists, indicating that shared libgcc is possible.
363 if test $enable_symvers != no; then
364   AC_MSG_CHECKING([for shared libgcc])
365   ac_save_CFLAGS="$CFLAGS"
366   CFLAGS=' -lgcc_s'
367   AC_TRY_LINK(, [return 0;], libitm_shared_libgcc=yes, libitm_shared_libgcc=no)
368   CFLAGS="$ac_save_CFLAGS"
369   if test $libitm_shared_libgcc = no; then
370     cat > conftest.c <<EOF
371 int main (void) { return 0; }
373 changequote(,)dnl
374     libitm_libgcc_s_suffix=`${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS \
375                              -shared -shared-libgcc -o conftest.so \
376                              conftest.c -v 2>&1 >/dev/null \
377                              | sed -n 's/^.* -lgcc_s\([^ ]*\) .*$/\1/p'`
378 changequote([,])dnl
379     rm -f conftest.c conftest.so
380     if test x${libitm_libgcc_s_suffix+set} = xset; then
381       CFLAGS=" -lgcc_s$libitm_libgcc_s_suffix"
382       AC_TRY_LINK(, [return 0;], libitm_shared_libgcc=yes)
383       CFLAGS="$ac_save_CFLAGS"
384     fi
385   fi
386   AC_MSG_RESULT($libitm_shared_libgcc)
389 # For GNU ld, we need at least this version.  The format is described in
390 # LIBITM_CHECK_LINKER_FEATURES above.
391 libitm_min_gnu_ld_version=21400
392 # XXXXXXXXXXX libitm_gnu_ld_version=21390
394 # Check to see if unspecified "yes" value can win, given results above.
395 # Change "yes" into either "no" or a style name.
396 if test $enable_symvers != no && test $libitm_shared_libgcc = yes; then
397   if test $with_gnu_ld = yes; then
398     if test $libitm_gnu_ld_version -ge $libitm_min_gnu_ld_version ; then
399       enable_symvers=gnu
400     elif test $libitm_ld_is_gold = yes ; then
401       enable_symvers=gnu
402     else
403       # The right tools, the right setup, but too old.  Fallbacks?
404       AC_MSG_WARN(=== Linker version $libitm_gnu_ld_version is too old for)
405       AC_MSG_WARN(=== full symbol versioning support in this release of GCC.)
406       AC_MSG_WARN(=== You would need to upgrade your binutils to version)
407       AC_MSG_WARN(=== $libitm_min_gnu_ld_version or later and rebuild GCC.)
408       if test $libitm_gnu_ld_version -ge 21200 ; then
409         # Globbing fix is present, proper block support is not.
410         dnl AC_MSG_WARN([=== Dude, you are soooo close.  Maybe we can fake it.])
411         dnl enable_symvers=???
412         AC_MSG_WARN([=== Symbol versioning will be disabled.])
413         enable_symvers=no
414       else
415         # 2.11 or older.
416         AC_MSG_WARN([=== Symbol versioning will be disabled.])
417         enable_symvers=no
418       fi
419     fi
420   elif test $enable_symvers = sun; then
421     : All interesting versions of Sun ld support sun style symbol versioning.
422   else
423     # just fail for now
424     AC_MSG_WARN([=== You have requested some kind of symbol versioning, but])
425     AC_MSG_WARN([=== either you are not using a supported linker, or you are])
426     AC_MSG_WARN([=== not building a shared libgcc_s (which is required).])
427     AC_MSG_WARN([=== Symbol versioning will be disabled.])
428     enable_symvers=no
429   fi
432 AM_CONDITIONAL(LIBITM_BUILD_VERSIONED_SHLIB, test $enable_symvers != no)
433 AM_CONDITIONAL(LIBITM_BUILD_VERSIONED_SHLIB_GNU, test $enable_symvers = gnu)
434 AM_CONDITIONAL(LIBITM_BUILD_VERSIONED_SHLIB_SUN, test $enable_symvers = sun)
435 AC_MSG_NOTICE(versioning on shared library symbols is $enable_symvers)