From 536a1d7d0a722383d45c70173f4a021eef3ad639 Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Tue, 24 Jul 2012 14:37:48 +0100 Subject: [PATCH] Add a test case that checks there are no bogus entries in .syms During refactoring of code, it has proved common to forget to remove old symbols from the .syms file. While the Win32 linker will complain about this, the Linux ELF linker does not. The new test case validates that every symbol listed in the .syms file actually exists in the built ELF libraries. Signed-off-by: Daniel P. Berrange --- src/Makefile.am | 42 +++++++++++++++++++++++++++++++++- src/check-symfile.pl | 54 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+), 1 deletion(-) create mode 100755 src/check-symfile.pl diff --git a/src/Makefile.am b/src/Makefile.am index 93fcf3bc8d..13641cea47 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -306,6 +306,46 @@ PDWTAGS = \ echo 'WARNING: install the dwarves package to get pdwtags' >&2; \ fi +ALL_ELF_LIBS = $(builddir)/.libs/libvirt.so +if WITH_DRIVER_MODULES +if WITH_QEMU +ALL_ELF_LIBS += $(builddir)/.libs/libvirt_driver_qemu.so +endif +if WITH_LXC +ALL_ELF_LIBS += $(builddir)/.libs/libvirt_driver_lxc.so +endif +if WITH_UML +ALL_ELF_LIBS += $(builddir)/.libs/libvirt_driver_uml.so +endif +if WITH_XEN +ALL_ELF_LIBS += $(builddir)/.libs/libvirt_driver_xen.so +endif +if WITH_LIBXL +ALL_ELF_LIBS += $(builddir)/.libs/libvirt_driver_libxl.so +endif +if WITH_NETCF +ALL_ELF_LIBS += $(builddir)/.libs/libvirt_driver_interface.so +endif +if WITH_NETWORK +ALL_ELF_LIBS += $(builddir)/.libs/libvirt_driver_network.so +endif +if WITH_NODE_DEVICES +ALL_ELF_LIBS += $(builddir)/.libs/libvirt_driver_nodedev.so +endif +if WITH_NWFILTER +ALL_ELF_LIBS += $(builddir)/.libs/libvirt_driver_nwfilter.so +endif +if WITH_SECRETS +ALL_ELF_LIBS += $(builddir)/.libs/libvirt_driver_secret.so +endif +if WITH_STORAGE +ALL_ELF_LIBS += $(builddir)/.libs/libvirt_driver_storage.so +endif +endif + +check-symfile: libvirt.syms $(ALL_ELF_LIBS:%.so=%.la) + $(AM_V_GEN)$(PERL) $(srcdir)/check-symfile.pl libvirt.syms $(ALL_ELF_LIBS) + PROTOCOL_STRUCTS = \ $(srcdir)/remote_protocol-structs \ $(srcdir)/qemu_protocol-structs \ @@ -328,7 +368,7 @@ else !WITH_REMOTE check-protocol: endif EXTRA_DIST += $(PROTOCOL_STRUCTS) -check-local: check-protocol +check-local: check-protocol check-symfile .PHONY: check-protocol $(PROTOCOL_STRUCTS:structs=struct) # Mock driver, covering domains, storage, networks, etc diff --git a/src/check-symfile.pl b/src/check-symfile.pl new file mode 100755 index 0000000000..19ffec5587 --- /dev/null +++ b/src/check-symfile.pl @@ -0,0 +1,54 @@ +#!/usr/bin/perl + +die "syntax: $0 SYMFILE ELFLIB(S)" unless int(@ARGV) >= 2; + +my $symfile = shift @ARGV; +my @elflibs = @ARGV; + +my @wantsyms; +my %gotsyms; + +# Skip on non-linux +if ($^O ne "linux") { + return 77; # Automake's skip code +} + +open SYMFILE, $symfile or die "cannot read $symfile: $!"; + +while () { + next if /{/; + next if /}/; + next if /global:/; + next if /local:/; + next if /^\s*$/; + next if /^\s*#/; + next if /\*/; + + die "malformed line $_" unless /^\s*(\S+);$/; + + push @wantsyms, $1; +} +close SYMFILE; + +foreach my $elflib (@elflibs) { + open NM, "-|", "nm", $elflib or die "cannot run 'nm $elflib': $!"; + + while () { + next unless /^\S+\s(?:T|D)\s(\S+)\s*$/; + + $gotsyms{$1} = 1; + } + + close NM; +} + +my $ret = 0; + +foreach my $sym (@wantsyms) { + next if exists $gotsyms{$sym}; + + print STDERR "Expected symbol $sym is not in ELF library\n"; + $ret = 1; +} + +exit($ret);