Blame config/ax_sys_weak_alias.m4

Packit c04fcb
# ===========================================================================
Packit c04fcb
#     http://www.gnu.org/software/autoconf-archive/ax_sys_weak_alias.html
Packit c04fcb
# ===========================================================================
Packit c04fcb
#
Packit c04fcb
# SYNOPSIS
Packit c04fcb
#
Packit c04fcb
#   AX_SYS_WEAK_ALIAS
Packit c04fcb
#
Packit c04fcb
# DESCRIPTION
Packit c04fcb
#
Packit c04fcb
#   Determines whether weak aliases are supported on the system, and if so,
Packit c04fcb
#   what scheme is used to declare them. Also checks to see if aliases can
Packit c04fcb
#   cross object file boundaries, as some systems don't permit them to.
Packit c04fcb
#
Packit c04fcb
#   Most systems permit something called a "weak alias" or "weak symbol."
Packit c04fcb
#   These aliases permit a library to provide a stub form of a routine
Packit c04fcb
#   defined in another library, thus allowing the first library to operate
Packit c04fcb
#   even if the other library is not linked. This macro will check for
Packit c04fcb
#   support of weak aliases, figure out what schemes are available, and
Packit c04fcb
#   determine some characteristics of the weak alias support -- primarily,
Packit c04fcb
#   whether a weak alias declared in one object file may be referenced from
Packit c04fcb
#   another object file.
Packit c04fcb
#
Packit c04fcb
#   There are four known schemes of declaring weak symbols; each scheme is
Packit c04fcb
#   checked in turn, and the first one found is prefered. Note that only one
Packit c04fcb
#   of the mentioned preprocessor macros will be defined!
Packit c04fcb
#
Packit c04fcb
#   1. Function attributes
Packit c04fcb
#
Packit c04fcb
#   This scheme was first introduced by the GNU C compiler, and attaches
Packit c04fcb
#   attributes to particular functions. It is among the easiest to use, and
Packit c04fcb
#   so is the first one checked. If this scheme is detected, the
Packit c04fcb
#   preprocessor macro HAVE_SYS_WEAK_ALIAS_ATTRIBUTE will be defined to 1.
Packit c04fcb
#   This scheme is used as in the following code fragment:
Packit c04fcb
#
Packit c04fcb
#     void __weakf(int c)
Packit c04fcb
#     {
Packit c04fcb
#       /* Function definition... */
Packit c04fcb
#     }
Packit c04fcb
#
Packit c04fcb
#     void weakf(int c) __attribute__((weak, alias("__weakf")));
Packit c04fcb
#
Packit c04fcb
#   2. #pragma weak
Packit c04fcb
#
Packit c04fcb
#   This scheme is in use by many compilers other than the GNU C compiler.
Packit c04fcb
#   It is also particularly easy to use, and fairly portable -- well, as
Packit c04fcb
#   portable as these things get. If this scheme is detected first, the
Packit c04fcb
#   preprocessor macro HAVE_SYS_WEAK_ALIAS_PRAGMA will be defined to 1. This
Packit c04fcb
#   scheme is used as in the following code fragment:
Packit c04fcb
#
Packit c04fcb
#     extern void weakf(int c);
Packit c04fcb
#     #pragma weak weakf = __weakf
Packit c04fcb
#     void __weakf(int c)
Packit c04fcb
#     {
Packit c04fcb
#       /* Function definition... */
Packit c04fcb
#     }
Packit c04fcb
#
Packit c04fcb
#   3. #pragma _HP_SECONDARY_DEF
Packit c04fcb
#
Packit c04fcb
#   This scheme appears to be in use by the HP compiler. As it is rather
Packit c04fcb
#   specialized, this is one of the last schemes checked. If it is the first
Packit c04fcb
#   one detected, the preprocessor macro HAVE_SYS_WEAK_ALIAS_HPSECONDARY
Packit c04fcb
#   will be defined to 1. This scheme is used as in the following code
Packit c04fcb
#   fragment:
Packit c04fcb
#
Packit c04fcb
#     extern void weakf(int c);
Packit c04fcb
#     #pragma _HP_SECONDARY_DEF __weakf weakf
Packit c04fcb
#     void __weakf(int c)
Packit c04fcb
#     {
Packit c04fcb
#       /* Function definition... */
Packit c04fcb
#     }
Packit c04fcb
#
Packit c04fcb
#   4. #pragma _CRI duplicate
Packit c04fcb
#
Packit c04fcb
#   This scheme appears to be in use by the Cray compiler. As it is rather
Packit c04fcb
#   specialized, it too is one of the last schemes checked. If it is the
Packit c04fcb
#   first one detected, the preprocessor macro
Packit c04fcb
#   HAVE_SYS_WEAK_ALIAS_CRIDUPLICATE will be defined to 1. This scheme is
Packit c04fcb
#   used as in the following code fragment:
Packit c04fcb
#
Packit c04fcb
#     extern void weakf(int c);
Packit c04fcb
#     #pragma _CRI duplicate weakf as __weakf
Packit c04fcb
#     void __weakf(int c)
Packit c04fcb
#     {
Packit c04fcb
#       /* Function definition... */
Packit c04fcb
#     }
Packit c04fcb
#
Packit c04fcb
#   In addition to the preprocessor macros listed above, if any scheme is
Packit c04fcb
#   found, the preprocessor macro HAVE_SYS_WEAK_ALIAS will also be defined
Packit c04fcb
#   to 1.
Packit c04fcb
#
Packit c04fcb
#   Once a weak aliasing scheme has been found, a check will be performed to
Packit c04fcb
#   see if weak aliases are honored across object file boundaries. If they
Packit c04fcb
#   are, the HAVE_SYS_WEAK_ALIAS_CROSSFILE preprocessor macro is defined to
Packit c04fcb
#   1.
Packit c04fcb
#
Packit c04fcb
#   This Autoconf macro also makes two substitutions. The first, WEAK_ALIAS,
Packit c04fcb
#   contains the name of the scheme found (one of "attribute", "pragma",
Packit c04fcb
#   "hpsecondary", or "criduplicate"), or "no" if no weak aliasing scheme
Packit c04fcb
#   was found. The second, WEAK_ALIAS_CROSSFILE, is set to "yes" or "no"
Packit c04fcb
#   depending on whether or not weak aliases may cross object file
Packit c04fcb
#   boundaries.
Packit c04fcb
#
Packit c04fcb
# LICENSE
Packit c04fcb
#
Packit c04fcb
#   Copyright (c) 2008 Kevin L. Mitchell <klmitch@mit.edu>
Packit c04fcb
#
Packit c04fcb
#   Copying and distribution of this file, with or without modification, are
Packit c04fcb
#   permitted in any medium without royalty provided the copyright notice
Packit c04fcb
#   and this notice are preserved. This file is offered as-is, without any
Packit c04fcb
#   warranty.
Packit c04fcb
Packit c04fcb
#serial 6
Packit c04fcb
Packit c04fcb
AU_ALIAS([KLM_SYS_WEAK_ALIAS], [AX_SYS_WEAK_ALIAS])
Packit c04fcb
AC_DEFUN([AX_SYS_WEAK_ALIAS], [
Packit c04fcb
  # starting point: no aliasing scheme yet...
Packit c04fcb
  ax_sys_weak_alias=no
Packit c04fcb
Packit c04fcb
  # Figure out what kind of aliasing may be supported...
Packit c04fcb
  _AX_SYS_WEAK_ALIAS_ATTRIBUTE
Packit c04fcb
  _AX_SYS_WEAK_ALIAS_PRAGMA
Packit c04fcb
  _AX_SYS_WEAK_ALIAS_HPSECONDARY
Packit c04fcb
  _AX_SYS_WEAK_ALIAS_CRIDUPLICATE
Packit c04fcb
Packit c04fcb
  # Do we actually support aliasing?
Packit c04fcb
  AC_CACHE_CHECK([how to create weak aliases with $CC],
Packit c04fcb
                 [ax_cv_sys_weak_alias],
Packit c04fcb
                 [ax_cv_sys_weak_alias=$ax_sys_weak_alias])
Packit c04fcb
Packit c04fcb
  # OK, set a #define
Packit c04fcb
  AS_IF([test $ax_cv_sys_weak_alias != no], [
Packit c04fcb
    AC_DEFINE([HAVE_SYS_WEAK_ALIAS], 1,
Packit c04fcb
              [Define this if your system can create weak aliases])
Packit c04fcb
  ])
Packit c04fcb
Packit c04fcb
  # Can aliases cross object file boundaries?
Packit c04fcb
  _AX_SYS_WEAK_ALIAS_CROSSFILE
Packit c04fcb
Packit c04fcb
  # OK, remember the results
Packit c04fcb
  AC_SUBST([WEAK_ALIAS], [$ax_cv_sys_weak_alias])
Packit c04fcb
  AC_SUBST([WEAK_ALIAS_CROSSFILE], [$ax_cv_sys_weak_alias_crossfile])
Packit c04fcb
])
Packit c04fcb
Packit c04fcb
AC_DEFUN([_AX_SYS_WEAK_ALIAS_ATTRIBUTE],
Packit c04fcb
[ # Test whether compiler accepts __attribute__ form of weak aliasing
Packit c04fcb
  AC_CACHE_CHECK([whether $CC accepts function __attribute__((weak,alias()))],
Packit c04fcb
  [ax_cv_sys_weak_alias_attribute], [
Packit c04fcb
    # We add -Werror if it's gcc to force an error exit if the weak attribute
Packit c04fcb
    # isn't understood
Packit c04fcb
    AS_IF([test $GCC = yes], [
Packit c04fcb
      save_CFLAGS=$CFLAGS
Packit c04fcb
      CFLAGS=-Werror])
Packit c04fcb
Packit c04fcb
    # Try linking with a weak alias...
Packit c04fcb
    AC_LINK_IFELSE([
Packit c04fcb
      AC_LANG_PROGRAM([
Packit c04fcb
void __weakf(int c) {}
Packit c04fcb
void weakf(int c) __attribute__((weak, alias("__weakf")));],
Packit c04fcb
        [weakf(0)])],
Packit c04fcb
      [ax_cv_sys_weak_alias_attribute=yes],
Packit c04fcb
      [ax_cv_sys_weak_alias_attribute=no])
Packit c04fcb
Packit c04fcb
    # Restore original CFLAGS
Packit c04fcb
    AS_IF([test $GCC = yes], [
Packit c04fcb
      CFLAGS=$save_CFLAGS])
Packit c04fcb
  ])
Packit c04fcb
Packit c04fcb
  # What was the result of the test?
Packit c04fcb
  AS_IF([test $ax_sys_weak_alias = no &&
Packit c04fcb
         test $ax_cv_sys_weak_alias_attribute = yes], [
Packit c04fcb
    ax_sys_weak_alias=attribute
Packit c04fcb
    AC_DEFINE([HAVE_SYS_WEAK_ALIAS_ATTRIBUTE], 1,
Packit c04fcb
              [Define this if weak aliases may be created with __attribute__])
Packit c04fcb
  ])
Packit c04fcb
])
Packit c04fcb
Packit c04fcb
AC_DEFUN([_AX_SYS_WEAK_ALIAS_PRAGMA],
Packit c04fcb
[ # Test whether compiler accepts #pragma form of weak aliasing
Packit c04fcb
  AC_CACHE_CHECK([whether $CC supports @%:@pragma weak],
Packit c04fcb
  [ax_cv_sys_weak_alias_pragma], [
Packit c04fcb
Packit c04fcb
    # Try linking with a weak alias...
Packit c04fcb
    AC_LINK_IFELSE([
Packit c04fcb
      AC_LANG_PROGRAM([
Packit c04fcb
extern void weakf(int c);
Packit c04fcb
@%:@pragma weak weakf = __weakf
Packit c04fcb
void __weakf(int c) {}],
Packit c04fcb
        [weakf(0)])],
Packit c04fcb
      [ax_cv_sys_weak_alias_pragma=yes],
Packit c04fcb
      [ax_cv_sys_weak_alias_pragma=no])
Packit c04fcb
  ])
Packit c04fcb
Packit c04fcb
  # What was the result of the test?
Packit c04fcb
  AS_IF([test $ax_sys_weak_alias = no &&
Packit c04fcb
         test $ax_cv_sys_weak_alias_pragma = yes], [
Packit c04fcb
    ax_sys_weak_alias=pragma
Packit c04fcb
    AC_DEFINE([HAVE_SYS_WEAK_ALIAS_PRAGMA], 1,
Packit c04fcb
              [Define this if weak aliases may be created with @%:@pragma weak])
Packit c04fcb
  ])
Packit c04fcb
])
Packit c04fcb
Packit c04fcb
AC_DEFUN([_AX_SYS_WEAK_ALIAS_HPSECONDARY],
Packit c04fcb
[ # Test whether compiler accepts _HP_SECONDARY_DEF pragma from HP...
Packit c04fcb
  AC_CACHE_CHECK([whether $CC supports @%:@pragma _HP_SECONDARY_DEF],
Packit c04fcb
  [ax_cv_sys_weak_alias_hpsecondary], [
Packit c04fcb
Packit c04fcb
    # Try linking with a weak alias...
Packit c04fcb
    AC_LINK_IFELSE([
Packit c04fcb
      AC_LANG_PROGRAM([
Packit c04fcb
extern void weakf(int c);
Packit c04fcb
@%:@pragma _HP_SECONDARY_DEF __weakf weakf
Packit c04fcb
void __weakf(int c) {}],
Packit c04fcb
        [weakf(0)])],
Packit c04fcb
      [ax_cv_sys_weak_alias_hpsecondary=yes],
Packit c04fcb
      [ax_cv_sys_weak_alias_hpsecondary=no])
Packit c04fcb
  ])
Packit c04fcb
Packit c04fcb
  # What was the result of the test?
Packit c04fcb
  AS_IF([test $ax_sys_weak_alias = no &&
Packit c04fcb
         test $ax_cv_sys_weak_alias_hpsecondary = yes], [
Packit c04fcb
    ax_sys_weak_alias=hpsecondary
Packit c04fcb
    AC_DEFINE([HAVE_SYS_WEAK_ALIAS_HPSECONDARY], 1,
Packit c04fcb
              [Define this if weak aliases may be created with @%:@pragma _HP_SECONDARY_DEF])
Packit c04fcb
  ])
Packit c04fcb
])
Packit c04fcb
Packit c04fcb
AC_DEFUN([_AX_SYS_WEAK_ALIAS_CRIDUPLICATE],
Packit c04fcb
[ # Test whether compiler accepts "_CRI duplicate" pragma from Cray
Packit c04fcb
  AC_CACHE_CHECK([whether $CC supports @%:@pragma _CRI duplicate],
Packit c04fcb
  [ax_cv_sys_weak_alias_criduplicate], [
Packit c04fcb
Packit c04fcb
    # Try linking with a weak alias...
Packit c04fcb
    AC_LINK_IFELSE([
Packit c04fcb
      AC_LANG_PROGRAM([
Packit c04fcb
extern void weakf(int c);
Packit c04fcb
@%:@pragma _CRI duplicate weakf as __weakf
Packit c04fcb
void __weakf(int c) {}],
Packit c04fcb
        [weakf(0)])],
Packit c04fcb
      [ax_cv_sys_weak_alias_criduplicate=yes],
Packit c04fcb
      [ax_cv_sys_weak_alias_criduplicate=no])
Packit c04fcb
  ])
Packit c04fcb
Packit c04fcb
  # What was the result of the test?
Packit c04fcb
  AS_IF([test $ax_sys_weak_alias = no &&
Packit c04fcb
         test $ax_cv_sys_weak_alias_criduplicate = yes], [
Packit c04fcb
    ax_sys_weak_alias=criduplicate
Packit c04fcb
    AC_DEFINE([HAVE_SYS_WEAK_ALIAS_CRIDUPLICATE], 1,
Packit c04fcb
              [Define this if weak aliases may be created with @%:@pragma _CRI duplicate])
Packit c04fcb
  ])
Packit c04fcb
])
Packit c04fcb
Packit c04fcb
dnl Note: This macro is modeled closely on AC_LINK_IFELSE, and in fact
Packit c04fcb
dnl depends on some implementation details of that macro, particularly
Packit c04fcb
dnl its use of _AC_MSG_LOG_CONFTEST to log the failed test program and
Packit c04fcb
dnl its use of ac_link for running the linker.
Packit c04fcb
AC_DEFUN([_AX_SYS_WEAK_ALIAS_CROSSFILE],
Packit c04fcb
[ # Check to see if weak aliases can cross object file boundaries
Packit c04fcb
  AC_CACHE_CHECK([whether $CC supports weak aliases across object file boundaries],
Packit c04fcb
  [ax_cv_sys_weak_alias_crossfile], [
Packit c04fcb
    AS_IF([test $ax_cv_sys_weak_alias = no],
Packit c04fcb
          [ax_cv_sys_weak_alias_crossfile=no], [
Packit c04fcb
dnl Must build our own test files...
Packit c04fcb
      # conftest1 contains our weak alias definition...
Packit c04fcb
      cat >conftest1.$ac_ext <<_ACEOF
Packit c04fcb
/* confdefs.h.  */
Packit c04fcb
_ACEOF
Packit c04fcb
      cat confdefs.h >>conftest1.$ac_ext
Packit c04fcb
      cat >>conftest1.$ac_ext <<_ACEOF
Packit c04fcb
/* end confdefs.h.  */
Packit c04fcb
Packit c04fcb
@%:@ifndef HAVE_SYS_WEAK_ALIAS_ATTRIBUTE
Packit c04fcb
extern void weakf(int c);
Packit c04fcb
@%:@endif
Packit c04fcb
@%:@if defined(HAVE_SYS_WEAK_ALIAS_PRAGMA)
Packit c04fcb
@%:@pragma weak weakf = __weakf
Packit c04fcb
@%:@elif defined(HAVE_SYS_WEAK_ALIAS_HPSECONDARY)
Packit c04fcb
@%:@pragma _HP_SECONDARY_DEF __weakf weakf
Packit c04fcb
@%:@elif defined(HAVE_SYS_WEAK_ALIAS_CRIDUPLICATE)
Packit c04fcb
@%:@pragma _CRI duplicate weakf as __weakf
Packit c04fcb
@%:@endif
Packit c04fcb
void __weakf(int c) {}
Packit c04fcb
@%:@ifdef HAVE_SYS_WEAK_ALIAS_ATTRIBUTE
Packit c04fcb
void weakf(int c) __attribute((weak, alias("__weakf")));
Packit c04fcb
@%:@endif
Packit c04fcb
_ACEOF
Packit c04fcb
      # And conftest2 contains our main routine that calls it
Packit c04fcb
      cat >conftest2.$ac_ext <<_ACEOF
Packit c04fcb
/* confdefs.h.  */
Packit c04fcb
_ACEOF
Packit c04fcb
      cat confdefs.h >> conftest2.$ac_ext
Packit c04fcb
      cat >>conftest2.$ac_ext <<_ACEOF
Packit c04fcb
/* end confdefs.h.  */
Packit c04fcb
Packit c04fcb
extern void weakf(int c);
Packit c04fcb
int
Packit c04fcb
main ()
Packit c04fcb
{
Packit c04fcb
  weakf(0);
Packit c04fcb
  return 0;
Packit c04fcb
}
Packit c04fcb
_ACEOF
Packit c04fcb
      # We must remove the object files (if any) ourselves...
Packit c04fcb
      rm -f conftest2.$ac_objext conftest$ac_exeext
Packit c04fcb
Packit c04fcb
      # Change ac_link to compile *2* files together
Packit c04fcb
      save_aclink=$ac_link
Packit c04fcb
      ac_link=`echo "$ac_link" | \
Packit c04fcb
               sed -e 's/conftest\(\.\$ac_ext\)/conftest1\1 conftest2\1/'`
Packit c04fcb
dnl Substitute our own routine for logging the conftest
Packit c04fcb
m4_pushdef([_AC_MSG_LOG_CONFTEST],
Packit c04fcb
[echo "$as_me: failed program was:" >&AS_MESSAGE_LOG_FD
Packit c04fcb
echo ">>> conftest1.$ac_ext" >&AS_MESSAGE_LOG_FD
Packit c04fcb
sed "s/^/| /" conftest1.$ac_ext >&AS_MESSAGE_LOG_FD
Packit c04fcb
echo ">>> conftest2.$ac_ext" >&AS_MESSAGE_LOG_FD
Packit c04fcb
sed "s/^/| /" conftest2.$ac_ext >&AS_MESSAGE_LOG_FD
Packit c04fcb
])dnl
Packit c04fcb
      # Since we created the files ourselves, don't use SOURCE argument
Packit c04fcb
      AC_LINK_IFELSE(, [ax_cv_sys_weak_alias_crossfile=yes],
Packit c04fcb
                     [ax_cv_sys_weak_alias_crossfile=no])
Packit c04fcb
dnl Restore _AC_MSG_LOG_CONFTEST
Packit c04fcb
m4_popdef([_AC_MSG_LOG_CONFTEST])dnl
Packit c04fcb
      # Restore ac_link
Packit c04fcb
      ac_link=$save_aclink
Packit c04fcb
Packit c04fcb
      # We must remove the object files (if any) and C files ourselves...
Packit c04fcb
      rm -f conftest1.$ac_ext conftest2.$ac_ext \
Packit c04fcb
            conftest1.$ac_objext conftest2.$ac_objext
Packit c04fcb
    ])
Packit c04fcb
  ])
Packit c04fcb
Packit c04fcb
  # What were the results of the test?
Packit c04fcb
  AS_IF([test $ax_cv_sys_weak_alias_crossfile = yes], [
Packit c04fcb
    AC_DEFINE([HAVE_SYS_WEAK_ALIAS_CROSSFILE], 1,
Packit c04fcb
              [Define this if weak aliases in other files are honored])
Packit c04fcb
  ])
Packit c04fcb
])