]>
Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* readelf.c -- display contents of an ELF format file |
8c2bc687 | 2 | Copyright 1998, 1999, 2000, 2001 Free Software Foundation, Inc. |
252b5132 RH |
3 | |
4 | Originally developed by Eric Youngdale <eric@andante.jic.com> | |
12ab83a9 | 5 | Modifications by Nick Clifton <nickc@redhat.com> |
252b5132 RH |
6 | |
7 | This file is part of GNU Binutils. | |
8 | ||
9 | This program is free software; you can redistribute it and/or modify | |
10 | it under the terms of the GNU General Public License as published by | |
11 | the Free Software Foundation; either version 2 of the License, or | |
12 | (at your option) any later version. | |
13 | ||
14 | This program is distributed in the hope that it will be useful, | |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
18 | ||
19 | You should have received a copy of the GNU General Public License | |
20 | along with this program; if not, write to the Free Software | |
21 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
22 | 02111-1307, USA. */ | |
23 | \f | |
24 | ||
25 | #include <assert.h> | |
00ed88bd | 26 | #include <sys/types.h> |
252b5132 RH |
27 | #include <sys/stat.h> |
28 | #include <stdio.h> | |
29 | #include <time.h> | |
30 | ||
a952a375 | 31 | #if __GNUC__ >= 2 |
19936277 | 32 | /* Define BFD64 here, even if our default architecture is 32 bit ELF |
a952a375 NC |
33 | as this will allow us to read in and parse 64bit and 32bit ELF files. |
34 | Only do this if we belive that the compiler can support a 64 bit | |
35 | data type. For now we only rely on GCC being able to do this. */ | |
19936277 | 36 | #define BFD64 |
a952a375 NC |
37 | #endif |
38 | ||
252b5132 RH |
39 | #include "bfd.h" |
40 | ||
41 | #include "elf/common.h" | |
42 | #include "elf/external.h" | |
43 | #include "elf/internal.h" | |
44 | #include "elf/dwarf2.h" | |
45 | ||
46 | /* The following headers use the elf/reloc-macros.h file to | |
47 | automatically generate relocation recognition functions | |
48 | such as elf_mips_reloc_type() */ | |
49 | ||
50 | #define RELOC_MACROS_GEN_FUNC | |
51 | ||
52 | #include "elf/i386.h" | |
53 | #include "elf/v850.h" | |
54 | #include "elf/ppc.h" | |
55 | #include "elf/mips.h" | |
56 | #include "elf/alpha.h" | |
57 | #include "elf/arm.h" | |
58 | #include "elf/m68k.h" | |
59 | #include "elf/sparc.h" | |
60 | #include "elf/m32r.h" | |
61 | #include "elf/d10v.h" | |
62 | #include "elf/d30v.h" | |
63 | #include "elf/sh.h" | |
64 | #include "elf/mn10200.h" | |
65 | #include "elf/mn10300.h" | |
66 | #include "elf/hppa.h" | |
b8720f9d | 67 | #include "elf/h8.h" |
252b5132 RH |
68 | #include "elf/arc.h" |
69 | #include "elf/fr30.h" | |
70 | #include "elf/mcore.h" | |
3c3bdf30 | 71 | #include "elf/mmix.h" |
63fcb9e9 | 72 | #include "elf/i960.h" |
7d466069 | 73 | #include "elf/pj.h" |
adde6300 | 74 | #include "elf/avr.h" |
800eeca4 | 75 | #include "elf/ia64.h" |
1b61cf92 | 76 | #include "elf/cris.h" |
535c37ff | 77 | #include "elf/i860.h" |
bcedfee6 | 78 | #include "elf/x86-64.h" |
a85d7ed0 | 79 | #include "elf/s390.h" |
93fbbb04 | 80 | #include "elf/xstormy16.h" |
252b5132 RH |
81 | |
82 | #include "bucomm.h" | |
83 | #include "getopt.h" | |
84 | ||
c45021f2 NC |
85 | char * program_name = "readelf"; |
86 | unsigned int dynamic_addr; | |
7036c0e1 | 87 | bfd_size_type dynamic_size; |
c45021f2 NC |
88 | unsigned int rela_addr; |
89 | unsigned int rela_size; | |
90 | char * dynamic_strings; | |
252b5132 | 91 | char * string_table; |
d40ac9bd | 92 | unsigned long string_table_length; |
19936277 | 93 | unsigned long num_dynamic_syms; |
7036c0e1 | 94 | Elf_Internal_Sym * dynamic_symbols; |
252b5132 | 95 | Elf_Internal_Syminfo * dynamic_syminfo; |
c45021f2 | 96 | unsigned long dynamic_syminfo_offset; |
252b5132 | 97 | unsigned int dynamic_syminfo_nent; |
c45021f2 NC |
98 | char program_interpreter [64]; |
99 | int dynamic_info[DT_JMPREL + 1]; | |
100 | int version_info[16]; | |
101 | int loadaddr = 0; | |
252b5132 RH |
102 | Elf_Internal_Ehdr elf_header; |
103 | Elf_Internal_Shdr * section_headers; | |
104 | Elf_Internal_Dyn * dynamic_segment; | |
7036c0e1 AJ |
105 | int show_name; |
106 | int do_dynamic; | |
107 | int do_syms; | |
108 | int do_reloc; | |
109 | int do_sections; | |
110 | int do_segments; | |
4d6ed7c8 | 111 | int do_unwind; |
7036c0e1 AJ |
112 | int do_using_dynamic; |
113 | int do_header; | |
114 | int do_dump; | |
115 | int do_version; | |
d974e256 | 116 | int do_wide; |
252b5132 RH |
117 | int do_histogram; |
118 | int do_debugging; | |
119 | int do_debug_info; | |
120 | int do_debug_abbrevs; | |
121 | int do_debug_lines; | |
122 | int do_debug_pubnames; | |
123 | int do_debug_aranges; | |
c47d488e | 124 | int do_debug_frames; |
31b6fca6 | 125 | int do_debug_frames_interp; |
e0c60db2 | 126 | int do_debug_macinfo; |
261a45ad | 127 | int do_debug_str; |
a952a375 | 128 | int do_arch; |
779fe533 | 129 | int do_notes; |
9ea033b2 | 130 | int is_32bit_elf; |
252b5132 RH |
131 | |
132 | /* A dynamic array of flags indicating which sections require dumping. */ | |
133 | char * dump_sects = NULL; | |
134 | unsigned int num_dump_sects = 0; | |
135 | ||
136 | #define HEX_DUMP (1 << 0) | |
137 | #define DISASS_DUMP (1 << 1) | |
138 | #define DEBUG_DUMP (1 << 2) | |
139 | ||
843dd992 NC |
140 | /* How to rpint a vma value. */ |
141 | typedef enum print_mode | |
142 | { | |
143 | HEX, | |
144 | DEC, | |
145 | DEC_5, | |
146 | UNSIGNED, | |
147 | PREFIX_HEX, | |
148 | FULL_HEX, | |
149 | LONG_HEX | |
150 | } | |
151 | print_mode; | |
152 | ||
252b5132 | 153 | /* Forward declarations for dumb compilers. */ |
30800947 | 154 | static void print_vma PARAMS ((bfd_vma, print_mode)); |
9ea033b2 NC |
155 | static bfd_vma (* byte_get) PARAMS ((unsigned char *, int)); |
156 | static bfd_vma byte_get_little_endian PARAMS ((unsigned char *, int)); | |
157 | static bfd_vma byte_get_big_endian PARAMS ((unsigned char *, int)); | |
158 | static const char * get_mips_dynamic_type PARAMS ((unsigned long)); | |
9a097730 | 159 | static const char * get_sparc64_dynamic_type PARAMS ((unsigned long)); |
103f02d3 | 160 | static const char * get_parisc_dynamic_type PARAMS ((unsigned long)); |
9ea033b2 | 161 | static const char * get_dynamic_type PARAMS ((unsigned long)); |
7036c0e1 AJ |
162 | static int slurp_rela_relocs PARAMS ((FILE *, unsigned long, unsigned long, Elf_Internal_Rela **, unsigned long *)); |
163 | static int slurp_rel_relocs PARAMS ((FILE *, unsigned long, unsigned long, Elf_Internal_Rel **, unsigned long *)); | |
19936277 | 164 | static int dump_relocations PARAMS ((FILE *, unsigned long, unsigned long, Elf_Internal_Sym *, unsigned long, char *, int)); |
9ea033b2 NC |
165 | static char * get_file_type PARAMS ((unsigned)); |
166 | static char * get_machine_name PARAMS ((unsigned)); | |
f3485b74 | 167 | static void decode_ARM_machine_flags PARAMS ((unsigned, char [])); |
9ea033b2 NC |
168 | static char * get_machine_flags PARAMS ((unsigned, unsigned)); |
169 | static const char * get_mips_segment_type PARAMS ((unsigned long)); | |
103f02d3 | 170 | static const char * get_parisc_segment_type PARAMS ((unsigned long)); |
4d6ed7c8 | 171 | static const char * get_ia64_segment_type PARAMS ((unsigned long)); |
9ea033b2 NC |
172 | static const char * get_segment_type PARAMS ((unsigned long)); |
173 | static const char * get_mips_section_type_name PARAMS ((unsigned int)); | |
103f02d3 | 174 | static const char * get_parisc_section_type_name PARAMS ((unsigned int)); |
4d6ed7c8 | 175 | static const char * get_ia64_section_type_name PARAMS ((unsigned int)); |
9ea033b2 | 176 | static const char * get_section_type_name PARAMS ((unsigned int)); |
d1133906 NC |
177 | static const char * get_symbol_binding PARAMS ((unsigned int)); |
178 | static const char * get_symbol_type PARAMS ((unsigned int)); | |
179 | static const char * get_symbol_visibility PARAMS ((unsigned int)); | |
180 | static const char * get_symbol_index_type PARAMS ((unsigned int)); | |
7036c0e1 | 181 | static const char * get_dynamic_flags PARAMS ((bfd_vma)); |
252b5132 | 182 | static void usage PARAMS ((void)); |
9ea033b2 | 183 | static void parse_args PARAMS ((int, char **)); |
252b5132 RH |
184 | static int process_file_header PARAMS ((void)); |
185 | static int process_program_headers PARAMS ((FILE *)); | |
186 | static int process_section_headers PARAMS ((FILE *)); | |
4d6ed7c8 | 187 | static int process_unwind PARAMS ((FILE *)); |
9ea033b2 | 188 | static void dynamic_segment_mips_val PARAMS ((Elf_Internal_Dyn *)); |
103f02d3 | 189 | static void dynamic_segment_parisc_val PARAMS ((Elf_Internal_Dyn *)); |
252b5132 RH |
190 | static int process_dynamic_segment PARAMS ((FILE *)); |
191 | static int process_symbol_table PARAMS ((FILE *)); | |
2863d58a | 192 | static int process_syminfo PARAMS ((FILE *)); |
252b5132 | 193 | static int process_section_contents PARAMS ((FILE *)); |
2863d58a AM |
194 | static void process_mips_fpe_exception PARAMS ((int)); |
195 | static int process_mips_specific PARAMS ((FILE *)); | |
ff78d6d6 | 196 | static int process_file PARAMS ((char *)); |
252b5132 RH |
197 | static int process_relocs PARAMS ((FILE *)); |
198 | static int process_version_sections PARAMS ((FILE *)); | |
9ea033b2 | 199 | static char * get_ver_flags PARAMS ((unsigned int)); |
9ea033b2 NC |
200 | static int get_32bit_section_headers PARAMS ((FILE *)); |
201 | static int get_64bit_section_headers PARAMS ((FILE *)); | |
202 | static int get_32bit_program_headers PARAMS ((FILE *, Elf_Internal_Phdr *)); | |
203 | static int get_64bit_program_headers PARAMS ((FILE *, Elf_Internal_Phdr *)); | |
204 | static int get_file_header PARAMS ((FILE *)); | |
205 | static Elf_Internal_Sym * get_32bit_elf_symbols PARAMS ((FILE *, unsigned long, unsigned long)); | |
206 | static Elf_Internal_Sym * get_64bit_elf_symbols PARAMS ((FILE *, unsigned long, unsigned long)); | |
4d6ed7c8 | 207 | static const char * get_elf_section_flags PARAMS ((bfd_vma)); |
9ea033b2 NC |
208 | static int * get_dynamic_data PARAMS ((FILE *, unsigned int)); |
209 | static int get_32bit_dynamic_segment PARAMS ((FILE *)); | |
210 | static int get_64bit_dynamic_segment PARAMS ((FILE *)); | |
252b5132 | 211 | #ifdef SUPPORT_DISASSEMBLY |
7036c0e1 | 212 | static int disassemble_section PARAMS ((Elf32_Internal_Shdr *, FILE *)); |
252b5132 | 213 | #endif |
7036c0e1 AJ |
214 | static int dump_section PARAMS ((Elf32_Internal_Shdr *, FILE *)); |
215 | static int display_debug_section PARAMS ((Elf32_Internal_Shdr *, FILE *)); | |
252b5132 RH |
216 | static int display_debug_info PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *)); |
217 | static int display_debug_not_supported PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *)); | |
2863d58a | 218 | static int prescan_debug_info PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *)); |
252b5132 | 219 | static int display_debug_lines PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *)); |
2863d58a | 220 | static int display_debug_pubnames PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *)); |
252b5132 RH |
221 | static int display_debug_abbrev PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *)); |
222 | static int display_debug_aranges PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *)); | |
c47d488e | 223 | static int display_debug_frames PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *)); |
e0c60db2 | 224 | static int display_debug_macinfo PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *)); |
261a45ad | 225 | static int display_debug_str PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *)); |
252b5132 | 226 | static unsigned char * process_abbrev_section PARAMS ((unsigned char *, unsigned char *)); |
261a45ad NC |
227 | static void load_debug_str PARAMS ((FILE *)); |
228 | static void free_debug_str PARAMS ((void)); | |
229 | static const char * fetch_indirect_string PARAMS ((unsigned long)); | |
252b5132 | 230 | static unsigned long read_leb128 PARAMS ((unsigned char *, int *, int)); |
3590ea00 | 231 | static int process_extended_line_op PARAMS ((unsigned char *, int, int)); |
252b5132 RH |
232 | static void reset_state_machine PARAMS ((int)); |
233 | static char * get_TAG_name PARAMS ((unsigned long)); | |
234 | static char * get_AT_name PARAMS ((unsigned long)); | |
235 | static char * get_FORM_name PARAMS ((unsigned long)); | |
236 | static void free_abbrevs PARAMS ((void)); | |
237 | static void add_abbrev PARAMS ((unsigned long, unsigned long, int)); | |
238 | static void add_abbrev_attr PARAMS ((unsigned long, unsigned long)); | |
1fa37306 | 239 | static unsigned char * read_and_display_attr PARAMS ((unsigned long, unsigned long, unsigned char *, unsigned long, unsigned long)); |
81766fca | 240 | static unsigned char * read_and_display_attr_value PARAMS ((unsigned long, unsigned long, unsigned char *, unsigned long, unsigned long)); |
252b5132 | 241 | static unsigned char * display_block PARAMS ((unsigned char *, unsigned long)); |
eb6bd4d3 | 242 | static void decode_location_expression PARAMS ((unsigned char *, unsigned int, unsigned long)); |
91770270 JL |
243 | static void request_dump PARAMS ((unsigned int, int)); |
244 | static const char * get_elf_class PARAMS ((unsigned int)); | |
245 | static const char * get_data_encoding PARAMS ((unsigned int)); | |
246 | static const char * get_osabi_name PARAMS ((unsigned int)); | |
9c19a809 | 247 | static int guess_is_rela PARAMS ((unsigned long)); |
7036c0e1 | 248 | static char * get_note_type PARAMS ((unsigned int)); |
6d118b09 | 249 | static int process_note PARAMS ((Elf32_Internal_Note *)); |
f7a99963 | 250 | static int process_corefile_note_segment PARAMS ((FILE *, bfd_vma, bfd_vma)); |
779fe533 | 251 | static int process_corefile_note_segments PARAMS ((FILE *)); |
7036c0e1 | 252 | static int process_corefile_contents PARAMS ((FILE *)); |
2863d58a | 253 | static int process_arch_specific PARAMS ((FILE *)); |
252b5132 RH |
254 | |
255 | typedef int Elf32_Word; | |
256 | ||
9c19a809 NC |
257 | #ifndef TRUE |
258 | #define TRUE 1 | |
259 | #define FALSE 0 | |
260 | #endif | |
261 | #define UNKNOWN -1 | |
262 | ||
7036c0e1 | 263 | #define SECTION_NAME(X) ((X) == NULL ? "<none>" : \ |
d40ac9bd NC |
264 | ((X)->sh_name >= string_table_length \ |
265 | ? "<corrupt>" : string_table + (X)->sh_name)) | |
252b5132 RH |
266 | |
267 | #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */ | |
268 | ||
7036c0e1 | 269 | #define BYTE_GET(field) byte_get (field, sizeof (field)) |
a952a375 NC |
270 | |
271 | /* If we can support a 64 bit data type then BFD64 should be defined | |
272 | and sizeof (bfd_vma) == 8. In this case when translating from an | |
273 | external 8 byte field to an internal field, we can assume that the | |
4d6ed7c8 | 274 | internal field is also 8 bytes wide and so we can extract all the data. |
a952a375 NC |
275 | If, however, BFD64 is not defined, then we must assume that the |
276 | internal data structure only has 4 byte wide fields that are the | |
277 | equivalent of the 8 byte wide external counterparts, and so we must | |
278 | truncate the data. */ | |
279 | #ifdef BFD64 | |
7036c0e1 | 280 | #define BYTE_GET8(field) byte_get (field, -8) |
a952a375 | 281 | #else |
7036c0e1 | 282 | #define BYTE_GET8(field) byte_get (field, 8) |
a952a375 | 283 | #endif |
252b5132 | 284 | |
261a45ad | 285 | #define NUM_ELEM(array) (sizeof (array) / sizeof ((array)[0])) |
252b5132 | 286 | |
9ea033b2 NC |
287 | #define GET_ELF_SYMBOLS(file, offset, size) \ |
288 | (is_32bit_elf ? get_32bit_elf_symbols (file, offset, size) \ | |
289 | : get_64bit_elf_symbols (file, offset, size)) | |
290 | ||
291 | ||
252b5132 | 292 | static void |
451dad9c | 293 | error VPARAMS ((const char *message, ...)) |
252b5132 | 294 | { |
451dad9c AM |
295 | VA_OPEN (args, message); |
296 | VA_FIXEDARG (args, const char *, message); | |
252b5132 RH |
297 | |
298 | fprintf (stderr, _("%s: Error: "), program_name); | |
252b5132 | 299 | vfprintf (stderr, message, args); |
451dad9c | 300 | VA_CLOSE (args); |
252b5132 RH |
301 | } |
302 | ||
303 | static void | |
451dad9c | 304 | warn VPARAMS ((const char *message, ...)) |
252b5132 | 305 | { |
451dad9c AM |
306 | VA_OPEN (args, message); |
307 | VA_FIXEDARG (args, const char *, message); | |
252b5132 RH |
308 | |
309 | fprintf (stderr, _("%s: Warning: "), program_name); | |
252b5132 | 310 | vfprintf (stderr, message, args); |
451dad9c | 311 | VA_CLOSE (args); |
252b5132 | 312 | } |
252b5132 | 313 | |
a6e9f9df AM |
314 | static PTR get_data PARAMS ((PTR, FILE *, long, size_t, const char *)); |
315 | ||
316 | static PTR | |
317 | get_data (var, file, offset, size, reason) | |
318 | PTR var; | |
319 | FILE *file; | |
320 | long offset; | |
321 | size_t size; | |
322 | const char *reason; | |
323 | { | |
324 | PTR mvar; | |
325 | ||
326 | if (size == 0) | |
327 | return NULL; | |
328 | ||
329 | if (fseek (file, offset, SEEK_SET)) | |
330 | { | |
331 | error (_("Unable to seek to %x for %s\n"), offset, reason); | |
332 | return NULL; | |
333 | } | |
334 | ||
335 | mvar = var; | |
336 | if (mvar == NULL) | |
337 | { | |
338 | mvar = (PTR) malloc (size); | |
339 | ||
340 | if (mvar == NULL) | |
341 | { | |
342 | error (_("Out of memory allocating %d bytes for %s\n"), | |
343 | size, reason); | |
344 | return NULL; | |
345 | } | |
346 | } | |
347 | ||
348 | if (fread (mvar, size, 1, file) != 1) | |
349 | { | |
350 | error (_("Unable to read in %d bytes of %s\n"), size, reason); | |
351 | if (mvar != var) | |
352 | free (mvar); | |
353 | return NULL; | |
354 | } | |
355 | ||
356 | return mvar; | |
357 | } | |
358 | ||
9ea033b2 | 359 | static bfd_vma |
252b5132 RH |
360 | byte_get_little_endian (field, size) |
361 | unsigned char * field; | |
362 | int size; | |
363 | { | |
364 | switch (size) | |
365 | { | |
366 | case 1: | |
367 | return * field; | |
368 | ||
369 | case 2: | |
370 | return ((unsigned int) (field [0])) | |
371 | | (((unsigned int) (field [1])) << 8); | |
372 | ||
31b6fca6 | 373 | #ifndef BFD64 |
9ea033b2 NC |
374 | case 8: |
375 | /* We want to extract data from an 8 byte wide field and | |
376 | place it into a 4 byte wide field. Since this is a little | |
377 | endian source we can juts use the 4 byte extraction code. */ | |
378 | /* Fall through. */ | |
31b6fca6 | 379 | #endif |
252b5132 RH |
380 | case 4: |
381 | return ((unsigned long) (field [0])) | |
382 | | (((unsigned long) (field [1])) << 8) | |
383 | | (((unsigned long) (field [2])) << 16) | |
384 | | (((unsigned long) (field [3])) << 24); | |
385 | ||
a952a375 | 386 | #ifdef BFD64 |
31b6fca6 | 387 | case 8: |
9ea033b2 NC |
388 | case -8: |
389 | /* This is a special case, generated by the BYTE_GET8 macro. | |
390 | It means that we are loading an 8 byte value from a field | |
391 | in an external structure into an 8 byte value in a field | |
392 | in an internal strcuture. */ | |
393 | return ((bfd_vma) (field [0])) | |
394 | | (((bfd_vma) (field [1])) << 8) | |
395 | | (((bfd_vma) (field [2])) << 16) | |
396 | | (((bfd_vma) (field [3])) << 24) | |
397 | | (((bfd_vma) (field [4])) << 32) | |
398 | | (((bfd_vma) (field [5])) << 40) | |
399 | | (((bfd_vma) (field [6])) << 48) | |
400 | | (((bfd_vma) (field [7])) << 56); | |
a952a375 | 401 | #endif |
252b5132 RH |
402 | default: |
403 | error (_("Unhandled data length: %d\n"), size); | |
9ea033b2 | 404 | abort (); |
252b5132 RH |
405 | } |
406 | } | |
407 | ||
f7a99963 | 408 | /* Print a VMA value. */ |
f7a99963 NC |
409 | static void |
410 | print_vma (vma, mode) | |
411 | bfd_vma vma; | |
412 | print_mode mode; | |
413 | { | |
414 | #ifdef BFD64 | |
415 | if (is_32bit_elf) | |
416 | #endif | |
417 | { | |
418 | switch (mode) | |
419 | { | |
420 | case FULL_HEX: printf ("0x"); /* drop through */ | |
5e220199 | 421 | case LONG_HEX: printf ("%8.8lx", (unsigned long) vma); break; |
f7a99963 | 422 | case PREFIX_HEX: printf ("0x"); /* drop through */ |
5e220199 NC |
423 | case HEX: printf ("%lx", (unsigned long) vma); break; |
424 | case DEC: printf ("%ld", (unsigned long) vma); break; | |
425 | case DEC_5: printf ("%5ld", (long) vma); break; | |
426 | case UNSIGNED: printf ("%lu", (unsigned long) vma); break; | |
f7a99963 NC |
427 | } |
428 | } | |
429 | #ifdef BFD64 | |
430 | else | |
431 | { | |
432 | switch (mode) | |
433 | { | |
434 | case FULL_HEX: | |
435 | printf ("0x"); | |
436 | /* drop through */ | |
76da6bbe | 437 | |
f7a99963 NC |
438 | case LONG_HEX: |
439 | printf_vma (vma); | |
440 | break; | |
76da6bbe | 441 | |
f7a99963 NC |
442 | case PREFIX_HEX: |
443 | printf ("0x"); | |
444 | /* drop through */ | |
76da6bbe | 445 | |
f7a99963 NC |
446 | case HEX: |
447 | #if BFD_HOST_64BIT_LONG | |
448 | printf ("%lx", vma); | |
449 | #else | |
450 | if (_bfd_int64_high (vma)) | |
2f11c261 | 451 | printf ("%lx%8.8lx", _bfd_int64_high (vma), _bfd_int64_low (vma)); |
f7a99963 NC |
452 | else |
453 | printf ("%lx", _bfd_int64_low (vma)); | |
454 | #endif | |
455 | break; | |
456 | ||
457 | case DEC: | |
2f528887 NC |
458 | #if BFD_HOST_64BIT_LONG |
459 | printf ("%ld", vma); | |
460 | #else | |
f7a99963 NC |
461 | if (_bfd_int64_high (vma)) |
462 | /* ugg */ | |
463 | printf ("++%ld", _bfd_int64_low (vma)); | |
464 | else | |
465 | printf ("%ld", _bfd_int64_low (vma)); | |
76da6bbe | 466 | #endif |
f7a99963 NC |
467 | break; |
468 | ||
469 | case DEC_5: | |
2f528887 NC |
470 | #if BFD_HOST_64BIT_LONG |
471 | printf ("%5ld", vma); | |
472 | #else | |
f7a99963 NC |
473 | if (_bfd_int64_high (vma)) |
474 | /* ugg */ | |
475 | printf ("++%ld", _bfd_int64_low (vma)); | |
476 | else | |
477 | printf ("%5ld", _bfd_int64_low (vma)); | |
76da6bbe | 478 | #endif |
f7a99963 | 479 | break; |
76da6bbe | 480 | |
f7a99963 | 481 | case UNSIGNED: |
2f528887 NC |
482 | #if BFD_HOST_64BIT_LONG |
483 | printf ("%lu", vma); | |
76da6bbe | 484 | #else |
f7a99963 NC |
485 | if (_bfd_int64_high (vma)) |
486 | /* ugg */ | |
487 | printf ("++%lu", _bfd_int64_low (vma)); | |
488 | else | |
489 | printf ("%lu", _bfd_int64_low (vma)); | |
2f528887 | 490 | #endif |
f7a99963 NC |
491 | break; |
492 | } | |
493 | } | |
494 | #endif | |
495 | } | |
496 | ||
9ea033b2 | 497 | static bfd_vma |
252b5132 RH |
498 | byte_get_big_endian (field, size) |
499 | unsigned char * field; | |
500 | int size; | |
501 | { | |
502 | switch (size) | |
503 | { | |
504 | case 1: | |
505 | return * field; | |
506 | ||
507 | case 2: | |
508 | return ((unsigned int) (field [1])) | (((int) (field [0])) << 8); | |
509 | ||
510 | case 4: | |
511 | return ((unsigned long) (field [3])) | |
512 | | (((unsigned long) (field [2])) << 8) | |
513 | | (((unsigned long) (field [1])) << 16) | |
514 | | (((unsigned long) (field [0])) << 24); | |
515 | ||
31b6fca6 | 516 | #ifndef BFD64 |
9ea033b2 NC |
517 | case 8: |
518 | /* Although we are extracing data from an 8 byte wide field, we | |
519 | are returning only 4 bytes of data. */ | |
520 | return ((unsigned long) (field [7])) | |
521 | | (((unsigned long) (field [6])) << 8) | |
522 | | (((unsigned long) (field [5])) << 16) | |
523 | | (((unsigned long) (field [4])) << 24); | |
31b6fca6 RH |
524 | #else |
525 | case 8: | |
9ea033b2 NC |
526 | case -8: |
527 | /* This is a special case, generated by the BYTE_GET8 macro. | |
528 | It means that we are loading an 8 byte value from a field | |
529 | in an external structure into an 8 byte value in a field | |
530 | in an internal strcuture. */ | |
531 | return ((bfd_vma) (field [7])) | |
532 | | (((bfd_vma) (field [6])) << 8) | |
533 | | (((bfd_vma) (field [5])) << 16) | |
534 | | (((bfd_vma) (field [4])) << 24) | |
535 | | (((bfd_vma) (field [3])) << 32) | |
536 | | (((bfd_vma) (field [2])) << 40) | |
537 | | (((bfd_vma) (field [1])) << 48) | |
538 | | (((bfd_vma) (field [0])) << 56); | |
a952a375 | 539 | #endif |
103f02d3 | 540 | |
252b5132 RH |
541 | default: |
542 | error (_("Unhandled data length: %d\n"), size); | |
9ea033b2 | 543 | abort (); |
252b5132 RH |
544 | } |
545 | } | |
546 | ||
bcedfee6 | 547 | /* Guess the relocation size commonly used by the specific machines. */ |
252b5132 | 548 | |
252b5132 | 549 | static int |
9c19a809 NC |
550 | guess_is_rela (e_machine) |
551 | unsigned long e_machine; | |
252b5132 | 552 | { |
9c19a809 | 553 | switch (e_machine) |
252b5132 RH |
554 | { |
555 | /* Targets that use REL relocations. */ | |
556 | case EM_ARM: | |
557 | case EM_386: | |
558 | case EM_486: | |
63fcb9e9 | 559 | case EM_960: |
2b0337b0 | 560 | case EM_M32R: |
252b5132 | 561 | case EM_CYGNUS_M32R: |
2b0337b0 | 562 | case EM_D10V: |
252b5132 RH |
563 | case EM_CYGNUS_D10V: |
564 | case EM_MIPS: | |
4fe85591 | 565 | case EM_MIPS_RS3_LE: |
9c19a809 | 566 | return FALSE; |
103f02d3 | 567 | |
252b5132 RH |
568 | /* Targets that use RELA relocations. */ |
569 | case EM_68K: | |
b8720f9d JL |
570 | case EM_H8_300: |
571 | case EM_H8_300H: | |
572 | case EM_H8S: | |
351b4b40 RH |
573 | case EM_SPARC32PLUS: |
574 | case EM_SPARCV9: | |
252b5132 RH |
575 | case EM_SPARC: |
576 | case EM_PPC: | |
2b0337b0 | 577 | case EM_V850: |
252b5132 | 578 | case EM_CYGNUS_V850: |
2b0337b0 | 579 | case EM_D30V: |
252b5132 | 580 | case EM_CYGNUS_D30V: |
2b0337b0 | 581 | case EM_MN10200: |
252b5132 | 582 | case EM_CYGNUS_MN10200: |
2b0337b0 | 583 | case EM_MN10300: |
252b5132 | 584 | case EM_CYGNUS_MN10300: |
2b0337b0 | 585 | case EM_FR30: |
252b5132 RH |
586 | case EM_CYGNUS_FR30: |
587 | case EM_SH: | |
588 | case EM_ALPHA: | |
589 | case EM_MCORE: | |
800eeca4 | 590 | case EM_IA_64: |
dff14200 | 591 | case EM_AVR: |
2b0337b0 | 592 | case EM_AVR_OLD: |
1b61cf92 | 593 | case EM_CRIS: |
535c37ff | 594 | case EM_860: |
bcedfee6 | 595 | case EM_X86_64: |
a85d7ed0 | 596 | case EM_S390: |
b7498e0e | 597 | case EM_S390_OLD: |
3c3bdf30 | 598 | case EM_MMIX: |
93fbbb04 | 599 | case EM_XSTORMY16: |
9c19a809 | 600 | return TRUE; |
103f02d3 | 601 | |
d1133906 NC |
602 | case EM_MMA: |
603 | case EM_PCP: | |
604 | case EM_NCPU: | |
605 | case EM_NDR1: | |
606 | case EM_STARCORE: | |
607 | case EM_ME16: | |
608 | case EM_ST100: | |
609 | case EM_TINYJ: | |
610 | case EM_FX66: | |
611 | case EM_ST9PLUS: | |
612 | case EM_ST7: | |
613 | case EM_68HC16: | |
614 | case EM_68HC11: | |
615 | case EM_68HC08: | |
616 | case EM_68HC05: | |
617 | case EM_SVX: | |
618 | case EM_ST19: | |
619 | case EM_VAX: | |
9c19a809 NC |
620 | default: |
621 | warn (_("Don't know about relocations on this machine architecture\n")); | |
622 | return FALSE; | |
623 | } | |
624 | } | |
252b5132 | 625 | |
9c19a809 | 626 | static int |
4d6ed7c8 NC |
627 | slurp_rela_relocs (file, rel_offset, rel_size, relasp, nrelasp) |
628 | FILE *file; | |
629 | unsigned long rel_offset; | |
630 | unsigned long rel_size; | |
631 | Elf_Internal_Rela **relasp; | |
632 | unsigned long *nrelasp; | |
9c19a809 | 633 | { |
4d6ed7c8 NC |
634 | Elf_Internal_Rela *relas; |
635 | unsigned long nrelas; | |
636 | unsigned int i; | |
252b5132 | 637 | |
4d6ed7c8 NC |
638 | if (is_32bit_elf) |
639 | { | |
640 | Elf32_External_Rela * erelas; | |
103f02d3 | 641 | |
a6e9f9df AM |
642 | erelas = (Elf32_External_Rela *) get_data (NULL, file, rel_offset, |
643 | rel_size, _("relocs")); | |
644 | if (!erelas) | |
645 | return 0; | |
252b5132 | 646 | |
4d6ed7c8 | 647 | nrelas = rel_size / sizeof (Elf32_External_Rela); |
103f02d3 | 648 | |
4d6ed7c8 NC |
649 | relas = (Elf_Internal_Rela *) |
650 | malloc (nrelas * sizeof (Elf_Internal_Rela)); | |
103f02d3 | 651 | |
4d6ed7c8 NC |
652 | if (relas == NULL) |
653 | { | |
654 | error(_("out of memory parsing relocs")); | |
655 | return 0; | |
656 | } | |
103f02d3 | 657 | |
4d6ed7c8 NC |
658 | for (i = 0; i < nrelas; i++) |
659 | { | |
660 | relas[i].r_offset = BYTE_GET (erelas[i].r_offset); | |
661 | relas[i].r_info = BYTE_GET (erelas[i].r_info); | |
662 | relas[i].r_addend = BYTE_GET (erelas[i].r_addend); | |
663 | } | |
103f02d3 | 664 | |
4d6ed7c8 NC |
665 | free (erelas); |
666 | } | |
667 | else | |
668 | { | |
669 | Elf64_External_Rela * erelas; | |
103f02d3 | 670 | |
a6e9f9df AM |
671 | erelas = (Elf64_External_Rela *) get_data (NULL, file, rel_offset, |
672 | rel_size, _("relocs")); | |
673 | if (!erelas) | |
674 | return 0; | |
4d6ed7c8 NC |
675 | |
676 | nrelas = rel_size / sizeof (Elf64_External_Rela); | |
103f02d3 | 677 | |
4d6ed7c8 NC |
678 | relas = (Elf_Internal_Rela *) |
679 | malloc (nrelas * sizeof (Elf_Internal_Rela)); | |
103f02d3 | 680 | |
4d6ed7c8 NC |
681 | if (relas == NULL) |
682 | { | |
683 | error(_("out of memory parsing relocs")); | |
684 | return 0; | |
9c19a809 | 685 | } |
4d6ed7c8 NC |
686 | |
687 | for (i = 0; i < nrelas; i++) | |
9c19a809 | 688 | { |
4d6ed7c8 NC |
689 | relas[i].r_offset = BYTE_GET8 (erelas[i].r_offset); |
690 | relas[i].r_info = BYTE_GET8 (erelas[i].r_info); | |
691 | relas[i].r_addend = BYTE_GET8 (erelas[i].r_addend); | |
692 | } | |
103f02d3 | 693 | |
4d6ed7c8 NC |
694 | free (erelas); |
695 | } | |
696 | *relasp = relas; | |
697 | *nrelasp = nrelas; | |
698 | return 1; | |
699 | } | |
103f02d3 | 700 | |
4d6ed7c8 NC |
701 | static int |
702 | slurp_rel_relocs (file, rel_offset, rel_size, relsp, nrelsp) | |
703 | FILE *file; | |
704 | unsigned long rel_offset; | |
705 | unsigned long rel_size; | |
706 | Elf_Internal_Rel **relsp; | |
707 | unsigned long *nrelsp; | |
708 | { | |
709 | Elf_Internal_Rel *rels; | |
710 | unsigned long nrels; | |
711 | unsigned int i; | |
103f02d3 | 712 | |
4d6ed7c8 NC |
713 | if (is_32bit_elf) |
714 | { | |
715 | Elf32_External_Rel * erels; | |
103f02d3 | 716 | |
a6e9f9df AM |
717 | erels = (Elf32_External_Rel *) get_data (NULL, file, rel_offset, |
718 | rel_size, _("relocs")); | |
719 | if (!erels) | |
720 | return 0; | |
103f02d3 | 721 | |
4d6ed7c8 | 722 | nrels = rel_size / sizeof (Elf32_External_Rel); |
103f02d3 | 723 | |
4d6ed7c8 | 724 | rels = (Elf_Internal_Rel *) malloc (nrels * sizeof (Elf_Internal_Rel)); |
103f02d3 | 725 | |
4d6ed7c8 NC |
726 | if (rels == NULL) |
727 | { | |
728 | error(_("out of memory parsing relocs")); | |
729 | return 0; | |
730 | } | |
731 | ||
732 | for (i = 0; i < nrels; i++) | |
733 | { | |
734 | rels[i].r_offset = BYTE_GET (erels[i].r_offset); | |
735 | rels[i].r_info = BYTE_GET (erels[i].r_info); | |
9ea033b2 | 736 | } |
4d6ed7c8 NC |
737 | |
738 | free (erels); | |
9c19a809 NC |
739 | } |
740 | else | |
741 | { | |
4d6ed7c8 | 742 | Elf64_External_Rel * erels; |
9ea033b2 | 743 | |
a6e9f9df AM |
744 | erels = (Elf64_External_Rel *) get_data (NULL, file, rel_offset, |
745 | rel_size, _("relocs")); | |
746 | if (!erels) | |
747 | return 0; | |
103f02d3 | 748 | |
4d6ed7c8 | 749 | nrels = rel_size / sizeof (Elf64_External_Rel); |
103f02d3 | 750 | |
4d6ed7c8 | 751 | rels = (Elf_Internal_Rel *) malloc (nrels * sizeof (Elf_Internal_Rel)); |
103f02d3 | 752 | |
4d6ed7c8 | 753 | if (rels == NULL) |
9c19a809 | 754 | { |
4d6ed7c8 NC |
755 | error(_("out of memory parsing relocs")); |
756 | return 0; | |
757 | } | |
103f02d3 | 758 | |
4d6ed7c8 NC |
759 | for (i = 0; i < nrels; i++) |
760 | { | |
761 | rels[i].r_offset = BYTE_GET8 (erels[i].r_offset); | |
762 | rels[i].r_info = BYTE_GET8 (erels[i].r_info); | |
763 | } | |
103f02d3 | 764 | |
4d6ed7c8 NC |
765 | free (erels); |
766 | } | |
767 | *relsp = rels; | |
768 | *nrelsp = nrels; | |
769 | return 1; | |
770 | } | |
103f02d3 | 771 | |
4d6ed7c8 NC |
772 | /* Display the contents of the relocation data found at the specified offset. */ |
773 | static int | |
774 | dump_relocations (file, rel_offset, rel_size, symtab, nsyms, strtab, is_rela) | |
775 | FILE * file; | |
776 | unsigned long rel_offset; | |
777 | unsigned long rel_size; | |
778 | Elf_Internal_Sym * symtab; | |
779 | unsigned long nsyms; | |
780 | char * strtab; | |
781 | int is_rela; | |
782 | { | |
783 | unsigned int i; | |
784 | Elf_Internal_Rel * rels; | |
785 | Elf_Internal_Rela * relas; | |
103f02d3 | 786 | |
103f02d3 | 787 | |
4d6ed7c8 NC |
788 | if (is_rela == UNKNOWN) |
789 | is_rela = guess_is_rela (elf_header.e_machine); | |
103f02d3 | 790 | |
4d6ed7c8 NC |
791 | if (is_rela) |
792 | { | |
793 | if (!slurp_rela_relocs (file, rel_offset, rel_size, &relas, &rel_size)) | |
794 | return 0; | |
795 | } | |
796 | else | |
797 | { | |
798 | if (!slurp_rel_relocs (file, rel_offset, rel_size, &rels, &rel_size)) | |
799 | return 0; | |
252b5132 RH |
800 | } |
801 | ||
410f7a12 L |
802 | if (is_32bit_elf) |
803 | { | |
804 | if (is_rela) | |
805 | printf | |
806 | (_(" Offset Info Type Symbol's Value Symbol's Name Addend\n")); | |
807 | else | |
808 | printf | |
809 | (_(" Offset Info Type Symbol's Value Symbol's Name\n")); | |
810 | } | |
252b5132 | 811 | else |
410f7a12 L |
812 | { |
813 | if (is_rela) | |
814 | printf | |
815 | (_(" Offset Info Type Symbol's Value Symbol's Name Addend\n")); | |
816 | else | |
817 | printf | |
818 | (_(" Offset Info Type Symbol's Value Symbol's Name\n")); | |
819 | } | |
252b5132 RH |
820 | |
821 | for (i = 0; i < rel_size; i++) | |
822 | { | |
9ea033b2 NC |
823 | const char * rtype; |
824 | bfd_vma offset; | |
825 | bfd_vma info; | |
826 | bfd_vma symtab_index; | |
827 | bfd_vma type; | |
103f02d3 | 828 | |
252b5132 RH |
829 | if (is_rela) |
830 | { | |
831 | offset = relas [i].r_offset; | |
832 | info = relas [i].r_info; | |
833 | } | |
834 | else | |
835 | { | |
836 | offset = rels [i].r_offset; | |
837 | info = rels [i].r_info; | |
838 | } | |
103f02d3 | 839 | |
9ea033b2 NC |
840 | if (is_32bit_elf) |
841 | { | |
842 | type = ELF32_R_TYPE (info); | |
843 | symtab_index = ELF32_R_SYM (info); | |
844 | } | |
845 | else | |
846 | { | |
351b4b40 RH |
847 | if (elf_header.e_machine == EM_SPARCV9) |
848 | type = ELF64_R_TYPE_ID (info); | |
849 | else | |
850 | type = ELF64_R_TYPE (info); | |
a952a375 NC |
851 | /* The #ifdef BFD64 below is to prevent a compile time warning. |
852 | We know that if we do not have a 64 bit data type that we | |
853 | will never execute this code anyway. */ | |
103f02d3 | 854 | #ifdef BFD64 |
9ea033b2 | 855 | symtab_index = ELF64_R_SYM (info); |
a952a375 | 856 | #endif |
9ea033b2 | 857 | } |
252b5132 | 858 | |
410f7a12 L |
859 | if (is_32bit_elf) |
860 | { | |
861 | #ifdef _bfd_int64_low | |
862 | printf ("%8.8lx %8.8lx ", _bfd_int64_low (offset), _bfd_int64_low (info)); | |
863 | #else | |
864 | printf ("%8.8lx %8.8lx ", offset, info); | |
865 | #endif | |
866 | } | |
867 | else | |
868 | { | |
9ea033b2 | 869 | #ifdef _bfd_int64_low |
410f7a12 L |
870 | printf ("%8.8lx%8.8lx %8.8lx%8.8lx ", |
871 | _bfd_int64_high (offset), | |
872 | _bfd_int64_low (offset), | |
873 | _bfd_int64_high (info), | |
874 | _bfd_int64_low (info)); | |
9ea033b2 | 875 | #else |
410f7a12 | 876 | printf ("%16.16lx %16.16lx ", offset, info); |
9ea033b2 | 877 | #endif |
410f7a12 | 878 | } |
103f02d3 | 879 | |
252b5132 RH |
880 | switch (elf_header.e_machine) |
881 | { | |
882 | default: | |
883 | rtype = NULL; | |
884 | break; | |
885 | ||
2b0337b0 | 886 | case EM_M32R: |
252b5132 | 887 | case EM_CYGNUS_M32R: |
9ea033b2 | 888 | rtype = elf_m32r_reloc_type (type); |
252b5132 RH |
889 | break; |
890 | ||
891 | case EM_386: | |
892 | case EM_486: | |
9ea033b2 | 893 | rtype = elf_i386_reloc_type (type); |
252b5132 RH |
894 | break; |
895 | ||
896 | case EM_68K: | |
9ea033b2 | 897 | rtype = elf_m68k_reloc_type (type); |
252b5132 RH |
898 | break; |
899 | ||
63fcb9e9 | 900 | case EM_960: |
9ea033b2 | 901 | rtype = elf_i960_reloc_type (type); |
63fcb9e9 ILT |
902 | break; |
903 | ||
adde6300 | 904 | case EM_AVR: |
2b0337b0 | 905 | case EM_AVR_OLD: |
adde6300 AM |
906 | rtype = elf_avr_reloc_type (type); |
907 | break; | |
908 | ||
9ea033b2 NC |
909 | case EM_OLD_SPARCV9: |
910 | case EM_SPARC32PLUS: | |
911 | case EM_SPARCV9: | |
252b5132 | 912 | case EM_SPARC: |
9ea033b2 | 913 | rtype = elf_sparc_reloc_type (type); |
252b5132 RH |
914 | break; |
915 | ||
2b0337b0 | 916 | case EM_V850: |
252b5132 | 917 | case EM_CYGNUS_V850: |
9ea033b2 | 918 | rtype = v850_reloc_type (type); |
252b5132 RH |
919 | break; |
920 | ||
2b0337b0 | 921 | case EM_D10V: |
252b5132 | 922 | case EM_CYGNUS_D10V: |
9ea033b2 | 923 | rtype = elf_d10v_reloc_type (type); |
252b5132 RH |
924 | break; |
925 | ||
2b0337b0 | 926 | case EM_D30V: |
252b5132 | 927 | case EM_CYGNUS_D30V: |
9ea033b2 | 928 | rtype = elf_d30v_reloc_type (type); |
252b5132 RH |
929 | break; |
930 | ||
931 | case EM_SH: | |
9ea033b2 | 932 | rtype = elf_sh_reloc_type (type); |
252b5132 RH |
933 | break; |
934 | ||
2b0337b0 | 935 | case EM_MN10300: |
252b5132 | 936 | case EM_CYGNUS_MN10300: |
9ea033b2 | 937 | rtype = elf_mn10300_reloc_type (type); |
252b5132 RH |
938 | break; |
939 | ||
2b0337b0 | 940 | case EM_MN10200: |
252b5132 | 941 | case EM_CYGNUS_MN10200: |
9ea033b2 | 942 | rtype = elf_mn10200_reloc_type (type); |
252b5132 RH |
943 | break; |
944 | ||
2b0337b0 | 945 | case EM_FR30: |
252b5132 | 946 | case EM_CYGNUS_FR30: |
9ea033b2 | 947 | rtype = elf_fr30_reloc_type (type); |
252b5132 RH |
948 | break; |
949 | ||
950 | case EM_MCORE: | |
9ea033b2 | 951 | rtype = elf_mcore_reloc_type (type); |
252b5132 RH |
952 | break; |
953 | ||
3c3bdf30 NC |
954 | case EM_MMIX: |
955 | rtype = elf_mmix_reloc_type (type); | |
956 | break; | |
957 | ||
252b5132 | 958 | case EM_PPC: |
25a1ff5b | 959 | case EM_PPC64: |
9ea033b2 | 960 | rtype = elf_ppc_reloc_type (type); |
252b5132 RH |
961 | break; |
962 | ||
963 | case EM_MIPS: | |
4fe85591 | 964 | case EM_MIPS_RS3_LE: |
9ea033b2 | 965 | rtype = elf_mips_reloc_type (type); |
252b5132 RH |
966 | break; |
967 | ||
968 | case EM_ALPHA: | |
9ea033b2 | 969 | rtype = elf_alpha_reloc_type (type); |
252b5132 RH |
970 | break; |
971 | ||
972 | case EM_ARM: | |
9ea033b2 | 973 | rtype = elf_arm_reloc_type (type); |
252b5132 RH |
974 | break; |
975 | ||
584da044 | 976 | case EM_ARC: |
9ea033b2 | 977 | rtype = elf_arc_reloc_type (type); |
252b5132 RH |
978 | break; |
979 | ||
980 | case EM_PARISC: | |
69e617ca | 981 | rtype = elf_hppa_reloc_type (type); |
252b5132 | 982 | break; |
7d466069 | 983 | |
b8720f9d JL |
984 | case EM_H8_300: |
985 | case EM_H8_300H: | |
986 | case EM_H8S: | |
987 | rtype = elf_h8_reloc_type (type); | |
988 | break; | |
989 | ||
7d466069 | 990 | case EM_PJ: |
2b0337b0 | 991 | case EM_PJ_OLD: |
7d466069 ILT |
992 | rtype = elf_pj_reloc_type (type); |
993 | break; | |
800eeca4 JW |
994 | case EM_IA_64: |
995 | rtype = elf_ia64_reloc_type (type); | |
996 | break; | |
1b61cf92 HPN |
997 | |
998 | case EM_CRIS: | |
999 | rtype = elf_cris_reloc_type (type); | |
1000 | break; | |
535c37ff JE |
1001 | |
1002 | case EM_860: | |
1003 | rtype = elf_i860_reloc_type (type); | |
1004 | break; | |
bcedfee6 NC |
1005 | |
1006 | case EM_X86_64: | |
1007 | rtype = elf_x86_64_reloc_type (type); | |
1008 | break; | |
a85d7ed0 | 1009 | |
b7498e0e | 1010 | case EM_S390_OLD: |
a85d7ed0 NC |
1011 | case EM_S390: |
1012 | rtype = elf_s390_reloc_type (type); | |
1013 | break; | |
93fbbb04 GK |
1014 | |
1015 | case EM_XSTORMY16: | |
1016 | rtype = elf_xstormy16_reloc_type (type); | |
1017 | break; | |
252b5132 RH |
1018 | } |
1019 | ||
1020 | if (rtype == NULL) | |
103f02d3 | 1021 | #ifdef _bfd_int64_low |
9ea033b2 NC |
1022 | printf (_("unrecognised: %-7lx"), _bfd_int64_low (type)); |
1023 | #else | |
1024 | printf (_("unrecognised: %-7lx"), type); | |
1025 | #endif | |
252b5132 RH |
1026 | else |
1027 | printf ("%-21.21s", rtype); | |
1028 | ||
19936277 | 1029 | if (symtab_index) |
252b5132 | 1030 | { |
af3fc3bc AM |
1031 | if (symtab == NULL || symtab_index >= nsyms) |
1032 | printf (" bad symbol index: %08lx", (unsigned long) symtab_index); | |
1033 | else | |
19936277 | 1034 | { |
af3fc3bc | 1035 | Elf_Internal_Sym * psym; |
19936277 | 1036 | |
af3fc3bc | 1037 | psym = symtab + symtab_index; |
103f02d3 | 1038 | |
af3fc3bc AM |
1039 | printf (" "); |
1040 | print_vma (psym->st_value, LONG_HEX); | |
1041 | printf (" "); | |
103f02d3 | 1042 | |
af3fc3bc AM |
1043 | if (psym->st_name == 0) |
1044 | printf ("%-25.25s", | |
1045 | SECTION_NAME (section_headers + psym->st_shndx)); | |
1046 | else if (strtab == NULL) | |
1047 | printf (_("<string table index %3ld>"), psym->st_name); | |
1048 | else | |
1049 | printf ("%-25.25s", strtab + psym->st_name); | |
103f02d3 | 1050 | |
af3fc3bc AM |
1051 | if (is_rela) |
1052 | printf (" + %lx", (unsigned long) relas [i].r_addend); | |
19936277 | 1053 | } |
252b5132 | 1054 | } |
1b228002 | 1055 | else if (is_rela) |
f7a99963 NC |
1056 | { |
1057 | printf ("%*c", is_32bit_elf ? 34 : 26, ' '); | |
1058 | print_vma (relas[i].r_addend, LONG_HEX); | |
1059 | } | |
252b5132 | 1060 | |
351b4b40 RH |
1061 | if (elf_header.e_machine == EM_SPARCV9 |
1062 | && !strcmp (rtype, "R_SPARC_OLO10")) | |
1063 | printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (info)); | |
1064 | ||
252b5132 RH |
1065 | putchar ('\n'); |
1066 | } | |
1067 | ||
88ec60c7 NC |
1068 | if (is_rela) |
1069 | free (relas); | |
1070 | else | |
1071 | free (rels); | |
252b5132 RH |
1072 | |
1073 | return 1; | |
1074 | } | |
1075 | ||
1076 | static const char * | |
1077 | get_mips_dynamic_type (type) | |
1078 | unsigned long type; | |
1079 | { | |
1080 | switch (type) | |
1081 | { | |
1082 | case DT_MIPS_RLD_VERSION: return "MIPS_RLD_VERSION"; | |
1083 | case DT_MIPS_TIME_STAMP: return "MIPS_TIME_STAMP"; | |
1084 | case DT_MIPS_ICHECKSUM: return "MIPS_ICHECKSUM"; | |
1085 | case DT_MIPS_IVERSION: return "MIPS_IVERSION"; | |
1086 | case DT_MIPS_FLAGS: return "MIPS_FLAGS"; | |
1087 | case DT_MIPS_BASE_ADDRESS: return "MIPS_BASE_ADDRESS"; | |
1088 | case DT_MIPS_MSYM: return "MIPS_MSYM"; | |
1089 | case DT_MIPS_CONFLICT: return "MIPS_CONFLICT"; | |
1090 | case DT_MIPS_LIBLIST: return "MIPS_LIBLIST"; | |
1091 | case DT_MIPS_LOCAL_GOTNO: return "MIPS_LOCAL_GOTNO"; | |
1092 | case DT_MIPS_CONFLICTNO: return "MIPS_CONFLICTNO"; | |
1093 | case DT_MIPS_LIBLISTNO: return "MIPS_LIBLISTNO"; | |
1094 | case DT_MIPS_SYMTABNO: return "MIPS_SYMTABNO"; | |
1095 | case DT_MIPS_UNREFEXTNO: return "MIPS_UNREFEXTNO"; | |
1096 | case DT_MIPS_GOTSYM: return "MIPS_GOTSYM"; | |
1097 | case DT_MIPS_HIPAGENO: return "MIPS_HIPAGENO"; | |
1098 | case DT_MIPS_RLD_MAP: return "MIPS_RLD_MAP"; | |
1099 | case DT_MIPS_DELTA_CLASS: return "MIPS_DELTA_CLASS"; | |
1100 | case DT_MIPS_DELTA_CLASS_NO: return "MIPS_DELTA_CLASS_NO"; | |
1101 | case DT_MIPS_DELTA_INSTANCE: return "MIPS_DELTA_INSTANCE"; | |
1102 | case DT_MIPS_DELTA_INSTANCE_NO: return "MIPS_DELTA_INSTANCE_NO"; | |
1103 | case DT_MIPS_DELTA_RELOC: return "MIPS_DELTA_RELOC"; | |
1104 | case DT_MIPS_DELTA_RELOC_NO: return "MIPS_DELTA_RELOC_NO"; | |
1105 | case DT_MIPS_DELTA_SYM: return "MIPS_DELTA_SYM"; | |
1106 | case DT_MIPS_DELTA_SYM_NO: return "MIPS_DELTA_SYM_NO"; | |
1107 | case DT_MIPS_DELTA_CLASSSYM: return "MIPS_DELTA_CLASSSYM"; | |
1108 | case DT_MIPS_DELTA_CLASSSYM_NO: return "MIPS_DELTA_CLASSSYM_NO"; | |
1109 | case DT_MIPS_CXX_FLAGS: return "MIPS_CXX_FLAGS"; | |
1110 | case DT_MIPS_PIXIE_INIT: return "MIPS_PIXIE_INIT"; | |
1111 | case DT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB"; | |
1112 | case DT_MIPS_LOCALPAGE_GOTIDX: return "MIPS_LOCALPAGE_GOTIDX"; | |
1113 | case DT_MIPS_LOCAL_GOTIDX: return "MIPS_LOCAL_GOTIDX"; | |
1114 | case DT_MIPS_HIDDEN_GOTIDX: return "MIPS_HIDDEN_GOTIDX"; | |
1115 | case DT_MIPS_PROTECTED_GOTIDX: return "MIPS_PROTECTED_GOTIDX"; | |
1116 | case DT_MIPS_OPTIONS: return "MIPS_OPTIONS"; | |
1117 | case DT_MIPS_INTERFACE: return "MIPS_INTERFACE"; | |
1118 | case DT_MIPS_DYNSTR_ALIGN: return "MIPS_DYNSTR_ALIGN"; | |
1119 | case DT_MIPS_INTERFACE_SIZE: return "MIPS_INTERFACE_SIZE"; | |
1120 | case DT_MIPS_RLD_TEXT_RESOLVE_ADDR: return "MIPS_RLD_TEXT_RESOLVE_ADDR"; | |
1121 | case DT_MIPS_PERF_SUFFIX: return "MIPS_PERF_SUFFIX"; | |
1122 | case DT_MIPS_COMPACT_SIZE: return "MIPS_COMPACT_SIZE"; | |
1123 | case DT_MIPS_GP_VALUE: return "MIPS_GP_VALUE"; | |
1124 | case DT_MIPS_AUX_DYNAMIC: return "MIPS_AUX_DYNAMIC"; | |
1125 | default: | |
1126 | return NULL; | |
1127 | } | |
1128 | } | |
1129 | ||
9a097730 RH |
1130 | static const char * |
1131 | get_sparc64_dynamic_type (type) | |
1132 | unsigned long type; | |
1133 | { | |
1134 | switch (type) | |
1135 | { | |
1136 | case DT_SPARC_REGISTER: return "SPARC_REGISTER"; | |
1137 | default: | |
1138 | return NULL; | |
1139 | } | |
103f02d3 UD |
1140 | } |
1141 | ||
1142 | static const char * | |
1143 | get_parisc_dynamic_type (type) | |
1144 | unsigned long type; | |
1145 | { | |
1146 | switch (type) | |
1147 | { | |
1148 | case DT_HP_LOAD_MAP: return "HP_LOAD_MAP"; | |
1149 | case DT_HP_DLD_FLAGS: return "HP_DLD_FLAGS"; | |
1150 | case DT_HP_DLD_HOOK: return "HP_DLD_HOOK"; | |
1151 | case DT_HP_UX10_INIT: return "HP_UX10_INIT"; | |
1152 | case DT_HP_UX10_INITSZ: return "HP_UX10_INITSZ"; | |
1153 | case DT_HP_PREINIT: return "HP_PREINIT"; | |
1154 | case DT_HP_PREINITSZ: return "HP_PREINITSZ"; | |
1155 | case DT_HP_NEEDED: return "HP_NEEDED"; | |
1156 | case DT_HP_TIME_STAMP: return "HP_TIME_STAMP"; | |
1157 | case DT_HP_CHECKSUM: return "HP_CHECKSUM"; | |
1158 | case DT_HP_GST_SIZE: return "HP_GST_SIZE"; | |
1159 | case DT_HP_GST_VERSION: return "HP_GST_VERSION"; | |
1160 | case DT_HP_GST_HASHVAL: return "HP_GST_HASHVAL"; | |
1161 | default: | |
1162 | return NULL; | |
1163 | } | |
1164 | } | |
9a097730 | 1165 | |
252b5132 RH |
1166 | static const char * |
1167 | get_dynamic_type (type) | |
1168 | unsigned long type; | |
1169 | { | |
1170 | static char buff [32]; | |
1171 | ||
1172 | switch (type) | |
1173 | { | |
1174 | case DT_NULL: return "NULL"; | |
1175 | case DT_NEEDED: return "NEEDED"; | |
1176 | case DT_PLTRELSZ: return "PLTRELSZ"; | |
1177 | case DT_PLTGOT: return "PLTGOT"; | |
1178 | case DT_HASH: return "HASH"; | |
1179 | case DT_STRTAB: return "STRTAB"; | |
1180 | case DT_SYMTAB: return "SYMTAB"; | |
1181 | case DT_RELA: return "RELA"; | |
1182 | case DT_RELASZ: return "RELASZ"; | |
1183 | case DT_RELAENT: return "RELAENT"; | |
1184 | case DT_STRSZ: return "STRSZ"; | |
1185 | case DT_SYMENT: return "SYMENT"; | |
1186 | case DT_INIT: return "INIT"; | |
1187 | case DT_FINI: return "FINI"; | |
1188 | case DT_SONAME: return "SONAME"; | |
1189 | case DT_RPATH: return "RPATH"; | |
1190 | case DT_SYMBOLIC: return "SYMBOLIC"; | |
1191 | case DT_REL: return "REL"; | |
1192 | case DT_RELSZ: return "RELSZ"; | |
1193 | case DT_RELENT: return "RELENT"; | |
1194 | case DT_PLTREL: return "PLTREL"; | |
1195 | case DT_DEBUG: return "DEBUG"; | |
1196 | case DT_TEXTREL: return "TEXTREL"; | |
1197 | case DT_JMPREL: return "JMPREL"; | |
1198 | case DT_BIND_NOW: return "BIND_NOW"; | |
1199 | case DT_INIT_ARRAY: return "INIT_ARRAY"; | |
1200 | case DT_FINI_ARRAY: return "FINI_ARRAY"; | |
1201 | case DT_INIT_ARRAYSZ: return "INIT_ARRAYSZ"; | |
1202 | case DT_FINI_ARRAYSZ: return "FINI_ARRAYSZ"; | |
d1133906 NC |
1203 | case DT_RUNPATH: return "RUNPATH"; |
1204 | case DT_FLAGS: return "FLAGS"; | |
2d0e6f43 | 1205 | |
d1133906 NC |
1206 | case DT_PREINIT_ARRAY: return "PREINIT_ARRAY"; |
1207 | case DT_PREINIT_ARRAYSZ: return "PREINIT_ARRAYSZ"; | |
103f02d3 | 1208 | |
05107a46 | 1209 | case DT_CHECKSUM: return "CHECKSUM"; |
252b5132 RH |
1210 | case DT_PLTPADSZ: return "PLTPADSZ"; |
1211 | case DT_MOVEENT: return "MOVEENT"; | |
1212 | case DT_MOVESZ: return "MOVESZ"; | |
dcefbbbd | 1213 | case DT_FEATURE: return "FEATURE"; |
252b5132 RH |
1214 | case DT_POSFLAG_1: return "POSFLAG_1"; |
1215 | case DT_SYMINSZ: return "SYMINSZ"; | |
1216 | case DT_SYMINENT: return "SYMINENT"; /* aka VALRNGHI */ | |
103f02d3 | 1217 | |
252b5132 | 1218 | case DT_ADDRRNGLO: return "ADDRRNGLO"; |
dcefbbbd L |
1219 | case DT_CONFIG: return "CONFIG"; |
1220 | case DT_DEPAUDIT: return "DEPAUDIT"; | |
1221 | case DT_AUDIT: return "AUDIT"; | |
1222 | case DT_PLTPAD: return "PLTPAD"; | |
1223 | case DT_MOVETAB: return "MOVETAB"; | |
252b5132 | 1224 | case DT_SYMINFO: return "SYMINFO"; /* aka ADDRRNGHI */ |
103f02d3 | 1225 | |
252b5132 | 1226 | case DT_VERSYM: return "VERSYM"; |
103f02d3 | 1227 | |
252b5132 RH |
1228 | case DT_RELACOUNT: return "RELACOUNT"; |
1229 | case DT_RELCOUNT: return "RELCOUNT"; | |
1230 | case DT_FLAGS_1: return "FLAGS_1"; | |
1231 | case DT_VERDEF: return "VERDEF"; | |
1232 | case DT_VERDEFNUM: return "VERDEFNUM"; | |
1233 | case DT_VERNEED: return "VERNEED"; | |
1234 | case DT_VERNEEDNUM: return "VERNEEDNUM"; | |
103f02d3 | 1235 | |
019148e4 | 1236 | case DT_AUXILIARY: return "AUXILIARY"; |
252b5132 RH |
1237 | case DT_USED: return "USED"; |
1238 | case DT_FILTER: return "FILTER"; | |
103f02d3 | 1239 | |
252b5132 RH |
1240 | default: |
1241 | if ((type >= DT_LOPROC) && (type <= DT_HIPROC)) | |
1242 | { | |
1243 | const char * result; | |
103f02d3 | 1244 | |
252b5132 RH |
1245 | switch (elf_header.e_machine) |
1246 | { | |
1247 | case EM_MIPS: | |
4fe85591 | 1248 | case EM_MIPS_RS3_LE: |
252b5132 RH |
1249 | result = get_mips_dynamic_type (type); |
1250 | break; | |
9a097730 RH |
1251 | case EM_SPARCV9: |
1252 | result = get_sparc64_dynamic_type (type); | |
1253 | break; | |
252b5132 RH |
1254 | default: |
1255 | result = NULL; | |
1256 | break; | |
1257 | } | |
1258 | ||
1259 | if (result != NULL) | |
1260 | return result; | |
1261 | ||
1262 | sprintf (buff, _("Processor Specific: %lx"), type); | |
1263 | } | |
1264 | else if ((type >= DT_LOOS) && (type <= DT_HIOS)) | |
103f02d3 UD |
1265 | { |
1266 | const char * result; | |
1267 | ||
1268 | switch (elf_header.e_machine) | |
1269 | { | |
1270 | case EM_PARISC: | |
1271 | result = get_parisc_dynamic_type (type); | |
1272 | break; | |
1273 | default: | |
1274 | result = NULL; | |
1275 | break; | |
1276 | } | |
1277 | ||
1278 | if (result != NULL) | |
1279 | return result; | |
1280 | ||
1281 | sprintf (buff, _("Operating System specific: %lx"), type); | |
1282 | } | |
252b5132 RH |
1283 | else |
1284 | sprintf (buff, _("<unknown>: %lx"), type); | |
103f02d3 | 1285 | |
252b5132 RH |
1286 | return buff; |
1287 | } | |
1288 | } | |
1289 | ||
1290 | static char * | |
1291 | get_file_type (e_type) | |
1292 | unsigned e_type; | |
1293 | { | |
1294 | static char buff [32]; | |
1295 | ||
1296 | switch (e_type) | |
1297 | { | |
1298 | case ET_NONE: return _("NONE (None)"); | |
1299 | case ET_REL: return _("REL (Relocatable file)"); | |
1300 | case ET_EXEC: return _("EXEC (Executable file)"); | |
1301 | case ET_DYN: return _("DYN (Shared object file)"); | |
1302 | case ET_CORE: return _("CORE (Core file)"); | |
1303 | ||
1304 | default: | |
1305 | if ((e_type >= ET_LOPROC) && (e_type <= ET_HIPROC)) | |
1306 | sprintf (buff, _("Processor Specific: (%x)"), e_type); | |
1307 | else if ((e_type >= ET_LOOS) && (e_type <= ET_HIOS)) | |
1308 | sprintf (buff, _("OS Specific: (%x)"), e_type); | |
1309 | else | |
1310 | sprintf (buff, _("<unknown>: %x"), e_type); | |
1311 | return buff; | |
1312 | } | |
1313 | } | |
1314 | ||
1315 | static char * | |
1316 | get_machine_name (e_machine) | |
1317 | unsigned e_machine; | |
1318 | { | |
d1133906 | 1319 | static char buff [64]; /* XXX */ |
252b5132 RH |
1320 | |
1321 | switch (e_machine) | |
1322 | { | |
c45021f2 NC |
1323 | case EM_NONE: return _("None"); |
1324 | case EM_M32: return "WE32100"; | |
1325 | case EM_SPARC: return "Sparc"; | |
1326 | case EM_386: return "Intel 80386"; | |
1327 | case EM_68K: return "MC68000"; | |
1328 | case EM_88K: return "MC88000"; | |
1329 | case EM_486: return "Intel 80486"; | |
1330 | case EM_860: return "Intel 80860"; | |
1331 | case EM_MIPS: return "MIPS R3000"; | |
1332 | case EM_S370: return "IBM System/370"; | |
7036c0e1 | 1333 | case EM_MIPS_RS3_LE: return "MIPS R4000 big-endian"; |
252b5132 | 1334 | case EM_OLD_SPARCV9: return "Sparc v9 (old)"; |
c45021f2 | 1335 | case EM_PARISC: return "HPPA"; |
252b5132 | 1336 | case EM_PPC_OLD: return "Power PC (old)"; |
7036c0e1 | 1337 | case EM_SPARC32PLUS: return "Sparc v8+" ; |
c45021f2 NC |
1338 | case EM_960: return "Intel 90860"; |
1339 | case EM_PPC: return "PowerPC"; | |
1340 | case EM_V800: return "NEC V800"; | |
1341 | case EM_FR20: return "Fujitsu FR20"; | |
1342 | case EM_RH32: return "TRW RH32"; | |
252b5132 | 1343 | case EM_MCORE: return "MCORE"; |
7036c0e1 AJ |
1344 | case EM_ARM: return "ARM"; |
1345 | case EM_OLD_ALPHA: return "Digital Alpha (old)"; | |
1346 | case EM_SH: return "Hitachi SH"; | |
c45021f2 NC |
1347 | case EM_SPARCV9: return "Sparc v9"; |
1348 | case EM_TRICORE: return "Siemens Tricore"; | |
584da044 | 1349 | case EM_ARC: return "ARC"; |
252b5132 RH |
1350 | case EM_H8_300: return "Hitachi H8/300"; |
1351 | case EM_H8_300H: return "Hitachi H8/300H"; | |
1352 | case EM_H8S: return "Hitachi H8S"; | |
1353 | case EM_H8_500: return "Hitachi H8/500"; | |
30800947 | 1354 | case EM_IA_64: return "Intel IA-64"; |
252b5132 RH |
1355 | case EM_MIPS_X: return "Stanford MIPS-X"; |
1356 | case EM_COLDFIRE: return "Motorola Coldfire"; | |
1357 | case EM_68HC12: return "Motorola M68HC12"; | |
c45021f2 | 1358 | case EM_ALPHA: return "Alpha"; |
2b0337b0 AO |
1359 | case EM_CYGNUS_D10V: |
1360 | case EM_D10V: return "d10v"; | |
1361 | case EM_CYGNUS_D30V: | |
1362 | case EM_D30V: return "d30v"; | |
1363 | case EM_CYGNUS_M32R: | |
1364 | case EM_M32R: return "Mitsubishi M32r"; | |
1365 | case EM_CYGNUS_V850: | |
1366 | case EM_V850: return "NEC v850"; | |
1367 | case EM_CYGNUS_MN10300: | |
1368 | case EM_MN10300: return "mn10300"; | |
1369 | case EM_CYGNUS_MN10200: | |
1370 | case EM_MN10200: return "mn10200"; | |
1371 | case EM_CYGNUS_FR30: | |
1372 | case EM_FR30: return "Fujitsu FR30"; | |
1373 | case EM_PJ_OLD: | |
7d466069 | 1374 | case EM_PJ: return "picoJava"; |
7036c0e1 AJ |
1375 | case EM_MMA: return "Fujitsu Multimedia Accelerator"; |
1376 | case EM_PCP: return "Siemens PCP"; | |
1377 | case EM_NCPU: return "Sony nCPU embedded RISC processor"; | |
1378 | case EM_NDR1: return "Denso NDR1 microprocesspr"; | |
1379 | case EM_STARCORE: return "Motorola Star*Core processor"; | |
1380 | case EM_ME16: return "Toyota ME16 processor"; | |
1381 | case EM_ST100: return "STMicroelectronics ST100 processor"; | |
1382 | case EM_TINYJ: return "Advanced Logic Corp. TinyJ embedded processor"; | |
1383 | case EM_FX66: return "Siemens FX66 microcontroller"; | |
1384 | case EM_ST9PLUS: return "STMicroelectronics ST9+ 8/16 bit microcontroller"; | |
1385 | case EM_ST7: return "STMicroelectronics ST7 8-bit microcontroller"; | |
1386 | case EM_68HC16: return "Motorola MC68HC16 Microcontroller"; | |
1387 | case EM_68HC11: return "Motorola MC68HC11 Microcontroller"; | |
1388 | case EM_68HC08: return "Motorola MC68HC08 Microcontroller"; | |
1389 | case EM_68HC05: return "Motorola MC68HC05 Microcontroller"; | |
1390 | case EM_SVX: return "Silicon Graphics SVx"; | |
1391 | case EM_ST19: return "STMicroelectronics ST19 8-bit microcontroller"; | |
1392 | case EM_VAX: return "Digital VAX"; | |
2b0337b0 | 1393 | case EM_AVR_OLD: |
dff14200 | 1394 | case EM_AVR: return "Atmel AVR 8-bit microcontroller"; |
1b61cf92 | 1395 | case EM_CRIS: return "Axis Communications 32-bit embedded processor"; |
c45021f2 NC |
1396 | case EM_JAVELIN: return "Infineon Technologies 32-bit embedded cpu"; |
1397 | case EM_FIREPATH: return "Element 14 64-bit DSP processor"; | |
1398 | case EM_ZSP: return "LSI Logic's 16-bit DSP processor"; | |
93ebe586 | 1399 | case EM_MMIX: return "Donald Knuth's educational 64-bit processor"; |
c45021f2 NC |
1400 | case EM_HUANY: return "Harvard Universitys's machine-independent object format"; |
1401 | case EM_PRISM: return "SiTera Prism"; | |
bcedfee6 | 1402 | case EM_X86_64: return "Advanced Micro Devices X86-64"; |
b7498e0e | 1403 | case EM_S390_OLD: |
a85d7ed0 | 1404 | case EM_S390: return "IBM S/390"; |
93fbbb04 | 1405 | case EM_XSTORMY16: return "Sanyo Xstormy16 CPU core"; |
252b5132 RH |
1406 | default: |
1407 | sprintf (buff, _("<unknown>: %x"), e_machine); | |
1408 | return buff; | |
1409 | } | |
1410 | } | |
1411 | ||
f3485b74 NC |
1412 | static void |
1413 | decode_ARM_machine_flags (e_flags, buf) | |
1414 | unsigned e_flags; | |
1415 | char buf[]; | |
1416 | { | |
1417 | unsigned eabi; | |
1418 | int unknown = 0; | |
1419 | ||
1420 | eabi = EF_ARM_EABI_VERSION (e_flags); | |
1421 | e_flags &= ~ EF_ARM_EABIMASK; | |
1422 | ||
1423 | /* Handle "generic" ARM flags. */ | |
1424 | if (e_flags & EF_ARM_RELEXEC) | |
1425 | { | |
1426 | strcat (buf, ", relocatable executable"); | |
1427 | e_flags &= ~ EF_ARM_RELEXEC; | |
1428 | } | |
76da6bbe | 1429 | |
f3485b74 NC |
1430 | if (e_flags & EF_ARM_HASENTRY) |
1431 | { | |
1432 | strcat (buf, ", has entry point"); | |
1433 | e_flags &= ~ EF_ARM_HASENTRY; | |
1434 | } | |
76da6bbe | 1435 | |
f3485b74 NC |
1436 | /* Now handle EABI specific flags. */ |
1437 | switch (eabi) | |
1438 | { | |
1439 | default: | |
a5bcd848 | 1440 | strcat (buf, ", <unrecognised EABI>"); |
f3485b74 NC |
1441 | if (e_flags) |
1442 | unknown = 1; | |
1443 | break; | |
1444 | ||
1445 | case EF_ARM_EABI_VER1: | |
a5bcd848 | 1446 | strcat (buf, ", Version1 EABI"); |
f3485b74 NC |
1447 | while (e_flags) |
1448 | { | |
1449 | unsigned flag; | |
76da6bbe | 1450 | |
f3485b74 NC |
1451 | /* Process flags one bit at a time. */ |
1452 | flag = e_flags & - e_flags; | |
1453 | e_flags &= ~ flag; | |
76da6bbe | 1454 | |
f3485b74 NC |
1455 | switch (flag) |
1456 | { | |
a5bcd848 | 1457 | case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK. */ |
f3485b74 NC |
1458 | strcat (buf, ", sorted symbol tables"); |
1459 | break; | |
76da6bbe | 1460 | |
f3485b74 NC |
1461 | default: |
1462 | unknown = 1; | |
1463 | break; | |
1464 | } | |
1465 | } | |
1466 | break; | |
76da6bbe | 1467 | |
a5bcd848 PB |
1468 | case EF_ARM_EABI_VER2: |
1469 | strcat (buf, ", Version2 EABI"); | |
1470 | while (e_flags) | |
1471 | { | |
1472 | unsigned flag; | |
1473 | ||
1474 | /* Process flags one bit at a time. */ | |
1475 | flag = e_flags & - e_flags; | |
1476 | e_flags &= ~ flag; | |
1477 | ||
1478 | switch (flag) | |
1479 | { | |
1480 | case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK. */ | |
1481 | strcat (buf, ", sorted symbol tables"); | |
1482 | break; | |
1483 | ||
1484 | case EF_ARM_DYNSYMSUSESEGIDX: | |
1485 | strcat (buf, ", dynamic symbols use segment index"); | |
1486 | break; | |
1487 | ||
1488 | case EF_ARM_MAPSYMSFIRST: | |
1489 | strcat (buf, ", mapping symbols precede others"); | |
1490 | break; | |
1491 | ||
1492 | default: | |
1493 | unknown = 1; | |
1494 | break; | |
1495 | } | |
1496 | } | |
1497 | break; | |
1498 | ||
f3485b74 | 1499 | case EF_ARM_EABI_UNKNOWN: |
a5bcd848 | 1500 | strcat (buf, ", GNU EABI"); |
f3485b74 NC |
1501 | while (e_flags) |
1502 | { | |
1503 | unsigned flag; | |
76da6bbe | 1504 | |
f3485b74 NC |
1505 | /* Process flags one bit at a time. */ |
1506 | flag = e_flags & - e_flags; | |
1507 | e_flags &= ~ flag; | |
76da6bbe | 1508 | |
f3485b74 NC |
1509 | switch (flag) |
1510 | { | |
a5bcd848 | 1511 | case EF_ARM_INTERWORK: |
f3485b74 NC |
1512 | strcat (buf, ", interworking enabled"); |
1513 | break; | |
76da6bbe | 1514 | |
a5bcd848 | 1515 | case EF_ARM_APCS_26: |
f3485b74 NC |
1516 | strcat (buf, ", uses APCS/26"); |
1517 | break; | |
76da6bbe | 1518 | |
a5bcd848 | 1519 | case EF_ARM_APCS_FLOAT: |
f3485b74 NC |
1520 | strcat (buf, ", uses APCS/float"); |
1521 | break; | |
76da6bbe | 1522 | |
a5bcd848 | 1523 | case EF_ARM_PIC: |
f3485b74 NC |
1524 | strcat (buf, ", position independent"); |
1525 | break; | |
76da6bbe | 1526 | |
a5bcd848 | 1527 | case EF_ARM_ALIGN8: |
f3485b74 NC |
1528 | strcat (buf, ", 8 bit structure alignment"); |
1529 | break; | |
76da6bbe | 1530 | |
a5bcd848 | 1531 | case EF_ARM_NEW_ABI: |
f3485b74 NC |
1532 | strcat (buf, ", uses new ABI"); |
1533 | break; | |
76da6bbe | 1534 | |
a5bcd848 | 1535 | case EF_ARM_OLD_ABI: |
f3485b74 NC |
1536 | strcat (buf, ", uses old ABI"); |
1537 | break; | |
76da6bbe | 1538 | |
a5bcd848 | 1539 | case EF_ARM_SOFT_FLOAT: |
f3485b74 NC |
1540 | strcat (buf, ", software FP"); |
1541 | break; | |
76da6bbe | 1542 | |
f3485b74 NC |
1543 | default: |
1544 | unknown = 1; | |
1545 | break; | |
1546 | } | |
1547 | } | |
1548 | } | |
f3485b74 NC |
1549 | |
1550 | if (unknown) | |
1551 | strcat (buf,", <unknown>"); | |
1552 | } | |
1553 | ||
252b5132 RH |
1554 | static char * |
1555 | get_machine_flags (e_flags, e_machine) | |
1556 | unsigned e_flags; | |
1557 | unsigned e_machine; | |
1558 | { | |
1559 | static char buf [1024]; | |
1560 | ||
1561 | buf[0] = '\0'; | |
76da6bbe | 1562 | |
252b5132 RH |
1563 | if (e_flags) |
1564 | { | |
1565 | switch (e_machine) | |
1566 | { | |
1567 | default: | |
1568 | break; | |
1569 | ||
f3485b74 NC |
1570 | case EM_ARM: |
1571 | decode_ARM_machine_flags (e_flags, buf); | |
1572 | break; | |
76da6bbe | 1573 | |
33c63f9d CM |
1574 | case EM_68K: |
1575 | if (e_flags & EF_CPU32) | |
1576 | strcat (buf, ", cpu32"); | |
1577 | break; | |
1578 | ||
252b5132 RH |
1579 | case EM_PPC: |
1580 | if (e_flags & EF_PPC_EMB) | |
1581 | strcat (buf, ", emb"); | |
1582 | ||
1583 | if (e_flags & EF_PPC_RELOCATABLE) | |
1584 | strcat (buf, ", relocatable"); | |
1585 | ||
1586 | if (e_flags & EF_PPC_RELOCATABLE_LIB) | |
1587 | strcat (buf, ", relocatable-lib"); | |
1588 | break; | |
1589 | ||
2b0337b0 | 1590 | case EM_V850: |
252b5132 RH |
1591 | case EM_CYGNUS_V850: |
1592 | switch (e_flags & EF_V850_ARCH) | |
1593 | { | |
1594 | case E_V850E_ARCH: | |
1595 | strcat (buf, ", v850e"); | |
1596 | break; | |
1597 | case E_V850EA_ARCH: | |
1598 | strcat (buf, ", v850ea"); | |
1599 | break; | |
1600 | case E_V850_ARCH: | |
1601 | strcat (buf, ", v850"); | |
1602 | break; | |
1603 | default: | |
1604 | strcat (buf, ", unknown v850 architecture variant"); | |
1605 | break; | |
1606 | } | |
1607 | break; | |
1608 | ||
2b0337b0 | 1609 | case EM_M32R: |
252b5132 RH |
1610 | case EM_CYGNUS_M32R: |
1611 | if ((e_flags & EF_M32R_ARCH) == E_M32R_ARCH) | |
1612 | strcat (buf, ", m32r"); | |
1613 | ||
1614 | break; | |
1615 | ||
1616 | case EM_MIPS: | |
4fe85591 | 1617 | case EM_MIPS_RS3_LE: |
252b5132 RH |
1618 | if (e_flags & EF_MIPS_NOREORDER) |
1619 | strcat (buf, ", noreorder"); | |
1620 | ||
1621 | if (e_flags & EF_MIPS_PIC) | |
1622 | strcat (buf, ", pic"); | |
1623 | ||
1624 | if (e_flags & EF_MIPS_CPIC) | |
1625 | strcat (buf, ", cpic"); | |
1626 | ||
d1bdd336 TS |
1627 | if (e_flags & EF_MIPS_UCODE) |
1628 | strcat (buf, ", ugen_reserved"); | |
1629 | ||
252b5132 RH |
1630 | if (e_flags & EF_MIPS_ABI2) |
1631 | strcat (buf, ", abi2"); | |
1632 | ||
a5d22d2a TS |
1633 | if (e_flags & EF_MIPS_32BITMODE) |
1634 | strcat (buf, ", 32bitmode"); | |
1635 | ||
252b5132 RH |
1636 | if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_1) |
1637 | strcat (buf, ", mips1"); | |
1638 | ||
1639 | if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_2) | |
1640 | strcat (buf, ", mips2"); | |
1641 | ||
1642 | if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_3) | |
1643 | strcat (buf, ", mips3"); | |
1644 | ||
1645 | if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_4) | |
1646 | strcat (buf, ", mips4"); | |
156c2f8b | 1647 | |
84ea6cf2 NC |
1648 | if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_5) |
1649 | strcat (buf, ", mips5"); | |
1650 | ||
e7af610e NC |
1651 | if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_32) |
1652 | strcat (buf, ", mips32"); | |
1653 | ||
84ea6cf2 NC |
1654 | if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_64) |
1655 | strcat (buf, ", mips64"); | |
1656 | ||
156c2f8b NC |
1657 | switch ((e_flags & EF_MIPS_MACH)) |
1658 | { | |
1659 | case E_MIPS_MACH_3900: strcat (buf, ", 3900"); break; | |
1660 | case E_MIPS_MACH_4010: strcat (buf, ", 4010"); break; | |
1661 | case E_MIPS_MACH_4100: strcat (buf, ", 4100"); break; | |
1662 | case E_MIPS_MACH_4650: strcat (buf, ", 4650"); break; | |
1663 | case E_MIPS_MACH_4111: strcat (buf, ", 4111"); break; | |
c6c98b38 | 1664 | case E_MIPS_MACH_SB1: strcat (buf, ", sb1"); break; |
e7af610e | 1665 | default: strcat (buf, " UNKNOWN"); break; |
156c2f8b | 1666 | } |
252b5132 | 1667 | break; |
351b4b40 RH |
1668 | |
1669 | case EM_SPARCV9: | |
1670 | if (e_flags & EF_SPARC_32PLUS) | |
1671 | strcat (buf, ", v8+"); | |
1672 | ||
1673 | if (e_flags & EF_SPARC_SUN_US1) | |
d07faca2 RH |
1674 | strcat (buf, ", ultrasparcI"); |
1675 | ||
1676 | if (e_flags & EF_SPARC_SUN_US3) | |
1677 | strcat (buf, ", ultrasparcIII"); | |
351b4b40 RH |
1678 | |
1679 | if (e_flags & EF_SPARC_HAL_R1) | |
1680 | strcat (buf, ", halr1"); | |
1681 | ||
1682 | if (e_flags & EF_SPARC_LEDATA) | |
1683 | strcat (buf, ", ledata"); | |
1684 | ||
1685 | if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_TSO) | |
1686 | strcat (buf, ", tso"); | |
1687 | ||
1688 | if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_PSO) | |
1689 | strcat (buf, ", pso"); | |
1690 | ||
1691 | if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_RMO) | |
1692 | strcat (buf, ", rmo"); | |
1693 | break; | |
7d466069 | 1694 | |
103f02d3 UD |
1695 | case EM_PARISC: |
1696 | switch (e_flags & EF_PARISC_ARCH) | |
1697 | { | |
1698 | case EFA_PARISC_1_0: | |
1699 | strcpy (buf, ", PA-RISC 1.0"); | |
1700 | break; | |
1701 | case EFA_PARISC_1_1: | |
1702 | strcpy (buf, ", PA-RISC 1.1"); | |
1703 | break; | |
1704 | case EFA_PARISC_2_0: | |
1705 | strcpy (buf, ", PA-RISC 2.0"); | |
1706 | break; | |
1707 | default: | |
1708 | break; | |
1709 | } | |
1710 | if (e_flags & EF_PARISC_TRAPNIL) | |
1711 | strcat (buf, ", trapnil"); | |
1712 | if (e_flags & EF_PARISC_EXT) | |
1713 | strcat (buf, ", ext"); | |
1714 | if (e_flags & EF_PARISC_LSB) | |
1715 | strcat (buf, ", lsb"); | |
1716 | if (e_flags & EF_PARISC_WIDE) | |
1717 | strcat (buf, ", wide"); | |
1718 | if (e_flags & EF_PARISC_NO_KABP) | |
1719 | strcat (buf, ", no kabp"); | |
1720 | if (e_flags & EF_PARISC_LAZYSWAP) | |
1721 | strcat (buf, ", lazyswap"); | |
30800947 | 1722 | break; |
76da6bbe | 1723 | |
7d466069 | 1724 | case EM_PJ: |
2b0337b0 | 1725 | case EM_PJ_OLD: |
7d466069 ILT |
1726 | if ((e_flags & EF_PICOJAVA_NEWCALLS) == EF_PICOJAVA_NEWCALLS) |
1727 | strcat (buf, ", new calling convention"); | |
1728 | ||
1729 | if ((e_flags & EF_PICOJAVA_GNUCALLS) == EF_PICOJAVA_GNUCALLS) | |
1730 | strcat (buf, ", gnu calling convention"); | |
1731 | break; | |
4d6ed7c8 NC |
1732 | |
1733 | case EM_IA_64: | |
1734 | if ((e_flags & EF_IA_64_ABI64)) | |
1735 | strcat (buf, ", 64-bit"); | |
1736 | else | |
1737 | strcat (buf, ", 32-bit"); | |
1738 | if ((e_flags & EF_IA_64_REDUCEDFP)) | |
1739 | strcat (buf, ", reduced fp model"); | |
1740 | if ((e_flags & EF_IA_64_NOFUNCDESC_CONS_GP)) | |
1741 | strcat (buf, ", no function descriptors, constant gp"); | |
1742 | else if ((e_flags & EF_IA_64_CONS_GP)) | |
1743 | strcat (buf, ", constant gp"); | |
1744 | if ((e_flags & EF_IA_64_ABSOLUTE)) | |
1745 | strcat (buf, ", absolute"); | |
1746 | break; | |
252b5132 RH |
1747 | } |
1748 | } | |
1749 | ||
1750 | return buf; | |
1751 | } | |
1752 | ||
252b5132 RH |
1753 | static const char * |
1754 | get_mips_segment_type (type) | |
1755 | unsigned long type; | |
1756 | { | |
1757 | switch (type) | |
1758 | { | |
1759 | case PT_MIPS_REGINFO: | |
1760 | return "REGINFO"; | |
1761 | case PT_MIPS_RTPROC: | |
1762 | return "RTPROC"; | |
1763 | case PT_MIPS_OPTIONS: | |
1764 | return "OPTIONS"; | |
1765 | default: | |
1766 | break; | |
1767 | } | |
1768 | ||
1769 | return NULL; | |
1770 | } | |
1771 | ||
103f02d3 UD |
1772 | static const char * |
1773 | get_parisc_segment_type (type) | |
1774 | unsigned long type; | |
1775 | { | |
1776 | switch (type) | |
1777 | { | |
1778 | case PT_HP_TLS: return "HP_TLS"; | |
1779 | case PT_HP_CORE_NONE: return "HP_CORE_NONE"; | |
1780 | case PT_HP_CORE_VERSION: return "HP_CORE_VERSION"; | |
1781 | case PT_HP_CORE_KERNEL: return "HP_CORE_KERNEL"; | |
1782 | case PT_HP_CORE_COMM: return "HP_CORE_COMM"; | |
1783 | case PT_HP_CORE_PROC: return "HP_CORE_PROC"; | |
1784 | case PT_HP_CORE_LOADABLE: return "HP_CORE_LOADABLE"; | |
1785 | case PT_HP_CORE_STACK: return "HP_CORE_STACK"; | |
1786 | case PT_HP_CORE_SHM: return "HP_CORE_SHM"; | |
1787 | case PT_HP_CORE_MMF: return "HP_CORE_MMF"; | |
1788 | case PT_HP_PARALLEL: return "HP_PARALLEL"; | |
1789 | case PT_HP_FASTBIND: return "HP_FASTBIND"; | |
1790 | case PT_PARISC_ARCHEXT: return "PARISC_ARCHEXT"; | |
1791 | case PT_PARISC_UNWIND: return "PARISC_UNWIND"; | |
1792 | default: | |
1793 | break; | |
1794 | } | |
1795 | ||
1796 | return NULL; | |
1797 | } | |
1798 | ||
4d6ed7c8 NC |
1799 | static const char * |
1800 | get_ia64_segment_type (type) | |
1801 | unsigned long type; | |
1802 | { | |
1803 | switch (type) | |
1804 | { | |
1805 | case PT_IA_64_ARCHEXT: return "IA_64_ARCHEXT"; | |
1806 | case PT_IA_64_UNWIND: return "IA_64_UNWIND"; | |
1807 | default: | |
1808 | break; | |
1809 | } | |
1810 | ||
1811 | return NULL; | |
1812 | } | |
1813 | ||
252b5132 RH |
1814 | static const char * |
1815 | get_segment_type (p_type) | |
1816 | unsigned long p_type; | |
1817 | { | |
1818 | static char buff [32]; | |
1819 | ||
1820 | switch (p_type) | |
1821 | { | |
1822 | case PT_NULL: return "NULL"; | |
1823 | case PT_LOAD: return "LOAD"; | |
1824 | case PT_DYNAMIC: return "DYNAMIC"; | |
1825 | case PT_INTERP: return "INTERP"; | |
1826 | case PT_NOTE: return "NOTE"; | |
1827 | case PT_SHLIB: return "SHLIB"; | |
1828 | case PT_PHDR: return "PHDR"; | |
1829 | ||
1830 | default: | |
1831 | if ((p_type >= PT_LOPROC) && (p_type <= PT_HIPROC)) | |
1832 | { | |
1833 | const char * result; | |
103f02d3 | 1834 | |
252b5132 RH |
1835 | switch (elf_header.e_machine) |
1836 | { | |
1837 | case EM_MIPS: | |
4fe85591 | 1838 | case EM_MIPS_RS3_LE: |
252b5132 RH |
1839 | result = get_mips_segment_type (p_type); |
1840 | break; | |
103f02d3 UD |
1841 | case EM_PARISC: |
1842 | result = get_parisc_segment_type (p_type); | |
1843 | break; | |
4d6ed7c8 NC |
1844 | case EM_IA_64: |
1845 | result = get_ia64_segment_type (p_type); | |
1846 | break; | |
252b5132 RH |
1847 | default: |
1848 | result = NULL; | |
1849 | break; | |
1850 | } | |
103f02d3 | 1851 | |
252b5132 RH |
1852 | if (result != NULL) |
1853 | return result; | |
103f02d3 | 1854 | |
252b5132 RH |
1855 | sprintf (buff, "LOPROC+%lx", p_type - PT_LOPROC); |
1856 | } | |
1857 | else if ((p_type >= PT_LOOS) && (p_type <= PT_HIOS)) | |
103f02d3 UD |
1858 | { |
1859 | const char * result; | |
1860 | ||
1861 | switch (elf_header.e_machine) | |
1862 | { | |
1863 | case EM_PARISC: | |
1864 | result = get_parisc_segment_type (p_type); | |
1865 | break; | |
1866 | default: | |
1867 | result = NULL; | |
1868 | break; | |
1869 | } | |
1870 | ||
1871 | if (result != NULL) | |
1872 | return result; | |
1873 | ||
1874 | sprintf (buff, "LOOS+%lx", p_type - PT_LOOS); | |
1875 | } | |
252b5132 RH |
1876 | else |
1877 | sprintf (buff, _("<unknown>: %lx"), p_type); | |
1878 | ||
1879 | return buff; | |
1880 | } | |
1881 | } | |
1882 | ||
1883 | static const char * | |
1884 | get_mips_section_type_name (sh_type) | |
1885 | unsigned int sh_type; | |
1886 | { | |
1887 | switch (sh_type) | |
1888 | { | |
1889 | case SHT_MIPS_LIBLIST: return "MIPS_LIBLIST"; | |
1890 | case SHT_MIPS_MSYM: return "MIPS_MSYM"; | |
1891 | case SHT_MIPS_CONFLICT: return "MIPS_CONFLICT"; | |
1892 | case SHT_MIPS_GPTAB: return "MIPS_GPTAB"; | |
1893 | case SHT_MIPS_UCODE: return "MIPS_UCODE"; | |
1894 | case SHT_MIPS_DEBUG: return "MIPS_DEBUG"; | |
1895 | case SHT_MIPS_REGINFO: return "MIPS_REGINFO"; | |
1896 | case SHT_MIPS_PACKAGE: return "MIPS_PACKAGE"; | |
1897 | case SHT_MIPS_PACKSYM: return "MIPS_PACKSYM"; | |
1898 | case SHT_MIPS_RELD: return "MIPS_RELD"; | |
1899 | case SHT_MIPS_IFACE: return "MIPS_IFACE"; | |
1900 | case SHT_MIPS_CONTENT: return "MIPS_CONTENT"; | |
1901 | case SHT_MIPS_OPTIONS: return "MIPS_OPTIONS"; | |
1902 | case SHT_MIPS_SHDR: return "MIPS_SHDR"; | |
1903 | case SHT_MIPS_FDESC: return "MIPS_FDESC"; | |
1904 | case SHT_MIPS_EXTSYM: return "MIPS_EXTSYM"; | |
1905 | case SHT_MIPS_DENSE: return "MIPS_DENSE"; | |
1906 | case SHT_MIPS_PDESC: return "MIPS_PDESC"; | |
1907 | case SHT_MIPS_LOCSYM: return "MIPS_LOCSYM"; | |
1908 | case SHT_MIPS_AUXSYM: return "MIPS_AUXSYM"; | |
1909 | case SHT_MIPS_OPTSYM: return "MIPS_OPTSYM"; | |
1910 | case SHT_MIPS_LOCSTR: return "MIPS_LOCSTR"; | |
1911 | case SHT_MIPS_LINE: return "MIPS_LINE"; | |
1912 | case SHT_MIPS_RFDESC: return "MIPS_RFDESC"; | |
1913 | case SHT_MIPS_DELTASYM: return "MIPS_DELTASYM"; | |
1914 | case SHT_MIPS_DELTAINST: return "MIPS_DELTAINST"; | |
1915 | case SHT_MIPS_DELTACLASS: return "MIPS_DELTACLASS"; | |
1916 | case SHT_MIPS_DWARF: return "MIPS_DWARF"; | |
1917 | case SHT_MIPS_DELTADECL: return "MIPS_DELTADECL"; | |
1918 | case SHT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB"; | |
1919 | case SHT_MIPS_EVENTS: return "MIPS_EVENTS"; | |
1920 | case SHT_MIPS_TRANSLATE: return "MIPS_TRANSLATE"; | |
1921 | case SHT_MIPS_PIXIE: return "MIPS_PIXIE"; | |
1922 | case SHT_MIPS_XLATE: return "MIPS_XLATE"; | |
1923 | case SHT_MIPS_XLATE_DEBUG: return "MIPS_XLATE_DEBUG"; | |
1924 | case SHT_MIPS_WHIRL: return "MIPS_WHIRL"; | |
1925 | case SHT_MIPS_EH_REGION: return "MIPS_EH_REGION"; | |
1926 | case SHT_MIPS_XLATE_OLD: return "MIPS_XLATE_OLD"; | |
1927 | case SHT_MIPS_PDR_EXCEPTION: return "MIPS_PDR_EXCEPTION"; | |
1928 | default: | |
1929 | break; | |
1930 | } | |
1931 | return NULL; | |
1932 | } | |
1933 | ||
103f02d3 UD |
1934 | static const char * |
1935 | get_parisc_section_type_name (sh_type) | |
1936 | unsigned int sh_type; | |
1937 | { | |
1938 | switch (sh_type) | |
1939 | { | |
1940 | case SHT_PARISC_EXT: return "PARISC_EXT"; | |
1941 | case SHT_PARISC_UNWIND: return "PARISC_UNWIND"; | |
1942 | case SHT_PARISC_DOC: return "PARISC_DOC"; | |
1943 | default: | |
1944 | break; | |
1945 | } | |
1946 | return NULL; | |
1947 | } | |
1948 | ||
4d6ed7c8 NC |
1949 | static const char * |
1950 | get_ia64_section_type_name (sh_type) | |
1951 | unsigned int sh_type; | |
1952 | { | |
1953 | switch (sh_type) | |
1954 | { | |
1955 | case SHT_IA_64_EXT: return "IA_64_EXT"; | |
1956 | case SHT_IA_64_UNWIND: return "IA_64_UNWIND"; | |
1957 | default: | |
1958 | break; | |
1959 | } | |
1960 | return NULL; | |
1961 | } | |
1962 | ||
252b5132 RH |
1963 | static const char * |
1964 | get_section_type_name (sh_type) | |
1965 | unsigned int sh_type; | |
1966 | { | |
1967 | static char buff [32]; | |
1968 | ||
1969 | switch (sh_type) | |
1970 | { | |
1971 | case SHT_NULL: return "NULL"; | |
1972 | case SHT_PROGBITS: return "PROGBITS"; | |
1973 | case SHT_SYMTAB: return "SYMTAB"; | |
1974 | case SHT_STRTAB: return "STRTAB"; | |
1975 | case SHT_RELA: return "RELA"; | |
1976 | case SHT_HASH: return "HASH"; | |
1977 | case SHT_DYNAMIC: return "DYNAMIC"; | |
1978 | case SHT_NOTE: return "NOTE"; | |
1979 | case SHT_NOBITS: return "NOBITS"; | |
1980 | case SHT_REL: return "REL"; | |
1981 | case SHT_SHLIB: return "SHLIB"; | |
1982 | case SHT_DYNSYM: return "DYNSYM"; | |
d1133906 NC |
1983 | case SHT_INIT_ARRAY: return "INIT_ARRAY"; |
1984 | case SHT_FINI_ARRAY: return "FINI_ARRAY"; | |
1985 | case SHT_PREINIT_ARRAY: return "PREINIT_ARRAY"; | |
93ebe586 NC |
1986 | case SHT_GROUP: return "GROUP"; |
1987 | case SHT_SYMTAB_SHNDX: return "SYMTAB SECTION INDICIES"; | |
252b5132 RH |
1988 | case SHT_GNU_verdef: return "VERDEF"; |
1989 | case SHT_GNU_verneed: return "VERNEED"; | |
1990 | case SHT_GNU_versym: return "VERSYM"; | |
1991 | case 0x6ffffff0: return "VERSYM"; | |
1992 | case 0x6ffffffc: return "VERDEF"; | |
1993 | case 0x7ffffffd: return "AUXILIARY"; | |
1994 | case 0x7fffffff: return "FILTER"; | |
1995 | ||
1996 | default: | |
1997 | if ((sh_type >= SHT_LOPROC) && (sh_type <= SHT_HIPROC)) | |
1998 | { | |
1999 | const char * result; | |
2000 | ||
2001 | switch (elf_header.e_machine) | |
2002 | { | |
2003 | case EM_MIPS: | |
4fe85591 | 2004 | case EM_MIPS_RS3_LE: |
252b5132 RH |
2005 | result = get_mips_section_type_name (sh_type); |
2006 | break; | |
103f02d3 UD |
2007 | case EM_PARISC: |
2008 | result = get_parisc_section_type_name (sh_type); | |
2009 | break; | |
4d6ed7c8 NC |
2010 | case EM_IA_64: |
2011 | result = get_ia64_section_type_name (sh_type); | |
2012 | break; | |
252b5132 RH |
2013 | default: |
2014 | result = NULL; | |
2015 | break; | |
2016 | } | |
2017 | ||
2018 | if (result != NULL) | |
2019 | return result; | |
2020 | ||
c91d0dfb | 2021 | sprintf (buff, "LOPROC+%x", sh_type - SHT_LOPROC); |
252b5132 RH |
2022 | } |
2023 | else if ((sh_type >= SHT_LOOS) && (sh_type <= SHT_HIOS)) | |
c91d0dfb | 2024 | sprintf (buff, "LOOS+%x", sh_type - SHT_LOOS); |
252b5132 | 2025 | else if ((sh_type >= SHT_LOUSER) && (sh_type <= SHT_HIUSER)) |
c91d0dfb | 2026 | sprintf (buff, "LOUSER+%x", sh_type - SHT_LOUSER); |
252b5132 RH |
2027 | else |
2028 | sprintf (buff, _("<unknown>: %x"), sh_type); | |
103f02d3 | 2029 | |
252b5132 RH |
2030 | return buff; |
2031 | } | |
2032 | } | |
2033 | ||
2034 | struct option options [] = | |
2035 | { | |
2036 | {"all", no_argument, 0, 'a'}, | |
2037 | {"file-header", no_argument, 0, 'h'}, | |
2038 | {"program-headers", no_argument, 0, 'l'}, | |
2039 | {"headers", no_argument, 0, 'e'}, | |
a952a375 | 2040 | {"histogram", no_argument, 0, 'I'}, |
252b5132 RH |
2041 | {"segments", no_argument, 0, 'l'}, |
2042 | {"sections", no_argument, 0, 'S'}, | |
2043 | {"section-headers", no_argument, 0, 'S'}, | |
2044 | {"symbols", no_argument, 0, 's'}, | |
2045 | {"syms", no_argument, 0, 's'}, | |
2046 | {"relocs", no_argument, 0, 'r'}, | |
779fe533 | 2047 | {"notes", no_argument, 0, 'n'}, |
252b5132 | 2048 | {"dynamic", no_argument, 0, 'd'}, |
a952a375 | 2049 | {"arch-specific", no_argument, 0, 'A'}, |
252b5132 RH |
2050 | {"version-info", no_argument, 0, 'V'}, |
2051 | {"use-dynamic", no_argument, 0, 'D'}, | |
2052 | {"hex-dump", required_argument, 0, 'x'}, | |
2053 | {"debug-dump", optional_argument, 0, 'w'}, | |
4d6ed7c8 | 2054 | {"unwind", no_argument, 0, 'u'}, |
252b5132 RH |
2055 | #ifdef SUPPORT_DISASSEMBLY |
2056 | {"instruction-dump", required_argument, 0, 'i'}, | |
2057 | #endif | |
2058 | ||
2059 | {"version", no_argument, 0, 'v'}, | |
d974e256 | 2060 | {"wide", no_argument, 0, 'W'}, |
252b5132 RH |
2061 | {"help", no_argument, 0, 'H'}, |
2062 | {0, no_argument, 0, 0} | |
2063 | }; | |
2064 | ||
2065 | static void | |
2066 | usage () | |
2067 | { | |
2068 | fprintf (stdout, _("Usage: readelf {options} elf-file(s)\n")); | |
2069 | fprintf (stdout, _(" Options are:\n")); | |
a952a375 | 2070 | fprintf (stdout, _(" -a or --all Equivalent to: -h -l -S -s -r -d -V -A -I\n")); |
252b5132 RH |
2071 | fprintf (stdout, _(" -h or --file-header Display the ELF file header\n")); |
2072 | fprintf (stdout, _(" -l or --program-headers or --segments\n")); | |
2073 | fprintf (stdout, _(" Display the program headers\n")); | |
2074 | fprintf (stdout, _(" -S or --section-headers or --sections\n")); | |
2075 | fprintf (stdout, _(" Display the sections' header\n")); | |
2076 | fprintf (stdout, _(" -e or --headers Equivalent to: -h -l -S\n")); | |
2077 | fprintf (stdout, _(" -s or --syms or --symbols Display the symbol table\n")); | |
779fe533 | 2078 | fprintf (stdout, _(" -n or --notes Display the core notes (if present)\n")); |
252b5132 | 2079 | fprintf (stdout, _(" -r or --relocs Display the relocations (if present)\n")); |
4d6ed7c8 | 2080 | fprintf (stdout, _(" -u or --unwind Display the unwind info (if present)\n")); |
252b5132 RH |
2081 | fprintf (stdout, _(" -d or --dynamic Display the dynamic segment (if present)\n")); |
2082 | fprintf (stdout, _(" -V or --version-info Display the version sections (if present)\n")); | |
a952a375 | 2083 | fprintf (stdout, _(" -A or --arch-specific Display architecture specific information (if any).\n")); |
252b5132 RH |
2084 | fprintf (stdout, _(" -D or --use-dynamic Use the dynamic section info when displaying symbols\n")); |
2085 | fprintf (stdout, _(" -x <number> or --hex-dump=<number>\n")); | |
2086 | fprintf (stdout, _(" Dump the contents of section <number>\n")); | |
261a45ad | 2087 | fprintf (stdout, _(" -w[liaprmfs] or --debug-dump[=line,=info,=abbrev,=pubnames,=ranges,=macro,=frames,=str]\n")); |
252b5132 RH |
2088 | fprintf (stdout, _(" Display the contents of DWARF2 debug sections\n")); |
2089 | #ifdef SUPPORT_DISASSEMBLY | |
2090 | fprintf (stdout, _(" -i <number> or --instruction-dump=<number>\n")); | |
2091 | fprintf (stdout, _(" Disassemble the contents of section <number>\n")); | |
2092 | #endif | |
a952a375 | 2093 | fprintf (stdout, _(" -I or --histogram Display histogram of bucket list lengths\n")); |
252b5132 | 2094 | fprintf (stdout, _(" -v or --version Display the version number of readelf\n")); |
d974e256 | 2095 | fprintf (stdout, _(" -W or --wide Don't split lines to fit into 80 columns\n")); |
252b5132 | 2096 | fprintf (stdout, _(" -H or --help Display this information\n")); |
8ad3436c | 2097 | fprintf (stdout, _("Report bugs to %s\n"), REPORT_BUGS_TO); |
252b5132 RH |
2098 | |
2099 | exit (0); | |
2100 | } | |
2101 | ||
2102 | static void | |
2103 | request_dump (section, type) | |
2104 | unsigned int section; | |
91770270 | 2105 | int type; |
252b5132 RH |
2106 | { |
2107 | if (section >= num_dump_sects) | |
2108 | { | |
2109 | char * new_dump_sects; | |
2110 | ||
2111 | new_dump_sects = (char *) calloc (section + 1, 1); | |
2112 | ||
2113 | if (new_dump_sects == NULL) | |
2114 | error (_("Out of memory allocating dump request table.")); | |
2115 | else | |
2116 | { | |
2117 | /* Copy current flag settings. */ | |
2118 | memcpy (new_dump_sects, dump_sects, num_dump_sects); | |
2119 | ||
2120 | free (dump_sects); | |
2121 | ||
2122 | dump_sects = new_dump_sects; | |
2123 | num_dump_sects = section + 1; | |
2124 | } | |
2125 | } | |
2126 | ||
2127 | if (dump_sects) | |
2128 | dump_sects [section] |= type; | |
2129 | ||
2130 | return; | |
2131 | } | |
2132 | ||
2133 | static void | |
2134 | parse_args (argc, argv) | |
2135 | int argc; | |
2136 | char ** argv; | |
2137 | { | |
2138 | int c; | |
2139 | ||
2140 | if (argc < 2) | |
2141 | usage (); | |
2142 | ||
2143 | while ((c = getopt_long | |
d974e256 | 2144 | (argc, argv, "ersuahnldSDAIw::x:i:vVW", options, NULL)) != EOF) |
252b5132 RH |
2145 | { |
2146 | char * cp; | |
2147 | int section; | |
2148 | ||
2149 | switch (c) | |
2150 | { | |
2151 | case 0: | |
2152 | /* Long options. */ | |
2153 | break; | |
2154 | case 'H': | |
2155 | usage (); | |
2156 | break; | |
2157 | ||
2158 | case 'a': | |
2159 | do_syms ++; | |
2160 | do_reloc ++; | |
4d6ed7c8 | 2161 | do_unwind ++; |
252b5132 RH |
2162 | do_dynamic ++; |
2163 | do_header ++; | |
2164 | do_sections ++; | |
2165 | do_segments ++; | |
2166 | do_version ++; | |
2167 | do_histogram ++; | |
a952a375 | 2168 | do_arch ++; |
779fe533 | 2169 | do_notes ++; |
252b5132 RH |
2170 | break; |
2171 | case 'e': | |
2172 | do_header ++; | |
2173 | do_sections ++; | |
2174 | do_segments ++; | |
2175 | break; | |
a952a375 NC |
2176 | case 'A': |
2177 | do_arch ++; | |
2178 | break; | |
252b5132 RH |
2179 | case 'D': |
2180 | do_using_dynamic ++; | |
2181 | break; | |
2182 | case 'r': | |
2183 | do_reloc ++; | |
2184 | break; | |
4d6ed7c8 NC |
2185 | case 'u': |
2186 | do_unwind ++; | |
2187 | break; | |
252b5132 RH |
2188 | case 'h': |
2189 | do_header ++; | |
2190 | break; | |
2191 | case 'l': | |
2192 | do_segments ++; | |
2193 | break; | |
2194 | case 's': | |
2195 | do_syms ++; | |
2196 | break; | |
2197 | case 'S': | |
2198 | do_sections ++; | |
2199 | break; | |
2200 | case 'd': | |
2201 | do_dynamic ++; | |
2202 | break; | |
a952a375 NC |
2203 | case 'I': |
2204 | do_histogram ++; | |
2205 | break; | |
779fe533 NC |
2206 | case 'n': |
2207 | do_notes ++; | |
2208 | break; | |
252b5132 RH |
2209 | case 'x': |
2210 | do_dump ++; | |
2211 | section = strtoul (optarg, & cp, 0); | |
2212 | if (! * cp && section >= 0) | |
2213 | { | |
2214 | request_dump (section, HEX_DUMP); | |
2215 | break; | |
2216 | } | |
2217 | goto oops; | |
2218 | case 'w': | |
2219 | do_dump ++; | |
2220 | if (optarg == 0) | |
2221 | do_debugging = 1; | |
2222 | else | |
2223 | { | |
f662939a NC |
2224 | unsigned int index = 0; |
2225 | ||
252b5132 | 2226 | do_debugging = 0; |
252b5132 | 2227 | |
f662939a NC |
2228 | while (optarg[index]) |
2229 | switch (optarg[index++]) | |
2230 | { | |
2231 | case 'i': | |
2232 | case 'I': | |
2233 | do_debug_info = 1; | |
2234 | break; | |
2235 | ||
2236 | case 'a': | |
2237 | case 'A': | |
2238 | do_debug_abbrevs = 1; | |
2239 | break; | |
2240 | ||
2241 | case 'l': | |
2242 | case 'L': | |
2243 | do_debug_lines = 1; | |
2244 | break; | |
2245 | ||
2246 | case 'p': | |
2247 | case 'P': | |
2248 | do_debug_pubnames = 1; | |
2249 | break; | |
2250 | ||
2251 | case 'r': | |
2252 | case 'R': | |
2253 | do_debug_aranges = 1; | |
2254 | break; | |
2255 | ||
2256 | case 'F': | |
2257 | do_debug_frames_interp = 1; | |
2258 | case 'f': | |
2259 | do_debug_frames = 1; | |
2260 | break; | |
2261 | ||
2262 | case 'm': | |
2263 | case 'M': | |
2264 | do_debug_macinfo = 1; | |
2265 | break; | |
2266 | ||
261a45ad NC |
2267 | case 's': |
2268 | case 'S': | |
2269 | do_debug_str = 1; | |
2270 | break; | |
2271 | ||
f662939a NC |
2272 | default: |
2273 | warn (_("Unrecognised debug option '%s'\n"), optarg); | |
2274 | break; | |
2275 | } | |
252b5132 RH |
2276 | } |
2277 | break; | |
2278 | #ifdef SUPPORT_DISASSEMBLY | |
2279 | case 'i': | |
2280 | do_dump ++; | |
2281 | section = strtoul (optarg, & cp, 0); | |
2282 | if (! * cp && section >= 0) | |
2283 | { | |
2284 | request_dump (section, DISASS_DUMP); | |
2285 | break; | |
2286 | } | |
2287 | goto oops; | |
2288 | #endif | |
2289 | case 'v': | |
2290 | print_version (program_name); | |
2291 | break; | |
2292 | case 'V': | |
2293 | do_version ++; | |
2294 | break; | |
d974e256 JJ |
2295 | case 'W': |
2296 | do_wide ++; | |
2297 | break; | |
252b5132 RH |
2298 | default: |
2299 | oops: | |
2300 | /* xgettext:c-format */ | |
2301 | error (_("Invalid option '-%c'\n"), c); | |
2302 | /* Drop through. */ | |
2303 | case '?': | |
2304 | usage (); | |
2305 | } | |
2306 | } | |
2307 | ||
4d6ed7c8 | 2308 | if (!do_dynamic && !do_syms && !do_reloc && !do_unwind && !do_sections |
252b5132 | 2309 | && !do_segments && !do_header && !do_dump && !do_version |
779fe533 | 2310 | && !do_histogram && !do_debugging && !do_arch && !do_notes) |
252b5132 RH |
2311 | usage (); |
2312 | else if (argc < 3) | |
2313 | { | |
2314 | warn (_("Nothing to do.\n")); | |
2315 | usage(); | |
2316 | } | |
2317 | } | |
2318 | ||
2319 | static const char * | |
2320 | get_elf_class (elf_class) | |
91770270 | 2321 | unsigned int elf_class; |
252b5132 | 2322 | { |
ab5e7794 | 2323 | static char buff [32]; |
103f02d3 | 2324 | |
252b5132 RH |
2325 | switch (elf_class) |
2326 | { | |
2327 | case ELFCLASSNONE: return _("none"); | |
e3c8793a NC |
2328 | case ELFCLASS32: return "ELF32"; |
2329 | case ELFCLASS64: return "ELF64"; | |
ab5e7794 | 2330 | default: |
789be9f7 | 2331 | sprintf (buff, _("<unknown: %x>"), elf_class); |
ab5e7794 | 2332 | return buff; |
252b5132 RH |
2333 | } |
2334 | } | |
2335 | ||
2336 | static const char * | |
2337 | get_data_encoding (encoding) | |
91770270 | 2338 | unsigned int encoding; |
252b5132 | 2339 | { |
ab5e7794 | 2340 | static char buff [32]; |
103f02d3 | 2341 | |
252b5132 RH |
2342 | switch (encoding) |
2343 | { | |
2344 | case ELFDATANONE: return _("none"); | |
33c63f9d CM |
2345 | case ELFDATA2LSB: return _("2's complement, little endian"); |
2346 | case ELFDATA2MSB: return _("2's complement, big endian"); | |
103f02d3 | 2347 | default: |
789be9f7 | 2348 | sprintf (buff, _("<unknown: %x>"), encoding); |
ab5e7794 | 2349 | return buff; |
252b5132 RH |
2350 | } |
2351 | } | |
2352 | ||
2353 | static const char * | |
2354 | get_osabi_name (osabi) | |
91770270 | 2355 | unsigned int osabi; |
252b5132 | 2356 | { |
ab5e7794 | 2357 | static char buff [32]; |
103f02d3 | 2358 | |
252b5132 RH |
2359 | switch (osabi) |
2360 | { | |
e3c8793a NC |
2361 | case ELFOSABI_NONE: return "UNIX - System V"; |
2362 | case ELFOSABI_HPUX: return "UNIX - HP-UX"; | |
2363 | case ELFOSABI_NETBSD: return "UNIX - NetBSD"; | |
2364 | case ELFOSABI_LINUX: return "UNIX - Linux"; | |
2365 | case ELFOSABI_HURD: return "GNU/Hurd"; | |
2366 | case ELFOSABI_SOLARIS: return "UNIX - Solaris"; | |
2367 | case ELFOSABI_AIX: return "UNIX - AIX"; | |
2368 | case ELFOSABI_IRIX: return "UNIX - IRIX"; | |
2369 | case ELFOSABI_FREEBSD: return "UNIX - FreeBSD"; | |
2370 | case ELFOSABI_TRU64: return "UNIX - TRU64"; | |
2371 | case ELFOSABI_MODESTO: return "Novell - Modesto"; | |
2372 | case ELFOSABI_OPENBSD: return "UNIX - OpenBSD"; | |
252b5132 | 2373 | case ELFOSABI_STANDALONE: return _("Standalone App"); |
e3c8793a | 2374 | case ELFOSABI_ARM: return "ARM"; |
ab5e7794 | 2375 | default: |
789be9f7 | 2376 | sprintf (buff, _("<unknown: %x>"), osabi); |
ab5e7794 | 2377 | return buff; |
252b5132 RH |
2378 | } |
2379 | } | |
2380 | ||
2381 | /* Decode the data held in 'elf_header'. */ | |
2382 | static int | |
2383 | process_file_header () | |
2384 | { | |
2385 | if ( elf_header.e_ident [EI_MAG0] != ELFMAG0 | |
2386 | || elf_header.e_ident [EI_MAG1] != ELFMAG1 | |
2387 | || elf_header.e_ident [EI_MAG2] != ELFMAG2 | |
2388 | || elf_header.e_ident [EI_MAG3] != ELFMAG3) | |
2389 | { | |
2390 | error | |
2391 | (_("Not an ELF file - it has the wrong magic bytes at the start\n")); | |
2392 | return 0; | |
2393 | } | |
2394 | ||
2395 | if (do_header) | |
2396 | { | |
2397 | int i; | |
2398 | ||
2399 | printf (_("ELF Header:\n")); | |
2400 | printf (_(" Magic: ")); | |
2401 | for (i = 0; i < EI_NIDENT; i ++) | |
2402 | printf ("%2.2x ", elf_header.e_ident [i]); | |
2403 | printf ("\n"); | |
2404 | printf (_(" Class: %s\n"), | |
2405 | get_elf_class (elf_header.e_ident [EI_CLASS])); | |
2406 | printf (_(" Data: %s\n"), | |
2407 | get_data_encoding (elf_header.e_ident [EI_DATA])); | |
2408 | printf (_(" Version: %d %s\n"), | |
2409 | elf_header.e_ident [EI_VERSION], | |
789be9f7 ILT |
2410 | (elf_header.e_ident [EI_VERSION] == EV_CURRENT |
2411 | ? "(current)" | |
2412 | : (elf_header.e_ident [EI_VERSION] != EV_NONE | |
2413 | ? "<unknown: %lx>" | |
2414 | : ""))); | |
252b5132 RH |
2415 | printf (_(" OS/ABI: %s\n"), |
2416 | get_osabi_name (elf_header.e_ident [EI_OSABI])); | |
2417 | printf (_(" ABI Version: %d\n"), | |
2418 | elf_header.e_ident [EI_ABIVERSION]); | |
2419 | printf (_(" Type: %s\n"), | |
2420 | get_file_type (elf_header.e_type)); | |
2421 | printf (_(" Machine: %s\n"), | |
2422 | get_machine_name (elf_header.e_machine)); | |
2423 | printf (_(" Version: 0x%lx\n"), | |
2424 | (unsigned long) elf_header.e_version); | |
76da6bbe | 2425 | |
f7a99963 NC |
2426 | printf (_(" Entry point address: ")); |
2427 | print_vma ((bfd_vma) elf_header.e_entry, PREFIX_HEX); | |
2428 | printf (_("\n Start of program headers: ")); | |
2429 | print_vma ((bfd_vma) elf_header.e_phoff, DEC); | |
2430 | printf (_(" (bytes into file)\n Start of section headers: ")); | |
2431 | print_vma ((bfd_vma) elf_header.e_shoff, DEC); | |
2432 | printf (_(" (bytes into file)\n")); | |
76da6bbe | 2433 | |
252b5132 RH |
2434 | printf (_(" Flags: 0x%lx%s\n"), |
2435 | (unsigned long) elf_header.e_flags, | |
2436 | get_machine_flags (elf_header.e_flags, elf_header.e_machine)); | |
2437 | printf (_(" Size of this header: %ld (bytes)\n"), | |
2438 | (long) elf_header.e_ehsize); | |
2439 | printf (_(" Size of program headers: %ld (bytes)\n"), | |
2440 | (long) elf_header.e_phentsize); | |
2441 | printf (_(" Number of program headers: %ld\n"), | |
2442 | (long) elf_header.e_phnum); | |
2443 | printf (_(" Size of section headers: %ld (bytes)\n"), | |
2444 | (long) elf_header.e_shentsize); | |
2445 | printf (_(" Number of section headers: %ld\n"), | |
2446 | (long) elf_header.e_shnum); | |
2447 | printf (_(" Section header string table index: %ld\n"), | |
2448 | (long) elf_header.e_shstrndx); | |
2449 | } | |
103f02d3 | 2450 | |
9ea033b2 NC |
2451 | return 1; |
2452 | } | |
2453 | ||
252b5132 | 2454 | |
9ea033b2 NC |
2455 | static int |
2456 | get_32bit_program_headers (file, program_headers) | |
2457 | FILE * file; | |
2458 | Elf_Internal_Phdr * program_headers; | |
2459 | { | |
2460 | Elf32_External_Phdr * phdrs; | |
2461 | Elf32_External_Phdr * external; | |
2462 | Elf32_Internal_Phdr * internal; | |
2463 | unsigned int i; | |
103f02d3 | 2464 | |
a6e9f9df AM |
2465 | phdrs = ((Elf32_External_Phdr *) |
2466 | get_data (NULL, file, elf_header.e_phoff, | |
2467 | elf_header.e_phentsize * elf_header.e_phnum, | |
2468 | _("program headers"))); | |
2469 | if (!phdrs) | |
2470 | return 0; | |
9ea033b2 NC |
2471 | |
2472 | for (i = 0, internal = program_headers, external = phdrs; | |
2473 | i < elf_header.e_phnum; | |
2474 | i ++, internal ++, external ++) | |
252b5132 | 2475 | { |
9ea033b2 NC |
2476 | internal->p_type = BYTE_GET (external->p_type); |
2477 | internal->p_offset = BYTE_GET (external->p_offset); | |
2478 | internal->p_vaddr = BYTE_GET (external->p_vaddr); | |
2479 | internal->p_paddr = BYTE_GET (external->p_paddr); | |
2480 | internal->p_filesz = BYTE_GET (external->p_filesz); | |
2481 | internal->p_memsz = BYTE_GET (external->p_memsz); | |
2482 | internal->p_flags = BYTE_GET (external->p_flags); | |
2483 | internal->p_align = BYTE_GET (external->p_align); | |
252b5132 RH |
2484 | } |
2485 | ||
9ea033b2 NC |
2486 | free (phdrs); |
2487 | ||
252b5132 RH |
2488 | return 1; |
2489 | } | |
2490 | ||
9ea033b2 NC |
2491 | static int |
2492 | get_64bit_program_headers (file, program_headers) | |
2493 | FILE * file; | |
2494 | Elf_Internal_Phdr * program_headers; | |
2495 | { | |
2496 | Elf64_External_Phdr * phdrs; | |
2497 | Elf64_External_Phdr * external; | |
2498 | Elf64_Internal_Phdr * internal; | |
2499 | unsigned int i; | |
103f02d3 | 2500 | |
a6e9f9df AM |
2501 | phdrs = ((Elf64_External_Phdr *) |
2502 | get_data (NULL, file, elf_header.e_phoff, | |
2503 | elf_header.e_phentsize * elf_header.e_phnum, | |
2504 | _("program headers"))); | |
2505 | if (!phdrs) | |
2506 | return 0; | |
9ea033b2 NC |
2507 | |
2508 | for (i = 0, internal = program_headers, external = phdrs; | |
2509 | i < elf_header.e_phnum; | |
2510 | i ++, internal ++, external ++) | |
2511 | { | |
2512 | internal->p_type = BYTE_GET (external->p_type); | |
2513 | internal->p_flags = BYTE_GET (external->p_flags); | |
2514 | internal->p_offset = BYTE_GET8 (external->p_offset); | |
2515 | internal->p_vaddr = BYTE_GET8 (external->p_vaddr); | |
2516 | internal->p_paddr = BYTE_GET8 (external->p_paddr); | |
2517 | internal->p_filesz = BYTE_GET8 (external->p_filesz); | |
2518 | internal->p_memsz = BYTE_GET8 (external->p_memsz); | |
2519 | internal->p_align = BYTE_GET8 (external->p_align); | |
2520 | } | |
2521 | ||
2522 | free (phdrs); | |
2523 | ||
2524 | return 1; | |
2525 | } | |
252b5132 RH |
2526 | |
2527 | static int | |
2528 | process_program_headers (file) | |
2529 | FILE * file; | |
2530 | { | |
9ea033b2 NC |
2531 | Elf_Internal_Phdr * program_headers; |
2532 | Elf_Internal_Phdr * segment; | |
2533 | unsigned int i; | |
252b5132 RH |
2534 | |
2535 | if (elf_header.e_phnum == 0) | |
2536 | { | |
2537 | if (do_segments) | |
2538 | printf (_("\nThere are no program headers in this file.\n")); | |
2539 | return 1; | |
2540 | } | |
2541 | ||
2542 | if (do_segments && !do_header) | |
2543 | { | |
f7a99963 NC |
2544 | printf (_("\nElf file type is %s\n"), get_file_type (elf_header.e_type)); |
2545 | printf (_("Entry point ")); | |
2546 | print_vma ((bfd_vma) elf_header.e_entry, PREFIX_HEX); | |
2547 | printf (_("\nThere are %d program headers, starting at offset "), | |
2548 | elf_header.e_phnum); | |
2549 | print_vma ((bfd_vma) elf_header.e_phoff, DEC); | |
2550 | printf ("\n"); | |
252b5132 RH |
2551 | } |
2552 | ||
9ea033b2 NC |
2553 | program_headers = (Elf_Internal_Phdr *) malloc |
2554 | (elf_header.e_phnum * sizeof (Elf_Internal_Phdr)); | |
252b5132 RH |
2555 | |
2556 | if (program_headers == NULL) | |
2557 | { | |
2558 | error (_("Out of memory\n")); | |
2559 | return 0; | |
2560 | } | |
2561 | ||
9ea033b2 NC |
2562 | if (is_32bit_elf) |
2563 | i = get_32bit_program_headers (file, program_headers); | |
2564 | else | |
2565 | i = get_64bit_program_headers (file, program_headers); | |
2566 | ||
2567 | if (i == 0) | |
252b5132 | 2568 | { |
9ea033b2 NC |
2569 | free (program_headers); |
2570 | return 0; | |
252b5132 | 2571 | } |
103f02d3 | 2572 | |
252b5132 RH |
2573 | if (do_segments) |
2574 | { | |
2575 | printf | |
2576 | (_("\nProgram Header%s:\n"), elf_header.e_phnum > 1 ? "s" : ""); | |
76da6bbe | 2577 | |
f7a99963 NC |
2578 | if (is_32bit_elf) |
2579 | printf | |
2580 | (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n")); | |
d974e256 JJ |
2581 | else if (do_wide) |
2582 | printf | |
2583 | (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n")); | |
f7a99963 NC |
2584 | else |
2585 | { | |
2586 | printf | |
2587 | (_(" Type Offset VirtAddr PhysAddr\n")); | |
2588 | printf | |
2589 | (_(" FileSiz MemSiz Flags Align\n")); | |
2590 | } | |
252b5132 RH |
2591 | } |
2592 | ||
2593 | loadaddr = -1; | |
2594 | dynamic_addr = 0; | |
1b228002 | 2595 | dynamic_size = 0; |
252b5132 RH |
2596 | |
2597 | for (i = 0, segment = program_headers; | |
2598 | i < elf_header.e_phnum; | |
2599 | i ++, segment ++) | |
2600 | { | |
2601 | if (do_segments) | |
2602 | { | |
103f02d3 | 2603 | printf (" %-14.14s ", get_segment_type (segment->p_type)); |
f7a99963 NC |
2604 | |
2605 | if (is_32bit_elf) | |
2606 | { | |
2607 | printf ("0x%6.6lx ", (unsigned long) segment->p_offset); | |
2608 | printf ("0x%8.8lx ", (unsigned long) segment->p_vaddr); | |
2609 | printf ("0x%8.8lx ", (unsigned long) segment->p_paddr); | |
2610 | printf ("0x%5.5lx ", (unsigned long) segment->p_filesz); | |
2611 | printf ("0x%5.5lx ", (unsigned long) segment->p_memsz); | |
2612 | printf ("%c%c%c ", | |
2613 | (segment->p_flags & PF_R ? 'R' : ' '), | |
2614 | (segment->p_flags & PF_W ? 'W' : ' '), | |
2615 | (segment->p_flags & PF_X ? 'E' : ' ')); | |
2616 | printf ("%#lx", (unsigned long) segment->p_align); | |
2617 | } | |
d974e256 JJ |
2618 | else if (do_wide) |
2619 | { | |
2620 | if ((unsigned long) segment->p_offset == segment->p_offset) | |
2621 | printf ("0x%6.6lx ", (unsigned long) segment->p_offset); | |
2622 | else | |
2623 | { | |
2624 | print_vma (segment->p_offset, FULL_HEX); | |
2625 | putchar (' '); | |
2626 | } | |
2627 | ||
2628 | print_vma (segment->p_vaddr, FULL_HEX); | |
2629 | putchar (' '); | |
2630 | print_vma (segment->p_paddr, FULL_HEX); | |
2631 | putchar (' '); | |
2632 | ||
2633 | if ((unsigned long) segment->p_filesz == segment->p_filesz) | |
2634 | printf ("0x%6.6lx ", (unsigned long) segment->p_filesz); | |
2635 | else | |
2636 | { | |
2637 | print_vma (segment->p_filesz, FULL_HEX); | |
2638 | putchar (' '); | |
2639 | } | |
2640 | ||
2641 | if ((unsigned long) segment->p_memsz == segment->p_memsz) | |
2642 | printf ("0x%6.6lx", (unsigned long) segment->p_memsz); | |
2643 | else | |
2644 | { | |
2645 | print_vma (segment->p_offset, FULL_HEX); | |
2646 | } | |
2647 | ||
2648 | printf (" %c%c%c ", | |
2649 | (segment->p_flags & PF_R ? 'R' : ' '), | |
2650 | (segment->p_flags & PF_W ? 'W' : ' '), | |
2651 | (segment->p_flags & PF_X ? 'E' : ' ')); | |
2652 | ||
2653 | if ((unsigned long) segment->p_align == segment->p_align) | |
2654 | printf ("%#lx", (unsigned long) segment->p_align); | |
2655 | else | |
2656 | { | |
2657 | print_vma (segment->p_align, PREFIX_HEX); | |
2658 | } | |
2659 | } | |
f7a99963 NC |
2660 | else |
2661 | { | |
2662 | print_vma (segment->p_offset, FULL_HEX); | |
2663 | putchar (' '); | |
2664 | print_vma (segment->p_vaddr, FULL_HEX); | |
2665 | putchar (' '); | |
2666 | print_vma (segment->p_paddr, FULL_HEX); | |
2667 | printf ("\n "); | |
2668 | print_vma (segment->p_filesz, FULL_HEX); | |
2669 | putchar (' '); | |
2670 | print_vma (segment->p_memsz, FULL_HEX); | |
2671 | printf (" %c%c%c ", | |
2672 | (segment->p_flags & PF_R ? 'R' : ' '), | |
2673 | (segment->p_flags & PF_W ? 'W' : ' '), | |
2674 | (segment->p_flags & PF_X ? 'E' : ' ')); | |
2675 | print_vma (segment->p_align, HEX); | |
2676 | } | |
252b5132 RH |
2677 | } |
2678 | ||
2679 | switch (segment->p_type) | |
2680 | { | |
2681 | case PT_LOAD: | |
2682 | if (loadaddr == -1) | |
2683 | loadaddr = (segment->p_vaddr & 0xfffff000) | |
2684 | - (segment->p_offset & 0xfffff000); | |
2685 | break; | |
2686 | ||
2687 | case PT_DYNAMIC: | |
2688 | if (dynamic_addr) | |
2689 | error (_("more than one dynamic segment\n")); | |
2690 | ||
2691 | dynamic_addr = segment->p_offset; | |
2692 | dynamic_size = segment->p_filesz; | |
2693 | break; | |
2694 | ||
2695 | case PT_INTERP: | |
f7a99963 | 2696 | if (fseek (file, (long) segment->p_offset, SEEK_SET)) |
252b5132 RH |
2697 | error (_("Unable to find program interpreter name\n")); |
2698 | else | |
2699 | { | |
2700 | program_interpreter[0] = 0; | |
2701 | fscanf (file, "%63s", program_interpreter); | |
2702 | ||
2703 | if (do_segments) | |
2704 | printf (_("\n [Requesting program interpreter: %s]"), | |
2705 | program_interpreter); | |
2706 | } | |
2707 | break; | |
2708 | } | |
2709 | ||
2710 | if (do_segments) | |
2711 | putc ('\n', stdout); | |
2712 | } | |
2713 | ||
2714 | if (loadaddr == -1) | |
2715 | { | |
e3c8793a | 2716 | /* Very strange. */ |
252b5132 RH |
2717 | loadaddr = 0; |
2718 | } | |
2719 | ||
2720 | if (do_segments && section_headers != NULL) | |
2721 | { | |
2722 | printf (_("\n Section to Segment mapping:\n")); | |
2723 | printf (_(" Segment Sections...\n")); | |
2724 | ||
2725 | assert (string_table != NULL); | |
2726 | ||
2727 | for (i = 0; i < elf_header.e_phnum; i++) | |
2728 | { | |
9ea033b2 NC |
2729 | int j; |
2730 | Elf_Internal_Shdr * section; | |
252b5132 RH |
2731 | |
2732 | segment = program_headers + i; | |
2733 | section = section_headers; | |
2734 | ||
2735 | printf (" %2.2d ", i); | |
2736 | ||
2737 | for (j = 0; j < elf_header.e_shnum; j++, section ++) | |
2738 | { | |
2739 | if (section->sh_size > 0 | |
2740 | /* Compare allocated sections by VMA, unallocated | |
2741 | sections by file offset. */ | |
2742 | && (section->sh_flags & SHF_ALLOC | |
2743 | ? (section->sh_addr >= segment->p_vaddr | |
2744 | && section->sh_addr + section->sh_size | |
2745 | <= segment->p_vaddr + segment->p_memsz) | |
b4c96d0d | 2746 | : ((bfd_vma) section->sh_offset >= segment->p_offset |
252b5132 RH |
2747 | && (section->sh_offset + section->sh_size |
2748 | <= segment->p_offset + segment->p_filesz)))) | |
2749 | printf ("%s ", SECTION_NAME (section)); | |
2750 | } | |
2751 | ||
2752 | putc ('\n',stdout); | |
2753 | } | |
2754 | } | |
2755 | ||
2756 | free (program_headers); | |
2757 | ||
2758 | return 1; | |
2759 | } | |
2760 | ||
2761 | ||
2762 | static int | |
9ea033b2 | 2763 | get_32bit_section_headers (file) |
252b5132 RH |
2764 | FILE * file; |
2765 | { | |
2766 | Elf32_External_Shdr * shdrs; | |
2767 | Elf32_Internal_Shdr * internal; | |
2768 | unsigned int i; | |
2769 | ||
a6e9f9df AM |
2770 | shdrs = ((Elf32_External_Shdr *) |
2771 | get_data (NULL, file, elf_header.e_shoff, | |
2772 | elf_header.e_shentsize * elf_header.e_shnum, | |
2773 | _("section headers"))); | |
2774 | if (!shdrs) | |
2775 | return 0; | |
252b5132 | 2776 | |
9ea033b2 NC |
2777 | section_headers = (Elf_Internal_Shdr *) malloc |
2778 | (elf_header.e_shnum * sizeof (Elf_Internal_Shdr)); | |
252b5132 RH |
2779 | |
2780 | if (section_headers == NULL) | |
2781 | { | |
2782 | error (_("Out of memory\n")); | |
2783 | return 0; | |
2784 | } | |
2785 | ||
2786 | for (i = 0, internal = section_headers; | |
2787 | i < elf_header.e_shnum; | |
2788 | i ++, internal ++) | |
2789 | { | |
2790 | internal->sh_name = BYTE_GET (shdrs[i].sh_name); | |
2791 | internal->sh_type = BYTE_GET (shdrs[i].sh_type); | |
2792 | internal->sh_flags = BYTE_GET (shdrs[i].sh_flags); | |
2793 | internal->sh_addr = BYTE_GET (shdrs[i].sh_addr); | |
2794 | internal->sh_offset = BYTE_GET (shdrs[i].sh_offset); | |
2795 | internal->sh_size = BYTE_GET (shdrs[i].sh_size); | |
2796 | internal->sh_link = BYTE_GET (shdrs[i].sh_link); | |
2797 | internal->sh_info = BYTE_GET (shdrs[i].sh_info); | |
2798 | internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign); | |
2799 | internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize); | |
2800 | } | |
2801 | ||
2802 | free (shdrs); | |
2803 | ||
2804 | return 1; | |
2805 | } | |
2806 | ||
9ea033b2 NC |
2807 | static int |
2808 | get_64bit_section_headers (file) | |
2809 | FILE * file; | |
2810 | { | |
2811 | Elf64_External_Shdr * shdrs; | |
2812 | Elf64_Internal_Shdr * internal; | |
2813 | unsigned int i; | |
2814 | ||
a6e9f9df AM |
2815 | shdrs = ((Elf64_External_Shdr *) |
2816 | get_data (NULL, file, elf_header.e_shoff, | |
2817 | elf_header.e_shentsize * elf_header.e_shnum, | |
2818 | _("section headers"))); | |
2819 | if (!shdrs) | |
2820 | return 0; | |
9ea033b2 NC |
2821 | |
2822 | section_headers = (Elf_Internal_Shdr *) malloc | |
2823 | (elf_header.e_shnum * sizeof (Elf_Internal_Shdr)); | |
2824 | ||
2825 | if (section_headers == NULL) | |
2826 | { | |
2827 | error (_("Out of memory\n")); | |
2828 | return 0; | |
2829 | } | |
2830 | ||
2831 | for (i = 0, internal = section_headers; | |
2832 | i < elf_header.e_shnum; | |
2833 | i ++, internal ++) | |
2834 | { | |
2835 | internal->sh_name = BYTE_GET (shdrs[i].sh_name); | |
2836 | internal->sh_type = BYTE_GET (shdrs[i].sh_type); | |
2837 | internal->sh_flags = BYTE_GET8 (shdrs[i].sh_flags); | |
2838 | internal->sh_addr = BYTE_GET8 (shdrs[i].sh_addr); | |
2839 | internal->sh_size = BYTE_GET8 (shdrs[i].sh_size); | |
2840 | internal->sh_entsize = BYTE_GET8 (shdrs[i].sh_entsize); | |
2841 | internal->sh_link = BYTE_GET (shdrs[i].sh_link); | |
2842 | internal->sh_info = BYTE_GET (shdrs[i].sh_info); | |
2843 | internal->sh_offset = BYTE_GET (shdrs[i].sh_offset); | |
2844 | internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign); | |
2845 | } | |
2846 | ||
2847 | free (shdrs); | |
2848 | ||
2849 | return 1; | |
2850 | } | |
2851 | ||
252b5132 | 2852 | static Elf_Internal_Sym * |
9ea033b2 | 2853 | get_32bit_elf_symbols (file, offset, number) |
252b5132 RH |
2854 | FILE * file; |
2855 | unsigned long offset; | |
2856 | unsigned long number; | |
2857 | { | |
2858 | Elf32_External_Sym * esyms; | |
2859 | Elf_Internal_Sym * isyms; | |
2860 | Elf_Internal_Sym * psym; | |
2861 | unsigned int j; | |
2862 | ||
a6e9f9df AM |
2863 | esyms = ((Elf32_External_Sym *) |
2864 | get_data (NULL, file, offset, | |
2865 | number * sizeof (Elf32_External_Sym), _("symbols"))); | |
2866 | if (!esyms) | |
2867 | return NULL; | |
252b5132 RH |
2868 | |
2869 | isyms = (Elf_Internal_Sym *) malloc (number * sizeof (Elf_Internal_Sym)); | |
2870 | ||
2871 | if (isyms == NULL) | |
2872 | { | |
2873 | error (_("Out of memory\n")); | |
2874 | free (esyms); | |
2875 | ||
2876 | return NULL; | |
2877 | } | |
2878 | ||
2879 | for (j = 0, psym = isyms; | |
2880 | j < number; | |
2881 | j ++, psym ++) | |
2882 | { | |
2883 | psym->st_name = BYTE_GET (esyms[j].st_name); | |
2884 | psym->st_value = BYTE_GET (esyms[j].st_value); | |
2885 | psym->st_size = BYTE_GET (esyms[j].st_size); | |
2886 | psym->st_shndx = BYTE_GET (esyms[j].st_shndx); | |
2887 | psym->st_info = BYTE_GET (esyms[j].st_info); | |
2888 | psym->st_other = BYTE_GET (esyms[j].st_other); | |
2889 | } | |
2890 | ||
2891 | free (esyms); | |
2892 | ||
2893 | return isyms; | |
2894 | } | |
2895 | ||
9ea033b2 NC |
2896 | static Elf_Internal_Sym * |
2897 | get_64bit_elf_symbols (file, offset, number) | |
2898 | FILE * file; | |
2899 | unsigned long offset; | |
2900 | unsigned long number; | |
2901 | { | |
2902 | Elf64_External_Sym * esyms; | |
2903 | Elf_Internal_Sym * isyms; | |
2904 | Elf_Internal_Sym * psym; | |
2905 | unsigned int j; | |
2906 | ||
a6e9f9df AM |
2907 | esyms = ((Elf64_External_Sym *) |
2908 | get_data (NULL, file, offset, | |
2909 | number * sizeof (Elf64_External_Sym), _("symbols"))); | |
2910 | if (!esyms) | |
2911 | return NULL; | |
9ea033b2 NC |
2912 | |
2913 | isyms = (Elf_Internal_Sym *) malloc (number * sizeof (Elf_Internal_Sym)); | |
2914 | ||
2915 | if (isyms == NULL) | |
2916 | { | |
2917 | error (_("Out of memory\n")); | |
2918 | free (esyms); | |
2919 | ||
2920 | return NULL; | |
2921 | } | |
2922 | ||
2923 | for (j = 0, psym = isyms; | |
2924 | j < number; | |
2925 | j ++, psym ++) | |
2926 | { | |
2927 | psym->st_name = BYTE_GET (esyms[j].st_name); | |
2928 | psym->st_info = BYTE_GET (esyms[j].st_info); | |
2929 | psym->st_other = BYTE_GET (esyms[j].st_other); | |
2930 | psym->st_shndx = BYTE_GET (esyms[j].st_shndx); | |
2931 | psym->st_value = BYTE_GET8 (esyms[j].st_value); | |
2932 | psym->st_size = BYTE_GET8 (esyms[j].st_size); | |
2933 | } | |
2934 | ||
2935 | free (esyms); | |
2936 | ||
2937 | return isyms; | |
2938 | } | |
2939 | ||
d1133906 NC |
2940 | static const char * |
2941 | get_elf_section_flags (sh_flags) | |
2942 | bfd_vma sh_flags; | |
2943 | { | |
2944 | static char buff [32]; | |
2945 | ||
2946 | * buff = 0; | |
76da6bbe | 2947 | |
d1133906 NC |
2948 | while (sh_flags) |
2949 | { | |
2950 | bfd_vma flag; | |
2951 | ||
2952 | flag = sh_flags & - sh_flags; | |
2953 | sh_flags &= ~ flag; | |
76da6bbe | 2954 | |
d1133906 NC |
2955 | switch (flag) |
2956 | { | |
2957 | case SHF_WRITE: strcat (buff, "W"); break; | |
2958 | case SHF_ALLOC: strcat (buff, "A"); break; | |
2959 | case SHF_EXECINSTR: strcat (buff, "X"); break; | |
2960 | case SHF_MERGE: strcat (buff, "M"); break; | |
2961 | case SHF_STRINGS: strcat (buff, "S"); break; | |
2962 | case SHF_INFO_LINK: strcat (buff, "I"); break; | |
2963 | case SHF_LINK_ORDER: strcat (buff, "L"); break; | |
2964 | case SHF_OS_NONCONFORMING: strcat (buff, "O"); break; | |
93ebe586 | 2965 | case SHF_GROUP: strcat (buff, "G"); break; |
76da6bbe | 2966 | |
d1133906 NC |
2967 | default: |
2968 | if (flag & SHF_MASKOS) | |
2969 | { | |
2970 | strcat (buff, "o"); | |
2971 | sh_flags &= ~ SHF_MASKOS; | |
2972 | } | |
2973 | else if (flag & SHF_MASKPROC) | |
2974 | { | |
2975 | strcat (buff, "p"); | |
2976 | sh_flags &= ~ SHF_MASKPROC; | |
2977 | } | |
2978 | else | |
2979 | strcat (buff, "x"); | |
2980 | break; | |
2981 | } | |
2982 | } | |
76da6bbe | 2983 | |
d1133906 NC |
2984 | return buff; |
2985 | } | |
2986 | ||
252b5132 RH |
2987 | static int |
2988 | process_section_headers (file) | |
2989 | FILE * file; | |
2990 | { | |
9ea033b2 NC |
2991 | Elf_Internal_Shdr * section; |
2992 | int i; | |
252b5132 RH |
2993 | |
2994 | section_headers = NULL; | |
2995 | ||
2996 | if (elf_header.e_shnum == 0) | |
2997 | { | |
2998 | if (do_sections) | |
2999 | printf (_("\nThere are no sections in this file.\n")); | |
3000 | ||
3001 | return 1; | |
3002 | } | |
3003 | ||
3004 | if (do_sections && !do_header) | |
9ea033b2 | 3005 | printf (_("There are %d section headers, starting at offset 0x%lx:\n"), |
252b5132 RH |
3006 | elf_header.e_shnum, (unsigned long) elf_header.e_shoff); |
3007 | ||
9ea033b2 NC |
3008 | if (is_32bit_elf) |
3009 | { | |
3010 | if (! get_32bit_section_headers (file)) | |
3011 | return 0; | |
3012 | } | |
3013 | else if (! get_64bit_section_headers (file)) | |
252b5132 RH |
3014 | return 0; |
3015 | ||
3016 | /* Read in the string table, so that we have names to display. */ | |
3017 | section = section_headers + elf_header.e_shstrndx; | |
3018 | ||
3019 | if (section->sh_size != 0) | |
3020 | { | |
a6e9f9df AM |
3021 | string_table = (char *) get_data (NULL, file, section->sh_offset, |
3022 | section->sh_size, _("string table")); | |
d40ac9bd NC |
3023 | |
3024 | string_table_length = section->sh_size; | |
252b5132 RH |
3025 | } |
3026 | ||
3027 | /* Scan the sections for the dynamic symbol table | |
e3c8793a | 3028 | and dynamic string table and debug sections. */ |
252b5132 RH |
3029 | dynamic_symbols = NULL; |
3030 | dynamic_strings = NULL; | |
3031 | dynamic_syminfo = NULL; | |
103f02d3 | 3032 | |
252b5132 RH |
3033 | for (i = 0, section = section_headers; |
3034 | i < elf_header.e_shnum; | |
3035 | i ++, section ++) | |
3036 | { | |
3037 | char * name = SECTION_NAME (section); | |
3038 | ||
3039 | if (section->sh_type == SHT_DYNSYM) | |
3040 | { | |
3041 | if (dynamic_symbols != NULL) | |
3042 | { | |
3043 | error (_("File contains multiple dynamic symbol tables\n")); | |
3044 | continue; | |
3045 | } | |
3046 | ||
19936277 | 3047 | num_dynamic_syms = section->sh_size / section->sh_entsize; |
9ea033b2 | 3048 | dynamic_symbols = |
19936277 | 3049 | GET_ELF_SYMBOLS (file, section->sh_offset, num_dynamic_syms); |
252b5132 RH |
3050 | } |
3051 | else if (section->sh_type == SHT_STRTAB | |
3052 | && strcmp (name, ".dynstr") == 0) | |
3053 | { | |
3054 | if (dynamic_strings != NULL) | |
3055 | { | |
3056 | error (_("File contains multiple dynamic string tables\n")); | |
3057 | continue; | |
3058 | } | |
3059 | ||
a6e9f9df AM |
3060 | dynamic_strings = (char *) get_data (NULL, file, section->sh_offset, |
3061 | section->sh_size, | |
3062 | _("dynamic strings")); | |
252b5132 RH |
3063 | } |
3064 | else if ((do_debugging || do_debug_info || do_debug_abbrevs | |
31b6fca6 | 3065 | || do_debug_lines || do_debug_pubnames || do_debug_aranges |
261a45ad | 3066 | || do_debug_frames || do_debug_macinfo || do_debug_str) |
252b5132 RH |
3067 | && strncmp (name, ".debug_", 7) == 0) |
3068 | { | |
3069 | name += 7; | |
3070 | ||
3071 | if (do_debugging | |
3072 | || (do_debug_info && (strcmp (name, "info") == 0)) | |
3073 | || (do_debug_abbrevs && (strcmp (name, "abbrev") == 0)) | |
3074 | || (do_debug_lines && (strcmp (name, "line") == 0)) | |
3075 | || (do_debug_pubnames && (strcmp (name, "pubnames") == 0)) | |
3076 | || (do_debug_aranges && (strcmp (name, "aranges") == 0)) | |
c47d488e | 3077 | || (do_debug_frames && (strcmp (name, "frame") == 0)) |
e0c60db2 | 3078 | || (do_debug_macinfo && (strcmp (name, "macinfo") == 0)) |
261a45ad | 3079 | || (do_debug_str && (strcmp (name, "str") == 0)) |
252b5132 RH |
3080 | ) |
3081 | request_dump (i, DEBUG_DUMP); | |
3082 | } | |
09fd7e38 JM |
3083 | /* linkonce section to be combined with .debug_info at link time. */ |
3084 | else if ((do_debugging || do_debug_info) | |
3085 | && strncmp (name, ".gnu.linkonce.wi.", 17) == 0) | |
3086 | request_dump (i, DEBUG_DUMP); | |
c47d488e DD |
3087 | else if (do_debug_frames && strcmp (name, ".eh_frame") == 0) |
3088 | request_dump (i, DEBUG_DUMP); | |
252b5132 RH |
3089 | } |
3090 | ||
3091 | if (! do_sections) | |
3092 | return 1; | |
3093 | ||
3094 | printf (_("\nSection Header%s:\n"), elf_header.e_shnum > 1 ? "s" : ""); | |
76da6bbe | 3095 | |
f7a99963 NC |
3096 | if (is_32bit_elf) |
3097 | printf | |
3098 | (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n")); | |
d974e256 JJ |
3099 | else if (do_wide) |
3100 | printf | |
3101 | (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n")); | |
f7a99963 NC |
3102 | else |
3103 | { | |
3104 | printf (_(" [Nr] Name Type Address Offset\n")); | |
3105 | printf (_(" Size EntSize Flags Link Info Align\n")); | |
3106 | } | |
252b5132 RH |
3107 | |
3108 | for (i = 0, section = section_headers; | |
3109 | i < elf_header.e_shnum; | |
3110 | i ++, section ++) | |
3111 | { | |
3112 | printf (" [%2d] %-17.17s %-15.15s ", | |
3113 | i, | |
3114 | SECTION_NAME (section), | |
3115 | get_section_type_name (section->sh_type)); | |
3116 | ||
f7a99963 NC |
3117 | if (is_32bit_elf) |
3118 | { | |
3119 | print_vma (section->sh_addr, LONG_HEX); | |
76da6bbe | 3120 | |
f7a99963 NC |
3121 | printf ( " %6.6lx %6.6lx %2.2lx", |
3122 | (unsigned long) section->sh_offset, | |
3123 | (unsigned long) section->sh_size, | |
3124 | (unsigned long) section->sh_entsize); | |
d1133906 NC |
3125 | |
3126 | printf (" %3s ", get_elf_section_flags (section->sh_flags)); | |
76da6bbe | 3127 | |
93ebe586 | 3128 | printf ("%2ld %3lx %2ld\n", |
f7a99963 NC |
3129 | (unsigned long) section->sh_link, |
3130 | (unsigned long) section->sh_info, | |
3131 | (unsigned long) section->sh_addralign); | |
3132 | } | |
d974e256 JJ |
3133 | else if (do_wide) |
3134 | { | |
3135 | print_vma (section->sh_addr, LONG_HEX); | |
3136 | ||
3137 | if ((long) section->sh_offset == section->sh_offset) | |
3138 | printf (" %6.6lx", (unsigned long) section->sh_offset); | |
3139 | else | |
3140 | { | |
3141 | putchar (' '); | |
3142 | print_vma (section->sh_offset, LONG_HEX); | |
3143 | } | |
3144 | ||
3145 | if ((unsigned long) section->sh_size == section->sh_size) | |
3146 | printf (" %6.6lx", (unsigned long) section->sh_size); | |
3147 | else | |
3148 | { | |
3149 | putchar (' '); | |
3150 | print_vma (section->sh_size, LONG_HEX); | |
3151 | } | |
3152 | ||
3153 | if ((unsigned long) section->sh_entsize == section->sh_entsize) | |
3154 | printf (" %2.2lx", (unsigned long) section->sh_entsize); | |
3155 | else | |
3156 | { | |
3157 | putchar (' '); | |
3158 | print_vma (section->sh_entsize, LONG_HEX); | |
3159 | } | |
3160 | ||
3161 | printf (" %3s ", get_elf_section_flags (section->sh_flags)); | |
3162 | ||
3163 | printf ("%2ld %3lx ", | |
3164 | (unsigned long) section->sh_link, | |
3165 | (unsigned long) section->sh_info); | |
3166 | ||
3167 | if ((unsigned long) section->sh_addralign == section->sh_addralign) | |
3168 | printf ("%2ld\n", (unsigned long) section->sh_addralign); | |
3169 | else | |
3170 | { | |
3171 | print_vma (section->sh_addralign, DEC); | |
3172 | putchar ('\n'); | |
3173 | } | |
3174 | } | |
f7a99963 NC |
3175 | else |
3176 | { | |
3177 | putchar (' '); | |
3178 | print_vma (section->sh_addr, LONG_HEX); | |
d974e256 JJ |
3179 | if ((long) section->sh_offset == section->sh_offset) |
3180 | printf (" %8.8lx", (unsigned long) section->sh_offset); | |
3181 | else | |
3182 | { | |
3183 | printf (" "); | |
3184 | print_vma (section->sh_offset, LONG_HEX); | |
3185 | } | |
f7a99963 NC |
3186 | printf ("\n "); |
3187 | print_vma (section->sh_size, LONG_HEX); | |
3188 | printf (" "); | |
3189 | print_vma (section->sh_entsize, LONG_HEX); | |
76da6bbe | 3190 | |
d1133906 | 3191 | printf (" %3s ", get_elf_section_flags (section->sh_flags)); |
76da6bbe | 3192 | |
f7a99963 NC |
3193 | printf (" %2ld %3lx %ld\n", |
3194 | (unsigned long) section->sh_link, | |
3195 | (unsigned long) section->sh_info, | |
3196 | (unsigned long) section->sh_addralign); | |
3197 | } | |
252b5132 RH |
3198 | } |
3199 | ||
e3c8793a NC |
3200 | printf (_("Key to Flags:\n\ |
3201 | W (write), A (alloc), X (execute), M (merge), S (strings)\n\ | |
3202 | I (info), L (link order), G (group), x (unknown)\n\ | |
3203 | O (extra OS processing required) o (OS specific), p (processor specific)\n")); | |
d1133906 | 3204 | |
252b5132 RH |
3205 | return 1; |
3206 | } | |
3207 | ||
3208 | /* Process the reloc section. */ | |
3209 | static int | |
3210 | process_relocs (file) | |
3211 | FILE * file; | |
3212 | { | |
3213 | unsigned long rel_size; | |
3214 | unsigned long rel_offset; | |
3215 | ||
3216 | ||
3217 | if (!do_reloc) | |
3218 | return 1; | |
3219 | ||
3220 | if (do_using_dynamic) | |
3221 | { | |
b4c96d0d | 3222 | int is_rela = FALSE; |
9c19a809 | 3223 | |
252b5132 RH |
3224 | rel_size = 0; |
3225 | rel_offset = 0; | |
3226 | ||
3227 | if (dynamic_info[DT_REL]) | |
3228 | { | |
3229 | rel_offset = dynamic_info[DT_REL]; | |
3230 | rel_size = dynamic_info[DT_RELSZ]; | |
9c19a809 | 3231 | is_rela = FALSE; |
252b5132 RH |
3232 | } |
3233 | else if (dynamic_info [DT_RELA]) | |
3234 | { | |
3235 | rel_offset = dynamic_info[DT_RELA]; | |
3236 | rel_size = dynamic_info[DT_RELASZ]; | |
9c19a809 | 3237 | is_rela = TRUE; |
252b5132 RH |
3238 | } |
3239 | else if (dynamic_info[DT_JMPREL]) | |
3240 | { | |
3241 | rel_offset = dynamic_info[DT_JMPREL]; | |
3242 | rel_size = dynamic_info[DT_PLTRELSZ]; | |
103f02d3 | 3243 | |
aa903cfb AS |
3244 | switch (dynamic_info[DT_PLTREL]) |
3245 | { | |
3246 | case DT_REL: | |
3247 | is_rela = FALSE; | |
3248 | break; | |
3249 | case DT_RELA: | |
3250 | is_rela = TRUE; | |
3251 | break; | |
3252 | default: | |
3253 | is_rela = UNKNOWN; | |
3254 | break; | |
3255 | } | |
252b5132 RH |
3256 | } |
3257 | ||
3258 | if (rel_size) | |
3259 | { | |
3260 | printf | |
3261 | (_("\nRelocation section at offset 0x%lx contains %ld bytes:\n"), | |
3262 | rel_offset, rel_size); | |
3263 | ||
3264 | dump_relocations (file, rel_offset - loadaddr, rel_size, | |
19936277 | 3265 | dynamic_symbols, num_dynamic_syms, dynamic_strings, is_rela); |
252b5132 RH |
3266 | } |
3267 | else | |
3268 | printf (_("\nThere are no dynamic relocations in this file.\n")); | |
3269 | } | |
3270 | else | |
3271 | { | |
3272 | Elf32_Internal_Shdr * section; | |
7036c0e1 AJ |
3273 | unsigned long i; |
3274 | int found = 0; | |
252b5132 RH |
3275 | |
3276 | for (i = 0, section = section_headers; | |
3277 | i < elf_header.e_shnum; | |
3278 | i++, section ++) | |
3279 | { | |
3280 | if ( section->sh_type != SHT_RELA | |
3281 | && section->sh_type != SHT_REL) | |
3282 | continue; | |
3283 | ||
3284 | rel_offset = section->sh_offset; | |
3285 | rel_size = section->sh_size; | |
3286 | ||
3287 | if (rel_size) | |
3288 | { | |
3289 | Elf32_Internal_Shdr * strsec; | |
252b5132 RH |
3290 | Elf_Internal_Sym * symtab; |
3291 | char * strtab; | |
9c19a809 | 3292 | int is_rela; |
19936277 | 3293 | unsigned long nsyms; |
103f02d3 | 3294 | |
252b5132 RH |
3295 | printf (_("\nRelocation section ")); |
3296 | ||
3297 | if (string_table == NULL) | |
19936277 | 3298 | printf ("%d", section->sh_name); |
252b5132 | 3299 | else |
19936277 | 3300 | printf ("'%s'", SECTION_NAME (section)); |
252b5132 RH |
3301 | |
3302 | printf (_(" at offset 0x%lx contains %lu entries:\n"), | |
3303 | rel_offset, (unsigned long) (rel_size / section->sh_entsize)); | |
3304 | ||
af3fc3bc AM |
3305 | symtab = NULL; |
3306 | strtab = NULL; | |
3307 | nsyms = 0; | |
3308 | if (section->sh_link) | |
3309 | { | |
3310 | Elf32_Internal_Shdr * symsec; | |
252b5132 | 3311 | |
af3fc3bc AM |
3312 | symsec = section_headers + section->sh_link; |
3313 | nsyms = symsec->sh_size / symsec->sh_entsize; | |
3314 | symtab = GET_ELF_SYMBOLS (file, symsec->sh_offset, nsyms); | |
252b5132 | 3315 | |
af3fc3bc AM |
3316 | if (symtab == NULL) |
3317 | continue; | |
252b5132 | 3318 | |
af3fc3bc | 3319 | strsec = section_headers + symsec->sh_link; |
103f02d3 | 3320 | |
a6e9f9df AM |
3321 | strtab = (char *) get_data (NULL, file, strsec->sh_offset, |
3322 | strsec->sh_size, | |
3323 | _("string table")); | |
af3fc3bc | 3324 | } |
aa903cfb | 3325 | is_rela = section->sh_type == SHT_RELA; |
252b5132 | 3326 | |
af3fc3bc AM |
3327 | dump_relocations (file, rel_offset, rel_size, |
3328 | symtab, nsyms, strtab, is_rela); | |
252b5132 | 3329 | |
af3fc3bc AM |
3330 | if (strtab) |
3331 | free (strtab); | |
3332 | if (symtab) | |
3333 | free (symtab); | |
252b5132 RH |
3334 | |
3335 | found = 1; | |
3336 | } | |
3337 | } | |
3338 | ||
3339 | if (! found) | |
3340 | printf (_("\nThere are no relocations in this file.\n")); | |
3341 | } | |
3342 | ||
3343 | return 1; | |
3344 | } | |
3345 | ||
4d6ed7c8 NC |
3346 | #include "unwind-ia64.h" |
3347 | ||
3348 | /* An absolute address consists of a section and an offset. If the | |
3349 | section is NULL, the offset itself is the address, otherwise, the | |
3350 | address equals to LOAD_ADDRESS(section) + offset. */ | |
3351 | ||
3352 | struct absaddr | |
3353 | { | |
3354 | unsigned short section; | |
3355 | bfd_vma offset; | |
3356 | }; | |
3357 | ||
3358 | struct unw_aux_info | |
3359 | { | |
3360 | struct unw_table_entry | |
3361 | { | |
3362 | struct absaddr start; | |
3363 | struct absaddr end; | |
3364 | struct absaddr info; | |
3365 | } | |
3366 | *table; /* Unwind table. */ | |
3367 | unsigned long table_len; /* Length of unwind table. */ | |
ecd03389 | 3368 | unsigned char * info; /* Unwind info. */ |
4d6ed7c8 NC |
3369 | unsigned long info_size; /* Size of unwind info. */ |
3370 | bfd_vma info_addr; /* starting address of unwind info. */ | |
3371 | bfd_vma seg_base; /* Starting address of segment. */ | |
3372 | Elf_Internal_Sym * symtab; /* The symbol table. */ | |
3373 | unsigned long nsyms; /* Number of symbols. */ | |
a59e3bd7 | 3374 | char * strtab; /* The string table. */ |
4d6ed7c8 NC |
3375 | unsigned long strtab_size; /* Size of string table. */ |
3376 | }; | |
3377 | ||
3378 | static void find_symbol_for_address PARAMS ((struct unw_aux_info *, | |
3379 | struct absaddr, const char **, | |
3380 | bfd_vma *)); | |
3381 | static void dump_ia64_unwind PARAMS ((struct unw_aux_info *)); | |
f5e21966 | 3382 | static int slurp_ia64_unwind_table PARAMS ((FILE *, struct unw_aux_info *, |
4d6ed7c8 NC |
3383 | Elf32_Internal_Shdr *)); |
3384 | ||
3385 | static void | |
3386 | find_symbol_for_address (aux, addr, symname, offset) | |
3387 | struct unw_aux_info *aux; | |
3388 | struct absaddr addr; | |
3389 | const char **symname; | |
3390 | bfd_vma *offset; | |
3391 | { | |
3392 | bfd_vma dist = (bfd_vma) 0x100000; | |
3393 | Elf_Internal_Sym *sym, *best = NULL; | |
3394 | unsigned long i; | |
3395 | ||
3396 | for (i = 0, sym = aux->symtab; i < aux->nsyms; ++i, ++sym) | |
3397 | { | |
3398 | if (ELF_ST_TYPE (sym->st_info) == STT_FUNC | |
3399 | && sym->st_name != 0 | |
3400 | && (addr.section == SHN_UNDEF || addr.section == sym->st_shndx) | |
3401 | && addr.offset >= sym->st_value | |
3402 | && addr.offset - sym->st_value < dist) | |
3403 | { | |
3404 | best = sym; | |
3405 | dist = addr.offset - sym->st_value; | |
3406 | if (!dist) | |
3407 | break; | |
3408 | } | |
3409 | } | |
3410 | if (best) | |
3411 | { | |
3412 | *symname = (best->st_name >= aux->strtab_size | |
3413 | ? "<corrupt>" : aux->strtab + best->st_name); | |
3414 | *offset = dist; | |
3415 | return; | |
3416 | } | |
3417 | *symname = NULL; | |
3418 | *offset = addr.offset; | |
3419 | } | |
3420 | ||
3421 | static void | |
3422 | dump_ia64_unwind (aux) | |
3423 | struct unw_aux_info *aux; | |
3424 | { | |
3425 | bfd_vma addr_size; | |
3426 | struct unw_table_entry * tp; | |
3427 | int in_body; | |
7036c0e1 | 3428 | |
4d6ed7c8 NC |
3429 | addr_size = is_32bit_elf ? 4 : 8; |
3430 | ||
3431 | for (tp = aux->table; tp < aux->table + aux->table_len; ++tp) | |
3432 | { | |
3433 | bfd_vma stamp; | |
3434 | bfd_vma offset; | |
3435 | const unsigned char * dp; | |
3436 | const unsigned char * head; | |
3437 | const char * procname; | |
3438 | ||
3439 | find_symbol_for_address (aux, tp->start, &procname, &offset); | |
3440 | ||
3441 | fputs ("\n<", stdout); | |
3442 | ||
3443 | if (procname) | |
3444 | { | |
3445 | fputs (procname, stdout); | |
3446 | ||
3447 | if (offset) | |
3448 | printf ("+%lx", (unsigned long) offset); | |
3449 | } | |
3450 | ||
3451 | fputs (">: [", stdout); | |
3452 | print_vma (tp->start.offset, PREFIX_HEX); | |
3453 | fputc ('-', stdout); | |
3454 | print_vma (tp->end.offset, PREFIX_HEX); | |
3455 | printf ("), info at +0x%lx\n", | |
3456 | (unsigned long) (tp->info.offset - aux->seg_base)); | |
3457 | ||
3458 | head = aux->info + (tp->info.offset - aux->info_addr); | |
3459 | stamp = BYTE_GET8 ((unsigned char *) head); | |
3460 | ||
3461 | printf (" v%u, flags=0x%lx (%s%s ), len=%lu bytes\n", | |
3462 | (unsigned) UNW_VER (stamp), | |
3463 | (unsigned long) ((stamp & UNW_FLAG_MASK) >> 32), | |
3464 | UNW_FLAG_EHANDLER (stamp) ? " ehandler" : "", | |
3465 | UNW_FLAG_UHANDLER (stamp) ? " uhandler" : "", | |
3466 | (unsigned long) (addr_size * UNW_LENGTH (stamp))); | |
3467 | ||
3468 | if (UNW_VER (stamp) != 1) | |
3469 | { | |
3470 | printf ("\tUnknown version.\n"); | |
3471 | continue; | |
3472 | } | |
3473 | ||
3474 | in_body = 0; | |
3475 | for (dp = head + 8; dp < head + 8 + addr_size * UNW_LENGTH (stamp);) | |
3476 | dp = unw_decode (dp, in_body, & in_body); | |
3477 | } | |
3478 | } | |
3479 | ||
3480 | static int | |
3481 | slurp_ia64_unwind_table (file, aux, sec) | |
3482 | FILE *file; | |
3483 | struct unw_aux_info *aux; | |
3484 | Elf32_Internal_Shdr *sec; | |
3485 | { | |
3486 | unsigned long size, addr_size, nrelas, i; | |
3487 | Elf_Internal_Phdr *prog_hdrs, *seg; | |
3488 | struct unw_table_entry *tep; | |
3489 | Elf32_Internal_Shdr *relsec; | |
3490 | Elf_Internal_Rela *rela, *rp; | |
3491 | unsigned char *table, *tp; | |
3492 | Elf_Internal_Sym *sym; | |
3493 | const char *relname; | |
3494 | int result; | |
3495 | ||
3496 | addr_size = is_32bit_elf ? 4 : 8; | |
3497 | ||
3498 | /* First, find the starting address of the segment that includes | |
3499 | this section: */ | |
3500 | ||
3501 | if (elf_header.e_phnum) | |
3502 | { | |
3503 | prog_hdrs = (Elf_Internal_Phdr *) | |
3504 | xmalloc (elf_header.e_phnum * sizeof (Elf_Internal_Phdr)); | |
3505 | ||
3506 | if (is_32bit_elf) | |
3507 | result = get_32bit_program_headers (file, prog_hdrs); | |
3508 | else | |
3509 | result = get_64bit_program_headers (file, prog_hdrs); | |
3510 | ||
3511 | if (!result) | |
3512 | { | |
3513 | free (prog_hdrs); | |
3514 | return 0; | |
3515 | } | |
3516 | ||
3517 | for (seg = prog_hdrs; seg < prog_hdrs + elf_header.e_phnum; ++seg) | |
3518 | { | |
3519 | if (seg->p_type != PT_LOAD) | |
3520 | continue; | |
3521 | ||
3522 | if (sec->sh_addr >= seg->p_vaddr | |
3523 | && (sec->sh_addr + sec->sh_size <= seg->p_vaddr + seg->p_memsz)) | |
3524 | { | |
3525 | aux->seg_base = seg->p_vaddr; | |
3526 | break; | |
3527 | } | |
3528 | } | |
3529 | ||
3530 | free (prog_hdrs); | |
3531 | } | |
3532 | ||
3533 | /* Second, build the unwind table from the contents of the unwind section: */ | |
3534 | size = sec->sh_size; | |
a6e9f9df AM |
3535 | table = (char *) get_data (NULL, file, sec->sh_offset, |
3536 | size, _("unwind table")); | |
3537 | if (!table) | |
3538 | return 0; | |
4d6ed7c8 NC |
3539 | |
3540 | tep = aux->table = xmalloc (size / (3 * addr_size) * sizeof (aux->table[0])); | |
3541 | for (tp = table; tp < table + size; tp += 3 * addr_size, ++ tep) | |
3542 | { | |
3543 | tep->start.section = SHN_UNDEF; | |
3544 | tep->end.section = SHN_UNDEF; | |
3545 | tep->info.section = SHN_UNDEF; | |
3546 | if (is_32bit_elf) | |
3547 | { | |
3548 | tep->start.offset = byte_get ((unsigned char *) tp + 0, 4); | |
3549 | tep->end.offset = byte_get ((unsigned char *) tp + 4, 4); | |
3550 | tep->info.offset = byte_get ((unsigned char *) tp + 8, 4); | |
3551 | } | |
3552 | else | |
3553 | { | |
3554 | tep->start.offset = BYTE_GET8 ((unsigned char *) tp + 0); | |
3555 | tep->end.offset = BYTE_GET8 ((unsigned char *) tp + 8); | |
3556 | tep->info.offset = BYTE_GET8 ((unsigned char *) tp + 16); | |
3557 | } | |
3558 | tep->start.offset += aux->seg_base; | |
3559 | tep->end.offset += aux->seg_base; | |
3560 | tep->info.offset += aux->seg_base; | |
3561 | } | |
3562 | free (table); | |
3563 | ||
3564 | /* Third, apply any relocations to the unwind table: */ | |
3565 | ||
3566 | for (relsec = section_headers; | |
3567 | relsec < section_headers + elf_header.e_shnum; | |
3568 | ++relsec) | |
3569 | { | |
3570 | if (relsec->sh_type != SHT_RELA | |
3571 | || section_headers + relsec->sh_info != sec) | |
3572 | continue; | |
3573 | ||
3574 | if (!slurp_rela_relocs (file, relsec->sh_offset, relsec->sh_size, | |
3575 | & rela, & nrelas)) | |
3576 | return 0; | |
3577 | ||
3578 | for (rp = rela; rp < rela + nrelas; ++rp) | |
3579 | { | |
3580 | if (is_32bit_elf) | |
3581 | { | |
3582 | relname = elf_ia64_reloc_type (ELF32_R_TYPE (rp->r_info)); | |
3583 | sym = aux->symtab + ELF32_R_SYM (rp->r_info); | |
3584 | ||
3585 | if (ELF32_ST_TYPE (sym->st_info) != STT_SECTION) | |
3586 | { | |
e5fb9629 | 3587 | warn (_("Skipping unexpected symbol type %u\n"), |
4d6ed7c8 NC |
3588 | ELF32_ST_TYPE (sym->st_info)); |
3589 | continue; | |
3590 | } | |
3591 | } | |
3592 | else | |
3593 | { | |
3594 | relname = elf_ia64_reloc_type (ELF64_R_TYPE (rp->r_info)); | |
3595 | sym = aux->symtab + ELF64_R_SYM (rp->r_info); | |
3596 | ||
3597 | if (ELF64_ST_TYPE (sym->st_info) != STT_SECTION) | |
3598 | { | |
e5fb9629 | 3599 | warn (_("Skipping unexpected symbol type %u\n"), |
4d6ed7c8 NC |
3600 | ELF64_ST_TYPE (sym->st_info)); |
3601 | continue; | |
3602 | } | |
3603 | } | |
3604 | ||
3605 | if (strncmp (relname, "R_IA64_SEGREL", 13) != 0) | |
3606 | { | |
e5fb9629 | 3607 | warn (_("Skipping unexpected relocation type %s\n"), relname); |
4d6ed7c8 NC |
3608 | continue; |
3609 | } | |
3610 | ||
3611 | i = rp->r_offset / (3 * addr_size); | |
3612 | ||
3613 | switch (rp->r_offset/addr_size % 3) | |
3614 | { | |
3615 | case 0: | |
3616 | aux->table[i].start.section = sym->st_shndx; | |
3617 | aux->table[i].start.offset += rp->r_addend; | |
3618 | break; | |
3619 | case 1: | |
3620 | aux->table[i].end.section = sym->st_shndx; | |
3621 | aux->table[i].end.offset += rp->r_addend; | |
3622 | break; | |
3623 | case 2: | |
3624 | aux->table[i].info.section = sym->st_shndx; | |
3625 | aux->table[i].info.offset += rp->r_addend; | |
3626 | break; | |
3627 | default: | |
3628 | break; | |
3629 | } | |
3630 | } | |
3631 | ||
3632 | free (rela); | |
3633 | } | |
3634 | ||
3635 | aux->table_len = size / (3 * addr_size); | |
3636 | return 1; | |
3637 | } | |
3638 | ||
3639 | static int | |
3640 | process_unwind (file) | |
3641 | FILE * file; | |
3642 | { | |
3643 | Elf32_Internal_Shdr *sec, *unwsec = NULL, *strsec; | |
579f31ac | 3644 | unsigned long i, addr_size, unwcount = 0, unwstart = 0; |
4d6ed7c8 NC |
3645 | struct unw_aux_info aux; |
3646 | ||
e58d53af L |
3647 | if (!do_unwind) |
3648 | return 1; | |
3649 | ||
f1467e33 L |
3650 | if (elf_header.e_machine != EM_IA_64) |
3651 | { | |
3652 | printf (_("\nThere are no unwind sections in this file.\n")); | |
3653 | return 1; | |
3654 | } | |
3655 | ||
4d6ed7c8 NC |
3656 | memset (& aux, 0, sizeof (aux)); |
3657 | ||
3658 | addr_size = is_32bit_elf ? 4 : 8; | |
3659 | ||
4d6ed7c8 NC |
3660 | for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec) |
3661 | { | |
3662 | if (sec->sh_type == SHT_SYMTAB) | |
3663 | { | |
3664 | aux.nsyms = sec->sh_size / sec->sh_entsize; | |
3665 | aux.symtab = GET_ELF_SYMBOLS (file, sec->sh_offset, aux.nsyms); | |
3666 | ||
3667 | strsec = section_headers + sec->sh_link; | |
3668 | aux.strtab_size = strsec->sh_size; | |
a6e9f9df AM |
3669 | aux.strtab = (char *) get_data (NULL, file, strsec->sh_offset, |
3670 | aux.strtab_size, _("string table")); | |
4d6ed7c8 NC |
3671 | } |
3672 | else if (sec->sh_type == SHT_IA_64_UNWIND) | |
579f31ac JJ |
3673 | unwcount++; |
3674 | } | |
3675 | ||
3676 | if (!unwcount) | |
3677 | printf (_("\nThere are no unwind sections in this file.\n")); | |
3678 | ||
3679 | while (unwcount-- > 0) | |
3680 | { | |
3681 | char *suffix; | |
3682 | size_t len, len2; | |
3683 | ||
3684 | for (i = unwstart, sec = section_headers + unwstart; | |
3685 | i < elf_header.e_shnum; ++i, ++sec) | |
3686 | if (sec->sh_type == SHT_IA_64_UNWIND) | |
3687 | { | |
3688 | unwsec = sec; | |
3689 | break; | |
3690 | } | |
3691 | ||
3692 | unwstart = i + 1; | |
3693 | len = sizeof (ELF_STRING_ia64_unwind_once) - 1; | |
3694 | ||
3695 | if (strncmp (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind_once, | |
3696 | len) == 0) | |
3697 | { | |
3698 | /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO */ | |
3699 | len2 = sizeof (ELF_STRING_ia64_unwind_info_once) - 1; | |
3700 | suffix = SECTION_NAME (unwsec) + len; | |
3701 | for (i = 0, sec = section_headers; i < elf_header.e_shnum; | |
3702 | ++i, ++sec) | |
3703 | if (strncmp (SECTION_NAME (sec), | |
3704 | ELF_STRING_ia64_unwind_info_once, len2) == 0 | |
3705 | && strcmp (SECTION_NAME (sec) + len2, suffix) == 0) | |
3706 | break; | |
3707 | } | |
3708 | else | |
3709 | { | |
3710 | /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO | |
3711 | .IA_64.unwind or BAR -> .IA_64.unwind_info */ | |
3712 | len = sizeof (ELF_STRING_ia64_unwind) - 1; | |
3713 | len2 = sizeof (ELF_STRING_ia64_unwind_info) - 1; | |
3714 | suffix = ""; | |
3715 | if (strncmp (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind, | |
3716 | len) == 0) | |
3717 | suffix = SECTION_NAME (unwsec) + len; | |
3718 | for (i = 0, sec = section_headers; i < elf_header.e_shnum; | |
3719 | ++i, ++sec) | |
3720 | if (strncmp (SECTION_NAME (sec), | |
3721 | ELF_STRING_ia64_unwind_info, len2) == 0 | |
3722 | && strcmp (SECTION_NAME (sec) + len2, suffix) == 0) | |
3723 | break; | |
3724 | } | |
3725 | ||
3726 | if (i == elf_header.e_shnum) | |
3727 | { | |
3728 | printf (_("\nCould not find unwind info section for ")); | |
3729 | ||
3730 | if (string_table == NULL) | |
3731 | printf ("%d", unwsec->sh_name); | |
3732 | else | |
3733 | printf ("'%s'", SECTION_NAME (unwsec)); | |
3734 | } | |
3735 | else | |
4d6ed7c8 NC |
3736 | { |
3737 | aux.info_size = sec->sh_size; | |
3738 | aux.info_addr = sec->sh_addr; | |
a6e9f9df AM |
3739 | aux.info = (char *) get_data (NULL, file, sec->sh_offset, |
3740 | aux.info_size, _("unwind info")); | |
4d6ed7c8 | 3741 | |
579f31ac | 3742 | printf (_("\nUnwind section ")); |
4d6ed7c8 | 3743 | |
579f31ac JJ |
3744 | if (string_table == NULL) |
3745 | printf ("%d", unwsec->sh_name); | |
3746 | else | |
3747 | printf ("'%s'", SECTION_NAME (unwsec)); | |
4d6ed7c8 | 3748 | |
579f31ac | 3749 | printf (_(" at offset 0x%lx contains %lu entries:\n"), |
e59b4dfb | 3750 | (unsigned long) unwsec->sh_offset, |
579f31ac | 3751 | (unsigned long) (unwsec->sh_size / (3 * addr_size))); |
4d6ed7c8 | 3752 | |
579f31ac | 3753 | (void) slurp_ia64_unwind_table (file, & aux, unwsec); |
4d6ed7c8 | 3754 | |
579f31ac JJ |
3755 | if (aux.table_len > 0) |
3756 | dump_ia64_unwind (& aux); | |
3757 | ||
3758 | if (aux.table) | |
3759 | free ((char *) aux.table); | |
3760 | if (aux.info) | |
3761 | free ((char *) aux.info); | |
3762 | aux.table = NULL; | |
3763 | aux.info = NULL; | |
3764 | } | |
4d6ed7c8 | 3765 | } |
4d6ed7c8 | 3766 | |
4d6ed7c8 NC |
3767 | if (aux.symtab) |
3768 | free (aux.symtab); | |
3769 | if (aux.strtab) | |
3770 | free ((char *) aux.strtab); | |
3771 | ||
3772 | return 1; | |
3773 | } | |
3774 | ||
252b5132 RH |
3775 | static void |
3776 | dynamic_segment_mips_val (entry) | |
3777 | Elf_Internal_Dyn * entry; | |
3778 | { | |
3779 | switch (entry->d_tag) | |
3780 | { | |
3781 | case DT_MIPS_FLAGS: | |
3782 | if (entry->d_un.d_val == 0) | |
3783 | printf ("NONE\n"); | |
3784 | else | |
3785 | { | |
3786 | static const char * opts[] = | |
3787 | { | |
3788 | "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT", | |
3789 | "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS", | |
3790 | "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD", | |
3791 | "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF", | |
3792 | "RLD_ORDER_SAFE" | |
3793 | }; | |
3794 | unsigned int cnt; | |
3795 | int first = 1; | |
3796 | for (cnt = 0; cnt < NUM_ELEM (opts); ++ cnt) | |
3797 | if (entry->d_un.d_val & (1 << cnt)) | |
3798 | { | |
3799 | printf ("%s%s", first ? "" : " ", opts[cnt]); | |
3800 | first = 0; | |
3801 | } | |
3802 | puts (""); | |
3803 | } | |
3804 | break; | |
103f02d3 | 3805 | |
252b5132 RH |
3806 | case DT_MIPS_IVERSION: |
3807 | if (dynamic_strings != NULL) | |
3808 | printf ("Interface Version: %s\n", | |
3809 | dynamic_strings + entry->d_un.d_val); | |
3810 | else | |
3811 | printf ("%ld\n", (long) entry->d_un.d_ptr); | |
3812 | break; | |
103f02d3 | 3813 | |
252b5132 RH |
3814 | case DT_MIPS_TIME_STAMP: |
3815 | { | |
3816 | char timebuf[20]; | |
50da7a9c NC |
3817 | struct tm * tmp; |
3818 | ||
252b5132 | 3819 | time_t time = entry->d_un.d_val; |
50da7a9c NC |
3820 | tmp = gmtime (&time); |
3821 | sprintf (timebuf, "%04u-%02u-%02uT%02u:%02u:%02u", | |
3822 | tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday, | |
3823 | tmp->tm_hour, tmp->tm_min, tmp->tm_sec); | |
252b5132 RH |
3824 | printf ("Time Stamp: %s\n", timebuf); |
3825 | } | |
3826 | break; | |
103f02d3 | 3827 | |
252b5132 RH |
3828 | case DT_MIPS_RLD_VERSION: |
3829 | case DT_MIPS_LOCAL_GOTNO: | |
3830 | case DT_MIPS_CONFLICTNO: | |
3831 | case DT_MIPS_LIBLISTNO: | |
3832 | case DT_MIPS_SYMTABNO: | |
3833 | case DT_MIPS_UNREFEXTNO: | |
3834 | case DT_MIPS_HIPAGENO: | |
3835 | case DT_MIPS_DELTA_CLASS_NO: | |
3836 | case DT_MIPS_DELTA_INSTANCE_NO: | |
3837 | case DT_MIPS_DELTA_RELOC_NO: | |
3838 | case DT_MIPS_DELTA_SYM_NO: | |
3839 | case DT_MIPS_DELTA_CLASSSYM_NO: | |
3840 | case DT_MIPS_COMPACT_SIZE: | |
3841 | printf ("%ld\n", (long) entry->d_un.d_ptr); | |
3842 | break; | |
103f02d3 UD |
3843 | |
3844 | default: | |
3845 | printf ("%#lx\n", (long) entry->d_un.d_ptr); | |
3846 | } | |
3847 | } | |
3848 | ||
3849 | ||
3850 | static void | |
3851 | dynamic_segment_parisc_val (entry) | |
3852 | Elf_Internal_Dyn * entry; | |
3853 | { | |
3854 | switch (entry->d_tag) | |
3855 | { | |
3856 | case DT_HP_DLD_FLAGS: | |
3857 | { | |
3858 | static struct | |
3859 | { | |
3860 | long int bit; | |
5e220199 NC |
3861 | const char * str; |
3862 | } | |
3863 | flags[] = | |
3864 | { | |
3865 | { DT_HP_DEBUG_PRIVATE, "HP_DEBUG_PRIVATE" }, | |
3866 | { DT_HP_DEBUG_CALLBACK, "HP_DEBUG_CALLBACK" }, | |
3867 | { DT_HP_DEBUG_CALLBACK_BOR, "HP_DEBUG_CALLBACK_BOR" }, | |
3868 | { DT_HP_NO_ENVVAR, "HP_NO_ENVVAR" }, | |
3869 | { DT_HP_BIND_NOW, "HP_BIND_NOW" }, | |
3870 | { DT_HP_BIND_NONFATAL, "HP_BIND_NONFATAL" }, | |
3871 | { DT_HP_BIND_VERBOSE, "HP_BIND_VERBOSE" }, | |
3872 | { DT_HP_BIND_RESTRICTED, "HP_BIND_RESTRICTED" }, | |
3873 | { DT_HP_BIND_SYMBOLIC, "HP_BIND_SYMBOLIC" }, | |
3874 | { DT_HP_RPATH_FIRST, "HP_RPATH_FIRST" }, | |
3875 | { DT_HP_BIND_DEPTH_FIRST, "HP_BIND_DEPTH_FIRST" } | |
3876 | }; | |
103f02d3 | 3877 | int first = 1; |
5e220199 | 3878 | size_t cnt; |
f7a99963 | 3879 | bfd_vma val = entry->d_un.d_val; |
103f02d3 UD |
3880 | |
3881 | for (cnt = 0; cnt < sizeof (flags) / sizeof (flags[0]); ++cnt) | |
3882 | if (val & flags[cnt].bit) | |
30800947 NC |
3883 | { |
3884 | if (! first) | |
3885 | putchar (' '); | |
3886 | fputs (flags[cnt].str, stdout); | |
3887 | first = 0; | |
3888 | val ^= flags[cnt].bit; | |
3889 | } | |
76da6bbe | 3890 | |
103f02d3 | 3891 | if (val != 0 || first) |
f7a99963 NC |
3892 | { |
3893 | if (! first) | |
3894 | putchar (' '); | |
3895 | print_vma (val, HEX); | |
3896 | } | |
103f02d3 UD |
3897 | } |
3898 | break; | |
76da6bbe | 3899 | |
252b5132 | 3900 | default: |
f7a99963 NC |
3901 | print_vma (entry->d_un.d_ptr, PREFIX_HEX); |
3902 | break; | |
252b5132 RH |
3903 | } |
3904 | } | |
3905 | ||
252b5132 | 3906 | static int |
9ea033b2 | 3907 | get_32bit_dynamic_segment (file) |
252b5132 RH |
3908 | FILE * file; |
3909 | { | |
9ea033b2 NC |
3910 | Elf32_External_Dyn * edyn; |
3911 | Elf_Internal_Dyn * entry; | |
3912 | bfd_size_type i; | |
103f02d3 | 3913 | |
a6e9f9df AM |
3914 | edyn = (Elf32_External_Dyn *) get_data (NULL, file, dynamic_addr, |
3915 | dynamic_size, _("dynamic segment")); | |
3916 | if (!edyn) | |
3917 | return 0; | |
103f02d3 | 3918 | |
9ea033b2 NC |
3919 | /* SGI's ELF has more than one section in the DYNAMIC segment. Determine |
3920 | how large this .dynamic is now. We can do this even before the byte | |
3921 | swapping since the DT_NULL tag is recognizable. */ | |
3922 | dynamic_size = 0; | |
3923 | while (*(Elf32_Word *) edyn [dynamic_size++].d_tag != DT_NULL) | |
3924 | ; | |
252b5132 | 3925 | |
9ea033b2 NC |
3926 | dynamic_segment = (Elf_Internal_Dyn *) |
3927 | malloc (dynamic_size * sizeof (Elf_Internal_Dyn)); | |
3928 | ||
3929 | if (dynamic_segment == NULL) | |
252b5132 | 3930 | { |
9ea033b2 NC |
3931 | error (_("Out of memory\n")); |
3932 | free (edyn); | |
3933 | return 0; | |
3934 | } | |
252b5132 | 3935 | |
9ea033b2 NC |
3936 | for (i = 0, entry = dynamic_segment; |
3937 | i < dynamic_size; | |
3938 | i ++, entry ++) | |
3939 | { | |
3940 | entry->d_tag = BYTE_GET (edyn [i].d_tag); | |
3941 | entry->d_un.d_val = BYTE_GET (edyn [i].d_un.d_val); | |
252b5132 RH |
3942 | } |
3943 | ||
9ea033b2 NC |
3944 | free (edyn); |
3945 | ||
3946 | return 1; | |
3947 | } | |
3948 | ||
3949 | static int | |
3950 | get_64bit_dynamic_segment (file) | |
3951 | FILE * file; | |
3952 | { | |
3953 | Elf64_External_Dyn * edyn; | |
3954 | Elf_Internal_Dyn * entry; | |
3955 | bfd_size_type i; | |
103f02d3 | 3956 | |
a6e9f9df AM |
3957 | edyn = (Elf64_External_Dyn *) get_data (NULL, file, dynamic_addr, |
3958 | dynamic_size, _("dynamic segment")); | |
3959 | if (!edyn) | |
3960 | return 0; | |
103f02d3 | 3961 | |
252b5132 | 3962 | /* SGI's ELF has more than one section in the DYNAMIC segment. Determine |
9ea033b2 | 3963 | how large this .dynamic is now. We can do this even before the byte |
252b5132 RH |
3964 | swapping since the DT_NULL tag is recognizable. */ |
3965 | dynamic_size = 0; | |
9ea033b2 | 3966 | while (*(bfd_vma *) edyn [dynamic_size ++].d_tag != DT_NULL) |
252b5132 RH |
3967 | ; |
3968 | ||
3969 | dynamic_segment = (Elf_Internal_Dyn *) | |
3970 | malloc (dynamic_size * sizeof (Elf_Internal_Dyn)); | |
3971 | ||
3972 | if (dynamic_segment == NULL) | |
3973 | { | |
3974 | error (_("Out of memory\n")); | |
3975 | free (edyn); | |
3976 | return 0; | |
3977 | } | |
3978 | ||
3979 | for (i = 0, entry = dynamic_segment; | |
3980 | i < dynamic_size; | |
3981 | i ++, entry ++) | |
3982 | { | |
9ea033b2 NC |
3983 | entry->d_tag = BYTE_GET8 (edyn [i].d_tag); |
3984 | entry->d_un.d_val = BYTE_GET8 (edyn [i].d_un.d_val); | |
252b5132 RH |
3985 | } |
3986 | ||
3987 | free (edyn); | |
3988 | ||
9ea033b2 NC |
3989 | return 1; |
3990 | } | |
3991 | ||
d1133906 NC |
3992 | static const char * |
3993 | get_dynamic_flags (flags) | |
3994 | bfd_vma flags; | |
3995 | { | |
3996 | static char buff [64]; | |
3997 | while (flags) | |
3998 | { | |
3999 | bfd_vma flag; | |
4000 | ||
4001 | flag = flags & - flags; | |
4002 | flags &= ~ flag; | |
4003 | ||
4004 | switch (flag) | |
4005 | { | |
4006 | case DF_ORIGIN: strcat (buff, "ORIGIN "); break; | |
4007 | case DF_SYMBOLIC: strcat (buff, "SYMBOLIC "); break; | |
4008 | case DF_TEXTREL: strcat (buff, "TEXTREL "); break; | |
4009 | case DF_BIND_NOW: strcat (buff, "BIND_NOW "); break; | |
305c7206 | 4010 | default: strcat (buff, "unknown "); break; |
d1133906 NC |
4011 | } |
4012 | } | |
305c7206 | 4013 | return buff; |
d1133906 NC |
4014 | } |
4015 | ||
9ea033b2 NC |
4016 | /* Parse and display the contents of the dynamic segment. */ |
4017 | static int | |
4018 | process_dynamic_segment (file) | |
4019 | FILE * file; | |
4020 | { | |
4021 | Elf_Internal_Dyn * entry; | |
4022 | bfd_size_type i; | |
4023 | ||
4024 | if (dynamic_size == 0) | |
4025 | { | |
4026 | if (do_dynamic) | |
4027 | printf (_("\nThere is no dynamic segment in this file.\n")); | |
4028 | ||
4029 | return 1; | |
4030 | } | |
4031 | ||
4032 | if (is_32bit_elf) | |
4033 | { | |
4034 | if (! get_32bit_dynamic_segment (file)) | |
4035 | return 0; | |
4036 | } | |
4037 | else if (! get_64bit_dynamic_segment (file)) | |
4038 | return 0; | |
4039 | ||
252b5132 RH |
4040 | /* Find the appropriate symbol table. */ |
4041 | if (dynamic_symbols == NULL) | |
4042 | { | |
4043 | for (i = 0, entry = dynamic_segment; | |
4044 | i < dynamic_size; | |
4045 | ++i, ++ entry) | |
4046 | { | |
4047 | unsigned long offset; | |
252b5132 RH |
4048 | |
4049 | if (entry->d_tag != DT_SYMTAB) | |
4050 | continue; | |
4051 | ||
4052 | dynamic_info[DT_SYMTAB] = entry->d_un.d_val; | |
4053 | ||
4054 | /* Since we do not know how big the symbol table is, | |
4055 | we default to reading in the entire file (!) and | |
4056 | processing that. This is overkill, I know, but it | |
e3c8793a | 4057 | should work. */ |
252b5132 RH |
4058 | offset = entry->d_un.d_val - loadaddr; |
4059 | ||
4060 | if (fseek (file, 0, SEEK_END)) | |
4061 | error (_("Unable to seek to end of file!")); | |
4062 | ||
9ea033b2 | 4063 | if (is_32bit_elf) |
19936277 | 4064 | num_dynamic_syms = (ftell (file) - offset) / sizeof (Elf32_External_Sym); |
9ea033b2 | 4065 | else |
19936277 | 4066 | num_dynamic_syms = (ftell (file) - offset) / sizeof (Elf64_External_Sym); |
252b5132 | 4067 | |
19936277 | 4068 | if (num_dynamic_syms < 1) |
252b5132 RH |
4069 | { |
4070 | error (_("Unable to determine the number of symbols to load\n")); | |
4071 | continue; | |
4072 | } | |
4073 | ||
19936277 | 4074 | dynamic_symbols = GET_ELF_SYMBOLS (file, offset, num_dynamic_syms); |
252b5132 RH |
4075 | } |
4076 | } | |
4077 | ||
4078 | /* Similarly find a string table. */ | |
4079 | if (dynamic_strings == NULL) | |
4080 | { | |
4081 | for (i = 0, entry = dynamic_segment; | |
4082 | i < dynamic_size; | |
4083 | ++i, ++ entry) | |
4084 | { | |
4085 | unsigned long offset; | |
4086 | long str_tab_len; | |
4087 | ||
4088 | if (entry->d_tag != DT_STRTAB) | |
4089 | continue; | |
4090 | ||
4091 | dynamic_info[DT_STRTAB] = entry->d_un.d_val; | |
4092 | ||
4093 | /* Since we do not know how big the string table is, | |
4094 | we default to reading in the entire file (!) and | |
4095 | processing that. This is overkill, I know, but it | |
e3c8793a | 4096 | should work. */ |
252b5132 RH |
4097 | |
4098 | offset = entry->d_un.d_val - loadaddr; | |
4099 | if (fseek (file, 0, SEEK_END)) | |
4100 | error (_("Unable to seek to end of file\n")); | |
4101 | str_tab_len = ftell (file) - offset; | |
4102 | ||
4103 | if (str_tab_len < 1) | |
4104 | { | |
4105 | error | |
4106 | (_("Unable to determine the length of the dynamic string table\n")); | |
4107 | continue; | |
4108 | } | |
4109 | ||
a6e9f9df AM |
4110 | dynamic_strings = (char *) get_data (NULL, file, offset, str_tab_len, |
4111 | _("dynamic string table")); | |
252b5132 RH |
4112 | break; |
4113 | } | |
4114 | } | |
4115 | ||
4116 | /* And find the syminfo section if available. */ | |
4117 | if (dynamic_syminfo == NULL) | |
4118 | { | |
4119 | unsigned int syminsz = 0; | |
4120 | ||
4121 | for (i = 0, entry = dynamic_segment; | |
4122 | i < dynamic_size; | |
4123 | ++i, ++ entry) | |
4124 | { | |
4125 | if (entry->d_tag == DT_SYMINENT) | |
4126 | { | |
4127 | /* Note: these braces are necessary to avoid a syntax | |
4128 | error from the SunOS4 C compiler. */ | |
4129 | assert (sizeof (Elf_External_Syminfo) == entry->d_un.d_val); | |
4130 | } | |
4131 | else if (entry->d_tag == DT_SYMINSZ) | |
4132 | syminsz = entry->d_un.d_val; | |
4133 | else if (entry->d_tag == DT_SYMINFO) | |
4134 | dynamic_syminfo_offset = entry->d_un.d_val - loadaddr; | |
4135 | } | |
4136 | ||
4137 | if (dynamic_syminfo_offset != 0 && syminsz != 0) | |
4138 | { | |
9ea033b2 NC |
4139 | Elf_External_Syminfo * extsyminfo; |
4140 | Elf_Internal_Syminfo * syminfo; | |
252b5132 RH |
4141 | |
4142 | /* There is a syminfo section. Read the data. */ | |
a6e9f9df AM |
4143 | extsyminfo = ((Elf_External_Syminfo *) |
4144 | get_data (NULL, file, dynamic_syminfo_offset, | |
4145 | syminsz, _("symbol information"))); | |
4146 | if (!extsyminfo) | |
4147 | return 0; | |
252b5132 RH |
4148 | |
4149 | dynamic_syminfo = (Elf_Internal_Syminfo *) malloc (syminsz); | |
4150 | if (dynamic_syminfo == NULL) | |
4151 | { | |
4152 | error (_("Out of memory\n")); | |
4153 | return 0; | |
4154 | } | |
4155 | ||
4156 | dynamic_syminfo_nent = syminsz / sizeof (Elf_External_Syminfo); | |
4157 | for (i = 0, syminfo = dynamic_syminfo; i < dynamic_syminfo_nent; | |
4158 | ++i, ++syminfo) | |
4159 | { | |
4160 | syminfo->si_boundto = BYTE_GET (extsyminfo[i].si_boundto); | |
4161 | syminfo->si_flags = BYTE_GET (extsyminfo[i].si_flags); | |
4162 | } | |
4163 | ||
4164 | free (extsyminfo); | |
4165 | } | |
4166 | } | |
4167 | ||
4168 | if (do_dynamic && dynamic_addr) | |
789be9f7 ILT |
4169 | printf (_("\nDynamic segment at offset 0x%x contains %ld entries:\n"), |
4170 | dynamic_addr, (long) dynamic_size); | |
252b5132 RH |
4171 | if (do_dynamic) |
4172 | printf (_(" Tag Type Name/Value\n")); | |
4173 | ||
4174 | for (i = 0, entry = dynamic_segment; | |
4175 | i < dynamic_size; | |
4176 | i++, entry ++) | |
4177 | { | |
4178 | if (do_dynamic) | |
f7a99963 | 4179 | { |
f3485b74 | 4180 | const char * dtype; |
e699b9ff | 4181 | |
f7a99963 NC |
4182 | putchar (' '); |
4183 | print_vma (entry->d_tag, FULL_HEX); | |
e699b9ff ILT |
4184 | dtype = get_dynamic_type (entry->d_tag); |
4185 | printf (" (%s)%*s", dtype, | |
4186 | ((is_32bit_elf ? 27 : 19) | |
4187 | - (int) strlen (dtype)), | |
f7a99963 NC |
4188 | " "); |
4189 | } | |
252b5132 RH |
4190 | |
4191 | switch (entry->d_tag) | |
4192 | { | |
d1133906 NC |
4193 | case DT_FLAGS: |
4194 | if (do_dynamic) | |
305c7206 | 4195 | printf ("%s", get_dynamic_flags (entry->d_un.d_val)); |
d1133906 | 4196 | break; |
76da6bbe | 4197 | |
252b5132 RH |
4198 | case DT_AUXILIARY: |
4199 | case DT_FILTER: | |
019148e4 L |
4200 | case DT_CONFIG: |
4201 | case DT_DEPAUDIT: | |
4202 | case DT_AUDIT: | |
252b5132 RH |
4203 | if (do_dynamic) |
4204 | { | |
019148e4 L |
4205 | switch (entry->d_tag) |
4206 | { | |
4207 | case DT_AUXILIARY: | |
4208 | printf (_("Auxiliary library")); | |
4209 | break; | |
4210 | ||
4211 | case DT_FILTER: | |
4212 | printf (_("Filter library")); | |
4213 | break; | |
4214 | ||
4215 | case DT_CONFIG: | |
4216 | printf (_("Configuration file")); | |
4217 | break; | |
4218 | ||
4219 | case DT_DEPAUDIT: | |
4220 | printf (_("Dependency audit library")); | |
4221 | break; | |
4222 | ||
4223 | case DT_AUDIT: | |
4224 | printf (_("Audit library")); | |
4225 | break; | |
4226 | } | |
252b5132 RH |
4227 | |
4228 | if (dynamic_strings) | |
4229 | printf (": [%s]\n", dynamic_strings + entry->d_un.d_val); | |
4230 | else | |
f7a99963 NC |
4231 | { |
4232 | printf (": "); | |
4233 | print_vma (entry->d_un.d_val, PREFIX_HEX); | |
4234 | putchar ('\n'); | |
4235 | } | |
252b5132 RH |
4236 | } |
4237 | break; | |
4238 | ||
dcefbbbd | 4239 | case DT_FEATURE: |
252b5132 RH |
4240 | if (do_dynamic) |
4241 | { | |
4242 | printf (_("Flags:")); | |
4243 | if (entry->d_un.d_val == 0) | |
4244 | printf (_(" None\n")); | |
4245 | else | |
4246 | { | |
4247 | unsigned long int val = entry->d_un.d_val; | |
4248 | if (val & DTF_1_PARINIT) | |
4249 | { | |
4250 | printf (" PARINIT"); | |
4251 | val ^= DTF_1_PARINIT; | |
4252 | } | |
dcefbbbd L |
4253 | if (val & DTF_1_CONFEXP) |
4254 | { | |
4255 | printf (" CONFEXP"); | |
4256 | val ^= DTF_1_CONFEXP; | |
4257 | } | |
252b5132 RH |
4258 | if (val != 0) |
4259 | printf (" %lx", val); | |
4260 | puts (""); | |
4261 | } | |
4262 | } | |
4263 | break; | |
4264 | ||
4265 | case DT_POSFLAG_1: | |
4266 | if (do_dynamic) | |
4267 | { | |
4268 | printf (_("Flags:")); | |
4269 | if (entry->d_un.d_val == 0) | |
4270 | printf (_(" None\n")); | |
4271 | else | |
4272 | { | |
4273 | unsigned long int val = entry->d_un.d_val; | |
4274 | if (val & DF_P1_LAZYLOAD) | |
4275 | { | |
4276 | printf (" LAZYLOAD"); | |
4277 | val ^= DF_P1_LAZYLOAD; | |
4278 | } | |
4279 | if (val & DF_P1_GROUPPERM) | |
4280 | { | |
4281 | printf (" GROUPPERM"); | |
4282 | val ^= DF_P1_GROUPPERM; | |
4283 | } | |
4284 | if (val != 0) | |
4285 | printf (" %lx", val); | |
4286 | puts (""); | |
4287 | } | |
4288 | } | |
4289 | break; | |
4290 | ||
4291 | case DT_FLAGS_1: | |
4292 | if (do_dynamic) | |
4293 | { | |
4294 | printf (_("Flags:")); | |
4295 | if (entry->d_un.d_val == 0) | |
4296 | printf (_(" None\n")); | |
4297 | else | |
4298 | { | |
4299 | unsigned long int val = entry->d_un.d_val; | |
4300 | if (val & DF_1_NOW) | |
4301 | { | |
4302 | printf (" NOW"); | |
4303 | val ^= DF_1_NOW; | |
4304 | } | |
4305 | if (val & DF_1_GLOBAL) | |
4306 | { | |
4307 | printf (" GLOBAL"); | |
4308 | val ^= DF_1_GLOBAL; | |
4309 | } | |
4310 | if (val & DF_1_GROUP) | |
4311 | { | |
4312 | printf (" GROUP"); | |
4313 | val ^= DF_1_GROUP; | |
4314 | } | |
4315 | if (val & DF_1_NODELETE) | |
4316 | { | |
4317 | printf (" NODELETE"); | |
4318 | val ^= DF_1_NODELETE; | |
4319 | } | |
4320 | if (val & DF_1_LOADFLTR) | |
4321 | { | |
4322 | printf (" LOADFLTR"); | |
4323 | val ^= DF_1_LOADFLTR; | |
4324 | } | |
4325 | if (val & DF_1_INITFIRST) | |
4326 | { | |
4327 | printf (" INITFIRST"); | |
4328 | val ^= DF_1_INITFIRST; | |
4329 | } | |
4330 | if (val & DF_1_NOOPEN) | |
4331 | { | |
4332 | printf (" NOOPEN"); | |
4333 | val ^= DF_1_NOOPEN; | |
4334 | } | |
4335 | if (val & DF_1_ORIGIN) | |
4336 | { | |
4337 | printf (" ORIGIN"); | |
4338 | val ^= DF_1_ORIGIN; | |
4339 | } | |
4340 | if (val & DF_1_DIRECT) | |
4341 | { | |
4342 | printf (" DIRECT"); | |
4343 | val ^= DF_1_DIRECT; | |
4344 | } | |
4345 | if (val & DF_1_TRANS) | |
4346 | { | |
4347 | printf (" TRANS"); | |
4348 | val ^= DF_1_TRANS; | |
4349 | } | |
4350 | if (val & DF_1_INTERPOSE) | |
4351 | { | |
4352 | printf (" INTERPOSE"); | |
4353 | val ^= DF_1_INTERPOSE; | |
4354 | } | |
f7db6139 | 4355 | if (val & DF_1_NODEFLIB) |
dcefbbbd | 4356 | { |
f7db6139 L |
4357 | printf (" NODEFLIB"); |
4358 | val ^= DF_1_NODEFLIB; | |
dcefbbbd L |
4359 | } |
4360 | if (val & DF_1_NODUMP) | |
4361 | { | |
4362 | printf (" NODUMP"); | |
4363 | val ^= DF_1_NODUMP; | |
4364 | } | |
4365 | if (val & DF_1_CONLFAT) | |
4366 | { | |
4367 | printf (" CONLFAT"); | |
4368 | val ^= DF_1_CONLFAT; | |
4369 | } | |
252b5132 RH |
4370 | if (val != 0) |
4371 | printf (" %lx", val); | |
4372 | puts (""); | |
4373 | } | |
4374 | } | |
4375 | break; | |
4376 | ||
4377 | case DT_PLTREL: | |
4378 | if (do_dynamic) | |
4379 | puts (get_dynamic_type (entry->d_un.d_val)); | |
4380 | break; | |
4381 | ||
4382 | case DT_NULL : | |
4383 | case DT_NEEDED : | |
4384 | case DT_PLTGOT : | |
4385 | case DT_HASH : | |
4386 | case DT_STRTAB : | |
4387 | case DT_SYMTAB : | |
4388 | case DT_RELA : | |
4389 | case DT_INIT : | |
4390 | case DT_FINI : | |
4391 | case DT_SONAME : | |
4392 | case DT_RPATH : | |
4393 | case DT_SYMBOLIC: | |
4394 | case DT_REL : | |
4395 | case DT_DEBUG : | |
4396 | case DT_TEXTREL : | |
4397 | case DT_JMPREL : | |
019148e4 | 4398 | case DT_RUNPATH : |
252b5132 RH |
4399 | dynamic_info[entry->d_tag] = entry->d_un.d_val; |
4400 | ||
4401 | if (do_dynamic) | |
4402 | { | |
4403 | char * name; | |
4404 | ||
4405 | if (dynamic_strings == NULL) | |
4406 | name = NULL; | |
4407 | else | |
4408 | name = dynamic_strings + entry->d_un.d_val; | |
4409 | ||
4410 | if (name) | |
4411 | { | |
4412 | switch (entry->d_tag) | |
4413 | { | |
4414 | case DT_NEEDED: | |
4415 | printf (_("Shared library: [%s]"), name); | |
4416 | ||
f7a99963 NC |
4417 | if (strcmp (name, program_interpreter) == 0) |
4418 | printf (_(" program interpreter")); | |
252b5132 RH |
4419 | break; |
4420 | ||
4421 | case DT_SONAME: | |
f7a99963 | 4422 | printf (_("Library soname: [%s]"), name); |
252b5132 RH |
4423 | break; |
4424 | ||
4425 | case DT_RPATH: | |
f7a99963 | 4426 | printf (_("Library rpath: [%s]"), name); |
252b5132 RH |
4427 | break; |
4428 | ||
019148e4 L |
4429 | case DT_RUNPATH: |
4430 | printf (_("Library runpath: [%s]"), name); | |
4431 | break; | |
4432 | ||
252b5132 | 4433 | default: |
f7a99963 NC |
4434 | print_vma (entry->d_un.d_val, PREFIX_HEX); |
4435 | break; | |
252b5132 RH |
4436 | } |
4437 | } | |
4438 | else | |
f7a99963 NC |
4439 | print_vma (entry->d_un.d_val, PREFIX_HEX); |
4440 | ||
4441 | putchar ('\n'); | |
252b5132 RH |
4442 | } |
4443 | break; | |
4444 | ||
4445 | case DT_PLTRELSZ: | |
4446 | case DT_RELASZ : | |
4447 | case DT_STRSZ : | |
4448 | case DT_RELSZ : | |
4449 | case DT_RELAENT : | |
4450 | case DT_SYMENT : | |
4451 | case DT_RELENT : | |
4452 | case DT_PLTPADSZ: | |
4453 | case DT_MOVEENT : | |
4454 | case DT_MOVESZ : | |
4455 | case DT_INIT_ARRAYSZ: | |
4456 | case DT_FINI_ARRAYSZ: | |
4457 | if (do_dynamic) | |
f7a99963 NC |
4458 | { |
4459 | print_vma (entry->d_un.d_val, UNSIGNED); | |
4460 | printf (" (bytes)\n"); | |
4461 | } | |
252b5132 RH |
4462 | break; |
4463 | ||
4464 | case DT_VERDEFNUM: | |
4465 | case DT_VERNEEDNUM: | |
4466 | case DT_RELACOUNT: | |
4467 | case DT_RELCOUNT: | |
4468 | if (do_dynamic) | |
f7a99963 NC |
4469 | { |
4470 | print_vma (entry->d_un.d_val, UNSIGNED); | |
4471 | putchar ('\n'); | |
4472 | } | |
252b5132 RH |
4473 | break; |
4474 | ||
4475 | case DT_SYMINSZ: | |
4476 | case DT_SYMINENT: | |
4477 | case DT_SYMINFO: | |
4478 | case DT_USED: | |
4479 | case DT_INIT_ARRAY: | |
4480 | case DT_FINI_ARRAY: | |
4481 | if (do_dynamic) | |
4482 | { | |
4483 | if (dynamic_strings != NULL && entry->d_tag == DT_USED) | |
4484 | { | |
4485 | char * name; | |
4486 | ||
4487 | name = dynamic_strings + entry->d_un.d_val; | |
4488 | ||
4489 | if (* name) | |
4490 | { | |
4491 | printf (_("Not needed object: [%s]\n"), name); | |
4492 | break; | |
4493 | } | |
4494 | } | |
103f02d3 | 4495 | |
f7a99963 NC |
4496 | print_vma (entry->d_un.d_val, PREFIX_HEX); |
4497 | putchar ('\n'); | |
252b5132 RH |
4498 | } |
4499 | break; | |
4500 | ||
4501 | case DT_BIND_NOW: | |
4502 | /* The value of this entry is ignored. */ | |
4503 | break; | |
103f02d3 | 4504 | |
252b5132 RH |
4505 | default: |
4506 | if ((entry->d_tag >= DT_VERSYM) && (entry->d_tag <= DT_VERNEEDNUM)) | |
4507 | version_info [DT_VERSIONTAGIDX (entry->d_tag)] = | |
4508 | entry->d_un.d_val; | |
4509 | ||
4510 | if (do_dynamic) | |
4511 | { | |
4512 | switch (elf_header.e_machine) | |
4513 | { | |
4514 | case EM_MIPS: | |
4fe85591 | 4515 | case EM_MIPS_RS3_LE: |
252b5132 RH |
4516 | dynamic_segment_mips_val (entry); |
4517 | break; | |
103f02d3 UD |
4518 | case EM_PARISC: |
4519 | dynamic_segment_parisc_val (entry); | |
4520 | break; | |
252b5132 | 4521 | default: |
f7a99963 NC |
4522 | print_vma (entry->d_un.d_val, PREFIX_HEX); |
4523 | putchar ('\n'); | |
252b5132 RH |
4524 | } |
4525 | } | |
4526 | break; | |
4527 | } | |
4528 | } | |
4529 | ||
4530 | return 1; | |
4531 | } | |
4532 | ||
4533 | static char * | |
4534 | get_ver_flags (flags) | |
4535 | unsigned int flags; | |
4536 | { | |
4537 | static char buff [32]; | |
4538 | ||
4539 | buff[0] = 0; | |
4540 | ||
4541 | if (flags == 0) | |
4542 | return _("none"); | |
4543 | ||
4544 | if (flags & VER_FLG_BASE) | |
4545 | strcat (buff, "BASE "); | |
4546 | ||
4547 | if (flags & VER_FLG_WEAK) | |
4548 | { | |
4549 | if (flags & VER_FLG_BASE) | |
4550 | strcat (buff, "| "); | |
4551 | ||
4552 | strcat (buff, "WEAK "); | |
4553 | } | |
4554 | ||
4555 | if (flags & ~(VER_FLG_BASE | VER_FLG_WEAK)) | |
4556 | strcat (buff, "| <unknown>"); | |
4557 | ||
4558 | return buff; | |
4559 | } | |
4560 | ||
4561 | /* Display the contents of the version sections. */ | |
4562 | static int | |
4563 | process_version_sections (file) | |
4564 | FILE * file; | |
4565 | { | |
4566 | Elf32_Internal_Shdr * section; | |
4567 | unsigned i; | |
4568 | int found = 0; | |
4569 | ||
4570 | if (! do_version) | |
4571 | return 1; | |
4572 | ||
4573 | for (i = 0, section = section_headers; | |
4574 | i < elf_header.e_shnum; | |
4575 | i++, section ++) | |
4576 | { | |
4577 | switch (section->sh_type) | |
4578 | { | |
4579 | case SHT_GNU_verdef: | |
4580 | { | |
4581 | Elf_External_Verdef * edefs; | |
4582 | unsigned int idx; | |
4583 | unsigned int cnt; | |
4584 | ||
4585 | found = 1; | |
4586 | ||
4587 | printf | |
4588 | (_("\nVersion definition section '%s' contains %ld entries:\n"), | |
4589 | SECTION_NAME (section), section->sh_info); | |
4590 | ||
4591 | printf (_(" Addr: 0x")); | |
4592 | printf_vma (section->sh_addr); | |
4593 | printf (_(" Offset: %#08lx Link: %lx (%s)\n"), | |
1b228002 | 4594 | (unsigned long) section->sh_offset, section->sh_link, |
252b5132 RH |
4595 | SECTION_NAME (section_headers + section->sh_link)); |
4596 | ||
a6e9f9df AM |
4597 | edefs = ((Elf_External_Verdef *) |
4598 | get_data (NULL, file, section->sh_offset, | |
4599 | section->sh_size, | |
4600 | _("version definition section"))); | |
4601 | if (!edefs) | |
4602 | break; | |
252b5132 RH |
4603 | |
4604 | for (idx = cnt = 0; cnt < section->sh_info; ++ cnt) | |
4605 | { | |
4606 | char * vstart; | |
4607 | Elf_External_Verdef * edef; | |
4608 | Elf_Internal_Verdef ent; | |
4609 | Elf_External_Verdaux * eaux; | |
4610 | Elf_Internal_Verdaux aux; | |
4611 | int j; | |
4612 | int isum; | |
103f02d3 | 4613 | |
252b5132 RH |
4614 | vstart = ((char *) edefs) + idx; |
4615 | ||
4616 | edef = (Elf_External_Verdef *) vstart; | |
4617 | ||
4618 | ent.vd_version = BYTE_GET (edef->vd_version); | |
4619 | ent.vd_flags = BYTE_GET (edef->vd_flags); | |
4620 | ent.vd_ndx = BYTE_GET (edef->vd_ndx); | |
4621 | ent.vd_cnt = BYTE_GET (edef->vd_cnt); | |
4622 | ent.vd_hash = BYTE_GET (edef->vd_hash); | |
4623 | ent.vd_aux = BYTE_GET (edef->vd_aux); | |
4624 | ent.vd_next = BYTE_GET (edef->vd_next); | |
4625 | ||
4626 | printf (_(" %#06x: Rev: %d Flags: %s"), | |
4627 | idx, ent.vd_version, get_ver_flags (ent.vd_flags)); | |
4628 | ||
4629 | printf (_(" Index: %d Cnt: %d "), | |
4630 | ent.vd_ndx, ent.vd_cnt); | |
4631 | ||
4632 | vstart += ent.vd_aux; | |
4633 | ||
4634 | eaux = (Elf_External_Verdaux *) vstart; | |
4635 | ||
4636 | aux.vda_name = BYTE_GET (eaux->vda_name); | |
4637 | aux.vda_next = BYTE_GET (eaux->vda_next); | |
4638 | ||
4639 | if (dynamic_strings) | |
4640 | printf (_("Name: %s\n"), dynamic_strings + aux.vda_name); | |
4641 | else | |
4642 | printf (_("Name index: %ld\n"), aux.vda_name); | |
4643 | ||
4644 | isum = idx + ent.vd_aux; | |
4645 | ||
4646 | for (j = 1; j < ent.vd_cnt; j ++) | |
4647 | { | |
4648 | isum += aux.vda_next; | |
4649 | vstart += aux.vda_next; | |
4650 | ||
4651 | eaux = (Elf_External_Verdaux *) vstart; | |
4652 | ||
4653 | aux.vda_name = BYTE_GET (eaux->vda_name); | |
4654 | aux.vda_next = BYTE_GET (eaux->vda_next); | |
4655 | ||
4656 | if (dynamic_strings) | |
4657 | printf (_(" %#06x: Parent %d: %s\n"), | |
4658 | isum, j, dynamic_strings + aux.vda_name); | |
4659 | else | |
4660 | printf (_(" %#06x: Parent %d, name index: %ld\n"), | |
4661 | isum, j, aux.vda_name); | |
4662 | } | |
4663 | ||
4664 | idx += ent.vd_next; | |
4665 | } | |
4666 | ||
4667 | free (edefs); | |
4668 | } | |
4669 | break; | |
103f02d3 | 4670 | |
252b5132 RH |
4671 | case SHT_GNU_verneed: |
4672 | { | |
4673 | Elf_External_Verneed * eneed; | |
4674 | unsigned int idx; | |
4675 | unsigned int cnt; | |
4676 | ||
4677 | found = 1; | |
4678 | ||
4679 | printf (_("\nVersion needs section '%s' contains %ld entries:\n"), | |
4680 | SECTION_NAME (section), section->sh_info); | |
4681 | ||
4682 | printf (_(" Addr: 0x")); | |
4683 | printf_vma (section->sh_addr); | |
4684 | printf (_(" Offset: %#08lx Link to section: %ld (%s)\n"), | |
1b228002 | 4685 | (unsigned long) section->sh_offset, section->sh_link, |
252b5132 RH |
4686 | SECTION_NAME (section_headers + section->sh_link)); |
4687 | ||
a6e9f9df AM |
4688 | eneed = ((Elf_External_Verneed *) |
4689 | get_data (NULL, file, section->sh_offset, | |
4690 | section->sh_size, _("version need section"))); | |
4691 | if (!eneed) | |
4692 | break; | |
252b5132 RH |
4693 | |
4694 | for (idx = cnt = 0; cnt < section->sh_info; ++cnt) | |
4695 | { | |
4696 | Elf_External_Verneed * entry; | |
4697 | Elf_Internal_Verneed ent; | |
4698 | int j; | |
4699 | int isum; | |
4700 | char * vstart; | |
4701 | ||
4702 | vstart = ((char *) eneed) + idx; | |
4703 | ||
4704 | entry = (Elf_External_Verneed *) vstart; | |
4705 | ||
4706 | ent.vn_version = BYTE_GET (entry->vn_version); | |
4707 | ent.vn_cnt = BYTE_GET (entry->vn_cnt); | |
4708 | ent.vn_file = BYTE_GET (entry->vn_file); | |
4709 | ent.vn_aux = BYTE_GET (entry->vn_aux); | |
4710 | ent.vn_next = BYTE_GET (entry->vn_next); | |
4711 | ||
4712 | printf (_(" %#06x: Version: %d"), idx, ent.vn_version); | |
4713 | ||
4714 | if (dynamic_strings) | |
4715 | printf (_(" File: %s"), dynamic_strings + ent.vn_file); | |
4716 | else | |
4717 | printf (_(" File: %lx"), ent.vn_file); | |
4718 | ||
4719 | printf (_(" Cnt: %d\n"), ent.vn_cnt); | |
4720 | ||
4721 | vstart += ent.vn_aux; | |
4722 | ||
4723 | for (j = 0, isum = idx + ent.vn_aux; j < ent.vn_cnt; ++j) | |
4724 | { | |
4725 | Elf_External_Vernaux * eaux; | |
4726 | Elf_Internal_Vernaux aux; | |
4727 | ||
4728 | eaux = (Elf_External_Vernaux *) vstart; | |
4729 | ||
4730 | aux.vna_hash = BYTE_GET (eaux->vna_hash); | |
4731 | aux.vna_flags = BYTE_GET (eaux->vna_flags); | |
4732 | aux.vna_other = BYTE_GET (eaux->vna_other); | |
4733 | aux.vna_name = BYTE_GET (eaux->vna_name); | |
4734 | aux.vna_next = BYTE_GET (eaux->vna_next); | |
4735 | ||
4736 | if (dynamic_strings) | |
4737 | printf (_(" %#06x: Name: %s"), | |
4738 | isum, dynamic_strings + aux.vna_name); | |
4739 | else | |
4740 | printf (_(" %#06x: Name index: %lx"), | |
4741 | isum, aux.vna_name); | |
4742 | ||
4743 | printf (_(" Flags: %s Version: %d\n"), | |
4744 | get_ver_flags (aux.vna_flags), aux.vna_other); | |
4745 | ||
4746 | isum += aux.vna_next; | |
4747 | vstart += aux.vna_next; | |
4748 | } | |
4749 | ||
4750 | idx += ent.vn_next; | |
4751 | } | |
103f02d3 | 4752 | |
252b5132 RH |
4753 | free (eneed); |
4754 | } | |
4755 | break; | |
4756 | ||
4757 | case SHT_GNU_versym: | |
4758 | { | |
4759 | Elf32_Internal_Shdr * link_section; | |
261a45ad NC |
4760 | int total; |
4761 | int cnt; | |
4762 | unsigned char * edata; | |
4763 | unsigned short * data; | |
4764 | char * strtab; | |
4765 | Elf_Internal_Sym * symbols; | |
252b5132 RH |
4766 | Elf32_Internal_Shdr * string_sec; |
4767 | ||
4768 | link_section = section_headers + section->sh_link; | |
4769 | total = section->sh_size / section->sh_entsize; | |
4770 | ||
4771 | found = 1; | |
4772 | ||
9ea033b2 NC |
4773 | symbols = GET_ELF_SYMBOLS (file, link_section->sh_offset, |
4774 | link_section->sh_size / link_section->sh_entsize); | |
252b5132 RH |
4775 | |
4776 | string_sec = section_headers + link_section->sh_link; | |
4777 | ||
a6e9f9df AM |
4778 | strtab = (char *) get_data (NULL, file, string_sec->sh_offset, |
4779 | string_sec->sh_size, | |
4780 | _("version string table")); | |
4781 | if (!strtab) | |
4782 | break; | |
252b5132 RH |
4783 | |
4784 | printf (_("\nVersion symbols section '%s' contains %d entries:\n"), | |
4785 | SECTION_NAME (section), total); | |
4786 | ||
4787 | printf (_(" Addr: ")); | |
4788 | printf_vma (section->sh_addr); | |
4789 | printf (_(" Offset: %#08lx Link: %lx (%s)\n"), | |
1b228002 | 4790 | (unsigned long) section->sh_offset, section->sh_link, |
252b5132 RH |
4791 | SECTION_NAME (link_section)); |
4792 | ||
a6e9f9df AM |
4793 | edata = |
4794 | ((unsigned char *) | |
4795 | get_data (NULL, file, | |
4796 | version_info[DT_VERSIONTAGIDX (DT_VERSYM)] - loadaddr, | |
4797 | total * sizeof (short), _("version symbol data"))); | |
4798 | if (!edata) | |
4799 | { | |
4800 | free (strtab); | |
4801 | break; | |
4802 | } | |
252b5132 RH |
4803 | |
4804 | data = (unsigned short *) malloc (total * sizeof (short)); | |
4805 | ||
4806 | for (cnt = total; cnt --;) | |
4807 | data [cnt] = byte_get (edata + cnt * sizeof (short), | |
4808 | sizeof (short)); | |
4809 | ||
4810 | free (edata); | |
4811 | ||
4812 | for (cnt = 0; cnt < total; cnt += 4) | |
4813 | { | |
4814 | int j, nn; | |
00d93f34 | 4815 | int check_def, check_need; |
f3485b74 | 4816 | char * name; |
252b5132 RH |
4817 | |
4818 | printf (" %03x:", cnt); | |
4819 | ||
4820 | for (j = 0; (j < 4) && (cnt + j) < total; ++j) | |
4821 | switch (data [cnt + j]) | |
4822 | { | |
4823 | case 0: | |
4824 | fputs (_(" 0 (*local*) "), stdout); | |
4825 | break; | |
4826 | ||
4827 | case 1: | |
4828 | fputs (_(" 1 (*global*) "), stdout); | |
4829 | break; | |
4830 | ||
4831 | default: | |
4832 | nn = printf ("%4x%c", data [cnt + j] & 0x7fff, | |
4833 | data [cnt + j] & 0x8000 ? 'h' : ' '); | |
4834 | ||
00d93f34 JJ |
4835 | check_def = 1; |
4836 | check_need = 1; | |
4837 | if (symbols [cnt + j].st_shndx >= SHN_LORESERVE | |
4838 | || section_headers[symbols [cnt + j].st_shndx].sh_type | |
4839 | != SHT_NOBITS) | |
252b5132 | 4840 | { |
00d93f34 JJ |
4841 | if (symbols [cnt + j].st_shndx == SHN_UNDEF) |
4842 | check_def = 0; | |
4843 | else | |
4844 | check_need = 0; | |
252b5132 | 4845 | } |
00d93f34 JJ |
4846 | |
4847 | if (check_need | |
4848 | && version_info [DT_VERSIONTAGIDX (DT_VERNEED)]) | |
252b5132 RH |
4849 | { |
4850 | Elf_Internal_Verneed ivn; | |
4851 | unsigned long offset; | |
4852 | ||
4853 | offset = version_info [DT_VERSIONTAGIDX (DT_VERNEED)] | |
4854 | - loadaddr; | |
4855 | ||
4856 | do | |
4857 | { | |
dd27201e | 4858 | Elf_Internal_Vernaux ivna; |
252b5132 RH |
4859 | Elf_External_Verneed evn; |
4860 | Elf_External_Vernaux evna; | |
dd27201e | 4861 | unsigned long a_off; |
252b5132 | 4862 | |
a6e9f9df AM |
4863 | get_data (&evn, file, offset, sizeof (evn), |
4864 | _("version need")); | |
252b5132 RH |
4865 | |
4866 | ivn.vn_aux = BYTE_GET (evn.vn_aux); | |
4867 | ivn.vn_next = BYTE_GET (evn.vn_next); | |
4868 | ||
4869 | a_off = offset + ivn.vn_aux; | |
4870 | ||
4871 | do | |
4872 | { | |
a6e9f9df AM |
4873 | get_data (&evna, file, a_off, sizeof (evna), |
4874 | _("version need aux (2)")); | |
252b5132 RH |
4875 | |
4876 | ivna.vna_next = BYTE_GET (evna.vna_next); | |
4877 | ivna.vna_other = BYTE_GET (evna.vna_other); | |
4878 | ||
4879 | a_off += ivna.vna_next; | |
4880 | } | |
4881 | while (ivna.vna_other != data [cnt + j] | |
4882 | && ivna.vna_next != 0); | |
4883 | ||
4884 | if (ivna.vna_other == data [cnt + j]) | |
4885 | { | |
4886 | ivna.vna_name = BYTE_GET (evna.vna_name); | |
4887 | ||
16062207 | 4888 | name = strtab + ivna.vna_name; |
252b5132 | 4889 | nn += printf ("(%s%-*s", |
16062207 ILT |
4890 | name, |
4891 | 12 - (int) strlen (name), | |
252b5132 | 4892 | ")"); |
00d93f34 | 4893 | check_def = 0; |
252b5132 RH |
4894 | break; |
4895 | } | |
4896 | ||
4897 | offset += ivn.vn_next; | |
4898 | } | |
4899 | while (ivn.vn_next); | |
4900 | } | |
00d93f34 JJ |
4901 | |
4902 | if (check_def && data [cnt + j] != 0x8001 | |
4903 | && version_info [DT_VERSIONTAGIDX (DT_VERDEF)]) | |
252b5132 RH |
4904 | { |
4905 | Elf_Internal_Verdef ivd; | |
4906 | Elf_External_Verdef evd; | |
4907 | unsigned long offset; | |
4908 | ||
4909 | offset = version_info | |
4910 | [DT_VERSIONTAGIDX (DT_VERDEF)] - loadaddr; | |
4911 | ||
4912 | do | |
4913 | { | |
a6e9f9df AM |
4914 | get_data (&evd, file, offset, sizeof (evd), |
4915 | _("version def")); | |
252b5132 RH |
4916 | |
4917 | ivd.vd_next = BYTE_GET (evd.vd_next); | |
4918 | ivd.vd_ndx = BYTE_GET (evd.vd_ndx); | |
4919 | ||
4920 | offset += ivd.vd_next; | |
4921 | } | |
4922 | while (ivd.vd_ndx != (data [cnt + j] & 0x7fff) | |
4923 | && ivd.vd_next != 0); | |
4924 | ||
4925 | if (ivd.vd_ndx == (data [cnt + j] & 0x7fff)) | |
4926 | { | |
4927 | Elf_External_Verdaux evda; | |
4928 | Elf_Internal_Verdaux ivda; | |
4929 | ||
4930 | ivd.vd_aux = BYTE_GET (evd.vd_aux); | |
4931 | ||
a6e9f9df AM |
4932 | get_data (&evda, file, |
4933 | offset - ivd.vd_next + ivd.vd_aux, | |
4934 | sizeof (evda), _("version def aux")); | |
252b5132 RH |
4935 | |
4936 | ivda.vda_name = BYTE_GET (evda.vda_name); | |
4937 | ||
16062207 | 4938 | name = strtab + ivda.vda_name; |
252b5132 | 4939 | nn += printf ("(%s%-*s", |
16062207 ILT |
4940 | name, |
4941 | 12 - (int) strlen (name), | |
252b5132 RH |
4942 | ")"); |
4943 | } | |
4944 | } | |
4945 | ||
4946 | if (nn < 18) | |
4947 | printf ("%*c", 18 - nn, ' '); | |
4948 | } | |
4949 | ||
4950 | putchar ('\n'); | |
4951 | } | |
4952 | ||
4953 | free (data); | |
4954 | free (strtab); | |
4955 | free (symbols); | |
4956 | } | |
4957 | break; | |
103f02d3 | 4958 | |
252b5132 RH |
4959 | default: |
4960 | break; | |
4961 | } | |
4962 | } | |
4963 | ||
4964 | if (! found) | |
4965 | printf (_("\nNo version information found in this file.\n")); | |
4966 | ||
4967 | return 1; | |
4968 | } | |
4969 | ||
d1133906 | 4970 | static const char * |
252b5132 RH |
4971 | get_symbol_binding (binding) |
4972 | unsigned int binding; | |
4973 | { | |
4974 | static char buff [32]; | |
4975 | ||
4976 | switch (binding) | |
4977 | { | |
103f02d3 UD |
4978 | case STB_LOCAL: return "LOCAL"; |
4979 | case STB_GLOBAL: return "GLOBAL"; | |
4980 | case STB_WEAK: return "WEAK"; | |
252b5132 RH |
4981 | default: |
4982 | if (binding >= STB_LOPROC && binding <= STB_HIPROC) | |
4983 | sprintf (buff, _("<processor specific>: %d"), binding); | |
4984 | else if (binding >= STB_LOOS && binding <= STB_HIOS) | |
4985 | sprintf (buff, _("<OS specific>: %d"), binding); | |
4986 | else | |
4987 | sprintf (buff, _("<unknown>: %d"), binding); | |
4988 | return buff; | |
4989 | } | |
4990 | } | |
4991 | ||
d1133906 | 4992 | static const char * |
252b5132 RH |
4993 | get_symbol_type (type) |
4994 | unsigned int type; | |
4995 | { | |
4996 | static char buff [32]; | |
4997 | ||
4998 | switch (type) | |
4999 | { | |
103f02d3 UD |
5000 | case STT_NOTYPE: return "NOTYPE"; |
5001 | case STT_OBJECT: return "OBJECT"; | |
5002 | case STT_FUNC: return "FUNC"; | |
5003 | case STT_SECTION: return "SECTION"; | |
5004 | case STT_FILE: return "FILE"; | |
d1133906 | 5005 | case STT_COMMON: return "COMMON"; |
252b5132 RH |
5006 | default: |
5007 | if (type >= STT_LOPROC && type <= STT_HIPROC) | |
df75f1af NC |
5008 | { |
5009 | if (elf_header.e_machine == EM_ARM && type == STT_ARM_TFUNC) | |
103f02d3 UD |
5010 | return "THUMB_FUNC"; |
5011 | ||
351b4b40 | 5012 | if (elf_header.e_machine == EM_SPARCV9 && type == STT_REGISTER) |
103f02d3 UD |
5013 | return "REGISTER"; |
5014 | ||
5015 | if (elf_header.e_machine == EM_PARISC && type == STT_PARISC_MILLI) | |
5016 | return "PARISC_MILLI"; | |
5017 | ||
df75f1af NC |
5018 | sprintf (buff, _("<processor specific>: %d"), type); |
5019 | } | |
252b5132 | 5020 | else if (type >= STT_LOOS && type <= STT_HIOS) |
103f02d3 UD |
5021 | { |
5022 | if (elf_header.e_machine == EM_PARISC) | |
5023 | { | |
5024 | if (type == STT_HP_OPAQUE) | |
5025 | return "HP_OPAQUE"; | |
5026 | if (type == STT_HP_STUB) | |
5027 | return "HP_STUB"; | |
5028 | } | |
5029 | ||
5030 | sprintf (buff, _("<OS specific>: %d"), type); | |
5031 | } | |
252b5132 RH |
5032 | else |
5033 | sprintf (buff, _("<unknown>: %d"), type); | |
5034 | return buff; | |
5035 | } | |
5036 | } | |
5037 | ||
d1133906 NC |
5038 | static const char * |
5039 | get_symbol_visibility (visibility) | |
5040 | unsigned int visibility; | |
5041 | { | |
5042 | switch (visibility) | |
5043 | { | |
5044 | case STV_DEFAULT: return "DEFAULT"; | |
5045 | case STV_INTERNAL: return "INTERNAL"; | |
5046 | case STV_HIDDEN: return "HIDDEN"; | |
5047 | case STV_PROTECTED: return "PROTECTED"; | |
5048 | default: abort (); | |
5049 | } | |
5050 | } | |
5051 | ||
5052 | static const char * | |
252b5132 RH |
5053 | get_symbol_index_type (type) |
5054 | unsigned int type; | |
5055 | { | |
5056 | switch (type) | |
5057 | { | |
5058 | case SHN_UNDEF: return "UND"; | |
5059 | case SHN_ABS: return "ABS"; | |
5060 | case SHN_COMMON: return "COM"; | |
5061 | default: | |
5062 | if (type >= SHN_LOPROC && type <= SHN_HIPROC) | |
5063 | return "PRC"; | |
5064 | else if (type >= SHN_LORESERVE && type <= SHN_HIRESERVE) | |
5065 | return "RSV"; | |
5066 | else if (type >= SHN_LOOS && type <= SHN_HIOS) | |
5067 | return "OS "; | |
5068 | else | |
5069 | { | |
5070 | static char buff [32]; | |
5071 | ||
5072 | sprintf (buff, "%3d", type); | |
5073 | return buff; | |
5074 | } | |
5075 | } | |
5076 | } | |
5077 | ||
252b5132 RH |
5078 | static int * |
5079 | get_dynamic_data (file, number) | |
5080 | FILE * file; | |
5081 | unsigned int number; | |
5082 | { | |
3c9f43b1 | 5083 | unsigned char * e_data; |
252b5132 RH |
5084 | int * i_data; |
5085 | ||
3c9f43b1 | 5086 | e_data = (unsigned char *) malloc (number * 4); |
252b5132 RH |
5087 | |
5088 | if (e_data == NULL) | |
5089 | { | |
5090 | error (_("Out of memory\n")); | |
5091 | return NULL; | |
5092 | } | |
5093 | ||
5094 | if (fread (e_data, 4, number, file) != number) | |
5095 | { | |
5096 | error (_("Unable to read in dynamic data\n")); | |
5097 | return NULL; | |
5098 | } | |
5099 | ||
5100 | i_data = (int *) malloc (number * sizeof (* i_data)); | |
5101 | ||
5102 | if (i_data == NULL) | |
5103 | { | |
5104 | error (_("Out of memory\n")); | |
5105 | free (e_data); | |
5106 | return NULL; | |
5107 | } | |
5108 | ||
5109 | while (number--) | |
5110 | i_data [number] = byte_get (e_data + number * 4, 4); | |
5111 | ||
5112 | free (e_data); | |
5113 | ||
5114 | return i_data; | |
5115 | } | |
5116 | ||
e3c8793a | 5117 | /* Dump the symbol table. */ |
252b5132 RH |
5118 | static int |
5119 | process_symbol_table (file) | |
5120 | FILE * file; | |
5121 | { | |
5122 | Elf32_Internal_Shdr * section; | |
3c9f43b1 AM |
5123 | unsigned char nb [4]; |
5124 | unsigned char nc [4]; | |
b4c96d0d | 5125 | int nbuckets = 0; |
5e220199 | 5126 | int nchains = 0; |
252b5132 RH |
5127 | int * buckets = NULL; |
5128 | int * chains = NULL; | |
5129 | ||
5130 | if (! do_syms && !do_histogram) | |
5131 | return 1; | |
5132 | ||
5133 | if (dynamic_info[DT_HASH] && ((do_using_dynamic && dynamic_strings != NULL) | |
5134 | || do_histogram)) | |
5135 | { | |
5136 | if (fseek (file, dynamic_info[DT_HASH] - loadaddr, SEEK_SET)) | |
5137 | { | |
5138 | error (_("Unable to seek to start of dynamic information")); | |
5139 | return 0; | |
5140 | } | |
5141 | ||
5142 | if (fread (nb, sizeof (nb), 1, file) != 1) | |
5143 | { | |
5144 | error (_("Failed to read in number of buckets\n")); | |
5145 | return 0; | |
5146 | } | |
5147 | ||
5148 | if (fread (nc, sizeof (nc), 1, file) != 1) | |
5149 | { | |
5150 | error (_("Failed to read in number of chains\n")); | |
5151 | return 0; | |
5152 | } | |
5153 | ||
5154 | nbuckets = byte_get (nb, 4); | |
5155 | nchains = byte_get (nc, 4); | |
5156 | ||
5157 | buckets = get_dynamic_data (file, nbuckets); | |
5158 | chains = get_dynamic_data (file, nchains); | |
5159 | ||
5160 | if (buckets == NULL || chains == NULL) | |
5161 | return 0; | |
5162 | } | |
5163 | ||
5164 | if (do_syms | |
5165 | && dynamic_info[DT_HASH] && do_using_dynamic && dynamic_strings != NULL) | |
5166 | { | |
5167 | int hn; | |
5168 | int si; | |
5169 | ||
5170 | printf (_("\nSymbol table for image:\n")); | |
f7a99963 | 5171 | if (is_32bit_elf) |
ca47b30c | 5172 | printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n")); |
f7a99963 | 5173 | else |
ca47b30c | 5174 | printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n")); |
252b5132 RH |
5175 | |
5176 | for (hn = 0; hn < nbuckets; hn++) | |
5177 | { | |
5178 | if (! buckets [hn]) | |
5179 | continue; | |
5180 | ||
f7a99963 | 5181 | for (si = buckets [hn]; si < nchains && si > 0; si = chains [si]) |
252b5132 RH |
5182 | { |
5183 | Elf_Internal_Sym * psym; | |
5184 | ||
5185 | psym = dynamic_symbols + si; | |
5186 | ||
f7a99963 NC |
5187 | printf (" %3d %3d: ", si, hn); |
5188 | print_vma (psym->st_value, LONG_HEX); | |
5189 | putchar (' ' ); | |
d1133906 | 5190 | print_vma (psym->st_size, DEC_5); |
76da6bbe | 5191 | |
d1133906 NC |
5192 | printf (" %6s", get_symbol_type (ELF_ST_TYPE (psym->st_info))); |
5193 | printf (" %6s", get_symbol_binding (ELF_ST_BIND (psym->st_info))); | |
5194 | printf (" %3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym->st_other))); | |
d1133906 | 5195 | printf (" %3.3s", get_symbol_index_type (psym->st_shndx)); |
252b5132 RH |
5196 | printf (" %s\n", dynamic_strings + psym->st_name); |
5197 | } | |
5198 | } | |
5199 | } | |
5200 | else if (do_syms && !do_using_dynamic) | |
5201 | { | |
5202 | unsigned int i; | |
5203 | ||
5204 | for (i = 0, section = section_headers; | |
5205 | i < elf_header.e_shnum; | |
5206 | i++, section++) | |
5207 | { | |
5208 | unsigned int si; | |
5209 | char * strtab; | |
5210 | Elf_Internal_Sym * symtab; | |
5211 | Elf_Internal_Sym * psym; | |
5212 | ||
5213 | ||
5214 | if ( section->sh_type != SHT_SYMTAB | |
5215 | && section->sh_type != SHT_DYNSYM) | |
5216 | continue; | |
5217 | ||
5218 | printf (_("\nSymbol table '%s' contains %lu entries:\n"), | |
5219 | SECTION_NAME (section), | |
5220 | (unsigned long) (section->sh_size / section->sh_entsize)); | |
f7a99963 | 5221 | if (is_32bit_elf) |
ca47b30c | 5222 | printf (_(" Num: Value Size Type Bind Vis Ndx Name\n")); |
f7a99963 | 5223 | else |
ca47b30c | 5224 | printf (_(" Num: Value Size Type Bind Vis Ndx Name\n")); |
252b5132 | 5225 | |
9ea033b2 | 5226 | symtab = GET_ELF_SYMBOLS (file, section->sh_offset, |
252b5132 RH |
5227 | section->sh_size / section->sh_entsize); |
5228 | if (symtab == NULL) | |
5229 | continue; | |
5230 | ||
5231 | if (section->sh_link == elf_header.e_shstrndx) | |
5232 | strtab = string_table; | |
5233 | else | |
5234 | { | |
5235 | Elf32_Internal_Shdr * string_sec; | |
5236 | ||
5237 | string_sec = section_headers + section->sh_link; | |
5238 | ||
a6e9f9df AM |
5239 | strtab = (char *) get_data (NULL, file, string_sec->sh_offset, |
5240 | string_sec->sh_size, | |
5241 | _("string table")); | |
252b5132 RH |
5242 | } |
5243 | ||
5244 | for (si = 0, psym = symtab; | |
5245 | si < section->sh_size / section->sh_entsize; | |
5246 | si ++, psym ++) | |
5247 | { | |
5e220199 | 5248 | printf ("%6d: ", si); |
f7a99963 NC |
5249 | print_vma (psym->st_value, LONG_HEX); |
5250 | putchar (' '); | |
5251 | print_vma (psym->st_size, DEC_5); | |
d1133906 NC |
5252 | printf (" %-7s", get_symbol_type (ELF_ST_TYPE (psym->st_info))); |
5253 | printf (" %-6s", get_symbol_binding (ELF_ST_BIND (psym->st_info))); | |
5254 | printf (" %-3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym->st_other))); | |
d1133906 | 5255 | printf (" %4s", get_symbol_index_type (psym->st_shndx)); |
252b5132 RH |
5256 | printf (" %s", strtab + psym->st_name); |
5257 | ||
5258 | if (section->sh_type == SHT_DYNSYM && | |
5259 | version_info [DT_VERSIONTAGIDX (DT_VERSYM)] != 0) | |
5260 | { | |
5261 | unsigned char data[2]; | |
5262 | unsigned short vers_data; | |
5263 | unsigned long offset; | |
5264 | int is_nobits; | |
5265 | int check_def; | |
5266 | ||
5267 | offset = version_info [DT_VERSIONTAGIDX (DT_VERSYM)] | |
5268 | - loadaddr; | |
5269 | ||
a6e9f9df AM |
5270 | get_data (&data, file, offset + si * sizeof (vers_data), |
5271 | sizeof (data), _("version data")); | |
252b5132 RH |
5272 | |
5273 | vers_data = byte_get (data, 2); | |
5274 | ||
5275 | is_nobits = psym->st_shndx < SHN_LORESERVE ? | |
5276 | (section_headers [psym->st_shndx].sh_type == SHT_NOBITS) | |
5277 | : 0; | |
5278 | ||
5279 | check_def = (psym->st_shndx != SHN_UNDEF); | |
5280 | ||
5281 | if ((vers_data & 0x8000) || vers_data > 1) | |
5282 | { | |
00d93f34 JJ |
5283 | if (version_info [DT_VERSIONTAGIDX (DT_VERNEED)] |
5284 | && (is_nobits || ! check_def)) | |
252b5132 RH |
5285 | { |
5286 | Elf_External_Verneed evn; | |
5287 | Elf_Internal_Verneed ivn; | |
5288 | Elf_Internal_Vernaux ivna; | |
5289 | ||
5290 | /* We must test both. */ | |
5291 | offset = version_info | |
5292 | [DT_VERSIONTAGIDX (DT_VERNEED)] - loadaddr; | |
5293 | ||
252b5132 RH |
5294 | do |
5295 | { | |
5296 | unsigned long vna_off; | |
5297 | ||
a6e9f9df AM |
5298 | get_data (&evn, file, offset, sizeof (evn), |
5299 | _("version need")); | |
dd27201e L |
5300 | |
5301 | ivn.vn_aux = BYTE_GET (evn.vn_aux); | |
5302 | ivn.vn_next = BYTE_GET (evn.vn_next); | |
5303 | ||
252b5132 RH |
5304 | vna_off = offset + ivn.vn_aux; |
5305 | ||
5306 | do | |
5307 | { | |
5308 | Elf_External_Vernaux evna; | |
5309 | ||
a6e9f9df AM |
5310 | get_data (&evna, file, vna_off, |
5311 | sizeof (evna), | |
5312 | _("version need aux (3)")); | |
252b5132 RH |
5313 | |
5314 | ivna.vna_other = BYTE_GET (evna.vna_other); | |
5315 | ivna.vna_next = BYTE_GET (evna.vna_next); | |
5316 | ivna.vna_name = BYTE_GET (evna.vna_name); | |
5317 | ||
5318 | vna_off += ivna.vna_next; | |
5319 | } | |
5320 | while (ivna.vna_other != vers_data | |
5321 | && ivna.vna_next != 0); | |
5322 | ||
5323 | if (ivna.vna_other == vers_data) | |
5324 | break; | |
5325 | ||
5326 | offset += ivn.vn_next; | |
5327 | } | |
5328 | while (ivn.vn_next != 0); | |
5329 | ||
5330 | if (ivna.vna_other == vers_data) | |
5331 | { | |
5332 | printf ("@%s (%d)", | |
5333 | strtab + ivna.vna_name, ivna.vna_other); | |
5334 | check_def = 0; | |
5335 | } | |
5336 | else if (! is_nobits) | |
5337 | error (_("bad dynamic symbol")); | |
5338 | else | |
5339 | check_def = 1; | |
5340 | } | |
5341 | ||
5342 | if (check_def) | |
5343 | { | |
00d93f34 JJ |
5344 | if (vers_data != 0x8001 |
5345 | && version_info [DT_VERSIONTAGIDX (DT_VERDEF)]) | |
252b5132 RH |
5346 | { |
5347 | Elf_Internal_Verdef ivd; | |
5348 | Elf_Internal_Verdaux ivda; | |
5349 | Elf_External_Verdaux evda; | |
5350 | unsigned long offset; | |
5351 | ||
5352 | offset = | |
5353 | version_info [DT_VERSIONTAGIDX (DT_VERDEF)] | |
5354 | - loadaddr; | |
5355 | ||
5356 | do | |
5357 | { | |
5358 | Elf_External_Verdef evd; | |
5359 | ||
a6e9f9df AM |
5360 | get_data (&evd, file, offset, sizeof (evd), |
5361 | _("version def")); | |
252b5132 RH |
5362 | |
5363 | ivd.vd_ndx = BYTE_GET (evd.vd_ndx); | |
5364 | ivd.vd_aux = BYTE_GET (evd.vd_aux); | |
5365 | ivd.vd_next = BYTE_GET (evd.vd_next); | |
5366 | ||
5367 | offset += ivd.vd_next; | |
5368 | } | |
5369 | while (ivd.vd_ndx != (vers_data & 0x7fff) | |
5370 | && ivd.vd_next != 0); | |
5371 | ||
5372 | offset -= ivd.vd_next; | |
5373 | offset += ivd.vd_aux; | |
5374 | ||
a6e9f9df AM |
5375 | get_data (&evda, file, offset, sizeof (evda), |
5376 | _("version def aux")); | |
252b5132 RH |
5377 | |
5378 | ivda.vda_name = BYTE_GET (evda.vda_name); | |
5379 | ||
5380 | if (psym->st_name != ivda.vda_name) | |
5381 | printf ((vers_data & 0x8000) | |
5382 | ? "@%s" : "@@%s", | |
5383 | strtab + ivda.vda_name); | |
5384 | } | |
5385 | } | |
5386 | } | |
5387 | } | |
5388 | ||
5389 | putchar ('\n'); | |
5390 | } | |
5391 | ||
5392 | free (symtab); | |
5393 | if (strtab != string_table) | |
5394 | free (strtab); | |
5395 | } | |
5396 | } | |
5397 | else if (do_syms) | |
5398 | printf | |
5399 | (_("\nDynamic symbol information is not available for displaying symbols.\n")); | |
5400 | ||
5401 | if (do_histogram && buckets != NULL) | |
5402 | { | |
584da044 NC |
5403 | int * lengths; |
5404 | int * counts; | |
5405 | int hn; | |
5406 | int si; | |
5407 | int maxlength = 0; | |
5408 | int nzero_counts = 0; | |
5409 | int nsyms = 0; | |
252b5132 RH |
5410 | |
5411 | printf (_("\nHistogram for bucket list length (total of %d buckets):\n"), | |
5412 | nbuckets); | |
5413 | printf (_(" Length Number %% of total Coverage\n")); | |
5414 | ||
5415 | lengths = (int *) calloc (nbuckets, sizeof (int)); | |
5416 | if (lengths == NULL) | |
5417 | { | |
5418 | error (_("Out of memory")); | |
5419 | return 0; | |
5420 | } | |
5421 | for (hn = 0; hn < nbuckets; ++hn) | |
5422 | { | |
5423 | if (! buckets [hn]) | |
5424 | continue; | |
5425 | ||
f7a99963 | 5426 | for (si = buckets[hn]; si > 0 && si < nchains; si = chains[si]) |
252b5132 | 5427 | { |
f7a99963 | 5428 | ++ nsyms; |
252b5132 | 5429 | if (maxlength < ++lengths[hn]) |
f7a99963 | 5430 | ++ maxlength; |
252b5132 RH |
5431 | } |
5432 | } | |
5433 | ||
5434 | counts = (int *) calloc (maxlength + 1, sizeof (int)); | |
5435 | if (counts == NULL) | |
5436 | { | |
5437 | error (_("Out of memory")); | |
5438 | return 0; | |
5439 | } | |
5440 | ||
5441 | for (hn = 0; hn < nbuckets; ++hn) | |
30800947 | 5442 | ++ counts [lengths [hn]]; |
252b5132 | 5443 | |
103f02d3 | 5444 | if (nbuckets > 0) |
252b5132 | 5445 | { |
103f02d3 UD |
5446 | printf (" 0 %-10d (%5.1f%%)\n", |
5447 | counts[0], (counts[0] * 100.0) / nbuckets); | |
5448 | for (si = 1; si <= maxlength; ++si) | |
5449 | { | |
5450 | nzero_counts += counts[si] * si; | |
5451 | printf ("%7d %-10d (%5.1f%%) %5.1f%%\n", | |
5452 | si, counts[si], (counts[si] * 100.0) / nbuckets, | |
5453 | (nzero_counts * 100.0) / nsyms); | |
5454 | } | |
252b5132 RH |
5455 | } |
5456 | ||
5457 | free (counts); | |
5458 | free (lengths); | |
5459 | } | |
5460 | ||
5461 | if (buckets != NULL) | |
5462 | { | |
5463 | free (buckets); | |
5464 | free (chains); | |
5465 | } | |
5466 | ||
5467 | return 1; | |
5468 | } | |
5469 | ||
5470 | static int | |
5471 | process_syminfo (file) | |
b4c96d0d | 5472 | FILE * file ATTRIBUTE_UNUSED; |
252b5132 | 5473 | { |
b4c96d0d | 5474 | unsigned int i; |
252b5132 RH |
5475 | |
5476 | if (dynamic_syminfo == NULL | |
5477 | || !do_dynamic) | |
5478 | /* No syminfo, this is ok. */ | |
5479 | return 1; | |
5480 | ||
5481 | /* There better should be a dynamic symbol section. */ | |
5482 | if (dynamic_symbols == NULL || dynamic_strings == NULL) | |
5483 | return 0; | |
5484 | ||
5485 | if (dynamic_addr) | |
5486 | printf (_("\nDynamic info segment at offset 0x%lx contains %d entries:\n"), | |
5487 | dynamic_syminfo_offset, dynamic_syminfo_nent); | |
5488 | ||
5489 | printf (_(" Num: Name BoundTo Flags\n")); | |
5490 | for (i = 0; i < dynamic_syminfo_nent; ++i) | |
5491 | { | |
5492 | unsigned short int flags = dynamic_syminfo[i].si_flags; | |
5493 | ||
5494 | printf ("%4d: %-30s ", i, | |
5495 | dynamic_strings + dynamic_symbols[i].st_name); | |
5496 | ||
5497 | switch (dynamic_syminfo[i].si_boundto) | |
5498 | { | |
5499 | case SYMINFO_BT_SELF: | |
5500 | fputs ("SELF ", stdout); | |
5501 | break; | |
5502 | case SYMINFO_BT_PARENT: | |
5503 | fputs ("PARENT ", stdout); | |
5504 | break; | |
5505 | default: | |
5506 | if (dynamic_syminfo[i].si_boundto > 0 | |
5507 | && dynamic_syminfo[i].si_boundto < dynamic_size) | |
5508 | printf ("%-10s ", | |
5509 | dynamic_strings | |
5510 | + dynamic_segment[dynamic_syminfo[i].si_boundto].d_un.d_val); | |
5511 | else | |
5512 | printf ("%-10d ", dynamic_syminfo[i].si_boundto); | |
5513 | break; | |
5514 | } | |
5515 | ||
5516 | if (flags & SYMINFO_FLG_DIRECT) | |
5517 | printf (" DIRECT"); | |
5518 | if (flags & SYMINFO_FLG_PASSTHRU) | |
5519 | printf (" PASSTHRU"); | |
5520 | if (flags & SYMINFO_FLG_COPY) | |
5521 | printf (" COPY"); | |
5522 | if (flags & SYMINFO_FLG_LAZYLOAD) | |
5523 | printf (" LAZYLOAD"); | |
5524 | ||
5525 | puts (""); | |
5526 | } | |
5527 | ||
5528 | return 1; | |
5529 | } | |
5530 | ||
5531 | #ifdef SUPPORT_DISASSEMBLY | |
5532 | static void | |
5533 | disassemble_section (section, file) | |
5534 | Elf32_Internal_Shdr * section; | |
5535 | FILE * file; | |
5536 | { | |
5537 | printf (_("\nAssembly dump of section %s\n"), | |
5538 | SECTION_NAME (section)); | |
5539 | ||
5540 | /* XXX -- to be done --- XXX */ | |
5541 | ||
5542 | return 1; | |
5543 | } | |
5544 | #endif | |
5545 | ||
5546 | static int | |
5547 | dump_section (section, file) | |
5548 | Elf32_Internal_Shdr * section; | |
5549 | FILE * file; | |
5550 | { | |
9ea033b2 NC |
5551 | bfd_size_type bytes; |
5552 | bfd_vma addr; | |
252b5132 RH |
5553 | unsigned char * data; |
5554 | unsigned char * start; | |
5555 | ||
5556 | bytes = section->sh_size; | |
5557 | ||
5558 | if (bytes == 0) | |
5559 | { | |
5560 | printf (_("\nSection '%s' has no data to dump.\n"), | |
5561 | SECTION_NAME (section)); | |
5562 | return 0; | |
5563 | } | |
5564 | else | |
5565 | printf (_("\nHex dump of section '%s':\n"), SECTION_NAME (section)); | |
5566 | ||
5567 | addr = section->sh_addr; | |
5568 | ||
a6e9f9df AM |
5569 | start = (unsigned char *) get_data (NULL, file, section->sh_offset, bytes, |
5570 | _("section data")); | |
5571 | if (!start) | |
5572 | return 0; | |
252b5132 RH |
5573 | |
5574 | data = start; | |
5575 | ||
5576 | while (bytes) | |
5577 | { | |
5578 | int j; | |
5579 | int k; | |
5580 | int lbytes; | |
5581 | ||
5582 | lbytes = (bytes > 16 ? 16 : bytes); | |
5583 | ||
148d3c43 | 5584 | printf (" 0x%8.8lx ", (unsigned long) addr); |
252b5132 RH |
5585 | |
5586 | switch (elf_header.e_ident [EI_DATA]) | |
5587 | { | |
9ea033b2 | 5588 | default: |
252b5132 RH |
5589 | case ELFDATA2LSB: |
5590 | for (j = 15; j >= 0; j --) | |
5591 | { | |
5592 | if (j < lbytes) | |
5593 | printf ("%2.2x", data [j]); | |
5594 | else | |
5595 | printf (" "); | |
5596 | ||
5597 | if (!(j & 0x3)) | |
5598 | printf (" "); | |
5599 | } | |
5600 | break; | |
5601 | ||
5602 | case ELFDATA2MSB: | |
5603 | for (j = 0; j < 16; j++) | |
5604 | { | |
5605 | if (j < lbytes) | |
5606 | printf ("%2.2x", data [j]); | |
5607 | else | |
5608 | printf (" "); | |
5609 | ||
5610 | if ((j & 3) == 3) | |
5611 | printf (" "); | |
5612 | } | |
5613 | break; | |
5614 | } | |
5615 | ||
5616 | for (j = 0; j < lbytes; j++) | |
5617 | { | |
5618 | k = data [j]; | |
5619 | if (k >= ' ' && k < 0x80) | |
5620 | printf ("%c", k); | |
5621 | else | |
5622 | printf ("."); | |
5623 | } | |
5624 | ||
5625 | putchar ('\n'); | |
5626 | ||
5627 | data += lbytes; | |
5628 | addr += lbytes; | |
5629 | bytes -= lbytes; | |
5630 | } | |
5631 | ||
5632 | free (start); | |
5633 | ||
5634 | return 1; | |
5635 | } | |
5636 | ||
5637 | ||
5638 | static unsigned long int | |
5639 | read_leb128 (data, length_return, sign) | |
5640 | unsigned char * data; | |
5641 | int * length_return; | |
5642 | int sign; | |
5643 | { | |
5644 | unsigned long int result = 0; | |
5645 | unsigned int num_read = 0; | |
5646 | int shift = 0; | |
5647 | unsigned char byte; | |
5648 | ||
5649 | do | |
5650 | { | |
5651 | byte = * data ++; | |
5652 | num_read ++; | |
5653 | ||
5654 | result |= (byte & 0x7f) << shift; | |
5655 | ||
5656 | shift += 7; | |
5657 | ||
5658 | } | |
5659 | while (byte & 0x80); | |
5660 | ||
5661 | if (length_return != NULL) | |
5662 | * length_return = num_read; | |
5663 | ||
5664 | if (sign && (shift < 32) && (byte & 0x40)) | |
5665 | result |= -1 << shift; | |
5666 | ||
5667 | return result; | |
5668 | } | |
5669 | ||
5670 | typedef struct State_Machine_Registers | |
5671 | { | |
5672 | unsigned long address; | |
5673 | unsigned int file; | |
5674 | unsigned int line; | |
5675 | unsigned int column; | |
5676 | int is_stmt; | |
5677 | int basic_block; | |
5678 | int end_sequence; | |
5679 | /* This variable hold the number of the last entry seen | |
5680 | in the File Table. */ | |
5681 | unsigned int last_file_entry; | |
5682 | } SMR; | |
5683 | ||
5684 | static SMR state_machine_regs; | |
5685 | ||
5686 | static void | |
5687 | reset_state_machine (is_stmt) | |
5688 | int is_stmt; | |
5689 | { | |
5690 | state_machine_regs.address = 0; | |
5691 | state_machine_regs.file = 1; | |
5692 | state_machine_regs.line = 1; | |
5693 | state_machine_regs.column = 0; | |
5694 | state_machine_regs.is_stmt = is_stmt; | |
5695 | state_machine_regs.basic_block = 0; | |
5696 | state_machine_regs.end_sequence = 0; | |
5697 | state_machine_regs.last_file_entry = 0; | |
5698 | } | |
5699 | ||
5700 | /* Handled an extend line op. Returns true if this is the end | |
5701 | of sequence. */ | |
5702 | static int | |
3590ea00 | 5703 | process_extended_line_op (data, is_stmt, pointer_size) |
252b5132 RH |
5704 | unsigned char * data; |
5705 | int is_stmt; | |
3590ea00 | 5706 | int pointer_size; |
252b5132 RH |
5707 | { |
5708 | unsigned char op_code; | |
5709 | int bytes_read; | |
5710 | unsigned int len; | |
5711 | unsigned char * name; | |
5712 | unsigned long adr; | |
103f02d3 | 5713 | |
252b5132 RH |
5714 | len = read_leb128 (data, & bytes_read, 0); |
5715 | data += bytes_read; | |
5716 | ||
5717 | if (len == 0) | |
5718 | { | |
e5fb9629 | 5719 | warn (_("badly formed extended line op encountered!\n")); |
252b5132 RH |
5720 | return bytes_read; |
5721 | } | |
5722 | ||
5723 | len += bytes_read; | |
5724 | op_code = * data ++; | |
5725 | ||
5726 | printf (_(" Extended opcode %d: "), op_code); | |
103f02d3 | 5727 | |
252b5132 RH |
5728 | switch (op_code) |
5729 | { | |
5730 | case DW_LNE_end_sequence: | |
5731 | printf (_("End of Sequence\n\n")); | |
5732 | reset_state_machine (is_stmt); | |
5733 | break; | |
5734 | ||
5735 | case DW_LNE_set_address: | |
3590ea00 | 5736 | adr = byte_get (data, pointer_size); |
252b5132 RH |
5737 | printf (_("set Address to 0x%lx\n"), adr); |
5738 | state_machine_regs.address = adr; | |
5739 | break; | |
5740 | ||
5741 | case DW_LNE_define_file: | |
5742 | printf (_(" define new File Table entry\n")); | |
5743 | printf (_(" Entry\tDir\tTime\tSize\tName\n")); | |
103f02d3 | 5744 | |
252b5132 RH |
5745 | printf (_(" %d\t"), ++ state_machine_regs.last_file_entry); |
5746 | name = data; | |
3c9f43b1 | 5747 | data += strlen ((char *) data) + 1; |
252b5132 RH |
5748 | printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0)); |
5749 | data += bytes_read; | |
5750 | printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0)); | |
5751 | data += bytes_read; | |
5752 | printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0)); | |
5753 | printf (_("%s\n\n"), name); | |
5754 | break; | |
5755 | ||
5756 | default: | |
5757 | printf (_("UNKNOWN: length %d\n"), len - bytes_read); | |
5758 | break; | |
5759 | } | |
5760 | ||
5761 | return len; | |
5762 | } | |
5763 | ||
3590ea00 NC |
5764 | /* Size of pointers in the .debug_line section. This information is not |
5765 | really present in that section. It's obtained before dumping the debug | |
5766 | sections by doing some pre-scan of the .debug_info section. */ | |
5767 | static int debug_line_pointer_size = 4; | |
252b5132 RH |
5768 | |
5769 | static int | |
5770 | display_debug_lines (section, start, file) | |
5771 | Elf32_Internal_Shdr * section; | |
5772 | unsigned char * start; | |
b4c96d0d | 5773 | FILE * file ATTRIBUTE_UNUSED; |
252b5132 RH |
5774 | { |
5775 | DWARF2_External_LineInfo * external; | |
5776 | DWARF2_Internal_LineInfo info; | |
5777 | unsigned char * standard_opcodes; | |
5778 | unsigned char * data = start; | |
5779 | unsigned char * end = start + section->sh_size; | |
5780 | unsigned char * end_of_sequence; | |
5781 | int i; | |
5782 | ||
5783 | printf (_("\nDump of debug contents of section %s:\n\n"), | |
5784 | SECTION_NAME (section)); | |
5785 | ||
5786 | while (data < end) | |
5787 | { | |
5788 | external = (DWARF2_External_LineInfo *) data; | |
5789 | ||
5790 | /* Check the length of the block. */ | |
5791 | info.li_length = BYTE_GET (external->li_length); | |
428409d5 NC |
5792 | |
5793 | if (info.li_length == 0xffffffff) | |
5794 | { | |
5795 | warn (_("64-bit DWARF line info is not supported yet.\n")); | |
5796 | break; | |
5797 | } | |
5798 | ||
b612ab9c | 5799 | if (info.li_length + sizeof (external->li_length) > section->sh_size) |
252b5132 RH |
5800 | { |
5801 | warn | |
5802 | (_("The line info appears to be corrupt - the section is too small\n")); | |
5803 | return 0; | |
5804 | } | |
103f02d3 | 5805 | |
252b5132 RH |
5806 | /* Check its version number. */ |
5807 | info.li_version = BYTE_GET (external->li_version); | |
5808 | if (info.li_version != 2) | |
5809 | { | |
5810 | warn (_("Only DWARF version 2 line info is currently supported.\n")); | |
5811 | return 0; | |
5812 | } | |
103f02d3 | 5813 | |
252b5132 RH |
5814 | info.li_prologue_length = BYTE_GET (external->li_prologue_length); |
5815 | info.li_min_insn_length = BYTE_GET (external->li_min_insn_length); | |
5816 | info.li_default_is_stmt = BYTE_GET (external->li_default_is_stmt); | |
5817 | info.li_line_base = BYTE_GET (external->li_line_base); | |
5818 | info.li_line_range = BYTE_GET (external->li_line_range); | |
5819 | info.li_opcode_base = BYTE_GET (external->li_opcode_base); | |
103f02d3 | 5820 | |
252b5132 RH |
5821 | /* Sign extend the line base field. */ |
5822 | info.li_line_base <<= 24; | |
5823 | info.li_line_base >>= 24; | |
103f02d3 | 5824 | |
252b5132 RH |
5825 | printf (_(" Length: %ld\n"), info.li_length); |
5826 | printf (_(" DWARF Version: %d\n"), info.li_version); | |
ff94ebf2 | 5827 | printf (_(" Prologue Length: %d\n"), info.li_prologue_length); |
252b5132 RH |
5828 | printf (_(" Minimum Instruction Length: %d\n"), info.li_min_insn_length); |
5829 | printf (_(" Initial value of 'is_stmt': %d\n"), info.li_default_is_stmt); | |
5830 | printf (_(" Line Base: %d\n"), info.li_line_base); | |
5831 | printf (_(" Line Range: %d\n"), info.li_line_range); | |
5832 | printf (_(" Opcode Base: %d\n"), info.li_opcode_base); | |
5833 | ||
b612ab9c | 5834 | end_of_sequence = data + info.li_length + sizeof (external->li_length); |
252b5132 RH |
5835 | |
5836 | reset_state_machine (info.li_default_is_stmt); | |
103f02d3 | 5837 | |
252b5132 RH |
5838 | /* Display the contents of the Opcodes table. */ |
5839 | standard_opcodes = data + sizeof (* external); | |
103f02d3 | 5840 | |
252b5132 | 5841 | printf (_("\n Opcodes:\n")); |
103f02d3 | 5842 | |
252b5132 | 5843 | for (i = 1; i < info.li_opcode_base; i++) |
7a4b7442 | 5844 | printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]); |
103f02d3 | 5845 | |
252b5132 RH |
5846 | /* Display the contents of the Directory table. */ |
5847 | data = standard_opcodes + info.li_opcode_base - 1; | |
103f02d3 | 5848 | |
252b5132 RH |
5849 | if (* data == 0) |
5850 | printf (_("\n The Directory Table is empty.\n")); | |
5851 | else | |
5852 | { | |
5853 | printf (_("\n The Directory Table:\n")); | |
103f02d3 | 5854 | |
252b5132 RH |
5855 | while (* data != 0) |
5856 | { | |
5857 | printf (_(" %s\n"), data); | |
103f02d3 | 5858 | |
3c9f43b1 | 5859 | data += strlen ((char *) data) + 1; |
252b5132 RH |
5860 | } |
5861 | } | |
103f02d3 | 5862 | |
252b5132 RH |
5863 | /* Skip the NUL at the end of the table. */ |
5864 | data ++; | |
103f02d3 | 5865 | |
252b5132 RH |
5866 | /* Display the contents of the File Name table. */ |
5867 | if (* data == 0) | |
5868 | printf (_("\n The File Name Table is empty.\n")); | |
5869 | else | |
5870 | { | |
5871 | printf (_("\n The File Name Table:\n")); | |
5872 | printf (_(" Entry\tDir\tTime\tSize\tName\n")); | |
103f02d3 | 5873 | |
252b5132 RH |
5874 | while (* data != 0) |
5875 | { | |
3c9f43b1 | 5876 | unsigned char * name; |
252b5132 | 5877 | int bytes_read; |
103f02d3 | 5878 | |
252b5132 RH |
5879 | printf (_(" %d\t"), ++ state_machine_regs.last_file_entry); |
5880 | name = data; | |
103f02d3 | 5881 | |
3c9f43b1 | 5882 | data += strlen ((char *) data) + 1; |
103f02d3 | 5883 | |
252b5132 RH |
5884 | printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0)); |
5885 | data += bytes_read; | |
5886 | printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0)); | |
5887 | data += bytes_read; | |
5888 | printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0)); | |
5889 | data += bytes_read; | |
5890 | printf (_("%s\n"), name); | |
5891 | } | |
5892 | } | |
103f02d3 | 5893 | |
252b5132 RH |
5894 | /* Skip the NUL at the end of the table. */ |
5895 | data ++; | |
103f02d3 | 5896 | |
252b5132 RH |
5897 | /* Now display the statements. */ |
5898 | printf (_("\n Line Number Statements:\n")); | |
103f02d3 UD |
5899 | |
5900 | ||
252b5132 RH |
5901 | while (data < end_of_sequence) |
5902 | { | |
5903 | unsigned char op_code; | |
5904 | int adv; | |
5905 | int bytes_read; | |
103f02d3 | 5906 | |
252b5132 | 5907 | op_code = * data ++; |
103f02d3 | 5908 | |
1a509dcc GK |
5909 | if (op_code >= info.li_opcode_base) |
5910 | { | |
5911 | op_code -= info.li_opcode_base; | |
5912 | adv = (op_code / info.li_line_range) * info.li_min_insn_length; | |
5913 | state_machine_regs.address += adv; | |
5914 | printf (_(" Special opcode %d: advance Address by %d to 0x%lx"), | |
5915 | op_code, adv, state_machine_regs.address); | |
5916 | adv = (op_code % info.li_line_range) + info.li_line_base; | |
5917 | state_machine_regs.line += adv; | |
5918 | printf (_(" and Line by %d to %d\n"), | |
5919 | adv, state_machine_regs.line); | |
5920 | } | |
5921 | else switch (op_code) | |
252b5132 RH |
5922 | { |
5923 | case DW_LNS_extended_op: | |
3590ea00 NC |
5924 | data += process_extended_line_op (data, info.li_default_is_stmt, |
5925 | debug_line_pointer_size); | |
252b5132 | 5926 | break; |
103f02d3 | 5927 | |
252b5132 RH |
5928 | case DW_LNS_copy: |
5929 | printf (_(" Copy\n")); | |
5930 | break; | |
103f02d3 | 5931 | |
252b5132 RH |
5932 | case DW_LNS_advance_pc: |
5933 | adv = info.li_min_insn_length * read_leb128 (data, & bytes_read, 0); | |
5934 | data += bytes_read; | |
5935 | state_machine_regs.address += adv; | |
5936 | printf (_(" Advance PC by %d to %lx\n"), adv, | |
5937 | state_machine_regs.address); | |
5938 | break; | |
103f02d3 | 5939 | |
252b5132 RH |
5940 | case DW_LNS_advance_line: |
5941 | adv = read_leb128 (data, & bytes_read, 1); | |
5942 | data += bytes_read; | |
5943 | state_machine_regs.line += adv; | |
5944 | printf (_(" Advance Line by %d to %d\n"), adv, | |
5945 | state_machine_regs.line); | |
5946 | break; | |
103f02d3 | 5947 | |
252b5132 RH |
5948 | case DW_LNS_set_file: |
5949 | adv = read_leb128 (data, & bytes_read, 0); | |
5950 | data += bytes_read; | |
5951 | printf (_(" Set File Name to entry %d in the File Name Table\n"), | |
5952 | adv); | |
5953 | state_machine_regs.file = adv; | |
5954 | break; | |
103f02d3 | 5955 | |
252b5132 RH |
5956 | case DW_LNS_set_column: |
5957 | adv = read_leb128 (data, & bytes_read, 0); | |
5958 | data += bytes_read; | |
5959 | printf (_(" Set column to %d\n"), adv); | |
5960 | state_machine_regs.column = adv; | |
5961 | break; | |
103f02d3 | 5962 | |
252b5132 RH |
5963 | case DW_LNS_negate_stmt: |
5964 | adv = state_machine_regs.is_stmt; | |
5965 | adv = ! adv; | |
5966 | printf (_(" Set is_stmt to %d\n"), adv); | |
5967 | state_machine_regs.is_stmt = adv; | |
5968 | break; | |
103f02d3 | 5969 | |
252b5132 RH |
5970 | case DW_LNS_set_basic_block: |
5971 | printf (_(" Set basic block\n")); | |
5972 | state_machine_regs.basic_block = 1; | |
5973 | break; | |
103f02d3 | 5974 | |
252b5132 | 5975 | case DW_LNS_const_add_pc: |
2366453a NC |
5976 | adv = (((255 - info.li_opcode_base) / info.li_line_range) |
5977 | * info.li_min_insn_length); | |
252b5132 RH |
5978 | state_machine_regs.address += adv; |
5979 | printf (_(" Advance PC by constant %d to 0x%lx\n"), adv, | |
5980 | state_machine_regs.address); | |
5981 | break; | |
103f02d3 | 5982 | |
252b5132 RH |
5983 | case DW_LNS_fixed_advance_pc: |
5984 | adv = byte_get (data, 2); | |
5985 | data += 2; | |
5986 | state_machine_regs.address += adv; | |
5987 | printf (_(" Advance PC by fixed size amount %d to 0x%lx\n"), | |
5988 | adv, state_machine_regs.address); | |
5989 | break; | |
103f02d3 | 5990 | |
1a509dcc GK |
5991 | case DW_LNS_set_prologue_end: |
5992 | printf (_(" Set prologue_end to true\n")); | |
5993 | break; | |
5994 | ||
5995 | case DW_LNS_set_epilogue_begin: | |
5996 | printf (_(" Set epilogue_begin to true\n")); | |
5997 | break; | |
5998 | ||
5999 | case DW_LNS_set_isa: | |
6000 | adv = read_leb128 (data, & bytes_read, 0); | |
6001 | data += bytes_read; | |
6002 | printf (_(" Set ISA to %d\n"), adv); | |
6003 | break; | |
6004 | ||
252b5132 | 6005 | default: |
1a509dcc GK |
6006 | printf (_(" Unknown opcode %d with operands: "), op_code); |
6007 | { | |
6008 | int i; | |
6009 | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) | |
6010 | { | |
6011 | printf ("0x%lx%s", read_leb128 (data, &bytes_read, 0), | |
6012 | i == 1 ? "" : ", "); | |
6013 | data += bytes_read; | |
6014 | } | |
6015 | putchar ('\n'); | |
6016 | } | |
252b5132 RH |
6017 | break; |
6018 | } | |
6019 | } | |
1a509dcc | 6020 | putchar ('\n'); |
252b5132 | 6021 | } |
103f02d3 | 6022 | |
252b5132 RH |
6023 | return 1; |
6024 | } | |
6025 | ||
6026 | static int | |
6027 | display_debug_pubnames (section, start, file) | |
6028 | Elf32_Internal_Shdr * section; | |
6029 | unsigned char * start; | |
b4c96d0d | 6030 | FILE * file ATTRIBUTE_UNUSED; |
252b5132 RH |
6031 | { |
6032 | DWARF2_External_PubNames * external; | |
6033 | DWARF2_Internal_PubNames pubnames; | |
6034 | unsigned char * end; | |
6035 | ||
6036 | end = start + section->sh_size; | |
6037 | ||
6038 | printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section)); | |
6039 | ||
6040 | while (start < end) | |
6041 | { | |
6042 | unsigned char * data; | |
6043 | unsigned long offset; | |
6044 | ||
6045 | external = (DWARF2_External_PubNames *) start; | |
6046 | ||
6047 | pubnames.pn_length = BYTE_GET (external->pn_length); | |
6048 | pubnames.pn_version = BYTE_GET (external->pn_version); | |
6049 | pubnames.pn_offset = BYTE_GET (external->pn_offset); | |
6050 | pubnames.pn_size = BYTE_GET (external->pn_size); | |
6051 | ||
6052 | data = start + sizeof (* external); | |
6053 | start += pubnames.pn_length + sizeof (external->pn_length); | |
6054 | ||
428409d5 NC |
6055 | if (pubnames.pn_length == 0xffffffff) |
6056 | { | |
6057 | warn (_("64-bit DWARF pubnames are not supported yet.\n")); | |
6058 | break; | |
6059 | } | |
6060 | ||
252b5132 RH |
6061 | if (pubnames.pn_version != 2) |
6062 | { | |
3f215a10 NC |
6063 | static int warned = 0; |
6064 | ||
6065 | if (! warned) | |
6066 | { | |
6067 | warn (_("Only DWARF 2 pubnames are currently supported\n")); | |
6068 | warned = 1; | |
6069 | } | |
76da6bbe | 6070 | |
252b5132 RH |
6071 | continue; |
6072 | } | |
6073 | ||
6074 | printf (_(" Length: %ld\n"), | |
6075 | pubnames.pn_length); | |
6076 | printf (_(" Version: %d\n"), | |
6077 | pubnames.pn_version); | |
6078 | printf (_(" Offset into .debug_info section: %ld\n"), | |
6079 | pubnames.pn_offset); | |
6080 | printf (_(" Size of area in .debug_info section: %ld\n"), | |
6081 | pubnames.pn_size); | |
6082 | ||
6083 | printf (_("\n Offset\tName\n")); | |
6084 | ||
6085 | do | |
6086 | { | |
6087 | offset = byte_get (data, 4); | |
6088 | ||
6089 | if (offset != 0) | |
6090 | { | |
6091 | data += 4; | |
6092 | printf (" %ld\t\t%s\n", offset, data); | |
3c9f43b1 | 6093 | data += strlen ((char *) data) + 1; |
252b5132 RH |
6094 | } |
6095 | } | |
6096 | while (offset != 0); | |
6097 | } | |
6098 | ||
6099 | printf ("\n"); | |
6100 | return 1; | |
6101 | } | |
6102 | ||
6103 | static char * | |
6104 | get_TAG_name (tag) | |
6105 | unsigned long tag; | |
6106 | { | |
6107 | switch (tag) | |
6108 | { | |
b811889f NC |
6109 | case DW_TAG_padding: return "DW_TAG_padding"; |
6110 | case DW_TAG_array_type: return "DW_TAG_array_type"; | |
6111 | case DW_TAG_class_type: return "DW_TAG_class_type"; | |
6112 | case DW_TAG_entry_point: return "DW_TAG_entry_point"; | |
6113 | case DW_TAG_enumeration_type: return "DW_TAG_enumeration_type"; | |
6114 | case DW_TAG_formal_parameter: return "DW_TAG_formal_parameter"; | |
6115 | case DW_TAG_imported_declaration: return "DW_TAG_imported_declaration"; | |
6116 | case DW_TAG_label: return "DW_TAG_label"; | |
6117 | case DW_TAG_lexical_block: return "DW_TAG_lexical_block"; | |
6118 | case DW_TAG_member: return "DW_TAG_member"; | |
6119 | case DW_TAG_pointer_type: return "DW_TAG_pointer_type"; | |
6120 | case DW_TAG_reference_type: return "DW_TAG_reference_type"; | |
6121 | case DW_TAG_compile_unit: return "DW_TAG_compile_unit"; | |
6122 | case DW_TAG_string_type: return "DW_TAG_string_type"; | |
6123 | case DW_TAG_structure_type: return "DW_TAG_structure_type"; | |
6124 | case DW_TAG_subroutine_type: return "DW_TAG_subroutine_type"; | |
6125 | case DW_TAG_typedef: return "DW_TAG_typedef"; | |
6126 | case DW_TAG_union_type: return "DW_TAG_union_type"; | |
252b5132 | 6127 | case DW_TAG_unspecified_parameters: return "DW_TAG_unspecified_parameters"; |
b811889f NC |
6128 | case DW_TAG_variant: return "DW_TAG_variant"; |
6129 | case DW_TAG_common_block: return "DW_TAG_common_block"; | |
6130 | case DW_TAG_common_inclusion: return "DW_TAG_common_inclusion"; | |
6131 | case DW_TAG_inheritance: return "DW_TAG_inheritance"; | |
6132 | case DW_TAG_inlined_subroutine: return "DW_TAG_inlined_subroutine"; | |
6133 | case DW_TAG_module: return "DW_TAG_module"; | |
6134 | case DW_TAG_ptr_to_member_type: return "DW_TAG_ptr_to_member_type"; | |
6135 | case DW_TAG_set_type: return "DW_TAG_set_type"; | |
6136 | case DW_TAG_subrange_type: return "DW_TAG_subrange_type"; | |
6137 | case DW_TAG_with_stmt: return "DW_TAG_with_stmt"; | |
6138 | case DW_TAG_access_declaration: return "DW_TAG_access_declaration"; | |
6139 | case DW_TAG_base_type: return "DW_TAG_base_type"; | |
6140 | case DW_TAG_catch_block: return "DW_TAG_catch_block"; | |
6141 | case DW_TAG_const_type: return "DW_TAG_const_type"; | |
6142 | case DW_TAG_constant: return "DW_TAG_constant"; | |
6143 | case DW_TAG_enumerator: return "DW_TAG_enumerator"; | |
6144 | case DW_TAG_file_type: return "DW_TAG_file_type"; | |
6145 | case DW_TAG_friend: return "DW_TAG_friend"; | |
6146 | case DW_TAG_namelist: return "DW_TAG_namelist"; | |
6147 | case DW_TAG_namelist_item: return "DW_TAG_namelist_item"; | |
6148 | case DW_TAG_packed_type: return "DW_TAG_packed_type"; | |
6149 | case DW_TAG_subprogram: return "DW_TAG_subprogram"; | |
6150 | case DW_TAG_template_type_param: return "DW_TAG_template_type_param"; | |
6151 | case DW_TAG_template_value_param: return "DW_TAG_template_value_param"; | |
6152 | case DW_TAG_thrown_type: return "DW_TAG_thrown_type"; | |
6153 | case DW_TAG_try_block: return "DW_TAG_try_block"; | |
6154 | case DW_TAG_variant_part: return "DW_TAG_variant_part"; | |
6155 | case DW_TAG_variable: return "DW_TAG_variable"; | |
6156 | case DW_TAG_volatile_type: return "DW_TAG_volatile_type"; | |
6157 | case DW_TAG_MIPS_loop: return "DW_TAG_MIPS_loop"; | |
6158 | case DW_TAG_format_label: return "DW_TAG_format_label"; | |
6159 | case DW_TAG_function_template: return "DW_TAG_function_template"; | |
6160 | case DW_TAG_class_template: return "DW_TAG_class_template"; | |
6161 | /* DWARF 2.1 values. */ | |
6162 | case DW_TAG_dwarf_procedure: return "DW_TAG_dwarf_procedure"; | |
6163 | case DW_TAG_restrict_type: return "DW_TAG_restrict_type"; | |
6164 | case DW_TAG_interface_type: return "DW_TAG_interface_type"; | |
6165 | case DW_TAG_namespace: return "DW_TAG_namespace"; | |
6166 | case DW_TAG_imported_module: return "DW_TAG_imported_module"; | |
6167 | case DW_TAG_unspecified_type: return "DW_TAG_unspecified_type"; | |
6168 | case DW_TAG_partial_unit: return "DW_TAG_partial_unit"; | |
6169 | case DW_TAG_imported_unit: return "DW_TAG_imported_unit"; | |
252b5132 RH |
6170 | default: |
6171 | { | |
6172 | static char buffer [100]; | |
6173 | ||
6174 | sprintf (buffer, _("Unknown TAG value: %lx"), tag); | |
6175 | return buffer; | |
6176 | } | |
6177 | } | |
6178 | } | |
6179 | ||
6180 | static char * | |
6181 | get_AT_name (attribute) | |
6182 | unsigned long attribute; | |
6183 | { | |
6184 | switch (attribute) | |
6185 | { | |
b811889f NC |
6186 | case DW_AT_sibling: return "DW_AT_sibling"; |
6187 | case DW_AT_location: return "DW_AT_location"; | |
6188 | case DW_AT_name: return "DW_AT_name"; | |
6189 | case DW_AT_ordering: return "DW_AT_ordering"; | |
6190 | case DW_AT_subscr_data: return "DW_AT_subscr_data"; | |
6191 | case DW_AT_byte_size: return "DW_AT_byte_size"; | |
6192 | case DW_AT_bit_offset: return "DW_AT_bit_offset"; | |
6193 | case DW_AT_bit_size: return "DW_AT_bit_size"; | |
6194 | case DW_AT_element_list: return "DW_AT_element_list"; | |
6195 | case DW_AT_stmt_list: return "DW_AT_stmt_list"; | |
6196 | case DW_AT_low_pc: return "DW_AT_low_pc"; | |
6197 | case DW_AT_high_pc: return "DW_AT_high_pc"; | |
6198 | case DW_AT_language: return "DW_AT_language"; | |
6199 | case DW_AT_member: return "DW_AT_member"; | |
6200 | case DW_AT_discr: return "DW_AT_discr"; | |
6201 | case DW_AT_discr_value: return "DW_AT_discr_value"; | |
6202 | case DW_AT_visibility: return "DW_AT_visibility"; | |
6203 | case DW_AT_import: return "DW_AT_import"; | |
6204 | case DW_AT_string_length: return "DW_AT_string_length"; | |
6205 | case DW_AT_common_reference: return "DW_AT_common_reference"; | |
6206 | case DW_AT_comp_dir: return "DW_AT_comp_dir"; | |
6207 | case DW_AT_const_value: return "DW_AT_const_value"; | |
6208 | case DW_AT_containing_type: return "DW_AT_containing_type"; | |
6209 | case DW_AT_default_value: return "DW_AT_default_value"; | |
6210 | case DW_AT_inline: return "DW_AT_inline"; | |
6211 | case DW_AT_is_optional: return "DW_AT_is_optional"; | |
6212 | case DW_AT_lower_bound: return "DW_AT_lower_bound"; | |
6213 | case DW_AT_producer: return "DW_AT_producer"; | |
6214 | case DW_AT_prototyped: return "DW_AT_prototyped"; | |
6215 | case DW_AT_return_addr: return "DW_AT_return_addr"; | |
6216 | case DW_AT_start_scope: return "DW_AT_start_scope"; | |
6217 | case DW_AT_stride_size: return "DW_AT_stride_size"; | |
6218 | case DW_AT_upper_bound: return "DW_AT_upper_bound"; | |
6219 | case DW_AT_abstract_origin: return "DW_AT_abstract_origin"; | |
6220 | case DW_AT_accessibility: return "DW_AT_accessibility"; | |
6221 | case DW_AT_address_class: return "DW_AT_address_class"; | |
6222 | case DW_AT_artificial: return "DW_AT_artificial"; | |
6223 | case DW_AT_base_types: return "DW_AT_base_types"; | |
6224 | case DW_AT_calling_convention: return "DW_AT_calling_convention"; | |
6225 | case DW_AT_count: return "DW_AT_count"; | |
252b5132 | 6226 | case DW_AT_data_member_location: return "DW_AT_data_member_location"; |
b811889f NC |
6227 | case DW_AT_decl_column: return "DW_AT_decl_column"; |
6228 | case DW_AT_decl_file: return "DW_AT_decl_file"; | |
6229 | case DW_AT_decl_line: return "DW_AT_decl_line"; | |
6230 | case DW_AT_declaration: return "DW_AT_declaration"; | |
6231 | case DW_AT_discr_list: return "DW_AT_discr_list"; | |
6232 | case DW_AT_encoding: return "DW_AT_encoding"; | |
6233 | case DW_AT_external: return "DW_AT_external"; | |
6234 | case DW_AT_frame_base: return "DW_AT_frame_base"; | |
6235 | case DW_AT_friend: return "DW_AT_friend"; | |
6236 | case DW_AT_identifier_case: return "DW_AT_identifier_case"; | |
6237 | case DW_AT_macro_info: return "DW_AT_macro_info"; | |
6238 | case DW_AT_namelist_items: return "DW_AT_namelist_items"; | |
6239 | case DW_AT_priority: return "DW_AT_priority"; | |
6240 | case DW_AT_segment: return "DW_AT_segment"; | |
6241 | case DW_AT_specification: return "DW_AT_specification"; | |
6242 | case DW_AT_static_link: return "DW_AT_static_link"; | |
6243 | case DW_AT_type: return "DW_AT_type"; | |
6244 | case DW_AT_use_location: return "DW_AT_use_location"; | |
6245 | case DW_AT_variable_parameter: return "DW_AT_variable_parameter"; | |
6246 | case DW_AT_virtuality: return "DW_AT_virtuality"; | |
252b5132 | 6247 | case DW_AT_vtable_elem_location: return "DW_AT_vtable_elem_location"; |
12ab83a9 | 6248 | /* DWARF 2.1 values. */ |
b811889f NC |
6249 | case DW_AT_allocated: return "DW_AT_allocated"; |
6250 | case DW_AT_associated: return "DW_AT_associated"; | |
6251 | case DW_AT_data_location: return "DW_AT_data_location"; | |
6252 | case DW_AT_stride: return "DW_AT_stride"; | |
6253 | case DW_AT_entry_pc: return "DW_AT_entry_pc"; | |
6254 | case DW_AT_use_UTF8: return "DW_AT_use_UTF8"; | |
6255 | case DW_AT_extension: return "DW_AT_extension"; | |
6256 | case DW_AT_ranges: return "DW_AT_ranges"; | |
6257 | case DW_AT_trampoline: return "DW_AT_trampoline"; | |
6258 | case DW_AT_call_column: return "DW_AT_call_column"; | |
6259 | case DW_AT_call_file: return "DW_AT_call_file"; | |
6260 | case DW_AT_call_line: return "DW_AT_call_line"; | |
12ab83a9 | 6261 | /* SGI/MIPS extensions. */ |
b811889f NC |
6262 | case DW_AT_MIPS_fde: return "DW_AT_MIPS_fde"; |
6263 | case DW_AT_MIPS_loop_begin: return "DW_AT_MIPS_loop_begin"; | |
252b5132 | 6264 | case DW_AT_MIPS_tail_loop_begin: return "DW_AT_MIPS_tail_loop_begin"; |
b811889f | 6265 | case DW_AT_MIPS_epilog_begin: return "DW_AT_MIPS_epilog_begin"; |
252b5132 RH |
6266 | case DW_AT_MIPS_loop_unroll_factor: return "DW_AT_MIPS_loop_unroll_factor"; |
6267 | case DW_AT_MIPS_software_pipeline_depth: return "DW_AT_MIPS_software_pipeline_depth"; | |
b811889f NC |
6268 | case DW_AT_MIPS_linkage_name: return "DW_AT_MIPS_linkage_name"; |
6269 | case DW_AT_MIPS_stride: return "DW_AT_MIPS_stride"; | |
6270 | case DW_AT_MIPS_abstract_name: return "DW_AT_MIPS_abstract_name"; | |
6271 | case DW_AT_MIPS_clone_origin: return "DW_AT_MIPS_clone_origin"; | |
6272 | case DW_AT_MIPS_has_inlines: return "DW_AT_MIPS_has_inlines"; | |
12ab83a9 | 6273 | /* GNU extensions. */ |
b811889f NC |
6274 | case DW_AT_sf_names: return "DW_AT_sf_names"; |
6275 | case DW_AT_src_info: return "DW_AT_src_info"; | |
6276 | case DW_AT_mac_info: return "DW_AT_mac_info"; | |
6277 | case DW_AT_src_coords: return "DW_AT_src_coords"; | |
6278 | case DW_AT_body_begin: return "DW_AT_body_begin"; | |
6279 | case DW_AT_body_end: return "DW_AT_body_end"; | |
252b5132 RH |
6280 | default: |
6281 | { | |
6282 | static char buffer [100]; | |
6283 | ||
6284 | sprintf (buffer, _("Unknown AT value: %lx"), attribute); | |
6285 | return buffer; | |
6286 | } | |
6287 | } | |
6288 | } | |
6289 | ||
6290 | static char * | |
6291 | get_FORM_name (form) | |
6292 | unsigned long form; | |
6293 | { | |
6294 | switch (form) | |
6295 | { | |
b811889f NC |
6296 | case DW_FORM_addr: return "DW_FORM_addr"; |
6297 | case DW_FORM_block2: return "DW_FORM_block2"; | |
6298 | case DW_FORM_block4: return "DW_FORM_block4"; | |
6299 | case DW_FORM_data2: return "DW_FORM_data2"; | |
6300 | case DW_FORM_data4: return "DW_FORM_data4"; | |
6301 | case DW_FORM_data8: return "DW_FORM_data8"; | |
6302 | case DW_FORM_string: return "DW_FORM_string"; | |
6303 | case DW_FORM_block: return "DW_FORM_block"; | |
6304 | case DW_FORM_block1: return "DW_FORM_block1"; | |
6305 | case DW_FORM_data1: return "DW_FORM_data1"; | |
6306 | case DW_FORM_flag: return "DW_FORM_flag"; | |
6307 | case DW_FORM_sdata: return "DW_FORM_sdata"; | |
6308 | case DW_FORM_strp: return "DW_FORM_strp"; | |
6309 | case DW_FORM_udata: return "DW_FORM_udata"; | |
6310 | case DW_FORM_ref_addr: return "DW_FORM_ref_addr"; | |
6311 | case DW_FORM_ref1: return "DW_FORM_ref1"; | |
6312 | case DW_FORM_ref2: return "DW_FORM_ref2"; | |
6313 | case DW_FORM_ref4: return "DW_FORM_ref4"; | |
6314 | case DW_FORM_ref8: return "DW_FORM_ref8"; | |
252b5132 | 6315 | case DW_FORM_ref_udata: return "DW_FORM_ref_udata"; |
b811889f | 6316 | case DW_FORM_indirect: return "DW_FORM_indirect"; |
252b5132 RH |
6317 | default: |
6318 | { | |
6319 | static char buffer [100]; | |
6320 | ||
6321 | sprintf (buffer, _("Unknown FORM value: %lx"), form); | |
6322 | return buffer; | |
6323 | } | |
6324 | } | |
6325 | } | |
6326 | ||
6327 | /* FIXME: There are better and more effiecint ways to handle | |
6328 | these structures. For now though, I just want something that | |
6329 | is simple to implement. */ | |
6330 | typedef struct abbrev_attr | |
6331 | { | |
6332 | unsigned long attribute; | |
6333 | unsigned long form; | |
6334 | struct abbrev_attr * next; | |
6335 | } | |
6336 | abbrev_attr; | |
6337 | ||
6338 | typedef struct abbrev_entry | |
6339 | { | |
6340 | unsigned long entry; | |
6341 | unsigned long tag; | |
6342 | int children; | |
6343 | struct abbrev_attr * first_attr; | |
6344 | struct abbrev_attr * last_attr; | |
6345 | struct abbrev_entry * next; | |
6346 | } | |
6347 | abbrev_entry; | |
6348 | ||
6349 | static abbrev_entry * first_abbrev = NULL; | |
6350 | static abbrev_entry * last_abbrev = NULL; | |
6351 | ||
6352 | static void | |
6353 | free_abbrevs PARAMS ((void)) | |
6354 | { | |
6355 | abbrev_entry * abbrev; | |
6356 | ||
6357 | for (abbrev = first_abbrev; abbrev;) | |
6358 | { | |
6359 | abbrev_entry * next = abbrev->next; | |
6360 | abbrev_attr * attr; | |
6361 | ||
6362 | for (attr = abbrev->first_attr; attr;) | |
6363 | { | |
6364 | abbrev_attr * next = attr->next; | |
6365 | ||
6366 | free (attr); | |
6367 | attr = next; | |
6368 | } | |
6369 | ||
6370 | free (abbrev); | |
6371 | abbrev = next; | |
6372 | } | |
6373 | ||
6374 | last_abbrev = first_abbrev = NULL; | |
6375 | } | |
6376 | ||
6377 | static void | |
6378 | add_abbrev (number, tag, children) | |
6379 | unsigned long number; | |
6380 | unsigned long tag; | |
6381 | int children; | |
6382 | { | |
6383 | abbrev_entry * entry; | |
6384 | ||
6385 | entry = (abbrev_entry *) malloc (sizeof (* entry)); | |
6386 | ||
6387 | if (entry == NULL) | |
6388 | /* ugg */ | |
6389 | return; | |
6390 | ||
6391 | entry->entry = number; | |
6392 | entry->tag = tag; | |
6393 | entry->children = children; | |
6394 | entry->first_attr = NULL; | |
6395 | entry->last_attr = NULL; | |
6396 | entry->next = NULL; | |
6397 | ||
6398 | if (first_abbrev == NULL) | |
6399 | first_abbrev = entry; | |
6400 | else | |
6401 | last_abbrev->next = entry; | |
6402 | ||
6403 | last_abbrev = entry; | |
6404 | } | |
6405 | ||
6406 | static void | |
6407 | add_abbrev_attr (attribute, form) | |
6408 | unsigned long attribute; | |
6409 | unsigned long form; | |
6410 | { | |
6411 | abbrev_attr * attr; | |
6412 | ||
6413 | attr = (abbrev_attr *) malloc (sizeof (* attr)); | |
6414 | ||
6415 | if (attr == NULL) | |
6416 | /* ugg */ | |
6417 | return; | |
6418 | ||
6419 | attr->attribute = attribute; | |
6420 | attr->form = form; | |
6421 | attr->next = NULL; | |
6422 | ||
6423 | if (last_abbrev->first_attr == NULL) | |
6424 | last_abbrev->first_attr = attr; | |
6425 | else | |
6426 | last_abbrev->last_attr->next = attr; | |
6427 | ||
6428 | last_abbrev->last_attr = attr; | |
6429 | } | |
6430 | ||
6431 | /* Processes the (partial) contents of a .debug_abbrev section. | |
6432 | Returns NULL if the end of the section was encountered. | |
6433 | Returns the address after the last byte read if the end of | |
6434 | an abbreviation set was found. */ | |
6435 | ||
6436 | static unsigned char * | |
6437 | process_abbrev_section (start, end) | |
6438 | unsigned char * start; | |
6439 | unsigned char * end; | |
6440 | { | |
6441 | if (first_abbrev != NULL) | |
6442 | return NULL; | |
6443 | ||
6444 | while (start < end) | |
6445 | { | |
6446 | int bytes_read; | |
6447 | unsigned long entry; | |
6448 | unsigned long tag; | |
6449 | unsigned long attribute; | |
6450 | int children; | |
6451 | ||
6452 | entry = read_leb128 (start, & bytes_read, 0); | |
6453 | start += bytes_read; | |
6454 | ||
a3f779db NC |
6455 | /* A single zero is supposed to end the section according |
6456 | to the standard. If there's more, then signal that to | |
6457 | the caller. */ | |
252b5132 | 6458 | if (entry == 0) |
a3f779db | 6459 | return start == end ? NULL : start; |
252b5132 RH |
6460 | |
6461 | tag = read_leb128 (start, & bytes_read, 0); | |
6462 | start += bytes_read; | |
6463 | ||
6464 | children = * start ++; | |
6465 | ||
6466 | add_abbrev (entry, tag, children); | |
6467 | ||
6468 | do | |
6469 | { | |
6470 | unsigned long form; | |
6471 | ||
6472 | attribute = read_leb128 (start, & bytes_read, 0); | |
6473 | start += bytes_read; | |
6474 | ||
6475 | form = read_leb128 (start, & bytes_read, 0); | |
6476 | start += bytes_read; | |
6477 | ||
6478 | if (attribute != 0) | |
6479 | add_abbrev_attr (attribute, form); | |
6480 | } | |
6481 | while (attribute != 0); | |
6482 | } | |
6483 | ||
6484 | return NULL; | |
6485 | } | |
6486 | ||
6487 | ||
e0c60db2 NC |
6488 | static int |
6489 | display_debug_macinfo (section, start, file) | |
6490 | Elf32_Internal_Shdr * section; | |
6491 | unsigned char * start; | |
6492 | FILE * file ATTRIBUTE_UNUSED; | |
6493 | { | |
6494 | unsigned char * end = start + section->sh_size; | |
6495 | unsigned char * curr = start; | |
6496 | unsigned int bytes_read; | |
6497 | enum dwarf_macinfo_record_type op; | |
6498 | ||
6499 | printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section)); | |
6500 | ||
6501 | while (curr < end) | |
6502 | { | |
6503 | unsigned int lineno; | |
6504 | const char * string; | |
6505 | ||
6506 | op = * curr; | |
6507 | curr ++; | |
6508 | ||
6509 | switch (op) | |
6510 | { | |
6511 | case DW_MACINFO_start_file: | |
6512 | { | |
6513 | unsigned int filenum; | |
6514 | ||
6515 | lineno = read_leb128 (curr, & bytes_read, 0); | |
6516 | curr += bytes_read; | |
6517 | filenum = read_leb128 (curr, & bytes_read, 0); | |
6518 | curr += bytes_read; | |
6519 | ||
6520 | printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"), lineno, filenum); | |
6521 | } | |
6522 | break; | |
6523 | ||
6524 | case DW_MACINFO_end_file: | |
6525 | printf (_(" DW_MACINFO_end_file\n")); | |
6526 | break; | |
6527 | ||
6528 | case DW_MACINFO_define: | |
6529 | lineno = read_leb128 (curr, & bytes_read, 0); | |
6530 | curr += bytes_read; | |
6531 | string = curr; | |
6532 | curr += strlen (string) + 1; | |
6533 | printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"), lineno, string); | |
6534 | break; | |
6535 | ||
6536 | case DW_MACINFO_undef: | |
6537 | lineno = read_leb128 (curr, & bytes_read, 0); | |
6538 | curr += bytes_read; | |
6539 | string = curr; | |
6540 | curr += strlen (string) + 1; | |
6541 | printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"), lineno, string); | |
6542 | break; | |
6543 | ||
6544 | case DW_MACINFO_vendor_ext: | |
6545 | { | |
6546 | unsigned int constant; | |
6547 | ||
6548 | constant = read_leb128 (curr, & bytes_read, 0); | |
6549 | curr += bytes_read; | |
6550 | string = curr; | |
6551 | curr += strlen (string) + 1; | |
6552 | printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"), constant, string); | |
6553 | } | |
6554 | break; | |
6555 | } | |
6556 | } | |
6557 | ||
6558 | return 1; | |
6559 | } | |
0823fbca | 6560 | |
e0c60db2 | 6561 | |
252b5132 RH |
6562 | static int |
6563 | display_debug_abbrev (section, start, file) | |
6564 | Elf32_Internal_Shdr * section; | |
6565 | unsigned char * start; | |
b4c96d0d | 6566 | FILE * file ATTRIBUTE_UNUSED; |
252b5132 | 6567 | { |
584da044 | 6568 | abbrev_entry * entry; |
252b5132 RH |
6569 | unsigned char * end = start + section->sh_size; |
6570 | ||
6571 | printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section)); | |
6572 | ||
6573 | do | |
6574 | { | |
6575 | start = process_abbrev_section (start, end); | |
6576 | ||
ef5cdfc7 JJ |
6577 | if (first_abbrev == NULL) |
6578 | continue; | |
6579 | ||
252b5132 RH |
6580 | printf (_(" Number TAG\n")); |
6581 | ||
6582 | for (entry = first_abbrev; entry; entry = entry->next) | |
6583 | { | |
6584 | abbrev_attr * attr; | |
6585 | ||
6586 | printf (_(" %ld %s [%s]\n"), | |
6587 | entry->entry, | |
6588 | get_TAG_name (entry->tag), | |
6589 | entry->children ? _("has children") : _("no children")); | |
6590 | ||
6591 | for (attr = entry->first_attr; attr; attr = attr->next) | |
6592 | { | |
6593 | printf (_(" %-18s %s\n"), | |
6594 | get_AT_name (attr->attribute), | |
6595 | get_FORM_name (attr->form)); | |
6596 | } | |
6597 | } | |
ef5cdfc7 JJ |
6598 | |
6599 | free_abbrevs (); | |
252b5132 RH |
6600 | } |
6601 | while (start); | |
6602 | ||
6603 | printf ("\n"); | |
6604 | ||
6605 | return 1; | |
6606 | } | |
6607 | ||
6608 | ||
6609 | static unsigned char * | |
6610 | display_block (data, length) | |
6611 | unsigned char * data; | |
6612 | unsigned long length; | |
6613 | { | |
6614 | printf (_(" %lu byte block: "), length); | |
6615 | ||
6616 | while (length --) | |
148d3c43 | 6617 | printf ("%lx ", (unsigned long) byte_get (data ++, 1)); |
252b5132 RH |
6618 | |
6619 | return data; | |
6620 | } | |
6621 | ||
6622 | static void | |
eb6bd4d3 | 6623 | decode_location_expression (data, pointer_size, length) |
252b5132 RH |
6624 | unsigned char * data; |
6625 | unsigned int pointer_size; | |
584da044 | 6626 | unsigned long length; |
252b5132 | 6627 | { |
584da044 NC |
6628 | unsigned op; |
6629 | int bytes_read; | |
6630 | unsigned long uvalue; | |
6631 | unsigned char * end = data + length; | |
252b5132 | 6632 | |
eb6bd4d3 | 6633 | while (data < end) |
252b5132 | 6634 | { |
eb6bd4d3 | 6635 | op = * data ++; |
252b5132 | 6636 | |
eb6bd4d3 JM |
6637 | switch (op) |
6638 | { | |
6639 | case DW_OP_addr: | |
6640 | printf ("DW_OP_addr: %lx", | |
6641 | (unsigned long) byte_get (data, pointer_size)); | |
6642 | data += pointer_size; | |
6643 | break; | |
6644 | case DW_OP_deref: | |
6645 | printf ("DW_OP_deref"); | |
6646 | break; | |
6647 | case DW_OP_const1u: | |
6648 | printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data++, 1)); | |
6649 | break; | |
6650 | case DW_OP_const1s: | |
6651 | printf ("DW_OP_const1s: %ld", (long) byte_get (data++, 1)); | |
6652 | break; | |
6653 | case DW_OP_const2u: | |
6654 | printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data, 2)); | |
6655 | data += 2; | |
6656 | break; | |
6657 | case DW_OP_const2s: | |
6658 | printf ("DW_OP_const2s: %ld", (long) byte_get (data, 2)); | |
6659 | data += 2; | |
6660 | break; | |
6661 | case DW_OP_const4u: | |
6662 | printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data, 4)); | |
6663 | data += 4; | |
6664 | break; | |
6665 | case DW_OP_const4s: | |
6666 | printf ("DW_OP_const4s: %ld", (long) byte_get (data, 4)); | |
6667 | data += 4; | |
6668 | break; | |
6669 | case DW_OP_const8u: | |
6670 | printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data, 4), | |
6671 | (unsigned long) byte_get (data + 4, 4)); | |
6672 | data += 8; | |
6673 | break; | |
6674 | case DW_OP_const8s: | |
6675 | printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data, 4), | |
6676 | (long) byte_get (data + 4, 4)); | |
6677 | data += 8; | |
6678 | break; | |
6679 | case DW_OP_constu: | |
6680 | printf ("DW_OP_constu: %lu", read_leb128 (data, &bytes_read, 0)); | |
6681 | data += bytes_read; | |
6682 | break; | |
6683 | case DW_OP_consts: | |
6684 | printf ("DW_OP_consts: %ld", read_leb128 (data, &bytes_read, 1)); | |
6685 | data += bytes_read; | |
6686 | break; | |
6687 | case DW_OP_dup: | |
6688 | printf ("DW_OP_dup"); | |
6689 | break; | |
6690 | case DW_OP_drop: | |
6691 | printf ("DW_OP_drop"); | |
6692 | break; | |
6693 | case DW_OP_over: | |
6694 | printf ("DW_OP_over"); | |
6695 | break; | |
6696 | case DW_OP_pick: | |
6697 | printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data++, 1)); | |
6698 | break; | |
6699 | case DW_OP_swap: | |
6700 | printf ("DW_OP_swap"); | |
6701 | break; | |
6702 | case DW_OP_rot: | |
6703 | printf ("DW_OP_rot"); | |
6704 | break; | |
6705 | case DW_OP_xderef: | |
6706 | printf ("DW_OP_xderef"); | |
6707 | break; | |
6708 | case DW_OP_abs: | |
6709 | printf ("DW_OP_abs"); | |
6710 | break; | |
6711 | case DW_OP_and: | |
6712 | printf ("DW_OP_and"); | |
6713 | break; | |
6714 | case DW_OP_div: | |
6715 | printf ("DW_OP_div"); | |
6716 | break; | |
6717 | case DW_OP_minus: | |
6718 | printf ("DW_OP_minus"); | |
6719 | break; | |
6720 | case DW_OP_mod: | |
6721 | printf ("DW_OP_mod"); | |
6722 | break; | |
6723 | case DW_OP_mul: | |
6724 | printf ("DW_OP_mul"); | |
6725 | break; | |
6726 | case DW_OP_neg: | |
6727 | printf ("DW_OP_neg"); | |
6728 | break; | |
6729 | case DW_OP_not: | |
6730 | printf ("DW_OP_not"); | |
6731 | break; | |
6732 | case DW_OP_or: | |
6733 | printf ("DW_OP_or"); | |
6734 | break; | |
6735 | case DW_OP_plus: | |
6736 | printf ("DW_OP_plus"); | |
6737 | break; | |
6738 | case DW_OP_plus_uconst: | |
6739 | printf ("DW_OP_plus_uconst: %lu", | |
6740 | read_leb128 (data, &bytes_read, 0)); | |
6741 | data += bytes_read; | |
6742 | break; | |
6743 | case DW_OP_shl: | |
6744 | printf ("DW_OP_shl"); | |
6745 | break; | |
6746 | case DW_OP_shr: | |
6747 | printf ("DW_OP_shr"); | |
6748 | break; | |
6749 | case DW_OP_shra: | |
6750 | printf ("DW_OP_shra"); | |
6751 | break; | |
6752 | case DW_OP_xor: | |
6753 | printf ("DW_OP_xor"); | |
6754 | break; | |
6755 | case DW_OP_bra: | |
6756 | printf ("DW_OP_bra: %ld", (long) byte_get (data, 2)); | |
6757 | data += 2; | |
6758 | break; | |
6759 | case DW_OP_eq: | |
6760 | printf ("DW_OP_eq"); | |
6761 | break; | |
6762 | case DW_OP_ge: | |
6763 | printf ("DW_OP_ge"); | |
6764 | break; | |
6765 | case DW_OP_gt: | |
6766 | printf ("DW_OP_gt"); | |
6767 | break; | |
6768 | case DW_OP_le: | |
6769 | printf ("DW_OP_le"); | |
6770 | break; | |
6771 | case DW_OP_lt: | |
6772 | printf ("DW_OP_lt"); | |
6773 | break; | |
6774 | case DW_OP_ne: | |
6775 | printf ("DW_OP_ne"); | |
6776 | break; | |
6777 | case DW_OP_skip: | |
6778 | printf ("DW_OP_skip: %ld", (long) byte_get (data, 2)); | |
6779 | data += 2; | |
6780 | break; | |
6781 | ||
6782 | case DW_OP_lit0: | |
6783 | case DW_OP_lit1: | |
6784 | case DW_OP_lit2: | |
6785 | case DW_OP_lit3: | |
6786 | case DW_OP_lit4: | |
6787 | case DW_OP_lit5: | |
6788 | case DW_OP_lit6: | |
6789 | case DW_OP_lit7: | |
6790 | case DW_OP_lit8: | |
6791 | case DW_OP_lit9: | |
6792 | case DW_OP_lit10: | |
6793 | case DW_OP_lit11: | |
6794 | case DW_OP_lit12: | |
6795 | case DW_OP_lit13: | |
6796 | case DW_OP_lit14: | |
6797 | case DW_OP_lit15: | |
6798 | case DW_OP_lit16: | |
6799 | case DW_OP_lit17: | |
6800 | case DW_OP_lit18: | |
6801 | case DW_OP_lit19: | |
6802 | case DW_OP_lit20: | |
6803 | case DW_OP_lit21: | |
6804 | case DW_OP_lit22: | |
6805 | case DW_OP_lit23: | |
6806 | case DW_OP_lit24: | |
6807 | case DW_OP_lit25: | |
6808 | case DW_OP_lit26: | |
6809 | case DW_OP_lit27: | |
6810 | case DW_OP_lit28: | |
6811 | case DW_OP_lit29: | |
6812 | case DW_OP_lit30: | |
6813 | case DW_OP_lit31: | |
6814 | printf ("DW_OP_lit%d", op - DW_OP_lit0); | |
6815 | break; | |
6816 | ||
6817 | case DW_OP_reg0: | |
6818 | case DW_OP_reg1: | |
6819 | case DW_OP_reg2: | |
6820 | case DW_OP_reg3: | |
6821 | case DW_OP_reg4: | |
6822 | case DW_OP_reg5: | |
6823 | case DW_OP_reg6: | |
6824 | case DW_OP_reg7: | |
6825 | case DW_OP_reg8: | |
6826 | case DW_OP_reg9: | |
6827 | case DW_OP_reg10: | |
6828 | case DW_OP_reg11: | |
6829 | case DW_OP_reg12: | |
6830 | case DW_OP_reg13: | |
6831 | case DW_OP_reg14: | |
6832 | case DW_OP_reg15: | |
6833 | case DW_OP_reg16: | |
6834 | case DW_OP_reg17: | |
6835 | case DW_OP_reg18: | |
6836 | case DW_OP_reg19: | |
6837 | case DW_OP_reg20: | |
6838 | case DW_OP_reg21: | |
6839 | case DW_OP_reg22: | |
6840 | case DW_OP_reg23: | |
6841 | case DW_OP_reg24: | |
6842 | case DW_OP_reg25: | |
6843 | case DW_OP_reg26: | |
6844 | case DW_OP_reg27: | |
6845 | case DW_OP_reg28: | |
6846 | case DW_OP_reg29: | |
6847 | case DW_OP_reg30: | |
6848 | case DW_OP_reg31: | |
6849 | printf ("DW_OP_reg%d", op - DW_OP_reg0); | |
6850 | break; | |
6851 | ||
6852 | case DW_OP_breg0: | |
6853 | case DW_OP_breg1: | |
6854 | case DW_OP_breg2: | |
6855 | case DW_OP_breg3: | |
6856 | case DW_OP_breg4: | |
6857 | case DW_OP_breg5: | |
6858 | case DW_OP_breg6: | |
6859 | case DW_OP_breg7: | |
6860 | case DW_OP_breg8: | |
6861 | case DW_OP_breg9: | |
6862 | case DW_OP_breg10: | |
6863 | case DW_OP_breg11: | |
6864 | case DW_OP_breg12: | |
6865 | case DW_OP_breg13: | |
6866 | case DW_OP_breg14: | |
6867 | case DW_OP_breg15: | |
6868 | case DW_OP_breg16: | |
6869 | case DW_OP_breg17: | |
6870 | case DW_OP_breg18: | |
6871 | case DW_OP_breg19: | |
6872 | case DW_OP_breg20: | |
6873 | case DW_OP_breg21: | |
6874 | case DW_OP_breg22: | |
6875 | case DW_OP_breg23: | |
6876 | case DW_OP_breg24: | |
6877 | case DW_OP_breg25: | |
6878 | case DW_OP_breg26: | |
6879 | case DW_OP_breg27: | |
6880 | case DW_OP_breg28: | |
6881 | case DW_OP_breg29: | |
6882 | case DW_OP_breg30: | |
6883 | case DW_OP_breg31: | |
6884 | printf ("DW_OP_breg%d: %ld", op - DW_OP_breg0, | |
6885 | read_leb128 (data, &bytes_read, 1)); | |
6886 | data += bytes_read; | |
6887 | break; | |
6888 | ||
6889 | case DW_OP_regx: | |
6890 | printf ("DW_OP_regx: %lu", read_leb128 (data, &bytes_read, 0)); | |
6891 | data += bytes_read; | |
6892 | break; | |
6893 | case DW_OP_fbreg: | |
6894 | printf ("DW_OP_fbreg: %ld", read_leb128 (data, &bytes_read, 1)); | |
6895 | data += bytes_read; | |
6896 | break; | |
6897 | case DW_OP_bregx: | |
6898 | uvalue = read_leb128 (data, &bytes_read, 0); | |
6899 | data += bytes_read; | |
6900 | printf ("DW_OP_bregx: %lu %ld", uvalue, | |
6901 | read_leb128 (data, &bytes_read, 1)); | |
6902 | data += bytes_read; | |
6903 | break; | |
6904 | case DW_OP_piece: | |
6905 | printf ("DW_OP_piece: %lu", read_leb128 (data, &bytes_read, 0)); | |
6906 | data += bytes_read; | |
6907 | break; | |
6908 | case DW_OP_deref_size: | |
6909 | printf ("DW_OP_deref_size: %ld", (long) byte_get (data++, 1)); | |
6910 | break; | |
6911 | case DW_OP_xderef_size: | |
6912 | printf ("DW_OP_xderef_size: %ld", (long) byte_get (data++, 1)); | |
6913 | break; | |
6914 | case DW_OP_nop: | |
6915 | printf ("DW_OP_nop"); | |
6916 | break; | |
6917 | ||
12ab83a9 NC |
6918 | /* DWARF 2.1 extensions. */ |
6919 | case DW_OP_push_object_address: | |
6920 | printf ("DW_OP_push_object_address"); | |
6921 | break; | |
6922 | case DW_OP_call2: | |
6923 | printf ("DW_OP_call2: <%lx>", (long) byte_get (data, 2)); | |
6924 | data += 2; | |
6925 | break; | |
6926 | case DW_OP_call4: | |
6927 | printf ("DW_OP_call4: <%lx>", (long) byte_get (data, 4)); | |
6928 | data += 4; | |
6929 | break; | |
6930 | case DW_OP_calli: | |
6931 | printf ("DW_OP_calli"); | |
6932 | break; | |
6933 | ||
eb6bd4d3 JM |
6934 | default: |
6935 | if (op >= DW_OP_lo_user | |
6936 | && op <= DW_OP_hi_user) | |
6937 | printf (_("(User defined location op)")); | |
6938 | else | |
6939 | printf (_("(Unknown location op)")); | |
6940 | /* No way to tell where the next op is, so just bail. */ | |
6941 | return; | |
6942 | } | |
12ab83a9 NC |
6943 | |
6944 | /* Separate the ops. */ | |
6945 | printf ("; "); | |
252b5132 RH |
6946 | } |
6947 | } | |
6948 | ||
6949 | ||
261a45ad NC |
6950 | static const char * debug_str_contents; |
6951 | static bfd_vma debug_str_size; | |
6952 | ||
6953 | static void | |
6954 | load_debug_str (file) | |
6955 | FILE * file; | |
6956 | { | |
6957 | Elf32_Internal_Shdr * sec; | |
6958 | int i; | |
6959 | ||
6960 | /* If it is already loaded, do nothing. */ | |
6961 | if (debug_str_contents != NULL) | |
6962 | return; | |
6963 | ||
6964 | /* Locate the .debug_str section. */ | |
6965 | for (i = 0, sec = section_headers; | |
6966 | i < elf_header.e_shnum; | |
6967 | i ++, sec ++) | |
6968 | if (strcmp (SECTION_NAME (sec), ".debug_str") == 0) | |
6969 | break; | |
6970 | ||
6971 | if (i == elf_header.e_shnum || sec->sh_size == 0) | |
6972 | return; | |
6973 | ||
6974 | debug_str_size = sec->sh_size; | |
6975 | ||
6976 | debug_str_contents = ((char *) | |
6977 | get_data (NULL, file, sec->sh_offset, sec->sh_size, | |
6978 | _("debug_str section data"))); | |
6979 | } | |
6980 | ||
6981 | static void | |
6982 | free_debug_str () | |
6983 | { | |
6984 | if (debug_str_contents == NULL) | |
6985 | return; | |
6986 | ||
6987 | free ((char *) debug_str_contents); | |
6988 | debug_str_contents = NULL; | |
6989 | debug_str_size = 0; | |
6990 | } | |
6991 | ||
6992 | static const char * | |
6993 | fetch_indirect_string (offset) | |
6994 | unsigned long offset; | |
6995 | { | |
6996 | if (debug_str_contents == NULL) | |
6997 | return _("<no .debug_str section>"); | |
6998 | ||
6999 | if (offset > debug_str_size) | |
7000 | return _("<offset is too big>"); | |
7001 | ||
7002 | return debug_str_contents + offset; | |
7003 | } | |
7004 | ||
7005 | ||
7006 | static int | |
7007 | display_debug_str (section, start, file) | |
7008 | Elf32_Internal_Shdr * section; | |
7009 | unsigned char * start; | |
7010 | FILE * file ATTRIBUTE_UNUSED; | |
7011 | { | |
7012 | unsigned long bytes; | |
7013 | bfd_vma addr; | |
7014 | ||
7015 | addr = section->sh_addr; | |
7016 | bytes = section->sh_size; | |
7017 | ||
7018 | if (bytes == 0) | |
7019 | { | |
7020 | printf (_("\nThe .debug_str section is empty.\n")); | |
7021 | return 0; | |
7022 | } | |
7023 | ||
7024 | printf (_("Contents of the .debug_str section:\n\n")); | |
7025 | ||
7026 | while (bytes) | |
7027 | { | |
7028 | int j; | |
7029 | int k; | |
7030 | int lbytes; | |
7031 | ||
7032 | lbytes = (bytes > 16 ? 16 : bytes); | |
7033 | ||
7034 | printf (" 0x%8.8lx ", (unsigned long) addr); | |
7035 | ||
7036 | for (j = 0; j < 16; j++) | |
7037 | { | |
7038 | if (j < lbytes) | |
7039 | printf ("%2.2x", start [j]); | |
7040 | else | |
7041 | printf (" "); | |
7042 | ||
7043 | if ((j & 3) == 3) | |
7044 | printf (" "); | |
7045 | } | |
7046 | ||
7047 | for (j = 0; j < lbytes; j++) | |
7048 | { | |
7049 | k = start [j]; | |
7050 | if (k >= ' ' && k < 0x80) | |
7051 | printf ("%c", k); | |
7052 | else | |
7053 | printf ("."); | |
7054 | } | |
7055 | ||
7056 | putchar ('\n'); | |
7057 | ||
7058 | start += lbytes; | |
7059 | addr += lbytes; | |
7060 | bytes -= lbytes; | |
7061 | } | |
7062 | ||
7063 | return 1; | |
7064 | } | |
7065 | ||
7066 | ||
252b5132 | 7067 | static unsigned char * |
81766fca | 7068 | read_and_display_attr_value (attribute, form, data, cu_offset, pointer_size) |
252b5132 RH |
7069 | unsigned long attribute; |
7070 | unsigned long form; | |
7071 | unsigned char * data; | |
1fa37306 | 7072 | unsigned long cu_offset; |
252b5132 RH |
7073 | unsigned long pointer_size; |
7074 | { | |
b4c96d0d ILT |
7075 | unsigned long uvalue = 0; |
7076 | unsigned char * block_start = NULL; | |
252b5132 | 7077 | int bytes_read; |
252b5132 | 7078 | |
252b5132 RH |
7079 | switch (form) |
7080 | { | |
60bcf0fa NC |
7081 | default: |
7082 | break; | |
76da6bbe | 7083 | |
252b5132 RH |
7084 | case DW_FORM_ref_addr: |
7085 | case DW_FORM_addr: | |
7086 | uvalue = byte_get (data, pointer_size); | |
252b5132 RH |
7087 | data += pointer_size; |
7088 | break; | |
7089 | ||
ef5cdfc7 JJ |
7090 | case DW_FORM_strp: |
7091 | uvalue = byte_get (data, /* offset_size */ 4); | |
7092 | data += /* offset_size */ 4; | |
7093 | break; | |
7094 | ||
252b5132 RH |
7095 | case DW_FORM_ref1: |
7096 | case DW_FORM_flag: | |
7097 | case DW_FORM_data1: | |
7098 | uvalue = byte_get (data ++, 1); | |
252b5132 RH |
7099 | break; |
7100 | ||
7101 | case DW_FORM_ref2: | |
7102 | case DW_FORM_data2: | |
7103 | uvalue = byte_get (data, 2); | |
7104 | data += 2; | |
252b5132 RH |
7105 | break; |
7106 | ||
7107 | case DW_FORM_ref4: | |
7108 | case DW_FORM_data4: | |
7109 | uvalue = byte_get (data, 4); | |
7110 | data += 4; | |
1fa37306 JM |
7111 | break; |
7112 | ||
7113 | case DW_FORM_sdata: | |
7114 | uvalue = read_leb128 (data, & bytes_read, 1); | |
7115 | data += bytes_read; | |
7116 | break; | |
7117 | ||
7118 | case DW_FORM_ref_udata: | |
7119 | case DW_FORM_udata: | |
7120 | uvalue = read_leb128 (data, & bytes_read, 0); | |
7121 | data += bytes_read; | |
7122 | break; | |
81766fca RH |
7123 | |
7124 | case DW_FORM_indirect: | |
7125 | form = read_leb128 (data, & bytes_read, 0); | |
7126 | data += bytes_read; | |
7127 | printf (" %s", get_FORM_name (form)); | |
7128 | return read_and_display_attr_value (attribute, form, data, cu_offset, | |
7129 | pointer_size); | |
1fa37306 JM |
7130 | } |
7131 | ||
7132 | switch (form) | |
7133 | { | |
7134 | case DW_FORM_ref_addr: | |
7135 | printf (" <#%lx>", uvalue); | |
7136 | break; | |
76da6bbe | 7137 | |
1fa37306 JM |
7138 | case DW_FORM_ref1: |
7139 | case DW_FORM_ref2: | |
7140 | case DW_FORM_ref4: | |
7141 | case DW_FORM_ref_udata: | |
7142 | printf (" <%lx>", uvalue + cu_offset); | |
7143 | break; | |
7144 | ||
7145 | case DW_FORM_addr: | |
7146 | printf (" %#lx", uvalue); | |
7147 | ||
7148 | case DW_FORM_flag: | |
7149 | case DW_FORM_data1: | |
7150 | case DW_FORM_data2: | |
7151 | case DW_FORM_data4: | |
7152 | case DW_FORM_sdata: | |
7153 | case DW_FORM_udata: | |
7154 | printf (" %ld", uvalue); | |
252b5132 RH |
7155 | break; |
7156 | ||
7157 | case DW_FORM_ref8: | |
7158 | case DW_FORM_data8: | |
7159 | uvalue = byte_get (data, 4); | |
7160 | printf (" %lx", uvalue); | |
148d3c43 | 7161 | printf (" %lx", (unsigned long) byte_get (data + 4, 4)); |
252b5132 RH |
7162 | data += 8; |
7163 | break; | |
7164 | ||
7165 | case DW_FORM_string: | |
7166 | printf (" %s", data); | |
3c9f43b1 | 7167 | data += strlen ((char *) data) + 1; |
252b5132 RH |
7168 | break; |
7169 | ||
252b5132 RH |
7170 | case DW_FORM_block: |
7171 | uvalue = read_leb128 (data, & bytes_read, 0); | |
7172 | block_start = data + bytes_read; | |
7173 | data = display_block (block_start, uvalue); | |
252b5132 RH |
7174 | break; |
7175 | ||
7176 | case DW_FORM_block1: | |
7177 | uvalue = byte_get (data, 1); | |
7178 | block_start = data + 1; | |
7179 | data = display_block (block_start, uvalue); | |
252b5132 RH |
7180 | break; |
7181 | ||
7182 | case DW_FORM_block2: | |
7183 | uvalue = byte_get (data, 2); | |
7184 | block_start = data + 2; | |
7185 | data = display_block (block_start, uvalue); | |
252b5132 RH |
7186 | break; |
7187 | ||
7188 | case DW_FORM_block4: | |
7189 | uvalue = byte_get (data, 4); | |
7190 | block_start = data + 4; | |
7191 | data = display_block (block_start, uvalue); | |
252b5132 RH |
7192 | break; |
7193 | ||
7194 | case DW_FORM_strp: | |
261a45ad NC |
7195 | printf (_(" (indirect string, offset: 0x%lx): "), uvalue); |
7196 | printf (fetch_indirect_string (uvalue)); | |
ef5cdfc7 JJ |
7197 | break; |
7198 | ||
252b5132 | 7199 | case DW_FORM_indirect: |
e3c8793a | 7200 | /* Handled above. */ |
252b5132 RH |
7201 | break; |
7202 | ||
7203 | default: | |
e5fb9629 | 7204 | warn (_("Unrecognised form: %d\n"), form); |
252b5132 RH |
7205 | break; |
7206 | } | |
7207 | ||
7208 | /* For some attributes we can display futher information. */ | |
7209 | ||
7210 | printf ("\t"); | |
7211 | ||
7212 | switch (attribute) | |
7213 | { | |
7214 | case DW_AT_inline: | |
7215 | switch (uvalue) | |
7216 | { | |
7217 | case DW_INL_not_inlined: printf (_("(not inlined)")); break; | |
7218 | case DW_INL_inlined: printf (_("(inlined)")); break; | |
7219 | case DW_INL_declared_not_inlined: printf (_("(declared as inline but ignored)")); break; | |
7220 | case DW_INL_declared_inlined: printf (_("(declared as inline and inlined)")); break; | |
7221 | default: printf (_(" (Unknown inline attribute value: %lx)"), uvalue); break; | |
7222 | } | |
7223 | break; | |
7224 | ||
252b5132 RH |
7225 | case DW_AT_language: |
7226 | switch (uvalue) | |
7227 | { | |
7228 | case DW_LANG_C: printf ("(non-ANSI C)"); break; | |
7229 | case DW_LANG_C89: printf ("(ANSI C)"); break; | |
7230 | case DW_LANG_C_plus_plus: printf ("(C++)"); break; | |
7231 | case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break; | |
7232 | case DW_LANG_Fortran90: printf ("(Fortran 90)"); break; | |
7233 | case DW_LANG_Modula2: printf ("(Modula 2)"); break; | |
7234 | case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break; | |
7235 | case DW_LANG_Ada83: printf ("(Ada)"); break; | |
7236 | case DW_LANG_Cobol74: printf ("(Cobol 74)"); break; | |
7237 | case DW_LANG_Cobol85: printf ("(Cobol 85)"); break; | |
b811889f NC |
7238 | /* DWARF 2.1 values. */ |
7239 | case DW_LANG_C99: printf ("(ANSI C99)"); break; | |
7240 | case DW_LANG_Ada95: printf ("(ADA 95)"); break; | |
f662939a | 7241 | case DW_LANG_Fortran95: printf ("(Fortran 95)"); break; |
b811889f | 7242 | /* MIPS extension. */ |
252b5132 RH |
7243 | case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break; |
7244 | default: printf ("(Unknown: %lx)", uvalue); break; | |
7245 | } | |
7246 | break; | |
7247 | ||
7248 | case DW_AT_encoding: | |
7249 | switch (uvalue) | |
7250 | { | |
7251 | case DW_ATE_void: printf ("(void)"); break; | |
7252 | case DW_ATE_address: printf ("(machine address)"); break; | |
7253 | case DW_ATE_boolean: printf ("(boolean)"); break; | |
7254 | case DW_ATE_complex_float: printf ("(complex float)"); break; | |
7255 | case DW_ATE_float: printf ("(float)"); break; | |
7256 | case DW_ATE_signed: printf ("(signed)"); break; | |
7257 | case DW_ATE_signed_char: printf ("(signed char)"); break; | |
7258 | case DW_ATE_unsigned: printf ("(unsigned)"); break; | |
7259 | case DW_ATE_unsigned_char: printf ("(unsigned char)"); break; | |
b811889f NC |
7260 | /* DWARF 2.1 value. */ |
7261 | case DW_ATE_imaginary_float: printf ("(imaginary float)"); break; | |
252b5132 RH |
7262 | default: |
7263 | if (uvalue >= DW_ATE_lo_user | |
7264 | && uvalue <= DW_ATE_hi_user) | |
7265 | printf ("(user defined type)"); | |
7266 | else | |
7267 | printf ("(unknown type)"); | |
7268 | break; | |
7269 | } | |
7270 | break; | |
7271 | ||
7272 | case DW_AT_accessibility: | |
7273 | switch (uvalue) | |
7274 | { | |
7275 | case DW_ACCESS_public: printf ("(public)"); break; | |
7276 | case DW_ACCESS_protected: printf ("(protected)"); break; | |
7277 | case DW_ACCESS_private: printf ("(private)"); break; | |
7278 | default: printf ("(unknown accessibility)"); break; | |
7279 | } | |
7280 | break; | |
7281 | ||
7282 | case DW_AT_visibility: | |
7283 | switch (uvalue) | |
7284 | { | |
7285 | case DW_VIS_local: printf ("(local)"); break; | |
7286 | case DW_VIS_exported: printf ("(exported)"); break; | |
7287 | case DW_VIS_qualified: printf ("(qualified)"); break; | |
7288 | default: printf ("(unknown visibility)"); break; | |
7289 | } | |
7290 | break; | |
7291 | ||
7292 | case DW_AT_virtuality: | |
7293 | switch (uvalue) | |
7294 | { | |
7295 | case DW_VIRTUALITY_none: printf ("(none)"); break; | |
7296 | case DW_VIRTUALITY_virtual: printf ("(virtual)"); break; | |
7297 | case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break; | |
7298 | default: printf ("(unknown virtuality)"); break; | |
7299 | } | |
7300 | break; | |
7301 | ||
7302 | case DW_AT_identifier_case: | |
7303 | switch (uvalue) | |
7304 | { | |
7305 | case DW_ID_case_sensitive: printf ("(case_sensitive)"); break; | |
7306 | case DW_ID_up_case: printf ("(up_case)"); break; | |
7307 | case DW_ID_down_case: printf ("(down_case)"); break; | |
7308 | case DW_ID_case_insensitive: printf ("(case_insensitive)"); break; | |
7309 | default: printf ("(unknown case)"); break; | |
7310 | } | |
7311 | break; | |
7312 | ||
7313 | case DW_AT_calling_convention: | |
7314 | switch (uvalue) | |
7315 | { | |
7316 | case DW_CC_normal: printf ("(normal)"); break; | |
7317 | case DW_CC_program: printf ("(program)"); break; | |
7318 | case DW_CC_nocall: printf ("(nocall)"); break; | |
7319 | default: | |
7320 | if (uvalue >= DW_CC_lo_user | |
7321 | && uvalue <= DW_CC_hi_user) | |
7322 | printf ("(user defined)"); | |
7323 | else | |
7324 | printf ("(unknown convention)"); | |
7325 | } | |
7326 | break; | |
7327 | ||
12ab83a9 NC |
7328 | case DW_AT_ordering: |
7329 | switch (uvalue) | |
7330 | { | |
7331 | case -1: printf ("(undefined)"); break; | |
7332 | case 0: printf ("(row major)"); break; | |
7333 | case 1: printf ("(column major)"); break; | |
7334 | } | |
7335 | break; | |
7336 | ||
eb6bd4d3 | 7337 | case DW_AT_frame_base: |
252b5132 RH |
7338 | case DW_AT_location: |
7339 | case DW_AT_data_member_location: | |
7340 | case DW_AT_vtable_elem_location: | |
12ab83a9 NC |
7341 | case DW_AT_allocated: |
7342 | case DW_AT_associated: | |
7343 | case DW_AT_data_location: | |
7344 | case DW_AT_stride: | |
7345 | case DW_AT_upper_bound: | |
7346 | case DW_AT_lower_bound: | |
eb6bd4d3 JM |
7347 | if (block_start) |
7348 | { | |
7349 | printf ("("); | |
7350 | decode_location_expression (block_start, pointer_size, uvalue); | |
7351 | printf (")"); | |
7352 | } | |
252b5132 RH |
7353 | break; |
7354 | ||
7355 | default: | |
7356 | break; | |
7357 | } | |
7358 | ||
81766fca RH |
7359 | return data; |
7360 | } | |
7361 | ||
7362 | static unsigned char * | |
7363 | read_and_display_attr (attribute, form, data, cu_offset, pointer_size) | |
7364 | unsigned long attribute; | |
7365 | unsigned long form; | |
7366 | unsigned char * data; | |
7367 | unsigned long cu_offset; | |
7368 | unsigned long pointer_size; | |
7369 | { | |
7370 | printf (" %-18s:", get_AT_name (attribute)); | |
7371 | data = read_and_display_attr_value (attribute, form, data, cu_offset, | |
7372 | pointer_size); | |
252b5132 RH |
7373 | printf ("\n"); |
7374 | return data; | |
7375 | } | |
7376 | ||
7377 | static int | |
7378 | display_debug_info (section, start, file) | |
7379 | Elf32_Internal_Shdr * section; | |
7380 | unsigned char * start; | |
7381 | FILE * file; | |
7382 | { | |
7383 | unsigned char * end = start + section->sh_size; | |
7384 | unsigned char * section_begin = start; | |
7385 | ||
7386 | printf (_("The section %s contains:\n\n"), SECTION_NAME (section)); | |
7387 | ||
261a45ad | 7388 | load_debug_str (file); |
ef5cdfc7 | 7389 | |
252b5132 RH |
7390 | while (start < end) |
7391 | { | |
7392 | DWARF2_External_CompUnit * external; | |
7393 | DWARF2_Internal_CompUnit compunit; | |
c0e047e0 | 7394 | Elf32_Internal_Shdr * relsec; |
252b5132 RH |
7395 | unsigned char * tags; |
7396 | int i; | |
7397 | int level; | |
1fa37306 | 7398 | unsigned long cu_offset; |
252b5132 RH |
7399 | |
7400 | external = (DWARF2_External_CompUnit *) start; | |
7401 | ||
7402 | compunit.cu_length = BYTE_GET (external->cu_length); | |
7403 | compunit.cu_version = BYTE_GET (external->cu_version); | |
7404 | compunit.cu_abbrev_offset = BYTE_GET (external->cu_abbrev_offset); | |
7405 | compunit.cu_pointer_size = BYTE_GET (external->cu_pointer_size); | |
7406 | ||
428409d5 NC |
7407 | if (compunit.cu_length == 0xffffffff) |
7408 | { | |
7409 | warn (_("64-bit DWARF debug info is not supported yet.\n")); | |
7410 | break; | |
7411 | } | |
7412 | ||
c0e047e0 AO |
7413 | /* Check for RELA relocations in the abbrev_offset address, and |
7414 | apply them. */ | |
7415 | for (relsec = section_headers; | |
7416 | relsec < section_headers + elf_header.e_shnum; | |
7417 | ++relsec) | |
7418 | { | |
7419 | unsigned long nrelas, nsyms; | |
7420 | Elf_Internal_Rela *rela, *rp; | |
7421 | Elf32_Internal_Shdr *symsec; | |
7422 | Elf_Internal_Sym *symtab; | |
7423 | Elf_Internal_Sym *sym; | |
7424 | ||
7425 | if (relsec->sh_type != SHT_RELA | |
7426 | || section_headers + relsec->sh_info != section) | |
7427 | continue; | |
7428 | ||
7429 | if (!slurp_rela_relocs (file, relsec->sh_offset, relsec->sh_size, | |
7430 | & rela, & nrelas)) | |
7431 | return 0; | |
7432 | ||
7433 | symsec = section_headers + relsec->sh_link; | |
7434 | nsyms = symsec->sh_size / symsec->sh_entsize; | |
7435 | symtab = GET_ELF_SYMBOLS (file, symsec->sh_offset, nsyms); | |
7436 | ||
7437 | for (rp = rela; rp < rela + nrelas; ++rp) | |
7438 | { | |
7439 | if (rp->r_offset | |
7440 | != (bfd_vma) ((unsigned char *) &external->cu_abbrev_offset | |
7441 | - section_begin)) | |
7442 | continue; | |
0823fbca | 7443 | |
c0e047e0 AO |
7444 | if (is_32bit_elf) |
7445 | { | |
7446 | sym = symtab + ELF32_R_SYM (rp->r_info); | |
7447 | ||
7448 | if (ELF32_ST_TYPE (sym->st_info) != STT_SECTION) | |
7449 | { | |
e5fb9629 | 7450 | warn (_("Skipping unexpected symbol type %u\n"), |
c0e047e0 AO |
7451 | ELF32_ST_TYPE (sym->st_info)); |
7452 | continue; | |
7453 | } | |
7454 | } | |
7455 | else | |
7456 | { | |
7457 | sym = symtab + ELF64_R_SYM (rp->r_info); | |
7458 | ||
7459 | if (ELF64_ST_TYPE (sym->st_info) != STT_SECTION) | |
7460 | { | |
e5fb9629 | 7461 | warn (_("Skipping unexpected symbol type %u\n"), |
c0e047e0 AO |
7462 | ELF64_ST_TYPE (sym->st_info)); |
7463 | continue; | |
7464 | } | |
7465 | } | |
7466 | ||
7467 | compunit.cu_abbrev_offset += rp->r_addend; | |
7468 | break; | |
7469 | } | |
7470 | ||
7471 | free (rela); | |
7472 | break; | |
7473 | } | |
7474 | ||
252b5132 | 7475 | tags = start + sizeof (* external); |
1fa37306 | 7476 | cu_offset = start - section_begin; |
252b5132 RH |
7477 | start += compunit.cu_length + sizeof (external->cu_length); |
7478 | ||
09fd7e38 JM |
7479 | printf (_(" Compilation Unit @ %lx:\n"), cu_offset); |
7480 | printf (_(" Length: %ld\n"), compunit.cu_length); | |
7481 | printf (_(" Version: %d\n"), compunit.cu_version); | |
7482 | printf (_(" Abbrev Offset: %ld\n"), compunit.cu_abbrev_offset); | |
7483 | printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size); | |
7484 | ||
252b5132 RH |
7485 | if (compunit.cu_version != 2) |
7486 | { | |
7487 | warn (_("Only version 2 DWARF debug information is currently supported.\n")); | |
7488 | continue; | |
7489 | } | |
7490 | ||
261a45ad | 7491 | free_abbrevs (); |
252b5132 RH |
7492 | |
7493 | /* Read in the abbrevs used by this compilation unit. */ | |
7494 | ||
7495 | { | |
7496 | Elf32_Internal_Shdr * sec; | |
7497 | unsigned char * begin; | |
7498 | ||
7499 | /* Locate the .debug_abbrev section and process it. */ | |
7500 | for (i = 0, sec = section_headers; | |
7501 | i < elf_header.e_shnum; | |
7502 | i ++, sec ++) | |
7503 | if (strcmp (SECTION_NAME (sec), ".debug_abbrev") == 0) | |
7504 | break; | |
7505 | ||
ef5cdfc7 | 7506 | if (i == elf_header.e_shnum || sec->sh_size == 0) |
252b5132 RH |
7507 | { |
7508 | warn (_("Unable to locate .debug_abbrev section!\n")); | |
7509 | return 0; | |
7510 | } | |
7511 | ||
a6e9f9df | 7512 | begin = ((unsigned char *) |
0823fbca | 7513 | get_data (NULL, file, sec->sh_offset, sec->sh_size, |
a6e9f9df AM |
7514 | _("debug_abbrev section data"))); |
7515 | if (!begin) | |
7516 | return 0; | |
252b5132 RH |
7517 | |
7518 | process_abbrev_section (begin + compunit.cu_abbrev_offset, | |
7519 | begin + sec->sh_size); | |
7520 | ||
7521 | free (begin); | |
7522 | } | |
7523 | ||
7524 | level = 0; | |
7525 | while (tags < start) | |
7526 | { | |
7527 | int bytes_read; | |
b4c96d0d | 7528 | unsigned long abbrev_number; |
252b5132 RH |
7529 | abbrev_entry * entry; |
7530 | abbrev_attr * attr; | |
7531 | ||
7532 | abbrev_number = read_leb128 (tags, & bytes_read, 0); | |
7533 | tags += bytes_read; | |
7534 | ||
7535 | /* A null DIE marks the end of a list of children. */ | |
7536 | if (abbrev_number == 0) | |
7537 | { | |
7538 | --level; | |
7539 | continue; | |
7540 | } | |
7541 | ||
7542 | /* Scan through the abbreviation list until we reach the | |
7543 | correct entry. */ | |
7544 | for (entry = first_abbrev; | |
7545 | entry && entry->entry != abbrev_number; | |
7546 | entry = entry->next) | |
7547 | continue; | |
7548 | ||
7549 | if (entry == NULL) | |
7550 | { | |
b4c96d0d | 7551 | warn (_("Unable to locate entry %lu in the abbreviation table\n"), |
252b5132 RH |
7552 | abbrev_number); |
7553 | return 0; | |
7554 | } | |
7555 | ||
410f7a12 L |
7556 | printf (_(" <%d><%lx>: Abbrev Number: %lu (%s)\n"), |
7557 | level, | |
7558 | (unsigned long) (tags - section_begin - bytes_read), | |
252b5132 RH |
7559 | abbrev_number, |
7560 | get_TAG_name (entry->tag)); | |
7561 | ||
7562 | for (attr = entry->first_attr; attr; attr = attr->next) | |
7563 | tags = read_and_display_attr (attr->attribute, | |
7564 | attr->form, | |
1fa37306 | 7565 | tags, cu_offset, |
252b5132 RH |
7566 | compunit.cu_pointer_size); |
7567 | ||
7568 | if (entry->children) | |
7569 | ++level; | |
7570 | } | |
7571 | } | |
7572 | ||
261a45ad | 7573 | free_debug_str (); |
ef5cdfc7 | 7574 | |
252b5132 RH |
7575 | printf ("\n"); |
7576 | ||
7577 | return 1; | |
7578 | } | |
7579 | ||
7580 | static int | |
7581 | display_debug_aranges (section, start, file) | |
7582 | Elf32_Internal_Shdr * section; | |
7583 | unsigned char * start; | |
b4c96d0d | 7584 | FILE * file ATTRIBUTE_UNUSED; |
252b5132 RH |
7585 | { |
7586 | unsigned char * end = start + section->sh_size; | |
7587 | ||
7588 | printf (_("The section %s contains:\n\n"), SECTION_NAME (section)); | |
7589 | ||
7590 | while (start < end) | |
7591 | { | |
7592 | DWARF2_External_ARange * external; | |
7593 | DWARF2_Internal_ARange arange; | |
7594 | unsigned char * ranges; | |
7595 | unsigned long length; | |
7596 | unsigned long address; | |
7a4b7442 | 7597 | int excess; |
252b5132 RH |
7598 | |
7599 | external = (DWARF2_External_ARange *) start; | |
7600 | ||
7601 | arange.ar_length = BYTE_GET (external->ar_length); | |
7602 | arange.ar_version = BYTE_GET (external->ar_version); | |
7603 | arange.ar_info_offset = BYTE_GET (external->ar_info_offset); | |
7604 | arange.ar_pointer_size = BYTE_GET (external->ar_pointer_size); | |
7605 | arange.ar_segment_size = BYTE_GET (external->ar_segment_size); | |
7606 | ||
e414a165 NC |
7607 | if (arange.ar_length == 0xffffffff) |
7608 | { | |
428409d5 | 7609 | warn (_("64-bit DWARF aranges are not supported yet.\n")); |
e414a165 NC |
7610 | break; |
7611 | } | |
7612 | ||
3f215a10 NC |
7613 | if (arange.ar_version != 2) |
7614 | { | |
7615 | warn (_("Only DWARF 2 aranges are currently supported.\n")); | |
7616 | break; | |
7617 | } | |
7618 | ||
252b5132 RH |
7619 | printf (_(" Length: %ld\n"), arange.ar_length); |
7620 | printf (_(" Version: %d\n"), arange.ar_version); | |
7621 | printf (_(" Offset into .debug_info: %lx\n"), arange.ar_info_offset); | |
7622 | printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size); | |
7623 | printf (_(" Segment Size: %d\n"), arange.ar_segment_size); | |
7624 | ||
7625 | printf (_("\n Address Length\n")); | |
7626 | ||
7627 | ranges = start + sizeof (* external); | |
7628 | ||
7a4b7442 | 7629 | /* Must pad to an alignment boundary that is twice the pointer size. */ |
584da044 | 7630 | excess = sizeof (* external) % (2 * arange.ar_pointer_size); |
7a4b7442 NC |
7631 | if (excess) |
7632 | ranges += (2 * arange.ar_pointer_size) - excess; | |
7633 | ||
252b5132 RH |
7634 | for (;;) |
7635 | { | |
7636 | address = byte_get (ranges, arange.ar_pointer_size); | |
7637 | ||
252b5132 RH |
7638 | ranges += arange.ar_pointer_size; |
7639 | ||
7640 | length = byte_get (ranges, arange.ar_pointer_size); | |
7641 | ||
7642 | ranges += arange.ar_pointer_size; | |
7643 | ||
7a4b7442 NC |
7644 | /* A pair of zeros marks the end of the list. */ |
7645 | if (address == 0 && length == 0) | |
7646 | break; | |
103f02d3 | 7647 | |
252b5132 RH |
7648 | printf (" %8.8lx %lu\n", address, length); |
7649 | } | |
7650 | ||
7651 | start += arange.ar_length + sizeof (external->ar_length); | |
7652 | } | |
7653 | ||
7654 | printf ("\n"); | |
7655 | ||
7656 | return 1; | |
7657 | } | |
7658 | ||
c47d488e DD |
7659 | typedef struct Frame_Chunk |
7660 | { | |
584da044 NC |
7661 | struct Frame_Chunk * next; |
7662 | unsigned char * chunk_start; | |
7663 | int ncols; | |
a98cc2b2 | 7664 | /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */ |
584da044 NC |
7665 | short int * col_type; |
7666 | int * col_offset; | |
7667 | char * augmentation; | |
7668 | unsigned int code_factor; | |
31b6fca6 | 7669 | int data_factor; |
584da044 NC |
7670 | unsigned long pc_begin; |
7671 | unsigned long pc_range; | |
7672 | int cfa_reg; | |
7673 | int cfa_offset; | |
7674 | int ra; | |
31b6fca6 | 7675 | unsigned char fde_encoding; |
c47d488e DD |
7676 | } |
7677 | Frame_Chunk; | |
7678 | ||
a98cc2b2 AH |
7679 | /* A marker for a col_type that means this column was never referenced |
7680 | in the frame info. */ | |
7681 | #define DW_CFA_unreferenced (-1) | |
7682 | ||
2863d58a AM |
7683 | static void frame_need_space PARAMS ((Frame_Chunk *, int)); |
7684 | static void frame_display_row PARAMS ((Frame_Chunk *, int *, int *)); | |
7685 | static int size_of_encoded_value PARAMS ((int)); | |
7686 | ||
c47d488e DD |
7687 | static void |
7688 | frame_need_space (fc, reg) | |
584da044 | 7689 | Frame_Chunk * fc; |
c47d488e DD |
7690 | int reg; |
7691 | { | |
7692 | int prev = fc->ncols; | |
7693 | ||
7694 | if (reg < fc->ncols) | |
7695 | return; | |
584da044 | 7696 | |
c47d488e | 7697 | fc->ncols = reg + 1; |
a98cc2b2 AH |
7698 | fc->col_type = (short int *) xrealloc (fc->col_type, |
7699 | fc->ncols * sizeof (short int)); | |
c47d488e DD |
7700 | fc->col_offset = (int *) xrealloc (fc->col_offset, |
7701 | fc->ncols * sizeof (int)); | |
7702 | ||
7703 | while (prev < fc->ncols) | |
7704 | { | |
a98cc2b2 | 7705 | fc->col_type[prev] = DW_CFA_unreferenced; |
c47d488e DD |
7706 | fc->col_offset[prev] = 0; |
7707 | prev++; | |
7708 | } | |
7709 | } | |
7710 | ||
7711 | static void | |
7712 | frame_display_row (fc, need_col_headers, max_regs) | |
584da044 NC |
7713 | Frame_Chunk * fc; |
7714 | int * need_col_headers; | |
7715 | int * max_regs; | |
c47d488e DD |
7716 | { |
7717 | int r; | |
7718 | char tmp[100]; | |
7719 | ||
584da044 NC |
7720 | if (* max_regs < fc->ncols) |
7721 | * max_regs = fc->ncols; | |
7722 | ||
7723 | if (* need_col_headers) | |
c47d488e | 7724 | { |
584da044 NC |
7725 | * need_col_headers = 0; |
7726 | ||
c47d488e | 7727 | printf (" LOC CFA "); |
584da044 NC |
7728 | |
7729 | for (r = 0; r < * max_regs; r++) | |
a98cc2b2 AH |
7730 | if (fc->col_type[r] != DW_CFA_unreferenced) |
7731 | { | |
7732 | if (r == fc->ra) | |
7733 | printf ("ra "); | |
7734 | else | |
7735 | printf ("r%-4d", r); | |
7736 | } | |
584da044 | 7737 | |
c47d488e DD |
7738 | printf ("\n"); |
7739 | } | |
584da044 | 7740 | |
31b6fca6 | 7741 | printf ("%08lx ", fc->pc_begin); |
c47d488e DD |
7742 | sprintf (tmp, "r%d%+d", fc->cfa_reg, fc->cfa_offset); |
7743 | printf ("%-8s ", tmp); | |
584da044 NC |
7744 | |
7745 | for (r = 0; r < fc->ncols; r++) | |
c47d488e | 7746 | { |
a98cc2b2 | 7747 | if (fc->col_type[r] != DW_CFA_unreferenced) |
c47d488e | 7748 | { |
a98cc2b2 AH |
7749 | switch (fc->col_type[r]) |
7750 | { | |
7751 | case DW_CFA_undefined: | |
7752 | strcpy (tmp, "u"); | |
7753 | break; | |
7754 | case DW_CFA_same_value: | |
7755 | strcpy (tmp, "s"); | |
7756 | break; | |
7757 | case DW_CFA_offset: | |
7758 | sprintf (tmp, "c%+d", fc->col_offset[r]); | |
7759 | break; | |
7760 | case DW_CFA_register: | |
7761 | sprintf (tmp, "r%d", fc->col_offset[r]); | |
7762 | break; | |
7763 | default: | |
7764 | strcpy (tmp, "n/a"); | |
7765 | break; | |
7766 | } | |
7767 | printf ("%-5s", tmp); | |
c47d488e | 7768 | } |
c47d488e DD |
7769 | } |
7770 | printf ("\n"); | |
7771 | } | |
7772 | ||
31b6fca6 RH |
7773 | static int |
7774 | size_of_encoded_value (encoding) | |
7775 | int encoding; | |
7776 | { | |
7777 | switch (encoding & 0x7) | |
7778 | { | |
7779 | default: /* ??? */ | |
7780 | case 0: return is_32bit_elf ? 4 : 8; | |
7781 | case 2: return 2; | |
7782 | case 3: return 4; | |
7783 | case 4: return 8; | |
7784 | } | |
7785 | } | |
7786 | ||
c47d488e | 7787 | #define GET(N) byte_get (start, N); start += N |
584da044 NC |
7788 | #define LEB() read_leb128 (start, & length_return, 0); start += length_return |
7789 | #define SLEB() read_leb128 (start, & length_return, 1); start += length_return | |
c47d488e DD |
7790 | |
7791 | static int | |
7792 | display_debug_frames (section, start, file) | |
7793 | Elf32_Internal_Shdr * section; | |
7794 | unsigned char * start; | |
7795 | FILE * file ATTRIBUTE_UNUSED; | |
7796 | { | |
7797 | unsigned char * end = start + section->sh_size; | |
584da044 NC |
7798 | unsigned char * section_start = start; |
7799 | Frame_Chunk * chunks = 0; | |
7800 | Frame_Chunk * remembered_state = 0; | |
7801 | Frame_Chunk * rs; | |
7802 | int is_eh = (strcmp (SECTION_NAME (section), ".eh_frame") == 0); | |
7803 | int length_return; | |
7804 | int max_regs = 0; | |
31b6fca6 | 7805 | int addr_size = is_32bit_elf ? 4 : 8; |
c47d488e DD |
7806 | |
7807 | printf (_("The section %s contains:\n"), SECTION_NAME (section)); | |
7808 | ||
7809 | while (start < end) | |
7810 | { | |
584da044 NC |
7811 | unsigned char * saved_start; |
7812 | unsigned char * block_end; | |
7813 | unsigned long length; | |
7814 | unsigned long cie_id; | |
7815 | Frame_Chunk * fc; | |
7816 | Frame_Chunk * cie; | |
7817 | int need_col_headers = 1; | |
31b6fca6 RH |
7818 | unsigned char * augmentation_data = NULL; |
7819 | unsigned long augmentation_data_len = 0; | |
7820 | int encoded_ptr_size = addr_size; | |
c47d488e DD |
7821 | |
7822 | saved_start = start; | |
7823 | length = byte_get (start, 4); start += 4; | |
7824 | ||
7825 | if (length == 0) | |
7826 | return 1; | |
7827 | ||
428409d5 NC |
7828 | if (length == 0xffffffff) |
7829 | { | |
7830 | warn (_("64-bit DWARF format frames are not supported yet.\n")); | |
7831 | break; | |
7832 | } | |
7833 | ||
c47d488e DD |
7834 | block_end = saved_start + length + 4; |
7835 | cie_id = byte_get (start, 4); start += 4; | |
7836 | ||
c47d488e DD |
7837 | if (is_eh ? (cie_id == 0) : (cie_id == DW_CIE_ID)) |
7838 | { | |
31b6fca6 RH |
7839 | int version; |
7840 | ||
c47d488e DD |
7841 | fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); |
7842 | memset (fc, 0, sizeof (Frame_Chunk)); | |
7843 | ||
7844 | fc->next = chunks; | |
7845 | chunks = fc; | |
7846 | fc->chunk_start = saved_start; | |
7847 | fc->ncols = 0; | |
a98cc2b2 | 7848 | fc->col_type = (short int *) xmalloc (sizeof (short int)); |
c47d488e DD |
7849 | fc->col_offset = (int *) xmalloc (sizeof (int)); |
7850 | frame_need_space (fc, max_regs-1); | |
7851 | ||
31b6fca6 | 7852 | version = *start++; |
584da044 | 7853 | |
31b6fca6 RH |
7854 | fc->augmentation = start; |
7855 | start = strchr (start, '\0') + 1; | |
584da044 | 7856 | |
c47d488e DD |
7857 | if (fc->augmentation[0] == 'z') |
7858 | { | |
c47d488e DD |
7859 | fc->code_factor = LEB (); |
7860 | fc->data_factor = SLEB (); | |
7861 | fc->ra = byte_get (start, 1); start += 1; | |
31b6fca6 RH |
7862 | augmentation_data_len = LEB (); |
7863 | augmentation_data = start; | |
7864 | start += augmentation_data_len; | |
c47d488e DD |
7865 | } |
7866 | else if (strcmp (fc->augmentation, "eh") == 0) | |
7867 | { | |
31b6fca6 | 7868 | start += addr_size; |
c47d488e DD |
7869 | fc->code_factor = LEB (); |
7870 | fc->data_factor = SLEB (); | |
7871 | fc->ra = byte_get (start, 1); start += 1; | |
7872 | } | |
7873 | else | |
7874 | { | |
7875 | fc->code_factor = LEB (); | |
7876 | fc->data_factor = SLEB (); | |
7877 | fc->ra = byte_get (start, 1); start += 1; | |
7878 | } | |
7879 | cie = fc; | |
31b6fca6 RH |
7880 | |
7881 | if (do_debug_frames_interp) | |
7882 | printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n", | |
7036c0e1 | 7883 | (unsigned long)(saved_start - section_start), length, cie_id, |
31b6fca6 RH |
7884 | fc->augmentation, fc->code_factor, fc->data_factor, |
7885 | fc->ra); | |
7886 | else | |
7887 | { | |
7888 | printf ("\n%08lx %08lx %08lx CIE\n", | |
7036c0e1 | 7889 | (unsigned long)(saved_start - section_start), length, cie_id); |
31b6fca6 RH |
7890 | printf (" Version: %d\n", version); |
7891 | printf (" Augmentation: \"%s\"\n", fc->augmentation); | |
7892 | printf (" Code alignment factor: %u\n", fc->code_factor); | |
7893 | printf (" Data alignment factor: %d\n", fc->data_factor); | |
7894 | printf (" Return address column: %d\n", fc->ra); | |
7895 | ||
7896 | if (augmentation_data_len) | |
7897 | { | |
7898 | unsigned long i; | |
7899 | printf (" Augmentation data: "); | |
7900 | for (i = 0; i < augmentation_data_len; ++i) | |
7901 | printf (" %02x", augmentation_data[i]); | |
7902 | putchar ('\n'); | |
7903 | } | |
7904 | putchar ('\n'); | |
7905 | } | |
7906 | ||
7907 | if (augmentation_data_len) | |
7908 | { | |
7909 | unsigned char *p, *q; | |
7910 | p = fc->augmentation + 1; | |
7911 | q = augmentation_data; | |
7912 | ||
7913 | while (1) | |
7914 | { | |
7915 | if (*p == 'L') | |
7036c0e1 | 7916 | q++; |
31b6fca6 RH |
7917 | else if (*p == 'P') |
7918 | q += 1 + size_of_encoded_value (*q); | |
7919 | else if (*p == 'R') | |
7920 | fc->fde_encoding = *q++; | |
7921 | else | |
7922 | break; | |
7923 | p++; | |
7924 | } | |
7925 | ||
7926 | if (fc->fde_encoding) | |
7927 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); | |
7928 | } | |
c47d488e DD |
7929 | |
7930 | frame_need_space (fc, fc->ra); | |
7931 | } | |
7932 | else | |
7933 | { | |
584da044 | 7934 | unsigned char * look_for; |
c47d488e | 7935 | static Frame_Chunk fde_fc; |
584da044 NC |
7936 | |
7937 | fc = & fde_fc; | |
c47d488e DD |
7938 | memset (fc, 0, sizeof (Frame_Chunk)); |
7939 | ||
31b6fca6 | 7940 | look_for = is_eh ? start - 4 - cie_id : section_start + cie_id; |
c47d488e | 7941 | |
428409d5 | 7942 | for (cie = chunks; cie ; cie = cie->next) |
31b6fca6 RH |
7943 | if (cie->chunk_start == look_for) |
7944 | break; | |
c47d488e | 7945 | |
c47d488e DD |
7946 | if (!cie) |
7947 | { | |
31b6fca6 RH |
7948 | warn ("Invalid CIE pointer %08lx in FDE at %08lx\n", |
7949 | cie_id, saved_start); | |
c47d488e DD |
7950 | start = block_end; |
7951 | fc->ncols = 0; | |
a98cc2b2 | 7952 | fc->col_type = (short int *) xmalloc (sizeof (short int)); |
c47d488e | 7953 | fc->col_offset = (int *) xmalloc (sizeof (int)); |
584da044 | 7954 | frame_need_space (fc, max_regs - 1); |
c47d488e DD |
7955 | cie = fc; |
7956 | fc->augmentation = ""; | |
31b6fca6 | 7957 | fc->fde_encoding = 0; |
c47d488e DD |
7958 | } |
7959 | else | |
7960 | { | |
7961 | fc->ncols = cie->ncols; | |
a98cc2b2 | 7962 | fc->col_type = (short int *) xmalloc (fc->ncols * sizeof (short int)); |
c47d488e | 7963 | fc->col_offset = (int *) xmalloc (fc->ncols * sizeof (int)); |
a98cc2b2 | 7964 | memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int)); |
c47d488e DD |
7965 | memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int)); |
7966 | fc->augmentation = cie->augmentation; | |
7967 | fc->code_factor = cie->code_factor; | |
7968 | fc->data_factor = cie->data_factor; | |
7969 | fc->cfa_reg = cie->cfa_reg; | |
7970 | fc->cfa_offset = cie->cfa_offset; | |
7971 | fc->ra = cie->ra; | |
7972 | frame_need_space (fc, max_regs-1); | |
31b6fca6 | 7973 | fc->fde_encoding = cie->fde_encoding; |
c47d488e DD |
7974 | } |
7975 | ||
31b6fca6 RH |
7976 | if (fc->fde_encoding) |
7977 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); | |
7978 | ||
7979 | fc->pc_begin = byte_get (start, encoded_ptr_size); | |
7980 | start += encoded_ptr_size; | |
7981 | fc->pc_range = byte_get (start, encoded_ptr_size); | |
7982 | start += encoded_ptr_size; | |
7983 | ||
c47d488e DD |
7984 | if (cie->augmentation[0] == 'z') |
7985 | { | |
31b6fca6 RH |
7986 | augmentation_data_len = LEB (); |
7987 | augmentation_data = start; | |
7988 | start += augmentation_data_len; | |
c47d488e DD |
7989 | } |
7990 | ||
410f7a12 | 7991 | printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=%08lx..%08lx\n", |
7036c0e1 | 7992 | (unsigned long)(saved_start - section_start), length, cie_id, |
410f7a12 L |
7993 | (unsigned long)(cie->chunk_start - section_start), |
7994 | fc->pc_begin, fc->pc_begin + fc->pc_range); | |
31b6fca6 RH |
7995 | if (! do_debug_frames_interp && augmentation_data_len) |
7996 | { | |
7997 | unsigned long i; | |
7998 | printf (" Augmentation data: "); | |
7999 | for (i = 0; i < augmentation_data_len; ++i) | |
8000 | printf (" %02x", augmentation_data[i]); | |
8001 | putchar ('\n'); | |
8002 | putchar ('\n'); | |
8003 | } | |
c47d488e DD |
8004 | } |
8005 | ||
8006 | /* At this point, fc is the current chunk, cie (if any) is set, and we're | |
8007 | about to interpret instructions for the chunk. */ | |
8008 | ||
31b6fca6 | 8009 | if (do_debug_frames_interp) |
a98cc2b2 AH |
8010 | { |
8011 | /* Start by making a pass over the chunk, allocating storage | |
8012 | and taking note of what registers are used. */ | |
584da044 | 8013 | unsigned char * tmp = start; |
a98cc2b2 | 8014 | |
a98cc2b2 AH |
8015 | while (start < block_end) |
8016 | { | |
8017 | unsigned op, opa; | |
8018 | unsigned long reg; | |
7036c0e1 | 8019 | |
584da044 | 8020 | op = * start ++; |
a98cc2b2 AH |
8021 | opa = op & 0x3f; |
8022 | if (op & 0xc0) | |
8023 | op &= 0xc0; | |
7036c0e1 | 8024 | |
a98cc2b2 AH |
8025 | /* Warning: if you add any more cases to this switch, be |
8026 | sure to add them to the corresponding switch below. */ | |
8027 | switch (op) | |
8028 | { | |
8029 | case DW_CFA_advance_loc: | |
8030 | break; | |
8031 | case DW_CFA_offset: | |
8032 | LEB (); | |
8033 | frame_need_space (fc, opa); | |
8034 | fc->col_type[opa] = DW_CFA_undefined; | |
8035 | break; | |
8036 | case DW_CFA_restore: | |
8037 | frame_need_space (fc, opa); | |
8038 | fc->col_type[opa] = DW_CFA_undefined; | |
8039 | break; | |
8040 | case DW_CFA_set_loc: | |
31b6fca6 | 8041 | start += encoded_ptr_size; |
a98cc2b2 AH |
8042 | break; |
8043 | case DW_CFA_advance_loc1: | |
8044 | start += 1; | |
8045 | break; | |
8046 | case DW_CFA_advance_loc2: | |
8047 | start += 2; | |
8048 | break; | |
8049 | case DW_CFA_advance_loc4: | |
8050 | start += 4; | |
8051 | break; | |
8052 | case DW_CFA_offset_extended: | |
8053 | reg = LEB (); LEB (); | |
8054 | frame_need_space (fc, reg); | |
8055 | fc->col_type[reg] = DW_CFA_undefined; | |
8056 | break; | |
8057 | case DW_CFA_restore_extended: | |
8058 | reg = LEB (); | |
8059 | frame_need_space (fc, reg); | |
8060 | fc->col_type[reg] = DW_CFA_undefined; | |
8061 | break; | |
8062 | case DW_CFA_undefined: | |
8063 | reg = LEB (); | |
8064 | frame_need_space (fc, reg); | |
8065 | fc->col_type[reg] = DW_CFA_undefined; | |
8066 | break; | |
8067 | case DW_CFA_same_value: | |
8068 | reg = LEB (); | |
8069 | frame_need_space (fc, reg); | |
8070 | fc->col_type[reg] = DW_CFA_undefined; | |
8071 | break; | |
8072 | case DW_CFA_register: | |
8073 | reg = LEB (); LEB (); | |
8074 | frame_need_space (fc, reg); | |
8075 | fc->col_type[reg] = DW_CFA_undefined; | |
8076 | break; | |
8077 | case DW_CFA_def_cfa: | |
8078 | LEB (); LEB (); | |
8079 | break; | |
8080 | case DW_CFA_def_cfa_register: | |
8081 | LEB (); | |
8082 | break; | |
8083 | case DW_CFA_def_cfa_offset: | |
8084 | LEB (); | |
8085 | break; | |
8086 | #ifndef DW_CFA_GNU_args_size | |
8087 | #define DW_CFA_GNU_args_size 0x2e | |
8088 | #endif | |
8089 | case DW_CFA_GNU_args_size: | |
8090 | LEB (); | |
7036c0e1 | 8091 | break; |
a98cc2b2 AH |
8092 | #ifndef DW_CFA_GNU_negative_offset_extended |
8093 | #define DW_CFA_GNU_negative_offset_extended 0x2f | |
8094 | #endif | |
8095 | case DW_CFA_GNU_negative_offset_extended: | |
7036c0e1 | 8096 | reg = LEB (); LEB (); |
a98cc2b2 AH |
8097 | frame_need_space (fc, reg); |
8098 | fc->col_type[reg] = DW_CFA_undefined; | |
7036c0e1 | 8099 | |
a98cc2b2 AH |
8100 | default: |
8101 | break; | |
8102 | } | |
8103 | } | |
8104 | start = tmp; | |
8105 | } | |
8106 | ||
8107 | /* Now we know what registers are used, make a second pass over | |
8108 | the chunk, this time actually printing out the info. */ | |
8109 | ||
c47d488e DD |
8110 | while (start < block_end) |
8111 | { | |
8112 | unsigned op, opa; | |
8113 | unsigned long ul, reg, roffs; | |
8114 | long l, ofs; | |
8115 | bfd_vma vma; | |
8116 | ||
8117 | op = * start ++; | |
8118 | opa = op & 0x3f; | |
8119 | if (op & 0xc0) | |
8120 | op &= 0xc0; | |
8121 | ||
a98cc2b2 AH |
8122 | /* Warning: if you add any more cases to this switch, be |
8123 | sure to add them to the corresponding switch above. */ | |
c47d488e DD |
8124 | switch (op) |
8125 | { | |
8126 | case DW_CFA_advance_loc: | |
31b6fca6 RH |
8127 | if (do_debug_frames_interp) |
8128 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8129 | else | |
8130 | printf (" DW_CFA_advance_loc: %d to %08lx\n", | |
8131 | opa * fc->code_factor, | |
8132 | fc->pc_begin + opa * fc->code_factor); | |
c47d488e DD |
8133 | fc->pc_begin += opa * fc->code_factor; |
8134 | break; | |
8135 | ||
8136 | case DW_CFA_offset: | |
c47d488e | 8137 | roffs = LEB (); |
31b6fca6 | 8138 | if (! do_debug_frames_interp) |
7036c0e1 | 8139 | printf (" DW_CFA_offset: r%d at cfa%+ld\n", |
31b6fca6 | 8140 | opa, roffs * fc->data_factor); |
c47d488e DD |
8141 | fc->col_type[opa] = DW_CFA_offset; |
8142 | fc->col_offset[opa] = roffs * fc->data_factor; | |
8143 | break; | |
8144 | ||
8145 | case DW_CFA_restore: | |
31b6fca6 RH |
8146 | if (! do_debug_frames_interp) |
8147 | printf (" DW_CFA_restore: r%d\n", opa); | |
c47d488e DD |
8148 | fc->col_type[opa] = cie->col_type[opa]; |
8149 | fc->col_offset[opa] = cie->col_offset[opa]; | |
8150 | break; | |
8151 | ||
8152 | case DW_CFA_set_loc: | |
31b6fca6 RH |
8153 | vma = byte_get (start, encoded_ptr_size); |
8154 | start += encoded_ptr_size; | |
8155 | if (do_debug_frames_interp) | |
8156 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8157 | else | |
7036c0e1 | 8158 | printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma); |
c47d488e DD |
8159 | fc->pc_begin = vma; |
8160 | break; | |
8161 | ||
8162 | case DW_CFA_advance_loc1: | |
c47d488e | 8163 | ofs = byte_get (start, 1); start += 1; |
31b6fca6 RH |
8164 | if (do_debug_frames_interp) |
8165 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8166 | else | |
7036c0e1 | 8167 | printf (" DW_CFA_advance_loc1: %ld to %08lx\n", |
31b6fca6 RH |
8168 | ofs * fc->code_factor, |
8169 | fc->pc_begin + ofs * fc->code_factor); | |
c47d488e DD |
8170 | fc->pc_begin += ofs * fc->code_factor; |
8171 | break; | |
8172 | ||
8173 | case DW_CFA_advance_loc2: | |
c47d488e | 8174 | ofs = byte_get (start, 2); start += 2; |
31b6fca6 RH |
8175 | if (do_debug_frames_interp) |
8176 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8177 | else | |
7036c0e1 | 8178 | printf (" DW_CFA_advance_loc2: %ld to %08lx\n", |
31b6fca6 RH |
8179 | ofs * fc->code_factor, |
8180 | fc->pc_begin + ofs * fc->code_factor); | |
c47d488e DD |
8181 | fc->pc_begin += ofs * fc->code_factor; |
8182 | break; | |
8183 | ||
8184 | case DW_CFA_advance_loc4: | |
c47d488e | 8185 | ofs = byte_get (start, 4); start += 4; |
31b6fca6 RH |
8186 | if (do_debug_frames_interp) |
8187 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8188 | else | |
7036c0e1 | 8189 | printf (" DW_CFA_advance_loc4: %ld to %08lx\n", |
31b6fca6 RH |
8190 | ofs * fc->code_factor, |
8191 | fc->pc_begin + ofs * fc->code_factor); | |
c47d488e DD |
8192 | fc->pc_begin += ofs * fc->code_factor; |
8193 | break; | |
8194 | ||
8195 | case DW_CFA_offset_extended: | |
8196 | reg = LEB (); | |
8197 | roffs = LEB (); | |
31b6fca6 | 8198 | if (! do_debug_frames_interp) |
7036c0e1 | 8199 | printf (" DW_CFA_offset_extended: r%ld at cfa%+ld\n", |
31b6fca6 | 8200 | reg, roffs * fc->data_factor); |
c47d488e DD |
8201 | fc->col_type[reg] = DW_CFA_offset; |
8202 | fc->col_offset[reg] = roffs * fc->data_factor; | |
8203 | break; | |
8204 | ||
8205 | case DW_CFA_restore_extended: | |
8206 | reg = LEB (); | |
31b6fca6 | 8207 | if (! do_debug_frames_interp) |
7036c0e1 | 8208 | printf (" DW_CFA_restore_extended: r%ld\n", reg); |
c47d488e DD |
8209 | fc->col_type[reg] = cie->col_type[reg]; |
8210 | fc->col_offset[reg] = cie->col_offset[reg]; | |
8211 | break; | |
8212 | ||
8213 | case DW_CFA_undefined: | |
8214 | reg = LEB (); | |
31b6fca6 | 8215 | if (! do_debug_frames_interp) |
7036c0e1 | 8216 | printf (" DW_CFA_undefined: r%ld\n", reg); |
c47d488e DD |
8217 | fc->col_type[reg] = DW_CFA_undefined; |
8218 | fc->col_offset[reg] = 0; | |
8219 | break; | |
8220 | ||
8221 | case DW_CFA_same_value: | |
8222 | reg = LEB (); | |
31b6fca6 | 8223 | if (! do_debug_frames_interp) |
7036c0e1 | 8224 | printf (" DW_CFA_same_value: r%ld\n", reg); |
c47d488e DD |
8225 | fc->col_type[reg] = DW_CFA_same_value; |
8226 | fc->col_offset[reg] = 0; | |
8227 | break; | |
8228 | ||
8229 | case DW_CFA_register: | |
8230 | reg = LEB (); | |
8231 | roffs = LEB (); | |
31b6fca6 | 8232 | if (! do_debug_frames_interp) |
7036c0e1 | 8233 | printf (" DW_CFA_register: r%ld\n", reg); |
c47d488e DD |
8234 | fc->col_type[reg] = DW_CFA_register; |
8235 | fc->col_offset[reg] = roffs; | |
8236 | break; | |
8237 | ||
8238 | case DW_CFA_remember_state: | |
31b6fca6 RH |
8239 | if (! do_debug_frames_interp) |
8240 | printf (" DW_CFA_remember_state\n"); | |
c47d488e DD |
8241 | rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); |
8242 | rs->ncols = fc->ncols; | |
a98cc2b2 | 8243 | rs->col_type = (short int *) xmalloc (rs->ncols * sizeof (short int)); |
c47d488e DD |
8244 | rs->col_offset = (int *) xmalloc (rs->ncols * sizeof (int)); |
8245 | memcpy (rs->col_type, fc->col_type, rs->ncols); | |
8246 | memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (int)); | |
8247 | rs->next = remembered_state; | |
8248 | remembered_state = rs; | |
8249 | break; | |
8250 | ||
8251 | case DW_CFA_restore_state: | |
31b6fca6 RH |
8252 | if (! do_debug_frames_interp) |
8253 | printf (" DW_CFA_restore_state\n"); | |
c47d488e DD |
8254 | rs = remembered_state; |
8255 | remembered_state = rs->next; | |
8256 | frame_need_space (fc, rs->ncols-1); | |
8257 | memcpy (fc->col_type, rs->col_type, rs->ncols); | |
8258 | memcpy (fc->col_offset, rs->col_offset, rs->ncols * sizeof (int)); | |
8259 | free (rs->col_type); | |
8260 | free (rs->col_offset); | |
8261 | free (rs); | |
8262 | break; | |
8263 | ||
8264 | case DW_CFA_def_cfa: | |
8265 | fc->cfa_reg = LEB (); | |
8266 | fc->cfa_offset = LEB (); | |
31b6fca6 RH |
8267 | if (! do_debug_frames_interp) |
8268 | printf (" DW_CFA_def_cfa: r%d ofs %d\n", | |
8269 | fc->cfa_reg, fc->cfa_offset); | |
c47d488e DD |
8270 | break; |
8271 | ||
8272 | case DW_CFA_def_cfa_register: | |
8273 | fc->cfa_reg = LEB (); | |
31b6fca6 RH |
8274 | if (! do_debug_frames_interp) |
8275 | printf (" DW_CFA_def_cfa_reg: r%d\n", fc->cfa_reg); | |
c47d488e DD |
8276 | break; |
8277 | ||
8278 | case DW_CFA_def_cfa_offset: | |
8279 | fc->cfa_offset = LEB (); | |
31b6fca6 RH |
8280 | if (! do_debug_frames_interp) |
8281 | printf (" DW_CFA_def_cfa_offset: %d\n", fc->cfa_offset); | |
c47d488e DD |
8282 | break; |
8283 | ||
8284 | case DW_CFA_nop: | |
31b6fca6 RH |
8285 | if (! do_debug_frames_interp) |
8286 | printf (" DW_CFA_nop\n"); | |
c47d488e DD |
8287 | break; |
8288 | ||
8289 | #ifndef DW_CFA_GNU_window_save | |
8290 | #define DW_CFA_GNU_window_save 0x2d | |
8291 | #endif | |
8292 | case DW_CFA_GNU_window_save: | |
31b6fca6 RH |
8293 | if (! do_debug_frames_interp) |
8294 | printf (" DW_CFA_GNU_window_save\n"); | |
c47d488e DD |
8295 | break; |
8296 | ||
c47d488e DD |
8297 | case DW_CFA_GNU_args_size: |
8298 | ul = LEB (); | |
31b6fca6 | 8299 | if (! do_debug_frames_interp) |
7036c0e1 | 8300 | printf (" DW_CFA_GNU_args_size: %ld\n", ul); |
c47d488e DD |
8301 | break; |
8302 | ||
c47d488e DD |
8303 | case DW_CFA_GNU_negative_offset_extended: |
8304 | reg = LEB (); | |
8305 | l = - LEB (); | |
8306 | frame_need_space (fc, reg); | |
31b6fca6 | 8307 | if (! do_debug_frames_interp) |
7036c0e1 | 8308 | printf (" DW_CFA_GNU_negative_offset_extended: r%ld at cfa%+ld\n", |
31b6fca6 | 8309 | reg, l * fc->data_factor); |
c47d488e DD |
8310 | fc->col_type[reg] = DW_CFA_offset; |
8311 | fc->col_offset[reg] = l * fc->data_factor; | |
8312 | break; | |
8313 | ||
8314 | default: | |
8315 | fprintf (stderr, "unsupported or unknown DW_CFA_%d\n", op); | |
8316 | start = block_end; | |
8317 | } | |
8318 | } | |
8319 | ||
31b6fca6 RH |
8320 | if (do_debug_frames_interp) |
8321 | frame_display_row (fc, &need_col_headers, &max_regs); | |
c47d488e DD |
8322 | |
8323 | start = block_end; | |
8324 | } | |
8325 | ||
8326 | printf ("\n"); | |
8327 | ||
8328 | return 1; | |
8329 | } | |
8330 | ||
8331 | #undef GET | |
8332 | #undef LEB | |
8333 | #undef SLEB | |
252b5132 RH |
8334 | |
8335 | static int | |
8336 | display_debug_not_supported (section, start, file) | |
8337 | Elf32_Internal_Shdr * section; | |
b4c96d0d ILT |
8338 | unsigned char * start ATTRIBUTE_UNUSED; |
8339 | FILE * file ATTRIBUTE_UNUSED; | |
252b5132 RH |
8340 | { |
8341 | printf (_("Displaying the debug contents of section %s is not yet supported.\n"), | |
8342 | SECTION_NAME (section)); | |
8343 | ||
8344 | return 1; | |
8345 | } | |
8346 | ||
3590ea00 NC |
8347 | /* Pre-scan the .debug_info section to record the size of address. |
8348 | When dumping the .debug_line, we use that size information, assuming | |
8349 | that all compilation units have the same address size. */ | |
8350 | static int | |
8351 | prescan_debug_info (section, start, file) | |
8352 | Elf32_Internal_Shdr * section ATTRIBUTE_UNUSED; | |
8353 | unsigned char * start; | |
8354 | FILE * file ATTRIBUTE_UNUSED; | |
8355 | { | |
8356 | DWARF2_External_CompUnit * external; | |
8357 | ||
8358 | external = (DWARF2_External_CompUnit *) start; | |
8359 | ||
8360 | debug_line_pointer_size = BYTE_GET (external->cu_pointer_size); | |
8361 | return 0; | |
8362 | } | |
8363 | ||
252b5132 | 8364 | /* A structure containing the name of a debug section and a pointer |
3590ea00 NC |
8365 | to a function that can decode it. The third field is a prescan |
8366 | function to be run over the section before displaying any of the | |
8367 | sections. */ | |
252b5132 RH |
8368 | struct |
8369 | { | |
261a45ad | 8370 | const char * const name; |
3590ea00 NC |
8371 | int (* display) PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *)); |
8372 | int (* prescan) PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *)); | |
252b5132 RH |
8373 | } |
8374 | debug_displays[] = | |
8375 | { | |
3590ea00 | 8376 | { ".debug_abbrev", display_debug_abbrev, NULL }, |
3590ea00 | 8377 | { ".debug_aranges", display_debug_aranges, NULL }, |
c47d488e | 8378 | { ".debug_frame", display_debug_frames, NULL }, |
261a45ad NC |
8379 | { ".debug_info", display_debug_info, prescan_debug_info }, |
8380 | { ".debug_line", display_debug_lines, NULL }, | |
8381 | { ".debug_pubnames", display_debug_pubnames, NULL }, | |
c47d488e | 8382 | { ".eh_frame", display_debug_frames, NULL }, |
e0c60db2 | 8383 | { ".debug_macinfo", display_debug_macinfo, NULL }, |
261a45ad NC |
8384 | { ".debug_str", display_debug_str, NULL }, |
8385 | ||
428409d5 | 8386 | { ".debug_pubtypes", display_debug_not_supported, NULL }, |
261a45ad | 8387 | { ".debug_ranges", display_debug_not_supported, NULL }, |
3590ea00 NC |
8388 | { ".debug_static_func", display_debug_not_supported, NULL }, |
8389 | { ".debug_static_vars", display_debug_not_supported, NULL }, | |
8390 | { ".debug_types", display_debug_not_supported, NULL }, | |
8391 | { ".debug_weaknames", display_debug_not_supported, NULL } | |
252b5132 RH |
8392 | }; |
8393 | ||
8394 | static int | |
8395 | display_debug_section (section, file) | |
8396 | Elf32_Internal_Shdr * section; | |
8397 | FILE * file; | |
8398 | { | |
8399 | char * name = SECTION_NAME (section); | |
8400 | bfd_size_type length; | |
8401 | unsigned char * start; | |
8402 | int i; | |
8403 | ||
8404 | length = section->sh_size; | |
8405 | if (length == 0) | |
8406 | { | |
8407 | printf (_("\nSection '%s' has no debugging data.\n"), name); | |
8408 | return 0; | |
8409 | } | |
8410 | ||
0823fbca | 8411 | start = (unsigned char *) get_data (NULL, file, section->sh_offset, length, |
a6e9f9df AM |
8412 | _("debug section data")); |
8413 | if (!start) | |
8414 | return 0; | |
252b5132 RH |
8415 | |
8416 | /* See if we know how to display the contents of this section. */ | |
09fd7e38 | 8417 | if (strncmp (name, ".gnu.linkonce.wi.", 17) == 0) |
7036c0e1 | 8418 | name = ".debug_info"; |
584da044 | 8419 | |
252b5132 RH |
8420 | for (i = NUM_ELEM (debug_displays); i--;) |
8421 | if (strcmp (debug_displays[i].name, name) == 0) | |
8422 | { | |
8423 | debug_displays[i].display (section, start, file); | |
8424 | break; | |
8425 | } | |
8426 | ||
8427 | if (i == -1) | |
8428 | printf (_("Unrecognised debug section: %s\n"), name); | |
8429 | ||
8430 | free (start); | |
8431 | ||
8432 | /* If we loaded in the abbrev section at some point, | |
8433 | we must release it here. */ | |
261a45ad | 8434 | free_abbrevs (); |
252b5132 RH |
8435 | |
8436 | return 1; | |
8437 | } | |
8438 | ||
8439 | static int | |
8440 | process_section_contents (file) | |
8441 | FILE * file; | |
8442 | { | |
3590ea00 | 8443 | Elf32_Internal_Shdr * section; |
7036c0e1 | 8444 | unsigned int i; |
252b5132 RH |
8445 | |
8446 | if (! do_dump) | |
8447 | return 1; | |
8448 | ||
3590ea00 NC |
8449 | /* Pre-scan the debug sections to find some debug information not |
8450 | present in some of them. For the .debug_line, we must find out the | |
8451 | size of address (specified in .debug_info and .debug_aranges). */ | |
8452 | for (i = 0, section = section_headers; | |
8453 | i < elf_header.e_shnum && i < num_dump_sects; | |
8454 | i ++, section ++) | |
8455 | { | |
8456 | char * name = SECTION_NAME (section); | |
8457 | int j; | |
8458 | ||
8459 | if (section->sh_size == 0) | |
8460 | continue; | |
8461 | ||
8462 | /* See if there is some pre-scan operation for this section. */ | |
8463 | for (j = NUM_ELEM (debug_displays); j--;) | |
8464 | if (strcmp (debug_displays[j].name, name) == 0) | |
8465 | { | |
8466 | if (debug_displays[j].prescan != NULL) | |
8467 | { | |
8468 | bfd_size_type length; | |
8469 | unsigned char * start; | |
8470 | ||
8471 | length = section->sh_size; | |
a6e9f9df | 8472 | start = ((unsigned char *) |
0823fbca | 8473 | get_data (NULL, file, section->sh_offset, length, |
a6e9f9df AM |
8474 | _("debug section data"))); |
8475 | if (!start) | |
8476 | return 0; | |
3590ea00 NC |
8477 | |
8478 | debug_displays[j].prescan (section, start, file); | |
8479 | free (start); | |
8480 | } | |
103f02d3 | 8481 | |
3590ea00 NC |
8482 | break; |
8483 | } | |
8484 | } | |
8485 | ||
252b5132 | 8486 | for (i = 0, section = section_headers; |
3590ea00 | 8487 | i < elf_header.e_shnum && i < num_dump_sects; |
252b5132 RH |
8488 | i ++, section ++) |
8489 | { | |
8490 | #ifdef SUPPORT_DISASSEMBLY | |
8491 | if (dump_sects[i] & DISASS_DUMP) | |
8492 | disassemble_section (section, file); | |
8493 | #endif | |
8494 | if (dump_sects[i] & HEX_DUMP) | |
8495 | dump_section (section, file); | |
8496 | ||
8497 | if (dump_sects[i] & DEBUG_DUMP) | |
8498 | display_debug_section (section, file); | |
8499 | } | |
8500 | ||
8501 | if (i < num_dump_sects) | |
8502 | warn (_("Some sections were not dumped because they do not exist!\n")); | |
8503 | ||
8504 | return 1; | |
8505 | } | |
8506 | ||
8507 | static void | |
8508 | process_mips_fpe_exception (mask) | |
8509 | int mask; | |
8510 | { | |
8511 | if (mask) | |
8512 | { | |
8513 | int first = 1; | |
8514 | if (mask & OEX_FPU_INEX) | |
8515 | fputs ("INEX", stdout), first = 0; | |
8516 | if (mask & OEX_FPU_UFLO) | |
8517 | printf ("%sUFLO", first ? "" : "|"), first = 0; | |
8518 | if (mask & OEX_FPU_OFLO) | |
8519 | printf ("%sOFLO", first ? "" : "|"), first = 0; | |
8520 | if (mask & OEX_FPU_DIV0) | |
8521 | printf ("%sDIV0", first ? "" : "|"), first = 0; | |
8522 | if (mask & OEX_FPU_INVAL) | |
8523 | printf ("%sINVAL", first ? "" : "|"); | |
8524 | } | |
8525 | else | |
8526 | fputs ("0", stdout); | |
8527 | } | |
8528 | ||
8529 | static int | |
8530 | process_mips_specific (file) | |
9ea033b2 | 8531 | FILE * file; |
252b5132 | 8532 | { |
9ea033b2 | 8533 | Elf_Internal_Dyn * entry; |
252b5132 RH |
8534 | size_t liblist_offset = 0; |
8535 | size_t liblistno = 0; | |
8536 | size_t conflictsno = 0; | |
8537 | size_t options_offset = 0; | |
8538 | size_t conflicts_offset = 0; | |
8539 | ||
8540 | /* We have a lot of special sections. Thanks SGI! */ | |
8541 | if (dynamic_segment == NULL) | |
8542 | /* No information available. */ | |
8543 | return 0; | |
8544 | ||
8545 | for (entry = dynamic_segment; entry->d_tag != DT_NULL; ++entry) | |
8546 | switch (entry->d_tag) | |
8547 | { | |
8548 | case DT_MIPS_LIBLIST: | |
8549 | liblist_offset = entry->d_un.d_val - loadaddr; | |
8550 | break; | |
8551 | case DT_MIPS_LIBLISTNO: | |
8552 | liblistno = entry->d_un.d_val; | |
8553 | break; | |
8554 | case DT_MIPS_OPTIONS: | |
8555 | options_offset = entry->d_un.d_val - loadaddr; | |
8556 | break; | |
8557 | case DT_MIPS_CONFLICT: | |
8558 | conflicts_offset = entry->d_un.d_val - loadaddr; | |
8559 | break; | |
8560 | case DT_MIPS_CONFLICTNO: | |
8561 | conflictsno = entry->d_un.d_val; | |
8562 | break; | |
8563 | default: | |
8564 | break; | |
8565 | } | |
8566 | ||
8567 | if (liblist_offset != 0 && liblistno != 0 && do_dynamic) | |
8568 | { | |
9ea033b2 | 8569 | Elf32_External_Lib * elib; |
252b5132 RH |
8570 | size_t cnt; |
8571 | ||
a6e9f9df AM |
8572 | elib = ((Elf32_External_Lib *) |
8573 | get_data (NULL, file, liblist_offset, | |
8574 | liblistno * sizeof (Elf32_External_Lib), | |
8575 | _("liblist"))); | |
8576 | if (elib) | |
252b5132 | 8577 | { |
a6e9f9df AM |
8578 | printf ("\nSection '.liblist' contains %lu entries:\n", |
8579 | (unsigned long) liblistno); | |
8580 | fputs (" Library Time Stamp Checksum Version Flags\n", | |
8581 | stdout); | |
8582 | ||
8583 | for (cnt = 0; cnt < liblistno; ++cnt) | |
252b5132 | 8584 | { |
a6e9f9df AM |
8585 | Elf32_Lib liblist; |
8586 | time_t time; | |
8587 | char timebuf[20]; | |
8588 | struct tm * tmp; | |
8589 | ||
8590 | liblist.l_name = BYTE_GET (elib[cnt].l_name); | |
8591 | time = BYTE_GET (elib[cnt].l_time_stamp); | |
8592 | liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum); | |
8593 | liblist.l_version = BYTE_GET (elib[cnt].l_version); | |
8594 | liblist.l_flags = BYTE_GET (elib[cnt].l_flags); | |
8595 | ||
8596 | tmp = gmtime (&time); | |
8597 | sprintf (timebuf, "%04u-%02u-%02uT%02u:%02u:%02u", | |
8598 | tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday, | |
8599 | tmp->tm_hour, tmp->tm_min, tmp->tm_sec); | |
8600 | ||
8601 | printf ("%3lu: %-20s %s %#10lx %-7ld", (unsigned long) cnt, | |
8602 | dynamic_strings + liblist.l_name, timebuf, | |
8603 | liblist.l_checksum, liblist.l_version); | |
8604 | ||
8605 | if (liblist.l_flags == 0) | |
8606 | puts (" NONE"); | |
8607 | else | |
8608 | { | |
8609 | static const struct | |
252b5132 | 8610 | { |
a6e9f9df AM |
8611 | const char * name; |
8612 | int bit; | |
252b5132 | 8613 | } |
a6e9f9df AM |
8614 | l_flags_vals[] = |
8615 | { | |
8616 | { " EXACT_MATCH", LL_EXACT_MATCH }, | |
8617 | { " IGNORE_INT_VER", LL_IGNORE_INT_VER }, | |
8618 | { " REQUIRE_MINOR", LL_REQUIRE_MINOR }, | |
8619 | { " EXPORTS", LL_EXPORTS }, | |
8620 | { " DELAY_LOAD", LL_DELAY_LOAD }, | |
8621 | { " DELTA", LL_DELTA } | |
8622 | }; | |
8623 | int flags = liblist.l_flags; | |
8624 | size_t fcnt; | |
8625 | ||
8626 | for (fcnt = 0; | |
8627 | fcnt < sizeof (l_flags_vals) / sizeof (l_flags_vals[0]); | |
8628 | ++fcnt) | |
8629 | if ((flags & l_flags_vals[fcnt].bit) != 0) | |
8630 | { | |
8631 | fputs (l_flags_vals[fcnt].name, stdout); | |
8632 | flags ^= l_flags_vals[fcnt].bit; | |
8633 | } | |
8634 | if (flags != 0) | |
8635 | printf (" %#x", (unsigned int) flags); | |
252b5132 | 8636 | |
a6e9f9df AM |
8637 | puts (""); |
8638 | } | |
252b5132 | 8639 | } |
252b5132 | 8640 | |
a6e9f9df AM |
8641 | free (elib); |
8642 | } | |
252b5132 RH |
8643 | } |
8644 | ||
8645 | if (options_offset != 0) | |
8646 | { | |
9ea033b2 | 8647 | Elf_External_Options * eopt; |
d1133906 | 8648 | Elf_Internal_Shdr * sect = section_headers; |
9ea033b2 NC |
8649 | Elf_Internal_Options * iopt; |
8650 | Elf_Internal_Options * option; | |
252b5132 RH |
8651 | size_t offset; |
8652 | int cnt; | |
8653 | ||
8654 | /* Find the section header so that we get the size. */ | |
8655 | while (sect->sh_type != SHT_MIPS_OPTIONS) | |
d1133906 | 8656 | ++ sect; |
252b5132 | 8657 | |
a6e9f9df AM |
8658 | eopt = (Elf_External_Options *) get_data (NULL, file, options_offset, |
8659 | sect->sh_size, _("options")); | |
8660 | if (eopt) | |
252b5132 | 8661 | { |
a6e9f9df AM |
8662 | iopt = ((Elf_Internal_Options *) |
8663 | malloc ((sect->sh_size / sizeof (eopt)) * sizeof (* iopt))); | |
8664 | if (iopt == NULL) | |
8665 | { | |
8666 | error (_("Out of memory")); | |
8667 | return 0; | |
8668 | } | |
76da6bbe | 8669 | |
a6e9f9df AM |
8670 | offset = cnt = 0; |
8671 | option = iopt; | |
252b5132 | 8672 | |
a6e9f9df AM |
8673 | while (offset < sect->sh_size) |
8674 | { | |
8675 | Elf_External_Options * eoption; | |
252b5132 | 8676 | |
a6e9f9df | 8677 | eoption = (Elf_External_Options *) ((char *) eopt + offset); |
252b5132 | 8678 | |
a6e9f9df AM |
8679 | option->kind = BYTE_GET (eoption->kind); |
8680 | option->size = BYTE_GET (eoption->size); | |
8681 | option->section = BYTE_GET (eoption->section); | |
8682 | option->info = BYTE_GET (eoption->info); | |
76da6bbe | 8683 | |
a6e9f9df | 8684 | offset += option->size; |
252b5132 | 8685 | |
a6e9f9df AM |
8686 | ++option; |
8687 | ++cnt; | |
8688 | } | |
252b5132 | 8689 | |
a6e9f9df AM |
8690 | printf (_("\nSection '%s' contains %d entries:\n"), |
8691 | SECTION_NAME (sect), cnt); | |
76da6bbe | 8692 | |
a6e9f9df | 8693 | option = iopt; |
252b5132 | 8694 | |
a6e9f9df | 8695 | while (cnt-- > 0) |
252b5132 | 8696 | { |
a6e9f9df AM |
8697 | size_t len; |
8698 | ||
8699 | switch (option->kind) | |
252b5132 | 8700 | { |
a6e9f9df AM |
8701 | case ODK_NULL: |
8702 | /* This shouldn't happen. */ | |
8703 | printf (" NULL %d %lx", option->section, option->info); | |
8704 | break; | |
8705 | case ODK_REGINFO: | |
8706 | printf (" REGINFO "); | |
8707 | if (elf_header.e_machine == EM_MIPS) | |
8708 | { | |
8709 | /* 32bit form. */ | |
8710 | Elf32_External_RegInfo * ereg; | |
8711 | Elf32_RegInfo reginfo; | |
8712 | ||
8713 | ereg = (Elf32_External_RegInfo *) (option + 1); | |
8714 | reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask); | |
8715 | reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]); | |
8716 | reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]); | |
8717 | reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]); | |
8718 | reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]); | |
8719 | reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value); | |
8720 | ||
8721 | printf ("GPR %08lx GP 0x%lx\n", | |
8722 | reginfo.ri_gprmask, | |
8723 | (unsigned long) reginfo.ri_gp_value); | |
8724 | printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n", | |
8725 | reginfo.ri_cprmask[0], reginfo.ri_cprmask[1], | |
8726 | reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]); | |
8727 | } | |
8728 | else | |
8729 | { | |
8730 | /* 64 bit form. */ | |
8731 | Elf64_External_RegInfo * ereg; | |
8732 | Elf64_Internal_RegInfo reginfo; | |
8733 | ||
8734 | ereg = (Elf64_External_RegInfo *) (option + 1); | |
8735 | reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask); | |
8736 | reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]); | |
8737 | reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]); | |
8738 | reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]); | |
8739 | reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]); | |
8740 | reginfo.ri_gp_value = BYTE_GET8 (ereg->ri_gp_value); | |
8741 | ||
8742 | printf ("GPR %08lx GP 0x", | |
8743 | reginfo.ri_gprmask); | |
8744 | printf_vma (reginfo.ri_gp_value); | |
8745 | printf ("\n"); | |
8746 | ||
8747 | printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n", | |
8748 | reginfo.ri_cprmask[0], reginfo.ri_cprmask[1], | |
8749 | reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]); | |
8750 | } | |
8751 | ++option; | |
8752 | continue; | |
8753 | case ODK_EXCEPTIONS: | |
8754 | fputs (" EXCEPTIONS fpe_min(", stdout); | |
8755 | process_mips_fpe_exception (option->info & OEX_FPU_MIN); | |
8756 | fputs (") fpe_max(", stdout); | |
8757 | process_mips_fpe_exception ((option->info & OEX_FPU_MAX) >> 8); | |
8758 | fputs (")", stdout); | |
8759 | ||
8760 | if (option->info & OEX_PAGE0) | |
8761 | fputs (" PAGE0", stdout); | |
8762 | if (option->info & OEX_SMM) | |
8763 | fputs (" SMM", stdout); | |
8764 | if (option->info & OEX_FPDBUG) | |
8765 | fputs (" FPDBUG", stdout); | |
8766 | if (option->info & OEX_DISMISS) | |
8767 | fputs (" DISMISS", stdout); | |
8768 | break; | |
8769 | case ODK_PAD: | |
8770 | fputs (" PAD ", stdout); | |
8771 | if (option->info & OPAD_PREFIX) | |
8772 | fputs (" PREFIX", stdout); | |
8773 | if (option->info & OPAD_POSTFIX) | |
8774 | fputs (" POSTFIX", stdout); | |
8775 | if (option->info & OPAD_SYMBOL) | |
8776 | fputs (" SYMBOL", stdout); | |
8777 | break; | |
8778 | case ODK_HWPATCH: | |
8779 | fputs (" HWPATCH ", stdout); | |
8780 | if (option->info & OHW_R4KEOP) | |
8781 | fputs (" R4KEOP", stdout); | |
8782 | if (option->info & OHW_R8KPFETCH) | |
8783 | fputs (" R8KPFETCH", stdout); | |
8784 | if (option->info & OHW_R5KEOP) | |
8785 | fputs (" R5KEOP", stdout); | |
8786 | if (option->info & OHW_R5KCVTL) | |
8787 | fputs (" R5KCVTL", stdout); | |
8788 | break; | |
8789 | case ODK_FILL: | |
8790 | fputs (" FILL ", stdout); | |
8791 | /* XXX Print content of info word? */ | |
8792 | break; | |
8793 | case ODK_TAGS: | |
8794 | fputs (" TAGS ", stdout); | |
8795 | /* XXX Print content of info word? */ | |
8796 | break; | |
8797 | case ODK_HWAND: | |
8798 | fputs (" HWAND ", stdout); | |
8799 | if (option->info & OHWA0_R4KEOP_CHECKED) | |
8800 | fputs (" R4KEOP_CHECKED", stdout); | |
8801 | if (option->info & OHWA0_R4KEOP_CLEAN) | |
8802 | fputs (" R4KEOP_CLEAN", stdout); | |
8803 | break; | |
8804 | case ODK_HWOR: | |
8805 | fputs (" HWOR ", stdout); | |
8806 | if (option->info & OHWA0_R4KEOP_CHECKED) | |
8807 | fputs (" R4KEOP_CHECKED", stdout); | |
8808 | if (option->info & OHWA0_R4KEOP_CLEAN) | |
8809 | fputs (" R4KEOP_CLEAN", stdout); | |
8810 | break; | |
8811 | case ODK_GP_GROUP: | |
8812 | printf (" GP_GROUP %#06lx self-contained %#06lx", | |
8813 | option->info & OGP_GROUP, | |
8814 | (option->info & OGP_SELF) >> 16); | |
8815 | break; | |
8816 | case ODK_IDENT: | |
8817 | printf (" IDENT %#06lx self-contained %#06lx", | |
8818 | option->info & OGP_GROUP, | |
8819 | (option->info & OGP_SELF) >> 16); | |
8820 | break; | |
8821 | default: | |
8822 | /* This shouldn't happen. */ | |
8823 | printf (" %3d ??? %d %lx", | |
8824 | option->kind, option->section, option->info); | |
8825 | break; | |
252b5132 | 8826 | } |
a6e9f9df AM |
8827 | |
8828 | len = sizeof (* eopt); | |
8829 | while (len < option->size) | |
8830 | if (((char *) option)[len] >= ' ' | |
8831 | && ((char *) option)[len] < 0x7f) | |
8832 | printf ("%c", ((char *) option)[len++]); | |
8833 | else | |
8834 | printf ("\\%03o", ((char *) option)[len++]); | |
8835 | ||
8836 | fputs ("\n", stdout); | |
252b5132 | 8837 | ++option; |
252b5132 RH |
8838 | } |
8839 | ||
a6e9f9df | 8840 | free (eopt); |
252b5132 | 8841 | } |
252b5132 RH |
8842 | } |
8843 | ||
8844 | if (conflicts_offset != 0 && conflictsno != 0) | |
8845 | { | |
9ea033b2 | 8846 | Elf32_Conflict * iconf; |
252b5132 RH |
8847 | size_t cnt; |
8848 | ||
8849 | if (dynamic_symbols == NULL) | |
8850 | { | |
8851 | error (_("conflict list with without table")); | |
8852 | return 0; | |
8853 | } | |
8854 | ||
584da044 | 8855 | iconf = (Elf32_Conflict *) malloc (conflictsno * sizeof (* iconf)); |
252b5132 RH |
8856 | if (iconf == NULL) |
8857 | { | |
8858 | error (_("Out of memory")); | |
8859 | return 0; | |
8860 | } | |
8861 | ||
9ea033b2 | 8862 | if (is_32bit_elf) |
252b5132 | 8863 | { |
a6e9f9df AM |
8864 | Elf32_External_Conflict * econf32; |
8865 | ||
8866 | econf32 = ((Elf32_External_Conflict *) | |
8867 | get_data (NULL, file, conflicts_offset, | |
8868 | conflictsno * sizeof (* econf32), | |
8869 | _("conflict"))); | |
8870 | if (!econf32) | |
8871 | return 0; | |
252b5132 RH |
8872 | |
8873 | for (cnt = 0; cnt < conflictsno; ++cnt) | |
8874 | iconf[cnt] = BYTE_GET (econf32[cnt]); | |
a6e9f9df AM |
8875 | |
8876 | free (econf32); | |
252b5132 RH |
8877 | } |
8878 | else | |
8879 | { | |
a6e9f9df AM |
8880 | Elf64_External_Conflict * econf64; |
8881 | ||
8882 | econf64 = ((Elf64_External_Conflict *) | |
8883 | get_data (NULL, file, conflicts_offset, | |
8884 | conflictsno * sizeof (* econf64), | |
8885 | _("conflict"))); | |
8886 | if (!econf64) | |
8887 | return 0; | |
252b5132 RH |
8888 | |
8889 | for (cnt = 0; cnt < conflictsno; ++cnt) | |
8890 | iconf[cnt] = BYTE_GET (econf64[cnt]); | |
a6e9f9df AM |
8891 | |
8892 | free (econf64); | |
252b5132 RH |
8893 | } |
8894 | ||
410f7a12 L |
8895 | printf (_("\nSection '.conflict' contains %ld entries:\n"), |
8896 | (long) conflictsno); | |
252b5132 RH |
8897 | puts (_(" Num: Index Value Name")); |
8898 | ||
8899 | for (cnt = 0; cnt < conflictsno; ++cnt) | |
8900 | { | |
19936277 | 8901 | Elf_Internal_Sym * psym = &dynamic_symbols[iconf[cnt]]; |
252b5132 | 8902 | |
16062207 | 8903 | printf ("%5lu: %8lu ", (unsigned long) cnt, iconf[cnt]); |
f7a99963 NC |
8904 | print_vma (psym->st_value, FULL_HEX); |
8905 | printf (" %s\n", dynamic_strings + psym->st_name); | |
252b5132 RH |
8906 | } |
8907 | ||
252b5132 RH |
8908 | free (iconf); |
8909 | } | |
8910 | ||
8911 | return 1; | |
8912 | } | |
8913 | ||
779fe533 NC |
8914 | static char * |
8915 | get_note_type (e_type) | |
8916 | unsigned e_type; | |
8917 | { | |
8918 | static char buff[64]; | |
103f02d3 | 8919 | |
779fe533 NC |
8920 | switch (e_type) |
8921 | { | |
8922 | case NT_PRSTATUS: return _("NT_PRSTATUS (prstatus structure)"); | |
8923 | case NT_FPREGSET: return _("NT_FPREGSET (floating point registers)"); | |
8924 | case NT_PRPSINFO: return _("NT_PRPSINFO (prpsinfo structure)"); | |
8925 | case NT_TASKSTRUCT: return _("NT_TASKSTRUCT (task structure)"); | |
d1133906 | 8926 | case NT_PRXFPREG: return _("NT_PRXFPREG (user_xfpregs structure)"); |
779fe533 NC |
8927 | case NT_PSTATUS: return _("NT_PSTATUS (pstatus structure)"); |
8928 | case NT_FPREGS: return _("NT_FPREGS (floating point registers)"); | |
8929 | case NT_PSINFO: return _("NT_PSINFO (psinfo structure)"); | |
8930 | case NT_LWPSTATUS: return _("NT_LWPSTATUS (lwpstatus_t structure)"); | |
8931 | case NT_LWPSINFO: return _("NT_LWPSINFO (lwpsinfo_t structure)"); | |
7bea2f73 | 8932 | case NT_WIN32PSTATUS: return _("NT_WIN32PSTATUS (win32_pstatus strcuture)"); |
779fe533 NC |
8933 | default: |
8934 | sprintf (buff, _("Unknown note type: (0x%08x)"), e_type); | |
8935 | return buff; | |
8936 | } | |
8937 | } | |
8938 | ||
6d118b09 NC |
8939 | /* Note that by the ELF standard, the name field is already null byte |
8940 | terminated, and namesz includes the terminating null byte. | |
8941 | I.E. the value of namesz for the name "FSF" is 4. | |
8942 | ||
e3c8793a | 8943 | If the value of namesz is zero, there is no name present. */ |
779fe533 NC |
8944 | static int |
8945 | process_note (pnote) | |
6d118b09 | 8946 | Elf32_Internal_Note * pnote; |
779fe533 | 8947 | { |
103f02d3 | 8948 | printf (" %s\t\t0x%08lx\t%s\n", |
6d118b09 | 8949 | pnote->namesz ? pnote->namedata : "(NONE)", |
7036c0e1 | 8950 | pnote->descsz, get_note_type (pnote->type)); |
779fe533 NC |
8951 | return 1; |
8952 | } | |
8953 | ||
6d118b09 | 8954 | |
779fe533 NC |
8955 | static int |
8956 | process_corefile_note_segment (file, offset, length) | |
8957 | FILE * file; | |
f7a99963 NC |
8958 | bfd_vma offset; |
8959 | bfd_vma length; | |
779fe533 NC |
8960 | { |
8961 | Elf_External_Note * pnotes; | |
8962 | Elf_External_Note * external; | |
779fe533 | 8963 | int res = 1; |
103f02d3 | 8964 | |
779fe533 NC |
8965 | if (length <= 0) |
8966 | return 0; | |
103f02d3 | 8967 | |
a6e9f9df AM |
8968 | pnotes = (Elf_External_Note *) get_data (NULL, file, offset, length, |
8969 | _("notes")); | |
8970 | if (!pnotes) | |
8971 | return 0; | |
779fe533 | 8972 | |
103f02d3 | 8973 | external = pnotes; |
103f02d3 | 8974 | |
305c7206 | 8975 | printf (_("\nNotes at offset 0x%08lx with length 0x%08lx:\n"), |
f3485b74 | 8976 | (unsigned long) offset, (unsigned long) length); |
779fe533 | 8977 | printf (_(" Owner\t\tData size\tDescription\n")); |
103f02d3 | 8978 | |
6d118b09 | 8979 | while (external < (Elf_External_Note *)((char *) pnotes + length)) |
779fe533 | 8980 | { |
6d118b09 NC |
8981 | Elf32_Internal_Note inote; |
8982 | char * temp = NULL; | |
8983 | ||
8984 | inote.type = BYTE_GET (external->type); | |
8985 | inote.namesz = BYTE_GET (external->namesz); | |
8986 | inote.namedata = external->name; | |
8987 | inote.descsz = BYTE_GET (external->descsz); | |
8988 | inote.descdata = inote.namedata + align_power (inote.namesz, 2); | |
8989 | inote.descpos = offset + (inote.descdata - (char *) pnotes); | |
76da6bbe | 8990 | |
6d118b09 NC |
8991 | external = (Elf_External_Note *)(inote.descdata + align_power (inote.descsz, 2)); |
8992 | ||
8993 | /* Verify that name is null terminated. It appears that at least | |
8994 | one version of Linux (RedHat 6.0) generates corefiles that don't | |
8995 | comply with the ELF spec by failing to include the null byte in | |
8996 | namesz. */ | |
8997 | if (inote.namedata[inote.namesz] != '\0') | |
8998 | { | |
8999 | temp = malloc (inote.namesz + 1); | |
76da6bbe | 9000 | |
6d118b09 NC |
9001 | if (temp == NULL) |
9002 | { | |
9003 | error (_("Out of memory\n")); | |
9004 | res = 0; | |
9005 | break; | |
9006 | } | |
76da6bbe | 9007 | |
6d118b09 NC |
9008 | strncpy (temp, inote.namedata, inote.namesz); |
9009 | temp[inote.namesz] = 0; | |
76da6bbe | 9010 | |
6d118b09 NC |
9011 | /* warn (_("'%s' NOTE name not properly null terminated\n"), temp); */ |
9012 | inote.namedata = temp; | |
9013 | } | |
9014 | ||
9015 | res &= process_note (& inote); | |
103f02d3 | 9016 | |
6d118b09 NC |
9017 | if (temp != NULL) |
9018 | { | |
9019 | free (temp); | |
9020 | temp = NULL; | |
9021 | } | |
779fe533 NC |
9022 | } |
9023 | ||
9024 | free (pnotes); | |
103f02d3 | 9025 | |
779fe533 NC |
9026 | return res; |
9027 | } | |
9028 | ||
9029 | static int | |
9030 | process_corefile_note_segments (file) | |
9031 | FILE * file; | |
9032 | { | |
9033 | Elf_Internal_Phdr * program_headers; | |
9034 | Elf_Internal_Phdr * segment; | |
9035 | unsigned int i; | |
9036 | int res = 1; | |
103f02d3 | 9037 | |
779fe533 NC |
9038 | program_headers = (Elf_Internal_Phdr *) malloc |
9039 | (elf_header.e_phnum * sizeof (Elf_Internal_Phdr)); | |
9040 | ||
9041 | if (program_headers == NULL) | |
9042 | { | |
9043 | error (_("Out of memory\n")); | |
9044 | return 0; | |
9045 | } | |
9046 | ||
9047 | if (is_32bit_elf) | |
9048 | i = get_32bit_program_headers (file, program_headers); | |
9049 | else | |
9050 | i = get_64bit_program_headers (file, program_headers); | |
9051 | ||
9052 | if (i == 0) | |
9053 | { | |
9054 | free (program_headers); | |
9055 | return 0; | |
9056 | } | |
103f02d3 | 9057 | |
779fe533 NC |
9058 | for (i = 0, segment = program_headers; |
9059 | i < elf_header.e_phnum; | |
9060 | i ++, segment ++) | |
9061 | { | |
9062 | if (segment->p_type == PT_NOTE) | |
103f02d3 | 9063 | res &= process_corefile_note_segment (file, |
30800947 NC |
9064 | (bfd_vma) segment->p_offset, |
9065 | (bfd_vma) segment->p_filesz); | |
779fe533 | 9066 | } |
103f02d3 | 9067 | |
779fe533 NC |
9068 | free (program_headers); |
9069 | ||
9070 | return res; | |
9071 | } | |
9072 | ||
9073 | static int | |
9074 | process_corefile_contents (file) | |
9075 | FILE * file; | |
9076 | { | |
9077 | /* If we have not been asked to display the notes then do nothing. */ | |
9078 | if (! do_notes) | |
9079 | return 1; | |
103f02d3 | 9080 | |
779fe533 NC |
9081 | /* If file is not a core file then exit. */ |
9082 | if (elf_header.e_type != ET_CORE) | |
9083 | return 1; | |
103f02d3 | 9084 | |
779fe533 NC |
9085 | /* No program headers means no NOTE segment. */ |
9086 | if (elf_header.e_phnum == 0) | |
9087 | { | |
9088 | printf (_("No note segments present in the core file.\n")); | |
9089 | return 1; | |
9090 | } | |
9091 | ||
9092 | return process_corefile_note_segments (file); | |
9093 | } | |
9094 | ||
252b5132 RH |
9095 | static int |
9096 | process_arch_specific (file) | |
9ea033b2 | 9097 | FILE * file; |
252b5132 | 9098 | { |
a952a375 NC |
9099 | if (! do_arch) |
9100 | return 1; | |
9101 | ||
252b5132 RH |
9102 | switch (elf_header.e_machine) |
9103 | { | |
9104 | case EM_MIPS: | |
4fe85591 | 9105 | case EM_MIPS_RS3_LE: |
252b5132 RH |
9106 | return process_mips_specific (file); |
9107 | break; | |
9108 | default: | |
9109 | break; | |
9110 | } | |
9111 | return 1; | |
9112 | } | |
9113 | ||
9114 | static int | |
9115 | get_file_header (file) | |
9116 | FILE * file; | |
9117 | { | |
9ea033b2 NC |
9118 | /* Read in the identity array. */ |
9119 | if (fread (elf_header.e_ident, EI_NIDENT, 1, file) != 1) | |
252b5132 RH |
9120 | return 0; |
9121 | ||
9ea033b2 NC |
9122 | /* Determine how to read the rest of the header. */ |
9123 | switch (elf_header.e_ident [EI_DATA]) | |
9124 | { | |
9125 | default: /* fall through */ | |
9126 | case ELFDATANONE: /* fall through */ | |
9127 | case ELFDATA2LSB: byte_get = byte_get_little_endian; break; | |
9128 | case ELFDATA2MSB: byte_get = byte_get_big_endian; break; | |
9129 | } | |
9130 | ||
9131 | /* For now we only support 32 bit and 64 bit ELF files. */ | |
9132 | is_32bit_elf = (elf_header.e_ident [EI_CLASS] != ELFCLASS64); | |
9133 | ||
9134 | /* Read in the rest of the header. */ | |
9135 | if (is_32bit_elf) | |
9136 | { | |
9137 | Elf32_External_Ehdr ehdr32; | |
252b5132 | 9138 | |
9ea033b2 NC |
9139 | if (fread (ehdr32.e_type, sizeof (ehdr32) - EI_NIDENT, 1, file) != 1) |
9140 | return 0; | |
103f02d3 | 9141 | |
9ea033b2 NC |
9142 | elf_header.e_type = BYTE_GET (ehdr32.e_type); |
9143 | elf_header.e_machine = BYTE_GET (ehdr32.e_machine); | |
9144 | elf_header.e_version = BYTE_GET (ehdr32.e_version); | |
9145 | elf_header.e_entry = BYTE_GET (ehdr32.e_entry); | |
9146 | elf_header.e_phoff = BYTE_GET (ehdr32.e_phoff); | |
9147 | elf_header.e_shoff = BYTE_GET (ehdr32.e_shoff); | |
9148 | elf_header.e_flags = BYTE_GET (ehdr32.e_flags); | |
9149 | elf_header.e_ehsize = BYTE_GET (ehdr32.e_ehsize); | |
9150 | elf_header.e_phentsize = BYTE_GET (ehdr32.e_phentsize); | |
9151 | elf_header.e_phnum = BYTE_GET (ehdr32.e_phnum); | |
9152 | elf_header.e_shentsize = BYTE_GET (ehdr32.e_shentsize); | |
9153 | elf_header.e_shnum = BYTE_GET (ehdr32.e_shnum); | |
9154 | elf_header.e_shstrndx = BYTE_GET (ehdr32.e_shstrndx); | |
9155 | } | |
252b5132 | 9156 | else |
9ea033b2 NC |
9157 | { |
9158 | Elf64_External_Ehdr ehdr64; | |
a952a375 NC |
9159 | |
9160 | /* If we have been compiled with sizeof (bfd_vma) == 4, then | |
9161 | we will not be able to cope with the 64bit data found in | |
9162 | 64 ELF files. Detect this now and abort before we start | |
9163 | overwritting things. */ | |
9164 | if (sizeof (bfd_vma) < 8) | |
9165 | { | |
e3c8793a NC |
9166 | error (_("This instance of readelf has been built without support for a\n\ |
9167 | 64 bit data type and so it cannot read 64 bit ELF files.\n")); | |
a952a375 NC |
9168 | return 0; |
9169 | } | |
103f02d3 | 9170 | |
9ea033b2 NC |
9171 | if (fread (ehdr64.e_type, sizeof (ehdr64) - EI_NIDENT, 1, file) != 1) |
9172 | return 0; | |
103f02d3 | 9173 | |
9ea033b2 NC |
9174 | elf_header.e_type = BYTE_GET (ehdr64.e_type); |
9175 | elf_header.e_machine = BYTE_GET (ehdr64.e_machine); | |
9176 | elf_header.e_version = BYTE_GET (ehdr64.e_version); | |
9177 | elf_header.e_entry = BYTE_GET8 (ehdr64.e_entry); | |
9178 | elf_header.e_phoff = BYTE_GET8 (ehdr64.e_phoff); | |
9179 | elf_header.e_shoff = BYTE_GET8 (ehdr64.e_shoff); | |
9180 | elf_header.e_flags = BYTE_GET (ehdr64.e_flags); | |
9181 | elf_header.e_ehsize = BYTE_GET (ehdr64.e_ehsize); | |
9182 | elf_header.e_phentsize = BYTE_GET (ehdr64.e_phentsize); | |
9183 | elf_header.e_phnum = BYTE_GET (ehdr64.e_phnum); | |
9184 | elf_header.e_shentsize = BYTE_GET (ehdr64.e_shentsize); | |
9185 | elf_header.e_shnum = BYTE_GET (ehdr64.e_shnum); | |
9186 | elf_header.e_shstrndx = BYTE_GET (ehdr64.e_shstrndx); | |
9187 | } | |
252b5132 RH |
9188 | |
9189 | return 1; | |
9190 | } | |
9191 | ||
ff78d6d6 | 9192 | static int |
252b5132 RH |
9193 | process_file (file_name) |
9194 | char * file_name; | |
9195 | { | |
9196 | FILE * file; | |
9197 | struct stat statbuf; | |
9198 | unsigned int i; | |
9199 | ||
9200 | if (stat (file_name, & statbuf) < 0) | |
9201 | { | |
9202 | error (_("Cannot stat input file %s.\n"), file_name); | |
ff78d6d6 | 9203 | return 1; |
252b5132 RH |
9204 | } |
9205 | ||
9206 | file = fopen (file_name, "rb"); | |
9207 | if (file == NULL) | |
9208 | { | |
9209 | error (_("Input file %s not found.\n"), file_name); | |
ff78d6d6 | 9210 | return 1; |
252b5132 RH |
9211 | } |
9212 | ||
9213 | if (! get_file_header (file)) | |
9214 | { | |
9215 | error (_("%s: Failed to read file header\n"), file_name); | |
9216 | fclose (file); | |
ff78d6d6 | 9217 | return 1; |
252b5132 RH |
9218 | } |
9219 | ||
9220 | /* Initialise per file variables. */ | |
9221 | for (i = NUM_ELEM (version_info); i--;) | |
9222 | version_info[i] = 0; | |
9223 | ||
9224 | for (i = NUM_ELEM (dynamic_info); i--;) | |
9225 | dynamic_info[i] = 0; | |
9226 | ||
9227 | /* Process the file. */ | |
9228 | if (show_name) | |
9229 | printf (_("\nFile: %s\n"), file_name); | |
9230 | ||
9231 | if (! process_file_header ()) | |
9232 | { | |
9233 | fclose (file); | |
ff78d6d6 | 9234 | return 1; |
252b5132 RH |
9235 | } |
9236 | ||
9237 | process_section_headers (file); | |
9238 | ||
9239 | process_program_headers (file); | |
9240 | ||
9241 | process_dynamic_segment (file); | |
9242 | ||
9243 | process_relocs (file); | |
9244 | ||
4d6ed7c8 NC |
9245 | process_unwind (file); |
9246 | ||
252b5132 RH |
9247 | process_symbol_table (file); |
9248 | ||
9249 | process_syminfo (file); | |
9250 | ||
9251 | process_version_sections (file); | |
9252 | ||
9253 | process_section_contents (file); | |
103f02d3 | 9254 | |
779fe533 | 9255 | process_corefile_contents (file); |
103f02d3 | 9256 | |
252b5132 RH |
9257 | process_arch_specific (file); |
9258 | ||
9259 | fclose (file); | |
9260 | ||
9261 | if (section_headers) | |
9262 | { | |
9263 | free (section_headers); | |
9264 | section_headers = NULL; | |
9265 | } | |
9266 | ||
9267 | if (string_table) | |
9268 | { | |
9269 | free (string_table); | |
9270 | string_table = NULL; | |
d40ac9bd | 9271 | string_table_length = 0; |
252b5132 RH |
9272 | } |
9273 | ||
9274 | if (dynamic_strings) | |
9275 | { | |
9276 | free (dynamic_strings); | |
9277 | dynamic_strings = NULL; | |
9278 | } | |
9279 | ||
9280 | if (dynamic_symbols) | |
9281 | { | |
9282 | free (dynamic_symbols); | |
9283 | dynamic_symbols = NULL; | |
19936277 | 9284 | num_dynamic_syms = 0; |
252b5132 RH |
9285 | } |
9286 | ||
9287 | if (dynamic_syminfo) | |
9288 | { | |
9289 | free (dynamic_syminfo); | |
9290 | dynamic_syminfo = NULL; | |
9291 | } | |
ff78d6d6 L |
9292 | |
9293 | return 0; | |
252b5132 RH |
9294 | } |
9295 | ||
9296 | #ifdef SUPPORT_DISASSEMBLY | |
9297 | /* Needed by the i386 disassembler. For extra credit, someone could | |
9ea033b2 | 9298 | fix this so that we insert symbolic addresses here, esp for GOT/PLT |
e3c8793a | 9299 | symbols. */ |
252b5132 RH |
9300 | |
9301 | void | |
9302 | print_address (unsigned int addr, FILE * outfile) | |
9303 | { | |
9304 | fprintf (outfile,"0x%8.8x", addr); | |
9305 | } | |
9306 | ||
e3c8793a | 9307 | /* Needed by the i386 disassembler. */ |
252b5132 RH |
9308 | void |
9309 | db_task_printsym (unsigned int addr) | |
9310 | { | |
9311 | print_address (addr, stderr); | |
9312 | } | |
9313 | #endif | |
9314 | ||
e414a165 NC |
9315 | int main PARAMS ((int, char **)); |
9316 | ||
252b5132 RH |
9317 | int |
9318 | main (argc, argv) | |
9319 | int argc; | |
9320 | char ** argv; | |
9321 | { | |
ff78d6d6 L |
9322 | int err; |
9323 | ||
252b5132 RH |
9324 | #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES) |
9325 | setlocale (LC_MESSAGES, ""); | |
3882b010 L |
9326 | #endif |
9327 | #if defined (HAVE_SETLOCALE) | |
9328 | setlocale (LC_CTYPE, ""); | |
252b5132 RH |
9329 | #endif |
9330 | bindtextdomain (PACKAGE, LOCALEDIR); | |
9331 | textdomain (PACKAGE); | |
9332 | ||
9333 | parse_args (argc, argv); | |
9334 | ||
9335 | if (optind < (argc - 1)) | |
9336 | show_name = 1; | |
9337 | ||
ff78d6d6 | 9338 | err = 0; |
252b5132 | 9339 | while (optind < argc) |
ff78d6d6 | 9340 | err |= process_file (argv [optind ++]); |
252b5132 RH |
9341 | |
9342 | if (dump_sects != NULL) | |
9343 | free (dump_sects); | |
9344 | ||
ff78d6d6 | 9345 | return err; |
252b5132 | 9346 | } |