1 /* readelf.c -- display contents of an ELF format file
2 Copyright (C) 1998, 99, 2000 Free Software Foundation, Inc.
4 Originally developed by Eric Youngdale <eric@andante.jic.com>
5 Modifications by Nick Clifton <nickc@cygnus.com>
7 This file is part of GNU Binutils.
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.
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.
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
26 #include <sys/types.h>
32 /* Define BFD64 here, even if our default architecture is 32 bit ELF
33 as this will allow us to read in and parse 64bit and 32bit ELF files.
34 Only do this if we belive that the compiler can support a 64 bit
35 data type. For now we only rely on GCC being able to do this. */
41 #include "elf/common.h"
42 #include "elf/external.h"
43 #include "elf/internal.h"
44 #include "elf/dwarf2.h"
46 /* The following headers use the elf/reloc-macros.h file to
47 automatically generate relocation recognition functions
48 such as elf_mips_reloc_type() */
50 #define RELOC_MACROS_GEN_FUNC
56 #include "elf/alpha.h"
59 #include "elf/sparc.h"
64 #include "elf/mn10200.h"
65 #include "elf/mn10300.h"
69 #include "elf/mcore.h"
77 char * program_name = "readelf";
78 unsigned int dynamic_addr;
79 bfd_size_type dynamic_size;
80 unsigned int rela_addr;
81 unsigned int rela_size;
82 char * dynamic_strings;
84 unsigned long num_dynamic_syms;
85 Elf_Internal_Sym * dynamic_symbols;
86 Elf_Internal_Syminfo * dynamic_syminfo;
87 unsigned long dynamic_syminfo_offset;
88 unsigned int dynamic_syminfo_nent;
89 char program_interpreter [64];
90 int dynamic_info[DT_JMPREL + 1];
93 Elf_Internal_Ehdr elf_header;
94 Elf_Internal_Shdr * section_headers;
95 Elf_Internal_Dyn * dynamic_segment;
102 int do_using_dynamic;
109 int do_debug_abbrevs;
111 int do_debug_pubnames;
112 int do_debug_aranges;
117 /* A dynamic array of flags indicating which sections require dumping. */
118 char * dump_sects = NULL;
119 unsigned int num_dump_sects = 0;
121 #define HEX_DUMP (1 << 0)
122 #define DISASS_DUMP (1 << 1)
123 #define DEBUG_DUMP (1 << 2)
125 /* How to rpint a vma value. */
126 typedef enum print_mode
138 /* Forward declarations for dumb compilers. */
139 static void print_vma PARAMS ((bfd_vma, print_mode));
140 static bfd_vma (* byte_get) PARAMS ((unsigned char *, int));
141 static bfd_vma byte_get_little_endian PARAMS ((unsigned char *, int));
142 static bfd_vma byte_get_big_endian PARAMS ((unsigned char *, int));
143 static const char * get_mips_dynamic_type PARAMS ((unsigned long));
144 static const char * get_sparc64_dynamic_type PARAMS ((unsigned long));
145 static const char * get_parisc_dynamic_type PARAMS ((unsigned long));
146 static const char * get_dynamic_type PARAMS ((unsigned long));
147 static int dump_relocations PARAMS ((FILE *, unsigned long, unsigned long, Elf_Internal_Sym *, unsigned long, char *, int));
148 static char * get_file_type PARAMS ((unsigned));
149 static char * get_machine_name PARAMS ((unsigned));
150 static void decode_ARM_machine_flags PARAMS ((unsigned, char []));
151 static char * get_machine_flags PARAMS ((unsigned, unsigned));
152 static const char * get_mips_segment_type PARAMS ((unsigned long));
153 static const char * get_parisc_segment_type PARAMS ((unsigned long));
154 static const char * get_segment_type PARAMS ((unsigned long));
155 static const char * get_mips_section_type_name PARAMS ((unsigned int));
156 static const char * get_parisc_section_type_name PARAMS ((unsigned int));
157 static const char * get_section_type_name PARAMS ((unsigned int));
158 static const char * get_symbol_binding PARAMS ((unsigned int));
159 static const char * get_symbol_type PARAMS ((unsigned int));
160 static const char * get_symbol_visibility PARAMS ((unsigned int));
161 static const char * get_symbol_index_type PARAMS ((unsigned int));
162 static const char * get_dynamic_flags PARAMS ((bfd_vma));
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 int get_32bit_section_headers PARAMS ((FILE *));
178 static int get_64bit_section_headers PARAMS ((FILE *));
179 static int get_32bit_program_headers PARAMS ((FILE *, Elf_Internal_Phdr *));
180 static int get_64bit_program_headers PARAMS ((FILE *, Elf_Internal_Phdr *));
181 static int get_file_header PARAMS ((FILE *));
182 static Elf_Internal_Sym * get_32bit_elf_symbols PARAMS ((FILE *, unsigned long, unsigned long));
183 static Elf_Internal_Sym * get_64bit_elf_symbols PARAMS ((FILE *, unsigned long, unsigned long));
184 static int * get_dynamic_data PARAMS ((FILE *, unsigned int));
185 static int get_32bit_dynamic_segment PARAMS ((FILE *));
186 static int get_64bit_dynamic_segment PARAMS ((FILE *));
187 #ifdef SUPPORT_DISASSEMBLY
188 static int disassemble_section PARAMS ((Elf32_Internal_Shdr *, FILE *));
190 static int dump_section PARAMS ((Elf32_Internal_Shdr *, FILE *));
191 static int display_debug_section PARAMS ((Elf32_Internal_Shdr *, FILE *));
192 static int display_debug_info PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
193 static int display_debug_not_supported PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
194 static int display_debug_lines PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
195 static int display_debug_abbrev PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
196 static int display_debug_aranges PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
197 static unsigned char * process_abbrev_section PARAMS ((unsigned char *, unsigned char *));
198 static unsigned long read_leb128 PARAMS ((unsigned char *, int *, int));
199 static int process_extended_line_op PARAMS ((unsigned char *, int, int));
200 static void reset_state_machine PARAMS ((int));
201 static char * get_TAG_name PARAMS ((unsigned long));
202 static char * get_AT_name PARAMS ((unsigned long));
203 static char * get_FORM_name PARAMS ((unsigned long));
204 static void free_abbrevs PARAMS ((void));
205 static void add_abbrev PARAMS ((unsigned long, unsigned long, int));
206 static void add_abbrev_attr PARAMS ((unsigned long, unsigned long));
207 static unsigned char * read_and_display_attr PARAMS ((unsigned long, unsigned long, unsigned char *, unsigned long, unsigned long));
208 static unsigned char * display_block PARAMS ((unsigned char *, unsigned long));
209 static void decode_location_expression PARAMS ((unsigned char *, unsigned int, unsigned long));
210 static void request_dump PARAMS ((unsigned int, char));
211 static const char * get_elf_class PARAMS ((unsigned char));
212 static const char * get_data_encoding PARAMS ((unsigned char));
213 static const char * get_osabi_name PARAMS ((unsigned char));
214 static int guess_is_rela PARAMS ((unsigned long));
215 static char * get_note_type PARAMS ((unsigned int));
216 static int process_note PARAMS ((Elf32_Internal_Note *));
217 static int process_corefile_note_segment PARAMS ((FILE *, bfd_vma, bfd_vma));
218 static int process_corefile_note_segments PARAMS ((FILE *));
219 static int process_corefile_contents PARAMS ((FILE *));
221 typedef int Elf32_Word;
229 #define SECTION_NAME(X) (string_table + (X)->sh_name)
231 #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
233 #define BYTE_GET(field) byte_get (field, sizeof (field))
235 /* If we can support a 64 bit data type then BFD64 should be defined
236 and sizeof (bfd_vma) == 8. In this case when translating from an
237 external 8 byte field to an internal field, we can assume that the
238 internal field is also 8 bytes wide and so we can extact all the data.
239 If, however, BFD64 is not defined, then we must assume that the
240 internal data structure only has 4 byte wide fields that are the
241 equivalent of the 8 byte wide external counterparts, and so we must
242 truncate the data. */
244 #define BYTE_GET8(field) byte_get (field, -8)
246 #define BYTE_GET8(field) byte_get (field, 8)
249 #define NUM_ELEM(array) (sizeof (array) / sizeof ((array)[0]))
251 #define GET_DATA_ALLOC(offset, size, var, type, reason) \
252 if (fseek (file, offset, SEEK_SET)) \
254 error (_("Unable to seek to start of %s at %x\n"), reason, offset); \
258 var = (type) malloc (size); \
262 error (_("Out of memory allocating %d bytes for %s\n"), size, reason); \
266 if (fread (var, size, 1, file) != 1) \
268 error (_("Unable to read in %d bytes of %s\n"), size, reason); \
275 #define GET_DATA(offset, var, reason) \
276 if (fseek (file, offset, SEEK_SET)) \
278 error (_("Unable to seek to %x for %s\n"), offset, reason); \
281 else if (fread (& var, sizeof (var), 1, file) != 1) \
283 error (_("Unable to read data at %x for %s\n"), offset, reason); \
287 #define GET_ELF_SYMBOLS(file, offset, size) \
288 (is_32bit_elf ? get_32bit_elf_symbols (file, offset, size) \
289 : get_64bit_elf_symbols (file, offset, size))
292 #ifdef ANSI_PROTOTYPES
294 error (const char * message, ...)
298 fprintf (stderr, _("%s: Error: "), program_name);
299 va_start (args, message);
300 vfprintf (stderr, message, args);
306 warn (const char * message, ...)
310 fprintf (stderr, _("%s: Warning: "), program_name);
311 va_start (args, message);
312 vfprintf (stderr, message, args);
324 fprintf (stderr, _("%s: Error: "), program_name);
326 message = va_arg (args, char *);
327 vfprintf (stderr, message, args);
339 fprintf (stderr, _("%s: Warning: "), program_name);
341 message = va_arg (args, char *);
342 vfprintf (stderr, message, args);
349 byte_get_little_endian (field, size)
350 unsigned char * field;
359 return ((unsigned int) (field [0]))
360 | (((unsigned int) (field [1])) << 8);
363 /* We want to extract data from an 8 byte wide field and
364 place it into a 4 byte wide field. Since this is a little
365 endian source we can juts use the 4 byte extraction code. */
368 return ((unsigned long) (field [0]))
369 | (((unsigned long) (field [1])) << 8)
370 | (((unsigned long) (field [2])) << 16)
371 | (((unsigned long) (field [3])) << 24);
375 /* This is a special case, generated by the BYTE_GET8 macro.
376 It means that we are loading an 8 byte value from a field
377 in an external structure into an 8 byte value in a field
378 in an internal strcuture. */
379 return ((bfd_vma) (field [0]))
380 | (((bfd_vma) (field [1])) << 8)
381 | (((bfd_vma) (field [2])) << 16)
382 | (((bfd_vma) (field [3])) << 24)
383 | (((bfd_vma) (field [4])) << 32)
384 | (((bfd_vma) (field [5])) << 40)
385 | (((bfd_vma) (field [6])) << 48)
386 | (((bfd_vma) (field [7])) << 56);
389 error (_("Unhandled data length: %d\n"), size);
394 /* Print a VMA value. */
396 print_vma (vma, mode)
406 case FULL_HEX: printf ("0x"); /* drop through */
407 case LONG_HEX: printf ("%8.8lx", (unsigned long) vma); break;
408 case PREFIX_HEX: printf ("0x"); /* drop through */
409 case HEX: printf ("%lx", (unsigned long) vma); break;
410 case DEC: printf ("%ld", (unsigned long) vma); break;
411 case DEC_5: printf ("%5ld", (long) vma); break;
412 case UNSIGNED: printf ("%lu", (unsigned long) vma); break;
433 #if BFD_HOST_64BIT_LONG
436 if (_bfd_int64_high (vma))
437 printf ("%lx%lx", _bfd_int64_high (vma), _bfd_int64_low (vma));
439 printf ("%lx", _bfd_int64_low (vma));
444 #if BFD_HOST_64BIT_LONG
447 if (_bfd_int64_high (vma))
449 printf ("++%ld", _bfd_int64_low (vma));
451 printf ("%ld", _bfd_int64_low (vma));
456 #if BFD_HOST_64BIT_LONG
457 printf ("%5ld", vma);
459 if (_bfd_int64_high (vma))
461 printf ("++%ld", _bfd_int64_low (vma));
463 printf ("%5ld", _bfd_int64_low (vma));
468 #if BFD_HOST_64BIT_LONG
471 if (_bfd_int64_high (vma))
473 printf ("++%lu", _bfd_int64_low (vma));
475 printf ("%lu", _bfd_int64_low (vma));
484 byte_get_big_endian (field, size)
485 unsigned char * field;
494 return ((unsigned int) (field [1])) | (((int) (field [0])) << 8);
497 return ((unsigned long) (field [3]))
498 | (((unsigned long) (field [2])) << 8)
499 | (((unsigned long) (field [1])) << 16)
500 | (((unsigned long) (field [0])) << 24);
503 /* Although we are extracing data from an 8 byte wide field, we
504 are returning only 4 bytes of data. */
505 return ((unsigned long) (field [7]))
506 | (((unsigned long) (field [6])) << 8)
507 | (((unsigned long) (field [5])) << 16)
508 | (((unsigned long) (field [4])) << 24);
512 /* This is a special case, generated by the BYTE_GET8 macro.
513 It means that we are loading an 8 byte value from a field
514 in an external structure into an 8 byte value in a field
515 in an internal strcuture. */
516 return ((bfd_vma) (field [7]))
517 | (((bfd_vma) (field [6])) << 8)
518 | (((bfd_vma) (field [5])) << 16)
519 | (((bfd_vma) (field [4])) << 24)
520 | (((bfd_vma) (field [3])) << 32)
521 | (((bfd_vma) (field [2])) << 40)
522 | (((bfd_vma) (field [1])) << 48)
523 | (((bfd_vma) (field [0])) << 56);
527 error (_("Unhandled data length: %d\n"), size);
533 /* Guess the relocation sized based on the sized commonly used by the specific machine. */
535 guess_is_rela (e_machine)
536 unsigned long e_machine;
540 /* Targets that use REL relocations. */
551 /* Targets that use RELA relocations. */
559 case EM_CYGNUS_MN10200:
560 case EM_CYGNUS_MN10300:
586 warn (_("Don't know about relocations on this machine architecture\n"));
591 /* Display the contents of the relocation data found at the specified offset. */
593 dump_relocations (file, rel_offset, rel_size, symtab, nsyms, strtab, is_rela)
595 unsigned long rel_offset;
596 unsigned long rel_size;
597 Elf_Internal_Sym * symtab;
603 Elf_Internal_Rel * rels;
604 Elf_Internal_Rela * relas;
607 if (is_rela == UNKNOWN)
608 is_rela = guess_is_rela (elf_header.e_machine);
614 Elf32_External_Rela * erelas;
616 GET_DATA_ALLOC (rel_offset, rel_size, erelas,
617 Elf32_External_Rela *, "relocs");
619 rel_size = rel_size / sizeof (Elf32_External_Rela);
621 relas = (Elf_Internal_Rela *)
622 malloc (rel_size * sizeof (Elf_Internal_Rela));
626 error(_("out of memory parsing relocs"));
630 for (i = 0; i < rel_size; i++)
632 relas[i].r_offset = BYTE_GET (erelas[i].r_offset);
633 relas[i].r_info = BYTE_GET (erelas[i].r_info);
634 relas[i].r_addend = BYTE_GET (erelas[i].r_addend);
639 rels = (Elf_Internal_Rel *) relas;
643 Elf64_External_Rela * erelas;
645 GET_DATA_ALLOC (rel_offset, rel_size, erelas,
646 Elf64_External_Rela *, "relocs");
648 rel_size = rel_size / sizeof (Elf64_External_Rela);
650 relas = (Elf_Internal_Rela *)
651 malloc (rel_size * sizeof (Elf_Internal_Rela));
655 error(_("out of memory parsing relocs"));
659 for (i = 0; i < rel_size; i++)
661 relas[i].r_offset = BYTE_GET8 (erelas[i].r_offset);
662 relas[i].r_info = BYTE_GET8 (erelas[i].r_info);
663 relas[i].r_addend = BYTE_GET8 (erelas[i].r_addend);
668 rels = (Elf_Internal_Rel *) relas;
675 Elf32_External_Rel * erels;
677 GET_DATA_ALLOC (rel_offset, rel_size, erels,
678 Elf32_External_Rel *, "relocs");
680 rel_size = rel_size / sizeof (Elf32_External_Rel);
682 rels = (Elf_Internal_Rel *)
683 malloc (rel_size * sizeof (Elf_Internal_Rel));
687 error(_("out of memory parsing relocs"));
691 for (i = 0; i < rel_size; i++)
693 rels[i].r_offset = BYTE_GET (erels[i].r_offset);
694 rels[i].r_info = BYTE_GET (erels[i].r_info);
699 relas = (Elf_Internal_Rela *) rels;
703 Elf64_External_Rel * erels;
705 GET_DATA_ALLOC (rel_offset, rel_size, erels,
706 Elf64_External_Rel *, "relocs");
708 rel_size = rel_size / sizeof (Elf64_External_Rel);
710 rels = (Elf_Internal_Rel *)
711 malloc (rel_size * sizeof (Elf_Internal_Rel));
715 error(_("out of memory parsing relocs"));
719 for (i = 0; i < rel_size; i++)
721 rels[i].r_offset = BYTE_GET8 (erels[i].r_offset);
722 rels[i].r_info = BYTE_GET8 (erels[i].r_info);
727 relas = (Elf_Internal_Rela *) rels;
733 (_(" Offset Info Type Symbol's Value Symbol's Name Addend\n"));
736 (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
738 for (i = 0; i < rel_size; i++)
743 bfd_vma symtab_index;
748 offset = relas [i].r_offset;
749 info = relas [i].r_info;
753 offset = rels [i].r_offset;
754 info = rels [i].r_info;
759 type = ELF32_R_TYPE (info);
760 symtab_index = ELF32_R_SYM (info);
764 if (elf_header.e_machine == EM_SPARCV9)
765 type = ELF64_R_TYPE_ID (info);
767 type = ELF64_R_TYPE (info);
768 /* The #ifdef BFD64 below is to prevent a compile time warning.
769 We know that if we do not have a 64 bit data type that we
770 will never execute this code anyway. */
772 symtab_index = ELF64_R_SYM (info);
776 #ifdef _bfd_int64_low
777 printf (" %8.8lx %5.5lx ", _bfd_int64_low (offset), _bfd_int64_low (info));
779 printf (" %8.8lx %5.5lx ", offset, info);
782 switch (elf_header.e_machine)
789 rtype = elf_m32r_reloc_type (type);
794 rtype = elf_i386_reloc_type (type);
798 rtype = elf_m68k_reloc_type (type);
802 rtype = elf_i960_reloc_type (type);
806 rtype = elf_avr_reloc_type (type);
813 rtype = elf_sparc_reloc_type (type);
817 rtype = v850_reloc_type (type);
821 rtype = elf_d10v_reloc_type (type);
825 rtype = elf_d30v_reloc_type (type);
829 rtype = elf_sh_reloc_type (type);
832 case EM_CYGNUS_MN10300:
833 rtype = elf_mn10300_reloc_type (type);
836 case EM_CYGNUS_MN10200:
837 rtype = elf_mn10200_reloc_type (type);
841 rtype = elf_fr30_reloc_type (type);
845 rtype = elf_mcore_reloc_type (type);
849 rtype = elf_ppc_reloc_type (type);
854 rtype = elf_mips_reloc_type (type);
858 rtype = elf_alpha_reloc_type (type);
862 rtype = elf_arm_reloc_type (type);
866 rtype = elf_arc_reloc_type (type);
870 rtype = elf_hppa_reloc_type (type);
874 rtype = elf_pj_reloc_type (type);
879 #ifdef _bfd_int64_low
880 printf (_("unrecognised: %-7lx"), _bfd_int64_low (type));
882 printf (_("unrecognised: %-7lx"), type);
885 printf ("%-21.21s", rtype);
891 if (symtab_index >= nsyms)
892 printf (" bad symbol index: %08lx", (unsigned long) symtab_index);
895 Elf_Internal_Sym * psym;
897 psym = symtab + symtab_index;
900 print_vma (psym->st_value, LONG_HEX);
903 if (psym->st_name == 0)
905 SECTION_NAME (section_headers + psym->st_shndx));
906 else if (strtab == NULL)
907 printf (_("<string table index %3ld>"), psym->st_name);
909 printf ("%-25.25s", strtab + psym->st_name);
912 printf (" + %lx", (unsigned long) relas [i].r_addend);
918 printf ("%*c", is_32bit_elf ? 34 : 26, ' ');
919 print_vma (relas[i].r_addend, LONG_HEX);
922 if (elf_header.e_machine == EM_SPARCV9
923 && !strcmp (rtype, "R_SPARC_OLO10"))
924 printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (info));
935 get_mips_dynamic_type (type)
940 case DT_MIPS_RLD_VERSION: return "MIPS_RLD_VERSION";
941 case DT_MIPS_TIME_STAMP: return "MIPS_TIME_STAMP";
942 case DT_MIPS_ICHECKSUM: return "MIPS_ICHECKSUM";
943 case DT_MIPS_IVERSION: return "MIPS_IVERSION";
944 case DT_MIPS_FLAGS: return "MIPS_FLAGS";
945 case DT_MIPS_BASE_ADDRESS: return "MIPS_BASE_ADDRESS";
946 case DT_MIPS_MSYM: return "MIPS_MSYM";
947 case DT_MIPS_CONFLICT: return "MIPS_CONFLICT";
948 case DT_MIPS_LIBLIST: return "MIPS_LIBLIST";
949 case DT_MIPS_LOCAL_GOTNO: return "MIPS_LOCAL_GOTNO";
950 case DT_MIPS_CONFLICTNO: return "MIPS_CONFLICTNO";
951 case DT_MIPS_LIBLISTNO: return "MIPS_LIBLISTNO";
952 case DT_MIPS_SYMTABNO: return "MIPS_SYMTABNO";
953 case DT_MIPS_UNREFEXTNO: return "MIPS_UNREFEXTNO";
954 case DT_MIPS_GOTSYM: return "MIPS_GOTSYM";
955 case DT_MIPS_HIPAGENO: return "MIPS_HIPAGENO";
956 case DT_MIPS_RLD_MAP: return "MIPS_RLD_MAP";
957 case DT_MIPS_DELTA_CLASS: return "MIPS_DELTA_CLASS";
958 case DT_MIPS_DELTA_CLASS_NO: return "MIPS_DELTA_CLASS_NO";
959 case DT_MIPS_DELTA_INSTANCE: return "MIPS_DELTA_INSTANCE";
960 case DT_MIPS_DELTA_INSTANCE_NO: return "MIPS_DELTA_INSTANCE_NO";
961 case DT_MIPS_DELTA_RELOC: return "MIPS_DELTA_RELOC";
962 case DT_MIPS_DELTA_RELOC_NO: return "MIPS_DELTA_RELOC_NO";
963 case DT_MIPS_DELTA_SYM: return "MIPS_DELTA_SYM";
964 case DT_MIPS_DELTA_SYM_NO: return "MIPS_DELTA_SYM_NO";
965 case DT_MIPS_DELTA_CLASSSYM: return "MIPS_DELTA_CLASSSYM";
966 case DT_MIPS_DELTA_CLASSSYM_NO: return "MIPS_DELTA_CLASSSYM_NO";
967 case DT_MIPS_CXX_FLAGS: return "MIPS_CXX_FLAGS";
968 case DT_MIPS_PIXIE_INIT: return "MIPS_PIXIE_INIT";
969 case DT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB";
970 case DT_MIPS_LOCALPAGE_GOTIDX: return "MIPS_LOCALPAGE_GOTIDX";
971 case DT_MIPS_LOCAL_GOTIDX: return "MIPS_LOCAL_GOTIDX";
972 case DT_MIPS_HIDDEN_GOTIDX: return "MIPS_HIDDEN_GOTIDX";
973 case DT_MIPS_PROTECTED_GOTIDX: return "MIPS_PROTECTED_GOTIDX";
974 case DT_MIPS_OPTIONS: return "MIPS_OPTIONS";
975 case DT_MIPS_INTERFACE: return "MIPS_INTERFACE";
976 case DT_MIPS_DYNSTR_ALIGN: return "MIPS_DYNSTR_ALIGN";
977 case DT_MIPS_INTERFACE_SIZE: return "MIPS_INTERFACE_SIZE";
978 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
979 case DT_MIPS_PERF_SUFFIX: return "MIPS_PERF_SUFFIX";
980 case DT_MIPS_COMPACT_SIZE: return "MIPS_COMPACT_SIZE";
981 case DT_MIPS_GP_VALUE: return "MIPS_GP_VALUE";
982 case DT_MIPS_AUX_DYNAMIC: return "MIPS_AUX_DYNAMIC";
989 get_sparc64_dynamic_type (type)
994 case DT_SPARC_REGISTER: return "SPARC_REGISTER";
1001 get_parisc_dynamic_type (type)
1006 case DT_HP_LOAD_MAP: return "HP_LOAD_MAP";
1007 case DT_HP_DLD_FLAGS: return "HP_DLD_FLAGS";
1008 case DT_HP_DLD_HOOK: return "HP_DLD_HOOK";
1009 case DT_HP_UX10_INIT: return "HP_UX10_INIT";
1010 case DT_HP_UX10_INITSZ: return "HP_UX10_INITSZ";
1011 case DT_HP_PREINIT: return "HP_PREINIT";
1012 case DT_HP_PREINITSZ: return "HP_PREINITSZ";
1013 case DT_HP_NEEDED: return "HP_NEEDED";
1014 case DT_HP_TIME_STAMP: return "HP_TIME_STAMP";
1015 case DT_HP_CHECKSUM: return "HP_CHECKSUM";
1016 case DT_HP_GST_SIZE: return "HP_GST_SIZE";
1017 case DT_HP_GST_VERSION: return "HP_GST_VERSION";
1018 case DT_HP_GST_HASHVAL: return "HP_GST_HASHVAL";
1025 get_dynamic_type (type)
1028 static char buff [32];
1032 case DT_NULL: return "NULL";
1033 case DT_NEEDED: return "NEEDED";
1034 case DT_PLTRELSZ: return "PLTRELSZ";
1035 case DT_PLTGOT: return "PLTGOT";
1036 case DT_HASH: return "HASH";
1037 case DT_STRTAB: return "STRTAB";
1038 case DT_SYMTAB: return "SYMTAB";
1039 case DT_RELA: return "RELA";
1040 case DT_RELASZ: return "RELASZ";
1041 case DT_RELAENT: return "RELAENT";
1042 case DT_STRSZ: return "STRSZ";
1043 case DT_SYMENT: return "SYMENT";
1044 case DT_INIT: return "INIT";
1045 case DT_FINI: return "FINI";
1046 case DT_SONAME: return "SONAME";
1047 case DT_RPATH: return "RPATH";
1048 case DT_SYMBOLIC: return "SYMBOLIC";
1049 case DT_REL: return "REL";
1050 case DT_RELSZ: return "RELSZ";
1051 case DT_RELENT: return "RELENT";
1052 case DT_PLTREL: return "PLTREL";
1053 case DT_DEBUG: return "DEBUG";
1054 case DT_TEXTREL: return "TEXTREL";
1055 case DT_JMPREL: return "JMPREL";
1056 case DT_BIND_NOW: return "BIND_NOW";
1057 case DT_INIT_ARRAY: return "INIT_ARRAY";
1058 case DT_FINI_ARRAY: return "FINI_ARRAY";
1059 case DT_INIT_ARRAYSZ: return "INIT_ARRAYSZ";
1060 case DT_FINI_ARRAYSZ: return "FINI_ARRAYSZ";
1061 case DT_RUNPATH: return "RUNPATH";
1062 case DT_FLAGS: return "FLAGS";
1064 case DT_PREINIT_ARRAY: return "PREINIT_ARRAY";
1065 case DT_PREINIT_ARRAYSZ: return "PREINIT_ARRAYSZ";
1067 case DT_PLTPADSZ: return "PLTPADSZ";
1068 case DT_MOVEENT: return "MOVEENT";
1069 case DT_MOVESZ: return "MOVESZ";
1070 case DT_FEATURE_1: return "FEATURE_1";
1071 case DT_POSFLAG_1: return "POSFLAG_1";
1072 case DT_SYMINSZ: return "SYMINSZ";
1073 case DT_SYMINENT: return "SYMINENT"; /* aka VALRNGHI */
1075 case DT_ADDRRNGLO: return "ADDRRNGLO";
1076 case DT_SYMINFO: return "SYMINFO"; /* aka ADDRRNGHI */
1078 case DT_VERSYM: return "VERSYM";
1080 case DT_RELACOUNT: return "RELACOUNT";
1081 case DT_RELCOUNT: return "RELCOUNT";
1082 case DT_FLAGS_1: return "FLAGS_1";
1083 case DT_VERDEF: return "VERDEF";
1084 case DT_VERDEFNUM: return "VERDEFNUM";
1085 case DT_VERNEED: return "VERNEED";
1086 case DT_VERNEEDNUM: return "VERNEEDNUM";
1088 case DT_AUXILIARY: return "AUXILARY";
1089 case DT_USED: return "USED";
1090 case DT_FILTER: return "FILTER";
1093 if ((type >= DT_LOPROC) && (type <= DT_HIPROC))
1095 const char * result;
1097 switch (elf_header.e_machine)
1100 case EM_MIPS_RS4_BE:
1101 result = get_mips_dynamic_type (type);
1104 result = get_sparc64_dynamic_type (type);
1114 sprintf (buff, _("Processor Specific: %lx"), type);
1116 else if ((type >= DT_LOOS) && (type <= DT_HIOS))
1118 const char * result;
1120 switch (elf_header.e_machine)
1123 result = get_parisc_dynamic_type (type);
1133 sprintf (buff, _("Operating System specific: %lx"), type);
1136 sprintf (buff, _("<unknown>: %lx"), type);
1143 get_file_type (e_type)
1146 static char buff [32];
1150 case ET_NONE: return _("NONE (None)");
1151 case ET_REL: return _("REL (Relocatable file)");
1152 case ET_EXEC: return _("EXEC (Executable file)");
1153 case ET_DYN: return _("DYN (Shared object file)");
1154 case ET_CORE: return _("CORE (Core file)");
1157 if ((e_type >= ET_LOPROC) && (e_type <= ET_HIPROC))
1158 sprintf (buff, _("Processor Specific: (%x)"), e_type);
1159 else if ((e_type >= ET_LOOS) && (e_type <= ET_HIOS))
1160 sprintf (buff, _("OS Specific: (%x)"), e_type);
1162 sprintf (buff, _("<unknown>: %x"), e_type);
1168 get_machine_name (e_machine)
1171 static char buff [64]; /* XXX */
1175 case EM_NONE: return _("None");
1176 case EM_M32: return "WE32100";
1177 case EM_SPARC: return "Sparc";
1178 case EM_386: return "Intel 80386";
1179 case EM_68K: return "MC68000";
1180 case EM_88K: return "MC88000";
1181 case EM_486: return "Intel 80486";
1182 case EM_860: return "Intel 80860";
1183 case EM_MIPS: return "MIPS R3000";
1184 case EM_S370: return "IBM System/370";
1185 case EM_MIPS_RS4_BE: return "MIPS R4000 big-endian";
1186 case EM_OLD_SPARCV9: return "Sparc v9 (old)";
1187 case EM_PARISC: return "HPPA";
1188 case EM_PPC_OLD: return "Power PC (old)";
1189 case EM_SPARC32PLUS: return "Sparc v8+" ;
1190 case EM_960: return "Intel 90860";
1191 case EM_PPC: return "PowerPC";
1192 case EM_V800: return "NEC V800";
1193 case EM_FR20: return "Fujitsu FR20";
1194 case EM_RH32: return "TRW RH32";
1195 case EM_MCORE: return "MCORE";
1196 case EM_ARM: return "ARM";
1197 case EM_OLD_ALPHA: return "Digital Alpha (old)";
1198 case EM_SH: return "Hitachi SH";
1199 case EM_SPARCV9: return "Sparc v9";
1200 case EM_TRICORE: return "Siemens Tricore";
1201 case EM_ARC: return "Argonaut RISC Core";
1202 case EM_H8_300: return "Hitachi H8/300";
1203 case EM_H8_300H: return "Hitachi H8/300H";
1204 case EM_H8S: return "Hitachi H8S";
1205 case EM_H8_500: return "Hitachi H8/500";
1206 case EM_IA_64: return "Intel IA-64";
1207 case EM_MIPS_X: return "Stanford MIPS-X";
1208 case EM_COLDFIRE: return "Motorola Coldfire";
1209 case EM_68HC12: return "Motorola M68HC12";
1210 case EM_ALPHA: return "Alpha";
1211 case EM_CYGNUS_D10V: return "d10v";
1212 case EM_CYGNUS_D30V: return "d30v";
1213 case EM_CYGNUS_ARC: return "Arc";
1214 case EM_CYGNUS_M32R: return "Mitsubishi M32r";
1215 case EM_CYGNUS_V850: return "NEC v850";
1216 case EM_CYGNUS_MN10300: return "mn10300";
1217 case EM_CYGNUS_MN10200: return "mn10200";
1218 case EM_CYGNUS_FR30: return "Fujitsu FR30";
1219 case EM_PJ: return "picoJava";
1220 case EM_MMA: return "Fujitsu Multimedia Accelerator";
1221 case EM_PCP: return "Siemens PCP";
1222 case EM_NCPU: return "Sony nCPU embedded RISC processor";
1223 case EM_NDR1: return "Denso NDR1 microprocesspr";
1224 case EM_STARCORE: return "Motorola Star*Core processor";
1225 case EM_ME16: return "Toyota ME16 processor";
1226 case EM_ST100: return "STMicroelectronics ST100 processor";
1227 case EM_TINYJ: return "Advanced Logic Corp. TinyJ embedded processor";
1228 case EM_FX66: return "Siemens FX66 microcontroller";
1229 case EM_ST9PLUS: return "STMicroelectronics ST9+ 8/16 bit microcontroller";
1230 case EM_ST7: return "STMicroelectronics ST7 8-bit microcontroller";
1231 case EM_68HC16: return "Motorola MC68HC16 Microcontroller";
1232 case EM_68HC11: return "Motorola MC68HC11 Microcontroller";
1233 case EM_68HC08: return "Motorola MC68HC08 Microcontroller";
1234 case EM_68HC05: return "Motorola MC68HC05 Microcontroller";
1235 case EM_SVX: return "Silicon Graphics SVx";
1236 case EM_ST19: return "STMicroelectronics ST19 8-bit microcontroller";
1237 case EM_VAX: return "Digital VAX";
1238 case EM_AVR: return "AVR";
1240 sprintf (buff, _("<unknown>: %x"), e_machine);
1246 decode_ARM_machine_flags (e_flags, buf)
1253 eabi = EF_ARM_EABI_VERSION (e_flags);
1254 e_flags &= ~ EF_ARM_EABIMASK;
1256 /* Handle "generic" ARM flags. */
1257 if (e_flags & EF_ARM_RELEXEC)
1259 strcat (buf, ", relocatable executable");
1260 e_flags &= ~ EF_ARM_RELEXEC;
1263 if (e_flags & EF_ARM_HASENTRY)
1265 strcat (buf, ", has entry point");
1266 e_flags &= ~ EF_ARM_HASENTRY;
1269 /* Now handle EABI specific flags. */
1273 strcat (buf, ", <unknown EABI>");
1278 case EF_ARM_EABI_VER1:
1283 /* Process flags one bit at a time. */
1284 flag = e_flags & - e_flags;
1289 case EF_ARM_SYMSARESORTED: /* Conflicts with EF_INTERWORK. */
1290 strcat (buf, ", sorted symbol tables");
1300 case EF_ARM_EABI_UNKNOWN:
1305 /* Process flags one bit at a time. */
1306 flag = e_flags & - e_flags;
1312 strcat (buf, ", interworking enabled");
1316 strcat (buf, ", uses APCS/26");
1320 strcat (buf, ", uses APCS/float");
1324 strcat (buf, ", position independent");
1328 strcat (buf, ", 8 bit structure alignment");
1332 strcat (buf, ", uses new ABI");
1336 strcat (buf, ", uses old ABI");
1340 strcat (buf, ", software FP");
1351 strcat (buf,", <unknown>");
1355 get_machine_flags (e_flags, e_machine)
1359 static char buf [1024];
1371 decode_ARM_machine_flags (e_flags, buf);
1375 if (e_flags & EF_CPU32)
1376 strcat (buf, ", cpu32");
1380 if (e_flags & EF_PPC_EMB)
1381 strcat (buf, ", emb");
1383 if (e_flags & EF_PPC_RELOCATABLE)
1384 strcat (buf, ", relocatable");
1386 if (e_flags & EF_PPC_RELOCATABLE_LIB)
1387 strcat (buf, ", relocatable-lib");
1390 case EM_CYGNUS_V850:
1391 switch (e_flags & EF_V850_ARCH)
1394 strcat (buf, ", v850e");
1397 strcat (buf, ", v850ea");
1400 strcat (buf, ", v850");
1403 strcat (buf, ", unknown v850 architecture variant");
1408 case EM_CYGNUS_M32R:
1409 if ((e_flags & EF_M32R_ARCH) == E_M32R_ARCH)
1410 strcat (buf, ", m32r");
1415 case EM_MIPS_RS4_BE:
1416 if (e_flags & EF_MIPS_NOREORDER)
1417 strcat (buf, ", noreorder");
1419 if (e_flags & EF_MIPS_PIC)
1420 strcat (buf, ", pic");
1422 if (e_flags & EF_MIPS_CPIC)
1423 strcat (buf, ", cpic");
1425 if (e_flags & EF_MIPS_ABI2)
1426 strcat (buf, ", abi2");
1428 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_1)
1429 strcat (buf, ", mips1");
1431 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_2)
1432 strcat (buf, ", mips2");
1434 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_3)
1435 strcat (buf, ", mips3");
1437 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_4)
1438 strcat (buf, ", mips4");
1442 if (e_flags & EF_SPARC_32PLUS)
1443 strcat (buf, ", v8+");
1445 if (e_flags & EF_SPARC_SUN_US1)
1446 strcat (buf, ", ultrasparcI");
1448 if (e_flags & EF_SPARC_SUN_US3)
1449 strcat (buf, ", ultrasparcIII");
1451 if (e_flags & EF_SPARC_HAL_R1)
1452 strcat (buf, ", halr1");
1454 if (e_flags & EF_SPARC_LEDATA)
1455 strcat (buf, ", ledata");
1457 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_TSO)
1458 strcat (buf, ", tso");
1460 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_PSO)
1461 strcat (buf, ", pso");
1463 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_RMO)
1464 strcat (buf, ", rmo");
1468 switch (e_flags & EF_PARISC_ARCH)
1470 case EFA_PARISC_1_0:
1471 strcpy (buf, ", PA-RISC 1.0");
1473 case EFA_PARISC_1_1:
1474 strcpy (buf, ", PA-RISC 1.1");
1476 case EFA_PARISC_2_0:
1477 strcpy (buf, ", PA-RISC 2.0");
1482 if (e_flags & EF_PARISC_TRAPNIL)
1483 strcat (buf, ", trapnil");
1484 if (e_flags & EF_PARISC_EXT)
1485 strcat (buf, ", ext");
1486 if (e_flags & EF_PARISC_LSB)
1487 strcat (buf, ", lsb");
1488 if (e_flags & EF_PARISC_WIDE)
1489 strcat (buf, ", wide");
1490 if (e_flags & EF_PARISC_NO_KABP)
1491 strcat (buf, ", no kabp");
1492 if (e_flags & EF_PARISC_LAZYSWAP)
1493 strcat (buf, ", lazyswap");
1497 if ((e_flags & EF_PICOJAVA_NEWCALLS) == EF_PICOJAVA_NEWCALLS)
1498 strcat (buf, ", new calling convention");
1500 if ((e_flags & EF_PICOJAVA_GNUCALLS) == EF_PICOJAVA_GNUCALLS)
1501 strcat (buf, ", gnu calling convention");
1510 get_mips_segment_type (type)
1515 case PT_MIPS_REGINFO:
1517 case PT_MIPS_RTPROC:
1519 case PT_MIPS_OPTIONS:
1529 get_parisc_segment_type (type)
1534 case PT_HP_TLS: return "HP_TLS";
1535 case PT_HP_CORE_NONE: return "HP_CORE_NONE";
1536 case PT_HP_CORE_VERSION: return "HP_CORE_VERSION";
1537 case PT_HP_CORE_KERNEL: return "HP_CORE_KERNEL";
1538 case PT_HP_CORE_COMM: return "HP_CORE_COMM";
1539 case PT_HP_CORE_PROC: return "HP_CORE_PROC";
1540 case PT_HP_CORE_LOADABLE: return "HP_CORE_LOADABLE";
1541 case PT_HP_CORE_STACK: return "HP_CORE_STACK";
1542 case PT_HP_CORE_SHM: return "HP_CORE_SHM";
1543 case PT_HP_CORE_MMF: return "HP_CORE_MMF";
1544 case PT_HP_PARALLEL: return "HP_PARALLEL";
1545 case PT_HP_FASTBIND: return "HP_FASTBIND";
1546 case PT_PARISC_ARCHEXT: return "PARISC_ARCHEXT";
1547 case PT_PARISC_UNWIND: return "PARISC_UNWIND";
1556 get_segment_type (p_type)
1557 unsigned long p_type;
1559 static char buff [32];
1563 case PT_NULL: return "NULL";
1564 case PT_LOAD: return "LOAD";
1565 case PT_DYNAMIC: return "DYNAMIC";
1566 case PT_INTERP: return "INTERP";
1567 case PT_NOTE: return "NOTE";
1568 case PT_SHLIB: return "SHLIB";
1569 case PT_PHDR: return "PHDR";
1572 if ((p_type >= PT_LOPROC) && (p_type <= PT_HIPROC))
1574 const char * result;
1576 switch (elf_header.e_machine)
1579 case EM_MIPS_RS4_BE:
1580 result = get_mips_segment_type (p_type);
1583 result = get_parisc_segment_type (p_type);
1593 sprintf (buff, "LOPROC+%lx", p_type - PT_LOPROC);
1595 else if ((p_type >= PT_LOOS) && (p_type <= PT_HIOS))
1597 const char * result;
1599 switch (elf_header.e_machine)
1602 result = get_parisc_segment_type (p_type);
1612 sprintf (buff, "LOOS+%lx", p_type - PT_LOOS);
1615 sprintf (buff, _("<unknown>: %lx"), p_type);
1622 get_mips_section_type_name (sh_type)
1623 unsigned int sh_type;
1627 case SHT_MIPS_LIBLIST: return "MIPS_LIBLIST";
1628 case SHT_MIPS_MSYM: return "MIPS_MSYM";
1629 case SHT_MIPS_CONFLICT: return "MIPS_CONFLICT";
1630 case SHT_MIPS_GPTAB: return "MIPS_GPTAB";
1631 case SHT_MIPS_UCODE: return "MIPS_UCODE";
1632 case SHT_MIPS_DEBUG: return "MIPS_DEBUG";
1633 case SHT_MIPS_REGINFO: return "MIPS_REGINFO";
1634 case SHT_MIPS_PACKAGE: return "MIPS_PACKAGE";
1635 case SHT_MIPS_PACKSYM: return "MIPS_PACKSYM";
1636 case SHT_MIPS_RELD: return "MIPS_RELD";
1637 case SHT_MIPS_IFACE: return "MIPS_IFACE";
1638 case SHT_MIPS_CONTENT: return "MIPS_CONTENT";
1639 case SHT_MIPS_OPTIONS: return "MIPS_OPTIONS";
1640 case SHT_MIPS_SHDR: return "MIPS_SHDR";
1641 case SHT_MIPS_FDESC: return "MIPS_FDESC";
1642 case SHT_MIPS_EXTSYM: return "MIPS_EXTSYM";
1643 case SHT_MIPS_DENSE: return "MIPS_DENSE";
1644 case SHT_MIPS_PDESC: return "MIPS_PDESC";
1645 case SHT_MIPS_LOCSYM: return "MIPS_LOCSYM";
1646 case SHT_MIPS_AUXSYM: return "MIPS_AUXSYM";
1647 case SHT_MIPS_OPTSYM: return "MIPS_OPTSYM";
1648 case SHT_MIPS_LOCSTR: return "MIPS_LOCSTR";
1649 case SHT_MIPS_LINE: return "MIPS_LINE";
1650 case SHT_MIPS_RFDESC: return "MIPS_RFDESC";
1651 case SHT_MIPS_DELTASYM: return "MIPS_DELTASYM";
1652 case SHT_MIPS_DELTAINST: return "MIPS_DELTAINST";
1653 case SHT_MIPS_DELTACLASS: return "MIPS_DELTACLASS";
1654 case SHT_MIPS_DWARF: return "MIPS_DWARF";
1655 case SHT_MIPS_DELTADECL: return "MIPS_DELTADECL";
1656 case SHT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB";
1657 case SHT_MIPS_EVENTS: return "MIPS_EVENTS";
1658 case SHT_MIPS_TRANSLATE: return "MIPS_TRANSLATE";
1659 case SHT_MIPS_PIXIE: return "MIPS_PIXIE";
1660 case SHT_MIPS_XLATE: return "MIPS_XLATE";
1661 case SHT_MIPS_XLATE_DEBUG: return "MIPS_XLATE_DEBUG";
1662 case SHT_MIPS_WHIRL: return "MIPS_WHIRL";
1663 case SHT_MIPS_EH_REGION: return "MIPS_EH_REGION";
1664 case SHT_MIPS_XLATE_OLD: return "MIPS_XLATE_OLD";
1665 case SHT_MIPS_PDR_EXCEPTION: return "MIPS_PDR_EXCEPTION";
1673 get_parisc_section_type_name (sh_type)
1674 unsigned int sh_type;
1678 case SHT_PARISC_EXT: return "PARISC_EXT";
1679 case SHT_PARISC_UNWIND: return "PARISC_UNWIND";
1680 case SHT_PARISC_DOC: return "PARISC_DOC";
1688 get_section_type_name (sh_type)
1689 unsigned int sh_type;
1691 static char buff [32];
1695 case SHT_NULL: return "NULL";
1696 case SHT_PROGBITS: return "PROGBITS";
1697 case SHT_SYMTAB: return "SYMTAB";
1698 case SHT_STRTAB: return "STRTAB";
1699 case SHT_RELA: return "RELA";
1700 case SHT_HASH: return "HASH";
1701 case SHT_DYNAMIC: return "DYNAMIC";
1702 case SHT_NOTE: return "NOTE";
1703 case SHT_NOBITS: return "NOBITS";
1704 case SHT_REL: return "REL";
1705 case SHT_SHLIB: return "SHLIB";
1706 case SHT_DYNSYM: return "DYNSYM";
1707 case SHT_INIT_ARRAY: return "INIT_ARRAY";
1708 case SHT_FINI_ARRAY: return "FINI_ARRAY";
1709 case SHT_PREINIT_ARRAY: return "PREINIT_ARRAY";
1710 case SHT_GNU_verdef: return "VERDEF";
1711 case SHT_GNU_verneed: return "VERNEED";
1712 case SHT_GNU_versym: return "VERSYM";
1713 case 0x6ffffff0: return "VERSYM";
1714 case 0x6ffffffc: return "VERDEF";
1715 case 0x7ffffffd: return "AUXILIARY";
1716 case 0x7fffffff: return "FILTER";
1719 if ((sh_type >= SHT_LOPROC) && (sh_type <= SHT_HIPROC))
1721 const char * result;
1723 switch (elf_header.e_machine)
1726 case EM_MIPS_RS4_BE:
1727 result = get_mips_section_type_name (sh_type);
1730 result = get_parisc_section_type_name (sh_type);
1740 sprintf (buff, "SHT_LOPROC+%x", sh_type - SHT_LOPROC);
1742 else if ((sh_type >= SHT_LOOS) && (sh_type <= SHT_HIOS))
1743 sprintf (buff, "SHT_LOOS+%x", sh_type - SHT_LOOS);
1744 else if ((sh_type >= SHT_LOUSER) && (sh_type <= SHT_HIUSER))
1745 sprintf (buff, "SHT_LOUSER+%x", sh_type - SHT_LOUSER);
1747 sprintf (buff, _("<unknown>: %x"), sh_type);
1753 struct option options [] =
1755 {"all", no_argument, 0, 'a'},
1756 {"file-header", no_argument, 0, 'h'},
1757 {"program-headers", no_argument, 0, 'l'},
1758 {"headers", no_argument, 0, 'e'},
1759 {"histogram", no_argument, 0, 'I'},
1760 {"segments", no_argument, 0, 'l'},
1761 {"sections", no_argument, 0, 'S'},
1762 {"section-headers", no_argument, 0, 'S'},
1763 {"symbols", no_argument, 0, 's'},
1764 {"syms", no_argument, 0, 's'},
1765 {"relocs", no_argument, 0, 'r'},
1766 {"notes", no_argument, 0, 'n'},
1767 {"dynamic", no_argument, 0, 'd'},
1768 {"arch-specific", no_argument, 0, 'A'},
1769 {"version-info", no_argument, 0, 'V'},
1770 {"use-dynamic", no_argument, 0, 'D'},
1771 {"hex-dump", required_argument, 0, 'x'},
1772 {"debug-dump", optional_argument, 0, 'w'},
1773 #ifdef SUPPORT_DISASSEMBLY
1774 {"instruction-dump", required_argument, 0, 'i'},
1777 {"version", no_argument, 0, 'v'},
1778 {"help", no_argument, 0, 'H'},
1779 {0, no_argument, 0, 0}
1785 fprintf (stdout, _("Usage: readelf {options} elf-file(s)\n"));
1786 fprintf (stdout, _(" Options are:\n"));
1787 fprintf (stdout, _(" -a or --all Equivalent to: -h -l -S -s -r -d -V -A -I\n"));
1788 fprintf (stdout, _(" -h or --file-header Display the ELF file header\n"));
1789 fprintf (stdout, _(" -l or --program-headers or --segments\n"));
1790 fprintf (stdout, _(" Display the program headers\n"));
1791 fprintf (stdout, _(" -S or --section-headers or --sections\n"));
1792 fprintf (stdout, _(" Display the sections' header\n"));
1793 fprintf (stdout, _(" -e or --headers Equivalent to: -h -l -S\n"));
1794 fprintf (stdout, _(" -s or --syms or --symbols Display the symbol table\n"));
1795 fprintf (stdout, _(" -n or --notes Display the core notes (if present)\n"));
1796 fprintf (stdout, _(" -r or --relocs Display the relocations (if present)\n"));
1797 fprintf (stdout, _(" -d or --dynamic Display the dynamic segment (if present)\n"));
1798 fprintf (stdout, _(" -V or --version-info Display the version sections (if present)\n"));
1799 fprintf (stdout, _(" -A or --arch-specific Display architecture specific information (if any).\n"));
1800 fprintf (stdout, _(" -D or --use-dynamic Use the dynamic section info when displaying symbols\n"));
1801 fprintf (stdout, _(" -x <number> or --hex-dump=<number>\n"));
1802 fprintf (stdout, _(" Dump the contents of section <number>\n"));
1803 fprintf (stdout, _(" -w[liapr] or --debug-dump[=line,=info,=abbrev,=pubnames,=ranges]\n"));
1804 fprintf (stdout, _(" Display the contents of DWARF2 debug sections\n"));
1805 #ifdef SUPPORT_DISASSEMBLY
1806 fprintf (stdout, _(" -i <number> or --instruction-dump=<number>\n"));
1807 fprintf (stdout, _(" Disassemble the contents of section <number>\n"));
1809 fprintf (stdout, _(" -I or --histogram Display histogram of bucket list lengths\n"));
1810 fprintf (stdout, _(" -v or --version Display the version number of readelf\n"));
1811 fprintf (stdout, _(" -H or --help Display this information\n"));
1812 fprintf (stdout, _("Report bugs to %s\n"), REPORT_BUGS_TO);
1818 request_dump (section, type)
1819 unsigned int section;
1822 if (section >= num_dump_sects)
1824 char * new_dump_sects;
1826 new_dump_sects = (char *) calloc (section + 1, 1);
1828 if (new_dump_sects == NULL)
1829 error (_("Out of memory allocating dump request table."));
1832 /* Copy current flag settings. */
1833 memcpy (new_dump_sects, dump_sects, num_dump_sects);
1837 dump_sects = new_dump_sects;
1838 num_dump_sects = section + 1;
1843 dump_sects [section] |= type;
1849 parse_args (argc, argv)
1858 while ((c = getopt_long
1859 (argc, argv, "ersahnldSDAIw::x:i:vV", options, NULL)) != EOF)
1894 do_using_dynamic ++;
1922 section = strtoul (optarg, & cp, 0);
1923 if (! * cp && section >= 0)
1925 request_dump (section, HEX_DUMP);
1945 do_debug_abbrevs = 1;
1955 do_debug_pubnames = 1;
1960 do_debug_aranges = 1;
1964 warn (_("Unrecognised debug option '%s'\n"), optarg);
1969 #ifdef SUPPORT_DISASSEMBLY
1972 section = strtoul (optarg, & cp, 0);
1973 if (! * cp && section >= 0)
1975 request_dump (section, DISASS_DUMP);
1981 print_version (program_name);
1988 /* xgettext:c-format */
1989 error (_("Invalid option '-%c'\n"), c);
1996 if (!do_dynamic && !do_syms && !do_reloc && !do_sections
1997 && !do_segments && !do_header && !do_dump && !do_version
1998 && !do_histogram && !do_debugging && !do_arch && !do_notes)
2002 warn (_("Nothing to do.\n"));
2008 get_elf_class (elf_class)
2009 unsigned char elf_class;
2011 static char buff [32];
2015 case ELFCLASSNONE: return _("none");
2016 case ELFCLASS32: return _("ELF32");
2017 case ELFCLASS64: return _("ELF64");
2019 sprintf (buff, _("<unknown: %x>"), elf_class);
2025 get_data_encoding (encoding)
2026 unsigned char encoding;
2028 static char buff [32];
2032 case ELFDATANONE: return _("none");
2033 case ELFDATA2LSB: return _("2's complement, little endian");
2034 case ELFDATA2MSB: return _("2's complement, big endian");
2036 sprintf (buff, _("<unknown: %x>"), encoding);
2042 get_osabi_name (osabi)
2043 unsigned char osabi;
2045 static char buff [32];
2049 case ELFOSABI_SYSV: return _("UNIX - System V");
2050 case ELFOSABI_HPUX: return _("UNIX - HP-UX");
2051 case ELFOSABI_LINUX: return _("UNIX - Linux");
2052 case ELFOSABI_STANDALONE: return _("Standalone App");
2053 case ELFOSABI_ARM: return _("ARM");
2055 sprintf (buff, _("<unknown: %x>"), osabi);
2060 /* Decode the data held in 'elf_header'. */
2062 process_file_header ()
2064 if ( elf_header.e_ident [EI_MAG0] != ELFMAG0
2065 || elf_header.e_ident [EI_MAG1] != ELFMAG1
2066 || elf_header.e_ident [EI_MAG2] != ELFMAG2
2067 || elf_header.e_ident [EI_MAG3] != ELFMAG3)
2070 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
2078 printf (_("ELF Header:\n"));
2079 printf (_(" Magic: "));
2080 for (i = 0; i < EI_NIDENT; i ++)
2081 printf ("%2.2x ", elf_header.e_ident [i]);
2083 printf (_(" Class: %s\n"),
2084 get_elf_class (elf_header.e_ident [EI_CLASS]));
2085 printf (_(" Data: %s\n"),
2086 get_data_encoding (elf_header.e_ident [EI_DATA]));
2087 printf (_(" Version: %d %s\n"),
2088 elf_header.e_ident [EI_VERSION],
2089 (elf_header.e_ident [EI_VERSION] == EV_CURRENT
2091 : (elf_header.e_ident [EI_VERSION] != EV_NONE
2094 printf (_(" OS/ABI: %s\n"),
2095 get_osabi_name (elf_header.e_ident [EI_OSABI]));
2096 printf (_(" ABI Version: %d\n"),
2097 elf_header.e_ident [EI_ABIVERSION]);
2098 printf (_(" Type: %s\n"),
2099 get_file_type (elf_header.e_type));
2100 printf (_(" Machine: %s\n"),
2101 get_machine_name (elf_header.e_machine));
2102 printf (_(" Version: 0x%lx\n"),
2103 (unsigned long) elf_header.e_version);
2105 printf (_(" Entry point address: "));
2106 print_vma ((bfd_vma) elf_header.e_entry, PREFIX_HEX);
2107 printf (_("\n Start of program headers: "));
2108 print_vma ((bfd_vma) elf_header.e_phoff, DEC);
2109 printf (_(" (bytes into file)\n Start of section headers: "));
2110 print_vma ((bfd_vma) elf_header.e_shoff, DEC);
2111 printf (_(" (bytes into file)\n"));
2113 printf (_(" Flags: 0x%lx%s\n"),
2114 (unsigned long) elf_header.e_flags,
2115 get_machine_flags (elf_header.e_flags, elf_header.e_machine));
2116 printf (_(" Size of this header: %ld (bytes)\n"),
2117 (long) elf_header.e_ehsize);
2118 printf (_(" Size of program headers: %ld (bytes)\n"),
2119 (long) elf_header.e_phentsize);
2120 printf (_(" Number of program headers: %ld\n"),
2121 (long) elf_header.e_phnum);
2122 printf (_(" Size of section headers: %ld (bytes)\n"),
2123 (long) elf_header.e_shentsize);
2124 printf (_(" Number of section headers: %ld\n"),
2125 (long) elf_header.e_shnum);
2126 printf (_(" Section header string table index: %ld\n"),
2127 (long) elf_header.e_shstrndx);
2135 get_32bit_program_headers (file, program_headers)
2137 Elf_Internal_Phdr * program_headers;
2139 Elf32_External_Phdr * phdrs;
2140 Elf32_External_Phdr * external;
2141 Elf32_Internal_Phdr * internal;
2144 GET_DATA_ALLOC (elf_header.e_phoff,
2145 elf_header.e_phentsize * elf_header.e_phnum,
2146 phdrs, Elf32_External_Phdr *, "program headers");
2148 for (i = 0, internal = program_headers, external = phdrs;
2149 i < elf_header.e_phnum;
2150 i ++, internal ++, external ++)
2152 internal->p_type = BYTE_GET (external->p_type);
2153 internal->p_offset = BYTE_GET (external->p_offset);
2154 internal->p_vaddr = BYTE_GET (external->p_vaddr);
2155 internal->p_paddr = BYTE_GET (external->p_paddr);
2156 internal->p_filesz = BYTE_GET (external->p_filesz);
2157 internal->p_memsz = BYTE_GET (external->p_memsz);
2158 internal->p_flags = BYTE_GET (external->p_flags);
2159 internal->p_align = BYTE_GET (external->p_align);
2168 get_64bit_program_headers (file, program_headers)
2170 Elf_Internal_Phdr * program_headers;
2172 Elf64_External_Phdr * phdrs;
2173 Elf64_External_Phdr * external;
2174 Elf64_Internal_Phdr * internal;
2177 GET_DATA_ALLOC (elf_header.e_phoff,
2178 elf_header.e_phentsize * elf_header.e_phnum,
2179 phdrs, Elf64_External_Phdr *, "program headers");
2181 for (i = 0, internal = program_headers, external = phdrs;
2182 i < elf_header.e_phnum;
2183 i ++, internal ++, external ++)
2185 internal->p_type = BYTE_GET (external->p_type);
2186 internal->p_flags = BYTE_GET (external->p_flags);
2187 internal->p_offset = BYTE_GET8 (external->p_offset);
2188 internal->p_vaddr = BYTE_GET8 (external->p_vaddr);
2189 internal->p_paddr = BYTE_GET8 (external->p_paddr);
2190 internal->p_filesz = BYTE_GET8 (external->p_filesz);
2191 internal->p_memsz = BYTE_GET8 (external->p_memsz);
2192 internal->p_align = BYTE_GET8 (external->p_align);
2201 process_program_headers (file)
2204 Elf_Internal_Phdr * program_headers;
2205 Elf_Internal_Phdr * segment;
2208 if (elf_header.e_phnum == 0)
2211 printf (_("\nThere are no program headers in this file.\n"));
2215 if (do_segments && !do_header)
2217 printf (_("\nElf file type is %s\n"), get_file_type (elf_header.e_type));
2218 printf (_("Entry point "));
2219 print_vma ((bfd_vma) elf_header.e_entry, PREFIX_HEX);
2220 printf (_("\nThere are %d program headers, starting at offset "),
2221 elf_header.e_phnum);
2222 print_vma ((bfd_vma) elf_header.e_phoff, DEC);
2226 program_headers = (Elf_Internal_Phdr *) malloc
2227 (elf_header.e_phnum * sizeof (Elf_Internal_Phdr));
2229 if (program_headers == NULL)
2231 error (_("Out of memory\n"));
2236 i = get_32bit_program_headers (file, program_headers);
2238 i = get_64bit_program_headers (file, program_headers);
2242 free (program_headers);
2249 (_("\nProgram Header%s:\n"), elf_header.e_phnum > 1 ? "s" : "");
2253 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
2257 (_(" Type Offset VirtAddr PhysAddr\n"));
2259 (_(" FileSiz MemSiz Flags Align\n"));
2267 for (i = 0, segment = program_headers;
2268 i < elf_header.e_phnum;
2273 printf (" %-14.14s ", get_segment_type (segment->p_type));
2277 printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
2278 printf ("0x%8.8lx ", (unsigned long) segment->p_vaddr);
2279 printf ("0x%8.8lx ", (unsigned long) segment->p_paddr);
2280 printf ("0x%5.5lx ", (unsigned long) segment->p_filesz);
2281 printf ("0x%5.5lx ", (unsigned long) segment->p_memsz);
2283 (segment->p_flags & PF_R ? 'R' : ' '),
2284 (segment->p_flags & PF_W ? 'W' : ' '),
2285 (segment->p_flags & PF_X ? 'E' : ' '));
2286 printf ("%#lx", (unsigned long) segment->p_align);
2290 print_vma (segment->p_offset, FULL_HEX);
2292 print_vma (segment->p_vaddr, FULL_HEX);
2294 print_vma (segment->p_paddr, FULL_HEX);
2296 print_vma (segment->p_filesz, FULL_HEX);
2298 print_vma (segment->p_memsz, FULL_HEX);
2300 (segment->p_flags & PF_R ? 'R' : ' '),
2301 (segment->p_flags & PF_W ? 'W' : ' '),
2302 (segment->p_flags & PF_X ? 'E' : ' '));
2303 print_vma (segment->p_align, HEX);
2307 switch (segment->p_type)
2311 loadaddr = (segment->p_vaddr & 0xfffff000)
2312 - (segment->p_offset & 0xfffff000);
2317 error (_("more than one dynamic segment\n"));
2319 dynamic_addr = segment->p_offset;
2320 dynamic_size = segment->p_filesz;
2324 if (fseek (file, (long) segment->p_offset, SEEK_SET))
2325 error (_("Unable to find program interpreter name\n"));
2328 program_interpreter[0] = 0;
2329 fscanf (file, "%63s", program_interpreter);
2332 printf (_("\n [Requesting program interpreter: %s]"),
2333 program_interpreter);
2339 putc ('\n', stdout);
2348 if (do_segments && section_headers != NULL)
2350 printf (_("\n Section to Segment mapping:\n"));
2351 printf (_(" Segment Sections...\n"));
2353 assert (string_table != NULL);
2355 for (i = 0; i < elf_header.e_phnum; i++)
2358 Elf_Internal_Shdr * section;
2360 segment = program_headers + i;
2361 section = section_headers;
2363 printf (" %2.2d ", i);
2365 for (j = 0; j < elf_header.e_shnum; j++, section ++)
2367 if (section->sh_size > 0
2368 /* Compare allocated sections by VMA, unallocated
2369 sections by file offset. */
2370 && (section->sh_flags & SHF_ALLOC
2371 ? (section->sh_addr >= segment->p_vaddr
2372 && section->sh_addr + section->sh_size
2373 <= segment->p_vaddr + segment->p_memsz)
2374 : ((bfd_vma) section->sh_offset >= segment->p_offset
2375 && (section->sh_offset + section->sh_size
2376 <= segment->p_offset + segment->p_filesz))))
2377 printf ("%s ", SECTION_NAME (section));
2384 free (program_headers);
2391 get_32bit_section_headers (file)
2394 Elf32_External_Shdr * shdrs;
2395 Elf32_Internal_Shdr * internal;
2398 GET_DATA_ALLOC (elf_header.e_shoff,
2399 elf_header.e_shentsize * elf_header.e_shnum,
2400 shdrs, Elf32_External_Shdr *, "section headers");
2402 section_headers = (Elf_Internal_Shdr *) malloc
2403 (elf_header.e_shnum * sizeof (Elf_Internal_Shdr));
2405 if (section_headers == NULL)
2407 error (_("Out of memory\n"));
2411 for (i = 0, internal = section_headers;
2412 i < elf_header.e_shnum;
2415 internal->sh_name = BYTE_GET (shdrs[i].sh_name);
2416 internal->sh_type = BYTE_GET (shdrs[i].sh_type);
2417 internal->sh_flags = BYTE_GET (shdrs[i].sh_flags);
2418 internal->sh_addr = BYTE_GET (shdrs[i].sh_addr);
2419 internal->sh_offset = BYTE_GET (shdrs[i].sh_offset);
2420 internal->sh_size = BYTE_GET (shdrs[i].sh_size);
2421 internal->sh_link = BYTE_GET (shdrs[i].sh_link);
2422 internal->sh_info = BYTE_GET (shdrs[i].sh_info);
2423 internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
2424 internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize);
2433 get_64bit_section_headers (file)
2436 Elf64_External_Shdr * shdrs;
2437 Elf64_Internal_Shdr * internal;
2440 GET_DATA_ALLOC (elf_header.e_shoff,
2441 elf_header.e_shentsize * elf_header.e_shnum,
2442 shdrs, Elf64_External_Shdr *, "section headers");
2444 section_headers = (Elf_Internal_Shdr *) malloc
2445 (elf_header.e_shnum * sizeof (Elf_Internal_Shdr));
2447 if (section_headers == NULL)
2449 error (_("Out of memory\n"));
2453 for (i = 0, internal = section_headers;
2454 i < elf_header.e_shnum;
2457 internal->sh_name = BYTE_GET (shdrs[i].sh_name);
2458 internal->sh_type = BYTE_GET (shdrs[i].sh_type);
2459 internal->sh_flags = BYTE_GET8 (shdrs[i].sh_flags);
2460 internal->sh_addr = BYTE_GET8 (shdrs[i].sh_addr);
2461 internal->sh_size = BYTE_GET8 (shdrs[i].sh_size);
2462 internal->sh_entsize = BYTE_GET8 (shdrs[i].sh_entsize);
2463 internal->sh_link = BYTE_GET (shdrs[i].sh_link);
2464 internal->sh_info = BYTE_GET (shdrs[i].sh_info);
2465 internal->sh_offset = BYTE_GET (shdrs[i].sh_offset);
2466 internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
2474 static Elf_Internal_Sym *
2475 get_32bit_elf_symbols (file, offset, number)
2477 unsigned long offset;
2478 unsigned long number;
2480 Elf32_External_Sym * esyms;
2481 Elf_Internal_Sym * isyms;
2482 Elf_Internal_Sym * psym;
2485 GET_DATA_ALLOC (offset, number * sizeof (Elf32_External_Sym),
2486 esyms, Elf32_External_Sym *, "symbols");
2488 isyms = (Elf_Internal_Sym *) malloc (number * sizeof (Elf_Internal_Sym));
2492 error (_("Out of memory\n"));
2498 for (j = 0, psym = isyms;
2502 psym->st_name = BYTE_GET (esyms[j].st_name);
2503 psym->st_value = BYTE_GET (esyms[j].st_value);
2504 psym->st_size = BYTE_GET (esyms[j].st_size);
2505 psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
2506 psym->st_info = BYTE_GET (esyms[j].st_info);
2507 psym->st_other = BYTE_GET (esyms[j].st_other);
2515 static Elf_Internal_Sym *
2516 get_64bit_elf_symbols (file, offset, number)
2518 unsigned long offset;
2519 unsigned long number;
2521 Elf64_External_Sym * esyms;
2522 Elf_Internal_Sym * isyms;
2523 Elf_Internal_Sym * psym;
2526 GET_DATA_ALLOC (offset, number * sizeof (Elf64_External_Sym),
2527 esyms, Elf64_External_Sym *, "symbols");
2529 isyms = (Elf_Internal_Sym *) malloc (number * sizeof (Elf_Internal_Sym));
2533 error (_("Out of memory\n"));
2539 for (j = 0, psym = isyms;
2543 psym->st_name = BYTE_GET (esyms[j].st_name);
2544 psym->st_info = BYTE_GET (esyms[j].st_info);
2545 psym->st_other = BYTE_GET (esyms[j].st_other);
2546 psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
2547 psym->st_value = BYTE_GET8 (esyms[j].st_value);
2548 psym->st_size = BYTE_GET8 (esyms[j].st_size);
2557 get_elf_section_flags (sh_flags)
2560 static char buff [32];
2568 flag = sh_flags & - sh_flags;
2573 case SHF_WRITE: strcat (buff, "W"); break;
2574 case SHF_ALLOC: strcat (buff, "A"); break;
2575 case SHF_EXECINSTR: strcat (buff, "X"); break;
2576 case SHF_MERGE: strcat (buff, "M"); break;
2577 case SHF_STRINGS: strcat (buff, "S"); break;
2578 case SHF_INFO_LINK: strcat (buff, "I"); break;
2579 case SHF_LINK_ORDER: strcat (buff, "L"); break;
2580 case SHF_OS_NONCONFORMING: strcat (buff, "O"); break;
2583 if (flag & SHF_MASKOS)
2586 sh_flags &= ~ SHF_MASKOS;
2588 else if (flag & SHF_MASKPROC)
2591 sh_flags &= ~ SHF_MASKPROC;
2603 process_section_headers (file)
2606 Elf_Internal_Shdr * section;
2609 section_headers = NULL;
2611 if (elf_header.e_shnum == 0)
2614 printf (_("\nThere are no sections in this file.\n"));
2619 if (do_sections && !do_header)
2620 printf (_("There are %d section headers, starting at offset 0x%lx:\n"),
2621 elf_header.e_shnum, (unsigned long) elf_header.e_shoff);
2625 if (! get_32bit_section_headers (file))
2628 else if (! get_64bit_section_headers (file))
2631 /* Read in the string table, so that we have names to display. */
2632 section = section_headers + elf_header.e_shstrndx;
2634 if (section->sh_size != 0)
2636 unsigned long string_table_offset;
2638 string_table_offset = section->sh_offset;
2640 GET_DATA_ALLOC (section->sh_offset, section->sh_size,
2641 string_table, char *, "string table");
2644 /* Scan the sections for the dynamic symbol table
2645 and dynamic string table and debug sections. */
2646 dynamic_symbols = NULL;
2647 dynamic_strings = NULL;
2648 dynamic_syminfo = NULL;
2650 for (i = 0, section = section_headers;
2651 i < elf_header.e_shnum;
2654 char * name = SECTION_NAME (section);
2656 if (section->sh_type == SHT_DYNSYM)
2658 if (dynamic_symbols != NULL)
2660 error (_("File contains multiple dynamic symbol tables\n"));
2664 num_dynamic_syms = section->sh_size / section->sh_entsize;
2666 GET_ELF_SYMBOLS (file, section->sh_offset, num_dynamic_syms);
2668 else if (section->sh_type == SHT_STRTAB
2669 && strcmp (name, ".dynstr") == 0)
2671 if (dynamic_strings != NULL)
2673 error (_("File contains multiple dynamic string tables\n"));
2677 GET_DATA_ALLOC (section->sh_offset, section->sh_size,
2678 dynamic_strings, char *, "dynamic strings");
2680 else if ((do_debugging || do_debug_info || do_debug_abbrevs
2681 || do_debug_lines || do_debug_pubnames || do_debug_aranges)
2682 && strncmp (name, ".debug_", 7) == 0)
2687 || (do_debug_info && (strcmp (name, "info") == 0))
2688 || (do_debug_abbrevs && (strcmp (name, "abbrev") == 0))
2689 || (do_debug_lines && (strcmp (name, "line") == 0))
2690 || (do_debug_pubnames && (strcmp (name, "pubnames") == 0))
2691 || (do_debug_aranges && (strcmp (name, "aranges") == 0))
2693 request_dump (i, DEBUG_DUMP);
2700 printf (_("\nSection Header%s:\n"), elf_header.e_shnum > 1 ? "s" : "");
2704 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
2707 printf (_(" [Nr] Name Type Address Offset\n"));
2708 printf (_(" Size EntSize Flags Link Info Align\n"));
2711 for (i = 0, section = section_headers;
2712 i < elf_header.e_shnum;
2715 printf (" [%2d] %-17.17s %-15.15s ",
2717 SECTION_NAME (section),
2718 get_section_type_name (section->sh_type));
2722 print_vma (section->sh_addr, LONG_HEX);
2724 printf ( " %6.6lx %6.6lx %2.2lx",
2725 (unsigned long) section->sh_offset,
2726 (unsigned long) section->sh_size,
2727 (unsigned long) section->sh_entsize);
2729 printf (" %3s ", get_elf_section_flags (section->sh_flags));
2731 printf (" %2ld %3lx %ld\n",
2732 (unsigned long) section->sh_link,
2733 (unsigned long) section->sh_info,
2734 (unsigned long) section->sh_addralign);
2739 print_vma (section->sh_addr, LONG_HEX);
2740 printf (" %8.8lx", section->sh_offset);
2742 print_vma (section->sh_size, LONG_HEX);
2744 print_vma (section->sh_entsize, LONG_HEX);
2746 printf (" %3s ", get_elf_section_flags (section->sh_flags));
2748 printf (" %2ld %3lx %ld\n",
2749 (unsigned long) section->sh_link,
2750 (unsigned long) section->sh_info,
2751 (unsigned long) section->sh_addralign);
2755 printf (_("Key to Flags: W (write), A (alloc), X (execute), M (merge), S (strings)\n"));
2756 printf (_(" I (info), L (link order), O (extra OS processing required)\n"));
2757 printf (_(" o (os specific), p (processor specific) x (unknown)\n"));
2762 /* Process the reloc section. */
2764 process_relocs (file)
2767 unsigned long rel_size;
2768 unsigned long rel_offset;
2774 if (do_using_dynamic)
2776 int is_rela = FALSE;
2781 if (dynamic_info[DT_REL])
2783 rel_offset = dynamic_info[DT_REL];
2784 rel_size = dynamic_info[DT_RELSZ];
2787 else if (dynamic_info [DT_RELA])
2789 rel_offset = dynamic_info[DT_RELA];
2790 rel_size = dynamic_info[DT_RELASZ];
2793 else if (dynamic_info[DT_JMPREL])
2795 rel_offset = dynamic_info[DT_JMPREL];
2796 rel_size = dynamic_info[DT_PLTRELSZ];
2798 switch (dynamic_info[DT_PLTREL])
2815 (_("\nRelocation section at offset 0x%lx contains %ld bytes:\n"),
2816 rel_offset, rel_size);
2818 dump_relocations (file, rel_offset - loadaddr, rel_size,
2819 dynamic_symbols, num_dynamic_syms, dynamic_strings, is_rela);
2822 printf (_("\nThere are no dynamic relocations in this file.\n"));
2826 Elf32_Internal_Shdr * section;
2830 for (i = 0, section = section_headers;
2831 i < elf_header.e_shnum;
2834 if ( section->sh_type != SHT_RELA
2835 && section->sh_type != SHT_REL)
2838 rel_offset = section->sh_offset;
2839 rel_size = section->sh_size;
2843 Elf32_Internal_Shdr * strsec;
2844 Elf32_Internal_Shdr * symsec;
2845 Elf_Internal_Sym * symtab;
2848 unsigned long nsyms;
2850 printf (_("\nRelocation section "));
2852 if (string_table == NULL)
2853 printf ("%d", section->sh_name);
2855 printf ("'%s'", SECTION_NAME (section));
2857 printf (_(" at offset 0x%lx contains %lu entries:\n"),
2858 rel_offset, (unsigned long) (rel_size / section->sh_entsize));
2860 symsec = section_headers + section->sh_link;
2862 nsyms = symsec->sh_size / symsec->sh_entsize;
2863 symtab = GET_ELF_SYMBOLS (file, symsec->sh_offset, nsyms);
2868 strsec = section_headers + symsec->sh_link;
2870 GET_DATA_ALLOC (strsec->sh_offset, strsec->sh_size, strtab,
2871 char *, "string table");
2873 is_rela = section->sh_type == SHT_RELA;
2875 dump_relocations (file, rel_offset, rel_size, symtab, nsyms, strtab, is_rela);
2885 printf (_("\nThere are no relocations in this file.\n"));
2893 dynamic_segment_mips_val (entry)
2894 Elf_Internal_Dyn * entry;
2896 switch (entry->d_tag)
2899 if (entry->d_un.d_val == 0)
2903 static const char * opts[] =
2905 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
2906 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
2907 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
2908 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
2913 for (cnt = 0; cnt < NUM_ELEM (opts); ++ cnt)
2914 if (entry->d_un.d_val & (1 << cnt))
2916 printf ("%s%s", first ? "" : " ", opts[cnt]);
2923 case DT_MIPS_IVERSION:
2924 if (dynamic_strings != NULL)
2925 printf ("Interface Version: %s\n",
2926 dynamic_strings + entry->d_un.d_val);
2928 printf ("%ld\n", (long) entry->d_un.d_ptr);
2931 case DT_MIPS_TIME_STAMP:
2936 time_t time = entry->d_un.d_val;
2937 tmp = gmtime (&time);
2938 sprintf (timebuf, "%04u-%02u-%02uT%02u:%02u:%02u",
2939 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
2940 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
2941 printf ("Time Stamp: %s\n", timebuf);
2945 case DT_MIPS_RLD_VERSION:
2946 case DT_MIPS_LOCAL_GOTNO:
2947 case DT_MIPS_CONFLICTNO:
2948 case DT_MIPS_LIBLISTNO:
2949 case DT_MIPS_SYMTABNO:
2950 case DT_MIPS_UNREFEXTNO:
2951 case DT_MIPS_HIPAGENO:
2952 case DT_MIPS_DELTA_CLASS_NO:
2953 case DT_MIPS_DELTA_INSTANCE_NO:
2954 case DT_MIPS_DELTA_RELOC_NO:
2955 case DT_MIPS_DELTA_SYM_NO:
2956 case DT_MIPS_DELTA_CLASSSYM_NO:
2957 case DT_MIPS_COMPACT_SIZE:
2958 printf ("%ld\n", (long) entry->d_un.d_ptr);
2962 printf ("%#lx\n", (long) entry->d_un.d_ptr);
2968 dynamic_segment_parisc_val (entry)
2969 Elf_Internal_Dyn * entry;
2971 switch (entry->d_tag)
2973 case DT_HP_DLD_FLAGS:
2982 { DT_HP_DEBUG_PRIVATE, "HP_DEBUG_PRIVATE" },
2983 { DT_HP_DEBUG_CALLBACK, "HP_DEBUG_CALLBACK" },
2984 { DT_HP_DEBUG_CALLBACK_BOR, "HP_DEBUG_CALLBACK_BOR" },
2985 { DT_HP_NO_ENVVAR, "HP_NO_ENVVAR" },
2986 { DT_HP_BIND_NOW, "HP_BIND_NOW" },
2987 { DT_HP_BIND_NONFATAL, "HP_BIND_NONFATAL" },
2988 { DT_HP_BIND_VERBOSE, "HP_BIND_VERBOSE" },
2989 { DT_HP_BIND_RESTRICTED, "HP_BIND_RESTRICTED" },
2990 { DT_HP_BIND_SYMBOLIC, "HP_BIND_SYMBOLIC" },
2991 { DT_HP_RPATH_FIRST, "HP_RPATH_FIRST" },
2992 { DT_HP_BIND_DEPTH_FIRST, "HP_BIND_DEPTH_FIRST" }
2996 bfd_vma val = entry->d_un.d_val;
2998 for (cnt = 0; cnt < sizeof (flags) / sizeof (flags[0]); ++cnt)
2999 if (val & flags[cnt].bit)
3003 fputs (flags[cnt].str, stdout);
3005 val ^= flags[cnt].bit;
3008 if (val != 0 || first)
3012 print_vma (val, HEX);
3018 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
3024 get_32bit_dynamic_segment (file)
3027 Elf32_External_Dyn * edyn;
3028 Elf_Internal_Dyn * entry;
3031 GET_DATA_ALLOC (dynamic_addr, dynamic_size,
3032 edyn, Elf32_External_Dyn *, "dynamic segment");
3034 /* SGI's ELF has more than one section in the DYNAMIC segment. Determine
3035 how large this .dynamic is now. We can do this even before the byte
3036 swapping since the DT_NULL tag is recognizable. */
3038 while (*(Elf32_Word *) edyn [dynamic_size++].d_tag != DT_NULL)
3041 dynamic_segment = (Elf_Internal_Dyn *)
3042 malloc (dynamic_size * sizeof (Elf_Internal_Dyn));
3044 if (dynamic_segment == NULL)
3046 error (_("Out of memory\n"));
3051 for (i = 0, entry = dynamic_segment;
3055 entry->d_tag = BYTE_GET (edyn [i].d_tag);
3056 entry->d_un.d_val = BYTE_GET (edyn [i].d_un.d_val);
3065 get_64bit_dynamic_segment (file)
3068 Elf64_External_Dyn * edyn;
3069 Elf_Internal_Dyn * entry;
3072 GET_DATA_ALLOC (dynamic_addr, dynamic_size,
3073 edyn, Elf64_External_Dyn *, "dynamic segment");
3075 /* SGI's ELF has more than one section in the DYNAMIC segment. Determine
3076 how large this .dynamic is now. We can do this even before the byte
3077 swapping since the DT_NULL tag is recognizable. */
3079 while (*(bfd_vma *) edyn [dynamic_size ++].d_tag != DT_NULL)
3082 dynamic_segment = (Elf_Internal_Dyn *)
3083 malloc (dynamic_size * sizeof (Elf_Internal_Dyn));
3085 if (dynamic_segment == NULL)
3087 error (_("Out of memory\n"));
3092 for (i = 0, entry = dynamic_segment;
3096 entry->d_tag = BYTE_GET8 (edyn [i].d_tag);
3097 entry->d_un.d_val = BYTE_GET8 (edyn [i].d_un.d_val);
3106 get_dynamic_flags (flags)
3109 static char buff [64];
3114 flag = flags & - flags;
3119 case DF_ORIGIN: strcat (buff, "ORIGIN "); break;
3120 case DF_SYMBOLIC: strcat (buff, "SYMBOLIC "); break;
3121 case DF_TEXTREL: strcat (buff, "TEXTREL "); break;
3122 case DF_BIND_NOW: strcat (buff, "BIND_NOW "); break;
3123 default: strcat (buff, "unknown "); break;
3129 /* Parse and display the contents of the dynamic segment. */
3131 process_dynamic_segment (file)
3134 Elf_Internal_Dyn * entry;
3137 if (dynamic_size == 0)
3140 printf (_("\nThere is no dynamic segment in this file.\n"));
3147 if (! get_32bit_dynamic_segment (file))
3150 else if (! get_64bit_dynamic_segment (file))
3153 /* Find the appropriate symbol table. */
3154 if (dynamic_symbols == NULL)
3156 for (i = 0, entry = dynamic_segment;
3160 unsigned long offset;
3162 if (entry->d_tag != DT_SYMTAB)
3165 dynamic_info[DT_SYMTAB] = entry->d_un.d_val;
3167 /* Since we do not know how big the symbol table is,
3168 we default to reading in the entire file (!) and
3169 processing that. This is overkill, I know, but it
3171 offset = entry->d_un.d_val - loadaddr;
3173 if (fseek (file, 0, SEEK_END))
3174 error (_("Unable to seek to end of file!"));
3177 num_dynamic_syms = (ftell (file) - offset) / sizeof (Elf32_External_Sym);
3179 num_dynamic_syms = (ftell (file) - offset) / sizeof (Elf64_External_Sym);
3181 if (num_dynamic_syms < 1)
3183 error (_("Unable to determine the number of symbols to load\n"));
3187 dynamic_symbols = GET_ELF_SYMBOLS (file, offset, num_dynamic_syms);
3191 /* Similarly find a string table. */
3192 if (dynamic_strings == NULL)
3194 for (i = 0, entry = dynamic_segment;
3198 unsigned long offset;
3201 if (entry->d_tag != DT_STRTAB)
3204 dynamic_info[DT_STRTAB] = entry->d_un.d_val;
3206 /* Since we do not know how big the string table is,
3207 we default to reading in the entire file (!) and
3208 processing that. This is overkill, I know, but it
3211 offset = entry->d_un.d_val - loadaddr;
3212 if (fseek (file, 0, SEEK_END))
3213 error (_("Unable to seek to end of file\n"));
3214 str_tab_len = ftell (file) - offset;
3216 if (str_tab_len < 1)
3219 (_("Unable to determine the length of the dynamic string table\n"));
3223 GET_DATA_ALLOC (offset, str_tab_len, dynamic_strings, char *,
3224 "dynamic string table");
3230 /* And find the syminfo section if available. */
3231 if (dynamic_syminfo == NULL)
3233 unsigned int syminsz = 0;
3235 for (i = 0, entry = dynamic_segment;
3239 if (entry->d_tag == DT_SYMINENT)
3241 /* Note: these braces are necessary to avoid a syntax
3242 error from the SunOS4 C compiler. */
3243 assert (sizeof (Elf_External_Syminfo) == entry->d_un.d_val);
3245 else if (entry->d_tag == DT_SYMINSZ)
3246 syminsz = entry->d_un.d_val;
3247 else if (entry->d_tag == DT_SYMINFO)
3248 dynamic_syminfo_offset = entry->d_un.d_val - loadaddr;
3251 if (dynamic_syminfo_offset != 0 && syminsz != 0)
3253 Elf_External_Syminfo * extsyminfo;
3254 Elf_Internal_Syminfo * syminfo;
3256 /* There is a syminfo section. Read the data. */
3257 GET_DATA_ALLOC (dynamic_syminfo_offset, syminsz, extsyminfo,
3258 Elf_External_Syminfo *, "symbol information");
3260 dynamic_syminfo = (Elf_Internal_Syminfo *) malloc (syminsz);
3261 if (dynamic_syminfo == NULL)
3263 error (_("Out of memory\n"));
3267 dynamic_syminfo_nent = syminsz / sizeof (Elf_External_Syminfo);
3268 for (i = 0, syminfo = dynamic_syminfo; i < dynamic_syminfo_nent;
3271 syminfo->si_boundto = BYTE_GET (extsyminfo[i].si_boundto);
3272 syminfo->si_flags = BYTE_GET (extsyminfo[i].si_flags);
3279 if (do_dynamic && dynamic_addr)
3280 printf (_("\nDynamic segment at offset 0x%x contains %ld entries:\n"),
3281 dynamic_addr, (long) dynamic_size);
3283 printf (_(" Tag Type Name/Value\n"));
3285 for (i = 0, entry = dynamic_segment;
3294 print_vma (entry->d_tag, FULL_HEX);
3295 dtype = get_dynamic_type (entry->d_tag);
3296 printf (" (%s)%*s", dtype,
3297 ((is_32bit_elf ? 27 : 19)
3298 - (int) strlen (dtype)),
3302 switch (entry->d_tag)
3306 printf ("%s", get_dynamic_flags (entry->d_un.d_val));
3313 if (entry->d_tag == DT_AUXILIARY)
3314 printf (_("Auxiliary library"));
3316 printf (_("Filter library"));
3318 if (dynamic_strings)
3319 printf (": [%s]\n", dynamic_strings + entry->d_un.d_val);
3323 print_vma (entry->d_un.d_val, PREFIX_HEX);
3332 printf (_("Flags:"));
3333 if (entry->d_un.d_val == 0)
3334 printf (_(" None\n"));
3337 unsigned long int val = entry->d_un.d_val;
3338 if (val & DTF_1_PARINIT)
3340 printf (" PARINIT");
3341 val ^= DTF_1_PARINIT;
3344 printf (" %lx", val);
3353 printf (_("Flags:"));
3354 if (entry->d_un.d_val == 0)
3355 printf (_(" None\n"));
3358 unsigned long int val = entry->d_un.d_val;
3359 if (val & DF_P1_LAZYLOAD)
3361 printf (" LAZYLOAD");
3362 val ^= DF_P1_LAZYLOAD;
3364 if (val & DF_P1_GROUPPERM)
3366 printf (" GROUPPERM");
3367 val ^= DF_P1_GROUPPERM;
3370 printf (" %lx", val);
3379 printf (_("Flags:"));
3380 if (entry->d_un.d_val == 0)
3381 printf (_(" None\n"));
3384 unsigned long int val = entry->d_un.d_val;
3390 if (val & DF_1_GLOBAL)
3395 if (val & DF_1_GROUP)
3400 if (val & DF_1_NODELETE)
3402 printf (" NODELETE");
3403 val ^= DF_1_NODELETE;
3405 if (val & DF_1_LOADFLTR)
3407 printf (" LOADFLTR");
3408 val ^= DF_1_LOADFLTR;
3410 if (val & DF_1_INITFIRST)
3412 printf (" INITFIRST");
3413 val ^= DF_1_INITFIRST;
3415 if (val & DF_1_NOOPEN)
3420 if (val & DF_1_ORIGIN)
3425 if (val & DF_1_DIRECT)
3430 if (val & DF_1_TRANS)
3435 if (val & DF_1_INTERPOSE)
3437 printf (" INTERPOSE");
3438 val ^= DF_1_INTERPOSE;
3441 printf (" %lx", val);
3449 puts (get_dynamic_type (entry->d_un.d_val));
3468 dynamic_info[entry->d_tag] = entry->d_un.d_val;
3474 if (dynamic_strings == NULL)
3477 name = dynamic_strings + entry->d_un.d_val;
3481 switch (entry->d_tag)
3484 printf (_("Shared library: [%s]"), name);
3486 if (strcmp (name, program_interpreter) == 0)
3487 printf (_(" program interpreter"));
3491 printf (_("Library soname: [%s]"), name);
3495 printf (_("Library rpath: [%s]"), name);
3499 print_vma (entry->d_un.d_val, PREFIX_HEX);
3504 print_vma (entry->d_un.d_val, PREFIX_HEX);
3520 case DT_INIT_ARRAYSZ:
3521 case DT_FINI_ARRAYSZ:
3524 print_vma (entry->d_un.d_val, UNSIGNED);
3525 printf (" (bytes)\n");
3535 print_vma (entry->d_un.d_val, UNSIGNED);
3548 if (dynamic_strings != NULL && entry->d_tag == DT_USED)
3552 name = dynamic_strings + entry->d_un.d_val;
3556 printf (_("Not needed object: [%s]\n"), name);
3561 print_vma (entry->d_un.d_val, PREFIX_HEX);
3567 /* The value of this entry is ignored. */
3571 if ((entry->d_tag >= DT_VERSYM) && (entry->d_tag <= DT_VERNEEDNUM))
3572 version_info [DT_VERSIONTAGIDX (entry->d_tag)] =
3577 switch (elf_header.e_machine)
3580 case EM_MIPS_RS4_BE:
3581 dynamic_segment_mips_val (entry);
3584 dynamic_segment_parisc_val (entry);
3587 print_vma (entry->d_un.d_val, PREFIX_HEX);
3599 get_ver_flags (flags)
3602 static char buff [32];
3609 if (flags & VER_FLG_BASE)
3610 strcat (buff, "BASE ");
3612 if (flags & VER_FLG_WEAK)
3614 if (flags & VER_FLG_BASE)
3615 strcat (buff, "| ");
3617 strcat (buff, "WEAK ");
3620 if (flags & ~(VER_FLG_BASE | VER_FLG_WEAK))
3621 strcat (buff, "| <unknown>");
3626 /* Display the contents of the version sections. */
3628 process_version_sections (file)
3631 Elf32_Internal_Shdr * section;
3638 for (i = 0, section = section_headers;
3639 i < elf_header.e_shnum;
3642 switch (section->sh_type)
3644 case SHT_GNU_verdef:
3646 Elf_External_Verdef * edefs;
3653 (_("\nVersion definition section '%s' contains %ld entries:\n"),
3654 SECTION_NAME (section), section->sh_info);
3656 printf (_(" Addr: 0x"));
3657 printf_vma (section->sh_addr);
3658 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
3659 (unsigned long) section->sh_offset, section->sh_link,
3660 SECTION_NAME (section_headers + section->sh_link));
3662 GET_DATA_ALLOC (section->sh_offset, section->sh_size,
3663 edefs, Elf_External_Verdef *,
3664 "version definition section");
3666 for (idx = cnt = 0; cnt < section->sh_info; ++ cnt)
3669 Elf_External_Verdef * edef;
3670 Elf_Internal_Verdef ent;
3671 Elf_External_Verdaux * eaux;
3672 Elf_Internal_Verdaux aux;
3676 vstart = ((char *) edefs) + idx;
3678 edef = (Elf_External_Verdef *) vstart;
3680 ent.vd_version = BYTE_GET (edef->vd_version);
3681 ent.vd_flags = BYTE_GET (edef->vd_flags);
3682 ent.vd_ndx = BYTE_GET (edef->vd_ndx);
3683 ent.vd_cnt = BYTE_GET (edef->vd_cnt);
3684 ent.vd_hash = BYTE_GET (edef->vd_hash);
3685 ent.vd_aux = BYTE_GET (edef->vd_aux);
3686 ent.vd_next = BYTE_GET (edef->vd_next);
3688 printf (_(" %#06x: Rev: %d Flags: %s"),
3689 idx, ent.vd_version, get_ver_flags (ent.vd_flags));
3691 printf (_(" Index: %d Cnt: %d "),
3692 ent.vd_ndx, ent.vd_cnt);
3694 vstart += ent.vd_aux;
3696 eaux = (Elf_External_Verdaux *) vstart;
3698 aux.vda_name = BYTE_GET (eaux->vda_name);
3699 aux.vda_next = BYTE_GET (eaux->vda_next);
3701 if (dynamic_strings)
3702 printf (_("Name: %s\n"), dynamic_strings + aux.vda_name);
3704 printf (_("Name index: %ld\n"), aux.vda_name);
3706 isum = idx + ent.vd_aux;
3708 for (j = 1; j < ent.vd_cnt; j ++)
3710 isum += aux.vda_next;
3711 vstart += aux.vda_next;
3713 eaux = (Elf_External_Verdaux *) vstart;
3715 aux.vda_name = BYTE_GET (eaux->vda_name);
3716 aux.vda_next = BYTE_GET (eaux->vda_next);
3718 if (dynamic_strings)
3719 printf (_(" %#06x: Parent %d: %s\n"),
3720 isum, j, dynamic_strings + aux.vda_name);
3722 printf (_(" %#06x: Parent %d, name index: %ld\n"),
3723 isum, j, aux.vda_name);
3733 case SHT_GNU_verneed:
3735 Elf_External_Verneed * eneed;
3741 printf (_("\nVersion needs section '%s' contains %ld entries:\n"),
3742 SECTION_NAME (section), section->sh_info);
3744 printf (_(" Addr: 0x"));
3745 printf_vma (section->sh_addr);
3746 printf (_(" Offset: %#08lx Link to section: %ld (%s)\n"),
3747 (unsigned long) section->sh_offset, section->sh_link,
3748 SECTION_NAME (section_headers + section->sh_link));
3750 GET_DATA_ALLOC (section->sh_offset, section->sh_size,
3751 eneed, Elf_External_Verneed *,
3752 "version need section");
3754 for (idx = cnt = 0; cnt < section->sh_info; ++cnt)
3756 Elf_External_Verneed * entry;
3757 Elf_Internal_Verneed ent;
3762 vstart = ((char *) eneed) + idx;
3764 entry = (Elf_External_Verneed *) vstart;
3766 ent.vn_version = BYTE_GET (entry->vn_version);
3767 ent.vn_cnt = BYTE_GET (entry->vn_cnt);
3768 ent.vn_file = BYTE_GET (entry->vn_file);
3769 ent.vn_aux = BYTE_GET (entry->vn_aux);
3770 ent.vn_next = BYTE_GET (entry->vn_next);
3772 printf (_(" %#06x: Version: %d"), idx, ent.vn_version);
3774 if (dynamic_strings)
3775 printf (_(" File: %s"), dynamic_strings + ent.vn_file);
3777 printf (_(" File: %lx"), ent.vn_file);
3779 printf (_(" Cnt: %d\n"), ent.vn_cnt);
3781 vstart += ent.vn_aux;
3783 for (j = 0, isum = idx + ent.vn_aux; j < ent.vn_cnt; ++j)
3785 Elf_External_Vernaux * eaux;
3786 Elf_Internal_Vernaux aux;
3788 eaux = (Elf_External_Vernaux *) vstart;
3790 aux.vna_hash = BYTE_GET (eaux->vna_hash);
3791 aux.vna_flags = BYTE_GET (eaux->vna_flags);
3792 aux.vna_other = BYTE_GET (eaux->vna_other);
3793 aux.vna_name = BYTE_GET (eaux->vna_name);
3794 aux.vna_next = BYTE_GET (eaux->vna_next);
3796 if (dynamic_strings)
3797 printf (_(" %#06x: Name: %s"),
3798 isum, dynamic_strings + aux.vna_name);
3800 printf (_(" %#06x: Name index: %lx"),
3801 isum, aux.vna_name);
3803 printf (_(" Flags: %s Version: %d\n"),
3804 get_ver_flags (aux.vna_flags), aux.vna_other);
3806 isum += aux.vna_next;
3807 vstart += aux.vna_next;
3817 case SHT_GNU_versym:
3819 Elf32_Internal_Shdr * link_section;
3822 unsigned char * edata;
3823 unsigned short * data;
3825 Elf_Internal_Sym * symbols;
3826 Elf32_Internal_Shdr * string_sec;
3828 link_section = section_headers + section->sh_link;
3829 total = section->sh_size / section->sh_entsize;
3833 symbols = GET_ELF_SYMBOLS (file, link_section->sh_offset,
3834 link_section->sh_size / link_section->sh_entsize);
3836 string_sec = section_headers + link_section->sh_link;
3838 GET_DATA_ALLOC (string_sec->sh_offset, string_sec->sh_size,
3839 strtab, char *, "version string table");
3841 printf (_("\nVersion symbols section '%s' contains %d entries:\n"),
3842 SECTION_NAME (section), total);
3844 printf (_(" Addr: "));
3845 printf_vma (section->sh_addr);
3846 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
3847 (unsigned long) section->sh_offset, section->sh_link,
3848 SECTION_NAME (link_section));
3850 GET_DATA_ALLOC (version_info [DT_VERSIONTAGIDX (DT_VERSYM)]
3852 total * sizeof (short), edata,
3853 unsigned char *, "version symbol data");
3855 data = (unsigned short *) malloc (total * sizeof (short));
3857 for (cnt = total; cnt --;)
3858 data [cnt] = byte_get (edata + cnt * sizeof (short),
3863 for (cnt = 0; cnt < total; cnt += 4)
3868 printf (" %03x:", cnt);
3870 for (j = 0; (j < 4) && (cnt + j) < total; ++j)
3871 switch (data [cnt + j])
3874 fputs (_(" 0 (*local*) "), stdout);
3878 fputs (_(" 1 (*global*) "), stdout);
3882 nn = printf ("%4x%c", data [cnt + j] & 0x7fff,
3883 data [cnt + j] & 0x8000 ? 'h' : ' ');
3885 if (symbols [cnt + j].st_shndx < SHN_LORESERVE
3886 && section_headers[symbols [cnt + j].st_shndx].sh_type
3889 /* We must test both. */
3890 Elf_Internal_Verneed ivn;
3891 unsigned long offset;
3893 offset = version_info [DT_VERSIONTAGIDX (DT_VERNEED)]
3898 Elf_External_Verneed evn;
3899 Elf_External_Vernaux evna;
3900 Elf_Internal_Vernaux ivna;
3901 unsigned long vna_off;
3903 GET_DATA (offset, evn, "version need");
3905 ivn.vn_aux = BYTE_GET (evn.vn_aux);
3906 ivn.vn_next = BYTE_GET (evn.vn_next);
3908 vna_off = offset + ivn.vn_aux;
3912 GET_DATA (vna_off, evna,
3913 "version need aux (1)");
3915 ivna.vna_next = BYTE_GET (evna.vna_next);
3916 ivna.vna_other = BYTE_GET (evna.vna_other);
3918 vna_off += ivna.vna_next;
3920 while (ivna.vna_other != data [cnt + j]
3921 && ivna.vna_next != 0);
3923 if (ivna.vna_other == data [cnt + j])
3925 ivna.vna_name = BYTE_GET (evna.vna_name);
3927 name = strtab + ivna.vna_name;
3928 nn += printf ("(%s%-*s",
3930 12 - (int) strlen (name),
3934 else if (ivn.vn_next == 0)
3936 if (data [cnt + j] != 0x8001)
3938 Elf_Internal_Verdef ivd;
3939 Elf_External_Verdef evd;
3941 offset = version_info
3942 [DT_VERSIONTAGIDX (DT_VERDEF)]
3947 GET_DATA (offset, evd,
3948 "version definition");
3950 ivd.vd_next = BYTE_GET (evd.vd_next);
3951 ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
3953 offset += ivd.vd_next;
3956 != (data [cnt + j] & 0x7fff)
3957 && ivd.vd_next != 0);
3960 == (data [cnt + j] & 0x7fff))
3962 Elf_External_Verdaux evda;
3963 Elf_Internal_Verdaux ivda;
3965 ivd.vd_aux = BYTE_GET (evd.vd_aux);
3967 GET_DATA (offset + ivd.vd_aux, evda,
3968 "version definition aux");
3971 BYTE_GET (evda.vda_name);
3973 name = strtab + ivda.vda_name;
3977 12 - (int) strlen (name),
3985 offset += ivn.vn_next;
3987 while (ivn.vn_next);
3989 else if (symbols [cnt + j].st_shndx == SHN_UNDEF)
3991 Elf_Internal_Verneed ivn;
3992 unsigned long offset;
3994 offset = version_info [DT_VERSIONTAGIDX (DT_VERNEED)]
3999 Elf_Internal_Vernaux ivna;
4000 Elf_External_Verneed evn;
4001 Elf_External_Vernaux evna;
4002 unsigned long a_off;
4004 GET_DATA (offset, evn, "version need");
4006 ivn.vn_aux = BYTE_GET (evn.vn_aux);
4007 ivn.vn_next = BYTE_GET (evn.vn_next);
4009 a_off = offset + ivn.vn_aux;
4013 GET_DATA (a_off, evna,
4014 "version need aux (2)");
4016 ivna.vna_next = BYTE_GET (evna.vna_next);
4017 ivna.vna_other = BYTE_GET (evna.vna_other);
4019 a_off += ivna.vna_next;
4021 while (ivna.vna_other != data [cnt + j]
4022 && ivna.vna_next != 0);
4024 if (ivna.vna_other == data [cnt + j])
4026 ivna.vna_name = BYTE_GET (evna.vna_name);
4028 name = strtab + ivna.vna_name;
4029 nn += printf ("(%s%-*s",
4031 12 - (int) strlen (name),
4036 offset += ivn.vn_next;
4038 while (ivn.vn_next);
4040 else if (data [cnt + j] != 0x8001)
4042 Elf_Internal_Verdef ivd;
4043 Elf_External_Verdef evd;
4044 unsigned long offset;
4046 offset = version_info
4047 [DT_VERSIONTAGIDX (DT_VERDEF)] - loadaddr;
4051 GET_DATA (offset, evd, "version def");
4053 ivd.vd_next = BYTE_GET (evd.vd_next);
4054 ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
4056 offset += ivd.vd_next;
4058 while (ivd.vd_ndx != (data [cnt + j] & 0x7fff)
4059 && ivd.vd_next != 0);
4061 if (ivd.vd_ndx == (data [cnt + j] & 0x7fff))
4063 Elf_External_Verdaux evda;
4064 Elf_Internal_Verdaux ivda;
4066 ivd.vd_aux = BYTE_GET (evd.vd_aux);
4068 GET_DATA (offset - ivd.vd_next + ivd.vd_aux,
4069 evda, "version def aux");
4071 ivda.vda_name = BYTE_GET (evda.vda_name);
4073 name = strtab + ivda.vda_name;
4074 nn += printf ("(%s%-*s",
4076 12 - (int) strlen (name),
4082 printf ("%*c", 18 - nn, ' ');
4100 printf (_("\nNo version information found in this file.\n"));
4106 get_symbol_binding (binding)
4107 unsigned int binding;
4109 static char buff [32];
4113 case STB_LOCAL: return "LOCAL";
4114 case STB_GLOBAL: return "GLOBAL";
4115 case STB_WEAK: return "WEAK";
4117 if (binding >= STB_LOPROC && binding <= STB_HIPROC)
4118 sprintf (buff, _("<processor specific>: %d"), binding);
4119 else if (binding >= STB_LOOS && binding <= STB_HIOS)
4120 sprintf (buff, _("<OS specific>: %d"), binding);
4122 sprintf (buff, _("<unknown>: %d"), binding);
4128 get_symbol_type (type)
4131 static char buff [32];
4135 case STT_NOTYPE: return "NOTYPE";
4136 case STT_OBJECT: return "OBJECT";
4137 case STT_FUNC: return "FUNC";
4138 case STT_SECTION: return "SECTION";
4139 case STT_FILE: return "FILE";
4140 case STT_COMMON: return "COMMON";
4142 if (type >= STT_LOPROC && type <= STT_HIPROC)
4144 if (elf_header.e_machine == EM_ARM && type == STT_ARM_TFUNC)
4145 return "THUMB_FUNC";
4147 if (elf_header.e_machine == EM_SPARCV9 && type == STT_REGISTER)
4150 if (elf_header.e_machine == EM_PARISC && type == STT_PARISC_MILLI)
4151 return "PARISC_MILLI";
4153 sprintf (buff, _("<processor specific>: %d"), type);
4155 else if (type >= STT_LOOS && type <= STT_HIOS)
4157 if (elf_header.e_machine == EM_PARISC)
4159 if (type == STT_HP_OPAQUE)
4161 if (type == STT_HP_STUB)
4165 sprintf (buff, _("<OS specific>: %d"), type);
4168 sprintf (buff, _("<unknown>: %d"), type);
4174 get_symbol_visibility (visibility)
4175 unsigned int visibility;
4179 case STV_DEFAULT: return "DEFAULT";
4180 case STV_INTERNAL: return "INTERNAL";
4181 case STV_HIDDEN: return "HIDDEN";
4182 case STV_PROTECTED: return "PROTECTED";
4188 get_symbol_index_type (type)
4193 case SHN_UNDEF: return "UND";
4194 case SHN_ABS: return "ABS";
4195 case SHN_COMMON: return "COM";
4197 if (type >= SHN_LOPROC && type <= SHN_HIPROC)
4199 else if (type >= SHN_LORESERVE && type <= SHN_HIRESERVE)
4201 else if (type >= SHN_LOOS && type <= SHN_HIOS)
4205 static char buff [32];
4207 sprintf (buff, "%3d", type);
4214 get_dynamic_data (file, number)
4216 unsigned int number;
4221 e_data = (char *) malloc (number * 4);
4225 error (_("Out of memory\n"));
4229 if (fread (e_data, 4, number, file) != number)
4231 error (_("Unable to read in dynamic data\n"));
4235 i_data = (int *) malloc (number * sizeof (* i_data));
4239 error (_("Out of memory\n"));
4245 i_data [number] = byte_get (e_data + number * 4, 4);
4252 /* Dump the symbol table */
4254 process_symbol_table (file)
4257 Elf32_Internal_Shdr * section;
4262 int * buckets = NULL;
4263 int * chains = NULL;
4265 if (! do_syms && !do_histogram)
4268 if (dynamic_info[DT_HASH] && ((do_using_dynamic && dynamic_strings != NULL)
4271 if (fseek (file, dynamic_info[DT_HASH] - loadaddr, SEEK_SET))
4273 error (_("Unable to seek to start of dynamic information"));
4277 if (fread (nb, sizeof (nb), 1, file) != 1)
4279 error (_("Failed to read in number of buckets\n"));
4283 if (fread (nc, sizeof (nc), 1, file) != 1)
4285 error (_("Failed to read in number of chains\n"));
4289 nbuckets = byte_get (nb, 4);
4290 nchains = byte_get (nc, 4);
4292 buckets = get_dynamic_data (file, nbuckets);
4293 chains = get_dynamic_data (file, nchains);
4295 if (buckets == NULL || chains == NULL)
4300 && dynamic_info[DT_HASH] && do_using_dynamic && dynamic_strings != NULL)
4305 printf (_("\nSymbol table for image:\n"));
4307 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
4309 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
4311 for (hn = 0; hn < nbuckets; hn++)
4316 for (si = buckets [hn]; si < nchains && si > 0; si = chains [si])
4318 Elf_Internal_Sym * psym;
4320 psym = dynamic_symbols + si;
4322 printf (" %3d %3d: ", si, hn);
4323 print_vma (psym->st_value, LONG_HEX);
4325 print_vma (psym->st_size, DEC_5);
4327 printf (" %6s", get_symbol_type (ELF_ST_TYPE (psym->st_info)));
4328 printf (" %6s", get_symbol_binding (ELF_ST_BIND (psym->st_info)));
4329 printf (" %3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym->st_other)));
4330 printf (" %3.3s", get_symbol_index_type (psym->st_shndx));
4331 printf (" %s\n", dynamic_strings + psym->st_name);
4335 else if (do_syms && !do_using_dynamic)
4339 for (i = 0, section = section_headers;
4340 i < elf_header.e_shnum;
4345 Elf_Internal_Sym * symtab;
4346 Elf_Internal_Sym * psym;
4349 if ( section->sh_type != SHT_SYMTAB
4350 && section->sh_type != SHT_DYNSYM)
4353 printf (_("\nSymbol table '%s' contains %lu entries:\n"),
4354 SECTION_NAME (section),
4355 (unsigned long) (section->sh_size / section->sh_entsize));
4357 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
4359 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
4361 symtab = GET_ELF_SYMBOLS (file, section->sh_offset,
4362 section->sh_size / section->sh_entsize);
4366 if (section->sh_link == elf_header.e_shstrndx)
4367 strtab = string_table;
4370 Elf32_Internal_Shdr * string_sec;
4372 string_sec = section_headers + section->sh_link;
4374 GET_DATA_ALLOC (string_sec->sh_offset, string_sec->sh_size,
4375 strtab, char *, "string table");
4378 for (si = 0, psym = symtab;
4379 si < section->sh_size / section->sh_entsize;
4382 printf ("%6d: ", si);
4383 print_vma (psym->st_value, LONG_HEX);
4385 print_vma (psym->st_size, DEC_5);
4386 printf (" %-7s", get_symbol_type (ELF_ST_TYPE (psym->st_info)));
4387 printf (" %-6s", get_symbol_binding (ELF_ST_BIND (psym->st_info)));
4388 printf (" %-3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym->st_other)));
4389 printf (" %4s", get_symbol_index_type (psym->st_shndx));
4390 printf (" %s", strtab + psym->st_name);
4392 if (section->sh_type == SHT_DYNSYM &&
4393 version_info [DT_VERSIONTAGIDX (DT_VERSYM)] != 0)
4395 unsigned char data[2];
4396 unsigned short vers_data;
4397 unsigned long offset;
4401 offset = version_info [DT_VERSIONTAGIDX (DT_VERSYM)]
4404 GET_DATA (offset + si * sizeof (vers_data), data,
4407 vers_data = byte_get (data, 2);
4409 is_nobits = psym->st_shndx < SHN_LORESERVE ?
4410 (section_headers [psym->st_shndx].sh_type == SHT_NOBITS)
4413 check_def = (psym->st_shndx != SHN_UNDEF);
4415 if ((vers_data & 0x8000) || vers_data > 1)
4417 if (is_nobits || ! check_def)
4419 Elf_External_Verneed evn;
4420 Elf_Internal_Verneed ivn;
4421 Elf_Internal_Vernaux ivna;
4423 /* We must test both. */
4424 offset = version_info
4425 [DT_VERSIONTAGIDX (DT_VERNEED)] - loadaddr;
4429 unsigned long vna_off;
4431 GET_DATA (offset, evn, "version need");
4433 ivn.vn_aux = BYTE_GET (evn.vn_aux);
4434 ivn.vn_next = BYTE_GET (evn.vn_next);
4436 vna_off = offset + ivn.vn_aux;
4440 Elf_External_Vernaux evna;
4442 GET_DATA (vna_off, evna,
4443 "version need aux (3)");
4445 ivna.vna_other = BYTE_GET (evna.vna_other);
4446 ivna.vna_next = BYTE_GET (evna.vna_next);
4447 ivna.vna_name = BYTE_GET (evna.vna_name);
4449 vna_off += ivna.vna_next;
4451 while (ivna.vna_other != vers_data
4452 && ivna.vna_next != 0);
4454 if (ivna.vna_other == vers_data)
4457 offset += ivn.vn_next;
4459 while (ivn.vn_next != 0);
4461 if (ivna.vna_other == vers_data)
4464 strtab + ivna.vna_name, ivna.vna_other);
4467 else if (! is_nobits)
4468 error (_("bad dynamic symbol"));
4475 if (vers_data != 0x8001)
4477 Elf_Internal_Verdef ivd;
4478 Elf_Internal_Verdaux ivda;
4479 Elf_External_Verdaux evda;
4480 unsigned long offset;
4483 version_info [DT_VERSIONTAGIDX (DT_VERDEF)]
4488 Elf_External_Verdef evd;
4490 GET_DATA (offset, evd, "version def");
4492 ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
4493 ivd.vd_aux = BYTE_GET (evd.vd_aux);
4494 ivd.vd_next = BYTE_GET (evd.vd_next);
4496 offset += ivd.vd_next;
4498 while (ivd.vd_ndx != (vers_data & 0x7fff)
4499 && ivd.vd_next != 0);
4501 offset -= ivd.vd_next;
4502 offset += ivd.vd_aux;
4504 GET_DATA (offset, evda, "version def aux");
4506 ivda.vda_name = BYTE_GET (evda.vda_name);
4508 if (psym->st_name != ivda.vda_name)
4509 printf ((vers_data & 0x8000)
4511 strtab + ivda.vda_name);
4521 if (strtab != string_table)
4527 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
4529 if (do_histogram && buckets != NULL)
4536 int nzero_counts = 0;
4539 printf (_("\nHistogram for bucket list length (total of %d buckets):\n"),
4541 printf (_(" Length Number %% of total Coverage\n"));
4543 lengths = (int *) calloc (nbuckets, sizeof (int));
4544 if (lengths == NULL)
4546 error (_("Out of memory"));
4549 for (hn = 0; hn < nbuckets; ++hn)
4554 for (si = buckets[hn]; si > 0 && si < nchains; si = chains[si])
4557 if (maxlength < ++lengths[hn])
4562 counts = (int *) calloc (maxlength + 1, sizeof (int));
4565 error (_("Out of memory"));
4569 for (hn = 0; hn < nbuckets; ++hn)
4570 ++ counts [lengths [hn]];
4574 printf (" 0 %-10d (%5.1f%%)\n",
4575 counts[0], (counts[0] * 100.0) / nbuckets);
4576 for (si = 1; si <= maxlength; ++si)
4578 nzero_counts += counts[si] * si;
4579 printf ("%7d %-10d (%5.1f%%) %5.1f%%\n",
4580 si, counts[si], (counts[si] * 100.0) / nbuckets,
4581 (nzero_counts * 100.0) / nsyms);
4589 if (buckets != NULL)
4599 process_syminfo (file)
4600 FILE * file ATTRIBUTE_UNUSED;
4604 if (dynamic_syminfo == NULL
4606 /* No syminfo, this is ok. */
4609 /* There better should be a dynamic symbol section. */
4610 if (dynamic_symbols == NULL || dynamic_strings == NULL)
4614 printf (_("\nDynamic info segment at offset 0x%lx contains %d entries:\n"),
4615 dynamic_syminfo_offset, dynamic_syminfo_nent);
4617 printf (_(" Num: Name BoundTo Flags\n"));
4618 for (i = 0; i < dynamic_syminfo_nent; ++i)
4620 unsigned short int flags = dynamic_syminfo[i].si_flags;
4622 printf ("%4d: %-30s ", i,
4623 dynamic_strings + dynamic_symbols[i].st_name);
4625 switch (dynamic_syminfo[i].si_boundto)
4627 case SYMINFO_BT_SELF:
4628 fputs ("SELF ", stdout);
4630 case SYMINFO_BT_PARENT:
4631 fputs ("PARENT ", stdout);
4634 if (dynamic_syminfo[i].si_boundto > 0
4635 && dynamic_syminfo[i].si_boundto < dynamic_size)
4638 + dynamic_segment[dynamic_syminfo[i].si_boundto].d_un.d_val);
4640 printf ("%-10d ", dynamic_syminfo[i].si_boundto);
4644 if (flags & SYMINFO_FLG_DIRECT)
4646 if (flags & SYMINFO_FLG_PASSTHRU)
4647 printf (" PASSTHRU");
4648 if (flags & SYMINFO_FLG_COPY)
4650 if (flags & SYMINFO_FLG_LAZYLOAD)
4651 printf (" LAZYLOAD");
4659 #ifdef SUPPORT_DISASSEMBLY
4661 disassemble_section (section, file)
4662 Elf32_Internal_Shdr * section;
4665 printf (_("\nAssembly dump of section %s\n"),
4666 SECTION_NAME (section));
4668 /* XXX -- to be done --- XXX */
4675 dump_section (section, file)
4676 Elf32_Internal_Shdr * section;
4679 bfd_size_type bytes;
4681 unsigned char * data;
4682 unsigned char * start;
4684 bytes = section->sh_size;
4688 printf (_("\nSection '%s' has no data to dump.\n"),
4689 SECTION_NAME (section));
4693 printf (_("\nHex dump of section '%s':\n"), SECTION_NAME (section));
4695 addr = section->sh_addr;
4697 GET_DATA_ALLOC (section->sh_offset, bytes, start, unsigned char *,
4708 lbytes = (bytes > 16 ? 16 : bytes);
4710 printf (" 0x%8.8lx ", (unsigned long) addr);
4712 switch (elf_header.e_ident [EI_DATA])
4716 for (j = 15; j >= 0; j --)
4719 printf ("%2.2x", data [j]);
4729 for (j = 0; j < 16; j++)
4732 printf ("%2.2x", data [j]);
4742 for (j = 0; j < lbytes; j++)
4745 if (k >= ' ' && k < 0x80)
4764 static unsigned long int
4765 read_leb128 (data, length_return, sign)
4766 unsigned char * data;
4767 int * length_return;
4770 unsigned long int result = 0;
4771 unsigned int num_read = 0;
4780 result |= (byte & 0x7f) << shift;
4785 while (byte & 0x80);
4787 if (length_return != NULL)
4788 * length_return = num_read;
4790 if (sign && (shift < 32) && (byte & 0x40))
4791 result |= -1 << shift;
4796 typedef struct State_Machine_Registers
4798 unsigned long address;
4801 unsigned int column;
4805 /* This variable hold the number of the last entry seen
4806 in the File Table. */
4807 unsigned int last_file_entry;
4810 static SMR state_machine_regs;
4813 reset_state_machine (is_stmt)
4816 state_machine_regs.address = 0;
4817 state_machine_regs.file = 1;
4818 state_machine_regs.line = 1;
4819 state_machine_regs.column = 0;
4820 state_machine_regs.is_stmt = is_stmt;
4821 state_machine_regs.basic_block = 0;
4822 state_machine_regs.end_sequence = 0;
4823 state_machine_regs.last_file_entry = 0;
4826 /* Handled an extend line op. Returns true if this is the end
4829 process_extended_line_op (data, is_stmt, pointer_size)
4830 unsigned char * data;
4834 unsigned char op_code;
4837 unsigned char * name;
4840 len = read_leb128 (data, & bytes_read, 0);
4845 warn (_("badly formed extended line op encountered!"));
4850 op_code = * data ++;
4852 printf (_(" Extended opcode %d: "), op_code);
4856 case DW_LNE_end_sequence:
4857 printf (_("End of Sequence\n\n"));
4858 reset_state_machine (is_stmt);
4861 case DW_LNE_set_address:
4862 adr = byte_get (data, pointer_size);
4863 printf (_("set Address to 0x%lx\n"), adr);
4864 state_machine_regs.address = adr;
4867 case DW_LNE_define_file:
4868 printf (_(" define new File Table entry\n"));
4869 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
4871 printf (_(" %d\t"), ++ state_machine_regs.last_file_entry);
4873 data += strlen (data) + 1;
4874 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
4876 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
4878 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
4879 printf (_("%s\n\n"), name);
4883 printf (_("UNKNOWN: length %d\n"), len - bytes_read);
4890 /* Size of pointers in the .debug_line section. This information is not
4891 really present in that section. It's obtained before dumping the debug
4892 sections by doing some pre-scan of the .debug_info section. */
4893 static int debug_line_pointer_size = 4;
4896 display_debug_lines (section, start, file)
4897 Elf32_Internal_Shdr * section;
4898 unsigned char * start;
4899 FILE * file ATTRIBUTE_UNUSED;
4901 DWARF2_External_LineInfo * external;
4902 DWARF2_Internal_LineInfo info;
4903 unsigned char * standard_opcodes;
4904 unsigned char * data = start;
4905 unsigned char * end = start + section->sh_size;
4906 unsigned char * end_of_sequence;
4909 printf (_("\nDump of debug contents of section %s:\n\n"),
4910 SECTION_NAME (section));
4914 external = (DWARF2_External_LineInfo *) data;
4916 /* Check the length of the block. */
4917 info.li_length = BYTE_GET (external->li_length);
4918 if (info.li_length > section->sh_size)
4921 (_("The line info appears to be corrupt - the section is too small\n"));
4925 /* Check its version number. */
4926 info.li_version = BYTE_GET (external->li_version);
4927 if (info.li_version != 2)
4929 warn (_("Only DWARF version 2 line info is currently supported.\n"));
4933 info.li_prologue_length = BYTE_GET (external->li_prologue_length);
4934 info.li_min_insn_length = BYTE_GET (external->li_min_insn_length);
4935 info.li_default_is_stmt = BYTE_GET (external->li_default_is_stmt);
4936 info.li_line_base = BYTE_GET (external->li_line_base);
4937 info.li_line_range = BYTE_GET (external->li_line_range);
4938 info.li_opcode_base = BYTE_GET (external->li_opcode_base);
4940 /* Sign extend the line base field. */
4941 info.li_line_base <<= 24;
4942 info.li_line_base >>= 24;
4944 printf (_(" Length: %ld\n"), info.li_length);
4945 printf (_(" DWARF Version: %d\n"), info.li_version);
4946 printf (_(" Prolgue Length: %d\n"), info.li_prologue_length);
4947 printf (_(" Minimum Instruction Length: %d\n"), info.li_min_insn_length);
4948 printf (_(" Initial value of 'is_stmt': %d\n"), info.li_default_is_stmt);
4949 printf (_(" Line Base: %d\n"), info.li_line_base);
4950 printf (_(" Line Range: %d\n"), info.li_line_range);
4951 printf (_(" Opcode Base: %d\n"), info.li_opcode_base);
4953 end_of_sequence = data + info.li_length + sizeof (info.li_length);
4955 reset_state_machine (info.li_default_is_stmt);
4957 /* Display the contents of the Opcodes table. */
4958 standard_opcodes = data + sizeof (* external);
4960 printf (_("\n Opcodes:\n"));
4962 for (i = 1; i < info.li_opcode_base; i++)
4963 printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]);
4965 /* Display the contents of the Directory table. */
4966 data = standard_opcodes + info.li_opcode_base - 1;
4969 printf (_("\n The Directory Table is empty.\n"));
4972 printf (_("\n The Directory Table:\n"));
4976 printf (_(" %s\n"), data);
4978 data += strlen (data) + 1;
4982 /* Skip the NUL at the end of the table. */
4985 /* Display the contents of the File Name table. */
4987 printf (_("\n The File Name Table is empty.\n"));
4990 printf (_("\n The File Name Table:\n"));
4991 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
4998 printf (_(" %d\t"), ++ state_machine_regs.last_file_entry);
5001 data += strlen (data) + 1;
5003 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
5005 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
5007 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
5009 printf (_("%s\n"), name);
5013 /* Skip the NUL at the end of the table. */
5016 /* Now display the statements. */
5017 printf (_("\n Line Number Statements:\n"));
5020 while (data < end_of_sequence)
5022 unsigned char op_code;
5026 op_code = * data ++;
5030 case DW_LNS_extended_op:
5031 data += process_extended_line_op (data, info.li_default_is_stmt,
5032 debug_line_pointer_size);
5036 printf (_(" Copy\n"));
5039 case DW_LNS_advance_pc:
5040 adv = info.li_min_insn_length * read_leb128 (data, & bytes_read, 0);
5042 state_machine_regs.address += adv;
5043 printf (_(" Advance PC by %d to %lx\n"), adv,
5044 state_machine_regs.address);
5047 case DW_LNS_advance_line:
5048 adv = read_leb128 (data, & bytes_read, 1);
5050 state_machine_regs.line += adv;
5051 printf (_(" Advance Line by %d to %d\n"), adv,
5052 state_machine_regs.line);
5055 case DW_LNS_set_file:
5056 adv = read_leb128 (data, & bytes_read, 0);
5058 printf (_(" Set File Name to entry %d in the File Name Table\n"),
5060 state_machine_regs.file = adv;
5063 case DW_LNS_set_column:
5064 adv = read_leb128 (data, & bytes_read, 0);
5066 printf (_(" Set column to %d\n"), adv);
5067 state_machine_regs.column = adv;
5070 case DW_LNS_negate_stmt:
5071 adv = state_machine_regs.is_stmt;
5073 printf (_(" Set is_stmt to %d\n"), adv);
5074 state_machine_regs.is_stmt = adv;
5077 case DW_LNS_set_basic_block:
5078 printf (_(" Set basic block\n"));
5079 state_machine_regs.basic_block = 1;
5082 case DW_LNS_const_add_pc:
5083 adv = (((255 - info.li_opcode_base) / info.li_line_range)
5084 * info.li_min_insn_length);
5085 state_machine_regs.address += adv;
5086 printf (_(" Advance PC by constant %d to 0x%lx\n"), adv,
5087 state_machine_regs.address);
5090 case DW_LNS_fixed_advance_pc:
5091 adv = byte_get (data, 2);
5093 state_machine_regs.address += adv;
5094 printf (_(" Advance PC by fixed size amount %d to 0x%lx\n"),
5095 adv, state_machine_regs.address);
5099 op_code -= info.li_opcode_base;
5100 adv = (op_code / info.li_line_range) * info.li_min_insn_length;
5101 state_machine_regs.address += adv;
5102 printf (_(" Special opcode %d: advance Address by %d to 0x%lx"),
5103 op_code, adv, state_machine_regs.address);
5104 adv = (op_code % info.li_line_range) + info.li_line_base;
5105 state_machine_regs.line += adv;
5106 printf (_(" and Line by %d to %d\n"),
5107 adv, state_machine_regs.line);
5118 display_debug_pubnames (section, start, file)
5119 Elf32_Internal_Shdr * section;
5120 unsigned char * start;
5121 FILE * file ATTRIBUTE_UNUSED;
5123 DWARF2_External_PubNames * external;
5124 DWARF2_Internal_PubNames pubnames;
5125 unsigned char * end;
5127 end = start + section->sh_size;
5129 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section));
5133 unsigned char * data;
5134 unsigned long offset;
5136 external = (DWARF2_External_PubNames *) start;
5138 pubnames.pn_length = BYTE_GET (external->pn_length);
5139 pubnames.pn_version = BYTE_GET (external->pn_version);
5140 pubnames.pn_offset = BYTE_GET (external->pn_offset);
5141 pubnames.pn_size = BYTE_GET (external->pn_size);
5143 data = start + sizeof (* external);
5144 start += pubnames.pn_length + sizeof (external->pn_length);
5146 if (pubnames.pn_version != 2)
5148 warn (_("Only DWARF 2 pubnames are currently supported"));
5152 printf (_(" Length: %ld\n"),
5153 pubnames.pn_length);
5154 printf (_(" Version: %d\n"),
5155 pubnames.pn_version);
5156 printf (_(" Offset into .debug_info section: %ld\n"),
5157 pubnames.pn_offset);
5158 printf (_(" Size of area in .debug_info section: %ld\n"),
5161 printf (_("\n Offset\tName\n"));
5165 offset = byte_get (data, 4);
5170 printf (" %ld\t\t%s\n", offset, data);
5171 data += strlen (data) + 1;
5174 while (offset != 0);
5187 case DW_TAG_padding: return "DW_TAG_padding";
5188 case DW_TAG_array_type: return "DW_TAG_array_type";
5189 case DW_TAG_class_type: return "DW_TAG_class_type";
5190 case DW_TAG_entry_point: return "DW_TAG_entry_point";
5191 case DW_TAG_enumeration_type: return "DW_TAG_enumeration_type";
5192 case DW_TAG_formal_parameter: return "DW_TAG_formal_parameter";
5193 case DW_TAG_imported_declaration: return "DW_TAG_imported_declaration";
5194 case DW_TAG_label: return "DW_TAG_label";
5195 case DW_TAG_lexical_block: return "DW_TAG_lexical_block";
5196 case DW_TAG_member: return "DW_TAG_member";
5197 case DW_TAG_pointer_type: return "DW_TAG_pointer_type";
5198 case DW_TAG_reference_type: return "DW_TAG_reference_type";
5199 case DW_TAG_compile_unit: return "DW_TAG_compile_unit";
5200 case DW_TAG_string_type: return "DW_TAG_string_type";
5201 case DW_TAG_structure_type: return "DW_TAG_structure_type";
5202 case DW_TAG_subroutine_type: return "DW_TAG_subroutine_type";
5203 case DW_TAG_typedef: return "DW_TAG_typedef";
5204 case DW_TAG_union_type: return "DW_TAG_union_type";
5205 case DW_TAG_unspecified_parameters: return "DW_TAG_unspecified_parameters";
5206 case DW_TAG_variant: return "DW_TAG_variant";
5207 case DW_TAG_common_block: return "DW_TAG_common_block";
5208 case DW_TAG_common_inclusion: return "DW_TAG_common_inclusion";
5209 case DW_TAG_inheritance: return "DW_TAG_inheritance";
5210 case DW_TAG_inlined_subroutine: return "DW_TAG_inlined_subroutine";
5211 case DW_TAG_module: return "DW_TAG_module";
5212 case DW_TAG_ptr_to_member_type: return "DW_TAG_ptr_to_member_type";
5213 case DW_TAG_set_type: return "DW_TAG_set_type";
5214 case DW_TAG_subrange_type: return "DW_TAG_subrange_type";
5215 case DW_TAG_with_stmt: return "DW_TAG_with_stmt";
5216 case DW_TAG_access_declaration: return "DW_TAG_access_declaration";
5217 case DW_TAG_base_type: return "DW_TAG_base_type";
5218 case DW_TAG_catch_block: return "DW_TAG_catch_block";
5219 case DW_TAG_const_type: return "DW_TAG_const_type";
5220 case DW_TAG_constant: return "DW_TAG_constant";
5221 case DW_TAG_enumerator: return "DW_TAG_enumerator";
5222 case DW_TAG_file_type: return "DW_TAG_file_type";
5223 case DW_TAG_friend: return "DW_TAG_friend";
5224 case DW_TAG_namelist: return "DW_TAG_namelist";
5225 case DW_TAG_namelist_item: return "DW_TAG_namelist_item";
5226 case DW_TAG_packed_type: return "DW_TAG_packed_type";
5227 case DW_TAG_subprogram: return "DW_TAG_subprogram";
5228 case DW_TAG_template_type_param: return "DW_TAG_template_type_param";
5229 case DW_TAG_template_value_param: return "DW_TAG_template_value_param";
5230 case DW_TAG_thrown_type: return "DW_TAG_thrown_type";
5231 case DW_TAG_try_block: return "DW_TAG_try_block";
5232 case DW_TAG_variant_part: return "DW_TAG_variant_part";
5233 case DW_TAG_variable: return "DW_TAG_variable";
5234 case DW_TAG_volatile_type: return "DW_TAG_volatile_type";
5235 case DW_TAG_MIPS_loop: return "DW_TAG_MIPS_loop";
5236 case DW_TAG_format_label: return "DW_TAG_format_label";
5237 case DW_TAG_function_template: return "DW_TAG_function_template";
5238 case DW_TAG_class_template: return "DW_TAG_class_template";
5241 static char buffer [100];
5243 sprintf (buffer, _("Unknown TAG value: %lx"), tag);
5250 get_AT_name (attribute)
5251 unsigned long attribute;
5255 case DW_AT_sibling: return "DW_AT_sibling";
5256 case DW_AT_location: return "DW_AT_location";
5257 case DW_AT_name: return "DW_AT_name";
5258 case DW_AT_ordering: return "DW_AT_ordering";
5259 case DW_AT_subscr_data: return "DW_AT_subscr_data";
5260 case DW_AT_byte_size: return "DW_AT_byte_size";
5261 case DW_AT_bit_offset: return "DW_AT_bit_offset";
5262 case DW_AT_bit_size: return "DW_AT_bit_size";
5263 case DW_AT_element_list: return "DW_AT_element_list";
5264 case DW_AT_stmt_list: return "DW_AT_stmt_list";
5265 case DW_AT_low_pc: return "DW_AT_low_pc";
5266 case DW_AT_high_pc: return "DW_AT_high_pc";
5267 case DW_AT_language: return "DW_AT_language";
5268 case DW_AT_member: return "DW_AT_member";
5269 case DW_AT_discr: return "DW_AT_discr";
5270 case DW_AT_discr_value: return "DW_AT_discr_value";
5271 case DW_AT_visibility: return "DW_AT_visibility";
5272 case DW_AT_import: return "DW_AT_import";
5273 case DW_AT_string_length: return "DW_AT_string_length";
5274 case DW_AT_common_reference: return "DW_AT_common_reference";
5275 case DW_AT_comp_dir: return "DW_AT_comp_dir";
5276 case DW_AT_const_value: return "DW_AT_const_value";
5277 case DW_AT_containing_type: return "DW_AT_containing_type";
5278 case DW_AT_default_value: return "DW_AT_default_value";
5279 case DW_AT_inline: return "DW_AT_inline";
5280 case DW_AT_is_optional: return "DW_AT_is_optional";
5281 case DW_AT_lower_bound: return "DW_AT_lower_bound";
5282 case DW_AT_producer: return "DW_AT_producer";
5283 case DW_AT_prototyped: return "DW_AT_prototyped";
5284 case DW_AT_return_addr: return "DW_AT_return_addr";
5285 case DW_AT_start_scope: return "DW_AT_start_scope";
5286 case DW_AT_stride_size: return "DW_AT_stride_size";
5287 case DW_AT_upper_bound: return "DW_AT_upper_bound";
5288 case DW_AT_abstract_origin: return "DW_AT_abstract_origin";
5289 case DW_AT_accessibility: return "DW_AT_accessibility";
5290 case DW_AT_address_class: return "DW_AT_address_class";
5291 case DW_AT_artificial: return "DW_AT_artificial";
5292 case DW_AT_base_types: return "DW_AT_base_types";
5293 case DW_AT_calling_convention: return "DW_AT_calling_convention";
5294 case DW_AT_count: return "DW_AT_count";
5295 case DW_AT_data_member_location: return "DW_AT_data_member_location";
5296 case DW_AT_decl_column: return "DW_AT_decl_column";
5297 case DW_AT_decl_file: return "DW_AT_decl_file";
5298 case DW_AT_decl_line: return "DW_AT_decl_line";
5299 case DW_AT_declaration: return "DW_AT_declaration";
5300 case DW_AT_discr_list: return "DW_AT_discr_list";
5301 case DW_AT_encoding: return "DW_AT_encoding";
5302 case DW_AT_external: return "DW_AT_external";
5303 case DW_AT_frame_base: return "DW_AT_frame_base";
5304 case DW_AT_friend: return "DW_AT_friend";
5305 case DW_AT_identifier_case: return "DW_AT_identifier_case";
5306 case DW_AT_macro_info: return "DW_AT_macro_info";
5307 case DW_AT_namelist_items: return "DW_AT_namelist_items";
5308 case DW_AT_priority: return "DW_AT_priority";
5309 case DW_AT_segment: return "DW_AT_segment";
5310 case DW_AT_specification: return "DW_AT_specification";
5311 case DW_AT_static_link: return "DW_AT_static_link";
5312 case DW_AT_type: return "DW_AT_type";
5313 case DW_AT_use_location: return "DW_AT_use_location";
5314 case DW_AT_variable_parameter: return "DW_AT_variable_parameter";
5315 case DW_AT_virtuality: return "DW_AT_virtuality";
5316 case DW_AT_vtable_elem_location: return "DW_AT_vtable_elem_location";
5317 case DW_AT_MIPS_fde: return "DW_AT_MIPS_fde";
5318 case DW_AT_MIPS_loop_begin: return "DW_AT_MIPS_loop_begin";
5319 case DW_AT_MIPS_tail_loop_begin: return "DW_AT_MIPS_tail_loop_begin";
5320 case DW_AT_MIPS_epilog_begin: return "DW_AT_MIPS_epilog_begin";
5321 case DW_AT_MIPS_loop_unroll_factor: return "DW_AT_MIPS_loop_unroll_factor";
5322 case DW_AT_MIPS_software_pipeline_depth: return "DW_AT_MIPS_software_pipeline_depth";
5323 case DW_AT_MIPS_linkage_name: return "DW_AT_MIPS_linkage_name";
5324 case DW_AT_MIPS_stride: return "DW_AT_MIPS_stride";
5325 case DW_AT_MIPS_abstract_name: return "DW_AT_MIPS_abstract_name";
5326 case DW_AT_MIPS_clone_origin: return "DW_AT_MIPS_clone_origin";
5327 case DW_AT_MIPS_has_inlines: return "DW_AT_MIPS_has_inlines";
5328 case DW_AT_sf_names: return "DW_AT_sf_names";
5329 case DW_AT_src_info: return "DW_AT_src_info";
5330 case DW_AT_mac_info: return "DW_AT_mac_info";
5331 case DW_AT_src_coords: return "DW_AT_src_coords";
5332 case DW_AT_body_begin: return "DW_AT_body_begin";
5333 case DW_AT_body_end: return "DW_AT_body_end";
5336 static char buffer [100];
5338 sprintf (buffer, _("Unknown AT value: %lx"), attribute);
5345 get_FORM_name (form)
5350 case DW_FORM_addr: return "DW_FORM_addr";
5351 case DW_FORM_block2: return "DW_FORM_block2";
5352 case DW_FORM_block4: return "DW_FORM_block4";
5353 case DW_FORM_data2: return "DW_FORM_data2";
5354 case DW_FORM_data4: return "DW_FORM_data4";
5355 case DW_FORM_data8: return "DW_FORM_data8";
5356 case DW_FORM_string: return "DW_FORM_string";
5357 case DW_FORM_block: return "DW_FORM_block";
5358 case DW_FORM_block1: return "DW_FORM_block1";
5359 case DW_FORM_data1: return "DW_FORM_data1";
5360 case DW_FORM_flag: return "DW_FORM_flag";
5361 case DW_FORM_sdata: return "DW_FORM_sdata";
5362 case DW_FORM_strp: return "DW_FORM_strp";
5363 case DW_FORM_udata: return "DW_FORM_udata";
5364 case DW_FORM_ref_addr: return "DW_FORM_ref_addr";
5365 case DW_FORM_ref1: return "DW_FORM_ref1";
5366 case DW_FORM_ref2: return "DW_FORM_ref2";
5367 case DW_FORM_ref4: return "DW_FORM_ref4";
5368 case DW_FORM_ref8: return "DW_FORM_ref8";
5369 case DW_FORM_ref_udata: return "DW_FORM_ref_udata";
5370 case DW_FORM_indirect: return "DW_FORM_indirect";
5373 static char buffer [100];
5375 sprintf (buffer, _("Unknown FORM value: %lx"), form);
5381 /* FIXME: There are better and more effiecint ways to handle
5382 these structures. For now though, I just want something that
5383 is simple to implement. */
5384 typedef struct abbrev_attr
5386 unsigned long attribute;
5388 struct abbrev_attr * next;
5392 typedef struct abbrev_entry
5394 unsigned long entry;
5397 struct abbrev_attr * first_attr;
5398 struct abbrev_attr * last_attr;
5399 struct abbrev_entry * next;
5403 static abbrev_entry * first_abbrev = NULL;
5404 static abbrev_entry * last_abbrev = NULL;
5407 free_abbrevs PARAMS ((void))
5409 abbrev_entry * abbrev;
5411 for (abbrev = first_abbrev; abbrev;)
5413 abbrev_entry * next = abbrev->next;
5416 for (attr = abbrev->first_attr; attr;)
5418 abbrev_attr * next = attr->next;
5428 last_abbrev = first_abbrev = NULL;
5432 add_abbrev (number, tag, children)
5433 unsigned long number;
5437 abbrev_entry * entry;
5439 entry = (abbrev_entry *) malloc (sizeof (* entry));
5445 entry->entry = number;
5447 entry->children = children;
5448 entry->first_attr = NULL;
5449 entry->last_attr = NULL;
5452 if (first_abbrev == NULL)
5453 first_abbrev = entry;
5455 last_abbrev->next = entry;
5457 last_abbrev = entry;
5461 add_abbrev_attr (attribute, form)
5462 unsigned long attribute;
5467 attr = (abbrev_attr *) malloc (sizeof (* attr));
5473 attr->attribute = attribute;
5477 if (last_abbrev->first_attr == NULL)
5478 last_abbrev->first_attr = attr;
5480 last_abbrev->last_attr->next = attr;
5482 last_abbrev->last_attr = attr;
5485 /* Processes the (partial) contents of a .debug_abbrev section.
5486 Returns NULL if the end of the section was encountered.
5487 Returns the address after the last byte read if the end of
5488 an abbreviation set was found. */
5490 static unsigned char *
5491 process_abbrev_section (start, end)
5492 unsigned char * start;
5493 unsigned char * end;
5495 if (first_abbrev != NULL)
5501 unsigned long entry;
5503 unsigned long attribute;
5506 entry = read_leb128 (start, & bytes_read, 0);
5507 start += bytes_read;
5509 /* A single zero is supposed to end the section according
5510 to the standard. If there's more, then signal that to
5513 return start == end ? NULL : start;
5515 tag = read_leb128 (start, & bytes_read, 0);
5516 start += bytes_read;
5518 children = * start ++;
5520 add_abbrev (entry, tag, children);
5526 attribute = read_leb128 (start, & bytes_read, 0);
5527 start += bytes_read;
5529 form = read_leb128 (start, & bytes_read, 0);
5530 start += bytes_read;
5533 add_abbrev_attr (attribute, form);
5535 while (attribute != 0);
5543 display_debug_abbrev (section, start, file)
5544 Elf32_Internal_Shdr * section;
5545 unsigned char * start;
5546 FILE * file ATTRIBUTE_UNUSED;
5548 abbrev_entry * entry;
5549 unsigned char * end = start + section->sh_size;
5551 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section));
5555 start = process_abbrev_section (start, end);
5557 printf (_(" Number TAG\n"));
5559 for (entry = first_abbrev; entry; entry = entry->next)
5563 printf (_(" %ld %s [%s]\n"),
5565 get_TAG_name (entry->tag),
5566 entry->children ? _("has children") : _("no children"));
5568 for (attr = entry->first_attr; attr; attr = attr->next)
5570 printf (_(" %-18s %s\n"),
5571 get_AT_name (attr->attribute),
5572 get_FORM_name (attr->form));
5584 static unsigned char *
5585 display_block (data, length)
5586 unsigned char * data;
5587 unsigned long length;
5589 printf (_(" %lu byte block: "), length);
5592 printf ("%lx ", (unsigned long) byte_get (data ++, 1));
5598 decode_location_expression (data, pointer_size, length)
5599 unsigned char * data;
5600 unsigned int pointer_size;
5601 unsigned long length;
5605 unsigned long uvalue;
5606 unsigned char *end = data + length;
5615 printf ("DW_OP_addr: %lx",
5616 (unsigned long) byte_get (data, pointer_size));
5617 data += pointer_size;
5620 printf ("DW_OP_deref");
5623 printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data++, 1));
5626 printf ("DW_OP_const1s: %ld", (long) byte_get (data++, 1));
5629 printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data, 2));
5633 printf ("DW_OP_const2s: %ld", (long) byte_get (data, 2));
5637 printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data, 4));
5641 printf ("DW_OP_const4s: %ld", (long) byte_get (data, 4));
5645 printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data, 4),
5646 (unsigned long) byte_get (data + 4, 4));
5650 printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data, 4),
5651 (long) byte_get (data + 4, 4));
5655 printf ("DW_OP_constu: %lu", read_leb128 (data, &bytes_read, 0));
5659 printf ("DW_OP_consts: %ld", read_leb128 (data, &bytes_read, 1));
5663 printf ("DW_OP_dup");
5666 printf ("DW_OP_drop");
5669 printf ("DW_OP_over");
5672 printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data++, 1));
5675 printf ("DW_OP_swap");
5678 printf ("DW_OP_rot");
5681 printf ("DW_OP_xderef");
5684 printf ("DW_OP_abs");
5687 printf ("DW_OP_and");
5690 printf ("DW_OP_div");
5693 printf ("DW_OP_minus");
5696 printf ("DW_OP_mod");
5699 printf ("DW_OP_mul");
5702 printf ("DW_OP_neg");
5705 printf ("DW_OP_not");
5708 printf ("DW_OP_or");
5711 printf ("DW_OP_plus");
5713 case DW_OP_plus_uconst:
5714 printf ("DW_OP_plus_uconst: %lu",
5715 read_leb128 (data, &bytes_read, 0));
5719 printf ("DW_OP_shl");
5722 printf ("DW_OP_shr");
5725 printf ("DW_OP_shra");
5728 printf ("DW_OP_xor");
5731 printf ("DW_OP_bra: %ld", (long) byte_get (data, 2));
5735 printf ("DW_OP_eq");
5738 printf ("DW_OP_ge");
5741 printf ("DW_OP_gt");
5744 printf ("DW_OP_le");
5747 printf ("DW_OP_lt");
5750 printf ("DW_OP_ne");
5753 printf ("DW_OP_skip: %ld", (long) byte_get (data, 2));
5789 printf ("DW_OP_lit%d", op - DW_OP_lit0);
5824 printf ("DW_OP_reg%d", op - DW_OP_reg0);
5859 printf ("DW_OP_breg%d: %ld", op - DW_OP_breg0,
5860 read_leb128 (data, &bytes_read, 1));
5865 printf ("DW_OP_regx: %lu", read_leb128 (data, &bytes_read, 0));
5869 printf ("DW_OP_fbreg: %ld", read_leb128 (data, &bytes_read, 1));
5873 uvalue = read_leb128 (data, &bytes_read, 0);
5875 printf ("DW_OP_bregx: %lu %ld", uvalue,
5876 read_leb128 (data, &bytes_read, 1));
5880 printf ("DW_OP_piece: %lu", read_leb128 (data, &bytes_read, 0));
5883 case DW_OP_deref_size:
5884 printf ("DW_OP_deref_size: %ld", (long) byte_get (data++, 1));
5886 case DW_OP_xderef_size:
5887 printf ("DW_OP_xderef_size: %ld", (long) byte_get (data++, 1));
5890 printf ("DW_OP_nop");
5894 if (op >= DW_OP_lo_user
5895 && op <= DW_OP_hi_user)
5896 printf (_("(User defined location op)"));
5898 printf (_("(Unknown location op)"));
5899 /* No way to tell where the next op is, so just bail. */
5906 static unsigned char *
5907 read_and_display_attr (attribute, form, data, cu_offset, pointer_size)
5908 unsigned long attribute;
5910 unsigned char * data;
5911 unsigned long cu_offset;
5912 unsigned long pointer_size;
5914 unsigned long uvalue = 0;
5915 unsigned char * block_start = NULL;
5918 printf (" %-18s:", get_AT_name (attribute));
5922 case DW_FORM_ref_addr:
5924 uvalue = byte_get (data, pointer_size);
5925 data += pointer_size;
5931 uvalue = byte_get (data ++, 1);
5936 uvalue = byte_get (data, 2);
5942 uvalue = byte_get (data, 4);
5947 uvalue = read_leb128 (data, & bytes_read, 1);
5951 case DW_FORM_ref_udata:
5953 uvalue = read_leb128 (data, & bytes_read, 0);
5960 case DW_FORM_ref_addr:
5961 printf (" <#%lx>", uvalue);
5967 case DW_FORM_ref_udata:
5968 printf (" <%lx>", uvalue + cu_offset);
5972 printf (" %#lx", uvalue);
5980 printf (" %ld", uvalue);
5985 uvalue = byte_get (data, 4);
5986 printf (" %lx", uvalue);
5987 printf (" %lx", (unsigned long) byte_get (data + 4, 4));
5991 case DW_FORM_string:
5992 printf (" %s", data);
5993 data += strlen (data) + 1;
5997 uvalue = read_leb128 (data, & bytes_read, 0);
5998 block_start = data + bytes_read;
5999 data = display_block (block_start, uvalue);
6002 case DW_FORM_block1:
6003 uvalue = byte_get (data, 1);
6004 block_start = data + 1;
6005 data = display_block (block_start, uvalue);
6008 case DW_FORM_block2:
6009 uvalue = byte_get (data, 2);
6010 block_start = data + 2;
6011 data = display_block (block_start, uvalue);
6014 case DW_FORM_block4:
6015 uvalue = byte_get (data, 4);
6016 block_start = data + 4;
6017 data = display_block (block_start, uvalue);
6021 case DW_FORM_indirect:
6022 warn (_("Unable to handle FORM: %d"), form);
6026 warn (_("Unrecognised form: %d"), form);
6030 /* For some attributes we can display futher information. */
6039 case DW_INL_not_inlined: printf (_("(not inlined)")); break;
6040 case DW_INL_inlined: printf (_("(inlined)")); break;
6041 case DW_INL_declared_not_inlined: printf (_("(declared as inline but ignored)")); break;
6042 case DW_INL_declared_inlined: printf (_("(declared as inline and inlined)")); break;
6043 default: printf (_(" (Unknown inline attribute value: %lx)"), uvalue); break;
6047 case DW_AT_language:
6050 case DW_LANG_C: printf ("(non-ANSI C)"); break;
6051 case DW_LANG_C89: printf ("(ANSI C)"); break;
6052 case DW_LANG_C_plus_plus: printf ("(C++)"); break;
6053 case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break;
6054 case DW_LANG_Fortran90: printf ("(Fortran 90)"); break;
6055 case DW_LANG_Modula2: printf ("(Modula 2)"); break;
6056 case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break;
6057 case DW_LANG_Ada83: printf ("(Ada)"); break;
6058 case DW_LANG_Cobol74: printf ("(Cobol 74)"); break;
6059 case DW_LANG_Cobol85: printf ("(Cobol 85)"); break;
6060 case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break;
6061 default: printf ("(Unknown: %lx)", uvalue); break;
6065 case DW_AT_encoding:
6068 case DW_ATE_void: printf ("(void)"); break;
6069 case DW_ATE_address: printf ("(machine address)"); break;
6070 case DW_ATE_boolean: printf ("(boolean)"); break;
6071 case DW_ATE_complex_float: printf ("(complex float)"); break;
6072 case DW_ATE_float: printf ("(float)"); break;
6073 case DW_ATE_signed: printf ("(signed)"); break;
6074 case DW_ATE_signed_char: printf ("(signed char)"); break;
6075 case DW_ATE_unsigned: printf ("(unsigned)"); break;
6076 case DW_ATE_unsigned_char: printf ("(unsigned char)"); break;
6078 if (uvalue >= DW_ATE_lo_user
6079 && uvalue <= DW_ATE_hi_user)
6080 printf ("(user defined type)");
6082 printf ("(unknown type)");
6087 case DW_AT_accessibility:
6090 case DW_ACCESS_public: printf ("(public)"); break;
6091 case DW_ACCESS_protected: printf ("(protected)"); break;
6092 case DW_ACCESS_private: printf ("(private)"); break;
6093 default: printf ("(unknown accessibility)"); break;
6097 case DW_AT_visibility:
6100 case DW_VIS_local: printf ("(local)"); break;
6101 case DW_VIS_exported: printf ("(exported)"); break;
6102 case DW_VIS_qualified: printf ("(qualified)"); break;
6103 default: printf ("(unknown visibility)"); break;
6107 case DW_AT_virtuality:
6110 case DW_VIRTUALITY_none: printf ("(none)"); break;
6111 case DW_VIRTUALITY_virtual: printf ("(virtual)"); break;
6112 case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break;
6113 default: printf ("(unknown virtuality)"); break;
6117 case DW_AT_identifier_case:
6120 case DW_ID_case_sensitive: printf ("(case_sensitive)"); break;
6121 case DW_ID_up_case: printf ("(up_case)"); break;
6122 case DW_ID_down_case: printf ("(down_case)"); break;
6123 case DW_ID_case_insensitive: printf ("(case_insensitive)"); break;
6124 default: printf ("(unknown case)"); break;
6128 case DW_AT_calling_convention:
6131 case DW_CC_normal: printf ("(normal)"); break;
6132 case DW_CC_program: printf ("(program)"); break;
6133 case DW_CC_nocall: printf ("(nocall)"); break;
6135 if (uvalue >= DW_CC_lo_user
6136 && uvalue <= DW_CC_hi_user)
6137 printf ("(user defined)");
6139 printf ("(unknown convention)");
6143 case DW_AT_frame_base:
6144 case DW_AT_location:
6145 case DW_AT_data_member_location:
6146 case DW_AT_vtable_elem_location:
6150 decode_location_expression (block_start, pointer_size, uvalue);
6164 display_debug_info (section, start, file)
6165 Elf32_Internal_Shdr * section;
6166 unsigned char * start;
6169 unsigned char * end = start + section->sh_size;
6170 unsigned char * section_begin = start;
6172 printf (_("The section %s contains:\n\n"), SECTION_NAME (section));
6176 DWARF2_External_CompUnit * external;
6177 DWARF2_Internal_CompUnit compunit;
6178 unsigned char * tags;
6181 unsigned long cu_offset;
6183 external = (DWARF2_External_CompUnit *) start;
6185 compunit.cu_length = BYTE_GET (external->cu_length);
6186 compunit.cu_version = BYTE_GET (external->cu_version);
6187 compunit.cu_abbrev_offset = BYTE_GET (external->cu_abbrev_offset);
6188 compunit.cu_pointer_size = BYTE_GET (external->cu_pointer_size);
6190 tags = start + sizeof (* external);
6191 cu_offset = start - section_begin;
6192 start += compunit.cu_length + sizeof (external->cu_length);
6194 if (compunit.cu_version != 2)
6196 warn (_("Only version 2 DWARF debug information is currently supported.\n"));
6200 printf (_(" Compilation Unit:\n"));
6201 printf (_(" Length: %ld\n"), compunit.cu_length);
6202 printf (_(" Version: %d\n"), compunit.cu_version);
6203 printf (_(" Abbrev Offset: %ld\n"), compunit.cu_abbrev_offset);
6204 printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size);
6206 if (first_abbrev != NULL)
6209 /* Read in the abbrevs used by this compilation unit. */
6212 Elf32_Internal_Shdr * sec;
6213 unsigned char * begin;
6215 /* Locate the .debug_abbrev section and process it. */
6216 for (i = 0, sec = section_headers;
6217 i < elf_header.e_shnum;
6219 if (strcmp (SECTION_NAME (sec), ".debug_abbrev") == 0)
6222 if (i == -1 || sec->sh_size == 0)
6224 warn (_("Unable to locate .debug_abbrev section!\n"));
6228 GET_DATA_ALLOC (sec->sh_offset, sec->sh_size, begin, unsigned char *,
6229 "debug_abbrev section data");
6231 process_abbrev_section (begin + compunit.cu_abbrev_offset,
6232 begin + sec->sh_size);
6238 while (tags < start)
6241 unsigned long abbrev_number;
6242 abbrev_entry * entry;
6245 abbrev_number = read_leb128 (tags, & bytes_read, 0);
6248 /* A null DIE marks the end of a list of children. */
6249 if (abbrev_number == 0)
6255 /* Scan through the abbreviation list until we reach the
6257 for (entry = first_abbrev;
6258 entry && entry->entry != abbrev_number;
6259 entry = entry->next)
6264 warn (_("Unable to locate entry %lu in the abbreviation table\n"),
6269 printf (_(" <%d><%x>: Abbrev Number: %lu (%s)\n"),
6270 level, tags - section_begin - bytes_read,
6272 get_TAG_name (entry->tag));
6274 for (attr = entry->first_attr; attr; attr = attr->next)
6275 tags = read_and_display_attr (attr->attribute,
6278 compunit.cu_pointer_size);
6280 if (entry->children)
6291 display_debug_aranges (section, start, file)
6292 Elf32_Internal_Shdr * section;
6293 unsigned char * start;
6294 FILE * file ATTRIBUTE_UNUSED;
6296 unsigned char * end = start + section->sh_size;
6298 printf (_("The section %s contains:\n\n"), SECTION_NAME (section));
6302 DWARF2_External_ARange * external;
6303 DWARF2_Internal_ARange arange;
6304 unsigned char * ranges;
6305 unsigned long length;
6306 unsigned long address;
6309 external = (DWARF2_External_ARange *) start;
6311 arange.ar_length = BYTE_GET (external->ar_length);
6312 arange.ar_version = BYTE_GET (external->ar_version);
6313 arange.ar_info_offset = BYTE_GET (external->ar_info_offset);
6314 arange.ar_pointer_size = BYTE_GET (external->ar_pointer_size);
6315 arange.ar_segment_size = BYTE_GET (external->ar_segment_size);
6317 printf (_(" Length: %ld\n"), arange.ar_length);
6318 printf (_(" Version: %d\n"), arange.ar_version);
6319 printf (_(" Offset into .debug_info: %lx\n"), arange.ar_info_offset);
6320 printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
6321 printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
6323 printf (_("\n Address Length\n"));
6325 ranges = start + sizeof (* external);
6327 /* Must pad to an alignment boundary that is twice the pointer size. */
6328 excess = sizeof (*external) % (2 * arange.ar_pointer_size);
6330 ranges += (2 * arange.ar_pointer_size) - excess;
6334 address = byte_get (ranges, arange.ar_pointer_size);
6336 ranges += arange.ar_pointer_size;
6338 length = byte_get (ranges, arange.ar_pointer_size);
6340 ranges += arange.ar_pointer_size;
6342 /* A pair of zeros marks the end of the list. */
6343 if (address == 0 && length == 0)
6346 printf (" %8.8lx %lu\n", address, length);
6349 start += arange.ar_length + sizeof (external->ar_length);
6359 display_debug_not_supported (section, start, file)
6360 Elf32_Internal_Shdr * section;
6361 unsigned char * start ATTRIBUTE_UNUSED;
6362 FILE * file ATTRIBUTE_UNUSED;
6364 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
6365 SECTION_NAME (section));
6370 /* Pre-scan the .debug_info section to record the size of address.
6371 When dumping the .debug_line, we use that size information, assuming
6372 that all compilation units have the same address size. */
6374 prescan_debug_info (section, start, file)
6375 Elf32_Internal_Shdr * section ATTRIBUTE_UNUSED;
6376 unsigned char * start;
6377 FILE * file ATTRIBUTE_UNUSED;
6379 DWARF2_External_CompUnit * external;
6381 external = (DWARF2_External_CompUnit *) start;
6383 debug_line_pointer_size = BYTE_GET (external->cu_pointer_size);
6387 /* A structure containing the name of a debug section and a pointer
6388 to a function that can decode it. The third field is a prescan
6389 function to be run over the section before displaying any of the
6394 int (* display) PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
6395 int (* prescan) PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
6399 { ".debug_info", display_debug_info, prescan_debug_info },
6400 { ".debug_abbrev", display_debug_abbrev, NULL },
6401 { ".debug_line", display_debug_lines, NULL },
6402 { ".debug_aranges", display_debug_aranges, NULL },
6403 { ".debug_pubnames", display_debug_pubnames, NULL },
6404 { ".debug_macinfo", display_debug_not_supported, NULL },
6405 { ".debug_frame", display_debug_not_supported, NULL },
6406 { ".debug_str", display_debug_not_supported, NULL },
6407 { ".debug_static_func", display_debug_not_supported, NULL },
6408 { ".debug_static_vars", display_debug_not_supported, NULL },
6409 { ".debug_types", display_debug_not_supported, NULL },
6410 { ".debug_weaknames", display_debug_not_supported, NULL }
6414 display_debug_section (section, file)
6415 Elf32_Internal_Shdr * section;
6418 char * name = SECTION_NAME (section);
6419 bfd_size_type length;
6420 unsigned char * start;
6423 length = section->sh_size;
6426 printf (_("\nSection '%s' has no debugging data.\n"), name);
6430 GET_DATA_ALLOC (section->sh_offset, length, start, unsigned char *,
6431 "debug section data");
6433 /* See if we know how to display the contents of this section. */
6434 for (i = NUM_ELEM (debug_displays); i--;)
6435 if (strcmp (debug_displays[i].name, name) == 0)
6437 debug_displays[i].display (section, start, file);
6442 printf (_("Unrecognised debug section: %s\n"), name);
6446 /* If we loaded in the abbrev section at some point,
6447 we must release it here. */
6448 if (first_abbrev != NULL)
6455 process_section_contents (file)
6458 Elf32_Internal_Shdr * section;
6464 /* Pre-scan the debug sections to find some debug information not
6465 present in some of them. For the .debug_line, we must find out the
6466 size of address (specified in .debug_info and .debug_aranges). */
6467 for (i = 0, section = section_headers;
6468 i < elf_header.e_shnum && i < num_dump_sects;
6471 char * name = SECTION_NAME (section);
6474 if (section->sh_size == 0)
6477 /* See if there is some pre-scan operation for this section. */
6478 for (j = NUM_ELEM (debug_displays); j--;)
6479 if (strcmp (debug_displays[j].name, name) == 0)
6481 if (debug_displays[j].prescan != NULL)
6483 bfd_size_type length;
6484 unsigned char * start;
6486 length = section->sh_size;
6487 GET_DATA_ALLOC (section->sh_offset, length, start, unsigned char *,
6488 "debug section data");
6490 debug_displays[j].prescan (section, start, file);
6498 for (i = 0, section = section_headers;
6499 i < elf_header.e_shnum && i < num_dump_sects;
6502 #ifdef SUPPORT_DISASSEMBLY
6503 if (dump_sects[i] & DISASS_DUMP)
6504 disassemble_section (section, file);
6506 if (dump_sects[i] & HEX_DUMP)
6507 dump_section (section, file);
6509 if (dump_sects[i] & DEBUG_DUMP)
6510 display_debug_section (section, file);
6513 if (i < num_dump_sects)
6514 warn (_("Some sections were not dumped because they do not exist!\n"));
6520 process_mips_fpe_exception (mask)
6526 if (mask & OEX_FPU_INEX)
6527 fputs ("INEX", stdout), first = 0;
6528 if (mask & OEX_FPU_UFLO)
6529 printf ("%sUFLO", first ? "" : "|"), first = 0;
6530 if (mask & OEX_FPU_OFLO)
6531 printf ("%sOFLO", first ? "" : "|"), first = 0;
6532 if (mask & OEX_FPU_DIV0)
6533 printf ("%sDIV0", first ? "" : "|"), first = 0;
6534 if (mask & OEX_FPU_INVAL)
6535 printf ("%sINVAL", first ? "" : "|");
6538 fputs ("0", stdout);
6542 process_mips_specific (file)
6545 Elf_Internal_Dyn * entry;
6546 size_t liblist_offset = 0;
6547 size_t liblistno = 0;
6548 size_t conflictsno = 0;
6549 size_t options_offset = 0;
6550 size_t conflicts_offset = 0;
6552 /* We have a lot of special sections. Thanks SGI! */
6553 if (dynamic_segment == NULL)
6554 /* No information available. */
6557 for (entry = dynamic_segment; entry->d_tag != DT_NULL; ++entry)
6558 switch (entry->d_tag)
6560 case DT_MIPS_LIBLIST:
6561 liblist_offset = entry->d_un.d_val - loadaddr;
6563 case DT_MIPS_LIBLISTNO:
6564 liblistno = entry->d_un.d_val;
6566 case DT_MIPS_OPTIONS:
6567 options_offset = entry->d_un.d_val - loadaddr;
6569 case DT_MIPS_CONFLICT:
6570 conflicts_offset = entry->d_un.d_val - loadaddr;
6572 case DT_MIPS_CONFLICTNO:
6573 conflictsno = entry->d_un.d_val;
6579 if (liblist_offset != 0 && liblistno != 0 && do_dynamic)
6581 Elf32_External_Lib * elib;
6584 GET_DATA_ALLOC (liblist_offset, liblistno * sizeof (Elf32_External_Lib),
6585 elib, Elf32_External_Lib *, "liblist");
6587 printf ("\nSection '.liblist' contains %lu entries:\n",
6588 (unsigned long) liblistno);
6589 fputs (" Library Time Stamp Checksum Version Flags\n",
6592 for (cnt = 0; cnt < liblistno; ++cnt)
6599 liblist.l_name = BYTE_GET (elib[cnt].l_name);
6600 time = BYTE_GET (elib[cnt].l_time_stamp);
6601 liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum);
6602 liblist.l_version = BYTE_GET (elib[cnt].l_version);
6603 liblist.l_flags = BYTE_GET (elib[cnt].l_flags);
6605 tmp = gmtime (&time);
6606 sprintf (timebuf, "%04u-%02u-%02uT%02u:%02u:%02u",
6607 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
6608 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
6610 printf ("%3lu: %-20s %s %#10lx %-7ld", (unsigned long) cnt,
6611 dynamic_strings + liblist.l_name, timebuf,
6612 liblist.l_checksum, liblist.l_version);
6614 if (liblist.l_flags == 0)
6625 { " EXACT_MATCH", LL_EXACT_MATCH },
6626 { " IGNORE_INT_VER", LL_IGNORE_INT_VER },
6627 { " REQUIRE_MINOR", LL_REQUIRE_MINOR },
6628 { " EXPORTS", LL_EXPORTS },
6629 { " DELAY_LOAD", LL_DELAY_LOAD },
6630 { " DELTA", LL_DELTA }
6632 int flags = liblist.l_flags;
6636 fcnt < sizeof (l_flags_vals) / sizeof (l_flags_vals[0]);
6638 if ((flags & l_flags_vals[fcnt].bit) != 0)
6640 fputs (l_flags_vals[fcnt].name, stdout);
6641 flags ^= l_flags_vals[fcnt].bit;
6644 printf (" %#x", (unsigned int) flags);
6653 if (options_offset != 0)
6655 Elf_External_Options * eopt;
6656 Elf_Internal_Shdr * sect = section_headers;
6657 Elf_Internal_Options * iopt;
6658 Elf_Internal_Options * option;
6662 /* Find the section header so that we get the size. */
6663 while (sect->sh_type != SHT_MIPS_OPTIONS)
6666 GET_DATA_ALLOC (options_offset, sect->sh_size, eopt,
6667 Elf_External_Options *, "options");
6669 iopt = (Elf_Internal_Options *) malloc ((sect->sh_size / sizeof (eopt))
6673 error (_("Out of memory"));
6680 while (offset < sect->sh_size)
6682 Elf_External_Options * eoption;
6684 eoption = (Elf_External_Options *) ((char *) eopt + offset);
6686 option->kind = BYTE_GET (eoption->kind);
6687 option->size = BYTE_GET (eoption->size);
6688 option->section = BYTE_GET (eoption->section);
6689 option->info = BYTE_GET (eoption->info);
6691 offset += option->size;
6697 printf (_("\nSection '%s' contains %d entries:\n"),
6698 string_table + sect->sh_name, cnt);
6706 switch (option->kind)
6709 /* This shouldn't happen. */
6710 printf (" NULL %d %lx", option->section, option->info);
6713 printf (" REGINFO ");
6714 if (elf_header.e_machine == EM_MIPS)
6717 Elf32_External_RegInfo *ereg;
6718 Elf32_RegInfo reginfo;
6720 ereg = (Elf32_External_RegInfo *) (option + 1);
6721 reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask);
6722 reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
6723 reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
6724 reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
6725 reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
6726 reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value);
6728 printf ("GPR %08lx GP 0x%lx\n",
6730 (unsigned long) reginfo.ri_gp_value);
6731 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
6732 reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
6733 reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
6738 Elf64_External_RegInfo * ereg;
6739 Elf64_Internal_RegInfo reginfo;
6741 ereg = (Elf64_External_RegInfo *) (option + 1);
6742 reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask);
6743 reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
6744 reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
6745 reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
6746 reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
6747 reginfo.ri_gp_value = BYTE_GET8 (ereg->ri_gp_value);
6749 printf ("GPR %08lx GP 0x",
6750 reginfo.ri_gprmask);
6751 printf_vma (reginfo.ri_gp_value);
6754 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
6755 reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
6756 reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
6760 case ODK_EXCEPTIONS:
6761 fputs (" EXCEPTIONS fpe_min(", stdout);
6762 process_mips_fpe_exception (option->info & OEX_FPU_MIN);
6763 fputs (") fpe_max(", stdout);
6764 process_mips_fpe_exception ((option->info & OEX_FPU_MAX) >> 8);
6765 fputs (")", stdout);
6767 if (option->info & OEX_PAGE0)
6768 fputs (" PAGE0", stdout);
6769 if (option->info & OEX_SMM)
6770 fputs (" SMM", stdout);
6771 if (option->info & OEX_FPDBUG)
6772 fputs (" FPDBUG", stdout);
6773 if (option->info & OEX_DISMISS)
6774 fputs (" DISMISS", stdout);
6777 fputs (" PAD ", stdout);
6778 if (option->info & OPAD_PREFIX)
6779 fputs (" PREFIX", stdout);
6780 if (option->info & OPAD_POSTFIX)
6781 fputs (" POSTFIX", stdout);
6782 if (option->info & OPAD_SYMBOL)
6783 fputs (" SYMBOL", stdout);
6786 fputs (" HWPATCH ", stdout);
6787 if (option->info & OHW_R4KEOP)
6788 fputs (" R4KEOP", stdout);
6789 if (option->info & OHW_R8KPFETCH)
6790 fputs (" R8KPFETCH", stdout);
6791 if (option->info & OHW_R5KEOP)
6792 fputs (" R5KEOP", stdout);
6793 if (option->info & OHW_R5KCVTL)
6794 fputs (" R5KCVTL", stdout);
6797 fputs (" FILL ", stdout);
6798 /* XXX Print content of info word? */
6801 fputs (" TAGS ", stdout);
6802 /* XXX Print content of info word? */
6805 fputs (" HWAND ", stdout);
6806 if (option->info & OHWA0_R4KEOP_CHECKED)
6807 fputs (" R4KEOP_CHECKED", stdout);
6808 if (option->info & OHWA0_R4KEOP_CLEAN)
6809 fputs (" R4KEOP_CLEAN", stdout);
6812 fputs (" HWOR ", stdout);
6813 if (option->info & OHWA0_R4KEOP_CHECKED)
6814 fputs (" R4KEOP_CHECKED", stdout);
6815 if (option->info & OHWA0_R4KEOP_CLEAN)
6816 fputs (" R4KEOP_CLEAN", stdout);
6819 printf (" GP_GROUP %#06lx self-contained %#06lx",
6820 option->info & OGP_GROUP,
6821 (option->info & OGP_SELF) >> 16);
6824 printf (" IDENT %#06lx self-contained %#06lx",
6825 option->info & OGP_GROUP,
6826 (option->info & OGP_SELF) >> 16);
6829 /* This shouldn't happen. */
6830 printf (" %3d ??? %d %lx",
6831 option->kind, option->section, option->info);
6835 len = sizeof (*eopt);
6836 while (len < option->size)
6837 if (((char *) option)[len] >= ' '
6838 && ((char *) option)[len] < 0x7f)
6839 printf ("%c", ((char *) option)[len++]);
6841 printf ("\\%03o", ((char *) option)[len++]);
6843 fputs ("\n", stdout);
6850 if (conflicts_offset != 0 && conflictsno != 0)
6852 Elf32_External_Conflict * econf32;
6853 Elf64_External_Conflict * econf64;
6854 Elf32_Conflict * iconf;
6857 if (dynamic_symbols == NULL)
6859 error (_("conflict list with without table"));
6863 iconf = (Elf32_Conflict *) malloc (conflictsno * sizeof (*iconf));
6866 error (_("Out of memory"));
6872 GET_DATA_ALLOC (conflicts_offset, conflictsno * sizeof (*econf32),
6873 econf32, Elf32_External_Conflict *, "conflict");
6875 for (cnt = 0; cnt < conflictsno; ++cnt)
6876 iconf[cnt] = BYTE_GET (econf32[cnt]);
6880 GET_DATA_ALLOC (conflicts_offset, conflictsno * sizeof (*econf64),
6881 econf64, Elf64_External_Conflict *, "conflict");
6883 for (cnt = 0; cnt < conflictsno; ++cnt)
6884 iconf[cnt] = BYTE_GET (econf64[cnt]);
6887 printf (_("\nSection '.conflict' contains %d entries:\n"), conflictsno);
6888 puts (_(" Num: Index Value Name"));
6890 for (cnt = 0; cnt < conflictsno; ++cnt)
6892 Elf_Internal_Sym * psym = &dynamic_symbols[iconf[cnt]];
6894 printf ("%5lu: %8lu ", (unsigned long) cnt, iconf[cnt]);
6895 print_vma (psym->st_value, FULL_HEX);
6896 printf (" %s\n", dynamic_strings + psym->st_name);
6906 get_note_type (e_type)
6909 static char buff[64];
6913 case NT_PRSTATUS: return _("NT_PRSTATUS (prstatus structure)");
6914 case NT_FPREGSET: return _("NT_FPREGSET (floating point registers)");
6915 case NT_PRPSINFO: return _("NT_PRPSINFO (prpsinfo structure)");
6916 case NT_TASKSTRUCT: return _("NT_TASKSTRUCT (task structure)");
6917 case NT_PRXFPREG: return _("NT_PRXFPREG (user_xfpregs structure)");
6918 case NT_PSTATUS: return _("NT_PSTATUS (pstatus structure)");
6919 case NT_FPREGS: return _("NT_FPREGS (floating point registers)");
6920 case NT_PSINFO: return _("NT_PSINFO (psinfo structure)");
6921 case NT_LWPSTATUS: return _("NT_LWPSTATUS (lwpstatus_t structure)");
6922 case NT_LWPSINFO: return _("NT_LWPSINFO (lwpsinfo_t structure)");
6923 case NT_WIN32PSTATUS: return _("NT_WIN32PSTATUS (win32_pstatus strcuture)");
6925 sprintf (buff, _("Unknown note type: (0x%08x)"), e_type);
6930 /* Note that by the ELF standard, the name field is already null byte
6931 terminated, and namesz includes the terminating null byte.
6932 I.E. the value of namesz for the name "FSF" is 4.
6934 If the value of namesz is zero, there is no name present. */
6936 process_note (pnote)
6937 Elf32_Internal_Note * pnote;
6939 printf (" %s\t\t0x%08lx\t%s\n",
6940 pnote->namesz ? pnote->namedata : "(NONE)",
6941 pnote->descsz, get_note_type (pnote->type));
6947 process_corefile_note_segment (file, offset, length)
6952 Elf_External_Note * pnotes;
6953 Elf_External_Note * external;
6959 GET_DATA_ALLOC (offset, length, pnotes, Elf_External_Note *, "notes");
6963 printf (_("\nNotes at offset 0x%08lx with length 0x%08lx:\n"),
6964 (unsigned long) offset, (unsigned long) length);
6965 printf (_(" Owner\t\tData size\tDescription\n"));
6967 while (external < (Elf_External_Note *)((char *) pnotes + length))
6969 Elf32_Internal_Note inote;
6972 inote.type = BYTE_GET (external->type);
6973 inote.namesz = BYTE_GET (external->namesz);
6974 inote.namedata = external->name;
6975 inote.descsz = BYTE_GET (external->descsz);
6976 inote.descdata = inote.namedata + align_power (inote.namesz, 2);
6977 inote.descpos = offset + (inote.descdata - (char *) pnotes);
6979 external = (Elf_External_Note *)(inote.descdata + align_power (inote.descsz, 2));
6981 /* Verify that name is null terminated. It appears that at least
6982 one version of Linux (RedHat 6.0) generates corefiles that don't
6983 comply with the ELF spec by failing to include the null byte in
6985 if (inote.namedata[inote.namesz] != '\0')
6987 temp = malloc (inote.namesz + 1);
6991 error (_("Out of memory\n"));
6996 strncpy (temp, inote.namedata, inote.namesz);
6997 temp[inote.namesz] = 0;
6999 /* warn (_("'%s' NOTE name not properly null terminated\n"), temp); */
7000 inote.namedata = temp;
7003 res &= process_note (& inote);
7018 process_corefile_note_segments (file)
7021 Elf_Internal_Phdr * program_headers;
7022 Elf_Internal_Phdr * segment;
7026 program_headers = (Elf_Internal_Phdr *) malloc
7027 (elf_header.e_phnum * sizeof (Elf_Internal_Phdr));
7029 if (program_headers == NULL)
7031 error (_("Out of memory\n"));
7036 i = get_32bit_program_headers (file, program_headers);
7038 i = get_64bit_program_headers (file, program_headers);
7042 free (program_headers);
7046 for (i = 0, segment = program_headers;
7047 i < elf_header.e_phnum;
7050 if (segment->p_type == PT_NOTE)
7051 res &= process_corefile_note_segment (file,
7052 (bfd_vma) segment->p_offset,
7053 (bfd_vma) segment->p_filesz);
7056 free (program_headers);
7062 process_corefile_contents (file)
7065 /* If we have not been asked to display the notes then do nothing. */
7069 /* If file is not a core file then exit. */
7070 if (elf_header.e_type != ET_CORE)
7073 /* No program headers means no NOTE segment. */
7074 if (elf_header.e_phnum == 0)
7076 printf (_("No note segments present in the core file.\n"));
7080 return process_corefile_note_segments (file);
7084 process_arch_specific (file)
7090 switch (elf_header.e_machine)
7093 case EM_MIPS_RS4_BE:
7094 return process_mips_specific (file);
7103 get_file_header (file)
7106 /* Read in the identity array. */
7107 if (fread (elf_header.e_ident, EI_NIDENT, 1, file) != 1)
7110 /* Determine how to read the rest of the header. */
7111 switch (elf_header.e_ident [EI_DATA])
7113 default: /* fall through */
7114 case ELFDATANONE: /* fall through */
7115 case ELFDATA2LSB: byte_get = byte_get_little_endian; break;
7116 case ELFDATA2MSB: byte_get = byte_get_big_endian; break;
7119 /* For now we only support 32 bit and 64 bit ELF files. */
7120 is_32bit_elf = (elf_header.e_ident [EI_CLASS] != ELFCLASS64);
7122 /* Read in the rest of the header. */
7125 Elf32_External_Ehdr ehdr32;
7127 if (fread (ehdr32.e_type, sizeof (ehdr32) - EI_NIDENT, 1, file) != 1)
7130 elf_header.e_type = BYTE_GET (ehdr32.e_type);
7131 elf_header.e_machine = BYTE_GET (ehdr32.e_machine);
7132 elf_header.e_version = BYTE_GET (ehdr32.e_version);
7133 elf_header.e_entry = BYTE_GET (ehdr32.e_entry);
7134 elf_header.e_phoff = BYTE_GET (ehdr32.e_phoff);
7135 elf_header.e_shoff = BYTE_GET (ehdr32.e_shoff);
7136 elf_header.e_flags = BYTE_GET (ehdr32.e_flags);
7137 elf_header.e_ehsize = BYTE_GET (ehdr32.e_ehsize);
7138 elf_header.e_phentsize = BYTE_GET (ehdr32.e_phentsize);
7139 elf_header.e_phnum = BYTE_GET (ehdr32.e_phnum);
7140 elf_header.e_shentsize = BYTE_GET (ehdr32.e_shentsize);
7141 elf_header.e_shnum = BYTE_GET (ehdr32.e_shnum);
7142 elf_header.e_shstrndx = BYTE_GET (ehdr32.e_shstrndx);
7146 Elf64_External_Ehdr ehdr64;
7148 /* If we have been compiled with sizeof (bfd_vma) == 4, then
7149 we will not be able to cope with the 64bit data found in
7150 64 ELF files. Detect this now and abort before we start
7151 overwritting things. */
7152 if (sizeof (bfd_vma) < 8)
7154 error (_("This instance of readelf has been built without support for a\n"));
7155 error (_("64 bit data type and so it cannot read 64 bit ELF files.\n"));
7159 if (fread (ehdr64.e_type, sizeof (ehdr64) - EI_NIDENT, 1, file) != 1)
7162 elf_header.e_type = BYTE_GET (ehdr64.e_type);
7163 elf_header.e_machine = BYTE_GET (ehdr64.e_machine);
7164 elf_header.e_version = BYTE_GET (ehdr64.e_version);
7165 elf_header.e_entry = BYTE_GET8 (ehdr64.e_entry);
7166 elf_header.e_phoff = BYTE_GET8 (ehdr64.e_phoff);
7167 elf_header.e_shoff = BYTE_GET8 (ehdr64.e_shoff);
7168 elf_header.e_flags = BYTE_GET (ehdr64.e_flags);
7169 elf_header.e_ehsize = BYTE_GET (ehdr64.e_ehsize);
7170 elf_header.e_phentsize = BYTE_GET (ehdr64.e_phentsize);
7171 elf_header.e_phnum = BYTE_GET (ehdr64.e_phnum);
7172 elf_header.e_shentsize = BYTE_GET (ehdr64.e_shentsize);
7173 elf_header.e_shnum = BYTE_GET (ehdr64.e_shnum);
7174 elf_header.e_shstrndx = BYTE_GET (ehdr64.e_shstrndx);
7181 process_file (file_name)
7185 struct stat statbuf;
7188 if (stat (file_name, & statbuf) < 0)
7190 error (_("Cannot stat input file %s.\n"), file_name);
7194 file = fopen (file_name, "rb");
7197 error (_("Input file %s not found.\n"), file_name);
7201 if (! get_file_header (file))
7203 error (_("%s: Failed to read file header\n"), file_name);
7208 /* Initialise per file variables. */
7209 for (i = NUM_ELEM (version_info); i--;)
7210 version_info[i] = 0;
7212 for (i = NUM_ELEM (dynamic_info); i--;)
7213 dynamic_info[i] = 0;
7215 /* Process the file. */
7217 printf (_("\nFile: %s\n"), file_name);
7219 if (! process_file_header ())
7225 process_section_headers (file);
7227 process_program_headers (file);
7229 process_dynamic_segment (file);
7231 process_relocs (file);
7233 process_symbol_table (file);
7235 process_syminfo (file);
7237 process_version_sections (file);
7239 process_section_contents (file);
7241 process_corefile_contents (file);
7243 process_arch_specific (file);
7247 if (section_headers)
7249 free (section_headers);
7250 section_headers = NULL;
7255 free (string_table);
7256 string_table = NULL;
7259 if (dynamic_strings)
7261 free (dynamic_strings);
7262 dynamic_strings = NULL;
7265 if (dynamic_symbols)
7267 free (dynamic_symbols);
7268 dynamic_symbols = NULL;
7269 num_dynamic_syms = 0;
7272 if (dynamic_syminfo)
7274 free (dynamic_syminfo);
7275 dynamic_syminfo = NULL;
7279 #ifdef SUPPORT_DISASSEMBLY
7280 /* Needed by the i386 disassembler. For extra credit, someone could
7281 fix this so that we insert symbolic addresses here, esp for GOT/PLT
7285 print_address (unsigned int addr, FILE * outfile)
7287 fprintf (outfile,"0x%8.8x", addr);
7290 /* Needed by the i386 disassembler. */
7292 db_task_printsym (unsigned int addr)
7294 print_address (addr, stderr);
7303 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
7304 setlocale (LC_MESSAGES, "");
7306 bindtextdomain (PACKAGE, LOCALEDIR);
7307 textdomain (PACKAGE);
7309 parse_args (argc, argv);
7311 if (optind < (argc - 1))
7314 while (optind < argc)
7315 process_file (argv [optind ++]);
7317 if (dump_sects != NULL)