xref: /illumos-gate/usr/src/cmd/sgs/prof/common/prof.c (revision 9174bfaa)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57a5d89c4Sab  * Common Development and Distribution License (the "License").
67a5d89c4Sab  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
2192ed1782Smike_s 
2292ed1782Smike_s /*
231dd08564Sab  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
2492ed1782Smike_s  * Use is subject to license terms.
254226f635SJason King  * Copyright 2018 Jason King
2692ed1782Smike_s  */
2792ed1782Smike_s 
287c478bd9Sstevel@tonic-gate /*	Copyright (c) 1988 AT&T	*/
29c3f7a870SToomas Soome /*	  All Rights Reserved	*/
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate /*
327c478bd9Sstevel@tonic-gate  *	Program profiling report generator.
337c478bd9Sstevel@tonic-gate  *
347c478bd9Sstevel@tonic-gate  *	Usage:
357c478bd9Sstevel@tonic-gate  *
364226f635SJason King  *	prof [-ChsVz] [-a | c | n | t]  [-o  |  x]   [-g  |  l]
3792ed1782Smike_s  *	    [-m mdata] [prog]
387c478bd9Sstevel@tonic-gate  *
397c478bd9Sstevel@tonic-gate  *	Where "prog" is the program that was profiled; "a.out" by default.
407c478bd9Sstevel@tonic-gate  *	Options are:
417c478bd9Sstevel@tonic-gate  *
427c478bd9Sstevel@tonic-gate  *	-n	Sort by symbol name.
437c478bd9Sstevel@tonic-gate  *	-t	Sort by decreasing time.
447c478bd9Sstevel@tonic-gate  *	-c	Sort by decreasing number of calls.
457c478bd9Sstevel@tonic-gate  *	-a	Sort by increasing symbol address.
467c478bd9Sstevel@tonic-gate  *
477c478bd9Sstevel@tonic-gate  *	The options that determine the type of sorting are mutually exclusive.
487c478bd9Sstevel@tonic-gate  *	Additional options are:
497c478bd9Sstevel@tonic-gate  *
507c478bd9Sstevel@tonic-gate  *	-o	Include symbol addresses in output (in octal).
517c478bd9Sstevel@tonic-gate  *	-x	Include symbol addresses in output (in hexadecimal).
527c478bd9Sstevel@tonic-gate  *	-g	Include non-global T-type symbols in output.
5392ed1782Smike_s  *	-l	Do NOT include local T-type symbols in output (default).
547c478bd9Sstevel@tonic-gate  *	-z	Include all symbols in profiling range, even if zero
557c478bd9Sstevel@tonic-gate  *			number of calls or time.
567c478bd9Sstevel@tonic-gate  *	-h	Suppress table header.
577c478bd9Sstevel@tonic-gate  *	-s	Follow report with additional statistical information.
587c478bd9Sstevel@tonic-gate  *	-m mdata Use file "mdata" instead of MON_OUT for profiling data.
597c478bd9Sstevel@tonic-gate  *	-V	print version information for prof (and exit, if only V spec'd)
607c478bd9Sstevel@tonic-gate  *	-C	call C++ demangle routine to demangle names before printing.
617c478bd9Sstevel@tonic-gate  */
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate #include <stdio.h>
647c478bd9Sstevel@tonic-gate #include <string.h>
657c478bd9Sstevel@tonic-gate #include <errno.h>
667c478bd9Sstevel@tonic-gate #include <dlfcn.h>
6792ed1782Smike_s #include <ctype.h>
68b9bd317cSab #include "conv.h"
697c478bd9Sstevel@tonic-gate #include "symint.h"
707c478bd9Sstevel@tonic-gate #include "sys/param.h"			/* for HZ */
717c478bd9Sstevel@tonic-gate #include "mon.h"
727c478bd9Sstevel@tonic-gate #include "sys/stat.h"
737c478bd9Sstevel@tonic-gate #include "debug.h"
747c478bd9Sstevel@tonic-gate 
75*22af455aSYuri Pankov 
767c478bd9Sstevel@tonic-gate #define	OLD_DEBUG(x)
777c478bd9Sstevel@tonic-gate 
78*22af455aSYuri Pankov OLD_DEBUG(static int debug_value);
79*22af455aSYuri Pankov 
807c478bd9Sstevel@tonic-gate #define	Print	(void) printf
817c478bd9Sstevel@tonic-gate #define	Fprint	(void) fprintf
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate #if vax
847c478bd9Sstevel@tonic-gate 	/* Max positive difference between a fnpc and sl_addr for match */
857c478bd9Sstevel@tonic-gate #define	CCADIFF	22
867c478bd9Sstevel@tonic-gate 	/* Type if n_type field in file symbol table entry. */
877c478bd9Sstevel@tonic-gate #endif
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate #if (u3b || u3b15 || u3b2 || i386)
907c478bd9Sstevel@tonic-gate 	/* Max positive difference between a fnpc and sl_addr for match */
917c478bd9Sstevel@tonic-gate #define	CCADIFF	20	/*  ?? (16 would probably do) */
927c478bd9Sstevel@tonic-gate 	/* For u3b, the "type" is storage class + section number (no type_t) */
937c478bd9Sstevel@tonic-gate #endif
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate #if (sparc)
967c478bd9Sstevel@tonic-gate #define	CCADIFF 24	/* PIC prologue length=20 + 4 */
977c478bd9Sstevel@tonic-gate #endif
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate #define	PROFSEC(ticks) ((double)(ticks)/HZ) /* Convert clock ticks to seconds */
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate 	/* Title fragment used if symbol addresses in output ("-o" or "-x"). */
1037c478bd9Sstevel@tonic-gate char *atitle = " Address ";
1047c478bd9Sstevel@tonic-gate 	/* Format for addresses in output */
1057c478bd9Sstevel@tonic-gate char *aformat = "%8o ";
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate #if !(vax || u3b || u3b15 || u3b2 || i386 || sparc)
1087c478bd9Sstevel@tonic-gate 	/* Make sure something we are set up for.  Else lay egg. */
1097c478bd9Sstevel@tonic-gate #include "### No code for processor type ###"
1107c478bd9Sstevel@tonic-gate #endif
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate 	/* Shorthand to gimme the Precise #of addresses per cells */
1147c478bd9Sstevel@tonic-gate #define	DBL_ADDRPERCELL		(((double)bias)/sf)
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate 	/* Used for unsigned fixed-point fraction with binary scale at */
1187c478bd9Sstevel@tonic-gate 	/* the left of 15'th bit (0 as least significant bit) . */
1197c478bd9Sstevel@tonic-gate #define	BIAS		((long)0200000L)
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate /*
1227c478bd9Sstevel@tonic-gate  *	TS1 insures that the symbols section is executable.
1237c478bd9Sstevel@tonic-gate  */
1247c478bd9Sstevel@tonic-gate #define	TS1(s) (((s) > 0) && (scnhdrp[(s)-1].sh_flags & SHF_EXECINSTR))
1257c478bd9Sstevel@tonic-gate /*
1267c478bd9Sstevel@tonic-gate  *	TS2 insures that the symbol should be reported.  We want
1277c478bd9Sstevel@tonic-gate  *	to report only those symbols that are functions (STT_FUNC)
1287c478bd9Sstevel@tonic-gate  *	or "notype" (STT_NOTYPE... "printf", for example).  Also,
1297c478bd9Sstevel@tonic-gate  *	unless the gflag is set, the symbol must be global.
1307c478bd9Sstevel@tonic-gate  */
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate #define	TS2(i)	\
1337c478bd9Sstevel@tonic-gate 	(((ELF32_ST_TYPE(i) == STT_FUNC) ||		\
1347c478bd9Sstevel@tonic-gate 			(ELF32_ST_TYPE(i) == STT_NOTYPE)) &&	\
1357c478bd9Sstevel@tonic-gate 		((ELF32_ST_BIND(i) == STB_GLOBAL) ||		\
1367c478bd9Sstevel@tonic-gate 			(gflag && (ELF32_ST_BIND(i) == STB_LOCAL))))
1377c478bd9Sstevel@tonic-gate 
1387c478bd9Sstevel@tonic-gate #define	TXTSYM(s, i)	(TS1(s) && TS2(i))
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate int gflag = 0;			/*  replaces gmatch and gmask */
1417c478bd9Sstevel@tonic-gate int Cflag = 0;
1427c478bd9Sstevel@tonic-gate 
1434226f635SJason King PROF_FILE	*ldptr;		/* For program ("a.out") file. */
1447c478bd9Sstevel@tonic-gate 
1457c478bd9Sstevel@tonic-gate FILE	*mon_iop;		/* For profile (MON_OUT) file. */
1467c478bd9Sstevel@tonic-gate char	*sym_fn = "a.out";	/* Default program file name. */
1477c478bd9Sstevel@tonic-gate char	*mon_fn = MON_OUT;	/* Default profile file name. */
1487c478bd9Sstevel@tonic-gate 				/* May be changed by "-m file". */
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate long bias;	/* adjusted bias */
1517c478bd9Sstevel@tonic-gate long temp;	/* for bias adjust */
1527c478bd9Sstevel@tonic-gate 
15392ed1782Smike_s extern void profver(void);
1547c478bd9Sstevel@tonic-gate 
1557c478bd9Sstevel@tonic-gate 	/* For symbol table entries read from program file. */
1567c478bd9Sstevel@tonic-gate PROF_SYMBOL nl;
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate /* Compare routines called from qsort() */
1597c478bd9Sstevel@tonic-gate 
16092ed1782Smike_s int c_ccaddr(const void *arg1, const void *arg2);
16192ed1782Smike_s int c_sladdr(const void *arg1, const void *arg2);
16292ed1782Smike_s int c_time(const void *arg1, const void *arg2);
16392ed1782Smike_s int c_ncalls(const void *arg1, const void *arg2);
16492ed1782Smike_s int c_name(const void *arg1, const void *arg2);
1657c478bd9Sstevel@tonic-gate 
1667c478bd9Sstevel@tonic-gate /* Other stuff. */
1677c478bd9Sstevel@tonic-gate 
1687c478bd9Sstevel@tonic-gate /* Return size of open file (arg is file descriptor) */
16992ed1782Smike_s static off_t fsize(int fd);
17092ed1782Smike_s 
17192ed1782Smike_s static void snh(void);
17292ed1782Smike_s static void Perror(char *s);
17392ed1782Smike_s static void eofon(FILE *iop, char *fn);
17492ed1782Smike_s static void usage(void);
17592ed1782Smike_s static char *getname(PROF_FILE *ldpter, PROF_SYMBOL symbol);
1767c478bd9Sstevel@tonic-gate 
1777c478bd9Sstevel@tonic-gate 	/* Memory allocation. Like malloc(), but no return if error. */
17892ed1782Smike_s static void *_prof_Malloc(int item_count, int item_size);
1797c478bd9Sstevel@tonic-gate 
1807c478bd9Sstevel@tonic-gate 	/* Scan past path part (if any) in the ... */
18192ed1782Smike_s static char *basename(char *s);
1827c478bd9Sstevel@tonic-gate 
1837c478bd9Sstevel@tonic-gate 	/* command name, for error messages. */
1847c478bd9Sstevel@tonic-gate char	*cmdname;
1857c478bd9Sstevel@tonic-gate /* Structure of subroutine call counters (cnt) is defined in mon.h. */
1867c478bd9Sstevel@tonic-gate 
1877c478bd9Sstevel@tonic-gate /* Structure for header of mon.out (hdr) is defined in mon.h. */
1887c478bd9Sstevel@tonic-gate 
1897c478bd9Sstevel@tonic-gate 	/* Local representation of symbols and call/time information. */
1907c478bd9Sstevel@tonic-gate struct slist {
1917c478bd9Sstevel@tonic-gate 	char *sl_name;		/* Symbol name. */
1927c478bd9Sstevel@tonic-gate 	char *sl_addr;		/* Address. */
1937c478bd9Sstevel@tonic-gate 	long sl_size;		/* size of symbol */
1947c478bd9Sstevel@tonic-gate 	long sl_count;		/* Count of subroutine calls */
1957c478bd9Sstevel@tonic-gate 	float sl_time;		/* Count of clock ticks in this routine, */
1967c478bd9Sstevel@tonic-gate 				/*		converted to secs. */
1977c478bd9Sstevel@tonic-gate };
1987c478bd9Sstevel@tonic-gate 
1997c478bd9Sstevel@tonic-gate 	/* local structure for tracking synonyms in our symbol list */
20092ed1782Smike_s struct snymEntry {
2017c478bd9Sstevel@tonic-gate 	char	*sym_addr;	/* address which has a synonym */
2027c478bd9Sstevel@tonic-gate 	int	howMany;	/* # of synonyms for this symbol */
2037c478bd9Sstevel@tonic-gate 	int	snymReported;	/* 'was printed in a report line already'  */
2044226f635SJason King 				/*	flag, */
2057c478bd9Sstevel@tonic-gate 				/*   > 0 report line printed for these syns. */
2067c478bd9Sstevel@tonic-gate 				/*  == 0 not printed yet. */
2077c478bd9Sstevel@tonic-gate 	long	tot_sl_count;	/* total subr calls for these snyms */
2087c478bd9Sstevel@tonic-gate 	float	tot_sl_time;	/* total clock ticks (a la sl_time) */
2097c478bd9Sstevel@tonic-gate };
2107c478bd9Sstevel@tonic-gate 
2117c478bd9Sstevel@tonic-gate 
2127c478bd9Sstevel@tonic-gate PROF_FILE	filhdr;			/* profile file descriptor */
2137c478bd9Sstevel@tonic-gate Elf32_Shdr	*scnhdrp;	/* pointer to first section header */
2147c478bd9Sstevel@tonic-gate 					/* (space by _prof_Malloc) */
2157c478bd9Sstevel@tonic-gate 
2167c478bd9Sstevel@tonic-gate struct hdr head;	/* Profile file (MON_OUT) header. */
2177c478bd9Sstevel@tonic-gate 
2187c478bd9Sstevel@tonic-gate int	(*sort)() = NULL;	/* Compare routine for sorting output */
2197c478bd9Sstevel@tonic-gate 				/*	symbols.  Set by "-[acnt]". */
2207c478bd9Sstevel@tonic-gate 
2217c478bd9Sstevel@tonic-gate int	flags;		/* Various flag bits. */
2227c478bd9Sstevel@tonic-gate 
2237c478bd9Sstevel@tonic-gate char	*pc_l;		/* From head.lpc. */
2247c478bd9Sstevel@tonic-gate 
2257c478bd9Sstevel@tonic-gate char	*pc_h;		/*   "  head.hpc. */
2267c478bd9Sstevel@tonic-gate 
2277c478bd9Sstevel@tonic-gate short	VwasSpecified = 0;	/* 1 if -V was specified */
2287c478bd9Sstevel@tonic-gate 
2297c478bd9Sstevel@tonic-gate /*
2307c478bd9Sstevel@tonic-gate  * Bit macro and flag bit definitions. These need to be identical to the
2317c478bd9Sstevel@tonic-gate  * set in profv.h. Any change here should be reflected in profv.c also.
2327c478bd9Sstevel@tonic-gate  */
2337c478bd9Sstevel@tonic-gate #define	FBIT(pos)	(01 << (pos))	/* Returns value with bit pos set. */
2347c478bd9Sstevel@tonic-gate #define	F_SORT		FBIT(0)		/* Set if "-[acnt]" seen. */
2357c478bd9Sstevel@tonic-gate #define	F_VERBOSE	FBIT(1)		/* Set if "-s" seen. */
2367c478bd9Sstevel@tonic-gate #define	F_ZSYMS		FBIT(2)		/* Set if "-z" seen. */
2377c478bd9Sstevel@tonic-gate #define	F_PADDR		FBIT(3)		/* Set if "-o" or "-x" seen. */
2387c478bd9Sstevel@tonic-gate #define	F_NHEAD		FBIT(4)		/* Set if "-h" seen. */
2397c478bd9Sstevel@tonic-gate 
2407c478bd9Sstevel@tonic-gate 
2417c478bd9Sstevel@tonic-gate struct snymEntry *snymList;	/* Pointer to allocated list of */
2427c478bd9Sstevel@tonic-gate 				/* synonym entries.  */
2437c478bd9Sstevel@tonic-gate struct snymEntry *snymp;
2447c478bd9Sstevel@tonic-gate 				/* for scanning entries. */
2457c478bd9Sstevel@tonic-gate 
2467c478bd9Sstevel@tonic-gate int snymCapacity;		/* #slots in snymList */
2477c478bd9Sstevel@tonic-gate int n_snyms;			/* #used slots in snymList */
2487c478bd9Sstevel@tonic-gate 
24992ed1782Smike_s static int readnl(int symindex);
25092ed1782Smike_s static int fprecision(long count);
25192ed1782Smike_s 
2527c478bd9Sstevel@tonic-gate /*
2537c478bd9Sstevel@tonic-gate  * Sort flags. Mutually exclusive. These need to be identical to the ones
2547c478bd9Sstevel@tonic-gate  * defined in profv.h
2557c478bd9Sstevel@tonic-gate  */
2567c478bd9Sstevel@tonic-gate #define	BY_ADDRESS	0x1
2577c478bd9Sstevel@tonic-gate #define	BY_NCALLS	0x2
2587c478bd9Sstevel@tonic-gate #define	BY_NAME		0x4
2597c478bd9Sstevel@tonic-gate #define	BY_TIME		0x8
2607c478bd9Sstevel@tonic-gate 
2617c478bd9Sstevel@tonic-gate extern unsigned char sort_flag;	/* what type of sort ? */
2627c478bd9Sstevel@tonic-gate 
2637c478bd9Sstevel@tonic-gate 	/*
2647c478bd9Sstevel@tonic-gate 	 * printSnymNames - print a comma-seperated list of snym names.
2657c478bd9Sstevel@tonic-gate 	 * This routine hunts down all the synonyms for the given
2667c478bd9Sstevel@tonic-gate 	 * symbol, and prints them as a comma-seperated list.
2677c478bd9Sstevel@tonic-gate 	 * NB we assume that all the synonyms _Follow_ this one,
2687c478bd9Sstevel@tonic-gate 	 * since they are only printed when the First one
2697c478bd9Sstevel@tonic-gate 	 * is seen.
2707c478bd9Sstevel@tonic-gate 	 */
2717c478bd9Sstevel@tonic-gate void
printSnymNames(struct slist * slp,struct snymEntry * snymp)27292ed1782Smike_s printSnymNames(struct slist *slp, struct snymEntry *snymp)
2737c478bd9Sstevel@tonic-gate {
2747c478bd9Sstevel@tonic-gate 	/* how many snyms for this addr, total, and their shared address */
2757c478bd9Sstevel@tonic-gate 	int i = snymp->howMany;
2767c478bd9Sstevel@tonic-gate 	char *sharedaddr = snymp->sym_addr;
2777c478bd9Sstevel@tonic-gate 
2787c478bd9Sstevel@tonic-gate 	/* put out first name - it counts as one, so decr count */
2797c478bd9Sstevel@tonic-gate 	(void) fputs(slp->sl_name, stdout);
2807c478bd9Sstevel@tonic-gate 	i--;
2817c478bd9Sstevel@tonic-gate 
2827c478bd9Sstevel@tonic-gate 	/* for the others: find each, print each. */
2837c478bd9Sstevel@tonic-gate 	while (--i >= 0) {
2841dd08564Sab 		while ((++slp)->sl_addr != sharedaddr)
2851dd08564Sab 			;
2867c478bd9Sstevel@tonic-gate 		Print(", %s", slp->sl_name);
2877c478bd9Sstevel@tonic-gate 	}
2887c478bd9Sstevel@tonic-gate 	/* finally.. the trailing newline */
28992ed1782Smike_s 	(void) putchar('\n');
2907c478bd9Sstevel@tonic-gate }
2917c478bd9Sstevel@tonic-gate 
2927c478bd9Sstevel@tonic-gate 
2937c478bd9Sstevel@tonic-gate 	/*
2947c478bd9Sstevel@tonic-gate 	 * getSnymEntry - see if addr was noted as a aliased address
2957c478bd9Sstevel@tonic-gate 	 * (i.e. a synonym symbol) and return the address of the
2967c478bd9Sstevel@tonic-gate 	 * snym entry if it was.
2977c478bd9Sstevel@tonic-gate 	 */
29892ed1782Smike_s struct snymEntry *
getSnymEntry(char * sl_addr)29992ed1782Smike_s getSnymEntry(char *sl_addr)
3007c478bd9Sstevel@tonic-gate {
3017c478bd9Sstevel@tonic-gate 	struct snymEntry *p;
3027c478bd9Sstevel@tonic-gate 	int i;
3037c478bd9Sstevel@tonic-gate 
3047c478bd9Sstevel@tonic-gate 	for (p = snymList, i = n_snyms; --i >= 0; p++)
3057c478bd9Sstevel@tonic-gate 		if (sl_addr == p->sym_addr)
3067c478bd9Sstevel@tonic-gate 			return (p);
3077c478bd9Sstevel@tonic-gate 
3087c478bd9Sstevel@tonic-gate 	return ((struct snymEntry *)0);
3097c478bd9Sstevel@tonic-gate }
3107c478bd9Sstevel@tonic-gate 
3117c478bd9Sstevel@tonic-gate 
31292ed1782Smike_s int
main(int argc,char ** argv)31392ed1782Smike_s main(int argc, char **argv)
3147c478bd9Sstevel@tonic-gate {
3157c478bd9Sstevel@tonic-gate 	char buffer[BUFSIZ];	/* buffer for printf */
3167c478bd9Sstevel@tonic-gate 
3177c478bd9Sstevel@tonic-gate 	WORD *pcounts;	/* Pointer to allocated area for */
3187c478bd9Sstevel@tonic-gate 			/*	pcounts: PC clock hit counts */
3197c478bd9Sstevel@tonic-gate 
32092ed1782Smike_s 	WORD *pcp;	/* For scanning pcounts. */
3217c478bd9Sstevel@tonic-gate 
3227c478bd9Sstevel@tonic-gate 	struct cnt *ccounts;	/* Pointer to allocated area for cnt */
3237c478bd9Sstevel@tonic-gate 				/* structures: subr PC-call counts. */
3247c478bd9Sstevel@tonic-gate 
32592ed1782Smike_s 	struct cnt *ccp;	/* For scanning ccounts. */
3267c478bd9Sstevel@tonic-gate 
3277c478bd9Sstevel@tonic-gate 	struct slist *slist;	/* Pointer to allocated slist structures: */
3287c478bd9Sstevel@tonic-gate 				/* symbol name/address/time/call counts */
3297c478bd9Sstevel@tonic-gate 
33092ed1782Smike_s 	struct slist *slp;	/* For scanning slist */
3317c478bd9Sstevel@tonic-gate 
3327c478bd9Sstevel@tonic-gate 	int vn_cc, n_cc;	/* Number of cnt structures in profile data */
3337c478bd9Sstevel@tonic-gate 				/*	file (later # ones used). */
3347c478bd9Sstevel@tonic-gate 
3357c478bd9Sstevel@tonic-gate 	int n_pc;	/* Number of pcounts in profile data file. */
3367c478bd9Sstevel@tonic-gate 
3377c478bd9Sstevel@tonic-gate 	int n_syms;	/* Number of text symbols (of proper type) */
3387c478bd9Sstevel@tonic-gate 			/*	that fill in range of profiling. */
3397c478bd9Sstevel@tonic-gate 
3407c478bd9Sstevel@tonic-gate 	int n_nonzero;	/* Number of (above symbols) actually printed */
3417c478bd9Sstevel@tonic-gate 			/*	because nonzero time or # calls. */
3427c478bd9Sstevel@tonic-gate 
3437c478bd9Sstevel@tonic-gate 	int symttl;	/* Total # symbols in program file sym-table */
3447c478bd9Sstevel@tonic-gate 
3457c478bd9Sstevel@tonic-gate 	int i;
3467c478bd9Sstevel@tonic-gate 
3477c478bd9Sstevel@tonic-gate 	int fdigits = 0; /* # of digits of precision for print msecs/call */
3487c478bd9Sstevel@tonic-gate 
34992ed1782Smike_s 	int n, symct;
3507c478bd9Sstevel@tonic-gate 
3517c478bd9Sstevel@tonic-gate 	long sf;	/* Scale for index into pcounts: */
3527c478bd9Sstevel@tonic-gate 			/*	i(pc) = ((pc - pc_l) * sf)/bias. */
3537c478bd9Sstevel@tonic-gate 
3547c478bd9Sstevel@tonic-gate 	unsigned pc_m;	/* Range of PCs profiled: pc_m = pc_h - pc_l */
3557c478bd9Sstevel@tonic-gate 
3567c478bd9Sstevel@tonic-gate 	float	t, t0;
3577c478bd9Sstevel@tonic-gate 	float	t_tot;	/* Total time: PROFSEC(sum of all pcounts[i]) */
3587c478bd9Sstevel@tonic-gate 	int	callTotal = 0;
3597c478bd9Sstevel@tonic-gate 
3607c478bd9Sstevel@tonic-gate 	DEBUG_LOC("main: top");
3617c478bd9Sstevel@tonic-gate 	setbuf(stdout, buffer);
3627c478bd9Sstevel@tonic-gate 	cmdname = basename(*argv);	/* command name. */
3637c478bd9Sstevel@tonic-gate 
3647c478bd9Sstevel@tonic-gate 	while ((n = getopt(argc, argv, "canthsglzoxT:m:VC")) != EOF) {
3657c478bd9Sstevel@tonic-gate 		switch (n) {
3667c478bd9Sstevel@tonic-gate 		int (*fcn)();	/* For function to sort results. */
3677c478bd9Sstevel@tonic-gate 
3687c478bd9Sstevel@tonic-gate 		case 'm':	/* Specify data file:	-m file */
3697c478bd9Sstevel@tonic-gate 			mon_fn = optarg;
3707c478bd9Sstevel@tonic-gate 			break;
3717c478bd9Sstevel@tonic-gate 
3727c478bd9Sstevel@tonic-gate #ifdef ddt
3737c478bd9Sstevel@tonic-gate 		case 'T':	/* Set trace flags: -T(octnum) */
3747c478bd9Sstevel@tonic-gate 			debug_value = (int)strtol(optarg, 0, 8);
3757c478bd9Sstevel@tonic-gate 			break;
3767c478bd9Sstevel@tonic-gate #endif
3777c478bd9Sstevel@tonic-gate 
3787c478bd9Sstevel@tonic-gate 		case 'n':	/* Sort by symbol name. */
3797c478bd9Sstevel@tonic-gate 			fcn = c_name;
3807c478bd9Sstevel@tonic-gate 			sort_flag |= BY_NAME;
3817c478bd9Sstevel@tonic-gate 			goto check;
3827c478bd9Sstevel@tonic-gate 
3837c478bd9Sstevel@tonic-gate 		case 't':	/* Sort by decreasing time. */
3847c478bd9Sstevel@tonic-gate 			fcn = c_time;
3857c478bd9Sstevel@tonic-gate 			sort_flag |= BY_TIME;
3867c478bd9Sstevel@tonic-gate 			goto check;
3877c478bd9Sstevel@tonic-gate 
3887c478bd9Sstevel@tonic-gate 		case 'c':	/* Sort by decreasing # calls. */
3897c478bd9Sstevel@tonic-gate 			fcn = c_ncalls;
3907c478bd9Sstevel@tonic-gate 			sort_flag |= BY_NCALLS;
3917c478bd9Sstevel@tonic-gate 			goto check;
3927c478bd9Sstevel@tonic-gate 
3937c478bd9Sstevel@tonic-gate 		case 'a':	/* Sort by increasing symbol address */
3947c478bd9Sstevel@tonic-gate 				/*		(don't have to -- it will be) */
3957c478bd9Sstevel@tonic-gate 			fcn = NULL;
3967c478bd9Sstevel@tonic-gate 			sort_flag |= BY_ADDRESS;
3977c478bd9Sstevel@tonic-gate 		check:		/* Here to check sort option conflicts. */
3987c478bd9Sstevel@tonic-gate 			if (sort != NULL && sort != fcn) {
3997c478bd9Sstevel@tonic-gate 				Fprint(stderr, "%s: Warning: %c overrides"
4007c478bd9Sstevel@tonic-gate 				" previous specification\n", cmdname, n);
4017c478bd9Sstevel@tonic-gate 			}
4027c478bd9Sstevel@tonic-gate 			sort = fcn;	/* Store sort routine */
4037c478bd9Sstevel@tonic-gate 			flags |= F_SORT; /* Note have done so */
4047c478bd9Sstevel@tonic-gate 			break;
4057c478bd9Sstevel@tonic-gate 
4067c478bd9Sstevel@tonic-gate 		case 'o':	/* Include symbol addresses in output. */
4077c478bd9Sstevel@tonic-gate 		case 'x':	/* Include symbol addresses in output. */
4087c478bd9Sstevel@tonic-gate 			aformat[2] = n;	/* 'o' or 'x' in format */
4097c478bd9Sstevel@tonic-gate 			flags |= F_PADDR;	/* Set flag. */
4107c478bd9Sstevel@tonic-gate 			break;
4117c478bd9Sstevel@tonic-gate 
4127c478bd9Sstevel@tonic-gate 		case 'g':	/* Include local T symbols as well as global */
4137c478bd9Sstevel@tonic-gate 			gflag = 1;
4147c478bd9Sstevel@tonic-gate 			break;
4157c478bd9Sstevel@tonic-gate 
4167c478bd9Sstevel@tonic-gate 		case 'l':	/* Do NOT include local T symbols */
4177c478bd9Sstevel@tonic-gate 			gflag = 0;
4187c478bd9Sstevel@tonic-gate 			break;
4197c478bd9Sstevel@tonic-gate 
4207c478bd9Sstevel@tonic-gate 		case 'z':	/* Print all symbols in profiling range, */
4217c478bd9Sstevel@tonic-gate 				/*	 even if no time or # calls. */
4227c478bd9Sstevel@tonic-gate 			flags |= F_ZSYMS;	/* Set flag. */
4237c478bd9Sstevel@tonic-gate 			break;
4247c478bd9Sstevel@tonic-gate 
4257c478bd9Sstevel@tonic-gate 		case 'h':	/* Suppress table header. */
4267c478bd9Sstevel@tonic-gate 			flags |= F_NHEAD;
4277c478bd9Sstevel@tonic-gate 			break;
4287c478bd9Sstevel@tonic-gate 
4297c478bd9Sstevel@tonic-gate 		case 's':	/* Follow normal output with extra summary. */
4307c478bd9Sstevel@tonic-gate 			flags |= F_VERBOSE;	/* Set flag (...) */
4317c478bd9Sstevel@tonic-gate 			break;
4327c478bd9Sstevel@tonic-gate 
4337c478bd9Sstevel@tonic-gate 		case 'V':
4347c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, "prof: %s %s\n",
4357c478bd9Sstevel@tonic-gate 			    (const char *)SGU_PKG, (const char *)SGU_REL);
4367c478bd9Sstevel@tonic-gate 			VwasSpecified = 1;
4377c478bd9Sstevel@tonic-gate 			break;
4387c478bd9Sstevel@tonic-gate 
4397c478bd9Sstevel@tonic-gate 		case 'C':	/* demangle C++ names before printing. */
4407c478bd9Sstevel@tonic-gate 			Cflag = 1;
4417c478bd9Sstevel@tonic-gate 			break;
4427c478bd9Sstevel@tonic-gate 
4437c478bd9Sstevel@tonic-gate 		case '?':	/* But no good. */
44492ed1782Smike_s 			usage();
4457c478bd9Sstevel@tonic-gate 		}	/* End switch (n) */
4467c478bd9Sstevel@tonic-gate 	}	/* End while (getopt) */
4477c478bd9Sstevel@tonic-gate 
4487c478bd9Sstevel@tonic-gate 	DEBUG_LOC("main: following getopt");
4497c478bd9Sstevel@tonic-gate 
4507c478bd9Sstevel@tonic-gate 	/* if -V the only argument, just exit. */
4517c478bd9Sstevel@tonic-gate 	if (VwasSpecified && argc == 2 && !flags)
4527c478bd9Sstevel@tonic-gate 		exit(0);
4537c478bd9Sstevel@tonic-gate 
4547c478bd9Sstevel@tonic-gate 	if (optind < argc)
4557c478bd9Sstevel@tonic-gate 		sym_fn = argv[optind];	/* name other than `a.out' */
4567c478bd9Sstevel@tonic-gate 
4577c478bd9Sstevel@tonic-gate 	if (sort == NULL && !(flags & F_SORT))
4587c478bd9Sstevel@tonic-gate 				/* If have not specified sort mode ... */
4597c478bd9Sstevel@tonic-gate 		sort = c_time;		/* then sort by decreasing time. */
4607c478bd9Sstevel@tonic-gate 
4617c478bd9Sstevel@tonic-gate 	/*
4627c478bd9Sstevel@tonic-gate 	 * profver() checks to see if the mon.out was "versioned" and if
4637c478bd9Sstevel@tonic-gate 	 * yes, processes it and exits; otherwise, we have an *old-style*
4647c478bd9Sstevel@tonic-gate 	 * mon.out and we process it the old way.
4657c478bd9Sstevel@tonic-gate 	 */
4667c478bd9Sstevel@tonic-gate 	profver();
4677c478bd9Sstevel@tonic-gate 
4687c478bd9Sstevel@tonic-gate 		/* Open monitor data file (has counts). */
4697c478bd9Sstevel@tonic-gate 	if ((mon_iop = fopen(mon_fn, "r")) == NULL)
4707c478bd9Sstevel@tonic-gate 		Perror(mon_fn);
4717c478bd9Sstevel@tonic-gate 
4727c478bd9Sstevel@tonic-gate 	DEBUG_LOC("main: before _symintOpen");
4737c478bd9Sstevel@tonic-gate 	if ((ldptr = _symintOpen(sym_fn)) == NULL) {
4747c478bd9Sstevel@tonic-gate 		Perror("_symintOpen failed");
4757c478bd9Sstevel@tonic-gate 	}
4767c478bd9Sstevel@tonic-gate 	DEBUG_LOC("main: after _symintOpen");
4777c478bd9Sstevel@tonic-gate 	filhdr = *ldptr;
4787c478bd9Sstevel@tonic-gate 
4797c478bd9Sstevel@tonic-gate 	scnhdrp = ldptr->pf_shdarr_p;
4807c478bd9Sstevel@tonic-gate 
4817c478bd9Sstevel@tonic-gate 	{
4827c478bd9Sstevel@tonic-gate 	Elf_Kind k = elf_kind(filhdr.pf_elf_p);
4837c478bd9Sstevel@tonic-gate 
4847c478bd9Sstevel@tonic-gate 	DEBUG_EXP(printf("elf_kind = %d\n", k));
4857c478bd9Sstevel@tonic-gate 	DEBUG_EXP(printf("elf_type = %d\n", filhdr.pf_elfhd_p->e_type));
4867c478bd9Sstevel@tonic-gate 	if ((k != ELF_K_ELF) || (filhdr.pf_elfhd_p->e_type != ET_EXEC)) {
4877c478bd9Sstevel@tonic-gate 		Fprint(stderr, "%s: %s: improper format\n", cmdname, sym_fn);
4887c478bd9Sstevel@tonic-gate 		exit(1);
4897c478bd9Sstevel@tonic-gate 	}
4907c478bd9Sstevel@tonic-gate 	}
4917c478bd9Sstevel@tonic-gate 
4927c478bd9Sstevel@tonic-gate 	/* Compute the file address of symbol table. Machine-dependent. */
4937c478bd9Sstevel@tonic-gate 
4947c478bd9Sstevel@tonic-gate 	DEBUG_EXP(printf("number of symbols (pf_nsyms) = %d\n",
4951dd08564Sab 	    filhdr.pf_nsyms));
4967c478bd9Sstevel@tonic-gate 
4977c478bd9Sstevel@tonic-gate 		/* Number of symbols in file symbol table. */
4987c478bd9Sstevel@tonic-gate 	symttl = filhdr.pf_nsyms;
4997c478bd9Sstevel@tonic-gate 	if (symttl == 0) {		/* This is possible. */
5007c478bd9Sstevel@tonic-gate 		Fprint(stderr, "%s: %s: no symbols\n", cmdname, sym_fn);
5017c478bd9Sstevel@tonic-gate 		exit(0);		/* Note zero exit code. */
5027c478bd9Sstevel@tonic-gate 	}
5037c478bd9Sstevel@tonic-gate 	/* Get size of file containing profiling data. Read header part. */
5047c478bd9Sstevel@tonic-gate 	n = fsize(fileno(mon_iop));
5057c478bd9Sstevel@tonic-gate 	if (fread((char *)&head, sizeof (struct hdr), 1, mon_iop) != 1)
5067c478bd9Sstevel@tonic-gate 		eofon(mon_iop, mon_fn);		/* Probably junk file. */
5077c478bd9Sstevel@tonic-gate 
5087c478bd9Sstevel@tonic-gate 	/* Get # cnt structures (they follow header), */
5097c478bd9Sstevel@tonic-gate 	/*		and allocate space for them. */
5107c478bd9Sstevel@tonic-gate 
5117c478bd9Sstevel@tonic-gate 	n_cc = head.nfns;
51292ed1782Smike_s 	ccounts = _prof_Malloc(n_cc, sizeof (struct cnt));
5137c478bd9Sstevel@tonic-gate 
5147c478bd9Sstevel@tonic-gate 		/* Read the call addr-count pairs. */
5157c478bd9Sstevel@tonic-gate 	if (fread((char *)ccounts, sizeof (struct cnt), n_cc, mon_iop) != n_cc)
5167c478bd9Sstevel@tonic-gate 		eofon(mon_iop, mon_fn);
5177c478bd9Sstevel@tonic-gate 
5187c478bd9Sstevel@tonic-gate 	/*
5197c478bd9Sstevel@tonic-gate 	 * Compute # PC counters (pcounts), which occupy whatever is left
5207c478bd9Sstevel@tonic-gate 	 * of the file after the header and call counts.
5217c478bd9Sstevel@tonic-gate 	 */
5227c478bd9Sstevel@tonic-gate 
5237c478bd9Sstevel@tonic-gate 	n_pc = (n - sizeof (head) - n_cc * sizeof (struct cnt))/sizeof (WORD);
5247c478bd9Sstevel@tonic-gate 	ccp = &ccounts[n_cc];	/* Point to last (+1) of call counters ... */
5257c478bd9Sstevel@tonic-gate 	do {		/* and scan backward until find highest one used. */
5267c478bd9Sstevel@tonic-gate 		if ((--ccp)->mcnt)
5277c478bd9Sstevel@tonic-gate 			break;		/* Stop when find nonzero count. */
5287c478bd9Sstevel@tonic-gate 	} while (--n_cc > 0);		/* Or all are zero. */
5297c478bd9Sstevel@tonic-gate 
5307c478bd9Sstevel@tonic-gate 	if (n_cc > 0) {
5317c478bd9Sstevel@tonic-gate 
5327c478bd9Sstevel@tonic-gate 	/* If less than all cnt entries are used, return unused space. */
5337c478bd9Sstevel@tonic-gate 	if (n_cc < head.nfns) {
5347c478bd9Sstevel@tonic-gate 		if ((ccounts = (struct cnt *)realloc((char *)ccounts,
5357c478bd9Sstevel@tonic-gate 		    (unsigned)n_cc * sizeof (struct cnt))) == NULL)
5367c478bd9Sstevel@tonic-gate 			snh();	/* Should not fail when reducing size. */
5377c478bd9Sstevel@tonic-gate 	}
5387c478bd9Sstevel@tonic-gate 
5397c478bd9Sstevel@tonic-gate 	/* If more than 250 cnt entries used set verbose for warning */
5407c478bd9Sstevel@tonic-gate 	if (n_cc > (MPROGS0 * 5)/6)
5417c478bd9Sstevel@tonic-gate 		flags |= F_VERBOSE;
5427c478bd9Sstevel@tonic-gate 
5437c478bd9Sstevel@tonic-gate 		/* Space for PC counts. */
5447c478bd9Sstevel@tonic-gate 	pcounts = (WORD *)_prof_Malloc(n_pc, sizeof (WORD));
5457c478bd9Sstevel@tonic-gate 		/* Read the PC counts from rest of MON_OUT file. */
5467c478bd9Sstevel@tonic-gate 	if (fread((char *)pcounts, sizeof (WORD), n_pc, mon_iop) != n_pc)
5477c478bd9Sstevel@tonic-gate 		eofon(mon_iop, mon_fn);
5487c478bd9Sstevel@tonic-gate 	/*
5497c478bd9Sstevel@tonic-gate 	 *
5507c478bd9Sstevel@tonic-gate 	 * Having gotten preliminaries out of the way, get down to business.
5517c478bd9Sstevel@tonic-gate 	 * The range pc_m of addresses over which profiling was done is
5527c478bd9Sstevel@tonic-gate 	 * computed from the low (pc_l) and high (pc_h) addresses, gotten
5537c478bd9Sstevel@tonic-gate 	 * from the MON_OUT header.  From this and the number of clock
5547c478bd9Sstevel@tonic-gate 	 * tick counters, n_pc, is computed the so-called "scale", sf, used
5557c478bd9Sstevel@tonic-gate 	 * in the mapping of addresses to indices, as follows:
5567c478bd9Sstevel@tonic-gate 	 *
5577c478bd9Sstevel@tonic-gate 	 *		(pc - pc_l) * sf
5587c478bd9Sstevel@tonic-gate 	 *	i(pc) = ----------------
5597c478bd9Sstevel@tonic-gate 	 *		  0200000
5607c478bd9Sstevel@tonic-gate 	 *
5617c478bd9Sstevel@tonic-gate 	 * Also, the N-to-one value, s_inv, such that
5627c478bd9Sstevel@tonic-gate 	 *
5637c478bd9Sstevel@tonic-gate 	 *	i(pc_l + K * s_inv + d) = K, for 0 <= d < s_inv
5647c478bd9Sstevel@tonic-gate 	 *
5657c478bd9Sstevel@tonic-gate 	 * Following this, the symbol table is scanned, and those symbols
5667c478bd9Sstevel@tonic-gate 	 * that qualify are counted.  These  are T-type symbols, excluding
5677c478bd9Sstevel@tonic-gate 	 * local (nonglobal) unless the "-g" option was given. Having thus
5687c478bd9Sstevel@tonic-gate 	 * determined the space requirements, space for symbols/times etc.
5697c478bd9Sstevel@tonic-gate 	 * is allocated, and the symbol table re-read, this time keeping
5707c478bd9Sstevel@tonic-gate 	 * qualified symbols.
5717c478bd9Sstevel@tonic-gate 	 *
5727c478bd9Sstevel@tonic-gate 	 * NB s_inv, as actually computed, is not sufficiently accurate
5737c478bd9Sstevel@tonic-gate 	 * (since it is truncated) for many calculations.  Since it is
5747c478bd9Sstevel@tonic-gate 	 * logically equivalent to 1/(sf/bias), and the latter is much
5757c478bd9Sstevel@tonic-gate 	 * more accurate, therefore the latter will often appear in
5767c478bd9Sstevel@tonic-gate 	 * the code when 's_inv' is mentioned.  dween
5777c478bd9Sstevel@tonic-gate 	 *
5787c478bd9Sstevel@tonic-gate 	 */
5797c478bd9Sstevel@tonic-gate 
5807c478bd9Sstevel@tonic-gate 
5817c478bd9Sstevel@tonic-gate 	pc_l = head.lpc;	/* Low PC of range that was profiled. */
5827c478bd9Sstevel@tonic-gate 	pc_h = head.hpc;	/* First address past range of profiling. */
5837c478bd9Sstevel@tonic-gate 	pc_m = pc_h - pc_l;	/* Range of profiled addresses. */
5847c478bd9Sstevel@tonic-gate 
5851dd08564Sab 	/* BEGIN CSTYLED */
5867c478bd9Sstevel@tonic-gate OLD_DEBUG(if (debug_value) Fprint(stderr,
5877c478bd9Sstevel@tonic-gate "low pc = %#o, high pc = %#o, range = %#o = %u\n\
5887c478bd9Sstevel@tonic-gate call counts: %u, %u used; pc counters: %u\n",
5897c478bd9Sstevel@tonic-gate pc_l, pc_h, pc_m, pc_m, head.nfns, n_cc, n_pc));
5901dd08564Sab 	/* END CSTYLED */
5917c478bd9Sstevel@tonic-gate 
5921dd08564Sab 	/*LINTED: E_ASSIGMENT_CAUSE_LOSS_PREC*/
5937c478bd9Sstevel@tonic-gate 	sf = (BIAS * (double)n_pc)/pc_m;
5947c478bd9Sstevel@tonic-gate 	/*
5957c478bd9Sstevel@tonic-gate 	 * Now adjust bias and sf so that there is no overflow
5967c478bd9Sstevel@tonic-gate 	 * when calculating indices.
5977c478bd9Sstevel@tonic-gate 	 */
5987c478bd9Sstevel@tonic-gate 	bias = BIAS;
5997c478bd9Sstevel@tonic-gate 	temp = pc_m;
6007c478bd9Sstevel@tonic-gate 	while ((temp >>= 1) > 0x7fff) {
6017c478bd9Sstevel@tonic-gate 		sf >>= 1;
6027c478bd9Sstevel@tonic-gate 		bias >>= 1;
6037c478bd9Sstevel@tonic-gate 	}
6047c478bd9Sstevel@tonic-gate 
6051dd08564Sab 	/* BEGIN CSTYLED */
6067c478bd9Sstevel@tonic-gate OLD_DEBUG(
6077c478bd9Sstevel@tonic-gate 	if (debug_value) {
608c3f7a870SToomas Soome 
609c3f7a870SToomas Soome 		Fprint(stderr, "sf = %d, s_inv = %d bias = %d\n",
610c3f7a870SToomas Soome 		    (long)sf, pc_m / n_pc, bias);
6117c478bd9Sstevel@tonic-gate 	}
6127c478bd9Sstevel@tonic-gate );
6131dd08564Sab 	/* END CSTYLED */
6147c478bd9Sstevel@tonic-gate 
6157c478bd9Sstevel@tonic-gate 		/* Prepare to read symbols from "a.out" (or whatever). */
6167c478bd9Sstevel@tonic-gate 	n_syms = 0;			/* Init count of qualified symbols. */
6177c478bd9Sstevel@tonic-gate 	n = symttl;			/* Total symbols. */
6187c478bd9Sstevel@tonic-gate 	while (--n >= 0)			/* Scan symbol table. */
6197c478bd9Sstevel@tonic-gate 		if (readnl(n))	/* Read and examine symbol, count qualifiers */
6207c478bd9Sstevel@tonic-gate 			n_syms++;
6217c478bd9Sstevel@tonic-gate 
6221dd08564Sab 	/* BEGIN CSTYLED */
6237c478bd9Sstevel@tonic-gate OLD_DEBUG(
6247c478bd9Sstevel@tonic-gate 	if (debug_value) {
6257c478bd9Sstevel@tonic-gate 		Fprint(stderr, "%u symbols, %u qualify\n", symttl, n_syms);
6267c478bd9Sstevel@tonic-gate 	}
6277c478bd9Sstevel@tonic-gate );
6281dd08564Sab 	/* END CSTYLED */
6297c478bd9Sstevel@tonic-gate 
6307c478bd9Sstevel@tonic-gate 		/* Allocate space for qualified symbols. */
6317c478bd9Sstevel@tonic-gate 
63292ed1782Smike_s 	slist = slp = _prof_Malloc(n_syms, sizeof (struct slist));
6337c478bd9Sstevel@tonic-gate 
6347c478bd9Sstevel@tonic-gate 		/*
6357c478bd9Sstevel@tonic-gate 		 * Allocate space for synonym symbols
6367c478bd9Sstevel@tonic-gate 		 * (i.e. symbols that refer to the same address).
6377c478bd9Sstevel@tonic-gate 		 * NB there can be no more than n_syms/2 addresses
6387c478bd9Sstevel@tonic-gate 		 * with symbols, That Have Aliases, that refer to them!
6397c478bd9Sstevel@tonic-gate 		 */
6407c478bd9Sstevel@tonic-gate 
6417c478bd9Sstevel@tonic-gate 	snymCapacity = n_syms/2;
6421dd08564Sab 	snymList = snymp =
6431dd08564Sab 	    _prof_Malloc(snymCapacity, sizeof (struct snymEntry));
6447c478bd9Sstevel@tonic-gate 	n_snyms = 0;
6457c478bd9Sstevel@tonic-gate 
6467c478bd9Sstevel@tonic-gate /* OLD_DEBUG(debug_value &= ~020); */
6477c478bd9Sstevel@tonic-gate 
6487c478bd9Sstevel@tonic-gate 	/* Loop on number of qualified symbols. */
6497c478bd9Sstevel@tonic-gate 	for (n = n_syms, symct = 0; n > 0; symct++) {
6507c478bd9Sstevel@tonic-gate 		if (readnl(symct)) {	/* Get one. Check again. */
6517c478bd9Sstevel@tonic-gate 				/* Is qualified. Move name ... */
6527c478bd9Sstevel@tonic-gate 			slp->sl_name = getname(ldptr, nl);
6537c478bd9Sstevel@tonic-gate 
6547c478bd9Sstevel@tonic-gate 				/* and address into slist structure. */
6557c478bd9Sstevel@tonic-gate 			slp->sl_addr = (char *)nl.ps_sym.st_value;
6567c478bd9Sstevel@tonic-gate 			slp->sl_size = nl.ps_sym.st_size;
6577c478bd9Sstevel@tonic-gate 
6587c478bd9Sstevel@tonic-gate 				/* set other slist fields to zero. */
6597c478bd9Sstevel@tonic-gate 			slp->sl_time = 0.0;
6607c478bd9Sstevel@tonic-gate 			slp->sl_count = 0;
6611dd08564Sab 	/* BEGIN CSTYLED */
6627c478bd9Sstevel@tonic-gate OLD_DEBUG(
6637c478bd9Sstevel@tonic-gate 	if (debug_value & 02)
6647c478bd9Sstevel@tonic-gate 		Fprint(stderr, "%-8.8s: %#8o\n", slp->sl_name, slp->sl_addr)
6657c478bd9Sstevel@tonic-gate );
6661dd08564Sab 	/* END CSTYLED */
6677c478bd9Sstevel@tonic-gate 
6687c478bd9Sstevel@tonic-gate 			slp++;
6697c478bd9Sstevel@tonic-gate 			--n;
6707c478bd9Sstevel@tonic-gate 		}
6717c478bd9Sstevel@tonic-gate 	}
6727c478bd9Sstevel@tonic-gate 	/*
6737c478bd9Sstevel@tonic-gate 	 *
6747c478bd9Sstevel@tonic-gate 	 * Now attempt to match call counts with symbols.  To do this, it
6757c478bd9Sstevel@tonic-gate 	 * helps to first sort both the symbols and the call address/count
6767c478bd9Sstevel@tonic-gate 	 * pairs by ascending address, since they are generally not, to
6777c478bd9Sstevel@tonic-gate 	 * begin with.  The addresses associated with the counts are not,
6787c478bd9Sstevel@tonic-gate 	 * of course, the subroutine addresses associated with the symbols,
6797c478bd9Sstevel@tonic-gate 	 * but some address slightly past these. Therefore a given count
6807c478bd9Sstevel@tonic-gate 	 * address (in the fnpc field) is matched with the closest symbol
6817c478bd9Sstevel@tonic-gate 	 * address (sl_addr) that is:
6827c478bd9Sstevel@tonic-gate 	 *	(1) less than the fnpc value but,
6837c478bd9Sstevel@tonic-gate 	 *	(2) not more than the length of the function
6847c478bd9Sstevel@tonic-gate 	 * In other words, unreasonable matchups are avoided.
6857c478bd9Sstevel@tonic-gate 	 * Situations such as this could arise when static procedures are
6867c478bd9Sstevel@tonic-gate 	 * counted but the "-g" option was not given to this program,
6877c478bd9Sstevel@tonic-gate 	 * causing the symbol to fail to qualify.  Without this limitation,
6887c478bd9Sstevel@tonic-gate 	 * unmatched counts could be erroneously charged.
6897c478bd9Sstevel@tonic-gate 	 *
6907c478bd9Sstevel@tonic-gate 	 */
6917c478bd9Sstevel@tonic-gate 
6927c478bd9Sstevel@tonic-gate 
6937c478bd9Sstevel@tonic-gate 	ccp = ccounts;			/* Point to first call counter. */
6947c478bd9Sstevel@tonic-gate 	slp = slist;			/*   "		"   "   symbol. */
6957c478bd9Sstevel@tonic-gate 		/* Sort call counters and ... */
6967c478bd9Sstevel@tonic-gate 	qsort((char *)ccp, (unsigned)n_cc, sizeof (struct cnt), c_ccaddr);
6977c478bd9Sstevel@tonic-gate 		/* symbols by increasing address. */
6987c478bd9Sstevel@tonic-gate 	qsort((char *)slp, (unsigned)n_syms, sizeof (struct slist), c_sladdr);
6997c478bd9Sstevel@tonic-gate 	vn_cc = n_cc;			/* save this for verbose option */
7007c478bd9Sstevel@tonic-gate 
7017c478bd9Sstevel@tonic-gate 
7027c478bd9Sstevel@tonic-gate 		/* Loop to match up call counts & symbols. */
7037c478bd9Sstevel@tonic-gate 	for (n = n_syms; n > 0 && vn_cc > 0; ) {
7047c478bd9Sstevel@tonic-gate 		int	sz = slp->sl_size;
7057c478bd9Sstevel@tonic-gate 
7067c478bd9Sstevel@tonic-gate 		if (sz == 0)
7071dd08564Sab 			sz = slp[ 1 ].sl_addr - slp->sl_addr;
7087c478bd9Sstevel@tonic-gate 		if (slp->sl_addr < ccp->fnpc &&
7097c478bd9Sstevel@tonic-gate 		    ccp->fnpc <= slp->sl_addr + sz) {
7107c478bd9Sstevel@tonic-gate 					/* got a candidate: find Closest. */
7117c478bd9Sstevel@tonic-gate 			struct slist *closest_symp;
7127c478bd9Sstevel@tonic-gate 			do {
7137c478bd9Sstevel@tonic-gate 				closest_symp = slp;
7147c478bd9Sstevel@tonic-gate 				slp++;
7157c478bd9Sstevel@tonic-gate 				--n;
7167c478bd9Sstevel@tonic-gate 			} while (n > 0 && slp->sl_addr < ccp->fnpc);
7177c478bd9Sstevel@tonic-gate 
7181dd08564Sab 	/* BEGIN CSTYLED */
7197c478bd9Sstevel@tonic-gate OLD_DEBUG(
7207c478bd9Sstevel@tonic-gate if (debug_value & 04) {
7217c478bd9Sstevel@tonic-gate 	Fprint(stderr,
7227c478bd9Sstevel@tonic-gate 		"Routine %-8.8s @ %#8x+%-2d matches count address %#8x\n",
7237c478bd9Sstevel@tonic-gate 		closest_symp->sl_name,
7247c478bd9Sstevel@tonic-gate 		closest_symp->sl_addr,
7257c478bd9Sstevel@tonic-gate 		ccp->fnpc-slp->sl_addr,
7267c478bd9Sstevel@tonic-gate 		ccp->fnpc);
7277c478bd9Sstevel@tonic-gate }
7287c478bd9Sstevel@tonic-gate );
7291dd08564Sab 	/* END CSTYLED */
7307c478bd9Sstevel@tonic-gate 			closest_symp->sl_count = ccp->mcnt;  /* Copy count. */
7317c478bd9Sstevel@tonic-gate 			++ccp;
7327c478bd9Sstevel@tonic-gate 			--vn_cc;
7337c478bd9Sstevel@tonic-gate 		} else if (ccp->fnpc < slp->sl_addr) {
7347c478bd9Sstevel@tonic-gate 			++ccp;
7357c478bd9Sstevel@tonic-gate 			--vn_cc;
7367c478bd9Sstevel@tonic-gate 		} else {
7377c478bd9Sstevel@tonic-gate 			++slp;
7387c478bd9Sstevel@tonic-gate 			--n;
7397c478bd9Sstevel@tonic-gate 		}
7407c478bd9Sstevel@tonic-gate 	}
7417c478bd9Sstevel@tonic-gate 
7427c478bd9Sstevel@tonic-gate 	/*
7437c478bd9Sstevel@tonic-gate 	 *
7447c478bd9Sstevel@tonic-gate 	 * The distribution of times to addresses is done on a proportional
7457c478bd9Sstevel@tonic-gate 	 * basis as follows: The t counts in pcounts[i] correspond to clock
7467c478bd9Sstevel@tonic-gate 	 * ticks for values of pc in the range pc, pc+1, ..., pc+s_inv-1
7477c478bd9Sstevel@tonic-gate 	 * (odd addresses excluded for PDP11s). Without more detailed info,
7487c478bd9Sstevel@tonic-gate 	 * it must be assumed that there is no greater probability
7497c478bd9Sstevel@tonic-gate 	 * of the clock ticking for any particular pc in this range than for
7507c478bd9Sstevel@tonic-gate 	 * any other.  Thus the t counts are considered to be equally
7517c478bd9Sstevel@tonic-gate 	 * distributed over the addresses in the range, and that the time for
7527c478bd9Sstevel@tonic-gate 	 * any given address in the range is pcounts[i]/s_inv.
7537c478bd9Sstevel@tonic-gate 	 *
7547c478bd9Sstevel@tonic-gate 	 * The values of the symbols that qualify, bounded below and above
7557c478bd9Sstevel@tonic-gate 	 * by pc_l and pc_h, respectively, partition the profiling range into
7567c478bd9Sstevel@tonic-gate 	 * regions to which are assigned the total times associated with the
7577c478bd9Sstevel@tonic-gate 	 * addresses they contain in the following way:
7587c478bd9Sstevel@tonic-gate 	 *
7597c478bd9Sstevel@tonic-gate 	 * The sum of all pcounts[i] for which the corresponding addresses are
7607c478bd9Sstevel@tonic-gate 	 * wholly within the partition are charged to the partition (the
7617c478bd9Sstevel@tonic-gate 	 * subroutine whose address is the lower bound of the partition).
7627c478bd9Sstevel@tonic-gate 	 *
7637c478bd9Sstevel@tonic-gate 	 * If the range of addresses corresponding to a given t = pcounts[i]
7647c478bd9Sstevel@tonic-gate 	 * lies astraddle the boundary of a partition, e.g., for some k such
7657c478bd9Sstevel@tonic-gate 	 * that 0 < k < s_inv-1, the addresses pc, pc+1, ..., pc+k-1 are in
7667c478bd9Sstevel@tonic-gate 	 * the lower partition, and the addresses pc+k, pc+k+1, ..., pc+s_inv-1
7677c478bd9Sstevel@tonic-gate 	 * are in the next partition, then k*pcounts[i]/s_inv time is charged
7687c478bd9Sstevel@tonic-gate 	 * to the lower partition, and (s_inv-k) * pcounts[i]/s_inv time to the
7697c478bd9Sstevel@tonic-gate 	 * upper.  It is conceivable, in cases of large granularity or small
7707c478bd9Sstevel@tonic-gate 	 * subroutines, for a range corresponding to a given pcounts[i] to
7717c478bd9Sstevel@tonic-gate 	 * overlap three regions, completely containing the (small) middle one.
7727c478bd9Sstevel@tonic-gate 	 * The algorithm is adjusted appropriately in this case.
7737c478bd9Sstevel@tonic-gate 	 *
7747c478bd9Sstevel@tonic-gate 	 */
7757c478bd9Sstevel@tonic-gate 
7767c478bd9Sstevel@tonic-gate 
7777c478bd9Sstevel@tonic-gate 	pcp = pcounts;				/* Reset to base. */
7787c478bd9Sstevel@tonic-gate 	slp = slist;				/* Ditto. */
7797c478bd9Sstevel@tonic-gate 	t0 = 0.0;				/* Time accumulator. */
7807c478bd9Sstevel@tonic-gate 	for (n = 0; n < n_syms; n++) {		/* Loop on symbols. */
7817c478bd9Sstevel@tonic-gate 			/* Start addr of region, low addr of overlap. */
7827c478bd9Sstevel@tonic-gate 		char *pc0, *pc00;
7837c478bd9Sstevel@tonic-gate 			/* Start addr of next region, low addr of overlap. */
7847c478bd9Sstevel@tonic-gate 		char *pc1, *pc10;
7857c478bd9Sstevel@tonic-gate 		/* First index into pcounts for this region and next region. */
78692ed1782Smike_s 		int i0, i1;
7877c478bd9Sstevel@tonic-gate 		long ticks;
7887c478bd9Sstevel@tonic-gate 
7897c478bd9Sstevel@tonic-gate 			/* Address of symbol (subroutine). */
7907c478bd9Sstevel@tonic-gate 		pc0 = slp[n].sl_addr;
7917c478bd9Sstevel@tonic-gate 
7927c478bd9Sstevel@tonic-gate 			/* Address of next symbol, if any or top */
7937c478bd9Sstevel@tonic-gate 			/* of profile range, if not */
7947c478bd9Sstevel@tonic-gate 		pc1 = (n < n_syms - 1) ? slp[n+1].sl_addr : pc_h;
7957c478bd9Sstevel@tonic-gate 
7967c478bd9Sstevel@tonic-gate 			/* Lower bound of indices into pcounts for this range */
7977c478bd9Sstevel@tonic-gate 
7987c478bd9Sstevel@tonic-gate 		i0 = (((unsigned)pc0 - (unsigned)pc_l) * sf)/bias;
7997c478bd9Sstevel@tonic-gate 
8007c478bd9Sstevel@tonic-gate 			/* Upper bound (least or least + 1) of indices. */
8017c478bd9Sstevel@tonic-gate 		i1 = (((unsigned)pc1 - (unsigned)pc_l) * sf)/bias;
8027c478bd9Sstevel@tonic-gate 
8037c478bd9Sstevel@tonic-gate 		if (i1 >= n_pc)				/* If past top, */
8047c478bd9Sstevel@tonic-gate 			i1 = n_pc - 1;				/* adjust. */
8057c478bd9Sstevel@tonic-gate 
8067c478bd9Sstevel@tonic-gate 			/* Lowest addr for which count maps to pcounts[i0]; */
8077c478bd9Sstevel@tonic-gate 		pc00 =  pc_l + (unsigned long)((bias * i0)/sf);
8087c478bd9Sstevel@tonic-gate 
8097c478bd9Sstevel@tonic-gate 			/* Lowest addr for which count maps to pcounts[i1]. */
8107c478bd9Sstevel@tonic-gate 		pc10 =  pc_l + (unsigned long)((bias * i1)/sf);
8117c478bd9Sstevel@tonic-gate 
8121dd08564Sab 	/* BEGIN CSTYLED */
8137c478bd9Sstevel@tonic-gate OLD_DEBUG(if (debug_value & 010) Fprint(stderr,
8147c478bd9Sstevel@tonic-gate "%-8.8s\ti0 = %4d, pc00 = %#6o, pc0 = %#6o\n\
8157c478bd9Sstevel@tonic-gate \t\ti1 = %4d, pc10 = %#6o, pc1 = %#6o\n\t\t",
8167c478bd9Sstevel@tonic-gate slp[n].sl_name, i0, pc00, pc0, i1, pc10, pc1));
8171dd08564Sab 	/* END CSTYLED */
8187c478bd9Sstevel@tonic-gate 		t = 0;			/* Init time for this symbol. */
8197c478bd9Sstevel@tonic-gate 		if (i0 == i1) {
8207c478bd9Sstevel@tonic-gate 			/* Counter overlaps two areas? (unlikely */
8217c478bd9Sstevel@tonic-gate 			/* unless large granularity). */
8227c478bd9Sstevel@tonic-gate 			ticks = pcp[i0];	/* # Times (clock ticks). */
8237c478bd9Sstevel@tonic-gate OLD_DEBUG(if (debug_value & 010) fprintf(stderr, "ticks = %d\n", ticks));
8247c478bd9Sstevel@tonic-gate 
8257c478bd9Sstevel@tonic-gate 			    /* Time less that which overlaps adjacent areas */
8267c478bd9Sstevel@tonic-gate 			t += PROFSEC(ticks * ((double)(pc1 - pc0) * sf)/bias);
8277c478bd9Sstevel@tonic-gate 
8281dd08564Sab 	/* BEGIN CSTYLED */
8297c478bd9Sstevel@tonic-gate OLD_DEBUG(if (debug_value & 010)
8307c478bd9Sstevel@tonic-gate 	Fprint(stderr, "%ld/(%.1f)", (pc1 - pc0) * ticks, DBL_ADDRPERCELL)
8317c478bd9Sstevel@tonic-gate );
8321dd08564Sab 	/* END CSTYLED */
8337c478bd9Sstevel@tonic-gate 		} else {
8347c478bd9Sstevel@tonic-gate 				/* Overlap with previous region? */
8357c478bd9Sstevel@tonic-gate 			if (pc00 < pc0) {
8367c478bd9Sstevel@tonic-gate 				ticks = pcp[i0];
8371dd08564Sab 	/* BEGIN CSTYLED */
8387c478bd9Sstevel@tonic-gate OLD_DEBUG(if (debug_value & 010)
8397c478bd9Sstevel@tonic-gate 	fprintf(stderr, "pc00 < pc0 ticks = %d\n", ticks));
8407c478bd9Sstevel@tonic-gate 
8417c478bd9Sstevel@tonic-gate 				/* Get time of overlapping area and */
8427c478bd9Sstevel@tonic-gate 				/* subtract proportion for lower region. */
8437c478bd9Sstevel@tonic-gate 				t += PROFSEC(
8447c478bd9Sstevel@tonic-gate 				ticks*(1-((double)(pc0-pc00) *sf)/bias));
8457c478bd9Sstevel@tonic-gate 
8467c478bd9Sstevel@tonic-gate 				/* Do not count this time when summing times */
8477c478bd9Sstevel@tonic-gate 				/*		wholly within the region. */
8487c478bd9Sstevel@tonic-gate 				i0++;
8491dd08564Sab 	/* BEGIN CSTYLED */
8507c478bd9Sstevel@tonic-gate OLD_DEBUG(if (debug_value & 010)
8517c478bd9Sstevel@tonic-gate 	Fprint(stderr, "%ld/(%.1f) + ", (pc0 - pc00) * ticks,
8527c478bd9Sstevel@tonic-gate 		DBL_ADDRPERCELL));
8531dd08564Sab 	/* END CSTYLED */
8547c478bd9Sstevel@tonic-gate 			}
8557c478bd9Sstevel@tonic-gate 
8567c478bd9Sstevel@tonic-gate 			/* Init sum of counts for PCs not shared w/other */
8577c478bd9Sstevel@tonic-gate 			/*	routines. */
8587c478bd9Sstevel@tonic-gate 			ticks = 0;
8597c478bd9Sstevel@tonic-gate 
8607c478bd9Sstevel@tonic-gate 			/* Stop at first count that overlaps following */
8617c478bd9Sstevel@tonic-gate 			/*	routine. */
8627c478bd9Sstevel@tonic-gate 			for (i = i0; i < i1; i++)
8637c478bd9Sstevel@tonic-gate 				ticks += pcp[i];
8647c478bd9Sstevel@tonic-gate 
8657c478bd9Sstevel@tonic-gate 			t += PROFSEC(ticks); /* Convert to secs, add to total */
8667c478bd9Sstevel@tonic-gate OLD_DEBUG(if (debug_value & 010) Fprint(stderr, "%ld", ticks));
8677c478bd9Sstevel@tonic-gate 			/* Some overlap with low addresses of next routine? */
8687c478bd9Sstevel@tonic-gate 			if (pc10 < pc1) {
8697c478bd9Sstevel@tonic-gate 					/* Yes. Get total count ... */
8707c478bd9Sstevel@tonic-gate 				ticks = pcp[i1];
8717c478bd9Sstevel@tonic-gate 
8727c478bd9Sstevel@tonic-gate 				/* and accumulate proportion for addresses in */
8737c478bd9Sstevel@tonic-gate 				/*		range of this routine */
8747c478bd9Sstevel@tonic-gate 				t += PROFSEC(((double)ticks *
8751dd08564Sab 				    (pc1 - pc10)*sf)/bias);
8761dd08564Sab 	/* BEGIN CSTYLED */
8777c478bd9Sstevel@tonic-gate OLD_DEBUG(if (debug_value & 010) fprintf(stderr, "ticks = %d\n", ticks));
8787c478bd9Sstevel@tonic-gate OLD_DEBUG(if (debug_value & 010)
8797c478bd9Sstevel@tonic-gate 	Fprint(stderr, " + %ld/(%.1f)", (pc1 - pc10) * ticks, DBL_ADDRPERCELL)
8807c478bd9Sstevel@tonic-gate );
8811dd08564Sab 	/* END CSTYLED */
8827c478bd9Sstevel@tonic-gate 			}
8837c478bd9Sstevel@tonic-gate 		}		/* End if (i0 == i1) ... else ... */
8847c478bd9Sstevel@tonic-gate 
8857c478bd9Sstevel@tonic-gate 		slp[n].sl_time = t;	/* Store time for this routine. */
8867c478bd9Sstevel@tonic-gate 		t0 += t;		/* Accumulate total time. */
8877c478bd9Sstevel@tonic-gate OLD_DEBUG(if (debug_value & 010) Fprint(stderr, " ticks = %.2f msec\n", t));
8887c478bd9Sstevel@tonic-gate 	}	/* End for (n = 0; n < n_syms; n++) */
8897c478bd9Sstevel@tonic-gate 
8907c478bd9Sstevel@tonic-gate 	/* Final pass to total up time. */
8917c478bd9Sstevel@tonic-gate 	/* Sum ticks, then convert to seconds. */
8927c478bd9Sstevel@tonic-gate 
8931dd08564Sab 	for (n = n_pc, temp = 0; --n >= 0; temp += *(pcp++))
8941dd08564Sab 		;
8957c478bd9Sstevel@tonic-gate 
8967c478bd9Sstevel@tonic-gate 	t_tot = PROFSEC(temp);
8977c478bd9Sstevel@tonic-gate 
8987c478bd9Sstevel@tonic-gate 	/*
8997c478bd9Sstevel@tonic-gate 	 * Now, whilst we still have the symbols sorted
9007c478bd9Sstevel@tonic-gate 	 * in address order..
9017c478bd9Sstevel@tonic-gate 	 * Loop to record duplicates, so we can display
9027c478bd9Sstevel@tonic-gate 	 * synonym symbols correctly.
9037c478bd9Sstevel@tonic-gate 	 * Synonym symbols, or symbols with the same address,
9047c478bd9Sstevel@tonic-gate 	 * are to be displayed by prof on the same line, with
9057c478bd9Sstevel@tonic-gate 	 * one statistics line, as below:
9067c478bd9Sstevel@tonic-gate 	 *			... 255  ldaopen, ldaopen
9077c478bd9Sstevel@tonic-gate 	 * The way this will be implemented, is as follows:
9087c478bd9Sstevel@tonic-gate 	 *
9097c478bd9Sstevel@tonic-gate 	 * Pass 1 - while the symbols are in address order, we
9107c478bd9Sstevel@tonic-gate 	 *  do a pre-pass through them, to determine for which
9117c478bd9Sstevel@tonic-gate 	 *  addresses there are more than one symbol (i.e. synonyms).
9127c478bd9Sstevel@tonic-gate 	 *  During this prepass we collect summary statistics in
9137c478bd9Sstevel@tonic-gate 	 *  the synonym entry, for all the synonyms.
9147c478bd9Sstevel@tonic-gate 	 *
9157c478bd9Sstevel@tonic-gate 	 * 'Pass' 2 - while printing a report,  for each report line,
9167c478bd9Sstevel@tonic-gate 	 *  if the current symbol is a synonym symbol (i.e. in the
9177c478bd9Sstevel@tonic-gate 	 *  snymList) then we scan forward and pick up all the names
9187c478bd9Sstevel@tonic-gate 	 *  which map to this address, and print them too.
9197c478bd9Sstevel@tonic-gate 	 *  If the address' synonyms have already been printed, then
9207c478bd9Sstevel@tonic-gate 	 *  we just skip this symbol and go on to process the next.
9217c478bd9Sstevel@tonic-gate 	 *
9227c478bd9Sstevel@tonic-gate 	 */
9237c478bd9Sstevel@tonic-gate 
9247c478bd9Sstevel@tonic-gate 	{
9257c478bd9Sstevel@tonic-gate 	/* pass 1 */
9267c478bd9Sstevel@tonic-gate 	char *thisaddr;
9277c478bd9Sstevel@tonic-gate 	char *lastaddr = slist->sl_addr; /* use 1st sym as */
9287c478bd9Sstevel@tonic-gate 					/* 'last/prior symbol' */
9297c478bd9Sstevel@tonic-gate 	int lastWasSnym = 0;	/* 1st can't be snym yet-no aliases seen! */
9307c478bd9Sstevel@tonic-gate 	int thisIsSnym;
9317c478bd9Sstevel@tonic-gate 
9321dd08564Sab 	/* BEGIN CSTYLED */
9337c478bd9Sstevel@tonic-gate OLD_DEBUG(
9347c478bd9Sstevel@tonic-gate int totsnyms = 0; int totseries = 0; struct slist *lastslp = slist;
9357c478bd9Sstevel@tonic-gate );
9361dd08564Sab 	/* END CSTYLED */
9377c478bd9Sstevel@tonic-gate 
9387c478bd9Sstevel@tonic-gate 	/* NB loop starts with 2nd symbol, loops over n_syms-1 symbols! */
9397c478bd9Sstevel@tonic-gate 	for (n = n_syms-1, slp = slist+1; --n >= 0; slp++) {
9407c478bd9Sstevel@tonic-gate 		thisaddr = slp->sl_addr;
9417c478bd9Sstevel@tonic-gate 		thisIsSnym = (thisaddr == lastaddr);
9427c478bd9Sstevel@tonic-gate 
9437c478bd9Sstevel@tonic-gate 		if (thisIsSnym) {
9447c478bd9Sstevel@tonic-gate 			/* gotta synonym */
9457c478bd9Sstevel@tonic-gate 			if (!lastWasSnym) {
9461dd08564Sab 	/* BEGIN CSTYLED */
9477c478bd9Sstevel@tonic-gate OLD_DEBUG(
9487c478bd9Sstevel@tonic-gate if (debug_value)  {
9497c478bd9Sstevel@tonic-gate 	Fprint(stderr,
9507c478bd9Sstevel@tonic-gate 		"Synonym series:\n1st->\t%s at address %x, ct=%ld, time=%f\n",
9517c478bd9Sstevel@tonic-gate 		lastslp->sl_name, lastaddr, lastslp->sl_count,
9527c478bd9Sstevel@tonic-gate 		lastslp->sl_time);
9537c478bd9Sstevel@tonic-gate 	totseries++;
9547c478bd9Sstevel@tonic-gate 	totsnyms++;
9557c478bd9Sstevel@tonic-gate }
9567c478bd9Sstevel@tonic-gate );
9571dd08564Sab 	/* END CSTYLED */
9587c478bd9Sstevel@tonic-gate 				/* this is the Second! of a series */
9597c478bd9Sstevel@tonic-gate 				snymp = (n_snyms++ == 0 ? snymList : snymp+1);
9607c478bd9Sstevel@tonic-gate 				snymp->howMany = 1; /* gotta count 1st one!! */
9617c478bd9Sstevel@tonic-gate 				snymp->sym_addr = slp->sl_addr;
9627c478bd9Sstevel@tonic-gate 				/* zero summary statistics */
9637c478bd9Sstevel@tonic-gate 				snymp->tot_sl_count = 0;
9647c478bd9Sstevel@tonic-gate 				snymp->tot_sl_time = 0.0;
9657c478bd9Sstevel@tonic-gate 				/* Offen the Reported flag */
9667c478bd9Sstevel@tonic-gate 				snymp->snymReported = 0;
9677c478bd9Sstevel@tonic-gate 			}
9681dd08564Sab 	/* BEGIN CSTYLED */
9697c478bd9Sstevel@tonic-gate OLD_DEBUG(
9707c478bd9Sstevel@tonic-gate if (debug_value)  {
9717c478bd9Sstevel@tonic-gate 	Fprint(stderr,
9727c478bd9Sstevel@tonic-gate 		"\t%s at address %x, ct=%ld, time=%f\n",
9737c478bd9Sstevel@tonic-gate 		slp->sl_name,
9747c478bd9Sstevel@tonic-gate 		thisaddr,
9757c478bd9Sstevel@tonic-gate 		slp->sl_count,
9767c478bd9Sstevel@tonic-gate 		slp->sl_time);
9777c478bd9Sstevel@tonic-gate 	totsnyms++;
9787c478bd9Sstevel@tonic-gate }
9797c478bd9Sstevel@tonic-gate );
9801dd08564Sab 	/* END CSTYLED */
9817c478bd9Sstevel@tonic-gate 			/* ok - bump count for snym, and note its Finding */
9827c478bd9Sstevel@tonic-gate 			snymp->howMany++;
9837c478bd9Sstevel@tonic-gate 			/* and update the summary statistics */
9847c478bd9Sstevel@tonic-gate 			snymp->tot_sl_count += slp->sl_count;
9857c478bd9Sstevel@tonic-gate 			snymp->tot_sl_time += slp->sl_time;
9867c478bd9Sstevel@tonic-gate 		}
9877c478bd9Sstevel@tonic-gate 		callTotal += slp->sl_count;
9887c478bd9Sstevel@tonic-gate 		lastaddr = thisaddr;
9897c478bd9Sstevel@tonic-gate 		lastWasSnym = thisIsSnym;
9901dd08564Sab 	/* BEGIN CSTYLED */
9917c478bd9Sstevel@tonic-gate OLD_DEBUG(
9927c478bd9Sstevel@tonic-gate if (debug_value) lastslp = slp;
9937c478bd9Sstevel@tonic-gate );
9941dd08564Sab 	/* END CSTYLED */
9957c478bd9Sstevel@tonic-gate 
9967c478bd9Sstevel@tonic-gate 	}
9971dd08564Sab 	/* BEGIN CSTYLED */
9987c478bd9Sstevel@tonic-gate OLD_DEBUG(
9997c478bd9Sstevel@tonic-gate if (debug_value)  {
10007c478bd9Sstevel@tonic-gate 	Fprint(stderr, "Total #series %d, #synonyms %d\n", totseries, totsnyms);
10017c478bd9Sstevel@tonic-gate }
10027c478bd9Sstevel@tonic-gate );
10031dd08564Sab 	/* END CSTYLED */
10047c478bd9Sstevel@tonic-gate 	}
10057c478bd9Sstevel@tonic-gate 	/*
10067c478bd9Sstevel@tonic-gate 	 * Most of the heavy work is done now.  Only minor stuff remains.
10077c478bd9Sstevel@tonic-gate 	 * The symbols are currently in address order and must be re-sorted
10087c478bd9Sstevel@tonic-gate 	 * if desired in a different order.  Report generating options
10097c478bd9Sstevel@tonic-gate 	 * include "-o" or "-x": Include symbol address, which causes
10107c478bd9Sstevel@tonic-gate 	 * another column
10117c478bd9Sstevel@tonic-gate 	 * in the output; and "-z": Include symbols in report even if zero
10127c478bd9Sstevel@tonic-gate 	 * time and call count.  Symbols not in profiling range are excluded
10137c478bd9Sstevel@tonic-gate 	 * in any case.  Following the main body of the report, the "-s"
10147c478bd9Sstevel@tonic-gate 	 * option causes certain additional information to be printed.
10157c478bd9Sstevel@tonic-gate 	 */
10167c478bd9Sstevel@tonic-gate 
1017c3f7a870SToomas Soome 	OLD_DEBUG(if (debug_value) Fprint(stderr,
1018c3f7a870SToomas Soome 	    "Time unaccounted for: %.7G\n", t_tot - t0));
10197c478bd9Sstevel@tonic-gate 
10207c478bd9Sstevel@tonic-gate 	if (sort)	/* If comparison routine given then use it. */
10217c478bd9Sstevel@tonic-gate 		qsort((char *)slist, (unsigned)n_syms,
10221dd08564Sab 		    sizeof (struct slist), sort);
10237c478bd9Sstevel@tonic-gate 
10247c478bd9Sstevel@tonic-gate 	if (!(flags & F_NHEAD)) {
10257c478bd9Sstevel@tonic-gate 		if (flags & F_PADDR)
102692ed1782Smike_s 			Print("%s", atitle);	/* Title for addresses. */
10277c478bd9Sstevel@tonic-gate 		(void) puts(" %Time Seconds Cumsecs  #Calls   msec/call  Name");
10287c478bd9Sstevel@tonic-gate 	}
10297c478bd9Sstevel@tonic-gate 	t = 0.0;			/* Init cumulative time. */
10307c478bd9Sstevel@tonic-gate 	if (t_tot != 0.0)		/* Convert to percent. */
10317c478bd9Sstevel@tonic-gate 		t_tot = 100.0/t_tot;	/* Prevent divide-by-zero fault */
10327c478bd9Sstevel@tonic-gate 	n_nonzero = 0;	/* Number of symbols with nonzero time or # calls. */
10337c478bd9Sstevel@tonic-gate 	for (n = n_syms, slp = slist; --n >= 0; slp++) {
10347c478bd9Sstevel@tonic-gate 		long count;	 /* # Calls. */
10357c478bd9Sstevel@tonic-gate 		/* t0, time in seconds. */
10367c478bd9Sstevel@tonic-gate 
10377c478bd9Sstevel@tonic-gate 		/* if a snym symbol, use summarized stats, else use indiv. */
10387c478bd9Sstevel@tonic-gate 		if ((snymp = getSnymEntry(slp->sl_addr)) != 0) {
10397c478bd9Sstevel@tonic-gate 			count = snymp->tot_sl_count;
10407c478bd9Sstevel@tonic-gate 			t0 = snymp->tot_sl_time;
10417c478bd9Sstevel@tonic-gate 
10427c478bd9Sstevel@tonic-gate 		} else {
10437c478bd9Sstevel@tonic-gate 			count = slp->sl_count;
10447c478bd9Sstevel@tonic-gate 			t0 = slp->sl_time;
10457c478bd9Sstevel@tonic-gate 		}
10467c478bd9Sstevel@tonic-gate 
10477c478bd9Sstevel@tonic-gate 		/* if a snym and already reported, skip this entry */
10487c478bd9Sstevel@tonic-gate 		if (snymp && snymp->snymReported)
10497c478bd9Sstevel@tonic-gate 			continue;
10507c478bd9Sstevel@tonic-gate 		/* Don't do entries with no action. */
10517c478bd9Sstevel@tonic-gate 		if (t0 == 0.0 && count == 0 && !(flags & F_ZSYMS))
10527c478bd9Sstevel@tonic-gate 			continue;
10537c478bd9Sstevel@tonic-gate 		if ((strcmp(slp->sl_name, "_mcount") == 0) ||
10547c478bd9Sstevel@tonic-gate 		    (strcmp(slp->sl_name, "mcount") == 0)) {
10551dd08564Sab 			count = callTotal;
10567c478bd9Sstevel@tonic-gate 		}
10577c478bd9Sstevel@tonic-gate 
10587c478bd9Sstevel@tonic-gate 		/* count number of entries (i.e. symbols) printed */
10597c478bd9Sstevel@tonic-gate 		if (snymp)
10607c478bd9Sstevel@tonic-gate 			n_nonzero += snymp->howMany; /* add for each snym */
10617c478bd9Sstevel@tonic-gate 		else
10627c478bd9Sstevel@tonic-gate 			n_nonzero++;
10637c478bd9Sstevel@tonic-gate 
106492ed1782Smike_s 		if (flags & F_PADDR) { /* Printing address of symbol? */
106592ed1782Smike_s 			/* LINTED: variable format */
10667c478bd9Sstevel@tonic-gate 			Print(aformat, slp->sl_addr);
106792ed1782Smike_s 		}
10687c478bd9Sstevel@tonic-gate 		t += t0;	/*  move here; compiler bug  !! */
10697c478bd9Sstevel@tonic-gate 		Print("%6.1f%8.2f%8.2f", t0 * t_tot, t0, t);
10707c478bd9Sstevel@tonic-gate 		fdigits = 0;
10717c478bd9Sstevel@tonic-gate 		if (count) {		/* Any calls recorded? */
10727c478bd9Sstevel@tonic-gate 		/* Get reasonable number of fractional digits to print. */
10737c478bd9Sstevel@tonic-gate 			fdigits = fprecision(count);
10747c478bd9Sstevel@tonic-gate 			Print("%8ld%#*.*f", count, fdigits+8, fdigits,
10757c478bd9Sstevel@tonic-gate 			    1000.0*t0/count);
10767c478bd9Sstevel@tonic-gate 			Print("%*s", 6-fdigits, " ");
10777c478bd9Sstevel@tonic-gate 		} else {
10787c478bd9Sstevel@tonic-gate 			Print("%22s", " ");
10797c478bd9Sstevel@tonic-gate 		}
10807c478bd9Sstevel@tonic-gate 		/*
10817c478bd9Sstevel@tonic-gate 		 * now print the name (or comma-seperate list of names,
10827c478bd9Sstevel@tonic-gate 		 * for synonym symbols).
10837c478bd9Sstevel@tonic-gate 		 */
10847c478bd9Sstevel@tonic-gate 		if (snymp) {
10857c478bd9Sstevel@tonic-gate 			printSnymNames(slp, snymp);	/* print it, then */
10867c478bd9Sstevel@tonic-gate 			snymp->snymReported = 1;	/* mark it Done */
10877c478bd9Sstevel@tonic-gate 		}
10887c478bd9Sstevel@tonic-gate 		else
10897c478bd9Sstevel@tonic-gate 			(void) puts(slp->sl_name);	/* print the one name */
10907c478bd9Sstevel@tonic-gate 	}
10917c478bd9Sstevel@tonic-gate 	if (flags & F_VERBOSE) {		/* Extra info? */
10927c478bd9Sstevel@tonic-gate 		Fprint(stderr, "%5d/%d call counts used\n", n_cc, head.nfns);
10937c478bd9Sstevel@tonic-gate 		Fprint(stderr, "%5d/%d symbols qualified", n_syms, symttl);
10947c478bd9Sstevel@tonic-gate 		if (n_nonzero < n_syms)
10957c478bd9Sstevel@tonic-gate 			Fprint(stderr,
10967c478bd9Sstevel@tonic-gate 			    ", %d had zero time and zero call-counts\n",
10977c478bd9Sstevel@tonic-gate 			    n_syms - n_nonzero);
10987c478bd9Sstevel@tonic-gate 		else
10997c478bd9Sstevel@tonic-gate 			(void) putc('\n', stderr);
110092ed1782Smike_s 		Fprint(stderr, "%#lx scale factor\n", (long)sf);
11017c478bd9Sstevel@tonic-gate 	}
11027c478bd9Sstevel@tonic-gate 
11037c478bd9Sstevel@tonic-gate 	_symintClose(ldptr);
11047c478bd9Sstevel@tonic-gate 	} else {
11051dd08564Sab 		Fprint(stderr, "prof: no call counts captured\n");
11067c478bd9Sstevel@tonic-gate 	}
110792ed1782Smike_s 	return (0);
11087c478bd9Sstevel@tonic-gate }
11097c478bd9Sstevel@tonic-gate /* Return size of file associated with file descriptor fd. */
11107c478bd9Sstevel@tonic-gate 
111192ed1782Smike_s static off_t
fsize(int fd)111292ed1782Smike_s fsize(int fd)
11137c478bd9Sstevel@tonic-gate {
11147c478bd9Sstevel@tonic-gate 	struct stat sbuf;
11157c478bd9Sstevel@tonic-gate 
11167c478bd9Sstevel@tonic-gate 	if (fstat(fd, &sbuf) < 0)  /* Status of open file. */
11177c478bd9Sstevel@tonic-gate 		Perror("stat");
11187c478bd9Sstevel@tonic-gate 	return (sbuf.st_size);			/* This is a long. */
11197c478bd9Sstevel@tonic-gate }
11207c478bd9Sstevel@tonic-gate 
11217c478bd9Sstevel@tonic-gate /* Read symbol entry. Return TRUE if satisfies conditions. */
11227c478bd9Sstevel@tonic-gate 
112392ed1782Smike_s static int
readnl(int symindex)112492ed1782Smike_s readnl(int symindex)
11257c478bd9Sstevel@tonic-gate {
11267c478bd9Sstevel@tonic-gate 	nl = ldptr->pf_symarr_p[symindex];
11277c478bd9Sstevel@tonic-gate 
11281dd08564Sab 	/* BEGIN CSTYLED */
11297c478bd9Sstevel@tonic-gate OLD_DEBUG(
11307c478bd9Sstevel@tonic-gate 	if (debug_value & 020) {
11317c478bd9Sstevel@tonic-gate 		Fprint(stderr,
11327c478bd9Sstevel@tonic-gate 			"`%-8.8s'\tst_info=%#4o, value=%#8.6o\n",
11337c478bd9Sstevel@tonic-gate 			ldptr->pf_symstr_p[nl.ps_sym.st_name],
11347c478bd9Sstevel@tonic-gate 			(unsigned char) nl.ps_sym.st_info,
11357c478bd9Sstevel@tonic-gate 			nl.ps_sym.st_value);
11367c478bd9Sstevel@tonic-gate 	}
11377c478bd9Sstevel@tonic-gate );
11381dd08564Sab 	/* END CSTYLED */
11391dd08564Sab 
11407c478bd9Sstevel@tonic-gate 	/*
11417c478bd9Sstevel@tonic-gate 	 * TXTSYM accepts global (and local, if "-g" given) T-type symbols.
11427c478bd9Sstevel@tonic-gate 	 * Only those in the profiling range are useful.
11437c478bd9Sstevel@tonic-gate 	 */
11447c478bd9Sstevel@tonic-gate 	return (nl.ps_sym.st_shndx < SHN_LORESERVE &&
11451dd08564Sab 	    TXTSYM(nl.ps_sym.st_shndx, nl.ps_sym.st_info) &&
11461dd08564Sab 	    (pc_l <= (char *)nl.ps_sym.st_value) &&
11471dd08564Sab 	    ((char *)nl.ps_sym.st_value < pc_h));
11487c478bd9Sstevel@tonic-gate }
11497c478bd9Sstevel@tonic-gate /*
11507c478bd9Sstevel@tonic-gate  * Error-checking memory allocators -
11517c478bd9Sstevel@tonic-gate  * Guarantees good return (else none at all).
11527c478bd9Sstevel@tonic-gate  */
11537c478bd9Sstevel@tonic-gate 
115492ed1782Smike_s static void *
_prof_Malloc(int item_count,int item_size)115592ed1782Smike_s _prof_Malloc(int item_count, int item_size)
11567c478bd9Sstevel@tonic-gate {
115792ed1782Smike_s 	void *p;
11587c478bd9Sstevel@tonic-gate 
11597c478bd9Sstevel@tonic-gate 	if ((p = malloc((unsigned)item_count * (unsigned)item_size)) == NULL)  {
11607c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, "%s: Out of space\n", cmdname);
11617c478bd9Sstevel@tonic-gate 		exit(1);
11627c478bd9Sstevel@tonic-gate 	}
11637c478bd9Sstevel@tonic-gate 	return (p);
11647c478bd9Sstevel@tonic-gate }
11657c478bd9Sstevel@tonic-gate 
11667c478bd9Sstevel@tonic-gate 
11677c478bd9Sstevel@tonic-gate 
11687c478bd9Sstevel@tonic-gate /*
11697c478bd9Sstevel@tonic-gate  *	Given the quotient Q = N/D, where entier(N) == N and D > 0, an
11707c478bd9Sstevel@tonic-gate  *	approximation of the "best" number of fractional digits to use
11717c478bd9Sstevel@tonic-gate  *	in printing Q is f = entier(log10(D)), which is crudely produced
11727c478bd9Sstevel@tonic-gate  *	by the following routine.
11737c478bd9Sstevel@tonic-gate  */
11747c478bd9Sstevel@tonic-gate 
117592ed1782Smike_s static int
fprecision(long count)117692ed1782Smike_s fprecision(long count)
11777c478bd9Sstevel@tonic-gate {
11787c478bd9Sstevel@tonic-gate 	return (count < 10 ? 0 : count < 100 ? 1 : count < 1000 ? 2 :
11797c478bd9Sstevel@tonic-gate 	    count < 10000 ? 3 : 4);
11807c478bd9Sstevel@tonic-gate }
11817c478bd9Sstevel@tonic-gate 
11827c478bd9Sstevel@tonic-gate /*
11837c478bd9Sstevel@tonic-gate  *	Return pointer to base name(name less path) of string s.
11847c478bd9Sstevel@tonic-gate  *	Handles case of superfluous trailing '/'s, and unlikely
11857c478bd9Sstevel@tonic-gate  *	case of s == "/".
11867c478bd9Sstevel@tonic-gate  */
11877c478bd9Sstevel@tonic-gate 
118892ed1782Smike_s static char *
basename(char * s)118992ed1782Smike_s basename(char *s)
11907c478bd9Sstevel@tonic-gate {
119192ed1782Smike_s 	char *p;
11927c478bd9Sstevel@tonic-gate 
11937c478bd9Sstevel@tonic-gate 	p = &s[strlen(s)];			/* End (+1) of string. */
11947c478bd9Sstevel@tonic-gate 	while (p > s && *--p == '/')		/* Trim trailing '/'s. */
11957c478bd9Sstevel@tonic-gate 		*p = '\0';
11967c478bd9Sstevel@tonic-gate 	p++;					/* New end (+1) of string. */
11971dd08564Sab 	while (p > s && *--p != '/')		/* Break backward on '/'. */
11981dd08564Sab 		;
11997c478bd9Sstevel@tonic-gate 	if (*p == '/')		/* If found '/', point to 1st following. */
12007c478bd9Sstevel@tonic-gate 		p++;
12017c478bd9Sstevel@tonic-gate 	if (*p == '\0')
12027c478bd9Sstevel@tonic-gate 		p = "/";			/* If NULL, must be "/". (?) */
12037c478bd9Sstevel@tonic-gate 	return (p);
12047c478bd9Sstevel@tonic-gate }
12057c478bd9Sstevel@tonic-gate /* Here if unexpected read problem. */
12067c478bd9Sstevel@tonic-gate 
120792ed1782Smike_s static void
eofon(FILE * iop,char * fn)120892ed1782Smike_s eofon(FILE *iop, char *fn)
12097c478bd9Sstevel@tonic-gate {
12107c478bd9Sstevel@tonic-gate 	if (ferror(iop))		/* Real error? */
12117c478bd9Sstevel@tonic-gate 		Perror(fn);		/* Yes. */
12127c478bd9Sstevel@tonic-gate 	Fprint(stderr, "%s: %s: Premature EOF\n", cmdname, fn);
12137c478bd9Sstevel@tonic-gate 	exit(1);
12147c478bd9Sstevel@tonic-gate }
12157c478bd9Sstevel@tonic-gate 
1216c3f7a870SToomas Soome /*
1217c3f7a870SToomas Soome  * Version of perror() that prints cmdname first.
1218c3f7a870SToomas Soome  * Print system error message & exit.
1219c3f7a870SToomas Soome  */
12207c478bd9Sstevel@tonic-gate 
122192ed1782Smike_s static void
Perror(char * s)122292ed1782Smike_s Perror(char *s)
1223c3f7a870SToomas Soome {
122492ed1782Smike_s 	int err = errno;	/* Save current errno in case */
12257c478bd9Sstevel@tonic-gate 
12267c478bd9Sstevel@tonic-gate 	Fprint(stderr, "%s: ", cmdname);
12277c478bd9Sstevel@tonic-gate 	errno = err;			/* Put real error back. */
12287c478bd9Sstevel@tonic-gate 	perror(s);			/* Print message. */
12297c478bd9Sstevel@tonic-gate 	_symintClose(ldptr);		/* cleanup symbol information */
12307c478bd9Sstevel@tonic-gate 	exit(1);			/* Exit w/nonzero status. */
12317c478bd9Sstevel@tonic-gate }
12327c478bd9Sstevel@tonic-gate 
12337c478bd9Sstevel@tonic-gate /* Here for things that "Should Never Happen". */
12347c478bd9Sstevel@tonic-gate 
123592ed1782Smike_s static void
snh(void)123692ed1782Smike_s snh(void)
12377c478bd9Sstevel@tonic-gate {
12387c478bd9