Browse files

Implement symbol versioning

Restrict visibility of symbols to the symbols we actually want to be
public.
  • Loading branch information...
1 parent bbb1d1a commit 57ffb888eb1bbec268df189d42926b7b5da26a5d Tollef Fog Heen committed Jun 6, 2011
Showing with 126 additions and 1 deletion.
  1. +4 −0 configure.ac
  2. +8 −1 lib/libvarnishapi/Makefile.am
  3. +70 −0 lib/libvarnishapi/libvarnishapi.map
  4. +44 −0 m4/ld-version-script.m4
View
4 configure.ac
@@ -441,6 +441,10 @@ AC_SUBST(VARNISH_STATE_DIR)
# Default configuration directory.
varnishconfdir='${sysconfdir}/varnish'
AC_SUBST(varnishconfdir)
+
+# Check for linker script support
+gl_LD_VERSION_SCRIPT
+
# Now that we're done using the compiler to look for functions and
# libraries, set CFLAGS to what we want them to be for our own code
View
9 lib/libvarnishapi/Makefile.am
@@ -24,9 +24,16 @@ libvarnishapi_la_SOURCES = \
vsm.c \
vsl_arg.c \
vsl.c \
- vsc.c
+ vsc.c \
+ libvarnishapi.map
libvarnishapi_la_CFLAGS = \
-DVARNISH_STATE_DIR='"${VARNISH_STATE_DIR}"'
libvarnishapi_la_LIBADD = @PCRE_LIBS@
+
+if HAVE_LD_VERSION_SCRIPT
+libvarnishapi_la_LDFLAGS += -Wl,--version-script=$(srcdir)/libvarnishapi.map
+else
+libvarnishapi_la_LDFLAGS += -export-symbols-regex '^V'
+endif
View
70 lib/libvarnishapi/libvarnishapi.map
@@ -0,0 +1,70 @@
+/*-
+ * Copyright (c) 2011 Varnish Software AS
+ * All rights reserved.
+ *
+ * Author: Tollef Fog Heen <tfheen@varnish-software.com>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+LIBVARNISHAPI_1.0 {
+ global:
+ # Functions
+ VSM_New;
+ VSM_Diag;
+ VSM_n_Arg;
+ VSM_Name;
+ VSM_Delete;
+ VSM_Open;
+ VSM_ReOpen;
+ VSM_Seq;
+ VSM_Head;
+ VSM_Find_Chunk;
+ VSM_Close;
+ VSM_iter0;
+ VSM_intern;
+
+ VSC_Setup;
+ VSC_Arg;
+ VSC_Open;
+ VSC_Main;
+ VSC_Iter;
+
+ VSL_Setup;
+ VSL_Open;
+ VSL_Arg;
+ VSL_H_Print;
+ VSL_Select;
+ VSL_NonBlocking;
+ VSL_Dispatch;
+ VSL_NextLog;
+ VSL_Matched;
+
+ VCLI_WriteResult;
+ VCLI_ReadResult;
+ VCLI_AuthResponse;
+
+ # Variables
+ VSL_tags;
+ local:
+ *;
+};
View
44 m4/ld-version-script.m4
@@ -0,0 +1,44 @@
+# 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
+
+# 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")
+])

0 comments on commit 57ffb88

Please sign in to comment.