xref: /illumos-gate/usr/src/tools/scripts/check_rtime.pl (revision e44e85a7f9935f0428e188393e3da61b17e83884)
1#!/usr/perl5/bin/perl -w
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 (the "License").
7# You may not use this file except in compliance with the License.
8#
9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10# or http://www.opensolaris.org/os/licensing.
11# See the License for the specific language governing permissions
12# and limitations under the License.
13#
14# When distributing Covered Code, include this CDDL HEADER in each
15# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16# If applicable, add the following below this CDDL HEADER, with the
17# fields enclosed by brackets "[]" replaced with your own identifying
18# information: Portions Copyright [yyyy] [name of copyright owner]
19#
20# CDDL HEADER END
21#
22
23#
24# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26#
27#
28
29#
30# Check ELF information.
31#
32# This script descends a directory hierarchy inspecting ELF dynamic executables
33# and shared objects.  The general theme is to verify that common Makefile rules
34# have been used to build these objects.  Typical failures occur when Makefile
35# rules are re-invented rather than being inherited from "cmd/lib" Makefiles.
36#
37# As always, a number of components don't follow the rules, and these are
38# excluded to reduce this scripts output.  Pathnames used for this exclusion
39# assume this script is being run over a "proto" area.  The -a (all) option
40# skips any exclusions.
41#
42# By default any file that has conditions that should be reported is first
43# listed and then each condition follows.  The -o (one-line) option produces a
44# more terse output which is better for sorting/diffing with "nightly".
45#
46# NOTE: missing dependencies, symbols or versions are reported by running the
47# file through ldd(1).  As objects within a proto area are built to exist in a
48# base system, standard use of ldd(1) will bind any objects to dependencies
49# that exist in the base system.  It is frequently the case that newer objects
50# exist in the proto area that are required to satisfy other objects
51# dependencies, and without using these newer objects an ldd(1) will produce
52# misleading error messages.  To compensate for this, the -d option (or the
53# existence of the CODEMSG_WS/ROOT environment variables) cause the creation of
54# alternative dependency mappings via crle(1) configuration files that establish
55# any proto shared objects as alternatives to their base system location.  Thus
56# ldd(1) can be executed against these configuration files so that objects in a
57# proto area bind to their dependencies in the same proto area.
58
59
60# Define all global variables (required for strict)
61use vars  qw($SkipDirs $SkipFiles $SkipTextrelFiles $SkipDirectBindFiles);
62use vars  qw($SkipUndefFiles $SkipUnusedDeps);
63use vars  qw($SkipStabFiles $SkipNoExStkFiles $SkipCrleConf);
64use vars  qw($SkipUnusedSearchPath $SkipUnrefObject $SkipUnusedObject);
65use vars  qw($Prog $Mach $Isalist $Env $Ena64 $Tmpdir $Error $Gnuc);
66use vars  qw($UnusedPaths $LddNoU $Crle32 $Crle64 $Conf32 $Conf64);
67use vars  qw($SkipDirectBindDirs $SkipInterps $SkipSymSort $OldDeps %opt);
68
69use strict;
70
71
72# Define any directories we should skip completely.
73$SkipDirs = qr{
74	usr/lib/devfsadm |		# 4382889
75	usr/lib/libc |			# optimized libc
76	usr/lib/rcm |			# 4426119
77	usr/perl5 |			# alan's taking care of these :-)
78	usr/src				# no need to look at shipped source
79}x;
80
81# Define any files we should skip completely.
82$SkipFiles = qr{ ^(?:
83	lddstub |			# lddstub has no dependencies
84	geniconvtbl\.so |		# 4384329
85	libssagent\.so\.1 |		# 4328854
86	libpsvcplugin_psr\.so\.1 |	# 4385799
87	libpsvcpolicy_psr\.so\.1 |	#  "  "
88	libpsvcpolicy\.so\.1 |		#  "  "
89	picl_slm\.so |			#  "  "
90	mod_ipp\.so |			# Apache loadable module
91	fptest |	# USIII specific extns. cause ldd noise on USII bld. m/c
92	grub
93	)$
94}x;
95
96# Define any files that are allowed text relocations.
97$SkipTextrelFiles = qr{ ^(?:
98	unix |				# kernel models are non-pic
99	mdb				# relocations against __RTC (dbx)
100	)$
101}x;
102
103# Define any directories or files that are allowed to have no direct bound
104# symbols
105$SkipDirectBindDirs = qr{
106	usr/ucb
107}x;
108
109$SkipDirectBindFiles = qr{ ^(?:
110	unix |
111	sbcp |
112	libproc.so.1 |
113	libnisdb.so.2
114	)$
115}x;
116
117# Define any files that are allowed undefined references.
118
119$SkipUndefFiles = qr{ ^(?:
120	libsvm\.so\.1 |			# libspmicommon.so.1 lacking
121	libnisdb\.so\.2			# C++
122	)$
123}x;
124
125# Define any files that have unused dependencies.
126$SkipUnusedDeps = qr{
127	lib/picl/plugins/ |		# require devtree dependencies
128	/lib/libp			# profile libc makes libm an unused
129}x;					#	dependency of standard libc
130
131# Define any objects that always look unused.
132$SkipUnusedObject = qr{
133	/libm_hwcap[0-9]+\.so\.2	# libm.so.2 dependency
134}x;
135
136# Define any files that should contain debugging information.
137$SkipStabFiles = qr{ ^(?:
138	unix
139	)$
140}x;
141
142# Define any files that don't require a non-executable stack definition.
143$SkipNoExStkFiles = qr{ ^(?:
144	forth |
145	unix |
146	multiboot
147	)$
148}x;
149
150# Identify any files that should be skipped when building a crle(1)
151# configuration file.  As the hwcap libraries can be loop-back mounted onto
152# libc, these can confuse crle(1) because of their identical dev/inode.
153$SkipCrleConf = qr{
154	lib/libc/libc_hwcap
155}x;
156
157# Skip "unused search path=" ldd(1) diagnostics.
158$SkipUnusedSearchPath = qr{
159	/usr/lib/fs/autofs.*\ from\ .automountd |		# dlopen()
160	/etc/ppp/plugins.*\ from\ .*pppd |			# dlopen()
161	/usr/lib/inet/ppp.*\ from\ .*pppd |			# dlopen()
162	/usr/sfw/lib.*\ from\ .*libipsecutil.so.1 |		# dlopen()
163	/usr/platform/.*rsmlib.*\ from\ .*librsm.so.2 |		# dlopen()
164	\$ORIGIN.*\ from\ .*fcode.so |				# dlopen()
165	/opt/VRTSvxvm/lib.*\ from\ .*libdiskmgt\.so\.1 |	# dlopen()
166	/usr/platform/.*\ from\ .*/usr/platform |		# picl
167	/usr/lib/picl/.*\ from\ .*/usr/platform |		# picl
168	/usr/platform/.*\ from\ .*/usr/lib/picl |		# picl
169	/usr/lib/smbsrv.*\ from\ .*libsmb\.so\.1 |		# future needs
170	/usr/lib/mps/secv1.*\ from\ .*libnss3\.so |		# non-OSNet
171	/usr/lib/mps.*\ from\ .*libnss3\.so |			# non-OSNet
172	/usr/sfw/lib.*\ from\ .*libdbus-1\.so\.3 |		# non-OSNet
173	/usr/sfw/lib.*\ from\ .*libdbus-glib-1\.so\.2 |		# non-OSNet
174	/usr/sfw/lib.*\ from\ .*libglib-2\.0\.so\.0 |		# non-OSNet
175	/usr/X11/lib.*\ from\ .*libglib-2\.0\.so\.0 |		# non-OSNet
176	/usr/sfw/lib.*\ from\ .*libgmodule-2\.0\.so\.0 |	# non-OSNet
177	/usr/X11/lib.*\ from\ .*libgmodule-2\.0\.so\.0 |	# non-OSNet
178	/usr/sfw/lib.*\ from\ .*libgnomevfs-2\.so\.0 |		# non-OSNet
179	/usr/sfw/lib.*\ from\ .*libgobject-2\.0\.so\.0 |	# non-OSNet
180	/usr/X11/lib.*\ from\ .*libgobject-2\.0\.so\.0 |	# non-OSNet
181	/usr/sfw/lib.*\ from\ .*libgthread-2\.0\.so\.0 |	# non-OSNet
182	/usr/X11/lib.*\ from\ .*libgthread-2\.0\.so\.0 |	# non-OSNet
183	/usr/sfw/lib.*\ from\ .*libcrypto\.so\.0\.9\.8 |	# non-OSNet
184	/usr/sfw/lib.*\ from\ .*libnetsnmp\.so\.5 |		# non-OSNet
185	/usr/sfw/lib.*\ from\ .*libgcc_s\.so\.1 |		# non-OSNet
186	/usr.*\ from\ .*tst\.gcc\.exe |				# gcc built
187	/usr/postgres/8.3/lib.*\ from\ .*libpq\.so\.5 |		# non-OSNET
188	/usr/sfw/lib.*\ from\ .*libpq\.so\.5			# non-OSNET
189}x;
190
191# Skip "unreferenced object=" ldd(1) diagnostics.
192$SkipUnrefObject = qr{
193	/libmapmalloc\.so\.1;\ unused\ dependency\ of |		# interposer
194	/libstdc\+\+\.so\.6;\ unused\ dependency\ of |		# gcc build
195	/libm\.so\.2.*\ of\ .*libstdc\+\+\.so\.6 |		# gcc build
196	/lib.*\ of\ .*/lib/picl/plugins/ |			# picl
197	/lib.*\ of\ .*libcimapi\.so |				# non-OSNET
198	/lib.*\ of\ .*libjvm\.so |				# non-OSNET
199	/lib.*\ of\ .*libnetsnmp\.so\.5 |			# non-OSNET
200	/lib.*\ of\ .*libnetsnmpagent\.so\.5 |			# non-OSNET
201	/lib.*\ of\ .*libnetsnmpmibs\.so\.5 |			# non-OSNET
202	/lib.*\ of\ .*libnetsnmphelpers\.so\.5 |		# non-OSNET
203	/lib.*\ of\ .*libnspr4\.so |				# non-OSNET
204	/lib.*\ of\ .*libsoftokn3\.so |				# non-OSNET
205	/lib.*\ of\ .*libspmicommon\.so\.1 |			# non-OSNET
206	/lib.*\ of\ .*libspmocommon\.so\.1 |			# non-OSNET
207	/lib.*\ of\ .*libssl3\.so |				# non-OSNET
208	/lib.*\ of\ .*libxml2\.so\.2 |				# non-OSNET
209	/lib.*\ of\ .*libxslt\.so\.1 |				# non-OSNET
210	/lib.*\ of\ .*libpq\.so\.4 |				# non-OSNET
211	/lib.*\ of\ .*libpython2\.4\.so\.1\.0 			# non-OSNET
212}x;
213
214# Define any files that should only have unused (ldd -u) processing.
215$UnusedPaths = qr{
216	ucb/shutdown			# libucb interposes on libc and makes
217					# dependencies on libc seem unnecessary
218}x;
219
220# Define interpreters we should ignore.
221$SkipInterps = qr{
222	misc/krtld |
223	misc/amd64/krtld |
224	misc/sparcv9/krtld
225}x;
226
227# Catch libintl and libw, although ld(1) will bind to these and thus determine
228# they're needed, their content was moved into libc as of on297 build 7.
229# libthread and libpthread were completely moved into libc as of on10 build 53.
230# libdl was moved into libc as of on10 build 49.  librt and libaio were moved
231# into libc as of Nevada build 44.
232$OldDeps = qr{ ^(?:
233	libintl\.so\.1 |
234	libw\.so\.1 |
235	libthread\.so\.1 |
236	libpthread\.so\.1 |
237	libdl\.so\.1 |
238	librt\.so\.1 |
239	libaio\.so\.1
240	)$
241}x;
242
243# Files for which we skip checking of duplicate addresses in the
244# symbol sort sections. Such exceptions should be rare --- most code will
245# not have duplicate addresses, since it takes assember or a "#pragma weak"
246# to do such aliasing in C. C++ is different: The compiler generates aliases
247# for implementation reasons, and the mangled names used to encode argument
248# and return value types are difficult to handle well in mapfiles.
249# Furthermore, the Sun compiler and gcc use different and incompatible
250# name mangling conventions. Since ON must be buildable by either, we
251# would have to maintain two sets of mapfiles for each such object.
252# C++ use is rare in ON, so this is not worth pursuing.
253#
254$SkipSymSort = qr{ ^.*(?:
255	opt/SUNWdtrt/tst/common/pid/tst.weak2.exe |	# DTrace test
256	lib/amd64/libnsl\.so\.1 |			# C++
257	lib/sparcv9/libnsl\.so\.1 |			# C++
258	lib/sparcv9/libfru\.so\.1 |			# C++
259	usr/lib/sgml/nsgmls |				# C++
260	usr/lib/lms |					# C++
261	ld\.so\.1 |					# libc_pic.a user
262	lib/libsun_fc\.so\.1 |				# C++
263	lib/amd64/libsun_fc\.so\.1 |			# C++
264	lib/sparcv9/libsun_fc\.so\.1 			# C++
265	)$
266}x;
267
268use Getopt::Std;
269
270# -----------------------------------------------------------------------------
271
272# Reliably compare two OS revisions.  Arguments are <ver1> <op> <ver2>.
273# <op> is the string form of a normal numeric comparison operator.
274sub cmp_os_ver {
275	my @ver1 = split(/\./, $_[0]);
276	my $op = $_[1];
277	my @ver2 = split(/\./, $_[2]);
278
279	push @ver2, ("0") x $#ver1 - $#ver2;
280	push @ver1, ("0") x $#ver2 - $#ver1;
281
282	my $diff = 0;
283	while (@ver1 || @ver2) {
284		if (($diff = shift(@ver1) - shift(@ver2)) != 0) {
285			last;
286		}
287	}
288	return (eval "$diff $op 0" ? 1 : 0);
289}
290
291# This script relies on ldd returning output reflecting only the binary
292# contents.  But if LD_PRELOAD* environment variables are present, libraries
293# named by them will also appear in the output, disrupting our analysis.
294# So, before we get too far, scrub the environment.
295
296delete($ENV{LD_PRELOAD});
297delete($ENV{LD_PRELOAD_32});
298delete($ENV{LD_PRELOAD_64});
299
300# Establish a program name for any error diagnostics.
301chomp($Prog = `basename $0`);
302
303# Determine what machinery is available.
304$Mach = `uname -p`;
305$Isalist = `isalist`;
306$Env = "";
307if ($Mach =~ /sparc/) {
308	if ($Isalist =~ /sparcv9/) {
309		$Ena64 = "ok";
310	}
311} elsif ($Mach =~ /i386/) {
312	if ($Isalist =~ /amd64/) {
313		$Ena64 = "ok";
314	}
315}
316
317# Check that we have arguments.
318if ((getopts('ad:imosv', \%opt) == 0) || ($#ARGV == -1)) {
319	print "usage: $Prog [-a] [-d depdir] [-m] [-o] [-s] file | dir, ...\n";
320	print "\t[-a]\t\tprocess all files (ignore any exception lists)\n";
321	print "\t[-d dir]\testablish dependencies from under directory\n";
322	print "\t[-i]\t\tproduce dynamic table entry information\n";
323	print "\t[-m]\t\tprocess mcs(1) comments\n";
324	print "\t[-o]\t\tproduce one-liner output (prefixed with pathname)\n";
325	print "\t[-s]\t\tprocess .stab and .symtab entries\n";
326	print "\t[-v]\t\tprocess version definition entries\n";
327	exit 1;
328} else {
329	my($Proto);
330
331	if ($opt{d}) {
332		# User specified dependency directory - make sure it exists.
333		if (! -d $opt{d}) {
334			print "$Prog: $opt{d} is not a directory\n";
335			exit 1;
336		}
337		$Proto = $opt{d};
338
339	} elsif ($ENV{CODEMGR_WS}) {
340		my($Root);
341
342		# Without a user specified dependency directory see if we're
343		# part of a codemanager workspace and if a proto area exists.
344		if (($Root = $ENV{ROOT}) && (-d $Root)) {
345			$Proto = $Root;
346		}
347	}
348
349	if (!($Tmpdir = $ENV{TMPDIR}) || (! -d $Tmpdir)) {
350		$Tmpdir = "/tmp";
351	}
352
353	# Determine whether this is a __GNUC build.  If so, unused search path
354	# processing is disabled.
355	if (defined $ENV{__GNUC}) {
356		$Gnuc = 1;
357	} else {
358		$Gnuc = 0;
359	}
360
361	# Look for dependencies under $Proto.
362	if ($Proto) {
363		# To support alternative dependency mapping we'll need ldd(1)'s
364		# -e option.  This is relatively new (s81_30), so make sure
365		# ldd(1) is capable before gathering any dependency information.
366		if (system('ldd -e /usr/lib/lddstub 2> /dev/null')) {
367			print "ldd: does not support -e, unable to ";
368			print "create alternative dependency mappingings.\n";
369			print "ldd: option added under 4390308 (s81_30).\n\n";
370		} else {
371			# Gather dependencies and construct a alternative
372			# dependency mapping via a crle(1) configuration file.
373			GetDeps($Proto, "/");
374			GenConf();
375		}
376	}
377
378	# To support unreferenced dependency detection we'll need ldd(1)'s -U
379	# option.  This is relatively new (4638070), and if not available we
380	# can still fall back to -u.  Even with this option, don't use -U with
381	# releases prior to 5.10 as the cleanup for -U use only got integrated
382	# into 5.10 under 4642023.  Note, that nightly doesn't typically set a
383	# RELEASE from the standard <env> files.  Users who wish to disable use
384	# of ldd(1)'s -U should set (or uncomment) RELEASE in their <env> file
385	# if using nightly, or otherwise establish it in their environment.
386	if (system('ldd -U /usr/lib/lddstub 2> /dev/null')) {
387		$LddNoU = 1;
388	} else {
389		my($Release);
390
391		if (($Release = $ENV{RELEASE}) &&
392		    (cmp_os_ver($Release, "<", "5.10"))) {
393			$LddNoU = 1;
394		} else {
395			$LddNoU = 0;
396		}
397	}
398
399	# For each argument determine if we're dealing with a file or directory.
400	foreach my $Arg (@ARGV) {
401		# Ignore symbolic links.
402		if (-l $Arg) {
403			next;
404		}
405
406		if (!stat($Arg)) {
407			next;
408		}
409
410		# Process simple files.
411		if (-f _) {
412			my($RelPath) = $Arg;
413			my($File) = $Arg;
414			my($Secure) = 0;
415
416			$RelPath =~ s!^.*/!./!;
417			$File =~ s!^.*/!!;
418
419			if (-u _ || -g _) {
420				$Secure = 1;
421			}
422
423			ProcFile($Arg, $RelPath, $File, $Secure);
424			next;
425		}
426		# Process directories.
427		if (-d _) {
428			ProcDir($Arg, ".");
429			next;
430		}
431
432		print "$Arg is not a file or directory\n";
433		$Error = 1;
434	}
435
436	# Cleanup
437	CleanUp();
438}
439
440$Error = 0;
441
442# Clean up any temporary files.
443sub CleanUp {
444	if ($Crle64) {
445		unlink $Crle64;
446	}
447	if ($Conf64) {
448		unlink $Conf64;
449	}
450	if ($Crle32) {
451		unlink $Crle32;
452	}
453	if ($Conf32) {
454		unlink $Conf32;
455	}
456}
457
458# Create an output message, either a one-liner (under -o) or preceded by the
459# files relative pathname as a title.
460sub OutMsg {
461	my($Ttl, $Path, $Msg) = @_;
462
463	if ($opt{o}) {
464		$Msg =~ s/^[ \t]*//;
465		print "$Path: $Msg\n";
466	} else {
467		if ($Ttl eq 0) {
468			print "==== $Path ====\n";
469		}
470		print "$Msg\n";
471	}
472}
473
474# Determine whether this a ELF dynamic object and if so investigate its runtime
475# attributes.
476sub ProcFile {
477	my($FullPath, $RelPath, $File, $Secure) = @_;
478	my(@Elf, @Ldd, $Dyn, $Intp, $Dll, $Ttl, $Sym, $Interp, $Stack);
479	my($Sun, $Relsz, $Pltsz, $Tex, $Stab, $Strip, $Lddopt, $SymSort);
480	my($Val, $Header, $SkipLdd, $IsX86, $RWX, $UnDep);
481	my($HasDirectBinding, $HasVerdef);
482
483	# Ignore symbolic links.
484	if (-l $FullPath) {
485		return;
486	}
487
488	$Ttl = 0;
489	@Ldd = 0;
490
491	# Determine whether we have access to inspect the file.
492	if (!(-r $FullPath)) {
493		OutMsg($Ttl++, $RelPath,
494		    "\tunable to inspect file: permission denied");
495		return;
496	}
497
498	# Determine if this is a file we don't care about.
499	if (!$opt{a}) {
500		if ($File =~ $SkipFiles) {
501			return;
502		}
503	}
504
505	# Determine whether we have a executable (static or dynamic) or a
506	# shared object.
507	@Elf = split(/\n/, `elfdump -epdicyv $FullPath 2>&1`);
508
509	$Dyn = $Intp = $Dll = $Stack = $IsX86 = $RWX = 0;
510	$Interp = 1;
511	$Header = 'None';
512	foreach my $Line (@Elf) {
513		# If we have an invalid file type (which we can tell from the
514		# first line), or we're processing an archive, bail.
515		if ($Header eq 'None') {
516			if (($Line =~ /invalid file/) ||
517			    ($Line =~ /$FullPath(.*):/)) {
518				return;
519			}
520		}
521
522		if ($Line =~ /^ELF Header/) {
523			$Header = 'Ehdr';
524
525		} elsif ($Line =~ /^Program Header/) {
526			$Header = 'Phdr';
527			$RWX = 0;
528
529		} elsif ($Line =~ /^Interpreter/) {
530			$Header = 'Intp';
531
532		} elsif ($Line =~ /^Dynamic Section/) {
533			# A dynamic section indicates we're a dynamic object
534			# (this makes sure we don't check static executables).
535			$Dyn = 1;
536
537		} elsif (($Header eq 'Ehdr') && ($Line =~ /e_type:/)) {
538			# The e_type field indicates whether this file is a
539			# shared object (ET_DYN) or an executable (ET_EXEC).
540			if ($Line =~ /ET_DYN/) {
541				$Dll = 1;
542			} elsif ($Line !~ /ET_EXEC/) {
543				return;
544			}
545		} elsif (($Header eq 'Ehdr') && ($Line =~ /ei_class:/)) {
546			# If we encounter a 64-bit object, but we're not running
547			# on a 64-bit system, suppress calling ldd(1).
548			if (($Line =~ /ELFCLASS64/) && !$Ena64) {
549				$SkipLdd = 1;
550			}
551		} elsif (($Header eq 'Ehdr') && ($Line =~ /e_machine:/)) {
552			# If it's a X86 object, we need to enforce RW- data.
553			if (($Line =~ /(EM_AMD64|EM_386)/)) {
554				$IsX86 = 1;
555			}
556		} elsif (($Header eq 'Phdr') &&
557		    ($Line =~ /\[ PF_X  PF_W  PF_R \]/)) {
558			# RWX segment seen.
559			$RWX = 1;
560
561		} elsif (($Header eq 'Phdr') &&
562		    ($Line =~ /\[ PT_LOAD \]/ && $RWX && $IsX86)) {
563			# Seen an RWX PT_LOAD segment.
564			if ($File !~ $SkipNoExStkFiles) {
565				OutMsg($Ttl++, $RelPath,
566				    "\tapplication requires non-executable " .
567				    "data\t<no -Mmapfile_noexdata?>");
568			}
569
570		} elsif (($Header eq 'Phdr') &&
571		    ($Line =~ /\[ PT_SUNWSTACK \]/)) {
572			# This object defines a non-executable stack.
573			$Stack = 1;
574
575		} elsif (($Header eq 'Intp') && !$opt{a} &&
576		    ($Line =~ $SkipInterps)) {
577			# This object defines an interpretor we should skip.
578			$Interp = 0;
579		}
580	}
581
582	# Determine whether this ELF executable or shared object has a
583	# conforming mcs(1) comment section.  If the correct $(POST_PROCESS)
584	# macros are used, only a 3 or 4 line .comment section should exist
585	# containing one or two "@(#)SunOS" identifying comments (one comment
586	# for a non-debug build, and two for a debug build). The results of
587	# the following split should be three or four lines, the last empty
588	# line being discarded by the split.
589	if ($opt{m}) {
590		my(@Mcs, $Con, $Dev);
591
592		@Mcs = split(/\n/, `mcs -p $FullPath 2>&1`);
593
594		$Con = $Dev = $Val = 0;
595		foreach my $Line (@Mcs) {
596			$Val++;
597
598			if (($Val == 3) && ($Line !~ /^@\(#\)SunOS/)) {
599				$Con = 1;
600				last;
601			}
602			if (($Val == 4) && ($Line =~ /^@\(#\)SunOS/)) {
603				$Dev = 1;
604				next;
605			}
606			if (($Dev == 0) && ($Val == 4)) {
607				$Con = 1;
608				last;
609			}
610			if (($Dev == 1) && ($Val == 5)) {
611				$Con = 1;
612				last;
613			}
614		}
615		if ($opt{m} && ($Con == 1)) {
616			OutMsg($Ttl++, $RelPath,
617			    "\tnon-conforming mcs(1) comment\t<no \$(POST_PROCESS)?>");
618		}
619	}
620
621	# Applications should contain a non-executable stack definition.
622	if (($Dll == 0) && ($Stack == 0)) {
623		if (!$opt{a}) {
624			if ($File =~ $SkipNoExStkFiles) {
625				goto DYN;
626			}
627		}
628		OutMsg($Ttl++, $RelPath,
629		    "\tapplication requires non-executable stack\t<no -Mmapfile_noexstk?>");
630	}
631
632DYN:
633	# Having caught any static executables in the mcs(1) check and non-
634	# executable stack definition check, continue with dynamic objects
635	# from now on.
636	if ($Dyn eq 0) {
637		return;
638	}
639
640	# Only use ldd unless we've encountered an interpreter that should
641	# be skipped.
642	if (!$SkipLdd && $Interp) {
643		my $LDDFullPath = $FullPath;
644
645		if ($Secure) {
646			# The execution of a secure application over an nfs file
647			# system mounted nosuid will result in warning messages
648			# being sent to /var/adm/messages.  As this type of
649			# environment can occur with root builds, move the file
650			# being investigated to a safe place first.  In addition
651			# remove its secure permission so that it can be
652			# influenced by any alternative dependency mappings.
653
654			my($TmpPath) = "$Tmpdir/$File";
655
656			system('cp', $LDDFullPath, $TmpPath);
657			chmod 0777, $TmpPath;
658			$LDDFullPath = $TmpPath;
659		}
660
661		# Use ldd(1) to determine the objects relocatability and use.
662		# By default look for all unreferenced dependencies.  However,
663		# some objects have legitimate dependencies that they do not
664		# reference.
665		if ($LddNoU || ($RelPath =~ $UnusedPaths)) {
666			$Lddopt = "-ru";
667		} else {
668			$Lddopt = "-rU";
669		}
670		@Ldd = split(/\n/, `ldd $Lddopt $Env $LDDFullPath 2>&1`);
671		if ($Secure) {
672			unlink $LDDFullPath;
673		}
674	}
675
676	$Val = 0;
677	$Sym = 5;
678	$UnDep = 1;
679
680	foreach my $Line (@Ldd) {
681
682		if ($Val == 0) {
683			$Val = 1;
684			# Make sure ldd(1) worked.  One possible failure is that
685			# this is an old ldd(1) prior to -e addition (4390308).
686			if ($Line =~ /usage:/) {
687				$Line =~ s/$/\t<old ldd(1)?>/;
688				OutMsg($Ttl++, $RelPath, $Line);
689				last;
690			} elsif ($Line =~ /execution failed/) {
691				OutMsg($Ttl++, $RelPath, $Line);
692				last;
693			}
694
695			# It's possible this binary can't be executed, ie. we've
696			# found a sparc binary while running on an intel system,
697			# or a sparcv9 binary on a sparcv7/8 system.
698			if ($Line =~ /wrong class/) {
699				OutMsg($Ttl++, $RelPath,
700				    "\thas wrong class or data encoding");
701				next;
702			}
703
704			# Historically, ldd(1) likes executable objects to have
705			# their execute bit set.  Note that this test isn't
706			# applied unless the -a option is in effect, as any
707			# non-executable files are skipped by default to reduce
708			# the cost of running this script.
709			if ($Line =~ /not executable/) {
710				OutMsg($Ttl++, $RelPath,
711				    "\tis not executable");
712				next;
713			}
714		}
715
716		# Look for "file" or "versions" that aren't found.  Note that
717		# these lines will occur before we find any symbol referencing
718		# errors.
719		if (($Sym == 5) && ($Line =~ /not found\)/)) {
720			if ($Line =~ /file not found\)/) {
721				$Line =~ s/$/\t<no -zdefs?>/;
722			}
723			OutMsg($Ttl++, $RelPath, $Line);
724			next;
725		}
726		# Look for relocations whose symbols can't be found.  Note, we
727		# only print out the first 5 relocations for any file as this
728		# output can be excessive.
729		if ($Sym && ($Line =~ /symbol not found/)) {
730			# Determine if this file is allowed undefined
731			# references.
732			if ($Sym == 5) {
733				if (!$opt{a}) {
734					if ($File =~ $SkipUndefFiles) {
735						$Sym = 0;
736						next;
737					}
738				}
739			}
740			if ($Sym-- == 1) {
741				if (!$opt{o}) {
742					OutMsg($Ttl++, $RelPath,
743					    "\tcontinued ...");
744				}
745				next;
746			}
747			# Just print the symbol name.
748			$Line =~ s/$/\t<no -zdefs?>/;
749			OutMsg($Ttl++, $RelPath, $Line);
750			next;
751		}
752		# Look for any unused search paths.
753		if ($Line =~ /unused search path=/) {
754			# Note, skip this comparison for __GNUC builds, as the
755			# gnu compilers insert numerous unused search paths.
756			if ($Gnuc == 1) {
757				next;
758			}
759			if (!$opt{a}) {
760				if ($Line =~ $SkipUnusedSearchPath) {
761					next;
762				}
763			}
764			if ($Secure) {
765				$Line =~ s!$Tmpdir/!!;
766			}
767			$Line =~ s/^[ \t]*(.*)/\t$1\t<remove search path?>/;
768			OutMsg($Ttl++, $RelPath, $Line);
769			next;
770		}
771		# Look for unreferenced dependencies.  Note, if any unreferenced
772		# objects are ignored, then set $UnDep so as to suppress any
773		# associated unused-object messages.
774		if ($Line =~ /unreferenced object=/) {
775			if (!$opt{a}) {
776				if ($Line =~ $SkipUnrefObject) {
777					$UnDep = 0;
778					next;
779				}
780			}
781			if ($Secure) {
782				$Line =~ s!$Tmpdir/!!;
783			}
784			$Line =~ s/^[ \t]*(.*)/\t$1\t<remove lib or -zignore?>/;
785			OutMsg($Ttl++, $RelPath, $Line);
786			next;
787		}
788		# Look for any unused dependencies.
789		if ($UnDep && ($Line =~ /unused/)) {
790			if (!$opt{a}) {
791				if ($RelPath =~ $SkipUnusedDeps) {
792					next;
793				}
794				if ($Line =~ $SkipUnusedObject) {
795					next;
796				}
797			}
798			if ($Secure) {
799				$Line =~ s!$Tmpdir/!!;
800			}
801			$Line =~ s/^[ \t]*(.*)/\t$1\t<remove lib or -zignore?>/;
802			OutMsg($Ttl++, $RelPath, $Line);
803			next;
804		}
805	}
806
807	# Reuse the elfdump(1) data to investigate additional dynamic linking
808	# information.
809
810	$Sun = $Relsz = $Pltsz = $Dyn = $Stab = $SymSort = 0;
811	$Tex = $Strip = 1;
812	$HasDirectBinding = 0;
813	$HasVerdef = 0;
814
815	$Header = 'None';
816ELF:	foreach my $Line (@Elf) {
817		# We're only interested in the section headers and the dynamic
818		# section.
819		if ($Line =~ /^Section Header/) {
820			$Header = 'Shdr';
821
822			if (($Sun == 0) && ($Line =~ /\.SUNW_reloc/)) {
823				# This object has a combined relocation section.
824				$Sun = 1;
825
826			} elsif (($Stab == 0) && ($Line =~ /\.stab/)) {
827				# This object contain .stabs sections
828				$Stab = 1;
829			} elsif (($SymSort == 0) &&
830				 ($Line =~ /\.SUNW_dyn(sym)|(tls)sort/)) {
831				# This object contains a symbol sort section
832				$SymSort = 1;
833			}
834
835			if (($Strip == 1) && ($Line =~ /\.symtab/)) {
836				# This object contains a complete symbol table.
837				$Strip = 0;
838			}
839			next;
840
841		} elsif ($Line =~ /^Dynamic Section/) {
842			$Header = 'Dyn';
843			next;
844		} elsif ($Line =~ /^Syminfo Section/) {
845			$Header = 'Syminfo';
846			next;
847		} elsif ($Line =~ /^Version Definition Section/) {
848			$HasVerdef = 1;
849			next;
850		} elsif (($Header ne 'Dyn') && ($Header ne 'Syminfo')) {
851			next;
852		}
853
854		# Look into the Syminfo section.
855		# Does this object have at least one Directly Bound symbol?
856		if (($Header eq 'Syminfo')) {
857			my(@Symword);
858
859			if ($HasDirectBinding == 1) {
860				next;
861			}
862
863			@Symword = split(' ', $Line);
864
865			if (!defined($Symword[1])) {
866				next;
867			}
868			if ($Symword[1] =~ /B/) {
869				$HasDirectBinding = 1;
870			}
871			next;
872		}
873
874		# Does this object contain text relocations.
875		if ($Tex && ($Line =~ /TEXTREL/)) {
876			# Determine if this file is allowed text relocations.
877			if (!$opt{a}) {
878				if ($File =~ $SkipTextrelFiles) {
879					$Tex = 0;
880					next ELF;
881				}
882			}
883			OutMsg($Ttl++, $RelPath,
884			    "\tTEXTREL .dynamic tag\t\t\t<no -Kpic?>");
885			$Tex = 0;
886			next;
887		}
888
889		# Does this file have any relocation sections (there are a few
890		# psr libraries with no relocations at all, thus a .SUNW_reloc
891		# section won't exist either).
892		if (($Relsz == 0) && ($Line =~ / RELA?SZ/)) {
893			$Relsz = hex((split(' ', $Line))[2]);
894			next;
895		}
896
897		# Does this file have any plt relocations.  If the plt size is
898		# equivalent to the total relocation size then we don't have
899		# any relocations suitable for combining into a .SUNW_reloc
900		# section.
901		if (($Pltsz == 0) && ($Line =~ / PLTRELSZ/)) {
902			$Pltsz = hex((split(' ', $Line))[2]);
903			next;
904		}
905
906		# Does this object have any dependencies.
907		if ($Line =~ /NEEDED/) {
908			my($Need) = (split(' ', $Line))[3];
909
910			if ($Need =~ $OldDeps) {
911				# Catch any old (unnecessary) dependencies.
912				OutMsg($Ttl++, $RelPath,
913				    "\tNEEDED=$Need\t<dependency no longer necessary>");
914			} elsif ($opt{i}) {
915				# Under the -i (information) option print out
916				# any useful dynamic entries.
917				OutMsg($Ttl++, $RelPath, "\tNEEDED=$Need");
918			}
919			next;
920		}
921
922		# Is this object built with -B direct flag on?
923		if ($Line =~ / DIRECT /) {
924			$HasDirectBinding = 1;
925		}
926
927		# Does this object specify a runpath.
928		if ($opt{i} && ($Line =~ /RPATH/)) {
929			my($Rpath) = (split(' ', $Line))[3];
930			OutMsg($Ttl++, $RelPath, "\tRPATH=$Rpath");
931			next;
932		}
933	}
934
935	# A shared object, that contains non-plt relocations, should have a
936	# combined relocation section indicating it was built with -z combreloc.
937	if ($Dll && $Relsz && ($Relsz != $Pltsz) && ($Sun == 0)) {
938		OutMsg($Ttl++, $RelPath,
939		    "\tSUNW_reloc section missing\t\t<no -zcombreloc?>");
940	}
941
942	# No objects released to a customer should have any .stabs sections
943	# remaining, they should be stripped.
944	if ($opt{s} && $Stab) {
945		if (!$opt{a}) {
946			if ($File =~ $SkipStabFiles) {
947				goto DONESTAB;
948			}
949		}
950		OutMsg($Ttl++, $RelPath,
951		    "\tdebugging sections should be deleted\t<no strip -x?>");
952	}
953
954	# Identify an object that is not built with either -B direct or
955	# -z direct.
956	if (($RelPath =~ $SkipDirectBindDirs) ||
957	    ($File =~ $SkipDirectBindFiles)) {
958		goto DONESTAB;
959	}
960	if ($Relsz && ($HasDirectBinding == 0)) {
961		OutMsg($Ttl++, $RelPath,
962		    "\tobject has no direct bindings\t<no -B direct or -z direct?>");
963	}
964
965DONESTAB:
966
967	# All objects should have a full symbol table to provide complete
968	# debugging stack traces.
969	if ($Strip) {
970		OutMsg($Ttl++, $RelPath,
971		    "\tsymbol table should not be stripped\t<remove -s?>");
972	}
973
974	# If there are symbol sort sections in this object, report on
975	# any that have duplicate addresses.
976	ProcSymSort($FullPath, $RelPath, \$Ttl) if $SymSort;
977
978	# If -v was specified, and the object has a version definition
979	# section, generate output showing each public symbol and the
980	# version it belongs to.
981	ProcVerdef($FullPath, $RelPath, \$Ttl) if $HasVerdef && $opt{v};
982}
983
984
985## ProcSymSortOutMsg(RefTtl, RelPath, secname, addr, names...)
986#
987# Call OutMsg for a duplicate address error in a symbol sort
988# section
989#
990sub ProcSymSortOutMsg {
991	my($RefTtl, $RelPath, $secname, $addr, @names) = @_;
992
993	OutMsg($$RefTtl++, $RelPath,
994	    "$secname: duplicate $addr: ". join(', ', @names));
995}
996
997
998## ProcSymSort(FullPath, RelPath)
999#
1000# Examine the symbol sort sections for the given object and report
1001# on any duplicate addresses found.  Ideally, mapfile directives
1002# should be used when building objects that have multiple symbols
1003# with the same address so that only one of them appears in the sort
1004# section. This saves space, reduces user confusion, and ensures that
1005# libproc and debuggers always display public names instead of symbols
1006# that are merely implementation details.
1007#
1008sub ProcSymSort {
1009
1010	my($FullPath, $RelPath, $RefTtl) = @_;
1011
1012	# If this object is exempt from checking, return quietly
1013	return if ($FullPath =~ $SkipSymSort);
1014
1015
1016	open(SORT, "elfdump -S $FullPath|") ||
1017	    die "$Prog: Unable to execute elfdump (symbol sort sections)\n";
1018
1019	my $line;
1020	my $last_addr;
1021	my @dups = ();
1022	my $secname;
1023	while ($line = <SORT>) {
1024		chomp $line;
1025
1026		next if ($line eq '');
1027
1028		# If this is a header line, pick up the section name
1029		if ($line =~ /^Symbol Sort Section:\s+([^\s]+)\s+/) {
1030			$secname = $1;
1031
1032			# Every new section is followed by a column header line
1033			$line = <SORT>;		# Toss header line
1034
1035			# Flush anything left from previous section
1036			ProcSymSortOutMsg($RefTtl, $RelPath, $secname,
1037			    $last_addr, @dups) if (scalar(@dups) > 1);
1038
1039			# Reset variables for new sort section
1040			$last_addr = '';
1041			@dups = ();
1042
1043			next;
1044		}
1045
1046		# Process symbol line
1047		my @fields = split /\s+/, $line;
1048		my $new_addr = $fields[2];
1049		my $new_type = $fields[8];
1050		my $new_name = $fields[9];
1051
1052		if ($new_type eq 'UNDEF') {
1053		    OutMsg($RefTtl++, $RelPath,
1054		        "$secname: unexpected UNDEF symbol " .
1055			"(link-editor error): $new_name");
1056		    next;
1057		}
1058
1059		if ($new_addr eq $last_addr) {
1060			push @dups, $new_name;
1061		} else {
1062			ProcSymSortOutMsg($RefTtl, $RelPath, $secname,
1063			    $last_addr, @dups) if (scalar(@dups) > 1);
1064			@dups = ( $new_name );
1065			$last_addr = $new_addr;
1066		}
1067	}
1068
1069	ProcSymSortOutMsg($RefTtl, $RelPath, $secname, $last_addr, @dups)
1070		if (scalar(@dups) > 1);
1071
1072	close SORT;
1073}
1074
1075
1076## ProcVerdef(FullPath, RelPath)
1077#
1078# Examine the version definition section for the given object and report
1079# each public symbol along with the version it belongs to.
1080#
1081sub ProcVerdef {
1082
1083	my($FullPath, $RelPath, $RefTtl) = @_;
1084	my $line;
1085	my $cur_ver = '';
1086	my $tab = $opt{o} ? '' : "\t";
1087
1088	# pvs -dov provides information about the versioning hierarchy
1089	# in the file. Lines are of the format:
1090	#	path - version[XXX];
1091	# where [XXX] indicates optional information, such as flags
1092	# or inherited versions.
1093	#
1094	# Private versions are allowed to change freely, so ignore them.
1095	open(PVS, "pvs -dov $FullPath|") ||
1096	    die "$Prog: Unable to execute pvs (version definition section)\n";
1097
1098	while ($line = <PVS>) {
1099		chomp $line;
1100
1101		if ($line =~ /^[^\s]+\s+-\s+([^;]+)/) {
1102			my $ver = $1;
1103
1104			next if $ver =~ /private/i;
1105			OutMsg($$RefTtl++, $RelPath, "${tab}VERDEF=$ver");
1106		}
1107	}
1108	close PVS;
1109
1110	# pvs -dos lists the symbols assigned to each version definition.
1111	# Lines are of the format:
1112	#	path - version: symbol;
1113	#	path - version: symbol (size);
1114	# where the (size) is added to data items, but not for functions.
1115	# We strip off the size, if present.
1116
1117	open(PVS, "pvs -dos $FullPath|") ||
1118	    die "$Prog: Unable to execute pvs (version definition section)\n";
1119	while ($line = <PVS>) {
1120		chomp $line;
1121		if ($line =~ /^[^\s]+\s+-\s+([^:]+):\s*([^\s;]+)/) {
1122		    my $ver = $1;
1123		    my $sym = $2;
1124
1125		    next if $ver =~ /private/i;
1126
1127		    if ($opt{o}) {
1128			OutMsg($$RefTtl++, $RelPath,
1129			       "VERSION=$ver, SYMBOL=$sym");
1130		    } else {
1131			if ($cur_ver ne $ver) {
1132			    OutMsg($$RefTtl++, $RelPath, "\tVERSION=$ver");
1133			    $cur_ver = $ver;
1134			}
1135			OutMsg($$RefTtl++, $RelPath, "\t\tSYMBOL=$sym");
1136		    }
1137		}
1138	}
1139
1140	close PVS;
1141}
1142
1143
1144sub ProcDir {
1145	my($FullDir, $RelDir) = @_;
1146	my($NewFull, $NewRel);
1147
1148	# Determine if this is a directory we don't care about.
1149	if (!$opt{a}) {
1150		if ($RelDir =~ $SkipDirs) {
1151			return;
1152		}
1153	}
1154
1155	# Open the directory and read each entry, omit files starting with "."
1156	if (opendir(DIR, $FullDir)) {
1157		foreach my $Entry (readdir(DIR)) {
1158			if ($Entry =~ /^\./) {
1159				next;
1160			}
1161			$NewFull = "$FullDir/$Entry";
1162
1163			# Ignore symlinks.
1164			if (-l $NewFull) {
1165				next;
1166			}
1167			if (!stat($NewFull)) {
1168				next;
1169			}
1170			$NewRel = "$RelDir/$Entry";
1171
1172			# Descend into and process any directories.
1173			if (-d _) {
1174				ProcDir($NewFull, $NewRel);
1175				next;
1176			}
1177
1178			# Typically dynamic objects are executable, so we can
1179			# reduce the overall cost of this script (a lot!) by
1180			# screening out non-executables here, rather than pass
1181			# them to file(1) later.  However, it has been known
1182			# for shared objects to be mistakenly left non-
1183			# executable, so with -a let all files through so that
1184			# this requirement can be verified (see ProcFile()).
1185			if (!$opt{a}) {
1186				if (! -x _) {
1187					next;
1188				}
1189			}
1190
1191			# Process any standard files.
1192			if (-f _) {
1193				my($Secure) = 0;
1194
1195				if (-u _ || -g _) {
1196					$Secure = 1;
1197				}
1198
1199				ProcFile($NewFull, $NewRel, $Entry, $Secure);
1200				next;
1201			}
1202
1203		}
1204		closedir(DIR);
1205	}
1206}
1207
1208# Create a crle(1) script for any 64-bit dependencies we locate.  A runtime
1209# configuration file will be generated to establish alternative dependency
1210# mappings for all these dependencies.
1211
1212sub Entercrle64 {
1213	my($FullDir, $RelDir, $Entry) = @_;
1214
1215	if (!$Crle64) {
1216		# Create and initialize the script if is doesn't already exit.
1217
1218		$Crle64 = "$Tmpdir/$Prog.crle64.$$";
1219		open(CRLE64, "> $Crle64") ||
1220			die "$Prog: open failed: $Crle64: $!";
1221
1222		print CRLE64 "#!/bin/sh\ncrle -64\\\n";
1223	}
1224	print CRLE64 "\t-o $FullDir -a $RelDir/$Entry \\\n";
1225}
1226
1227# Create a crle(1) script for any 32-bit dependencies we locate.  A runtime
1228# configuration file will be generated to establish alternative dependency
1229# mappings for all these dependencies.
1230
1231sub Entercrle32 {
1232	my($FullDir, $RelDir, $Entry) = @_;
1233
1234	if (!$Crle32) {
1235		# Create and initialize the script if is doesn't already exit.
1236
1237		$Crle32 = "$Tmpdir/$Prog.crle32.$$";
1238		open(CRLE32, "> $Crle32") ||
1239			die "$Prog: open failed: $Crle32: $!";
1240
1241		print CRLE32 "#!/bin/sh\ncrle \\\n";
1242	}
1243	print CRLE32 "\t-o $FullDir -a $RelDir/$Entry \\\n";
1244}
1245
1246# Having finished gathering dependencies, complete any crle(1) scripts and
1247# execute them to generate the associated runtime configuration files.  In
1248# addition establish the environment variable required to pass the configuration
1249# files to ldd(1).
1250
1251sub GenConf {
1252	if ($Crle64) {
1253		$Conf64 = "$Tmpdir/$Prog.conf64.$$";
1254		print CRLE64 "\t-c $Conf64\n";
1255
1256		chmod 0755, $Crle64;
1257		close CRLE64;
1258
1259		if (system($Crle64)) {
1260			undef $Conf64;
1261		}
1262	}
1263	if ($Crle32) {
1264		$Conf32 = "$Tmpdir/$Prog.conf32.$$";
1265		print CRLE32 "\t-c $Conf32\n";
1266
1267		chmod 0755, $Crle32;
1268		close CRLE32;
1269
1270		if (system($Crle32)) {
1271			undef $Conf32;
1272		}
1273	}
1274
1275	if ($Crle64 && $Conf64 && $Crle32 && $Conf32) {
1276		$Env = "-e LD_FLAGS=config_64=$Conf64,config_32=$Conf32";
1277	} elsif ($Crle64 && $Conf64) {
1278		$Env = "-e LD_FLAGS=config_64=$Conf64";
1279	} elsif ($Crle32 && $Conf32) {
1280		$Env = "-e LD_FLAGS=config_32=$Conf32";
1281	}
1282}
1283
1284# Recurse through a directory hierarchy looking for appropriate dependencies.
1285
1286sub GetDeps {
1287	my($FullDir, $RelDir) = @_;
1288	my($NewFull);
1289
1290	# Open the directory and read each entry, omit files starting with "."
1291	if (opendir(DIR, $FullDir)) {
1292		 foreach my $Entry (readdir(DIR)) {
1293			if ($Entry =~ /^\./) {
1294				next;
1295			}
1296			$NewFull = "$FullDir/$Entry";
1297
1298			# We need to follow links so that any dependencies
1299			# are expressed in all their available forms.
1300			# Bail on symlinks like 32 -> .
1301			if (-l $NewFull) {
1302				if (readlink($NewFull) =~ /^\.$/) {
1303					next;
1304				}
1305			}
1306			if (!stat($NewFull)) {
1307				next;
1308			}
1309
1310			if (!$opt{a}) {
1311				if ($NewFull =~ $SkipCrleConf) {
1312					next;
1313				}
1314			}
1315
1316			# If this is a directory descend into it.
1317			if (-d _) {
1318				my($NewRel);
1319
1320				if ($RelDir =~ /^\/$/) {
1321					$NewRel = "$RelDir$Entry";
1322				} else {
1323					$NewRel = "$RelDir/$Entry";
1324				}
1325
1326				GetDeps($NewFull, $NewRel);
1327				next;
1328			}
1329
1330			# If this is a regular file determine if its a
1331			# valid ELF dependency.
1332			if (-f _) {
1333				my($File);
1334
1335				# Typically shared object dependencies end with
1336				# ".so" or ".so.?", hence we can reduce the cost
1337				# of this script (a lot!) by screening out files
1338				# that don't follow this pattern.
1339				if (!$opt{a}) {
1340					if ($Entry !~ /\.so(?:\.\d+)*$/) {
1341						next;
1342					}
1343				}
1344
1345				$File = `file $NewFull`;
1346				if ($File !~ /dynamic lib/) {
1347					next;
1348				}
1349
1350				if ($File =~ /32-bit/) {
1351					Entercrle32($FullDir, $RelDir, $Entry);
1352				} elsif ($Ena64) {
1353					Entercrle64($FullDir, $RelDir, $Entry);
1354				}
1355				next;
1356			}
1357		}
1358		closedir(DIR);
1359	}
1360}
1361exit $Error
1362