xref: /titanic_50/usr/src/cmd/sgs/elfdump/common/_elfdump.h (revision 753a6d457b330b1b29b2d3eefcd0831116ce950d)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	__ELFDUMP_H
28 #define	__ELFDUMP_H
29 
30 #include	<_machelf.h>
31 #include	<debug.h>
32 
33 /*
34  * Local include file for elfdump.
35  */
36 #ifdef	__cplusplus
37 extern "C" {
38 #endif
39 
40 /*
41  * flags: This is a bitmask that controls elfdump's operations. There
42  * are three categories of flag:
43  *
44  *	SHOW - Specify categories of things in the ELF object to display.
45  *	CALC - Compute something based on the contents of the ELF object.
46  *	CTL - Control options specify general options that are not
47  *		specific to any specific part of the ELF object, but
48  *		which apply at a higher level.
49  *
50  * To simplify masking these categories, they are assigned bit ranges
51  * as follows:
52  *	SHOW: Bottom 24-bits
53  *	CALC: Upper nibble of most significant byte
54  *	CTL: Lower nibble of most significant byte
55  */
56 #define	FLG_SHOW_DYNAMIC	0x00000001
57 #define	FLG_SHOW_EHDR		0x00000002
58 #define	FLG_SHOW_INTERP		0x00000004
59 #define	FLG_SHOW_SHDR		0x00000008
60 #define	FLG_SHOW_NOTE		0x00000010
61 #define	FLG_SHOW_PHDR		0x00000020
62 #define	FLG_SHOW_RELOC		0x00000040
63 #define	FLG_SHOW_SYMBOLS	0x00000080
64 #define	FLG_SHOW_VERSIONS	0x00000100
65 #define	FLG_SHOW_HASH		0x00000200
66 #define	FLG_SHOW_GOT		0x00000400
67 #define	FLG_SHOW_SYMINFO	0x00000800
68 #define	FLG_SHOW_MOVE		0x00001000
69 #define	FLG_SHOW_GROUP		0x00002000
70 #define	FLG_SHOW_CAP		0x00004000
71 #define	FLG_SHOW_UNWIND		0x00008000
72 #define	FLG_SHOW_SORT		0x00010000
73 
74 #define	FLG_CTL_LONGNAME	0x01000000
75 #define	FLG_CTL_DEMANGLE	0x02000000
76 #define	FLG_CTL_FAKESHDR	0x04000000
77 #define	FLG_CTL_MATCH		0x08000000
78 
79 #define	FLG_CALC_CHECKSUM	0x10000000
80 
81 /* Bitmasks that isolate the parts of a flag value */
82 #define	FLG_MASK_SHOW		0x00ffffff
83 #define	FLG_MASK_CTL		0x0f000000
84 #define	FLG_MASK_CALC		0xf0000000
85 
86 /*
87  * Mask that selects the show flags that do not require the ELF
88  * object to have a section header array.
89  */
90 #define	FLG_MASK_SHOW_NOSHDR	(FLG_SHOW_EHDR | FLG_SHOW_PHDR)
91 
92 /*
93  * Masks to select the flags that require the ELF object to
94  * have a section header array, within each flag type.
95  */
96 #define	FLG_MASK_SHOW_SHDR	(FLG_MASK_SHOW & ~FLG_MASK_SHOW_NOSHDR)
97 #define	FLG_MASK_CALC_SHDR	FLG_CALC_CHECKSUM
98 
99 
100 /* Size of buffer used for formatting an index into textual representation */
101 #define	MAXNDXSIZE	10
102 
103 typedef struct cache {
104 	Elf_Scn		*c_scn;
105 	Shdr		*c_shdr;
106 	Elf_Data	*c_data;
107 	char		*c_name;
108 	int		c_ndx;		/* Section index */
109 } Cache;
110 
111 typedef struct got_info {
112 	Word		g_reltype;	/* it will never happen, but */
113 					/* support mixed relocations */
114 	void		*g_rel;
115 	const char	*g_symname;
116 } Got_info;
117 
118 extern	const Cache	 cache_init;
119 
120 extern	void		failure(const char *, const char *);
121 extern	const char	*demangle(const char *, uint_t);
122 
123 
124 /*
125  * Flags for the match() function:
126  *	MATCH_F_STRICT
127  *		A strict match requires an explicit match to
128  *		a user specified match (-I, -N, -T) option. A
129  *		non-strict match also succeeds if the match
130  *		list is empty.
131  *
132  *	MATCH_F_PHDR
133  *		The match item is a program header. If this
134  *		flag is not set, the match item is a section
135  *		header.
136  *
137  *	MATCH_F_NAME
138  *		The name parameter contains valid information.
139  *
140  *	MATCH_F_NDX
141  *		The ndx argument contains valid information
142  *
143  *	MATCH_F_TYPE
144  *		The type argument contains valid information
145  */
146 typedef enum {
147 	MATCH_F_STRICT =	1,
148 	MATCH_F_PHDR =		2,
149 	MATCH_F_NAME =		4,
150 	MATCH_F_NDX =		8,
151 	MATCH_F_TYPE =		16
152 } match_flags_t;
153 
154 /* It is common for calls to match() to specify all three arguments */
155 #define	MATCH_F_ALL	(MATCH_F_NAME | MATCH_F_NDX | MATCH_F_TYPE)
156 
157 extern int	match(match_flags_t, const char *, uint_t, uint_t);
158 
159 /*
160  * Possible return values from corenote()
161  */
162 typedef enum {
163 	CORENOTE_R_OK = 0,	/* Note data successfully displayed */
164 	CORENOTE_R_OK_DUMP = 1,	/* Note OK, but not handled. Display Hex dump */
165 	CORENOTE_R_BADDATA = 2,	/* Note data truncated or otherwise malformed */
166 	CORENOTE_R_BADARCH = 3,	/* core file note code does not contain */
167 				/*	support for given architecture */
168 	CORENOTE_R_BADTYPE = 4	/* Unknown note type */
169 } corenote_ret_t;
170 
171 /*
172  * Define various elfdump() functions into their 32-bit and 64-bit variants.
173  */
174 #if	defined(_ELF64)
175 #define	cap			cap64
176 #define	checksum		checksum64
177 #define	dynamic			dynamic64
178 #define	fake_shdr_cache		fake_shdr_cache64
179 #define	fake_shdr_cache_free	fake_shdr_cache_free64
180 #define	got			got64
181 #define	group			group64
182 #define	hash			hash64
183 #define	interp			interp64
184 #define	move			move64
185 #define	note			note64
186 #define	note_entry		note_entry64
187 #define	regular			regular64
188 #define	reloc			reloc64
189 #define	sections		sections64
190 #define	string			string64
191 #define	symbols			symbols64
192 #define	syminfo			syminfo64
193 #define	symlookup		symlookup64
194 #define	unwind			unwind64
195 #define	versions		versions64
196 #define	version_def		version_def64
197 #define	version_need		version_need64
198 #else
199 #define	cap			cap32
200 #define	checksum		checksum32
201 #define	dynamic			dynamic32
202 #define	fake_shdr_cache		fake_shdr_cache32
203 #define	fake_shdr_cache_free	fake_shdr_cache_free32
204 #define	got			got32
205 #define	group			group32
206 #define	hash			hash32
207 #define	interp			interp32
208 #define	move			move32
209 #define	note			note32
210 #define	note_entry		note_entry32
211 #define	regular			regular32
212 #define	reloc			reloc32
213 #define	sections		sections32
214 #define	string			string32
215 #define	symbols			symbols32
216 #define	syminfo			syminfo32
217 #define	symlookup		symlookup32
218 #define	unwind			unwind32
219 #define	versions		versions32
220 #define	version_def		version_def32
221 #define	version_need		version_need32
222 #endif
223 
224 extern	corenote_ret_t	corenote(Half, int, Word, const char *, Word);
225 extern	void	dump_eh_frame(uchar_t *, size_t, uint64_t, Half e_machine,
226 		    uchar_t *e_ident);
227 extern	void	dump_hex_bytes(const void *, size_t, int, int, int);
228 
229 extern	int	fake_shdr_cache32(const char *, int, Elf *, Elf32_Ehdr *,
230 		    Cache **, size_t *);
231 extern	int	fake_shdr_cache64(const char *, int, Elf *, Elf64_Ehdr *,
232 		    Cache **, size_t *);
233 
234 extern	void	fake_shdr_cache_free32(Cache *, size_t);
235 extern	void	fake_shdr_cache_free64(Cache *, size_t);
236 
237 extern	int	regular32(const char *, int, Elf *, uint_t, const char *, int);
238 extern	int	regular64(const char *, int, Elf *, uint_t, const char *, int);
239 
240 #ifdef	__cplusplus
241 }
242 #endif
243 
244 #endif	/* __ELFDUMP_H */
245