1:
2#
3# ----------------------------------------------------------------------------
4# "THE BEER-WARE LICENSE" (Revision 42):
5# <phk@FreeBSD.org> 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# Sort options by "Matthew Emmerton" <matt@gsicomp.on.ca>
11#
12# $FreeBSD$
13#
14# This shell script will make a cross reference of the symbols of a kernel.
15#
16
17COMPILEDIR=/sys/`uname -m`/compile
18KERNELNAME=LINT
19SORTORDER=-k1
20
21args=`getopt h?k:s: $*`;
22if [ $? != 0 ]
23then
24	args="-h";
25fi
26set -- $args;
27for i
28do
29	case "$i"
30	in
31	-h|-\?)
32		echo "Usage: $0 [ -k <kernelname> ] [ -s [ 'symbol' | 'filename' ] ]";
33		exit 0;
34		;;
35	-k)
36		KERNELNAME=$2
37		if [ -d ${COMPILEDIR}/${KERNELNAME} ];
38		then
39			shift; shift;
40			continue;
41		fi
42		echo "Kernel '$KERNELNAME' does not exist in ${COMPILEDIR}!";
43		exit 1;
44		;;
45	-s)
46		if [ "x$2" = "xsymbol" ]
47		then
48			SORTORDER=-k1
49			shift; shift;
50			continue;
51		fi
52		if [ "x$2" = "xfilename" ]
53		then
54			SORTORDER=-k2
55			shift; shift;
56			continue;
57		fi
58		echo "Invalid selection for -s: $2";
59		exit 1;
60		;;
61	--)
62		shift;
63		break;
64		;;
65	esac
66done
67
68cd ${COMPILEDIR}/${KERNELNAME}
69
70MOD_OBJS=`find modules -name \*.o`
71
72for i in *.o $MOD_OBJS
73do
74	nm -gon $i
75done | sed '
76/aicasm.*:/d
77/genassym.*:/d
78s/.*\///
79s/:/ /
80' |  awk '
81NF > 1	{
82	if ($2 == "t") 
83		next
84	if ($2 == "F")
85		next
86	if ($2 == "U") {
87		ref[$3]=ref[$3]" "$1
88		nm[$3]++
89	} else if ($3 == "D" || $3 == "T" || $3 == "B" || $3 == "R" || $3 == "A") {
90		if (def[$4] != "")
91			def[$4]=def[$4]" "$1
92		else
93			def[$4]=$1
94		nm[$4]++
95	} else if ($2 == "?") {
96		if (def[$3] == "S")
97			i++
98		else if (def[$3] != "")
99			def[$3]=def[$3]",S"
100		else
101			def[$3]="S"
102		ref[$3]=ref[$3]" "$1
103		nm[$3]++
104	} else if ($2 == "C") {
105		if (def[$3] == $2)
106			i++
107		else if (def[$3] == "")
108			def[$3]=$1
109		else
110			ref[$3]=ref[$3]" "$1
111		nm[$3]++
112	} else {
113		print ">>>",$0
114	}
115	}
116END	{
117	for (i in nm) {
118		printf "%s {%s} %s\n",i,def[i],ref[i]
119	}
120	}
121' | sort $SORTORDER | awk '
122	{
123	if ($2 == "{S}")
124		$2 = "<Linker set>"
125	if (length($3) == 0) {
126		printf "%-31s %d %s\tUNREF\n",$1,0, $2
127		N1++
128	} else if ($2 == "{}") {
129		printf "%-31s %d {UNDEF}\n",$1, NF-2
130		N2++
131	} else {
132		printf "%-31s %d %s",$1,NF-2,$2
133		p = 80;
134		for (i = 3 ; i <= NF; i++) {
135			if (p+length ($i)+1 > 48) {
136				printf "\n\t\t\t\t\t%s", $i
137				p = 7;
138			} else {
139				printf " %s", $i
140			}
141			p += 1 + length ($i)
142		}
143		printf "\n"
144		N3++
145		if (NF-2 == 1) 
146			N4++
147		if (NF-2 == 2)
148			N5++
149	}
150	}
151END	{
152	printf "Total symbols: %5d\n",N1+N2+N3
153	printf "unref symbols: %5d\n",N1
154	printf "undef symbols: %5d\n",N2
155	printf "1 ref symbols: %5d\n",N4
156	printf "2 ref symbols: %5d\n",N5
157	}
158'
159