]> git.ipfire.org Git - thirdparty/gcc.git/blame - libatomic/acinclude.m4
Use i386-cpuinfo.c on all i386 targets
[thirdparty/gcc.git] / libatomic / acinclude.m4
CommitLineData
48310492
RH
1dnl
2dnl Unconditionally define a preprocessor macro, translating the shell
3dnl macro from yes/no to 1/0.
4dnl
5AC_DEFUN([LIBAT_DEFINE_YESNO], [
6 yesno=`echo $2 | tr 'yesno' '1 0 '`
7 AC_DEFINE_UNQUOTED([$1], $yesno, [$3])
8])
9dnl
10dnl Iterate over all of the modes we're prepared to check.
11dnl
12AC_DEFUN([LIBAT_FORALL_MODES],
13 [$1(QI,1)
14 $1(HI,2)
15 $1(SI,4)
16 $1(DI,8)
17 $1(TI,16)]
18)
19dnl
20dnl Check for builtin types by mode.
21dnl
22dnl A less interesting of size checking than autoconf normally provides.
23dnl We know that gcc always provides <stdint.h>, but we don't often
24dnl provide a builtin type for TImode.
25dnl
26AC_DEFUN([LIBAT_HAVE_INT_MODE],[
27 AC_CACHE_CHECK([for $2 byte integer],[libat_cv_have_mode_$1],
28 [AC_COMPILE_IFELSE([int x __attribute__((mode($1)));],
29 [libat_cv_have_mode_$1=yes],[libat_cv_have_mode_$1=no])])
30 LIBAT_DEFINE_YESNO([HAVE_INT$2], [$libat_cv_have_mode_$1],
31 [Have support for $2 byte integers.])
32 if test x$libat_cv_have_mode_$1 = xyes; then
33 SIZES="$SIZES $2"
34 fi
35])
36dnl
37dnl Check for atomic builtins.
38dnl See:
39dnl http://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html
40dnl
41dnl This checks to see if the host supports the compiler-generated
42dnl builtins for atomic operations for various integral sizes.
43dnl
44AC_DEFUN([LIBAT_TEST_ATOMIC_INIT],[
45 # Do link tests if possible, instead asm tests, limited to some platforms
46 # see discussion in PR target/40134, PR libstdc++/40133 and the thread
47 # starting at http://gcc.gnu.org/ml/gcc-patches/2009-07/msg00322.html
48 atomic_builtins_link_tests=no
49 if test x$gcc_no_link != xyes; then
50 # Can do link tests. Limit to some tested platforms
51 case "$host" in
52 *-*-linux* | *-*-uclinux* | *-*-kfreebsd*-gnu | *-*-gnu*)
53 atomic_builtins_link_tests=yes
54 ;;
55 esac
56 fi
57])
58AC_DEFUN([LIBAT_TEST_ATOMIC_BUILTIN],[
59 AC_CACHE_CHECK([$1],[$2],[
60 AC_LANG_CONFTEST([AC_LANG_PROGRAM([],[$3])])
61 if test x$atomic_builtins_link_tests = xyes; then
62 if AC_TRY_EVAL(ac_link); then
63 eval $2=yes
64 else
65 eval $2=no
66 fi
67 else
68 old_CFLAGS="$CFLAGS"
69 # Compile unoptimized.
70 CFLAGS='-O0 -S'
71 if AC_TRY_EVAL(ac_compile); then
72 if grep __atomic_ conftest.s >/dev/null 2>&1 ; then
73 eval $2=no
74 else
75 eval $2=yes
76 fi
0fe5522f
RH
77 else
78 eval $2=no
48310492
RH
79 fi
80 CFLAGS="$old_CFLAGS"
81 fi
82 rm -f conftest*
83 ])
84])
85
86dnl
87dnl Test if we have __atomic_load and __atomic_store for mode $1, size $2
88dnl
89AC_DEFUN([LIBAT_HAVE_ATOMIC_LOADSTORE],[
90 LIBAT_TEST_ATOMIC_BUILTIN([for __atomic_load/store for size $2],
91 [libat_cv_have_at_ldst_$2],
92 [typedef int T __attribute__((mode($1)));
93 T *x; volatile T sink; asm("" : "=g"(x));
94 sink = __atomic_load_n(x, 0);
95 __atomic_store_n(x, sink, 0);])
96 LIBAT_DEFINE_YESNO([HAVE_ATOMIC_LDST_$2], [$libat_cv_have_at_ldst_$2],
97 [Have __atomic_load/store for $2 byte integers.])
98 AH_BOTTOM([#define MAYBE_HAVE_ATOMIC_LDST_$2 HAVE_ATOMIC_LDST_$2])
99])
100
101dnl
102dnl Test if we have __atomic_test_and_set for mode $1, size $2
103dnl
104AC_DEFUN([LIBAT_HAVE_ATOMIC_TAS],[
105 LIBAT_TEST_ATOMIC_BUILTIN([for __atomic_test_and_set for size $2],
106 [libat_cv_have_at_tas_$2],
107 [typedef int T __attribute__((mode($1))); T *x; asm("" : "=g"(x));
108 __atomic_test_and_set(x, 0);])
109 LIBAT_DEFINE_YESNO([HAVE_ATOMIC_TAS_$2], [$libat_cv_have_at_tas_$2],
110 [Have __atomic_test_and_set for $2 byte integers.])
111 AH_BOTTOM([#define MAYBE_HAVE_ATOMIC_TAS_$2 HAVE_ATOMIC_TAS_$2])
112])
113
114dnl
115dnl Test if we have __atomic_exchange for mode $1, size $2
116dnl
117AC_DEFUN([LIBAT_HAVE_ATOMIC_EXCHANGE],[
118 LIBAT_TEST_ATOMIC_BUILTIN([for __atomic_exchange for size $2],
119 [libat_cv_have_at_exch_$2],
120 [typedef int T __attribute__((mode($1))); T *x; asm("" : "=g"(x));
121 __atomic_exchange_n(x, 0, 0);])
122 LIBAT_DEFINE_YESNO([HAVE_ATOMIC_EXCHANGE_$2], [$libat_cv_have_at_exch_$2],
123 [Have __atomic_exchange for $2 byte integers.])
124 AH_BOTTOM([#define MAYBE_HAVE_ATOMIC_EXCHANGE_$2 HAVE_ATOMIC_EXCHANGE_$2])
125])
126
127dnl
128dnl Test if we have __atomic_compare_exchange for mode $1, size $2
129dnl
130AC_DEFUN([LIBAT_HAVE_ATOMIC_CAS],[
131 LIBAT_TEST_ATOMIC_BUILTIN([for __atomic_compare_exchange for size $2],
132 [libat_cv_have_at_cas_$2],
133 [typedef int T __attribute__((mode($1))); T *x, *y;
134 asm("" : "=g"(x), "=g"(y));
135 __atomic_compare_exchange_n(x, y, 0, 0, 0, 0);])
136 LIBAT_DEFINE_YESNO([HAVE_ATOMIC_CAS_$2], [$libat_cv_have_at_cas_$2],
137 [Have __atomic_compare_exchange for $2 byte integers.])
138 AH_BOTTOM([#define MAYBE_HAVE_ATOMIC_CAS_$2 HAVE_ATOMIC_CAS_$2])
139])
140
141dnl
142dnl Test if we have __atomic_fetch_add for mode $1, size $2
143dnl
144AC_DEFUN([LIBAT_HAVE_ATOMIC_FETCH_ADD],[
145 LIBAT_TEST_ATOMIC_BUILTIN([for __atomic_fetch_add for size $2],
146 [libat_cv_have_at_fadd_$2],
147 [typedef int T __attribute__((mode($1))); T *x, y;
148 asm("" : "=g"(x), "=g"(y));
149 __atomic_fetch_add (x, y, 0);
150 __atomic_add_fetch (x, y, 0);])
151 LIBAT_DEFINE_YESNO([HAVE_ATOMIC_FETCH_ADD_$2], [$libat_cv_have_at_fadd_$2],
152 [Have __atomic_fetch_add for $2 byte integers.])
153 AH_BOTTOM([#define MAYBE_HAVE_ATOMIC_FETCH_ADD_$2 HAVE_ATOMIC_FETCH_ADD_$2])
154])
155
156dnl
157dnl Test if we have __atomic_fetch_op for all op for mode $1, size $2
158dnl
159AC_DEFUN([LIBAT_HAVE_ATOMIC_FETCH_OP],[
160 LIBAT_TEST_ATOMIC_BUILTIN([for __atomic_fetch_op for size $2],
161 [libat_cv_have_at_fop_$2],
162 [typedef int T __attribute__((mode($1))); T *x, y;
163 asm("" : "=g"(x), "=g"(y));
164 __atomic_fetch_add (x, y, 0); __atomic_add_fetch (x, y, 0);
165 __atomic_fetch_sub (x, y, 0); __atomic_sub_fetch (x, y, 0);
166 __atomic_fetch_and (x, y, 0); __atomic_and_fetch (x, y, 0);
167 __atomic_fetch_nand (x, y, 0); __atomic_nand_fetch (x, y, 0);
168 __atomic_fetch_xor (x, y, 0); __atomic_xor_fetch (x, y, 0);
169 __atomic_fetch_or (x, y, 0); __atomic_or_fetch (x, y, 0); ])
170 LIBAT_DEFINE_YESNO([HAVE_ATOMIC_FETCH_OP_$2], [$libat_cv_have_at_fop_$2],
171 [Have __atomic_fetch_op for all op for $2 byte integers.])
172 AH_BOTTOM([#define MAYBE_HAVE_ATOMIC_FETCH_OP_$2 HAVE_ATOMIC_FETCH_OP_$2])
173])
174
175dnl
176dnl Test for the size of the target word.
177dnl
178AC_DEFUN([LIBAT_WORDSIZE],[
179 AC_CACHE_CHECK([for the word size],[libat_cv_wordsize],
180 [AC_COMPUTE_INT(libat_cv_wordsize,
181 [sizeof(word)], [typedef int word __attribute__((mode(word)));],
182 AC_ERROR([Could not determine word size.]))])
183 AC_DEFINE_UNQUOTED(WORDSIZE, $libat_cv_wordsize,
184 [The word size in bytes of the machine.])
185])
186
187dnl
188dnl Check whether the target supports ifuncs.
189dnl
190AC_DEFUN([LIBAT_CHECK_IFUNC], [
191 AC_CACHE_CHECK([whether the target supports funcs], libat_cv_have_ifunc, [
192 save_CFLAGS="$CFLAGS"
193 CFLAGS="$CFLAGS -Werror"
194 AC_TRY_LINK([
195 int foo_alt(void) { return 0; }
196 void *foo_sel(void) { return foo_alt; }
197 int foo(void) __attribute__((ifunc("foo_sel")));],
198 [return foo();], libat_cv_have_ifunc=yes, libat_cv_have_ifunc=no)])
199 LIBAT_DEFINE_YESNO([HAVE_IFUNC], [$libat_cv_have_ifunc],
200 [Define to 1 if the target supports __attribute__((ifunc(...))).])
201])
202
203dnl ----------------------------------------------------------------------
204dnl This whole bit snagged from libitm.
205
206dnl Check whether the target supports hidden visibility.
207AC_DEFUN([LIBAT_CHECK_ATTRIBUTE_VISIBILITY], [
208 AC_CACHE_CHECK([whether the target supports hidden visibility],
209 libat_cv_have_attribute_visibility, [
210 save_CFLAGS="$CFLAGS"
211 CFLAGS="$CFLAGS -Werror"
212 AC_TRY_COMPILE([void __attribute__((visibility("hidden"))) foo(void) { }],
213 [], libat_cv_have_attribute_visibility=yes,
214 libat_cv_have_attribute_visibility=no)
215 CFLAGS="$save_CFLAGS"])
216 if test $libat_cv_have_attribute_visibility = yes; then
217 AC_DEFINE(HAVE_ATTRIBUTE_VISIBILITY, 1,
218 [Define to 1 if the target supports __attribute__((visibility(...))).])
219 fi])
220
221dnl Check whether the target supports dllexport
222AC_DEFUN([LIBAT_CHECK_ATTRIBUTE_DLLEXPORT], [
223 AC_CACHE_CHECK([whether the target supports dllexport],
224 libat_cv_have_attribute_dllexport, [
225 save_CFLAGS="$CFLAGS"
226 CFLAGS="$CFLAGS -Werror"
227 AC_TRY_COMPILE([void __attribute__((dllexport)) foo(void) { }],
228 [], libat_cv_have_attribute_dllexport=yes,
229 libat_cv_have_attribute_dllexport=no)
230 CFLAGS="$save_CFLAGS"])
231 if test $libat_cv_have_attribute_dllexport = yes; then
232 AC_DEFINE(HAVE_ATTRIBUTE_DLLEXPORT, 1,
233 [Define to 1 if the target supports __attribute__((dllexport)).])
234 fi])
235
236dnl Check whether the target supports symbol aliases.
237AC_DEFUN([LIBAT_CHECK_ATTRIBUTE_ALIAS], [
238 AC_CACHE_CHECK([whether the target supports symbol aliases],
239 libat_cv_have_attribute_alias, [
240 AC_TRY_LINK([
241void foo(void) { }
242extern void bar(void) __attribute__((alias("foo")));],
243 [bar();], libat_cv_have_attribute_alias=yes, libat_cv_have_attribute_alias=no)])
244 if test $libat_cv_have_attribute_alias = yes; then
245 AC_DEFINE(HAVE_ATTRIBUTE_ALIAS, 1,
246 [Define to 1 if the target supports __attribute__((alias(...))).])
247 fi])
248
249dnl ----------------------------------------------------------------------
250dnl This whole bit snagged from libstdc++-v3.
251
252dnl
253dnl LIBAT_ENABLE
254dnl (FEATURE, DEFAULT, HELP-ARG, HELP-STRING)
255dnl (FEATURE, DEFAULT, HELP-ARG, HELP-STRING, permit a|b|c)
256dnl (FEATURE, DEFAULT, HELP-ARG, HELP-STRING, SHELL-CODE-HANDLER)
257dnl
258dnl See docs/html/17_intro/configury.html#enable for documentation.
259dnl
260m4_define([LIBAT_ENABLE],[dnl
261m4_define([_g_switch],[--enable-$1])dnl
262m4_define([_g_help],[AC_HELP_STRING(_g_switch$3,[$4 @<:@default=$2@:>@])])dnl
263 AC_ARG_ENABLE($1,_g_help,
264 m4_bmatch([$5],
265 [^permit ],
266 [[
267 case "$enableval" in
268 m4_bpatsubst([$5],[permit ])) ;;
269 *) AC_MSG_ERROR(Unknown argument to enable/disable $1) ;;
270 dnl Idea for future: generate a URL pointing to
271 dnl "onlinedocs/configopts.html#whatever"
272 esac
273 ]],
274 [^$],
275 [[
276 case "$enableval" in
277 yes|no) ;;
278 *) AC_MSG_ERROR(Argument to enable/disable $1 must be yes or no) ;;
279 esac
280 ]],
281 [[$5]]),
282 [enable_]m4_bpatsubst([$1],-,_)[=][$2])
283m4_undefine([_g_switch])dnl
284m4_undefine([_g_help])dnl
285])
286
287dnl
288dnl If GNU ld is in use, check to see if tricky linker opts can be used. If
289dnl the native linker is in use, all variables will be defined to something
290dnl safe (like an empty string).
291dnl
292dnl Defines:
293dnl SECTION_LDFLAGS='-Wl,--gc-sections' if possible
294dnl OPT_LDFLAGS='-Wl,-O1' if possible
295dnl LD (as a side effect of testing)
296dnl Sets:
297dnl with_gnu_ld
298dnl libat_ld_is_gold (possibly)
299dnl libat_gnu_ld_version (possibly)
300dnl
301dnl The last will be a single integer, e.g., version 1.23.45.0.67.89 will
302dnl set libat_gnu_ld_version to 12345. Zeros cause problems.
303dnl
304AC_DEFUN([LIBAT_CHECK_LINKER_FEATURES], [
305 # If we're not using GNU ld, then there's no point in even trying these
306 # tests. Check for that first. We should have already tested for gld
307 # by now (in libtool), but require it now just to be safe...
308 test -z "$SECTION_LDFLAGS" && SECTION_LDFLAGS=''
309 test -z "$OPT_LDFLAGS" && OPT_LDFLAGS=''
310 AC_REQUIRE([AC_PROG_LD])
311 AC_REQUIRE([AC_PROG_AWK])
312
313 # The name set by libtool depends on the version of libtool. Shame on us
314 # for depending on an impl detail, but c'est la vie. Older versions used
315 # ac_cv_prog_gnu_ld, but now it's lt_cv_prog_gnu_ld, and is copied back on
316 # top of with_gnu_ld (which is also set by --with-gnu-ld, so that actually
317 # makes sense). We'll test with_gnu_ld everywhere else, so if that isn't
318 # set (hence we're using an older libtool), then set it.
319 if test x${with_gnu_ld+set} != xset; then
320 if test x${ac_cv_prog_gnu_ld+set} != xset; then
321 # We got through "ac_require(ac_prog_ld)" and still not set? Huh?
322 with_gnu_ld=no
323 else
324 with_gnu_ld=$ac_cv_prog_gnu_ld
325 fi
326 fi
327
328 # Start by getting the version number. I think the libtool test already
329 # does some of this, but throws away the result.
330 libat_ld_is_gold=no
331 if $LD --version 2>/dev/null | grep 'GNU gold'> /dev/null 2>&1; then
332 libat_ld_is_gold=yes
333 fi
334 changequote(,)
335 ldver=`$LD --version 2>/dev/null |
336 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'`
337 changequote([,])
338 libat_gnu_ld_version=`echo $ldver | \
339 $AWK -F. '{ if (NF<3) [$]3=0; print ([$]1*100+[$]2)*100+[$]3 }'`
340
341 # Set --gc-sections.
342 if test "$with_gnu_ld" = "notbroken"; then
343 # GNU ld it is! Joy and bunny rabbits!
344
345 # All these tests are for C++; save the language and the compiler flags.
346 # Need to do this so that g++ won't try to link in libstdc++
347 ac_test_CFLAGS="${CFLAGS+set}"
348 ac_save_CFLAGS="$CFLAGS"
349 CFLAGS='-x c++ -Wl,--gc-sections'
350
351 # Check for -Wl,--gc-sections
352 # XXX This test is broken at the moment, as symbols required for linking
353 # are now in libsupc++ (not built yet). In addition, this test has
354 # cored on solaris in the past. In addition, --gc-sections doesn't
355 # really work at the moment (keeps on discarding used sections, first
356 # .eh_frame and now some of the glibc sections for iconv).
357 # Bzzzzt. Thanks for playing, maybe next time.
358 AC_MSG_CHECKING([for ld that supports -Wl,--gc-sections])
359 AC_TRY_RUN([
360 int main(void)
361 {
362 try { throw 1; }
363 catch (...) { };
364 return 0;
365 }
366 ], [ac_sectionLDflags=yes],[ac_sectionLDflags=no], [ac_sectionLDflags=yes])
367 if test "$ac_test_CFLAGS" = set; then
368 CFLAGS="$ac_save_CFLAGS"
369 else
370 # this is the suspicious part
371 CFLAGS=''
372 fi
373 if test "$ac_sectionLDflags" = "yes"; then
374 SECTION_LDFLAGS="-Wl,--gc-sections $SECTION_LDFLAGS"
375 fi
376 AC_MSG_RESULT($ac_sectionLDflags)
377 fi
378
379 # Set linker optimization flags.
380 if test x"$with_gnu_ld" = x"yes"; then
381 OPT_LDFLAGS="-Wl,-O1 $OPT_LDFLAGS"
382 fi
383
384 AC_SUBST(SECTION_LDFLAGS)
385 AC_SUBST(OPT_LDFLAGS)
386])
387
388
389dnl
390dnl If GNU ld is in use, check to see if tricky linker opts can be used. If
391dnl the native linker is in use, all variables will be defined to something
392dnl safe (like an empty string).
393dnl
394dnl Defines:
395dnl SECTION_LDFLAGS='-Wl,--gc-sections' if possible
396dnl OPT_LDFLAGS='-Wl,-O1' if possible
397dnl LD (as a side effect of testing)
398dnl Sets:
399dnl with_gnu_ld
400dnl libat_ld_is_gold (possibly)
401dnl libat_gnu_ld_version (possibly)
402dnl
403dnl The last will be a single integer, e.g., version 1.23.45.0.67.89 will
404dnl set libat_gnu_ld_version to 12345. Zeros cause problems.
405dnl
406AC_DEFUN([LIBAT_CHECK_LINKER_FEATURES], [
407 # If we're not using GNU ld, then there's no point in even trying these
408 # tests. Check for that first. We should have already tested for gld
409 # by now (in libtool), but require it now just to be safe...
410 test -z "$SECTION_LDFLAGS" && SECTION_LDFLAGS=''
411 test -z "$OPT_LDFLAGS" && OPT_LDFLAGS=''
412 AC_REQUIRE([AC_PROG_LD])
413 AC_REQUIRE([AC_PROG_AWK])
414
415 # The name set by libtool depends on the version of libtool. Shame on us
416 # for depending on an impl detail, but c'est la vie. Older versions used
417 # ac_cv_prog_gnu_ld, but now it's lt_cv_prog_gnu_ld, and is copied back on
418 # top of with_gnu_ld (which is also set by --with-gnu-ld, so that actually
419 # makes sense). We'll test with_gnu_ld everywhere else, so if that isn't
420 # set (hence we're using an older libtool), then set it.
421 if test x${with_gnu_ld+set} != xset; then
422 if test x${ac_cv_prog_gnu_ld+set} != xset; then
423 # We got through "ac_require(ac_prog_ld)" and still not set? Huh?
424 with_gnu_ld=no
425 else
426 with_gnu_ld=$ac_cv_prog_gnu_ld
427 fi
428 fi
429
430 # Start by getting the version number. I think the libtool test already
431 # does some of this, but throws away the result.
432 libat_ld_is_gold=no
433 if $LD --version 2>/dev/null | grep 'GNU gold'> /dev/null 2>&1; then
434 libat_ld_is_gold=yes
435 fi
436 changequote(,)
437 ldver=`$LD --version 2>/dev/null |
438 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'`
439 changequote([,])
440 libat_gnu_ld_version=`echo $ldver | \
441 $AWK -F. '{ if (NF<3) [$]3=0; print ([$]1*100+[$]2)*100+[$]3 }'`
442
443 # Set --gc-sections.
444 if test "$with_gnu_ld" = "notbroken"; then
445 # GNU ld it is! Joy and bunny rabbits!
446
447 # All these tests are for C++; save the language and the compiler flags.
448 # Need to do this so that g++ won't try to link in libstdc++
449 ac_test_CFLAGS="${CFLAGS+set}"
450 ac_save_CFLAGS="$CFLAGS"
451 CFLAGS='-x c++ -Wl,--gc-sections'
452
453 # Check for -Wl,--gc-sections
454 # XXX This test is broken at the moment, as symbols required for linking
455 # are now in libsupc++ (not built yet). In addition, this test has
456 # cored on solaris in the past. In addition, --gc-sections doesn't
457 # really work at the moment (keeps on discarding used sections, first
458 # .eh_frame and now some of the glibc sections for iconv).
459 # Bzzzzt. Thanks for playing, maybe next time.
460 AC_MSG_CHECKING([for ld that supports -Wl,--gc-sections])
461 AC_TRY_RUN([
462 int main(void)
463 {
464 try { throw 1; }
465 catch (...) { };
466 return 0;
467 }
468 ], [ac_sectionLDflags=yes],[ac_sectionLDflags=no], [ac_sectionLDflags=yes])
469 if test "$ac_test_CFLAGS" = set; then
470 CFLAGS="$ac_save_CFLAGS"
471 else
472 # this is the suspicious part
473 CFLAGS=''
474 fi
475 if test "$ac_sectionLDflags" = "yes"; then
476 SECTION_LDFLAGS="-Wl,--gc-sections $SECTION_LDFLAGS"
477 fi
478 AC_MSG_RESULT($ac_sectionLDflags)
479 fi
480
481 # Set linker optimization flags.
482 if test x"$with_gnu_ld" = x"yes"; then
483 OPT_LDFLAGS="-Wl,-O1 $OPT_LDFLAGS"
484 fi
485
486 AC_SUBST(SECTION_LDFLAGS)
487 AC_SUBST(OPT_LDFLAGS)
488])
489
490
491dnl
492dnl Add version tags to symbols in shared library (or not), additionally
493dnl marking other symbols as private/local (or not).
494dnl
495dnl --enable-symvers=style adds a version script to the linker call when
496dnl creating the shared library. The choice of version script is
497dnl controlled by 'style'.
498dnl --disable-symvers does not.
499dnl + Usage: LIBAT_ENABLE_SYMVERS[(DEFAULT)]
500dnl Where DEFAULT is either 'yes' or 'no'. Passing `yes' tries to
501dnl choose a default style based on linker characteristics. Passing
502dnl 'no' disables versioning.
503dnl
504AC_DEFUN([LIBAT_ENABLE_SYMVERS], [
505
506LIBAT_ENABLE(symvers,yes,[=STYLE],
507 [enables symbol versioning of the shared library],
508 [permit yes|no|gnu*|sun])
509
510# If we never went through the LIBAT_CHECK_LINKER_FEATURES macro, then we
511# don't know enough about $LD to do tricks...
512AC_REQUIRE([LIBAT_CHECK_LINKER_FEATURES])
513
514# Turn a 'yes' into a suitable default.
515if test x$enable_symvers = xyes ; then
516 # FIXME The following test is too strict, in theory.
517 if test $enable_shared = no || test "x$LD" = x; then
518 enable_symvers=no
519 else
520 if test $with_gnu_ld = yes ; then
521 enable_symvers=gnu
522 else
523 case ${target_os} in
524 # Sun symbol versioning exists since Solaris 2.5.
525 solaris2.[[5-9]]* | solaris2.1[[0-9]]*)
526 enable_symvers=sun ;;
527 *)
528 enable_symvers=no ;;
529 esac
530 fi
531 fi
532fi
533
534# Check if 'sun' was requested on non-Solaris 2 platforms.
535if test x$enable_symvers = xsun ; then
536 case ${target_os} in
537 solaris2*)
538 # All fine.
539 ;;
540 *)
541 # Unlikely to work.
542 AC_MSG_WARN([=== You have requested Sun symbol versioning, but])
543 AC_MSG_WARN([=== you are not targetting Solaris 2.])
544 AC_MSG_WARN([=== Symbol versioning will be disabled.])
545 enable_symvers=no
546 ;;
547 esac
548fi
549
550# Check to see if libgcc_s exists, indicating that shared libgcc is possible.
551if test $enable_symvers != no; then
552 AC_MSG_CHECKING([for shared libgcc])
553 ac_save_CFLAGS="$CFLAGS"
554 CFLAGS=' -lgcc_s'
555 AC_TRY_LINK(, [return 0;], libat_shared_libgcc=yes, libat_shared_libgcc=no)
556 CFLAGS="$ac_save_CFLAGS"
557 if test $libat_shared_libgcc = no; then
558 cat > conftest.c <<EOF
559int main (void) { return 0; }
560EOF
561changequote(,)dnl
562 libat_libgcc_s_suffix=`${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS \
563 -shared -shared-libgcc -o conftest.so \
564 conftest.c -v 2>&1 >/dev/null \
565 | sed -n 's/^.* -lgcc_s\([^ ]*\) .*$/\1/p'`
566changequote([,])dnl
567 rm -f conftest.c conftest.so
568 if test x${libat_libgcc_s_suffix+set} = xset; then
569 CFLAGS=" -lgcc_s$libat_libgcc_s_suffix"
570 AC_TRY_LINK(, [return 0;], libat_shared_libgcc=yes)
571 CFLAGS="$ac_save_CFLAGS"
572 fi
573 fi
574 AC_MSG_RESULT($libat_shared_libgcc)
575fi
576
577# For GNU ld, we need at least this version. The format is described in
578# LIBAT_CHECK_LINKER_FEATURES above.
579libat_min_gnu_ld_version=21400
580# XXXXXXXXXXX libat_gnu_ld_version=21390
581
582# Check to see if unspecified "yes" value can win, given results above.
583# Change "yes" into either "no" or a style name.
584if test $enable_symvers != no && test $libat_shared_libgcc = yes; then
585 if test $with_gnu_ld = yes; then
586 if test $libat_gnu_ld_version -ge $libat_min_gnu_ld_version ; then
587 enable_symvers=gnu
588 elif test $libat_ld_is_gold = yes ; then
589 enable_symvers=gnu
590 else
591 # The right tools, the right setup, but too old. Fallbacks?
592 AC_MSG_WARN(=== Linker version $libat_gnu_ld_version is too old for)
593 AC_MSG_WARN(=== full symbol versioning support in this release of GCC.)
594 AC_MSG_WARN(=== You would need to upgrade your binutils to version)
595 AC_MSG_WARN(=== $libat_min_gnu_ld_version or later and rebuild GCC.)
596 if test $libat_gnu_ld_version -ge 21200 ; then
597 # Globbing fix is present, proper block support is not.
598 dnl AC_MSG_WARN([=== Dude, you are soooo close. Maybe we can fake it.])
599 dnl enable_symvers=???
600 AC_MSG_WARN([=== Symbol versioning will be disabled.])
601 enable_symvers=no
602 else
603 # 2.11 or older.
604 AC_MSG_WARN([=== Symbol versioning will be disabled.])
605 enable_symvers=no
606 fi
607 fi
608 elif test $enable_symvers = sun; then
609 : All interesting versions of Sun ld support sun style symbol versioning.
610 else
611 # just fail for now
612 AC_MSG_WARN([=== You have requested some kind of symbol versioning, but])
613 AC_MSG_WARN([=== either you are not using a supported linker, or you are])
614 AC_MSG_WARN([=== not building a shared libgcc_s (which is required).])
615 AC_MSG_WARN([=== Symbol versioning will be disabled.])
616 enable_symvers=no
617 fi
618fi
619if test $enable_symvers = gnu; then
620 AC_DEFINE(LIBAT_GNU_SYMBOL_VERSIONING, 1,
621 [Define to 1 if GNU symbol versioning is used for libatomic.])
622fi
623
624AM_CONDITIONAL(LIBAT_BUILD_VERSIONED_SHLIB, test $enable_symvers != no)
625AM_CONDITIONAL(LIBAT_BUILD_VERSIONED_SHLIB_GNU, test $enable_symvers = gnu)
626AM_CONDITIONAL(LIBAT_BUILD_VERSIONED_SHLIB_SUN, test $enable_symvers = sun)
627AC_MSG_NOTICE(versioning on shared library symbols is $enable_symvers)
628])
629
630dnl ----------------------------------------------------------------------
631sinclude(../libtool.m4)
632dnl The lines below arrange for aclocal not to bring an installed
633dnl libtool.m4 into aclocal.m4, while still arranging for automake to
634dnl add a definition of LIBTOOL to Makefile.in.
635ifelse(,,,[AC_SUBST(LIBTOOL)
636AC_DEFUN([AM_PROG_LIBTOOL])
637AC_DEFUN([AC_LIBTOOL_DLOPEN])
638AC_DEFUN([AC_PROG_LD])
639])