X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=Porting%2Ffindrfuncs;h=c9a7ff80a73d21e5df45506ca32ecb10044a497f;hb=924a5df912d426c87116919236e37a89c996fd37;hp=c4a2985c837a35819b0749b58a27be9dc36a0d59;hpb=6c03d0f32decf210521faaa44c28820ed270af66;p=p5sagit%2Fp5-mst-13.2.git diff --git a/Porting/findrfuncs b/Porting/findrfuncs index c4a2985..c9a7ff8 100644 --- a/Porting/findrfuncs +++ b/Porting/findrfuncs @@ -1,11 +1,14 @@ -#!/usr/bin/perl -w +#!/usr/bin/perl -ws # # findrfuncs: find reentrant variants of functions used in an executable. +# # Requires a functional "nm -u". Searches headers in /usr/include # to find available *_r functions and looks for non-reentrant # variants used in the supplied executable. # +# Requires debug info in the shared libraries/executables. +# # Gurusamy Sarathy # gsar@ActiveState.com # @@ -26,45 +29,92 @@ if (open(CONFIG, "config.sh")) { my $CONFIG = ; $SO = $1 if $CONFIG =~ /^so='(\w+)'/m; $EXE = $1 if $CONFIG =~ /^_exe='\.(\w+)'/m; + close(CONFIG); } push @EXES, "perl$EXE"; -find(sub {push @EXES, $File::Find::name if /.$SO$/}, '.' ); +find(sub {push @EXES, $File::Find::name if /\.$SO$/}, '.' ); push @EXES, @ARGV; if ($^O eq 'dec_osf') { $NMU = 'nm -Bu'; +} elsif ($^O eq 'irix') { + $NMU = 'nm -pu'; } my %rfuncs; my @syms; find(sub { return unless -f $File::Find::name; - open my $F, "<$File::Find::name" + local *F; + open F, "<$File::Find::name" or die "Can't open $File::Find::name: $!"; my $line; - while (defined ($line = <$F>)) { + while (defined ($line = )) { if ($line =~ /\b(\w+_r)\b/) { #warn "$1 => $File::Find::name\n"; - $rfuncs{$1} = $File::Find::name; + $rfuncs{$1}->{$File::Find::name}++; } } - close $F; + close F; }, @INCDIRS); # delete bogus symbols grepped out of comments and such delete $rfuncs{setlocale_r} if $^O eq 'linux'; +# delete obsolete (as promised by man pages) symbols +my $netdb_r_obsolete; +if ($^O eq 'hpux') { + delete $rfuncs{crypt_r}; + delete $rfuncs{drand48_r}; + delete $rfuncs{endgrent_r}; + delete $rfuncs{endpwent_r}; + delete $rfuncs{getgrent_r}; + delete $rfuncs{getpwent_r}; + delete $rfuncs{setlocale_r}; + delete $rfuncs{srand48_r}; + delete $rfuncs{strerror_r}; + $netdb_r_obsolete = 1; +} elsif ($^O eq 'dec_osf') { + delete $rfuncs{crypt_r}; + delete $rfuncs{strerror_r}; + $netdb_r_obsolete = 1; +} +if ($netdb_r_obsolete) { + delete @rfuncs{qw(endhostent_r + endnetent_r + endprotoent_r + endservent_r + gethostbyaddr_r + gethostbyname_r + gethostent_r + getnetbyaddr_r + getnetbyname_r + getnetent_r + getprotobyname_r + getprotobynumber_r + getprotoent_r + getservbyname_r + getservbyport_r + getservent_r + sethostent_r + setnetent_r + setprotoent_r + setservent_r)}; +} + my %syms; for my $exe (@EXES) { - for my $sym (`$NMU $exe`) { + # warn "#--- $exe\n"; + for my $sym (`$NMU $exe 2>/dev/null`) { chomp $sym; - $sym =~ s/^\s+[Uu]\s+//; $sym =~ s/^\s+//; - next if /\s/; + $sym =~ s/^([0-9A-Fa-f]+\s+)?[Uu]\s+//; + $sym =~ s/\s+[Uu]\s+-$//; + next if $sym =~ /\s/; $sym =~ s/\@.*\z//; # remove @@GLIBC_2.0 etc # warn "#### $sym\n"; if (exists $rfuncs{"${sym}_r"} && ! $syms{"$sym:$exe"}++) { @@ -75,9 +125,9 @@ for my $exe (@EXES) { if (@syms) { print "\nFollowing symbols in $exe have reentrant versions:\n"; for my $sym (@syms) { - print "$sym => $sym" . "_r (in file " . $rfuncs{"${sym}_r"} . ")\n"; + my @f = sort keys %{$rfuncs{$sym . '_r'}}; + print "$sym => $sym" . "_r (@f)\n"; } } @syms = (); } -