acinclude.m4 14 KB

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