[experimental-ims] dca3cfb Check the ABI of VMODs.

Geoff Simmons geoff at varnish-cache.org
Wed Aug 31 16:03:02 CEST 2011


commit dca3cfb36c63646c300c824e26f2582abbcff924
Author: Tollef Fog Heen <tfheen at varnish-software.com>
Date:   Fri Aug 19 11:09:31 2011 +0200

    Check the ABI of VMODs.
    
    The ABI we give vmods consist of the Varnish version number and the
    git commit ID meaning we can break ABI at will.
    
    Output a warning if we can't determine git commit ID

diff --git a/.gitignore b/.gitignore
index 095ca12..6cf0950 100644
--- a/.gitignore
+++ b/.gitignore
@@ -46,7 +46,7 @@ TAGS
 /include/vcl_returns.h
 /include/vrt_obj.h
 /include/vrt_stv_var.h
-/lib/libvarnish/vcs_version.h
+/include/vcs_version.h
 /lib/libvcl/vcc_fixed_token.c
 /lib/libvcl/vcc_obj.c
 /lib/libvcl/vcc_token_defs.h
diff --git a/include/Makefile.am b/include/Makefile.am
index 10ebd81..6e07532 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -34,6 +34,7 @@ nobase_noinst_HEADERS = \
 	vsb.h \
 	vcl.h \
 	vcl_returns.h \
+	vcs_version.h \
 	vct.h \
 	vend.h \
 	vev.h \
@@ -41,6 +42,7 @@ nobase_noinst_HEADERS = \
 	vlu.h \
 	vbm.h \
 	vmb.h \
+	vmod_abi.h \
 	vre.h \
 	vrt.h \
 	vrt_obj.h \
@@ -50,6 +52,52 @@ nobase_noinst_HEADERS = \
 vrt_stv_var.h vcl_returns.h vcl.h vrt_obj.h: $(top_srcdir)/lib/libvcl/generate.py $(top_srcdir)/include/vrt.h
 	@PYTHON@ $(top_srcdir)/lib/libvcl/generate.py $(top_srcdir) $(top_builddir)
 
+BUILT_SOURCES = vcs_version.h vmod_abi.h
+MAINTAINERCLEANFILES = vcs_version.h 
+vcs_version.h: FORCE
+	@if [ -d "$(top_srcdir)/.git" ]; then \
+		V="$$(git show -s --pretty=format:%h)" \
+		H="$$(head -n 1 vcs_version.h 2>/dev/null || true)"; \
+		if [ "/* $$V */" != "$$H" ]; then \
+		( \
+		  echo "/* $$V */" ;\
+		  echo '/*' ;\
+		  echo ' * NB:  This file is machine generated, DO NOT EDIT!' ;\
+		  echo ' *' ;\
+		  echo ' * Run make to regenerate' ;\
+		  echo ' *'  ;\
+		  echo ' */' ;\
+		  echo '' ;\
+		  echo "#define VCS_Version \"$$V\"" \
+		) > vcs_version.h ; \
+		fi \
+	else \
+		if [ ! -f vcs_version.h ]; then \
+		( \
+		  echo "/* NOGIT */" ; \
+		  echo '/* No git commit ID available, see include/Makefile.am for explanation */' ; \
+		  echo '#define VCS_Version "NOGIT"' \
+		) >  vcs_version.h ; \
+		fi \
+	fi
+FORCE:
+
+# If vcs_version contains NOGIT, Varnish has not been built from a
+# tarball made with make dist, nor from a git checkout, so there's no
+# way for us to give strong guarantees about what version you're
+# actually running.
+#
+# The way to fix this is to either build Varnish from a tarball made
+# with `make dist` or a git checkout.
+
+vmod_abi.h: vcs_version.h
+	@GITID=$$(sed 's/[^0-9a-f]//g;q' vcs_version.h) ; \
+	if [ -z "$$GITID" ]; then \
+		echo "warning: weak VMOD ABI checking, see include/Makefile.am" ; \
+	fi ; \
+	echo "#define VMOD_ABI_Version \"@PACKAGE_STRING@ $$GITID\"" > vmod_abi.h
+
 CLEANFILES = vcl_returns.h \
 	vcl.h \
-	vrt_obj.h
+	vrt_obj.h \
+	vmod_abi.h
diff --git a/lib/libvarnish/Makefile.am b/lib/libvarnish/Makefile.am
index a5ebc5c..21a9d98 100644
--- a/lib/libvarnish/Makefile.am
+++ b/lib/libvarnish/Makefile.am
@@ -14,7 +14,6 @@ libvarnish_la_SOURCES = \
 	cli_serve.c \
 	flopen.c \
 	num.c \
-	vcs_version.h \
 	time.c \
 	tcp.c \
 	vct.c \
@@ -33,28 +32,6 @@ libvarnish_la_SOURCES = \
 libvarnish_la_CFLAGS = -DVARNISH_STATE_DIR='"${VARNISH_STATE_DIR}"'
 libvarnish_la_LIBADD = ${RT_LIBS} ${NET_LIBS} ${LIBM} @PCRE_LIBS@
 
-BUILT_SOURCES = vcs_version.h
-MAINTAINERCLEANFILES = vcs_version.h
-vcs_version.h: FORCE
-	if [ -d "$(top_srcdir)/.git" ]; then \
-		V="$$(git show -s --pretty=format:%h)" \
-		H="$$(head -n 1 vcs_version.h 2>/dev/null || true)"; \
-		if [ "/* $$V */" != "$$H" ]; then \
-		( \
-		  echo "/* $$V */" ;\
-		  echo '/*' ;\
-		  echo ' * NB:  This file is machine generated, DO NOT EDIT!' ;\
-		  echo ' *' ;\
-		  echo ' * Run make to regenerate' ;\
-		  echo ' *'  ;\
-		  echo ' */' ;\
-		  echo '' ;\
-		  echo "#define VCS_Version \"$$V\"" \
-		) > vcs_version.h ; \
-		fi \
-	fi
-FORCE:
-
 if ENABLE_TESTS
 TESTS = num_c_test
 
diff --git a/lib/libvarnishapi/Makefile.am b/lib/libvarnishapi/Makefile.am
index a646f76..f88d748 100644
--- a/lib/libvarnishapi/Makefile.am
+++ b/lib/libvarnishapi/Makefile.am
@@ -12,7 +12,7 @@ libvarnishapi_la_SOURCES = \
 	\
 	../libvarnish/assert.c \
 	../libvarnish/argv.c \
-	../libvarnish/vcs_version.h \
+	../../include/vcs_version.h \
 	../libvarnish/version.c \
 	../libvarnish/cli_common.c \
 	../libvarnish/cli_auth.c \
diff --git a/lib/libvcl/vcc_vmod.c b/lib/libvcl/vcc_vmod.c
index 077706c..35cc702 100644
--- a/lib/libvcl/vcc_vmod.c
+++ b/lib/libvcl/vcc_vmod.c
@@ -37,6 +37,7 @@
 #include "vcc_priv.h"
 #include "vcc_compile.h"
 #include "libvarnish.h"
+#include "vmod_abi.h"
 
 void
 vcc_ParseImport(struct vcc *tl)
@@ -46,6 +47,7 @@ vcc_ParseImport(struct vcc *tl)
 	struct token *mod, *t1;
 	const char *modname;
 	const char *proto;
+	const char *abi;
 	const char **spec;
 	struct symbol *sym;
 	const struct symbol *osym;
@@ -133,6 +135,16 @@ vcc_ParseImport(struct vcc *tl)
 		return;
 	}
 
+	abi = dlsym(hdl, "Vmod_Varnish_ABI");
+	if (abi == NULL || strcmp(abi, VMOD_ABI_Version) != 0) {
+		VSB_printf(tl->sb, "Could not load module %.*s\n\t%s\n",
+		    PF(mod), fn);
+		VSB_printf(tl->sb, "\tABI mismatch, expected <%s>, got <%s>\n",
+			   VMOD_ABI_Version, abi);
+		vcc_ErrWhere(tl, mod);
+		return;
+	}
+
 	proto = dlsym(hdl, "Vmod_Proto");
 	if (proto == NULL) {
 		VSB_printf(tl->sb, "Could not load module %.*s\n\t%s\n\t%s\n",
diff --git a/lib/libvmod_std/vmod.py b/lib/libvmod_std/vmod.py
index ee6a021..56bddf2 100755
--- a/lib/libvmod_std/vmod.py
+++ b/lib/libvmod_std/vmod.py
@@ -281,6 +281,7 @@ fh.write(plist)
 
 fc.write('#include "vrt.h"\n')
 fc.write('#include "vcc_if.h"\n')
+fc.write('#include "vmod_abi.h"\n')
 fc.write("\n");
 
 fc.write("\n");
@@ -307,5 +308,6 @@ fc.write("\n");
 
 fc.write('const char * const Vmod_Spec[] = {\n' + slist + '\t0\n};\n')
 
+fc.write('const char Vmod_Varnish_ABI[] = VMOD_ABI_Version;\n')
 fc.write("\n")
 



More information about the varnish-commit mailing list