mirror of
https://github.com/samba-team/samba.git
synced 2025-03-09 08:58:35 +03:00
much better findstatic script
(This used to be commit 2947b7624f921032bcd2cc5507747b2f7ef190de)
This commit is contained in:
parent
4f7a02d5de
commit
fe082a8ff5
65
source3/script/findstatic.pl
Executable file
65
source3/script/findstatic.pl
Executable file
@ -0,0 +1,65 @@
|
||||
#!/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";
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($found == 0) {
|
||||
my($t) = $typemap{$stype{$s}};
|
||||
print " '$s' is unique to $f ($t)\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,59 +0,0 @@
|
||||
#!/bin/sh
|
||||
# find a list of fns and variables in the code that could be static
|
||||
# Andrew Tridgell <tridge@samba.org>
|
||||
|
||||
# rather linux specific, but that doesn't matter in this case
|
||||
# also very slow (order is N^2) but fast enough for this project
|
||||
|
||||
declare -a FNS
|
||||
|
||||
for f in $@; do
|
||||
echo "Checking in $f"
|
||||
T_FNS=`nm $f | grep ' T ' | cut -d' ' -f3`
|
||||
C_FNS=`nm $f | egrep ' [DC] ' | cut -d' ' -f3`
|
||||
if [ "$T_FNS" = "" -a "$C_FNS" = "" ]; then
|
||||
echo "No public functions or data in $f"
|
||||
continue
|
||||
fi
|
||||
for fn in $T_FNS; do
|
||||
if [ $fn = "main" ]; then
|
||||
continue
|
||||
fi
|
||||
found=0
|
||||
for f2 in $@; do
|
||||
if [ $f != $f2 ]; then
|
||||
FNS2=`nm $f2 | egrep ' U ' | awk '{print $2}'`
|
||||
for fn2 in $FNS2; do
|
||||
if [ $fn2 = $fn ]; then
|
||||
found=1
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
done
|
||||
if [ $found = 0 ]; then
|
||||
echo "Global function $fn is unique to $f"
|
||||
fi
|
||||
done
|
||||
|
||||
for fn in $C_FNS; do
|
||||
if [ $fn = "main" ]; then
|
||||
continue
|
||||
fi
|
||||
found=0
|
||||
for f2 in $@; do
|
||||
if [ $f != $f2 ]; then
|
||||
FNS2=`nm $f2 | grep ' U ' | awk '{print $2}'`
|
||||
for fn2 in $FNS2; do
|
||||
if [ $fn2 = $fn ]; then
|
||||
found=1
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
done
|
||||
if [ $found = 0 ]; then
|
||||
echo "Global variable $fn is unique to $f"
|
||||
fi
|
||||
done
|
||||
done
|
Loading…
x
Reference in New Issue
Block a user