[PATCH] Add AC_LIB_PROG_LD_GNU m4 macro to check for GNU ld in the test suite.

Dan Nicholson dbn.lists at gmail.com
Mon Jun 8 06:04:38 PDT 2009


On Mon, Jun 8, 2009 at 2:46 AM, Peter Hutterer<peter.hutterer at who-t.net> wrote:
> The GNU linker supports a -wrap option to wrap function calls at link-time.
> This allows for easy overriding of functions in the X server with stubs in
> the test suite. This functionality is only supported on the GNU linker and
> will be used extensively in the tests. Disable the tests if GNU ld is not
> available.
>
> Macro obtained from
> https://svn9.cvsdude.com/vvc/kdesolaris/trunk/GETTEXT/0.17/autoconf-lib-link/m4/lib-ld.m4?revision=1104&view=markup&sortby=author&pathrev=1240
> ---
>
> This little linker feature is extremely useful. It allows overriding
> in-server functions. Say you need to test a function foo in the server:
>
> void foo(int magic)
> {
>    /* do something*/
>    bar();
> }
>
> Then you can override bar() to be a noop or return default values while
> banging random values against foo(). For example, testing ProcXIQueryVersion
> from INT_MIN to INT_MAX uncovered four or five issues and I didn't even have
> to fire up the server (or a client).
>
> If there are no complaints, I'll push that in the next days. Tests using
> this feature will follow.
>
>  configure.ac          |   12 +++++-
>  m4/ac_lib_prog_gnu.m4 |  110 +++++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 121 insertions(+), 1 deletions(-)
>  create mode 100644 m4/ac_lib_prog_gnu.m4
>
> diff --git a/configure.ac b/configure.ac
> index fc29bf0..8988adb 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -1145,11 +1145,21 @@ fi
>  AM_CONDITIONAL(DEBUG, [test "x$DEBUGGING" = xyes])
>
>  if test "x$UNITTESTS" = xauto; then
> -       PKG_CHECK_MODULES([GLIB], [glib-2.0 >= 2.16], [UNITTESTS=yes], [UNITTESTS=no])
> +       PKG_CHECK_MODULES([GLIB], [glib-2.0 >= 2.16], [HAVE_GLIB=yes], [HAVE_GLIB=no])
> +       AC_LIB_PROG_LD_GNU
> +       if test "x$HAVE_GLIB" = xyes && test "x$with_gnu_ld" = xyes; then
> +           UNITTESTS=yes
> +       else
> +           UNITTESTS=no
> +       fi
>  fi
>  if test "x$UNITTESTS" = xyes; then
>        AC_DEFINE(UNITTESTS, 1, [Enable unit tests])
>        PKG_CHECK_MODULES([GLIB], [glib-2.0 >= 2.16])
> +       AC_LIB_PROG_LD_GNU
> +       if test "x$with_gnu_ld" = xno; then
> +           AC_MSG_ERROR([GNU ld required to build unit tests])
> +       fi
>        AC_SUBST([GLIB_LIBS])
>        AC_SUBST([GLIB_CFLAGS])
>  fi
> diff --git a/m4/ac_lib_prog_gnu.m4 b/m4/ac_lib_prog_gnu.m4
> new file mode 100644
> index 0000000..176cff0
> --- /dev/null
> +++ b/m4/ac_lib_prog_gnu.m4
> @@ -0,0 +1,110 @@
> +dnl Copyright (C) 1996-2003 Free Software Foundation, Inc.
> +dnl This file is free software; the Free Software Foundation
> +dnl gives unlimited permission to copy and/or distribute it,
> +dnl with or without modifications, as long as this notice is preserved.
> +
> +dnl Subroutines of libtool.m4,
> +dnl with replacements s/AC_/AC_LIB/ and s/lt_cv/acl_cv/ to avoid collision
> +dnl with libtool.m4.

As long as we're already using libtool.m4, this macro is just
duplication. Libtool already does all this for us in AC_PROG_LD and
AC_PROG_LD_GNU. lt_cv_prog_gnu_ld and with_gnu_ld are already set to
yes or no.

So, you can drop the whole external macro so long as you do your
checking after AC_PROG_LIBTOOL/LT_INIT. To be extra safe, you can add
a specific call to AC_PROG_LD, but it's probably not necessary.

--
Dan


More information about the xorg-devel mailing list