[PATCH] Symbol versioning prototype. Not for merging.

Nicholas Miell nmiell at gmail.com
Sat Nov 6 20:46:10 PDT 2010


---
 build/ld-version-script.m4 |   44 ++++++++++++++++++++++++++++++++++++++++++++
 configure.ac               |    1 +
 src/Makefile.am            |    5 +++++
 src/cairo-sym-versions.map |   10 ++++++++++
 src/cairo-version.c        |    7 +++++++
 src/cairo.h                |    3 +++
 src/cairoint.h             |    1 +
 src/check-link.c           |    2 +-
 8 files changed, 72 insertions(+), 1 deletions(-)
 create mode 100644 build/ld-version-script.m4
 create mode 100644 src/cairo-sym-versions.map

diff --git a/build/ld-version-script.m4 b/build/ld-version-script.m4
new file mode 100644
index 0000000..8fd8c89
--- /dev/null
+++ b/build/ld-version-script.m4
@@ -0,0 +1,44 @@
+# ld-version-script.m4 serial 2
+dnl Copyright (C) 2008, 2009, 2010 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([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/configure.ac b/configure.ac
index 1238f5e..8913584 100644
--- a/configure.ac
+++ b/configure.ac
@@ -14,6 +14,7 @@ m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
 AC_LIBTOOL_WIN32_DLL dnl Must be called before AC_PROG_LIBTOOL
 AC_PROG_LIBTOOL dnl ([1.4]) Don't remove!
 GTK_DOC_CHECK([1.6])
+gl_LD_VERSION_SCRIPT
 
 AC_SYS_LARGEFILE
 
diff --git a/src/Makefile.am b/src/Makefile.am
index 5edf706..cf6d7da 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -47,6 +47,11 @@ libcairo_la_SOURCES = \
 	$(enabled_cairo_sources) \
 	$(NULL)
 libcairo_la_LDFLAGS = $(AM_LDFLAGS) -version-info $(CAIRO_LIBTOOL_VERSION_INFO) -no-undefined $(export_symbols)
+
+if HAVE_LD_VERSION_SCRIPT
+libcairo_la_LDFLAGS += -Wl,--version-script=cairo-sym-versions.map
+endif
+
 libcairo_la_LIBADD = $(CAIRO_LIBS) \
 	$(cairo_cxx_lib)
 libcairo_la_DEPENDENCIES = $(cairo_def_dependency) $(cairo_cxx_lib)
diff --git a/src/cairo-sym-versions.map b/src/cairo-sym-versions.map
new file mode 100644
index 0000000..21f7a0b
--- /dev/null
+++ b/src/cairo-sym-versions.map
@@ -0,0 +1,10 @@
+CAIRO_1.12 {
+	global: cairo_test_symbol;
+};
+
+# CAIRO_1.14 {
+#	global: new symbols go here;
+# } CAIRO_1.12;
+
+# CAIRO_1.16 {
+# } CAIRO_1.14;
diff --git a/src/cairo-version.c b/src/cairo-version.c
index 2f53e11..1f05553 100644
--- a/src/cairo-version.c
+++ b/src/cairo-version.c
@@ -242,3 +242,10 @@ cairo_version_string (void)
     return CAIRO_VERSION_STRING;
 }
 slim_hidden_def (cairo_version_string);
+
+const char*
+cairo_test_symbol (void)
+{
+    return CAIRO_VERSION_STRING;
+}
+slim_hidden_def (cairo_test_symbol);
diff --git a/src/cairo.h b/src/cairo.h
index 136c5db..d4f3540 100644
--- a/src/cairo.h
+++ b/src/cairo.h
@@ -88,6 +88,9 @@ cairo_version (void);
 cairo_public const char*
 cairo_version_string (void);
 
+cairo_public const char*
+cairo_test_symbol (void);
+
 /**
  * cairo_bool_t:
  *
diff --git a/src/cairoint.h b/src/cairoint.h
index 5836101..49a7b1d 100644
--- a/src/cairoint.h
+++ b/src/cairoint.h
@@ -2500,6 +2500,7 @@ slim_hidden_proto (cairo_user_font_face_set_unicode_to_glyph_func);
 slim_hidden_proto (cairo_user_to_device);
 slim_hidden_proto (cairo_user_to_device_distance);
 slim_hidden_proto (cairo_version_string);
+slim_hidden_proto (cairo_test_symbol);
 slim_hidden_proto (cairo_region_create);
 slim_hidden_proto (cairo_region_create_rectangle);
 slim_hidden_proto (cairo_region_create_rectangles);
diff --git a/src/check-link.c b/src/check-link.c
index 66ca1b2..d25d72c 100644
--- a/src/check-link.c
+++ b/src/check-link.c
@@ -17,7 +17,7 @@ main (void)
   } else {
     fprintf (stderr,
 	     "Error: linked to cairo version %s instead of %s\n",
-	     cairo_version_string (),
+	     cairo_test_symbol (),
 	     CAIRO_VERSION_STRING);
     return 1;
   }
-- 
1.7.3.2



--------------040400000909030300060700--


More information about the cairo mailing list