Skip to content
This repository has been archived by the owner on Jul 30, 2021. It is now read-only.

Commit

Permalink
Check the ABI of VMODs.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Tollef Fog Heen committed Aug 19, 2011
1 parent 6ba82cb commit dca3cfb
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -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
Expand Down
50 changes: 49 additions & 1 deletion include/Makefile.am
Expand Up @@ -34,13 +34,15 @@ nobase_noinst_HEADERS = \
vsb.h \
vcl.h \
vcl_returns.h \
vcs_version.h \
vct.h \
vend.h \
vev.h \
vin.h \
vlu.h \
vbm.h \
vmb.h \
vmod_abi.h \
vre.h \
vrt.h \
vrt_obj.h \
Expand All @@ -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
23 changes: 0 additions & 23 deletions lib/libvarnish/Makefile.am
Expand Up @@ -14,7 +14,6 @@ libvarnish_la_SOURCES = \
cli_serve.c \
flopen.c \
num.c \
vcs_version.h \
time.c \
tcp.c \
vct.c \
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/libvarnishapi/Makefile.am
Expand Up @@ -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 \
Expand Down
12 changes: 12 additions & 0 deletions lib/libvcl/vcc_vmod.c
Expand Up @@ -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)
Expand All @@ -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;
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions lib/libvmod_std/vmod.py
Expand Up @@ -281,6 +281,7 @@ def file_header(fo):

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");
Expand All @@ -307,5 +308,6 @@ def file_header(fo):

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")

0 comments on commit dca3cfb

Please sign in to comment.