17c478bd9Sstevel@tonic-gate#!/usr/perl5/bin/perl -w 27c478bd9Sstevel@tonic-gate# 37c478bd9Sstevel@tonic-gate# CDDL HEADER START 47c478bd9Sstevel@tonic-gate# 57c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the 6*749f21d3Swesolows# Common Development and Distribution License (the "License"). 7*749f21d3Swesolows# You may not use this file except in compliance with the License. 87c478bd9Sstevel@tonic-gate# 97c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate# and limitations under the License. 137c478bd9Sstevel@tonic-gate# 147c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate# 207c478bd9Sstevel@tonic-gate# CDDL HEADER END 217c478bd9Sstevel@tonic-gate# 22*749f21d3Swesolows 237c478bd9Sstevel@tonic-gate# 24*749f21d3Swesolows# Copyright 2006 Sun Microsystems, Inc. All rights reserved. 257c478bd9Sstevel@tonic-gate# Use is subject to license terms. 267c478bd9Sstevel@tonic-gate# 277c478bd9Sstevel@tonic-gate# ident "%Z%%M% %I% %E% SMI" 287c478bd9Sstevel@tonic-gate# 29*749f21d3Swesolows 30*749f21d3Swesolows# 317c478bd9Sstevel@tonic-gate# Check ELF information. 327c478bd9Sstevel@tonic-gate# 337c478bd9Sstevel@tonic-gate# This script descends a directory hierarchy inspecting ELF dynamic executables 347c478bd9Sstevel@tonic-gate# and shared objects. The general theme is to verify that common Makefile rules 357c478bd9Sstevel@tonic-gate# have been used to build these objects. Typical failures occur when Makefile 367c478bd9Sstevel@tonic-gate# rules are re-invented rather than being inherited from "cmd/lib" Makefiles. 377c478bd9Sstevel@tonic-gate# 387c478bd9Sstevel@tonic-gate# As always, a number of components don't follow the rules, and these are 397c478bd9Sstevel@tonic-gate# excluded to reduce this scripts output. Pathnames used for this exclusion 407c478bd9Sstevel@tonic-gate# assume this script is being run over a "proto" area. The -a (all) option 417c478bd9Sstevel@tonic-gate# skips any exclusions. 427c478bd9Sstevel@tonic-gate# 437c478bd9Sstevel@tonic-gate# By default any file that has conditions that should be reported is first 447c478bd9Sstevel@tonic-gate# listed and then each condition follows. The -o (one-line) option produces a 457c478bd9Sstevel@tonic-gate# more terse output which is better for sorting/diffing with "nightly". 467c478bd9Sstevel@tonic-gate# 477c478bd9Sstevel@tonic-gate# NOTE: missing dependencies, symbols or versions are reported by running the 487c478bd9Sstevel@tonic-gate# file through ldd(1). As objects within a proto area are built to exist in a 497c478bd9Sstevel@tonic-gate# base system, standard use of ldd(1) will bind any objects to dependencies 507c478bd9Sstevel@tonic-gate# that exist in the base system. It is frequently the case that newer objects 517c478bd9Sstevel@tonic-gate# exist in the proto area that are required to satisfy other objects 527c478bd9Sstevel@tonic-gate# dependencies, and without using these newer objects an ldd(1) will produce 537c478bd9Sstevel@tonic-gate# misleading error messages. To compensate for this, the -d option (or the 547c478bd9Sstevel@tonic-gate# existence of the CODEMSG_WS/ROOT environment variables) cause the creation of 557c478bd9Sstevel@tonic-gate# alternative dependency mappings via crle(1) configuration files that establish 567c478bd9Sstevel@tonic-gate# any proto shared objects as alternatives to their base system location. Thus 577c478bd9Sstevel@tonic-gate# ldd(1) can be executed against these configuration files so that objects in a 587c478bd9Sstevel@tonic-gate# proto area bind to their dependencies in the same proto area. 597c478bd9Sstevel@tonic-gate 607c478bd9Sstevel@tonic-gate 617c478bd9Sstevel@tonic-gate# Define all global variables (required for strict) 627c478bd9Sstevel@tonic-gateuse vars qw($SkipDirs $SkipFiles $SkipTextrelFiles); 637c478bd9Sstevel@tonic-gateuse vars qw($SkipUndefDirs $SkipUndefFiles $SkipUnusedDirs $SkipUnusedFiles); 648ad60789Srieuse vars qw($SkipStabFiles $SkipNoExStkFiles); 657c478bd9Sstevel@tonic-gateuse vars qw($UnusedNoise $Prog $Mach $Isalist $Env $Ena64 $Tmpdir $Error); 667c478bd9Sstevel@tonic-gateuse vars qw($UnusedFiles $UnusedPaths $LddNoU $Crle32 $Crle64 $Conf32 $Conf64); 677c478bd9Sstevel@tonic-gateuse vars qw($SkipInterps $OldDeps %opt); 687c478bd9Sstevel@tonic-gate 697c478bd9Sstevel@tonic-gateuse strict; 707c478bd9Sstevel@tonic-gate 717c478bd9Sstevel@tonic-gate 727c478bd9Sstevel@tonic-gate# Define any directories we should skip completely. 737c478bd9Sstevel@tonic-gate$SkipDirs = qr{ 747c478bd9Sstevel@tonic-gate etc/lib | # special - used for partial statics 757c478bd9Sstevel@tonic-gate usr/lib/devfsadm | # 4382889 767c478bd9Sstevel@tonic-gate usr/lib/libc | # optimized libc 777c478bd9Sstevel@tonic-gate usr/lib/rcm | # 4426119 787c478bd9Sstevel@tonic-gate usr/perl5 | # alan's taking care of these :-) 797c478bd9Sstevel@tonic-gate usr/src # no need to look at shipped source 807c478bd9Sstevel@tonic-gate}x; 817c478bd9Sstevel@tonic-gate 827c478bd9Sstevel@tonic-gate# Define any files we should skip completely. 837c478bd9Sstevel@tonic-gate$SkipFiles = qr{ ^(?: 847c478bd9Sstevel@tonic-gate ld\.so\.1 | # confusing but correct dependencies 857c478bd9Sstevel@tonic-gate lddstub | # lddstub has no dependencies 867c478bd9Sstevel@tonic-gate libmakestate\.so\.1 | # temporary; delivered by compiler group 877c478bd9Sstevel@tonic-gate libm\.so\.1 | # temporary; delivered by compiler group 887c478bd9Sstevel@tonic-gate libm\.so\.2 | # temporary; delivered by compiler group 897c478bd9Sstevel@tonic-gate geniconvtbl\.so | # 4384329 907c478bd9Sstevel@tonic-gate libssagent\.so\.1 | # 4328854 917c478bd9Sstevel@tonic-gate libdmi\.so\.1 | # " " 927c478bd9Sstevel@tonic-gate libdmici\.so\.1 | # " " 937c478bd9Sstevel@tonic-gate libdmimi\.so\.1 | # " " 947c478bd9Sstevel@tonic-gate libpsvcplugin_psr\.so\.1 | # 4385799 957c478bd9Sstevel@tonic-gate libpsvcpolicy_psr\.so\.1 | # " " 967c478bd9Sstevel@tonic-gate libpsvcpolicy\.so\.1 | # " " 977c478bd9Sstevel@tonic-gate picl_slm\.so | # " " 987c478bd9Sstevel@tonic-gate libcrypto_extra\.so\.0\.9\.7 | # OpenSSL SUNWcry filter lib 997c478bd9Sstevel@tonic-gate libssl_extra\.so\.0\.9\.7 | # OpenSSL SUNWcry filter lib 1007c478bd9Sstevel@tonic-gate fcpackage\.so | # circular dependency on fcthread.so 1017c478bd9Sstevel@tonic-gate grub 1027c478bd9Sstevel@tonic-gate )$ 1037c478bd9Sstevel@tonic-gate}x; 1047c478bd9Sstevel@tonic-gate 1057c478bd9Sstevel@tonic-gate# Define any files that are allowed text relocations. 1067c478bd9Sstevel@tonic-gate$SkipTextrelFiles = qr{ ^(?: 1077c478bd9Sstevel@tonic-gate unix | # kernel models are non-pic 1087c478bd9Sstevel@tonic-gate mdb # relocations against __RTC (dbx) 1097c478bd9Sstevel@tonic-gate )$ 1107c478bd9Sstevel@tonic-gate}x; 1117c478bd9Sstevel@tonic-gate 1127c478bd9Sstevel@tonic-gate# Define any files that are allowed undefined references. 1137c478bd9Sstevel@tonic-gate$SkipUndefDirs = qr{ 1147c478bd9Sstevel@tonic-gate usr/lib/inet/ppp/ | # pppd plugins have callbacks 1157c478bd9Sstevel@tonic-gate usr/lib/libp/ | # libc.so.1 requires _mcount 1167c478bd9Sstevel@tonic-gate usr/lib/vold/ | # vold dependencies have callbacks 1177c478bd9Sstevel@tonic-gate usr/lib/rmmount | # rmmount actions have callbacks 1187c478bd9Sstevel@tonic-gate /lib/mdb/ | # mdb modules have callbacks 1197c478bd9Sstevel@tonic-gate /lib/fm/fmd/plugins/ | # fmd modules have callbacks 1207c478bd9Sstevel@tonic-gate /lib/fm/fmd/schemes/ # fmd schemes have callbacks 1217c478bd9Sstevel@tonic-gate}x; 1227c478bd9Sstevel@tonic-gate 1237c478bd9Sstevel@tonic-gate$SkipUndefFiles = qr{ ^(?: 1247c478bd9Sstevel@tonic-gate libthread_db\.so\.0 | # callbacks to proc service interface 1257c478bd9Sstevel@tonic-gate libthread_db\.so\.1 | # " " " " 1267c478bd9Sstevel@tonic-gate librtld_db\.so\.1 | # " " " " 1277c478bd9Sstevel@tonic-gate libc_db\.so\.1 | # " " " " 1287c478bd9Sstevel@tonic-gate libldstab\.so\.1 | # link-edit support libraries have 1297c478bd9Sstevel@tonic-gate libld\.so\.3 | # callback to the link-editors 1307c478bd9Sstevel@tonic-gate libld\.so\.2 | # " " " " 1317c478bd9Sstevel@tonic-gate liblddbg\.so\.4 | # " " " " 1327c478bd9Sstevel@tonic-gate librtld\.so\.1 | # " " " " 1337c478bd9Sstevel@tonic-gate libnisdb\.so\.2 | # C++ 1347c478bd9Sstevel@tonic-gate libsvm\.so\.1 | # libspmicommon.so.1 lacking 1357c478bd9Sstevel@tonic-gate libwanboot\.so\.1 | # libcrypto.a and libssl.a 1367c478bd9Sstevel@tonic-gate libwrap\.so\.1\.0 | # uses symbols provided by application 1377c478bd9Sstevel@tonic-gate fcthread\.so | # uses symbols provided by application 1387c478bd9Sstevel@tonic-gate fn\.so\.2 | # callback to automount 1397c478bd9Sstevel@tonic-gate preen_md\.so\.1 | # callback to driver 1407c478bd9Sstevel@tonic-gate libike\.so\.1 | # callbacks to in.iked for IKE policy 1417c478bd9Sstevel@tonic-gate devfsadmd_mod\.so | # sysevent module callback to syseventd 1427c478bd9Sstevel@tonic-gate sysevent_conf_mod\.so | # sysevent module callback to syseventd 1437c478bd9Sstevel@tonic-gate sysevent_reg_mod\.so # sysevent module callback to syseventd 1447c478bd9Sstevel@tonic-gate )$ 1457c478bd9Sstevel@tonic-gate}x; 1467c478bd9Sstevel@tonic-gate 1477c478bd9Sstevel@tonic-gate# Define any files that have unused dependencies. 1487c478bd9Sstevel@tonic-gate$SkipUnusedDirs = qr{ 1497c478bd9Sstevel@tonic-gate lib/picl/plugins/ | # require devtree dependencies 1507c478bd9Sstevel@tonic-gate /lib/libp # profile libc makes libm an unused 1517c478bd9Sstevel@tonic-gate}x; # dependency of standard libc 1527c478bd9Sstevel@tonic-gate 1537c478bd9Sstevel@tonic-gate$SkipUnusedFiles = qr{ ^(?: 1547c478bd9Sstevel@tonic-gate devfsadm | # 4382889 1557c478bd9Sstevel@tonic-gate disks | # " " 1567c478bd9Sstevel@tonic-gate tapes | # " " 1577c478bd9Sstevel@tonic-gate ports | # " " 1587c478bd9Sstevel@tonic-gate audlinks | # " " 1597c478bd9Sstevel@tonic-gate devlinks | # " " 1607c478bd9Sstevel@tonic-gate drvconfig | # " " 1617c478bd9Sstevel@tonic-gate ntptrace | # on intel doesn't need libmd5 1627c478bd9Sstevel@tonic-gate rmmount | # 4418770, volmgt dependency is required 1637c478bd9Sstevel@tonic-gate # to compensate for SunPCi. 1647c478bd9Sstevel@tonic-gate ocfserv | # libsched unreference by libjvm, 1657c478bd9Sstevel@tonic-gate poold | # see 4952319. 1667c478bd9Sstevel@tonic-gate libc\.so\.1\.9 | # 4lib/libc versions have private 1677c478bd9Sstevel@tonic-gate libc\.so\.2\.9 # copies of stuff from libc. 1687c478bd9Sstevel@tonic-gate )$ 1697c478bd9Sstevel@tonic-gate}x; 1707c478bd9Sstevel@tonic-gate 1717c478bd9Sstevel@tonic-gate# Define any files that should contain debugging information. 1727c478bd9Sstevel@tonic-gate$SkipStabFiles = qr{ ^(?: 1737c478bd9Sstevel@tonic-gate abi_.* | 1747c478bd9Sstevel@tonic-gate interceptors\.so\.1 | 1757c478bd9Sstevel@tonic-gate unix 1767c478bd9Sstevel@tonic-gate )$ 1777c478bd9Sstevel@tonic-gate}x; 1787c478bd9Sstevel@tonic-gate 1797c478bd9Sstevel@tonic-gate# Define any files that don't require a non-executable stack definition. 1807c478bd9Sstevel@tonic-gate$SkipNoExStkFiles = qr{ ^(?: 1817c478bd9Sstevel@tonic-gate forth | 1827c478bd9Sstevel@tonic-gate unix | 1837c478bd9Sstevel@tonic-gate multiboot 1847c478bd9Sstevel@tonic-gate )$ 1857c478bd9Sstevel@tonic-gate}x; 1867c478bd9Sstevel@tonic-gate 1877c478bd9Sstevel@tonic-gate# Define any files that should only have unused (ldd -u) processing. 1887c478bd9Sstevel@tonic-gate$UnusedPaths = qr{ 1897c478bd9Sstevel@tonic-gate ucb/shutdown # libucb interposes on libc and makes 1907c478bd9Sstevel@tonic-gate # dependencies on libc seem unnecessary 1917c478bd9Sstevel@tonic-gate}x; 1927c478bd9Sstevel@tonic-gate 1937c478bd9Sstevel@tonic-gate$UnusedFiles = qr{ ^(?: 1947c478bd9Sstevel@tonic-gate rpc\.nisd # CCNEEDED makes pthread unreferenced 1957c478bd9Sstevel@tonic-gate )$ 1967c478bd9Sstevel@tonic-gate}x; 1977c478bd9Sstevel@tonic-gate 1987c478bd9Sstevel@tonic-gate# Define unused dependencies we should ignore. 1997c478bd9Sstevel@tonic-gate# libCrun has a unnecessary dependency on libw, and libmapmalloc is often 2007c478bd9Sstevel@tonic-gate# defined to interpose on libc but isn't used by the application itself. 2017c478bd9Sstevel@tonic-gate# Threads dependencies look unused if libc is bound first. 2027c478bd9Sstevel@tonic-gate$UnusedNoise = qr{ 2037c478bd9Sstevel@tonic-gate libw\.so\.1;\ unused | 2047c478bd9Sstevel@tonic-gate unused\ object=.*libw\.so\.1 | 2057c478bd9Sstevel@tonic-gate libthread\.so\.1;\ unused | 2067c478bd9Sstevel@tonic-gate libpthread\.so\.1;\ unused | 2077c478bd9Sstevel@tonic-gate unused\ object=.*libpthread\.so\.1 | 2087c478bd9Sstevel@tonic-gate libnsl\.so\.1;\ unused\ dependency\ of\ .*libxslt\.so\.1 | 2097c478bd9Sstevel@tonic-gate libdl\.so\.1;\ unused\ dependency\ of\ .*libspmicommon\.so\.1 | 2107c478bd9Sstevel@tonic-gate libdl\.so\.1;\ unused\ dependency\ of\ .*libCrun\.so\.1 | 2117c478bd9Sstevel@tonic-gate libfru\.so\.1;\ unused\ object=.*libdl\.so\.1 | 2127c478bd9Sstevel@tonic-gate libfrupicl\.so\.1;\ unused\ object=.*libdl\.so\.1 | 2131b605adaSmike_s libmapmalloc\.so\.1;\ unused | 2141b605adaSmike_s unused\ dependency\ of\ .*libstdc\+\+\.so\.6 | 215*749f21d3Swesolows unreferenced\ object=.*libstdc\+\+\.so\.6 | 216*749f21d3Swesolows unused\ dependency\ of\ .*libnetsnmphelpers\.so\.5 | 217*749f21d3Swesolows unused\ dependency\ of\ .*libnetsnmpmibs\.so\.5 | 218*749f21d3Swesolows unused\ dependency\ of\ .*libnetsnmpagent\.so\.5 2197c478bd9Sstevel@tonic-gate}x; 2207c478bd9Sstevel@tonic-gate 2217c478bd9Sstevel@tonic-gate# Define interpreters we should ignore. 2227c478bd9Sstevel@tonic-gate$SkipInterps = qr{ 2237c478bd9Sstevel@tonic-gate misc/krtld | 2247c478bd9Sstevel@tonic-gate misc/amd64/krtld | 2257c478bd9Sstevel@tonic-gate misc/sparcv9/krtld 2267c478bd9Sstevel@tonic-gate}x; 2277c478bd9Sstevel@tonic-gate 2287c478bd9Sstevel@tonic-gate# Catch libintl and libw, although ld(1) will bind to these and thus determine 2297c478bd9Sstevel@tonic-gate# they're needed, their content was moved into libc as of on297 build 7. 2307c478bd9Sstevel@tonic-gate# libthread and libpthread were completely moved into libc as of on10 build 53. 2317c478bd9Sstevel@tonic-gate# Also, catch libdl, whose content was moved into libc as of on10 build 49. 2327c478bd9Sstevel@tonic-gate$OldDeps = qr{ ^(?: 2337c478bd9Sstevel@tonic-gate libintl\.so\.1 | 2347c478bd9Sstevel@tonic-gate libw\.so\.1 | 2357c478bd9Sstevel@tonic-gate libthread\.so\.1 | 2367c478bd9Sstevel@tonic-gate libpthread\.so\.1 | 2377c478bd9Sstevel@tonic-gate libdl\.so\.1 2387c478bd9Sstevel@tonic-gate )$ 2397c478bd9Sstevel@tonic-gate}x; 2407c478bd9Sstevel@tonic-gate 2417c478bd9Sstevel@tonic-gateuse Getopt::Std; 2427c478bd9Sstevel@tonic-gate 2437c478bd9Sstevel@tonic-gate# ----------------------------------------------------------------------------- 2447c478bd9Sstevel@tonic-gate 2457c478bd9Sstevel@tonic-gate# Reliably compare two OS revisions. Arguments are <ver1> <op> <ver2>. 2467c478bd9Sstevel@tonic-gate# <op> is the string form of a normal numeric comparison operator. 2477c478bd9Sstevel@tonic-gatesub cmp_os_ver { 2487c478bd9Sstevel@tonic-gate my @ver1 = split(/\./, $_[0]); 2497c478bd9Sstevel@tonic-gate my $op = $_[1]; 2507c478bd9Sstevel@tonic-gate my @ver2 = split(/\./, $_[2]); 2517c478bd9Sstevel@tonic-gate 2527c478bd9Sstevel@tonic-gate push @ver2, ("0") x $#ver1 - $#ver2; 2537c478bd9Sstevel@tonic-gate push @ver1, ("0") x $#ver2 - $#ver1; 2547c478bd9Sstevel@tonic-gate 2557c478bd9Sstevel@tonic-gate my $diff = 0; 2567c478bd9Sstevel@tonic-gate while (@ver1 || @ver2) { 2577c478bd9Sstevel@tonic-gate if (($diff = shift(@ver1) - shift(@ver2)) != 0) { 2587c478bd9Sstevel@tonic-gate last; 2597c478bd9Sstevel@tonic-gate } 2607c478bd9Sstevel@tonic-gate } 2617c478bd9Sstevel@tonic-gate return (eval "$diff $op 0" ? 1 : 0); 2627c478bd9Sstevel@tonic-gate} 2637c478bd9Sstevel@tonic-gate 2647c478bd9Sstevel@tonic-gate# Establish a program name for any error diagnostics. 2657c478bd9Sstevel@tonic-gatechomp($Prog = `basename $0`); 2667c478bd9Sstevel@tonic-gate 2677c478bd9Sstevel@tonic-gate# Determine what machinery is available. 2687c478bd9Sstevel@tonic-gate$Mach = `uname -p`; 2697c478bd9Sstevel@tonic-gate$Isalist = `isalist`; 2707c478bd9Sstevel@tonic-gate$Env = ""; 2717c478bd9Sstevel@tonic-gateif ($Mach =~ /sparc/) { 2727c478bd9Sstevel@tonic-gate if ($Isalist =~ /sparcv9/) { 2737c478bd9Sstevel@tonic-gate $Ena64 = "ok"; 2747c478bd9Sstevel@tonic-gate } 2757c478bd9Sstevel@tonic-gate} elsif ($Mach =~ /i386/) { 2767c478bd9Sstevel@tonic-gate if ($Isalist =~ /amd64/) { 2777c478bd9Sstevel@tonic-gate $Ena64 = "ok"; 2787c478bd9Sstevel@tonic-gate } 2797c478bd9Sstevel@tonic-gate} 2807c478bd9Sstevel@tonic-gate 2817c478bd9Sstevel@tonic-gate# Check that we have arguments. 2827c478bd9Sstevel@tonic-gateif ((getopts('ad:imos', \%opt) == 0) || ($#ARGV == -1)) { 2837c478bd9Sstevel@tonic-gate print "usage: $Prog [-a] [-d depdir] [-m] [-o] [-s] file | dir, ...\n"; 2847c478bd9Sstevel@tonic-gate print "\t[-a]\t\tprocess all files (ignore any exception lists)\n"; 2857c478bd9Sstevel@tonic-gate print "\t[-d dir]\testablish dependencies from under directory\n"; 2867c478bd9Sstevel@tonic-gate print "\t[-i]\t\tproduce dynamic table entry information\n"; 2877c478bd9Sstevel@tonic-gate print "\t[-m]\t\tprocess mcs(1) comments\n"; 2887c478bd9Sstevel@tonic-gate print "\t[-o]\t\tproduce one-liner output (prefixed with pathname)\n"; 2897c478bd9Sstevel@tonic-gate print "\t[-s]\t\tprocess .stab and .symtab entries\n"; 2907c478bd9Sstevel@tonic-gate exit 1; 2917c478bd9Sstevel@tonic-gate} else { 2927c478bd9Sstevel@tonic-gate my($Proto); 2937c478bd9Sstevel@tonic-gate 2947c478bd9Sstevel@tonic-gate if ($opt{d}) { 2957c478bd9Sstevel@tonic-gate # User specified dependency directory - make sure it exists. 2967c478bd9Sstevel@tonic-gate if (! -d $opt{d}) { 2977c478bd9Sstevel@tonic-gate print "$Prog: $opt{d} is not a directory\n"; 2987c478bd9Sstevel@tonic-gate exit 1; 2997c478bd9Sstevel@tonic-gate } 3007c478bd9Sstevel@tonic-gate $Proto = $opt{d}; 3017c478bd9Sstevel@tonic-gate 3027c478bd9Sstevel@tonic-gate } elsif ($ENV{CODEMGR_WS}) { 3037c478bd9Sstevel@tonic-gate my($Root); 3047c478bd9Sstevel@tonic-gate 3057c478bd9Sstevel@tonic-gate # Without a user specified dependency directory see if we're 3067c478bd9Sstevel@tonic-gate # part of a codemanager workspace and if a proto area exists. 3077c478bd9Sstevel@tonic-gate if (($Root = $ENV{ROOT}) && (-d $Root)) { 3087c478bd9Sstevel@tonic-gate $Proto = $Root; 3097c478bd9Sstevel@tonic-gate } 3107c478bd9Sstevel@tonic-gate } 3117c478bd9Sstevel@tonic-gate 3127c478bd9Sstevel@tonic-gate if (!($Tmpdir = $ENV{TMPDIR}) || (! -d $Tmpdir)) { 3137c478bd9Sstevel@tonic-gate $Tmpdir = "/tmp"; 3147c478bd9Sstevel@tonic-gate } 3157c478bd9Sstevel@tonic-gate 3167c478bd9Sstevel@tonic-gate # Look for dependencies under $Proto. 3177c478bd9Sstevel@tonic-gate if ($Proto) { 3187c478bd9Sstevel@tonic-gate # To support alternative dependency mapping we'll need ldd(1)'s 3197c478bd9Sstevel@tonic-gate # -e option. This is relatively new (s81_30), so make sure 3207c478bd9Sstevel@tonic-gate # ldd(1)is capable before gathering any dependency information. 3217c478bd9Sstevel@tonic-gate if (system('ldd -e /usr/lib/lddstub 2> /dev/null')) { 3227c478bd9Sstevel@tonic-gate print "ldd: does not support -e, unable to "; 3237c478bd9Sstevel@tonic-gate print "create alternative dependency mappingings.\n"; 3247c478bd9Sstevel@tonic-gate print "ldd: option added under 4390308 (s81_30).\n\n"; 3257c478bd9Sstevel@tonic-gate } else { 3267c478bd9Sstevel@tonic-gate # Gather dependencies and construct a alternative 3277c478bd9Sstevel@tonic-gate # dependency mapping via a crle(1) configuration file. 3287c478bd9Sstevel@tonic-gate GetDeps($Proto, "/"); 3297c478bd9Sstevel@tonic-gate GenConf(); 3307c478bd9Sstevel@tonic-gate } 3317c478bd9Sstevel@tonic-gate } 3327c478bd9Sstevel@tonic-gate 3337c478bd9Sstevel@tonic-gate # To support unreferenced dependency detection we'll need ldd(1)'s -U 3347c478bd9Sstevel@tonic-gate # option. This is relatively new (4638070), and if not available we 3357c478bd9Sstevel@tonic-gate # can still fall back to -u. Even with this option, don't use -U with 3367c478bd9Sstevel@tonic-gate # releases prior to 5.10 as the cleanup for -U use only got integrated 3377c478bd9Sstevel@tonic-gate # into 5.10 under 4642023. Note, that nightly doesn't typically set a 3387c478bd9Sstevel@tonic-gate # RELEASE from the standard <env> files. Users who wish to disable use 3397c478bd9Sstevel@tonic-gate # of ldd(1)'s -U should set (or uncomment) RELEASE in their <env> file 3407c478bd9Sstevel@tonic-gate # if using nightly, or otherwise establish it in their environment. 3417c478bd9Sstevel@tonic-gate if (system('ldd -U /usr/lib/lddstub 2> /dev/null')) { 3427c478bd9Sstevel@tonic-gate $LddNoU = 1; 3437c478bd9Sstevel@tonic-gate } else { 3447c478bd9Sstevel@tonic-gate my($Release); 3457c478bd9Sstevel@tonic-gate 3467c478bd9Sstevel@tonic-gate if (($Release = $ENV{RELEASE}) && 3477c478bd9Sstevel@tonic-gate (cmp_os_ver($Release, "<", "5.10"))) { 3487c478bd9Sstevel@tonic-gate $LddNoU = 1; 3497c478bd9Sstevel@tonic-gate } else { 3507c478bd9Sstevel@tonic-gate $LddNoU = 0; 3517c478bd9Sstevel@tonic-gate } 3527c478bd9Sstevel@tonic-gate } 3537c478bd9Sstevel@tonic-gate 3547c478bd9Sstevel@tonic-gate # For each argument determine if we're dealing with a file or directory. 3557c478bd9Sstevel@tonic-gate foreach my $Arg (@ARGV) { 3567c478bd9Sstevel@tonic-gate # Ignore symbolic links. 3577c478bd9Sstevel@tonic-gate if (-l $Arg) { 3587c478bd9Sstevel@tonic-gate next; 3597c478bd9Sstevel@tonic-gate } 3607c478bd9Sstevel@tonic-gate 3617c478bd9Sstevel@tonic-gate if (!stat($Arg)) { 3627c478bd9Sstevel@tonic-gate next; 3637c478bd9Sstevel@tonic-gate } 3647c478bd9Sstevel@tonic-gate 3657c478bd9Sstevel@tonic-gate # Process simple files. 3667c478bd9Sstevel@tonic-gate if (-f _) { 3677c478bd9Sstevel@tonic-gate my($RelPath) = $Arg; 3687c478bd9Sstevel@tonic-gate my($File) = $Arg; 3697c478bd9Sstevel@tonic-gate my($Secure) = 0; 3707c478bd9Sstevel@tonic-gate 3717c478bd9Sstevel@tonic-gate $RelPath =~ s!^.*/!./!; 3727c478bd9Sstevel@tonic-gate $File =~ s!^.*/!!; 3737c478bd9Sstevel@tonic-gate 3747c478bd9Sstevel@tonic-gate if (-u _ || -g _) { 3757c478bd9Sstevel@tonic-gate $Secure = 1; 3767c478bd9Sstevel@tonic-gate } 3777c478bd9Sstevel@tonic-gate 3787c478bd9Sstevel@tonic-gate ProcFile($Arg, $RelPath, $File, $Secure); 3797c478bd9Sstevel@tonic-gate next; 3807c478bd9Sstevel@tonic-gate } 3817c478bd9Sstevel@tonic-gate # Process directories. 3827c478bd9Sstevel@tonic-gate if (-d _) { 3837c478bd9Sstevel@tonic-gate ProcDir($Arg, "."); 3847c478bd9Sstevel@tonic-gate next; 3857c478bd9Sstevel@tonic-gate } 3867c478bd9Sstevel@tonic-gate 3877c478bd9Sstevel@tonic-gate print "$Arg is not a file or directory\n"; 3887c478bd9Sstevel@tonic-gate $Error = 1; 3897c478bd9Sstevel@tonic-gate } 3907c478bd9Sstevel@tonic-gate 3917c478bd9Sstevel@tonic-gate # Cleanup 3927c478bd9Sstevel@tonic-gate CleanUp(); 3937c478bd9Sstevel@tonic-gate} 3947c478bd9Sstevel@tonic-gate 3957c478bd9Sstevel@tonic-gate$Error = 0; 3967c478bd9Sstevel@tonic-gate 3977c478bd9Sstevel@tonic-gate# Clean up and temporary files. 3987c478bd9Sstevel@tonic-gatesub CleanUp { 3997c478bd9Sstevel@tonic-gate if ($Crle64) { 4007c478bd9Sstevel@tonic-gate unlink $Crle64; 4017c478bd9Sstevel@tonic-gate } 4027c478bd9Sstevel@tonic-gate if ($Conf64) { 4037c478bd9Sstevel@tonic-gate unlink $Conf64; 4047c478bd9Sstevel@tonic-gate } 4057c478bd9Sstevel@tonic-gate if ($Crle32) { 4067c478bd9Sstevel@tonic-gate unlink $Crle32; 4077c478bd9Sstevel@tonic-gate } 4087c478bd9Sstevel@tonic-gate if ($Conf32) { 4097c478bd9Sstevel@tonic-gate unlink $Conf32; 4107c478bd9Sstevel@tonic-gate } 4117c478bd9Sstevel@tonic-gate} 4127c478bd9Sstevel@tonic-gate 4137c478bd9Sstevel@tonic-gate# Create an output message, either a one-liner (under -o) or preceded by the 4147c478bd9Sstevel@tonic-gate# files relative pathname as a title. 4157c478bd9Sstevel@tonic-gatesub OutMsg { 4167c478bd9Sstevel@tonic-gate my($Ttl, $Path, $Msg) = @_; 4177c478bd9Sstevel@tonic-gate 4187c478bd9Sstevel@tonic-gate if ($opt{o}) { 4197c478bd9Sstevel@tonic-gate $Msg =~ s/^[ \t]*//; 4207c478bd9Sstevel@tonic-gate print "$Path: $Msg\n"; 4217c478bd9Sstevel@tonic-gate } else { 4227c478bd9Sstevel@tonic-gate if ($Ttl eq 0) { 4237c478bd9Sstevel@tonic-gate print "==== $Path ====\n"; 4247c478bd9Sstevel@tonic-gate } 4257c478bd9Sstevel@tonic-gate print "$Msg\n"; 4267c478bd9Sstevel@tonic-gate } 4277c478bd9Sstevel@tonic-gate} 4287c478bd9Sstevel@tonic-gate 4297c478bd9Sstevel@tonic-gate# Determine whether this a ELF dynamic object and if so investigate its runtime 4307c478bd9Sstevel@tonic-gate# attributes. 4317c478bd9Sstevel@tonic-gatesub ProcFile { 4327c478bd9Sstevel@tonic-gate my($FullPath, $RelPath, $File, $Secure) = @_; 4337c478bd9Sstevel@tonic-gate my(@Elf, @Ldd, $Dyn, $Intp, $Dll, $Ttl, $Sym, $Interp, $Stack); 4347c478bd9Sstevel@tonic-gate my($Sun, $Relsz, $Pltsz, $Uns, $Tex, $Stab, $Strip, $Lddopt); 4357c478bd9Sstevel@tonic-gate my($Val, $Header, $SkipLdd, $IsX86, $RWX); 4367c478bd9Sstevel@tonic-gate 4377c478bd9Sstevel@tonic-gate # Ignore symbolic links. 4387c478bd9Sstevel@tonic-gate if (-l $FullPath) { 4397c478bd9Sstevel@tonic-gate return; 4407c478bd9Sstevel@tonic-gate } 4417c478bd9Sstevel@tonic-gate 4427c478bd9Sstevel@tonic-gate $Ttl = 0; 4437c478bd9Sstevel@tonic-gate @Ldd = 0; 4447c478bd9Sstevel@tonic-gate 4457c478bd9Sstevel@tonic-gate # Determine whether we have access to inspect the file. 4467c478bd9Sstevel@tonic-gate if (!(-r $FullPath)) { 4477c478bd9Sstevel@tonic-gate OutMsg($Ttl++, $RelPath, 4487c478bd9Sstevel@tonic-gate "\tunable to inspect file: permission denied"); 4497c478bd9Sstevel@tonic-gate return; 4507c478bd9Sstevel@tonic-gate } 4517c478bd9Sstevel@tonic-gate 4527c478bd9Sstevel@tonic-gate # Determine if this is a file we don't care about. 4537c478bd9Sstevel@tonic-gate if (!$opt{a}) { 4547c478bd9Sstevel@tonic-gate if ($File =~ $SkipFiles) { 4557c478bd9Sstevel@tonic-gate return; 4567c478bd9Sstevel@tonic-gate } 4577c478bd9Sstevel@tonic-gate } 4587c478bd9Sstevel@tonic-gate 4597c478bd9Sstevel@tonic-gate # Determine whether we have a executable (static or dynamic) or a 4607c478bd9Sstevel@tonic-gate # shared object. 4617c478bd9Sstevel@tonic-gate @Elf = split(/\n/, `elfdump -epdic $FullPath 2>&1`); 4627c478bd9Sstevel@tonic-gate 4637c478bd9Sstevel@tonic-gate $Dyn = $Intp = $Dll = $Stack = $IsX86 = $RWX = 0; 4647c478bd9Sstevel@tonic-gate $Interp = 1; 4657c478bd9Sstevel@tonic-gate $Header = 'None'; 4667c478bd9Sstevel@tonic-gate foreach my $Line (@Elf) { 4677c478bd9Sstevel@tonic-gate # If we have an invalid file type (which we can tell from the 4687c478bd9Sstevel@tonic-gate # first line), or we're processing an archive, bail. 4697c478bd9Sstevel@tonic-gate if ($Header eq 'None') { 4707c478bd9Sstevel@tonic-gate if (($Line =~ /invalid file/) || 4717c478bd9Sstevel@tonic-gate ($Line =~ /$FullPath(.*):/)) { 4727c478bd9Sstevel@tonic-gate return; 4737c478bd9Sstevel@tonic-gate } 4747c478bd9Sstevel@tonic-gate } 4757c478bd9Sstevel@tonic-gate 4767c478bd9Sstevel@tonic-gate if ($Line =~ /^ELF Header/) { 4777c478bd9Sstevel@tonic-gate $Header = 'Ehdr'; 4787c478bd9Sstevel@tonic-gate 4797c478bd9Sstevel@tonic-gate } elsif ($Line =~ /^Program Header/) { 4807c478bd9Sstevel@tonic-gate $Header = 'Phdr'; 4817c478bd9Sstevel@tonic-gate $RWX = 0; 4827c478bd9Sstevel@tonic-gate 4837c478bd9Sstevel@tonic-gate } elsif ($Line =~ /^Interpreter/) { 4847c478bd9Sstevel@tonic-gate $Header = 'Intp'; 4857c478bd9Sstevel@tonic-gate 4867c478bd9Sstevel@tonic-gate } elsif ($Line =~ /^Dynamic Section/) { 4877c478bd9Sstevel@tonic-gate # A dynamic section indicates we're a dynamic object 4887c478bd9Sstevel@tonic-gate # (this makes sure we don't check static executables). 4897c478bd9Sstevel@tonic-gate $Dyn = 1; 4907c478bd9Sstevel@tonic-gate 4917c478bd9Sstevel@tonic-gate } elsif (($Header eq 'Ehdr') && ($Line =~ /e_type:/)) { 4927c478bd9Sstevel@tonic-gate # The e_type field indicates whether this file is a 4937c478bd9Sstevel@tonic-gate # shared object (ET_DYN) or an executable (ET_EXEC). 4947c478bd9Sstevel@tonic-gate if ($Line =~ /ET_DYN/) { 4957c478bd9Sstevel@tonic-gate $Dll = 1; 4967c478bd9Sstevel@tonic-gate } elsif ($Line !~ /ET_EXEC/) { 4977c478bd9Sstevel@tonic-gate return; 4987c478bd9Sstevel@tonic-gate } 4997c478bd9Sstevel@tonic-gate } elsif (($Header eq 'Ehdr') && ($Line =~ /ei_class:/)) { 5007c478bd9Sstevel@tonic-gate # If we encounter a 64-bit object, but we're not running 5017c478bd9Sstevel@tonic-gate # on a 64-bit system, suppress calling ldd(1). 5027c478bd9Sstevel@tonic-gate if (($Line =~ /ELFCLASS64/) && !$Ena64) { 5037c478bd9Sstevel@tonic-gate $SkipLdd = 1; 5047c478bd9Sstevel@tonic-gate } 5057c478bd9Sstevel@tonic-gate } elsif (($Header eq 'Ehdr') && ($Line =~ /e_machine:/)) { 5067c478bd9Sstevel@tonic-gate # If it's a X86 object, we need to enforce RW- data. 5077c478bd9Sstevel@tonic-gate if (($Line =~ /(EM_AMD64|EM_386)/)) { 5087c478bd9Sstevel@tonic-gate $IsX86 = 1; 5097c478bd9Sstevel@tonic-gate } 5107c478bd9Sstevel@tonic-gate } elsif (($Header eq 'Phdr') && 5117c478bd9Sstevel@tonic-gate ($Line =~ /\[ PF_X PF_W PF_R \]/)) { 5127c478bd9Sstevel@tonic-gate # RWX segment seen. 5137c478bd9Sstevel@tonic-gate $RWX = 1; 5147c478bd9Sstevel@tonic-gate 5157c478bd9Sstevel@tonic-gate } elsif (($Header eq 'Phdr') && 5167c478bd9Sstevel@tonic-gate ($Line =~ /\[ PT_LOAD \]/ && $RWX && $IsX86)) { 5177c478bd9Sstevel@tonic-gate # Seen an RWX PT_LOAD segment. 5187c478bd9Sstevel@tonic-gate if ($File !~ $SkipNoExStkFiles) { 5197c478bd9Sstevel@tonic-gate OutMsg($Ttl++, $RelPath, 5207c478bd9Sstevel@tonic-gate "\tapplication requires non-executable " . 5217c478bd9Sstevel@tonic-gate "data\t<no -Mmapfile_noexdata?>"); 5227c478bd9Sstevel@tonic-gate } 5237c478bd9Sstevel@tonic-gate 5247c478bd9Sstevel@tonic-gate } elsif (($Header eq 'Phdr') && 5257c478bd9Sstevel@tonic-gate ($Line =~ /\[ PT_SUNWSTACK \]/)) { 5267c478bd9Sstevel@tonic-gate # This object defines a non-executable stack. 5277c478bd9Sstevel@tonic-gate $Stack = 1; 5287c478bd9Sstevel@tonic-gate 5297c478bd9Sstevel@tonic-gate } elsif (($Header eq 'Intp') && !$opt{a} && 5307c478bd9Sstevel@tonic-gate ($Line =~ $SkipInterps)) { 5317c478bd9Sstevel@tonic-gate # This object defines an interpretor we should skip. 5327c478bd9Sstevel@tonic-gate $Interp = 0; 5337c478bd9Sstevel@tonic-gate } 5347c478bd9Sstevel@tonic-gate } 5357c478bd9Sstevel@tonic-gate 5367c478bd9Sstevel@tonic-gate # Determine whether this ELF executable or shared object has a 5377c478bd9Sstevel@tonic-gate # conforming mcs(1) comment section. If the correct $(POST_PROCESS) 5387c478bd9Sstevel@tonic-gate # macros are used, only a 3 or 4 line .comment section should exist 5397c478bd9Sstevel@tonic-gate # containing one or two "@(#)SunOS" identifying comments (one comment 5407c478bd9Sstevel@tonic-gate # for a non-debug build, and two for a debug build). The results of 5417c478bd9Sstevel@tonic-gate # the following split should be three or four lines, the last empty 5427c478bd9Sstevel@tonic-gate # line being discarded by the split. 5437c478bd9Sstevel@tonic-gate if ($opt{m}) { 5447c478bd9Sstevel@tonic-gate my(@Mcs, $Con, $Dev); 5457c478bd9Sstevel@tonic-gate 5467c478bd9Sstevel@tonic-gate @Mcs = split(/\n/, `mcs -p $FullPath 2>&1`); 5477c478bd9Sstevel@tonic-gate 5487c478bd9Sstevel@tonic-gate $Con = $Dev = $Val = 0; 5497c478bd9Sstevel@tonic-gate foreach my $Line (@Mcs) { 5507c478bd9Sstevel@tonic-gate $Val++; 5517c478bd9Sstevel@tonic-gate 5527c478bd9Sstevel@tonic-gate if (($Val == 3) && ($Line !~ /^@\(#\)SunOS/)) { 5537c478bd9Sstevel@tonic-gate $Con = 1; 5547c478bd9Sstevel@tonic-gate last; 5557c478bd9Sstevel@tonic-gate } 5567c478bd9Sstevel@tonic-gate if (($Val == 4) && ($Line =~ /^@\(#\)SunOS/)) { 5577c478bd9Sstevel@tonic-gate $Dev = 1; 5587c478bd9Sstevel@tonic-gate next; 5597c478bd9Sstevel@tonic-gate } 5607c478bd9Sstevel@tonic-gate if (($Dev == 0) && ($Val == 4)) { 5617c478bd9Sstevel@tonic-gate $Con = 1; 5627c478bd9Sstevel@tonic-gate last; 5637c478bd9Sstevel@tonic-gate } 5647c478bd9Sstevel@tonic-gate if (($Dev == 1) && ($Val == 5)) { 5657c478bd9Sstevel@tonic-gate $Con = 1; 5667c478bd9Sstevel@tonic-gate last; 5677c478bd9Sstevel@tonic-gate } 5687c478bd9Sstevel@tonic-gate } 5697c478bd9Sstevel@tonic-gate if ($opt{m} && ($Con == 1)) { 5707c478bd9Sstevel@tonic-gate OutMsg($Ttl++, $RelPath, 5717c478bd9Sstevel@tonic-gate "\tnon-conforming mcs(1) comment\t<no \$(POST_PROCESS)?>"); 5727c478bd9Sstevel@tonic-gate } 5737c478bd9Sstevel@tonic-gate } 5747c478bd9Sstevel@tonic-gate 5757c478bd9Sstevel@tonic-gate # Applications should contain a non-executable stack definition. 5767c478bd9Sstevel@tonic-gate if (($Dll == 0) && ($Stack == 0)) { 5777c478bd9Sstevel@tonic-gate if (!$opt{a}) { 5787c478bd9Sstevel@tonic-gate if ($File =~ $SkipNoExStkFiles) { 5797c478bd9Sstevel@tonic-gate goto DYN; 5807c478bd9Sstevel@tonic-gate } 5817c478bd9Sstevel@tonic-gate } 5827c478bd9Sstevel@tonic-gate OutMsg($Ttl++, $RelPath, 5837c478bd9Sstevel@tonic-gate "\tapplication requires non-executable stack\t<no -Mmapfile_noexstk?>"); 5847c478bd9Sstevel@tonic-gate } 5857c478bd9Sstevel@tonic-gate 5867c478bd9Sstevel@tonic-gateDYN: 5877c478bd9Sstevel@tonic-gate # Having caught any static executables in the mcs(1) check and non- 5887c478bd9Sstevel@tonic-gate # executable stack definition check, continue with dynamic objects 5897c478bd9Sstevel@tonic-gate # from now on. 5907c478bd9Sstevel@tonic-gate if ($Dyn eq 0) { 5917c478bd9Sstevel@tonic-gate return; 5927c478bd9Sstevel@tonic-gate } 5937c478bd9Sstevel@tonic-gate 5947c478bd9Sstevel@tonic-gate # Only use ldd unless we've encountered an interpreter that should 5957c478bd9Sstevel@tonic-gate # ne skipped. 5967c478bd9Sstevel@tonic-gate if (!$SkipLdd && $Interp) { 5977c478bd9Sstevel@tonic-gate if ($Secure) { 5987c478bd9Sstevel@tonic-gate # The execution of a secure application over an nfs file 5997c478bd9Sstevel@tonic-gate # system mounted nosuid will result in warning messages 6007c478bd9Sstevel@tonic-gate # being sent to /var/adm/messages. As this type of 6017c478bd9Sstevel@tonic-gate # environment can occur with root builds, move the file 6027c478bd9Sstevel@tonic-gate # being investigated to a safe place first. In addition 6037c478bd9Sstevel@tonic-gate # remove its secure permission so that it can be 6047c478bd9Sstevel@tonic-gate # influenced by any alternative dependency mappings. 6057c478bd9Sstevel@tonic-gate 6067c478bd9Sstevel@tonic-gate my($TmpPath) = "$Tmpdir/$File"; 6077c478bd9Sstevel@tonic-gate 6087c478bd9Sstevel@tonic-gate system('cp', $FullPath, $TmpPath); 6097c478bd9Sstevel@tonic-gate chmod 0777, $TmpPath; 6107c478bd9Sstevel@tonic-gate $FullPath = $TmpPath; 6117c478bd9Sstevel@tonic-gate } 6127c478bd9Sstevel@tonic-gate 6137c478bd9Sstevel@tonic-gate # Use ldd(1) to determine the objects relocatability and use. 6147c478bd9Sstevel@tonic-gate # By default look for all unreferenced dependencies. However, 6157c478bd9Sstevel@tonic-gate # some objects have legitimate dependencies that they do not 6167c478bd9Sstevel@tonic-gate # reference. 6177c478bd9Sstevel@tonic-gate if ($LddNoU || ($File =~ $UnusedFiles) || 6187c478bd9Sstevel@tonic-gate ($RelPath =~ $UnusedPaths)) { 6197c478bd9Sstevel@tonic-gate $Lddopt = "-ru"; 6207c478bd9Sstevel@tonic-gate } else { 6217c478bd9Sstevel@tonic-gate $Lddopt = "-rU"; 6227c478bd9Sstevel@tonic-gate } 6237c478bd9Sstevel@tonic-gate @Ldd = split(/\n/, `ldd $Lddopt $Env $FullPath 2>&1`); 6247c478bd9Sstevel@tonic-gate if ($Secure) { 6257c478bd9Sstevel@tonic-gate unlink $FullPath; 6267c478bd9Sstevel@tonic-gate } 6277c478bd9Sstevel@tonic-gate } 6287c478bd9Sstevel@tonic-gate 6297c478bd9Sstevel@tonic-gate $Val = 0; 6307c478bd9Sstevel@tonic-gate $Sym = 5; 6317c478bd9Sstevel@tonic-gate $Uns = 1; 6327c478bd9Sstevel@tonic-gate 6337c478bd9Sstevel@tonic-gateLDD: foreach my $Line (@Ldd) { 6347c478bd9Sstevel@tonic-gate 6357c478bd9Sstevel@tonic-gate if ($Val == 0) { 6367c478bd9Sstevel@tonic-gate $Val = 1; 6377c478bd9Sstevel@tonic-gate # Make sure ldd(1) worked. One possible failure is that 6387c478bd9Sstevel@tonic-gate # this is an old ldd(1) prior to -e addition (4390308). 6397c478bd9Sstevel@tonic-gate if ($Line =~ /usage:/) { 6407c478bd9Sstevel@tonic-gate $Line =~ s/$/\t<old ldd(1)?>/; 6417c478bd9Sstevel@tonic-gate OutMsg($Ttl++, $RelPath, $Line); 6427c478bd9Sstevel@tonic-gate last; 6437c478bd9Sstevel@tonic-gate } elsif ($Line =~ /execution failed/) { 6447c478bd9Sstevel@tonic-gate OutMsg($Ttl++, $RelPath, $Line); 6457c478bd9Sstevel@tonic-gate last; 6467c478bd9Sstevel@tonic-gate } 6477c478bd9Sstevel@tonic-gate 6487c478bd9Sstevel@tonic-gate # It's possible this binary can't be executed, ie. we've 6497c478bd9Sstevel@tonic-gate # found a sparc binary while running on an intel system, 6507c478bd9Sstevel@tonic-gate # or a sparcv9 binary on a sparcv7/8 system. 6517c478bd9Sstevel@tonic-gate if ($Line =~ /wrong class/) { 6527c478bd9Sstevel@tonic-gate OutMsg($Ttl++, $RelPath, 6537c478bd9Sstevel@tonic-gate "\thas wrong class or data encoding"); 6547c478bd9Sstevel@tonic-gate next; 6557c478bd9Sstevel@tonic-gate } 6567c478bd9Sstevel@tonic-gate 6577c478bd9Sstevel@tonic-gate # Historically, ldd(1) likes executable objects to have 6587c478bd9Sstevel@tonic-gate # their execute bit set. Note that this test isn't 6597c478bd9Sstevel@tonic-gate # applied unless the -a option is in effect, as any 6607c478bd9Sstevel@tonic-gate # non-executable files are skipped by default to reduce 6617c478bd9Sstevel@tonic-gate # the cost of running this script. 6627c478bd9Sstevel@tonic-gate if ($Line =~ /not executable/) { 6637c478bd9Sstevel@tonic-gate OutMsg($Ttl++, $RelPath, 6647c478bd9Sstevel@tonic-gate "\tis not executable"); 6657c478bd9Sstevel@tonic-gate next; 6667c478bd9Sstevel@tonic-gate } 6677c478bd9Sstevel@tonic-gate } 6687c478bd9Sstevel@tonic-gate 6697c478bd9Sstevel@tonic-gate # Look for "file" or "versions" that aren't found. Note that 6707c478bd9Sstevel@tonic-gate # these lines will occur before we find any symbol referencing 6717c478bd9Sstevel@tonic-gate # errors. 6727c478bd9Sstevel@tonic-gate if (($Sym == 5) && ($Line =~ /not found\)/)) { 6737c478bd9Sstevel@tonic-gate if ($Line =~ /file not found\)/) { 6747c478bd9Sstevel@tonic-gate $Line =~ s/$/\t<no -zdefs?>/; 6757c478bd9Sstevel@tonic-gate } 6767c478bd9Sstevel@tonic-gate OutMsg($Ttl++, $RelPath, $Line); 6777c478bd9Sstevel@tonic-gate next; 6787c478bd9Sstevel@tonic-gate } 6797c478bd9Sstevel@tonic-gate # Look for relocations whose symbols can't be found. Note, we 6807c478bd9Sstevel@tonic-gate # only print out the first 5 relocations for any file as this 6817c478bd9Sstevel@tonic-gate # output can be excessive. 6827c478bd9Sstevel@tonic-gate if ($Sym && ($Line =~ /symbol not found/)) { 6837c478bd9Sstevel@tonic-gate # Determine if this file is allowed undefined 6847c478bd9Sstevel@tonic-gate # references. 6857c478bd9Sstevel@tonic-gate if ($Sym == 5) { 6867c478bd9Sstevel@tonic-gate if (!$opt{a}) { 6877c478bd9Sstevel@tonic-gate if ($RelPath =~ $SkipUndefDirs) { 6887c478bd9Sstevel@tonic-gate $Sym = 0; 6897c478bd9Sstevel@tonic-gate next LDD; 6907c478bd9Sstevel@tonic-gate } 6917c478bd9Sstevel@tonic-gate if ($File =~ $SkipUndefFiles) { 6927c478bd9Sstevel@tonic-gate $Sym = 0; 6937c478bd9Sstevel@tonic-gate next LDD; 6947c478bd9Sstevel@tonic-gate } 6957c478bd9Sstevel@tonic-gate } 6967c478bd9Sstevel@tonic-gate } 6977c478bd9Sstevel@tonic-gate if ($Sym-- == 1) { 6987c478bd9Sstevel@tonic-gate if (!$opt{o}) { 6997c478bd9Sstevel@tonic-gate OutMsg($Ttl++, $RelPath, 7007c478bd9Sstevel@tonic-gate "\tcontinued ..."); 7017c478bd9Sstevel@tonic-gate } 7027c478bd9Sstevel@tonic-gate next; 7037c478bd9Sstevel@tonic-gate } 7047c478bd9Sstevel@tonic-gate # Just print the symbol name. 7057c478bd9Sstevel@tonic-gate $Line =~ s/$/\t<no -zdefs?>/; 7067c478bd9Sstevel@tonic-gate OutMsg($Ttl++, $RelPath, $Line); 7077c478bd9Sstevel@tonic-gate next; 7087c478bd9Sstevel@tonic-gate } 7097c478bd9Sstevel@tonic-gate # Look for any unused dependencies. 7107c478bd9Sstevel@tonic-gate if ($Uns && ($Line =~ /unused/)) { 7117c478bd9Sstevel@tonic-gate if (!$opt{a}) { 7127c478bd9Sstevel@tonic-gate if ($RelPath =~ $SkipUnusedDirs) { 7137c478bd9Sstevel@tonic-gate $Uns = 0; 7147c478bd9Sstevel@tonic-gate next LDD; 7157c478bd9Sstevel@tonic-gate } 7167c478bd9Sstevel@tonic-gate if ($File =~ $SkipUnusedFiles) { 7177c478bd9Sstevel@tonic-gate $Uns = 0; 7187c478bd9Sstevel@tonic-gate next LDD; 7197c478bd9Sstevel@tonic-gate } 7207c478bd9Sstevel@tonic-gate 7217c478bd9Sstevel@tonic-gate # Remove any noise. 7227c478bd9Sstevel@tonic-gate if ($Line =~ $UnusedNoise) { 7237c478bd9Sstevel@tonic-gate $Uns = 0; 7247c478bd9Sstevel@tonic-gate next LDD; 7257c478bd9Sstevel@tonic-gate } 7267c478bd9Sstevel@tonic-gate } 7277c478bd9Sstevel@tonic-gate if ($Secure) { 7287c478bd9Sstevel@tonic-gate $Line =~ s!$Tmpdir/!!; 7297c478bd9Sstevel@tonic-gate } 7307c478bd9Sstevel@tonic-gate $Line =~ s/^[ \t]*(.*)/\t$1\t<remove lib or -zignore?>/; 7317c478bd9Sstevel@tonic-gate OutMsg($Ttl++, $RelPath, $Line); 7327c478bd9Sstevel@tonic-gate next; 7337c478bd9Sstevel@tonic-gate } 7347c478bd9Sstevel@tonic-gate } 7357c478bd9Sstevel@tonic-gate 7367c478bd9Sstevel@tonic-gate # Reuse the elfdump(1) data to investigate additional dynamic linking 7377c478bd9Sstevel@tonic-gate # information. 7387c478bd9Sstevel@tonic-gate 7397c478bd9Sstevel@tonic-gate $Sun = $Relsz = $Pltsz = $Dyn = $Stab = 0; 7407c478bd9Sstevel@tonic-gate $Tex = $Strip = 1; 7417c478bd9Sstevel@tonic-gate 7427c478bd9Sstevel@tonic-gate $Header = 'None'; 7437c478bd9Sstevel@tonic-gateELF: foreach my $Line (@Elf) { 7447c478bd9Sstevel@tonic-gate # We're only interested in the section headers and the dynamic 7457c478bd9Sstevel@tonic-gate # section. 7467c478bd9Sstevel@tonic-gate if ($Line =~ /^Section Header/) { 7477c478bd9Sstevel@tonic-gate $Header = 'Shdr'; 7487c478bd9Sstevel@tonic-gate 7497c478bd9Sstevel@tonic-gate if (($Sun == 0) && ($Line =~ /\.SUNW_reloc/)) { 7507c478bd9Sstevel@tonic-gate # This object has a combined relocation section. 7517c478bd9Sstevel@tonic-gate $Sun = 1; 7527c478bd9Sstevel@tonic-gate 7537c478bd9Sstevel@tonic-gate } elsif (($Stab == 0) && ($Line =~ /\.stab/)) { 7547c478bd9Sstevel@tonic-gate # This object contain .stabs sections 7557c478bd9Sstevel@tonic-gate $Stab = 1; 7567c478bd9Sstevel@tonic-gate } 7577c478bd9Sstevel@tonic-gate 7587c478bd9Sstevel@tonic-gate if (($Strip == 1) && ($Line =~ /\.symtab/)) { 7597c478bd9Sstevel@tonic-gate # This object contains a complete symbol table. 7607c478bd9Sstevel@tonic-gate $Strip = 0; 7617c478bd9Sstevel@tonic-gate } 7627c478bd9Sstevel@tonic-gate next; 7637c478bd9Sstevel@tonic-gate 7647c478bd9Sstevel@tonic-gate } elsif ($Line =~ /^Dynamic Section/) { 7657c478bd9Sstevel@tonic-gate $Header = 'Dyn'; 7667c478bd9Sstevel@tonic-gate next; 7677c478bd9Sstevel@tonic-gate } elsif ($Header ne 'Dyn') { 7687c478bd9Sstevel@tonic-gate next; 7697c478bd9Sstevel@tonic-gate } 7707c478bd9Sstevel@tonic-gate 7717c478bd9Sstevel@tonic-gate # Does this object contain text relocations. 7727c478bd9Sstevel@tonic-gate if ($Tex && ($Line =~ /TEXTREL/)) { 7737c478bd9Sstevel@tonic-gate # Determine if this file is allowed text relocations. 7747c478bd9Sstevel@tonic-gate if (!$opt{a}) { 7757c478bd9Sstevel@tonic-gate if ($File =~ $SkipTextrelFiles) { 7767c478bd9Sstevel@tonic-gate $Tex = 0; 7777c478bd9Sstevel@tonic-gate next ELF; 7787c478bd9Sstevel@tonic-gate } 7797c478bd9Sstevel@tonic-gate } 7807c478bd9Sstevel@tonic-gate OutMsg($Ttl++, $RelPath, 7817c478bd9Sstevel@tonic-gate "\tTEXTREL .dynamic tag\t\t\t<no -Kpic?>"); 7827c478bd9Sstevel@tonic-gate $Tex = 0; 7837c478bd9Sstevel@tonic-gate next; 7847c478bd9Sstevel@tonic-gate } 7857c478bd9Sstevel@tonic-gate 7867c478bd9Sstevel@tonic-gate # Does this file have any relocation sections (there are a few 7877c478bd9Sstevel@tonic-gate # psr libraries with no relocations at all, thus a .SUNW_reloc 7887c478bd9Sstevel@tonic-gate # section won't exist either). 7897c478bd9Sstevel@tonic-gate if (($Relsz == 0) && ($Line =~ / RELA?SZ/)) { 7907c478bd9Sstevel@tonic-gate $Relsz = hex((split(' ', $Line))[2]); 7917c478bd9Sstevel@tonic-gate next; 7927c478bd9Sstevel@tonic-gate } 7937c478bd9Sstevel@tonic-gate 7947c478bd9Sstevel@tonic-gate # Does this file have any plt relocations. If the plt size is 7957c478bd9Sstevel@tonic-gate # equivalent to the total relocation size then we don't have 7967c478bd9Sstevel@tonic-gate # any relocations suitable for combining into a .SUNW_reloc 7977c478bd9Sstevel@tonic-gate # section. 7987c478bd9Sstevel@tonic-gate if (($Pltsz == 0) && ($Line =~ / PLTRELSZ/)) { 7997c478bd9Sstevel@tonic-gate $Pltsz = hex((split(' ', $Line))[2]); 8007c478bd9Sstevel@tonic-gate next; 8017c478bd9Sstevel@tonic-gate } 8027c478bd9Sstevel@tonic-gate 8037c478bd9Sstevel@tonic-gate # Under the -i (information) option print out any useful dynamic 8047c478bd9Sstevel@tonic-gate # entries. 8057c478bd9Sstevel@tonic-gate # Does this object have any dependencies. 8067c478bd9Sstevel@tonic-gate if ($opt{i} && ($Line =~ /NEEDED/)) { 8077c478bd9Sstevel@tonic-gate my($Need) = (split(' ', $Line))[3]; 8087c478bd9Sstevel@tonic-gate 8097c478bd9Sstevel@tonic-gate # Catch any old (unnecessary) dependencies. 8107c478bd9Sstevel@tonic-gate if ($Need =~ $OldDeps) { 8117c478bd9Sstevel@tonic-gate OutMsg($Ttl++, $RelPath, 8127c478bd9Sstevel@tonic-gate "\tNEEDED=$Need\t<dependency no longer necessary>"); 8137c478bd9Sstevel@tonic-gate } else { 8147c478bd9Sstevel@tonic-gate OutMsg($Ttl++, $RelPath, "\tNEEDED=$Need"); 8157c478bd9Sstevel@tonic-gate } 8167c478bd9Sstevel@tonic-gate next; 8177c478bd9Sstevel@tonic-gate } 8187c478bd9Sstevel@tonic-gate 8197c478bd9Sstevel@tonic-gate # Does this object specify a runpath. 8207c478bd9Sstevel@tonic-gate if ($opt{i} && ($Line =~ /RPATH/)) { 8217c478bd9Sstevel@tonic-gate my($Rpath) = (split(' ', $Line))[3]; 8227c478bd9Sstevel@tonic-gate OutMsg($Ttl++, $RelPath, "\tRPATH=$Rpath"); 8237c478bd9Sstevel@tonic-gate next; 8247c478bd9Sstevel@tonic-gate } 8257c478bd9Sstevel@tonic-gate } 8267c478bd9Sstevel@tonic-gate 8277c478bd9Sstevel@tonic-gate # A shared object, that contains non-plt relocations, should have a 8287c478bd9Sstevel@tonic-gate # combined relocation section indicating it was built with -z combreloc. 8297c478bd9Sstevel@tonic-gate if ($Dll && $Relsz && ($Relsz != $Pltsz) && ($Sun == 0)) { 8307c478bd9Sstevel@tonic-gate OutMsg($Ttl++, $RelPath, 8317c478bd9Sstevel@tonic-gate "\tSUNW_reloc section missing\t\t<no -zcombreloc?>"); 8327c478bd9Sstevel@tonic-gate } 8337c478bd9Sstevel@tonic-gate 8347c478bd9Sstevel@tonic-gate # No objects released to a customer should have any .stabs sections 8357c478bd9Sstevel@tonic-gate # remaining, they should be stripped. 8367c478bd9Sstevel@tonic-gate if ($opt{s} && $Stab) { 8377c478bd9Sstevel@tonic-gate if (!$opt{a}) { 8387c478bd9Sstevel@tonic-gate if ($File =~ $SkipStabFiles) { 8397c478bd9Sstevel@tonic-gate goto DONESTAB; 8407c478bd9Sstevel@tonic-gate } 8417c478bd9Sstevel@tonic-gate } 8427c478bd9Sstevel@tonic-gate OutMsg($Ttl++, $RelPath, 8438ad60789Srie "\tdebugging sections should be deleted\t<no strip -x?>"); 8447c478bd9Sstevel@tonic-gate } 8457c478bd9Sstevel@tonic-gate 8467c478bd9Sstevel@tonic-gateDONESTAB: 8477c478bd9Sstevel@tonic-gate 8488ad60789Srie # All objects should have a full symbol table to provide complete 8497c478bd9Sstevel@tonic-gate # debugging stack traces. 8508ad60789Srie if ($Strip) { 8517c478bd9Sstevel@tonic-gate OutMsg($Ttl++, $RelPath, 8527c478bd9Sstevel@tonic-gate "\tsymbol table should not be stripped\t<remove -s?>"); 8537c478bd9Sstevel@tonic-gate } 8547c478bd9Sstevel@tonic-gate} 8557c478bd9Sstevel@tonic-gate 8567c478bd9Sstevel@tonic-gate 8577c478bd9Sstevel@tonic-gatesub ProcDir { 8587c478bd9Sstevel@tonic-gate my($FullDir, $RelDir) = @_; 8597c478bd9Sstevel@tonic-gate my($NewFull, $NewRel); 8607c478bd9Sstevel@tonic-gate 8617c478bd9Sstevel@tonic-gate # Determine if this is a directory we don't care about. 8627c478bd9Sstevel@tonic-gate if (!$opt{a}) { 8637c478bd9Sstevel@tonic-gate if ($RelDir =~ $SkipDirs) { 8647c478bd9Sstevel@tonic-gate return; 8657c478bd9Sstevel@tonic-gate } 8667c478bd9Sstevel@tonic-gate } 8677c478bd9Sstevel@tonic-gate 8687c478bd9Sstevel@tonic-gate # Open the directory and read each entry, omit files starting with "." 8697c478bd9Sstevel@tonic-gate if (opendir(DIR, $FullDir)) { 8707c478bd9Sstevel@tonic-gate foreach my $Entry (readdir(DIR)) { 8717c478bd9Sstevel@tonic-gate if ($Entry =~ /^\./) { 8727c478bd9Sstevel@tonic-gate next; 8737c478bd9Sstevel@tonic-gate } 8747c478bd9Sstevel@tonic-gate $NewFull = "$FullDir/$Entry"; 8757c478bd9Sstevel@tonic-gate 8767c478bd9Sstevel@tonic-gate # Ignore symlinks. 8777c478bd9Sstevel@tonic-gate if (-l $NewFull) { 8787c478bd9Sstevel@tonic-gate next; 8797c478bd9Sstevel@tonic-gate } 8807c478bd9Sstevel@tonic-gate if (!stat($NewFull)) { 8817c478bd9Sstevel@tonic-gate next; 8827c478bd9Sstevel@tonic-gate } 8837c478bd9Sstevel@tonic-gate $NewRel = "$RelDir/$Entry"; 8847c478bd9Sstevel@tonic-gate 8857c478bd9Sstevel@tonic-gate # Descend into and process any directories. 8867c478bd9Sstevel@tonic-gate if (-d _) { 8877c478bd9Sstevel@tonic-gate ProcDir($NewFull, $NewRel); 8887c478bd9Sstevel@tonic-gate next; 8897c478bd9Sstevel@tonic-gate } 8907c478bd9Sstevel@tonic-gate 8917c478bd9Sstevel@tonic-gate # Typically dynamic objects are executable, so we can 8927c478bd9Sstevel@tonic-gate # reduce the overall cost of this script (a lot!) by 8937c478bd9Sstevel@tonic-gate # screening out non-executables here, rather than pass 8947c478bd9Sstevel@tonic-gate # them to file(1) later. However, it has been known 8957c478bd9Sstevel@tonic-gate # for shared objects to be mistakenly left non- 8967c478bd9Sstevel@tonic-gate # executable, so with -a let all files through so that 8977c478bd9Sstevel@tonic-gate # this requirement can be verified (see ProcFile()). 8987c478bd9Sstevel@tonic-gate if (!$opt{a}) { 8997c478bd9Sstevel@tonic-gate if (! -x _) { 9007c478bd9Sstevel@tonic-gate next; 9017c478bd9Sstevel@tonic-gate } 9027c478bd9Sstevel@tonic-gate } 9037c478bd9Sstevel@tonic-gate 9047c478bd9Sstevel@tonic-gate # Process any standard files. 9057c478bd9Sstevel@tonic-gate if (-f _) { 9067c478bd9Sstevel@tonic-gate my($Secure) = 0; 9077c478bd9Sstevel@tonic-gate 9087c478bd9Sstevel@tonic-gate if (-u _ || -g _) { 9097c478bd9Sstevel@tonic-gate $Secure = 1; 9107c478bd9Sstevel@tonic-gate } 9117c478bd9Sstevel@tonic-gate 9127c478bd9Sstevel@tonic-gate ProcFile($NewFull, $NewRel, $Entry, $Secure); 9137c478bd9Sstevel@tonic-gate next; 9147c478bd9Sstevel@tonic-gate } 9157c478bd9Sstevel@tonic-gate 9167c478bd9Sstevel@tonic-gate } 9177c478bd9Sstevel@tonic-gate closedir(DIR); 9187c478bd9Sstevel@tonic-gate } 9197c478bd9Sstevel@tonic-gate} 9207c478bd9Sstevel@tonic-gate 9217c478bd9Sstevel@tonic-gate# Create a crle(1) script for any 64-bit dependencies we locate. A runtime 9227c478bd9Sstevel@tonic-gate# configuration file will be generated to establish alternative dependency 9237c478bd9Sstevel@tonic-gate# mappings for all these dependencies. 9247c478bd9Sstevel@tonic-gate 9257c478bd9Sstevel@tonic-gatesub Entercrle64 { 9267c478bd9Sstevel@tonic-gate my($FullDir, $RelDir, $Entry) = @_; 9277c478bd9Sstevel@tonic-gate 9287c478bd9Sstevel@tonic-gate if (!$Crle64) { 9297c478bd9Sstevel@tonic-gate # Create and initialize the script if is doesn't already exit. 9307c478bd9Sstevel@tonic-gate 9317c478bd9Sstevel@tonic-gate $Crle64 = "$Tmpdir/$Prog.crle64.$$"; 9327c478bd9Sstevel@tonic-gate open(CRLE64, "> $Crle64") || 9337c478bd9Sstevel@tonic-gate die "$Prog: open failed: $Crle64: $!"; 9347c478bd9Sstevel@tonic-gate 9357c478bd9Sstevel@tonic-gate print CRLE64 "#!/bin/sh\ncrle -64\\\n"; 9367c478bd9Sstevel@tonic-gate } 9377c478bd9Sstevel@tonic-gate print CRLE64 "\t-o $FullDir -a $RelDir/$Entry \\\n"; 9387c478bd9Sstevel@tonic-gate} 9397c478bd9Sstevel@tonic-gate 9407c478bd9Sstevel@tonic-gate# Create a crle(1) script for any 32-bit dependencies we locate. A runtime 9417c478bd9Sstevel@tonic-gate# configuration file will be generated to establish alternative dependency 9427c478bd9Sstevel@tonic-gate# mappings for all these dependencies. 9437c478bd9Sstevel@tonic-gate 9447c478bd9Sstevel@tonic-gatesub Entercrle32 { 9457c478bd9Sstevel@tonic-gate my($FullDir, $RelDir, $Entry) = @_; 9467c478bd9Sstevel@tonic-gate 9477c478bd9Sstevel@tonic-gate if (!$Crle32) { 9487c478bd9Sstevel@tonic-gate # Create and initialize the script if is doesn't already exit. 9497c478bd9Sstevel@tonic-gate 9507c478bd9Sstevel@tonic-gate $Crle32 = "$Tmpdir/$Prog.crle32.$$"; 9517c478bd9Sstevel@tonic-gate open(CRLE32, "> $Crle32") || 9527c478bd9Sstevel@tonic-gate die "$Prog: open failed: $Crle32: $!"; 9537c478bd9Sstevel@tonic-gate 9547c478bd9Sstevel@tonic-gate print CRLE32 "#!/bin/sh\ncrle \\\n"; 9557c478bd9Sstevel@tonic-gate } 9567c478bd9Sstevel@tonic-gate print CRLE32 "\t-o $FullDir -a $RelDir/$Entry \\\n"; 9577c478bd9Sstevel@tonic-gate} 9587c478bd9Sstevel@tonic-gate 9597c478bd9Sstevel@tonic-gate# Having finished gathering dependencies, complete any crle(1) scripts and 9607c478bd9Sstevel@tonic-gate# execute them to generate the associated runtime configuration files. In 9617c478bd9Sstevel@tonic-gate# addition establish the environment variable required to pass the configuration 9627c478bd9Sstevel@tonic-gate# files to ldd(1). 9637c478bd9Sstevel@tonic-gate 9647c478bd9Sstevel@tonic-gatesub GenConf { 9657c478bd9Sstevel@tonic-gate if ($Crle64) { 9667c478bd9Sstevel@tonic-gate $Conf64 = "$Tmpdir/$Prog.conf64.$$"; 9677c478bd9Sstevel@tonic-gate print CRLE64 "\t-c $Conf64\n"; 9687c478bd9Sstevel@tonic-gate 9697c478bd9Sstevel@tonic-gate chmod 0755, $Crle64; 9707c478bd9Sstevel@tonic-gate close CRLE64; 9717c478bd9Sstevel@tonic-gate 9727c478bd9Sstevel@tonic-gate if (system($Crle64)) { 9737c478bd9Sstevel@tonic-gate undef $Conf64; 9747c478bd9Sstevel@tonic-gate } 9757c478bd9Sstevel@tonic-gate } 9767c478bd9Sstevel@tonic-gate if ($Crle32) { 9777c478bd9Sstevel@tonic-gate $Conf32 = "$Tmpdir/$Prog.conf32.$$"; 9787c478bd9Sstevel@tonic-gate print CRLE32 "\t-c $Conf32\n"; 9797c478bd9Sstevel@tonic-gate 9807c478bd9Sstevel@tonic-gate chmod 0755, $Crle32; 9817c478bd9Sstevel@tonic-gate close CRLE32; 9827c478bd9Sstevel@tonic-gate 9837c478bd9Sstevel@tonic-gate if (system($Crle32)) { 9847c478bd9Sstevel@tonic-gate undef $Conf32; 9857c478bd9Sstevel@tonic-gate } 9867c478bd9Sstevel@tonic-gate } 9877c478bd9Sstevel@tonic-gate 9887c478bd9Sstevel@tonic-gate if ($Crle64 && $Conf64 && $Crle32 && $Conf32) { 9897c478bd9Sstevel@tonic-gate $Env = "-e LD_FLAGS=config_64=$Conf64,config_32=$Conf32"; 9907c478bd9Sstevel@tonic-gate } elsif ($Crle64 && $Conf64) { 9917c478bd9Sstevel@tonic-gate $Env = "-e LD_FLAGS=config_64=$Conf64"; 9927c478bd9Sstevel@tonic-gate } elsif ($Crle32 && $Conf32) { 9937c478bd9Sstevel@tonic-gate $Env = "-e LD_FLAGS=config_32=$Conf32"; 9947c478bd9Sstevel@tonic-gate } 9957c478bd9Sstevel@tonic-gate} 9967c478bd9Sstevel@tonic-gate 9977c478bd9Sstevel@tonic-gate# Recurse through a directory hierarchy looking for appropriate dependencies. 9987c478bd9Sstevel@tonic-gate 9997c478bd9Sstevel@tonic-gatesub GetDeps { 10007c478bd9Sstevel@tonic-gate my($FullDir, $RelDir) = @_; 10017c478bd9Sstevel@tonic-gate my($NewFull); 10027c478bd9Sstevel@tonic-gate 10037c478bd9Sstevel@tonic-gate # Open the directory and read each entry, omit files starting with "." 10047c478bd9Sstevel@tonic-gate if (opendir(DIR, $FullDir)) { 10057c478bd9Sstevel@tonic-gate foreach my $Entry (readdir(DIR)) { 10067c478bd9Sstevel@tonic-gate if ($Entry =~ /^\./) { 10077c478bd9Sstevel@tonic-gate next; 10087c478bd9Sstevel@tonic-gate } 10097c478bd9Sstevel@tonic-gate $NewFull = "$FullDir/$Entry"; 10107c478bd9Sstevel@tonic-gate 10117c478bd9Sstevel@tonic-gate # We need to follow links so that any dependencies 10127c478bd9Sstevel@tonic-gate # are expressed in all their available forms. 10137c478bd9Sstevel@tonic-gate # Bail on symlinks like 32 -> . 10147c478bd9Sstevel@tonic-gate if (-l $NewFull) { 10157c478bd9Sstevel@tonic-gate if (readlink($NewFull) =~ /^\.$/) { 10167c478bd9Sstevel@tonic-gate next; 10177c478bd9Sstevel@tonic-gate } 10187c478bd9Sstevel@tonic-gate } 10197c478bd9Sstevel@tonic-gate if (!stat($NewFull)) { 10207c478bd9Sstevel@tonic-gate next; 10217c478bd9Sstevel@tonic-gate } 10227c478bd9Sstevel@tonic-gate 10237c478bd9Sstevel@tonic-gate # If this is a directory descend into it. 10247c478bd9Sstevel@tonic-gate if (-d _) { 10257c478bd9Sstevel@tonic-gate my($NewRel); 10267c478bd9Sstevel@tonic-gate 10277c478bd9Sstevel@tonic-gate if ($RelDir =~ /^\/$/) { 10287c478bd9Sstevel@tonic-gate $NewRel = "$RelDir$Entry"; 10297c478bd9Sstevel@tonic-gate } else { 10307c478bd9Sstevel@tonic-gate $NewRel = "$RelDir/$Entry"; 10317c478bd9Sstevel@tonic-gate } 10327c478bd9Sstevel@tonic-gate 10337c478bd9Sstevel@tonic-gate GetDeps($NewFull, $NewRel); 10347c478bd9Sstevel@tonic-gate next; 10357c478bd9Sstevel@tonic-gate } 10367c478bd9Sstevel@tonic-gate 10377c478bd9Sstevel@tonic-gate # If this is a regular file determine if its a 10387c478bd9Sstevel@tonic-gate # valid ELF dependency. 10397c478bd9Sstevel@tonic-gate if (-f _) { 10407c478bd9Sstevel@tonic-gate my($File); 10417c478bd9Sstevel@tonic-gate 10427c478bd9Sstevel@tonic-gate # Typically shared object dependencies end with 10437c478bd9Sstevel@tonic-gate # ".so" or ".so.?", hence we can reduce the cost 10447c478bd9Sstevel@tonic-gate # of this script (a lot!) by screening out files 10457c478bd9Sstevel@tonic-gate # that don't follow this pattern. 10467c478bd9Sstevel@tonic-gate if (!$opt{a}) { 10477c478bd9Sstevel@tonic-gate if ($Entry !~ /\.so(?:\.\d+)*$/) { 10487c478bd9Sstevel@tonic-gate next; 10497c478bd9Sstevel@tonic-gate } 10507c478bd9Sstevel@tonic-gate } 10517c478bd9Sstevel@tonic-gate 10527c478bd9Sstevel@tonic-gate $File = `file $NewFull`; 10537c478bd9Sstevel@tonic-gate if ($File !~ /dynamic lib/) { 10547c478bd9Sstevel@tonic-gate next; 10557c478bd9Sstevel@tonic-gate } 10567c478bd9Sstevel@tonic-gate 10577c478bd9Sstevel@tonic-gate if ($File =~ /32-bit/) { 10587c478bd9Sstevel@tonic-gate Entercrle32($FullDir, $RelDir, $Entry); 10597c478bd9Sstevel@tonic-gate } elsif ($Ena64) { 10607c478bd9Sstevel@tonic-gate Entercrle64($FullDir, $RelDir, $Entry); 10617c478bd9Sstevel@tonic-gate } 10627c478bd9Sstevel@tonic-gate next; 10637c478bd9Sstevel@tonic-gate } 10647c478bd9Sstevel@tonic-gate } 10657c478bd9Sstevel@tonic-gate closedir(DIR); 10667c478bd9Sstevel@tonic-gate } 10677c478bd9Sstevel@tonic-gate} 10687c478bd9Sstevel@tonic-gateexit $Error 1069