xref: /titanic_51/usr/src/tools/scripts/check_rtime.pl (revision bfed486ad8de8b8ebc6345a8e10accae08bf2f45)
17c478bd9Sstevel@tonic-gate#!/usr/perl5/bin/perl -w
27c478bd9Sstevel@tonic-gate#
37c478bd9Sstevel@tonic-gate# CDDL HEADER START
47c478bd9Sstevel@tonic-gate#
57c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the
6749f21d3Swesolows# Common Development and Distribution License (the "License").
7749f21d3Swesolows# You may not use this file except in compliance with the License.
87c478bd9Sstevel@tonic-gate#
97c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate# and limitations under the License.
137c478bd9Sstevel@tonic-gate#
147c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate#
207c478bd9Sstevel@tonic-gate# CDDL HEADER END
217c478bd9Sstevel@tonic-gate#
22749f21d3Swesolows
237c478bd9Sstevel@tonic-gate#
24567efe8fSDavid Major# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
257c478bd9Sstevel@tonic-gate# Use is subject to license terms.
267c478bd9Sstevel@tonic-gate#
277c478bd9Sstevel@tonic-gate#
28749f21d3Swesolows
29749f21d3Swesolows#
307c478bd9Sstevel@tonic-gate# Check ELF information.
317c478bd9Sstevel@tonic-gate#
327c478bd9Sstevel@tonic-gate# This script descends a directory hierarchy inspecting ELF dynamic executables
337c478bd9Sstevel@tonic-gate# and shared objects.  The general theme is to verify that common Makefile rules
347c478bd9Sstevel@tonic-gate# have been used to build these objects.  Typical failures occur when Makefile
357c478bd9Sstevel@tonic-gate# rules are re-invented rather than being inherited from "cmd/lib" Makefiles.
367c478bd9Sstevel@tonic-gate#
377c478bd9Sstevel@tonic-gate# As always, a number of components don't follow the rules, and these are
387c478bd9Sstevel@tonic-gate# excluded to reduce this scripts output.  Pathnames used for this exclusion
397c478bd9Sstevel@tonic-gate# assume this script is being run over a "proto" area.  The -a (all) option
407c478bd9Sstevel@tonic-gate# skips any exclusions.
417c478bd9Sstevel@tonic-gate#
427c478bd9Sstevel@tonic-gate# By default any file that has conditions that should be reported is first
437c478bd9Sstevel@tonic-gate# listed and then each condition follows.  The -o (one-line) option produces a
447c478bd9Sstevel@tonic-gate# more terse output which is better for sorting/diffing with "nightly".
457c478bd9Sstevel@tonic-gate#
467c478bd9Sstevel@tonic-gate# NOTE: missing dependencies, symbols or versions are reported by running the
477c478bd9Sstevel@tonic-gate# file through ldd(1).  As objects within a proto area are built to exist in a
487c478bd9Sstevel@tonic-gate# base system, standard use of ldd(1) will bind any objects to dependencies
497c478bd9Sstevel@tonic-gate# that exist in the base system.  It is frequently the case that newer objects
507c478bd9Sstevel@tonic-gate# exist in the proto area that are required to satisfy other objects
517c478bd9Sstevel@tonic-gate# dependencies, and without using these newer objects an ldd(1) will produce
527c478bd9Sstevel@tonic-gate# misleading error messages.  To compensate for this, the -d option (or the
537c478bd9Sstevel@tonic-gate# existence of the CODEMSG_WS/ROOT environment variables) cause the creation of
547c478bd9Sstevel@tonic-gate# alternative dependency mappings via crle(1) configuration files that establish
557c478bd9Sstevel@tonic-gate# any proto shared objects as alternatives to their base system location.  Thus
567c478bd9Sstevel@tonic-gate# ldd(1) can be executed against these configuration files so that objects in a
577c478bd9Sstevel@tonic-gate# proto area bind to their dependencies in the same proto area.
587c478bd9Sstevel@tonic-gate
597c478bd9Sstevel@tonic-gate
607c478bd9Sstevel@tonic-gate# Define all global variables (required for strict)
61f6acbf7cSrieuse vars  qw($SkipDirs $SkipFiles $SkipTextrelFiles $SkipDirectBindFiles);
6267e3a03eSrieuse vars  qw($SkipUndefFiles $SkipUnusedDirs);
634840e086Srieuse vars  qw($SkipStabFiles $SkipNoExStkFiles $SkipCrleConf);
6467e3a03eSrieuse vars  qw($SkipUnusedSearchPath $SkipUnrefObject);
65d89524d0Srieuse vars  qw($Prog $Mach $Isalist $Env $Ena64 $Tmpdir $Error $Gnuc);
6667e3a03eSrieuse vars  qw($UnusedPaths $LddNoU $Crle32 $Crle64 $Conf32 $Conf64);
67f6acbf7cSrieuse vars  qw($SkipDirectBindDirs $SkipInterps $SkipSymSort $OldDeps %opt);
687c478bd9Sstevel@tonic-gate
697c478bd9Sstevel@tonic-gateuse strict;
707c478bd9Sstevel@tonic-gate
717c478bd9Sstevel@tonic-gate
727c478bd9Sstevel@tonic-gate# Define any directories we should skip completely.
737c478bd9Sstevel@tonic-gate$SkipDirs = qr{
747c478bd9Sstevel@tonic-gate	usr/lib/devfsadm |		# 4382889
757c478bd9Sstevel@tonic-gate	usr/lib/libc |			# optimized libc
767c478bd9Sstevel@tonic-gate	usr/lib/rcm |			# 4426119
777c478bd9Sstevel@tonic-gate	usr/perl5 |			# alan's taking care of these :-)
787c478bd9Sstevel@tonic-gate	usr/src				# no need to look at shipped source
797c478bd9Sstevel@tonic-gate}x;
807c478bd9Sstevel@tonic-gate
817c478bd9Sstevel@tonic-gate# Define any files we should skip completely.
827c478bd9Sstevel@tonic-gate$SkipFiles = qr{ ^(?:
837c478bd9Sstevel@tonic-gate	lddstub |			# lddstub has no dependencies
847c478bd9Sstevel@tonic-gate	geniconvtbl\.so |		# 4384329
857c478bd9Sstevel@tonic-gate	libssagent\.so\.1 |		# 4328854
867c478bd9Sstevel@tonic-gate	libpsvcplugin_psr\.so\.1 |	# 4385799
877c478bd9Sstevel@tonic-gate	libpsvcpolicy_psr\.so\.1 |	#  "  "
887c478bd9Sstevel@tonic-gate	libpsvcpolicy\.so\.1 |		#  "  "
897c478bd9Sstevel@tonic-gate	picl_slm\.so |			#  "  "
90827ff201Sjacobs	mod_ipp\.so |			# Apache loadable module
9160c45ed0Svs195195	fptest |	# USIII specific extns. cause ldd noise on USII bld. m/c
927c478bd9Sstevel@tonic-gate	grub
937c478bd9Sstevel@tonic-gate	)$
947c478bd9Sstevel@tonic-gate}x;
957c478bd9Sstevel@tonic-gate
967c478bd9Sstevel@tonic-gate# Define any files that are allowed text relocations.
977c478bd9Sstevel@tonic-gate$SkipTextrelFiles = qr{ ^(?:
987c478bd9Sstevel@tonic-gate	unix |				# kernel models are non-pic
997c478bd9Sstevel@tonic-gate	mdb				# relocations against __RTC (dbx)
1007c478bd9Sstevel@tonic-gate	)$
1017c478bd9Sstevel@tonic-gate}x;
1027c478bd9Sstevel@tonic-gate
103f6acbf7cSrie# Define any directories or files that are allowed to have no direct bound
104f6acbf7cSrie# symbols
105f6acbf7cSrie$SkipDirectBindDirs = qr{
106f6acbf7cSrie	usr/ucb
107f6acbf7cSrie}x;
108f6acbf7cSrie
109f6acbf7cSrie$SkipDirectBindFiles = qr{ ^(?:
110f6acbf7cSrie	unix |
111f6acbf7cSrie	sbcp |
112f6acbf7cSrie	libproc.so.1 |
113f6acbf7cSrie	libnisdb.so.2
114f6acbf7cSrie	)$
115f6acbf7cSrie}x;
116f6acbf7cSrie
1177c478bd9Sstevel@tonic-gate# Define any files that are allowed undefined references.
1187c478bd9Sstevel@tonic-gate
1197c478bd9Sstevel@tonic-gate$SkipUndefFiles = qr{ ^(?:
1207c478bd9Sstevel@tonic-gate	libsvm\.so\.1 |			# libspmicommon.so.1 lacking
12167e3a03eSrie	libnisdb\.so\.2			# C++
1227c478bd9Sstevel@tonic-gate	)$
1237c478bd9Sstevel@tonic-gate}x;
1247c478bd9Sstevel@tonic-gate
1257c478bd9Sstevel@tonic-gate# Define any files that have unused dependencies.
1267c478bd9Sstevel@tonic-gate$SkipUnusedDirs = qr{
1277c478bd9Sstevel@tonic-gate	lib/picl/plugins/ |		# require devtree dependencies
1287c478bd9Sstevel@tonic-gate	/lib/libp			# profile libc makes libm an unused
1297c478bd9Sstevel@tonic-gate}x;					#	dependency of standard libc
1307c478bd9Sstevel@tonic-gate
1317c478bd9Sstevel@tonic-gate# Define any files that should contain debugging information.
1327c478bd9Sstevel@tonic-gate$SkipStabFiles = qr{ ^(?:
1337c478bd9Sstevel@tonic-gate	unix
1347c478bd9Sstevel@tonic-gate	)$
1357c478bd9Sstevel@tonic-gate}x;
1367c478bd9Sstevel@tonic-gate
1377c478bd9Sstevel@tonic-gate# Define any files that don't require a non-executable stack definition.
1387c478bd9Sstevel@tonic-gate$SkipNoExStkFiles = qr{ ^(?:
1397c478bd9Sstevel@tonic-gate	forth |
1407c478bd9Sstevel@tonic-gate	unix |
1417c478bd9Sstevel@tonic-gate	multiboot
1427c478bd9Sstevel@tonic-gate	)$
1437c478bd9Sstevel@tonic-gate}x;
1447c478bd9Sstevel@tonic-gate
1454840e086Srie# Identify any files that should be skipped when building a crle(1)
1464840e086Srie# configuration file.  As the hwcap libraries can be loop-back mounted onto
1474840e086Srie# libc, these can confuse crle(1) because of their identical dev/inode.
1484840e086Srie$SkipCrleConf = qr{
1494840e086Srie	lib/libc/libc_hwcap
1504840e086Srie}x;
1514840e086Srie
15267e3a03eSrie# Skip "unused search path=" ldd(1) diagnostics.
15367e3a03eSrie$SkipUnusedSearchPath = qr{
15467e3a03eSrie	/usr/lib/fs/autofs.*\ from\ .automountd |		# dlopen()
15567e3a03eSrie	/etc/ppp/plugins.*\ from\ .*pppd |			# dlopen()
15667e3a03eSrie	/usr/lib/inet/ppp.*\ from\ .*pppd |			# dlopen()
15767e3a03eSrie	/usr/sfw/lib.*\ from\ .*libipsecutil.so.1 |		# dlopen()
15867e3a03eSrie	/usr/platform/.*rsmlib.*\ from\ .*librsm.so.2 |		# dlopen()
15967e3a03eSrie	\$ORIGIN.*\ from\ .*fcode.so |				# dlopen()
160686a3f3fSJiri Cervenka	/opt/VRTSvxvm/lib.*\ from\ .*libdiskmgt\.so\.1 |	# dlopen()
16167e3a03eSrie	/usr/platform/.*\ from\ .*/usr/platform |		# picl
16267e3a03eSrie	/usr/lib/picl/.*\ from\ .*/usr/platform |		# picl
16367e3a03eSrie	/usr/platform/.*\ from\ .*/usr/lib/picl |		# picl
16467e3a03eSrie	/usr/lib/smbsrv.*\ from\ .*libsmb\.so\.1 |		# future needs
16567e3a03eSrie	/usr/lib/mps/secv1.*\ from\ .*libnss3\.so |		# non-OSNet
16667e3a03eSrie	/usr/lib/mps.*\ from\ .*libnss3\.so |			# non-OSNet
16767e3a03eSrie	/usr/sfw/lib.*\ from\ .*libdbus-1\.so\.3 |		# non-OSNet
16867e3a03eSrie	/usr/sfw/lib.*\ from\ .*libdbus-glib-1\.so\.2 |		# non-OSNet
16967e3a03eSrie	/usr/sfw/lib.*\ from\ .*libglib-2\.0\.so\.0 |		# non-OSNet
17067e3a03eSrie	/usr/X11/lib.*\ from\ .*libglib-2\.0\.so\.0 |		# non-OSNet
17167e3a03eSrie	/usr/sfw/lib.*\ from\ .*libgobject-2\.0\.so\.0 |	# non-OSNet
17267e3a03eSrie	/usr/X11/lib.*\ from\ .*libgobject-2\.0\.so\.0 |	# non-OSNet
17367e3a03eSrie	/usr/sfw/lib.*\ from\ .*libcrypto\.so\.0\.9\.8 |	# non-OSNet
17467e3a03eSrie	/usr/sfw/lib.*\ from\ .*libnetsnmp\.so\.5 |		# non-OSNet
17536cb57a5Srie	/usr/sfw/lib.*\ from\ .*libgcc_s\.so\.1 |		# non-OSNet
176567efe8fSDavid Major	/usr.*\ from\ .*tst\.gcc\.exe |				# gcc built
1776b91cdf9SDavid Major	/usr/postgres/8.3/lib.*\ from\ .*libpq\.so\.5 |		# non-OSNET
1786b91cdf9SDavid Major	/usr/sfw/lib.*\ from\ .*libpq\.so\.5			# non-OSNET
17967e3a03eSrie}x;
18067e3a03eSrie
18167e3a03eSrie# Skip "unreferenced object=" ldd(1) diagnostics.
18267e3a03eSrie$SkipUnrefObject = qr{
18367e3a03eSrie	/libmapmalloc\.so\.1;\ unused\ dependency\ of |		# interposer
184d89524d0Srie	/libstdc\+\+\.so\.6;\ unused\ dependency\ of |		# gcc build
185d89524d0Srie	/libm\.so\.2.*\ of\ .*libstdc\+\+\.so\.6 |		# gcc build
18667e3a03eSrie	/lib.*\ of\ .*/lib/picl/plugins/ |			# picl
18767e3a03eSrie	/lib.*\ of\ .*libcimapi\.so |				# non-OSNET
18867e3a03eSrie	/lib.*\ of\ .*libjvm\.so |				# non-OSNET
18967e3a03eSrie	/lib.*\ of\ .*libnetsnmp\.so\.5 |			# non-OSNET
19067e3a03eSrie	/lib.*\ of\ .*libnetsnmpagent\.so\.5 |			# non-OSNET
19167e3a03eSrie	/lib.*\ of\ .*libnetsnmpmibs\.so\.5 |			# non-OSNET
19267e3a03eSrie	/lib.*\ of\ .*libnetsnmphelpers\.so\.5 |		# non-OSNET
19367e3a03eSrie	/lib.*\ of\ .*libnspr4\.so |				# non-OSNET
19467e3a03eSrie	/lib.*\ of\ .*libsoftokn3\.so |				# non-OSNET
19567e3a03eSrie	/lib.*\ of\ .*libspmicommon\.so\.1 |			# non-OSNET
19667e3a03eSrie	/lib.*\ of\ .*libspmocommon\.so\.1 |			# non-OSNET
19767e3a03eSrie	/lib.*\ of\ .*libssl3\.so |				# non-OSNET
19867e3a03eSrie	/lib.*\ of\ .*libxml2\.so\.2 |				# non-OSNET
199cee0fb94SAllan Matthews	/lib.*\ of\ .*libxslt\.so\.1 |				# non-OSNET
200cee0fb94SAllan Matthews	/lib.*\ of\ .*libpq\.so\.4 				# non-OSNET
20167e3a03eSrie}x;
20267e3a03eSrie
2037c478bd9Sstevel@tonic-gate# Define any files that should only have unused (ldd -u) processing.
2047c478bd9Sstevel@tonic-gate$UnusedPaths = qr{
2057c478bd9Sstevel@tonic-gate	ucb/shutdown			# libucb interposes on libc and makes
2067c478bd9Sstevel@tonic-gate					# dependencies on libc seem unnecessary
2077c478bd9Sstevel@tonic-gate}x;
2087c478bd9Sstevel@tonic-gate
2097c478bd9Sstevel@tonic-gate# Define interpreters we should ignore.
2107c478bd9Sstevel@tonic-gate$SkipInterps = qr{
2117c478bd9Sstevel@tonic-gate	misc/krtld |
2127c478bd9Sstevel@tonic-gate	misc/amd64/krtld |
2137c478bd9Sstevel@tonic-gate	misc/sparcv9/krtld
2147c478bd9Sstevel@tonic-gate}x;
2157c478bd9Sstevel@tonic-gate
2167c478bd9Sstevel@tonic-gate# Catch libintl and libw, although ld(1) will bind to these and thus determine
2177c478bd9Sstevel@tonic-gate# they're needed, their content was moved into libc as of on297 build 7.
2187c478bd9Sstevel@tonic-gate# libthread and libpthread were completely moved into libc as of on10 build 53.
21967e3a03eSrie# libdl was moved into libc as of on10 build 49.  librt and libaio were moved
22067e3a03eSrie# into libc as of Nevada build 44.
2217c478bd9Sstevel@tonic-gate$OldDeps = qr{ ^(?:
2227c478bd9Sstevel@tonic-gate	libintl\.so\.1 |
2237c478bd9Sstevel@tonic-gate	libw\.so\.1 |
2247c478bd9Sstevel@tonic-gate	libthread\.so\.1 |
2257c478bd9Sstevel@tonic-gate	libpthread\.so\.1 |
22667e3a03eSrie	libdl\.so\.1 |
22767e3a03eSrie	librt\.so\.1 |
22867e3a03eSrie	libaio\.so\.1
2297c478bd9Sstevel@tonic-gate	)$
2307c478bd9Sstevel@tonic-gate}x;
2317c478bd9Sstevel@tonic-gate
232dfb96a4fSab196087# Files for which we skip checking of duplicate addresses in the
233dfb96a4fSab196087# symbol sort sections. Such exceptions should be rare --- most code will
234dfb96a4fSab196087# not have duplicate addresses, since it takes assember or a "#pragma weak"
235dfb96a4fSab196087# to do such aliasing in C. C++ is different: The compiler generates aliases
236dfb96a4fSab196087# for implementation reasons, and the mangled names used to encode argument
237dfb96a4fSab196087# and return value types are difficult to handle well in mapfiles.
238dfb96a4fSab196087# Furthermore, the Sun compiler and gcc use different and incompatible
239dfb96a4fSab196087# name mangling conventions. Since ON must be buildable by either, we
240dfb96a4fSab196087# would have to maintain two sets of mapfiles for each such object.
241dfb96a4fSab196087# C++ use is rare in ON, so this is not worth pursuing.
242dfb96a4fSab196087#
243dfb96a4fSab196087$SkipSymSort = qr{ ^.*(?:
244dfb96a4fSab196087	opt/SUNWdtrt/tst/common/pid/tst.weak2.exe |	# DTrace test
245dfb96a4fSab196087	lib/amd64/libnsl\.so\.1 |			# C++
246dfb96a4fSab196087	lib/sparcv9/libnsl\.so\.1 |			# C++
24701668883Sab196087	lib/sparcv9/libfru\.so\.1 |			# C++
24867e3a03eSrie	usr/lib/sgml/nsgmls |				# C++
249fcf3ce44SJohn Forte	ld\.so\.1 |					# libc_pic.a user
250fcf3ce44SJohn Forte	lib/libsun_fc\.so\.1 |				# C++
251fcf3ce44SJohn Forte	lib/amd64/libsun_fc\.so\.1 |			# C++
252fcf3ce44SJohn Forte	lib/sparcv9/libsun_fc\.so\.1 			# C++
253dfb96a4fSab196087	)$
254dfb96a4fSab196087}x;
255dfb96a4fSab196087
2567c478bd9Sstevel@tonic-gateuse Getopt::Std;
2577c478bd9Sstevel@tonic-gate
2587c478bd9Sstevel@tonic-gate# -----------------------------------------------------------------------------
2597c478bd9Sstevel@tonic-gate
2607c478bd9Sstevel@tonic-gate# Reliably compare two OS revisions.  Arguments are <ver1> <op> <ver2>.
2617c478bd9Sstevel@tonic-gate# <op> is the string form of a normal numeric comparison operator.
2627c478bd9Sstevel@tonic-gatesub cmp_os_ver {
2637c478bd9Sstevel@tonic-gate	my @ver1 = split(/\./, $_[0]);
2647c478bd9Sstevel@tonic-gate	my $op = $_[1];
2657c478bd9Sstevel@tonic-gate	my @ver2 = split(/\./, $_[2]);
2667c478bd9Sstevel@tonic-gate
2677c478bd9Sstevel@tonic-gate	push @ver2, ("0") x $#ver1 - $#ver2;
2687c478bd9Sstevel@tonic-gate	push @ver1, ("0") x $#ver2 - $#ver1;
2697c478bd9Sstevel@tonic-gate
2707c478bd9Sstevel@tonic-gate	my $diff = 0;
2717c478bd9Sstevel@tonic-gate	while (@ver1 || @ver2) {
2727c478bd9Sstevel@tonic-gate		if (($diff = shift(@ver1) - shift(@ver2)) != 0) {
2737c478bd9Sstevel@tonic-gate			last;
2747c478bd9Sstevel@tonic-gate		}
2757c478bd9Sstevel@tonic-gate	}
2767c478bd9Sstevel@tonic-gate	return (eval "$diff $op 0" ? 1 : 0);
2777c478bd9Sstevel@tonic-gate}
2787c478bd9Sstevel@tonic-gate
279918fadfaSsommerfe# This script relies on ldd returning output reflecting only the binary
280918fadfaSsommerfe# contents.  But if LD_PRELOAD* environment variables are present, libraries
281918fadfaSsommerfe# named by them will also appear in the output, disrupting our analysis.
282918fadfaSsommerfe# So, before we get too far, scrub the environment.
283918fadfaSsommerfe
284918fadfaSsommerfedelete($ENV{LD_PRELOAD});
285918fadfaSsommerfedelete($ENV{LD_PRELOAD_32});
286918fadfaSsommerfedelete($ENV{LD_PRELOAD_64});
287918fadfaSsommerfe
2887c478bd9Sstevel@tonic-gate# Establish a program name for any error diagnostics.
2897c478bd9Sstevel@tonic-gatechomp($Prog = `basename $0`);
2907c478bd9Sstevel@tonic-gate
2917c478bd9Sstevel@tonic-gate# Determine what machinery is available.
2927c478bd9Sstevel@tonic-gate$Mach = `uname -p`;
2937c478bd9Sstevel@tonic-gate$Isalist = `isalist`;
2947c478bd9Sstevel@tonic-gate$Env = "";
2957c478bd9Sstevel@tonic-gateif ($Mach =~ /sparc/) {
2967c478bd9Sstevel@tonic-gate	if ($Isalist =~ /sparcv9/) {
2977c478bd9Sstevel@tonic-gate		$Ena64 = "ok";
2987c478bd9Sstevel@tonic-gate	}
2997c478bd9Sstevel@tonic-gate} elsif ($Mach =~ /i386/) {
3007c478bd9Sstevel@tonic-gate	if ($Isalist =~ /amd64/) {
3017c478bd9Sstevel@tonic-gate		$Ena64 = "ok";
3027c478bd9Sstevel@tonic-gate	}
3037c478bd9Sstevel@tonic-gate}
3047c478bd9Sstevel@tonic-gate
3057c478bd9Sstevel@tonic-gate# Check that we have arguments.
306*bfed486aSAli Bahramiif ((getopts('ad:imosv', \%opt) == 0) || ($#ARGV == -1)) {
3077c478bd9Sstevel@tonic-gate	print "usage: $Prog [-a] [-d depdir] [-m] [-o] [-s] file | dir, ...\n";
3087c478bd9Sstevel@tonic-gate	print "\t[-a]\t\tprocess all files (ignore any exception lists)\n";
3097c478bd9Sstevel@tonic-gate	print "\t[-d dir]\testablish dependencies from under directory\n";
3107c478bd9Sstevel@tonic-gate	print "\t[-i]\t\tproduce dynamic table entry information\n";
3117c478bd9Sstevel@tonic-gate	print "\t[-m]\t\tprocess mcs(1) comments\n";
3127c478bd9Sstevel@tonic-gate	print "\t[-o]\t\tproduce one-liner output (prefixed with pathname)\n";
3137c478bd9Sstevel@tonic-gate	print "\t[-s]\t\tprocess .stab and .symtab entries\n";
314*bfed486aSAli Bahrami	print "\t[-v]\t\tprocess version definition entries\n";
3157c478bd9Sstevel@tonic-gate	exit 1;
3167c478bd9Sstevel@tonic-gate} else {
3177c478bd9Sstevel@tonic-gate	my($Proto);
3187c478bd9Sstevel@tonic-gate
3197c478bd9Sstevel@tonic-gate	if ($opt{d}) {
3207c478bd9Sstevel@tonic-gate		# User specified dependency directory - make sure it exists.
3217c478bd9Sstevel@tonic-gate		if (! -d $opt{d}) {
3227c478bd9Sstevel@tonic-gate			print "$Prog: $opt{d} is not a directory\n";
3237c478bd9Sstevel@tonic-gate			exit 1;
3247c478bd9Sstevel@tonic-gate		}
3257c478bd9Sstevel@tonic-gate		$Proto = $opt{d};
3267c478bd9Sstevel@tonic-gate
3277c478bd9Sstevel@tonic-gate	} elsif ($ENV{CODEMGR_WS}) {
3287c478bd9Sstevel@tonic-gate		my($Root);
3297c478bd9Sstevel@tonic-gate
3307c478bd9Sstevel@tonic-gate		# Without a user specified dependency directory see if we're
3317c478bd9Sstevel@tonic-gate		# part of a codemanager workspace and if a proto area exists.
3327c478bd9Sstevel@tonic-gate		if (($Root = $ENV{ROOT}) && (-d $Root)) {
3337c478bd9Sstevel@tonic-gate			$Proto = $Root;
3347c478bd9Sstevel@tonic-gate		}
3357c478bd9Sstevel@tonic-gate	}
3367c478bd9Sstevel@tonic-gate
3377c478bd9Sstevel@tonic-gate	if (!($Tmpdir = $ENV{TMPDIR}) || (! -d $Tmpdir)) {
3387c478bd9Sstevel@tonic-gate		$Tmpdir = "/tmp";
3397c478bd9Sstevel@tonic-gate	}
3407c478bd9Sstevel@tonic-gate
341d89524d0Srie	# Determine whether this is a __GNUC build.  If so, unused search path
342d89524d0Srie	# processing is disabled.
343d89524d0Srie	if (defined $ENV{__GNUC}) {
344d89524d0Srie		$Gnuc = 1;
345d89524d0Srie	} else {
346d89524d0Srie		$Gnuc = 0;
347d89524d0Srie	}
348d89524d0Srie
3497c478bd9Sstevel@tonic-gate	# Look for dependencies under $Proto.
3507c478bd9Sstevel@tonic-gate	if ($Proto) {
3517c478bd9Sstevel@tonic-gate		# To support alternative dependency mapping we'll need ldd(1)'s
3527c478bd9Sstevel@tonic-gate		# -e option.  This is relatively new (s81_30), so make sure
3537c478bd9Sstevel@tonic-gate		# ldd(1) is capable before gathering any dependency information.
3547c478bd9Sstevel@tonic-gate		if (system('ldd -e /usr/lib/lddstub 2> /dev/null')) {
3557c478bd9Sstevel@tonic-gate			print "ldd: does not support -e, unable to ";
3567c478bd9Sstevel@tonic-gate			print "create alternative dependency mappingings.\n";
3577c478bd9Sstevel@tonic-gate			print "ldd: option added under 4390308 (s81_30).\n\n";
3587c478bd9Sstevel@tonic-gate		} else {
3597c478bd9Sstevel@tonic-gate			# Gather dependencies and construct a alternative
3607c478bd9Sstevel@tonic-gate			# dependency mapping via a crle(1) configuration file.
3617c478bd9Sstevel@tonic-gate			GetDeps($Proto, "/");
3627c478bd9Sstevel@tonic-gate			GenConf();
3637c478bd9Sstevel@tonic-gate		}
3647c478bd9Sstevel@tonic-gate	}
3657c478bd9Sstevel@tonic-gate
3667c478bd9Sstevel@tonic-gate	# To support unreferenced dependency detection we'll need ldd(1)'s -U
3677c478bd9Sstevel@tonic-gate	# option.  This is relatively new (4638070), and if not available we
3687c478bd9Sstevel@tonic-gate	# can still fall back to -u.  Even with this option, don't use -U with
3697c478bd9Sstevel@tonic-gate	# releases prior to 5.10 as the cleanup for -U use only got integrated
3707c478bd9Sstevel@tonic-gate	# into 5.10 under 4642023.  Note, that nightly doesn't typically set a
3717c478bd9Sstevel@tonic-gate	# RELEASE from the standard <env> files.  Users who wish to disable use
3727c478bd9Sstevel@tonic-gate	# of ldd(1)'s -U should set (or uncomment) RELEASE in their <env> file
3737c478bd9Sstevel@tonic-gate	# if using nightly, or otherwise establish it in their environment.
3747c478bd9Sstevel@tonic-gate	if (system('ldd -U /usr/lib/lddstub 2> /dev/null')) {
3757c478bd9Sstevel@tonic-gate		$LddNoU = 1;
3767c478bd9Sstevel@tonic-gate	} else {
3777c478bd9Sstevel@tonic-gate		my($Release);
3787c478bd9Sstevel@tonic-gate
3797c478bd9Sstevel@tonic-gate		if (($Release = $ENV{RELEASE}) &&
3807c478bd9Sstevel@tonic-gate		    (cmp_os_ver($Release, "<", "5.10"))) {
3817c478bd9Sstevel@tonic-gate			$LddNoU = 1;
3827c478bd9Sstevel@tonic-gate		} else {
3837c478bd9Sstevel@tonic-gate			$LddNoU = 0;
3847c478bd9Sstevel@tonic-gate		}
3857c478bd9Sstevel@tonic-gate	}
3867c478bd9Sstevel@tonic-gate
3877c478bd9Sstevel@tonic-gate	# For each argument determine if we're dealing with a file or directory.
3887c478bd9Sstevel@tonic-gate	foreach my $Arg (@ARGV) {
3897c478bd9Sstevel@tonic-gate		# Ignore symbolic links.
3907c478bd9Sstevel@tonic-gate		if (-l $Arg) {
3917c478bd9Sstevel@tonic-gate			next;
3927c478bd9Sstevel@tonic-gate		}
3937c478bd9Sstevel@tonic-gate
3947c478bd9Sstevel@tonic-gate		if (!stat($Arg)) {
3957c478bd9Sstevel@tonic-gate			next;
3967c478bd9Sstevel@tonic-gate		}
3977c478bd9Sstevel@tonic-gate
3987c478bd9Sstevel@tonic-gate		# Process simple files.
3997c478bd9Sstevel@tonic-gate		if (-f _) {
4007c478bd9Sstevel@tonic-gate			my($RelPath) = $Arg;
4017c478bd9Sstevel@tonic-gate			my($File) = $Arg;
4027c478bd9Sstevel@tonic-gate			my($Secure) = 0;
4037c478bd9Sstevel@tonic-gate
4047c478bd9Sstevel@tonic-gate			$RelPath =~ s!^.*/!./!;
4057c478bd9Sstevel@tonic-gate			$File =~ s!^.*/!!;
4067c478bd9Sstevel@tonic-gate
4077c478bd9Sstevel@tonic-gate			if (-u _ || -g _) {
4087c478bd9Sstevel@tonic-gate				$Secure = 1;
4097c478bd9Sstevel@tonic-gate			}
4107c478bd9Sstevel@tonic-gate
4117c478bd9Sstevel@tonic-gate			ProcFile($Arg, $RelPath, $File, $Secure);
4127c478bd9Sstevel@tonic-gate			next;
4137c478bd9Sstevel@tonic-gate		}
4147c478bd9Sstevel@tonic-gate		# Process directories.
4157c478bd9Sstevel@tonic-gate		if (-d _) {
4167c478bd9Sstevel@tonic-gate			ProcDir($Arg, ".");
4177c478bd9Sstevel@tonic-gate			next;
4187c478bd9Sstevel@tonic-gate		}
4197c478bd9Sstevel@tonic-gate
4207c478bd9Sstevel@tonic-gate		print "$Arg is not a file or directory\n";
4217c478bd9Sstevel@tonic-gate		$Error = 1;
4227c478bd9Sstevel@tonic-gate	}
4237c478bd9Sstevel@tonic-gate
4247c478bd9Sstevel@tonic-gate	# Cleanup
4257c478bd9Sstevel@tonic-gate	CleanUp();
4267c478bd9Sstevel@tonic-gate}
4277c478bd9Sstevel@tonic-gate
4287c478bd9Sstevel@tonic-gate$Error = 0;
4297c478bd9Sstevel@tonic-gate
4304840e086Srie# Clean up any temporary files.
4317c478bd9Sstevel@tonic-gatesub CleanUp {
4327c478bd9Sstevel@tonic-gate	if ($Crle64) {
4337c478bd9Sstevel@tonic-gate		unlink $Crle64;
4347c478bd9Sstevel@tonic-gate	}
4357c478bd9Sstevel@tonic-gate	if ($Conf64) {
4367c478bd9Sstevel@tonic-gate		unlink $Conf64;
4377c478bd9Sstevel@tonic-gate	}
4387c478bd9Sstevel@tonic-gate	if ($Crle32) {
4397c478bd9Sstevel@tonic-gate		unlink $Crle32;
4407c478bd9Sstevel@tonic-gate	}
4417c478bd9Sstevel@tonic-gate	if ($Conf32) {
4427c478bd9Sstevel@tonic-gate		unlink $Conf32;
4437c478bd9Sstevel@tonic-gate	}
4447c478bd9Sstevel@tonic-gate}
4457c478bd9Sstevel@tonic-gate
4467c478bd9Sstevel@tonic-gate# Create an output message, either a one-liner (under -o) or preceded by the
4477c478bd9Sstevel@tonic-gate# files relative pathname as a title.
4487c478bd9Sstevel@tonic-gatesub OutMsg {
4497c478bd9Sstevel@tonic-gate	my($Ttl, $Path, $Msg) = @_;
4507c478bd9Sstevel@tonic-gate
4517c478bd9Sstevel@tonic-gate	if ($opt{o}) {
4527c478bd9Sstevel@tonic-gate		$Msg =~ s/^[ \t]*//;
4537c478bd9Sstevel@tonic-gate		print "$Path: $Msg\n";
4547c478bd9Sstevel@tonic-gate	} else {
4557c478bd9Sstevel@tonic-gate		if ($Ttl eq 0) {
4567c478bd9Sstevel@tonic-gate			print "==== $Path ====\n";
4577c478bd9Sstevel@tonic-gate		}
4587c478bd9Sstevel@tonic-gate		print "$Msg\n";
4597c478bd9Sstevel@tonic-gate	}
4607c478bd9Sstevel@tonic-gate}
4617c478bd9Sstevel@tonic-gate
4627c478bd9Sstevel@tonic-gate# Determine whether this a ELF dynamic object and if so investigate its runtime
4637c478bd9Sstevel@tonic-gate# attributes.
4647c478bd9Sstevel@tonic-gatesub ProcFile {
4657c478bd9Sstevel@tonic-gate	my($FullPath, $RelPath, $File, $Secure) = @_;
4667c478bd9Sstevel@tonic-gate	my(@Elf, @Ldd, $Dyn, $Intp, $Dll, $Ttl, $Sym, $Interp, $Stack);
46767e3a03eSrie	my($Sun, $Relsz, $Pltsz, $Tex, $Stab, $Strip, $Lddopt, $SymSort);
46867e3a03eSrie	my($Val, $Header, $SkipLdd, $IsX86, $RWX, $UnDep);
469*bfed486aSAli Bahrami	my($HasDirectBinding, $HasVerdef);
4707c478bd9Sstevel@tonic-gate
4717c478bd9Sstevel@tonic-gate	# Ignore symbolic links.
4727c478bd9Sstevel@tonic-gate	if (-l $FullPath) {
4737c478bd9Sstevel@tonic-gate		return;
4747c478bd9Sstevel@tonic-gate	}
4757c478bd9Sstevel@tonic-gate
4767c478bd9Sstevel@tonic-gate	$Ttl = 0;
4777c478bd9Sstevel@tonic-gate	@Ldd = 0;
4787c478bd9Sstevel@tonic-gate
4797c478bd9Sstevel@tonic-gate	# Determine whether we have access to inspect the file.
4807c478bd9Sstevel@tonic-gate	if (!(-r $FullPath)) {
4817c478bd9Sstevel@tonic-gate		OutMsg($Ttl++, $RelPath,
4827c478bd9Sstevel@tonic-gate		    "\tunable to inspect file: permission denied");
4837c478bd9Sstevel@tonic-gate		return;
4847c478bd9Sstevel@tonic-gate	}
4857c478bd9Sstevel@tonic-gate
4867c478bd9Sstevel@tonic-gate	# Determine if this is a file we don't care about.
4877c478bd9Sstevel@tonic-gate	if (!$opt{a}) {
4887c478bd9Sstevel@tonic-gate		if ($File =~ $SkipFiles) {
4897c478bd9Sstevel@tonic-gate			return;
4907c478bd9Sstevel@tonic-gate		}
4917c478bd9Sstevel@tonic-gate	}
4927c478bd9Sstevel@tonic-gate
4937c478bd9Sstevel@tonic-gate	# Determine whether we have a executable (static or dynamic) or a
4947c478bd9Sstevel@tonic-gate	# shared object.
495*bfed486aSAli Bahrami	@Elf = split(/\n/, `elfdump -epdicyv $FullPath 2>&1`);
4967c478bd9Sstevel@tonic-gate
4977c478bd9Sstevel@tonic-gate	$Dyn = $Intp = $Dll = $Stack = $IsX86 = $RWX = 0;
4987c478bd9Sstevel@tonic-gate	$Interp = 1;
4997c478bd9Sstevel@tonic-gate	$Header = 'None';
5007c478bd9Sstevel@tonic-gate	foreach my $Line (@Elf) {
5017c478bd9Sstevel@tonic-gate		# If we have an invalid file type (which we can tell from the
5027c478bd9Sstevel@tonic-gate		# first line), or we're processing an archive, bail.
5037c478bd9Sstevel@tonic-gate		if ($Header eq 'None') {
5047c478bd9Sstevel@tonic-gate			if (($Line =~ /invalid file/) ||
5057c478bd9Sstevel@tonic-gate			    ($Line =~ /$FullPath(.*):/)) {
5067c478bd9Sstevel@tonic-gate				return;
5077c478bd9Sstevel@tonic-gate			}
5087c478bd9Sstevel@tonic-gate		}
5097c478bd9Sstevel@tonic-gate
5107c478bd9Sstevel@tonic-gate		if ($Line =~ /^ELF Header/) {
5117c478bd9Sstevel@tonic-gate			$Header = 'Ehdr';
5127c478bd9Sstevel@tonic-gate
5137c478bd9Sstevel@tonic-gate		} elsif ($Line =~ /^Program Header/) {
5147c478bd9Sstevel@tonic-gate			$Header = 'Phdr';
5157c478bd9Sstevel@tonic-gate			$RWX = 0;
5167c478bd9Sstevel@tonic-gate
5177c478bd9Sstevel@tonic-gate		} elsif ($Line =~ /^Interpreter/) {
5187c478bd9Sstevel@tonic-gate			$Header = 'Intp';
5197c478bd9Sstevel@tonic-gate
5207c478bd9Sstevel@tonic-gate		} elsif ($Line =~ /^Dynamic Section/) {
5217c478bd9Sstevel@tonic-gate			# A dynamic section indicates we're a dynamic object
5227c478bd9Sstevel@tonic-gate			# (this makes sure we don't check static executables).
5237c478bd9Sstevel@tonic-gate			$Dyn = 1;
5247c478bd9Sstevel@tonic-gate
5257c478bd9Sstevel@tonic-gate		} elsif (($Header eq 'Ehdr') && ($Line =~ /e_type:/)) {
5267c478bd9Sstevel@tonic-gate			# The e_type field indicates whether this file is a
5277c478bd9Sstevel@tonic-gate			# shared object (ET_DYN) or an executable (ET_EXEC).
5287c478bd9Sstevel@tonic-gate			if ($Line =~ /ET_DYN/) {
5297c478bd9Sstevel@tonic-gate				$Dll = 1;
5307c478bd9Sstevel@tonic-gate			} elsif ($Line !~ /ET_EXEC/) {
5317c478bd9Sstevel@tonic-gate				return;
5327c478bd9Sstevel@tonic-gate			}
5337c478bd9Sstevel@tonic-gate		} elsif (($Header eq 'Ehdr') && ($Line =~ /ei_class:/)) {
5347c478bd9Sstevel@tonic-gate			# If we encounter a 64-bit object, but we're not running
5357c478bd9Sstevel@tonic-gate			# on a 64-bit system, suppress calling ldd(1).
5367c478bd9Sstevel@tonic-gate			if (($Line =~ /ELFCLASS64/) && !$Ena64) {
5377c478bd9Sstevel@tonic-gate				$SkipLdd = 1;
5387c478bd9Sstevel@tonic-gate			}
5397c478bd9Sstevel@tonic-gate		} elsif (($Header eq 'Ehdr') && ($Line =~ /e_machine:/)) {
5407c478bd9Sstevel@tonic-gate			# If it's a X86 object, we need to enforce RW- data.
5417c478bd9Sstevel@tonic-gate			if (($Line =~ /(EM_AMD64|EM_386)/)) {
5427c478bd9Sstevel@tonic-gate				$IsX86 = 1;
5437c478bd9Sstevel@tonic-gate			}
5447c478bd9Sstevel@tonic-gate		} elsif (($Header eq 'Phdr') &&
5457c478bd9Sstevel@tonic-gate		    ($Line =~ /\[ PF_X  PF_W  PF_R \]/)) {
5467c478bd9Sstevel@tonic-gate			# RWX segment seen.
5477c478bd9Sstevel@tonic-gate			$RWX = 1;
5487c478bd9Sstevel@tonic-gate
5497c478bd9Sstevel@tonic-gate		} elsif (($Header eq 'Phdr') &&
5507c478bd9Sstevel@tonic-gate		    ($Line =~ /\[ PT_LOAD \]/ && $RWX && $IsX86)) {
5517c478bd9Sstevel@tonic-gate			# Seen an RWX PT_LOAD segment.
5527c478bd9Sstevel@tonic-gate			if ($File !~ $SkipNoExStkFiles) {
5537c478bd9Sstevel@tonic-gate				OutMsg($Ttl++, $RelPath,
5547c478bd9Sstevel@tonic-gate				    "\tapplication requires non-executable " .
5557c478bd9Sstevel@tonic-gate				    "data\t<no -Mmapfile_noexdata?>");
5567c478bd9Sstevel@tonic-gate			}
5577c478bd9Sstevel@tonic-gate
5587c478bd9Sstevel@tonic-gate		} elsif (($Header eq 'Phdr') &&
5597c478bd9Sstevel@tonic-gate		    ($Line =~ /\[ PT_SUNWSTACK \]/)) {
5607c478bd9Sstevel@tonic-gate			# This object defines a non-executable stack.
5617c478bd9Sstevel@tonic-gate			$Stack = 1;
5627c478bd9Sstevel@tonic-gate
5637c478bd9Sstevel@tonic-gate		} elsif (($Header eq 'Intp') && !$opt{a} &&
5647c478bd9Sstevel@tonic-gate		    ($Line =~ $SkipInterps)) {
5657c478bd9Sstevel@tonic-gate			# This object defines an interpretor we should skip.
5667c478bd9Sstevel@tonic-gate			$Interp = 0;
5677c478bd9Sstevel@tonic-gate		}
5687c478bd9Sstevel@tonic-gate	}
5697c478bd9Sstevel@tonic-gate
5707c478bd9Sstevel@tonic-gate	# Determine whether this ELF executable or shared object has a
5717c478bd9Sstevel@tonic-gate	# conforming mcs(1) comment section.  If the correct $(POST_PROCESS)
5727c478bd9Sstevel@tonic-gate	# macros are used, only a 3 or 4 line .comment section should exist
5737c478bd9Sstevel@tonic-gate	# containing one or two "@(#)SunOS" identifying comments (one comment
5747c478bd9Sstevel@tonic-gate	# for a non-debug build, and two for a debug build). The results of
5757c478bd9Sstevel@tonic-gate	# the following split should be three or four lines, the last empty
5767c478bd9Sstevel@tonic-gate	# line being discarded by the split.
5777c478bd9Sstevel@tonic-gate	if ($opt{m}) {
5787c478bd9Sstevel@tonic-gate		my(@Mcs, $Con, $Dev);
5797c478bd9Sstevel@tonic-gate
5807c478bd9Sstevel@tonic-gate		@Mcs = split(/\n/, `mcs -p $FullPath 2>&1`);
5817c478bd9Sstevel@tonic-gate
5827c478bd9Sstevel@tonic-gate		$Con = $Dev = $Val = 0;
5837c478bd9Sstevel@tonic-gate		foreach my $Line (@Mcs) {
5847c478bd9Sstevel@tonic-gate			$Val++;
5857c478bd9Sstevel@tonic-gate
5867c478bd9Sstevel@tonic-gate			if (($Val == 3) && ($Line !~ /^@\(#\)SunOS/)) {
5877c478bd9Sstevel@tonic-gate				$Con = 1;
5887c478bd9Sstevel@tonic-gate				last;
5897c478bd9Sstevel@tonic-gate			}
5907c478bd9Sstevel@tonic-gate			if (($Val == 4) && ($Line =~ /^@\(#\)SunOS/)) {
5917c478bd9Sstevel@tonic-gate				$Dev = 1;
5927c478bd9Sstevel@tonic-gate				next;
5937c478bd9Sstevel@tonic-gate			}
5947c478bd9Sstevel@tonic-gate			if (($Dev == 0) && ($Val == 4)) {
5957c478bd9Sstevel@tonic-gate				$Con = 1;
5967c478bd9Sstevel@tonic-gate				last;
5977c478bd9Sstevel@tonic-gate			}
5987c478bd9Sstevel@tonic-gate			if (($Dev == 1) && ($Val == 5)) {
5997c478bd9Sstevel@tonic-gate				$Con = 1;
6007c478bd9Sstevel@tonic-gate				last;
6017c478bd9Sstevel@tonic-gate			}
6027c478bd9Sstevel@tonic-gate		}
6037c478bd9Sstevel@tonic-gate		if ($opt{m} && ($Con == 1)) {
6047c478bd9Sstevel@tonic-gate			OutMsg($Ttl++, $RelPath,
6057c478bd9Sstevel@tonic-gate			    "\tnon-conforming mcs(1) comment\t<no \$(POST_PROCESS)?>");
6067c478bd9Sstevel@tonic-gate		}
6077c478bd9Sstevel@tonic-gate	}
6087c478bd9Sstevel@tonic-gate
6097c478bd9Sstevel@tonic-gate	# Applications should contain a non-executable stack definition.
6107c478bd9Sstevel@tonic-gate	if (($Dll == 0) && ($Stack == 0)) {
6117c478bd9Sstevel@tonic-gate		if (!$opt{a}) {
6127c478bd9Sstevel@tonic-gate			if ($File =~ $SkipNoExStkFiles) {
6137c478bd9Sstevel@tonic-gate				goto DYN;
6147c478bd9Sstevel@tonic-gate			}
6157c478bd9Sstevel@tonic-gate		}
6167c478bd9Sstevel@tonic-gate		OutMsg($Ttl++, $RelPath,
6177c478bd9Sstevel@tonic-gate		    "\tapplication requires non-executable stack\t<no -Mmapfile_noexstk?>");
6187c478bd9Sstevel@tonic-gate	}
6197c478bd9Sstevel@tonic-gate
6207c478bd9Sstevel@tonic-gateDYN:
6217c478bd9Sstevel@tonic-gate	# Having caught any static executables in the mcs(1) check and non-
6227c478bd9Sstevel@tonic-gate	# executable stack definition check, continue with dynamic objects
6237c478bd9Sstevel@tonic-gate	# from now on.
6247c478bd9Sstevel@tonic-gate	if ($Dyn eq 0) {
6257c478bd9Sstevel@tonic-gate		return;
6267c478bd9Sstevel@tonic-gate	}
6277c478bd9Sstevel@tonic-gate
6287c478bd9Sstevel@tonic-gate	# Only use ldd unless we've encountered an interpreter that should
6294840e086Srie	# be skipped.
6307c478bd9Sstevel@tonic-gate	if (!$SkipLdd && $Interp) {
631976d55c9Sab196087		my $LDDFullPath = $FullPath;
632976d55c9Sab196087
6337c478bd9Sstevel@tonic-gate		if ($Secure) {
6347c478bd9Sstevel@tonic-gate			# The execution of a secure application over an nfs file
6357c478bd9Sstevel@tonic-gate			# system mounted nosuid will result in warning messages
6367c478bd9Sstevel@tonic-gate			# being sent to /var/adm/messages.  As this type of
6377c478bd9Sstevel@tonic-gate			# environment can occur with root builds, move the file
6387c478bd9Sstevel@tonic-gate			# being investigated to a safe place first.  In addition
6397c478bd9Sstevel@tonic-gate			# remove its secure permission so that it can be
6407c478bd9Sstevel@tonic-gate			# influenced by any alternative dependency mappings.
6417c478bd9Sstevel@tonic-gate
6427c478bd9Sstevel@tonic-gate			my($TmpPath) = "$Tmpdir/$File";
6437c478bd9Sstevel@tonic-gate
644976d55c9Sab196087			system('cp', $LDDFullPath, $TmpPath);
6457c478bd9Sstevel@tonic-gate			chmod 0777, $TmpPath;
646976d55c9Sab196087			$LDDFullPath = $TmpPath;
6477c478bd9Sstevel@tonic-gate		}
6487c478bd9Sstevel@tonic-gate
6497c478bd9Sstevel@tonic-gate		# Use ldd(1) to determine the objects relocatability and use.
6507c478bd9Sstevel@tonic-gate		# By default look for all unreferenced dependencies.  However,
6517c478bd9Sstevel@tonic-gate		# some objects have legitimate dependencies that they do not
6527c478bd9Sstevel@tonic-gate		# reference.
65367e3a03eSrie		if ($LddNoU || ($RelPath =~ $UnusedPaths)) {
6547c478bd9Sstevel@tonic-gate			$Lddopt = "-ru";
6557c478bd9Sstevel@tonic-gate		} else {
6567c478bd9Sstevel@tonic-gate			$Lddopt = "-rU";
6577c478bd9Sstevel@tonic-gate		}
658976d55c9Sab196087		@Ldd = split(/\n/, `ldd $Lddopt $Env $LDDFullPath 2>&1`);
6597c478bd9Sstevel@tonic-gate		if ($Secure) {
660976d55c9Sab196087			unlink $LDDFullPath;
6617c478bd9Sstevel@tonic-gate		}
6627c478bd9Sstevel@tonic-gate	}
6637c478bd9Sstevel@tonic-gate
6647c478bd9Sstevel@tonic-gate	$Val = 0;
6657c478bd9Sstevel@tonic-gate	$Sym = 5;
66667e3a03eSrie	$UnDep = 1;
6677c478bd9Sstevel@tonic-gate
66867e3a03eSrie	foreach my $Line (@Ldd) {
6697c478bd9Sstevel@tonic-gate
6707c478bd9Sstevel@tonic-gate		if ($Val == 0) {
6717c478bd9Sstevel@tonic-gate			$Val = 1;
6727c478bd9Sstevel@tonic-gate			# Make sure ldd(1) worked.  One possible failure is that
6737c478bd9Sstevel@tonic-gate			# this is an old ldd(1) prior to -e addition (4390308).
6747c478bd9Sstevel@tonic-gate			if ($Line =~ /usage:/) {
6757c478bd9Sstevel@tonic-gate				$Line =~ s/$/\t<old ldd(1)?>/;
6767c478bd9Sstevel@tonic-gate				OutMsg($Ttl++, $RelPath, $Line);
6777c478bd9Sstevel@tonic-gate				last;
6787c478bd9Sstevel@tonic-gate			} elsif ($Line =~ /execution failed/) {
6797c478bd9Sstevel@tonic-gate				OutMsg($Ttl++, $RelPath, $Line);
6807c478bd9Sstevel@tonic-gate				last;
6817c478bd9Sstevel@tonic-gate			}
6827c478bd9Sstevel@tonic-gate
6837c478bd9Sstevel@tonic-gate			# It's possible this binary can't be executed, ie. we've
6847c478bd9Sstevel@tonic-gate			# found a sparc binary while running on an intel system,
6857c478bd9Sstevel@tonic-gate			# or a sparcv9 binary on a sparcv7/8 system.
6867c478bd9Sstevel@tonic-gate			if ($Line =~ /wrong class/) {
6877c478bd9Sstevel@tonic-gate				OutMsg($Ttl++, $RelPath,
6887c478bd9Sstevel@tonic-gate				    "\thas wrong class or data encoding");
6897c478bd9Sstevel@tonic-gate				next;
6907c478bd9Sstevel@tonic-gate			}
6917c478bd9Sstevel@tonic-gate
6927c478bd9Sstevel@tonic-gate			# Historically, ldd(1) likes executable objects to have
6937c478bd9Sstevel@tonic-gate			# their execute bit set.  Note that this test isn't
6947c478bd9Sstevel@tonic-gate			# applied unless the -a option is in effect, as any
6957c478bd9Sstevel@tonic-gate			# non-executable files are skipped by default to reduce
6967c478bd9Sstevel@tonic-gate			# the cost of running this script.
6977c478bd9Sstevel@tonic-gate			if ($Line =~ /not executable/) {
6987c478bd9Sstevel@tonic-gate				OutMsg($Ttl++, $RelPath,
6997c478bd9Sstevel@tonic-gate				    "\tis not executable");
7007c478bd9Sstevel@tonic-gate				next;
7017c478bd9Sstevel@tonic-gate			}
7027c478bd9Sstevel@tonic-gate		}
7037c478bd9Sstevel@tonic-gate
7047c478bd9Sstevel@tonic-gate		# Look for "file" or "versions" that aren't found.  Note that
7057c478bd9Sstevel@tonic-gate		# these lines will occur before we find any symbol referencing
7067c478bd9Sstevel@tonic-gate		# errors.
7077c478bd9Sstevel@tonic-gate		if (($Sym == 5) && ($Line =~ /not found\)/)) {
7087c478bd9Sstevel@tonic-gate			if ($Line =~ /file not found\)/) {
7097c478bd9Sstevel@tonic-gate				$Line =~ s/$/\t<no -zdefs?>/;
7107c478bd9Sstevel@tonic-gate			}
7117c478bd9Sstevel@tonic-gate			OutMsg($Ttl++, $RelPath, $Line);
7127c478bd9Sstevel@tonic-gate			next;
7137c478bd9Sstevel@tonic-gate		}
7147c478bd9Sstevel@tonic-gate		# Look for relocations whose symbols can't be found.  Note, we
7157c478bd9Sstevel@tonic-gate		# only print out the first 5 relocations for any file as this
7167c478bd9Sstevel@tonic-gate		# output can be excessive.
7177c478bd9Sstevel@tonic-gate		if ($Sym && ($Line =~ /symbol not found/)) {
7187c478bd9Sstevel@tonic-gate			# Determine if this file is allowed undefined
7197c478bd9Sstevel@tonic-gate			# references.
7207c478bd9Sstevel@tonic-gate			if ($Sym == 5) {
7217c478bd9Sstevel@tonic-gate				if (!$opt{a}) {
7227c478bd9Sstevel@tonic-gate					if ($File =~ $SkipUndefFiles) {
7237c478bd9Sstevel@tonic-gate						$Sym = 0;
72467e3a03eSrie						next;
7257c478bd9Sstevel@tonic-gate					}
7267c478bd9Sstevel@tonic-gate				}
7277c478bd9Sstevel@tonic-gate			}
7287c478bd9Sstevel@tonic-gate			if ($Sym-- == 1) {
7297c478bd9Sstevel@tonic-gate				if (!$opt{o}) {
7307c478bd9Sstevel@tonic-gate					OutMsg($Ttl++, $RelPath,
7317c478bd9Sstevel@tonic-gate					    "\tcontinued ...");
7327c478bd9Sstevel@tonic-gate				}
7337c478bd9Sstevel@tonic-gate				next;
7347c478bd9Sstevel@tonic-gate			}
7357c478bd9Sstevel@tonic-gate			# Just print the symbol name.
7367c478bd9Sstevel@tonic-gate			$Line =~ s/$/\t<no -zdefs?>/;
7377c478bd9Sstevel@tonic-gate			OutMsg($Ttl++, $RelPath, $Line);
7387c478bd9Sstevel@tonic-gate			next;
7397c478bd9Sstevel@tonic-gate		}
74067e3a03eSrie		# Look for any unused search paths.
74167e3a03eSrie		if ($Line =~ /unused search path=/) {
742d89524d0Srie			# Note, skip this comparison for __GNUC builds, as the
743d89524d0Srie			# gnu compilers insert numerous unused search paths.
744d89524d0Srie			if ($Gnuc == 1) {
745d89524d0Srie				next;
746d89524d0Srie			}
74767e3a03eSrie			if (!$opt{a}) {
74867e3a03eSrie				if ($Line =~ $SkipUnusedSearchPath) {
74967e3a03eSrie					next;
75067e3a03eSrie				}
75167e3a03eSrie			}
75267e3a03eSrie			if ($Secure) {
75367e3a03eSrie				$Line =~ s!$Tmpdir/!!;
75467e3a03eSrie			}
75567e3a03eSrie			$Line =~ s/^[ \t]*(.*)/\t$1\t<remove search path?>/;
75667e3a03eSrie			OutMsg($Ttl++, $RelPath, $Line);
75767e3a03eSrie			next;
75867e3a03eSrie		}
75967e3a03eSrie		# Look for unreferenced dependencies.  Note, if any unreferenced
76067e3a03eSrie		# objects are ignored, then set $UnDep so as to suppress any
76167e3a03eSrie		# associated unused-object messages.
76267e3a03eSrie		if ($Line =~ /unreferenced object=/) {
76367e3a03eSrie			if (!$opt{a}) {
76467e3a03eSrie				if ($Line =~ $SkipUnrefObject) {
76567e3a03eSrie					$UnDep = 0;
76667e3a03eSrie					next;
76767e3a03eSrie				}
76867e3a03eSrie			}
76967e3a03eSrie			if ($Secure) {
77067e3a03eSrie				$Line =~ s!$Tmpdir/!!;
77167e3a03eSrie			}
77267e3a03eSrie			$Line =~ s/^[ \t]*(.*)/\t$1\t<remove lib or -zignore?>/;
77367e3a03eSrie			OutMsg($Ttl++, $RelPath, $Line);
77467e3a03eSrie			next;
77567e3a03eSrie		}
7767c478bd9Sstevel@tonic-gate		# Look for any unused dependencies.
77767e3a03eSrie		if ($UnDep && ($Line =~ /unused/)) {
7787c478bd9Sstevel@tonic-gate			if (!$opt{a}) {
7797c478bd9Sstevel@tonic-gate				if ($RelPath =~ $SkipUnusedDirs) {
78067e3a03eSrie					$UnDep = 0;
78167e3a03eSrie					next;
7827c478bd9Sstevel@tonic-gate				}
7837c478bd9Sstevel@tonic-gate			}
7847c478bd9Sstevel@tonic-gate			if ($Secure) {
7857c478bd9Sstevel@tonic-gate				$Line =~ s!$Tmpdir/!!;
7867c478bd9Sstevel@tonic-gate			}
7877c478bd9Sstevel@tonic-gate			$Line =~ s/^[ \t]*(.*)/\t$1\t<remove lib or -zignore?>/;
7887c478bd9Sstevel@tonic-gate			OutMsg($Ttl++, $RelPath, $Line);
7897c478bd9Sstevel@tonic-gate			next;
7907c478bd9Sstevel@tonic-gate		}
7917c478bd9Sstevel@tonic-gate	}
7927c478bd9Sstevel@tonic-gate
7937c478bd9Sstevel@tonic-gate	# Reuse the elfdump(1) data to investigate additional dynamic linking
7947c478bd9Sstevel@tonic-gate	# information.
7957c478bd9Sstevel@tonic-gate
796dfb96a4fSab196087	$Sun = $Relsz = $Pltsz = $Dyn = $Stab = $SymSort = 0;
7977c478bd9Sstevel@tonic-gate	$Tex = $Strip = 1;
798f6acbf7cSrie	$HasDirectBinding = 0;
799*bfed486aSAli Bahrami	$HasVerdef = 0;
8007c478bd9Sstevel@tonic-gate
8017c478bd9Sstevel@tonic-gate	$Header = 'None';
8027c478bd9Sstevel@tonic-gateELF:	foreach my $Line (@Elf) {
8037c478bd9Sstevel@tonic-gate		# We're only interested in the section headers and the dynamic
8047c478bd9Sstevel@tonic-gate		# section.
8057c478bd9Sstevel@tonic-gate		if ($Line =~ /^Section Header/) {
8067c478bd9Sstevel@tonic-gate			$Header = 'Shdr';
8077c478bd9Sstevel@tonic-gate
8087c478bd9Sstevel@tonic-gate			if (($Sun == 0) && ($Line =~ /\.SUNW_reloc/)) {
8097c478bd9Sstevel@tonic-gate				# This object has a combined relocation section.
8107c478bd9Sstevel@tonic-gate				$Sun = 1;
8117c478bd9Sstevel@tonic-gate
8127c478bd9Sstevel@tonic-gate			} elsif (($Stab == 0) && ($Line =~ /\.stab/)) {
8137c478bd9Sstevel@tonic-gate				# This object contain .stabs sections
8147c478bd9Sstevel@tonic-gate				$Stab = 1;
815dfb96a4fSab196087			} elsif (($SymSort == 0) &&
816dfb96a4fSab196087				 ($Line =~ /\.SUNW_dyn(sym)|(tls)sort/)) {
817dfb96a4fSab196087				# This object contains a symbol sort section
818dfb96a4fSab196087				$SymSort = 1;
8197c478bd9Sstevel@tonic-gate			}
8207c478bd9Sstevel@tonic-gate
8217c478bd9Sstevel@tonic-gate			if (($Strip == 1) && ($Line =~ /\.symtab/)) {
8227c478bd9Sstevel@tonic-gate				# This object contains a complete symbol table.
8237c478bd9Sstevel@tonic-gate				$Strip = 0;
8247c478bd9Sstevel@tonic-gate			}
8257c478bd9Sstevel@tonic-gate			next;
8267c478bd9Sstevel@tonic-gate
8277c478bd9Sstevel@tonic-gate		} elsif ($Line =~ /^Dynamic Section/) {
8287c478bd9Sstevel@tonic-gate			$Header = 'Dyn';
8297c478bd9Sstevel@tonic-gate			next;
830f6acbf7cSrie		} elsif ($Line =~ /^Syminfo Section/) {
831f6acbf7cSrie			$Header = 'Syminfo';
832f6acbf7cSrie			next;
833*bfed486aSAli Bahrami		} elsif ($Line =~ /^Version Definition Section/) {
834*bfed486aSAli Bahrami			$HasVerdef = 1;
835*bfed486aSAli Bahrami			next;
836f6acbf7cSrie		} elsif (($Header ne 'Dyn') && ($Header ne 'Syminfo')) {
837f6acbf7cSrie			next;
838f6acbf7cSrie		}
839f6acbf7cSrie
840f6acbf7cSrie		# Look into the Syminfo section.
841f6acbf7cSrie		# Does this object have at least one Directly Bound symbol?
842f6acbf7cSrie		if (($Header eq 'Syminfo')) {
843f6acbf7cSrie			my(@Symword);
844f6acbf7cSrie
845f6acbf7cSrie			if ($HasDirectBinding == 1) {
846f6acbf7cSrie				next;
847f6acbf7cSrie			}
848f6acbf7cSrie
849f6acbf7cSrie			@Symword = split(' ', $Line);
850f6acbf7cSrie
851f6acbf7cSrie			if (!defined($Symword[1])) {
852f6acbf7cSrie				next;
853f6acbf7cSrie			}
854f6acbf7cSrie			if ($Symword[1] =~ /B/) {
855f6acbf7cSrie				$HasDirectBinding = 1;
856f6acbf7cSrie			}
8577c478bd9Sstevel@tonic-gate			next;
8587c478bd9Sstevel@tonic-gate		}
8597c478bd9Sstevel@tonic-gate
8607c478bd9Sstevel@tonic-gate		# Does this object contain text relocations.
8617c478bd9Sstevel@tonic-gate		if ($Tex && ($Line =~ /TEXTREL/)) {
8627c478bd9Sstevel@tonic-gate			# Determine if this file is allowed text relocations.
8637c478bd9Sstevel@tonic-gate			if (!$opt{a}) {
8647c478bd9Sstevel@tonic-gate				if ($File =~ $SkipTextrelFiles) {
8657c478bd9Sstevel@tonic-gate					$Tex = 0;
8667c478bd9Sstevel@tonic-gate					next ELF;
8677c478bd9Sstevel@tonic-gate				}
8687c478bd9Sstevel@tonic-gate			}
8697c478bd9Sstevel@tonic-gate			OutMsg($Ttl++, $RelPath,
8707c478bd9Sstevel@tonic-gate			    "\tTEXTREL .dynamic tag\t\t\t<no -Kpic?>");
8717c478bd9Sstevel@tonic-gate			$Tex = 0;
8727c478bd9Sstevel@tonic-gate			next;
8737c478bd9Sstevel@tonic-gate		}
8747c478bd9Sstevel@tonic-gate
8757c478bd9Sstevel@tonic-gate		# Does this file have any relocation sections (there are a few
8767c478bd9Sstevel@tonic-gate		# psr libraries with no relocations at all, thus a .SUNW_reloc
8777c478bd9Sstevel@tonic-gate		# section won't exist either).
8787c478bd9Sstevel@tonic-gate		if (($Relsz == 0) && ($Line =~ / RELA?SZ/)) {
8797c478bd9Sstevel@tonic-gate			$Relsz = hex((split(' ', $Line))[2]);
8807c478bd9Sstevel@tonic-gate			next;
8817c478bd9Sstevel@tonic-gate		}
8827c478bd9Sstevel@tonic-gate
8837c478bd9Sstevel@tonic-gate		# Does this file have any plt relocations.  If the plt size is
8847c478bd9Sstevel@tonic-gate		# equivalent to the total relocation size then we don't have
8857c478bd9Sstevel@tonic-gate		# any relocations suitable for combining into a .SUNW_reloc
8867c478bd9Sstevel@tonic-gate		# section.
8877c478bd9Sstevel@tonic-gate		if (($Pltsz == 0) && ($Line =~ / PLTRELSZ/)) {
8887c478bd9Sstevel@tonic-gate			$Pltsz = hex((split(' ', $Line))[2]);
8897c478bd9Sstevel@tonic-gate			next;
8907c478bd9Sstevel@tonic-gate		}
8917c478bd9Sstevel@tonic-gate
8927c478bd9Sstevel@tonic-gate		# Does this object have any dependencies.
89367e3a03eSrie		if ($Line =~ /NEEDED/) {
8947c478bd9Sstevel@tonic-gate			my($Need) = (split(' ', $Line))[3];
8957c478bd9Sstevel@tonic-gate
8967c478bd9Sstevel@tonic-gate			if ($Need =~ $OldDeps) {
89767e3a03eSrie				# Catch any old (unnecessary) dependencies.
8987c478bd9Sstevel@tonic-gate				OutMsg($Ttl++, $RelPath,
8997c478bd9Sstevel@tonic-gate				    "\tNEEDED=$Need\t<dependency no longer necessary>");
90067e3a03eSrie			} elsif ($opt{i}) {
90167e3a03eSrie				# Under the -i (information) option print out
90267e3a03eSrie				# any useful dynamic entries.
9037c478bd9Sstevel@tonic-gate				OutMsg($Ttl++, $RelPath, "\tNEEDED=$Need");
9047c478bd9Sstevel@tonic-gate			}
9057c478bd9Sstevel@tonic-gate			next;
9067c478bd9Sstevel@tonic-gate		}
9077c478bd9Sstevel@tonic-gate
908f6acbf7cSrie		# Is this object built with -B direct flag on?
909f6acbf7cSrie		if ($Line =~ / DIRECT /) {
910f6acbf7cSrie			$HasDirectBinding = 1;
911f6acbf7cSrie		}
912f6acbf7cSrie
9137c478bd9Sstevel@tonic-gate		# Does this object specify a runpath.
9147c478bd9Sstevel@tonic-gate		if ($opt{i} && ($Line =~ /RPATH/)) {
9157c478bd9Sstevel@tonic-gate			my($Rpath) = (split(' ', $Line))[3];
9167c478bd9Sstevel@tonic-gate			OutMsg($Ttl++, $RelPath, "\tRPATH=$Rpath");
9177c478bd9Sstevel@tonic-gate			next;
9187c478bd9Sstevel@tonic-gate		}
9197c478bd9Sstevel@tonic-gate	}
9207c478bd9Sstevel@tonic-gate
9217c478bd9Sstevel@tonic-gate	# A shared object, that contains non-plt relocations, should have a
9227c478bd9Sstevel@tonic-gate	# combined relocation section indicating it was built with -z combreloc.
9237c478bd9Sstevel@tonic-gate	if ($Dll && $Relsz && ($Relsz != $Pltsz) && ($Sun == 0)) {
9247c478bd9Sstevel@tonic-gate		OutMsg($Ttl++, $RelPath,
9257c478bd9Sstevel@tonic-gate		    "\tSUNW_reloc section missing\t\t<no -zcombreloc?>");
9267c478bd9Sstevel@tonic-gate	}
9277c478bd9Sstevel@tonic-gate
9287c478bd9Sstevel@tonic-gate	# No objects released to a customer should have any .stabs sections
9297c478bd9Sstevel@tonic-gate	# remaining, they should be stripped.
9307c478bd9Sstevel@tonic-gate	if ($opt{s} && $Stab) {
9317c478bd9Sstevel@tonic-gate		if (!$opt{a}) {
9327c478bd9Sstevel@tonic-gate			if ($File =~ $SkipStabFiles) {
9337c478bd9Sstevel@tonic-gate				goto DONESTAB;
9347c478bd9Sstevel@tonic-gate			}
9357c478bd9Sstevel@tonic-gate		}
9367c478bd9Sstevel@tonic-gate		OutMsg($Ttl++, $RelPath,
9378ad60789Srie		    "\tdebugging sections should be deleted\t<no strip -x?>");
9387c478bd9Sstevel@tonic-gate	}
9397c478bd9Sstevel@tonic-gate
940f6acbf7cSrie	# Identify an object that is not built with either -B direct or
941f6acbf7cSrie	# -z direct.
942f6acbf7cSrie	if (($RelPath =~ $SkipDirectBindDirs) ||
943f6acbf7cSrie	    ($File =~ $SkipDirectBindFiles)) {
944f6acbf7cSrie		goto DONESTAB;
945f6acbf7cSrie	}
946f6acbf7cSrie	if ($Relsz && ($HasDirectBinding == 0)) {
947f6acbf7cSrie		OutMsg($Ttl++, $RelPath,
948f6acbf7cSrie		    "\tobject has no direct bindings\t<no -B direct or -z direct?>");
949f6acbf7cSrie	}
950f6acbf7cSrie
9517c478bd9Sstevel@tonic-gateDONESTAB:
9527c478bd9Sstevel@tonic-gate
9538ad60789Srie	# All objects should have a full symbol table to provide complete
9547c478bd9Sstevel@tonic-gate	# debugging stack traces.
9558ad60789Srie	if ($Strip) {
9567c478bd9Sstevel@tonic-gate		OutMsg($Ttl++, $RelPath,
9577c478bd9Sstevel@tonic-gate		    "\tsymbol table should not be stripped\t<remove -s?>");
9587c478bd9Sstevel@tonic-gate	}
959dfb96a4fSab196087
960dfb96a4fSab196087	# If there are symbol sort sections in this object, report on
961dfb96a4fSab196087	# any that have duplicate addresses.
962dfb96a4fSab196087	ProcSymSort($FullPath, $RelPath, \$Ttl) if $SymSort;
963*bfed486aSAli Bahrami
964*bfed486aSAli Bahrami	# If -v was specified, and the object has a version definition
965*bfed486aSAli Bahrami	# section, generate output showing each public symbol and the
966*bfed486aSAli Bahrami	# version it belongs to.
967*bfed486aSAli Bahrami	ProcVerdef($FullPath, $RelPath, \$Ttl) if $HasVerdef && $opt{v};
968dfb96a4fSab196087}
969dfb96a4fSab196087
970dfb96a4fSab196087
971dfb96a4fSab196087## ProcSymSortOutMsg(RefTtl, RelPath, secname, addr, names...)
972dfb96a4fSab196087#
973dfb96a4fSab196087# Call OutMsg for a duplicate address error in a symbol sort
974dfb96a4fSab196087# section
975dfb96a4fSab196087#
976dfb96a4fSab196087sub ProcSymSortOutMsg {
977dfb96a4fSab196087	my($RefTtl, $RelPath, $secname, $addr, @names) = @_;
978dfb96a4fSab196087
979dfb96a4fSab196087	OutMsg($$RefTtl++, $RelPath,
980dfb96a4fSab196087	    "$secname: duplicate $addr: ". join(', ', @names));
981dfb96a4fSab196087}
982dfb96a4fSab196087
983dfb96a4fSab196087
984dfb96a4fSab196087## ProcSymSort(FullPath, RelPath)
985dfb96a4fSab196087#
986dfb96a4fSab196087# Examine the symbol sort sections for the given object and report
987dfb96a4fSab196087# on any duplicate addresses found.  Ideally, mapfile directives
988dfb96a4fSab196087# should be used when building objects that have multiple symbols
989dfb96a4fSab196087# with the same address so that only one of them appears in the sort
990dfb96a4fSab196087# section. This saves space, reduces user confusion, and ensures that
991dfb96a4fSab196087# libproc and debuggers always display public names instead of symbols
992dfb96a4fSab196087# that are merely implementation details.
993dfb96a4fSab196087#
994dfb96a4fSab196087sub ProcSymSort {
995dfb96a4fSab196087
996dfb96a4fSab196087	my($FullPath, $RelPath, $RefTtl) = @_;
997dfb96a4fSab196087
998dfb96a4fSab196087	# If this object is exempt from checking, return quietly
999dfb96a4fSab196087	return if ($FullPath =~ $SkipSymSort);
1000dfb96a4fSab196087
1001dfb96a4fSab196087
1002dfb96a4fSab196087	open(SORT, "elfdump -S $FullPath|") ||
1003dfb96a4fSab196087	    die "$Prog: Unable to execute elfdump (symbol sort sections)\n";
1004dfb96a4fSab196087
1005dfb96a4fSab196087	my $line;
1006dfb96a4fSab196087	my $last_addr;
1007dfb96a4fSab196087	my @dups = ();
1008dfb96a4fSab196087	my $secname;
1009dfb96a4fSab196087	while ($line = <SORT>) {
1010dfb96a4fSab196087		chomp $line;
1011dfb96a4fSab196087
1012dfb96a4fSab196087		next if ($line eq '');
1013dfb96a4fSab196087
1014dfb96a4fSab196087		# If this is a header line, pick up the section name
1015dfb96a4fSab196087		if ($line =~ /^Symbol Sort Section:\s+([^\s]+)\s+/) {
1016dfb96a4fSab196087			$secname = $1;
1017dfb96a4fSab196087
1018dfb96a4fSab196087			# Every new section is followed by a column header line
1019dfb96a4fSab196087			$line = <SORT>;		# Toss header line
1020dfb96a4fSab196087
1021dfb96a4fSab196087			# Flush anything left from previous section
1022dfb96a4fSab196087			ProcSymSortOutMsg($RefTtl, $RelPath, $secname,
1023dfb96a4fSab196087			    $last_addr, @dups) if (scalar(@dups) > 1);
1024dfb96a4fSab196087
1025dfb96a4fSab196087			# Reset variables for new sort section
1026dfb96a4fSab196087			$last_addr = '';
1027dfb96a4fSab196087			@dups = ();
1028dfb96a4fSab196087
1029dfb96a4fSab196087			next;
1030dfb96a4fSab196087		}
1031dfb96a4fSab196087
1032dfb96a4fSab196087		# Process symbol line
1033dfb96a4fSab196087		my @fields = split /\s+/, $line;
1034dfb96a4fSab196087		my $new_addr = $fields[2];
1035169e20d9SAli Bahrami		my $new_type = $fields[8];
1036dfb96a4fSab196087		my $new_name = $fields[9];
1037607c61fdSab196087
1038169e20d9SAli Bahrami		if ($new_type eq 'UNDEF') {
1039169e20d9SAli Bahrami		    OutMsg($RefTtl++, $RelPath,
1040169e20d9SAli Bahrami		        "$secname: unexpected UNDEF symbol " .
1041169e20d9SAli Bahrami			"(link-editor error): $new_name");
1042169e20d9SAli Bahrami		    next;
1043169e20d9SAli Bahrami		}
1044169e20d9SAli Bahrami
1045a854c1c1Sab196087		if ($new_addr eq $last_addr) {
1046dfb96a4fSab196087			push @dups, $new_name;
1047dfb96a4fSab196087		} else {
1048dfb96a4fSab196087			ProcSymSortOutMsg($RefTtl, $RelPath, $secname,
1049dfb96a4fSab196087			    $last_addr, @dups) if (scalar(@dups) > 1);
1050dfb96a4fSab196087			@dups = ( $new_name );
1051dfb96a4fSab196087			$last_addr = $new_addr;
1052dfb96a4fSab196087		}
1053dfb96a4fSab196087	}
1054dfb96a4fSab196087
1055dfb96a4fSab196087	ProcSymSortOutMsg($RefTtl, $RelPath, $secname, $last_addr, @dups)
1056dfb96a4fSab196087		if (scalar(@dups) > 1);
1057dfb96a4fSab196087
1058dfb96a4fSab196087	close SORT;
10597c478bd9Sstevel@tonic-gate}
10607c478bd9Sstevel@tonic-gate
10617c478bd9Sstevel@tonic-gate
1062*bfed486aSAli Bahrami## ProcVerdef(FullPath, RelPath)
1063*bfed486aSAli Bahrami#
1064*bfed486aSAli Bahrami# Examine the version definition section for the given object and report
1065*bfed486aSAli Bahrami# each public symbol along with the version it belongs to.
1066*bfed486aSAli Bahrami#
1067*bfed486aSAli Bahramisub ProcVerdef {
1068*bfed486aSAli Bahrami
1069*bfed486aSAli Bahrami	my($FullPath, $RelPath, $RefTtl) = @_;
1070*bfed486aSAli Bahrami	my $line;
1071*bfed486aSAli Bahrami	my $cur_ver = '';
1072*bfed486aSAli Bahrami	my $tab = $opt{o} ? '' : "\t";
1073*bfed486aSAli Bahrami
1074*bfed486aSAli Bahrami	# pvs -dov provides information about the versioning hierarchy
1075*bfed486aSAli Bahrami	# in the file. Lines are of the format:
1076*bfed486aSAli Bahrami	#	path - version[XXX];
1077*bfed486aSAli Bahrami	# where [XXX] indicates optional information, such as flags
1078*bfed486aSAli Bahrami	# or inherited versions.
1079*bfed486aSAli Bahrami	#
1080*bfed486aSAli Bahrami	# Private versions are allowed to change freely, so ignore them.
1081*bfed486aSAli Bahrami	open(PVS, "pvs -dov $FullPath|") ||
1082*bfed486aSAli Bahrami	    die "$Prog: Unable to execute pvs (version definition section)\n";
1083*bfed486aSAli Bahrami
1084*bfed486aSAli Bahrami	while ($line = <PVS>) {
1085*bfed486aSAli Bahrami		chomp $line;
1086*bfed486aSAli Bahrami
1087*bfed486aSAli Bahrami		if ($line =~ /^[^\s]+\s+-\s+([^;]+)/) {
1088*bfed486aSAli Bahrami			my $ver = $1;
1089*bfed486aSAli Bahrami
1090*bfed486aSAli Bahrami			next if $ver =~ /private/i;
1091*bfed486aSAli Bahrami			OutMsg($$RefTtl++, $RelPath, "${tab}VERDEF=$ver");
1092*bfed486aSAli Bahrami		}
1093*bfed486aSAli Bahrami	}
1094*bfed486aSAli Bahrami	close PVS;
1095*bfed486aSAli Bahrami
1096*bfed486aSAli Bahrami	# pvs -dos lists the symbols assigned to each version definition.
1097*bfed486aSAli Bahrami	# Lines are of the format:
1098*bfed486aSAli Bahrami	#	path - version: symbol;
1099*bfed486aSAli Bahrami	#	path - version: symbol (size);
1100*bfed486aSAli Bahrami	# where the (size) is added to data items, but not for functions.
1101*bfed486aSAli Bahrami	# We strip off the size, if present.
1102*bfed486aSAli Bahrami
1103*bfed486aSAli Bahrami	open(PVS, "pvs -dos $FullPath|") ||
1104*bfed486aSAli Bahrami	    die "$Prog: Unable to execute pvs (version definition section)\n";
1105*bfed486aSAli Bahrami	while ($line = <PVS>) {
1106*bfed486aSAli Bahrami		chomp $line;
1107*bfed486aSAli Bahrami		if ($line =~ /^[^\s]+\s+-\s+([^:]+):\s*([^\s;]+)/) {
1108*bfed486aSAli Bahrami		    my $ver = $1;
1109*bfed486aSAli Bahrami		    my $sym = $2;
1110*bfed486aSAli Bahrami
1111*bfed486aSAli Bahrami		    next if $ver =~ /private/i;
1112*bfed486aSAli Bahrami
1113*bfed486aSAli Bahrami		    if ($opt{o}) {
1114*bfed486aSAli Bahrami			OutMsg($$RefTtl++, $RelPath,
1115*bfed486aSAli Bahrami			       "VERSION=$ver, SYMBOL=$sym");
1116*bfed486aSAli Bahrami		    } else {
1117*bfed486aSAli Bahrami			if ($cur_ver ne $ver) {
1118*bfed486aSAli Bahrami			    OutMsg($$RefTtl++, $RelPath, "\tVERSION=$ver");
1119*bfed486aSAli Bahrami			    $cur_ver = $ver;
1120*bfed486aSAli Bahrami			}
1121*bfed486aSAli Bahrami			OutMsg($$RefTtl++, $RelPath, "\t\tSYMBOL=$sym");
1122*bfed486aSAli Bahrami		    }
1123*bfed486aSAli Bahrami		}
1124*bfed486aSAli Bahrami	}
1125*bfed486aSAli Bahrami
1126*bfed486aSAli Bahrami	close PVS;
1127*bfed486aSAli Bahrami}
1128*bfed486aSAli Bahrami
1129*bfed486aSAli Bahrami
11307c478bd9Sstevel@tonic-gatesub ProcDir {
11317c478bd9Sstevel@tonic-gate	my($FullDir, $RelDir) = @_;
11327c478bd9Sstevel@tonic-gate	my($NewFull, $NewRel);
11337c478bd9Sstevel@tonic-gate
11347c478bd9Sstevel@tonic-gate	# Determine if this is a directory we don't care about.
11357c478bd9Sstevel@tonic-gate	if (!$opt{a}) {
11367c478bd9Sstevel@tonic-gate		if ($RelDir =~ $SkipDirs) {
11377c478bd9Sstevel@tonic-gate			return;
11387c478bd9Sstevel@tonic-gate		}
11397c478bd9Sstevel@tonic-gate	}
11407c478bd9Sstevel@tonic-gate
11417c478bd9Sstevel@tonic-gate	# Open the directory and read each entry, omit files starting with "."
11427c478bd9Sstevel@tonic-gate	if (opendir(DIR, $FullDir)) {
11437c478bd9Sstevel@tonic-gate		foreach my $Entry (readdir(DIR)) {
11447c478bd9Sstevel@tonic-gate			if ($Entry =~ /^\./) {
11457c478bd9Sstevel@tonic-gate				next;
11467c478bd9Sstevel@tonic-gate			}
11477c478bd9Sstevel@tonic-gate			$NewFull = "$FullDir/$Entry";
11487c478bd9Sstevel@tonic-gate
11497c478bd9Sstevel@tonic-gate			# Ignore symlinks.
11507c478bd9Sstevel@tonic-gate			if (-l $NewFull) {
11517c478bd9Sstevel@tonic-gate				next;
11527c478bd9Sstevel@tonic-gate			}
11537c478bd9Sstevel@tonic-gate			if (!stat($NewFull)) {
11547c478bd9Sstevel@tonic-gate				next;
11557c478bd9Sstevel@tonic-gate			}
11567c478bd9Sstevel@tonic-gate			$NewRel = "$RelDir/$Entry";
11577c478bd9Sstevel@tonic-gate
11587c478bd9Sstevel@tonic-gate			# Descend into and process any directories.
11597c478bd9Sstevel@tonic-gate			if (-d _) {
11607c478bd9Sstevel@tonic-gate				ProcDir($NewFull, $NewRel);
11617c478bd9Sstevel@tonic-gate				next;
11627c478bd9Sstevel@tonic-gate			}
11637c478bd9Sstevel@tonic-gate
11647c478bd9Sstevel@tonic-gate			# Typically dynamic objects are executable, so we can
11657c478bd9Sstevel@tonic-gate			# reduce the overall cost of this script (a lot!) by
11667c478bd9Sstevel@tonic-gate			# screening out non-executables here, rather than pass
11677c478bd9Sstevel@tonic-gate			# them to file(1) later.  However, it has been known
11687c478bd9Sstevel@tonic-gate			# for shared objects to be mistakenly left non-
11697c478bd9Sstevel@tonic-gate			# executable, so with -a let all files through so that
11707c478bd9Sstevel@tonic-gate			# this requirement can be verified (see ProcFile()).
11717c478bd9Sstevel@tonic-gate			if (!$opt{a}) {
11727c478bd9Sstevel@tonic-gate				if (! -x _) {
11737c478bd9Sstevel@tonic-gate					next;
11747c478bd9Sstevel@tonic-gate				}
11757c478bd9Sstevel@tonic-gate			}
11767c478bd9Sstevel@tonic-gate
11777c478bd9Sstevel@tonic-gate			# Process any standard files.
11787c478bd9Sstevel@tonic-gate			if (-f _) {
11797c478bd9Sstevel@tonic-gate				my($Secure) = 0;
11807c478bd9Sstevel@tonic-gate
11817c478bd9Sstevel@tonic-gate				if (-u _ || -g _) {
11827c478bd9Sstevel@tonic-gate					$Secure = 1;
11837c478bd9Sstevel@tonic-gate				}
11847c478bd9Sstevel@tonic-gate
11857c478bd9Sstevel@tonic-gate				ProcFile($NewFull, $NewRel, $Entry, $Secure);
11867c478bd9Sstevel@tonic-gate				next;
11877c478bd9Sstevel@tonic-gate			}
11887c478bd9Sstevel@tonic-gate
11897c478bd9Sstevel@tonic-gate		}
11907c478bd9Sstevel@tonic-gate		closedir(DIR);
11917c478bd9Sstevel@tonic-gate	}
11927c478bd9Sstevel@tonic-gate}
11937c478bd9Sstevel@tonic-gate
11947c478bd9Sstevel@tonic-gate# Create a crle(1) script for any 64-bit dependencies we locate.  A runtime
11957c478bd9Sstevel@tonic-gate# configuration file will be generated to establish alternative dependency
11967c478bd9Sstevel@tonic-gate# mappings for all these dependencies.
11977c478bd9Sstevel@tonic-gate
11987c478bd9Sstevel@tonic-gatesub Entercrle64 {
11997c478bd9Sstevel@tonic-gate	my($FullDir, $RelDir, $Entry) = @_;
12007c478bd9Sstevel@tonic-gate
12017c478bd9Sstevel@tonic-gate	if (!$Crle64) {
12027c478bd9Sstevel@tonic-gate		# Create and initialize the script if is doesn't already exit.
12037c478bd9Sstevel@tonic-gate
12047c478bd9Sstevel@tonic-gate		$Crle64 = "$Tmpdir/$Prog.crle64.$$";
12057c478bd9Sstevel@tonic-gate		open(CRLE64, "> $Crle64") ||
12067c478bd9Sstevel@tonic-gate			die "$Prog: open failed: $Crle64: $!";
12077c478bd9Sstevel@tonic-gate
12087c478bd9Sstevel@tonic-gate		print CRLE64 "#!/bin/sh\ncrle -64\\\n";
12097c478bd9Sstevel@tonic-gate	}
12107c478bd9Sstevel@tonic-gate	print CRLE64 "\t-o $FullDir -a $RelDir/$Entry \\\n";
12117c478bd9Sstevel@tonic-gate}
12127c478bd9Sstevel@tonic-gate
12137c478bd9Sstevel@tonic-gate# Create a crle(1) script for any 32-bit dependencies we locate.  A runtime
12147c478bd9Sstevel@tonic-gate# configuration file will be generated to establish alternative dependency
12157c478bd9Sstevel@tonic-gate# mappings for all these dependencies.
12167c478bd9Sstevel@tonic-gate
12177c478bd9Sstevel@tonic-gatesub Entercrle32 {
12187c478bd9Sstevel@tonic-gate	my($FullDir, $RelDir, $Entry) = @_;
12197c478bd9Sstevel@tonic-gate
12207c478bd9Sstevel@tonic-gate	if (!$Crle32) {
12217c478bd9Sstevel@tonic-gate		# Create and initialize the script if is doesn't already exit.
12227c478bd9Sstevel@tonic-gate
12237c478bd9Sstevel@tonic-gate		$Crle32 = "$Tmpdir/$Prog.crle32.$$";
12247c478bd9Sstevel@tonic-gate		open(CRLE32, "> $Crle32") ||
12257c478bd9Sstevel@tonic-gate			die "$Prog: open failed: $Crle32: $!";
12267c478bd9Sstevel@tonic-gate
12277c478bd9Sstevel@tonic-gate		print CRLE32 "#!/bin/sh\ncrle \\\n";
12287c478bd9Sstevel@tonic-gate	}
12297c478bd9Sstevel@tonic-gate	print CRLE32 "\t-o $FullDir -a $RelDir/$Entry \\\n";
12307c478bd9Sstevel@tonic-gate}
12317c478bd9Sstevel@tonic-gate
12327c478bd9Sstevel@tonic-gate# Having finished gathering dependencies, complete any crle(1) scripts and
12337c478bd9Sstevel@tonic-gate# execute them to generate the associated runtime configuration files.  In
12347c478bd9Sstevel@tonic-gate# addition establish the environment variable required to pass the configuration
12357c478bd9Sstevel@tonic-gate# files to ldd(1).
12367c478bd9Sstevel@tonic-gate
12377c478bd9Sstevel@tonic-gatesub GenConf {
12387c478bd9Sstevel@tonic-gate	if ($Crle64) {
12397c478bd9Sstevel@tonic-gate		$Conf64 = "$Tmpdir/$Prog.conf64.$$";
12407c478bd9Sstevel@tonic-gate		print CRLE64 "\t-c $Conf64\n";
12417c478bd9Sstevel@tonic-gate
12427c478bd9Sstevel@tonic-gate		chmod 0755, $Crle64;
12437c478bd9Sstevel@tonic-gate		close CRLE64;
12447c478bd9Sstevel@tonic-gate
12457c478bd9Sstevel@tonic-gate		if (system($Crle64)) {
12467c478bd9Sstevel@tonic-gate			undef $Conf64;
12477c478bd9Sstevel@tonic-gate		}
12487c478bd9Sstevel@tonic-gate	}
12497c478bd9Sstevel@tonic-gate	if ($Crle32) {
12507c478bd9Sstevel@tonic-gate		$Conf32 = "$Tmpdir/$Prog.conf32.$$";
12517c478bd9Sstevel@tonic-gate		print CRLE32 "\t-c $Conf32\n";
12527c478bd9Sstevel@tonic-gate
12537c478bd9Sstevel@tonic-gate		chmod 0755, $Crle32;
12547c478bd9Sstevel@tonic-gate		close CRLE32;
12557c478bd9Sstevel@tonic-gate
12567c478bd9Sstevel@tonic-gate		if (system($Crle32)) {
12577c478bd9Sstevel@tonic-gate			undef $Conf32;
12587c478bd9Sstevel@tonic-gate		}
12597c478bd9Sstevel@tonic-gate	}
12607c478bd9Sstevel@tonic-gate
12617c478bd9Sstevel@tonic-gate	if ($Crle64 && $Conf64 && $Crle32 && $Conf32) {
12627c478bd9Sstevel@tonic-gate		$Env = "-e LD_FLAGS=config_64=$Conf64,config_32=$Conf32";
12637c478bd9Sstevel@tonic-gate	} elsif ($Crle64 && $Conf64) {
12647c478bd9Sstevel@tonic-gate		$Env = "-e LD_FLAGS=config_64=$Conf64";
12657c478bd9Sstevel@tonic-gate	} elsif ($Crle32 && $Conf32) {
12667c478bd9Sstevel@tonic-gate		$Env = "-e LD_FLAGS=config_32=$Conf32";
12677c478bd9Sstevel@tonic-gate	}
12687c478bd9Sstevel@tonic-gate}
12697c478bd9Sstevel@tonic-gate
12707c478bd9Sstevel@tonic-gate# Recurse through a directory hierarchy looking for appropriate dependencies.
12717c478bd9Sstevel@tonic-gate
12727c478bd9Sstevel@tonic-gatesub GetDeps {
12737c478bd9Sstevel@tonic-gate	my($FullDir, $RelDir) = @_;
12747c478bd9Sstevel@tonic-gate	my($NewFull);
12757c478bd9Sstevel@tonic-gate
12767c478bd9Sstevel@tonic-gate	# Open the directory and read each entry, omit files starting with "."
12777c478bd9Sstevel@tonic-gate	if (opendir(DIR, $FullDir)) {
12787c478bd9Sstevel@tonic-gate		 foreach my $Entry (readdir(DIR)) {
12797c478bd9Sstevel@tonic-gate			if ($Entry =~ /^\./) {
12807c478bd9Sstevel@tonic-gate				next;
12817c478bd9Sstevel@tonic-gate			}
12827c478bd9Sstevel@tonic-gate			$NewFull = "$FullDir/$Entry";
12837c478bd9Sstevel@tonic-gate
12847c478bd9Sstevel@tonic-gate			# We need to follow links so that any dependencies
12857c478bd9Sstevel@tonic-gate			# are expressed in all their available forms.
12867c478bd9Sstevel@tonic-gate			# Bail on symlinks like 32 -> .
12877c478bd9Sstevel@tonic-gate			if (-l $NewFull) {
12887c478bd9Sstevel@tonic-gate				if (readlink($NewFull) =~ /^\.$/) {
12897c478bd9Sstevel@tonic-gate					next;
12907c478bd9Sstevel@tonic-gate				}
12917c478bd9Sstevel@tonic-gate			}
12927c478bd9Sstevel@tonic-gate			if (!stat($NewFull)) {
12937c478bd9Sstevel@tonic-gate				next;
12947c478bd9Sstevel@tonic-gate			}
12957c478bd9Sstevel@tonic-gate
12964840e086Srie			if (!$opt{a}) {
12974840e086Srie				if ($NewFull =~ $SkipCrleConf) {
12984840e086Srie					next;
12994840e086Srie				}
13004840e086Srie			}
13014840e086Srie
13027c478bd9Sstevel@tonic-gate			# If this is a directory descend into it.
13037c478bd9Sstevel@tonic-gate			if (-d _) {
13047c478bd9Sstevel@tonic-gate				my($NewRel);
13057c478bd9Sstevel@tonic-gate
13067c478bd9Sstevel@tonic-gate				if ($RelDir =~ /^\/$/) {
13077c478bd9Sstevel@tonic-gate					$NewRel = "$RelDir$Entry";
13087c478bd9Sstevel@tonic-gate				} else {
13097c478bd9Sstevel@tonic-gate					$NewRel = "$RelDir/$Entry";
13107c478bd9Sstevel@tonic-gate				}
13117c478bd9Sstevel@tonic-gate
13127c478bd9Sstevel@tonic-gate				GetDeps($NewFull, $NewRel);
13137c478bd9Sstevel@tonic-gate				next;
13147c478bd9Sstevel@tonic-gate			}
13157c478bd9Sstevel@tonic-gate
13167c478bd9Sstevel@tonic-gate			# If this is a regular file determine if its a
13177c478bd9Sstevel@tonic-gate			# valid ELF dependency.
13187c478bd9Sstevel@tonic-gate			if (-f _) {
13197c478bd9Sstevel@tonic-gate				my($File);
13207c478bd9Sstevel@tonic-gate
13217c478bd9Sstevel@tonic-gate				# Typically shared object dependencies end with
13227c478bd9Sstevel@tonic-gate				# ".so" or ".so.?", hence we can reduce the cost
13237c478bd9Sstevel@tonic-gate				# of this script (a lot!) by screening out files
13247c478bd9Sstevel@tonic-gate				# that don't follow this pattern.
13257c478bd9Sstevel@tonic-gate				if (!$opt{a}) {
13267c478bd9Sstevel@tonic-gate					if ($Entry !~ /\.so(?:\.\d+)*$/) {
13277c478bd9Sstevel@tonic-gate						next;
13287c478bd9Sstevel@tonic-gate					}
13297c478bd9Sstevel@tonic-gate				}
13307c478bd9Sstevel@tonic-gate
13317c478bd9Sstevel@tonic-gate				$File = `file $NewFull`;
13327c478bd9Sstevel@tonic-gate				if ($File !~ /dynamic lib/) {
13337c478bd9Sstevel@tonic-gate					next;
13347c478bd9Sstevel@tonic-gate				}
13357c478bd9Sstevel@tonic-gate
13367c478bd9Sstevel@tonic-gate				if ($File =~ /32-bit/) {
13377c478bd9Sstevel@tonic-gate					Entercrle32($FullDir, $RelDir, $Entry);
13387c478bd9Sstevel@tonic-gate				} elsif ($Ena64) {
13397c478bd9Sstevel@tonic-gate					Entercrle64($FullDir, $RelDir, $Entry);
13407c478bd9Sstevel@tonic-gate				}
13417c478bd9Sstevel@tonic-gate				next;
13427c478bd9Sstevel@tonic-gate			}
13437c478bd9Sstevel@tonic-gate		}
13447c478bd9Sstevel@tonic-gate		closedir(DIR);
13457c478bd9Sstevel@tonic-gate	}
13467c478bd9Sstevel@tonic-gate}
13477c478bd9Sstevel@tonic-gateexit $Error
1348