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