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