Add new module ld-version-script. Fix doc for visibility.
authorSimon Josefsson <simon@josefsson.org>
Tue, 3 Mar 2009 11:00:59 +0000 (12:00 +0100)
committerSimon Josefsson <simon@josefsson.org>
Tue, 3 Mar 2009 11:00:59 +0000 (12:00 +0100)
ChangeLog
doc/gnulib.texi
doc/ld-version-script.texi [new file with mode: 0644]
doc/visibility.texi
m4/ld-version-script.m4 [new file with mode: 0644]
modules/ld-version-script [new file with mode: 0644]

index b3e2b3bb8bb478848f1e4070aedc81684e9f14be..796cd5e5074c12685369e3e2ee02ad91f1681c43 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2009-03-03  Simon Josefsson  <simon@josefsson.org>
+
+       * 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  <lutter@redhat.com>
 
        * lib/safe-alloc.h (__GNUC_PREREQ): New macro.
index d2a3a132fb870063f18d5d8271dccea524d4af2f..ceb0335cfc807cec838935e22da72fc388d26191 100644 (file)
@@ -5825,6 +5825,8 @@ This list of functions is sorted according to the header that declares them.
 * func::
 * warnings::
 * manywarnings::
+* visibility::
+* LD Version Scripts::
 @end menu
 
 @node alloca
@@ -5917,6 +5919,10 @@ generated automatically.
 
 @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 (file)
index 0000000..8582edf
--- /dev/null
@@ -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}).
index c6dcbb821d0706bb8121c4d0b9eed09e4ddbeb82..2fbcbf517d789c1112ee26faccba6d47af85a498 100644 (file)
@@ -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 (file)
index 0000000..e321347
--- /dev/null
@@ -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 <<EOF
+VERS_1 {
+       global: sym;
+};
+
+VERS_2 {
+        global: sym;
+} VERS_1;
+EOF
+    AC_LINK_IFELSE(AC_LANG_PROGRAM([], []),
+                   [have_ld_version_script=yes], [have_ld_version_script=no])
+    rm -f conftest.map
+    LDFLAGS="$save_LDFLAGS"
+    AC_MSG_RESULT($have_ld_version_script)
+  fi
+  AM_CONDITIONAL(HAVE_LD_VERSION_SCRIPT, test "$have_ld_version_script" = "yes")
+])
diff --git a/modules/ld-version-script b/modules/ld-version-script
new file mode 100644 (file)
index 0000000..6b0d990
--- /dev/null
@@ -0,0 +1,14 @@
+Description:
+Macros to test whether LD support --linker-script.
+
+Files:
+m4/ld-version-script.m4
+
+configure.ac:
+gl_LD_VERSION_SCRIPT
+
+License:
+unlimited
+
+Maintainer:
+Simon Josefsson