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