HP-UX nm seems to repeat itself.
[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;
29}
30
31push @EXES, "perl$EXE";
32
33find(sub {push @EXES, $File::Find::name if /.$SO$/}, '.' );
34
35push @EXES, @ARGV;
36
37if ($^O eq 'dec_osf') {
38 $NMU = 'nm -Bu';
39}
40
41my %rfuncs;
42my @syms;
43find(sub {
44 return unless -f $File::Find::name;
45 open my $F, "<$File::Find::name"
46 or die "Can't open $File::Find::name: $!";
47 my $line;
48 while (defined ($line = <$F>)) {
49 if ($line =~ /\b(\w+_r)\b/) {
50 #warn "$1 => $File::Find::name\n";
51 $rfuncs{$1} = $File::Find::name;
52 }
53 }
54 close $F;
55 }, @INCDIRS);
56
57# delete bogus symbols grepped out of comments and such
58delete $rfuncs{setlocale_r} if $^O eq 'linux';
59
6c03d0f3 60my %syms;
61
bb304ec8 62for my $exe (@EXES) {
63 for my $sym (`$NMU $exe`) {
64 chomp $sym;
65 $sym =~ s/^\s+[Uu]\s+//;
66 $sym =~ s/^\s+//;
67 next if /\s/;
68 $sym =~ s/\@.*\z//; # remove @@GLIBC_2.0 etc
69 # warn "#### $sym\n";
6c03d0f3 70 if (exists $rfuncs{"${sym}_r"} && ! $syms{"$sym:$exe"}++) {
bb304ec8 71 push @syms, $sym;
72 }
73 }
74
75 if (@syms) {
76 print "\nFollowing symbols in $exe have reentrant versions:\n";
77 for my $sym (@syms) {
78 print "$sym => $sym" . "_r (in file " . $rfuncs{"${sym}_r"} . ")\n";
79 }
80 }
81 @syms = ();
82}
83