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