xref: /onnv-gate/usr/src/cmd/sgs/elfdump/common/_elfdump.h (revision 9273:9a0603d78ad3)
11618Srie /*
21618Srie  * CDDL HEADER START
31618Srie  *
41618Srie  * The contents of this file are subject to the terms of the
51618Srie  * Common Development and Distribution License (the "License").
61618Srie  * You may not use this file except in compliance with the License.
71618Srie  *
81618Srie  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
91618Srie  * or http://www.opensolaris.org/os/licensing.
101618Srie  * See the License for the specific language governing permissions
111618Srie  * and limitations under the License.
121618Srie  *
131618Srie  * When distributing Covered Code, include this CDDL HEADER in each
141618Srie  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
151618Srie  * If applicable, add the following below this CDDL HEADER, with the
161618Srie  * fields enclosed by brackets "[]" replaced with your own identifying
171618Srie  * information: Portions Copyright [yyyy] [name of copyright owner]
181618Srie  *
191618Srie  * CDDL HEADER END
201618Srie  */
211618Srie 
221618Srie /*
239085SAli.Bahrami@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
241618Srie  * Use is subject to license terms.
251618Srie  */
261618Srie 
271618Srie #ifndef	__ELFDUMP_H
281618Srie #define	__ELFDUMP_H
291618Srie 
306206Sab196087 #include	<_machelf.h>
311618Srie #include	<debug.h>
321618Srie 
331618Srie /*
341618Srie  * Local include file for elfdump.
351618Srie  */
361618Srie #ifdef	__cplusplus
371618Srie extern "C" {
381618Srie #endif
391618Srie 
405411Sab196087 /*
415411Sab196087  * flags: This is a bitmask that controls elfdump's operations. There
425411Sab196087  * are three categories of flag:
435411Sab196087  *
445411Sab196087  *	SHOW - Specify categories of things in the ELF object to display.
455411Sab196087  *	CALC - Compute something based on the contents of the ELF object.
465411Sab196087  *	CTL - Control options specify general options that are not
475411Sab196087  *		specific to any specific part of the ELF object, but
485411Sab196087  *		which apply at a higher level.
495411Sab196087  *
505411Sab196087  * To simplify masking these categories, they are assigned bit ranges
515411Sab196087  * as follows:
525411Sab196087  *	SHOW: Bottom 24-bits
53*9273SAli.Bahrami@Sun.COM  *	CALC: Upper 2 bits of most significant byte
54*9273SAli.Bahrami@Sun.COM  *	CTL: Lower 6 bits of most significant byte
555411Sab196087  */
565411Sab196087 #define	FLG_SHOW_DYNAMIC	0x00000001
575411Sab196087 #define	FLG_SHOW_EHDR		0x00000002
585411Sab196087 #define	FLG_SHOW_INTERP		0x00000004
595411Sab196087 #define	FLG_SHOW_SHDR		0x00000008
605411Sab196087 #define	FLG_SHOW_NOTE		0x00000010
615411Sab196087 #define	FLG_SHOW_PHDR		0x00000020
625411Sab196087 #define	FLG_SHOW_RELOC		0x00000040
635411Sab196087 #define	FLG_SHOW_SYMBOLS	0x00000080
645411Sab196087 #define	FLG_SHOW_VERSIONS	0x00000100
655411Sab196087 #define	FLG_SHOW_HASH		0x00000200
665411Sab196087 #define	FLG_SHOW_GOT		0x00000400
675411Sab196087 #define	FLG_SHOW_SYMINFO	0x00000800
685411Sab196087 #define	FLG_SHOW_MOVE		0x00001000
695411Sab196087 #define	FLG_SHOW_GROUP		0x00002000
705411Sab196087 #define	FLG_SHOW_CAP		0x00004000
715411Sab196087 #define	FLG_SHOW_UNWIND		0x00008000
725411Sab196087 #define	FLG_SHOW_SORT		0x00010000
731618Srie 
745411Sab196087 #define	FLG_CTL_LONGNAME	0x01000000
755411Sab196087 #define	FLG_CTL_DEMANGLE	0x02000000
765411Sab196087 #define	FLG_CTL_FAKESHDR	0x04000000
775411Sab196087 #define	FLG_CTL_MATCH		0x08000000
78*9273SAli.Bahrami@Sun.COM #define	FLG_CTL_OSABI		0x10000000
795411Sab196087 
80*9273SAli.Bahrami@Sun.COM #define	FLG_CALC_CHECKSUM	0x40000000
815411Sab196087 
825411Sab196087 /* Bitmasks that isolate the parts of a flag value */
835411Sab196087 #define	FLG_MASK_SHOW		0x00ffffff
84*9273SAli.Bahrami@Sun.COM #define	FLG_MASK_CTL		0x3f000000
85*9273SAli.Bahrami@Sun.COM #define	FLG_MASK_CALC		0xc0000000
865411Sab196087 
875411Sab196087 /*
885411Sab196087  * Mask that selects the show flags that do not require the ELF
895411Sab196087  * object to have a section header array.
905411Sab196087  */
915411Sab196087 #define	FLG_MASK_SHOW_NOSHDR	(FLG_SHOW_EHDR | FLG_SHOW_PHDR)
925411Sab196087 
935411Sab196087 /*
945411Sab196087  * Masks to select the flags that require the ELF object to
955411Sab196087  * have a section header array, within each flag type.
965411Sab196087  */
975411Sab196087 #define	FLG_MASK_SHOW_SHDR	(FLG_MASK_SHOW & ~FLG_MASK_SHOW_NOSHDR)
985411Sab196087 #define	FLG_MASK_CALC_SHDR	FLG_CALC_CHECKSUM
995411Sab196087 
1005411Sab196087 
1015411Sab196087 /* Size of buffer used for formatting an index into textual representation */
1021618Srie #define	MAXNDXSIZE	10
1031618Srie 
1041618Srie typedef struct cache {
1053862Srie 	Elf_Scn		*c_scn;
1061618Srie 	Shdr		*c_shdr;
1071618Srie 	Elf_Data	*c_data;
1081618Srie 	char		*c_name;
1094063Sab196087 	int		c_ndx;		/* Section index */
1101618Srie } Cache;
1111618Srie 
1121618Srie typedef struct got_info {
1131618Srie 	Word		g_reltype;	/* it will never happen, but */
1141618Srie 					/* support mixed relocations */
1151618Srie 	void		*g_rel;
1161618Srie 	const char	*g_symname;
1171618Srie } Got_info;
1181618Srie 
1191618Srie extern	const Cache	 cache_init;
1201618Srie 
1211618Srie extern	void		failure(const char *, const char *);
1221618Srie extern	const char	*demangle(const char *, uint_t);
1235411Sab196087 
1245411Sab196087 
1255411Sab196087 /*
1265411Sab196087  * Flags for the match() function:
1275411Sab196087  *	MATCH_F_STRICT
1285411Sab196087  *		A strict match requires an explicit match to
1295411Sab196087  *		a user specified match (-I, -N, -T) option. A
1305411Sab196087  *		non-strict match also succeeds if the match
1315411Sab196087  *		list is empty.
1325411Sab196087  *
1335411Sab196087  *	MATCH_F_PHDR
1345411Sab196087  *		The match item is a program header. If this
1355411Sab196087  *		flag is not set, the match item is a section
1365411Sab196087  *		header.
1375411Sab196087  *
1385411Sab196087  *	MATCH_F_NAME
1395411Sab196087  *		The name parameter contains valid information.
1405411Sab196087  *
1415411Sab196087  *	MATCH_F_NDX
1425411Sab196087  *		The ndx argument contains valid information
1435411Sab196087  *
1445411Sab196087  *	MATCH_F_TYPE
1455411Sab196087  *		The type argument contains valid information
1465411Sab196087  */
1475411Sab196087 typedef enum {
1485411Sab196087 	MATCH_F_STRICT =	1,
1495411Sab196087 	MATCH_F_PHDR =		2,
1505411Sab196087 	MATCH_F_NAME =		4,
1515411Sab196087 	MATCH_F_NDX =		8,
1525411Sab196087 	MATCH_F_TYPE =		16
1535411Sab196087 } match_flags_t;
1545411Sab196087 
1555411Sab196087 /* It is common for calls to match() to specify all three arguments */
1565411Sab196087 #define	MATCH_F_ALL	(MATCH_F_NAME | MATCH_F_NDX | MATCH_F_TYPE)
1575411Sab196087 
1585411Sab196087 extern int	match(match_flags_t, const char *, uint_t, uint_t);
1591618Srie 
1601618Srie /*
1616635Sab196087  * Possible return values from corenote()
1626635Sab196087  */
1636635Sab196087 typedef enum {
1646635Sab196087 	CORENOTE_R_OK = 0,	/* Note data successfully displayed */
1656635Sab196087 	CORENOTE_R_OK_DUMP = 1,	/* Note OK, but not handled. Display Hex dump */
1666635Sab196087 	CORENOTE_R_BADDATA = 2,	/* Note data truncated or otherwise malformed */
1676635Sab196087 	CORENOTE_R_BADARCH = 3,	/* core file note code does not contain */
1686635Sab196087 				/*	support for given architecture */
1696635Sab196087 	CORENOTE_R_BADTYPE = 4	/* Unknown note type */
1706635Sab196087 } corenote_ret_t;
1716635Sab196087 
1726635Sab196087 /*
1731618Srie  * Define various elfdump() functions into their 32-bit and 64-bit variants.
1741618Srie  */
1751618Srie #if	defined(_ELF64)
1761618Srie #define	cap			cap64
1771618Srie #define	checksum		checksum64
1781618Srie #define	dynamic			dynamic64
1794665Sab196087 #define	fake_shdr_cache		fake_shdr_cache64
1804665Sab196087 #define	fake_shdr_cache_free	fake_shdr_cache_free64
1811618Srie #define	got			got64
1821618Srie #define	group			group64
1831618Srie #define	hash			hash64
1841618Srie #define	interp			interp64
1851618Srie #define	move			move64
1861618Srie #define	note			note64
1871618Srie #define	note_entry		note_entry64
1881618Srie #define	regular			regular64
1891618Srie #define	reloc			reloc64
1901618Srie #define	sections		sections64
1911618Srie #define	string			string64
1921618Srie #define	symbols			symbols64
1931618Srie #define	syminfo			syminfo64
1941618Srie #define	symlookup		symlookup64
1951618Srie #define	unwind			unwind64
1961618Srie #define	versions		versions64
1971618Srie #define	version_def		version_def64
1981618Srie #define	version_need		version_need64
1991618Srie #else
2001618Srie #define	cap			cap32
2011618Srie #define	checksum		checksum32
2021618Srie #define	dynamic			dynamic32
2034665Sab196087 #define	fake_shdr_cache		fake_shdr_cache32
2044665Sab196087 #define	fake_shdr_cache_free	fake_shdr_cache_free32
2051618Srie #define	got			got32
2061618Srie #define	group			group32
2071618Srie #define	hash			hash32
2081618Srie #define	interp			interp32
2091618Srie #define	move			move32
2101618Srie #define	note			note32
2111618Srie #define	note_entry		note_entry32
2121618Srie #define	regular			regular32
2131618Srie #define	reloc			reloc32
2141618Srie #define	sections		sections32
2151618Srie #define	string			string32
2161618Srie #define	symbols			symbols32
2171618Srie #define	syminfo			syminfo32
2181618Srie #define	symlookup		symlookup32
2191618Srie #define	unwind			unwind32
2201618Srie #define	versions		versions32
2211618Srie #define	version_def		version_def32
2221618Srie #define	version_need		version_need32
2231618Srie #endif
2241618Srie 
2256635Sab196087 extern	corenote_ret_t	corenote(Half, int, Word, const char *, Word);
2269085SAli.Bahrami@Sun.COM extern	void	dump_eh_frame(uchar_t *, size_t, uint64_t, Half e_machine,
2279085SAli.Bahrami@Sun.COM 		    uchar_t *e_ident);
2289085SAli.Bahrami@Sun.COM extern	void	dump_hex_bytes(const void *, size_t, int, int, int);
2296635Sab196087 
2304665Sab196087 extern	int	fake_shdr_cache32(const char *, int, Elf *, Elf32_Ehdr *,
2316635Sab196087 		    Cache **, size_t *);
2324665Sab196087 extern	int	fake_shdr_cache64(const char *, int, Elf *, Elf64_Ehdr *,
2336635Sab196087 		    Cache **, size_t *);
2344665Sab196087 
2354665Sab196087 extern	void	fake_shdr_cache_free32(Cache *, size_t);
2364665Sab196087 extern	void	fake_shdr_cache_free64(Cache *, size_t);
2374665Sab196087 
238*9273SAli.Bahrami@Sun.COM extern	int	regular32(const char *, int, Elf *, uint_t, const char *, int,
239*9273SAli.Bahrami@Sun.COM 		    uchar_t);
240*9273SAli.Bahrami@Sun.COM extern	int	regular64(const char *, int, Elf *, uint_t, const char *, int,
241*9273SAli.Bahrami@Sun.COM 		    uchar_t);
2421618Srie 
2431618Srie #ifdef	__cplusplus
2441618Srie }
2451618Srie #endif
2461618Srie 
2471618Srie #endif	/* __ELFDUMP_H */
248