1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1998-2000 by Sun Microsystems, Inc.
24*7c478bd9Sstevel@tonic-gate  * All rights reserved.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #ifndef	_STATIC_PROF_H
28*7c478bd9Sstevel@tonic-gate #define	_STATIC_PROF_H
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
31*7c478bd9Sstevel@tonic-gate extern "C" {
32*7c478bd9Sstevel@tonic-gate #endif
33*7c478bd9Sstevel@tonic-gate 
34*7c478bd9Sstevel@tonic-gate /*
35*7c478bd9Sstevel@tonic-gate  * include headers
36*7c478bd9Sstevel@tonic-gate  */
37*7c478bd9Sstevel@tonic-gate 
38*7c478bd9Sstevel@tonic-gate #include <stdio.h>
39*7c478bd9Sstevel@tonic-gate #include <string.h>
40*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
41*7c478bd9Sstevel@tonic-gate #include <unistd.h>
42*7c478bd9Sstevel@tonic-gate #include <fcntl.h>
43*7c478bd9Sstevel@tonic-gate #include <libelf.h>
44*7c478bd9Sstevel@tonic-gate #include <link.h>
45*7c478bd9Sstevel@tonic-gate #include <sys/elf_SPARC.h>
46*7c478bd9Sstevel@tonic-gate #include <sys/utsname.h>
47*7c478bd9Sstevel@tonic-gate #include <errno.h>
48*7c478bd9Sstevel@tonic-gate 
49*7c478bd9Sstevel@tonic-gate /*
50*7c478bd9Sstevel@tonic-gate  * Declaration of global variables
51*7c478bd9Sstevel@tonic-gate  */
52*7c478bd9Sstevel@tonic-gate 
53*7c478bd9Sstevel@tonic-gate #define	DEFBKTS		24997	/* 3571 nice big prime number */
54*7c478bd9Sstevel@tonic-gate #define	MASK		(~(unsigned long)0<<28)
55*7c478bd9Sstevel@tonic-gate 
56*7c478bd9Sstevel@tonic-gate /*
57*7c478bd9Sstevel@tonic-gate  * bucket struct of hash table
58*7c478bd9Sstevel@tonic-gate  */
59*7c478bd9Sstevel@tonic-gate typedef struct binding_bucket
60*7c478bd9Sstevel@tonic-gate {
61*7c478bd9Sstevel@tonic-gate 	char			*sym;
62*7c478bd9Sstevel@tonic-gate 	char			*ref_lib;
63*7c478bd9Sstevel@tonic-gate 	char			*def_lib;
64*7c478bd9Sstevel@tonic-gate 	char			*obj;
65*7c478bd9Sstevel@tonic-gate 	char			*section;
66*7c478bd9Sstevel@tonic-gate 	char			*sttype;
67*7c478bd9Sstevel@tonic-gate 	char			*stbind;
68*7c478bd9Sstevel@tonic-gate } binding_bucket;
69*7c478bd9Sstevel@tonic-gate 
70*7c478bd9Sstevel@tonic-gate static binding_bucket	bkts[DEFBKTS];
71*7c478bd9Sstevel@tonic-gate 
72*7c478bd9Sstevel@tonic-gate /*
73*7c478bd9Sstevel@tonic-gate  * data structure for linked list of DT_NEEDED entries
74*7c478bd9Sstevel@tonic-gate  */
75*7c478bd9Sstevel@tonic-gate typedef struct dt_list_tag
76*7c478bd9Sstevel@tonic-gate {
77*7c478bd9Sstevel@tonic-gate 	char			*libname;
78*7c478bd9Sstevel@tonic-gate #if	defined(_LP64)
79*7c478bd9Sstevel@tonic-gate 	Elf64_Sword		d_tag;
80*7c478bd9Sstevel@tonic-gate #else
81*7c478bd9Sstevel@tonic-gate 	Elf32_Sword		d_tag;
82*7c478bd9Sstevel@tonic-gate #endif
83*7c478bd9Sstevel@tonic-gate 	struct dt_list_tag	*next;
84*7c478bd9Sstevel@tonic-gate } dt_list;
85*7c478bd9Sstevel@tonic-gate 
86*7c478bd9Sstevel@tonic-gate static dt_list		*dt_needed = NULL; /* ptr to link list of dtneeded */
87*7c478bd9Sstevel@tonic-gate 
88*7c478bd9Sstevel@tonic-gate /*
89*7c478bd9Sstevel@tonic-gate  * struct for the binary object under test
90*7c478bd9Sstevel@tonic-gate  */
91*7c478bd9Sstevel@tonic-gate typedef struct obj_com
92*7c478bd9Sstevel@tonic-gate {
93*7c478bd9Sstevel@tonic-gate 	char		**filenames;	/* name of application file */
94*7c478bd9Sstevel@tonic-gate 	char		*filename;
95*7c478bd9Sstevel@tonic-gate 	int		numfiles;	/* number of applications to check */
96*7c478bd9Sstevel@tonic-gate 	/* ---Current application ELF file information--- */
97*7c478bd9Sstevel@tonic-gate 	char		*ename;	/* name of current ELF file */
98*7c478bd9Sstevel@tonic-gate 	int		fd;	/* file descriptor for current file */
99*7c478bd9Sstevel@tonic-gate 	Elf		*elf;	/* elf descriptor for current file */
100*7c478bd9Sstevel@tonic-gate #if	defined(_LP64)
101*7c478bd9Sstevel@tonic-gate 	Elf64_Ehdr	*ehdr;	/* 64 bit elf header for current file */
102*7c478bd9Sstevel@tonic-gate 	Elf64_Phdr	*phdr;	/* 64 bit prog header for current file */
103*7c478bd9Sstevel@tonic-gate 	Elf64_Dyn	*dynsect;	/* pointer to 64 bit dynamic section */
104*7c478bd9Sstevel@tonic-gate #else
105*7c478bd9Sstevel@tonic-gate 	Elf32_Ehdr    	*ehdr;	/* 32 bit elf header for current file */
106*7c478bd9Sstevel@tonic-gate 	Elf32_Phdr    	*phdr;	/* 32 bit prog header for current file */
107*7c478bd9Sstevel@tonic-gate 	Elf32_Dyn	*dynsect;	/* ptr to 64 bit dynamic section */
108*7c478bd9Sstevel@tonic-gate #endif
109*7c478bd9Sstevel@tonic-gate 	Elf_Data	*ddata;	/* ptr to dstring table data descriptor */
110*7c478bd9Sstevel@tonic-gate 	char		*dynnames; /* pointer to dynamic string table */
111*7c478bd9Sstevel@tonic-gate 	/* ---ELF file symbol table information--- */
112*7c478bd9Sstevel@tonic-gate 	/* dynamic symbol table */
113*7c478bd9Sstevel@tonic-gate #if	defined(_LP64)
114*7c478bd9Sstevel@tonic-gate 	Elf64_Sym	*dsym_tab;
115*7c478bd9Sstevel@tonic-gate #else
116*7c478bd9Sstevel@tonic-gate 	Elf32_Sym	*dsym_tab;
117*7c478bd9Sstevel@tonic-gate #endif
118*7c478bd9Sstevel@tonic-gate 	Elf_Data	*dsym_data;
119*7c478bd9Sstevel@tonic-gate 	int		dsym_num;
120*7c478bd9Sstevel@tonic-gate 	char		*dsym_names;
121*7c478bd9Sstevel@tonic-gate 	/* regular symbol table */
122*7c478bd9Sstevel@tonic-gate #if	defined(_LP64)
123*7c478bd9Sstevel@tonic-gate 	Elf64_Sym	*sym_tab;
124*7c478bd9Sstevel@tonic-gate #else
125*7c478bd9Sstevel@tonic-gate 	Elf32_Sym	*sym_tab;
126*7c478bd9Sstevel@tonic-gate #endif
127*7c478bd9Sstevel@tonic-gate 	Elf_Data	*sym_data;
128*7c478bd9Sstevel@tonic-gate 	int		sym_num;
129*7c478bd9Sstevel@tonic-gate 	char		*sym_names;
130*7c478bd9Sstevel@tonic-gate } obj_com;
131*7c478bd9Sstevel@tonic-gate 
132*7c478bd9Sstevel@tonic-gate /*
133*7c478bd9Sstevel@tonic-gate  * struct of the linked list of object files
134*7c478bd9Sstevel@tonic-gate  */
135*7c478bd9Sstevel@tonic-gate typedef struct obj_list_tag
136*7c478bd9Sstevel@tonic-gate {
137*7c478bd9Sstevel@tonic-gate 	obj_com		*obj;
138*7c478bd9Sstevel@tonic-gate 	struct obj_list_tag	*next;
139*7c478bd9Sstevel@tonic-gate } obj_list;
140*7c478bd9Sstevel@tonic-gate 
141*7c478bd9Sstevel@tonic-gate static int	oflag = 0;		/* flag for redirecting output */
142*7c478bd9Sstevel@tonic-gate static int	pflag = 0;		/* flag for profiling to stdout */
143*7c478bd9Sstevel@tonic-gate static int	sflag = 1;		/* flag for silent mode */
144*7c478bd9Sstevel@tonic-gate static int	aflag = 1;		/* flag for read input as archive */
145*7c478bd9Sstevel@tonic-gate extern int	errno;			/* file opening error return code */
146*7c478bd9Sstevel@tonic-gate static FILE	*OUTPUT_FD = stdout;	/* output fd: default as stdout */
147*7c478bd9Sstevel@tonic-gate static char	*outputfile;		/* full pathname of output file */
148*7c478bd9Sstevel@tonic-gate 
149*7c478bd9Sstevel@tonic-gate #define	SUCCEED		0
150*7c478bd9Sstevel@tonic-gate #define	FAIL		1
151*7c478bd9Sstevel@tonic-gate 
152*7c478bd9Sstevel@tonic-gate #define	TRUE		1
153*7c478bd9Sstevel@tonic-gate #define	FALSE		0
154*7c478bd9Sstevel@tonic-gate 
155*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
156*7c478bd9Sstevel@tonic-gate }
157*7c478bd9Sstevel@tonic-gate #endif
158*7c478bd9Sstevel@tonic-gate 
159*7c478bd9Sstevel@tonic-gate #endif	/* _STATIC_PROF_H */
160