Commit 615ab483 authored by Tollef Fog Heen's avatar Tollef Fog Heen

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
parent e6e34d24
......@@ -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
......
......@@ -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
......@@ -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
......
......@@ -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 \
......
......@@ -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",
......
......@@ -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")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment