acinclude.m4 16 KB

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