xref: /freebsd/crypto/krb5/src/util/export-check.pl (revision 7f2fe78b9dd5f51c821d771b63d2e096f6fd49e9)
1#
2
3# Copyright 2006 Massachusetts Institute of Technology.
4# All Rights Reserved.
5#
6# Export of this software from the United States of America may
7#   require a specific license from the United States Government.
8#   It is the responsibility of any person or organization contemplating
9#   export to obtain such a license before exporting.
10#
11# WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
12# distribute this software and its documentation for any purpose and
13# without fee is hereby granted, provided that the above copyright
14# notice appear in all copies and that both that copyright notice and
15# this permission notice appear in supporting documentation, and that
16# the name of M.I.T. not be used in advertising or publicity pertaining
17# to distribution of the software without specific, written prior
18# permission.  Furthermore if you modify this software you must label
19# your software as modified software and not distribute it in such a
20# fashion that it might be confused with the original M.I.T. software.
21# M.I.T. makes no representations about the suitability of
22# this software for any purpose.  It is provided "as is" without express
23# or implied warranty.
24#
25
26$0 =~ s/^.*?([\w.-]+)$/$1/;
27
28# The real stuff.
29
30# Args: exportlist libfoo.so
31
32# This code assumes the GNU version of nm.
33# For now, we'll only run it on GNU/Linux systems, so that's okay.
34
35if ($#ARGV != 1) {
36    die "usage: $0 exportfile libfoo.so\n";
37}
38my($exfile, $libfile) = @ARGV;
39
40@missing = ();
41open NM, "nm -Dg --defined-only $libfile |" || die "can't run nm on $libfile: $!";
42open EXPORT, "< $exfile" || die "can't read $exfile: $!";
43
44@export = <EXPORT>;
45map chop, @export;
46@export = sort @export;
47
48@found = ();
49while (<NM>) {
50    chop;
51    s/^[0-9a-fA-F]+ +//;
52    s/@@.*$//;
53    next if /^A /;
54    if (!/^[TDRBGS] /) {
55	unlink $libfile;
56	die "not sure what to do with '$_'";
57    }
58    s/^[TDRBGS] +//;
59    push @found, $_;
60}
61@found = sort @found;
62while ($#export >= 0 && $#found >= 0) {
63    if ($#export >= 1 && $export[0] eq $export[1]) {
64	print STDERR "Duplicate symbol in export list: $export[0]\n";
65	exit(1);
66    }
67    if ($export[0] eq $found[0]) {
68#	print "ok $export[0]\n";
69	shift @export;
70	shift @found;
71    } elsif ($export[0] lt $found[0]) {
72	push @missing, shift @export;
73    } else {
74	# Ignore added symbols, for now.
75	shift @found;
76    }
77}
78if ($#export >= 0) { @missing = (@missing, @export); }
79if ($#missing >= 0) {
80    print STDERR "Missing symbols:\n\t", join("\n\t", @missing), "\n";
81#    unlink $libfile;
82    exit(1);
83}
84exit 0;
85