Blame build-aux/check-symfile.pl

Packit a07778
#!/usr/bin/env perl
Packit a07778
Packit a07778
# Copyright (C) 2012-2013 Red Hat, Inc.
Packit a07778
#
Packit a07778
# This library is free software; you can redistribute it and/or
Packit a07778
# modify it under the terms of the GNU Lesser General Public
Packit a07778
# License as published by the Free Software Foundation; either
Packit a07778
# version 2.1 of the License, or (at your option) any later version.
Packit a07778
#
Packit a07778
# This library is distributed in the hope that it will be useful,
Packit a07778
# but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit a07778
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit a07778
# Lesser General Public License for more details.
Packit a07778
#
Packit a07778
# You should have received a copy of the GNU Lesser General Public
Packit a07778
# License along with this library.  If not, see
Packit a07778
# <http://www.gnu.org/licenses/>.
Packit a07778
Packit a07778
die "syntax: $0 SYMFILE ELFLIB(S)" unless int(@ARGV) >= 2;
Packit a07778
Packit a07778
my $symfile = shift @ARGV;
Packit a07778
my @elflibs = @ARGV;
Packit a07778
Packit a07778
my %wantsyms;
Packit a07778
my %gotsyms;
Packit a07778
Packit a07778
my $ret = 0;
Packit a07778
Packit a07778
open SYMFILE, $symfile or die "cannot read $symfile: $!";
Packit a07778
Packit a07778
while (<SYMFILE>) {
Packit a07778
    next if /{/;
Packit a07778
    next if /}/;
Packit a07778
    next if /global:/;
Packit a07778
    next if /local:/;
Packit a07778
    next if /^\s*$/;
Packit a07778
    next if /^\s*#/;
Packit a07778
    next if /\*/;
Packit a07778
Packit a07778
    die "malformed line $_" unless /^\s*(\S+);$/;
Packit a07778
Packit a07778
    if (exists $wantsyms{$1}) {
Packit a07778
        print STDERR "Symbol $1 is listed twice\n";
Packit a07778
        $ret = 1;
Packit a07778
    } else {
Packit a07778
        $wantsyms{$1} = 1;
Packit a07778
    }
Packit a07778
}
Packit a07778
close SYMFILE;
Packit a07778
Packit a07778
foreach my $elflib (@elflibs) {
Packit a07778
    open NM, "-|", "nm", $elflib or die "cannot run 'nm $elflib': $!";
Packit a07778
Packit a07778
    while (<NM>) {
Packit a07778
        next unless /^\S+\s(?:[TBD])\s(\S+)\s*$/;
Packit a07778
Packit a07778
        $gotsyms{$1} = 1;
Packit a07778
    }
Packit a07778
Packit a07778
    close NM;
Packit a07778
}
Packit a07778
Packit a07778
foreach my $sym (keys(%wantsyms)) {
Packit a07778
    next if exists $gotsyms{$sym};
Packit a07778
Packit a07778
    print STDERR "Expected symbol $sym is not in ELF library\n";
Packit a07778
    $ret = 1;
Packit a07778
}
Packit a07778
Packit a07778
exit($ret);