Initial import from FreeBSD RELENG_4:
[dragonfly.git] / tools / tools / kernxref / kernxref.sh
1 :
2 #
3 # ----------------------------------------------------------------------------
4 # "THE BEER-WARE LICENSE" (Revision 42):
5 # <phk@login.dknet.dk> wrote this file.  As long as you retain this notice you
6 # can do whatever you want with this stuff. If we meet some day, and you think
7 # this stuff is worth it, you can buy me a beer in return.   Poul-Henning Kamp
8 # ----------------------------------------------------------------------------
9 #
10 # $FreeBSD: src/tools/tools/kernxref/kernxref.sh,v 1.13 1999/08/28 00:54:30 peter Exp $
11 #
12 # This shellscript will make a cross reference of the symbols of the LINT 
13 # kernel.
14
15 COMPILEDIR=/sys/compile
16 KERNELNAME=LINT
17
18 cd ${COMPILEDIR}/${KERNELNAME}
19 if file vers.o | grep -q ELF; then
20         OBJFORMAT=elf;
21 else
22         OBJFORMAT=aout;
23 fi
24
25 OBJFORMAT=${OBJFORMAT} nm -gon `echo *.o /modules/*.ko  \
26         | tr ' ' '\012'                                 \
27         | egrep -v '(aicasm|genassym)'`                 \
28         | tr : ' ' | awk '
29 NF > 1  {
30         if (length($2) == 8) {
31                 $2 = $3
32                 $3 = $4
33         }
34         if ($2 == "t") 
35                 next
36         if ($2 == "F")
37                 next
38         nm[$3]++
39         if ($2 == "U") {
40                 ref[$3]=ref[$3]" "$1
41         } else if ($2 == "T" || $2 == "D" || $2 == "A") {
42                 if (def[$3] != "")
43                         def[$3]=def[$3]" "$1
44                 else
45                         def[$3]=$1
46         } else if ($2 == "?") {
47                 if (def[$3] == "S")
48                         i++
49                 else if (def[$3] != "")
50                         def[$3]=def[$3]",S"
51                 else
52                         def[$3]="S"
53                 ref[$3]=ref[$3]" "$1
54         } else if ($2 == "C") {
55                 if (def[$3] == $2)
56                         i++
57                 else if (def[$3] == "")
58                         def[$3]=$1
59                 else
60                         ref[$3]=ref[$3]" "$1
61         } else {
62                 print ">>>",$0
63         }
64         }
65 END     {
66         for (i in nm) {
67                 printf "%s {%s} %s\n",i,def[i],ref[i]
68         }
69         }
70 ' | sort | awk '
71         {
72         if ($2 == "{S}")
73                 $2 = "<Linker set>"
74         if (length($3) == 0) {
75                 printf "%-30s %3d %s\n\tUNREF\n",$1,0, $2
76                 N1++
77         } else if ($2 == "{}") {
78                 printf "%-30s %3d {UNDEF}\n",$1, NF-2
79                 N2++
80         } else {
81                 printf "%-30s %3d %s",$1,NF-2,$2
82                 p = 80;
83                 for (i = 3 ; i <= NF; i++) {
84                         if (p+length ($i)+1 > 78) {
85                                 printf "\n\t%s", $i
86                                 p = 7;
87                         } else {
88                                 printf " %s", $i
89                         }
90                         p += 1 + length ($i)
91                 }
92                 printf "\n"
93                 N3++
94                 if (NF-2 == 1) 
95                         N4++
96                 if (NF-2 == 2)
97                         N5++
98         }
99         }
100 END     {
101         printf "Total symbols: %5d\n",N1+N2+N3
102         printf "unref symbols: %5d\n",N1
103         printf "undef symbols: %5d\n",N2
104         printf "1 ref symbols: %5d\n",N4
105         printf "2 ref symbols: %5d\n",N5
106         }
107 '