2
# find a list of fns and variables in the code that could be static
3
# usually called with something like this:
4
# findstatic.pl `find . -name "*.o"`
5
# Andrew Tridgell <tridge@samba.org>
9
# use nm to find the symbols
10
my($saved_delim) = $/;
12
my($syms) = `nm -o @ARGV`;
15
my(@lines) = split(/\n/s, $syms);
23
"C" => "uninitialised variable",
24
"D" => "initialised variable"
28
# parse the symbols into defined and undefined
29
for (my($i)=0; $i <= $#{@lines}; $i++) {
30
my($line) = $lines[$i];
31
if ($line =~ /(.*):[a-f0-9]* ([TCD]) (.*)/) {
34
push(@{$def{$fname}}, $symbol);
37
if ($line =~ /(.*):\s* U (.*)/) {
40
push(@{$undef{$fname}}, $symbol);
44
# look for defined symbols that are never referenced outside the place they
46
foreach my $f (keys %def) {
47
print "Checking $f\n";
49
foreach my $s (@{$def{$f}}) {
51
foreach my $f2 (keys %undef) {
53
foreach my $s2 (@{$undef{$f2}}) {
62
my($t) = $typemap{$stype{$s}};
63
print " '$s' is unique to $f ($t)\n";
66
if ($found_one == 0) {
67
print " all symbols in '$f' are unused (main program?)\n";