On Mon, Nov 24, 2014 at 3:23 PM, Niels Möller <[email protected]> wrote:
>> The attached patch will add symbol versioning in nettle. That would
>> mean that software linked against nettle 3.x will be able to
>> interoperate with libraries that are linked on a previous version of
>> nettle (and vice versa).
> Thanks. I take it that solves the soname-related problem you reported
> yesterday? (I hope to be able to respond properly later today).

The yesterday's problem is solved in git where you have bumped the hogweed's
major version number. The problem it is solved by that patch is to software that
due to dependencies is linked to both old and new nettle library versions.

> I think it would be good with some comments in the linker script
> libnettle.map, explaining when and how to update it. E.g., the "3" in
> "NETTLE_3", when should that be updated? Should it always follow the
> soname? If so, maybe we should have a libnettle.map.in and let configure
> substitute the major number.

Done in the current patch. That's the rule I follow.

> How should we handle incompatible changes to internal, undocumented
> functions?

With the version script, nothing that is not prefixed with nettle_ or
_nettle_ is exported.
If you need to export more than that they should be listed in the
version script, possibly
with a different name (e.g, INTERNALS).

> Then I usually bump the minor number only, but not the soname?

In gnutls I change the soname only when API functions are removed, or
API functions are changed.

> Maybe it's impossible or unlikely to get two versions with the
> same soname linked into the same running program, in which case symbol
> versions don't need any finer resolution than the soname?

At least with gnutls in Debian it was actually occurring. There were
libraries linked to gnutls 2.12 and applications to gnutls 3.x.

regards,
Nikos
From 3849dcf767b30195089658ee7189ed13f404093b Mon Sep 17 00:00:00 2001
From: Nikos Mavrogiannopoulos <[email protected]>
Date: Mon, 24 Nov 2014 14:02:25 +0100
Subject: [PATCH] Added symbol versioning

Signed-off-by: Nikos Mavrogiannopoulos <[email protected]>
---
 .gitignore       |  1 +
 Makefile.in      |  4 ++--
 aclocal.m4       | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 configure.ac     |  4 +++-
 libnettle.map    | 12 ++++++++++++
 libnettle.map.in | 17 +++++++++++++++++
 6 files changed, 92 insertions(+), 3 deletions(-)
 create mode 100644 libnettle.map
 create mode 100644 libnettle.map.in

diff --git a/.gitignore b/.gitignore
index 2b16f4c..d54c65e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -67,3 +67,4 @@ core
 /nettle.tps
 /nettle.vr
 /nettle.vrs
+*.po
diff --git a/Makefile.in b/Makefile.in
index 10a58b0..d23794d 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -244,7 +244,7 @@ libhogweed.a: $(hogweed_OBJS)
 
 # Rules building shared libraries.
 $(LIBNETTLE_FORLINK): $(nettle_OBJS)
-	$(LIBNETTLE_LINK) $(nettle_OBJS) -o $@ $(LIBNETTLE_LIBS)
+	$(LIBNETTLE_LINK) $(nettle_OBJS) @EXTRA_LINKER_FLAGS@ -o $@ $(LIBNETTLE_LIBS)
 	-mkdir .lib 2>/dev/null
 	(cd .lib \
           && rm -f $(LIBNETTLE_FORLINK) \
@@ -255,7 +255,7 @@ $(LIBNETTLE_FORLINK): $(nettle_OBJS)
 	echo nettle > libnettle.stamp
 
 $(LIBHOGWEED_FORLINK): $(hogweed_OBJS) $(LIBNETTLE_FORLINK)
-	$(LIBHOGWEED_LINK) $(hogweed_OBJS) -o $@ $(LIBHOGWEED_LIBS)
+	$(LIBHOGWEED_LINK) $(hogweed_OBJS) @EXTRA_LINKER_FLAGS@ -o $@ $(LIBHOGWEED_LIBS)
 	-mkdir .lib 2>/dev/null
 	(cd .lib \
           && rm -f $(LIBHOGWEED_FORLINK) \
diff --git a/aclocal.m4 b/aclocal.m4
index 36daec6..4ac3ba5 100644
--- a/aclocal.m4
+++ b/aclocal.m4
@@ -1211,3 +1211,60 @@ ac_cv_type_int_fast32_t="$ac_cv_type_int_fast32_t"
 ac_cv_type_intmax_t="$ac_cv_type_intmax_t"
 ])
 ])
+
+# ld-version-script.m4 serial 3
+dnl Copyright (C) 2008-2014 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
+
+# FIXME: The test below returns a false positive for mingw
+# cross-compiles, 'local:' statements does not reduce number of
+# exported symbols in a DLL.  Use --disable-ld-version-script to work
+# around the problem.
+
+# gl_LD_VERSION_SCRIPT
+# --------------------
+# Check if LD supports linker scripts, and define automake conditional
+# HAVE_LD_VERSION_SCRIPT if so.
+AC_DEFUN([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
+foo
+EOF
+    AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])],
+                   [accepts_syntax_errors=yes], [accepts_syntax_errors=no])
+    if test "$accepts_syntax_errors" = no; then
+      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])
+    else
+      have_ld_version_script=no
+    fi
+    rm -f conftest.map
+    LDFLAGS="$save_LDFLAGS"
+    AC_MSG_RESULT($have_ld_version_script)
+  fi
+  if test "$have_ld_version_script" = "yes";then
+	EXTRA_LINKER_FLAGS="-Wl,--version-script=\$(srcdir)/libnettle.map"
+	AC_SUBST(EXTRA_LINKER_FLAGS)
+  fi
+])
diff --git a/configure.ac b/configure.ac
index bb33962..9465c34 100644
--- a/configure.ac
+++ b/configure.ac
@@ -114,6 +114,8 @@ AC_TRY_COMPILE([],[return 0;],[IF_CXX=''], [IF_CXX='#'])
 AC_SUBST([IF_CXX])
 AC_LANG_POP
 
+LD_VERSION_SCRIPT
+
 AC_PROG_MAKE_SET
 AC_PROG_RANLIB
 AC_CHECK_TOOL(NM, nm, strings)
@@ -843,7 +845,7 @@ fi
 
 AC_CONFIG_FILES([config.make config.m4 Makefile bignum.h])
 AC_CONFIG_FILES([tools/Makefile testsuite/Makefile examples/Makefile])
-AC_CONFIG_FILES([nettle.pc hogweed.pc])
+AC_CONFIG_FILES([nettle.pc hogweed.pc libnettle.map])
 
 AC_OUTPUT
 
diff --git a/libnettle.map b/libnettle.map
new file mode 100644
index 0000000..4598e6f
--- /dev/null
+++ b/libnettle.map
@@ -0,0 +1,12 @@
+# libnettle.map -- libnettle linker version script.           -*- ld-script -*-
+
+NETTLE_5
+{
+  global:
+    nettle_*;
+    _nettle_*;
+
+  local:
+    *;
+};
+
diff --git a/libnettle.map.in b/libnettle.map.in
new file mode 100644
index 0000000..02455bc
--- /dev/null
+++ b/libnettle.map.in
@@ -0,0 +1,17 @@
+# libnettle.map -- libnettle linker version script.           -*- ld-script -*-
+
+#
+# The symbol version must be updated on every nettle
+# library major number change. That is taken care by
+# auto-generating the file.
+
+NETTLE_@LIBNETTLE_MAJOR@
+{
+  global:
+    nettle_*;
+    _nettle_*;
+
+  local:
+    *;
+};
+
-- 
1.9.3

_______________________________________________
nettle-bugs mailing list
[email protected]
http://lists.lysator.liu.se/mailman/listinfo/nettle-bugs

Reply via email to