xref: /titanic_52/usr/src/cmd/sgs/lari/lari.pl (revision 7010c12ad3ac2cada55cf126121a8c46957d3632)
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
6c1c6f601Srie# Common Development and Distribution License (the "License").
7c1c6f601Srie# 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#
22c1c6f601Srie
237c478bd9Sstevel@tonic-gate#
24c1c6f601Srie# 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#
297c478bd9Sstevel@tonic-gate# Link Analysis of Runtime Interfaces.
307c478bd9Sstevel@tonic-gate#
317c478bd9Sstevel@tonic-gate
327c478bd9Sstevel@tonic-gate# Define all global variables (required for strict)
337c478bd9Sstevel@tonic-gateuse vars  qw($Prog $DestDir $ObjRef $ObjFlag $ObjSize $TmpDir $LddArgs);
347c478bd9Sstevel@tonic-gateuse vars  qw($Glob $Intp $Cpyr $Prot $Extn $Self $Filt $Dirc $Plta $User $Func);
357c478bd9Sstevel@tonic-gateuse vars  qw($Objt $UndefSym $IgnSyms $Rtld $MultSyms $CrtSyms $GlobWeak);
367c478bd9Sstevel@tonic-gateuse vars  qw($DbgSeed %opt %Symbols %Objects %Versioned %DemSyms);
377c478bd9Sstevel@tonic-gateuse vars  qw($Platform $Nodi $Osft $Oaft $Ssft $Saft $Msft);
387c478bd9Sstevel@tonic-gate
397c478bd9Sstevel@tonic-gateuse strict;
407c478bd9Sstevel@tonic-gate
417c478bd9Sstevel@tonic-gateuse Getopt::Std;
427c478bd9Sstevel@tonic-gateuse File::Basename;
437c478bd9Sstevel@tonic-gate
447c478bd9Sstevel@tonic-gate# Pattern match to skip objects.
45*7010c12aSrie$Rtld = qr{
467c478bd9Sstevel@tonic-gate	/lib/ld\.so\.1 |
477c478bd9Sstevel@tonic-gate	/usr/lib/ld\.so\.1 |
487c478bd9Sstevel@tonic-gate	/lib/sparcv9/ld\.so\.1 |
49c1c6f601Srie	/usr/lib/sparcv9/ld\.so\.1 |
50c1c6f601Srie	/lib/amd64/ld\.so\.1 |
51c1c6f601Srie	/usr/lib/amd64/ld\.so\.1
527c478bd9Sstevel@tonic-gate}x;
537c478bd9Sstevel@tonic-gate
547c478bd9Sstevel@tonic-gate# Pattern matching required to determine a global symbol.
557c478bd9Sstevel@tonic-gate$GlobWeak = qr{ ^(?:
567c478bd9Sstevel@tonic-gate	GLOB |
577c478bd9Sstevel@tonic-gate	WEAK
587c478bd9Sstevel@tonic-gate	)$
597c478bd9Sstevel@tonic-gate}x;
607c478bd9Sstevel@tonic-gate
617c478bd9Sstevel@tonic-gate# Pattern matching to determine link-editor specific symbols and those common
627c478bd9Sstevel@tonic-gate# to the compilation environment (ie. provided by all crt's).
637c478bd9Sstevel@tonic-gate$MultSyms = qr{ ^(?:
647c478bd9Sstevel@tonic-gate	 _DYNAMIC |
657c478bd9Sstevel@tonic-gate	 _GLOBAL_OFFSET_TABLE_ |
667c478bd9Sstevel@tonic-gate	 _PROCEDURE_LINKAGE_TABLE_ |
677c478bd9Sstevel@tonic-gate	 _etext |
687c478bd9Sstevel@tonic-gate	 _edata |
697c478bd9Sstevel@tonic-gate	 _end |
707c478bd9Sstevel@tonic-gate	 _init |
717c478bd9Sstevel@tonic-gate	 _fini |
727c478bd9Sstevel@tonic-gate	 _lib_version |			# Defined in values
737c478bd9Sstevel@tonic-gate	 __xpg4 |			# Defined in values
747c478bd9Sstevel@tonic-gate	 __xpg6				# Defined in values
757c478bd9Sstevel@tonic-gate	)$
767c478bd9Sstevel@tonic-gate}x;
777c478bd9Sstevel@tonic-gate
787c478bd9Sstevel@tonic-gate$CrtSyms = qr{ ^(?:
797c478bd9Sstevel@tonic-gate	 ___Argv |			# Defined in crt
807c478bd9Sstevel@tonic-gate	 __environ_lock |		# Defined in crt
817c478bd9Sstevel@tonic-gate	 _environ |			# Defined in crt
827c478bd9Sstevel@tonic-gate	 environ			# Defined in crt
837c478bd9Sstevel@tonic-gate	 )$
847c478bd9Sstevel@tonic-gate}x;
857c478bd9Sstevel@tonic-gate
867c478bd9Sstevel@tonic-gate# Pattern match to remove undefined, NOTY and versioning symbols.
877c478bd9Sstevel@tonic-gate$UndefSym = qr{ ^(?:
887c478bd9Sstevel@tonic-gate	UNDEF
897c478bd9Sstevel@tonic-gate	)$
907c478bd9Sstevel@tonic-gate}x;
917c478bd9Sstevel@tonic-gate
927c478bd9Sstevel@tonic-gate$IgnSyms = qr{ ^(?:
937c478bd9Sstevel@tonic-gate	NOTY |
947c478bd9Sstevel@tonic-gate	ABS
957c478bd9Sstevel@tonic-gate	)$
967c478bd9Sstevel@tonic-gate}x;
977c478bd9Sstevel@tonic-gate
987c478bd9Sstevel@tonic-gate# Symbol flags.
997c478bd9Sstevel@tonic-gate$Glob = 0x00001;	# symbol is global
1007c478bd9Sstevel@tonic-gate$Intp = 0x00010;	# symbol originates for explicit interposer
1017c478bd9Sstevel@tonic-gate$Dirc = 0x00020;	# symbol bound to directly
1027c478bd9Sstevel@tonic-gate$Cpyr = 0x00040;	# symbol bound to copy-relocation reference
1037c478bd9Sstevel@tonic-gate$Prot = 0x00080;	# symbol is protected (symbolic)
1047c478bd9Sstevel@tonic-gate$Extn = 0x00100;	# symbol has been bound to from an external reference
1057c478bd9Sstevel@tonic-gate$Self = 0x00200;	# symbol has been bound to from the same object
1067c478bd9Sstevel@tonic-gate$Filt = 0x00400;	# symbol bound to a filtee
1077c478bd9Sstevel@tonic-gate$Plta = 0x00800;	# symbol bound to executables plt address
1087c478bd9Sstevel@tonic-gate$User = 0x01000;	# symbol binding originates from user (dlsym) request
1097c478bd9Sstevel@tonic-gate$Func = 0x02000;	# symbol is of type function
1107c478bd9Sstevel@tonic-gate$Objt = 0x04000;	# symbol is of type object
1117c478bd9Sstevel@tonic-gate$Nodi = 0x08000;	# symbol prohibits direct binding
1127c478bd9Sstevel@tonic-gate
1137c478bd9Sstevel@tonic-gate$Osft = 0x10000;	# symbol is an standard object filter
1147c478bd9Sstevel@tonic-gate$Oaft = 0x20000;	# symbol is an auxiliary object filter
1157c478bd9Sstevel@tonic-gate$Ssft = 0x40000;	# symbol is a per-symbol standard filter
1167c478bd9Sstevel@tonic-gate$Saft = 0x80000;	# symbol is a per-symbol auxilary filter
1177c478bd9Sstevel@tonic-gate$Msft = 0xf0000;	# filter mask
1187c478bd9Sstevel@tonic-gate
1197c478bd9Sstevel@tonic-gate# Offsets into $Symbols{$SymName}{$Obj} array.
1207c478bd9Sstevel@tonic-gate$ObjRef =	0;
1217c478bd9Sstevel@tonic-gate$ObjFlag =	1;
1227c478bd9Sstevel@tonic-gate$ObjSize =	2;
1237c478bd9Sstevel@tonic-gate
1247c478bd9Sstevel@tonic-gate
1257c478bd9Sstevel@tonic-gate# Establish locale
1267c478bd9Sstevel@tonic-gateuse POSIX qw(locale_h);
1277c478bd9Sstevel@tonic-gateuse Sun::Solaris::Utils qw(textdomain gettext);
1287c478bd9Sstevel@tonic-gate
1297c478bd9Sstevel@tonic-gatesetlocale(LC_ALL, "");
1307c478bd9Sstevel@tonic-gatetextdomain("SUNW_OST_SGS");
1317c478bd9Sstevel@tonic-gate
1327c478bd9Sstevel@tonic-gate# Establish a program name for any error diagnostics.
1337c478bd9Sstevel@tonic-gate$Prog = basename($0);
1347c478bd9Sstevel@tonic-gate
1357c478bd9Sstevel@tonic-gatesub inappropriate {
1367c478bd9Sstevel@tonic-gate	my ($Opt1, $Opt2, $Flag) = @_;
1377c478bd9Sstevel@tonic-gate
1387c478bd9Sstevel@tonic-gate	if ($Flag) {
1397c478bd9Sstevel@tonic-gate	    printf STDERR
1407c478bd9Sstevel@tonic-gate		gettext("%s: inappropriate use of %s with %s: %s ignored\n"),
1417c478bd9Sstevel@tonic-gate		$Prog, $Opt1, $Opt2, $Opt1;
1427c478bd9Sstevel@tonic-gate	} else {
1437c478bd9Sstevel@tonic-gate	    printf STDERR
1447c478bd9Sstevel@tonic-gate		gettext("%s: inappropriate use of %s without %s: %s ignored\n"),
1457c478bd9Sstevel@tonic-gate		$Prog, $Opt1, $Opt2, $Opt1;
1467c478bd9Sstevel@tonic-gate	}
1477c478bd9Sstevel@tonic-gate}
1487c478bd9Sstevel@tonic-gate
1497c478bd9Sstevel@tonic-gate# Cleanup any temporary files on interruption
1507c478bd9Sstevel@tonic-gatesub Cleanup {
1517c478bd9Sstevel@tonic-gate	my ($Sig) = @_;
1527c478bd9Sstevel@tonic-gate
1537c478bd9Sstevel@tonic-gate	$SIG{$Sig} = 'IGNORE';
1547c478bd9Sstevel@tonic-gate
1557c478bd9Sstevel@tonic-gate	if ($DbgSeed ne "") {
1567c478bd9Sstevel@tonic-gate		foreach my $File (<\Q${DbgSeed}\E.*>) {
1577c478bd9Sstevel@tonic-gate			if ($File =~ /^\Q$DbgSeed\E\.\d+$/) {
1587c478bd9Sstevel@tonic-gate				unlink($File);
1597c478bd9Sstevel@tonic-gate			}
1607c478bd9Sstevel@tonic-gate		}
1617c478bd9Sstevel@tonic-gate	}
1627c478bd9Sstevel@tonic-gate	exit 1;
1637c478bd9Sstevel@tonic-gate}
1647c478bd9Sstevel@tonic-gate
1657c478bd9Sstevel@tonic-gate# Check that we have arguments.
1667c478bd9Sstevel@tonic-gateif ((getopts('abCDd:imosv', \%opt) == 0) || ($#ARGV < 0)) {
1677c478bd9Sstevel@tonic-gate	printf STDERR gettext("usage:\n");
1687c478bd9Sstevel@tonic-gate	printf STDERR
1697c478bd9Sstevel@tonic-gate	    gettext("    %s [-bCDsv] [-a | -i | -o ] file | dir ...\n"), $Prog;
1707c478bd9Sstevel@tonic-gate	printf STDERR
1717c478bd9Sstevel@tonic-gate	    gettext("    %s [-CDosv] [-m [-d mapdir]] file\n"), $Prog;
1727c478bd9Sstevel@tonic-gate	print STDERR
1737c478bd9Sstevel@tonic-gate	    gettext("\t[-a]     print diagnostics for all symbols\n");
1747c478bd9Sstevel@tonic-gate	print STDERR
1757c478bd9Sstevel@tonic-gate	    gettext("\t[-b]     print diagnostics for multiple-bound " .
1767c478bd9Sstevel@tonic-gate		"symbols\n");
1777c478bd9Sstevel@tonic-gate	print STDERR
1787c478bd9Sstevel@tonic-gate	    gettext("\t[-C]     print demangled symbol names also\n");
1797c478bd9Sstevel@tonic-gate	print STDERR
1807c478bd9Sstevel@tonic-gate	    gettext("\t[-D]     read debugging information from \"file\"\n");
1817c478bd9Sstevel@tonic-gate	print STDERR
1827c478bd9Sstevel@tonic-gate	    gettext("\t[-d dir] create mapfiles in \"mapdir\"\n");
1837c478bd9Sstevel@tonic-gate	print STDERR
1847c478bd9Sstevel@tonic-gate	    gettext("\t[-i]     print interesting information (default)\n");
1857c478bd9Sstevel@tonic-gate	print STDERR
1867c478bd9Sstevel@tonic-gate	    gettext("\t[-m]     create mapfiles for interface requirements\n");
1877c478bd9Sstevel@tonic-gate	print STDERR
1887c478bd9Sstevel@tonic-gate	    gettext("\t[-o]     print overhead information\n");
1897c478bd9Sstevel@tonic-gate	print STDERR
1907c478bd9Sstevel@tonic-gate	    gettext("\t[-s]     save bindings information created by ldd(1)\n");
1917c478bd9Sstevel@tonic-gate	print STDERR
1927c478bd9Sstevel@tonic-gate	    gettext("\t[-v]     ignore versioned objects\n");
1937c478bd9Sstevel@tonic-gate	exit 1;
1947c478bd9Sstevel@tonic-gate} else {
1957c478bd9Sstevel@tonic-gate	my ($Mult, $Error);
1967c478bd9Sstevel@tonic-gate
1977c478bd9Sstevel@tonic-gate	# Catch any incompatible argument usage.
1987c478bd9Sstevel@tonic-gate	if ($opt{m}) {
1997c478bd9Sstevel@tonic-gate		if ($opt{a}) {
2007c478bd9Sstevel@tonic-gate			inappropriate("-a", "-m", 1);
2017c478bd9Sstevel@tonic-gate			$opt{a} = 0;
2027c478bd9Sstevel@tonic-gate		}
2037c478bd9Sstevel@tonic-gate		if ($opt{i}) {
2047c478bd9Sstevel@tonic-gate			inappropriate("-i", "-m", 1);
2057c478bd9Sstevel@tonic-gate			$opt{i} = 0;
2067c478bd9Sstevel@tonic-gate		}
2077c478bd9Sstevel@tonic-gate	} else {
2087c478bd9Sstevel@tonic-gate		if ($opt{d}) {
2097c478bd9Sstevel@tonic-gate			inappropriate("-d", "-m", 0);
2107c478bd9Sstevel@tonic-gate			$opt{d} = 0;
2117c478bd9Sstevel@tonic-gate		}
2127c478bd9Sstevel@tonic-gate	}
2137c478bd9Sstevel@tonic-gate	if ($opt{a}) {
2147c478bd9Sstevel@tonic-gate		if ($opt{o}) {
2157c478bd9Sstevel@tonic-gate			inappropriate("-a", "-o", 1);
2167c478bd9Sstevel@tonic-gate			$opt{o} = 0;
2177c478bd9Sstevel@tonic-gate		}
2187c478bd9Sstevel@tonic-gate		if ($opt{i}) {
2197c478bd9Sstevel@tonic-gate			inappropriate("-a", "-i", 1);
2207c478bd9Sstevel@tonic-gate			$opt{i} = 0;
2217c478bd9Sstevel@tonic-gate		}
2227c478bd9Sstevel@tonic-gate	}
223*7010c12aSrie	if ($opt{o}) {
224*7010c12aSrie		if ($opt{i}) {
2257c478bd9Sstevel@tonic-gate			inappropriate("-o", "-i", 1);
2267c478bd9Sstevel@tonic-gate			$opt{i} = 0;
2277c478bd9Sstevel@tonic-gate		}
228*7010c12aSrie		if ($opt{b}) {
229*7010c12aSrie			inappropriate("-o", "-b", 1);
230*7010c12aSrie			$opt{b} = 0;
231*7010c12aSrie		}
232*7010c12aSrie	}
2337c478bd9Sstevel@tonic-gate
2347c478bd9Sstevel@tonic-gate	# If -m is used, only one input file is applicable.
2357c478bd9Sstevel@tonic-gate	if ($opt{m} && ($#ARGV != 0)) {
2367c478bd9Sstevel@tonic-gate		printf STDERR gettext("%s: only one input file is allowed " .
2377c478bd9Sstevel@tonic-gate		    "with the -m option\n"), $Prog;
2387c478bd9Sstevel@tonic-gate		exit 1;
2397c478bd9Sstevel@tonic-gate	}
2407c478bd9Sstevel@tonic-gate
2417c478bd9Sstevel@tonic-gate	# Insure any specified directory exists, or apply a default.
2427c478bd9Sstevel@tonic-gate	if ($opt{d}) {
2437c478bd9Sstevel@tonic-gate		# User specified directory - make sure it exists.
2447c478bd9Sstevel@tonic-gate		if (! -d $opt{d}) {
2457c478bd9Sstevel@tonic-gate			printf STDERR gettext("%s: %s is not a directory\n"),
2467c478bd9Sstevel@tonic-gate			    $Prog, $opt{d};
2477c478bd9Sstevel@tonic-gate			exit 1;
2487c478bd9Sstevel@tonic-gate		}
2497c478bd9Sstevel@tonic-gate		$DestDir = $opt{d};
2507c478bd9Sstevel@tonic-gate	} else {
2517c478bd9Sstevel@tonic-gate		$DestDir = ".";
2527c478bd9Sstevel@tonic-gate	}
2537c478bd9Sstevel@tonic-gate
2547c478bd9Sstevel@tonic-gate	# Establish a temporary directory if necessary.
2557c478bd9Sstevel@tonic-gate	if (!$opt{D}) {
2567c478bd9Sstevel@tonic-gate		if (!($TmpDir = $ENV{TMPDIR}) || (! -d $TmpDir)) {
2577c478bd9Sstevel@tonic-gate			$TmpDir = "/tmp";
2587c478bd9Sstevel@tonic-gate		}
2597c478bd9Sstevel@tonic-gate	}
2607c478bd9Sstevel@tonic-gate
2617c478bd9Sstevel@tonic-gate	# Establish any initial ldd(1) argument requirements.
2627c478bd9Sstevel@tonic-gate	if ($LddArgs = $ENV{LARI_LDD_ARGS}) {
2637c478bd9Sstevel@tonic-gate		$LddArgs = $LddArgs . ' -r -e LD_DEBUG=bindings,files,detail';
2647c478bd9Sstevel@tonic-gate	} else {
2657c478bd9Sstevel@tonic-gate		$LddArgs = '-r -e LD_DEBUG=bindings,files,detail';
2667c478bd9Sstevel@tonic-gate	}
2677c478bd9Sstevel@tonic-gate
2687c478bd9Sstevel@tonic-gate	# If we've been asked to demangle symbols, make sure we can find the
2697c478bd9Sstevel@tonic-gate	# demangler.
2707c478bd9Sstevel@tonic-gate	if ($opt{C}) {
2717c478bd9Sstevel@tonic-gate		my ($DemName) = `dem XXXX 2> /dev/null`;
2727c478bd9Sstevel@tonic-gate		if (!$DemName) {
2737c478bd9Sstevel@tonic-gate			printf STDERR gettext("%s: can not locate demangler: " .
2747c478bd9Sstevel@tonic-gate			    "-C ignored\n"), $Prog;
2757c478bd9Sstevel@tonic-gate			$opt{C} = 0;
2767c478bd9Sstevel@tonic-gate		}
2777c478bd9Sstevel@tonic-gate	}
2787c478bd9Sstevel@tonic-gate
2797c478bd9Sstevel@tonic-gate	# If -a or -o hasn't been specified, default to -i.
2807c478bd9Sstevel@tonic-gate	if (!$opt{a} && !$opt{o}) {
2817c478bd9Sstevel@tonic-gate		$opt{i} = 1;
2827c478bd9Sstevel@tonic-gate	}
2837c478bd9Sstevel@tonic-gate
284*7010c12aSrie	# Determine whether we have multiple input files.
2857c478bd9Sstevel@tonic-gate	if ($#ARGV == 0) {
2867c478bd9Sstevel@tonic-gate		$Mult = 0;
2877c478bd9Sstevel@tonic-gate	} else {
2887c478bd9Sstevel@tonic-gate		$Mult = 1;
2897c478bd9Sstevel@tonic-gate	}
2907c478bd9Sstevel@tonic-gate
2917c478bd9Sstevel@tonic-gate	# Determine what platform we're running on - some inappropriate
2927c478bd9Sstevel@tonic-gate	# platform specific dependencies are better skipped.
2937c478bd9Sstevel@tonic-gate	chomp($Platform = `uname -i`);
2947c478bd9Sstevel@tonic-gate
2957c478bd9Sstevel@tonic-gate	# Establish signal handlers
2967c478bd9Sstevel@tonic-gate	$SIG{INT} = \&Cleanup;
2977c478bd9Sstevel@tonic-gate	$SIG{QUIT} = \&Cleanup;
2987c478bd9Sstevel@tonic-gate
2997c478bd9Sstevel@tonic-gate	$DbgSeed = "";
3007c478bd9Sstevel@tonic-gate
3017c478bd9Sstevel@tonic-gate	# For each argument determine if we're dealing with a file or directory.
3027c478bd9Sstevel@tonic-gate	$Error = 0;
3037c478bd9Sstevel@tonic-gate	foreach my $Arg (@ARGV) {
3047c478bd9Sstevel@tonic-gate		if (!stat($Arg)) {
3057c478bd9Sstevel@tonic-gate			printf STDERR gettext("%s: %s: unable to stat file\n"),
3067c478bd9Sstevel@tonic-gate			    $Prog, $Arg;
3077c478bd9Sstevel@tonic-gate			$Error = 1;
3087c478bd9Sstevel@tonic-gate			next;
3097c478bd9Sstevel@tonic-gate		}
3107c478bd9Sstevel@tonic-gate
3117c478bd9Sstevel@tonic-gate		# Process simple files.
3127c478bd9Sstevel@tonic-gate		if (-f _) {
3137c478bd9Sstevel@tonic-gate			if (!-r _) {
3147c478bd9Sstevel@tonic-gate				printf STDERR gettext("%s: %s: unable to " .
3157c478bd9Sstevel@tonic-gate				   "read file\n"), $Prog, $Arg;
3167c478bd9Sstevel@tonic-gate				$Error = 1;
3177c478bd9Sstevel@tonic-gate				next;
3187c478bd9Sstevel@tonic-gate			}
3197c478bd9Sstevel@tonic-gate			if (!$opt{D}) {
3207c478bd9Sstevel@tonic-gate				if (ProcFile($Arg, $Mult, 1) == 0) {
3217c478bd9Sstevel@tonic-gate					$Error = 1;
3227c478bd9Sstevel@tonic-gate				}
3237c478bd9Sstevel@tonic-gate			} else {
3247c478bd9Sstevel@tonic-gate				# If the -D option is specified, read the
3257c478bd9Sstevel@tonic-gate				# bindings debugging information from the
3267c478bd9Sstevel@tonic-gate				# specified file.
3277c478bd9Sstevel@tonic-gate				if ($Mult) {
3287c478bd9Sstevel@tonic-gate					print STDOUT "$Arg:\n";
3297c478bd9Sstevel@tonic-gate				}
3307c478bd9Sstevel@tonic-gate				ProcBindings($Arg, $Mult, $Arg);
3317c478bd9Sstevel@tonic-gate			}
3327c478bd9Sstevel@tonic-gate			next;
3337c478bd9Sstevel@tonic-gate		}
3347c478bd9Sstevel@tonic-gate
3357c478bd9Sstevel@tonic-gate		# Process directories.
3367c478bd9Sstevel@tonic-gate		if (-d _) {
3377c478bd9Sstevel@tonic-gate			ProcDir($Arg);
3387c478bd9Sstevel@tonic-gate			next;
3397c478bd9Sstevel@tonic-gate		}
3407c478bd9Sstevel@tonic-gate
3417c478bd9Sstevel@tonic-gate		printf STDERR gettext("%s: %s: is not a file or directory\n"),
3427c478bd9Sstevel@tonic-gate		    $Prog, $Arg;
3437c478bd9Sstevel@tonic-gate		$Error = 1;
3447c478bd9Sstevel@tonic-gate	}
3457c478bd9Sstevel@tonic-gate	exit $Error;
3467c478bd9Sstevel@tonic-gate}
3477c478bd9Sstevel@tonic-gate
3487c478bd9Sstevel@tonic-gatesub ProcDir {
3497c478bd9Sstevel@tonic-gate	my ($Dir) = @_;
3507c478bd9Sstevel@tonic-gate	my ($File);
3517c478bd9Sstevel@tonic-gate
3527c478bd9Sstevel@tonic-gate	# Open the directory and read each entry, omit "." and "..".  Sorting
3537c478bd9Sstevel@tonic-gate	# the directory listing makes analyzing different source hierarchies
3547c478bd9Sstevel@tonic-gate	# easier.
3557c478bd9Sstevel@tonic-gate	if (opendir(DIR, $Dir)) {
3567c478bd9Sstevel@tonic-gate		foreach my $Entry (sort(readdir(DIR))) {
3577c478bd9Sstevel@tonic-gate			if (($Entry eq '.') || ($Entry eq '..')) {
3587c478bd9Sstevel@tonic-gate				next;
3597c478bd9Sstevel@tonic-gate			}
3607c478bd9Sstevel@tonic-gate
3617c478bd9Sstevel@tonic-gate			# If we're decending into a platform directory, ignore
3627c478bd9Sstevel@tonic-gate			# any inappropriate platform specific files.  These
3637c478bd9Sstevel@tonic-gate			# files can have dependencies that in turn bring in the
3647c478bd9Sstevel@tonic-gate			# appropriate platform specific file, resulting in more
3657c478bd9Sstevel@tonic-gate			# than one dependency offering the same interfaces.  In
3667c478bd9Sstevel@tonic-gate			# practice, the non-appropriate platform specific file
3677c478bd9Sstevel@tonic-gate			# wouldn't be loaded with a process.
3687c478bd9Sstevel@tonic-gate			if (($Dir =~ /\/platform$/) &&
3697c478bd9Sstevel@tonic-gate			    ($Entry !~ /^$Platform$/)) {
3707c478bd9Sstevel@tonic-gate				next;
3717c478bd9Sstevel@tonic-gate			}
3727c478bd9Sstevel@tonic-gate
3737c478bd9Sstevel@tonic-gate			$File = "$Dir/$Entry";
3747c478bd9Sstevel@tonic-gate			if (!lstat($File)) {
3757c478bd9Sstevel@tonic-gate				next;
3767c478bd9Sstevel@tonic-gate			}
3777c478bd9Sstevel@tonic-gate			# Ignore symlinks.
3787c478bd9Sstevel@tonic-gate			if (-l _) {
3797c478bd9Sstevel@tonic-gate				next;
3807c478bd9Sstevel@tonic-gate			}
3817c478bd9Sstevel@tonic-gate
3827c478bd9Sstevel@tonic-gate			# Descend into, and process any directories.
3837c478bd9Sstevel@tonic-gate			if (-d _) {
3847c478bd9Sstevel@tonic-gate				ProcDir($File);
3857c478bd9Sstevel@tonic-gate				next;
3867c478bd9Sstevel@tonic-gate			}
3877c478bd9Sstevel@tonic-gate
3887c478bd9Sstevel@tonic-gate			# Process any standard files.
3897c478bd9Sstevel@tonic-gate			if (-f _ && -r _) {
3907c478bd9Sstevel@tonic-gate				ProcFile($File, 1, 0);
3917c478bd9Sstevel@tonic-gate				next;
3927c478bd9Sstevel@tonic-gate
3937c478bd9Sstevel@tonic-gate			}
3947c478bd9Sstevel@tonic-gate		}
3957c478bd9Sstevel@tonic-gate		closedir(DIR);
3967c478bd9Sstevel@tonic-gate	}
3977c478bd9Sstevel@tonic-gate}
3987c478bd9Sstevel@tonic-gate
3997c478bd9Sstevel@tonic-gate# Process a file.  If the file was explicitly defined on the command-line, and
4007c478bd9Sstevel@tonic-gate# an error occurs, tell the user.  Otherwise, this file probably came about from
4017c478bd9Sstevel@tonic-gate# scanning a directory, in which case just skip it and move on.
4027c478bd9Sstevel@tonic-gatesub ProcFile {
4037c478bd9Sstevel@tonic-gate	my ($File, $Mult, $CmdLine) = @_;
4047c478bd9Sstevel@tonic-gate	my (@Ldd, $NoFound, $DbgFile, @DbgGlob, $Type);
4057c478bd9Sstevel@tonic-gate
406*7010c12aSrie	# If we're scanning a directory (ie. /lib) and have picked up ld.so.1,
407*7010c12aSrie	# ignore it.
408*7010c12aSrie	if (($CmdLine eq 0) && ($File =~ $Rtld)) {
409*7010c12aSrie		return 1;
410*7010c12aSrie	}
411*7010c12aSrie
4127c478bd9Sstevel@tonic-gate	$Type = `LC_ALL=C file '$File' 2>&1`;
4137c478bd9Sstevel@tonic-gate	if (($Type !~ /dynamically linked/) || ($Type =~ /Sun demand paged/)) {
4147c478bd9Sstevel@tonic-gate		if ($CmdLine) {
4157c478bd9Sstevel@tonic-gate			printf STDERR gettext("%s: %s: is an invalid file " .
4167c478bd9Sstevel@tonic-gate			    "type\n"), $Prog, $File;
4177c478bd9Sstevel@tonic-gate		}
4187c478bd9Sstevel@tonic-gate		return 0;
4197c478bd9Sstevel@tonic-gate	}
4207c478bd9Sstevel@tonic-gate
4217c478bd9Sstevel@tonic-gate	# Create a temporary filename for capturing binding information.
4227c478bd9Sstevel@tonic-gate	$DbgSeed = basename($File);
4237c478bd9Sstevel@tonic-gate	$DbgSeed = "$TmpDir/lari.dbg.$$.$DbgSeed";
4247c478bd9Sstevel@tonic-gate
4257c478bd9Sstevel@tonic-gate	# Exercise the file under ldd(1), capturing all the bindings.
4267c478bd9Sstevel@tonic-gate	@Ldd = split(/\n/,
4277c478bd9Sstevel@tonic-gate	    `LC_ALL=C ldd $LddArgs -e LD_DEBUG_OUTPUT='$DbgSeed' '$File' 2>&1`);
4287c478bd9Sstevel@tonic-gate
4297c478bd9Sstevel@tonic-gate	# If ldd isn't -e capable we'll get a usage message.  The -e option was
4307c478bd9Sstevel@tonic-gate	# introduced in Solaris 9 and related patches.  Also, make sure the user
4317c478bd9Sstevel@tonic-gate	# sees any ldd errors.
4327c478bd9Sstevel@tonic-gate	$NoFound = 0;
4337c478bd9Sstevel@tonic-gate	for my $Line (@Ldd) {
4347c478bd9Sstevel@tonic-gate		if ($Line =~ /^usage: ldd/) {
4357c478bd9Sstevel@tonic-gate			printf STDERR gettext("%s: ldd: does not support -e, " .
4367c478bd9Sstevel@tonic-gate			    "unable to capture bindings output\n"), $Prog;
4377c478bd9Sstevel@tonic-gate			exit 1;
4387c478bd9Sstevel@tonic-gate		}
4397c478bd9Sstevel@tonic-gate		if ($Line =~ /not found/) {
4407c478bd9Sstevel@tonic-gate			$NoFound = 1;
4417c478bd9Sstevel@tonic-gate			last;
4427c478bd9Sstevel@tonic-gate		}
4437c478bd9Sstevel@tonic-gate	}
4447c478bd9Sstevel@tonic-gate
4457c478bd9Sstevel@tonic-gate	# The runtime linker will have appended a process id to the debug file.
4467c478bd9Sstevel@tonic-gate	# As we have to intuit the name, make sure there is only one debug
4477c478bd9Sstevel@tonic-gate	# file match, otherwise there must be some clutter in the output
4487c478bd9Sstevel@tonic-gate	# directory that is going to mess up our analysis.
4497c478bd9Sstevel@tonic-gate	foreach my $Match (<\Q${DbgSeed}\E.*>) {
4507c478bd9Sstevel@tonic-gate		if ($Match =~ /^\Q$DbgSeed\E\.\d+$/) {
4517c478bd9Sstevel@tonic-gate			push(@DbgGlob, $Match);
4527c478bd9Sstevel@tonic-gate		}
4537c478bd9Sstevel@tonic-gate	}
4547c478bd9Sstevel@tonic-gate	if (@DbgGlob == 0) {
4557c478bd9Sstevel@tonic-gate		# If there is no debug file, bail.  This can occur if the file
4567c478bd9Sstevel@tonic-gate		# being processed is secure.
4577c478bd9Sstevel@tonic-gate		if ($CmdLine) {
4587c478bd9Sstevel@tonic-gate			printf STDERR gettext("%s: %s: unable to capture " .
4597c478bd9Sstevel@tonic-gate			    "bindings output - possible secure application?\n"),
4607c478bd9Sstevel@tonic-gate			    $Prog, $File;
4617c478bd9Sstevel@tonic-gate		}
4627c478bd9Sstevel@tonic-gate		return 0;
4637c478bd9Sstevel@tonic-gate	} elsif (@DbgGlob > 1) {
4647c478bd9Sstevel@tonic-gate		# Too many debug files found.
4657c478bd9Sstevel@tonic-gate		if ($CmdLine) {
4667c478bd9Sstevel@tonic-gate			printf STDERR gettext("%s: %s: multiple bindings " .
4677c478bd9Sstevel@tonic-gate			    "output files exist: %s: clean up temporary " .
4687c478bd9Sstevel@tonic-gate			    "directory\n"), $Prog, $File, $DbgSeed;
4697c478bd9Sstevel@tonic-gate		}
4707c478bd9Sstevel@tonic-gate		return 0;
4717c478bd9Sstevel@tonic-gate	} else {
4727c478bd9Sstevel@tonic-gate		$DbgFile = $DbgGlob[0];
4737c478bd9Sstevel@tonic-gate	}
4747c478bd9Sstevel@tonic-gate
4757c478bd9Sstevel@tonic-gate	# Ok, we're ready to process the bindings information.  Print a header
4767c478bd9Sstevel@tonic-gate	# if necessary, and if there were any ldd(1) errors push some of them
4777c478bd9Sstevel@tonic-gate	# out before any bindings information.  Limit the output, as it can
4787c478bd9Sstevel@tonic-gate	# sometimes be excessive.  If there are errors, the bindings information
4797c478bd9Sstevel@tonic-gate	# is likely to be incomplete.
4807c478bd9Sstevel@tonic-gate	if ($Mult) {
4817c478bd9Sstevel@tonic-gate		print STDOUT "$File:\n";
4827c478bd9Sstevel@tonic-gate	}
4837c478bd9Sstevel@tonic-gate	if ($NoFound) {
4847c478bd9Sstevel@tonic-gate		my ($Cnt) = 4;
4857c478bd9Sstevel@tonic-gate
4867c478bd9Sstevel@tonic-gate		for my $Line (@Ldd) {
4877c478bd9Sstevel@tonic-gate			if ($Line =~ /not found/) {
4887c478bd9Sstevel@tonic-gate				print STDOUT "$Line\n";
4897c478bd9Sstevel@tonic-gate				$Cnt--;
4907c478bd9Sstevel@tonic-gate			}
4917c478bd9Sstevel@tonic-gate			if ($Cnt == 0) {
4927c478bd9Sstevel@tonic-gate				print STDOUT gettext("\tcontinued ...\n");
4937c478bd9Sstevel@tonic-gate				last;
4947c478bd9Sstevel@tonic-gate			}
4957c478bd9Sstevel@tonic-gate		}
4967c478bd9Sstevel@tonic-gate	}
4977c478bd9Sstevel@tonic-gate
4987c478bd9Sstevel@tonic-gate	# If the user wants the original debugging file left behind, rename it
4997c478bd9Sstevel@tonic-gate	# so that it doesn't get re-read by another instance of lari processing
5007c478bd9Sstevel@tonic-gate	# this file.
5017c478bd9Sstevel@tonic-gate	if ($opt{s}) {
5027c478bd9Sstevel@tonic-gate		rename($DbgFile, $DbgSeed);
5037c478bd9Sstevel@tonic-gate		$DbgFile = $DbgSeed;
5047c478bd9Sstevel@tonic-gate		printf STDOUT gettext("%s: %s: bindings information " .
5057c478bd9Sstevel@tonic-gate		    "saved as: %s\n"), $Prog, $File, $DbgFile;
5067c478bd9Sstevel@tonic-gate	}
5077c478bd9Sstevel@tonic-gate
5087c478bd9Sstevel@tonic-gate	ProcBindings($File, $Mult, $DbgFile);
5097c478bd9Sstevel@tonic-gate
5107c478bd9Sstevel@tonic-gate	# Now that we've finished with the debugging file, nuke it if necessary.
5117c478bd9Sstevel@tonic-gate	if (!$opt{s}) {
5127c478bd9Sstevel@tonic-gate		unlink($DbgFile);
5137c478bd9Sstevel@tonic-gate	}
5147c478bd9Sstevel@tonic-gate	$DbgSeed = "";
5157c478bd9Sstevel@tonic-gate	return 1;
5167c478bd9Sstevel@tonic-gate}
5177c478bd9Sstevel@tonic-gate
5187c478bd9Sstevel@tonic-gatesub ProcBindings {
5197c478bd9Sstevel@tonic-gate	my ($File, $Mult, $DbgFile) = @_;
5207c478bd9Sstevel@tonic-gate	my (%Filtees, $FileHandle);
5217c478bd9Sstevel@tonic-gate
5227c478bd9Sstevel@tonic-gate	# Reinitialize our arrays when we're dealing with multiple files.
5237c478bd9Sstevel@tonic-gate	if ($Mult) {
5247c478bd9Sstevel@tonic-gate		%Symbols = ();
5257c478bd9Sstevel@tonic-gate		%Objects = ();
5267c478bd9Sstevel@tonic-gate		%Versioned = ();
5277c478bd9Sstevel@tonic-gate	}
5287c478bd9Sstevel@tonic-gate
5297c478bd9Sstevel@tonic-gate	# As debugging output can be significant, read a line at a time.
5307c478bd9Sstevel@tonic-gate	open($FileHandle, "<$DbgFile");
5317c478bd9Sstevel@tonic-gate	while (defined(my $Line = <$FileHandle>)) {
5327c478bd9Sstevel@tonic-gate		chomp($Line);
5337c478bd9Sstevel@tonic-gate
5347c478bd9Sstevel@tonic-gate		# If we find a relationship between a filter and filtee, save
5357c478bd9Sstevel@tonic-gate		# it, we'll come back to this once we've gathered everybodies
5367c478bd9Sstevel@tonic-gate		# symbols.
5377c478bd9Sstevel@tonic-gate		if ($Line =~ /;  filtered by /) {
5387c478bd9Sstevel@tonic-gate			my ($Filtee) = $Line;
5397c478bd9Sstevel@tonic-gate			my ($Filter) = $Line;
5407c478bd9Sstevel@tonic-gate
5417c478bd9Sstevel@tonic-gate			# Separate the filter and filtee names, ignore the
5427c478bd9Sstevel@tonic-gate			# runtime linker.
5437c478bd9Sstevel@tonic-gate			$Filtee =~ s/^.*: file=(.*);  filtered by .*/$1/;
5447c478bd9Sstevel@tonic-gate			if ($Filtee =~ $Rtld) {
5457c478bd9Sstevel@tonic-gate				next;
5467c478bd9Sstevel@tonic-gate			}
5477c478bd9Sstevel@tonic-gate			$Filter =~ s/^.*;  filtered by //;
5487c478bd9Sstevel@tonic-gate			$Filtees{$Filtee}{$Filter} = 1;
5497c478bd9Sstevel@tonic-gate			next;
5507c478bd9Sstevel@tonic-gate		}
5517c478bd9Sstevel@tonic-gate
5527c478bd9Sstevel@tonic-gate		# If we find a configuration alternative, determine whether it
5537c478bd9Sstevel@tonic-gate		# is for one of our filtees, and if so record it.
5547c478bd9Sstevel@tonic-gate		if ($Line =~ / configuration alternate found:/) {
5557c478bd9Sstevel@tonic-gate			my ($Orig) = $Line;
5567c478bd9Sstevel@tonic-gate			my ($Altr) = $Line;
5577c478bd9Sstevel@tonic-gate
5587c478bd9Sstevel@tonic-gate			# Separate the original and alternative names.
5597c478bd9Sstevel@tonic-gate			$Orig =~ s/^.*: file=(.*)  .*$/$1/;
5607c478bd9Sstevel@tonic-gate			$Altr =~ s/^.* configuration alternate found: (.*)$/$1/;
5617c478bd9Sstevel@tonic-gate
5627c478bd9Sstevel@tonic-gate			for my $Filtee (keys(%Filtees)) {
5637c478bd9Sstevel@tonic-gate				if ($Filtee ne $Orig) {
5647c478bd9Sstevel@tonic-gate					next;
5657c478bd9Sstevel@tonic-gate				}
5667c478bd9Sstevel@tonic-gate				for my $Filter (keys(%{$Filtees{$Filtee}})) {
5677c478bd9Sstevel@tonic-gate					$Filtees{$Altr}{$Filter} = 1;
5687c478bd9Sstevel@tonic-gate				}
5697c478bd9Sstevel@tonic-gate			}
5707c478bd9Sstevel@tonic-gate			next;
5717c478bd9Sstevel@tonic-gate		}
5727c478bd9Sstevel@tonic-gate
5737c478bd9Sstevel@tonic-gate		# Collect the symbols from any file analyzed.
5747c478bd9Sstevel@tonic-gate		if ($Line =~ /^.*: file=(.*);  analyzing .*/) {
5757c478bd9Sstevel@tonic-gate			GetAllSymbols($1);
5767c478bd9Sstevel@tonic-gate			next;
5777c478bd9Sstevel@tonic-gate		}
5787c478bd9Sstevel@tonic-gate
5797c478bd9Sstevel@tonic-gate		# Process any symbolic relocations that bind to a file.
5807c478bd9Sstevel@tonic-gate		if ($Line =~ /: binding file=.* to file=/) {
5817c478bd9Sstevel@tonic-gate			my ($RefFile, $DstFile, $SymName);
5827c478bd9Sstevel@tonic-gate			my (@Syms, $Found, @Fields);
5837c478bd9Sstevel@tonic-gate			my ($BndInfo) = 0;
5847c478bd9Sstevel@tonic-gate			my ($Offset) = 1;
5857c478bd9Sstevel@tonic-gate			my ($Dlsym) = 0;
5867c478bd9Sstevel@tonic-gate			my ($Detail) = 0;
5877c478bd9Sstevel@tonic-gate
5887c478bd9Sstevel@tonic-gate			# For greatest flexibility, split the line into fields
5897c478bd9Sstevel@tonic-gate			# and walk each field until we find what we need.
5907c478bd9Sstevel@tonic-gate			@Fields = split(' ', $Line);
5917c478bd9Sstevel@tonic-gate
5927c478bd9Sstevel@tonic-gate			# The referencing file, "... binding file=".*".
5937c478bd9Sstevel@tonic-gate			while ($Fields[$Offset]) {
5947c478bd9Sstevel@tonic-gate				if ($Fields[$Offset] =~ /^file=(.*)/) {
5957c478bd9Sstevel@tonic-gate					$RefFile = $1;
5967c478bd9Sstevel@tonic-gate					$Offset++;
5977c478bd9Sstevel@tonic-gate					last;
5987c478bd9Sstevel@tonic-gate				}
5997c478bd9Sstevel@tonic-gate				$Offset++;
6007c478bd9Sstevel@tonic-gate			}
6017c478bd9Sstevel@tonic-gate			# The referencing offset, typically this is the address
6027c478bd9Sstevel@tonic-gate			# of the reference, "(0x1234...)", but in the case of a
6037c478bd9Sstevel@tonic-gate			# user lookup it's the string "(dlsym)".  If we don't
6047c478bd9Sstevel@tonic-gate			# find this offset information we've been given a debug
6057c478bd9Sstevel@tonic-gate			# file that didn't user the "datail" token, in which case
6067c478bd9Sstevel@tonic-gate			# we're not getting all the information we need.
6077c478bd9Sstevel@tonic-gate			if ($Fields[$Offset] =~ /^\((.*)\)/) {
6087c478bd9Sstevel@tonic-gate				if ($1 eq 'dlsym') {
6097c478bd9Sstevel@tonic-gate					$Dlsym = 1;
6107c478bd9Sstevel@tonic-gate				}
6117c478bd9Sstevel@tonic-gate				$Detail = 1;
6127c478bd9Sstevel@tonic-gate				$Offset++;
6137c478bd9Sstevel@tonic-gate			}
6147c478bd9Sstevel@tonic-gate			# The destination file, "... to file=".*".
6157c478bd9Sstevel@tonic-gate			while ($Fields[$Offset]) {
6167c478bd9Sstevel@tonic-gate				if ($Fields[$Offset] =~ /^file=(.*)/) {
6177c478bd9Sstevel@tonic-gate					$DstFile = $1;
6187c478bd9Sstevel@tonic-gate					$Offset++;
6197c478bd9Sstevel@tonic-gate					last;
6207c478bd9Sstevel@tonic-gate				}
6217c478bd9Sstevel@tonic-gate				$Offset++;
6227c478bd9Sstevel@tonic-gate			}
6237c478bd9Sstevel@tonic-gate			# The symbol being bound, "... symbol `.*' ...".
6247c478bd9Sstevel@tonic-gate			while ($Fields[$Offset]) {
6257c478bd9Sstevel@tonic-gate				if ($Fields[$Offset] =~ /^\`(.*)\'$/) {
6267c478bd9Sstevel@tonic-gate					$SymName = $1;
6277c478bd9Sstevel@tonic-gate					$Offset++;
6287c478bd9Sstevel@tonic-gate					last;
6297c478bd9Sstevel@tonic-gate				}
6307c478bd9Sstevel@tonic-gate				$Offset++;
6317c478bd9Sstevel@tonic-gate			}
6327c478bd9Sstevel@tonic-gate			# Possible trailing binding info, "... (direct,.*)$".
6337c478bd9Sstevel@tonic-gate			while ($Fields[$Offset]) {
6347c478bd9Sstevel@tonic-gate				if ($Fields[$Offset] =~ /^\((.*)\)$/) {
6357c478bd9Sstevel@tonic-gate					$BndInfo = $1;
6367c478bd9Sstevel@tonic-gate					$Offset++;
6377c478bd9Sstevel@tonic-gate					last;
6387c478bd9Sstevel@tonic-gate				}
6397c478bd9Sstevel@tonic-gate				$Offset++;
6407c478bd9Sstevel@tonic-gate			}
6417c478bd9Sstevel@tonic-gate
6427c478bd9Sstevel@tonic-gate			if ($Detail == 0) {
6437c478bd9Sstevel@tonic-gate				printf STDERR gettext("%s: %s: debug file " .
6447c478bd9Sstevel@tonic-gate				    "does not contain `detail' information\n"),
6457c478bd9Sstevel@tonic-gate				    $Prog, $DbgFile;
6467c478bd9Sstevel@tonic-gate				return;
6477c478bd9Sstevel@tonic-gate			}
6487c478bd9Sstevel@tonic-gate
6497c478bd9Sstevel@tonic-gate			# Collect the symbols from each object.
6507c478bd9Sstevel@tonic-gate			GetAllSymbols($RefFile);
6517c478bd9Sstevel@tonic-gate			GetAllSymbols($DstFile);
6527c478bd9Sstevel@tonic-gate
6537c478bd9Sstevel@tonic-gate			# Identify that this definition has been bound to.
6547c478bd9Sstevel@tonic-gate			$Symbols{$SymName}{$DstFile}[$ObjRef]++;
6557c478bd9Sstevel@tonic-gate			if ($RefFile eq $DstFile) {
6567c478bd9Sstevel@tonic-gate				# If the reference binds to a definition within
6577c478bd9Sstevel@tonic-gate				# the same file this symbol may be a candidate
6587c478bd9Sstevel@tonic-gate				# for reducing to local.
6597c478bd9Sstevel@tonic-gate				$Symbols{$SymName}{$DstFile}[$ObjFlag] |= $Self;
6607c478bd9Sstevel@tonic-gate				$Objects{$DstFile}{$SymName} |= $Self;
6617c478bd9Sstevel@tonic-gate			} else {
6627c478bd9Sstevel@tonic-gate				# This symbol is required to satisfy an external
6637c478bd9Sstevel@tonic-gate				# reference.
6647c478bd9Sstevel@tonic-gate				$Symbols{$SymName}{$DstFile}[$ObjFlag] |= $Extn;
6657c478bd9Sstevel@tonic-gate				$Objects{$DstFile}{$SymName} |= $Extn;
6667c478bd9Sstevel@tonic-gate			}
6677c478bd9Sstevel@tonic-gate
6687c478bd9Sstevel@tonic-gate			# Assign any other state indicated by the binding info
6697c478bd9Sstevel@tonic-gate			# associated with the diagnostic output.
6707c478bd9Sstevel@tonic-gate			if (!$BndInfo) {
6717c478bd9Sstevel@tonic-gate				next;
6727c478bd9Sstevel@tonic-gate			}
6737c478bd9Sstevel@tonic-gate
6747c478bd9Sstevel@tonic-gate			if ($BndInfo =~ /direct/) {
6757c478bd9Sstevel@tonic-gate				$Symbols{$SymName}{$DstFile}[$ObjFlag] |= $Dirc;
6767c478bd9Sstevel@tonic-gate				$Objects{$DstFile}{$SymName} |= $Dirc;
6777c478bd9Sstevel@tonic-gate			}
6787c478bd9Sstevel@tonic-gate			if ($BndInfo =~ /copy-ref/) {
6797c478bd9Sstevel@tonic-gate				$Symbols{$SymName}{$DstFile}[$ObjFlag] |= $Cpyr;
6807c478bd9Sstevel@tonic-gate				$Objects{$DstFile}{$SymName} |= $Cpyr;
6817c478bd9Sstevel@tonic-gate			}
6827c478bd9Sstevel@tonic-gate			if ($BndInfo =~ /filtee/) {
6837c478bd9Sstevel@tonic-gate				$Symbols{$SymName}{$DstFile}[$ObjFlag] |= $Filt;
6847c478bd9Sstevel@tonic-gate				$Objects{$DstFile}{$SymName} |= $Filt;
6857c478bd9Sstevel@tonic-gate			}
6867c478bd9Sstevel@tonic-gate			if ($BndInfo =~ /interpose/) {
6877c478bd9Sstevel@tonic-gate				$Symbols{$SymName}{$DstFile}[$ObjFlag] |= $Intp;
6887c478bd9Sstevel@tonic-gate				$Objects{$DstFile}{$SymName} |= $Intp;
6897c478bd9Sstevel@tonic-gate			}
6907c478bd9Sstevel@tonic-gate			if ($BndInfo =~ /plt-addr/) {
6917c478bd9Sstevel@tonic-gate				$Symbols{$SymName}{$DstFile}[$ObjFlag] |= $Plta;
6927c478bd9Sstevel@tonic-gate				$Objects{$DstFile}{$SymName} |= $Plta;
6937c478bd9Sstevel@tonic-gate			}
6947c478bd9Sstevel@tonic-gate			if ($Dlsym) {
6957c478bd9Sstevel@tonic-gate				$Symbols{$SymName}{$DstFile}[$ObjFlag] |= $User;
6967c478bd9Sstevel@tonic-gate				$Objects{$DstFile}{$SymName} |= $User;
6977c478bd9Sstevel@tonic-gate			}
6987c478bd9Sstevel@tonic-gate		}
6997c478bd9Sstevel@tonic-gate	}
7007c478bd9Sstevel@tonic-gate	close($FileHandle);
7017c478bd9Sstevel@tonic-gate
7027c478bd9Sstevel@tonic-gate	# Now that we've processed all objects, complete any auxiliary filtee
7037c478bd9Sstevel@tonic-gate	# tagging.  For each filtee, determine which of the symbols it exports
7047c478bd9Sstevel@tonic-gate	# are also defined in its filters.  If a filtee is bound to, the
7057c478bd9Sstevel@tonic-gate	# runtime linkers diagnostics will indicate a filtee binding.  However,
7067c478bd9Sstevel@tonic-gate	# some of the filtee symbols may not be bound to, so here we mark them
7077c478bd9Sstevel@tonic-gate	# all so as to remove them from any interesting output.
7087c478bd9Sstevel@tonic-gate	for my $Filtee (keys(%Filtees)) {
7097c478bd9Sstevel@tonic-gate
7107c478bd9Sstevel@tonic-gate		# Standard filters aren't captured at all, as nothing can bind
7117c478bd9Sstevel@tonic-gate		# to them.
7127c478bd9Sstevel@tonic-gate		if (!exists($Objects{$Filtee})) {
7137c478bd9Sstevel@tonic-gate			next;
7147c478bd9Sstevel@tonic-gate		}
7157c478bd9Sstevel@tonic-gate
7167c478bd9Sstevel@tonic-gate		# Determine what symbols this filtee offers.
7177c478bd9Sstevel@tonic-gate		foreach my $SymName (keys(%{$Objects{$Filtee}})) {
7187c478bd9Sstevel@tonic-gate
7197c478bd9Sstevel@tonic-gate			# Ignore the usual reserved stuff.
7207c478bd9Sstevel@tonic-gate			if (!$opt{a} && (($SymName =~ $MultSyms) ||
7217c478bd9Sstevel@tonic-gate			    ($SymName =~ $CrtSyms))) {
7227c478bd9Sstevel@tonic-gate				next;
7237c478bd9Sstevel@tonic-gate			}
7247c478bd9Sstevel@tonic-gate
7257c478bd9Sstevel@tonic-gate			# Determine whether this symbol exists in our filter.
7267c478bd9Sstevel@tonic-gate			for my $Filter (keys(%{$Filtees{$Filtee}})) {
7277c478bd9Sstevel@tonic-gate				if (!$Symbols{$SymName}{$Filter}) {
7287c478bd9Sstevel@tonic-gate					next;
7297c478bd9Sstevel@tonic-gate				}
7307c478bd9Sstevel@tonic-gate				if (!($Symbols{$SymName}{$Filter}[$ObjFlag] &
7317c478bd9Sstevel@tonic-gate				    $Msft)) {
7327c478bd9Sstevel@tonic-gate					next;
7337c478bd9Sstevel@tonic-gate				}
7347c478bd9Sstevel@tonic-gate				$Symbols{$SymName}{$Filtee}[$ObjFlag] |= $Filt;
7357c478bd9Sstevel@tonic-gate			}
7367c478bd9Sstevel@tonic-gate		}
7377c478bd9Sstevel@tonic-gate	}
7387c478bd9Sstevel@tonic-gate
7397c478bd9Sstevel@tonic-gate	# Process objects and their symbols as required.
7407c478bd9Sstevel@tonic-gate	if ($opt{m}) {
7417c478bd9Sstevel@tonic-gate		# If we're creating a mapfile, traverse each object we've
7427c478bd9Sstevel@tonic-gate		# collected.
7437c478bd9Sstevel@tonic-gate		foreach my $Obj (keys(%Objects)) {
7447c478bd9Sstevel@tonic-gate			my ($File, $Path);
7457c478bd9Sstevel@tonic-gate
746c1c6f601Srie			# Skip any objects that should be ignored.
7477c478bd9Sstevel@tonic-gate			if ($Obj =~ $Rtld) {
7487c478bd9Sstevel@tonic-gate				next;
7497c478bd9Sstevel@tonic-gate			}
7507c478bd9Sstevel@tonic-gate
7517c478bd9Sstevel@tonic-gate			# Skip any versioned objects if required.
7527c478bd9Sstevel@tonic-gate			if ($opt{v} && $Versioned{$Obj}) {
7537c478bd9Sstevel@tonic-gate				next;
7547c478bd9Sstevel@tonic-gate			}
7557c478bd9Sstevel@tonic-gate
7567c478bd9Sstevel@tonic-gate			# Open the mapfile if required.
7577c478bd9Sstevel@tonic-gate			$File = basename($Obj);
7587c478bd9Sstevel@tonic-gate			$Path = "$DestDir/mapfile-$File";
7597c478bd9Sstevel@tonic-gate			if (!open(MAPOUT, "> $Path")) {
7607c478bd9Sstevel@tonic-gate				printf STDERR gettext("%s: %s: open failed:" .
7617c478bd9Sstevel@tonic-gate				    "%s\n"), $Prog, $Path, $!;
7627c478bd9Sstevel@tonic-gate				exit 1;
7637c478bd9Sstevel@tonic-gate			}
7647c478bd9Sstevel@tonic-gate
7657c478bd9Sstevel@tonic-gate			# Establish the mapfile preamble.
7667c478bd9Sstevel@tonic-gate			print MAPOUT "#\n# Interface Definition mapfile for:\n";
7677c478bd9Sstevel@tonic-gate			print MAPOUT "#\tDynamic Object: $Obj\n";
7687c478bd9Sstevel@tonic-gate			print MAPOUT "#\tProcess:        $File\n#\n\n";
7697c478bd9Sstevel@tonic-gate
7707c478bd9Sstevel@tonic-gate			# Process each global symbol.
7717c478bd9Sstevel@tonic-gate			print MAPOUT "$File {\n\tglobal:\n";
7727c478bd9Sstevel@tonic-gate
7737c478bd9Sstevel@tonic-gate			foreach my $SymName (sort(keys(%{$Objects{$Obj}}))) {
7747c478bd9Sstevel@tonic-gate				my ($Flag) = $Objects{$Obj}{$SymName};
7757c478bd9Sstevel@tonic-gate
7767c478bd9Sstevel@tonic-gate				# For the first pass we're only interested in
7777c478bd9Sstevel@tonic-gate				# symbols that have been bound to from an
7787c478bd9Sstevel@tonic-gate				# external object, or must be global to enable
7797c478bd9Sstevel@tonic-gate				# a binding to an interposing definition.
7807c478bd9Sstevel@tonic-gate				# Skip bindings to ourself as these are
7817c478bd9Sstevel@tonic-gate				# candidates for demoting to local.
7827c478bd9Sstevel@tonic-gate				if (!($Flag & ($Extn | $Intp))) {
7837c478bd9Sstevel@tonic-gate					next;
7847c478bd9Sstevel@tonic-gate				}
7857c478bd9Sstevel@tonic-gate				if (($Flag & ($Extn | $Self)) == $Self) {
7867c478bd9Sstevel@tonic-gate					next;
7877c478bd9Sstevel@tonic-gate				}
7887c478bd9Sstevel@tonic-gate
7897c478bd9Sstevel@tonic-gate				# Add the demangled name as a comment if
7907c478bd9Sstevel@tonic-gate				# required.
7917c478bd9Sstevel@tonic-gate				if ($opt{C}) {
7927c478bd9Sstevel@tonic-gate					my ($DemName) = Demangle($SymName);
7937c478bd9Sstevel@tonic-gate
7947c478bd9Sstevel@tonic-gate					if ($DemName ne "") {
7957c478bd9Sstevel@tonic-gate						print MAPOUT "\t\t#$DemName\n";
7967c478bd9Sstevel@tonic-gate					}
7977c478bd9Sstevel@tonic-gate				}
7987c478bd9Sstevel@tonic-gate				print MAPOUT "\t\t$SymName;\n";
7997c478bd9Sstevel@tonic-gate			}
8007c478bd9Sstevel@tonic-gate
8017c478bd9Sstevel@tonic-gate			# Process each local demotion.
8027c478bd9Sstevel@tonic-gate			print MAPOUT "\tlocal:\n";
8037c478bd9Sstevel@tonic-gate
8047c478bd9Sstevel@tonic-gate			if ($opt{o}) {
8057c478bd9Sstevel@tonic-gate				foreach my $SymName
8067c478bd9Sstevel@tonic-gate				    (sort(keys(%{$Objects{$Obj}}))) {
8077c478bd9Sstevel@tonic-gate					my ($Flag) = $Objects{$Obj}{$SymName};
8087c478bd9Sstevel@tonic-gate
8097c478bd9Sstevel@tonic-gate					# For this pass we're only interested
8107c478bd9Sstevel@tonic-gate					# in symbol definitions that haven't
8117c478bd9Sstevel@tonic-gate					# been bound to, or have only been
8127c478bd9Sstevel@tonic-gate					# bound to from the same object.
8137c478bd9Sstevel@tonic-gate					if ($Flag & $Extn) {
8147c478bd9Sstevel@tonic-gate						next;
8157c478bd9Sstevel@tonic-gate					}
8167c478bd9Sstevel@tonic-gate
8177c478bd9Sstevel@tonic-gate					# Add the demangled name as a comment if
8187c478bd9Sstevel@tonic-gate					# required.
8197c478bd9Sstevel@tonic-gate					if ($opt{C}) {
8207c478bd9Sstevel@tonic-gate						my ($DemName) =
8217c478bd9Sstevel@tonic-gate						    Demangle($SymName);
8227c478bd9Sstevel@tonic-gate
8237c478bd9Sstevel@tonic-gate						if ($DemName ne "") {
8247c478bd9Sstevel@tonic-gate							print MAPOUT
8257c478bd9Sstevel@tonic-gate							    "\t\t#$DemName\n";
8267c478bd9Sstevel@tonic-gate						}
8277c478bd9Sstevel@tonic-gate					}
8287c478bd9Sstevel@tonic-gate					print MAPOUT "\t\t$SymName;\n";
8297c478bd9Sstevel@tonic-gate				}
8307c478bd9Sstevel@tonic-gate			}
8317c478bd9Sstevel@tonic-gate
8327c478bd9Sstevel@tonic-gate			# Capture everything else as local.
8337c478bd9Sstevel@tonic-gate			print MAPOUT "\t\t\*;\n};\n";
8347c478bd9Sstevel@tonic-gate			close MAPOUT;
8357c478bd9Sstevel@tonic-gate		}
8367c478bd9Sstevel@tonic-gate
8377c478bd9Sstevel@tonic-gate	} else {
8387c478bd9Sstevel@tonic-gate		# If we're gathering information regarding the symbols used by
8397c478bd9Sstevel@tonic-gate		# the process, automatically sort any standard output using the
8407c478bd9Sstevel@tonic-gate		# symbol name.
8417c478bd9Sstevel@tonic-gate		if (!open(SORT, "| sort +1")) {
8427c478bd9Sstevel@tonic-gate			printf STDERR gettext("%s: fork failed: %s\n"),
8437c478bd9Sstevel@tonic-gate			    $Prog, $!;
8447c478bd9Sstevel@tonic-gate			exit 1;
8457c478bd9Sstevel@tonic-gate		}
8467c478bd9Sstevel@tonic-gate
8477c478bd9Sstevel@tonic-gate		foreach my $SymName (keys(%Symbols)) {
8487c478bd9Sstevel@tonic-gate			my ($Cnt);
8497c478bd9Sstevel@tonic-gate
8507c478bd9Sstevel@tonic-gate			# If we're looking for interesting symbols, inspect
8517c478bd9Sstevel@tonic-gate			# each definition of each symbol.  If one is found to
8527c478bd9Sstevel@tonic-gate			# be interesting, the whole family are printed.
8537c478bd9Sstevel@tonic-gate			if (($Cnt = Interesting($SymName)) == 0) {
8547c478bd9Sstevel@tonic-gate				next;
8557c478bd9Sstevel@tonic-gate			}
8567c478bd9Sstevel@tonic-gate
8577c478bd9Sstevel@tonic-gate			# We've found something interesting, or all symbols
8587c478bd9Sstevel@tonic-gate			# should be output.  List all objects that define this
8597c478bd9Sstevel@tonic-gate			# symbol.
8607c478bd9Sstevel@tonic-gate			foreach my $Obj (keys(%{$Symbols{$SymName}})) {
8617c478bd9Sstevel@tonic-gate				my ($DemName, $Type);
8627c478bd9Sstevel@tonic-gate				my ($Flag) = $Symbols{$SymName}{$Obj}[$ObjFlag];
8637c478bd9Sstevel@tonic-gate				my ($Str) = "$Cnt:";
8647c478bd9Sstevel@tonic-gate
8657c478bd9Sstevel@tonic-gate				# Do we just want overhead symbols.  Consider
8667c478bd9Sstevel@tonic-gate				# copy-relocations, and plt address binding,
8677c478bd9Sstevel@tonic-gate				# as overhead too.
8687c478bd9Sstevel@tonic-gate				if ($opt{o} && (($Flag &
8697c478bd9Sstevel@tonic-gate				    ($Extn | $Cpyr | $Plta)) == $Extn)) {
8707c478bd9Sstevel@tonic-gate					next;
8717c478bd9Sstevel@tonic-gate				}
8727c478bd9Sstevel@tonic-gate
8737c478bd9Sstevel@tonic-gate				# Do we just want all symbols that have been
8747c478bd9Sstevel@tonic-gate				# bound to.
8757c478bd9Sstevel@tonic-gate				if (($opt{a} || $opt{o}) && $opt{b} &&
8767c478bd9Sstevel@tonic-gate				    (($Flag & ($Extn | $Self | $Prot)) == 0)) {
8777c478bd9Sstevel@tonic-gate					next;
8787c478bd9Sstevel@tonic-gate				}
8797c478bd9Sstevel@tonic-gate
8807c478bd9Sstevel@tonic-gate				# If we haven't been asked for all symbols, only
8817c478bd9Sstevel@tonic-gate				# print those reserved symbols that have been
8827c478bd9Sstevel@tonic-gate				# bound to, as the number of reserved symbols
8837c478bd9Sstevel@tonic-gate				# can be quite excessive.
8847c478bd9Sstevel@tonic-gate				if (!$opt{a} && ((($SymName =~ $MultSyms) &&
8857c478bd9Sstevel@tonic-gate				    (($Flag & ($Extn | $Self)) == 0)) ||
8867c478bd9Sstevel@tonic-gate				    (($SymName =~ $CrtSyms) && (($Flag &
8877c478bd9Sstevel@tonic-gate				    ($Extn | $Self | $Prot)) == 0)))) {
8887c478bd9Sstevel@tonic-gate					next;
8897c478bd9Sstevel@tonic-gate				}
8907c478bd9Sstevel@tonic-gate
8917c478bd9Sstevel@tonic-gate				# Skip any versioned objects if required.
8927c478bd9Sstevel@tonic-gate				if ($opt{v} && $Versioned{$Obj}) {
8937c478bd9Sstevel@tonic-gate					next;
8947c478bd9Sstevel@tonic-gate				}
8957c478bd9Sstevel@tonic-gate
8967c478bd9Sstevel@tonic-gate				# Display this symbol.
8977c478bd9Sstevel@tonic-gate				if ($Symbols{$SymName}{$Obj}[$ObjRef]) {
8987c478bd9Sstevel@tonic-gate					$Str = $Str .
8997c478bd9Sstevel@tonic-gate					    $Symbols{$SymName}{$Obj}[$ObjRef];
9007c478bd9Sstevel@tonic-gate				} else {
9017c478bd9Sstevel@tonic-gate					$Str = $Str . '0';
9027c478bd9Sstevel@tonic-gate				}
9037c478bd9Sstevel@tonic-gate
9047c478bd9Sstevel@tonic-gate				# Has the symbol been bound to externally
9057c478bd9Sstevel@tonic-gate				if ($Flag & $Extn) {
9067c478bd9Sstevel@tonic-gate					$Str = $Str . 'E';
9077c478bd9Sstevel@tonic-gate				}
9087c478bd9Sstevel@tonic-gate				# Has the symbol been bound to from the same
9097c478bd9Sstevel@tonic-gate				# object.
9107c478bd9Sstevel@tonic-gate				if ($Flag & $Self) {
9117c478bd9Sstevel@tonic-gate					$Str = $Str . 'S';
9127c478bd9Sstevel@tonic-gate				}
9137c478bd9Sstevel@tonic-gate				# Has the symbol been bound to directly.
9147c478bd9Sstevel@tonic-gate				if ($Flag & $Dirc) {
9157c478bd9Sstevel@tonic-gate					$Str = $Str . 'D';
9167c478bd9Sstevel@tonic-gate				}
9177c478bd9Sstevel@tonic-gate				# Does this symbol originate for an explicit
9187c478bd9Sstevel@tonic-gate				# interposer.
9197c478bd9Sstevel@tonic-gate				if ($Flag & $Intp) {
9207c478bd9Sstevel@tonic-gate					$Str = $Str . 'I';
9217c478bd9Sstevel@tonic-gate				}
9227c478bd9Sstevel@tonic-gate				# Is this symbol the reference data of a copy
9237c478bd9Sstevel@tonic-gate				# relocation.
9247c478bd9Sstevel@tonic-gate				if ($Flag & $Cpyr) {
9257c478bd9Sstevel@tonic-gate					$Str = $Str . 'C';
9267c478bd9Sstevel@tonic-gate				}
9277c478bd9Sstevel@tonic-gate				# Is this symbol part of filtee.
9287c478bd9Sstevel@tonic-gate				if ($Flag & $Filt) {
9297c478bd9Sstevel@tonic-gate					$Str = $Str . 'F';
9307c478bd9Sstevel@tonic-gate				}
9317c478bd9Sstevel@tonic-gate				# Is this symbol protected (in which case there
9327c478bd9Sstevel@tonic-gate				# may be a symbolic binding within the same
9337c478bd9Sstevel@tonic-gate				# object to this symbol).
9347c478bd9Sstevel@tonic-gate				if ($Flag & $Prot) {
9357c478bd9Sstevel@tonic-gate					$Str = $Str . 'P';
9367c478bd9Sstevel@tonic-gate				}
9377c478bd9Sstevel@tonic-gate				# Is this symbol an executables .plt address.
9387c478bd9Sstevel@tonic-gate				if ($Flag & $Plta) {
9397c478bd9Sstevel@tonic-gate					$Str = $Str . 'A';
9407c478bd9Sstevel@tonic-gate				}
9417c478bd9Sstevel@tonic-gate				# Does this binding originate from a user
9427c478bd9Sstevel@tonic-gate				# (dlsym) request.
9437c478bd9Sstevel@tonic-gate				if ($Flag & $User) {
9447c478bd9Sstevel@tonic-gate					$Str = $Str . 'U';
9457c478bd9Sstevel@tonic-gate				}
9467c478bd9Sstevel@tonic-gate				# Does this definition redirect the binding.
9477c478bd9Sstevel@tonic-gate				if ($Flag & $Msft) {
9487c478bd9Sstevel@tonic-gate					$Str = $Str . 'R';
9497c478bd9Sstevel@tonic-gate				}
9507c478bd9Sstevel@tonic-gate				# Does this definition explicity define no
9517c478bd9Sstevel@tonic-gate				# direct binding.
9527c478bd9Sstevel@tonic-gate				if ($Flag & $Nodi) {
9537c478bd9Sstevel@tonic-gate					$Str = $Str . 'N';
9547c478bd9Sstevel@tonic-gate				}
9557c478bd9Sstevel@tonic-gate
9567c478bd9Sstevel@tonic-gate				# Determine whether this is a function or a data
9577c478bd9Sstevel@tonic-gate				# object.  For the latter, display the symbol
9587c478bd9Sstevel@tonic-gate				# size.  Otherwise, the symbol is a reserved
9597c478bd9Sstevel@tonic-gate				# label, and is left untyped.
9607c478bd9Sstevel@tonic-gate				if ($Flag & $Func) {
9617c478bd9Sstevel@tonic-gate					$Type = '()';
9627c478bd9Sstevel@tonic-gate				} elsif ($Flag & $Objt) {
9637c478bd9Sstevel@tonic-gate					$Type = '[' .
9647c478bd9Sstevel@tonic-gate					    $Symbols{$SymName}{$Obj}[$ObjSize] .
9657c478bd9Sstevel@tonic-gate					']';
9667c478bd9Sstevel@tonic-gate				} else {
9677c478bd9Sstevel@tonic-gate					$Type = "";
9687c478bd9Sstevel@tonic-gate				}
9697c478bd9Sstevel@tonic-gate
9707c478bd9Sstevel@tonic-gate				# Demangle the symbol name if desired.
9717c478bd9Sstevel@tonic-gate				$DemName = Demangle($SymName);
9727c478bd9Sstevel@tonic-gate
9737c478bd9Sstevel@tonic-gate				if ($Mult) {
9747c478bd9Sstevel@tonic-gate					print SORT "  [$Str]: " .
9757c478bd9Sstevel@tonic-gate					    "$SymName$Type$DemName: $Obj\n";
9767c478bd9Sstevel@tonic-gate				} else {
9777c478bd9Sstevel@tonic-gate					print SORT "[$Str]: " .
9787c478bd9Sstevel@tonic-gate					    "$SymName$Type$DemName: $Obj\n";
9797c478bd9Sstevel@tonic-gate				}
9807c478bd9Sstevel@tonic-gate			}
9817c478bd9Sstevel@tonic-gate		}
9827c478bd9Sstevel@tonic-gate		close SORT;
9837c478bd9Sstevel@tonic-gate	}
9847c478bd9Sstevel@tonic-gate}
9857c478bd9Sstevel@tonic-gate
9867c478bd9Sstevel@tonic-gate# Heuristics to determine whether a symbol binding is interesting.  In most
9877c478bd9Sstevel@tonic-gate# applications there can be a large amount of symbol binding information to
9887c478bd9Sstevel@tonic-gate# wade through.  The most typical binding, to a single definition, probably
9897c478bd9Sstevel@tonic-gate# isn't interesting or the cause of unexpected behavior.  Here, we try and
9907c478bd9Sstevel@tonic-gate# determine those bindings that may can cause unexpected behavior.
9917c478bd9Sstevel@tonic-gate#
9927c478bd9Sstevel@tonic-gate# Note, this routine is actually called for all symbols so that their count
9937c478bd9Sstevel@tonic-gate# can be calculated in one place.
9947c478bd9Sstevel@tonic-gatesub Interesting
9957c478bd9Sstevel@tonic-gate{
9967c478bd9Sstevel@tonic-gate	my ($SymName) = @_;
9977c478bd9Sstevel@tonic-gate	my ($ObjCnt, $GFlags, $BndCnt, $FltCnt, $NodiCnt, $RdirCnt, $ExRef);
9987c478bd9Sstevel@tonic-gate
9997c478bd9Sstevel@tonic-gate	# Scan all definitions of this symbol, thus determining the definition
10007c478bd9Sstevel@tonic-gate	# count, the number of filters, redirections, executable references
10017c478bd9Sstevel@tonic-gate	# (copy-relocations, or plt addresses), no-direct bindings, and the
10027c478bd9Sstevel@tonic-gate	# number of definitions that have been bound to.
10037c478bd9Sstevel@tonic-gate	$ObjCnt = $GFlags = $BndCnt = $FltCnt =
10047c478bd9Sstevel@tonic-gate		$NodiCnt = $RdirCnt = $ExRef = 0;
10057c478bd9Sstevel@tonic-gate	foreach my $Obj (keys(%{$Symbols{$SymName}})) {
10067c478bd9Sstevel@tonic-gate		my ($Flag) = $Symbols{$SymName}{$Obj}[$ObjFlag];
10077c478bd9Sstevel@tonic-gate
10087c478bd9Sstevel@tonic-gate		# Ignore standard filters when determining the symbol count, as
10097c478bd9Sstevel@tonic-gate		# a standard filter can never be bound to.
10107c478bd9Sstevel@tonic-gate		if (($Flag & ($Osft | $Ssft)) == 0) {
10117c478bd9Sstevel@tonic-gate			$ObjCnt++;
10127c478bd9Sstevel@tonic-gate		}
10137c478bd9Sstevel@tonic-gate
10147c478bd9Sstevel@tonic-gate		$GFlags |= $Flag;
10157c478bd9Sstevel@tonic-gate		if ($Flag & $Filt) {
10167c478bd9Sstevel@tonic-gate			$FltCnt++;
10177c478bd9Sstevel@tonic-gate		}
10187c478bd9Sstevel@tonic-gate		if ($Flag & $Nodi) {
10197c478bd9Sstevel@tonic-gate			$NodiCnt++;
10207c478bd9Sstevel@tonic-gate		}
10217c478bd9Sstevel@tonic-gate		if ($Flag & ($Cpyr | $Plta)) {
10227c478bd9Sstevel@tonic-gate			$ExRef++;
10237c478bd9Sstevel@tonic-gate		}
10247c478bd9Sstevel@tonic-gate		if ($Flag & $Msft) {
10257c478bd9Sstevel@tonic-gate			$RdirCnt++;
10267c478bd9Sstevel@tonic-gate		}
10277c478bd9Sstevel@tonic-gate
10287c478bd9Sstevel@tonic-gate		# Ignore bindings to undefined .plts, and copy-relocation
10297c478bd9Sstevel@tonic-gate		# references.  These are implementation details, rather than
10307c478bd9Sstevel@tonic-gate		# a truly interesting multiple-binding.  If a symbol is tagged
10317c478bd9Sstevel@tonic-gate		# as protected, count it as having bound to itself, even though
10327c478bd9Sstevel@tonic-gate		# we can't tell if it's really been used.
10337c478bd9Sstevel@tonic-gate		if (($Flag & ($Self | $Extn | $Prot)) &&
10347c478bd9Sstevel@tonic-gate		    (($Flag & ($Plta | $Cpyr)) == 0)) {
10357c478bd9Sstevel@tonic-gate			$BndCnt++;
10367c478bd9Sstevel@tonic-gate		}
10377c478bd9Sstevel@tonic-gate	}
10387c478bd9Sstevel@tonic-gate
1039*7010c12aSrie	# If we want all overhead symbols, return the count.
1040*7010c12aSrie	if ($opt{o}) {
1041*7010c12aSrie		return $ObjCnt;
1042*7010c12aSrie	}
1043*7010c12aSrie
1044*7010c12aSrie	# If we want all symbols, return the count.  If we want all bound
1045*7010c12aSrie	# symbols, return the count provided it is non-zero.
1046*7010c12aSrie	if ($opt{a} && (!$opt{b} || ($BndCnt > 0))) {
10477c478bd9Sstevel@tonic-gate		return $ObjCnt;
10487c478bd9Sstevel@tonic-gate	}
10497c478bd9Sstevel@tonic-gate
10507c478bd9Sstevel@tonic-gate	# Single instance symbol definitions aren't very interesting.
10517c478bd9Sstevel@tonic-gate	if ($ObjCnt == 1) {
10527c478bd9Sstevel@tonic-gate		return 0;
10537c478bd9Sstevel@tonic-gate	}
10547c478bd9Sstevel@tonic-gate
10557c478bd9Sstevel@tonic-gate	# Traverse each symbol definition looking for the following:
10567c478bd9Sstevel@tonic-gate	#
10577c478bd9Sstevel@tonic-gate	#   .	Multiple symbols are bound to externally.
10587c478bd9Sstevel@tonic-gate	#   .	A symbol is bound to externally, and possibly symbolically.
10597c478bd9Sstevel@tonic-gate	#
10607c478bd9Sstevel@tonic-gate	# Two symbol bindings are acceptable in some cases, and thus aren't
10617c478bd9Sstevel@tonic-gate	# interesting:
10627c478bd9Sstevel@tonic-gate	#
10637c478bd9Sstevel@tonic-gate	#   .	Copy relocations.  Here, the executable binds to a shared object
10647c478bd9Sstevel@tonic-gate	#	to access the data definition, which is then copied to the
10657c478bd9Sstevel@tonic-gate	#	executable.  All other references should then bind to the copied
10667c478bd9Sstevel@tonic-gate	#	data.
10677c478bd9Sstevel@tonic-gate	#   .	Non-plt relocations to functions that are referenced by the
10687c478bd9Sstevel@tonic-gate	#	executable will bind to the .plt in the executable.  This
10697c478bd9Sstevel@tonic-gate	#	provides for address comparison calculations (although plainly
10707c478bd9Sstevel@tonic-gate	#	an overhead).
10717c478bd9Sstevel@tonic-gate	#
10727c478bd9Sstevel@tonic-gate	# Multiple symbol bindings are acceptable in some cases, and thus aren't
10737c478bd9Sstevel@tonic-gate	# interesting:
10747c478bd9Sstevel@tonic-gate	#
10757c478bd9Sstevel@tonic-gate	#   .	Filtees.  Multiple filtees may exist for one filter.
10767c478bd9Sstevel@tonic-gate	#
10777c478bd9Sstevel@tonic-gate	if ((($ObjCnt == 2) && ($GFlags & ($Cpyr | $Plta))) ||
10787c478bd9Sstevel@tonic-gate	    ($ObjCnt == ($FltCnt + 1))) {
10797c478bd9Sstevel@tonic-gate		return 0;
10807c478bd9Sstevel@tonic-gate	}
10817c478bd9Sstevel@tonic-gate
1082*7010c12aSrie	# Only display any reserved symbols if more than one binding has
1083*7010c12aSrie	# occurred.
1084*7010c12aSrie	if ((($SymName =~ $MultSyms) || ($SymName =~ $CrtSyms)) &&
10857c478bd9Sstevel@tonic-gate	    ($BndCnt < 2)) {
10867c478bd9Sstevel@tonic-gate		return (0);
10877c478bd9Sstevel@tonic-gate	}
10887c478bd9Sstevel@tonic-gate
1089*7010c12aSrie	# For all other symbols, determine whether a binding has occurred.
1090*7010c12aSrie	# Note: definitions within an executable are tagged as protected ("P")
1091*7010c12aSrie	# as they may have been bound to from within the executable - we can't
1092*7010c12aSrie	# tell.
1093*7010c12aSrie	if ($opt{b} && ($BndCnt == 0)) {
1094*7010c12aSrie		return (0);
1095*7010c12aSrie	}
1096*7010c12aSrie
10977c478bd9Sstevel@tonic-gate	# Multiple instances of a definition, where all but one are filter
10987c478bd9Sstevel@tonic-gate	# references and/or copy relocations, are also uninteresting.
10997c478bd9Sstevel@tonic-gate	# Effectively, only one symbol is providing the final binding.
11007c478bd9Sstevel@tonic-gate	if (($FltCnt && $RdirCnt) &&
11017c478bd9Sstevel@tonic-gate	    (($FltCnt + $RdirCnt + $ExRef) == $ObjCnt)) {
11027c478bd9Sstevel@tonic-gate		return (0);
11037c478bd9Sstevel@tonic-gate	}
11047c478bd9Sstevel@tonic-gate
11057c478bd9Sstevel@tonic-gate	# Multiple instances of explicitly defined no-direct binding symbols
11067c478bd9Sstevel@tonic-gate	# are known to occur, and their no-binding definition indicates they
11077c478bd9Sstevel@tonic-gate	# are expected and accounted for.  Thus, these aren't interesting.
11087c478bd9Sstevel@tonic-gate	if (($ExRef + $NodiCnt) == $ObjCnt) {
11097c478bd9Sstevel@tonic-gate		return (0);
11107c478bd9Sstevel@tonic-gate	}
11117c478bd9Sstevel@tonic-gate
11127c478bd9Sstevel@tonic-gate	# We have an interesting symbol, returns its count.
11137c478bd9Sstevel@tonic-gate	return $ObjCnt;
11147c478bd9Sstevel@tonic-gate}
11157c478bd9Sstevel@tonic-gate
11167c478bd9Sstevel@tonic-gate# Obtain the global symbol definitions of an object and determine whether the
11177c478bd9Sstevel@tonic-gate# object has been versioned.
11187c478bd9Sstevel@tonic-gatesub GetAllSymbols {
11197c478bd9Sstevel@tonic-gate	my ($Obj) = @_;
11207c478bd9Sstevel@tonic-gate	my (@Elfd, @Elfs, @Elfr, $Type, $Exec, $FileHandle);
11217c478bd9Sstevel@tonic-gate	my (%AddrToName, %NameToAddr);
11227c478bd9Sstevel@tonic-gate	my ($Vers) = 0;
11237c478bd9Sstevel@tonic-gate	my ($Symb) = 0;
11247c478bd9Sstevel@tonic-gate	my ($Copy) = 0;
11257c478bd9Sstevel@tonic-gate	my ($Interpose) = 0;
11267c478bd9Sstevel@tonic-gate	my ($Fltr) = 0;
11277c478bd9Sstevel@tonic-gate
11287c478bd9Sstevel@tonic-gate	# Determine whether we've already retrieved this object's symbols.
11297c478bd9Sstevel@tonic-gate	# Also, ignore the runtime linker, it's on a separate link-map, and
11307c478bd9Sstevel@tonic-gate	# except for the filtee symbols that might be bound via libdl, is
1131*7010c12aSrie	# uninteresting.  Tag the runtime linker as versioned to simplify
1132*7010c12aSrie	# possible -v processing.
1133*7010c12aSrie	if ($Objects{$Obj}) {
1134*7010c12aSrie		return;
1135*7010c12aSrie	}
1136*7010c12aSrie
1137*7010c12aSrie	if ($Obj =~ $Rtld) {
1138*7010c12aSrie		$Versioned{$Obj} = 1;
11397c478bd9Sstevel@tonic-gate		return;
11407c478bd9Sstevel@tonic-gate	}
11417c478bd9Sstevel@tonic-gate
11427c478bd9Sstevel@tonic-gate	# Get the dynamic information.
11437c478bd9Sstevel@tonic-gate	@Elfd = split(/\n/, `LC_ALL=C elfdump -d '$Obj' 2> /dev/null`);
11447c478bd9Sstevel@tonic-gate
11457c478bd9Sstevel@tonic-gate	# If there's no information, it's possible we've been given a debug
11467c478bd9Sstevel@tonic-gate	# output file and are processing it from a location from which the
11477c478bd9Sstevel@tonic-gate	# dependencies specified in the debug file aren't accessible.
11487c478bd9Sstevel@tonic-gate	if (!@Elfd) {
11497c478bd9Sstevel@tonic-gate		printf STDERR gettext("%s: %s: unable to process ELF file\n"),
11507c478bd9Sstevel@tonic-gate		    $Prog, $Obj;
11517c478bd9Sstevel@tonic-gate
11527c478bd9Sstevel@tonic-gate		# Add the file to our list, so that we don't create the same
11537c478bd9Sstevel@tonic-gate		# message again.  Processing should continue so that we can
11547c478bd9Sstevel@tonic-gate		# flush out as many error messages as possible.
11557c478bd9Sstevel@tonic-gate		$Objects{$Obj}{"DoesNotExist"} = 0;
11567c478bd9Sstevel@tonic-gate		return;
11577c478bd9Sstevel@tonic-gate	}
11587c478bd9Sstevel@tonic-gate
11597c478bd9Sstevel@tonic-gate	# If we're processing a filter there's no need to save any symbols, as
11607c478bd9Sstevel@tonic-gate	# no bindings will occur to this object.
11617c478bd9Sstevel@tonic-gate	#
11627c478bd9Sstevel@tonic-gate	# Determine whether we've got a symbolicly bound object.  With newer
11637c478bd9Sstevel@tonic-gate	# linkers all symbols will be marked as protected ("P"), but with older
11647c478bd9Sstevel@tonic-gate	# linkers this state could only be intuited from the symbolic dynamic
11657c478bd9Sstevel@tonic-gate	# tag.
11667c478bd9Sstevel@tonic-gate	foreach my $Line (@Elfd) {
11677c478bd9Sstevel@tonic-gate		my (@Fields);
11687c478bd9Sstevel@tonic-gate		@Fields = split(' ', $Line);
11697c478bd9Sstevel@tonic-gate
11707c478bd9Sstevel@tonic-gate		# Determine if the FILTER tag is set.
11717c478bd9Sstevel@tonic-gate		if ($#Fields == 3) {
11727c478bd9Sstevel@tonic-gate			if ($Fields[1] eq "FILTER") {
11737c478bd9Sstevel@tonic-gate				$Fltr |= $Osft;
11747c478bd9Sstevel@tonic-gate				next;
11757c478bd9Sstevel@tonic-gate			}
11767c478bd9Sstevel@tonic-gate			if ($Fields[1] eq "AUXILIARY") {
11777c478bd9Sstevel@tonic-gate				$Fltr |= $Oaft;
11787c478bd9Sstevel@tonic-gate				next;
11797c478bd9Sstevel@tonic-gate			}
11807c478bd9Sstevel@tonic-gate			next;
11817c478bd9Sstevel@tonic-gate		}
11827c478bd9Sstevel@tonic-gate
11837c478bd9Sstevel@tonic-gate		# We're only interested in the FLAGS entry.
11847c478bd9Sstevel@tonic-gate		if (($#Fields < 4) || ($Fields[1] !~ "^FLAGS")) {
11857c478bd9Sstevel@tonic-gate			next;
11867c478bd9Sstevel@tonic-gate		}
11877c478bd9Sstevel@tonic-gate		if (($Fields[1] eq "FLAGS") && ($Line =~ " SYMBOLIC ")) {
11887c478bd9Sstevel@tonic-gate			$Symb = 1;
11897c478bd9Sstevel@tonic-gate			next;
11907c478bd9Sstevel@tonic-gate		}
11917c478bd9Sstevel@tonic-gate		if (($Fields[1] eq "FLAGS_1") && ($Line =~ " INTERPOSE ")) {
11927c478bd9Sstevel@tonic-gate			$Interpose = 1;
11937c478bd9Sstevel@tonic-gate		}
11947c478bd9Sstevel@tonic-gate	}
11957c478bd9Sstevel@tonic-gate
11967c478bd9Sstevel@tonic-gate	# If this file is a dynamic executable, determine if this object has
11977c478bd9Sstevel@tonic-gate	# any copy relocations so that any associated bindings can be labeled
11987c478bd9Sstevel@tonic-gate	# more meaningfully.
11997c478bd9Sstevel@tonic-gate	$Type = `LC_ALL=C file '$Obj'`;
12007c478bd9Sstevel@tonic-gate	if ($Type =~ /executable/) {
12017c478bd9Sstevel@tonic-gate		$Exec = 1;
12027c478bd9Sstevel@tonic-gate		# Obtain any copy relocations.
12037c478bd9Sstevel@tonic-gate		@Elfr = split(/\n/, `LC_ALL=C elfdump -r '$Obj' 2>&1`);
12047c478bd9Sstevel@tonic-gate
12057c478bd9Sstevel@tonic-gate		foreach my $Rel (@Elfr) {
12067c478bd9Sstevel@tonic-gate			my ($SymName, @Fields);
12077c478bd9Sstevel@tonic-gate
12087c478bd9Sstevel@tonic-gate			if ($Rel !~ /^\s+R_\S+_COPY /) {
12097c478bd9Sstevel@tonic-gate				next;
12107c478bd9Sstevel@tonic-gate			}
12117c478bd9Sstevel@tonic-gate			@Fields = split(' ', $Rel);
1212*7010c12aSrie			# Intel relocation records don't contain an addend,
1213*7010c12aSrie			# where as every other supported platform does.
1214*7010c12aSrie			if ($Fields[0] eq 'R_386_COPY') {
12157c478bd9Sstevel@tonic-gate				$SymName = $Fields[3];
12167c478bd9Sstevel@tonic-gate			} else {
1217*7010c12aSrie				$SymName = $Fields[4];
12187c478bd9Sstevel@tonic-gate			}
12197c478bd9Sstevel@tonic-gate
12207c478bd9Sstevel@tonic-gate			$Symbols{$SymName}{$Obj}[$ObjFlag] |= $Cpyr;
12217c478bd9Sstevel@tonic-gate			$Objects{$Obj}{$SymName} |= $Cpyr;
12227c478bd9Sstevel@tonic-gate			$Copy = 1;
12237c478bd9Sstevel@tonic-gate		}
12247c478bd9Sstevel@tonic-gate	} else {
12257c478bd9Sstevel@tonic-gate		$Exec = 0;
12267c478bd9Sstevel@tonic-gate	}
12277c478bd9Sstevel@tonic-gate
12287c478bd9Sstevel@tonic-gate	# Obtain the dynamic symbol table for this object.  Symbol tables can
12297c478bd9Sstevel@tonic-gate	# be quite large, so open the elfump command through a pipe.
12307c478bd9Sstevel@tonic-gate	open($FileHandle, "LC_ALL=C elfdump -sN.dynsym '$Obj' 2> /dev/null |");
12317c478bd9Sstevel@tonic-gate
12327c478bd9Sstevel@tonic-gate	# Now process all symbols.
12337c478bd9Sstevel@tonic-gate	while (defined(my $Line = <$FileHandle>)) {
12347c478bd9Sstevel@tonic-gate		chomp($Line);
12357c478bd9Sstevel@tonic-gate
12367c478bd9Sstevel@tonic-gate		my (@Fields) = split(' ', $Line);
12377c478bd9Sstevel@tonic-gate		my ($Flags);
12387c478bd9Sstevel@tonic-gate
12397c478bd9Sstevel@tonic-gate		# We're only interested in defined non-reserved symbol entries.
12407c478bd9Sstevel@tonic-gate		# Note, ABS and NOTY symbols of non-zero size have been known to
12417c478bd9Sstevel@tonic-gate		# occur, so capture them.
12427c478bd9Sstevel@tonic-gate		if (($#Fields < 8) || ($Fields[4] !~ $GlobWeak) ||
12437c478bd9Sstevel@tonic-gate		    ($Fields[7] =~ $UndefSym) || (!$opt{a} &&
12447c478bd9Sstevel@tonic-gate		    ($Fields[7] =~ $IgnSyms) && (oct($Fields[2]) eq 0))) {
12457c478bd9Sstevel@tonic-gate			next;
12467c478bd9Sstevel@tonic-gate		}
12477c478bd9Sstevel@tonic-gate
12487c478bd9Sstevel@tonic-gate		# If we're found copy relocations, save the address and names
12497c478bd9Sstevel@tonic-gate		# of any OBJT definitions, together with the copy symbol.
12507c478bd9Sstevel@tonic-gate		if ($Copy && ($Fields[3] eq 'OBJT')) {
12517c478bd9Sstevel@tonic-gate			push(@{$AddrToName{$Fields[1]}}, $Fields[8]);
12527c478bd9Sstevel@tonic-gate		}
12537c478bd9Sstevel@tonic-gate		if (($Symbols{$Fields[8]}{$Obj}) &&
12547c478bd9Sstevel@tonic-gate		    ($Symbols{$Fields[8]}{$Obj}[$ObjFlag] & $Cpyr)) {
12557c478bd9Sstevel@tonic-gate			$NameToAddr{$Fields[8]} = $Fields[1];
12567c478bd9Sstevel@tonic-gate		}
12577c478bd9Sstevel@tonic-gate
12587c478bd9Sstevel@tonic-gate		# If the symbol visibility is protected, this is an internal
12597c478bd9Sstevel@tonic-gate		# symbolic binding (NOTE, an INTERNAL visibility for a global
12607c478bd9Sstevel@tonic-gate		# symbol is invalid, but for a while ld(1) was setting this
12617c478bd9Sstevel@tonic-gate		# attribute mistakenly for protected).
12627c478bd9Sstevel@tonic-gate		# If this is a dynamic executable, mark its symbols as protected
12637c478bd9Sstevel@tonic-gate		# (they can't be interposed on any more than symbols defined
12647c478bd9Sstevel@tonic-gate		# protected within shared objects).
12657c478bd9Sstevel@tonic-gate		$Flags = $Glob | $Fltr;
12667c478bd9Sstevel@tonic-gate		if (($Fields[5] =~ /^[IP]$/) || $Symb || $Exec) {
12677c478bd9Sstevel@tonic-gate			$Flags |= $Prot;
12687c478bd9Sstevel@tonic-gate		}
12697c478bd9Sstevel@tonic-gate
12707c478bd9Sstevel@tonic-gate		# If this object is marked as an interposer, tag each symbol.
12717c478bd9Sstevel@tonic-gate		if ($Interpose) {
12727c478bd9Sstevel@tonic-gate			$Flags |= $Intp;
12737c478bd9Sstevel@tonic-gate		}
12747c478bd9Sstevel@tonic-gate
12757c478bd9Sstevel@tonic-gate		# Identify the symbol as a function or data type, and for the
12767c478bd9Sstevel@tonic-gate		# latter, capture the symbol size.  Ignore the standard
12777c478bd9Sstevel@tonic-gate		# symbolic labels, as we don't want to type them.
12787c478bd9Sstevel@tonic-gate		if ($Fields[8] !~ $MultSyms) {
12797c478bd9Sstevel@tonic-gate			if ($Fields[3] =~ /^FUNC$/) {
12807c478bd9Sstevel@tonic-gate				$Flags |= $Func;
12817c478bd9Sstevel@tonic-gate			} elsif ($Fields[3] =~ /^OBJT$/) {
12827c478bd9Sstevel@tonic-gate				my ($Size) = $Fields[2];
12837c478bd9Sstevel@tonic-gate
12847c478bd9Sstevel@tonic-gate				if (oct($Size) eq 0) {
12857c478bd9Sstevel@tonic-gate					$Size = "0";
12867c478bd9Sstevel@tonic-gate				} else {
12877c478bd9Sstevel@tonic-gate					$Size =~ s/0x0*/0x/;
12887c478bd9Sstevel@tonic-gate				}
12897c478bd9Sstevel@tonic-gate				$Flags |= $Objt;
12907c478bd9Sstevel@tonic-gate				$Symbols{$Fields[8]}{$Obj}[$ObjSize] = $Size;
12917c478bd9Sstevel@tonic-gate			}
12927c478bd9Sstevel@tonic-gate		}
12937c478bd9Sstevel@tonic-gate
12947c478bd9Sstevel@tonic-gate		$Symbols{$Fields[8]}{$Obj}[$ObjFlag] |= $Flags;
12957c478bd9Sstevel@tonic-gate		$Objects{$Obj}{$Fields[8]} |= $Flags;
12967c478bd9Sstevel@tonic-gate
12977c478bd9Sstevel@tonic-gate		# If the version field is non-null this object has already been
12987c478bd9Sstevel@tonic-gate		# versioned.
12997c478bd9Sstevel@tonic-gate		if (($Vers == 0) && ($Fields[6] ne '0')) {
13007c478bd9Sstevel@tonic-gate			$Versioned{$Obj} = 1;
13017c478bd9Sstevel@tonic-gate			$Vers = 1;
13027c478bd9Sstevel@tonic-gate		}
13037c478bd9Sstevel@tonic-gate	}
13047c478bd9Sstevel@tonic-gate	close($FileHandle);
13057c478bd9Sstevel@tonic-gate
13067c478bd9Sstevel@tonic-gate	# Obtain any symbol information table for this object.  Symbol tables can
13077c478bd9Sstevel@tonic-gate	# be quite large, so open the elfump command through a pipe.
13087c478bd9Sstevel@tonic-gate	open($FileHandle, "LC_ALL=C elfdump -y '$Obj' 2> /dev/null |");
13097c478bd9Sstevel@tonic-gate
13107c478bd9Sstevel@tonic-gate	# Now process all symbols.
13117c478bd9Sstevel@tonic-gate	while (defined(my $Line = <$FileHandle>)) {
13127c478bd9Sstevel@tonic-gate		chomp($Line);
13137c478bd9Sstevel@tonic-gate
13147c478bd9Sstevel@tonic-gate		my (@Fields) = split(' ', $Line);
13157c478bd9Sstevel@tonic-gate		my ($Flags) = 0;
13167c478bd9Sstevel@tonic-gate
13177c478bd9Sstevel@tonic-gate		# Binding attributes are in the second column.
13187c478bd9Sstevel@tonic-gate		if ($#Fields < 1) {
13197c478bd9Sstevel@tonic-gate			next;
13207c478bd9Sstevel@tonic-gate		}
13217c478bd9Sstevel@tonic-gate		if ($Fields[1] =~ /N/) {
13227c478bd9Sstevel@tonic-gate			$Flags |= $Nodi
13237c478bd9Sstevel@tonic-gate		}
13247c478bd9Sstevel@tonic-gate		if ($Fields[1] =~ /F/) {
13257c478bd9Sstevel@tonic-gate			$Flags |= $Ssft;
13267c478bd9Sstevel@tonic-gate		}
13277c478bd9Sstevel@tonic-gate		if ($Fields[1] =~ /A/) {
13287c478bd9Sstevel@tonic-gate			$Flags |= $Saft;
13297c478bd9Sstevel@tonic-gate		}
13307c478bd9Sstevel@tonic-gate
13317c478bd9Sstevel@tonic-gate		# Determine the symbol name based upon the number of fields.
13327c478bd9Sstevel@tonic-gate		if ($Flags && $Symbols{$Fields[$#Fields]}{$Obj}) {
13337c478bd9Sstevel@tonic-gate			$Symbols{$Fields[$#Fields]}{$Obj}[$ObjFlag] |= $Flags;
13347c478bd9Sstevel@tonic-gate			$Objects{$Obj}{$Fields[$#Fields]} |= $Flags;
13357c478bd9Sstevel@tonic-gate		}
13367c478bd9Sstevel@tonic-gate	}
13377c478bd9Sstevel@tonic-gate	close($FileHandle);
13387c478bd9Sstevel@tonic-gate
13397c478bd9Sstevel@tonic-gate	# If this symbol has already been marked as a copy-relocation reference,
13407c478bd9Sstevel@tonic-gate	# see if this symbol has any aliases, which should also be marked.
13417c478bd9Sstevel@tonic-gate	if ($Copy) {
13427c478bd9Sstevel@tonic-gate		foreach my $SymName (keys(%NameToAddr)) {
13437c478bd9Sstevel@tonic-gate			my ($Addr) = $NameToAddr{$SymName};
13447c478bd9Sstevel@tonic-gate
13457c478bd9Sstevel@tonic-gate			# Determine all symbols that have the same address.
13467c478bd9Sstevel@tonic-gate			foreach my $AliasName (@{$AddrToName{$Addr}}) {
13477c478bd9Sstevel@tonic-gate				if ($SymName eq $AliasName) {
13487c478bd9Sstevel@tonic-gate					next;
13497c478bd9Sstevel@tonic-gate				}
13507c478bd9Sstevel@tonic-gate				$Symbols{$AliasName}{$Obj}[$ObjFlag] |= $Cpyr;
13517c478bd9Sstevel@tonic-gate				$Objects{$Obj}{$AliasName} |= $Cpyr;
13527c478bd9Sstevel@tonic-gate			}
13537c478bd9Sstevel@tonic-gate		}
13547c478bd9Sstevel@tonic-gate	}
13557c478bd9Sstevel@tonic-gate}
13567c478bd9Sstevel@tonic-gate
13577c478bd9Sstevel@tonic-gate# Demangle a symbol name if required.
13587c478bd9Sstevel@tonic-gatesub Demangle
13597c478bd9Sstevel@tonic-gate{
13607c478bd9Sstevel@tonic-gate	my ($SymName) = @_;
13617c478bd9Sstevel@tonic-gate	my ($DemName);
13627c478bd9Sstevel@tonic-gate
13637c478bd9Sstevel@tonic-gate	if ($opt{C}) {
13647c478bd9Sstevel@tonic-gate		my (@Dem);
13657c478bd9Sstevel@tonic-gate
13667c478bd9Sstevel@tonic-gate		# Determine if we've already demangled this name.
13677c478bd9Sstevel@tonic-gate		if (exists($DemSyms{$SymName})) {
13687c478bd9Sstevel@tonic-gate			return $DemSyms{$SymName};
13697c478bd9Sstevel@tonic-gate		}
13707c478bd9Sstevel@tonic-gate
13717c478bd9Sstevel@tonic-gate		@Dem = split(/\n/, `dem '$SymName'`);
13727c478bd9Sstevel@tonic-gate		foreach my $Line (@Dem) {
13737c478bd9Sstevel@tonic-gate			my (@Fields) = split(' ', $Line);
13747c478bd9Sstevel@tonic-gate
13757c478bd9Sstevel@tonic-gate			if (($#Fields < 2) || ($Fields[1] ne '==') ||
13767c478bd9Sstevel@tonic-gate			    ($Fields[0] eq $Fields[2])) {
13777c478bd9Sstevel@tonic-gate				next;
13787c478bd9Sstevel@tonic-gate			}
13797c478bd9Sstevel@tonic-gate			$DemName = $Line;
13807c478bd9Sstevel@tonic-gate			$DemName =~ s/.*== (.*)$/ \[$1]/;
13817c478bd9Sstevel@tonic-gate			$DemSyms{$SymName} = $DemName;
13827c478bd9Sstevel@tonic-gate			return($DemName);
13837c478bd9Sstevel@tonic-gate		}
13847c478bd9Sstevel@tonic-gate	}
13857c478bd9Sstevel@tonic-gate	$DemSyms{$SymName} = "";
13867c478bd9Sstevel@tonic-gate	return("");
13877c478bd9Sstevel@tonic-gate}
1388