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 <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrange 2012-07-24 14:37:48 +01:00
parent 25b0988974
commit 536a1d7d0a
2 changed files with 95 additions and 1 deletions

View File

@ -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

54
src/check-symfile.pl Executable file
View File

@ -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);