diff options
-rw-r--r-- | configure.ac | 7 | ||||
-rw-r--r-- | osinfo/Makefile.am | 16 | ||||
-rwxr-xr-x | osinfo/check-symfile.pl | 70 | ||||
-rwxr-xr-x | osinfo/check-symsorting.pl | 100 |
4 files changed, 193 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac index 62c9a6f..aed1029 100644 --- a/configure.ac +++ b/configure.ac @@ -92,6 +92,13 @@ AC_SUBST([NO_UNDEFINED_FLAGS]) AC_SUBST([VERSION_SCRIPT_FLAGS]) AM_CONDITIONAL([USE_VERSION_DEFS], [test "$USE_VERSION_DEFS" = "1"]) +with_linux=no +case $host in + *-*-linux*) with_linux=yes ;; +esac +AM_CONDITIONAL([WITH_LINUX], [test "$with_linux" = "yes"]) + + AC_ARG_ENABLE([introspection], AS_HELP_STRING([--enable-introspection], [enable GObject introspection]), [], [enable_introspection=check]) diff --git a/osinfo/Makefile.am b/osinfo/Makefile.am index 89eaf9d..853f7cf 100644 --- a/osinfo/Makefile.am +++ b/osinfo/Makefile.am @@ -151,6 +151,22 @@ osinfo_enum_types.h: $(OSINFO_HEADER_FILES) osinfo_enum_types.h.template osinfo_enum_types.c: $(OSINFO_HEADER_FILES) osinfo_enum_types.c.template osinfo_enum_types.h $(AM_V_GEN) ( $(GLIB_MKENUMS) --template $(srcdir)/osinfo_enum_types.c.template $(libosinfo_1_0_include_HEADERS:%=$(srcdir)/%) ) > $(srcdir)/osinfo_enum_types.c +# .libs/libosinfo.so is built by libtool as a side-effect of the Makefile +# rule for libosinfo.la. However, checking symbols relies on Linux ELF layout +if WITH_LINUX +check-symfile: libosinfo.syms libosinfo-1.0.la + $(AM_V_GEN)$(PERL) $(srcdir)/check-symfile.pl libosinfo.syms \ + .libs/libosinfo-1.0.so +else ! WITH_LINUX +check-symfile: +endif ! WITH_LINUX +check-symsorting: + $(AM_V_GEN)$(PERL) $(srcdir)/check-symsorting.pl \ + $(srcdir) libosinfo.syms +EXTRA_DIST += check-symfile.pl check-symsorting.pl + +check-local: check-symfile check-symsorting + if WITH_GOBJECT_INTROSPECTION Libosinfo-1.0.gir: libosinfo-1.0.la $(G_IR_SCANNER) Makefile.am diff --git a/osinfo/check-symfile.pl b/osinfo/check-symfile.pl new file mode 100755 index 0000000..d59a213 --- /dev/null +++ b/osinfo/check-symfile.pl @@ -0,0 +1,70 @@ +#!/usr/bin/perl + +# Copyright (C) 2012-2013 Red Hat, Inc. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library. If not, see +# <http://www.gnu.org/licenses/>. + +die "syntax: $0 SYMFILE ELFLIB(S)" unless int(@ARGV) >= 2; + +my $symfile = shift @ARGV; +my @elflibs = @ARGV; + +my %wantsyms; +my %gotsyms; + +my $ret = 0; + +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+);$/; + + if (exists $wantsyms{$1}) { + print STDERR "Symbol $1 is listed twice\n"; + $ret = 1; + } else { + $wantsyms{$1} = 1; + } +} +close SYMFILE; + +foreach my $elflib (@elflibs) { + open NM, "-|", "nm", $elflib or die "cannot run 'nm $elflib': $!"; + + while (<NM>) { + next unless /^\S+\s(?:[TBD])\s(\S+)\s*$/; + + $gotsyms{$1} = 1; + } + + close NM; +} + +foreach my $sym (keys(%wantsyms)) { + next if exists $gotsyms{$sym}; + + print STDERR "Expected symbol $sym is not in ELF library\n"; + $ret = 1; +} + +exit($ret); diff --git a/osinfo/check-symsorting.pl b/osinfo/check-symsorting.pl new file mode 100755 index 0000000..470247c --- /dev/null +++ b/osinfo/check-symsorting.pl @@ -0,0 +1,100 @@ +#!/usr/bin/perl + +# Copyright (C) 2012-2013 Red Hat, Inc. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library. If not, see +# <http://www.gnu.org/licenses/>. + +use strict; +use warnings; + +die "syntax: $0 SRCDIR SYMFILE..." unless int(@ARGV) >= 2; + +my $ret = 0; +my $srcdir = shift; +my $incomment = 0; +my $name; +foreach my $symfile (@ARGV) { + open SYMFILE, $symfile or die "cannot read $symfile: $!"; + + my $line = 0; + my @group; + + while (<SYMFILE>) { + chomp; + + if ($incomment) { + if (m,\*/,) { + $incomment = 0; + } else { + # skip + } + } else { + if (m,/\*,) { + $incomment = 1; + } elsif (/^(.*)\s*{\s*$/) { + @group = (); + $line = $.; + $name = $1; + } elsif (/^\s*}(.*);$/) { + &check_sorting(\@group, $symfile, $line, $name); + } elsif (/^\s*(global|local):/) { + # skip + } elsif (/^\s*\*;\s*$/) { + # skip + } elsif (/^\s*$/) { + # skip + } else { + $_ =~ s/;//; + push @group, $_; + } + } + } + + close SYMFILE; +} + +sub check_sorting { + my $group = shift; + my $symfile = shift; + my $line = shift; + my $name = shift; + + my @group = @{$group}; + my @sorted = sort { lc $a cmp lc $b } @group; + my $sorted = 1; + my $first; + my $last; + + # Check that symbols within a group are in order + for (my $i = 0 ; $i <= $#sorted ; $i++) { + if ($sorted[$i] ne $group[$i]) { + $first = $i unless defined $first; + $last = $i; + $sorted = 0; + } + } + if (!$sorted) { + @group = splice @group, $first, ($last-$first+1); + @sorted = splice @sorted, $first, ($last-$first+1); + print "Symbol block $name at $symfile:$line: symbols not sorted\n"; + print map { " " . $_ . "\n" } @group; + print "Correct ordering\n"; + print map { " " . $_ . "\n" } @sorted; + print "\n"; + $ret = 1; + } +} + +exit $ret; |