xref: /onnv-gate/usr/src/cmd/sgs/elfdump/common/_elfdump.h (revision 6206:6b0ed502a8e7)
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 /*
23*6206Sab196087  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
241618Srie  * Use is subject to license terms.
251618Srie  */
261618Srie 
271618Srie #ifndef	__ELFDUMP_H
281618Srie #define	__ELFDUMP_H
291618Srie 
301618Srie #pragma ident	"%Z%%M%	%I%	%E% SMI"
311618Srie 
32*6206Sab196087 #include	<_machelf.h>
331618Srie #include	<debug.h>
341618Srie 
351618Srie /*
361618Srie  * Local include file for elfdump.
371618Srie  */
381618Srie #ifdef	__cplusplus
391618Srie extern "C" {
401618Srie #endif
411618Srie 
425411Sab196087 /*
435411Sab196087  * flags: This is a bitmask that controls elfdump's operations. There
445411Sab196087  * are three categories of flag:
455411Sab196087  *
465411Sab196087  *	SHOW - Specify categories of things in the ELF object to display.
475411Sab196087  *	CALC - Compute something based on the contents of the ELF object.
485411Sab196087  *	CTL - Control options specify general options that are not
495411Sab196087  *		specific to any specific part of the ELF object, but
505411Sab196087  *		which apply at a higher level.
515411Sab196087  *
525411Sab196087  * To simplify masking these categories, they are assigned bit ranges
535411Sab196087  * as follows:
545411Sab196087  *	SHOW: Bottom 24-bits
555411Sab196087  *	CALC: Upper nibble of most significant byte
565411Sab196087  *	CTL: Lower nibble of most significant byte
575411Sab196087  */
585411Sab196087 #define	FLG_SHOW_DYNAMIC	0x00000001
595411Sab196087 #define	FLG_SHOW_EHDR		0x00000002
605411Sab196087 #define	FLG_SHOW_INTERP		0x00000004
615411Sab196087 #define	FLG_SHOW_SHDR		0x00000008
625411Sab196087 #define	FLG_SHOW_NOTE		0x00000010
635411Sab196087 #define	FLG_SHOW_PHDR		0x00000020
645411Sab196087 #define	FLG_SHOW_RELOC		0x00000040
655411Sab196087 #define	FLG_SHOW_SYMBOLS	0x00000080
665411Sab196087 #define	FLG_SHOW_VERSIONS	0x00000100
675411Sab196087 #define	FLG_SHOW_HASH		0x00000200
685411Sab196087 #define	FLG_SHOW_GOT		0x00000400
695411Sab196087 #define	FLG_SHOW_SYMINFO	0x00000800
705411Sab196087 #define	FLG_SHOW_MOVE		0x00001000
715411Sab196087 #define	FLG_SHOW_GROUP		0x00002000
725411Sab196087 #define	FLG_SHOW_CAP		0x00004000
735411Sab196087 #define	FLG_SHOW_UNWIND		0x00008000
745411Sab196087 #define	FLG_SHOW_SORT		0x00010000
751618Srie 
765411Sab196087 #define	FLG_CTL_LONGNAME	0x01000000
775411Sab196087 #define	FLG_CTL_DEMANGLE	0x02000000
785411Sab196087 #define	FLG_CTL_FAKESHDR	0x04000000
795411Sab196087 #define	FLG_CTL_MATCH		0x08000000
805411Sab196087 
815411Sab196087 #define	FLG_CALC_CHECKSUM	0x10000000
825411Sab196087 
835411Sab196087 /* Bitmasks that isolate the parts of a flag value */
845411Sab196087 #define	FLG_MASK_SHOW		0x00ffffff
855411Sab196087 #define	FLG_MASK_CTL		0x0f000000
865411Sab196087 #define	FLG_MASK_CALC		0xf0000000
875411Sab196087 
885411Sab196087 /*
895411Sab196087  * Mask that selects the show flags that do not require the ELF
905411Sab196087  * object to have a section header array.
915411Sab196087  */
925411Sab196087 #define	FLG_MASK_SHOW_NOSHDR	(FLG_SHOW_EHDR | FLG_SHOW_PHDR)
935411Sab196087 
945411Sab196087 /*
955411Sab196087  * Masks to select the flags that require the ELF object to
965411Sab196087  * have a section header array, within each flag type.
975411Sab196087  */
985411Sab196087 #define	FLG_MASK_SHOW_SHDR	(FLG_MASK_SHOW & ~FLG_MASK_SHOW_NOSHDR)
995411Sab196087 #define	FLG_MASK_CALC_SHDR	FLG_CALC_CHECKSUM
1005411Sab196087 
1015411Sab196087 
1025411Sab196087 /* Size of buffer used for formatting an index into textual representation */
1031618Srie #define	MAXNDXSIZE	10
1041618Srie 
1051618Srie typedef struct cache {
1063862Srie 	Elf_Scn		*c_scn;
1071618Srie 	Shdr		*c_shdr;
1081618Srie 	Elf_Data	*c_data;
1091618Srie 	char		*c_name;
1104063Sab196087 	int		c_ndx;		/* Section index */
1111618Srie } Cache;
1121618Srie 
1131618Srie typedef struct got_info {
1141618Srie 	Word		g_reltype;	/* it will never happen, but */
1151618Srie 					/* support mixed relocations */
1161618Srie 	void		*g_rel;
1171618Srie 	const char	*g_symname;
1181618Srie } Got_info;
1191618Srie 
1201618Srie extern	const Cache	 cache_init;
1211618Srie 
1221618Srie extern	void		failure(const char *, const char *);
1231618Srie extern	const char	*demangle(const char *, uint_t);
1245411Sab196087 
1255411Sab196087 
1265411Sab196087 /*
1275411Sab196087  * Flags for the match() function:
1285411Sab196087  *	MATCH_F_STRICT
1295411Sab196087  *		A strict match requires an explicit match to
1305411Sab196087  *		a user specified match (-I, -N, -T) option. A
1315411Sab196087  *		non-strict match also succeeds if the match
1325411Sab196087  *		list is empty.
1335411Sab196087  *
1345411Sab196087  *	MATCH_F_PHDR
1355411Sab196087  *		The match item is a program header. If this
1365411Sab196087  *		flag is not set, the match item is a section
1375411Sab196087  *		header.
1385411Sab196087  *
1395411Sab196087  *	MATCH_F_NAME
1405411Sab196087  *		The name parameter contains valid information.
1415411Sab196087  *
1425411Sab196087  *	MATCH_F_NDX
1435411Sab196087  *		The ndx argument contains valid information
1445411Sab196087  *
1455411Sab196087  *	MATCH_F_TYPE
1465411Sab196087  *		The type argument contains valid information
1475411Sab196087  */
1485411Sab196087 typedef enum {
1495411Sab196087 	MATCH_F_STRICT =	1,
1505411Sab196087 	MATCH_F_PHDR =		2,
1515411Sab196087 	MATCH_F_NAME =		4,
1525411Sab196087 	MATCH_F_NDX =		8,
1535411Sab196087 	MATCH_F_TYPE =		16
1545411Sab196087 } match_flags_t;
1555411Sab196087 
1565411Sab196087 /* It is common for calls to match() to specify all three arguments */
1575411Sab196087 #define	MATCH_F_ALL	(MATCH_F_NAME | MATCH_F_NDX | MATCH_F_TYPE)
1585411Sab196087 
1595411Sab196087 extern int	match(match_flags_t, const char *, uint_t, uint_t);
1601618Srie 
1611618Srie /*
1621618Srie  * Define various elfdump() functions into their 32-bit and 64-bit variants.
1631618Srie  */
1641618Srie #if	defined(_ELF64)
1651618Srie #define	cap			cap64
1661618Srie #define	checksum		checksum64
1671618Srie #define	dynamic			dynamic64
1684665Sab196087 #define	fake_shdr_cache		fake_shdr_cache64
1694665Sab196087 #define	fake_shdr_cache_free	fake_shdr_cache_free64
1701618Srie #define	got			got64
1711618Srie #define	group			group64
1721618Srie #define	hash			hash64
1731618Srie #define	interp			interp64
1741618Srie #define	move			move64
1751618Srie #define	note			note64
1761618Srie #define	note_entry		note_entry64
1771618Srie #define	regular			regular64
1781618Srie #define	reloc			reloc64
1791618Srie #define	sections		sections64
1801618Srie #define	string			string64
1811618Srie #define	symbols			symbols64
1821618Srie #define	syminfo			syminfo64
1831618Srie #define	symlookup		symlookup64
1841618Srie #define	unwind			unwind64
1851618Srie #define	versions		versions64
1861618Srie #define	version_def		version_def64
1871618Srie #define	version_need		version_need64
1881618Srie #else
1891618Srie #define	cap			cap32
1901618Srie #define	checksum		checksum32
1911618Srie #define	dynamic			dynamic32
1924665Sab196087 #define	fake_shdr_cache		fake_shdr_cache32
1934665Sab196087 #define	fake_shdr_cache_free	fake_shdr_cache_free32
1941618Srie #define	got			got32
1951618Srie #define	group			group32
1961618Srie #define	hash			hash32
1971618Srie #define	interp			interp32
1981618Srie #define	move			move32
1991618Srie #define	note			note32
2001618Srie #define	note_entry		note_entry32
2011618Srie #define	regular			regular32
2021618Srie #define	reloc			reloc32
2031618Srie #define	sections		sections32
2041618Srie #define	string			string32
2051618Srie #define	symbols			symbols32
2061618Srie #define	syminfo			syminfo32
2071618Srie #define	symlookup		symlookup32
2081618Srie #define	unwind			unwind32
2091618Srie #define	versions		versions32
2101618Srie #define	version_def		version_def32
2111618Srie #define	version_need		version_need32
2121618Srie #endif
2131618Srie 
2144665Sab196087 extern	int	fake_shdr_cache32(const char *, int, Elf *, Elf32_Ehdr *,
2154665Sab196087     Cache **, size_t *);
2164665Sab196087 extern	int	fake_shdr_cache64(const char *, int, Elf *, Elf64_Ehdr *,
2174665Sab196087     Cache **, size_t *);
2184665Sab196087 
2194665Sab196087 extern	void	fake_shdr_cache_free32(Cache *, size_t);
2204665Sab196087 extern	void	fake_shdr_cache_free64(Cache *, size_t);
2214665Sab196087 
2225411Sab196087 extern	int	regular32(const char *, int, Elf *, uint_t, const char *, int);
2235411Sab196087 extern	int	regular64(const char *, int, Elf *, uint_t, const char *, int);
2241618Srie 
2251618Srie #ifdef	__cplusplus
2261618Srie }
2271618Srie #endif
2281618Srie 
2291618Srie #endif	/* __ELFDUMP_H */
230