4 # findrfuncs: find reentrant variants of functions used in an executable.
5 # Requires a functional "nm -u". Searches headers in /usr/include
6 # to find available *_r functions and looks for non-reentrant
7 # variants used in the supplied executable.
10 # gsar@ActiveState.com
12 # Hacked to automatically find the executable and shared objects.
20 my @INCDIRS = qw(/usr/include);
24 if (open(CONFIG, "config.sh")) {
26 my $CONFIG = <CONFIG>;
27 $SO = $1 if $CONFIG =~ /^so='(\w+)'/m;
28 $EXE = $1 if $CONFIG =~ /^_exe='\.(\w+)'/m;
32 push @EXES, "perl$EXE";
34 find(sub {push @EXES, $File::Find::name if /\.$SO$/}, '.' );
38 if ($^O eq 'dec_osf') {
40 } elsif ($^O eq 'irix') {
47 return unless -f $File::Find::name;
49 open F, "<$File::Find::name"
50 or die "Can't open $File::Find::name: $!";
52 while (defined ($line = <F>)) {
53 if ($line =~ /\b(\w+_r)\b/) {
54 #warn "$1 => $File::Find::name\n";
55 $rfuncs{$1}->{$File::Find::name}++;
61 # delete bogus symbols grepped out of comments and such
62 delete $rfuncs{setlocale_r} if $^O eq 'linux';
64 # delete obsolete (as promised by man pages) symbols
67 delete $rfuncs{crypt_r};
68 delete $rfuncs{drand48_r};
69 delete $rfuncs{endgrent_r};
70 delete $rfuncs{endpwent_r};
71 delete $rfuncs{getgrent_r};
72 delete $rfuncs{getpwent_r};
73 delete $rfuncs{setlocale_r};
74 delete $rfuncs{srand48_r};
75 delete $rfuncs{strerror_r};
76 $netdb_r_obsolete = 1;
77 } elsif ($^O eq 'dec_osf') {
78 delete $rfuncs{crypt_r};
79 delete $rfuncs{strerror_r};
80 $netdb_r_obsolete = 1;
82 if ($netdb_r_obsolete) {
83 delete @rfuncs{qw(endhostent_r
107 for my $exe (@EXES) {
108 # warn "#--- $exe\n";
109 for my $sym (`$NMU $exe`) {
112 $sym =~ s/^([0-9A-Fa-f]+\s+)?[Uu]\s+//;
113 $sym =~ s/\s+[Uu]\s+-$//;
115 $sym =~ s/\@.*\z//; # remove @@GLIBC_2.0 etc
116 # warn "#### $sym\n";
117 if (exists $rfuncs{"${sym}_r"} && ! $syms{"$sym:$exe"}++) {
123 print "\nFollowing symbols in $exe have reentrant versions:\n";
124 for my $sym (@syms) {
125 my @f = sort keys %{$rfuncs{$sym . '_r'}};
126 print "$sym => $sym" . "_r (@f)\n";