]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - binutils/readelf.c
fix typo in previous delta
[thirdparty/binutils-gdb.git] / binutils / readelf.c
1 /* readelf.c -- display contents of an ELF format file
2 Copyright (C) 1998, 1999 Free Software Foundation, Inc.
3
4 Originally developed by Eric Youngdale <eric@andante.jic.com>
5 Modifications by Nick Clifton <nickc@cygnus.com>
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>
26 #include <sys/stat.h>
27 #include <stdio.h>
28 #include <time.h>
29
30 #if __GNUC__ >= 2
31 /* Define BFD64 here, even if our default architecture is 32 bit ELF
32 as this will allow us to read in and parse 64bit and 32bit ELF files.
33 Only do this if we belive that the compiler can support a 64 bit
34 data type. For now we only rely on GCC being able to do this. */
35 #define BFD64
36 #endif
37
38 #include "bfd.h"
39
40 #include "elf/common.h"
41 #include "elf/external.h"
42 #include "elf/internal.h"
43 #include "elf/dwarf2.h"
44
45 /* The following headers use the elf/reloc-macros.h file to
46 automatically generate relocation recognition functions
47 such as elf_mips_reloc_type() */
48
49 #define RELOC_MACROS_GEN_FUNC
50
51 #include "elf/i386.h"
52 #include "elf/v850.h"
53 #include "elf/ppc.h"
54 #include "elf/mips.h"
55 #include "elf/alpha.h"
56 #include "elf/arm.h"
57 #include "elf/m68k.h"
58 #include "elf/sparc.h"
59 #include "elf/m32r.h"
60 #include "elf/d10v.h"
61 #include "elf/d30v.h"
62 #include "elf/sh.h"
63 #include "elf/mn10200.h"
64 #include "elf/mn10300.h"
65 #include "elf/hppa.h"
66 #include "elf/arc.h"
67 #include "elf/fr30.h"
68 #include "elf/mcore.h"
69 #include "elf/i960.h"
70 #include "elf/pj.h"
71
72 #include "bucomm.h"
73 #include "getopt.h"
74
75 #ifdef ANSI_PROTOTYPES
76 #include <stdarg.h>
77 #else
78 #include <varargs.h>
79 #endif
80
81 char * program_name = "readelf";
82 unsigned int dynamic_addr;
83 bfd_size_type dynamic_size;
84 unsigned int rela_addr;
85 unsigned int rela_size;
86 char * dynamic_strings;
87 char * string_table;
88 unsigned long num_dynamic_syms;
89 Elf_Internal_Sym * dynamic_symbols;
90 Elf_Internal_Syminfo * dynamic_syminfo;
91 unsigned long dynamic_syminfo_offset;
92 unsigned int dynamic_syminfo_nent;
93 char program_interpreter [64];
94 int dynamic_info[DT_JMPREL + 1];
95 int version_info[16];
96 int loadaddr = 0;
97 Elf_Internal_Ehdr elf_header;
98 Elf_Internal_Shdr * section_headers;
99 Elf_Internal_Dyn * dynamic_segment;
100 int show_name;
101 int do_dynamic;
102 int do_syms;
103 int do_reloc;
104 int do_sections;
105 int do_segments;
106 int do_using_dynamic;
107 int do_header;
108 int do_dump;
109 int do_version;
110 int do_histogram;
111 int do_debugging;
112 int do_debug_info;
113 int do_debug_abbrevs;
114 int do_debug_lines;
115 int do_debug_pubnames;
116 int do_debug_aranges;
117 int do_arch;
118 int do_notes;
119 int is_32bit_elf;
120
121 /* A dynamic array of flags indicating which sections require dumping. */
122 char * dump_sects = NULL;
123 unsigned int num_dump_sects = 0;
124
125 #define HEX_DUMP (1 << 0)
126 #define DISASS_DUMP (1 << 1)
127 #define DEBUG_DUMP (1 << 2)
128
129 /* How to rpint a vma value. */
130 typedef enum print_mode
131 {
132 HEX,
133 DEC,
134 DEC_5,
135 UNSIGNED,
136 PREFIX_HEX,
137 FULL_HEX,
138 LONG_HEX
139 }
140 print_mode;
141
142 /* Forward declarations for dumb compilers. */
143 static void print_vma PARAMS ((bfd_vma, print_mode));
144 static bfd_vma (* byte_get) PARAMS ((unsigned char *, int));
145 static bfd_vma byte_get_little_endian PARAMS ((unsigned char *, int));
146 static bfd_vma byte_get_big_endian PARAMS ((unsigned char *, int));
147 static const char * get_mips_dynamic_type PARAMS ((unsigned long));
148 static const char * get_sparc64_dynamic_type PARAMS ((unsigned long));
149 static const char * get_parisc_dynamic_type PARAMS ((unsigned long));
150 static const char * get_dynamic_type PARAMS ((unsigned long));
151 static int dump_relocations PARAMS ((FILE *, unsigned long, unsigned long, Elf_Internal_Sym *, unsigned long, char *, int));
152 static char * get_file_type PARAMS ((unsigned));
153 static char * get_machine_name PARAMS ((unsigned));
154 static char * get_machine_flags PARAMS ((unsigned, unsigned));
155 static const char * get_mips_segment_type PARAMS ((unsigned long));
156 static const char * get_parisc_segment_type PARAMS ((unsigned long));
157 static const char * get_segment_type PARAMS ((unsigned long));
158 static const char * get_mips_section_type_name PARAMS ((unsigned int));
159 static const char * get_parisc_section_type_name PARAMS ((unsigned int));
160 static const char * get_section_type_name PARAMS ((unsigned int));
161 static char * get_symbol_binding PARAMS ((unsigned int));
162 static char * get_symbol_type PARAMS ((unsigned int));
163 static void usage PARAMS ((void));
164 static void parse_args PARAMS ((int, char **));
165 static int process_file_header PARAMS ((void));
166 static int process_program_headers PARAMS ((FILE *));
167 static int process_section_headers PARAMS ((FILE *));
168 static void dynamic_segment_mips_val PARAMS ((Elf_Internal_Dyn *));
169 static void dynamic_segment_parisc_val PARAMS ((Elf_Internal_Dyn *));
170 static int process_dynamic_segment PARAMS ((FILE *));
171 static int process_symbol_table PARAMS ((FILE *));
172 static int process_section_contents PARAMS ((FILE *));
173 static void process_file PARAMS ((char *));
174 static int process_relocs PARAMS ((FILE *));
175 static int process_version_sections PARAMS ((FILE *));
176 static char * get_ver_flags PARAMS ((unsigned int));
177 static char * get_symbol_index_type PARAMS ((unsigned int));
178 static int get_32bit_section_headers PARAMS ((FILE *));
179 static int get_64bit_section_headers PARAMS ((FILE *));
180 static int get_32bit_program_headers PARAMS ((FILE *, Elf_Internal_Phdr *));
181 static int get_64bit_program_headers PARAMS ((FILE *, Elf_Internal_Phdr *));
182 static int get_file_header PARAMS ((FILE *));
183 static Elf_Internal_Sym * get_32bit_elf_symbols PARAMS ((FILE *, unsigned long, unsigned long));
184 static Elf_Internal_Sym * get_64bit_elf_symbols PARAMS ((FILE *, unsigned long, unsigned long));
185 static int * get_dynamic_data PARAMS ((FILE *, unsigned int));
186 static int get_32bit_dynamic_segment PARAMS ((FILE *));
187 static int get_64bit_dynamic_segment PARAMS ((FILE *));
188 #ifdef SUPPORT_DISASSEMBLY
189 static int disassemble_section PARAMS ((Elf32_Internal_Shdr *, FILE *));
190 #endif
191 static int dump_section PARAMS ((Elf32_Internal_Shdr *, FILE *));
192 static int display_debug_section PARAMS ((Elf32_Internal_Shdr *, FILE *));
193 static int display_debug_info PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
194 static int display_debug_not_supported PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
195 static int display_debug_lines PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
196 static int display_debug_abbrev PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
197 static int display_debug_aranges PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
198 static unsigned char * process_abbrev_section PARAMS ((unsigned char *, unsigned char *));
199 static unsigned long read_leb128 PARAMS ((unsigned char *, int *, int));
200 static int process_extended_line_op PARAMS ((unsigned char *, int, int));
201 static void reset_state_machine PARAMS ((int));
202 static char * get_TAG_name PARAMS ((unsigned long));
203 static char * get_AT_name PARAMS ((unsigned long));
204 static char * get_FORM_name PARAMS ((unsigned long));
205 static void free_abbrevs PARAMS ((void));
206 static void add_abbrev PARAMS ((unsigned long, unsigned long, int));
207 static void add_abbrev_attr PARAMS ((unsigned long, unsigned long));
208 static unsigned char * read_and_display_attr PARAMS ((unsigned long, unsigned long, unsigned char *, unsigned long));
209 static unsigned char * display_block PARAMS ((unsigned char *, unsigned long));
210 static void decode_location_expression PARAMS ((unsigned char *, unsigned int));
211 static void request_dump PARAMS ((unsigned int, char));
212 static const char * get_elf_class PARAMS ((unsigned char));
213 static const char * get_data_encoding PARAMS ((unsigned char));
214 static const char * get_osabi_name PARAMS ((unsigned char));
215 static int guess_is_rela PARAMS ((unsigned long));
216 static char * get_note_type PARAMS ((unsigned int));
217 static int process_note PARAMS ((Elf32_Internal_Note *));
218 static int process_corefile_note_segment PARAMS ((FILE *, bfd_vma, bfd_vma));
219 static int process_corefile_note_segments PARAMS ((FILE *));
220 static int process_corefile_contents PARAMS ((FILE *));
221
222 typedef int Elf32_Word;
223
224 #ifndef TRUE
225 #define TRUE 1
226 #define FALSE 0
227 #endif
228 #define UNKNOWN -1
229
230 #define SECTION_NAME(X) (string_table + (X)->sh_name)
231
232 #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
233
234 #define BYTE_GET(field) byte_get (field, sizeof (field))
235
236 /* If we can support a 64 bit data type then BFD64 should be defined
237 and sizeof (bfd_vma) == 8. In this case when translating from an
238 external 8 byte field to an internal field, we can assume that the
239 internal field is also 8 bytes wide and so we can extact all the data.
240 If, however, BFD64 is not defined, then we must assume that the
241 internal data structure only has 4 byte wide fields that are the
242 equivalent of the 8 byte wide external counterparts, and so we must
243 truncate the data. */
244 #ifdef BFD64
245 #define BYTE_GET8(field) byte_get (field, -8)
246 #else
247 #define BYTE_GET8(field) byte_get (field, 8)
248 #endif
249
250 #define NUM_ELEM(array) (sizeof (array) / sizeof ((array)[0]))
251
252 #define GET_DATA_ALLOC(offset, size, var, type, reason) \
253 if (fseek (file, offset, SEEK_SET)) \
254 { \
255 error (_("Unable to seek to start of %s at %x\n"), reason, offset); \
256 return 0; \
257 } \
258 \
259 var = (type) malloc (size); \
260 \
261 if (var == NULL) \
262 { \
263 error (_("Out of memory allocating %d bytes for %s\n"), size, reason); \
264 return 0; \
265 } \
266 \
267 if (fread (var, size, 1, file) != 1) \
268 { \
269 error (_("Unable to read in %d bytes of %s\n"), size, reason); \
270 free (var); \
271 var = NULL; \
272 return 0; \
273 }
274
275
276 #define GET_DATA(offset, var, reason) \
277 if (fseek (file, offset, SEEK_SET)) \
278 { \
279 error (_("Unable to seek to %x for %s\n"), offset, reason); \
280 return 0; \
281 } \
282 else if (fread (& var, sizeof (var), 1, file) != 1) \
283 { \
284 error (_("Unable to read data at %x for %s\n"), offset, reason); \
285 return 0; \
286 }
287
288 #define GET_ELF_SYMBOLS(file, offset, size) \
289 (is_32bit_elf ? get_32bit_elf_symbols (file, offset, size) \
290 : get_64bit_elf_symbols (file, offset, size))
291
292
293 #ifdef ANSI_PROTOTYPES
294 static void
295 error (const char * message, ...)
296 {
297 va_list args;
298
299 fprintf (stderr, _("%s: Error: "), program_name);
300 va_start (args, message);
301 vfprintf (stderr, message, args);
302 va_end (args);
303 return;
304 }
305
306 static void
307 warn (const char * message, ...)
308 {
309 va_list args;
310
311 fprintf (stderr, _("%s: Warning: "), program_name);
312 va_start (args, message);
313 vfprintf (stderr, message, args);
314 va_end (args);
315 return;
316 }
317 #else
318 static void
319 error (va_alist)
320 va_dcl
321 {
322 char * message;
323 va_list args;
324
325 fprintf (stderr, _("%s: Error: "), program_name);
326 va_start (args);
327 message = va_arg (args, char *);
328 vfprintf (stderr, message, args);
329 va_end (args);
330 return;
331 }
332
333 static void
334 warn (va_alist)
335 va_dcl
336 {
337 char * message;
338 va_list args;
339
340 fprintf (stderr, _("%s: Warning: "), program_name);
341 va_start (args);
342 message = va_arg (args, char *);
343 vfprintf (stderr, message, args);
344 va_end (args);
345 return;
346 }
347 #endif
348
349 static bfd_vma
350 byte_get_little_endian (field, size)
351 unsigned char * field;
352 int size;
353 {
354 switch (size)
355 {
356 case 1:
357 return * field;
358
359 case 2:
360 return ((unsigned int) (field [0]))
361 | (((unsigned int) (field [1])) << 8);
362
363 case 8:
364 /* We want to extract data from an 8 byte wide field and
365 place it into a 4 byte wide field. Since this is a little
366 endian source we can juts use the 4 byte extraction code. */
367 /* Fall through. */
368 case 4:
369 return ((unsigned long) (field [0]))
370 | (((unsigned long) (field [1])) << 8)
371 | (((unsigned long) (field [2])) << 16)
372 | (((unsigned long) (field [3])) << 24);
373
374 #ifdef BFD64
375 case -8:
376 /* This is a special case, generated by the BYTE_GET8 macro.
377 It means that we are loading an 8 byte value from a field
378 in an external structure into an 8 byte value in a field
379 in an internal strcuture. */
380 return ((bfd_vma) (field [0]))
381 | (((bfd_vma) (field [1])) << 8)
382 | (((bfd_vma) (field [2])) << 16)
383 | (((bfd_vma) (field [3])) << 24)
384 | (((bfd_vma) (field [4])) << 32)
385 | (((bfd_vma) (field [5])) << 40)
386 | (((bfd_vma) (field [6])) << 48)
387 | (((bfd_vma) (field [7])) << 56);
388 #endif
389 default:
390 error (_("Unhandled data length: %d\n"), size);
391 abort ();
392 }
393 }
394
395 /* Print a VMA value. */
396 static void
397 print_vma (vma, mode)
398 bfd_vma vma;
399 print_mode mode;
400 {
401 #ifdef BFD64
402 if (is_32bit_elf)
403 #endif
404 {
405 switch (mode)
406 {
407 case FULL_HEX: printf ("0x"); /* drop through */
408 case LONG_HEX: printf ("%8.8lx", (unsigned long) vma); break;
409 case PREFIX_HEX: printf ("0x"); /* drop through */
410 case HEX: printf ("%lx", (unsigned long) vma); break;
411 case DEC: printf ("%ld", (unsigned long) vma); break;
412 case DEC_5: printf ("%5ld", (long) vma); break;
413 case UNSIGNED: printf ("%lu", (unsigned long) vma); break;
414 }
415 }
416 #ifdef BFD64
417 else
418 {
419 switch (mode)
420 {
421 case FULL_HEX:
422 printf ("0x");
423 /* drop through */
424
425 case LONG_HEX:
426 printf_vma (vma);
427 break;
428
429 case PREFIX_HEX:
430 printf ("0x");
431 /* drop through */
432
433 case HEX:
434 #if BFD_HOST_64BIT_LONG
435 printf ("%lx", vma);
436 #else
437 if (_bfd_int64_high (vma))
438 printf ("%lx%lx", _bfd_int64_high (vma), _bfd_int64_low (vma));
439 else
440 printf ("%lx", _bfd_int64_low (vma));
441 #endif
442 break;
443
444 case DEC:
445 if (_bfd_int64_high (vma))
446 /* ugg */
447 printf ("++%ld", _bfd_int64_low (vma));
448 else
449 printf ("%ld", _bfd_int64_low (vma));
450 break;
451
452 case DEC_5:
453 if (_bfd_int64_high (vma))
454 /* ugg */
455 printf ("++%ld", _bfd_int64_low (vma));
456 else
457 printf ("%5ld", _bfd_int64_low (vma));
458 break;
459
460 case UNSIGNED:
461 if (_bfd_int64_high (vma))
462 /* ugg */
463 printf ("++%lu", _bfd_int64_low (vma));
464 else
465 printf ("%lu", _bfd_int64_low (vma));
466 break;
467 }
468 }
469 #endif
470 }
471
472 static bfd_vma
473 byte_get_big_endian (field, size)
474 unsigned char * field;
475 int size;
476 {
477 switch (size)
478 {
479 case 1:
480 return * field;
481
482 case 2:
483 return ((unsigned int) (field [1])) | (((int) (field [0])) << 8);
484
485 case 4:
486 return ((unsigned long) (field [3]))
487 | (((unsigned long) (field [2])) << 8)
488 | (((unsigned long) (field [1])) << 16)
489 | (((unsigned long) (field [0])) << 24);
490
491 case 8:
492 /* Although we are extracing data from an 8 byte wide field, we
493 are returning only 4 bytes of data. */
494 return ((unsigned long) (field [7]))
495 | (((unsigned long) (field [6])) << 8)
496 | (((unsigned long) (field [5])) << 16)
497 | (((unsigned long) (field [4])) << 24);
498
499 #ifdef BFD64
500 case -8:
501 /* This is a special case, generated by the BYTE_GET8 macro.
502 It means that we are loading an 8 byte value from a field
503 in an external structure into an 8 byte value in a field
504 in an internal strcuture. */
505 return ((bfd_vma) (field [7]))
506 | (((bfd_vma) (field [6])) << 8)
507 | (((bfd_vma) (field [5])) << 16)
508 | (((bfd_vma) (field [4])) << 24)
509 | (((bfd_vma) (field [3])) << 32)
510 | (((bfd_vma) (field [2])) << 40)
511 | (((bfd_vma) (field [1])) << 48)
512 | (((bfd_vma) (field [0])) << 56);
513 #endif
514
515 default:
516 error (_("Unhandled data length: %d\n"), size);
517 abort ();
518 }
519 }
520
521
522 /* Guess the relocation sized based on the sized commonly used by the specific machine. */
523 static int
524 guess_is_rela (e_machine)
525 unsigned long e_machine;
526 {
527 switch (e_machine)
528 {
529 /* Targets that use REL relocations. */
530 case EM_ARM:
531 case EM_386:
532 case EM_486:
533 case EM_960:
534 case EM_CYGNUS_M32R:
535 case EM_CYGNUS_D10V:
536 case EM_MIPS:
537 case EM_MIPS_RS4_BE:
538 return FALSE;
539
540 /* Targets that use RELA relocations. */
541 case EM_68K:
542 case EM_SPARC32PLUS:
543 case EM_SPARCV9:
544 case EM_SPARC:
545 case EM_PPC:
546 case EM_CYGNUS_V850:
547 case EM_CYGNUS_D30V:
548 case EM_CYGNUS_MN10200:
549 case EM_CYGNUS_MN10300:
550 case EM_CYGNUS_FR30:
551 case EM_SH:
552 case EM_ALPHA:
553 case EM_MCORE:
554 return TRUE;
555
556 default:
557 warn (_("Don't know about relocations on this machine architecture\n"));
558 return FALSE;
559 }
560 }
561
562 /* Display the contents of the relocation data found at the specified offset. */
563 static int
564 dump_relocations (file, rel_offset, rel_size, symtab, nsyms, strtab, is_rela)
565 FILE * file;
566 unsigned long rel_offset;
567 unsigned long rel_size;
568 Elf_Internal_Sym * symtab;
569 unsigned long nsyms;
570 char * strtab;
571 int is_rela;
572 {
573 unsigned int i;
574 Elf_Internal_Rel * rels;
575 Elf_Internal_Rela * relas;
576
577
578 if (is_rela == UNKNOWN)
579 is_rela = guess_is_rela (elf_header.e_machine);
580
581 if (is_rela)
582 {
583 if (is_32bit_elf)
584 {
585 Elf32_External_Rela * erelas;
586
587 GET_DATA_ALLOC (rel_offset, rel_size, erelas,
588 Elf32_External_Rela *, "relocs");
589
590 rel_size = rel_size / sizeof (Elf32_External_Rela);
591
592 relas = (Elf_Internal_Rela *)
593 malloc (rel_size * sizeof (Elf_Internal_Rela));
594
595 if (relas == NULL)
596 {
597 error(_("out of memory parsing relocs"));
598 return 0;
599 }
600
601 for (i = 0; i < rel_size; i++)
602 {
603 relas[i].r_offset = BYTE_GET (erelas[i].r_offset);
604 relas[i].r_info = BYTE_GET (erelas[i].r_info);
605 relas[i].r_addend = BYTE_GET (erelas[i].r_addend);
606 }
607
608 free (erelas);
609
610 rels = (Elf_Internal_Rel *) relas;
611 }
612 else
613 {
614 Elf64_External_Rela * erelas;
615
616 GET_DATA_ALLOC (rel_offset, rel_size, erelas,
617 Elf64_External_Rela *, "relocs");
618
619 rel_size = rel_size / sizeof (Elf64_External_Rela);
620
621 relas = (Elf_Internal_Rela *)
622 malloc (rel_size * sizeof (Elf_Internal_Rela));
623
624 if (relas == NULL)
625 {
626 error(_("out of memory parsing relocs"));
627 return 0;
628 }
629
630 for (i = 0; i < rel_size; i++)
631 {
632 relas[i].r_offset = BYTE_GET8 (erelas[i].r_offset);
633 relas[i].r_info = BYTE_GET8 (erelas[i].r_info);
634 relas[i].r_addend = BYTE_GET8 (erelas[i].r_addend);
635 }
636
637 free (erelas);
638
639 rels = (Elf_Internal_Rel *) relas;
640 }
641 }
642 else
643 {
644 if (is_32bit_elf)
645 {
646 Elf32_External_Rel * erels;
647
648 GET_DATA_ALLOC (rel_offset, rel_size, erels,
649 Elf32_External_Rel *, "relocs");
650
651 rel_size = rel_size / sizeof (Elf32_External_Rel);
652
653 rels = (Elf_Internal_Rel *)
654 malloc (rel_size * sizeof (Elf_Internal_Rel));
655
656 if (rels == NULL)
657 {
658 error(_("out of memory parsing relocs"));
659 return 0;
660 }
661
662 for (i = 0; i < rel_size; i++)
663 {
664 rels[i].r_offset = BYTE_GET (erels[i].r_offset);
665 rels[i].r_info = BYTE_GET (erels[i].r_info);
666 }
667
668 free (erels);
669
670 relas = (Elf_Internal_Rela *) rels;
671 }
672 else
673 {
674 Elf64_External_Rel * erels;
675
676 GET_DATA_ALLOC (rel_offset, rel_size, erels,
677 Elf64_External_Rel *, "relocs");
678
679 rel_size = rel_size / sizeof (Elf64_External_Rel);
680
681 rels = (Elf_Internal_Rel *)
682 malloc (rel_size * sizeof (Elf_Internal_Rel));
683
684 if (rels == NULL)
685 {
686 error(_("out of memory parsing relocs"));
687 return 0;
688 }
689
690 for (i = 0; i < rel_size; i++)
691 {
692 rels[i].r_offset = BYTE_GET8 (erels[i].r_offset);
693 rels[i].r_info = BYTE_GET8 (erels[i].r_info);
694 }
695
696 free (erels);
697
698 relas = (Elf_Internal_Rela *) rels;
699 }
700 }
701
702 if (is_rela)
703 printf
704 (_(" Offset Info Type Symbol's Value Symbol's Name Addend\n"));
705 else
706 printf
707 (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
708
709 for (i = 0; i < rel_size; i++)
710 {
711 const char * rtype;
712 bfd_vma offset;
713 bfd_vma info;
714 bfd_vma symtab_index;
715 bfd_vma type;
716
717 if (is_rela)
718 {
719 offset = relas [i].r_offset;
720 info = relas [i].r_info;
721 }
722 else
723 {
724 offset = rels [i].r_offset;
725 info = rels [i].r_info;
726 }
727
728 if (is_32bit_elf)
729 {
730 type = ELF32_R_TYPE (info);
731 symtab_index = ELF32_R_SYM (info);
732 }
733 else
734 {
735 if (elf_header.e_machine == EM_SPARCV9)
736 type = ELF64_R_TYPE_ID (info);
737 else
738 type = ELF64_R_TYPE (info);
739 /* The #ifdef BFD64 below is to prevent a compile time warning.
740 We know that if we do not have a 64 bit data type that we
741 will never execute this code anyway. */
742 #ifdef BFD64
743 symtab_index = ELF64_R_SYM (info);
744 #endif
745 }
746
747 #ifdef _bfd_int64_low
748 printf (" %8.8lx %5.5lx ", _bfd_int64_low (offset), _bfd_int64_low (info));
749 #else
750 printf (" %8.8lx %5.5lx ", offset, info);
751 #endif
752
753 switch (elf_header.e_machine)
754 {
755 default:
756 rtype = NULL;
757 break;
758
759 case EM_CYGNUS_M32R:
760 rtype = elf_m32r_reloc_type (type);
761 break;
762
763 case EM_386:
764 case EM_486:
765 rtype = elf_i386_reloc_type (type);
766 break;
767
768 case EM_68K:
769 rtype = elf_m68k_reloc_type (type);
770 break;
771
772 case EM_960:
773 rtype = elf_i960_reloc_type (type);
774 break;
775
776 case EM_OLD_SPARCV9:
777 case EM_SPARC32PLUS:
778 case EM_SPARCV9:
779 case EM_SPARC:
780 rtype = elf_sparc_reloc_type (type);
781 break;
782
783 case EM_CYGNUS_V850:
784 rtype = v850_reloc_type (type);
785 break;
786
787 case EM_CYGNUS_D10V:
788 rtype = elf_d10v_reloc_type (type);
789 break;
790
791 case EM_CYGNUS_D30V:
792 rtype = elf_d30v_reloc_type (type);
793 break;
794
795 case EM_SH:
796 rtype = elf_sh_reloc_type (type);
797 break;
798
799 case EM_CYGNUS_MN10300:
800 rtype = elf_mn10300_reloc_type (type);
801 break;
802
803 case EM_CYGNUS_MN10200:
804 rtype = elf_mn10200_reloc_type (type);
805 break;
806
807 case EM_CYGNUS_FR30:
808 rtype = elf_fr30_reloc_type (type);
809 break;
810
811 case EM_MCORE:
812 rtype = elf_mcore_reloc_type (type);
813 break;
814
815 case EM_PPC:
816 rtype = elf_ppc_reloc_type (type);
817 break;
818
819 case EM_MIPS:
820 case EM_MIPS_RS4_BE:
821 rtype = elf_mips_reloc_type (type);
822 break;
823
824 case EM_ALPHA:
825 rtype = elf_alpha_reloc_type (type);
826 break;
827
828 case EM_ARM:
829 rtype = elf_arm_reloc_type (type);
830 break;
831
832 case EM_CYGNUS_ARC:
833 rtype = elf_arc_reloc_type (type);
834 break;
835
836 case EM_PARISC:
837 rtype = elf_hppa_reloc_type (type);
838 break;
839
840 case EM_PJ:
841 rtype = elf_pj_reloc_type (type);
842 break;
843 }
844
845 if (rtype == NULL)
846 #ifdef _bfd_int64_low
847 printf (_("unrecognised: %-7lx"), _bfd_int64_low (type));
848 #else
849 printf (_("unrecognised: %-7lx"), type);
850 #endif
851 else
852 printf ("%-21.21s", rtype);
853
854 if (symtab_index)
855 {
856 if (symtab != NULL)
857 {
858 if (symtab_index >= nsyms)
859 printf (" bad symbol index: %08lx", (unsigned long) symtab_index);
860 else
861 {
862 Elf_Internal_Sym * psym;
863
864 psym = symtab + symtab_index;
865
866 printf (" ");
867 print_vma (psym->st_value, LONG_HEX);
868 printf (" ");
869
870 if (psym->st_name == 0)
871 printf ("%-25.25s",
872 SECTION_NAME (section_headers + psym->st_shndx));
873 else if (strtab == NULL)
874 printf (_("<string table index %3ld>"), psym->st_name);
875 else
876 printf ("%-25.25s", strtab + psym->st_name);
877
878 if (is_rela)
879 printf (" + %lx", (unsigned long) relas [i].r_addend);
880 }
881 }
882 }
883 else if (is_rela)
884 {
885 printf ("%*c", is_32bit_elf ? 34 : 26, ' ');
886 print_vma (relas[i].r_addend, LONG_HEX);
887 }
888
889 if (elf_header.e_machine == EM_SPARCV9
890 && !strcmp (rtype, "R_SPARC_OLO10"))
891 printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (info));
892
893 putchar ('\n');
894 }
895
896 free (relas);
897
898 return 1;
899 }
900
901 static const char *
902 get_mips_dynamic_type (type)
903 unsigned long type;
904 {
905 switch (type)
906 {
907 case DT_MIPS_RLD_VERSION: return "MIPS_RLD_VERSION";
908 case DT_MIPS_TIME_STAMP: return "MIPS_TIME_STAMP";
909 case DT_MIPS_ICHECKSUM: return "MIPS_ICHECKSUM";
910 case DT_MIPS_IVERSION: return "MIPS_IVERSION";
911 case DT_MIPS_FLAGS: return "MIPS_FLAGS";
912 case DT_MIPS_BASE_ADDRESS: return "MIPS_BASE_ADDRESS";
913 case DT_MIPS_MSYM: return "MIPS_MSYM";
914 case DT_MIPS_CONFLICT: return "MIPS_CONFLICT";
915 case DT_MIPS_LIBLIST: return "MIPS_LIBLIST";
916 case DT_MIPS_LOCAL_GOTNO: return "MIPS_LOCAL_GOTNO";
917 case DT_MIPS_CONFLICTNO: return "MIPS_CONFLICTNO";
918 case DT_MIPS_LIBLISTNO: return "MIPS_LIBLISTNO";
919 case DT_MIPS_SYMTABNO: return "MIPS_SYMTABNO";
920 case DT_MIPS_UNREFEXTNO: return "MIPS_UNREFEXTNO";
921 case DT_MIPS_GOTSYM: return "MIPS_GOTSYM";
922 case DT_MIPS_HIPAGENO: return "MIPS_HIPAGENO";
923 case DT_MIPS_RLD_MAP: return "MIPS_RLD_MAP";
924 case DT_MIPS_DELTA_CLASS: return "MIPS_DELTA_CLASS";
925 case DT_MIPS_DELTA_CLASS_NO: return "MIPS_DELTA_CLASS_NO";
926 case DT_MIPS_DELTA_INSTANCE: return "MIPS_DELTA_INSTANCE";
927 case DT_MIPS_DELTA_INSTANCE_NO: return "MIPS_DELTA_INSTANCE_NO";
928 case DT_MIPS_DELTA_RELOC: return "MIPS_DELTA_RELOC";
929 case DT_MIPS_DELTA_RELOC_NO: return "MIPS_DELTA_RELOC_NO";
930 case DT_MIPS_DELTA_SYM: return "MIPS_DELTA_SYM";
931 case DT_MIPS_DELTA_SYM_NO: return "MIPS_DELTA_SYM_NO";
932 case DT_MIPS_DELTA_CLASSSYM: return "MIPS_DELTA_CLASSSYM";
933 case DT_MIPS_DELTA_CLASSSYM_NO: return "MIPS_DELTA_CLASSSYM_NO";
934 case DT_MIPS_CXX_FLAGS: return "MIPS_CXX_FLAGS";
935 case DT_MIPS_PIXIE_INIT: return "MIPS_PIXIE_INIT";
936 case DT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB";
937 case DT_MIPS_LOCALPAGE_GOTIDX: return "MIPS_LOCALPAGE_GOTIDX";
938 case DT_MIPS_LOCAL_GOTIDX: return "MIPS_LOCAL_GOTIDX";
939 case DT_MIPS_HIDDEN_GOTIDX: return "MIPS_HIDDEN_GOTIDX";
940 case DT_MIPS_PROTECTED_GOTIDX: return "MIPS_PROTECTED_GOTIDX";
941 case DT_MIPS_OPTIONS: return "MIPS_OPTIONS";
942 case DT_MIPS_INTERFACE: return "MIPS_INTERFACE";
943 case DT_MIPS_DYNSTR_ALIGN: return "MIPS_DYNSTR_ALIGN";
944 case DT_MIPS_INTERFACE_SIZE: return "MIPS_INTERFACE_SIZE";
945 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
946 case DT_MIPS_PERF_SUFFIX: return "MIPS_PERF_SUFFIX";
947 case DT_MIPS_COMPACT_SIZE: return "MIPS_COMPACT_SIZE";
948 case DT_MIPS_GP_VALUE: return "MIPS_GP_VALUE";
949 case DT_MIPS_AUX_DYNAMIC: return "MIPS_AUX_DYNAMIC";
950 default:
951 return NULL;
952 }
953 }
954
955 static const char *
956 get_sparc64_dynamic_type (type)
957 unsigned long type;
958 {
959 switch (type)
960 {
961 case DT_SPARC_REGISTER: return "SPARC_REGISTER";
962 default:
963 return NULL;
964 }
965 }
966
967 static const char *
968 get_parisc_dynamic_type (type)
969 unsigned long type;
970 {
971 switch (type)
972 {
973 case DT_HP_LOAD_MAP: return "HP_LOAD_MAP";
974 case DT_HP_DLD_FLAGS: return "HP_DLD_FLAGS";
975 case DT_HP_DLD_HOOK: return "HP_DLD_HOOK";
976 case DT_HP_UX10_INIT: return "HP_UX10_INIT";
977 case DT_HP_UX10_INITSZ: return "HP_UX10_INITSZ";
978 case DT_HP_PREINIT: return "HP_PREINIT";
979 case DT_HP_PREINITSZ: return "HP_PREINITSZ";
980 case DT_HP_NEEDED: return "HP_NEEDED";
981 case DT_HP_TIME_STAMP: return "HP_TIME_STAMP";
982 case DT_HP_CHECKSUM: return "HP_CHECKSUM";
983 case DT_HP_GST_SIZE: return "HP_GST_SIZE";
984 case DT_HP_GST_VERSION: return "HP_GST_VERSION";
985 case DT_HP_GST_HASHVAL: return "HP_GST_HASHVAL";
986 default:
987 return NULL;
988 }
989 }
990
991 static const char *
992 get_dynamic_type (type)
993 unsigned long type;
994 {
995 static char buff [32];
996
997 switch (type)
998 {
999 case DT_NULL: return "NULL";
1000 case DT_NEEDED: return "NEEDED";
1001 case DT_PLTRELSZ: return "PLTRELSZ";
1002 case DT_PLTGOT: return "PLTGOT";
1003 case DT_HASH: return "HASH";
1004 case DT_STRTAB: return "STRTAB";
1005 case DT_SYMTAB: return "SYMTAB";
1006 case DT_RELA: return "RELA";
1007 case DT_RELASZ: return "RELASZ";
1008 case DT_RELAENT: return "RELAENT";
1009 case DT_STRSZ: return "STRSZ";
1010 case DT_SYMENT: return "SYMENT";
1011 case DT_INIT: return "INIT";
1012 case DT_FINI: return "FINI";
1013 case DT_SONAME: return "SONAME";
1014 case DT_RPATH: return "RPATH";
1015 case DT_SYMBOLIC: return "SYMBOLIC";
1016 case DT_REL: return "REL";
1017 case DT_RELSZ: return "RELSZ";
1018 case DT_RELENT: return "RELENT";
1019 case DT_PLTREL: return "PLTREL";
1020 case DT_DEBUG: return "DEBUG";
1021 case DT_TEXTREL: return "TEXTREL";
1022 case DT_JMPREL: return "JMPREL";
1023 case DT_BIND_NOW: return "BIND_NOW";
1024 case DT_INIT_ARRAY: return "INIT_ARRAY";
1025 case DT_FINI_ARRAY: return "FINI_ARRAY";
1026 case DT_INIT_ARRAYSZ: return "INIT_ARRAYSZ";
1027 case DT_FINI_ARRAYSZ: return "FINI_ARRAYSZ";
1028
1029 case DT_PLTPADSZ: return "PLTPADSZ";
1030 case DT_MOVEENT: return "MOVEENT";
1031 case DT_MOVESZ: return "MOVESZ";
1032 case DT_FEATURE_1: return "FEATURE_1";
1033 case DT_POSFLAG_1: return "POSFLAG_1";
1034 case DT_SYMINSZ: return "SYMINSZ";
1035 case DT_SYMINENT: return "SYMINENT"; /* aka VALRNGHI */
1036
1037 case DT_ADDRRNGLO: return "ADDRRNGLO";
1038 case DT_SYMINFO: return "SYMINFO"; /* aka ADDRRNGHI */
1039
1040 case DT_VERSYM: return "VERSYM";
1041
1042 case DT_RELACOUNT: return "RELACOUNT";
1043 case DT_RELCOUNT: return "RELCOUNT";
1044 case DT_FLAGS_1: return "FLAGS_1";
1045 case DT_VERDEF: return "VERDEF";
1046 case DT_VERDEFNUM: return "VERDEFNUM";
1047 case DT_VERNEED: return "VERNEED";
1048 case DT_VERNEEDNUM: return "VERNEEDNUM";
1049
1050 case DT_AUXILIARY: return "AUXILARY";
1051 case DT_USED: return "USED";
1052 case DT_FILTER: return "FILTER";
1053
1054 default:
1055 if ((type >= DT_LOPROC) && (type <= DT_HIPROC))
1056 {
1057 const char * result;
1058
1059 switch (elf_header.e_machine)
1060 {
1061 case EM_MIPS:
1062 case EM_MIPS_RS4_BE:
1063 result = get_mips_dynamic_type (type);
1064 break;
1065 case EM_SPARCV9:
1066 result = get_sparc64_dynamic_type (type);
1067 break;
1068 default:
1069 result = NULL;
1070 break;
1071 }
1072
1073 if (result != NULL)
1074 return result;
1075
1076 sprintf (buff, _("Processor Specific: %lx"), type);
1077 }
1078 else if ((type >= DT_LOOS) && (type <= DT_HIOS))
1079 {
1080 const char * result;
1081
1082 switch (elf_header.e_machine)
1083 {
1084 case EM_PARISC:
1085 result = get_parisc_dynamic_type (type);
1086 break;
1087 default:
1088 result = NULL;
1089 break;
1090 }
1091
1092 if (result != NULL)
1093 return result;
1094
1095 sprintf (buff, _("Operating System specific: %lx"), type);
1096 }
1097 else
1098 sprintf (buff, _("<unknown>: %lx"), type);
1099
1100 return buff;
1101 }
1102 }
1103
1104 static char *
1105 get_file_type (e_type)
1106 unsigned e_type;
1107 {
1108 static char buff [32];
1109
1110 switch (e_type)
1111 {
1112 case ET_NONE: return _("NONE (None)");
1113 case ET_REL: return _("REL (Relocatable file)");
1114 case ET_EXEC: return _("EXEC (Executable file)");
1115 case ET_DYN: return _("DYN (Shared object file)");
1116 case ET_CORE: return _("CORE (Core file)");
1117
1118 default:
1119 if ((e_type >= ET_LOPROC) && (e_type <= ET_HIPROC))
1120 sprintf (buff, _("Processor Specific: (%x)"), e_type);
1121 else if ((e_type >= ET_LOOS) && (e_type <= ET_HIOS))
1122 sprintf (buff, _("OS Specific: (%x)"), e_type);
1123 else
1124 sprintf (buff, _("<unknown>: %x"), e_type);
1125 return buff;
1126 }
1127 }
1128
1129 static char *
1130 get_machine_name (e_machine)
1131 unsigned e_machine;
1132 {
1133 static char buff [32];
1134
1135 switch (e_machine)
1136 {
1137 case EM_NONE: return _("None");
1138 case EM_M32: return "WE32100";
1139 case EM_SPARC: return "Sparc";
1140 case EM_386: return "Intel 80386";
1141 case EM_68K: return "MC68000";
1142 case EM_88K: return "MC88000";
1143 case EM_486: return "Intel 80486";
1144 case EM_860: return "Intel 80860";
1145 case EM_MIPS: return "MIPS R3000 big-endian";
1146 case EM_S370: return "Amdahl";
1147 case EM_MIPS_RS4_BE: return "MIPS R4000 big-endian";
1148 case EM_OLD_SPARCV9: return "Sparc v9 (old)";
1149 case EM_PARISC: return "HPPA";
1150 case EM_PPC_OLD: return "Power PC (old)";
1151 case EM_SPARC32PLUS: return "Sparc v8+" ;
1152 case EM_960: return "Intel 90860";
1153 case EM_PPC: return "PowerPC";
1154 case EM_V800: return "NEC V800";
1155 case EM_FR20: return "Fujitsu FR20";
1156 case EM_RH32: return "TRW RH32";
1157 case EM_MCORE: return "MCORE";
1158 case EM_ARM: return "ARM";
1159 case EM_OLD_ALPHA: return "Digital Alpha (old)";
1160 case EM_SH: return "Hitachi SH";
1161 case EM_SPARCV9: return "Sparc v9";
1162 case EM_TRICORE: return "Siemens Tricore";
1163 case EM_ARC: return "Argonaut RISC Core";
1164 case EM_H8_300: return "Hitachi H8/300";
1165 case EM_H8_300H: return "Hitachi H8/300H";
1166 case EM_H8S: return "Hitachi H8S";
1167 case EM_H8_500: return "Hitachi H8/500";
1168 case EM_IA_64: return "Intel IA-64";
1169 case EM_MIPS_X: return "Stanford MIPS-X";
1170 case EM_COLDFIRE: return "Motorola Coldfire";
1171 case EM_68HC12: return "Motorola M68HC12";
1172 case EM_ALPHA: return "Alpha";
1173 case EM_CYGNUS_D10V: return "d10v";
1174 case EM_CYGNUS_D30V: return "d30v";
1175 case EM_CYGNUS_ARC: return "Arc";
1176 case EM_CYGNUS_M32R: return "Mitsubishi M32r";
1177 case EM_CYGNUS_V850: return "NEC v850";
1178 case EM_CYGNUS_MN10300: return "mn10300";
1179 case EM_CYGNUS_MN10200: return "mn10200";
1180 case EM_CYGNUS_FR30: return "Fujitsu FR30";
1181 case EM_PJ: return "picoJava";
1182 default:
1183 sprintf (buff, _("<unknown>: %x"), e_machine);
1184 return buff;
1185 }
1186 }
1187
1188 static char *
1189 get_machine_flags (e_flags, e_machine)
1190 unsigned e_flags;
1191 unsigned e_machine;
1192 {
1193 static char buf [1024];
1194
1195 buf[0] = '\0';
1196 if (e_flags)
1197 {
1198 switch (e_machine)
1199 {
1200 default:
1201 break;
1202
1203 case EM_68K:
1204 if (e_flags & EF_CPU32)
1205 strcat (buf, ", cpu32");
1206 break;
1207
1208 case EM_PPC:
1209 if (e_flags & EF_PPC_EMB)
1210 strcat (buf, ", emb");
1211
1212 if (e_flags & EF_PPC_RELOCATABLE)
1213 strcat (buf, ", relocatable");
1214
1215 if (e_flags & EF_PPC_RELOCATABLE_LIB)
1216 strcat (buf, ", relocatable-lib");
1217 break;
1218
1219 case EM_CYGNUS_V850:
1220 switch (e_flags & EF_V850_ARCH)
1221 {
1222 case E_V850E_ARCH:
1223 strcat (buf, ", v850e");
1224 break;
1225 case E_V850EA_ARCH:
1226 strcat (buf, ", v850ea");
1227 break;
1228 case E_V850_ARCH:
1229 strcat (buf, ", v850");
1230 break;
1231 default:
1232 strcat (buf, ", unknown v850 architecture variant");
1233 break;
1234 }
1235 break;
1236
1237 case EM_CYGNUS_M32R:
1238 if ((e_flags & EF_M32R_ARCH) == E_M32R_ARCH)
1239 strcat (buf, ", m32r");
1240
1241 break;
1242
1243 case EM_MIPS:
1244 case EM_MIPS_RS4_BE:
1245 if (e_flags & EF_MIPS_NOREORDER)
1246 strcat (buf, ", noreorder");
1247
1248 if (e_flags & EF_MIPS_PIC)
1249 strcat (buf, ", pic");
1250
1251 if (e_flags & EF_MIPS_CPIC)
1252 strcat (buf, ", cpic");
1253
1254 if (e_flags & EF_MIPS_ABI2)
1255 strcat (buf, ", abi2");
1256
1257 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_1)
1258 strcat (buf, ", mips1");
1259
1260 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_2)
1261 strcat (buf, ", mips2");
1262
1263 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_3)
1264 strcat (buf, ", mips3");
1265
1266 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_4)
1267 strcat (buf, ", mips4");
1268 break;
1269
1270 case EM_SPARCV9:
1271 if (e_flags & EF_SPARC_32PLUS)
1272 strcat (buf, ", v8+");
1273
1274 if (e_flags & EF_SPARC_SUN_US1)
1275 strcat (buf, ", ultrasparcI");
1276
1277 if (e_flags & EF_SPARC_SUN_US3)
1278 strcat (buf, ", ultrasparcIII");
1279
1280 if (e_flags & EF_SPARC_HAL_R1)
1281 strcat (buf, ", halr1");
1282
1283 if (e_flags & EF_SPARC_LEDATA)
1284 strcat (buf, ", ledata");
1285
1286 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_TSO)
1287 strcat (buf, ", tso");
1288
1289 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_PSO)
1290 strcat (buf, ", pso");
1291
1292 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_RMO)
1293 strcat (buf, ", rmo");
1294 break;
1295
1296 case EM_PARISC:
1297 switch (e_flags & EF_PARISC_ARCH)
1298 {
1299 case EFA_PARISC_1_0:
1300 strcpy (buf, ", PA-RISC 1.0");
1301 break;
1302 case EFA_PARISC_1_1:
1303 strcpy (buf, ", PA-RISC 1.1");
1304 break;
1305 case EFA_PARISC_2_0:
1306 strcpy (buf, ", PA-RISC 2.0");
1307 break;
1308 default:
1309 break;
1310 }
1311 if (e_flags & EF_PARISC_TRAPNIL)
1312 strcat (buf, ", trapnil");
1313 if (e_flags & EF_PARISC_EXT)
1314 strcat (buf, ", ext");
1315 if (e_flags & EF_PARISC_LSB)
1316 strcat (buf, ", lsb");
1317 if (e_flags & EF_PARISC_WIDE)
1318 strcat (buf, ", wide");
1319 if (e_flags & EF_PARISC_NO_KABP)
1320 strcat (buf, ", no kabp");
1321 if (e_flags & EF_PARISC_LAZYSWAP)
1322 strcat (buf, ", lazyswap");
1323 break;
1324
1325 case EM_PJ:
1326 if ((e_flags & EF_PICOJAVA_NEWCALLS) == EF_PICOJAVA_NEWCALLS)
1327 strcat (buf, ", new calling convention");
1328
1329 if ((e_flags & EF_PICOJAVA_GNUCALLS) == EF_PICOJAVA_GNUCALLS)
1330 strcat (buf, ", gnu calling convention");
1331 break;
1332 }
1333 }
1334
1335 return buf;
1336 }
1337
1338 static const char *
1339 get_mips_segment_type (type)
1340 unsigned long type;
1341 {
1342 switch (type)
1343 {
1344 case PT_MIPS_REGINFO:
1345 return "REGINFO";
1346 case PT_MIPS_RTPROC:
1347 return "RTPROC";
1348 case PT_MIPS_OPTIONS:
1349 return "OPTIONS";
1350 default:
1351 break;
1352 }
1353
1354 return NULL;
1355 }
1356
1357 static const char *
1358 get_parisc_segment_type (type)
1359 unsigned long type;
1360 {
1361 switch (type)
1362 {
1363 case PT_HP_TLS: return "HP_TLS";
1364 case PT_HP_CORE_NONE: return "HP_CORE_NONE";
1365 case PT_HP_CORE_VERSION: return "HP_CORE_VERSION";
1366 case PT_HP_CORE_KERNEL: return "HP_CORE_KERNEL";
1367 case PT_HP_CORE_COMM: return "HP_CORE_COMM";
1368 case PT_HP_CORE_PROC: return "HP_CORE_PROC";
1369 case PT_HP_CORE_LOADABLE: return "HP_CORE_LOADABLE";
1370 case PT_HP_CORE_STACK: return "HP_CORE_STACK";
1371 case PT_HP_CORE_SHM: return "HP_CORE_SHM";
1372 case PT_HP_CORE_MMF: return "HP_CORE_MMF";
1373 case PT_HP_PARALLEL: return "HP_PARALLEL";
1374 case PT_HP_FASTBIND: return "HP_FASTBIND";
1375 case PT_PARISC_ARCHEXT: return "PARISC_ARCHEXT";
1376 case PT_PARISC_UNWIND: return "PARISC_UNWIND";
1377 default:
1378 break;
1379 }
1380
1381 return NULL;
1382 }
1383
1384 static const char *
1385 get_segment_type (p_type)
1386 unsigned long p_type;
1387 {
1388 static char buff [32];
1389
1390 switch (p_type)
1391 {
1392 case PT_NULL: return "NULL";
1393 case PT_LOAD: return "LOAD";
1394 case PT_DYNAMIC: return "DYNAMIC";
1395 case PT_INTERP: return "INTERP";
1396 case PT_NOTE: return "NOTE";
1397 case PT_SHLIB: return "SHLIB";
1398 case PT_PHDR: return "PHDR";
1399
1400 default:
1401 if ((p_type >= PT_LOPROC) && (p_type <= PT_HIPROC))
1402 {
1403 const char * result;
1404
1405 switch (elf_header.e_machine)
1406 {
1407 case EM_MIPS:
1408 case EM_MIPS_RS4_BE:
1409 result = get_mips_segment_type (p_type);
1410 break;
1411 case EM_PARISC:
1412 result = get_parisc_segment_type (p_type);
1413 break;
1414 default:
1415 result = NULL;
1416 break;
1417 }
1418
1419 if (result != NULL)
1420 return result;
1421
1422 sprintf (buff, "LOPROC+%lx", p_type - PT_LOPROC);
1423 }
1424 else if ((p_type >= PT_LOOS) && (p_type <= PT_HIOS))
1425 {
1426 const char * result;
1427
1428 switch (elf_header.e_machine)
1429 {
1430 case EM_PARISC:
1431 result = get_parisc_segment_type (p_type);
1432 break;
1433 default:
1434 result = NULL;
1435 break;
1436 }
1437
1438 if (result != NULL)
1439 return result;
1440
1441 sprintf (buff, "LOOS+%lx", p_type - PT_LOOS);
1442 }
1443 else
1444 sprintf (buff, _("<unknown>: %lx"), p_type);
1445
1446 return buff;
1447 }
1448 }
1449
1450 static const char *
1451 get_mips_section_type_name (sh_type)
1452 unsigned int sh_type;
1453 {
1454 switch (sh_type)
1455 {
1456 case SHT_MIPS_LIBLIST: return "MIPS_LIBLIST";
1457 case SHT_MIPS_MSYM: return "MIPS_MSYM";
1458 case SHT_MIPS_CONFLICT: return "MIPS_CONFLICT";
1459 case SHT_MIPS_GPTAB: return "MIPS_GPTAB";
1460 case SHT_MIPS_UCODE: return "MIPS_UCODE";
1461 case SHT_MIPS_DEBUG: return "MIPS_DEBUG";
1462 case SHT_MIPS_REGINFO: return "MIPS_REGINFO";
1463 case SHT_MIPS_PACKAGE: return "MIPS_PACKAGE";
1464 case SHT_MIPS_PACKSYM: return "MIPS_PACKSYM";
1465 case SHT_MIPS_RELD: return "MIPS_RELD";
1466 case SHT_MIPS_IFACE: return "MIPS_IFACE";
1467 case SHT_MIPS_CONTENT: return "MIPS_CONTENT";
1468 case SHT_MIPS_OPTIONS: return "MIPS_OPTIONS";
1469 case SHT_MIPS_SHDR: return "MIPS_SHDR";
1470 case SHT_MIPS_FDESC: return "MIPS_FDESC";
1471 case SHT_MIPS_EXTSYM: return "MIPS_EXTSYM";
1472 case SHT_MIPS_DENSE: return "MIPS_DENSE";
1473 case SHT_MIPS_PDESC: return "MIPS_PDESC";
1474 case SHT_MIPS_LOCSYM: return "MIPS_LOCSYM";
1475 case SHT_MIPS_AUXSYM: return "MIPS_AUXSYM";
1476 case SHT_MIPS_OPTSYM: return "MIPS_OPTSYM";
1477 case SHT_MIPS_LOCSTR: return "MIPS_LOCSTR";
1478 case SHT_MIPS_LINE: return "MIPS_LINE";
1479 case SHT_MIPS_RFDESC: return "MIPS_RFDESC";
1480 case SHT_MIPS_DELTASYM: return "MIPS_DELTASYM";
1481 case SHT_MIPS_DELTAINST: return "MIPS_DELTAINST";
1482 case SHT_MIPS_DELTACLASS: return "MIPS_DELTACLASS";
1483 case SHT_MIPS_DWARF: return "MIPS_DWARF";
1484 case SHT_MIPS_DELTADECL: return "MIPS_DELTADECL";
1485 case SHT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB";
1486 case SHT_MIPS_EVENTS: return "MIPS_EVENTS";
1487 case SHT_MIPS_TRANSLATE: return "MIPS_TRANSLATE";
1488 case SHT_MIPS_PIXIE: return "MIPS_PIXIE";
1489 case SHT_MIPS_XLATE: return "MIPS_XLATE";
1490 case SHT_MIPS_XLATE_DEBUG: return "MIPS_XLATE_DEBUG";
1491 case SHT_MIPS_WHIRL: return "MIPS_WHIRL";
1492 case SHT_MIPS_EH_REGION: return "MIPS_EH_REGION";
1493 case SHT_MIPS_XLATE_OLD: return "MIPS_XLATE_OLD";
1494 case SHT_MIPS_PDR_EXCEPTION: return "MIPS_PDR_EXCEPTION";
1495 default:
1496 break;
1497 }
1498 return NULL;
1499 }
1500
1501 static const char *
1502 get_parisc_section_type_name (sh_type)
1503 unsigned int sh_type;
1504 {
1505 switch (sh_type)
1506 {
1507 case SHT_PARISC_EXT: return "PARISC_EXT";
1508 case SHT_PARISC_UNWIND: return "PARISC_UNWIND";
1509 case SHT_PARISC_DOC: return "PARISC_DOC";
1510 default:
1511 break;
1512 }
1513 return NULL;
1514 }
1515
1516 static const char *
1517 get_section_type_name (sh_type)
1518 unsigned int sh_type;
1519 {
1520 static char buff [32];
1521
1522 switch (sh_type)
1523 {
1524 case SHT_NULL: return "NULL";
1525 case SHT_PROGBITS: return "PROGBITS";
1526 case SHT_SYMTAB: return "SYMTAB";
1527 case SHT_STRTAB: return "STRTAB";
1528 case SHT_RELA: return "RELA";
1529 case SHT_HASH: return "HASH";
1530 case SHT_DYNAMIC: return "DYNAMIC";
1531 case SHT_NOTE: return "NOTE";
1532 case SHT_NOBITS: return "NOBITS";
1533 case SHT_REL: return "REL";
1534 case SHT_SHLIB: return "SHLIB";
1535 case SHT_DYNSYM: return "DYNSYM";
1536 case SHT_GNU_verdef: return "VERDEF";
1537 case SHT_GNU_verneed: return "VERNEED";
1538 case SHT_GNU_versym: return "VERSYM";
1539 case 0x6ffffff0: return "VERSYM";
1540 case 0x6ffffffc: return "VERDEF";
1541 case 0x7ffffffd: return "AUXILIARY";
1542 case 0x7fffffff: return "FILTER";
1543
1544 default:
1545 if ((sh_type >= SHT_LOPROC) && (sh_type <= SHT_HIPROC))
1546 {
1547 const char * result;
1548
1549 switch (elf_header.e_machine)
1550 {
1551 case EM_MIPS:
1552 case EM_MIPS_RS4_BE:
1553 result = get_mips_section_type_name (sh_type);
1554 break;
1555 case EM_PARISC:
1556 result = get_parisc_section_type_name (sh_type);
1557 break;
1558 default:
1559 result = NULL;
1560 break;
1561 }
1562
1563 if (result != NULL)
1564 return result;
1565
1566 sprintf (buff, "SHT_LOPROC+%x", sh_type - SHT_LOPROC);
1567 }
1568 else if ((sh_type >= SHT_LOOS) && (sh_type <= SHT_HIOS))
1569 sprintf (buff, "SHT_LOOS+%x", sh_type - SHT_LOOS);
1570 else if ((sh_type >= SHT_LOUSER) && (sh_type <= SHT_HIUSER))
1571 sprintf (buff, "SHT_LOUSER+%x", sh_type - SHT_LOUSER);
1572 else
1573 sprintf (buff, _("<unknown>: %x"), sh_type);
1574
1575 return buff;
1576 }
1577 }
1578
1579 struct option options [] =
1580 {
1581 {"all", no_argument, 0, 'a'},
1582 {"file-header", no_argument, 0, 'h'},
1583 {"program-headers", no_argument, 0, 'l'},
1584 {"headers", no_argument, 0, 'e'},
1585 {"histogram", no_argument, 0, 'I'},
1586 {"segments", no_argument, 0, 'l'},
1587 {"sections", no_argument, 0, 'S'},
1588 {"section-headers", no_argument, 0, 'S'},
1589 {"symbols", no_argument, 0, 's'},
1590 {"syms", no_argument, 0, 's'},
1591 {"relocs", no_argument, 0, 'r'},
1592 {"notes", no_argument, 0, 'n'},
1593 {"dynamic", no_argument, 0, 'd'},
1594 {"arch-specific", no_argument, 0, 'A'},
1595 {"version-info", no_argument, 0, 'V'},
1596 {"use-dynamic", no_argument, 0, 'D'},
1597 {"hex-dump", required_argument, 0, 'x'},
1598 {"debug-dump", optional_argument, 0, 'w'},
1599 #ifdef SUPPORT_DISASSEMBLY
1600 {"instruction-dump", required_argument, 0, 'i'},
1601 #endif
1602
1603 {"version", no_argument, 0, 'v'},
1604 {"help", no_argument, 0, 'H'},
1605 {0, no_argument, 0, 0}
1606 };
1607
1608 static void
1609 usage ()
1610 {
1611 fprintf (stdout, _("Usage: readelf {options} elf-file(s)\n"));
1612 fprintf (stdout, _(" Options are:\n"));
1613 fprintf (stdout, _(" -a or --all Equivalent to: -h -l -S -s -r -d -V -A -I\n"));
1614 fprintf (stdout, _(" -h or --file-header Display the ELF file header\n"));
1615 fprintf (stdout, _(" -l or --program-headers or --segments\n"));
1616 fprintf (stdout, _(" Display the program headers\n"));
1617 fprintf (stdout, _(" -S or --section-headers or --sections\n"));
1618 fprintf (stdout, _(" Display the sections' header\n"));
1619 fprintf (stdout, _(" -e or --headers Equivalent to: -h -l -S\n"));
1620 fprintf (stdout, _(" -s or --syms or --symbols Display the symbol table\n"));
1621 fprintf (stdout, _(" -n or --notes Display the core notes (if present)\n"));
1622 fprintf (stdout, _(" -r or --relocs Display the relocations (if present)\n"));
1623 fprintf (stdout, _(" -d or --dynamic Display the dynamic segment (if present)\n"));
1624 fprintf (stdout, _(" -V or --version-info Display the version sections (if present)\n"));
1625 fprintf (stdout, _(" -A or --arch-specific Display architecture specific information (if any).\n"));
1626 fprintf (stdout, _(" -D or --use-dynamic Use the dynamic section info when displaying symbols\n"));
1627 fprintf (stdout, _(" -x <number> or --hex-dump=<number>\n"));
1628 fprintf (stdout, _(" Dump the contents of section <number>\n"));
1629 fprintf (stdout, _(" -w[liapr] or --debug-dump[=line,=info,=abbrev,=pubnames,=ranges]\n"));
1630 fprintf (stdout, _(" Display the contents of DWARF2 debug sections\n"));
1631 #ifdef SUPPORT_DISASSEMBLY
1632 fprintf (stdout, _(" -i <number> or --instruction-dump=<number>\n"));
1633 fprintf (stdout, _(" Disassemble the contents of section <number>\n"));
1634 #endif
1635 fprintf (stdout, _(" -I or --histogram Display histogram of bucket list lengths\n"));
1636 fprintf (stdout, _(" -v or --version Display the version number of readelf\n"));
1637 fprintf (stdout, _(" -H or --help Display this information\n"));
1638 fprintf (stdout, _("Report bugs to bug-gnu-utils@gnu.org\n"));
1639
1640 exit (0);
1641 }
1642
1643 static void
1644 request_dump (section, type)
1645 unsigned int section;
1646 char type;
1647 {
1648 if (section >= num_dump_sects)
1649 {
1650 char * new_dump_sects;
1651
1652 new_dump_sects = (char *) calloc (section + 1, 1);
1653
1654 if (new_dump_sects == NULL)
1655 error (_("Out of memory allocating dump request table."));
1656 else
1657 {
1658 /* Copy current flag settings. */
1659 memcpy (new_dump_sects, dump_sects, num_dump_sects);
1660
1661 free (dump_sects);
1662
1663 dump_sects = new_dump_sects;
1664 num_dump_sects = section + 1;
1665 }
1666 }
1667
1668 if (dump_sects)
1669 dump_sects [section] |= type;
1670
1671 return;
1672 }
1673
1674 static void
1675 parse_args (argc, argv)
1676 int argc;
1677 char ** argv;
1678 {
1679 int c;
1680
1681 if (argc < 2)
1682 usage ();
1683
1684 while ((c = getopt_long
1685 (argc, argv, "ersahnldSDAIw::x:i:vV", options, NULL)) != EOF)
1686 {
1687 char * cp;
1688 int section;
1689
1690 switch (c)
1691 {
1692 case 0:
1693 /* Long options. */
1694 break;
1695 case 'H':
1696 usage ();
1697 break;
1698
1699 case 'a':
1700 do_syms ++;
1701 do_reloc ++;
1702 do_dynamic ++;
1703 do_header ++;
1704 do_sections ++;
1705 do_segments ++;
1706 do_version ++;
1707 do_histogram ++;
1708 do_arch ++;
1709 do_notes ++;
1710 break;
1711 case 'e':
1712 do_header ++;
1713 do_sections ++;
1714 do_segments ++;
1715 break;
1716 case 'A':
1717 do_arch ++;
1718 break;
1719 case 'D':
1720 do_using_dynamic ++;
1721 break;
1722 case 'r':
1723 do_reloc ++;
1724 break;
1725 case 'h':
1726 do_header ++;
1727 break;
1728 case 'l':
1729 do_segments ++;
1730 break;
1731 case 's':
1732 do_syms ++;
1733 break;
1734 case 'S':
1735 do_sections ++;
1736 break;
1737 case 'd':
1738 do_dynamic ++;
1739 break;
1740 case 'I':
1741 do_histogram ++;
1742 break;
1743 case 'n':
1744 do_notes ++;
1745 break;
1746 case 'x':
1747 do_dump ++;
1748 section = strtoul (optarg, & cp, 0);
1749 if (! * cp && section >= 0)
1750 {
1751 request_dump (section, HEX_DUMP);
1752 break;
1753 }
1754 goto oops;
1755 case 'w':
1756 do_dump ++;
1757 if (optarg == 0)
1758 do_debugging = 1;
1759 else
1760 {
1761 do_debugging = 0;
1762 switch (optarg[0])
1763 {
1764 case 'i':
1765 case 'I':
1766 do_debug_info = 1;
1767 break;
1768
1769 case 'a':
1770 case 'A':
1771 do_debug_abbrevs = 1;
1772 break;
1773
1774 case 'l':
1775 case 'L':
1776 do_debug_lines = 1;
1777 break;
1778
1779 case 'p':
1780 case 'P':
1781 do_debug_pubnames = 1;
1782 break;
1783
1784 case 'r':
1785 case 'R':
1786 do_debug_aranges = 1;
1787 break;
1788
1789 default:
1790 warn (_("Unrecognised debug option '%s'\n"), optarg);
1791 break;
1792 }
1793 }
1794 break;
1795 #ifdef SUPPORT_DISASSEMBLY
1796 case 'i':
1797 do_dump ++;
1798 section = strtoul (optarg, & cp, 0);
1799 if (! * cp && section >= 0)
1800 {
1801 request_dump (section, DISASS_DUMP);
1802 break;
1803 }
1804 goto oops;
1805 #endif
1806 case 'v':
1807 print_version (program_name);
1808 break;
1809 case 'V':
1810 do_version ++;
1811 break;
1812 default:
1813 oops:
1814 /* xgettext:c-format */
1815 error (_("Invalid option '-%c'\n"), c);
1816 /* Drop through. */
1817 case '?':
1818 usage ();
1819 }
1820 }
1821
1822 if (!do_dynamic && !do_syms && !do_reloc && !do_sections
1823 && !do_segments && !do_header && !do_dump && !do_version
1824 && !do_histogram && !do_debugging && !do_arch && !do_notes)
1825 usage ();
1826 else if (argc < 3)
1827 {
1828 warn (_("Nothing to do.\n"));
1829 usage();
1830 }
1831 }
1832
1833 static const char *
1834 get_elf_class (elf_class)
1835 unsigned char elf_class;
1836 {
1837 static char buff [32];
1838
1839 switch (elf_class)
1840 {
1841 case ELFCLASSNONE: return _("none");
1842 case ELFCLASS32: return _("ELF32");
1843 case ELFCLASS64: return _("ELF64");
1844 default:
1845 sprintf (buff, _("<unknown: %x>"), elf_class);
1846 return buff;
1847 }
1848 }
1849
1850 static const char *
1851 get_data_encoding (encoding)
1852 unsigned char encoding;
1853 {
1854 static char buff [32];
1855
1856 switch (encoding)
1857 {
1858 case ELFDATANONE: return _("none");
1859 case ELFDATA2LSB: return _("2's complement, little endian");
1860 case ELFDATA2MSB: return _("2's complement, big endian");
1861 default:
1862 sprintf (buff, _("<unknown: %x>"), encoding);
1863 return buff;
1864 }
1865 }
1866
1867 static const char *
1868 get_osabi_name (osabi)
1869 unsigned char osabi;
1870 {
1871 static char buff [32];
1872
1873 switch (osabi)
1874 {
1875 case ELFOSABI_SYSV: return _("UNIX - System V");
1876 case ELFOSABI_HPUX: return _("UNIX - HP-UX");
1877 case ELFOSABI_STANDALONE: return _("Standalone App");
1878 default:
1879 sprintf (buff, _("<unknown: %x>"), osabi);
1880 return buff;
1881 }
1882 }
1883
1884 /* Decode the data held in 'elf_header'. */
1885 static int
1886 process_file_header ()
1887 {
1888 if ( elf_header.e_ident [EI_MAG0] != ELFMAG0
1889 || elf_header.e_ident [EI_MAG1] != ELFMAG1
1890 || elf_header.e_ident [EI_MAG2] != ELFMAG2
1891 || elf_header.e_ident [EI_MAG3] != ELFMAG3)
1892 {
1893 error
1894 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
1895 return 0;
1896 }
1897
1898 if (do_header)
1899 {
1900 int i;
1901
1902 printf (_("ELF Header:\n"));
1903 printf (_(" Magic: "));
1904 for (i = 0; i < EI_NIDENT; i ++)
1905 printf ("%2.2x ", elf_header.e_ident [i]);
1906 printf ("\n");
1907 printf (_(" Class: %s\n"),
1908 get_elf_class (elf_header.e_ident [EI_CLASS]));
1909 printf (_(" Data: %s\n"),
1910 get_data_encoding (elf_header.e_ident [EI_DATA]));
1911 printf (_(" Version: %d %s\n"),
1912 elf_header.e_ident [EI_VERSION],
1913 (elf_header.e_ident [EI_VERSION] == EV_CURRENT
1914 ? "(current)"
1915 : (elf_header.e_ident [EI_VERSION] != EV_NONE
1916 ? "<unknown: %lx>"
1917 : "")));
1918 printf (_(" OS/ABI: %s\n"),
1919 get_osabi_name (elf_header.e_ident [EI_OSABI]));
1920 printf (_(" ABI Version: %d\n"),
1921 elf_header.e_ident [EI_ABIVERSION]);
1922 printf (_(" Type: %s\n"),
1923 get_file_type (elf_header.e_type));
1924 printf (_(" Machine: %s\n"),
1925 get_machine_name (elf_header.e_machine));
1926 printf (_(" Version: 0x%lx\n"),
1927 (unsigned long) elf_header.e_version);
1928
1929 printf (_(" Entry point address: "));
1930 print_vma ((bfd_vma) elf_header.e_entry, PREFIX_HEX);
1931 printf (_("\n Start of program headers: "));
1932 print_vma ((bfd_vma) elf_header.e_phoff, DEC);
1933 printf (_(" (bytes into file)\n Start of section headers: "));
1934 print_vma ((bfd_vma) elf_header.e_shoff, DEC);
1935 printf (_(" (bytes into file)\n"));
1936
1937 printf (_(" Flags: 0x%lx%s\n"),
1938 (unsigned long) elf_header.e_flags,
1939 get_machine_flags (elf_header.e_flags, elf_header.e_machine));
1940 printf (_(" Size of this header: %ld (bytes)\n"),
1941 (long) elf_header.e_ehsize);
1942 printf (_(" Size of program headers: %ld (bytes)\n"),
1943 (long) elf_header.e_phentsize);
1944 printf (_(" Number of program headers: %ld\n"),
1945 (long) elf_header.e_phnum);
1946 printf (_(" Size of section headers: %ld (bytes)\n"),
1947 (long) elf_header.e_shentsize);
1948 printf (_(" Number of section headers: %ld\n"),
1949 (long) elf_header.e_shnum);
1950 printf (_(" Section header string table index: %ld\n"),
1951 (long) elf_header.e_shstrndx);
1952 }
1953
1954 return 1;
1955 }
1956
1957
1958 static int
1959 get_32bit_program_headers (file, program_headers)
1960 FILE * file;
1961 Elf_Internal_Phdr * program_headers;
1962 {
1963 Elf32_External_Phdr * phdrs;
1964 Elf32_External_Phdr * external;
1965 Elf32_Internal_Phdr * internal;
1966 unsigned int i;
1967
1968 GET_DATA_ALLOC (elf_header.e_phoff,
1969 elf_header.e_phentsize * elf_header.e_phnum,
1970 phdrs, Elf32_External_Phdr *, "program headers");
1971
1972 for (i = 0, internal = program_headers, external = phdrs;
1973 i < elf_header.e_phnum;
1974 i ++, internal ++, external ++)
1975 {
1976 internal->p_type = BYTE_GET (external->p_type);
1977 internal->p_offset = BYTE_GET (external->p_offset);
1978 internal->p_vaddr = BYTE_GET (external->p_vaddr);
1979 internal->p_paddr = BYTE_GET (external->p_paddr);
1980 internal->p_filesz = BYTE_GET (external->p_filesz);
1981 internal->p_memsz = BYTE_GET (external->p_memsz);
1982 internal->p_flags = BYTE_GET (external->p_flags);
1983 internal->p_align = BYTE_GET (external->p_align);
1984 }
1985
1986 free (phdrs);
1987
1988 return 1;
1989 }
1990
1991 static int
1992 get_64bit_program_headers (file, program_headers)
1993 FILE * file;
1994 Elf_Internal_Phdr * program_headers;
1995 {
1996 Elf64_External_Phdr * phdrs;
1997 Elf64_External_Phdr * external;
1998 Elf64_Internal_Phdr * internal;
1999 unsigned int i;
2000
2001 GET_DATA_ALLOC (elf_header.e_phoff,
2002 elf_header.e_phentsize * elf_header.e_phnum,
2003 phdrs, Elf64_External_Phdr *, "program headers");
2004
2005 for (i = 0, internal = program_headers, external = phdrs;
2006 i < elf_header.e_phnum;
2007 i ++, internal ++, external ++)
2008 {
2009 internal->p_type = BYTE_GET (external->p_type);
2010 internal->p_flags = BYTE_GET (external->p_flags);
2011 internal->p_offset = BYTE_GET8 (external->p_offset);
2012 internal->p_vaddr = BYTE_GET8 (external->p_vaddr);
2013 internal->p_paddr = BYTE_GET8 (external->p_paddr);
2014 internal->p_filesz = BYTE_GET8 (external->p_filesz);
2015 internal->p_memsz = BYTE_GET8 (external->p_memsz);
2016 internal->p_align = BYTE_GET8 (external->p_align);
2017 }
2018
2019 free (phdrs);
2020
2021 return 1;
2022 }
2023
2024 static int
2025 process_program_headers (file)
2026 FILE * file;
2027 {
2028 Elf_Internal_Phdr * program_headers;
2029 Elf_Internal_Phdr * segment;
2030 unsigned int i;
2031
2032 if (elf_header.e_phnum == 0)
2033 {
2034 if (do_segments)
2035 printf (_("\nThere are no program headers in this file.\n"));
2036 return 1;
2037 }
2038
2039 if (do_segments && !do_header)
2040 {
2041 printf (_("\nElf file type is %s\n"), get_file_type (elf_header.e_type));
2042 printf (_("Entry point "));
2043 print_vma ((bfd_vma) elf_header.e_entry, PREFIX_HEX);
2044 printf (_("\nThere are %d program headers, starting at offset "),
2045 elf_header.e_phnum);
2046 print_vma ((bfd_vma) elf_header.e_phoff, DEC);
2047 printf ("\n");
2048 }
2049
2050 program_headers = (Elf_Internal_Phdr *) malloc
2051 (elf_header.e_phnum * sizeof (Elf_Internal_Phdr));
2052
2053 if (program_headers == NULL)
2054 {
2055 error (_("Out of memory\n"));
2056 return 0;
2057 }
2058
2059 if (is_32bit_elf)
2060 i = get_32bit_program_headers (file, program_headers);
2061 else
2062 i = get_64bit_program_headers (file, program_headers);
2063
2064 if (i == 0)
2065 {
2066 free (program_headers);
2067 return 0;
2068 }
2069
2070 if (do_segments)
2071 {
2072 printf
2073 (_("\nProgram Header%s:\n"), elf_header.e_phnum > 1 ? "s" : "");
2074
2075 if (is_32bit_elf)
2076 printf
2077 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
2078 else
2079 {
2080 printf
2081 (_(" Type Offset VirtAddr PhysAddr\n"));
2082 printf
2083 (_(" FileSiz MemSiz Flags Align\n"));
2084 }
2085 }
2086
2087 loadaddr = -1;
2088 dynamic_addr = 0;
2089 dynamic_size = 0;
2090
2091 for (i = 0, segment = program_headers;
2092 i < elf_header.e_phnum;
2093 i ++, segment ++)
2094 {
2095 if (do_segments)
2096 {
2097 printf (" %-14.14s ", get_segment_type (segment->p_type));
2098
2099 if (is_32bit_elf)
2100 {
2101 printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
2102 printf ("0x%8.8lx ", (unsigned long) segment->p_vaddr);
2103 printf ("0x%8.8lx ", (unsigned long) segment->p_paddr);
2104 printf ("0x%5.5lx ", (unsigned long) segment->p_filesz);
2105 printf ("0x%5.5lx ", (unsigned long) segment->p_memsz);
2106 printf ("%c%c%c ",
2107 (segment->p_flags & PF_R ? 'R' : ' '),
2108 (segment->p_flags & PF_W ? 'W' : ' '),
2109 (segment->p_flags & PF_X ? 'E' : ' '));
2110 printf ("%#lx", (unsigned long) segment->p_align);
2111 }
2112 else
2113 {
2114 print_vma (segment->p_offset, FULL_HEX);
2115 putchar (' ');
2116 print_vma (segment->p_vaddr, FULL_HEX);
2117 putchar (' ');
2118 print_vma (segment->p_paddr, FULL_HEX);
2119 printf ("\n ");
2120 print_vma (segment->p_filesz, FULL_HEX);
2121 putchar (' ');
2122 print_vma (segment->p_memsz, FULL_HEX);
2123 printf (" %c%c%c ",
2124 (segment->p_flags & PF_R ? 'R' : ' '),
2125 (segment->p_flags & PF_W ? 'W' : ' '),
2126 (segment->p_flags & PF_X ? 'E' : ' '));
2127 print_vma (segment->p_align, HEX);
2128 }
2129 }
2130
2131 switch (segment->p_type)
2132 {
2133 case PT_LOAD:
2134 if (loadaddr == -1)
2135 loadaddr = (segment->p_vaddr & 0xfffff000)
2136 - (segment->p_offset & 0xfffff000);
2137 break;
2138
2139 case PT_DYNAMIC:
2140 if (dynamic_addr)
2141 error (_("more than one dynamic segment\n"));
2142
2143 dynamic_addr = segment->p_offset;
2144 dynamic_size = segment->p_filesz;
2145 break;
2146
2147 case PT_INTERP:
2148 if (fseek (file, (long) segment->p_offset, SEEK_SET))
2149 error (_("Unable to find program interpreter name\n"));
2150 else
2151 {
2152 program_interpreter[0] = 0;
2153 fscanf (file, "%63s", program_interpreter);
2154
2155 if (do_segments)
2156 printf (_("\n [Requesting program interpreter: %s]"),
2157 program_interpreter);
2158 }
2159 break;
2160 }
2161
2162 if (do_segments)
2163 putc ('\n', stdout);
2164 }
2165
2166 if (loadaddr == -1)
2167 {
2168 /* Very strange. */
2169 loadaddr = 0;
2170 }
2171
2172 if (do_segments && section_headers != NULL)
2173 {
2174 printf (_("\n Section to Segment mapping:\n"));
2175 printf (_(" Segment Sections...\n"));
2176
2177 assert (string_table != NULL);
2178
2179 for (i = 0; i < elf_header.e_phnum; i++)
2180 {
2181 int j;
2182 Elf_Internal_Shdr * section;
2183
2184 segment = program_headers + i;
2185 section = section_headers;
2186
2187 printf (" %2.2d ", i);
2188
2189 for (j = 0; j < elf_header.e_shnum; j++, section ++)
2190 {
2191 if (section->sh_size > 0
2192 /* Compare allocated sections by VMA, unallocated
2193 sections by file offset. */
2194 && (section->sh_flags & SHF_ALLOC
2195 ? (section->sh_addr >= segment->p_vaddr
2196 && section->sh_addr + section->sh_size
2197 <= segment->p_vaddr + segment->p_memsz)
2198 : ((bfd_vma) section->sh_offset >= segment->p_offset
2199 && (section->sh_offset + section->sh_size
2200 <= segment->p_offset + segment->p_filesz))))
2201 printf ("%s ", SECTION_NAME (section));
2202 }
2203
2204 putc ('\n',stdout);
2205 }
2206 }
2207
2208 free (program_headers);
2209
2210 return 1;
2211 }
2212
2213
2214 static int
2215 get_32bit_section_headers (file)
2216 FILE * file;
2217 {
2218 Elf32_External_Shdr * shdrs;
2219 Elf32_Internal_Shdr * internal;
2220 unsigned int i;
2221
2222 GET_DATA_ALLOC (elf_header.e_shoff,
2223 elf_header.e_shentsize * elf_header.e_shnum,
2224 shdrs, Elf32_External_Shdr *, "section headers");
2225
2226 section_headers = (Elf_Internal_Shdr *) malloc
2227 (elf_header.e_shnum * sizeof (Elf_Internal_Shdr));
2228
2229 if (section_headers == NULL)
2230 {
2231 error (_("Out of memory\n"));
2232 return 0;
2233 }
2234
2235 for (i = 0, internal = section_headers;
2236 i < elf_header.e_shnum;
2237 i ++, internal ++)
2238 {
2239 internal->sh_name = BYTE_GET (shdrs[i].sh_name);
2240 internal->sh_type = BYTE_GET (shdrs[i].sh_type);
2241 internal->sh_flags = BYTE_GET (shdrs[i].sh_flags);
2242 internal->sh_addr = BYTE_GET (shdrs[i].sh_addr);
2243 internal->sh_offset = BYTE_GET (shdrs[i].sh_offset);
2244 internal->sh_size = BYTE_GET (shdrs[i].sh_size);
2245 internal->sh_link = BYTE_GET (shdrs[i].sh_link);
2246 internal->sh_info = BYTE_GET (shdrs[i].sh_info);
2247 internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
2248 internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize);
2249 }
2250
2251 free (shdrs);
2252
2253 return 1;
2254 }
2255
2256 static int
2257 get_64bit_section_headers (file)
2258 FILE * file;
2259 {
2260 Elf64_External_Shdr * shdrs;
2261 Elf64_Internal_Shdr * internal;
2262 unsigned int i;
2263
2264 GET_DATA_ALLOC (elf_header.e_shoff,
2265 elf_header.e_shentsize * elf_header.e_shnum,
2266 shdrs, Elf64_External_Shdr *, "section headers");
2267
2268 section_headers = (Elf_Internal_Shdr *) malloc
2269 (elf_header.e_shnum * sizeof (Elf_Internal_Shdr));
2270
2271 if (section_headers == NULL)
2272 {
2273 error (_("Out of memory\n"));
2274 return 0;
2275 }
2276
2277 for (i = 0, internal = section_headers;
2278 i < elf_header.e_shnum;
2279 i ++, internal ++)
2280 {
2281 internal->sh_name = BYTE_GET (shdrs[i].sh_name);
2282 internal->sh_type = BYTE_GET (shdrs[i].sh_type);
2283 internal->sh_flags = BYTE_GET8 (shdrs[i].sh_flags);
2284 internal->sh_addr = BYTE_GET8 (shdrs[i].sh_addr);
2285 internal->sh_size = BYTE_GET8 (shdrs[i].sh_size);
2286 internal->sh_entsize = BYTE_GET8 (shdrs[i].sh_entsize);
2287 internal->sh_link = BYTE_GET (shdrs[i].sh_link);
2288 internal->sh_info = BYTE_GET (shdrs[i].sh_info);
2289 internal->sh_offset = BYTE_GET (shdrs[i].sh_offset);
2290 internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
2291 }
2292
2293 free (shdrs);
2294
2295 return 1;
2296 }
2297
2298 static Elf_Internal_Sym *
2299 get_32bit_elf_symbols (file, offset, number)
2300 FILE * file;
2301 unsigned long offset;
2302 unsigned long number;
2303 {
2304 Elf32_External_Sym * esyms;
2305 Elf_Internal_Sym * isyms;
2306 Elf_Internal_Sym * psym;
2307 unsigned int j;
2308
2309 GET_DATA_ALLOC (offset, number * sizeof (Elf32_External_Sym),
2310 esyms, Elf32_External_Sym *, "symbols");
2311
2312 isyms = (Elf_Internal_Sym *) malloc (number * sizeof (Elf_Internal_Sym));
2313
2314 if (isyms == NULL)
2315 {
2316 error (_("Out of memory\n"));
2317 free (esyms);
2318
2319 return NULL;
2320 }
2321
2322 for (j = 0, psym = isyms;
2323 j < number;
2324 j ++, psym ++)
2325 {
2326 psym->st_name = BYTE_GET (esyms[j].st_name);
2327 psym->st_value = BYTE_GET (esyms[j].st_value);
2328 psym->st_size = BYTE_GET (esyms[j].st_size);
2329 psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
2330 psym->st_info = BYTE_GET (esyms[j].st_info);
2331 psym->st_other = BYTE_GET (esyms[j].st_other);
2332 }
2333
2334 free (esyms);
2335
2336 return isyms;
2337 }
2338
2339 static Elf_Internal_Sym *
2340 get_64bit_elf_symbols (file, offset, number)
2341 FILE * file;
2342 unsigned long offset;
2343 unsigned long number;
2344 {
2345 Elf64_External_Sym * esyms;
2346 Elf_Internal_Sym * isyms;
2347 Elf_Internal_Sym * psym;
2348 unsigned int j;
2349
2350 GET_DATA_ALLOC (offset, number * sizeof (Elf64_External_Sym),
2351 esyms, Elf64_External_Sym *, "symbols");
2352
2353 isyms = (Elf_Internal_Sym *) malloc (number * sizeof (Elf_Internal_Sym));
2354
2355 if (isyms == NULL)
2356 {
2357 error (_("Out of memory\n"));
2358 free (esyms);
2359
2360 return NULL;
2361 }
2362
2363 for (j = 0, psym = isyms;
2364 j < number;
2365 j ++, psym ++)
2366 {
2367 psym->st_name = BYTE_GET (esyms[j].st_name);
2368 psym->st_info = BYTE_GET (esyms[j].st_info);
2369 psym->st_other = BYTE_GET (esyms[j].st_other);
2370 psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
2371 psym->st_value = BYTE_GET8 (esyms[j].st_value);
2372 psym->st_size = BYTE_GET8 (esyms[j].st_size);
2373 }
2374
2375 free (esyms);
2376
2377 return isyms;
2378 }
2379
2380 static int
2381 process_section_headers (file)
2382 FILE * file;
2383 {
2384 Elf_Internal_Shdr * section;
2385 int i;
2386
2387 section_headers = NULL;
2388
2389 if (elf_header.e_shnum == 0)
2390 {
2391 if (do_sections)
2392 printf (_("\nThere are no sections in this file.\n"));
2393
2394 return 1;
2395 }
2396
2397 if (do_sections && !do_header)
2398 printf (_("There are %d section headers, starting at offset 0x%lx:\n"),
2399 elf_header.e_shnum, (unsigned long) elf_header.e_shoff);
2400
2401 if (is_32bit_elf)
2402 {
2403 if (! get_32bit_section_headers (file))
2404 return 0;
2405 }
2406 else if (! get_64bit_section_headers (file))
2407 return 0;
2408
2409 /* Read in the string table, so that we have names to display. */
2410 section = section_headers + elf_header.e_shstrndx;
2411
2412 if (section->sh_size != 0)
2413 {
2414 unsigned long string_table_offset;
2415
2416 string_table_offset = section->sh_offset;
2417
2418 GET_DATA_ALLOC (section->sh_offset, section->sh_size,
2419 string_table, char *, "string table");
2420 }
2421
2422 /* Scan the sections for the dynamic symbol table
2423 and dynamic string table and debug sections. */
2424 dynamic_symbols = NULL;
2425 dynamic_strings = NULL;
2426 dynamic_syminfo = NULL;
2427
2428 for (i = 0, section = section_headers;
2429 i < elf_header.e_shnum;
2430 i ++, section ++)
2431 {
2432 char * name = SECTION_NAME (section);
2433
2434 if (section->sh_type == SHT_DYNSYM)
2435 {
2436 if (dynamic_symbols != NULL)
2437 {
2438 error (_("File contains multiple dynamic symbol tables\n"));
2439 continue;
2440 }
2441
2442 num_dynamic_syms = section->sh_size / section->sh_entsize;
2443 dynamic_symbols =
2444 GET_ELF_SYMBOLS (file, section->sh_offset, num_dynamic_syms);
2445 }
2446 else if (section->sh_type == SHT_STRTAB
2447 && strcmp (name, ".dynstr") == 0)
2448 {
2449 if (dynamic_strings != NULL)
2450 {
2451 error (_("File contains multiple dynamic string tables\n"));
2452 continue;
2453 }
2454
2455 GET_DATA_ALLOC (section->sh_offset, section->sh_size,
2456 dynamic_strings, char *, "dynamic strings");
2457 }
2458 else if ((do_debugging || do_debug_info || do_debug_abbrevs
2459 || do_debug_lines || do_debug_pubnames || do_debug_aranges)
2460 && strncmp (name, ".debug_", 7) == 0)
2461 {
2462 name += 7;
2463
2464 if (do_debugging
2465 || (do_debug_info && (strcmp (name, "info") == 0))
2466 || (do_debug_abbrevs && (strcmp (name, "abbrev") == 0))
2467 || (do_debug_lines && (strcmp (name, "line") == 0))
2468 || (do_debug_pubnames && (strcmp (name, "pubnames") == 0))
2469 || (do_debug_aranges && (strcmp (name, "aranges") == 0))
2470 )
2471 request_dump (i, DEBUG_DUMP);
2472 }
2473 }
2474
2475 if (! do_sections)
2476 return 1;
2477
2478 printf (_("\nSection Header%s:\n"), elf_header.e_shnum > 1 ? "s" : "");
2479 if (is_32bit_elf)
2480 printf
2481 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
2482 else
2483 {
2484 printf (_(" [Nr] Name Type Address Offset\n"));
2485 printf (_(" Size EntSize Flags Link Info Align\n"));
2486 }
2487
2488 for (i = 0, section = section_headers;
2489 i < elf_header.e_shnum;
2490 i ++, section ++)
2491 {
2492 printf (" [%2d] %-17.17s %-15.15s ",
2493 i,
2494 SECTION_NAME (section),
2495 get_section_type_name (section->sh_type));
2496
2497 if (is_32bit_elf)
2498 {
2499 print_vma (section->sh_addr, LONG_HEX);
2500
2501 printf ( " %6.6lx %6.6lx %2.2lx",
2502 (unsigned long) section->sh_offset,
2503 (unsigned long) section->sh_size,
2504 (unsigned long) section->sh_entsize);
2505
2506 printf (" %c%c%c %2ld %3lx %ld\n",
2507 (section->sh_flags & SHF_WRITE ? 'W' : ' '),
2508 (section->sh_flags & SHF_ALLOC ? 'A' : ' '),
2509 (section->sh_flags & SHF_EXECINSTR ? 'X' : ' '),
2510 (unsigned long) section->sh_link,
2511 (unsigned long) section->sh_info,
2512 (unsigned long) section->sh_addralign);
2513 }
2514 else
2515 {
2516 putchar (' ');
2517 print_vma (section->sh_addr, LONG_HEX);
2518 printf (" %8.8lx", section->sh_offset);
2519 printf ("\n ");
2520 print_vma (section->sh_size, LONG_HEX);
2521 printf (" ");
2522 print_vma (section->sh_entsize, LONG_HEX);
2523
2524 printf (" %c%c%c",
2525 (section->sh_flags & SHF_WRITE ? 'W' : ' '),
2526 (section->sh_flags & SHF_ALLOC ? 'A' : ' '),
2527 (section->sh_flags & SHF_EXECINSTR ? 'X' : ' '));
2528
2529 printf (" %2ld %3lx %ld\n",
2530 (unsigned long) section->sh_link,
2531 (unsigned long) section->sh_info,
2532 (unsigned long) section->sh_addralign);
2533 }
2534 }
2535
2536 return 1;
2537 }
2538
2539 /* Process the reloc section. */
2540 static int
2541 process_relocs (file)
2542 FILE * file;
2543 {
2544 unsigned long rel_size;
2545 unsigned long rel_offset;
2546
2547
2548 if (!do_reloc)
2549 return 1;
2550
2551 if (do_using_dynamic)
2552 {
2553 int is_rela = FALSE;
2554
2555 rel_size = 0;
2556 rel_offset = 0;
2557
2558 if (dynamic_info[DT_REL])
2559 {
2560 rel_offset = dynamic_info[DT_REL];
2561 rel_size = dynamic_info[DT_RELSZ];
2562 is_rela = FALSE;
2563 }
2564 else if (dynamic_info [DT_RELA])
2565 {
2566 rel_offset = dynamic_info[DT_RELA];
2567 rel_size = dynamic_info[DT_RELASZ];
2568 is_rela = TRUE;
2569 }
2570 else if (dynamic_info[DT_JMPREL])
2571 {
2572 rel_offset = dynamic_info[DT_JMPREL];
2573 rel_size = dynamic_info[DT_PLTRELSZ];
2574
2575 switch (dynamic_info[DT_PLTREL])
2576 {
2577 case DT_REL:
2578 is_rela = FALSE;
2579 break;
2580 case DT_RELA:
2581 is_rela = TRUE;
2582 break;
2583 default:
2584 is_rela = UNKNOWN;
2585 break;
2586 }
2587 }
2588
2589 if (rel_size)
2590 {
2591 printf
2592 (_("\nRelocation section at offset 0x%lx contains %ld bytes:\n"),
2593 rel_offset, rel_size);
2594
2595 dump_relocations (file, rel_offset - loadaddr, rel_size,
2596 dynamic_symbols, num_dynamic_syms, dynamic_strings, is_rela);
2597 }
2598 else
2599 printf (_("\nThere are no dynamic relocations in this file.\n"));
2600 }
2601 else
2602 {
2603 Elf32_Internal_Shdr * section;
2604 unsigned long i;
2605 int found = 0;
2606
2607 for (i = 0, section = section_headers;
2608 i < elf_header.e_shnum;
2609 i++, section ++)
2610 {
2611 if ( section->sh_type != SHT_RELA
2612 && section->sh_type != SHT_REL)
2613 continue;
2614
2615 rel_offset = section->sh_offset;
2616 rel_size = section->sh_size;
2617
2618 if (rel_size)
2619 {
2620 Elf32_Internal_Shdr * strsec;
2621 Elf32_Internal_Shdr * symsec;
2622 Elf_Internal_Sym * symtab;
2623 char * strtab;
2624 int is_rela;
2625 unsigned long nsyms;
2626
2627 printf (_("\nRelocation section "));
2628
2629 if (string_table == NULL)
2630 printf ("%d", section->sh_name);
2631 else
2632 printf ("'%s'", SECTION_NAME (section));
2633
2634 printf (_(" at offset 0x%lx contains %lu entries:\n"),
2635 rel_offset, (unsigned long) (rel_size / section->sh_entsize));
2636
2637 symsec = section_headers + section->sh_link;
2638
2639 nsyms = symsec->sh_size / symsec->sh_entsize;
2640 symtab = GET_ELF_SYMBOLS (file, symsec->sh_offset, nsyms);
2641
2642 if (symtab == NULL)
2643 continue;
2644
2645 strsec = section_headers + symsec->sh_link;
2646
2647 GET_DATA_ALLOC (strsec->sh_offset, strsec->sh_size, strtab,
2648 char *, "string table");
2649
2650 is_rela = section->sh_type == SHT_RELA;
2651
2652 dump_relocations (file, rel_offset, rel_size, symtab, nsyms, strtab, is_rela);
2653
2654 free (strtab);
2655 free (symtab);
2656
2657 found = 1;
2658 }
2659 }
2660
2661 if (! found)
2662 printf (_("\nThere are no relocations in this file.\n"));
2663 }
2664
2665 return 1;
2666 }
2667
2668
2669 static void
2670 dynamic_segment_mips_val (entry)
2671 Elf_Internal_Dyn * entry;
2672 {
2673 switch (entry->d_tag)
2674 {
2675 case DT_MIPS_FLAGS:
2676 if (entry->d_un.d_val == 0)
2677 printf ("NONE\n");
2678 else
2679 {
2680 static const char * opts[] =
2681 {
2682 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
2683 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
2684 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
2685 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
2686 "RLD_ORDER_SAFE"
2687 };
2688 unsigned int cnt;
2689 int first = 1;
2690 for (cnt = 0; cnt < NUM_ELEM (opts); ++ cnt)
2691 if (entry->d_un.d_val & (1 << cnt))
2692 {
2693 printf ("%s%s", first ? "" : " ", opts[cnt]);
2694 first = 0;
2695 }
2696 puts ("");
2697 }
2698 break;
2699
2700 case DT_MIPS_IVERSION:
2701 if (dynamic_strings != NULL)
2702 printf ("Interface Version: %s\n",
2703 dynamic_strings + entry->d_un.d_val);
2704 else
2705 printf ("%ld\n", (long) entry->d_un.d_ptr);
2706 break;
2707
2708 case DT_MIPS_TIME_STAMP:
2709 {
2710 char timebuf[20];
2711 time_t time = entry->d_un.d_val;
2712 strftime (timebuf, 20, "%Y-%m-%dT%H:%M:%S", gmtime (&time));
2713 printf ("Time Stamp: %s\n", timebuf);
2714 }
2715 break;
2716
2717 case DT_MIPS_RLD_VERSION:
2718 case DT_MIPS_LOCAL_GOTNO:
2719 case DT_MIPS_CONFLICTNO:
2720 case DT_MIPS_LIBLISTNO:
2721 case DT_MIPS_SYMTABNO:
2722 case DT_MIPS_UNREFEXTNO:
2723 case DT_MIPS_HIPAGENO:
2724 case DT_MIPS_DELTA_CLASS_NO:
2725 case DT_MIPS_DELTA_INSTANCE_NO:
2726 case DT_MIPS_DELTA_RELOC_NO:
2727 case DT_MIPS_DELTA_SYM_NO:
2728 case DT_MIPS_DELTA_CLASSSYM_NO:
2729 case DT_MIPS_COMPACT_SIZE:
2730 printf ("%ld\n", (long) entry->d_un.d_ptr);
2731 break;
2732
2733 default:
2734 printf ("%#lx\n", (long) entry->d_un.d_ptr);
2735 }
2736 }
2737
2738
2739 static void
2740 dynamic_segment_parisc_val (entry)
2741 Elf_Internal_Dyn * entry;
2742 {
2743 switch (entry->d_tag)
2744 {
2745 case DT_HP_DLD_FLAGS:
2746 {
2747 static struct
2748 {
2749 long int bit;
2750 const char * str;
2751 }
2752 flags[] =
2753 {
2754 { DT_HP_DEBUG_PRIVATE, "HP_DEBUG_PRIVATE" },
2755 { DT_HP_DEBUG_CALLBACK, "HP_DEBUG_CALLBACK" },
2756 { DT_HP_DEBUG_CALLBACK_BOR, "HP_DEBUG_CALLBACK_BOR" },
2757 { DT_HP_NO_ENVVAR, "HP_NO_ENVVAR" },
2758 { DT_HP_BIND_NOW, "HP_BIND_NOW" },
2759 { DT_HP_BIND_NONFATAL, "HP_BIND_NONFATAL" },
2760 { DT_HP_BIND_VERBOSE, "HP_BIND_VERBOSE" },
2761 { DT_HP_BIND_RESTRICTED, "HP_BIND_RESTRICTED" },
2762 { DT_HP_BIND_SYMBOLIC, "HP_BIND_SYMBOLIC" },
2763 { DT_HP_RPATH_FIRST, "HP_RPATH_FIRST" },
2764 { DT_HP_BIND_DEPTH_FIRST, "HP_BIND_DEPTH_FIRST" }
2765 };
2766 int first = 1;
2767 size_t cnt;
2768 bfd_vma val = entry->d_un.d_val;
2769
2770 for (cnt = 0; cnt < sizeof (flags) / sizeof (flags[0]); ++cnt)
2771 if (val & flags[cnt].bit)
2772 {
2773 if (! first)
2774 putchar (' ');
2775 fputs (flags[cnt].str, stdout);
2776 first = 0;
2777 val ^= flags[cnt].bit;
2778 }
2779
2780 if (val != 0 || first)
2781 {
2782 if (! first)
2783 putchar (' ');
2784 print_vma (val, HEX);
2785 }
2786 }
2787 break;
2788
2789 default:
2790 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
2791 break;
2792 }
2793 }
2794
2795 static int
2796 get_32bit_dynamic_segment (file)
2797 FILE * file;
2798 {
2799 Elf32_External_Dyn * edyn;
2800 Elf_Internal_Dyn * entry;
2801 bfd_size_type i;
2802
2803 GET_DATA_ALLOC (dynamic_addr, dynamic_size,
2804 edyn, Elf32_External_Dyn *, "dynamic segment");
2805
2806 /* SGI's ELF has more than one section in the DYNAMIC segment. Determine
2807 how large this .dynamic is now. We can do this even before the byte
2808 swapping since the DT_NULL tag is recognizable. */
2809 dynamic_size = 0;
2810 while (*(Elf32_Word *) edyn [dynamic_size++].d_tag != DT_NULL)
2811 ;
2812
2813 dynamic_segment = (Elf_Internal_Dyn *)
2814 malloc (dynamic_size * sizeof (Elf_Internal_Dyn));
2815
2816 if (dynamic_segment == NULL)
2817 {
2818 error (_("Out of memory\n"));
2819 free (edyn);
2820 return 0;
2821 }
2822
2823 for (i = 0, entry = dynamic_segment;
2824 i < dynamic_size;
2825 i ++, entry ++)
2826 {
2827 entry->d_tag = BYTE_GET (edyn [i].d_tag);
2828 entry->d_un.d_val = BYTE_GET (edyn [i].d_un.d_val);
2829 }
2830
2831 free (edyn);
2832
2833 return 1;
2834 }
2835
2836 static int
2837 get_64bit_dynamic_segment (file)
2838 FILE * file;
2839 {
2840 Elf64_External_Dyn * edyn;
2841 Elf_Internal_Dyn * entry;
2842 bfd_size_type i;
2843
2844 GET_DATA_ALLOC (dynamic_addr, dynamic_size,
2845 edyn, Elf64_External_Dyn *, "dynamic segment");
2846
2847 /* SGI's ELF has more than one section in the DYNAMIC segment. Determine
2848 how large this .dynamic is now. We can do this even before the byte
2849 swapping since the DT_NULL tag is recognizable. */
2850 dynamic_size = 0;
2851 while (*(bfd_vma *) edyn [dynamic_size ++].d_tag != DT_NULL)
2852 ;
2853
2854 dynamic_segment = (Elf_Internal_Dyn *)
2855 malloc (dynamic_size * sizeof (Elf_Internal_Dyn));
2856
2857 if (dynamic_segment == NULL)
2858 {
2859 error (_("Out of memory\n"));
2860 free (edyn);
2861 return 0;
2862 }
2863
2864 for (i = 0, entry = dynamic_segment;
2865 i < dynamic_size;
2866 i ++, entry ++)
2867 {
2868 entry->d_tag = BYTE_GET8 (edyn [i].d_tag);
2869 entry->d_un.d_val = BYTE_GET8 (edyn [i].d_un.d_val);
2870 }
2871
2872 free (edyn);
2873
2874 return 1;
2875 }
2876
2877 /* Parse and display the contents of the dynamic segment. */
2878 static int
2879 process_dynamic_segment (file)
2880 FILE * file;
2881 {
2882 Elf_Internal_Dyn * entry;
2883 bfd_size_type i;
2884
2885 if (dynamic_size == 0)
2886 {
2887 if (do_dynamic)
2888 printf (_("\nThere is no dynamic segment in this file.\n"));
2889
2890 return 1;
2891 }
2892
2893 if (is_32bit_elf)
2894 {
2895 if (! get_32bit_dynamic_segment (file))
2896 return 0;
2897 }
2898 else if (! get_64bit_dynamic_segment (file))
2899 return 0;
2900
2901 /* Find the appropriate symbol table. */
2902 if (dynamic_symbols == NULL)
2903 {
2904 for (i = 0, entry = dynamic_segment;
2905 i < dynamic_size;
2906 ++i, ++ entry)
2907 {
2908 unsigned long offset;
2909
2910 if (entry->d_tag != DT_SYMTAB)
2911 continue;
2912
2913 dynamic_info[DT_SYMTAB] = entry->d_un.d_val;
2914
2915 /* Since we do not know how big the symbol table is,
2916 we default to reading in the entire file (!) and
2917 processing that. This is overkill, I know, but it
2918 should work. */
2919 offset = entry->d_un.d_val - loadaddr;
2920
2921 if (fseek (file, 0, SEEK_END))
2922 error (_("Unable to seek to end of file!"));
2923
2924 if (is_32bit_elf)
2925 num_dynamic_syms = (ftell (file) - offset) / sizeof (Elf32_External_Sym);
2926 else
2927 num_dynamic_syms = (ftell (file) - offset) / sizeof (Elf64_External_Sym);
2928
2929 if (num_dynamic_syms < 1)
2930 {
2931 error (_("Unable to determine the number of symbols to load\n"));
2932 continue;
2933 }
2934
2935 dynamic_symbols = GET_ELF_SYMBOLS (file, offset, num_dynamic_syms);
2936 }
2937 }
2938
2939 /* Similarly find a string table. */
2940 if (dynamic_strings == NULL)
2941 {
2942 for (i = 0, entry = dynamic_segment;
2943 i < dynamic_size;
2944 ++i, ++ entry)
2945 {
2946 unsigned long offset;
2947 long str_tab_len;
2948
2949 if (entry->d_tag != DT_STRTAB)
2950 continue;
2951
2952 dynamic_info[DT_STRTAB] = entry->d_un.d_val;
2953
2954 /* Since we do not know how big the string table is,
2955 we default to reading in the entire file (!) and
2956 processing that. This is overkill, I know, but it
2957 should work. */
2958
2959 offset = entry->d_un.d_val - loadaddr;
2960 if (fseek (file, 0, SEEK_END))
2961 error (_("Unable to seek to end of file\n"));
2962 str_tab_len = ftell (file) - offset;
2963
2964 if (str_tab_len < 1)
2965 {
2966 error
2967 (_("Unable to determine the length of the dynamic string table\n"));
2968 continue;
2969 }
2970
2971 GET_DATA_ALLOC (offset, str_tab_len, dynamic_strings, char *,
2972 "dynamic string table");
2973
2974 break;
2975 }
2976 }
2977
2978 /* And find the syminfo section if available. */
2979 if (dynamic_syminfo == NULL)
2980 {
2981 unsigned int syminsz = 0;
2982
2983 for (i = 0, entry = dynamic_segment;
2984 i < dynamic_size;
2985 ++i, ++ entry)
2986 {
2987 if (entry->d_tag == DT_SYMINENT)
2988 {
2989 /* Note: these braces are necessary to avoid a syntax
2990 error from the SunOS4 C compiler. */
2991 assert (sizeof (Elf_External_Syminfo) == entry->d_un.d_val);
2992 }
2993 else if (entry->d_tag == DT_SYMINSZ)
2994 syminsz = entry->d_un.d_val;
2995 else if (entry->d_tag == DT_SYMINFO)
2996 dynamic_syminfo_offset = entry->d_un.d_val - loadaddr;
2997 }
2998
2999 if (dynamic_syminfo_offset != 0 && syminsz != 0)
3000 {
3001 Elf_External_Syminfo * extsyminfo;
3002 Elf_Internal_Syminfo * syminfo;
3003
3004 /* There is a syminfo section. Read the data. */
3005 GET_DATA_ALLOC (dynamic_syminfo_offset, syminsz, extsyminfo,
3006 Elf_External_Syminfo *, "symbol information");
3007
3008 dynamic_syminfo = (Elf_Internal_Syminfo *) malloc (syminsz);
3009 if (dynamic_syminfo == NULL)
3010 {
3011 error (_("Out of memory\n"));
3012 return 0;
3013 }
3014
3015 dynamic_syminfo_nent = syminsz / sizeof (Elf_External_Syminfo);
3016 for (i = 0, syminfo = dynamic_syminfo; i < dynamic_syminfo_nent;
3017 ++i, ++syminfo)
3018 {
3019 syminfo->si_boundto = BYTE_GET (extsyminfo[i].si_boundto);
3020 syminfo->si_flags = BYTE_GET (extsyminfo[i].si_flags);
3021 }
3022
3023 free (extsyminfo);
3024 }
3025 }
3026
3027 if (do_dynamic && dynamic_addr)
3028 printf (_("\nDynamic segment at offset 0x%x contains %ld entries:\n"),
3029 dynamic_addr, (long) dynamic_size);
3030 if (do_dynamic)
3031 printf (_(" Tag Type Name/Value\n"));
3032
3033 for (i = 0, entry = dynamic_segment;
3034 i < dynamic_size;
3035 i++, entry ++)
3036 {
3037 if (do_dynamic)
3038 {
3039 putchar (' ');
3040 print_vma (entry->d_tag, FULL_HEX);
3041 printf (" (%s)%*s",
3042 get_dynamic_type (entry->d_tag),
3043 (is_32bit_elf ? 27 : 19) - strlen (get_dynamic_type (entry->d_tag)),
3044 " ");
3045 }
3046
3047 switch (entry->d_tag)
3048 {
3049 case DT_AUXILIARY:
3050 case DT_FILTER:
3051 if (do_dynamic)
3052 {
3053 if (entry->d_tag == DT_AUXILIARY)
3054 printf (_("Auxiliary library"));
3055 else
3056 printf (_("Filter library"));
3057
3058 if (dynamic_strings)
3059 printf (": [%s]\n", dynamic_strings + entry->d_un.d_val);
3060 else
3061 {
3062 printf (": ");
3063 print_vma (entry->d_un.d_val, PREFIX_HEX);
3064 putchar ('\n');
3065 }
3066 }
3067 break;
3068
3069 case DT_FEATURE_1:
3070 if (do_dynamic)
3071 {
3072 printf (_("Flags:"));
3073 if (entry->d_un.d_val == 0)
3074 printf (_(" None\n"));
3075 else
3076 {
3077 unsigned long int val = entry->d_un.d_val;
3078 if (val & DTF_1_PARINIT)
3079 {
3080 printf (" PARINIT");
3081 val ^= DTF_1_PARINIT;
3082 }
3083 if (val != 0)
3084 printf (" %lx", val);
3085 puts ("");
3086 }
3087 }
3088 break;
3089
3090 case DT_POSFLAG_1:
3091 if (do_dynamic)
3092 {
3093 printf (_("Flags:"));
3094 if (entry->d_un.d_val == 0)
3095 printf (_(" None\n"));
3096 else
3097 {
3098 unsigned long int val = entry->d_un.d_val;
3099 if (val & DF_P1_LAZYLOAD)
3100 {
3101 printf (" LAZYLOAD");
3102 val ^= DF_P1_LAZYLOAD;
3103 }
3104 if (val & DF_P1_GROUPPERM)
3105 {
3106 printf (" GROUPPERM");
3107 val ^= DF_P1_GROUPPERM;
3108 }
3109 if (val != 0)
3110 printf (" %lx", val);
3111 puts ("");
3112 }
3113 }
3114 break;
3115
3116 case DT_FLAGS_1:
3117 if (do_dynamic)
3118 {
3119 printf (_("Flags:"));
3120 if (entry->d_un.d_val == 0)
3121 printf (_(" None\n"));
3122 else
3123 {
3124 unsigned long int val = entry->d_un.d_val;
3125 if (val & DF_1_NOW)
3126 {
3127 printf (" NOW");
3128 val ^= DF_1_NOW;
3129 }
3130 if (val & DF_1_GLOBAL)
3131 {
3132 printf (" GLOBAL");
3133 val ^= DF_1_GLOBAL;
3134 }
3135 if (val & DF_1_GROUP)
3136 {
3137 printf (" GROUP");
3138 val ^= DF_1_GROUP;
3139 }
3140 if (val & DF_1_NODELETE)
3141 {
3142 printf (" NODELETE");
3143 val ^= DF_1_NODELETE;
3144 }
3145 if (val & DF_1_LOADFLTR)
3146 {
3147 printf (" LOADFLTR");
3148 val ^= DF_1_LOADFLTR;
3149 }
3150 if (val & DF_1_INITFIRST)
3151 {
3152 printf (" INITFIRST");
3153 val ^= DF_1_INITFIRST;
3154 }
3155 if (val & DF_1_NOOPEN)
3156 {
3157 printf (" NOOPEN");
3158 val ^= DF_1_NOOPEN;
3159 }
3160 if (val & DF_1_ORIGIN)
3161 {
3162 printf (" ORIGIN");
3163 val ^= DF_1_ORIGIN;
3164 }
3165 if (val & DF_1_DIRECT)
3166 {
3167 printf (" DIRECT");
3168 val ^= DF_1_DIRECT;
3169 }
3170 if (val & DF_1_TRANS)
3171 {
3172 printf (" TRANS");
3173 val ^= DF_1_TRANS;
3174 }
3175 if (val & DF_1_INTERPOSE)
3176 {
3177 printf (" INTERPOSE");
3178 val ^= DF_1_INTERPOSE;
3179 }
3180 if (val != 0)
3181 printf (" %lx", val);
3182 puts ("");
3183 }
3184 }
3185 break;
3186
3187 case DT_PLTREL:
3188 if (do_dynamic)
3189 puts (get_dynamic_type (entry->d_un.d_val));
3190 break;
3191
3192 case DT_NULL :
3193 case DT_NEEDED :
3194 case DT_PLTGOT :
3195 case DT_HASH :
3196 case DT_STRTAB :
3197 case DT_SYMTAB :
3198 case DT_RELA :
3199 case DT_INIT :
3200 case DT_FINI :
3201 case DT_SONAME :
3202 case DT_RPATH :
3203 case DT_SYMBOLIC:
3204 case DT_REL :
3205 case DT_DEBUG :
3206 case DT_TEXTREL :
3207 case DT_JMPREL :
3208 dynamic_info[entry->d_tag] = entry->d_un.d_val;
3209
3210 if (do_dynamic)
3211 {
3212 char * name;
3213
3214 if (dynamic_strings == NULL)
3215 name = NULL;
3216 else
3217 name = dynamic_strings + entry->d_un.d_val;
3218
3219 if (name)
3220 {
3221 switch (entry->d_tag)
3222 {
3223 case DT_NEEDED:
3224 printf (_("Shared library: [%s]"), name);
3225
3226 if (strcmp (name, program_interpreter) == 0)
3227 printf (_(" program interpreter"));
3228 break;
3229
3230 case DT_SONAME:
3231 printf (_("Library soname: [%s]"), name);
3232 break;
3233
3234 case DT_RPATH:
3235 printf (_("Library rpath: [%s]"), name);
3236 break;
3237
3238 default:
3239 print_vma (entry->d_un.d_val, PREFIX_HEX);
3240 break;
3241 }
3242 }
3243 else
3244 print_vma (entry->d_un.d_val, PREFIX_HEX);
3245
3246 putchar ('\n');
3247 }
3248 break;
3249
3250 case DT_PLTRELSZ:
3251 case DT_RELASZ :
3252 case DT_STRSZ :
3253 case DT_RELSZ :
3254 case DT_RELAENT :
3255 case DT_SYMENT :
3256 case DT_RELENT :
3257 case DT_PLTPADSZ:
3258 case DT_MOVEENT :
3259 case DT_MOVESZ :
3260 case DT_INIT_ARRAYSZ:
3261 case DT_FINI_ARRAYSZ:
3262 if (do_dynamic)
3263 {
3264 print_vma (entry->d_un.d_val, UNSIGNED);
3265 printf (" (bytes)\n");
3266 }
3267 break;
3268
3269 case DT_VERDEFNUM:
3270 case DT_VERNEEDNUM:
3271 case DT_RELACOUNT:
3272 case DT_RELCOUNT:
3273 if (do_dynamic)
3274 {
3275 print_vma (entry->d_un.d_val, UNSIGNED);
3276 putchar ('\n');
3277 }
3278 break;
3279
3280 case DT_SYMINSZ:
3281 case DT_SYMINENT:
3282 case DT_SYMINFO:
3283 case DT_USED:
3284 case DT_INIT_ARRAY:
3285 case DT_FINI_ARRAY:
3286 if (do_dynamic)
3287 {
3288 if (dynamic_strings != NULL && entry->d_tag == DT_USED)
3289 {
3290 char * name;
3291
3292 name = dynamic_strings + entry->d_un.d_val;
3293
3294 if (* name)
3295 {
3296 printf (_("Not needed object: [%s]\n"), name);
3297 break;
3298 }
3299 }
3300
3301 print_vma (entry->d_un.d_val, PREFIX_HEX);
3302 putchar ('\n');
3303 }
3304 break;
3305
3306 case DT_BIND_NOW:
3307 /* The value of this entry is ignored. */
3308 break;
3309
3310 default:
3311 if ((entry->d_tag >= DT_VERSYM) && (entry->d_tag <= DT_VERNEEDNUM))
3312 version_info [DT_VERSIONTAGIDX (entry->d_tag)] =
3313 entry->d_un.d_val;
3314
3315 if (do_dynamic)
3316 {
3317 switch (elf_header.e_machine)
3318 {
3319 case EM_MIPS:
3320 case EM_MIPS_RS4_BE:
3321 dynamic_segment_mips_val (entry);
3322 break;
3323 case EM_PARISC:
3324 dynamic_segment_parisc_val (entry);
3325 break;
3326 default:
3327 print_vma (entry->d_un.d_val, PREFIX_HEX);
3328 putchar ('\n');
3329 }
3330 }
3331 break;
3332 }
3333 }
3334
3335 return 1;
3336 }
3337
3338 static char *
3339 get_ver_flags (flags)
3340 unsigned int flags;
3341 {
3342 static char buff [32];
3343
3344 buff[0] = 0;
3345
3346 if (flags == 0)
3347 return _("none");
3348
3349 if (flags & VER_FLG_BASE)
3350 strcat (buff, "BASE ");
3351
3352 if (flags & VER_FLG_WEAK)
3353 {
3354 if (flags & VER_FLG_BASE)
3355 strcat (buff, "| ");
3356
3357 strcat (buff, "WEAK ");
3358 }
3359
3360 if (flags & ~(VER_FLG_BASE | VER_FLG_WEAK))
3361 strcat (buff, "| <unknown>");
3362
3363 return buff;
3364 }
3365
3366 /* Display the contents of the version sections. */
3367 static int
3368 process_version_sections (file)
3369 FILE * file;
3370 {
3371 Elf32_Internal_Shdr * section;
3372 unsigned i;
3373 int found = 0;
3374
3375 if (! do_version)
3376 return 1;
3377
3378 for (i = 0, section = section_headers;
3379 i < elf_header.e_shnum;
3380 i++, section ++)
3381 {
3382 switch (section->sh_type)
3383 {
3384 case SHT_GNU_verdef:
3385 {
3386 Elf_External_Verdef * edefs;
3387 unsigned int idx;
3388 unsigned int cnt;
3389
3390 found = 1;
3391
3392 printf
3393 (_("\nVersion definition section '%s' contains %ld entries:\n"),
3394 SECTION_NAME (section), section->sh_info);
3395
3396 printf (_(" Addr: 0x"));
3397 printf_vma (section->sh_addr);
3398 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
3399 (unsigned long) section->sh_offset, section->sh_link,
3400 SECTION_NAME (section_headers + section->sh_link));
3401
3402 GET_DATA_ALLOC (section->sh_offset, section->sh_size,
3403 edefs, Elf_External_Verdef *,
3404 "version definition section");
3405
3406 for (idx = cnt = 0; cnt < section->sh_info; ++ cnt)
3407 {
3408 char * vstart;
3409 Elf_External_Verdef * edef;
3410 Elf_Internal_Verdef ent;
3411 Elf_External_Verdaux * eaux;
3412 Elf_Internal_Verdaux aux;
3413 int j;
3414 int isum;
3415
3416 vstart = ((char *) edefs) + idx;
3417
3418 edef = (Elf_External_Verdef *) vstart;
3419
3420 ent.vd_version = BYTE_GET (edef->vd_version);
3421 ent.vd_flags = BYTE_GET (edef->vd_flags);
3422 ent.vd_ndx = BYTE_GET (edef->vd_ndx);
3423 ent.vd_cnt = BYTE_GET (edef->vd_cnt);
3424 ent.vd_hash = BYTE_GET (edef->vd_hash);
3425 ent.vd_aux = BYTE_GET (edef->vd_aux);
3426 ent.vd_next = BYTE_GET (edef->vd_next);
3427
3428 printf (_(" %#06x: Rev: %d Flags: %s"),
3429 idx, ent.vd_version, get_ver_flags (ent.vd_flags));
3430
3431 printf (_(" Index: %d Cnt: %d "),
3432 ent.vd_ndx, ent.vd_cnt);
3433
3434 vstart += ent.vd_aux;
3435
3436 eaux = (Elf_External_Verdaux *) vstart;
3437
3438 aux.vda_name = BYTE_GET (eaux->vda_name);
3439 aux.vda_next = BYTE_GET (eaux->vda_next);
3440
3441 if (dynamic_strings)
3442 printf (_("Name: %s\n"), dynamic_strings + aux.vda_name);
3443 else
3444 printf (_("Name index: %ld\n"), aux.vda_name);
3445
3446 isum = idx + ent.vd_aux;
3447
3448 for (j = 1; j < ent.vd_cnt; j ++)
3449 {
3450 isum += aux.vda_next;
3451 vstart += aux.vda_next;
3452
3453 eaux = (Elf_External_Verdaux *) vstart;
3454
3455 aux.vda_name = BYTE_GET (eaux->vda_name);
3456 aux.vda_next = BYTE_GET (eaux->vda_next);
3457
3458 if (dynamic_strings)
3459 printf (_(" %#06x: Parent %d: %s\n"),
3460 isum, j, dynamic_strings + aux.vda_name);
3461 else
3462 printf (_(" %#06x: Parent %d, name index: %ld\n"),
3463 isum, j, aux.vda_name);
3464 }
3465
3466 idx += ent.vd_next;
3467 }
3468
3469 free (edefs);
3470 }
3471 break;
3472
3473 case SHT_GNU_verneed:
3474 {
3475 Elf_External_Verneed * eneed;
3476 unsigned int idx;
3477 unsigned int cnt;
3478
3479 found = 1;
3480
3481 printf (_("\nVersion needs section '%s' contains %ld entries:\n"),
3482 SECTION_NAME (section), section->sh_info);
3483
3484 printf (_(" Addr: 0x"));
3485 printf_vma (section->sh_addr);
3486 printf (_(" Offset: %#08lx Link to section: %ld (%s)\n"),
3487 (unsigned long) section->sh_offset, section->sh_link,
3488 SECTION_NAME (section_headers + section->sh_link));
3489
3490 GET_DATA_ALLOC (section->sh_offset, section->sh_size,
3491 eneed, Elf_External_Verneed *,
3492 "version need section");
3493
3494 for (idx = cnt = 0; cnt < section->sh_info; ++cnt)
3495 {
3496 Elf_External_Verneed * entry;
3497 Elf_Internal_Verneed ent;
3498 int j;
3499 int isum;
3500 char * vstart;
3501
3502 vstart = ((char *) eneed) + idx;
3503
3504 entry = (Elf_External_Verneed *) vstart;
3505
3506 ent.vn_version = BYTE_GET (entry->vn_version);
3507 ent.vn_cnt = BYTE_GET (entry->vn_cnt);
3508 ent.vn_file = BYTE_GET (entry->vn_file);
3509 ent.vn_aux = BYTE_GET (entry->vn_aux);
3510 ent.vn_next = BYTE_GET (entry->vn_next);
3511
3512 printf (_(" %#06x: Version: %d"), idx, ent.vn_version);
3513
3514 if (dynamic_strings)
3515 printf (_(" File: %s"), dynamic_strings + ent.vn_file);
3516 else
3517 printf (_(" File: %lx"), ent.vn_file);
3518
3519 printf (_(" Cnt: %d\n"), ent.vn_cnt);
3520
3521 vstart += ent.vn_aux;
3522
3523 for (j = 0, isum = idx + ent.vn_aux; j < ent.vn_cnt; ++j)
3524 {
3525 Elf_External_Vernaux * eaux;
3526 Elf_Internal_Vernaux aux;
3527
3528 eaux = (Elf_External_Vernaux *) vstart;
3529
3530 aux.vna_hash = BYTE_GET (eaux->vna_hash);
3531 aux.vna_flags = BYTE_GET (eaux->vna_flags);
3532 aux.vna_other = BYTE_GET (eaux->vna_other);
3533 aux.vna_name = BYTE_GET (eaux->vna_name);
3534 aux.vna_next = BYTE_GET (eaux->vna_next);
3535
3536 if (dynamic_strings)
3537 printf (_(" %#06x: Name: %s"),
3538 isum, dynamic_strings + aux.vna_name);
3539 else
3540 printf (_(" %#06x: Name index: %lx"),
3541 isum, aux.vna_name);
3542
3543 printf (_(" Flags: %s Version: %d\n"),
3544 get_ver_flags (aux.vna_flags), aux.vna_other);
3545
3546 isum += aux.vna_next;
3547 vstart += aux.vna_next;
3548 }
3549
3550 idx += ent.vn_next;
3551 }
3552
3553 free (eneed);
3554 }
3555 break;
3556
3557 case SHT_GNU_versym:
3558 {
3559 Elf32_Internal_Shdr * link_section;
3560 int total;
3561 int cnt;
3562 unsigned char * edata;
3563 unsigned short * data;
3564 char * strtab;
3565 Elf_Internal_Sym * symbols;
3566 Elf32_Internal_Shdr * string_sec;
3567
3568 link_section = section_headers + section->sh_link;
3569 total = section->sh_size / section->sh_entsize;
3570
3571 found = 1;
3572
3573 symbols = GET_ELF_SYMBOLS (file, link_section->sh_offset,
3574 link_section->sh_size / link_section->sh_entsize);
3575
3576 string_sec = section_headers + link_section->sh_link;
3577
3578 GET_DATA_ALLOC (string_sec->sh_offset, string_sec->sh_size,
3579 strtab, char *, "version string table");
3580
3581 printf (_("\nVersion symbols section '%s' contains %d entries:\n"),
3582 SECTION_NAME (section), total);
3583
3584 printf (_(" Addr: "));
3585 printf_vma (section->sh_addr);
3586 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
3587 (unsigned long) section->sh_offset, section->sh_link,
3588 SECTION_NAME (link_section));
3589
3590 GET_DATA_ALLOC (version_info [DT_VERSIONTAGIDX (DT_VERSYM)]
3591 - loadaddr,
3592 total * sizeof (short), edata,
3593 unsigned char *, "version symbol data");
3594
3595 data = (unsigned short *) malloc (total * sizeof (short));
3596
3597 for (cnt = total; cnt --;)
3598 data [cnt] = byte_get (edata + cnt * sizeof (short),
3599 sizeof (short));
3600
3601 free (edata);
3602
3603 for (cnt = 0; cnt < total; cnt += 4)
3604 {
3605 int j, nn;
3606
3607 printf (" %03x:", cnt);
3608
3609 for (j = 0; (j < 4) && (cnt + j) < total; ++j)
3610 switch (data [cnt + j])
3611 {
3612 case 0:
3613 fputs (_(" 0 (*local*) "), stdout);
3614 break;
3615
3616 case 1:
3617 fputs (_(" 1 (*global*) "), stdout);
3618 break;
3619
3620 default:
3621 nn = printf ("%4x%c", data [cnt + j] & 0x7fff,
3622 data [cnt + j] & 0x8000 ? 'h' : ' ');
3623
3624 if (symbols [cnt + j].st_shndx < SHN_LORESERVE
3625 && section_headers[symbols [cnt + j].st_shndx].sh_type
3626 == SHT_NOBITS)
3627 {
3628 /* We must test both. */
3629 Elf_Internal_Verneed ivn;
3630 unsigned long offset;
3631
3632 offset = version_info [DT_VERSIONTAGIDX (DT_VERNEED)]
3633 - loadaddr;
3634
3635 do
3636 {
3637 Elf_External_Verneed evn;
3638 Elf_External_Vernaux evna;
3639 Elf_Internal_Vernaux ivna;
3640 unsigned long vna_off;
3641
3642 GET_DATA (offset, evn, "version need");
3643
3644 ivn.vn_aux = BYTE_GET (evn.vn_aux);
3645 ivn.vn_next = BYTE_GET (evn.vn_next);
3646
3647 vna_off = offset + ivn.vn_aux;
3648
3649 do
3650 {
3651 GET_DATA (vna_off, evna,
3652 "version need aux (1)");
3653
3654 ivna.vna_next = BYTE_GET (evna.vna_next);
3655 ivna.vna_other = BYTE_GET (evna.vna_other);
3656
3657 vna_off += ivna.vna_next;
3658 }
3659 while (ivna.vna_other != data [cnt + j]
3660 && ivna.vna_next != 0);
3661
3662 if (ivna.vna_other == data [cnt + j])
3663 {
3664 ivna.vna_name = BYTE_GET (evna.vna_name);
3665
3666 nn += printf ("(%s%-*s",
3667 strtab + ivna.vna_name,
3668 12 - strlen (strtab
3669 + ivna.vna_name),
3670 ")");
3671 break;
3672 }
3673 else if (ivn.vn_next == 0)
3674 {
3675 if (data [cnt + j] != 0x8001)
3676 {
3677 Elf_Internal_Verdef ivd;
3678 Elf_External_Verdef evd;
3679
3680 offset = version_info
3681 [DT_VERSIONTAGIDX (DT_VERDEF)]
3682 - loadaddr;
3683
3684 do
3685 {
3686 GET_DATA (offset, evd,
3687 "version definition");
3688
3689 ivd.vd_next = BYTE_GET (evd.vd_next);
3690 ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
3691
3692 offset += ivd.vd_next;
3693 }
3694 while (ivd.vd_ndx
3695 != (data [cnt + j] & 0x7fff)
3696 && ivd.vd_next != 0);
3697
3698 if (ivd.vd_ndx
3699 == (data [cnt + j] & 0x7fff))
3700 {
3701 Elf_External_Verdaux evda;
3702 Elf_Internal_Verdaux ivda;
3703
3704 ivd.vd_aux = BYTE_GET (evd.vd_aux);
3705
3706 GET_DATA (offset + ivd.vd_aux, evda,
3707 "version definition aux");
3708
3709 ivda.vda_name =
3710 BYTE_GET (evda.vda_name);
3711
3712 nn +=
3713 printf ("(%s%-*s",
3714 strtab + ivda.vda_name,
3715 12
3716 - strlen (strtab
3717 + ivda.vda_name),
3718 ")");
3719 }
3720 }
3721
3722 break;
3723 }
3724 else
3725 offset += ivn.vn_next;
3726 }
3727 while (ivn.vn_next);
3728 }
3729 else if (symbols [cnt + j].st_shndx == SHN_UNDEF)
3730 {
3731 Elf_Internal_Verneed ivn;
3732 unsigned long offset;
3733
3734 offset = version_info [DT_VERSIONTAGIDX (DT_VERNEED)]
3735 - loadaddr;
3736
3737 do
3738 {
3739 Elf_Internal_Vernaux ivna;
3740 Elf_External_Verneed evn;
3741 Elf_External_Vernaux evna;
3742 unsigned long a_off;
3743
3744 GET_DATA (offset, evn, "version need");
3745
3746 ivn.vn_aux = BYTE_GET (evn.vn_aux);
3747 ivn.vn_next = BYTE_GET (evn.vn_next);
3748
3749 a_off = offset + ivn.vn_aux;
3750
3751 do
3752 {
3753 GET_DATA (a_off, evna,
3754 "version need aux (2)");
3755
3756 ivna.vna_next = BYTE_GET (evna.vna_next);
3757 ivna.vna_other = BYTE_GET (evna.vna_other);
3758
3759 a_off += ivna.vna_next;
3760 }
3761 while (ivna.vna_other != data [cnt + j]
3762 && ivna.vna_next != 0);
3763
3764 if (ivna.vna_other == data [cnt + j])
3765 {
3766 ivna.vna_name = BYTE_GET (evna.vna_name);
3767
3768 nn += printf ("(%s%-*s",
3769 strtab + ivna.vna_name,
3770 12 - strlen (strtab
3771 + ivna.vna_name),
3772 ")");
3773 break;
3774 }
3775
3776 offset += ivn.vn_next;
3777 }
3778 while (ivn.vn_next);
3779 }
3780 else if (data [cnt + j] != 0x8001)
3781 {
3782 Elf_Internal_Verdef ivd;
3783 Elf_External_Verdef evd;
3784 unsigned long offset;
3785
3786 offset = version_info
3787 [DT_VERSIONTAGIDX (DT_VERDEF)] - loadaddr;
3788
3789 do
3790 {
3791 GET_DATA (offset, evd, "version def");
3792
3793 ivd.vd_next = BYTE_GET (evd.vd_next);
3794 ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
3795
3796 offset += ivd.vd_next;
3797 }
3798 while (ivd.vd_ndx != (data [cnt + j] & 0x7fff)
3799 && ivd.vd_next != 0);
3800
3801 if (ivd.vd_ndx == (data [cnt + j] & 0x7fff))
3802 {
3803 Elf_External_Verdaux evda;
3804 Elf_Internal_Verdaux ivda;
3805
3806 ivd.vd_aux = BYTE_GET (evd.vd_aux);
3807
3808 GET_DATA (offset - ivd.vd_next + ivd.vd_aux,
3809 evda, "version def aux");
3810
3811 ivda.vda_name = BYTE_GET (evda.vda_name);
3812
3813 nn += printf ("(%s%-*s",
3814 strtab + ivda.vda_name,
3815 12 - strlen (strtab
3816 + ivda.vda_name),
3817 ")");
3818 }
3819 }
3820
3821 if (nn < 18)
3822 printf ("%*c", 18 - nn, ' ');
3823 }
3824
3825 putchar ('\n');
3826 }
3827
3828 free (data);
3829 free (strtab);
3830 free (symbols);
3831 }
3832 break;
3833
3834 default:
3835 break;
3836 }
3837 }
3838
3839 if (! found)
3840 printf (_("\nNo version information found in this file.\n"));
3841
3842 return 1;
3843 }
3844
3845 static char *
3846 get_symbol_binding (binding)
3847 unsigned int binding;
3848 {
3849 static char buff [32];
3850
3851 switch (binding)
3852 {
3853 case STB_LOCAL: return "LOCAL";
3854 case STB_GLOBAL: return "GLOBAL";
3855 case STB_WEAK: return "WEAK";
3856 default:
3857 if (binding >= STB_LOPROC && binding <= STB_HIPROC)
3858 sprintf (buff, _("<processor specific>: %d"), binding);
3859 else if (binding >= STB_LOOS && binding <= STB_HIOS)
3860 sprintf (buff, _("<OS specific>: %d"), binding);
3861 else
3862 sprintf (buff, _("<unknown>: %d"), binding);
3863 return buff;
3864 }
3865 }
3866
3867 static char *
3868 get_symbol_type (type)
3869 unsigned int type;
3870 {
3871 static char buff [32];
3872
3873 switch (type)
3874 {
3875 case STT_NOTYPE: return "NOTYPE";
3876 case STT_OBJECT: return "OBJECT";
3877 case STT_FUNC: return "FUNC";
3878 case STT_SECTION: return "SECTION";
3879 case STT_FILE: return "FILE";
3880 default:
3881 if (type >= STT_LOPROC && type <= STT_HIPROC)
3882 {
3883 if (elf_header.e_machine == EM_ARM && type == STT_ARM_TFUNC)
3884 return "THUMB_FUNC";
3885
3886 if (elf_header.e_machine == EM_SPARCV9 && type == STT_REGISTER)
3887 return "REGISTER";
3888
3889 if (elf_header.e_machine == EM_PARISC && type == STT_PARISC_MILLI)
3890 return "PARISC_MILLI";
3891
3892 sprintf (buff, _("<processor specific>: %d"), type);
3893 }
3894 else if (type >= STT_LOOS && type <= STT_HIOS)
3895 {
3896 if (elf_header.e_machine == EM_PARISC)
3897 {
3898 if (type == STT_HP_OPAQUE)
3899 return "HP_OPAQUE";
3900 if (type == STT_HP_STUB)
3901 return "HP_STUB";
3902 }
3903
3904 sprintf (buff, _("<OS specific>: %d"), type);
3905 }
3906 else
3907 sprintf (buff, _("<unknown>: %d"), type);
3908 return buff;
3909 }
3910 }
3911
3912 static char *
3913 get_symbol_index_type (type)
3914 unsigned int type;
3915 {
3916 switch (type)
3917 {
3918 case SHN_UNDEF: return "UND";
3919 case SHN_ABS: return "ABS";
3920 case SHN_COMMON: return "COM";
3921 default:
3922 if (type >= SHN_LOPROC && type <= SHN_HIPROC)
3923 return "PRC";
3924 else if (type >= SHN_LORESERVE && type <= SHN_HIRESERVE)
3925 return "RSV";
3926 else if (type >= SHN_LOOS && type <= SHN_HIOS)
3927 return "OS ";
3928 else
3929 {
3930 static char buff [32];
3931
3932 sprintf (buff, "%3d", type);
3933 return buff;
3934 }
3935 }
3936 }
3937
3938
3939 static int *
3940 get_dynamic_data (file, number)
3941 FILE * file;
3942 unsigned int number;
3943 {
3944 char * e_data;
3945 int * i_data;
3946
3947 e_data = (char *) malloc (number * 4);
3948
3949 if (e_data == NULL)
3950 {
3951 error (_("Out of memory\n"));
3952 return NULL;
3953 }
3954
3955 if (fread (e_data, 4, number, file) != number)
3956 {
3957 error (_("Unable to read in dynamic data\n"));
3958 return NULL;
3959 }
3960
3961 i_data = (int *) malloc (number * sizeof (* i_data));
3962
3963 if (i_data == NULL)
3964 {
3965 error (_("Out of memory\n"));
3966 free (e_data);
3967 return NULL;
3968 }
3969
3970 while (number--)
3971 i_data [number] = byte_get (e_data + number * 4, 4);
3972
3973 free (e_data);
3974
3975 return i_data;
3976 }
3977
3978 /* Dump the symbol table */
3979 static int
3980 process_symbol_table (file)
3981 FILE * file;
3982 {
3983 Elf32_Internal_Shdr * section;
3984 char nb [4];
3985 char nc [4];
3986 int nbuckets = 0;
3987 int nchains = 0;
3988 int * buckets = NULL;
3989 int * chains = NULL;
3990
3991 if (! do_syms && !do_histogram)
3992 return 1;
3993
3994 if (dynamic_info[DT_HASH] && ((do_using_dynamic && dynamic_strings != NULL)
3995 || do_histogram))
3996 {
3997 if (fseek (file, dynamic_info[DT_HASH] - loadaddr, SEEK_SET))
3998 {
3999 error (_("Unable to seek to start of dynamic information"));
4000 return 0;
4001 }
4002
4003 if (fread (nb, sizeof (nb), 1, file) != 1)
4004 {
4005 error (_("Failed to read in number of buckets\n"));
4006 return 0;
4007 }
4008
4009 if (fread (nc, sizeof (nc), 1, file) != 1)
4010 {
4011 error (_("Failed to read in number of chains\n"));
4012 return 0;
4013 }
4014
4015 nbuckets = byte_get (nb, 4);
4016 nchains = byte_get (nc, 4);
4017
4018 buckets = get_dynamic_data (file, nbuckets);
4019 chains = get_dynamic_data (file, nchains);
4020
4021 if (buckets == NULL || chains == NULL)
4022 return 0;
4023 }
4024
4025 if (do_syms
4026 && dynamic_info[DT_HASH] && do_using_dynamic && dynamic_strings != NULL)
4027 {
4028 int hn;
4029 int si;
4030
4031 printf (_("\nSymbol table for image:\n"));
4032 if (is_32bit_elf)
4033 printf (_(" Num Buc: Value Size Type Bind Ot Ndx Name\n"));
4034 else
4035 printf (_(" Num Buc: Value Size Type Bind Ot Ndx Name\n"));
4036
4037 for (hn = 0; hn < nbuckets; hn++)
4038 {
4039 if (! buckets [hn])
4040 continue;
4041
4042 for (si = buckets [hn]; si < nchains && si > 0; si = chains [si])
4043 {
4044 Elf_Internal_Sym * psym;
4045
4046 psym = dynamic_symbols + si;
4047
4048 printf (" %3d %3d: ", si, hn);
4049 print_vma (psym->st_value, LONG_HEX);
4050 putchar (' ' );
4051 print_vma (psym->st_size, DEC_5);
4052
4053 printf (" %6s %6s %2d ",
4054 get_symbol_type (ELF_ST_TYPE (psym->st_info)),
4055 get_symbol_binding (ELF_ST_BIND (psym->st_info)),
4056 psym->st_other);
4057
4058 printf ("%3.3s", get_symbol_index_type (psym->st_shndx));
4059
4060 printf (" %s\n", dynamic_strings + psym->st_name);
4061 }
4062 }
4063 }
4064 else if (do_syms && !do_using_dynamic)
4065 {
4066 unsigned int i;
4067
4068 for (i = 0, section = section_headers;
4069 i < elf_header.e_shnum;
4070 i++, section++)
4071 {
4072 unsigned int si;
4073 char * strtab;
4074 Elf_Internal_Sym * symtab;
4075 Elf_Internal_Sym * psym;
4076
4077
4078 if ( section->sh_type != SHT_SYMTAB
4079 && section->sh_type != SHT_DYNSYM)
4080 continue;
4081
4082 printf (_("\nSymbol table '%s' contains %lu entries:\n"),
4083 SECTION_NAME (section),
4084 (unsigned long) (section->sh_size / section->sh_entsize));
4085 if (is_32bit_elf)
4086 printf (_(" Num: Value Size Type Bind Ot Ndx Name\n"));
4087 else
4088 printf (_(" Num: Value Size Type Bind Ot Ndx Name\n"));
4089
4090 symtab = GET_ELF_SYMBOLS (file, section->sh_offset,
4091 section->sh_size / section->sh_entsize);
4092 if (symtab == NULL)
4093 continue;
4094
4095 if (section->sh_link == elf_header.e_shstrndx)
4096 strtab = string_table;
4097 else
4098 {
4099 Elf32_Internal_Shdr * string_sec;
4100
4101 string_sec = section_headers + section->sh_link;
4102
4103 GET_DATA_ALLOC (string_sec->sh_offset, string_sec->sh_size,
4104 strtab, char *, "string table");
4105 }
4106
4107 for (si = 0, psym = symtab;
4108 si < section->sh_size / section->sh_entsize;
4109 si ++, psym ++)
4110 {
4111 printf ("%6d: ", si);
4112 print_vma (psym->st_value, LONG_HEX);
4113 putchar (' ');
4114 print_vma (psym->st_size, DEC_5);
4115 printf (" %-7s %-6s %2d ",
4116 get_symbol_type (ELF_ST_TYPE (psym->st_info)),
4117 get_symbol_binding (ELF_ST_BIND (psym->st_info)),
4118 psym->st_other);
4119
4120 printf ("%4s", get_symbol_index_type (psym->st_shndx));
4121
4122 printf (" %s", strtab + psym->st_name);
4123
4124 if (section->sh_type == SHT_DYNSYM &&
4125 version_info [DT_VERSIONTAGIDX (DT_VERSYM)] != 0)
4126 {
4127 unsigned char data[2];
4128 unsigned short vers_data;
4129 unsigned long offset;
4130 int is_nobits;
4131 int check_def;
4132
4133 offset = version_info [DT_VERSIONTAGIDX (DT_VERSYM)]
4134 - loadaddr;
4135
4136 GET_DATA (offset + si * sizeof (vers_data), data,
4137 "version data");
4138
4139 vers_data = byte_get (data, 2);
4140
4141 is_nobits = psym->st_shndx < SHN_LORESERVE ?
4142 (section_headers [psym->st_shndx].sh_type == SHT_NOBITS)
4143 : 0;
4144
4145 check_def = (psym->st_shndx != SHN_UNDEF);
4146
4147 if ((vers_data & 0x8000) || vers_data > 1)
4148 {
4149 if (is_nobits || ! check_def)
4150 {
4151 Elf_External_Verneed evn;
4152 Elf_Internal_Verneed ivn;
4153 Elf_Internal_Vernaux ivna;
4154
4155 /* We must test both. */
4156 offset = version_info
4157 [DT_VERSIONTAGIDX (DT_VERNEED)] - loadaddr;
4158
4159 GET_DATA (offset, evn, "version need");
4160
4161 ivn.vn_aux = BYTE_GET (evn.vn_aux);
4162 ivn.vn_next = BYTE_GET (evn.vn_next);
4163
4164 do
4165 {
4166 unsigned long vna_off;
4167
4168 vna_off = offset + ivn.vn_aux;
4169
4170 do
4171 {
4172 Elf_External_Vernaux evna;
4173
4174 GET_DATA (vna_off, evna,
4175 "version need aux (3)");
4176
4177 ivna.vna_other = BYTE_GET (evna.vna_other);
4178 ivna.vna_next = BYTE_GET (evna.vna_next);
4179 ivna.vna_name = BYTE_GET (evna.vna_name);
4180
4181 vna_off += ivna.vna_next;
4182 }
4183 while (ivna.vna_other != vers_data
4184 && ivna.vna_next != 0);
4185
4186 if (ivna.vna_other == vers_data)
4187 break;
4188
4189 offset += ivn.vn_next;
4190 }
4191 while (ivn.vn_next != 0);
4192
4193 if (ivna.vna_other == vers_data)
4194 {
4195 printf ("@%s (%d)",
4196 strtab + ivna.vna_name, ivna.vna_other);
4197 check_def = 0;
4198 }
4199 else if (! is_nobits)
4200 error (_("bad dynamic symbol"));
4201 else
4202 check_def = 1;
4203 }
4204
4205 if (check_def)
4206 {
4207 if (vers_data != 0x8001)
4208 {
4209 Elf_Internal_Verdef ivd;
4210 Elf_Internal_Verdaux ivda;
4211 Elf_External_Verdaux evda;
4212 unsigned long offset;
4213
4214 offset =
4215 version_info [DT_VERSIONTAGIDX (DT_VERDEF)]
4216 - loadaddr;
4217
4218 do
4219 {
4220 Elf_External_Verdef evd;
4221
4222 GET_DATA (offset, evd, "version def");
4223
4224 ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
4225 ivd.vd_aux = BYTE_GET (evd.vd_aux);
4226 ivd.vd_next = BYTE_GET (evd.vd_next);
4227
4228 offset += ivd.vd_next;
4229 }
4230 while (ivd.vd_ndx != (vers_data & 0x7fff)
4231 && ivd.vd_next != 0);
4232
4233 offset -= ivd.vd_next;
4234 offset += ivd.vd_aux;
4235
4236 GET_DATA (offset, evda, "version def aux");
4237
4238 ivda.vda_name = BYTE_GET (evda.vda_name);
4239
4240 if (psym->st_name != ivda.vda_name)
4241 printf ((vers_data & 0x8000)
4242 ? "@%s" : "@@%s",
4243 strtab + ivda.vda_name);
4244 }
4245 }
4246 }
4247 }
4248
4249 putchar ('\n');
4250 }
4251
4252 free (symtab);
4253 if (strtab != string_table)
4254 free (strtab);
4255 }
4256 }
4257 else if (do_syms)
4258 printf
4259 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
4260
4261 if (do_histogram && buckets != NULL)
4262 {
4263 int *lengths;
4264 int *counts;
4265 int hn;
4266 int si;
4267 int maxlength = 0;
4268 int nzero_counts = 0;
4269 int nsyms = 0;
4270
4271 printf (_("\nHistogram for bucket list length (total of %d buckets):\n"),
4272 nbuckets);
4273 printf (_(" Length Number %% of total Coverage\n"));
4274
4275 lengths = (int *) calloc (nbuckets, sizeof (int));
4276 if (lengths == NULL)
4277 {
4278 error (_("Out of memory"));
4279 return 0;
4280 }
4281 for (hn = 0; hn < nbuckets; ++hn)
4282 {
4283 if (! buckets [hn])
4284 continue;
4285
4286 for (si = buckets[hn]; si > 0 && si < nchains; si = chains[si])
4287 {
4288 ++ nsyms;
4289 if (maxlength < ++lengths[hn])
4290 ++ maxlength;
4291 }
4292 }
4293
4294 counts = (int *) calloc (maxlength + 1, sizeof (int));
4295 if (counts == NULL)
4296 {
4297 error (_("Out of memory"));
4298 return 0;
4299 }
4300
4301 for (hn = 0; hn < nbuckets; ++hn)
4302 ++ counts [lengths [hn]];
4303
4304 if (nbuckets > 0)
4305 {
4306 printf (" 0 %-10d (%5.1f%%)\n",
4307 counts[0], (counts[0] * 100.0) / nbuckets);
4308 for (si = 1; si <= maxlength; ++si)
4309 {
4310 nzero_counts += counts[si] * si;
4311 printf ("%7d %-10d (%5.1f%%) %5.1f%%\n",
4312 si, counts[si], (counts[si] * 100.0) / nbuckets,
4313 (nzero_counts * 100.0) / nsyms);
4314 }
4315 }
4316
4317 free (counts);
4318 free (lengths);
4319 }
4320
4321 if (buckets != NULL)
4322 {
4323 free (buckets);
4324 free (chains);
4325 }
4326
4327 return 1;
4328 }
4329
4330 static int
4331 process_syminfo (file)
4332 FILE * file ATTRIBUTE_UNUSED;
4333 {
4334 unsigned int i;
4335
4336 if (dynamic_syminfo == NULL
4337 || !do_dynamic)
4338 /* No syminfo, this is ok. */
4339 return 1;
4340
4341 /* There better should be a dynamic symbol section. */
4342 if (dynamic_symbols == NULL || dynamic_strings == NULL)
4343 return 0;
4344
4345 if (dynamic_addr)
4346 printf (_("\nDynamic info segment at offset 0x%lx contains %d entries:\n"),
4347 dynamic_syminfo_offset, dynamic_syminfo_nent);
4348
4349 printf (_(" Num: Name BoundTo Flags\n"));
4350 for (i = 0; i < dynamic_syminfo_nent; ++i)
4351 {
4352 unsigned short int flags = dynamic_syminfo[i].si_flags;
4353
4354 printf ("%4d: %-30s ", i,
4355 dynamic_strings + dynamic_symbols[i].st_name);
4356
4357 switch (dynamic_syminfo[i].si_boundto)
4358 {
4359 case SYMINFO_BT_SELF:
4360 fputs ("SELF ", stdout);
4361 break;
4362 case SYMINFO_BT_PARENT:
4363 fputs ("PARENT ", stdout);
4364 break;
4365 default:
4366 if (dynamic_syminfo[i].si_boundto > 0
4367 && dynamic_syminfo[i].si_boundto < dynamic_size)
4368 printf ("%-10s ",
4369 dynamic_strings
4370 + dynamic_segment[dynamic_syminfo[i].si_boundto].d_un.d_val);
4371 else
4372 printf ("%-10d ", dynamic_syminfo[i].si_boundto);
4373 break;
4374 }
4375
4376 if (flags & SYMINFO_FLG_DIRECT)
4377 printf (" DIRECT");
4378 if (flags & SYMINFO_FLG_PASSTHRU)
4379 printf (" PASSTHRU");
4380 if (flags & SYMINFO_FLG_COPY)
4381 printf (" COPY");
4382 if (flags & SYMINFO_FLG_LAZYLOAD)
4383 printf (" LAZYLOAD");
4384
4385 puts ("");
4386 }
4387
4388 return 1;
4389 }
4390
4391 #ifdef SUPPORT_DISASSEMBLY
4392 static void
4393 disassemble_section (section, file)
4394 Elf32_Internal_Shdr * section;
4395 FILE * file;
4396 {
4397 printf (_("\nAssembly dump of section %s\n"),
4398 SECTION_NAME (section));
4399
4400 /* XXX -- to be done --- XXX */
4401
4402 return 1;
4403 }
4404 #endif
4405
4406 static int
4407 dump_section (section, file)
4408 Elf32_Internal_Shdr * section;
4409 FILE * file;
4410 {
4411 bfd_size_type bytes;
4412 bfd_vma addr;
4413 unsigned char * data;
4414 unsigned char * start;
4415
4416 bytes = section->sh_size;
4417
4418 if (bytes == 0)
4419 {
4420 printf (_("\nSection '%s' has no data to dump.\n"),
4421 SECTION_NAME (section));
4422 return 0;
4423 }
4424 else
4425 printf (_("\nHex dump of section '%s':\n"), SECTION_NAME (section));
4426
4427 addr = section->sh_addr;
4428
4429 GET_DATA_ALLOC (section->sh_offset, bytes, start, unsigned char *,
4430 "section data");
4431
4432 data = start;
4433
4434 while (bytes)
4435 {
4436 int j;
4437 int k;
4438 int lbytes;
4439
4440 lbytes = (bytes > 16 ? 16 : bytes);
4441
4442 printf (" 0x%8.8lx ", (unsigned long) addr);
4443
4444 switch (elf_header.e_ident [EI_DATA])
4445 {
4446 default:
4447 case ELFDATA2LSB:
4448 for (j = 15; j >= 0; j --)
4449 {
4450 if (j < lbytes)
4451 printf ("%2.2x", data [j]);
4452 else
4453 printf (" ");
4454
4455 if (!(j & 0x3))
4456 printf (" ");
4457 }
4458 break;
4459
4460 case ELFDATA2MSB:
4461 for (j = 0; j < 16; j++)
4462 {
4463 if (j < lbytes)
4464 printf ("%2.2x", data [j]);
4465 else
4466 printf (" ");
4467
4468 if ((j & 3) == 3)
4469 printf (" ");
4470 }
4471 break;
4472 }
4473
4474 for (j = 0; j < lbytes; j++)
4475 {
4476 k = data [j];
4477 if (k >= ' ' && k < 0x80)
4478 printf ("%c", k);
4479 else
4480 printf (".");
4481 }
4482
4483 putchar ('\n');
4484
4485 data += lbytes;
4486 addr += lbytes;
4487 bytes -= lbytes;
4488 }
4489
4490 free (start);
4491
4492 return 1;
4493 }
4494
4495
4496 static unsigned long int
4497 read_leb128 (data, length_return, sign)
4498 unsigned char * data;
4499 int * length_return;
4500 int sign;
4501 {
4502 unsigned long int result = 0;
4503 unsigned int num_read = 0;
4504 int shift = 0;
4505 unsigned char byte;
4506
4507 do
4508 {
4509 byte = * data ++;
4510 num_read ++;
4511
4512 result |= (byte & 0x7f) << shift;
4513
4514 shift += 7;
4515
4516 }
4517 while (byte & 0x80);
4518
4519 if (length_return != NULL)
4520 * length_return = num_read;
4521
4522 if (sign && (shift < 32) && (byte & 0x40))
4523 result |= -1 << shift;
4524
4525 return result;
4526 }
4527
4528 typedef struct State_Machine_Registers
4529 {
4530 unsigned long address;
4531 unsigned int file;
4532 unsigned int line;
4533 unsigned int column;
4534 int is_stmt;
4535 int basic_block;
4536 int end_sequence;
4537 /* This variable hold the number of the last entry seen
4538 in the File Table. */
4539 unsigned int last_file_entry;
4540 } SMR;
4541
4542 static SMR state_machine_regs;
4543
4544 static void
4545 reset_state_machine (is_stmt)
4546 int is_stmt;
4547 {
4548 state_machine_regs.address = 0;
4549 state_machine_regs.file = 1;
4550 state_machine_regs.line = 1;
4551 state_machine_regs.column = 0;
4552 state_machine_regs.is_stmt = is_stmt;
4553 state_machine_regs.basic_block = 0;
4554 state_machine_regs.end_sequence = 0;
4555 state_machine_regs.last_file_entry = 0;
4556 }
4557
4558 /* Handled an extend line op. Returns true if this is the end
4559 of sequence. */
4560 static int
4561 process_extended_line_op (data, is_stmt, pointer_size)
4562 unsigned char * data;
4563 int is_stmt;
4564 int pointer_size;
4565 {
4566 unsigned char op_code;
4567 int bytes_read;
4568 unsigned int len;
4569 unsigned char * name;
4570 unsigned long adr;
4571
4572 len = read_leb128 (data, & bytes_read, 0);
4573 data += bytes_read;
4574
4575 if (len == 0)
4576 {
4577 warn (_("badly formed extended line op encountered!"));
4578 return bytes_read;
4579 }
4580
4581 len += bytes_read;
4582 op_code = * data ++;
4583
4584 printf (_(" Extended opcode %d: "), op_code);
4585
4586 switch (op_code)
4587 {
4588 case DW_LNE_end_sequence:
4589 printf (_("End of Sequence\n\n"));
4590 reset_state_machine (is_stmt);
4591 break;
4592
4593 case DW_LNE_set_address:
4594 adr = byte_get (data, pointer_size);
4595 printf (_("set Address to 0x%lx\n"), adr);
4596 state_machine_regs.address = adr;
4597 break;
4598
4599 case DW_LNE_define_file:
4600 printf (_(" define new File Table entry\n"));
4601 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
4602
4603 printf (_(" %d\t"), ++ state_machine_regs.last_file_entry);
4604 name = data;
4605 data += strlen (data) + 1;
4606 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
4607 data += bytes_read;
4608 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
4609 data += bytes_read;
4610 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
4611 printf (_("%s\n\n"), name);
4612 break;
4613
4614 default:
4615 printf (_("UNKNOWN: length %d\n"), len - bytes_read);
4616 break;
4617 }
4618
4619 return len;
4620 }
4621
4622 /* Size of pointers in the .debug_line section. This information is not
4623 really present in that section. It's obtained before dumping the debug
4624 sections by doing some pre-scan of the .debug_info section. */
4625 static int debug_line_pointer_size = 4;
4626
4627 static int
4628 display_debug_lines (section, start, file)
4629 Elf32_Internal_Shdr * section;
4630 unsigned char * start;
4631 FILE * file ATTRIBUTE_UNUSED;
4632 {
4633 DWARF2_External_LineInfo * external;
4634 DWARF2_Internal_LineInfo info;
4635 unsigned char * standard_opcodes;
4636 unsigned char * data = start;
4637 unsigned char * end = start + section->sh_size;
4638 unsigned char * end_of_sequence;
4639 int i;
4640
4641 printf (_("\nDump of debug contents of section %s:\n\n"),
4642 SECTION_NAME (section));
4643
4644 while (data < end)
4645 {
4646 external = (DWARF2_External_LineInfo *) data;
4647
4648 /* Check the length of the block. */
4649 info.li_length = BYTE_GET (external->li_length);
4650 if (info.li_length > section->sh_size)
4651 {
4652 warn
4653 (_("The line info appears to be corrupt - the section is too small\n"));
4654 return 0;
4655 }
4656
4657 /* Check its version number. */
4658 info.li_version = BYTE_GET (external->li_version);
4659 if (info.li_version != 2)
4660 {
4661 warn (_("Only DWARF version 2 line info is currently supported.\n"));
4662 return 0;
4663 }
4664
4665 info.li_prologue_length = BYTE_GET (external->li_prologue_length);
4666 info.li_min_insn_length = BYTE_GET (external->li_min_insn_length);
4667 info.li_default_is_stmt = BYTE_GET (external->li_default_is_stmt);
4668 info.li_line_base = BYTE_GET (external->li_line_base);
4669 info.li_line_range = BYTE_GET (external->li_line_range);
4670 info.li_opcode_base = BYTE_GET (external->li_opcode_base);
4671
4672 /* Sign extend the line base field. */
4673 info.li_line_base <<= 24;
4674 info.li_line_base >>= 24;
4675
4676 printf (_(" Length: %ld\n"), info.li_length);
4677 printf (_(" DWARF Version: %d\n"), info.li_version);
4678 printf (_(" Prolgue Length: %d\n"), info.li_prologue_length);
4679 printf (_(" Minimum Instruction Length: %d\n"), info.li_min_insn_length);
4680 printf (_(" Initial value of 'is_stmt': %d\n"), info.li_default_is_stmt);
4681 printf (_(" Line Base: %d\n"), info.li_line_base);
4682 printf (_(" Line Range: %d\n"), info.li_line_range);
4683 printf (_(" Opcode Base: %d\n"), info.li_opcode_base);
4684
4685 end_of_sequence = data + info.li_length + sizeof (info.li_length);
4686
4687 reset_state_machine (info.li_default_is_stmt);
4688
4689 /* Display the contents of the Opcodes table. */
4690 standard_opcodes = data + sizeof (* external);
4691
4692 printf (_("\n Opcodes:\n"));
4693
4694 for (i = 1; i < info.li_opcode_base; i++)
4695 printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]);
4696
4697 /* Display the contents of the Directory table. */
4698 data = standard_opcodes + info.li_opcode_base - 1;
4699
4700 if (* data == 0)
4701 printf (_("\n The Directory Table is empty.\n"));
4702 else
4703 {
4704 printf (_("\n The Directory Table:\n"));
4705
4706 while (* data != 0)
4707 {
4708 printf (_(" %s\n"), data);
4709
4710 data += strlen (data) + 1;
4711 }
4712 }
4713
4714 /* Skip the NUL at the end of the table. */
4715 data ++;
4716
4717 /* Display the contents of the File Name table. */
4718 if (* data == 0)
4719 printf (_("\n The File Name Table is empty.\n"));
4720 else
4721 {
4722 printf (_("\n The File Name Table:\n"));
4723 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
4724
4725 while (* data != 0)
4726 {
4727 char * name;
4728 int bytes_read;
4729
4730 printf (_(" %d\t"), ++ state_machine_regs.last_file_entry);
4731 name = data;
4732
4733 data += strlen (data) + 1;
4734
4735 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
4736 data += bytes_read;
4737 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
4738 data += bytes_read;
4739 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
4740 data += bytes_read;
4741 printf (_("%s\n"), name);
4742 }
4743 }
4744
4745 /* Skip the NUL at the end of the table. */
4746 data ++;
4747
4748 /* Now display the statements. */
4749 printf (_("\n Line Number Statements:\n"));
4750
4751
4752 while (data < end_of_sequence)
4753 {
4754 unsigned char op_code;
4755 int adv;
4756 int bytes_read;
4757
4758 op_code = * data ++;
4759
4760 switch (op_code)
4761 {
4762 case DW_LNS_extended_op:
4763 data += process_extended_line_op (data, info.li_default_is_stmt,
4764 debug_line_pointer_size);
4765 break;
4766
4767 case DW_LNS_copy:
4768 printf (_(" Copy\n"));
4769 break;
4770
4771 case DW_LNS_advance_pc:
4772 adv = info.li_min_insn_length * read_leb128 (data, & bytes_read, 0);
4773 data += bytes_read;
4774 state_machine_regs.address += adv;
4775 printf (_(" Advance PC by %d to %lx\n"), adv,
4776 state_machine_regs.address);
4777 break;
4778
4779 case DW_LNS_advance_line:
4780 adv = read_leb128 (data, & bytes_read, 1);
4781 data += bytes_read;
4782 state_machine_regs.line += adv;
4783 printf (_(" Advance Line by %d to %d\n"), adv,
4784 state_machine_regs.line);
4785 break;
4786
4787 case DW_LNS_set_file:
4788 adv = read_leb128 (data, & bytes_read, 0);
4789 data += bytes_read;
4790 printf (_(" Set File Name to entry %d in the File Name Table\n"),
4791 adv);
4792 state_machine_regs.file = adv;
4793 break;
4794
4795 case DW_LNS_set_column:
4796 adv = read_leb128 (data, & bytes_read, 0);
4797 data += bytes_read;
4798 printf (_(" Set column to %d\n"), adv);
4799 state_machine_regs.column = adv;
4800 break;
4801
4802 case DW_LNS_negate_stmt:
4803 adv = state_machine_regs.is_stmt;
4804 adv = ! adv;
4805 printf (_(" Set is_stmt to %d\n"), adv);
4806 state_machine_regs.is_stmt = adv;
4807 break;
4808
4809 case DW_LNS_set_basic_block:
4810 printf (_(" Set basic block\n"));
4811 state_machine_regs.basic_block = 1;
4812 break;
4813
4814 case DW_LNS_const_add_pc:
4815 adv = (((255 - info.li_opcode_base) / info.li_line_range)
4816 * info.li_min_insn_length);
4817 state_machine_regs.address += adv;
4818 printf (_(" Advance PC by constant %d to 0x%lx\n"), adv,
4819 state_machine_regs.address);
4820 break;
4821
4822 case DW_LNS_fixed_advance_pc:
4823 adv = byte_get (data, 2);
4824 data += 2;
4825 state_machine_regs.address += adv;
4826 printf (_(" Advance PC by fixed size amount %d to 0x%lx\n"),
4827 adv, state_machine_regs.address);
4828 break;
4829
4830 default:
4831 op_code -= info.li_opcode_base;
4832 adv = (op_code / info.li_line_range) * info.li_min_insn_length;
4833 state_machine_regs.address += adv;
4834 printf (_(" Special opcode %d: advance Address by %d to 0x%lx"),
4835 op_code, adv, state_machine_regs.address);
4836 adv = (op_code % info.li_line_range) + info.li_line_base;
4837 state_machine_regs.line += adv;
4838 printf (_(" and Line by %d to %d\n"),
4839 adv, state_machine_regs.line);
4840 break;
4841 }
4842 }
4843 printf ("\n");
4844 }
4845
4846 return 1;
4847 }
4848
4849 static int
4850 display_debug_pubnames (section, start, file)
4851 Elf32_Internal_Shdr * section;
4852 unsigned char * start;
4853 FILE * file ATTRIBUTE_UNUSED;
4854 {
4855 DWARF2_External_PubNames * external;
4856 DWARF2_Internal_PubNames pubnames;
4857 unsigned char * end;
4858
4859 end = start + section->sh_size;
4860
4861 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section));
4862
4863 while (start < end)
4864 {
4865 unsigned char * data;
4866 unsigned long offset;
4867
4868 external = (DWARF2_External_PubNames *) start;
4869
4870 pubnames.pn_length = BYTE_GET (external->pn_length);
4871 pubnames.pn_version = BYTE_GET (external->pn_version);
4872 pubnames.pn_offset = BYTE_GET (external->pn_offset);
4873 pubnames.pn_size = BYTE_GET (external->pn_size);
4874
4875 data = start + sizeof (* external);
4876 start += pubnames.pn_length + sizeof (external->pn_length);
4877
4878 if (pubnames.pn_version != 2)
4879 {
4880 warn (_("Only DWARF 2 pubnames are currently supported"));
4881 continue;
4882 }
4883
4884 printf (_(" Length: %ld\n"),
4885 pubnames.pn_length);
4886 printf (_(" Version: %d\n"),
4887 pubnames.pn_version);
4888 printf (_(" Offset into .debug_info section: %ld\n"),
4889 pubnames.pn_offset);
4890 printf (_(" Size of area in .debug_info section: %ld\n"),
4891 pubnames.pn_size);
4892
4893 printf (_("\n Offset\tName\n"));
4894
4895 do
4896 {
4897 offset = byte_get (data, 4);
4898
4899 if (offset != 0)
4900 {
4901 data += 4;
4902 printf (" %ld\t\t%s\n", offset, data);
4903 data += strlen (data) + 1;
4904 }
4905 }
4906 while (offset != 0);
4907 }
4908
4909 printf ("\n");
4910 return 1;
4911 }
4912
4913 static char *
4914 get_TAG_name (tag)
4915 unsigned long tag;
4916 {
4917 switch (tag)
4918 {
4919 case DW_TAG_padding: return "DW_TAG_padding";
4920 case DW_TAG_array_type: return "DW_TAG_array_type";
4921 case DW_TAG_class_type: return "DW_TAG_class_type";
4922 case DW_TAG_entry_point: return "DW_TAG_entry_point";
4923 case DW_TAG_enumeration_type: return "DW_TAG_enumeration_type";
4924 case DW_TAG_formal_parameter: return "DW_TAG_formal_parameter";
4925 case DW_TAG_imported_declaration: return "DW_TAG_imported_declaration";
4926 case DW_TAG_label: return "DW_TAG_label";
4927 case DW_TAG_lexical_block: return "DW_TAG_lexical_block";
4928 case DW_TAG_member: return "DW_TAG_member";
4929 case DW_TAG_pointer_type: return "DW_TAG_pointer_type";
4930 case DW_TAG_reference_type: return "DW_TAG_reference_type";
4931 case DW_TAG_compile_unit: return "DW_TAG_compile_unit";
4932 case DW_TAG_string_type: return "DW_TAG_string_type";
4933 case DW_TAG_structure_type: return "DW_TAG_structure_type";
4934 case DW_TAG_subroutine_type: return "DW_TAG_subroutine_type";
4935 case DW_TAG_typedef: return "DW_TAG_typedef";
4936 case DW_TAG_union_type: return "DW_TAG_union_type";
4937 case DW_TAG_unspecified_parameters: return "DW_TAG_unspecified_parameters";
4938 case DW_TAG_variant: return "DW_TAG_variant";
4939 case DW_TAG_common_block: return "DW_TAG_common_block";
4940 case DW_TAG_common_inclusion: return "DW_TAG_common_inclusion";
4941 case DW_TAG_inheritance: return "DW_TAG_inheritance";
4942 case DW_TAG_inlined_subroutine: return "DW_TAG_inlined_subroutine";
4943 case DW_TAG_module: return "DW_TAG_module";
4944 case DW_TAG_ptr_to_member_type: return "DW_TAG_ptr_to_member_type";
4945 case DW_TAG_set_type: return "DW_TAG_set_type";
4946 case DW_TAG_subrange_type: return "DW_TAG_subrange_type";
4947 case DW_TAG_with_stmt: return "DW_TAG_with_stmt";
4948 case DW_TAG_access_declaration: return "DW_TAG_access_declaration";
4949 case DW_TAG_base_type: return "DW_TAG_base_type";
4950 case DW_TAG_catch_block: return "DW_TAG_catch_block";
4951 case DW_TAG_const_type: return "DW_TAG_const_type";
4952 case DW_TAG_constant: return "DW_TAG_constant";
4953 case DW_TAG_enumerator: return "DW_TAG_enumerator";
4954 case DW_TAG_file_type: return "DW_TAG_file_type";
4955 case DW_TAG_friend: return "DW_TAG_friend";
4956 case DW_TAG_namelist: return "DW_TAG_namelist";
4957 case DW_TAG_namelist_item: return "DW_TAG_namelist_item";
4958 case DW_TAG_packed_type: return "DW_TAG_packed_type";
4959 case DW_TAG_subprogram: return "DW_TAG_subprogram";
4960 case DW_TAG_template_type_param: return "DW_TAG_template_type_param";
4961 case DW_TAG_template_value_param: return "DW_TAG_template_value_param";
4962 case DW_TAG_thrown_type: return "DW_TAG_thrown_type";
4963 case DW_TAG_try_block: return "DW_TAG_try_block";
4964 case DW_TAG_variant_part: return "DW_TAG_variant_part";
4965 case DW_TAG_variable: return "DW_TAG_variable";
4966 case DW_TAG_volatile_type: return "DW_TAG_volatile_type";
4967 case DW_TAG_MIPS_loop: return "DW_TAG_MIPS_loop";
4968 case DW_TAG_format_label: return "DW_TAG_format_label";
4969 case DW_TAG_function_template: return "DW_TAG_function_template";
4970 case DW_TAG_class_template: return "DW_TAG_class_template";
4971 default:
4972 {
4973 static char buffer [100];
4974
4975 sprintf (buffer, _("Unknown TAG value: %lx"), tag);
4976 return buffer;
4977 }
4978 }
4979 }
4980
4981 static char *
4982 get_AT_name (attribute)
4983 unsigned long attribute;
4984 {
4985 switch (attribute)
4986 {
4987 case DW_AT_sibling: return "DW_AT_sibling";
4988 case DW_AT_location: return "DW_AT_location";
4989 case DW_AT_name: return "DW_AT_name";
4990 case DW_AT_ordering: return "DW_AT_ordering";
4991 case DW_AT_subscr_data: return "DW_AT_subscr_data";
4992 case DW_AT_byte_size: return "DW_AT_byte_size";
4993 case DW_AT_bit_offset: return "DW_AT_bit_offset";
4994 case DW_AT_bit_size: return "DW_AT_bit_size";
4995 case DW_AT_element_list: return "DW_AT_element_list";
4996 case DW_AT_stmt_list: return "DW_AT_stmt_list";
4997 case DW_AT_low_pc: return "DW_AT_low_pc";
4998 case DW_AT_high_pc: return "DW_AT_high_pc";
4999 case DW_AT_language: return "DW_AT_language";
5000 case DW_AT_member: return "DW_AT_member";
5001 case DW_AT_discr: return "DW_AT_discr";
5002 case DW_AT_discr_value: return "DW_AT_discr_value";
5003 case DW_AT_visibility: return "DW_AT_visibility";
5004 case DW_AT_import: return "DW_AT_import";
5005 case DW_AT_string_length: return "DW_AT_string_length";
5006 case DW_AT_common_reference: return "DW_AT_common_reference";
5007 case DW_AT_comp_dir: return "DW_AT_comp_dir";
5008 case DW_AT_const_value: return "DW_AT_const_value";
5009 case DW_AT_containing_type: return "DW_AT_containing_type";
5010 case DW_AT_default_value: return "DW_AT_default_value";
5011 case DW_AT_inline: return "DW_AT_inline";
5012 case DW_AT_is_optional: return "DW_AT_is_optional";
5013 case DW_AT_lower_bound: return "DW_AT_lower_bound";
5014 case DW_AT_producer: return "DW_AT_producer";
5015 case DW_AT_prototyped: return "DW_AT_prototyped";
5016 case DW_AT_return_addr: return "DW_AT_return_addr";
5017 case DW_AT_start_scope: return "DW_AT_start_scope";
5018 case DW_AT_stride_size: return "DW_AT_stride_size";
5019 case DW_AT_upper_bound: return "DW_AT_upper_bound";
5020 case DW_AT_abstract_origin: return "DW_AT_abstract_origin";
5021 case DW_AT_accessibility: return "DW_AT_accessibility";
5022 case DW_AT_address_class: return "DW_AT_address_class";
5023 case DW_AT_artificial: return "DW_AT_artificial";
5024 case DW_AT_base_types: return "DW_AT_base_types";
5025 case DW_AT_calling_convention: return "DW_AT_calling_convention";
5026 case DW_AT_count: return "DW_AT_count";
5027 case DW_AT_data_member_location: return "DW_AT_data_member_location";
5028 case DW_AT_decl_column: return "DW_AT_decl_column";
5029 case DW_AT_decl_file: return "DW_AT_decl_file";
5030 case DW_AT_decl_line: return "DW_AT_decl_line";
5031 case DW_AT_declaration: return "DW_AT_declaration";
5032 case DW_AT_discr_list: return "DW_AT_discr_list";
5033 case DW_AT_encoding: return "DW_AT_encoding";
5034 case DW_AT_external: return "DW_AT_external";
5035 case DW_AT_frame_base: return "DW_AT_frame_base";
5036 case DW_AT_friend: return "DW_AT_friend";
5037 case DW_AT_identifier_case: return "DW_AT_identifier_case";
5038 case DW_AT_macro_info: return "DW_AT_macro_info";
5039 case DW_AT_namelist_items: return "DW_AT_namelist_items";
5040 case DW_AT_priority: return "DW_AT_priority";
5041 case DW_AT_segment: return "DW_AT_segment";
5042 case DW_AT_specification: return "DW_AT_specification";
5043 case DW_AT_static_link: return "DW_AT_static_link";
5044 case DW_AT_type: return "DW_AT_type";
5045 case DW_AT_use_location: return "DW_AT_use_location";
5046 case DW_AT_variable_parameter: return "DW_AT_variable_parameter";
5047 case DW_AT_virtuality: return "DW_AT_virtuality";
5048 case DW_AT_vtable_elem_location: return "DW_AT_vtable_elem_location";
5049 case DW_AT_MIPS_fde: return "DW_AT_MIPS_fde";
5050 case DW_AT_MIPS_loop_begin: return "DW_AT_MIPS_loop_begin";
5051 case DW_AT_MIPS_tail_loop_begin: return "DW_AT_MIPS_tail_loop_begin";
5052 case DW_AT_MIPS_epilog_begin: return "DW_AT_MIPS_epilog_begin";
5053 case DW_AT_MIPS_loop_unroll_factor: return "DW_AT_MIPS_loop_unroll_factor";
5054 case DW_AT_MIPS_software_pipeline_depth: return "DW_AT_MIPS_software_pipeline_depth";
5055 case DW_AT_MIPS_linkage_name: return "DW_AT_MIPS_linkage_name";
5056 case DW_AT_MIPS_stride: return "DW_AT_MIPS_stride";
5057 case DW_AT_MIPS_abstract_name: return "DW_AT_MIPS_abstract_name";
5058 case DW_AT_MIPS_clone_origin: return "DW_AT_MIPS_clone_origin";
5059 case DW_AT_MIPS_has_inlines: return "DW_AT_MIPS_has_inlines";
5060 case DW_AT_sf_names: return "DW_AT_sf_names";
5061 case DW_AT_src_info: return "DW_AT_src_info";
5062 case DW_AT_mac_info: return "DW_AT_mac_info";
5063 case DW_AT_src_coords: return "DW_AT_src_coords";
5064 case DW_AT_body_begin: return "DW_AT_body_begin";
5065 case DW_AT_body_end: return "DW_AT_body_end";
5066 default:
5067 {
5068 static char buffer [100];
5069
5070 sprintf (buffer, _("Unknown AT value: %lx"), attribute);
5071 return buffer;
5072 }
5073 }
5074 }
5075
5076 static char *
5077 get_FORM_name (form)
5078 unsigned long form;
5079 {
5080 switch (form)
5081 {
5082 case DW_FORM_addr: return "DW_FORM_addr";
5083 case DW_FORM_block2: return "DW_FORM_block2";
5084 case DW_FORM_block4: return "DW_FORM_block4";
5085 case DW_FORM_data2: return "DW_FORM_data2";
5086 case DW_FORM_data4: return "DW_FORM_data4";
5087 case DW_FORM_data8: return "DW_FORM_data8";
5088 case DW_FORM_string: return "DW_FORM_string";
5089 case DW_FORM_block: return "DW_FORM_block";
5090 case DW_FORM_block1: return "DW_FORM_block1";
5091 case DW_FORM_data1: return "DW_FORM_data1";
5092 case DW_FORM_flag: return "DW_FORM_flag";
5093 case DW_FORM_sdata: return "DW_FORM_sdata";
5094 case DW_FORM_strp: return "DW_FORM_strp";
5095 case DW_FORM_udata: return "DW_FORM_udata";
5096 case DW_FORM_ref_addr: return "DW_FORM_ref_addr";
5097 case DW_FORM_ref1: return "DW_FORM_ref1";
5098 case DW_FORM_ref2: return "DW_FORM_ref2";
5099 case DW_FORM_ref4: return "DW_FORM_ref4";
5100 case DW_FORM_ref8: return "DW_FORM_ref8";
5101 case DW_FORM_ref_udata: return "DW_FORM_ref_udata";
5102 case DW_FORM_indirect: return "DW_FORM_indirect";
5103 default:
5104 {
5105 static char buffer [100];
5106
5107 sprintf (buffer, _("Unknown FORM value: %lx"), form);
5108 return buffer;
5109 }
5110 }
5111 }
5112
5113 /* FIXME: There are better and more effiecint ways to handle
5114 these structures. For now though, I just want something that
5115 is simple to implement. */
5116 typedef struct abbrev_attr
5117 {
5118 unsigned long attribute;
5119 unsigned long form;
5120 struct abbrev_attr * next;
5121 }
5122 abbrev_attr;
5123
5124 typedef struct abbrev_entry
5125 {
5126 unsigned long entry;
5127 unsigned long tag;
5128 int children;
5129 struct abbrev_attr * first_attr;
5130 struct abbrev_attr * last_attr;
5131 struct abbrev_entry * next;
5132 }
5133 abbrev_entry;
5134
5135 static abbrev_entry * first_abbrev = NULL;
5136 static abbrev_entry * last_abbrev = NULL;
5137
5138 static void
5139 free_abbrevs PARAMS ((void))
5140 {
5141 abbrev_entry * abbrev;
5142
5143 for (abbrev = first_abbrev; abbrev;)
5144 {
5145 abbrev_entry * next = abbrev->next;
5146 abbrev_attr * attr;
5147
5148 for (attr = abbrev->first_attr; attr;)
5149 {
5150 abbrev_attr * next = attr->next;
5151
5152 free (attr);
5153 attr = next;
5154 }
5155
5156 free (abbrev);
5157 abbrev = next;
5158 }
5159
5160 last_abbrev = first_abbrev = NULL;
5161 }
5162
5163 static void
5164 add_abbrev (number, tag, children)
5165 unsigned long number;
5166 unsigned long tag;
5167 int children;
5168 {
5169 abbrev_entry * entry;
5170
5171 entry = (abbrev_entry *) malloc (sizeof (* entry));
5172
5173 if (entry == NULL)
5174 /* ugg */
5175 return;
5176
5177 entry->entry = number;
5178 entry->tag = tag;
5179 entry->children = children;
5180 entry->first_attr = NULL;
5181 entry->last_attr = NULL;
5182 entry->next = NULL;
5183
5184 if (first_abbrev == NULL)
5185 first_abbrev = entry;
5186 else
5187 last_abbrev->next = entry;
5188
5189 last_abbrev = entry;
5190 }
5191
5192 static void
5193 add_abbrev_attr (attribute, form)
5194 unsigned long attribute;
5195 unsigned long form;
5196 {
5197 abbrev_attr * attr;
5198
5199 attr = (abbrev_attr *) malloc (sizeof (* attr));
5200
5201 if (attr == NULL)
5202 /* ugg */
5203 return;
5204
5205 attr->attribute = attribute;
5206 attr->form = form;
5207 attr->next = NULL;
5208
5209 if (last_abbrev->first_attr == NULL)
5210 last_abbrev->first_attr = attr;
5211 else
5212 last_abbrev->last_attr->next = attr;
5213
5214 last_abbrev->last_attr = attr;
5215 }
5216
5217 /* Processes the (partial) contents of a .debug_abbrev section.
5218 Returns NULL if the end of the section was encountered.
5219 Returns the address after the last byte read if the end of
5220 an abbreviation set was found. */
5221
5222 static unsigned char *
5223 process_abbrev_section (start, end)
5224 unsigned char * start;
5225 unsigned char * end;
5226 {
5227 if (first_abbrev != NULL)
5228 return NULL;
5229
5230 while (start < end)
5231 {
5232 int bytes_read;
5233 unsigned long entry;
5234 unsigned long tag;
5235 unsigned long attribute;
5236 int children;
5237
5238 entry = read_leb128 (start, & bytes_read, 0);
5239 start += bytes_read;
5240
5241 /* A single zero is supposed to end the section according
5242 to the standard. If there's more, then signal that to
5243 the caller. */
5244 if (entry == 0)
5245 return start == end ? NULL : start;
5246
5247 tag = read_leb128 (start, & bytes_read, 0);
5248 start += bytes_read;
5249
5250 children = * start ++;
5251
5252 add_abbrev (entry, tag, children);
5253
5254 do
5255 {
5256 unsigned long form;
5257
5258 attribute = read_leb128 (start, & bytes_read, 0);
5259 start += bytes_read;
5260
5261 form = read_leb128 (start, & bytes_read, 0);
5262 start += bytes_read;
5263
5264 if (attribute != 0)
5265 add_abbrev_attr (attribute, form);
5266 }
5267 while (attribute != 0);
5268 }
5269
5270 return NULL;
5271 }
5272
5273
5274 static int
5275 display_debug_abbrev (section, start, file)
5276 Elf32_Internal_Shdr * section;
5277 unsigned char * start;
5278 FILE * file ATTRIBUTE_UNUSED;
5279 {
5280 abbrev_entry * entry;
5281 unsigned char * end = start + section->sh_size;
5282
5283 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section));
5284
5285 do
5286 {
5287 start = process_abbrev_section (start, end);
5288
5289 printf (_(" Number TAG\n"));
5290
5291 for (entry = first_abbrev; entry; entry = entry->next)
5292 {
5293 abbrev_attr * attr;
5294
5295 printf (_(" %ld %s [%s]\n"),
5296 entry->entry,
5297 get_TAG_name (entry->tag),
5298 entry->children ? _("has children") : _("no children"));
5299
5300 for (attr = entry->first_attr; attr; attr = attr->next)
5301 {
5302 printf (_(" %-18s %s\n"),
5303 get_AT_name (attr->attribute),
5304 get_FORM_name (attr->form));
5305 }
5306 }
5307 }
5308 while (start);
5309
5310 printf ("\n");
5311
5312 return 1;
5313 }
5314
5315
5316 static unsigned char *
5317 display_block (data, length)
5318 unsigned char * data;
5319 unsigned long length;
5320 {
5321 printf (_(" %lu byte block: "), length);
5322
5323 while (length --)
5324 printf ("%lx ", (unsigned long) byte_get (data ++, 1));
5325
5326 return data;
5327 }
5328
5329 static void
5330 decode_location_expression (data, pointer_size)
5331 unsigned char * data;
5332 unsigned int pointer_size;
5333 {
5334 unsigned char op;
5335 int bytes_read;
5336 unsigned long uvalue;
5337
5338 op = * data ++;
5339
5340 switch (op)
5341 {
5342 case DW_OP_addr:
5343 printf ("DW_OP_addr: %lx", (unsigned long) byte_get (data, pointer_size));
5344 break;
5345 case DW_OP_deref:
5346 printf ("DW_OP_deref");
5347 break;
5348 case DW_OP_const1u:
5349 printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data, 1));
5350 break;
5351 case DW_OP_const1s:
5352 printf ("DW_OP_const1s: %ld", (long) byte_get (data, 1));
5353 break;
5354 case DW_OP_const2u:
5355 printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data, 2));
5356 break;
5357 case DW_OP_const2s:
5358 printf ("DW_OP_const2s: %ld", (long) byte_get (data, 2));
5359 break;
5360 case DW_OP_const4u:
5361 printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data, 4));
5362 break;
5363 case DW_OP_const4s:
5364 printf ("DW_OP_const4s: %ld", (long) byte_get (data, 4));
5365 break;
5366 case DW_OP_const8u:
5367 printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data, 4),
5368 (unsigned long) byte_get (data + 4, 4));
5369 break;
5370 case DW_OP_const8s:
5371 printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data, 4),
5372 (long) byte_get (data + 4, 4));
5373 break;
5374 case DW_OP_constu:
5375 printf ("DW_OP_constu: %lu", read_leb128 (data, NULL, 0));
5376 break;
5377 case DW_OP_consts:
5378 printf ("DW_OP_consts: %ld", read_leb128 (data, NULL, 1));
5379 break;
5380 case DW_OP_dup:
5381 printf ("DW_OP_dup");
5382 break;
5383 case DW_OP_drop:
5384 printf ("DW_OP_drop");
5385 break;
5386 case DW_OP_over:
5387 printf ("DW_OP_over");
5388 break;
5389 case DW_OP_pick:
5390 printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data, 1));
5391 break;
5392 case DW_OP_swap:
5393 printf ("DW_OP_swap");
5394 break;
5395 case DW_OP_rot:
5396 printf ("DW_OP_rot");
5397 break;
5398 case DW_OP_xderef:
5399 printf ("DW_OP_xderef");
5400 break;
5401 case DW_OP_abs:
5402 printf ("DW_OP_abs");
5403 break;
5404 case DW_OP_and:
5405 printf ("DW_OP_and");
5406 break;
5407 case DW_OP_div:
5408 printf ("DW_OP_div");
5409 break;
5410 case DW_OP_minus:
5411 printf ("DW_OP_minus");
5412 break;
5413 case DW_OP_mod:
5414 printf ("DW_OP_mod");
5415 break;
5416 case DW_OP_mul:
5417 printf ("DW_OP_mul");
5418 break;
5419 case DW_OP_neg:
5420 printf ("DW_OP_neg");
5421 break;
5422 case DW_OP_not:
5423 printf ("DW_OP_not");
5424 break;
5425 case DW_OP_or:
5426 printf ("DW_OP_or");
5427 break;
5428 case DW_OP_plus:
5429 printf ("DW_OP_plus");
5430 break;
5431 case DW_OP_plus_uconst:
5432 printf ("DW_OP_plus_uconst: %lu", read_leb128 (data, NULL, 0));
5433 break;
5434 case DW_OP_shl:
5435 printf ("DW_OP_shl");
5436 break;
5437 case DW_OP_shr:
5438 printf ("DW_OP_shr");
5439 break;
5440 case DW_OP_shra:
5441 printf ("DW_OP_shra");
5442 break;
5443 case DW_OP_xor:
5444 printf ("DW_OP_xor");
5445 break;
5446 case DW_OP_bra:
5447 printf ("DW_OP_bra: %ld", (long) byte_get (data, 2));
5448 break;
5449 case DW_OP_eq:
5450 printf ("DW_OP_eq");
5451 break;
5452 case DW_OP_ge:
5453 printf ("DW_OP_ge");
5454 break;
5455 case DW_OP_gt:
5456 printf ("DW_OP_gt");
5457 break;
5458 case DW_OP_le:
5459 printf ("DW_OP_le");
5460 break;
5461 case DW_OP_lt:
5462 printf ("DW_OP_lt");
5463 break;
5464 case DW_OP_ne:
5465 printf ("DW_OP_ne");
5466 break;
5467 case DW_OP_skip:
5468 printf ("DW_OP_skip: %ld", (long) byte_get (data, 2));
5469 break;
5470 case DW_OP_lit0:
5471 printf ("DW_OP_lit0");
5472 break;
5473 case DW_OP_lit1:
5474 printf ("DW_OP_lit1");
5475 break;
5476 case DW_OP_lit2:
5477 printf ("DW_OP_lit2");
5478 break;
5479 case DW_OP_lit3:
5480 printf ("DW_OP_lit3");
5481 break;
5482 case DW_OP_lit4:
5483 printf ("DW_OP_lit4");
5484 break;
5485 case DW_OP_lit5:
5486 printf ("DW_OP_lit5");
5487 break;
5488 case DW_OP_lit6:
5489 printf ("DW_OP_lit6");
5490 break;
5491 case DW_OP_lit7:
5492 printf ("DW_OP_lit7");
5493 break;
5494 case DW_OP_lit8:
5495 printf ("DW_OP_lit8");
5496 break;
5497 case DW_OP_lit9:
5498 printf ("DW_OP_lit9");
5499 break;
5500 case DW_OP_lit10:
5501 printf ("DW_OP_lit10");
5502 break;
5503 case DW_OP_lit11:
5504 printf ("DW_OP_lit11");
5505 break;
5506 case DW_OP_lit12:
5507 printf ("DW_OP_lit12");
5508 break;
5509 case DW_OP_lit13:
5510 printf ("DW_OP_lit13");
5511 break;
5512 case DW_OP_lit14:
5513 printf ("DW_OP_lit14");
5514 break;
5515 case DW_OP_lit15:
5516 printf ("DW_OP_lit15");
5517 break;
5518 case DW_OP_lit16:
5519 printf ("DW_OP_lit16");
5520 break;
5521 case DW_OP_lit17:
5522 printf ("DW_OP_lit17");
5523 break;
5524 case DW_OP_lit18:
5525 printf ("DW_OP_lit18");
5526 break;
5527 case DW_OP_lit19:
5528 printf ("DW_OP_lit19");
5529 break;
5530 case DW_OP_lit20:
5531 printf ("DW_OP_lit20");
5532 break;
5533 case DW_OP_lit21:
5534 printf ("DW_OP_lit21");
5535 break;
5536 case DW_OP_lit22:
5537 printf ("DW_OP_lit22");
5538 break;
5539 case DW_OP_lit23:
5540 printf ("DW_OP_lit23");
5541 break;
5542 case DW_OP_lit24:
5543 printf ("DW_OP_lit24");
5544 break;
5545 case DW_OP_lit25:
5546 printf ("DW_OP_lit25");
5547 break;
5548 case DW_OP_lit26:
5549 printf ("DW_OP_lit26");
5550 break;
5551 case DW_OP_lit27:
5552 printf ("DW_OP_lit27");
5553 break;
5554 case DW_OP_lit28:
5555 printf ("DW_OP_lit28");
5556 break;
5557 case DW_OP_lit29:
5558 printf ("DW_OP_lit29");
5559 break;
5560 case DW_OP_lit30:
5561 printf ("DW_OP_lit30");
5562 break;
5563 case DW_OP_lit31:
5564 printf ("DW_OP_lit31");
5565 break;
5566 case DW_OP_reg0:
5567 printf ("DW_OP_reg0");
5568 break;
5569 case DW_OP_reg1:
5570 printf ("DW_OP_reg1");
5571 break;
5572 case DW_OP_reg2:
5573 printf ("DW_OP_reg2");
5574 break;
5575 case DW_OP_reg3:
5576 printf ("DW_OP_reg3");
5577 break;
5578 case DW_OP_reg4:
5579 printf ("DW_OP_reg4");
5580 break;
5581 case DW_OP_reg5:
5582 printf ("DW_OP_reg5");
5583 break;
5584 case DW_OP_reg6:
5585 printf ("DW_OP_reg6");
5586 break;
5587 case DW_OP_reg7:
5588 printf ("DW_OP_reg7");
5589 break;
5590 case DW_OP_reg8:
5591 printf ("DW_OP_reg8");
5592 break;
5593 case DW_OP_reg9:
5594 printf ("DW_OP_reg9");
5595 break;
5596 case DW_OP_reg10:
5597 printf ("DW_OP_reg10");
5598 break;
5599 case DW_OP_reg11:
5600 printf ("DW_OP_reg11");
5601 break;
5602 case DW_OP_reg12:
5603 printf ("DW_OP_reg12");
5604 break;
5605 case DW_OP_reg13:
5606 printf ("DW_OP_reg13");
5607 break;
5608 case DW_OP_reg14:
5609 printf ("DW_OP_reg14");
5610 break;
5611 case DW_OP_reg15:
5612 printf ("DW_OP_reg15");
5613 break;
5614 case DW_OP_reg16:
5615 printf ("DW_OP_reg16");
5616 break;
5617 case DW_OP_reg17:
5618 printf ("DW_OP_reg17");
5619 break;
5620 case DW_OP_reg18:
5621 printf ("DW_OP_reg18");
5622 break;
5623 case DW_OP_reg19:
5624 printf ("DW_OP_reg19");
5625 break;
5626 case DW_OP_reg20:
5627 printf ("DW_OP_reg20");
5628 break;
5629 case DW_OP_reg21:
5630 printf ("DW_OP_reg21");
5631 break;
5632 case DW_OP_reg22:
5633 printf ("DW_OP_reg22");
5634 break;
5635 case DW_OP_reg23:
5636 printf ("DW_OP_reg23");
5637 break;
5638 case DW_OP_reg24:
5639 printf ("DW_OP_reg24");
5640 break;
5641 case DW_OP_reg25:
5642 printf ("DW_OP_reg25");
5643 break;
5644 case DW_OP_reg26:
5645 printf ("DW_OP_reg26");
5646 break;
5647 case DW_OP_reg27:
5648 printf ("DW_OP_reg27");
5649 break;
5650 case DW_OP_reg28:
5651 printf ("DW_OP_reg28");
5652 break;
5653 case DW_OP_reg29:
5654 printf ("DW_OP_reg29");
5655 break;
5656 case DW_OP_reg30:
5657 printf ("DW_OP_reg30");
5658 break;
5659 case DW_OP_reg31:
5660 printf ("DW_OP_reg31");
5661 break;
5662 case DW_OP_breg0:
5663 printf ("DW_OP_breg0: %ld", read_leb128 (data, NULL, 1));
5664 break;
5665 case DW_OP_breg1:
5666 printf ("DW_OP_breg1: %ld", read_leb128 (data, NULL, 1));
5667 break;
5668 case DW_OP_breg2:
5669 printf ("DW_OP_breg2: %ld", read_leb128 (data, NULL, 1));
5670 break;
5671 case DW_OP_breg3:
5672 printf ("DW_OP_breg3: %ld", read_leb128 (data, NULL, 1));
5673 break;
5674 case DW_OP_breg4:
5675 printf ("DW_OP_breg4: %ld", read_leb128 (data, NULL, 1));
5676 break;
5677 case DW_OP_breg5:
5678 printf ("DW_OP_breg5: %ld", read_leb128 (data, NULL, 1));
5679 break;
5680 case DW_OP_breg6:
5681 printf ("DW_OP_breg6: %ld", read_leb128 (data, NULL, 1));
5682 break;
5683 case DW_OP_breg7:
5684 printf ("DW_OP_breg7: %ld", read_leb128 (data, NULL, 1));
5685 break;
5686 case DW_OP_breg8:
5687 printf ("DW_OP_breg8: %ld", read_leb128 (data, NULL, 1));
5688 break;
5689 case DW_OP_breg9:
5690 printf ("DW_OP_breg9: %ld", read_leb128 (data, NULL, 1));
5691 break;
5692 case DW_OP_breg10:
5693 printf ("DW_OP_breg10: %ld", read_leb128 (data, NULL, 1));
5694 break;
5695 case DW_OP_breg11:
5696 printf ("DW_OP_breg11: %ld", read_leb128 (data, NULL, 1));
5697 break;
5698 case DW_OP_breg12:
5699 printf ("DW_OP_breg12: %ld", read_leb128 (data, NULL, 1));
5700 break;
5701 case DW_OP_breg13:
5702 printf ("DW_OP_breg13: %ld", read_leb128 (data, NULL, 1));
5703 break;
5704 case DW_OP_breg14:
5705 printf ("DW_OP_breg14: %ld", read_leb128 (data, NULL, 1));
5706 break;
5707 case DW_OP_breg15:
5708 printf ("DW_OP_breg15: %ld", read_leb128 (data, NULL, 1));
5709 break;
5710 case DW_OP_breg16:
5711 printf ("DW_OP_breg16: %ld", read_leb128 (data, NULL, 1));
5712 break;
5713 case DW_OP_breg17:
5714 printf ("DW_OP_breg17: %ld", read_leb128 (data, NULL, 1));
5715 break;
5716 case DW_OP_breg18:
5717 printf ("DW_OP_breg18: %ld", read_leb128 (data, NULL, 1));
5718 break;
5719 case DW_OP_breg19:
5720 printf ("DW_OP_breg19: %ld", read_leb128 (data, NULL, 1));
5721 break;
5722 case DW_OP_breg20:
5723 printf ("DW_OP_breg20: %ld", read_leb128 (data, NULL, 1));
5724 break;
5725 case DW_OP_breg21:
5726 printf ("DW_OP_breg21: %ld", read_leb128 (data, NULL, 1));
5727 break;
5728 case DW_OP_breg22:
5729 printf ("DW_OP_breg22: %ld", read_leb128 (data, NULL, 1));
5730 break;
5731 case DW_OP_breg23:
5732 printf ("DW_OP_breg23: %ld", read_leb128 (data, NULL, 1));
5733 break;
5734 case DW_OP_breg24:
5735 printf ("DW_OP_breg24: %ld", read_leb128 (data, NULL, 1));
5736 break;
5737 case DW_OP_breg25:
5738 printf ("DW_OP_breg25: %ld", read_leb128 (data, NULL, 1));
5739 break;
5740 case DW_OP_breg26:
5741 printf ("DW_OP_breg26: %ld", read_leb128 (data, NULL, 1));
5742 break;
5743 case DW_OP_breg27:
5744 printf ("DW_OP_breg27: %ld", read_leb128 (data, NULL, 1));
5745 break;
5746 case DW_OP_breg28:
5747 printf ("DW_OP_breg28: %ld", read_leb128 (data, NULL, 1));
5748 break;
5749 case DW_OP_breg29:
5750 printf ("DW_OP_breg29: %ld", read_leb128 (data, NULL, 1));
5751 break;
5752 case DW_OP_breg30:
5753 printf ("DW_OP_breg30: %ld", read_leb128 (data, NULL, 1));
5754 break;
5755 case DW_OP_breg31:
5756 printf ("DW_OP_breg31: %ld", read_leb128 (data, NULL, 1));
5757 break;
5758 case DW_OP_regx:
5759 printf ("DW_OP_regx: %lu", read_leb128 (data, NULL, 0));
5760 break;
5761 case DW_OP_fbreg:
5762 printf ("DW_OP_fbreg: %ld", read_leb128 (data, NULL, 1));
5763 break;
5764 case DW_OP_bregx:
5765 uvalue = read_leb128 (data, &bytes_read, 0);
5766 printf ("DW_OP_bregx: %lu %ld", uvalue,
5767 read_leb128 (data + bytes_read, NULL, 1));
5768 break;
5769 case DW_OP_piece:
5770 printf ("DW_OP_piece: %lu", read_leb128 (data, NULL, 0));
5771 break;
5772 case DW_OP_deref_size:
5773 printf ("DW_OP_deref_size: %ld", (long) byte_get (data, 1));
5774 break;
5775 case DW_OP_xderef_size:
5776 printf ("DW_OP_xderef_size: %ld", (long) byte_get (data, 1));
5777 break;
5778 case DW_OP_nop:
5779 printf ("DW_OP_nop");
5780 break;
5781
5782 default:
5783 if (op >= DW_OP_lo_user
5784 && op <= DW_OP_hi_user)
5785 printf (_("(User defined location op)"));
5786 else
5787 printf (_("(Unknown location op)"));
5788 break;
5789 }
5790 }
5791
5792
5793 static unsigned char *
5794 read_and_display_attr (attribute, form, data, pointer_size)
5795 unsigned long attribute;
5796 unsigned long form;
5797 unsigned char * data;
5798 unsigned long pointer_size;
5799 {
5800 unsigned long uvalue = 0;
5801 unsigned char * block_start = NULL;
5802 int bytes_read;
5803 int is_ref = 0;
5804
5805 printf (" %-18s:", get_AT_name (attribute));
5806
5807 switch (form)
5808 {
5809 case DW_FORM_ref_addr:
5810 case DW_FORM_ref1:
5811 case DW_FORM_ref2:
5812 case DW_FORM_ref4:
5813 case DW_FORM_ref8:
5814 case DW_FORM_ref_udata:
5815 is_ref = 1;
5816 }
5817
5818 switch (form)
5819 {
5820 case DW_FORM_ref_addr:
5821 case DW_FORM_addr:
5822 uvalue = byte_get (data, pointer_size);
5823 printf (is_ref ? " <%x>" : " %#x", uvalue);
5824 data += pointer_size;
5825 break;
5826
5827 case DW_FORM_ref1:
5828 case DW_FORM_flag:
5829 case DW_FORM_data1:
5830 uvalue = byte_get (data ++, 1);
5831 printf (is_ref ? " <%x>" : " %d", uvalue);
5832 break;
5833
5834 case DW_FORM_ref2:
5835 case DW_FORM_data2:
5836 uvalue = byte_get (data, 2);
5837 data += 2;
5838 printf (is_ref ? " <%x>" : " %d", uvalue);
5839 break;
5840
5841 case DW_FORM_ref4:
5842 case DW_FORM_data4:
5843 uvalue = byte_get (data, 4);
5844 data += 4;
5845 printf (is_ref ? " <%x>" : " %d", uvalue);
5846 break;
5847
5848 case DW_FORM_ref8:
5849 case DW_FORM_data8:
5850 uvalue = byte_get (data, 4);
5851 printf (" %lx", uvalue);
5852 printf (" %lx", (unsigned long) byte_get (data + 4, 4));
5853 data += 8;
5854 break;
5855
5856 case DW_FORM_string:
5857 printf (" %s", data);
5858 data += strlen (data) + 1;
5859 break;
5860
5861 case DW_FORM_sdata:
5862 uvalue = read_leb128 (data, & bytes_read, 1);
5863 data += bytes_read;
5864 printf (" %ld", (long) uvalue);
5865 break;
5866
5867 case DW_FORM_ref_udata:
5868 case DW_FORM_udata:
5869 uvalue = read_leb128 (data, & bytes_read, 0);
5870 data += bytes_read;
5871 printf (is_ref ? " <%lx>" : " %ld", uvalue);
5872 break;
5873
5874 case DW_FORM_block:
5875 uvalue = read_leb128 (data, & bytes_read, 0);
5876 block_start = data + bytes_read;
5877 data = display_block (block_start, uvalue);
5878 uvalue = * block_start;
5879 break;
5880
5881 case DW_FORM_block1:
5882 uvalue = byte_get (data, 1);
5883 block_start = data + 1;
5884 data = display_block (block_start, uvalue);
5885 uvalue = * block_start;
5886 break;
5887
5888 case DW_FORM_block2:
5889 uvalue = byte_get (data, 2);
5890 block_start = data + 2;
5891 data = display_block (block_start, uvalue);
5892 uvalue = * block_start;
5893 break;
5894
5895 case DW_FORM_block4:
5896 uvalue = byte_get (data, 4);
5897 block_start = data + 4;
5898 data = display_block (block_start, uvalue);
5899 uvalue = * block_start;
5900 break;
5901
5902 case DW_FORM_strp:
5903 case DW_FORM_indirect:
5904 warn (_("Unable to handle FORM: %d"), form);
5905 break;
5906
5907 default:
5908 warn (_("Unrecognised form: %d"), form);
5909 break;
5910 }
5911
5912 /* For some attributes we can display futher information. */
5913
5914 printf ("\t");
5915
5916 switch (attribute)
5917 {
5918 case DW_AT_inline:
5919 switch (uvalue)
5920 {
5921 case DW_INL_not_inlined: printf (_("(not inlined)")); break;
5922 case DW_INL_inlined: printf (_("(inlined)")); break;
5923 case DW_INL_declared_not_inlined: printf (_("(declared as inline but ignored)")); break;
5924 case DW_INL_declared_inlined: printf (_("(declared as inline and inlined)")); break;
5925 default: printf (_(" (Unknown inline attribute value: %lx)"), uvalue); break;
5926 }
5927 break;
5928
5929 case DW_AT_frame_base:
5930 if (uvalue >= DW_OP_reg0 && uvalue <= DW_OP_reg31)
5931 printf ("(reg %ld)", uvalue - DW_OP_reg0);
5932 break;
5933
5934 case DW_AT_language:
5935 switch (uvalue)
5936 {
5937 case DW_LANG_C: printf ("(non-ANSI C)"); break;
5938 case DW_LANG_C89: printf ("(ANSI C)"); break;
5939 case DW_LANG_C_plus_plus: printf ("(C++)"); break;
5940 case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break;
5941 case DW_LANG_Fortran90: printf ("(Fortran 90)"); break;
5942 case DW_LANG_Modula2: printf ("(Modula 2)"); break;
5943 case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break;
5944 case DW_LANG_Ada83: printf ("(Ada)"); break;
5945 case DW_LANG_Cobol74: printf ("(Cobol 74)"); break;
5946 case DW_LANG_Cobol85: printf ("(Cobol 85)"); break;
5947 case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break;
5948 default: printf ("(Unknown: %lx)", uvalue); break;
5949 }
5950 break;
5951
5952 case DW_AT_encoding:
5953 switch (uvalue)
5954 {
5955 case DW_ATE_void: printf ("(void)"); break;
5956 case DW_ATE_address: printf ("(machine address)"); break;
5957 case DW_ATE_boolean: printf ("(boolean)"); break;
5958 case DW_ATE_complex_float: printf ("(complex float)"); break;
5959 case DW_ATE_float: printf ("(float)"); break;
5960 case DW_ATE_signed: printf ("(signed)"); break;
5961 case DW_ATE_signed_char: printf ("(signed char)"); break;
5962 case DW_ATE_unsigned: printf ("(unsigned)"); break;
5963 case DW_ATE_unsigned_char: printf ("(unsigned char)"); break;
5964 default:
5965 if (uvalue >= DW_ATE_lo_user
5966 && uvalue <= DW_ATE_hi_user)
5967 printf ("(user defined type)");
5968 else
5969 printf ("(unknown type)");
5970 break;
5971 }
5972 break;
5973
5974 case DW_AT_accessibility:
5975 switch (uvalue)
5976 {
5977 case DW_ACCESS_public: printf ("(public)"); break;
5978 case DW_ACCESS_protected: printf ("(protected)"); break;
5979 case DW_ACCESS_private: printf ("(private)"); break;
5980 default: printf ("(unknown accessibility)"); break;
5981 }
5982 break;
5983
5984 case DW_AT_visibility:
5985 switch (uvalue)
5986 {
5987 case DW_VIS_local: printf ("(local)"); break;
5988 case DW_VIS_exported: printf ("(exported)"); break;
5989 case DW_VIS_qualified: printf ("(qualified)"); break;
5990 default: printf ("(unknown visibility)"); break;
5991 }
5992 break;
5993
5994 case DW_AT_virtuality:
5995 switch (uvalue)
5996 {
5997 case DW_VIRTUALITY_none: printf ("(none)"); break;
5998 case DW_VIRTUALITY_virtual: printf ("(virtual)"); break;
5999 case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break;
6000 default: printf ("(unknown virtuality)"); break;
6001 }
6002 break;
6003
6004 case DW_AT_identifier_case:
6005 switch (uvalue)
6006 {
6007 case DW_ID_case_sensitive: printf ("(case_sensitive)"); break;
6008 case DW_ID_up_case: printf ("(up_case)"); break;
6009 case DW_ID_down_case: printf ("(down_case)"); break;
6010 case DW_ID_case_insensitive: printf ("(case_insensitive)"); break;
6011 default: printf ("(unknown case)"); break;
6012 }
6013 break;
6014
6015 case DW_AT_calling_convention:
6016 switch (uvalue)
6017 {
6018 case DW_CC_normal: printf ("(normal)"); break;
6019 case DW_CC_program: printf ("(program)"); break;
6020 case DW_CC_nocall: printf ("(nocall)"); break;
6021 default:
6022 if (uvalue >= DW_CC_lo_user
6023 && uvalue <= DW_CC_hi_user)
6024 printf ("(user defined)");
6025 else
6026 printf ("(unknown convention)");
6027 }
6028 break;
6029
6030 case DW_AT_location:
6031 case DW_AT_data_member_location:
6032 case DW_AT_vtable_elem_location:
6033 printf ("(");
6034 decode_location_expression (block_start, pointer_size);
6035 printf (")");
6036 break;
6037
6038 default:
6039 break;
6040 }
6041
6042 printf ("\n");
6043 return data;
6044 }
6045
6046 static int
6047 display_debug_info (section, start, file)
6048 Elf32_Internal_Shdr * section;
6049 unsigned char * start;
6050 FILE * file;
6051 {
6052 unsigned char * end = start + section->sh_size;
6053 unsigned char * section_begin = start;
6054
6055 printf (_("The section %s contains:\n\n"), SECTION_NAME (section));
6056
6057 while (start < end)
6058 {
6059 DWARF2_External_CompUnit * external;
6060 DWARF2_Internal_CompUnit compunit;
6061 unsigned char * tags;
6062 int i;
6063 int level;
6064
6065 external = (DWARF2_External_CompUnit *) start;
6066
6067 compunit.cu_length = BYTE_GET (external->cu_length);
6068 compunit.cu_version = BYTE_GET (external->cu_version);
6069 compunit.cu_abbrev_offset = BYTE_GET (external->cu_abbrev_offset);
6070 compunit.cu_pointer_size = BYTE_GET (external->cu_pointer_size);
6071
6072 tags = start + sizeof (* external);
6073 start += compunit.cu_length + sizeof (external->cu_length);
6074
6075 if (compunit.cu_version != 2)
6076 {
6077 warn (_("Only version 2 DWARF debug information is currently supported.\n"));
6078 continue;
6079 }
6080
6081 printf (_(" Compilation Unit:\n"));
6082 printf (_(" Length: %ld\n"), compunit.cu_length);
6083 printf (_(" Version: %d\n"), compunit.cu_version);
6084 printf (_(" Abbrev Offset: %ld\n"), compunit.cu_abbrev_offset);
6085 printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size);
6086
6087 if (first_abbrev != NULL)
6088 free_abbrevs ();
6089
6090 /* Read in the abbrevs used by this compilation unit. */
6091
6092 {
6093 Elf32_Internal_Shdr * sec;
6094 unsigned char * begin;
6095
6096 /* Locate the .debug_abbrev section and process it. */
6097 for (i = 0, sec = section_headers;
6098 i < elf_header.e_shnum;
6099 i ++, sec ++)
6100 if (strcmp (SECTION_NAME (sec), ".debug_abbrev") == 0)
6101 break;
6102
6103 if (i == -1 || sec->sh_size == 0)
6104 {
6105 warn (_("Unable to locate .debug_abbrev section!\n"));
6106 return 0;
6107 }
6108
6109 GET_DATA_ALLOC (sec->sh_offset, sec->sh_size, begin, unsigned char *,
6110 "debug_abbrev section data");
6111
6112 process_abbrev_section (begin + compunit.cu_abbrev_offset,
6113 begin + sec->sh_size);
6114
6115 free (begin);
6116 }
6117
6118 level = 0;
6119 while (tags < start)
6120 {
6121 int bytes_read;
6122 unsigned long abbrev_number;
6123 abbrev_entry * entry;
6124 abbrev_attr * attr;
6125
6126 abbrev_number = read_leb128 (tags, & bytes_read, 0);
6127 tags += bytes_read;
6128
6129 /* A null DIE marks the end of a list of children. */
6130 if (abbrev_number == 0)
6131 {
6132 --level;
6133 continue;
6134 }
6135
6136 /* Scan through the abbreviation list until we reach the
6137 correct entry. */
6138 for (entry = first_abbrev;
6139 entry && entry->entry != abbrev_number;
6140 entry = entry->next)
6141 continue;
6142
6143 if (entry == NULL)
6144 {
6145 warn (_("Unable to locate entry %lu in the abbreviation table\n"),
6146 abbrev_number);
6147 return 0;
6148 }
6149
6150 printf (_(" <%d><%x>: Abbrev Number: %lu (%s)\n"),
6151 level, tags - section_begin - bytes_read,
6152 abbrev_number,
6153 get_TAG_name (entry->tag));
6154
6155 for (attr = entry->first_attr; attr; attr = attr->next)
6156 tags = read_and_display_attr (attr->attribute,
6157 attr->form,
6158 tags,
6159 compunit.cu_pointer_size);
6160
6161 if (entry->children)
6162 ++level;
6163 }
6164 }
6165
6166 printf ("\n");
6167
6168 return 1;
6169 }
6170
6171 static int
6172 display_debug_aranges (section, start, file)
6173 Elf32_Internal_Shdr * section;
6174 unsigned char * start;
6175 FILE * file ATTRIBUTE_UNUSED;
6176 {
6177 unsigned char * end = start + section->sh_size;
6178
6179 printf (_("The section %s contains:\n\n"), SECTION_NAME (section));
6180
6181 while (start < end)
6182 {
6183 DWARF2_External_ARange * external;
6184 DWARF2_Internal_ARange arange;
6185 unsigned char * ranges;
6186 unsigned long length;
6187 unsigned long address;
6188 int excess;
6189
6190 external = (DWARF2_External_ARange *) start;
6191
6192 arange.ar_length = BYTE_GET (external->ar_length);
6193 arange.ar_version = BYTE_GET (external->ar_version);
6194 arange.ar_info_offset = BYTE_GET (external->ar_info_offset);
6195 arange.ar_pointer_size = BYTE_GET (external->ar_pointer_size);
6196 arange.ar_segment_size = BYTE_GET (external->ar_segment_size);
6197
6198 printf (_(" Length: %ld\n"), arange.ar_length);
6199 printf (_(" Version: %d\n"), arange.ar_version);
6200 printf (_(" Offset into .debug_info: %lx\n"), arange.ar_info_offset);
6201 printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
6202 printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
6203
6204 printf (_("\n Address Length\n"));
6205
6206 ranges = start + sizeof (* external);
6207
6208 /* Must pad to an alignment boundary that is twice the pointer size. */
6209 excess = sizeof (*external) % (2 * arange.ar_pointer_size);
6210 if (excess)
6211 ranges += (2 * arange.ar_pointer_size) - excess;
6212
6213 for (;;)
6214 {
6215 address = byte_get (ranges, arange.ar_pointer_size);
6216
6217 ranges += arange.ar_pointer_size;
6218
6219 length = byte_get (ranges, arange.ar_pointer_size);
6220
6221 ranges += arange.ar_pointer_size;
6222
6223 /* A pair of zeros marks the end of the list. */
6224 if (address == 0 && length == 0)
6225 break;
6226
6227 printf (" %8.8lx %lu\n", address, length);
6228 }
6229
6230 start += arange.ar_length + sizeof (external->ar_length);
6231 }
6232
6233 printf ("\n");
6234
6235 return 1;
6236 }
6237
6238
6239 static int
6240 display_debug_not_supported (section, start, file)
6241 Elf32_Internal_Shdr * section;
6242 unsigned char * start ATTRIBUTE_UNUSED;
6243 FILE * file ATTRIBUTE_UNUSED;
6244 {
6245 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
6246 SECTION_NAME (section));
6247
6248 return 1;
6249 }
6250
6251 /* Pre-scan the .debug_info section to record the size of address.
6252 When dumping the .debug_line, we use that size information, assuming
6253 that all compilation units have the same address size. */
6254 static int
6255 prescan_debug_info (section, start, file)
6256 Elf32_Internal_Shdr * section ATTRIBUTE_UNUSED;
6257 unsigned char * start;
6258 FILE * file ATTRIBUTE_UNUSED;
6259 {
6260 DWARF2_External_CompUnit * external;
6261
6262 external = (DWARF2_External_CompUnit *) start;
6263
6264 debug_line_pointer_size = BYTE_GET (external->cu_pointer_size);
6265 return 0;
6266 }
6267
6268 /* A structure containing the name of a debug section and a pointer
6269 to a function that can decode it. The third field is a prescan
6270 function to be run over the section before displaying any of the
6271 sections. */
6272 struct
6273 {
6274 char * name;
6275 int (* display) PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
6276 int (* prescan) PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
6277 }
6278 debug_displays[] =
6279 {
6280 { ".debug_info", display_debug_info, prescan_debug_info },
6281 { ".debug_abbrev", display_debug_abbrev, NULL },
6282 { ".debug_line", display_debug_lines, NULL },
6283 { ".debug_aranges", display_debug_aranges, NULL },
6284 { ".debug_pubnames", display_debug_pubnames, NULL },
6285 { ".debug_macinfo", display_debug_not_supported, NULL },
6286 { ".debug_frame", display_debug_not_supported, NULL },
6287 { ".debug_str", display_debug_not_supported, NULL },
6288 { ".debug_static_func", display_debug_not_supported, NULL },
6289 { ".debug_static_vars", display_debug_not_supported, NULL },
6290 { ".debug_types", display_debug_not_supported, NULL },
6291 { ".debug_weaknames", display_debug_not_supported, NULL }
6292 };
6293
6294 static int
6295 display_debug_section (section, file)
6296 Elf32_Internal_Shdr * section;
6297 FILE * file;
6298 {
6299 char * name = SECTION_NAME (section);
6300 bfd_size_type length;
6301 unsigned char * start;
6302 int i;
6303
6304 length = section->sh_size;
6305 if (length == 0)
6306 {
6307 printf (_("\nSection '%s' has no debugging data.\n"), name);
6308 return 0;
6309 }
6310
6311 GET_DATA_ALLOC (section->sh_offset, length, start, unsigned char *,
6312 "debug section data");
6313
6314 /* See if we know how to display the contents of this section. */
6315 for (i = NUM_ELEM (debug_displays); i--;)
6316 if (strcmp (debug_displays[i].name, name) == 0)
6317 {
6318 debug_displays[i].display (section, start, file);
6319 break;
6320 }
6321
6322 if (i == -1)
6323 printf (_("Unrecognised debug section: %s\n"), name);
6324
6325 free (start);
6326
6327 /* If we loaded in the abbrev section at some point,
6328 we must release it here. */
6329 if (first_abbrev != NULL)
6330 free_abbrevs ();
6331
6332 return 1;
6333 }
6334
6335 static int
6336 process_section_contents (file)
6337 FILE * file;
6338 {
6339 Elf32_Internal_Shdr * section;
6340 unsigned int i;
6341
6342 if (! do_dump)
6343 return 1;
6344
6345 /* Pre-scan the debug sections to find some debug information not
6346 present in some of them. For the .debug_line, we must find out the
6347 size of address (specified in .debug_info and .debug_aranges). */
6348 for (i = 0, section = section_headers;
6349 i < elf_header.e_shnum && i < num_dump_sects;
6350 i ++, section ++)
6351 {
6352 char * name = SECTION_NAME (section);
6353 int j;
6354
6355 if (section->sh_size == 0)
6356 continue;
6357
6358 /* See if there is some pre-scan operation for this section. */
6359 for (j = NUM_ELEM (debug_displays); j--;)
6360 if (strcmp (debug_displays[j].name, name) == 0)
6361 {
6362 if (debug_displays[j].prescan != NULL)
6363 {
6364 bfd_size_type length;
6365 unsigned char * start;
6366
6367 length = section->sh_size;
6368 GET_DATA_ALLOC (section->sh_offset, length, start, unsigned char *,
6369 "debug section data");
6370
6371 debug_displays[j].prescan (section, start, file);
6372 free (start);
6373 }
6374
6375 break;
6376 }
6377 }
6378
6379 for (i = 0, section = section_headers;
6380 i < elf_header.e_shnum && i < num_dump_sects;
6381 i ++, section ++)
6382 {
6383 #ifdef SUPPORT_DISASSEMBLY
6384 if (dump_sects[i] & DISASS_DUMP)
6385 disassemble_section (section, file);
6386 #endif
6387 if (dump_sects[i] & HEX_DUMP)
6388 dump_section (section, file);
6389
6390 if (dump_sects[i] & DEBUG_DUMP)
6391 display_debug_section (section, file);
6392 }
6393
6394 if (i < num_dump_sects)
6395 warn (_("Some sections were not dumped because they do not exist!\n"));
6396
6397 return 1;
6398 }
6399
6400 static void
6401 process_mips_fpe_exception (mask)
6402 int mask;
6403 {
6404 if (mask)
6405 {
6406 int first = 1;
6407 if (mask & OEX_FPU_INEX)
6408 fputs ("INEX", stdout), first = 0;
6409 if (mask & OEX_FPU_UFLO)
6410 printf ("%sUFLO", first ? "" : "|"), first = 0;
6411 if (mask & OEX_FPU_OFLO)
6412 printf ("%sOFLO", first ? "" : "|"), first = 0;
6413 if (mask & OEX_FPU_DIV0)
6414 printf ("%sDIV0", first ? "" : "|"), first = 0;
6415 if (mask & OEX_FPU_INVAL)
6416 printf ("%sINVAL", first ? "" : "|");
6417 }
6418 else
6419 fputs ("0", stdout);
6420 }
6421
6422 static int
6423 process_mips_specific (file)
6424 FILE * file;
6425 {
6426 Elf_Internal_Dyn * entry;
6427 size_t liblist_offset = 0;
6428 size_t liblistno = 0;
6429 size_t conflictsno = 0;
6430 size_t options_offset = 0;
6431 size_t conflicts_offset = 0;
6432
6433 /* We have a lot of special sections. Thanks SGI! */
6434 if (dynamic_segment == NULL)
6435 /* No information available. */
6436 return 0;
6437
6438 for (entry = dynamic_segment; entry->d_tag != DT_NULL; ++entry)
6439 switch (entry->d_tag)
6440 {
6441 case DT_MIPS_LIBLIST:
6442 liblist_offset = entry->d_un.d_val - loadaddr;
6443 break;
6444 case DT_MIPS_LIBLISTNO:
6445 liblistno = entry->d_un.d_val;
6446 break;
6447 case DT_MIPS_OPTIONS:
6448 options_offset = entry->d_un.d_val - loadaddr;
6449 break;
6450 case DT_MIPS_CONFLICT:
6451 conflicts_offset = entry->d_un.d_val - loadaddr;
6452 break;
6453 case DT_MIPS_CONFLICTNO:
6454 conflictsno = entry->d_un.d_val;
6455 break;
6456 default:
6457 break;
6458 }
6459
6460 if (liblist_offset != 0 && liblistno != 0 && do_dynamic)
6461 {
6462 Elf32_External_Lib * elib;
6463 size_t cnt;
6464
6465 GET_DATA_ALLOC (liblist_offset, liblistno * sizeof (Elf32_External_Lib),
6466 elib, Elf32_External_Lib *, "liblist");
6467
6468 printf ("\nSection '.liblist' contains %d entries:\n", liblistno);
6469 fputs (" Library Time Stamp Checksum Version Flags\n",
6470 stdout);
6471
6472 for (cnt = 0; cnt < liblistno; ++cnt)
6473 {
6474 Elf32_Lib liblist;
6475 time_t time;
6476 char timebuf[20];
6477
6478 liblist.l_name = BYTE_GET (elib[cnt].l_name);
6479 time = BYTE_GET (elib[cnt].l_time_stamp);
6480 liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum);
6481 liblist.l_version = BYTE_GET (elib[cnt].l_version);
6482 liblist.l_flags = BYTE_GET (elib[cnt].l_flags);
6483
6484 strftime (timebuf, 20, "%Y-%m-%dT%H:%M:%S", gmtime (&time));
6485
6486 printf ("%3d: %-20s %s %#10lx %-7ld", cnt,
6487 dynamic_strings + liblist.l_name, timebuf,
6488 liblist.l_checksum, liblist.l_version);
6489
6490 if (liblist.l_flags == 0)
6491 puts (" NONE");
6492 else
6493 {
6494 static const struct
6495 {
6496 const char * name;
6497 int bit;
6498 }
6499 l_flags_vals[] =
6500 {
6501 { " EXACT_MATCH", LL_EXACT_MATCH },
6502 { " IGNORE_INT_VER", LL_IGNORE_INT_VER },
6503 { " REQUIRE_MINOR", LL_REQUIRE_MINOR },
6504 { " EXPORTS", LL_EXPORTS },
6505 { " DELAY_LOAD", LL_DELAY_LOAD },
6506 { " DELTA", LL_DELTA }
6507 };
6508 int flags = liblist.l_flags;
6509 size_t fcnt;
6510
6511 for (fcnt = 0;
6512 fcnt < sizeof (l_flags_vals) / sizeof (l_flags_vals[0]);
6513 ++fcnt)
6514 if ((flags & l_flags_vals[fcnt].bit) != 0)
6515 {
6516 fputs (l_flags_vals[fcnt].name, stdout);
6517 flags ^= l_flags_vals[fcnt].bit;
6518 }
6519 if (flags != 0)
6520 printf (" %#x", (unsigned int) flags);
6521
6522 puts ("");
6523 }
6524 }
6525
6526 free (elib);
6527 }
6528
6529 if (options_offset != 0)
6530 {
6531 Elf_External_Options * eopt;
6532 Elf_Internal_Shdr * sect = section_headers;
6533 Elf_Internal_Options * iopt;
6534 Elf_Internal_Options * option;
6535 size_t offset;
6536 int cnt;
6537
6538 /* Find the section header so that we get the size. */
6539 while (sect->sh_type != SHT_MIPS_OPTIONS)
6540 ++sect;
6541
6542 GET_DATA_ALLOC (options_offset, sect->sh_size, eopt,
6543 Elf_External_Options *, "options");
6544
6545 iopt = (Elf_Internal_Options *) malloc ((sect->sh_size / sizeof (eopt))
6546 * sizeof (*iopt));
6547 if (iopt == NULL)
6548 {
6549 error (_("Out of memory"));
6550 return 0;
6551 }
6552
6553 offset = cnt = 0;
6554 option = iopt;
6555 while (offset < sect->sh_size)
6556 {
6557 Elf_External_Options * eoption;
6558
6559 eoption = (Elf_External_Options *) ((char *) eopt + offset);
6560
6561 option->kind = BYTE_GET (eoption->kind);
6562 option->size = BYTE_GET (eoption->size);
6563 option->section = BYTE_GET (eoption->section);
6564 option->info = BYTE_GET (eoption->info);
6565
6566 offset += option->size;
6567 ++option;
6568 ++cnt;
6569 }
6570
6571 printf (_("\nSection '%s' contains %d entries:\n"),
6572 string_table + sect->sh_name, cnt);
6573
6574 option = iopt;
6575 while (cnt-- > 0)
6576 {
6577 size_t len;
6578
6579 switch (option->kind)
6580 {
6581 case ODK_NULL:
6582 /* This shouldn't happen. */
6583 printf (" NULL %d %lx", option->section, option->info);
6584 break;
6585 case ODK_REGINFO:
6586 printf (" REGINFO ");
6587 if (elf_header.e_machine == EM_MIPS)
6588 {
6589 /* 32bit form. */
6590 Elf32_External_RegInfo *ereg;
6591 Elf32_RegInfo reginfo;
6592
6593 ereg = (Elf32_External_RegInfo *) (option + 1);
6594 reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask);
6595 reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
6596 reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
6597 reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
6598 reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
6599 reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value);
6600
6601 printf ("GPR %08lx GP 0x%lx\n",
6602 reginfo.ri_gprmask,
6603 (unsigned long) reginfo.ri_gp_value);
6604 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
6605 reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
6606 reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
6607 }
6608 else
6609 {
6610 /* 64 bit form. */
6611 Elf64_External_RegInfo * ereg;
6612 Elf64_Internal_RegInfo reginfo;
6613
6614 ereg = (Elf64_External_RegInfo *) (option + 1);
6615 reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask);
6616 reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
6617 reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
6618 reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
6619 reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
6620 reginfo.ri_gp_value = BYTE_GET8 (ereg->ri_gp_value);
6621
6622 printf ("GPR %08lx GP 0x",
6623 reginfo.ri_gprmask);
6624 printf_vma (reginfo.ri_gp_value);
6625 printf ("\n");
6626
6627 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
6628 reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
6629 reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
6630 }
6631 ++option;
6632 continue;
6633 case ODK_EXCEPTIONS:
6634 fputs (" EXCEPTIONS fpe_min(", stdout);
6635 process_mips_fpe_exception (option->info & OEX_FPU_MIN);
6636 fputs (") fpe_max(", stdout);
6637 process_mips_fpe_exception ((option->info & OEX_FPU_MAX) >> 8);
6638 fputs (")", stdout);
6639
6640 if (option->info & OEX_PAGE0)
6641 fputs (" PAGE0", stdout);
6642 if (option->info & OEX_SMM)
6643 fputs (" SMM", stdout);
6644 if (option->info & OEX_FPDBUG)
6645 fputs (" FPDBUG", stdout);
6646 if (option->info & OEX_DISMISS)
6647 fputs (" DISMISS", stdout);
6648 break;
6649 case ODK_PAD:
6650 fputs (" PAD ", stdout);
6651 if (option->info & OPAD_PREFIX)
6652 fputs (" PREFIX", stdout);
6653 if (option->info & OPAD_POSTFIX)
6654 fputs (" POSTFIX", stdout);
6655 if (option->info & OPAD_SYMBOL)
6656 fputs (" SYMBOL", stdout);
6657 break;
6658 case ODK_HWPATCH:
6659 fputs (" HWPATCH ", stdout);
6660 if (option->info & OHW_R4KEOP)
6661 fputs (" R4KEOP", stdout);
6662 if (option->info & OHW_R8KPFETCH)
6663 fputs (" R8KPFETCH", stdout);
6664 if (option->info & OHW_R5KEOP)
6665 fputs (" R5KEOP", stdout);
6666 if (option->info & OHW_R5KCVTL)
6667 fputs (" R5KCVTL", stdout);
6668 break;
6669 case ODK_FILL:
6670 fputs (" FILL ", stdout);
6671 /* XXX Print content of info word? */
6672 break;
6673 case ODK_TAGS:
6674 fputs (" TAGS ", stdout);
6675 /* XXX Print content of info word? */
6676 break;
6677 case ODK_HWAND:
6678 fputs (" HWAND ", stdout);
6679 if (option->info & OHWA0_R4KEOP_CHECKED)
6680 fputs (" R4KEOP_CHECKED", stdout);
6681 if (option->info & OHWA0_R4KEOP_CLEAN)
6682 fputs (" R4KEOP_CLEAN", stdout);
6683 break;
6684 case ODK_HWOR:
6685 fputs (" HWOR ", stdout);
6686 if (option->info & OHWA0_R4KEOP_CHECKED)
6687 fputs (" R4KEOP_CHECKED", stdout);
6688 if (option->info & OHWA0_R4KEOP_CLEAN)
6689 fputs (" R4KEOP_CLEAN", stdout);
6690 break;
6691 case ODK_GP_GROUP:
6692 printf (" GP_GROUP %#06lx self-contained %#06lx",
6693 option->info & OGP_GROUP,
6694 (option->info & OGP_SELF) >> 16);
6695 break;
6696 case ODK_IDENT:
6697 printf (" IDENT %#06lx self-contained %#06lx",
6698 option->info & OGP_GROUP,
6699 (option->info & OGP_SELF) >> 16);
6700 break;
6701 default:
6702 /* This shouldn't happen. */
6703 printf (" %3d ??? %d %lx",
6704 option->kind, option->section, option->info);
6705 break;
6706 }
6707
6708 len = sizeof (*eopt);
6709 while (len < option->size)
6710 if (((char *) option)[len] >= ' '
6711 && ((char *) option)[len] < 0x7f)
6712 printf ("%c", ((char *) option)[len++]);
6713 else
6714 printf ("\\%03o", ((char *) option)[len++]);
6715
6716 fputs ("\n", stdout);
6717 ++option;
6718 }
6719
6720 free (eopt);
6721 }
6722
6723 if (conflicts_offset != 0 && conflictsno != 0)
6724 {
6725 Elf32_External_Conflict * econf32;
6726 Elf64_External_Conflict * econf64;
6727 Elf32_Conflict * iconf;
6728 size_t cnt;
6729
6730 if (dynamic_symbols == NULL)
6731 {
6732 error (_("conflict list with without table"));
6733 return 0;
6734 }
6735
6736 iconf = (Elf32_Conflict *) malloc (conflictsno * sizeof (*iconf));
6737 if (iconf == NULL)
6738 {
6739 error (_("Out of memory"));
6740 return 0;
6741 }
6742
6743 if (is_32bit_elf)
6744 {
6745 GET_DATA_ALLOC (conflicts_offset, conflictsno * sizeof (*econf32),
6746 econf32, Elf32_External_Conflict *, "conflict");
6747
6748 for (cnt = 0; cnt < conflictsno; ++cnt)
6749 iconf[cnt] = BYTE_GET (econf32[cnt]);
6750 }
6751 else
6752 {
6753 GET_DATA_ALLOC (conflicts_offset, conflictsno * sizeof (*econf64),
6754 econf64, Elf64_External_Conflict *, "conflict");
6755
6756 for (cnt = 0; cnt < conflictsno; ++cnt)
6757 iconf[cnt] = BYTE_GET (econf64[cnt]);
6758 }
6759
6760 printf (_("\nSection '.conflict' contains %d entries:\n"), conflictsno);
6761 puts (_(" Num: Index Value Name"));
6762
6763 for (cnt = 0; cnt < conflictsno; ++cnt)
6764 {
6765 Elf_Internal_Sym * psym = &dynamic_symbols[iconf[cnt]];
6766
6767 printf ("%5u: %8lu ", cnt, iconf[cnt]);
6768 print_vma (psym->st_value, FULL_HEX);
6769 printf (" %s\n", dynamic_strings + psym->st_name);
6770 }
6771
6772 free (iconf);
6773 }
6774
6775 return 1;
6776 }
6777
6778 static char *
6779 get_note_type (e_type)
6780 unsigned e_type;
6781 {
6782 static char buff[64];
6783
6784 switch (e_type)
6785 {
6786 case NT_PRSTATUS: return _("NT_PRSTATUS (prstatus structure)");
6787 case NT_FPREGSET: return _("NT_FPREGSET (floating point registers)");
6788 case NT_PRPSINFO: return _("NT_PRPSINFO (prpsinfo structure)");
6789 case NT_TASKSTRUCT: return _("NT_TASKSTRUCT (task structure)");
6790 case NT_PSTATUS: return _("NT_PSTATUS (pstatus structure)");
6791 case NT_FPREGS: return _("NT_FPREGS (floating point registers)");
6792 case NT_PSINFO: return _("NT_PSINFO (psinfo structure)");
6793 case NT_LWPSTATUS: return _("NT_LWPSTATUS (lwpstatus_t structure)");
6794 case NT_LWPSINFO: return _("NT_LWPSINFO (lwpsinfo_t structure)");
6795 default:
6796 sprintf (buff, _("Unknown note type: (0x%08x)"), e_type);
6797 return buff;
6798 }
6799 }
6800
6801 /* Note that by the ELF standard, the name field is already null byte
6802 terminated, and namesz includes the terminating null byte.
6803 I.E. the value of namesz for the name "FSF" is 4.
6804
6805 If the value of namesz is zero, there is no name present. */
6806 static int
6807 process_note (pnote)
6808 Elf32_Internal_Note * pnote;
6809 {
6810 printf (" %s\t\t0x%08lx\t%s\n",
6811 pnote->namesz ? pnote->namedata : "(NONE)",
6812 pnote->descsz, get_note_type (pnote->type));
6813 return 1;
6814 }
6815
6816
6817 static int
6818 process_corefile_note_segment (file, offset, length)
6819 FILE * file;
6820 bfd_vma offset;
6821 bfd_vma length;
6822 {
6823 Elf_External_Note * pnotes;
6824 Elf_External_Note * external;
6825 int res = 1;
6826
6827 if (length <= 0)
6828 return 0;
6829
6830 GET_DATA_ALLOC (offset, length, pnotes, Elf_External_Note *, "notes");
6831
6832 external = pnotes;
6833
6834 printf (_("\nNotes at offset 0x%08lx with length 0x%08lx:\n"), offset, length);
6835 printf (_(" Owner\t\tData size\tDescription\n"));
6836
6837 while (external < (Elf_External_Note *)((char *) pnotes + length))
6838 {
6839 Elf32_Internal_Note inote;
6840 char * temp = NULL;
6841
6842 inote.type = BYTE_GET (external->type);
6843 inote.namesz = BYTE_GET (external->namesz);
6844 inote.namedata = external->name;
6845 inote.descsz = BYTE_GET (external->descsz);
6846 inote.descdata = inote.namedata + align_power (inote.namesz, 2);
6847 inote.descpos = offset + (inote.descdata - (char *) pnotes);
6848
6849 external = (Elf_External_Note *)(inote.descdata + align_power (inote.descsz, 2));
6850
6851 /* Verify that name is null terminated. It appears that at least
6852 one version of Linux (RedHat 6.0) generates corefiles that don't
6853 comply with the ELF spec by failing to include the null byte in
6854 namesz. */
6855 if (inote.namedata[inote.namesz] != '\0')
6856 {
6857 temp = malloc (inote.namesz + 1);
6858
6859 if (temp == NULL)
6860 {
6861 error (_("Out of memory\n"));
6862 res = 0;
6863 break;
6864 }
6865
6866 strncpy (temp, inote.namedata, inote.namesz);
6867 temp[inote.namesz] = 0;
6868
6869 /* warn (_("'%s' NOTE name not properly null terminated\n"), temp); */
6870 inote.namedata = temp;
6871 }
6872
6873 res &= process_note (& inote);
6874
6875 if (temp != NULL)
6876 {
6877 free (temp);
6878 temp = NULL;
6879 }
6880 }
6881
6882 free (pnotes);
6883
6884 return res;
6885 }
6886
6887 static int
6888 process_corefile_note_segments (file)
6889 FILE * file;
6890 {
6891 Elf_Internal_Phdr * program_headers;
6892 Elf_Internal_Phdr * segment;
6893 unsigned int i;
6894 int res = 1;
6895
6896 program_headers = (Elf_Internal_Phdr *) malloc
6897 (elf_header.e_phnum * sizeof (Elf_Internal_Phdr));
6898
6899 if (program_headers == NULL)
6900 {
6901 error (_("Out of memory\n"));
6902 return 0;
6903 }
6904
6905 if (is_32bit_elf)
6906 i = get_32bit_program_headers (file, program_headers);
6907 else
6908 i = get_64bit_program_headers (file, program_headers);
6909
6910 if (i == 0)
6911 {
6912 free (program_headers);
6913 return 0;
6914 }
6915
6916 for (i = 0, segment = program_headers;
6917 i < elf_header.e_phnum;
6918 i ++, segment ++)
6919 {
6920 if (segment->p_type == PT_NOTE)
6921 res &= process_corefile_note_segment (file,
6922 (bfd_vma) segment->p_offset,
6923 (bfd_vma) segment->p_filesz);
6924 }
6925
6926 free (program_headers);
6927
6928 return res;
6929 }
6930
6931 static int
6932 process_corefile_contents (file)
6933 FILE * file;
6934 {
6935 /* If we have not been asked to display the notes then do nothing. */
6936 if (! do_notes)
6937 return 1;
6938
6939 /* If file is not a core file then exit. */
6940 if (elf_header.e_type != ET_CORE)
6941 return 1;
6942
6943 /* No program headers means no NOTE segment. */
6944 if (elf_header.e_phnum == 0)
6945 {
6946 printf (_("No note segments present in the core file.\n"));
6947 return 1;
6948 }
6949
6950 return process_corefile_note_segments (file);
6951 }
6952
6953 static int
6954 process_arch_specific (file)
6955 FILE * file;
6956 {
6957 if (! do_arch)
6958 return 1;
6959
6960 switch (elf_header.e_machine)
6961 {
6962 case EM_MIPS:
6963 case EM_MIPS_RS4_BE:
6964 return process_mips_specific (file);
6965 break;
6966 default:
6967 break;
6968 }
6969 return 1;
6970 }
6971
6972 static int
6973 get_file_header (file)
6974 FILE * file;
6975 {
6976 /* Read in the identity array. */
6977 if (fread (elf_header.e_ident, EI_NIDENT, 1, file) != 1)
6978 return 0;
6979
6980 /* Determine how to read the rest of the header. */
6981 switch (elf_header.e_ident [EI_DATA])
6982 {
6983 default: /* fall through */
6984 case ELFDATANONE: /* fall through */
6985 case ELFDATA2LSB: byte_get = byte_get_little_endian; break;
6986 case ELFDATA2MSB: byte_get = byte_get_big_endian; break;
6987 }
6988
6989 /* For now we only support 32 bit and 64 bit ELF files. */
6990 is_32bit_elf = (elf_header.e_ident [EI_CLASS] != ELFCLASS64);
6991
6992 /* Read in the rest of the header. */
6993 if (is_32bit_elf)
6994 {
6995 Elf32_External_Ehdr ehdr32;
6996
6997 if (fread (ehdr32.e_type, sizeof (ehdr32) - EI_NIDENT, 1, file) != 1)
6998 return 0;
6999
7000 elf_header.e_type = BYTE_GET (ehdr32.e_type);
7001 elf_header.e_machine = BYTE_GET (ehdr32.e_machine);
7002 elf_header.e_version = BYTE_GET (ehdr32.e_version);
7003 elf_header.e_entry = BYTE_GET (ehdr32.e_entry);
7004 elf_header.e_phoff = BYTE_GET (ehdr32.e_phoff);
7005 elf_header.e_shoff = BYTE_GET (ehdr32.e_shoff);
7006 elf_header.e_flags = BYTE_GET (ehdr32.e_flags);
7007 elf_header.e_ehsize = BYTE_GET (ehdr32.e_ehsize);
7008 elf_header.e_phentsize = BYTE_GET (ehdr32.e_phentsize);
7009 elf_header.e_phnum = BYTE_GET (ehdr32.e_phnum);
7010 elf_header.e_shentsize = BYTE_GET (ehdr32.e_shentsize);
7011 elf_header.e_shnum = BYTE_GET (ehdr32.e_shnum);
7012 elf_header.e_shstrndx = BYTE_GET (ehdr32.e_shstrndx);
7013 }
7014 else
7015 {
7016 Elf64_External_Ehdr ehdr64;
7017
7018 /* If we have been compiled with sizeof (bfd_vma) == 4, then
7019 we will not be able to cope with the 64bit data found in
7020 64 ELF files. Detect this now and abort before we start
7021 overwritting things. */
7022 if (sizeof (bfd_vma) < 8)
7023 {
7024 error (_("This instance of readelf has been built without support for a\n"));
7025 error (_("64 bit data type and so it cannot read 64 bit ELF files.\n"));
7026 return 0;
7027 }
7028
7029 if (fread (ehdr64.e_type, sizeof (ehdr64) - EI_NIDENT, 1, file) != 1)
7030 return 0;
7031
7032 elf_header.e_type = BYTE_GET (ehdr64.e_type);
7033 elf_header.e_machine = BYTE_GET (ehdr64.e_machine);
7034 elf_header.e_version = BYTE_GET (ehdr64.e_version);
7035 elf_header.e_entry = BYTE_GET8 (ehdr64.e_entry);
7036 elf_header.e_phoff = BYTE_GET8 (ehdr64.e_phoff);
7037 elf_header.e_shoff = BYTE_GET8 (ehdr64.e_shoff);
7038 elf_header.e_flags = BYTE_GET (ehdr64.e_flags);
7039 elf_header.e_ehsize = BYTE_GET (ehdr64.e_ehsize);
7040 elf_header.e_phentsize = BYTE_GET (ehdr64.e_phentsize);
7041 elf_header.e_phnum = BYTE_GET (ehdr64.e_phnum);
7042 elf_header.e_shentsize = BYTE_GET (ehdr64.e_shentsize);
7043 elf_header.e_shnum = BYTE_GET (ehdr64.e_shnum);
7044 elf_header.e_shstrndx = BYTE_GET (ehdr64.e_shstrndx);
7045 }
7046
7047 return 1;
7048 }
7049
7050 static void
7051 process_file (file_name)
7052 char * file_name;
7053 {
7054 FILE * file;
7055 struct stat statbuf;
7056 unsigned int i;
7057
7058 if (stat (file_name, & statbuf) < 0)
7059 {
7060 error (_("Cannot stat input file %s.\n"), file_name);
7061 return;
7062 }
7063
7064 file = fopen (file_name, "rb");
7065 if (file == NULL)
7066 {
7067 error (_("Input file %s not found.\n"), file_name);
7068 return;
7069 }
7070
7071 if (! get_file_header (file))
7072 {
7073 error (_("%s: Failed to read file header\n"), file_name);
7074 fclose (file);
7075 return;
7076 }
7077
7078 /* Initialise per file variables. */
7079 for (i = NUM_ELEM (version_info); i--;)
7080 version_info[i] = 0;
7081
7082 for (i = NUM_ELEM (dynamic_info); i--;)
7083 dynamic_info[i] = 0;
7084
7085 /* Process the file. */
7086 if (show_name)
7087 printf (_("\nFile: %s\n"), file_name);
7088
7089 if (! process_file_header ())
7090 {
7091 fclose (file);
7092 return;
7093 }
7094
7095 process_section_headers (file);
7096
7097 process_program_headers (file);
7098
7099 process_dynamic_segment (file);
7100
7101 process_relocs (file);
7102
7103 process_symbol_table (file);
7104
7105 process_syminfo (file);
7106
7107 process_version_sections (file);
7108
7109 process_section_contents (file);
7110
7111 process_corefile_contents (file);
7112
7113 process_arch_specific (file);
7114
7115 fclose (file);
7116
7117 if (section_headers)
7118 {
7119 free (section_headers);
7120 section_headers = NULL;
7121 }
7122
7123 if (string_table)
7124 {
7125 free (string_table);
7126 string_table = NULL;
7127 }
7128
7129 if (dynamic_strings)
7130 {
7131 free (dynamic_strings);
7132 dynamic_strings = NULL;
7133 }
7134
7135 if (dynamic_symbols)
7136 {
7137 free (dynamic_symbols);
7138 dynamic_symbols = NULL;
7139 num_dynamic_syms = 0;
7140 }
7141
7142 if (dynamic_syminfo)
7143 {
7144 free (dynamic_syminfo);
7145 dynamic_syminfo = NULL;
7146 }
7147 }
7148
7149 #ifdef SUPPORT_DISASSEMBLY
7150 /* Needed by the i386 disassembler. For extra credit, someone could
7151 fix this so that we insert symbolic addresses here, esp for GOT/PLT
7152 symbols */
7153
7154 void
7155 print_address (unsigned int addr, FILE * outfile)
7156 {
7157 fprintf (outfile,"0x%8.8x", addr);
7158 }
7159
7160 /* Needed by the i386 disassembler. */
7161 void
7162 db_task_printsym (unsigned int addr)
7163 {
7164 print_address (addr, stderr);
7165 }
7166 #endif
7167
7168 int
7169 main (argc, argv)
7170 int argc;
7171 char ** argv;
7172 {
7173 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
7174 setlocale (LC_MESSAGES, "");
7175 #endif
7176 bindtextdomain (PACKAGE, LOCALEDIR);
7177 textdomain (PACKAGE);
7178
7179 parse_args (argc, argv);
7180
7181 if (optind < (argc - 1))
7182 show_name = 1;
7183
7184 while (optind < argc)
7185 process_file (argv [optind ++]);
7186
7187 if (dump_sects != NULL)
7188 free (dump_sects);
7189
7190 return 0;
7191 }