]> git.ipfire.org Git - thirdparty/gcc.git/blame - libitm/acinclude.m4
Merge from transactional-memory branch.
[thirdparty/gcc.git] / libitm / acinclude.m4
CommitLineData
4c0315d0 1dnl ----------------------------------------------------------------------
2dnl This whole bit snagged from libgfortran.
3
4dnl Check whether the target supports __sync_*_compare_and_swap.
5AC_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])
14
15dnl Check whether the target supports 64-bit __sync_*_compare_and_swap.
16AC_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])
28
29dnl Check whether the target supports hidden visibility.
30AC_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])
43
44dnl Check whether the target supports dllexport
45AC_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])
58
59dnl Check whether the target supports symbol aliases.
60AC_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([
64void foo(void) { }
65extern 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])
71
72dnl Check how size_t is mangled.
73AC_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.])
96])
97
98sinclude(../libtool.m4)
99dnl The lines below arrange for aclocal not to bring an installed
100dnl libtool.m4 into aclocal.m4, while still arranging for automake to
101dnl add a definition of LIBTOOL to Makefile.in.
102ifelse(,,,[AC_SUBST(LIBTOOL)
103AC_DEFUN([AM_PROG_LIBTOOL])
104AC_DEFUN([AC_LIBTOOL_DLOPEN])
105AC_DEFUN([AC_PROG_LD])
106])
107
108dnl ----------------------------------------------------------------------
109dnl This whole bit snagged from libstdc++-v3.
110
111dnl
112dnl LIBITM_ENABLE
113dnl (FEATURE, DEFAULT, HELP-ARG, HELP-STRING)
114dnl (FEATURE, DEFAULT, HELP-ARG, HELP-STRING, permit a|b|c)
115dnl (FEATURE, DEFAULT, HELP-ARG, HELP-STRING, SHELL-CODE-HANDLER)
116dnl
117dnl See docs/html/17_intro/configury.html#enable for documentation.
118dnl
119m4_define([LIBITM_ENABLE],[dnl
120m4_define([_g_switch],[--enable-$1])dnl
121m4_define([_g_help],[AC_HELP_STRING(_g_switch$3,[$4 @<:@default=$2@:>@])])dnl
122 AC_ARG_ENABLE($1,_g_help,
123 m4_bmatch([$5],
124 [^permit ],
125 [[
126 case "$enableval" in
127 m4_bpatsubst([$5],[permit ])) ;;
128 *) AC_MSG_ERROR(Unknown argument to enable/disable $1) ;;
129 dnl Idea for future: generate a URL pointing to
130 dnl "onlinedocs/configopts.html#whatever"
131 esac
132 ]],
133 [^$],
134 [[
135 case "$enableval" in
136 yes|no) ;;
137 *) AC_MSG_ERROR(Argument to enable/disable $1 must be yes or no) ;;
138 esac
139 ]],
140 [[$5]]),
141 [enable_]m4_bpatsubst([$1],-,_)[=][$2])
142m4_undefine([_g_switch])dnl
143m4_undefine([_g_help])dnl
144])
145
146
147dnl
148dnl If GNU ld is in use, check to see if tricky linker opts can be used. If
149dnl the native linker is in use, all variables will be defined to something
150dnl safe (like an empty string).
151dnl
152dnl Defines:
153dnl SECTION_LDFLAGS='-Wl,--gc-sections' if possible
154dnl OPT_LDFLAGS='-Wl,-O1' if possible
155dnl LD (as a side effect of testing)
156dnl Sets:
157dnl with_gnu_ld
158dnl libitm_gnu_ld_version (possibly)
159dnl
160dnl The last will be a single integer, e.g., version 1.23.45.0.67.89 will
161dnl set libitm_gnu_ld_version to 12345. Zeros cause problems.
162dnl
163AC_DEFUN([LIBITM_CHECK_LINKER_FEATURES], [
164 # If we're not using GNU ld, then there's no point in even trying these
165 # tests. Check for that first. We should have already tested for gld
166 # by now (in libtool), but require it now just to be safe...
167 test -z "$SECTION_LDFLAGS" && SECTION_LDFLAGS=''
168 test -z "$OPT_LDFLAGS" && OPT_LDFLAGS=''
169 AC_REQUIRE([AC_PROG_LD])
170 AC_REQUIRE([AC_PROG_AWK])
171
172 # The name set by libtool depends on the version of libtool. Shame on us
173 # for depending on an impl detail, but c'est la vie. Older versions used
174 # ac_cv_prog_gnu_ld, but now it's lt_cv_prog_gnu_ld, and is copied back on
175 # top of with_gnu_ld (which is also set by --with-gnu-ld, so that actually
176 # makes sense). We'll test with_gnu_ld everywhere else, so if that isn't
177 # set (hence we're using an older libtool), then set it.
178 if test x${with_gnu_ld+set} != xset; then
179 if test x${ac_cv_prog_gnu_ld+set} != xset; then
180 # We got through "ac_require(ac_prog_ld)" and still not set? Huh?
181 with_gnu_ld=no
182 else
183 with_gnu_ld=$ac_cv_prog_gnu_ld
184 fi
185 fi
186
187 # Start by getting the version number. I think the libtool test already
188 # does some of this, but throws away the result.
189 changequote(,)
190 ldver=`$LD --version 2>/dev/null | head -1 | \
191 sed -e 's/GNU ld \(version \)\{0,1\}\(([^)]*) \)\{0,1\}\([0-9.][0-9.]*\).*/\3/'`
192 changequote([,])
193 libitm_gnu_ld_version=`echo $ldver | \
194 $AWK -F. '{ if (NF<3) [$]3=0; print ([$]1*100+[$]2)*100+[$]3 }'`
195
196 # Set --gc-sections.
197 if test "$with_gnu_ld" = "notbroken"; then
198 # GNU ld it is! Joy and bunny rabbits!
199
200 # All these tests are for C++; save the language and the compiler flags.
201 # Need to do this so that g++ won't try to link in libstdc++
202 ac_test_CFLAGS="${CFLAGS+set}"
203 ac_save_CFLAGS="$CFLAGS"
204 CFLAGS='-x c++ -Wl,--gc-sections'
205
206 # Check for -Wl,--gc-sections
207 # XXX This test is broken at the moment, as symbols required for linking
208 # are now in libsupc++ (not built yet). In addition, this test has
209 # cored on solaris in the past. In addition, --gc-sections doesn't
210 # really work at the moment (keeps on discarding used sections, first
211 # .eh_frame and now some of the glibc sections for iconv).
212 # Bzzzzt. Thanks for playing, maybe next time.
213 AC_MSG_CHECKING([for ld that supports -Wl,--gc-sections])
214 AC_TRY_RUN([
215 int main(void)
216 {
217 try { throw 1; }
218 catch (...) { };
219 return 0;
220 }
221 ], [ac_sectionLDflags=yes],[ac_sectionLDflags=no], [ac_sectionLDflags=yes])
222 if test "$ac_test_CFLAGS" = set; then
223 CFLAGS="$ac_save_CFLAGS"
224 else
225 # this is the suspicious part
226 CFLAGS=''
227 fi
228 if test "$ac_sectionLDflags" = "yes"; then
229 SECTION_LDFLAGS="-Wl,--gc-sections $SECTION_LDFLAGS"
230 fi
231 AC_MSG_RESULT($ac_sectionLDflags)
232 fi
233
234 # Set linker optimization flags.
235 if test x"$with_gnu_ld" = x"yes"; then
236 OPT_LDFLAGS="-Wl,-O1 $OPT_LDFLAGS"
237 fi
238
239 AC_SUBST(SECTION_LDFLAGS)
240 AC_SUBST(OPT_LDFLAGS)
241])
242
243
244dnl
245dnl Add version tags to symbols in shared library (or not), additionally
246dnl marking other symbols as private/local (or not).
247dnl
248dnl --enable-symvers=style adds a version script to the linker call when
249dnl creating the shared library. The choice of version script is
250dnl controlled by 'style'.
251dnl --disable-symvers does not.
252dnl + Usage: LIBITM_ENABLE_SYMVERS[(DEFAULT)]
253dnl Where DEFAULT is either 'yes' or 'no'. Passing `yes' tries to
254dnl choose a default style based on linker characteristics. Passing
255dnl 'no' disables versioning.
256dnl
257AC_DEFUN([LIBITM_ENABLE_SYMVERS], [
258
259LIBITM_ENABLE(symvers,yes,[=STYLE],
260 [enables symbol versioning of the shared library],
261 [permit yes|no|gnu])
262
263# If we never went through the LIBITM_CHECK_LINKER_FEATURES macro, then we
264# don't know enough about $LD to do tricks...
265AC_REQUIRE([LIBITM_CHECK_LINKER_FEATURES])
266# FIXME The following test is too strict, in theory.
267if test $enable_shared = no ||
268 test "x$LD" = x ||
269 test x$libitm_gnu_ld_version = x; then
270 enable_symvers=no
271fi
272
273# Check to see if libgcc_s exists, indicating that shared libgcc is possible.
274if test $enable_symvers != no; then
275 AC_MSG_CHECKING([for shared libgcc])
276 ac_save_CFLAGS="$CFLAGS"
277 CFLAGS=' -lgcc_s'
278 AC_TRY_LINK(, [return 0;], libitm_shared_libgcc=yes, libitm_shared_libgcc=no)
279 CFLAGS="$ac_save_CFLAGS"
280 if test $libitm_shared_libgcc = no; then
281 cat > conftest.c <<EOF
282int main (void) { return 0; }
283EOF
284changequote(,)dnl
285 libitm_libgcc_s_suffix=`${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS \
286 -shared -shared-libgcc -o conftest.so \
287 conftest.c -v 2>&1 >/dev/null \
288 | sed -n 's/^.* -lgcc_s\([^ ]*\) .*$/\1/p'`
289changequote([,])dnl
290 rm -f conftest.c conftest.so
291 if test x${libitm_libgcc_s_suffix+set} = xset; then
292 CFLAGS=" -lgcc_s$libitm_libgcc_s_suffix"
293 AC_TRY_LINK(, [return 0;], libitm_shared_libgcc=yes)
294 CFLAGS="$ac_save_CFLAGS"
295 fi
296 fi
297 AC_MSG_RESULT($libitm_shared_libgcc)
298fi
299
300# For GNU ld, we need at least this version. The format is described in
301# LIBITM_CHECK_LINKER_FEATURES above.
302libitm_min_gnu_ld_version=21400
303# XXXXXXXXXXX libitm_gnu_ld_version=21390
304
305# Check to see if unspecified "yes" value can win, given results above.
306# Change "yes" into either "no" or a style name.
307if test $enable_symvers = yes; then
308 if test $with_gnu_ld = yes &&
309 test $libitm_shared_libgcc = yes;
310 then
311 if test $libitm_gnu_ld_version -ge $libitm_min_gnu_ld_version ; then
312 enable_symvers=gnu
313 else
314 # The right tools, the right setup, but too old. Fallbacks?
315 AC_MSG_WARN(=== Linker version $libitm_gnu_ld_version is too old for)
316 AC_MSG_WARN(=== full symbol versioning support in this release of GCC.)
317 AC_MSG_WARN(=== You would need to upgrade your binutils to version)
318 AC_MSG_WARN(=== $libitm_min_gnu_ld_version or later and rebuild GCC.)
319 if test $libitm_gnu_ld_version -ge 21200 ; then
320 # Globbing fix is present, proper block support is not.
321 dnl AC_MSG_WARN([=== Dude, you are soooo close. Maybe we can fake it.])
322 dnl enable_symvers=???
323 AC_MSG_WARN([=== Symbol versioning will be disabled.])
324 enable_symvers=no
325 else
326 # 2.11 or older.
327 AC_MSG_WARN([=== Symbol versioning will be disabled.])
328 enable_symvers=no
329 fi
330 fi
331 else
332 # just fail for now
333 AC_MSG_WARN([=== You have requested some kind of symbol versioning, but])
334 AC_MSG_WARN([=== either you are not using a supported linker, or you are])
335 AC_MSG_WARN([=== not building a shared libgcc_s (which is required).])
336 AC_MSG_WARN([=== Symbol versioning will be disabled.])
337 enable_symvers=no
338 fi
339fi
340
341AM_CONDITIONAL(LIBITM_BUILD_VERSIONED_SHLIB, test $enable_symvers != no)
342AC_MSG_NOTICE(versioning on shared library symbols is $enable_symvers)
343])