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