xref: /illumos-gate/usr/src/cmd/sgs/elfdump/common/_elfdump.h (revision 7800901e60d340b6af88e94a2149805dcfcaaf56)
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 2007 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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include	<machelf.h>
33 #include	<debug.h>
34 
35 /*
36  * Local include file for elfdump.
37  */
38 #ifdef	__cplusplus
39 extern "C" {
40 #endif
41 
42 #define	FLG_DYNAMIC	0x00000001
43 #define	FLG_EHDR	0x00000002
44 #define	FLG_INTERP	0x00000004
45 #define	FLG_SHDR	0x00000008
46 #define	FLG_NOTE	0x00000010
47 #define	FLG_PHDR	0x00000020
48 #define	FLG_RELOC	0x00000040
49 #define	FLG_SYMBOLS	0x00000080
50 #define	FLG_VERSIONS	0x00000100
51 #define	FLG_HASH	0x00000200
52 #define	FLG_GOT		0x00000400
53 #define	FLG_SYMINFO	0x00000800
54 #define	FLG_MOVE	0x00001000
55 #define	FLG_GROUP	0x00002000
56 #define	FLG_CAP		0x00004000
57 #define	FLG_UNWIND	0x00008000
58 #define	FLG_SORT	0x00010000
59 #define	FLG_LONGNAME	0x00100000	/* not done by default */
60 #define	FLG_CHECKSUM	0x00200000	/* not done by default */
61 #define	FLG_DEMANGLE	0x00400000	/* not done by default */
62 #define	FLG_FAKESHDR	0x00800000	/* not done by default */
63 #define	FLG_EVERYTHING	0x000fffff
64 
65 #define	MAXNDXSIZE	10
66 
67 typedef struct cache {
68 	Elf_Scn		*c_scn;
69 	Shdr		*c_shdr;
70 	Elf_Data	*c_data;
71 	char		*c_name;
72 	int		c_ndx;		/* Section index */
73 } Cache;
74 
75 typedef struct got_info {
76 	Word		g_reltype;	/* it will never happen, but */
77 					/* support mixed relocations */
78 	void		*g_rel;
79 	const char	*g_symname;
80 } Got_info;
81 
82 extern	const Cache	 cache_init;
83 
84 extern	void		failure(const char *, const char *);
85 extern	const char	*demangle(const char *, uint_t);
86 extern int		match(int, const char *, int);
87 
88 /*
89  * Define various elfdump() functions into their 32-bit and 64-bit variants.
90  */
91 #if	defined(_ELF64)
92 #define	cap			cap64
93 #define	checksum		checksum64
94 #define	dynamic			dynamic64
95 #define	fake_shdr_cache		fake_shdr_cache64
96 #define	fake_shdr_cache_free	fake_shdr_cache_free64
97 #define	got			got64
98 #define	group			group64
99 #define	hash			hash64
100 #define	interp			interp64
101 #define	move			move64
102 #define	note			note64
103 #define	note_entry		note_entry64
104 #define	regular			regular64
105 #define	reloc			reloc64
106 #define	sections		sections64
107 #define	string			string64
108 #define	symbols			symbols64
109 #define	syminfo			syminfo64
110 #define	symlookup		symlookup64
111 #define	unwind			unwind64
112 #define	versions		versions64
113 #define	version_def		version_def64
114 #define	version_need		version_need64
115 #else
116 #define	cap			cap32
117 #define	checksum		checksum32
118 #define	dynamic			dynamic32
119 #define	fake_shdr_cache		fake_shdr_cache32
120 #define	fake_shdr_cache_free	fake_shdr_cache_free32
121 #define	got			got32
122 #define	group			group32
123 #define	hash			hash32
124 #define	interp			interp32
125 #define	move			move32
126 #define	note			note32
127 #define	note_entry		note_entry32
128 #define	regular			regular32
129 #define	reloc			reloc32
130 #define	sections		sections32
131 #define	string			string32
132 #define	symbols			symbols32
133 #define	syminfo			syminfo32
134 #define	symlookup		symlookup32
135 #define	unwind			unwind32
136 #define	versions		versions32
137 #define	version_def		version_def32
138 #define	version_need		version_need32
139 #endif
140 
141 extern	int	fake_shdr_cache32(const char *, int, Elf *, Elf32_Ehdr *,
142     Cache **, size_t *);
143 extern	int	fake_shdr_cache64(const char *, int, Elf *, Elf64_Ehdr *,
144     Cache **, size_t *);
145 
146 extern	void	fake_shdr_cache_free32(Cache *, size_t);
147 extern	void	fake_shdr_cache_free64(Cache *, size_t);
148 
149 extern	void	regular32(const char *, int, Elf *, uint_t, int);
150 extern	void	regular64(const char *, int, Elf *, uint_t, int);
151 
152 #ifdef	__cplusplus
153 }
154 #endif
155 
156 #endif	/* __ELFDUMP_H */
157