15aefb655Srie /* 25aefb655Srie * CDDL HEADER START 35aefb655Srie * 45aefb655Srie * The contents of this file are subject to the terms of the 55aefb655Srie * Common Development and Distribution License (the "License"). 65aefb655Srie * You may not use this file except in compliance with the License. 75aefb655Srie * 85aefb655Srie * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 95aefb655Srie * or http://www.opensolaris.org/os/licensing. 105aefb655Srie * See the License for the specific language governing permissions 115aefb655Srie * and limitations under the License. 125aefb655Srie * 135aefb655Srie * When distributing Covered Code, include this CDDL HEADER in each 145aefb655Srie * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 155aefb655Srie * If applicable, add the following below this CDDL HEADER, with the 165aefb655Srie * fields enclosed by brackets "[]" replaced with your own identifying 175aefb655Srie * information: Portions Copyright [yyyy] [name of copyright owner] 185aefb655Srie * 195aefb655Srie * CDDL HEADER END 205aefb655Srie */ 215aefb655Srie 225aefb655Srie /* 237e16fca0SAli Bahrami * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 245aefb655Srie * Use is subject to license terms. 255aefb655Srie */ 265aefb655Srie 275aefb655Srie #ifndef __ELFDUMP_H 285aefb655Srie #define __ELFDUMP_H 295aefb655Srie 30ba2be530Sab196087 #include <_machelf.h> 315aefb655Srie #include <debug.h> 325aefb655Srie 335aefb655Srie /* 345aefb655Srie * Local include file for elfdump. 355aefb655Srie */ 365aefb655Srie #ifdef __cplusplus 375aefb655Srie extern "C" { 385aefb655Srie #endif 395aefb655Srie 40981a172dSab196087 /* 41981a172dSab196087 * flags: This is a bitmask that controls elfdump's operations. There 42981a172dSab196087 * are three categories of flag: 43981a172dSab196087 * 44981a172dSab196087 * SHOW - Specify categories of things in the ELF object to display. 45981a172dSab196087 * CALC - Compute something based on the contents of the ELF object. 46981a172dSab196087 * CTL - Control options specify general options that are not 47981a172dSab196087 * specific to any specific part of the ELF object, but 48981a172dSab196087 * which apply at a higher level. 49981a172dSab196087 * 50981a172dSab196087 * To simplify masking these categories, they are assigned bit ranges 51981a172dSab196087 * as follows: 52981a172dSab196087 * SHOW: Bottom 24-bits 534f680cc6SAli Bahrami * CALC: Upper 2 bits of most significant byte 544f680cc6SAli Bahrami * CTL: Lower 6 bits of most significant byte 55981a172dSab196087 */ 56981a172dSab196087 #define FLG_SHOW_DYNAMIC 0x00000001 57981a172dSab196087 #define FLG_SHOW_EHDR 0x00000002 58981a172dSab196087 #define FLG_SHOW_INTERP 0x00000004 59981a172dSab196087 #define FLG_SHOW_SHDR 0x00000008 60981a172dSab196087 #define FLG_SHOW_NOTE 0x00000010 61981a172dSab196087 #define FLG_SHOW_PHDR 0x00000020 62981a172dSab196087 #define FLG_SHOW_RELOC 0x00000040 63981a172dSab196087 #define FLG_SHOW_SYMBOLS 0x00000080 64981a172dSab196087 #define FLG_SHOW_VERSIONS 0x00000100 65981a172dSab196087 #define FLG_SHOW_HASH 0x00000200 66981a172dSab196087 #define FLG_SHOW_GOT 0x00000400 67981a172dSab196087 #define FLG_SHOW_SYMINFO 0x00000800 68981a172dSab196087 #define FLG_SHOW_MOVE 0x00001000 69981a172dSab196087 #define FLG_SHOW_GROUP 0x00002000 70981a172dSab196087 #define FLG_SHOW_CAP 0x00004000 71981a172dSab196087 #define FLG_SHOW_UNWIND 0x00008000 72981a172dSab196087 #define FLG_SHOW_SORT 0x00010000 735aefb655Srie 74981a172dSab196087 #define FLG_CTL_LONGNAME 0x01000000 75981a172dSab196087 #define FLG_CTL_DEMANGLE 0x02000000 76981a172dSab196087 #define FLG_CTL_FAKESHDR 0x04000000 77981a172dSab196087 #define FLG_CTL_MATCH 0x08000000 784f680cc6SAli Bahrami #define FLG_CTL_OSABI 0x10000000 79981a172dSab196087 804f680cc6SAli Bahrami #define FLG_CALC_CHECKSUM 0x40000000 81981a172dSab196087 82981a172dSab196087 /* Bitmasks that isolate the parts of a flag value */ 83981a172dSab196087 #define FLG_MASK_SHOW 0x00ffffff 844f680cc6SAli Bahrami #define FLG_MASK_CTL 0x3f000000 854f680cc6SAli Bahrami #define FLG_MASK_CALC 0xc0000000 86981a172dSab196087 87981a172dSab196087 /* 88981a172dSab196087 * Mask that selects the show flags that do not require the ELF 89981a172dSab196087 * object to have a section header array. 90981a172dSab196087 */ 91981a172dSab196087 #define FLG_MASK_SHOW_NOSHDR (FLG_SHOW_EHDR | FLG_SHOW_PHDR) 92981a172dSab196087 93981a172dSab196087 /* 94981a172dSab196087 * Masks to select the flags that require the ELF object to 95981a172dSab196087 * have a section header array, within each flag type. 96981a172dSab196087 */ 97981a172dSab196087 #define FLG_MASK_SHOW_SHDR (FLG_MASK_SHOW & ~FLG_MASK_SHOW_NOSHDR) 98981a172dSab196087 #define FLG_MASK_CALC_SHDR FLG_CALC_CHECKSUM 99981a172dSab196087 100981a172dSab196087 101981a172dSab196087 /* Size of buffer used for formatting an index into textual representation */ 1025aefb655Srie #define MAXNDXSIZE 10 1035aefb655Srie 1045aefb655Srie typedef struct cache { 105f5a18a30Srie Elf_Scn *c_scn; 1065aefb655Srie Shdr *c_shdr; 1075aefb655Srie Elf_Data *c_data; 1085aefb655Srie char *c_name; 10931fdd7caSab196087 int c_ndx; /* Section index */ 1105aefb655Srie } Cache; 1115aefb655Srie 1125aefb655Srie typedef struct got_info { 1135aefb655Srie Word g_reltype; /* it will never happen, but */ 1145aefb655Srie /* support mixed relocations */ 1155aefb655Srie void *g_rel; 1165aefb655Srie const char *g_symname; 1175aefb655Srie } Got_info; 1185aefb655Srie 1195aefb655Srie extern const Cache cache_init; 1205aefb655Srie 1215aefb655Srie extern void failure(const char *, const char *); 1225aefb655Srie extern const char *demangle(const char *, uint_t); 123981a172dSab196087 124981a172dSab196087 125981a172dSab196087 /* 126981a172dSab196087 * Flags for the match() function: 127981a172dSab196087 * MATCH_F_STRICT 128981a172dSab196087 * A strict match requires an explicit match to 129981a172dSab196087 * a user specified match (-I, -N, -T) option. A 130981a172dSab196087 * non-strict match also succeeds if the match 131981a172dSab196087 * list is empty. 132981a172dSab196087 * 133981a172dSab196087 * MATCH_F_PHDR 134981a172dSab196087 * The match item is a program header. If this 135981a172dSab196087 * flag is not set, the match item is a section 136981a172dSab196087 * header. 137981a172dSab196087 * 138981a172dSab196087 * MATCH_F_NAME 139981a172dSab196087 * The name parameter contains valid information. 140981a172dSab196087 * 141981a172dSab196087 * MATCH_F_NDX 142981a172dSab196087 * The ndx argument contains valid information 143981a172dSab196087 * 144981a172dSab196087 * MATCH_F_TYPE 145981a172dSab196087 * The type argument contains valid information 146981a172dSab196087 */ 147981a172dSab196087 typedef enum { 148981a172dSab196087 MATCH_F_STRICT = 1, 149981a172dSab196087 MATCH_F_PHDR = 2, 150981a172dSab196087 MATCH_F_NAME = 4, 151981a172dSab196087 MATCH_F_NDX = 8, 152981a172dSab196087 MATCH_F_TYPE = 16 153981a172dSab196087 } match_flags_t; 154981a172dSab196087 155981a172dSab196087 /* It is common for calls to match() to specify all three arguments */ 156981a172dSab196087 #define MATCH_F_ALL (MATCH_F_NAME | MATCH_F_NDX | MATCH_F_TYPE) 157981a172dSab196087 158981a172dSab196087 extern int match(match_flags_t, const char *, uint_t, uint_t); 1595aefb655Srie 1605aefb655Srie /* 161c6c9aed4Sab196087 * Possible return values from corenote() 162c6c9aed4Sab196087 */ 163c6c9aed4Sab196087 typedef enum { 164c6c9aed4Sab196087 CORENOTE_R_OK = 0, /* Note data successfully displayed */ 165c6c9aed4Sab196087 CORENOTE_R_OK_DUMP = 1, /* Note OK, but not handled. Display Hex dump */ 166c6c9aed4Sab196087 CORENOTE_R_BADDATA = 2, /* Note data truncated or otherwise malformed */ 167c6c9aed4Sab196087 CORENOTE_R_BADARCH = 3, /* core file note code does not contain */ 168c6c9aed4Sab196087 /* support for given architecture */ 169c6c9aed4Sab196087 CORENOTE_R_BADTYPE = 4 /* Unknown note type */ 170c6c9aed4Sab196087 } corenote_ret_t; 171c6c9aed4Sab196087 172c6c9aed4Sab196087 /* 1735aefb655Srie * Define various elfdump() functions into their 32-bit and 64-bit variants. 1745aefb655Srie */ 1755aefb655Srie #if defined(_ELF64) 1765aefb655Srie #define cap cap64 1775aefb655Srie #define checksum checksum64 1785aefb655Srie #define dynamic dynamic64 17939773e46Sab196087 #define fake_shdr_cache fake_shdr_cache64 18039773e46Sab196087 #define fake_shdr_cache_free fake_shdr_cache_free64 1815aefb655Srie #define got got64 1825aefb655Srie #define group group64 1835aefb655Srie #define hash hash64 1845aefb655Srie #define interp interp64 1855aefb655Srie #define move move64 1865aefb655Srie #define note note64 1875aefb655Srie #define note_entry note_entry64 1885aefb655Srie #define regular regular64 1895aefb655Srie #define reloc reloc64 1905aefb655Srie #define sections sections64 1915aefb655Srie #define string string64 1925aefb655Srie #define symbols symbols64 1935aefb655Srie #define syminfo syminfo64 1945aefb655Srie #define symlookup symlookup64 1955aefb655Srie #define unwind unwind64 1965aefb655Srie #define versions versions64 1975aefb655Srie #define version_def version_def64 1985aefb655Srie #define version_need version_need64 1995aefb655Srie #else 2005aefb655Srie #define cap cap32 2015aefb655Srie #define checksum checksum32 2025aefb655Srie #define dynamic dynamic32 20339773e46Sab196087 #define fake_shdr_cache fake_shdr_cache32 20439773e46Sab196087 #define fake_shdr_cache_free fake_shdr_cache_free32 2055aefb655Srie #define got got32 2065aefb655Srie #define group group32 2075aefb655Srie #define hash hash32 2085aefb655Srie #define interp interp32 2095aefb655Srie #define move move32 2105aefb655Srie #define note note32 2115aefb655Srie #define note_entry note_entry32 2125aefb655Srie #define regular regular32 2135aefb655Srie #define reloc reloc32 2145aefb655Srie #define sections sections32 2155aefb655Srie #define string string32 2165aefb655Srie #define symbols symbols32 2175aefb655Srie #define syminfo syminfo32 2185aefb655Srie #define symlookup symlookup32 2195aefb655Srie #define unwind unwind32 2205aefb655Srie #define versions versions32 2215aefb655Srie #define version_def version_def32 2225aefb655Srie #define version_need version_need32 2235aefb655Srie #endif 2245aefb655Srie 225c6c9aed4Sab196087 extern corenote_ret_t corenote(Half, int, Word, const char *, Word); 226*37915d86SRichard Lowe extern void dump_eh_frame(const char *, char *, uchar_t *, size_t, uint64_t, 227*37915d86SRichard Lowe Half e_machine, uchar_t *e_ident, uint64_t gotaddr); 2287e16fca0SAli Bahrami extern void dump_hex_bytes(const void *, size_t, int, int, int); 229c6c9aed4Sab196087 23039773e46Sab196087 extern int fake_shdr_cache32(const char *, int, Elf *, Elf32_Ehdr *, 23139773e46Sab196087 Cache **, size_t *); 23239773e46Sab196087 extern int fake_shdr_cache64(const char *, int, Elf *, Elf64_Ehdr *, 23339773e46Sab196087 Cache **, size_t *); 23439773e46Sab196087 23539773e46Sab196087 extern void fake_shdr_cache_free32(Cache *, size_t); 23639773e46Sab196087 extern void fake_shdr_cache_free64(Cache *, size_t); 23739773e46Sab196087 2384f680cc6SAli Bahrami extern int regular32(const char *, int, Elf *, uint_t, const char *, int, 2394f680cc6SAli Bahrami uchar_t); 2404f680cc6SAli Bahrami extern int regular64(const char *, int, Elf *, uint_t, const char *, int, 2414f680cc6SAli Bahrami uchar_t); 2425aefb655Srie 2435aefb655Srie #ifdef __cplusplus 2445aefb655Srie } 2455aefb655Srie #endif 2465aefb655Srie 2475aefb655Srie #endif /* __ELFDUMP_H */ 248