summaryrefslogtreecommitdiffstats
path: root/src/util/export-check.pl
blob: 9ea36488dda742c795d114da156579f82f277be1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#
$0 =~ s/^.*?([\w.-]+)$/$1/;

# The real stuff.

# Args: exportlist libfoo.so

# This code assumes the GNU version of nm.
# For now, we'll only run it on GNU/Linux systems, so that's okay.

if ($#ARGV != 1) {
    die "usage: $0 exportfile libfoo.so\n";
}
my($exfile, $libfile) = @ARGV;

@missing = ();
open NM, "nm -Dg --defined-only $libfile |" || die "can't run nm on $libfile: $!";
open EXPORT, "< $exfile" || die "can't read $exfile: $!";

@export = <EXPORT>;
map chop, @export;
@export = sort @export;

@found = ();
while (<NM>) {
    chop;
    s/^[0-9a-fA-F]+ +//;
    next if /^A /;
    if (!/^[TDRBG] /) {
	unlink $libfile;
	die "not sure what to do with '$_'";
    }
    s/^[TDRBG] +//;
    push @found, $_;
}
@found = sort @found;
while ($#export >= 0 && $#found >= 0) {
    if ($export[0] eq $found[0]) {
#	print "ok $export[0]\n";
	shift @export;
	shift @found;
    } elsif ($export[0] lt $found[0]) {
	push @missing, shift @export;
    } else {
	# Ignore added symbols, for now.
	shift @found;
    }
}
if ($#export >= 0) { @missing = (@missing, @export); }
if ($#missing >= 0) {
    print STDERR "Missing symbols:\n\t", join("\n\t", @missing), "\n";
#    unlink $libfile;
    exit(1);
}
exit 0;