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