]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Add a test case that checks there are no bogus entries in .syms
authorDaniel P. Berrange <berrange@redhat.com>
Tue, 24 Jul 2012 13:37:48 +0000 (14:37 +0100)
committerDaniel P. Berrange <berrange@redhat.com>
Fri, 27 Jul 2012 09:54:38 +0000 (10:54 +0100)
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
src/check-symfile.pl [new file with mode: 0755]

index 93fcf3bc8d209cec5e160016d081b1a7ea53bb90..13641cea47e04a58a63ee0c800706031d02faba7 100644 (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
diff --git a/src/check-symfile.pl b/src/check-symfile.pl
new file mode 100755 (executable)
index 0000000..19ffec5
--- /dev/null
@@ -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);