xref: /titanic_41/usr/src/cmd/sgs/lorder/lorder.sh (revision 82629e3015252bf18319ba3815c773df23e21436)
1#! /bin/sh -f
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License, Version 1.0 only
7# (the "License").  You may not use this file except in compliance
8# with the License.
9#
10# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11# or http://www.opensolaris.org/os/licensing.
12# See the License for the specific language governing permissions
13# and limitations under the License.
14#
15# When distributing Covered Code, include this CDDL HEADER in each
16# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17# If applicable, add the following below this CDDL HEADER, with the
18# fields enclosed by brackets "[]" replaced with your own identifying
19# information: Portions Copyright [yyyy] [name of copyright owner]
20#
21# CDDL HEADER END
22#
23#	Copyright (c) 1989 AT&T
24#	  All Rights Reserved
25
26
27# Copyright 1998-2003 Sun Microsystems, Inc.  All rights reserved.
28# Use is subject to license terms.
29
30#pragma ident	"%Z%%M%	%I%	%E% SMI"
31
32#	COMMON LORDER
33#
34#
35if [ -z "$TMPDIR" ]
36then
37	TDIR="/tmp"
38else
39	TDIR=$TMPDIR
40fi
41trap "rm -f $TDIR/$$symdef $TDIR/$$symref $TDIR/$$tmp; exit"  1 2 13 15
42PFX=
43WHERE=/usr/ccs/bin
44
45USAGE="Usage: ${PFX}lorder file ..."
46for i in "$@"
47do
48	case "$i" in
49	-*)	echo "$USAGE";
50		exit 2;;
51	esac
52
53	if [ ! -r "$i" ]
54	then
55		echo "${PFX}lorder: $i: cannot open"
56		exit 2;
57	fi
58done
59
60case $# in
610)	echo "$USAGE"
62	exit 2;;
631)	case $1 in
64	*.o)	set $1 $1
65	esac
66esac
67
68#	The following sed script is commented here.
69#	The first three expressions in the sed script
70#	insures that we only have lines
71#	that contain file names and the external
72#	declarations associated with each file.
73#	The next two parts of the sed script put the pattern
74#	(in this case the file name) into the hold space
75#	and creates the "filename filename" lines and
76#	writes them out. The first part is for .o files,
77#	the second is for .o's in archives.
78#	The last 2 sections of code are exactly alike but
79#	they handle different external symbols, namely the
80#	symbols that are defined in the text section, data section, bss
81#	section or common symbols and symbols
82#	that are referenced but not defined in this file.
83#	A line containing the symbol (from the pattern space) and
84#	the file it is referenced in (from the hold space) is
85#	put into the pattern space.
86#	If its text, data, bss or common it is written out to the
87#	symbol definition (symdef) file, otherwise it was referenced
88#	but not declared in this file so it is written out to the
89#	symbol referenced (symref) file.
90#
91#
92${WHERE}/${PFX}nm -p $* 2>$TDIR/$$tmp | sed -e '/^[ 	]*$/d' -e '
93	/^[0-9]* R $/d
94	/ [a-zFS] /d
95	/[^]]:$/{
96		s/://
97		h
98		s/.*/& &/
99		p
100		d
101	}
102	/]:$/{
103		s/]://
104		s/^.*\[//
105		h
106		s/.*/& &/
107		p
108		d
109	}
110	/ [TDBNCAR] /{
111		s/^.* [TDBNCAR] //
112		G
113		s/\n/ /
114		w '$TDIR/$$symdef'
115		d
116	}
117	/ U /{
118		s/^.* U //
119		G
120		s/\n/ /
121		w '$TDIR/$$symref'
122		d
123	}
124'
125if [ -s $TDIR/$$tmp ]
126then
127	sed -e "s/^${PFX}nm:/${PFX}lorder:/" < $TDIR/$$tmp >&2
128	rm -f $TDIR/$$symdef $TDIR/$$symref $TDIR/$$tmp
129	exit 1
130fi
131sort $TDIR/$$symdef -o $TDIR/$$symdef
132sort $TDIR/$$symref -o $TDIR/$$symref
133join $TDIR/$$symref $TDIR/$$symdef | sed 's/[^ ]* *//'
134rm -f $TDIR/$$symdef $TDIR/$$symref $TDIR/$$tmp
135