[Spice-devel] [PATCH 1/7] Add configure-time check for -Wl, --version-script option

Daniel P. Berrange berrange at redhat.com
Fri Feb 17 02:21:13 PST 2012


On Thu, Feb 16, 2012 at 11:30:07PM -0600, Dan McGee wrote:
> This is supported by the GNU linker, but not the Solaris linker, which
> is used as the default on that platform even when compiling with GCC.
> Omit passing the option to the linker on platforms that do not support
> it.
> 
> Signed-off-by: Dan McGee <dpmcgee at gmail.com>
> ---
>  configure.ac       |   10 ++++++++++
>  server/Makefile.am |   12 ++++++++----
>  2 files changed, 18 insertions(+), 4 deletions(-)
> 
> diff --git a/configure.ac b/configure.ac
> index 1c15e74..b8acfa9 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -518,6 +518,16 @@ fi
>  AC_MSG_RESULT($have_gcc4)
>  AC_SUBST(VISIBILITY_HIDDEN_CFLAGS)
>  
> +dnl ensure linker supports ---version-script option before using it
> +AC_CACHE_CHECK([if -Wl,--version-script works], [spice_cv_ld_version_script],
> +    [save_LDFLAGS="$LDFLAGS"
> +     LDFLAGS="$LDFLAGS -Wl,--version-script=$srcdir/server/spice-server.syms"
> +     AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])],
> +        [spice_cv_ld_version_script=yes], [spice_cv_ld_version_script=no])
> +     LDFLAGS="$save_LDFLAGS"])
> +AM_CONDITIONAL([HAVE_LD_VERSION_SCRIPT],
> +    [test x"$spice_cv_ld_version_script" = xyes])
> +

The Solaris linker does actually support version scripts using the
exact same file syntax as the GNU linker. The only thing that is different
is the linker command line arg. Mingw32 supports the same linker flags,
but requires a different file syntax (which can be auto-generated from
a .version file with awk/sed)
 
So in libvirt/GTK-VNC we use the following m4 magic in configure to detect
the suitable linker args

NO_UNDEFINED_LDFLAGS=
VERSION_SCRIPT_FLAGS=
USE_VERSION_DEFS=0
case "$host" in
  *-*-mingw*)
    VERSION_SCRIPT_FLAGS="-Wl,"
    USE_VERSION_DEFS=1
    NO_UNDEFINED_FLAGS="-no-undefined"
    ;;

  *-*-cygwin*)
    NO_UNDEFINED_LDFLAGS="-no-undefined"
    ;;

  *)
    NO_UNDEFINED_FLAGS="-Wl,--no-undefined"
    VERSION_SCRIPT_FLAGS=-Wl,--version-script=
    `ld --help 2>&1 | grep -- --version-script >/dev/null` || \
      VERSION_SCRIPT_FLAGS="-Wl,-M -Wl,"
    ;;
esac
AC_SUBST([NO_UNDEFINED_FLAGS])
AC_SUBST([VERSION_SCRIPT_FLAGS])
AM_CONDITIONAL([USE_VERSION_DEFS], [test "$USE_VERSION_DEFS" = "1"])


And then in the Makefile.am use


if USE_VERSION_DEFS
GTK_VNC_VERSION_FILE = $(builddir)/libgtk-vnc_sym.def
BUILT_SOURCES += $(GTK_VNC_VERSION_FILE)
else
GTK_VNC_VERSION_FILE = $(srcdir)/libgtk-vnc_sym.version
endif

%.def: %.version Makefile
        $(AM_V_GEN)rm -f -- $@-tmp $@ ; \
        printf 'EXPORTS\n' > $@-tmp && \
        sed -e '/^$$/d; /#/d; /:/d; /\}/d; /\*/d; /GTK_VNC_/d; s/[ \t]*\(.*\)\;/    \1/g' $< >> $@-tmp && \
        chmod a-w $@-tmp && \
        mv $@-tmp $@
endif

gtk_vnc_LDFLAGS = \
                        $(VERSION_SCRIPT_FLAGS)$(GTK_VNC_VERSION_FILE) \
                        $(NO_UNDEFINED_FLAGS)

And this works on Linux, Mingw32, OS-X, *BSD & Solaris.

Regards,
Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|


More information about the Spice-devel mailing list