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