diff options
author | Lennart Poettering <lennart@poettering.net> | 2006-08-25 19:25:29 +0000 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2006-08-25 19:25:29 +0000 |
commit | a895ea80c64a0dc1969bf4e3a2fecf7483a69c3f (patch) | |
tree | 5ce474dec6c65f9f8efff38f1f355da2d92fcfed /avahi-core/findstatic.pl | |
parent | 36abf208ca92f341b2c4fd4854089434c5f2520e (diff) |
add findstatic.pl script from Andrew Tridgell to SVN. It's useful for finding
symbols that are exported but shouldn't. It's not intended for shipping in the
tarballs. However it needed a safe place to live, since I use it regularly
during Avahi development.
git-svn-id: file:///home/lennart/svn/public/avahi/trunk@1281 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe
Diffstat (limited to 'avahi-core/findstatic.pl')
-rwxr-xr-x | avahi-core/findstatic.pl | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/avahi-core/findstatic.pl b/avahi-core/findstatic.pl new file mode 100755 index 0000000..43a4916 --- /dev/null +++ b/avahi-core/findstatic.pl @@ -0,0 +1,70 @@ +#!/usr/bin/perl -w +# find a list of fns and variables in the code that could be static +# usually called with something like this: +# findstatic.pl `find . -name "*.o"` +# Andrew Tridgell <tridge@samba.org> + +use strict; + +# use nm to find the symbols +my($saved_delim) = $/; +undef $/; +my($syms) = `nm -o @ARGV`; +$/ = $saved_delim; + +my(@lines) = split(/\n/s, $syms); + +my(%def); +my(%undef); +my(%stype); + +my(%typemap) = ( + "T" => "function", + "C" => "uninitialised variable", + "D" => "initialised variable" + ); + + +# parse the symbols into defined and undefined +for (my($i)=0; $i <= $#{@lines}; $i++) { + my($line) = $lines[$i]; + if ($line =~ /(.*):[a-f0-9]* ([TCD]) (.*)/) { + my($fname) = $1; + my($symbol) = $3; + push(@{$def{$fname}}, $symbol); + $stype{$symbol} = $2; + } + if ($line =~ /(.*):\s* U (.*)/) { + my($fname) = $1; + my($symbol) = $2; + push(@{$undef{$fname}}, $symbol); + } +} + +# look for defined symbols that are never referenced outside the place they +# are defined +foreach my $f (keys %def) { + print "Checking $f\n"; + my($found_one) = 0; + foreach my $s (@{$def{$f}}) { + my($found) = 0; + foreach my $f2 (keys %undef) { + if ($f2 ne $f) { + foreach my $s2 (@{$undef{$f2}}) { + if ($s2 eq $s) { + $found = 1; + $found_one = 1; + } + } + } + } + if ($found == 0) { + my($t) = $typemap{$stype{$s}}; + print " '$s' is unique to $f ($t)\n"; + } + } + if ($found_one == 0) { + print " all symbols in '$f' are unused (main program?)\n"; + } +} + |