1*ebfedea0SLionel Sambuc#!/usr/local/bin/perl 2*ebfedea0SLionel Sambuc 3*ebfedea0SLionel Sambuc# we make up an array of 4*ebfedea0SLionel Sambuc# $file{function_name}=filename; 5*ebfedea0SLionel Sambuc# $unres{filename}="func1 func2 ...." 6*ebfedea0SLionel Sambuc$debug=1; 7*ebfedea0SLionel Sambuc#$nm_func="parse_linux"; 8*ebfedea0SLionel Sambuc$nm_func="parse_solaris"; 9*ebfedea0SLionel Sambuc 10*ebfedea0SLionel Sambucforeach (@ARGV) 11*ebfedea0SLionel Sambuc { 12*ebfedea0SLionel Sambuc &$nm_func($_); 13*ebfedea0SLionel Sambuc } 14*ebfedea0SLionel Sambuc 15*ebfedea0SLionel Sambucforeach $file (sort keys %unres) 16*ebfedea0SLionel Sambuc { 17*ebfedea0SLionel Sambuc @a=split(/\s+/,$unres{$file}); 18*ebfedea0SLionel Sambuc %ff=(); 19*ebfedea0SLionel Sambuc foreach $func (@a) 20*ebfedea0SLionel Sambuc { 21*ebfedea0SLionel Sambuc $f=$file{$func}; 22*ebfedea0SLionel Sambuc $ff{$f}=1 if $f ne ""; 23*ebfedea0SLionel Sambuc } 24*ebfedea0SLionel Sambuc 25*ebfedea0SLionel Sambuc foreach $a (keys %ff) 26*ebfedea0SLionel Sambuc { $we_need{$file}.="$a "; } 27*ebfedea0SLionel Sambuc } 28*ebfedea0SLionel Sambuc 29*ebfedea0SLionel Sambucforeach $file (sort keys %we_need) 30*ebfedea0SLionel Sambuc { 31*ebfedea0SLionel Sambuc# print " $file $we_need{$file}\n"; 32*ebfedea0SLionel Sambuc foreach $bit (split(/\s+/,$we_need{$file})) 33*ebfedea0SLionel Sambuc { push(@final,&walk($bit)); } 34*ebfedea0SLionel Sambuc 35*ebfedea0SLionel Sambuc foreach (@final) { $fin{$_}=1; } 36*ebfedea0SLionel Sambuc @final=""; 37*ebfedea0SLionel Sambuc foreach (sort keys %fin) 38*ebfedea0SLionel Sambuc { push(@final,$_); } 39*ebfedea0SLionel Sambuc 40*ebfedea0SLionel Sambuc print "$file: @final\n"; 41*ebfedea0SLionel Sambuc } 42*ebfedea0SLionel Sambuc 43*ebfedea0SLionel Sambucsub walk 44*ebfedea0SLionel Sambuc { 45*ebfedea0SLionel Sambuc local($f)=@_; 46*ebfedea0SLionel Sambuc local(@a,%seen,@ret,$r); 47*ebfedea0SLionel Sambuc 48*ebfedea0SLionel Sambuc @ret=""; 49*ebfedea0SLionel Sambuc $f =~ s/^\s+//; 50*ebfedea0SLionel Sambuc $f =~ s/\s+$//; 51*ebfedea0SLionel Sambuc return "" if ($f =~ "^\s*$"); 52*ebfedea0SLionel Sambuc 53*ebfedea0SLionel Sambuc return(split(/\s/,$done{$f})) if defined ($done{$f}); 54*ebfedea0SLionel Sambuc 55*ebfedea0SLionel Sambuc return if $in{$f} > 0; 56*ebfedea0SLionel Sambuc $in{$f}++; 57*ebfedea0SLionel Sambuc push(@ret,$f); 58*ebfedea0SLionel Sambuc foreach $r (split(/\s+/,$we_need{$f})) 59*ebfedea0SLionel Sambuc { 60*ebfedea0SLionel Sambuc push(@ret,&walk($r)); 61*ebfedea0SLionel Sambuc } 62*ebfedea0SLionel Sambuc $in{$f}--; 63*ebfedea0SLionel Sambuc $done{$f}=join(" ",@ret); 64*ebfedea0SLionel Sambuc return(@ret); 65*ebfedea0SLionel Sambuc } 66*ebfedea0SLionel Sambuc 67*ebfedea0SLionel Sambucsub parse_linux 68*ebfedea0SLionel Sambuc { 69*ebfedea0SLionel Sambuc local($name)=@_; 70*ebfedea0SLionel Sambuc 71*ebfedea0SLionel Sambuc open(IN,"nm $name|") || die "unable to run 'nn $name':$!\n"; 72*ebfedea0SLionel Sambuc while (<IN>) 73*ebfedea0SLionel Sambuc { 74*ebfedea0SLionel Sambuc chop; 75*ebfedea0SLionel Sambuc next if /^\s*$/; 76*ebfedea0SLionel Sambuc if (/^[^[](.*):$/) 77*ebfedea0SLionel Sambuc { 78*ebfedea0SLionel Sambuc $file=$1; 79*ebfedea0SLionel Sambuc $file="$1.c" if /\[(.*).o\]/; 80*ebfedea0SLionel Sambuc print STDERR "$file\n"; 81*ebfedea0SLionel Sambuc $we_need{$file}=" "; 82*ebfedea0SLionel Sambuc next; 83*ebfedea0SLionel Sambuc } 84*ebfedea0SLionel Sambuc 85*ebfedea0SLionel Sambuc @a=split(/\s*\|\s*/); 86*ebfedea0SLionel Sambuc next unless $#a == 7; 87*ebfedea0SLionel Sambuc next unless $a[4] eq "GLOB"; 88*ebfedea0SLionel Sambuc if ($a[6] eq "UNDEF") 89*ebfedea0SLionel Sambuc { 90*ebfedea0SLionel Sambuc $unres{$file}.=$a[7]." "; 91*ebfedea0SLionel Sambuc } 92*ebfedea0SLionel Sambuc else 93*ebfedea0SLionel Sambuc { 94*ebfedea0SLionel Sambuc if ($file{$a[7]} ne "") 95*ebfedea0SLionel Sambuc { 96*ebfedea0SLionel Sambuc print STDERR "duplicate definition of $a[7],\n$file{$a[7]} and $file \n"; 97*ebfedea0SLionel Sambuc } 98*ebfedea0SLionel Sambuc else 99*ebfedea0SLionel Sambuc { 100*ebfedea0SLionel Sambuc $file{$a[7]}=$file; 101*ebfedea0SLionel Sambuc } 102*ebfedea0SLionel Sambuc } 103*ebfedea0SLionel Sambuc } 104*ebfedea0SLionel Sambuc close(IN); 105*ebfedea0SLionel Sambuc } 106*ebfedea0SLionel Sambuc 107*ebfedea0SLionel Sambucsub parse_solaris 108*ebfedea0SLionel Sambuc { 109*ebfedea0SLionel Sambuc local($name)=@_; 110*ebfedea0SLionel Sambuc 111*ebfedea0SLionel Sambuc open(IN,"nm $name|") || die "unable to run 'nn $name':$!\n"; 112*ebfedea0SLionel Sambuc while (<IN>) 113*ebfedea0SLionel Sambuc { 114*ebfedea0SLionel Sambuc chop; 115*ebfedea0SLionel Sambuc next if /^\s*$/; 116*ebfedea0SLionel Sambuc if (/^(\S+):$/) 117*ebfedea0SLionel Sambuc { 118*ebfedea0SLionel Sambuc $file=$1; 119*ebfedea0SLionel Sambuc #$file="$1.c" if $file =~ /^(.*).o$/; 120*ebfedea0SLionel Sambuc print STDERR "$file\n"; 121*ebfedea0SLionel Sambuc $we_need{$file}=" "; 122*ebfedea0SLionel Sambuc next; 123*ebfedea0SLionel Sambuc } 124*ebfedea0SLionel Sambuc @a=split(/\s*\|\s*/); 125*ebfedea0SLionel Sambuc next unless $#a == 7; 126*ebfedea0SLionel Sambuc next unless $a[4] eq "GLOB"; 127*ebfedea0SLionel Sambuc if ($a[6] eq "UNDEF") 128*ebfedea0SLionel Sambuc { 129*ebfedea0SLionel Sambuc $unres{$file}.=$a[7]." "; 130*ebfedea0SLionel Sambuc print STDERR "$file needs $a[7]\n" if $debug; 131*ebfedea0SLionel Sambuc } 132*ebfedea0SLionel Sambuc else 133*ebfedea0SLionel Sambuc { 134*ebfedea0SLionel Sambuc if ($file{$a[7]} ne "") 135*ebfedea0SLionel Sambuc { 136*ebfedea0SLionel Sambuc print STDERR "duplicate definition of $a[7],\n$file{$a[7]} and $file \n"; 137*ebfedea0SLionel Sambuc } 138*ebfedea0SLionel Sambuc else 139*ebfedea0SLionel Sambuc { 140*ebfedea0SLionel Sambuc $file{$a[7]}=$file; 141*ebfedea0SLionel Sambuc print STDERR "$file has $a[7]\n" if $debug; 142*ebfedea0SLionel Sambuc } 143*ebfedea0SLionel Sambuc } 144*ebfedea0SLionel Sambuc } 145*ebfedea0SLionel Sambuc close(IN); 146*ebfedea0SLionel Sambuc } 147*ebfedea0SLionel Sambuc 148