Blame build-aux/check-symfile.pl

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