acinclude.m4 13 KB

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