2017-12-07 Vladimir Makarov <vmakarov@redhat.com>
[official-gcc.git] / config / weakref.m4
blobecb85672805882b330cac43e0fc12e7fe96aeec9
2 dnl Check if the target supports weak.
3 AC_DEFUN([GCC_CHECK_ATTRIBUTE_WEAK], [
4   AC_CACHE_CHECK([whether the target supports weak],
5                  ac_cv_have_attribute_weak, [
6   weakref_m4_saved_CFLAGS="$CFLAGS"
7   CFLAGS="$CFLAGS -Werror"
8   AC_TRY_COMPILE([void __attribute__((weak)) foo(void) { }],
9                  [], ac_cv_have_attribute_weak=yes,
10                  ac_cv_have_attribute_weak=no)
11   CFLAGS="$weakref_m4_saved_CFLAGS"])
12   if test x"$ac_cv_have_attribute_weak" = xyes; then
13     AC_DEFINE(HAVE_ATTRIBUTE_WEAK, 1,
14       [Define to 1 if the target supports __attribute__((weak)).])
15   fi])
17 dnl Check whether weak refs work like the ELF ones.
18 dnl This means that the weak reference works without having to satify 
19 dnl linkage for the item.
20 dnl There are targets (at least Darwin) where we have fully functional
21 dnl weakrefs at runtime, but must supply the referenced item at link time.
22 AC_DEFUN([GCC_CHECK_ELF_STYLE_WEAKREF], [
23   AC_CACHE_CHECK([whether weak refs work like ELF],
24                   ac_cv_have_elf_style_weakref, [
25   weakref_m4_saved_CFLAGS="$CFLAGS"
26   case "${host}" in
27     *-apple-darwin*) CFLAGS="$CFLAGS -Wl,-undefined,dynamic_lookup" ;;
28     *) ;;
29   esac  
30   AC_RUN_IFELSE([AC_LANG_SOURCE([[
31 extern void fNotToBeFound(void) __attribute__((weak));
32 int main () 
34   if (fNotToBeFound)
35     return 1;
36   else
37     return 0;
39 ]])], ac_cv_have_elf_style_weakref=yes, ac_cv_have_elf_style_weakref=no, [
40 case "${host}" in
41   *-apple-darwin[[89]]*) ac_cv_have_elf_style_weakref=no ;;
42   *) ac_cv_have_elf_style_weakref=yes;;
43 esac])CFLAGS="$weakref_m4_saved_CFLAGS"])
44 if test x"$ac_cv_have_elf_style_weakref" = xyes; then
45   AC_DEFINE(HAVE_ELF_STYLE_WEAKREF, 1, [Define to 1 if target has a weakref that works like the ELF one.])
46 fi])