4 # findrfuncs: find reentrant variants of functions used in an executable.
6 # Requires a functional "nm -u". Searches headers in /usr/include
7 # to find available *_r functions and looks for non-reentrant
8 # variants used in the supplied executable.
10 # Requires debug info in the shared libraries/executables.
13 # gsar@ActiveState.com
15 # Hacked to automatically find the executable and shared objects.
23 my @INCDIRS = qw(/usr/include);
27 if (open(CONFIG, "config.sh")) {
29 my $CONFIG = <CONFIG>;
30 $SO = $1 if $CONFIG =~ /^so='(\w+)'/m;
31 $EXE = $1 if $CONFIG =~ /^_exe='\.(\w+)'/m;
35 push @EXES, "perl$EXE";
37 find(sub {push @EXES, $File::Find::name if /\.$SO$/}, '.' );
41 if ($^O eq 'dec_osf') {
43 } elsif ($^O eq 'irix') {
50 return unless -f $File::Find::name;
52 open F, "<$File::Find::name"
53 or die "Can't open $File::Find::name: $!";
55 while (defined ($line = <F>)) {
56 if ($line =~ /\b(\w+_r)\b/) {
57 #warn "$1 => $File::Find::name\n";
58 $rfuncs{$1}->{$File::Find::name}++;
64 # delete bogus symbols grepped out of comments and such
65 delete $rfuncs{setlocale_r} if $^O eq 'linux';
67 # delete obsolete (as promised by man pages) symbols
70 delete $rfuncs{crypt_r};
71 delete $rfuncs{drand48_r};
72 delete $rfuncs{endgrent_r};
73 delete $rfuncs{endpwent_r};
74 delete $rfuncs{getgrent_r};
75 delete $rfuncs{getpwent_r};
76 delete $rfuncs{setlocale_r};
77 delete $rfuncs{srand48_r};
78 delete $rfuncs{strerror_r};
79 $netdb_r_obsolete = 1;
80 } elsif ($^O eq 'dec_osf') {
81 delete $rfuncs{crypt_r};
82 delete $rfuncs{strerror_r};
83 $netdb_r_obsolete = 1;
85 if ($netdb_r_obsolete) {
86 delete @rfuncs{qw(endhostent_r
110 for my $exe (@EXES) {
111 # warn "#--- $exe\n";
112 for my $sym (`$NMU $exe 2>/dev/null`) {
115 $sym =~ s/^([0-9A-Fa-f]+\s+)?[Uu]\s+//;
116 $sym =~ s/\s+[Uu]\s+-$//;
117 next if $sym =~ /\s/;
118 $sym =~ s/\@.*\z//; # remove @@GLIBC_2.0 etc
119 # warn "#### $sym\n";
120 if (exists $rfuncs{"${sym}_r"} && ! $syms{"$sym:$exe"}++) {
126 print "\nFollowing symbols in $exe have reentrant versions:\n";
127 for my $sym (@syms) {
128 my @f = sort keys %{$rfuncs{$sym . '_r'}};
129 print "$sym => $sym" . "_r (@f)\n";