Blame src/util/export-check.pl

Packit fd8b60
#
Packit fd8b60
Packit fd8b60
# Copyright 2006 Massachusetts Institute of Technology.
Packit fd8b60
# All Rights Reserved.
Packit fd8b60
#
Packit fd8b60
# Export of this software from the United States of America may
Packit fd8b60
#   require a specific license from the United States Government.
Packit fd8b60
#   It is the responsibility of any person or organization contemplating
Packit fd8b60
#   export to obtain such a license before exporting.
Packit fd8b60
#
Packit fd8b60
# WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
Packit fd8b60
# distribute this software and its documentation for any purpose and
Packit fd8b60
# without fee is hereby granted, provided that the above copyright
Packit fd8b60
# notice appear in all copies and that both that copyright notice and
Packit fd8b60
# this permission notice appear in supporting documentation, and that
Packit fd8b60
# the name of M.I.T. not be used in advertising or publicity pertaining
Packit fd8b60
# to distribution of the software without specific, written prior
Packit fd8b60
# permission.  Furthermore if you modify this software you must label
Packit fd8b60
# your software as modified software and not distribute it in such a
Packit fd8b60
# fashion that it might be confused with the original M.I.T. software.
Packit fd8b60
# M.I.T. makes no representations about the suitability of
Packit fd8b60
# this software for any purpose.  It is provided "as is" without express
Packit fd8b60
# or implied warranty.
Packit fd8b60
#
Packit fd8b60
Packit fd8b60
$0 =~ s/^.*?([\w.-]+)$/$1/;
Packit fd8b60
Packit fd8b60
# The real stuff.
Packit fd8b60
Packit fd8b60
# Args: exportlist libfoo.so
Packit fd8b60
Packit fd8b60
# This code assumes the GNU version of nm.
Packit fd8b60
# For now, we'll only run it on GNU/Linux systems, so that's okay.
Packit fd8b60
Packit fd8b60
if ($#ARGV != 1) {
Packit fd8b60
    die "usage: $0 exportfile libfoo.so\n";
Packit fd8b60
}
Packit fd8b60
my($exfile, $libfile) = @ARGV;
Packit fd8b60
Packit fd8b60
@missing = ();
Packit fd8b60
open NM, "nm -Dg --defined-only $libfile |" || die "can't run nm on $libfile: $!";
Packit fd8b60
open EXPORT, "< $exfile" || die "can't read $exfile: $!";
Packit fd8b60
Packit fd8b60
@export = <EXPORT>;
Packit fd8b60
map chop, @export;
Packit fd8b60
@export = sort @export;
Packit fd8b60
Packit fd8b60
@found = ();
Packit fd8b60
while (<NM>) {
Packit fd8b60
    chop;
Packit fd8b60
    s/^[0-9a-fA-F]+ +//;
Packit fd8b60
    next if /^A /;
Packit fd8b60
    if (!/^[TDRBGS] /) {
Packit fd8b60
	unlink $libfile;
Packit fd8b60
	die "not sure what to do with '$_'";
Packit fd8b60
    }
Packit fd8b60
    s/^[TDRBGS] +//;
Packit fd8b60
    push @found, $_;
Packit fd8b60
}
Packit fd8b60
@found = sort @found;
Packit fd8b60
while ($#export >= 0 && $#found >= 0) {
Packit fd8b60
    if ($#export >= 1 && $export[0] eq $export[1]) {
Packit fd8b60
	print STDERR "Duplicate symbol in export list: $export[0]\n";
Packit fd8b60
	exit(1);
Packit fd8b60
    }
Packit fd8b60
    if ($export[0] eq $found[0]) {
Packit fd8b60
#	print "ok $export[0]\n";
Packit fd8b60
	shift @export;
Packit fd8b60
	shift @found;
Packit fd8b60
    } elsif ($export[0] lt $found[0]) {
Packit fd8b60
	push @missing, shift @export;
Packit fd8b60
    } else {
Packit fd8b60
	# Ignore added symbols, for now.
Packit fd8b60
	shift @found;
Packit fd8b60
    }
Packit fd8b60
}
Packit fd8b60
if ($#export >= 0) { @missing = (@missing, @export); }
Packit fd8b60
if ($#missing >= 0) {
Packit fd8b60
    print STDERR "Missing symbols:\n\t", join("\n\t", @missing), "\n";
Packit fd8b60
#    unlink $libfile;
Packit fd8b60
    exit(1);
Packit fd8b60
}
Packit fd8b60
exit 0;