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 6749f21d3Swesolows# Common Development and Distribution License (the "License"). 7749f21d3Swesolows# 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# 22749f21d3Swesolows 237c478bd9Sstevel@tonic-gate# 24*5253169eSAli Bahrami# Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. 257c478bd9Sstevel@tonic-gate# 26749f21d3Swesolows 27749f21d3Swesolows# 287c478bd9Sstevel@tonic-gate# Check ELF information. 297c478bd9Sstevel@tonic-gate# 307c478bd9Sstevel@tonic-gate# This script descends a directory hierarchy inspecting ELF dynamic executables 317c478bd9Sstevel@tonic-gate# and shared objects. The general theme is to verify that common Makefile rules 327c478bd9Sstevel@tonic-gate# have been used to build these objects. Typical failures occur when Makefile 337c478bd9Sstevel@tonic-gate# rules are re-invented rather than being inherited from "cmd/lib" Makefiles. 347c478bd9Sstevel@tonic-gate# 357c478bd9Sstevel@tonic-gate# As always, a number of components don't follow the rules, and these are 3675ce41a5SAli Bahrami# excluded to reduce this scripts output. 377c478bd9Sstevel@tonic-gate# 387c478bd9Sstevel@tonic-gate# By default any file that has conditions that should be reported is first 397c478bd9Sstevel@tonic-gate# listed and then each condition follows. The -o (one-line) option produces a 407c478bd9Sstevel@tonic-gate# more terse output which is better for sorting/diffing with "nightly". 417c478bd9Sstevel@tonic-gate# 427c478bd9Sstevel@tonic-gate# NOTE: missing dependencies, symbols or versions are reported by running the 437c478bd9Sstevel@tonic-gate# file through ldd(1). As objects within a proto area are built to exist in a 447c478bd9Sstevel@tonic-gate# base system, standard use of ldd(1) will bind any objects to dependencies 457c478bd9Sstevel@tonic-gate# that exist in the base system. It is frequently the case that newer objects 467c478bd9Sstevel@tonic-gate# exist in the proto area that are required to satisfy other objects 477c478bd9Sstevel@tonic-gate# dependencies, and without using these newer objects an ldd(1) will produce 4875ce41a5SAli Bahrami# misleading error messages. To compensate for this, the -D/-d options, or the 4975ce41a5SAli Bahrami# existence of the CODEMSG_WS/ROOT environment variables, cause the creation of 507c478bd9Sstevel@tonic-gate# alternative dependency mappings via crle(1) configuration files that establish 517c478bd9Sstevel@tonic-gate# any proto shared objects as alternatives to their base system location. Thus 527c478bd9Sstevel@tonic-gate# ldd(1) can be executed against these configuration files so that objects in a 537c478bd9Sstevel@tonic-gate# proto area bind to their dependencies in the same proto area. 547c478bd9Sstevel@tonic-gate 557c478bd9Sstevel@tonic-gate 567c478bd9Sstevel@tonic-gate# Define all global variables (required for strict) 5775ce41a5SAli Bahramiuse vars qw($Prog $Env $Ena64 $Tmpdir $Gnuc); 5875ce41a5SAli Bahramiuse vars qw($LddNoU $Conf32 $Conf64); 5975ce41a5SAli Bahramiuse vars qw(%opt); 6075ce41a5SAli Bahramiuse vars qw($ErrFH $ErrTtl $InfoFH $InfoTtl $OutCnt1 $OutCnt2); 6175ce41a5SAli Bahrami 6275ce41a5SAli Bahrami# An exception file is used to specify regular expressions to match 6375ce41a5SAli Bahrami# objects. These directives specify special attributes of the object. 6475ce41a5SAli Bahrami# The regular expressions are read from the file and compiled into the 6575ce41a5SAli Bahrami# regular expression variables. 6675ce41a5SAli Bahrami# 6775ce41a5SAli Bahrami# The name of each regular expression variable is of the form 6875ce41a5SAli Bahrami# 6975ce41a5SAli Bahrami# $EXRE_xxx 7075ce41a5SAli Bahrami# 7175ce41a5SAli Bahrami# where xxx is the name of the exception in lower case. For example, 7275ce41a5SAli Bahrami# the regular expression variable for EXEC_STACK is $EXRE_exec_stack. 7375ce41a5SAli Bahrami# 7475ce41a5SAli Bahrami# onbld_elfmod::LoadExceptionsToEXRE() depends on this naming convention 7575ce41a5SAli Bahrami# to initialize the regular expression variables, and to detect invalid 7675ce41a5SAli Bahrami# exception names. 7775ce41a5SAli Bahrami# 7875ce41a5SAli Bahrami# If a given exception is not used in the exception file, its regular 7975ce41a5SAli Bahrami# expression variable will be undefined. Users of these variables must 8075ce41a5SAli Bahrami# test the variable with defined() prior to use: 8175ce41a5SAli Bahrami# 8275ce41a5SAli Bahrami# defined($EXRE_exec_stack) && ($foo =~ $EXRE_exec_stack) 8375ce41a5SAli Bahrami# 84*5253169eSAli Bahrami# or if the test is to make sure the item is not specified: 85*5253169eSAli Bahrami# 86*5253169eSAli Bahrami# !defined($EXRE_exec_stack) || ($foo !~ $EXRE_exec_stack) 87*5253169eSAli Bahrami# 8875ce41a5SAli Bahrami# ---- 8975ce41a5SAli Bahrami# 9075ce41a5SAli Bahrami# The exceptions are: 9175ce41a5SAli Bahrami# 92*5253169eSAli Bahrami# EXEC_DATA 93*5253169eSAli Bahrami# Objects that are not required to have non-executable writable 94*5253169eSAli Bahrami# data segments. 95*5253169eSAli Bahrami# 9675ce41a5SAli Bahrami# EXEC_STACK 9775ce41a5SAli Bahrami# Objects that are not required to have a non-executable stack 9875ce41a5SAli Bahrami# 9975ce41a5SAli Bahrami# NOCRLEALT 10075ce41a5SAli Bahrami# Objects that should be skipped by AltObjectConfig() when building 10175ce41a5SAli Bahrami# the crle script that maps objects to the proto area. 10275ce41a5SAli Bahrami# 10375ce41a5SAli Bahrami# NODIRECT 10475ce41a5SAli Bahrami# Objects that are not required to use direct bindings 10575ce41a5SAli Bahrami# 10675ce41a5SAli Bahrami# NOSYMSORT 10775ce41a5SAli Bahrami# Objects we should not check for duplicate addresses in 10875ce41a5SAli Bahrami# the symbol sort sections. 10975ce41a5SAli Bahrami# 11075ce41a5SAli Bahrami# OLDDEP 11175ce41a5SAli Bahrami# Objects that are no longer needed because their functionalty 11275ce41a5SAli Bahrami# has migrated elsewhere. These are usually pure filters that 11375ce41a5SAli Bahrami# point at libc. 11475ce41a5SAli Bahrami# 11575ce41a5SAli Bahrami# SKIP 11675ce41a5SAli Bahrami# Files and directories that should be excluded from analysis. 11775ce41a5SAli Bahrami# 11875ce41a5SAli Bahrami# STAB 11975ce41a5SAli Bahrami# Objects that are allowed to contain stab debugging sections 12075ce41a5SAli Bahrami# 12175ce41a5SAli Bahrami# TEXTREL 12275ce41a5SAli Bahrami# Object for which relocations are allowed to the text segment 12375ce41a5SAli Bahrami# 12475ce41a5SAli Bahrami# UNDEF_REF 12575ce41a5SAli Bahrami# Objects that are allowed undefined references 12675ce41a5SAli Bahrami# 12775ce41a5SAli Bahrami# UNREF_OBJ 12875ce41a5SAli Bahrami# "unreferenced object=" ldd(1) diagnostics. 12975ce41a5SAli Bahrami# 13075ce41a5SAli Bahrami# UNUSED_DEPS 13175ce41a5SAli Bahrami# Objects that are allowed to have unused dependencies 13275ce41a5SAli Bahrami# 13375ce41a5SAli Bahrami# UNUSED_OBJ 13475ce41a5SAli Bahrami# Objects that are allowed to be unused dependencies 13575ce41a5SAli Bahrami# 13675ce41a5SAli Bahrami# UNUSED_RPATH 13775ce41a5SAli Bahrami# Objects with unused runpaths 13875ce41a5SAli Bahrami# 13975ce41a5SAli Bahrami 140*5253169eSAli Bahramiuse vars qw($EXRE_exec_data $EXRE_exec_stack $EXRE_nocrlealt); 141*5253169eSAli Bahramiuse vars qw($EXRE_nodirect $EXRE_nosymsort); 14275ce41a5SAli Bahramiuse vars qw($EXRE_olddep $EXRE_skip $EXRE_stab $EXRE_textrel $EXRE_undef_ref); 14375ce41a5SAli Bahramiuse vars qw($EXRE_unref_obj $EXRE_unused_deps $EXRE_unused_obj); 14475ce41a5SAli Bahramiuse vars qw($EXRE_unused_rpath); 1457c478bd9Sstevel@tonic-gate 1467c478bd9Sstevel@tonic-gateuse strict; 1477c478bd9Sstevel@tonic-gateuse Getopt::Std; 14875ce41a5SAli Bahramiuse File::Basename; 1497c478bd9Sstevel@tonic-gate 1507c478bd9Sstevel@tonic-gate 1517c478bd9Sstevel@tonic-gate# Reliably compare two OS revisions. Arguments are <ver1> <op> <ver2>. 1527c478bd9Sstevel@tonic-gate# <op> is the string form of a normal numeric comparison operator. 1537c478bd9Sstevel@tonic-gatesub cmp_os_ver { 1547c478bd9Sstevel@tonic-gate my @ver1 = split(/\./, $_[0]); 1557c478bd9Sstevel@tonic-gate my $op = $_[1]; 1567c478bd9Sstevel@tonic-gate my @ver2 = split(/\./, $_[2]); 1577c478bd9Sstevel@tonic-gate 1587c478bd9Sstevel@tonic-gate push @ver2, ("0") x $#ver1 - $#ver2; 1597c478bd9Sstevel@tonic-gate push @ver1, ("0") x $#ver2 - $#ver1; 1607c478bd9Sstevel@tonic-gate 1617c478bd9Sstevel@tonic-gate my $diff = 0; 1627c478bd9Sstevel@tonic-gate while (@ver1 || @ver2) { 1637c478bd9Sstevel@tonic-gate if (($diff = shift(@ver1) - shift(@ver2)) != 0) { 1647c478bd9Sstevel@tonic-gate last; 1657c478bd9Sstevel@tonic-gate } 1667c478bd9Sstevel@tonic-gate } 1677c478bd9Sstevel@tonic-gate return (eval "$diff $op 0" ? 1 : 0); 1687c478bd9Sstevel@tonic-gate} 1697c478bd9Sstevel@tonic-gate 17075ce41a5SAli Bahrami## ProcFile(FullPath, RelPath, File, Class, Type, Verdef) 17175ce41a5SAli Bahrami# 1727c478bd9Sstevel@tonic-gate# Determine whether this a ELF dynamic object and if so investigate its runtime 1737c478bd9Sstevel@tonic-gate# attributes. 17475ce41a5SAli Bahrami# 1757c478bd9Sstevel@tonic-gatesub ProcFile { 17675ce41a5SAli Bahrami my($FullPath, $RelPath, $Class, $Type, $Verdef) = @_; 17775ce41a5SAli Bahrami my(@Elf, @Ldd, $Dyn, $Sym, $Stack); 17867e3a03eSrie my($Sun, $Relsz, $Pltsz, $Tex, $Stab, $Strip, $Lddopt, $SymSort); 17975ce41a5SAli Bahrami my($Val, $Header, $IsX86, $RWX, $UnDep); 18075ce41a5SAli Bahrami my($HasDirectBinding); 1817c478bd9Sstevel@tonic-gate 18275ce41a5SAli Bahrami # Only look at executables and sharable objects 18375ce41a5SAli Bahrami return if ($Type ne 'EXEC') && ($Type ne 'DYN'); 1847c478bd9Sstevel@tonic-gate 18575ce41a5SAli Bahrami # Ignore symbolic links 18675ce41a5SAli Bahrami return if -l $FullPath; 18775ce41a5SAli Bahrami 18875ce41a5SAli Bahrami # Is this an object or directory hierarchy we don't care about? 18975ce41a5SAli Bahrami return if (defined($EXRE_skip) && ($RelPath =~ $EXRE_skip)); 19075ce41a5SAli Bahrami 19175ce41a5SAli Bahrami # Bail if we can't stat the file. Otherwise, note if it is SUID/SGID. 19275ce41a5SAli Bahrami return if !stat($FullPath); 19375ce41a5SAli Bahrami my $Secure = (-u _ || -g _) ? 1 : 0; 19475ce41a5SAli Bahrami 19575ce41a5SAli Bahrami # Reset output message counts for new input file 19675ce41a5SAli Bahrami $$ErrTtl = $$InfoTtl = 0; 19775ce41a5SAli Bahrami 1987c478bd9Sstevel@tonic-gate @Ldd = 0; 1997c478bd9Sstevel@tonic-gate 2007c478bd9Sstevel@tonic-gate # Determine whether we have access to inspect the file. 2017c478bd9Sstevel@tonic-gate if (!(-r $FullPath)) { 20275ce41a5SAli Bahrami onbld_elfmod::OutMsg($ErrFH, $ErrTtl, $RelPath, 20375ce41a5SAli Bahrami "unable to inspect file: permission denied"); 2047c478bd9Sstevel@tonic-gate return; 2057c478bd9Sstevel@tonic-gate } 2067c478bd9Sstevel@tonic-gate 2077c478bd9Sstevel@tonic-gate # Determine whether we have a executable (static or dynamic) or a 2087c478bd9Sstevel@tonic-gate # shared object. 20975ce41a5SAli Bahrami @Elf = split(/\n/, `elfdump -epdcy $FullPath 2>&1`); 2107c478bd9Sstevel@tonic-gate 21175ce41a5SAli Bahrami $Dyn = $Stack = $IsX86 = $RWX = 0; 2127c478bd9Sstevel@tonic-gate $Header = 'None'; 2137c478bd9Sstevel@tonic-gate foreach my $Line (@Elf) { 2147c478bd9Sstevel@tonic-gate # If we have an invalid file type (which we can tell from the 2157c478bd9Sstevel@tonic-gate # first line), or we're processing an archive, bail. 2167c478bd9Sstevel@tonic-gate if ($Header eq 'None') { 2177c478bd9Sstevel@tonic-gate if (($Line =~ /invalid file/) || 218*5253169eSAli Bahrami ($Line =~ /\Q$FullPath\E(.*):/)) { 2197c478bd9Sstevel@tonic-gate return; 2207c478bd9Sstevel@tonic-gate } 2217c478bd9Sstevel@tonic-gate } 2227c478bd9Sstevel@tonic-gate 2237c478bd9Sstevel@tonic-gate if ($Line =~ /^ELF Header/) { 2247c478bd9Sstevel@tonic-gate $Header = 'Ehdr'; 22575ce41a5SAli Bahrami next; 22675ce41a5SAli Bahrami } 2277c478bd9Sstevel@tonic-gate 22875ce41a5SAli Bahrami if ($Line =~ /^Program Header/) { 2297c478bd9Sstevel@tonic-gate $Header = 'Phdr'; 2307c478bd9Sstevel@tonic-gate $RWX = 0; 23175ce41a5SAli Bahrami next; 23275ce41a5SAli Bahrami } 2337c478bd9Sstevel@tonic-gate 23475ce41a5SAli Bahrami if ($Line =~ /^Dynamic Section/) { 2357c478bd9Sstevel@tonic-gate # A dynamic section indicates we're a dynamic object 2367c478bd9Sstevel@tonic-gate # (this makes sure we don't check static executables). 2377c478bd9Sstevel@tonic-gate $Dyn = 1; 23875ce41a5SAli Bahrami next; 23975ce41a5SAli Bahrami } 2407c478bd9Sstevel@tonic-gate 24175ce41a5SAli Bahrami if (($Header eq 'Ehdr') && ($Line =~ /e_machine:/)) { 2427c478bd9Sstevel@tonic-gate # If it's a X86 object, we need to enforce RW- data. 24375ce41a5SAli Bahrami $IsX86 = 1 if $Line =~ /(EM_AMD64|EM_386)/; 24475ce41a5SAli Bahrami next; 2457c478bd9Sstevel@tonic-gate } 24675ce41a5SAli Bahrami 24775ce41a5SAli Bahrami if (($Header eq 'Phdr') && 248*5253169eSAli Bahrami ($Line =~ /\[ PF_X\s+PF_W\s+PF_R \]/)) { 2497c478bd9Sstevel@tonic-gate # RWX segment seen. 2507c478bd9Sstevel@tonic-gate $RWX = 1; 25175ce41a5SAli Bahrami next; 2527c478bd9Sstevel@tonic-gate } 2537c478bd9Sstevel@tonic-gate 25475ce41a5SAli Bahrami if (($Header eq 'Phdr') && 25575ce41a5SAli Bahrami ($Line =~ /\[ PT_LOAD \]/ && $RWX && $IsX86)) { 25675ce41a5SAli Bahrami # Seen an RWX PT_LOAD segment. 257*5253169eSAli Bahrami if (!defined($EXRE_exec_data) || 258*5253169eSAli Bahrami ($RelPath !~ $EXRE_exec_data)) { 25975ce41a5SAli Bahrami onbld_elfmod::OutMsg($ErrFH, $ErrTtl, $RelPath, 26075ce41a5SAli Bahrami "application requires non-executable " . 26175ce41a5SAli Bahrami "data\t<no -Mmapfile_noexdata?>"); 26275ce41a5SAli Bahrami } 26375ce41a5SAli Bahrami next; 26475ce41a5SAli Bahrami } 26575ce41a5SAli Bahrami 26675ce41a5SAli Bahrami if (($Header eq 'Phdr') && ($Line =~ /\[ PT_SUNWSTACK \]/)) { 2677c478bd9Sstevel@tonic-gate # This object defines a non-executable stack. 2687c478bd9Sstevel@tonic-gate $Stack = 1; 26975ce41a5SAli Bahrami next; 2707c478bd9Sstevel@tonic-gate } 2717c478bd9Sstevel@tonic-gate } 2727c478bd9Sstevel@tonic-gate 2737c478bd9Sstevel@tonic-gate # Determine whether this ELF executable or shared object has a 2747c478bd9Sstevel@tonic-gate # conforming mcs(1) comment section. If the correct $(POST_PROCESS) 2757c478bd9Sstevel@tonic-gate # macros are used, only a 3 or 4 line .comment section should exist 2767c478bd9Sstevel@tonic-gate # containing one or two "@(#)SunOS" identifying comments (one comment 2777c478bd9Sstevel@tonic-gate # for a non-debug build, and two for a debug build). The results of 2787c478bd9Sstevel@tonic-gate # the following split should be three or four lines, the last empty 2797c478bd9Sstevel@tonic-gate # line being discarded by the split. 2807c478bd9Sstevel@tonic-gate if ($opt{m}) { 2817c478bd9Sstevel@tonic-gate my(@Mcs, $Con, $Dev); 2827c478bd9Sstevel@tonic-gate 2837c478bd9Sstevel@tonic-gate @Mcs = split(/\n/, `mcs -p $FullPath 2>&1`); 2847c478bd9Sstevel@tonic-gate 2857c478bd9Sstevel@tonic-gate $Con = $Dev = $Val = 0; 2867c478bd9Sstevel@tonic-gate foreach my $Line (@Mcs) { 2877c478bd9Sstevel@tonic-gate $Val++; 2887c478bd9Sstevel@tonic-gate 2897c478bd9Sstevel@tonic-gate if (($Val == 3) && ($Line !~ /^@\(#\)SunOS/)) { 2907c478bd9Sstevel@tonic-gate $Con = 1; 2917c478bd9Sstevel@tonic-gate last; 2927c478bd9Sstevel@tonic-gate } 2937c478bd9Sstevel@tonic-gate if (($Val == 4) && ($Line =~ /^@\(#\)SunOS/)) { 2947c478bd9Sstevel@tonic-gate $Dev = 1; 2957c478bd9Sstevel@tonic-gate next; 2967c478bd9Sstevel@tonic-gate } 2977c478bd9Sstevel@tonic-gate if (($Dev == 0) && ($Val == 4)) { 2987c478bd9Sstevel@tonic-gate $Con = 1; 2997c478bd9Sstevel@tonic-gate last; 3007c478bd9Sstevel@tonic-gate } 3017c478bd9Sstevel@tonic-gate if (($Dev == 1) && ($Val == 5)) { 3027c478bd9Sstevel@tonic-gate $Con = 1; 3037c478bd9Sstevel@tonic-gate last; 3047c478bd9Sstevel@tonic-gate } 3057c478bd9Sstevel@tonic-gate } 3067c478bd9Sstevel@tonic-gate if ($opt{m} && ($Con == 1)) { 30775ce41a5SAli Bahrami onbld_elfmod::OutMsg($ErrFH, $ErrTtl, $RelPath, 30875ce41a5SAli Bahrami "non-conforming mcs(1) comment\t<no \$(POST_PROCESS)?>"); 3097c478bd9Sstevel@tonic-gate } 3107c478bd9Sstevel@tonic-gate } 3117c478bd9Sstevel@tonic-gate 3127c478bd9Sstevel@tonic-gate # Applications should contain a non-executable stack definition. 31375ce41a5SAli Bahrami if (($Type eq 'EXEC') && ($Stack == 0) && 31475ce41a5SAli Bahrami (!defined($EXRE_exec_stack) || ($RelPath !~ $EXRE_exec_stack))) { 31575ce41a5SAli Bahrami onbld_elfmod::OutMsg($ErrFH, $ErrTtl, $RelPath, 31675ce41a5SAli Bahrami "non-executable stack required\t<no -Mmapfile_noexstk?>"); 3177c478bd9Sstevel@tonic-gate } 3187c478bd9Sstevel@tonic-gate 3197c478bd9Sstevel@tonic-gate # Having caught any static executables in the mcs(1) check and non- 3207c478bd9Sstevel@tonic-gate # executable stack definition check, continue with dynamic objects 3217c478bd9Sstevel@tonic-gate # from now on. 3227c478bd9Sstevel@tonic-gate if ($Dyn eq 0) { 3237c478bd9Sstevel@tonic-gate return; 3247c478bd9Sstevel@tonic-gate } 3257c478bd9Sstevel@tonic-gate 32675ce41a5SAli Bahrami # Use ldd unless its a 64-bit object and we lack the hardware. 32775ce41a5SAli Bahrami if (($Class == 32) || $Ena64) { 328976d55c9Sab196087 my $LDDFullPath = $FullPath; 329976d55c9Sab196087 3307c478bd9Sstevel@tonic-gate if ($Secure) { 3317c478bd9Sstevel@tonic-gate # The execution of a secure application over an nfs file 3327c478bd9Sstevel@tonic-gate # system mounted nosuid will result in warning messages 3337c478bd9Sstevel@tonic-gate # being sent to /var/adm/messages. As this type of 3347c478bd9Sstevel@tonic-gate # environment can occur with root builds, move the file 3357c478bd9Sstevel@tonic-gate # being investigated to a safe place first. In addition 3367c478bd9Sstevel@tonic-gate # remove its secure permission so that it can be 3377c478bd9Sstevel@tonic-gate # influenced by any alternative dependency mappings. 3387c478bd9Sstevel@tonic-gate 33975ce41a5SAli Bahrami my $File = $RelPath; 34075ce41a5SAli Bahrami $File =~ s!^.*/!!; # basename 34175ce41a5SAli Bahrami 3427c478bd9Sstevel@tonic-gate my($TmpPath) = "$Tmpdir/$File"; 3437c478bd9Sstevel@tonic-gate 344976d55c9Sab196087 system('cp', $LDDFullPath, $TmpPath); 3457c478bd9Sstevel@tonic-gate chmod 0777, $TmpPath; 346976d55c9Sab196087 $LDDFullPath = $TmpPath; 3477c478bd9Sstevel@tonic-gate } 3487c478bd9Sstevel@tonic-gate 3497c478bd9Sstevel@tonic-gate # Use ldd(1) to determine the objects relocatability and use. 3507c478bd9Sstevel@tonic-gate # By default look for all unreferenced dependencies. However, 3517c478bd9Sstevel@tonic-gate # some objects have legitimate dependencies that they do not 3527c478bd9Sstevel@tonic-gate # reference. 35375ce41a5SAli Bahrami if ($LddNoU) { 3547c478bd9Sstevel@tonic-gate $Lddopt = "-ru"; 3557c478bd9Sstevel@tonic-gate } else { 3567c478bd9Sstevel@tonic-gate $Lddopt = "-rU"; 3577c478bd9Sstevel@tonic-gate } 358976d55c9Sab196087 @Ldd = split(/\n/, `ldd $Lddopt $Env $LDDFullPath 2>&1`); 3597c478bd9Sstevel@tonic-gate if ($Secure) { 360976d55c9Sab196087 unlink $LDDFullPath; 3617c478bd9Sstevel@tonic-gate } 3627c478bd9Sstevel@tonic-gate } 3637c478bd9Sstevel@tonic-gate 3647c478bd9Sstevel@tonic-gate $Val = 0; 3657c478bd9Sstevel@tonic-gate $Sym = 5; 36667e3a03eSrie $UnDep = 1; 3677c478bd9Sstevel@tonic-gate 36867e3a03eSrie foreach my $Line (@Ldd) { 3697c478bd9Sstevel@tonic-gate 3707c478bd9Sstevel@tonic-gate if ($Val == 0) { 3717c478bd9Sstevel@tonic-gate $Val = 1; 3727c478bd9Sstevel@tonic-gate # Make sure ldd(1) worked. One possible failure is that 3737c478bd9Sstevel@tonic-gate # this is an old ldd(1) prior to -e addition (4390308). 3747c478bd9Sstevel@tonic-gate if ($Line =~ /usage:/) { 3757c478bd9Sstevel@tonic-gate $Line =~ s/$/\t<old ldd(1)?>/; 37675ce41a5SAli Bahrami onbld_elfmod::OutMsg($ErrFH, $ErrTtl, 37775ce41a5SAli Bahrami $RelPath, $Line); 3787c478bd9Sstevel@tonic-gate last; 3797c478bd9Sstevel@tonic-gate } elsif ($Line =~ /execution failed/) { 38075ce41a5SAli Bahrami onbld_elfmod::OutMsg($ErrFH, $ErrTtl, 38175ce41a5SAli Bahrami $RelPath, $Line); 3827c478bd9Sstevel@tonic-gate last; 3837c478bd9Sstevel@tonic-gate } 3847c478bd9Sstevel@tonic-gate 3857c478bd9Sstevel@tonic-gate # It's possible this binary can't be executed, ie. we've 3867c478bd9Sstevel@tonic-gate # found a sparc binary while running on an intel system, 3877c478bd9Sstevel@tonic-gate # or a sparcv9 binary on a sparcv7/8 system. 3887c478bd9Sstevel@tonic-gate if ($Line =~ /wrong class/) { 38975ce41a5SAli Bahrami onbld_elfmod::OutMsg($ErrFH, $ErrTtl, $RelPath, 39075ce41a5SAli Bahrami "has wrong class or data encoding"); 3917c478bd9Sstevel@tonic-gate next; 3927c478bd9Sstevel@tonic-gate } 3937c478bd9Sstevel@tonic-gate 3947c478bd9Sstevel@tonic-gate # Historically, ldd(1) likes executable objects to have 39575ce41a5SAli Bahrami # their execute bit set. 3967c478bd9Sstevel@tonic-gate if ($Line =~ /not executable/) { 39775ce41a5SAli Bahrami onbld_elfmod::OutMsg($ErrFH, $ErrTtl, $RelPath, 39875ce41a5SAli Bahrami "is not executable"); 3997c478bd9Sstevel@tonic-gate next; 4007c478bd9Sstevel@tonic-gate } 4017c478bd9Sstevel@tonic-gate } 4027c478bd9Sstevel@tonic-gate 4037c478bd9Sstevel@tonic-gate # Look for "file" or "versions" that aren't found. Note that 4047c478bd9Sstevel@tonic-gate # these lines will occur before we find any symbol referencing 4057c478bd9Sstevel@tonic-gate # errors. 4067c478bd9Sstevel@tonic-gate if (($Sym == 5) && ($Line =~ /not found\)/)) { 4077c478bd9Sstevel@tonic-gate if ($Line =~ /file not found\)/) { 4087c478bd9Sstevel@tonic-gate $Line =~ s/$/\t<no -zdefs?>/; 4097c478bd9Sstevel@tonic-gate } 41075ce41a5SAli Bahrami onbld_elfmod::OutMsg($ErrFH, $ErrTtl, $RelPath, $Line); 4117c478bd9Sstevel@tonic-gate next; 4127c478bd9Sstevel@tonic-gate } 4137c478bd9Sstevel@tonic-gate # Look for relocations whose symbols can't be found. Note, we 4147c478bd9Sstevel@tonic-gate # only print out the first 5 relocations for any file as this 4157c478bd9Sstevel@tonic-gate # output can be excessive. 4167c478bd9Sstevel@tonic-gate if ($Sym && ($Line =~ /symbol not found/)) { 4177c478bd9Sstevel@tonic-gate # Determine if this file is allowed undefined 4187c478bd9Sstevel@tonic-gate # references. 41975ce41a5SAli Bahrami if (($Sym == 5) && defined($EXRE_undef_ref) && 42075ce41a5SAli Bahrami ($RelPath =~ $EXRE_undef_ref)) { 4217c478bd9Sstevel@tonic-gate $Sym = 0; 42267e3a03eSrie next; 4237c478bd9Sstevel@tonic-gate } 4247c478bd9Sstevel@tonic-gate if ($Sym-- == 1) { 42575ce41a5SAli Bahrami onbld_elfmod::OutMsg($ErrFH, $ErrTtl, $RelPath, 42675ce41a5SAli Bahrami "continued ...") if !$opt{o}; 4277c478bd9Sstevel@tonic-gate next; 4287c478bd9Sstevel@tonic-gate } 4297c478bd9Sstevel@tonic-gate # Just print the symbol name. 4307c478bd9Sstevel@tonic-gate $Line =~ s/$/\t<no -zdefs?>/; 43175ce41a5SAli Bahrami onbld_elfmod::OutMsg($ErrFH, $ErrTtl, $RelPath, $Line); 4327c478bd9Sstevel@tonic-gate next; 4337c478bd9Sstevel@tonic-gate } 43467e3a03eSrie # Look for any unused search paths. 43567e3a03eSrie if ($Line =~ /unused search path=/) { 436d89524d0Srie # Note, skip this comparison for __GNUC builds, as the 437d89524d0Srie # gnu compilers insert numerous unused search paths. 438d89524d0Srie if ($Gnuc == 1) { 439d89524d0Srie next; 440d89524d0Srie } 44175ce41a5SAli Bahrami next if defined($EXRE_unused_rpath) && 44275ce41a5SAli Bahrami ($Line =~ $EXRE_unused_rpath); 44375ce41a5SAli Bahrami 44467e3a03eSrie if ($Secure) { 44567e3a03eSrie $Line =~ s!$Tmpdir/!!; 44667e3a03eSrie } 44767e3a03eSrie $Line =~ s/^[ \t]*(.*)/\t$1\t<remove search path?>/; 44875ce41a5SAli Bahrami onbld_elfmod::OutMsg($ErrFH, $ErrTtl, $RelPath, $Line); 44967e3a03eSrie next; 45067e3a03eSrie } 45167e3a03eSrie # Look for unreferenced dependencies. Note, if any unreferenced 45267e3a03eSrie # objects are ignored, then set $UnDep so as to suppress any 45367e3a03eSrie # associated unused-object messages. 45467e3a03eSrie if ($Line =~ /unreferenced object=/) { 45575ce41a5SAli Bahrami if (defined($EXRE_unref_obj) && 45675ce41a5SAli Bahrami ($Line =~ $EXRE_unref_obj)) { 45767e3a03eSrie $UnDep = 0; 45867e3a03eSrie next; 45967e3a03eSrie } 46067e3a03eSrie if ($Secure) { 46167e3a03eSrie $Line =~ s!$Tmpdir/!!; 46267e3a03eSrie } 46375ce41a5SAli Bahrami $Line =~ s/^[ \t]*(.*)/$1\t<remove lib or -zignore?>/; 46475ce41a5SAli Bahrami onbld_elfmod::OutMsg($ErrFH, $ErrTtl, $RelPath, $Line); 46567e3a03eSrie next; 46667e3a03eSrie } 4677c478bd9Sstevel@tonic-gate # Look for any unused dependencies. 46867e3a03eSrie if ($UnDep && ($Line =~ /unused/)) { 46975ce41a5SAli Bahrami # Skip if object is allowed to have unused dependencies 47075ce41a5SAli Bahrami next if defined($EXRE_unused_deps) && 47175ce41a5SAli Bahrami ($RelPath =~ $EXRE_unused_deps); 47275ce41a5SAli Bahrami 47375ce41a5SAli Bahrami # Skip if dependency is always allowed to be unused 47475ce41a5SAli Bahrami next if defined($EXRE_unused_obj) && 47575ce41a5SAli Bahrami ($Line =~ $EXRE_unused_obj); 47675ce41a5SAli Bahrami 47775ce41a5SAli Bahrami $Line =~ s!$Tmpdir/!! if $Secure; 47875ce41a5SAli Bahrami $Line =~ s/^[ \t]*(.*)/$1\t<remove lib or -zignore?>/; 47975ce41a5SAli Bahrami onbld_elfmod::OutMsg($ErrFH, $ErrTtl, $RelPath, $Line); 4807c478bd9Sstevel@tonic-gate next; 4817c478bd9Sstevel@tonic-gate } 4827c478bd9Sstevel@tonic-gate } 4837c478bd9Sstevel@tonic-gate 4847c478bd9Sstevel@tonic-gate # Reuse the elfdump(1) data to investigate additional dynamic linking 4857c478bd9Sstevel@tonic-gate # information. 4867c478bd9Sstevel@tonic-gate 487dfb96a4fSab196087 $Sun = $Relsz = $Pltsz = $Dyn = $Stab = $SymSort = 0; 4887c478bd9Sstevel@tonic-gate $Tex = $Strip = 1; 489f6acbf7cSrie $HasDirectBinding = 0; 4907c478bd9Sstevel@tonic-gate 4917c478bd9Sstevel@tonic-gate $Header = 'None'; 4927c478bd9Sstevel@tonic-gateELF: foreach my $Line (@Elf) { 4937c478bd9Sstevel@tonic-gate # We're only interested in the section headers and the dynamic 4947c478bd9Sstevel@tonic-gate # section. 4957c478bd9Sstevel@tonic-gate if ($Line =~ /^Section Header/) { 4967c478bd9Sstevel@tonic-gate $Header = 'Shdr'; 4977c478bd9Sstevel@tonic-gate 4987c478bd9Sstevel@tonic-gate if (($Sun == 0) && ($Line =~ /\.SUNW_reloc/)) { 4997c478bd9Sstevel@tonic-gate # This object has a combined relocation section. 5007c478bd9Sstevel@tonic-gate $Sun = 1; 5017c478bd9Sstevel@tonic-gate 5027c478bd9Sstevel@tonic-gate } elsif (($Stab == 0) && ($Line =~ /\.stab/)) { 5037c478bd9Sstevel@tonic-gate # This object contain .stabs sections 5047c478bd9Sstevel@tonic-gate $Stab = 1; 505dfb96a4fSab196087 } elsif (($SymSort == 0) && 506dfb96a4fSab196087 ($Line =~ /\.SUNW_dyn(sym)|(tls)sort/)) { 507dfb96a4fSab196087 # This object contains a symbol sort section 508dfb96a4fSab196087 $SymSort = 1; 5097c478bd9Sstevel@tonic-gate } 5107c478bd9Sstevel@tonic-gate 5117c478bd9Sstevel@tonic-gate if (($Strip == 1) && ($Line =~ /\.symtab/)) { 5127c478bd9Sstevel@tonic-gate # This object contains a complete symbol table. 5137c478bd9Sstevel@tonic-gate $Strip = 0; 5147c478bd9Sstevel@tonic-gate } 5157c478bd9Sstevel@tonic-gate next; 5167c478bd9Sstevel@tonic-gate 5177c478bd9Sstevel@tonic-gate } elsif ($Line =~ /^Dynamic Section/) { 5187c478bd9Sstevel@tonic-gate $Header = 'Dyn'; 5197c478bd9Sstevel@tonic-gate next; 520f6acbf7cSrie } elsif ($Line =~ /^Syminfo Section/) { 521f6acbf7cSrie $Header = 'Syminfo'; 522f6acbf7cSrie next; 523f6acbf7cSrie } elsif (($Header ne 'Dyn') && ($Header ne 'Syminfo')) { 524f6acbf7cSrie next; 525f6acbf7cSrie } 526f6acbf7cSrie 527f6acbf7cSrie # Look into the Syminfo section. 528f6acbf7cSrie # Does this object have at least one Directly Bound symbol? 529f6acbf7cSrie if (($Header eq 'Syminfo')) { 530f6acbf7cSrie my(@Symword); 531f6acbf7cSrie 532f6acbf7cSrie if ($HasDirectBinding == 1) { 533f6acbf7cSrie next; 534f6acbf7cSrie } 535f6acbf7cSrie 536f6acbf7cSrie @Symword = split(' ', $Line); 537f6acbf7cSrie 538f6acbf7cSrie if (!defined($Symword[1])) { 539f6acbf7cSrie next; 540f6acbf7cSrie } 541f6acbf7cSrie if ($Symword[1] =~ /B/) { 542f6acbf7cSrie $HasDirectBinding = 1; 543f6acbf7cSrie } 5447c478bd9Sstevel@tonic-gate next; 5457c478bd9Sstevel@tonic-gate } 5467c478bd9Sstevel@tonic-gate 5477c478bd9Sstevel@tonic-gate # Does this object contain text relocations. 5487c478bd9Sstevel@tonic-gate if ($Tex && ($Line =~ /TEXTREL/)) { 5497c478bd9Sstevel@tonic-gate # Determine if this file is allowed text relocations. 55075ce41a5SAli Bahrami if (defined($EXRE_textrel) && 55175ce41a5SAli Bahrami ($RelPath =~ $EXRE_textrel)) { 5527c478bd9Sstevel@tonic-gate $Tex = 0; 5537c478bd9Sstevel@tonic-gate next ELF; 5547c478bd9Sstevel@tonic-gate } 55575ce41a5SAli Bahrami onbld_elfmod::OutMsg($ErrFH, $ErrTtl, $RelPath, 55675ce41a5SAli Bahrami "TEXTREL .dynamic tag\t\t\t<no -Kpic?>"); 5577c478bd9Sstevel@tonic-gate $Tex = 0; 5587c478bd9Sstevel@tonic-gate next; 5597c478bd9Sstevel@tonic-gate } 5607c478bd9Sstevel@tonic-gate 5617c478bd9Sstevel@tonic-gate # Does this file have any relocation sections (there are a few 5627c478bd9Sstevel@tonic-gate # psr libraries with no relocations at all, thus a .SUNW_reloc 5637c478bd9Sstevel@tonic-gate # section won't exist either). 5647c478bd9Sstevel@tonic-gate if (($Relsz == 0) && ($Line =~ / RELA?SZ/)) { 5657c478bd9Sstevel@tonic-gate $Relsz = hex((split(' ', $Line))[2]); 5667c478bd9Sstevel@tonic-gate next; 5677c478bd9Sstevel@tonic-gate } 5687c478bd9Sstevel@tonic-gate 5697c478bd9Sstevel@tonic-gate # Does this file have any plt relocations. If the plt size is 5707c478bd9Sstevel@tonic-gate # equivalent to the total relocation size then we don't have 5717c478bd9Sstevel@tonic-gate # any relocations suitable for combining into a .SUNW_reloc 5727c478bd9Sstevel@tonic-gate # section. 5737c478bd9Sstevel@tonic-gate if (($Pltsz == 0) && ($Line =~ / PLTRELSZ/)) { 5747c478bd9Sstevel@tonic-gate $Pltsz = hex((split(' ', $Line))[2]); 5757c478bd9Sstevel@tonic-gate next; 5767c478bd9Sstevel@tonic-gate } 5777c478bd9Sstevel@tonic-gate 5787c478bd9Sstevel@tonic-gate # Does this object have any dependencies. 57967e3a03eSrie if ($Line =~ /NEEDED/) { 5807c478bd9Sstevel@tonic-gate my($Need) = (split(' ', $Line))[3]; 5817c478bd9Sstevel@tonic-gate 58275ce41a5SAli Bahrami if (defined($EXRE_olddep) && ($Need =~ $EXRE_olddep)) { 58367e3a03eSrie # Catch any old (unnecessary) dependencies. 58475ce41a5SAli Bahrami onbld_elfmod::OutMsg($ErrFH, $ErrTtl, $RelPath, 58575ce41a5SAli Bahrami "NEEDED=$Need\t<dependency no longer necessary>"); 58667e3a03eSrie } elsif ($opt{i}) { 58767e3a03eSrie # Under the -i (information) option print out 58867e3a03eSrie # any useful dynamic entries. 58975ce41a5SAli Bahrami onbld_elfmod::OutMsg($InfoFH, $InfoTtl, $RelPath, 59075ce41a5SAli Bahrami "NEEDED=$Need"); 5917c478bd9Sstevel@tonic-gate } 5927c478bd9Sstevel@tonic-gate next; 5937c478bd9Sstevel@tonic-gate } 5947c478bd9Sstevel@tonic-gate 595f6acbf7cSrie # Is this object built with -B direct flag on? 596f6acbf7cSrie if ($Line =~ / DIRECT /) { 597f6acbf7cSrie $HasDirectBinding = 1; 598f6acbf7cSrie } 599f6acbf7cSrie 6007c478bd9Sstevel@tonic-gate # Does this object specify a runpath. 6017c478bd9Sstevel@tonic-gate if ($opt{i} && ($Line =~ /RPATH/)) { 6027c478bd9Sstevel@tonic-gate my($Rpath) = (split(' ', $Line))[3]; 60375ce41a5SAli Bahrami onbld_elfmod::OutMsg($InfoFH, $InfoTtl, 60475ce41a5SAli Bahrami $RelPath, "RPATH=$Rpath"); 6057c478bd9Sstevel@tonic-gate next; 6067c478bd9Sstevel@tonic-gate } 6077c478bd9Sstevel@tonic-gate } 6087c478bd9Sstevel@tonic-gate 6097c478bd9Sstevel@tonic-gate # A shared object, that contains non-plt relocations, should have a 6107c478bd9Sstevel@tonic-gate # combined relocation section indicating it was built with -z combreloc. 61175ce41a5SAli Bahrami if (($Type eq 'DYN') && $Relsz && ($Relsz != $Pltsz) && ($Sun == 0)) { 61275ce41a5SAli Bahrami onbld_elfmod::OutMsg($ErrFH, $ErrTtl, $RelPath, 613*5253169eSAli Bahrami ".SUNW_reloc section missing\t\t<no -zcombreloc?>"); 6147c478bd9Sstevel@tonic-gate } 6157c478bd9Sstevel@tonic-gate 6167c478bd9Sstevel@tonic-gate # No objects released to a customer should have any .stabs sections 6177c478bd9Sstevel@tonic-gate # remaining, they should be stripped. 6187c478bd9Sstevel@tonic-gate if ($opt{s} && $Stab) { 61975ce41a5SAli Bahrami goto DONESTAB if defined($EXRE_stab) && ($RelPath =~ $EXRE_stab); 62075ce41a5SAli Bahrami 62175ce41a5SAli Bahrami onbld_elfmod::OutMsg($ErrFH, $ErrTtl, $RelPath, 62275ce41a5SAli Bahrami "debugging sections should be deleted\t<no strip -x?>"); 6237c478bd9Sstevel@tonic-gate } 6247c478bd9Sstevel@tonic-gate 625f6acbf7cSrie # Identify an object that is not built with either -B direct or 626f6acbf7cSrie # -z direct. 62775ce41a5SAli Bahrami goto DONESTAB 62875ce41a5SAli Bahrami if (defined($EXRE_nodirect) && ($RelPath =~ $EXRE_nodirect)); 62975ce41a5SAli Bahrami 630f6acbf7cSrie if ($Relsz && ($HasDirectBinding == 0)) { 63175ce41a5SAli Bahrami onbld_elfmod::OutMsg($ErrFH, $ErrTtl, $RelPath, 63275ce41a5SAli Bahrami "object has no direct bindings\t<no -B direct or -z direct?>"); 633f6acbf7cSrie } 634f6acbf7cSrie 6357c478bd9Sstevel@tonic-gateDONESTAB: 6367c478bd9Sstevel@tonic-gate 6378ad60789Srie # All objects should have a full symbol table to provide complete 6387c478bd9Sstevel@tonic-gate # debugging stack traces. 63975ce41a5SAli Bahrami onbld_elfmod::OutMsg($ErrFH, $ErrTtl, $RelPath, 64075ce41a5SAli Bahrami "symbol table should not be stripped\t<remove -s?>") if $Strip; 641dfb96a4fSab196087 642dfb96a4fSab196087 # If there are symbol sort sections in this object, report on 643dfb96a4fSab196087 # any that have duplicate addresses. 64475ce41a5SAli Bahrami ProcSymSort($FullPath, $RelPath) if $SymSort; 645bfed486aSAli Bahrami 646bfed486aSAli Bahrami # If -v was specified, and the object has a version definition 647bfed486aSAli Bahrami # section, generate output showing each public symbol and the 648bfed486aSAli Bahrami # version it belongs to. 64975ce41a5SAli Bahrami ProcVerdef($FullPath, $RelPath) 65075ce41a5SAli Bahrami if ($Verdef eq 'VERDEF') && $opt{v}; 651dfb96a4fSab196087} 652dfb96a4fSab196087 653dfb96a4fSab196087 65475ce41a5SAli Bahrami## ProcSymSortOutMsg(RelPath, secname, addr, names...) 655dfb96a4fSab196087# 65675ce41a5SAli Bahrami# Call onbld_elfmod::OutMsg for a duplicate address error in a symbol sort 657dfb96a4fSab196087# section 658dfb96a4fSab196087# 659dfb96a4fSab196087sub ProcSymSortOutMsg { 66075ce41a5SAli Bahrami my($RelPath, $secname, $addr, @names) = @_; 661dfb96a4fSab196087 66275ce41a5SAli Bahrami onbld_elfmod::OutMsg($ErrFH, $ErrTtl, $RelPath, 663dfb96a4fSab196087 "$secname: duplicate $addr: ". join(', ', @names)); 664dfb96a4fSab196087} 665dfb96a4fSab196087 666dfb96a4fSab196087 667dfb96a4fSab196087## ProcSymSort(FullPath, RelPath) 668dfb96a4fSab196087# 669dfb96a4fSab196087# Examine the symbol sort sections for the given object and report 670dfb96a4fSab196087# on any duplicate addresses found. Ideally, mapfile directives 671dfb96a4fSab196087# should be used when building objects that have multiple symbols 672dfb96a4fSab196087# with the same address so that only one of them appears in the sort 673dfb96a4fSab196087# section. This saves space, reduces user confusion, and ensures that 674dfb96a4fSab196087# libproc and debuggers always display public names instead of symbols 675dfb96a4fSab196087# that are merely implementation details. 676dfb96a4fSab196087# 677dfb96a4fSab196087sub ProcSymSort { 678dfb96a4fSab196087 67975ce41a5SAli Bahrami my($FullPath, $RelPath) = @_; 680dfb96a4fSab196087 681dfb96a4fSab196087 # If this object is exempt from checking, return quietly 68275ce41a5SAli Bahrami return if defined($EXRE_nosymsort) && ($FullPath =~ $EXRE_nosymsort); 683dfb96a4fSab196087 684dfb96a4fSab196087 685dfb96a4fSab196087 open(SORT, "elfdump -S $FullPath|") || 686dfb96a4fSab196087 die "$Prog: Unable to execute elfdump (symbol sort sections)\n"; 687dfb96a4fSab196087 688dfb96a4fSab196087 my $line; 689dfb96a4fSab196087 my $last_addr; 690dfb96a4fSab196087 my @dups = (); 691dfb96a4fSab196087 my $secname; 692dfb96a4fSab196087 while ($line = <SORT>) { 693dfb96a4fSab196087 chomp $line; 694dfb96a4fSab196087 695dfb96a4fSab196087 next if ($line eq ''); 696dfb96a4fSab196087 697dfb96a4fSab196087 # If this is a header line, pick up the section name 698dfb96a4fSab196087 if ($line =~ /^Symbol Sort Section:\s+([^\s]+)\s+/) { 699dfb96a4fSab196087 $secname = $1; 700dfb96a4fSab196087 701dfb96a4fSab196087 # Every new section is followed by a column header line 702dfb96a4fSab196087 $line = <SORT>; # Toss header line 703dfb96a4fSab196087 704dfb96a4fSab196087 # Flush anything left from previous section 70575ce41a5SAli Bahrami ProcSymSortOutMsg($RelPath, $secname, $last_addr, @dups) 70675ce41a5SAli Bahrami if (scalar(@dups) > 1); 707dfb96a4fSab196087 708dfb96a4fSab196087 # Reset variables for new sort section 709dfb96a4fSab196087 $last_addr = ''; 710dfb96a4fSab196087 @dups = (); 711dfb96a4fSab196087 712dfb96a4fSab196087 next; 713dfb96a4fSab196087 } 714dfb96a4fSab196087 715dfb96a4fSab196087 # Process symbol line 716dfb96a4fSab196087 my @fields = split /\s+/, $line; 717dfb96a4fSab196087 my $new_addr = $fields[2]; 718169e20d9SAli Bahrami my $new_type = $fields[8]; 719dfb96a4fSab196087 my $new_name = $fields[9]; 720607c61fdSab196087 721169e20d9SAli Bahrami if ($new_type eq 'UNDEF') { 72275ce41a5SAli Bahrami onbld_elfmod::OutMsg($ErrFH, $ErrTtl, $RelPath, 723169e20d9SAli Bahrami "$secname: unexpected UNDEF symbol " . 724169e20d9SAli Bahrami "(link-editor error): $new_name"); 725169e20d9SAli Bahrami next; 726169e20d9SAli Bahrami } 727169e20d9SAli Bahrami 728a854c1c1Sab196087 if ($new_addr eq $last_addr) { 729dfb96a4fSab196087 push @dups, $new_name; 730dfb96a4fSab196087 } else { 73175ce41a5SAli Bahrami ProcSymSortOutMsg($RelPath, $secname, 732dfb96a4fSab196087 $last_addr, @dups) if (scalar(@dups) > 1); 733dfb96a4fSab196087 @dups = ( $new_name ); 734dfb96a4fSab196087 $last_addr = $new_addr; 735dfb96a4fSab196087 } 736dfb96a4fSab196087 } 737dfb96a4fSab196087 73875ce41a5SAli Bahrami ProcSymSortOutMsg($RelPath, $secname, $last_addr, @dups) 739dfb96a4fSab196087 if (scalar(@dups) > 1); 740dfb96a4fSab196087 741dfb96a4fSab196087 close SORT; 7427c478bd9Sstevel@tonic-gate} 7437c478bd9Sstevel@tonic-gate 7447c478bd9Sstevel@tonic-gate 745bfed486aSAli Bahrami## ProcVerdef(FullPath, RelPath) 746bfed486aSAli Bahrami# 747bfed486aSAli Bahrami# Examine the version definition section for the given object and report 748bfed486aSAli Bahrami# each public symbol along with the version it belongs to. 749bfed486aSAli Bahrami# 750bfed486aSAli Bahramisub ProcVerdef { 751bfed486aSAli Bahrami 75275ce41a5SAli Bahrami my($FullPath, $RelPath) = @_; 753bfed486aSAli Bahrami my $line; 754bfed486aSAli Bahrami my $cur_ver = ''; 755bfed486aSAli Bahrami my $tab = $opt{o} ? '' : "\t"; 756bfed486aSAli Bahrami 757bfed486aSAli Bahrami # pvs -dov provides information about the versioning hierarchy 758bfed486aSAli Bahrami # in the file. Lines are of the format: 759bfed486aSAli Bahrami # path - version[XXX]; 760bfed486aSAli Bahrami # where [XXX] indicates optional information, such as flags 761bfed486aSAli Bahrami # or inherited versions. 762bfed486aSAli Bahrami # 763bfed486aSAli Bahrami # Private versions are allowed to change freely, so ignore them. 764bfed486aSAli Bahrami open(PVS, "pvs -dov $FullPath|") || 765bfed486aSAli Bahrami die "$Prog: Unable to execute pvs (version definition section)\n"; 766bfed486aSAli Bahrami 767bfed486aSAli Bahrami while ($line = <PVS>) { 768bfed486aSAli Bahrami chomp $line; 769bfed486aSAli Bahrami 770bfed486aSAli Bahrami if ($line =~ /^[^\s]+\s+-\s+([^;]+)/) { 771bfed486aSAli Bahrami my $ver = $1; 772bfed486aSAli Bahrami 773bfed486aSAli Bahrami next if $ver =~ /private/i; 77475ce41a5SAli Bahrami onbld_elfmod::OutMsg($InfoFH, $InfoTtl, $RelPath, 77575ce41a5SAli Bahrami "${tab}VERDEF=$ver"); 776bfed486aSAli Bahrami } 777bfed486aSAli Bahrami } 778bfed486aSAli Bahrami close PVS; 779bfed486aSAli Bahrami 780bfed486aSAli Bahrami # pvs -dos lists the symbols assigned to each version definition. 781bfed486aSAli Bahrami # Lines are of the format: 782bfed486aSAli Bahrami # path - version: symbol; 783bfed486aSAli Bahrami # path - version: symbol (size); 784bfed486aSAli Bahrami # where the (size) is added to data items, but not for functions. 785bfed486aSAli Bahrami # We strip off the size, if present. 786bfed486aSAli Bahrami 787bfed486aSAli Bahrami open(PVS, "pvs -dos $FullPath|") || 788bfed486aSAli Bahrami die "$Prog: Unable to execute pvs (version definition section)\n"; 789bfed486aSAli Bahrami while ($line = <PVS>) { 790bfed486aSAli Bahrami chomp $line; 791bfed486aSAli Bahrami if ($line =~ /^[^\s]+\s+-\s+([^:]+):\s*([^\s;]+)/) { 792bfed486aSAli Bahrami my $ver = $1; 793bfed486aSAli Bahrami my $sym = $2; 794bfed486aSAli Bahrami 795bfed486aSAli Bahrami next if $ver =~ /private/i; 796bfed486aSAli Bahrami 797bfed486aSAli Bahrami if ($opt{o}) { 79875ce41a5SAli Bahrami onbld_elfmod::OutMsg($InfoFH, $InfoTtl, $RelPath, 799bfed486aSAli Bahrami "VERSION=$ver, SYMBOL=$sym"); 800bfed486aSAli Bahrami } else { 801bfed486aSAli Bahrami if ($cur_ver ne $ver) { 80275ce41a5SAli Bahrami onbld_elfmod::OutMsg($InfoFH, $InfoTtl, 80375ce41a5SAli Bahrami $RelPath, "VERSION=$ver"); 804bfed486aSAli Bahrami $cur_ver = $ver; 805bfed486aSAli Bahrami } 80675ce41a5SAli Bahrami onbld_elfmod::OutMsg($InfoFH, $InfoTtl, 80775ce41a5SAli Bahrami $RelPath, "SYMBOL=$sym"); 808bfed486aSAli Bahrami } 809bfed486aSAli Bahrami } 810bfed486aSAli Bahrami } 811bfed486aSAli Bahrami 812bfed486aSAli Bahrami close PVS; 813bfed486aSAli Bahrami} 814bfed486aSAli Bahrami 815bfed486aSAli Bahrami 81675ce41a5SAli Bahrami## OpenFindElf(file, FileHandleRef, LineNumRef) 81775ce41a5SAli Bahrami# 81875ce41a5SAli Bahrami# Open file in 'find_elf -r' format, and return the value of 81975ce41a5SAli Bahrami# the opening PREFIX line. 82075ce41a5SAli Bahrami# 82175ce41a5SAli Bahrami# entry: 82275ce41a5SAli Bahrami# file - file, or find_elf child process, to open 82375ce41a5SAli Bahrami# FileHandleRef - Reference to file handle to open 82475ce41a5SAli Bahrami# LineNumRef - Reference to integer to increment as lines are input 82575ce41a5SAli Bahrami# 82675ce41a5SAli Bahrami# exit: 82775ce41a5SAli Bahrami# This routine issues a fatal error and does not return on error. 82875ce41a5SAli Bahrami# Otherwise, the value of PREFIX is returned. 82975ce41a5SAli Bahrami# 83075ce41a5SAli Bahramisub OpenFindElf { 83175ce41a5SAli Bahrami my ($file, $fh, $LineNum) = @_; 83275ce41a5SAli Bahrami my $line; 83375ce41a5SAli Bahrami my $prefix; 8347c478bd9Sstevel@tonic-gate 83575ce41a5SAli Bahrami open($fh, $file) || die "$Prog: Unable to open: $file"; 83675ce41a5SAli Bahrami $$LineNum = 0; 83775ce41a5SAli Bahrami 83875ce41a5SAli Bahrami # This script requires relative paths as created by 'find_elf -r'. 83975ce41a5SAli Bahrami # When this is done, the first non-comment line will always 84075ce41a5SAli Bahrami # be PREFIX. Obtain that line, or issue a fatal error. 84175ce41a5SAli Bahrami while ($line = onbld_elfmod::GetLine($fh, $LineNum)) { 84275ce41a5SAli Bahrami if ($line =~ /^PREFIX\s+(.*)$/i) { 84375ce41a5SAli Bahrami $prefix = $1; 84475ce41a5SAli Bahrami last; 8457c478bd9Sstevel@tonic-gate } 8467c478bd9Sstevel@tonic-gate 84775ce41a5SAli Bahrami die "$Prog: No PREFIX line seen on line $$LineNum: $file"; 8487c478bd9Sstevel@tonic-gate } 8497c478bd9Sstevel@tonic-gate 85075ce41a5SAli Bahrami $prefix; 8517c478bd9Sstevel@tonic-gate} 8527c478bd9Sstevel@tonic-gate 8537c478bd9Sstevel@tonic-gate 85475ce41a5SAli Bahrami## ProcFindElf(file) 85575ce41a5SAli Bahrami# 85675ce41a5SAli Bahrami# Open the specified file, which must be produced by "find_elf -r", 85775ce41a5SAli Bahrami# and process the files it describes. 85875ce41a5SAli Bahrami# 85975ce41a5SAli Bahramisub ProcFindElf { 86075ce41a5SAli Bahrami my $file = $_[0]; 86175ce41a5SAli Bahrami my $line; 86275ce41a5SAli Bahrami my $LineNum; 86375ce41a5SAli Bahrami 86475ce41a5SAli Bahrami my $prefix = OpenFindElf($file, \*FIND_ELF, \$LineNum); 86575ce41a5SAli Bahrami 86675ce41a5SAli Bahrami while ($line = onbld_elfmod::GetLine(\*FIND_ELF, \$LineNum)) { 86775ce41a5SAli Bahrami next if !($line =~ /^OBJECT\s/i); 86875ce41a5SAli Bahrami 86975ce41a5SAli Bahrami my ($item, $class, $type, $verdef, $obj) = 87075ce41a5SAli Bahrami split(/\s+/, $line, 5); 87175ce41a5SAli Bahrami 87275ce41a5SAli Bahrami ProcFile("$prefix/$obj", $obj, $class, $type, $verdef); 8737c478bd9Sstevel@tonic-gate } 8747c478bd9Sstevel@tonic-gate 87575ce41a5SAli Bahrami close FIND_ELF; 8767c478bd9Sstevel@tonic-gate} 8777c478bd9Sstevel@tonic-gate 87875ce41a5SAli Bahrami 87975ce41a5SAli Bahrami## AltObjectConfig(file) 88075ce41a5SAli Bahrami# 88175ce41a5SAli Bahrami# Recurse through a directory hierarchy looking for appropriate dependencies 88275ce41a5SAli Bahrami# to map from their standard system locations to the proto area via a crle 88375ce41a5SAli Bahrami# config file. 88475ce41a5SAli Bahrami# 88575ce41a5SAli Bahrami# entry: 88675ce41a5SAli Bahrami# file - File of ELF objects, in 'find_elf -r' format, to examine. 88775ce41a5SAli Bahrami# 88875ce41a5SAli Bahrami# exit: 88975ce41a5SAli Bahrami# Scripts are generated for the 32 and 64-bit cases to run crle 89075ce41a5SAli Bahrami# and create runtime configuration files that will establish 89175ce41a5SAli Bahrami# alternative dependency mappings for the objects identified. 89275ce41a5SAli Bahrami# 89375ce41a5SAli Bahrami# $Env - Set to environment variable definitions that will cause 89475ce41a5SAli Bahrami# the config files generated by this routine to be used 89575ce41a5SAli Bahrami# by ldd. 89675ce41a5SAli Bahrami# $Conf32, $Conf64 - Undefined, or set to the config files generated 89775ce41a5SAli Bahrami# by this routine. If defined, the caller is responsible for 89875ce41a5SAli Bahrami# unlinking the files before exiting. 89975ce41a5SAli Bahrami# 90075ce41a5SAli Bahramisub AltObjectConfig { 90175ce41a5SAli Bahrami my $file = $_[0]; 90275ce41a5SAli Bahrami my ($Crle32, $Crle64); 90375ce41a5SAli Bahrami my $line; 90475ce41a5SAli Bahrami my $LineNum; 90575ce41a5SAli Bahrami my $obj_path; 90675ce41a5SAli Bahrami my $obj_active = 0; 90775ce41a5SAli Bahrami my $obj_class; 90875ce41a5SAli Bahrami 90975ce41a5SAli Bahrami my $prefix = OpenFindElf($file, \*FIND_ELF); 91075ce41a5SAli Bahrami 91175ce41a5SAli BahramiLINE: 91275ce41a5SAli Bahrami while ($line = onbld_elfmod::GetLine(\*FIND_ELF, \$LineNum)) { 91375ce41a5SAli Bahrami ITEM: { 91475ce41a5SAli Bahrami 91575ce41a5SAli Bahrami if ($line =~ /^OBJECT\s/i) { 91675ce41a5SAli Bahrami my ($item, $class, $type, $verdef, $obj) = 91775ce41a5SAli Bahrami split(/\s+/, $line, 5); 91875ce41a5SAli Bahrami 91975ce41a5SAli Bahrami if ($type eq 'DYN') { 92075ce41a5SAli Bahrami $obj_active = 1; 92175ce41a5SAli Bahrami $obj_path = $obj; 92275ce41a5SAli Bahrami $obj_class = $class; 92375ce41a5SAli Bahrami } else { 92475ce41a5SAli Bahrami # Only want sharable objects 92575ce41a5SAli Bahrami $obj_active = 0; 9267c478bd9Sstevel@tonic-gate } 92775ce41a5SAli Bahrami last ITEM; 9287c478bd9Sstevel@tonic-gate } 9297c478bd9Sstevel@tonic-gate 93075ce41a5SAli Bahrami # We need to follow links to sharable objects so 93175ce41a5SAli Bahrami # that any dependencies are expressed in all their 93275ce41a5SAli Bahrami # available forms. We depend on ALIAS lines directly 93375ce41a5SAli Bahrami # following the object they alias, so if we have 93475ce41a5SAli Bahrami # a current object, this alias belongs to it. 93575ce41a5SAli Bahrami if ($obj_active && ($line =~ /^ALIAS\s/i)) { 93675ce41a5SAli Bahrami my ($item, $real_obj, $obj) = 93775ce41a5SAli Bahrami split(/\s+/, $line, 3); 93875ce41a5SAli Bahrami $obj_path = $obj; 93975ce41a5SAli Bahrami last ITEM; 9407c478bd9Sstevel@tonic-gate } 9417c478bd9Sstevel@tonic-gate 94275ce41a5SAli Bahrami # Skip unrecognized item 94375ce41a5SAli Bahrami next LINE; 94475ce41a5SAli Bahrami } 9457c478bd9Sstevel@tonic-gate 94675ce41a5SAli Bahrami next if !$obj_active; 9477c478bd9Sstevel@tonic-gate 94875ce41a5SAli Bahrami my $full = "$prefix/$obj_path"; 94975ce41a5SAli Bahrami 95075ce41a5SAli Bahrami next if defined($EXRE_nocrlealt) && 95175ce41a5SAli Bahrami ($obj_path =~ $EXRE_nocrlealt); 95275ce41a5SAli Bahrami 95375ce41a5SAli Bahrami my $Dir = $full; 95475ce41a5SAli Bahrami $Dir =~ s/^(.*)\/.*$/$1/; 95575ce41a5SAli Bahrami 95675ce41a5SAli Bahrami # Create a crle(1) script for the dependency we've found. 95775ce41a5SAli Bahrami # We build separate scripts for the 32 and 64-bit cases. 95875ce41a5SAli Bahrami # We create and initialize each script when we encounter 95975ce41a5SAli Bahrami # the first object that needs it. 96075ce41a5SAli Bahrami if ($obj_class == 32) { 9617c478bd9Sstevel@tonic-gate if (!$Crle32) { 9627c478bd9Sstevel@tonic-gate $Crle32 = "$Tmpdir/$Prog.crle32.$$"; 9637c478bd9Sstevel@tonic-gate open(CRLE32, "> $Crle32") || 9647c478bd9Sstevel@tonic-gate die "$Prog: open failed: $Crle32: $!"; 9657c478bd9Sstevel@tonic-gate print CRLE32 "#!/bin/sh\ncrle \\\n"; 9667c478bd9Sstevel@tonic-gate } 96775ce41a5SAli Bahrami print CRLE32 "\t-o $Dir -a /$obj_path \\\n"; 96875ce41a5SAli Bahrami } elsif ($Ena64) { 96975ce41a5SAli Bahrami if (!$Crle64) { 97075ce41a5SAli Bahrami $Crle64 = "$Tmpdir/$Prog.crle64.$$"; 97175ce41a5SAli Bahrami open(CRLE64, "> $Crle64") || 97275ce41a5SAli Bahrami die "$Prog: open failed: $Crle64: $!"; 97375ce41a5SAli Bahrami print CRLE64 "#!/bin/sh\ncrle -64\\\n"; 97475ce41a5SAli Bahrami } 97575ce41a5SAli Bahrami print CRLE64 "\t-o $Dir -a /$obj_path \\\n"; 97675ce41a5SAli Bahrami } 9777c478bd9Sstevel@tonic-gate } 9787c478bd9Sstevel@tonic-gate 97975ce41a5SAli Bahrami close FIND_ELF; 9807c478bd9Sstevel@tonic-gate 98175ce41a5SAli Bahrami 98275ce41a5SAli Bahrami # Now that the config scripts are complete, use them to generate 98375ce41a5SAli Bahrami # runtime linker config files. 9847c478bd9Sstevel@tonic-gate if ($Crle64) { 9857c478bd9Sstevel@tonic-gate $Conf64 = "$Tmpdir/$Prog.conf64.$$"; 9867c478bd9Sstevel@tonic-gate print CRLE64 "\t-c $Conf64\n"; 9877c478bd9Sstevel@tonic-gate 9887c478bd9Sstevel@tonic-gate chmod 0755, $Crle64; 9897c478bd9Sstevel@tonic-gate close CRLE64; 9907c478bd9Sstevel@tonic-gate 99175ce41a5SAli Bahrami undef $Conf64 if system($Crle64); 99275ce41a5SAli Bahrami 99375ce41a5SAli Bahrami # Done with the script 99475ce41a5SAli Bahrami unlink $Crle64; 9957c478bd9Sstevel@tonic-gate } 9967c478bd9Sstevel@tonic-gate if ($Crle32) { 9977c478bd9Sstevel@tonic-gate $Conf32 = "$Tmpdir/$Prog.conf32.$$"; 9987c478bd9Sstevel@tonic-gate print CRLE32 "\t-c $Conf32\n"; 9997c478bd9Sstevel@tonic-gate 10007c478bd9Sstevel@tonic-gate chmod 0755, $Crle32; 10017c478bd9Sstevel@tonic-gate close CRLE32; 10027c478bd9Sstevel@tonic-gate 100375ce41a5SAli Bahrami undef $Conf32 if system($Crle32); 100475ce41a5SAli Bahrami 100575ce41a5SAli Bahrami # Done with the script 100675ce41a5SAli Bahrami unlink $Crle32; 10077c478bd9Sstevel@tonic-gate } 10087c478bd9Sstevel@tonic-gate 100975ce41a5SAli Bahrami # Set $Env so that we will use the config files generated above 101075ce41a5SAli Bahrami # when we run ldd. 10117c478bd9Sstevel@tonic-gate if ($Crle64 && $Conf64 && $Crle32 && $Conf32) { 10127c478bd9Sstevel@tonic-gate $Env = "-e LD_FLAGS=config_64=$Conf64,config_32=$Conf32"; 10137c478bd9Sstevel@tonic-gate } elsif ($Crle64 && $Conf64) { 10147c478bd9Sstevel@tonic-gate $Env = "-e LD_FLAGS=config_64=$Conf64"; 10157c478bd9Sstevel@tonic-gate } elsif ($Crle32 && $Conf32) { 10167c478bd9Sstevel@tonic-gate $Env = "-e LD_FLAGS=config_32=$Conf32"; 10177c478bd9Sstevel@tonic-gate } 10187c478bd9Sstevel@tonic-gate} 10197c478bd9Sstevel@tonic-gate 102075ce41a5SAli Bahrami# ----------------------------------------------------------------------------- 10217c478bd9Sstevel@tonic-gate 102275ce41a5SAli Bahrami# This script relies on ldd returning output reflecting only the binary 102375ce41a5SAli Bahrami# contents. But if LD_PRELOAD* environment variables are present, libraries 102475ce41a5SAli Bahrami# named by them will also appear in the output, disrupting our analysis. 102575ce41a5SAli Bahrami# So, before we get too far, scrub the environment. 10267c478bd9Sstevel@tonic-gate 102775ce41a5SAli Bahramidelete($ENV{LD_PRELOAD}); 102875ce41a5SAli Bahramidelete($ENV{LD_PRELOAD_32}); 102975ce41a5SAli Bahramidelete($ENV{LD_PRELOAD_64}); 10307c478bd9Sstevel@tonic-gate 103175ce41a5SAli Bahrami# Establish a program name for any error diagnostics. 103275ce41a5SAli Bahramichomp($Prog = `basename $0`); 10337c478bd9Sstevel@tonic-gate 103475ce41a5SAli Bahrami# The onbld_elfmod package is maintained in the same directory as this 103575ce41a5SAli Bahrami# script, and is installed in ../lib/perl. Use the local one if present, 103675ce41a5SAli Bahrami# and the installed one otherwise. 103775ce41a5SAli Bahramimy $moddir = dirname($0); 103875ce41a5SAli Bahrami$moddir = "$moddir/../lib/perl" if ! -f "$moddir/onbld_elfmod.pm"; 103975ce41a5SAli Bahramirequire "$moddir/onbld_elfmod.pm"; 104075ce41a5SAli Bahrami 104175ce41a5SAli Bahrami# Determine what machinery is available. 104275ce41a5SAli Bahramimy $Mach = `uname -p`; 104375ce41a5SAli Bahramimy$Isalist = `isalist`; 104475ce41a5SAli Bahramiif ($Mach =~ /sparc/) { 104575ce41a5SAli Bahrami if ($Isalist =~ /sparcv9/) { 104675ce41a5SAli Bahrami $Ena64 = "ok"; 104775ce41a5SAli Bahrami } 104875ce41a5SAli Bahrami} elsif ($Mach =~ /i386/) { 104975ce41a5SAli Bahrami if ($Isalist =~ /amd64/) { 105075ce41a5SAli Bahrami $Ena64 = "ok"; 10514840e086Srie } 10524840e086Srie} 10534840e086Srie 105475ce41a5SAli Bahrami# $Env is used with all calls to ldd. It is set by AltObjectConfig to 105575ce41a5SAli Bahrami# cause an alternate object mapping runtime config file to be used. 105675ce41a5SAli Bahrami$Env = ''; 10577c478bd9Sstevel@tonic-gate 105875ce41a5SAli Bahrami# Check that we have arguments. 105975ce41a5SAli Bahramiif ((getopts('D:d:E:e:f:I:imosvw:', \%opt) == 0) || 106075ce41a5SAli Bahrami (!$opt{f} && ($#ARGV == -1))) { 106175ce41a5SAli Bahrami print "usage: $Prog [-imosv] [-D depfile | -d depdir] [-E errfile]\n"; 106275ce41a5SAli Bahrami print "\t\t[-e exfile] [-f listfile] [-I infofile] [-w outdir]\n"; 106375ce41a5SAli Bahrami print "\t\t[file | dir]...\n"; 106475ce41a5SAli Bahrami print "\n"; 106575ce41a5SAli Bahrami print "\t[-D depfile]\testablish dependencies from 'find_elf -r' file list\n"; 106675ce41a5SAli Bahrami print "\t[-d depdir]\testablish dependencies from under directory\n"; 106775ce41a5SAli Bahrami print "\t[-E errfile]\tdirect error output to file\n"; 106875ce41a5SAli Bahrami print "\t[-e exfile]\texceptions file\n"; 106975ce41a5SAli Bahrami print "\t[-f listfile]\tuse file list produced by find_elf -r\n"; 107075ce41a5SAli Bahrami print "\t[-I infofile]\tdirect informational output (-i, -v) to file\n"; 107175ce41a5SAli Bahrami print "\t[-i]\t\tproduce dynamic table entry information\n"; 107275ce41a5SAli Bahrami print "\t[-m]\t\tprocess mcs(1) comments\n"; 107375ce41a5SAli Bahrami print "\t[-o]\t\tproduce one-liner output (prefixed with pathname)\n"; 107475ce41a5SAli Bahrami print "\t[-s]\t\tprocess .stab and .symtab entries\n"; 107575ce41a5SAli Bahrami print "\t[-v]\t\tprocess version definition entries\n"; 107675ce41a5SAli Bahrami print "\t[-w outdir]\tinterpret all files relative to given directory\n"; 107775ce41a5SAli Bahrami exit 1; 107875ce41a5SAli Bahrami} 107975ce41a5SAli Bahrami 108075ce41a5SAli Bahramidie "$Prog: -D and -d options are mutually exclusive\n" if ($opt{D} && $opt{d}); 108175ce41a5SAli Bahrami 108275ce41a5SAli Bahrami$Tmpdir = "/tmp" if (!($Tmpdir = $ENV{TMPDIR}) || (! -d $Tmpdir)); 108375ce41a5SAli Bahrami 108475ce41a5SAli Bahrami# Determine whether this is a __GNUC build. If so, unused search path 108575ce41a5SAli Bahrami# processing is disabled. 108675ce41a5SAli Bahrami$Gnuc = defined $ENV{__GNUC} ? 1 : 0; 108775ce41a5SAli Bahrami 108875ce41a5SAli Bahrami# If -w, change working directory to given location 108975ce41a5SAli Bahrami!$opt{w} || chdir($opt{w}) || die "$Prog: can't cd to $opt{w}"; 109075ce41a5SAli Bahrami 109175ce41a5SAli Bahrami# Locate and process the exceptions file 109275ce41a5SAli Bahramionbld_elfmod::LoadExceptionsToEXRE('check_rtime'); 109375ce41a5SAli Bahrami 109475ce41a5SAli Bahrami# Is there a proto area available, either via the -d option, or because 109575ce41a5SAli Bahrami# we are part of an activated workspace? 109675ce41a5SAli Bahramimy $Proto; 109775ce41a5SAli Bahramiif ($opt{d}) { 109875ce41a5SAli Bahrami # User specified dependency directory - make sure it exists. 109975ce41a5SAli Bahrami -d $opt{d} || die "$Prog: $opt{d} is not a directory\n"; 110075ce41a5SAli Bahrami $Proto = $opt{d}; 110175ce41a5SAli Bahrami} elsif ($ENV{CODEMGR_WS}) { 110275ce41a5SAli Bahrami my $Root; 110375ce41a5SAli Bahrami 110475ce41a5SAli Bahrami # Without a user specified dependency directory see if we're 110575ce41a5SAli Bahrami # part of a codemanager workspace and if a proto area exists. 110675ce41a5SAli Bahrami $Proto = $Root if ($Root = $ENV{ROOT}) && (-d $Root); 110775ce41a5SAli Bahrami} 110875ce41a5SAli Bahrami 110975ce41a5SAli Bahrami# If we are basing this analysis off the sharable objects found in 111075ce41a5SAli Bahrami# a proto area, then gather dependencies and construct an alternative 111175ce41a5SAli Bahrami# dependency mapping via a crle(1) configuration file. 111275ce41a5SAli Bahrami# 111375ce41a5SAli Bahrami# To support alternative dependency mapping we'll need ldd(1)'s 111475ce41a5SAli Bahrami# -e option. This is relatively new (s81_30), so make sure 111575ce41a5SAli Bahrami# ldd(1) is capable before gathering any dependency information. 111675ce41a5SAli Bahramiif ($opt{D} || $Proto) { 111775ce41a5SAli Bahrami if (system('ldd -e /usr/lib/lddstub 2> /dev/null')) { 111875ce41a5SAli Bahrami print "ldd: does not support -e, unable to "; 111975ce41a5SAli Bahrami print "create alternative dependency mappingings.\n"; 112075ce41a5SAli Bahrami print "ldd: option added under 4390308 (s81_30).\n\n"; 11217c478bd9Sstevel@tonic-gate } else { 112275ce41a5SAli Bahrami # If -D was specified, it supplies a list of files in 112375ce41a5SAli Bahrami # 'find_elf -r' format, and can use it directly. Otherwise, 112475ce41a5SAli Bahrami # we will run find_elf as a child process to find the 112575ce41a5SAli Bahrami # sharable objects found under $Proto. 112675ce41a5SAli Bahrami AltObjectConfig($opt{D} ? $opt{D} : "find_elf -frs $Proto|"); 11277c478bd9Sstevel@tonic-gate } 11287c478bd9Sstevel@tonic-gate} 11297c478bd9Sstevel@tonic-gate 113075ce41a5SAli Bahrami# To support unreferenced dependency detection we'll need ldd(1)'s -U 113175ce41a5SAli Bahrami# option. This is relatively new (4638070), and if not available we 113275ce41a5SAli Bahrami# can still fall back to -u. Even with this option, don't use -U with 113375ce41a5SAli Bahrami# releases prior to 5.10 as the cleanup for -U use only got integrated 113475ce41a5SAli Bahrami# into 5.10 under 4642023. Note, that nightly doesn't typically set a 113575ce41a5SAli Bahrami# RELEASE from the standard <env> files. Users who wish to disable use 113675ce41a5SAli Bahrami# of ldd(1)'s -U should set (or uncomment) RELEASE in their <env> file 113775ce41a5SAli Bahrami# if using nightly, or otherwise establish it in their environment. 113875ce41a5SAli Bahramiif (system('ldd -U /usr/lib/lddstub 2> /dev/null')) { 113975ce41a5SAli Bahrami $LddNoU = 1; 114075ce41a5SAli Bahrami} else { 114175ce41a5SAli Bahrami my($Release); 114275ce41a5SAli Bahrami 114375ce41a5SAli Bahrami if (($Release = $ENV{RELEASE}) && (cmp_os_ver($Release, "<", "5.10"))) { 114475ce41a5SAli Bahrami $LddNoU = 1; 114575ce41a5SAli Bahrami } else { 114675ce41a5SAli Bahrami $LddNoU = 0; 114775ce41a5SAli Bahrami } 11487c478bd9Sstevel@tonic-gate} 11497c478bd9Sstevel@tonic-gate 115075ce41a5SAli Bahrami# Set up variables used to handle output files: 115175ce41a5SAli Bahrami# 115275ce41a5SAli Bahrami# Error messages go to stdout unless -E is specified. $ErrFH is a 115375ce41a5SAli Bahrami# file handle reference that points at the file handle where error messages 115475ce41a5SAli Bahrami# are sent, and $ErrTtl is a reference that points at an integer used 115575ce41a5SAli Bahrami# to count how many lines have been sent there. 115675ce41a5SAli Bahrami# 115775ce41a5SAli Bahrami# Informational messages go to stdout unless -I is specified. $InfoFH is a 115875ce41a5SAli Bahrami# file handle reference that points at the file handle where info messages 115975ce41a5SAli Bahrami# are sent, and $InfoTtl is a reference that points at an integer used 116075ce41a5SAli Bahrami# to count how many lines have been sent there. 116175ce41a5SAli Bahrami# 116275ce41a5SAli Bahramiif ($opt{E}) { 116375ce41a5SAli Bahrami open(ERROR, ">$opt{E}") || die "$Prog: open failed: $opt{E}"; 116475ce41a5SAli Bahrami $ErrFH = \*ERROR; 116575ce41a5SAli Bahrami} else { 116675ce41a5SAli Bahrami $ErrFH = \*STDOUT; 11677c478bd9Sstevel@tonic-gate} 116875ce41a5SAli Bahrami 116975ce41a5SAli Bahramiif ($opt{I}) { 117075ce41a5SAli Bahrami open(INFO, ">$opt{I}") || die "$Prog: open failed: $opt{I}"; 117175ce41a5SAli Bahrami $InfoFH = \*INFO; 117275ce41a5SAli Bahrami} else { 117375ce41a5SAli Bahrami $InfoFH = \*STDOUT; 11747c478bd9Sstevel@tonic-gate} 117575ce41a5SAli Bahramimy ($err_dev, $err_ino) = stat($ErrFH); 117675ce41a5SAli Bahramimy ($info_dev, $info_ino) = stat($InfoFH); 117775ce41a5SAli Bahrami$ErrTtl = \$OutCnt1; 117875ce41a5SAli Bahrami$InfoTtl = (($err_dev == $info_dev) && ($err_ino == $info_ino)) ? 117975ce41a5SAli Bahrami \$OutCnt1 : \$OutCnt2; 118075ce41a5SAli Bahrami 118175ce41a5SAli Bahrami 118275ce41a5SAli Bahrami# If we were given a list of objects in 'find_elf -r' format, then 118375ce41a5SAli Bahrami# process it. 118475ce41a5SAli BahramiProcFindElf($opt{f}) if $opt{f}; 118575ce41a5SAli Bahrami 118675ce41a5SAli Bahrami# Process each argument 118775ce41a5SAli Bahramiforeach my $Arg (@ARGV) { 118875ce41a5SAli Bahrami # Run find_elf to find the files given by $Arg and process them 118975ce41a5SAli Bahrami ProcFindElf("find_elf -fr $Arg|"); 11907c478bd9Sstevel@tonic-gate} 119175ce41a5SAli Bahrami 119275ce41a5SAli Bahrami# Cleanup output files 119375ce41a5SAli Bahramiunlink $Conf64 if $Conf64; 119475ce41a5SAli Bahramiunlink $Conf32 if $Conf32; 119575ce41a5SAli Bahramiclose ERROR if $opt{E}; 119675ce41a5SAli Bahramiclose INFO if $opt{I}; 119775ce41a5SAli Bahrami 119875ce41a5SAli Bahramiexit 0; 1199