acinclude.m4 23 KB

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