# HG changeset patch # User Simon Josefsson # Date 1236078059 -3600 # Node ID 28202c1cd52d371cfce6f52a3cf91c75d84e635e # Parent c90f22b1783e31903260dbd4e6131b88454e359a Add new module ld-version-script. Fix doc for visibility. diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2009-03-03 Simon Josefsson + + * doc/gnulib.texi: Link to sections for ld version script and + visibility. + * doc/visibility.texi: Add @node and @section. + * modules/ld-version-script: New module. + * m4/ld-version-script.m4: New file. + * doc/ld-version-script.texi: New file. + 2009-03-02 David Lutterkort * lib/safe-alloc.h (__GNUC_PREREQ): New macro. diff --git a/doc/gnulib.texi b/doc/gnulib.texi --- a/doc/gnulib.texi +++ b/doc/gnulib.texi @@ -5825,6 +5825,8 @@ * func:: * warnings:: * manywarnings:: +* visibility:: +* LD Version Scripts:: @end menu @node alloca @@ -5917,6 +5919,10 @@ @include manywarnings.texi +@include visibility.texi + +@include ld-version-script.texi + @node GNU Free Documentation License @appendix GNU Free Documentation License diff --git a/doc/ld-version-script.texi b/doc/ld-version-script.texi new file mode 100644 --- /dev/null +++ b/doc/ld-version-script.texi @@ -0,0 +1,77 @@ +i@node LD Version Scripts +@section LD Version Scripts + +The @code{ld-version-script} module can be used to add shared library +versioning support. Currently, only GNU LD and the Solaris linker +supports this. + +Version scripts provides information that can be used by GNU/Linux +distribution packaging tools. For example, Debian has a tool +@code{dpkg-shlibdeps} that can determine the minimal required version +of each dependency (by looking at the symbol list) and stuff the +information into the Debian specific packaging files. + +For more information and other uses of version scripts, see Ulrich +Drepper's paper @url{http://people.redhat.com/drepper/dsohowto.pdf} + +You use the module by importing it to your library, and then add the +following lines to the @code{Makefile.am} that builds the library: + +@smallexample +if HAVE_LD_VERSION_SCRIPT +libfoo_la_LDFLAGS += -Wl,--version-script=$(srcdir)/libfoo.map +endif +@end smallexample + +The version script file format is documented in the GNU LD manual, but +a small example would be: + +@smallexample +LIBFOO_1.0 @{ + global: + libfoo_init; libfoo_doit; libfoo_done; + + local: + *; +@}; +@end smallexample + +If you target platforms that do not support linker scripts (i.e., all +platforms that doesn't use GNU LD) you may want to consider a more +portable but less powerful alternative: libtool +@code{-export-symbols}. It will hide internal symbols from your +library, but will not add ELF versioning symbols. Your usage would +then be something like: + +@smallexample +if HAVE_LD_VERSION_SCRIPT +libfoo_la_LDFLAGS += -Wl,--version-script=$(srcdir)/libfoo.map +else +libfoo_la_LDFLAGS += -export-symbols $(srcdir)/libfoo.sym +endif +@end smallexample + +See the Libtool manual for the file syntax, but a small example would +be: + +@smallexample +libfoo_init +libfoo_doit +libfoo_done +@end smallexample + +To avoid the need for a @code{*.sym} file if your symbols are easily +expressed using a regular expression, you may use +@code{-export-symbols-regex}: + +@smallexample +if HAVE_LD_VERSION_SCRIPT +libfoo_la_LDFLAGS += -Wl,--version-script=$(srcdir)/libfoo.map +else +libfoo_la_LDFLAGS += -export-symbols-regex '^libfoo_.*' +endif +@end smallexample + +For more discussions about symbol visibility, rather than shared +library versioning, see the @code{visibility} module +(@pxref{visibility}). diff --git a/doc/visibility.texi b/doc/visibility.texi --- a/doc/visibility.texi +++ b/doc/visibility.texi @@ -1,3 +1,6 @@ +@node visibility +@section visibility + @c Documentation of gnulib module 'visibility'. @c Copyright (C) 2005-2006, 2009 Free Software Foundation, Inc. diff --git a/m4/ld-version-script.m4 b/m4/ld-version-script.m4 new file mode 100644 --- /dev/null +++ b/m4/ld-version-script.m4 @@ -0,0 +1,39 @@ +# ld-version-script.m4 serial 1 +dnl Copyright (C) 2008, 2009 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 From Simon Josefsson + +# gl_LD_VERSION_SCRIPT +# -------------------- +# Check if LD supports linker scripts, and define automake conditional +# HAVE_LD_VERSION_SCRIPT if so. +AC_DEFUN([gl_LD_VERSION_SCRIPT], +[ + AC_ARG_ENABLE([ld-version-script], + AS_HELP_STRING([--enable-ld-version-script], + [enable linker version script (default is enabled when possible)]), + [have_ld_version_script=$enableval], []) + if test -z "$have_ld_version_script"; then + AC_MSG_CHECKING([if LD -Wl,--version-script works]) + save_LDFLAGS="$LDFLAGS" + LDFLAGS="$LDFLAGS -Wl,--version-script=conftest.map" + cat > conftest.map <