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 /* 43 * flags: This is a bitmask that controls elfdump's operations. There 44 * are three categories of flag: 45 * 46 * SHOW - Specify categories of things in the ELF object to display. 47 * CALC - Compute something based on the contents of the ELF object. 48 * CTL - Control options specify general options that are not 49 * specific to any specific part of the ELF object, but 50 * which apply at a higher level. 51 * 52 * To simplify masking these categories, they are assigned bit ranges 53 * as follows: 54 * SHOW: Bottom 24-bits 55 * CALC: Upper nibble of most significant byte 56 * CTL: Lower nibble of most significant byte 57 */ 58 #define FLG_SHOW_DYNAMIC 0x00000001 59 #define FLG_SHOW_EHDR 0x00000002 60 #define FLG_SHOW_INTERP 0x00000004 61 #define FLG_SHOW_SHDR 0x00000008 62 #define FLG_SHOW_NOTE 0x00000010 63 #define FLG_SHOW_PHDR 0x00000020 64 #define FLG_SHOW_RELOC 0x00000040 65 #define FLG_SHOW_SYMBOLS 0x00000080 66 #define FLG_SHOW_VERSIONS 0x00000100 67 #define FLG_SHOW_HASH 0x00000200 68 #define FLG_SHOW_GOT 0x00000400 69 #define FLG_SHOW_SYMINFO 0x00000800 70 #define FLG_SHOW_MOVE 0x00001000 71 #define FLG_SHOW_GROUP 0x00002000 72 #define FLG_SHOW_CAP 0x00004000 73 #define FLG_SHOW_UNWIND 0x00008000 74 #define FLG_SHOW_SORT 0x00010000 75 76 #define FLG_CTL_LONGNAME 0x01000000 77 #define FLG_CTL_DEMANGLE 0x02000000 78 #define FLG_CTL_FAKESHDR 0x04000000 79 #define FLG_CTL_MATCH 0x08000000 80 81 #define FLG_CALC_CHECKSUM 0x10000000 82 83 /* Bitmasks that isolate the parts of a flag value */ 84 #define FLG_MASK_SHOW 0x00ffffff 85 #define FLG_MASK_CTL 0x0f000000 86 #define FLG_MASK_CALC 0xf0000000 87 88 /* 89 * Mask that selects the show flags that do not require the ELF 90 * object to have a section header array. 91 */ 92 #define FLG_MASK_SHOW_NOSHDR (FLG_SHOW_EHDR | FLG_SHOW_PHDR) 93 94 /* 95 * Masks to select the flags that require the ELF object to 96 * have a section header array, within each flag type. 97 */ 98 #define FLG_MASK_SHOW_SHDR (FLG_MASK_SHOW & ~FLG_MASK_SHOW_NOSHDR) 99 #define FLG_MASK_CALC_SHDR FLG_CALC_CHECKSUM 100 101 102 /* Size of buffer used for formatting an index into textual representation */ 103 #define MAXNDXSIZE 10 104 105 typedef struct cache { 106 Elf_Scn *c_scn; 107 Shdr *c_shdr; 108 Elf_Data *c_data; 109 char *c_name; 110 int c_ndx; /* Section index */ 111 } Cache; 112 113 typedef struct got_info { 114 Word g_reltype; /* it will never happen, but */ 115 /* support mixed relocations */ 116 void *g_rel; 117 const char *g_symname; 118 } Got_info; 119 120 extern const Cache cache_init; 121 122 extern void failure(const char *, const char *); 123 extern const char *demangle(const char *, uint_t); 124 125 126 /* 127 * Flags for the match() function: 128 * MATCH_F_STRICT 129 * A strict match requires an explicit match to 130 * a user specified match (-I, -N, -T) option. A 131 * non-strict match also succeeds if the match 132 * list is empty. 133 * 134 * MATCH_F_PHDR 135 * The match item is a program header. If this 136 * flag is not set, the match item is a section 137 * header. 138 * 139 * MATCH_F_NAME 140 * The name parameter contains valid information. 141 * 142 * MATCH_F_NDX 143 * The ndx argument contains valid information 144 * 145 * MATCH_F_TYPE 146 * The type argument contains valid information 147 */ 148 typedef enum { 149 MATCH_F_STRICT = 1, 150 MATCH_F_PHDR = 2, 151 MATCH_F_NAME = 4, 152 MATCH_F_NDX = 8, 153 MATCH_F_TYPE = 16 154 } match_flags_t; 155 156 /* It is common for calls to match() to specify all three arguments */ 157 #define MATCH_F_ALL (MATCH_F_NAME | MATCH_F_NDX | MATCH_F_TYPE) 158 159 extern int match(match_flags_t, const char *, uint_t, uint_t); 160 161 /* 162 * Define various elfdump() functions into their 32-bit and 64-bit variants. 163 */ 164 #if defined(_ELF64) 165 #define cap cap64 166 #define checksum checksum64 167 #define dynamic dynamic64 168 #define fake_shdr_cache fake_shdr_cache64 169 #define fake_shdr_cache_free fake_shdr_cache_free64 170 #define got got64 171 #define group group64 172 #define hash hash64 173 #define interp interp64 174 #define move move64 175 #define note note64 176 #define note_entry note_entry64 177 #define regular regular64 178 #define reloc reloc64 179 #define sections sections64 180 #define string string64 181 #define symbols symbols64 182 #define syminfo syminfo64 183 #define symlookup symlookup64 184 #define unwind unwind64 185 #define versions versions64 186 #define version_def version_def64 187 #define version_need version_need64 188 #else 189 #define cap cap32 190 #define checksum checksum32 191 #define dynamic dynamic32 192 #define fake_shdr_cache fake_shdr_cache32 193 #define fake_shdr_cache_free fake_shdr_cache_free32 194 #define got got32 195 #define group group32 196 #define hash hash32 197 #define interp interp32 198 #define move move32 199 #define note note32 200 #define note_entry note_entry32 201 #define regular regular32 202 #define reloc reloc32 203 #define sections sections32 204 #define string string32 205 #define symbols symbols32 206 #define syminfo syminfo32 207 #define symlookup symlookup32 208 #define unwind unwind32 209 #define versions versions32 210 #define version_def version_def32 211 #define version_need version_need32 212 #endif 213 214 extern int fake_shdr_cache32(const char *, int, Elf *, Elf32_Ehdr *, 215 Cache **, size_t *); 216 extern int fake_shdr_cache64(const char *, int, Elf *, Elf64_Ehdr *, 217 Cache **, size_t *); 218 219 extern void fake_shdr_cache_free32(Cache *, size_t); 220 extern void fake_shdr_cache_free64(Cache *, size_t); 221 222 extern int regular32(const char *, int, Elf *, uint_t, const char *, int); 223 extern int regular64(const char *, int, Elf *, uint_t, const char *, int); 224 225 #ifdef __cplusplus 226 } 227 #endif 228 229 #endif /* __ELFDUMP_H */ 230