[libvirt] [PATCH] Add a test case that checks there are no bogus entries in .syms

From: "Daniel P. Berrange" <berrange@redhat.com> 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 <berrange@redhat.com> --- 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 44da1fa..c6c4aff 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 0000000..19ffec5 --- /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 (<SYMFILE>) { + 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 (<NM>) { + 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); -- 1.7.10.4

On 07/24/2012 09:48 AM, Daniel P. Berrange wrote:
From: "Daniel P. Berrange" <berrange@redhat.com>
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.
And apparently it works - it found the following three unimplemented functions in a fresh checkout from master: GEN check-symfile Expected symbol virNetClientSetEOFNotify is not in ELF library Expected symbol virNWFilterGetIpAddrForIfname is not in ELF library Expected symbol virNWFilterDelIpAddrForIfname is not in ELF library make[2]: *** [check-symfile] Error 1 It would be even nicer if it 1) verified that each symbol was defined in the proper symfile for its library, and 2) was able to check even those libraries that weren't built for the given platform, but (1) isn't really practical, since we currently mix a lot of stuff together in libvirt_private.syms, and I can't think of a reasonable way to do (2). ACK (assuming that anything that causes it to fail is fixed in git first, of course).
participants (2)
-
Daniel P. Berrange
-
Laine Stump