Typo fixes.
[p5sagit/p5-mst-13.2.git] / Porting / findrfuncs
CommitLineData
bb304ec8 1#!/usr/bin/perl -w
2
3#
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.
8#
9# Gurusamy Sarathy
10# gsar@ActiveState.com
11#
12# Hacked to automatically find the executable and shared objects.
13# --jhi
14
15use strict;
16use File::Find;
17
18my @EXES;
19my $NMU = 'nm -u';
20my @INCDIRS = qw(/usr/include);
21my $SO = 'so';
22my $EXE = '';
23
24if (open(CONFIG, "config.sh")) {
25 local $/;
26 my $CONFIG = <CONFIG>;
27 $SO = $1 if $CONFIG =~ /^so='(\w+)'/m;
28 $EXE = $1 if $CONFIG =~ /^_exe='\.(\w+)'/m;
c8688140 29 close(CONFIG);
bb304ec8 30}
31
32push @EXES, "perl$EXE";
33
72108f2b 34find(sub {push @EXES, $File::Find::name if /\.$SO$/}, '.' );
bb304ec8 35
36push @EXES, @ARGV;
37
38if ($^O eq 'dec_osf') {
39 $NMU = 'nm -Bu';
c8688140 40} elsif ($^O eq 'irix') {
41 $NMU = 'nm -pu';
bb304ec8 42}
43
44my %rfuncs;
45my @syms;
46find(sub {
47 return unless -f $File::Find::name;
72108f2b 48 local *F;
49 open F, "<$File::Find::name"
bb304ec8 50 or die "Can't open $File::Find::name: $!";
51 my $line;
72108f2b 52 while (defined ($line = <F>)) {
bb304ec8 53 if ($line =~ /\b(\w+_r)\b/) {
54 #warn "$1 => $File::Find::name\n";
c8688140 55 $rfuncs{$1}->{$File::Find::name}++;
bb304ec8 56 }
57 }
72108f2b 58 close F;
bb304ec8 59 }, @INCDIRS);
60
61# delete bogus symbols grepped out of comments and such
62delete $rfuncs{setlocale_r} if $^O eq 'linux';
63
6c03d0f3 64my %syms;
65
bb304ec8 66for my $exe (@EXES) {
c8688140 67 # warn "#--- $exe\n";
bb304ec8 68 for my $sym (`$NMU $exe`) {
69 chomp $sym;
bb304ec8 70 $sym =~ s/^\s+//;
c8688140 71 $sym =~ s/^([0-9A-Fa-f]+\s+)?[Uu]\s+//;
72108f2b 72 $sym =~ s/\s+[Uu]\s+-$//;
bb304ec8 73 next if /\s/;
74 $sym =~ s/\@.*\z//; # remove @@GLIBC_2.0 etc
75 # warn "#### $sym\n";
6c03d0f3 76 if (exists $rfuncs{"${sym}_r"} && ! $syms{"$sym:$exe"}++) {
bb304ec8 77 push @syms, $sym;
78 }
79 }
80
81 if (@syms) {
82 print "\nFollowing symbols in $exe have reentrant versions:\n";
83 for my $sym (@syms) {
c8688140 84 my @f = sort keys %{$rfuncs{$sym . '_r'}};
85 print "$sym => $sym" . "_r (@f)\n";
bb304ec8 86 }
87 }
88 @syms = ();
89}
90