1 /* readelf.c -- display contents of an ELF format file
2 Copyright (C) 1998, 1999 Free Software Foundation, Inc.
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
31 /* Define BFD64 here, even if our default architecture is 32 bit ELF
32 as this will allow us to read in and parse 64bit and 32bit ELF files.
33 Only do this if we belive that the compiler can support a 64 bit
34 data type. For now we only rely on GCC being able to do this. */
40 #include "elf/common.h"
41 #include "elf/external.h"
42 #include "elf/internal.h"
43 #include "elf/dwarf2.h"
45 /* The following headers use the elf/reloc-macros.h file to
46 automatically generate relocation recognition functions
47 such as elf_mips_reloc_type() */
49 #define RELOC_MACROS_GEN_FUNC
55 #include "elf/alpha.h"
58 #include "elf/sparc.h"
63 #include "elf/mn10200.h"
64 #include "elf/mn10300.h"
68 #include "elf/mcore.h"
75 #ifdef ANSI_PROTOTYPES
81 char * program_name = "readelf";
82 unsigned int dynamic_addr;
83 bfd_size_type dynamic_size;
84 unsigned int rela_addr;
85 unsigned int rela_size;
86 char * dynamic_strings;
88 unsigned long num_dynamic_syms;
89 Elf_Internal_Sym * dynamic_symbols;
90 Elf_Internal_Syminfo * dynamic_syminfo;
91 unsigned long dynamic_syminfo_offset;
92 unsigned int dynamic_syminfo_nent;
93 char program_interpreter [64];
94 int dynamic_info[DT_JMPREL + 1];
97 Elf_Internal_Ehdr elf_header;
98 Elf_Internal_Shdr * section_headers;
99 Elf_Internal_Dyn * dynamic_segment;
106 int do_using_dynamic;
113 int do_debug_abbrevs;
115 int do_debug_pubnames;
116 int do_debug_aranges;
121 /* A dynamic array of flags indicating which sections require dumping. */
122 char * dump_sects = NULL;
123 unsigned int num_dump_sects = 0;
125 #define HEX_DUMP (1 << 0)
126 #define DISASS_DUMP (1 << 1)
127 #define DEBUG_DUMP (1 << 2)
129 /* Forward declarations for dumb compilers. */
130 static bfd_vma (* byte_get) PARAMS ((unsigned char *, int));
131 static bfd_vma byte_get_little_endian PARAMS ((unsigned char *, int));
132 static bfd_vma byte_get_big_endian PARAMS ((unsigned char *, int));
133 static const char * get_mips_dynamic_type PARAMS ((unsigned long));
134 static const char * get_sparc64_dynamic_type PARAMS ((unsigned long));
135 static const char * get_parisc_dynamic_type PARAMS ((unsigned long));
136 static const char * get_dynamic_type PARAMS ((unsigned long));
137 static int dump_relocations PARAMS ((FILE *, unsigned long, unsigned long, Elf_Internal_Sym *, unsigned long, char *, int));
138 static char * get_file_type PARAMS ((unsigned));
139 static char * get_machine_name PARAMS ((unsigned));
140 static char * get_machine_flags PARAMS ((unsigned, unsigned));
141 static const char * get_mips_segment_type PARAMS ((unsigned long));
142 static const char * get_parisc_segment_type PARAMS ((unsigned long));
143 static const char * get_segment_type PARAMS ((unsigned long));
144 static const char * get_mips_section_type_name PARAMS ((unsigned int));
145 static const char * get_parisc_section_type_name PARAMS ((unsigned int));
146 static const char * get_section_type_name PARAMS ((unsigned int));
147 static char * get_symbol_binding PARAMS ((unsigned int));
148 static char * get_symbol_type PARAMS ((unsigned int));
149 static void usage PARAMS ((void));
150 static void parse_args PARAMS ((int, char **));
151 static int process_file_header PARAMS ((void));
152 static int process_program_headers PARAMS ((FILE *));
153 static int process_section_headers PARAMS ((FILE *));
154 static void dynamic_segment_mips_val PARAMS ((Elf_Internal_Dyn *));
155 static void dynamic_segment_parisc_val PARAMS ((Elf_Internal_Dyn *));
156 static int process_dynamic_segment PARAMS ((FILE *));
157 static int process_symbol_table PARAMS ((FILE *));
158 static int process_section_contents PARAMS ((FILE *));
159 static void process_file PARAMS ((char *));
160 static int process_relocs PARAMS ((FILE *));
161 static int process_version_sections PARAMS ((FILE *));
162 static char * get_ver_flags PARAMS ((unsigned int));
163 static char * get_symbol_index_type PARAMS ((unsigned int));
164 static int get_32bit_section_headers PARAMS ((FILE *));
165 static int get_64bit_section_headers PARAMS ((FILE *));
166 static int get_32bit_program_headers PARAMS ((FILE *, Elf_Internal_Phdr *));
167 static int get_64bit_program_headers PARAMS ((FILE *, Elf_Internal_Phdr *));
168 static int get_file_header PARAMS ((FILE *));
169 static Elf_Internal_Sym * get_32bit_elf_symbols PARAMS ((FILE *, unsigned long, unsigned long));
170 static Elf_Internal_Sym * get_64bit_elf_symbols PARAMS ((FILE *, unsigned long, unsigned long));
171 static int * get_dynamic_data PARAMS ((FILE *, unsigned int));
172 static int get_32bit_dynamic_segment PARAMS ((FILE *));
173 static int get_64bit_dynamic_segment PARAMS ((FILE *));
174 #ifdef SUPPORT_DISASSEMBLY
175 static int disassemble_section PARAMS ((Elf32_Internal_Shdr *, FILE *));
177 static int dump_section PARAMS ((Elf32_Internal_Shdr *, FILE *));
178 static int display_debug_section PARAMS ((Elf32_Internal_Shdr *, FILE *));
179 static int display_debug_info PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
180 static int display_debug_not_supported PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
181 static int display_debug_lines PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
182 static int display_debug_abbrev PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
183 static int display_debug_aranges PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
184 static unsigned char * process_abbrev_section PARAMS ((unsigned char *, unsigned char *));
185 static unsigned long read_leb128 PARAMS ((unsigned char *, int *, int));
186 static int process_extended_line_op PARAMS ((unsigned char *, int, int));
187 static void reset_state_machine PARAMS ((int));
188 static char * get_TAG_name PARAMS ((unsigned long));
189 static char * get_AT_name PARAMS ((unsigned long));
190 static char * get_FORM_name PARAMS ((unsigned long));
191 static void free_abbrevs PARAMS ((void));
192 static void add_abbrev PARAMS ((unsigned long, unsigned long, int));
193 static void add_abbrev_attr PARAMS ((unsigned long, unsigned long));
194 static unsigned char * read_and_display_attr PARAMS ((unsigned long, unsigned long, unsigned char *, unsigned long));
195 static unsigned char * display_block PARAMS ((unsigned char *, unsigned long));
196 static void decode_location_expression PARAMS ((unsigned char *, unsigned int));
197 static void request_dump PARAMS ((unsigned int, char));
198 static const char * get_elf_class PARAMS ((unsigned char));
199 static const char * get_data_encoding PARAMS ((unsigned char));
200 static const char * get_osabi_name PARAMS ((unsigned char));
201 static int guess_is_rela PARAMS ((unsigned long));
202 static char * get_note_type PARAMS ((unsigned int));
203 static int process_note PARAMS ((Elf32_Internal_Note *));
204 static int process_corefile_note_segment PARAMS ((FILE *, unsigned long, unsigned long));
205 static int process_corefile_note_segments PARAMS ((FILE *));
206 static int process_corefile_contents PARAMS ((FILE *));
208 typedef int Elf32_Word;
216 #define SECTION_NAME(X) (string_table + (X)->sh_name)
218 #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
220 #define BYTE_GET(field) byte_get (field, sizeof (field))
222 /* If we can support a 64 bit data type then BFD64 should be defined
223 and sizeof (bfd_vma) == 8. In this case when translating from an
224 external 8 byte field to an internal field, we can assume that the
225 internal field is also 8 bytes wide and so we can extact all the data.
226 If, however, BFD64 is not defined, then we must assume that the
227 internal data structure only has 4 byte wide fields that are the
228 equivalent of the 8 byte wide external counterparts, and so we must
229 truncate the data. */
231 #define BYTE_GET8(field) byte_get (field, -8)
233 #define BYTE_GET8(field) byte_get (field, 8)
236 #define NUM_ELEM(array) (sizeof (array) / sizeof ((array)[0]))
238 #define GET_DATA_ALLOC(offset, size, var, type, reason) \
239 if (fseek (file, offset, SEEK_SET)) \
241 error (_("Unable to seek to start of %s at %x\n"), reason, offset); \
245 var = (type) malloc (size); \
249 error (_("Out of memory allocating %d bytes for %s\n"), size, reason); \
253 if (fread (var, size, 1, file) != 1) \
255 error (_("Unable to read in %d bytes of %s\n"), size, reason); \
262 #define GET_DATA(offset, var, reason) \
263 if (fseek (file, offset, SEEK_SET)) \
265 error (_("Unable to seek to %x for %s\n"), offset, reason); \
268 else if (fread (& var, sizeof (var), 1, file) != 1) \
270 error (_("Unable to read data at %x for %s\n"), offset, reason); \
274 #define GET_ELF_SYMBOLS(file, offset, size) \
275 (is_32bit_elf ? get_32bit_elf_symbols (file, offset, size) \
276 : get_64bit_elf_symbols (file, offset, size))
279 #ifdef ANSI_PROTOTYPES
281 error (const char * message, ...)
285 fprintf (stderr, _("%s: Error: "), program_name);
286 va_start (args, message);
287 vfprintf (stderr, message, args);
293 warn (const char * message, ...)
297 fprintf (stderr, _("%s: Warning: "), program_name);
298 va_start (args, message);
299 vfprintf (stderr, message, args);
311 fprintf (stderr, _("%s: Error: "), program_name);
313 message = va_arg (args, char *);
314 vfprintf (stderr, message, args);
326 fprintf (stderr, _("%s: Warning: "), program_name);
328 message = va_arg (args, char *);
329 vfprintf (stderr, message, args);
336 byte_get_little_endian (field, size)
337 unsigned char * field;
346 return ((unsigned int) (field [0]))
347 | (((unsigned int) (field [1])) << 8);
350 /* We want to extract data from an 8 byte wide field and
351 place it into a 4 byte wide field. Since this is a little
352 endian source we can juts use the 4 byte extraction code. */
355 return ((unsigned long) (field [0]))
356 | (((unsigned long) (field [1])) << 8)
357 | (((unsigned long) (field [2])) << 16)
358 | (((unsigned long) (field [3])) << 24);
362 /* This is a special case, generated by the BYTE_GET8 macro.
363 It means that we are loading an 8 byte value from a field
364 in an external structure into an 8 byte value in a field
365 in an internal strcuture. */
366 return ((bfd_vma) (field [0]))
367 | (((bfd_vma) (field [1])) << 8)
368 | (((bfd_vma) (field [2])) << 16)
369 | (((bfd_vma) (field [3])) << 24)
370 | (((bfd_vma) (field [4])) << 32)
371 | (((bfd_vma) (field [5])) << 40)
372 | (((bfd_vma) (field [6])) << 48)
373 | (((bfd_vma) (field [7])) << 56);
376 error (_("Unhandled data length: %d\n"), size);
382 byte_get_big_endian (field, size)
383 unsigned char * field;
392 return ((unsigned int) (field [1])) | (((int) (field [0])) << 8);
395 return ((unsigned long) (field [3]))
396 | (((unsigned long) (field [2])) << 8)
397 | (((unsigned long) (field [1])) << 16)
398 | (((unsigned long) (field [0])) << 24);
401 /* Although we are extracing data from an 8 byte wide field, we
402 are returning only 4 bytes of data. */
403 return ((unsigned long) (field [7]))
404 | (((unsigned long) (field [6])) << 8)
405 | (((unsigned long) (field [5])) << 16)
406 | (((unsigned long) (field [4])) << 24);
410 /* This is a special case, generated by the BYTE_GET8 macro.
411 It means that we are loading an 8 byte value from a field
412 in an external structure into an 8 byte value in a field
413 in an internal strcuture. */
414 return ((bfd_vma) (field [7]))
415 | (((bfd_vma) (field [6])) << 8)
416 | (((bfd_vma) (field [5])) << 16)
417 | (((bfd_vma) (field [4])) << 24)
418 | (((bfd_vma) (field [3])) << 32)
419 | (((bfd_vma) (field [2])) << 40)
420 | (((bfd_vma) (field [1])) << 48)
421 | (((bfd_vma) (field [0])) << 56);
425 error (_("Unhandled data length: %d\n"), size);
431 /* Guess the relocation sized based on the sized commonly used by the specific machine. */
433 guess_is_rela (e_machine)
434 unsigned long e_machine;
438 /* Targets that use REL relocations. */
449 /* Targets that use RELA relocations. */
457 case EM_CYGNUS_MN10200:
458 case EM_CYGNUS_MN10300:
466 warn (_("Don't know about relocations on this machine architecture\n"));
471 /* Display the contents of the relocation data found at the specified offset. */
473 dump_relocations (file, rel_offset, rel_size, symtab, nsyms, strtab, is_rela)
475 unsigned long rel_offset;
476 unsigned long rel_size;
477 Elf_Internal_Sym * symtab;
483 Elf_Internal_Rel * rels;
484 Elf_Internal_Rela * relas;
487 if (is_rela == UNKNOWN)
488 is_rela = guess_is_rela (elf_header.e_machine);
494 Elf32_External_Rela * erelas;
496 GET_DATA_ALLOC (rel_offset, rel_size, erelas,
497 Elf32_External_Rela *, "relocs");
499 rel_size = rel_size / sizeof (Elf32_External_Rela);
501 relas = (Elf_Internal_Rela *)
502 malloc (rel_size * sizeof (Elf_Internal_Rela));
506 error(_("out of memory parsing relocs"));
510 for (i = 0; i < rel_size; i++)
512 relas[i].r_offset = BYTE_GET (erelas[i].r_offset);
513 relas[i].r_info = BYTE_GET (erelas[i].r_info);
514 relas[i].r_addend = BYTE_GET (erelas[i].r_addend);
519 rels = (Elf_Internal_Rel *) relas;
523 Elf64_External_Rela * erelas;
525 GET_DATA_ALLOC (rel_offset, rel_size, erelas,
526 Elf64_External_Rela *, "relocs");
528 rel_size = rel_size / sizeof (Elf64_External_Rela);
530 relas = (Elf_Internal_Rela *)
531 malloc (rel_size * sizeof (Elf_Internal_Rela));
535 error(_("out of memory parsing relocs"));
539 for (i = 0; i < rel_size; i++)
541 relas[i].r_offset = BYTE_GET8 (erelas[i].r_offset);
542 relas[i].r_info = BYTE_GET8 (erelas[i].r_info);
543 relas[i].r_addend = BYTE_GET8 (erelas[i].r_addend);
548 rels = (Elf_Internal_Rel *) relas;
555 Elf32_External_Rel * erels;
557 GET_DATA_ALLOC (rel_offset, rel_size, erels,
558 Elf32_External_Rel *, "relocs");
560 rel_size = rel_size / sizeof (Elf32_External_Rel);
562 rels = (Elf_Internal_Rel *)
563 malloc (rel_size * sizeof (Elf_Internal_Rel));
567 error(_("out of memory parsing relocs"));
571 for (i = 0; i < rel_size; i++)
573 rels[i].r_offset = BYTE_GET (erels[i].r_offset);
574 rels[i].r_info = BYTE_GET (erels[i].r_info);
579 relas = (Elf_Internal_Rela *) rels;
583 Elf64_External_Rel * erels;
585 GET_DATA_ALLOC (rel_offset, rel_size, erels,
586 Elf64_External_Rel *, "relocs");
588 rel_size = rel_size / sizeof (Elf64_External_Rel);
590 rels = (Elf_Internal_Rel *)
591 malloc (rel_size * sizeof (Elf_Internal_Rel));
595 error(_("out of memory parsing relocs"));
599 for (i = 0; i < rel_size; i++)
601 rels[i].r_offset = BYTE_GET8 (erels[i].r_offset);
602 rels[i].r_info = BYTE_GET8 (erels[i].r_info);
607 relas = (Elf_Internal_Rela *) rels;
613 (_(" Offset Info Type Symbol's Value Symbol's Name Addend\n"));
616 (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
618 for (i = 0; i < rel_size; i++)
623 bfd_vma symtab_index;
628 offset = relas [i].r_offset;
629 info = relas [i].r_info;
633 offset = rels [i].r_offset;
634 info = rels [i].r_info;
639 type = ELF32_R_TYPE (info);
640 symtab_index = ELF32_R_SYM (info);
644 if (elf_header.e_machine == EM_SPARCV9)
645 type = ELF64_R_TYPE_ID (info);
647 type = ELF64_R_TYPE (info);
648 /* The #ifdef BFD64 below is to prevent a compile time warning.
649 We know that if we do not have a 64 bit data type that we
650 will never execute this code anyway. */
652 symtab_index = ELF64_R_SYM (info);
656 #ifdef _bfd_int64_low
657 printf (" %8.8lx %5.5lx ", _bfd_int64_low (offset), _bfd_int64_low (info));
659 printf (" %8.8lx %5.5lx ", offset, info);
662 switch (elf_header.e_machine)
669 rtype = elf_m32r_reloc_type (type);
674 rtype = elf_i386_reloc_type (type);
678 rtype = elf_m68k_reloc_type (type);
682 rtype = elf_i960_reloc_type (type);
689 rtype = elf_sparc_reloc_type (type);
693 rtype = v850_reloc_type (type);
697 rtype = elf_d10v_reloc_type (type);
701 rtype = elf_d30v_reloc_type (type);
705 rtype = elf_sh_reloc_type (type);
708 case EM_CYGNUS_MN10300:
709 rtype = elf_mn10300_reloc_type (type);
712 case EM_CYGNUS_MN10200:
713 rtype = elf_mn10200_reloc_type (type);
717 rtype = elf_fr30_reloc_type (type);
721 rtype = elf_mcore_reloc_type (type);
725 rtype = elf_ppc_reloc_type (type);
730 rtype = elf_mips_reloc_type (type);
734 rtype = elf_alpha_reloc_type (type);
738 rtype = elf_arm_reloc_type (type);
742 rtype = elf_arc_reloc_type (type);
746 rtype = elf_hppa_reloc_type (type);
750 rtype = elf_pj_reloc_type (type);
755 #ifdef _bfd_int64_low
756 printf (_("unrecognised: %-7lx"), _bfd_int64_low (type));
758 printf (_("unrecognised: %-7lx"), type);
761 printf ("%-21.21s", rtype);
767 if (symtab_index >= nsyms)
768 printf (" bad symbol index: %08lx", (unsigned long) symtab_index);
771 Elf_Internal_Sym * psym;
773 psym = symtab + symtab_index;
775 printf (" %08lx ", (unsigned long) psym->st_value);
777 if (psym->st_name == 0)
779 SECTION_NAME (section_headers + psym->st_shndx));
780 else if (strtab == NULL)
781 printf (_("<string table index %3ld>"), psym->st_name);
783 printf ("%-25.25s", strtab + psym->st_name);
786 printf (" + %lx", (unsigned long) relas [i].r_addend);
791 printf ("%34c%lx", ' ', (unsigned long) relas[i].r_addend);
793 if (elf_header.e_machine == EM_SPARCV9
794 && !strcmp (rtype, "R_SPARC_OLO10"))
795 printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (info));
806 get_mips_dynamic_type (type)
811 case DT_MIPS_RLD_VERSION: return "MIPS_RLD_VERSION";
812 case DT_MIPS_TIME_STAMP: return "MIPS_TIME_STAMP";
813 case DT_MIPS_ICHECKSUM: return "MIPS_ICHECKSUM";
814 case DT_MIPS_IVERSION: return "MIPS_IVERSION";
815 case DT_MIPS_FLAGS: return "MIPS_FLAGS";
816 case DT_MIPS_BASE_ADDRESS: return "MIPS_BASE_ADDRESS";
817 case DT_MIPS_MSYM: return "MIPS_MSYM";
818 case DT_MIPS_CONFLICT: return "MIPS_CONFLICT";
819 case DT_MIPS_LIBLIST: return "MIPS_LIBLIST";
820 case DT_MIPS_LOCAL_GOTNO: return "MIPS_LOCAL_GOTNO";
821 case DT_MIPS_CONFLICTNO: return "MIPS_CONFLICTNO";
822 case DT_MIPS_LIBLISTNO: return "MIPS_LIBLISTNO";
823 case DT_MIPS_SYMTABNO: return "MIPS_SYMTABNO";
824 case DT_MIPS_UNREFEXTNO: return "MIPS_UNREFEXTNO";
825 case DT_MIPS_GOTSYM: return "MIPS_GOTSYM";
826 case DT_MIPS_HIPAGENO: return "MIPS_HIPAGENO";
827 case DT_MIPS_RLD_MAP: return "MIPS_RLD_MAP";
828 case DT_MIPS_DELTA_CLASS: return "MIPS_DELTA_CLASS";
829 case DT_MIPS_DELTA_CLASS_NO: return "MIPS_DELTA_CLASS_NO";
830 case DT_MIPS_DELTA_INSTANCE: return "MIPS_DELTA_INSTANCE";
831 case DT_MIPS_DELTA_INSTANCE_NO: return "MIPS_DELTA_INSTANCE_NO";
832 case DT_MIPS_DELTA_RELOC: return "MIPS_DELTA_RELOC";
833 case DT_MIPS_DELTA_RELOC_NO: return "MIPS_DELTA_RELOC_NO";
834 case DT_MIPS_DELTA_SYM: return "MIPS_DELTA_SYM";
835 case DT_MIPS_DELTA_SYM_NO: return "MIPS_DELTA_SYM_NO";
836 case DT_MIPS_DELTA_CLASSSYM: return "MIPS_DELTA_CLASSSYM";
837 case DT_MIPS_DELTA_CLASSSYM_NO: return "MIPS_DELTA_CLASSSYM_NO";
838 case DT_MIPS_CXX_FLAGS: return "MIPS_CXX_FLAGS";
839 case DT_MIPS_PIXIE_INIT: return "MIPS_PIXIE_INIT";
840 case DT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB";
841 case DT_MIPS_LOCALPAGE_GOTIDX: return "MIPS_LOCALPAGE_GOTIDX";
842 case DT_MIPS_LOCAL_GOTIDX: return "MIPS_LOCAL_GOTIDX";
843 case DT_MIPS_HIDDEN_GOTIDX: return "MIPS_HIDDEN_GOTIDX";
844 case DT_MIPS_PROTECTED_GOTIDX: return "MIPS_PROTECTED_GOTIDX";
845 case DT_MIPS_OPTIONS: return "MIPS_OPTIONS";
846 case DT_MIPS_INTERFACE: return "MIPS_INTERFACE";
847 case DT_MIPS_DYNSTR_ALIGN: return "MIPS_DYNSTR_ALIGN";
848 case DT_MIPS_INTERFACE_SIZE: return "MIPS_INTERFACE_SIZE";
849 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
850 case DT_MIPS_PERF_SUFFIX: return "MIPS_PERF_SUFFIX";
851 case DT_MIPS_COMPACT_SIZE: return "MIPS_COMPACT_SIZE";
852 case DT_MIPS_GP_VALUE: return "MIPS_GP_VALUE";
853 case DT_MIPS_AUX_DYNAMIC: return "MIPS_AUX_DYNAMIC";
860 get_sparc64_dynamic_type (type)
865 case DT_SPARC_REGISTER: return "SPARC_REGISTER";
872 get_parisc_dynamic_type (type)
877 case DT_HP_LOAD_MAP: return "HP_LOAD_MAP";
878 case DT_HP_DLD_FLAGS: return "HP_DLD_FLAGS";
879 case DT_HP_DLD_HOOK: return "HP_DLD_HOOK";
880 case DT_HP_UX10_INIT: return "HP_UX10_INIT";
881 case DT_HP_UX10_INITSZ: return "HP_UX10_INITSZ";
882 case DT_HP_PREINIT: return "HP_PREINIT";
883 case DT_HP_PREINITSZ: return "HP_PREINITSZ";
884 case DT_HP_NEEDED: return "HP_NEEDED";
885 case DT_HP_TIME_STAMP: return "HP_TIME_STAMP";
886 case DT_HP_CHECKSUM: return "HP_CHECKSUM";
887 case DT_HP_GST_SIZE: return "HP_GST_SIZE";
888 case DT_HP_GST_VERSION: return "HP_GST_VERSION";
889 case DT_HP_GST_HASHVAL: return "HP_GST_HASHVAL";
896 get_dynamic_type (type)
899 static char buff [32];
903 case DT_NULL: return "NULL";
904 case DT_NEEDED: return "NEEDED";
905 case DT_PLTRELSZ: return "PLTRELSZ";
906 case DT_PLTGOT: return "PLTGOT";
907 case DT_HASH: return "HASH";
908 case DT_STRTAB: return "STRTAB";
909 case DT_SYMTAB: return "SYMTAB";
910 case DT_RELA: return "RELA";
911 case DT_RELASZ: return "RELASZ";
912 case DT_RELAENT: return "RELAENT";
913 case DT_STRSZ: return "STRSZ";
914 case DT_SYMENT: return "SYMENT";
915 case DT_INIT: return "INIT";
916 case DT_FINI: return "FINI";
917 case DT_SONAME: return "SONAME";
918 case DT_RPATH: return "RPATH";
919 case DT_SYMBOLIC: return "SYMBOLIC";
920 case DT_REL: return "REL";
921 case DT_RELSZ: return "RELSZ";
922 case DT_RELENT: return "RELENT";
923 case DT_PLTREL: return "PLTREL";
924 case DT_DEBUG: return "DEBUG";
925 case DT_TEXTREL: return "TEXTREL";
926 case DT_JMPREL: return "JMPREL";
927 case DT_BIND_NOW: return "BIND_NOW";
928 case DT_INIT_ARRAY: return "INIT_ARRAY";
929 case DT_FINI_ARRAY: return "FINI_ARRAY";
930 case DT_INIT_ARRAYSZ: return "INIT_ARRAYSZ";
931 case DT_FINI_ARRAYSZ: return "FINI_ARRAYSZ";
933 case DT_PLTPADSZ: return "PLTPADSZ";
934 case DT_MOVEENT: return "MOVEENT";
935 case DT_MOVESZ: return "MOVESZ";
936 case DT_FEATURE_1: return "FEATURE_1";
937 case DT_POSFLAG_1: return "POSFLAG_1";
938 case DT_SYMINSZ: return "SYMINSZ";
939 case DT_SYMINENT: return "SYMINENT"; /* aka VALRNGHI */
941 case DT_ADDRRNGLO: return "ADDRRNGLO";
942 case DT_SYMINFO: return "SYMINFO"; /* aka ADDRRNGHI */
944 case DT_VERSYM: return "VERSYM";
946 case DT_RELACOUNT: return "RELACOUNT";
947 case DT_RELCOUNT: return "RELCOUNT";
948 case DT_FLAGS_1: return "FLAGS_1";
949 case DT_VERDEF: return "VERDEF";
950 case DT_VERDEFNUM: return "VERDEFNUM";
951 case DT_VERNEED: return "VERNEED";
952 case DT_VERNEEDNUM: return "VERNEEDNUM";
954 case DT_AUXILIARY: return "AUXILARY";
955 case DT_USED: return "USED";
956 case DT_FILTER: return "FILTER";
959 if ((type >= DT_LOPROC) && (type <= DT_HIPROC))
963 switch (elf_header.e_machine)
967 result = get_mips_dynamic_type (type);
970 result = get_sparc64_dynamic_type (type);
980 sprintf (buff, _("Processor Specific: %lx"), type);
982 else if ((type >= DT_LOOS) && (type <= DT_HIOS))
986 switch (elf_header.e_machine)
989 result = get_parisc_dynamic_type (type);
999 sprintf (buff, _("Operating System specific: %lx"), type);
1002 sprintf (buff, _("<unknown>: %lx"), type);
1009 get_file_type (e_type)
1012 static char buff [32];
1016 case ET_NONE: return _("NONE (None)");
1017 case ET_REL: return _("REL (Relocatable file)");
1018 case ET_EXEC: return _("EXEC (Executable file)");
1019 case ET_DYN: return _("DYN (Shared object file)");
1020 case ET_CORE: return _("CORE (Core file)");
1023 if ((e_type >= ET_LOPROC) && (e_type <= ET_HIPROC))
1024 sprintf (buff, _("Processor Specific: (%x)"), e_type);
1025 else if ((e_type >= ET_LOOS) && (e_type <= ET_HIOS))
1026 sprintf (buff, _("OS Specific: (%x)"), e_type);
1028 sprintf (buff, _("<unknown>: %x"), e_type);
1034 get_machine_name (e_machine)
1037 static char buff [32];
1041 case EM_NONE: return _("None");
1042 case EM_M32: return "WE32100";
1043 case EM_SPARC: return "Sparc";
1044 case EM_386: return "Intel 80386";
1045 case EM_68K: return "MC68000";
1046 case EM_88K: return "MC88000";
1047 case EM_486: return "Intel 80486";
1048 case EM_860: return "Intel 80860";
1049 case EM_MIPS: return "MIPS R3000 big-endian";
1050 case EM_S370: return "Amdahl";
1051 case EM_MIPS_RS4_BE: return "MIPS R4000 big-endian";
1052 case EM_OLD_SPARCV9: return "Sparc v9 (old)";
1053 case EM_PARISC: return "HPPA";
1054 case EM_PPC_OLD: return "Power PC (old)";
1055 case EM_SPARC32PLUS: return "Sparc v8+" ;
1056 case EM_960: return "Intel 90860";
1057 case EM_PPC: return "PowerPC";
1058 case EM_V800: return "NEC V800";
1059 case EM_FR20: return "Fujitsu FR20";
1060 case EM_RH32: return "TRW RH32";
1061 case EM_MCORE: return "MCORE";
1062 case EM_ARM: return "ARM";
1063 case EM_OLD_ALPHA: return "Digital Alpha (old)";
1064 case EM_SH: return "Hitachi SH";
1065 case EM_SPARCV9: return "Sparc v9";
1066 case EM_TRICORE: return "Siemens Tricore";
1067 case EM_ARC: return "Argonaut RISC Core";
1068 case EM_H8_300: return "Hitachi H8/300";
1069 case EM_H8_300H: return "Hitachi H8/300H";
1070 case EM_H8S: return "Hitachi H8S";
1071 case EM_H8_500: return "Hitachi H8/500";
1072 case EM_IA_64: return "Intel Merced";
1073 case EM_MIPS_X: return "Stanford MIPS-X";
1074 case EM_COLDFIRE: return "Motorola Coldfire";
1075 case EM_68HC12: return "Motorola M68HC12";
1076 case EM_ALPHA: return "Alpha";
1077 case EM_CYGNUS_D10V: return "d10v";
1078 case EM_CYGNUS_D30V: return "d30v";
1079 case EM_CYGNUS_ARC: return "Arc";
1080 case EM_CYGNUS_M32R: return "Mitsubishi M32r";
1081 case EM_CYGNUS_V850: return "NEC v850";
1082 case EM_CYGNUS_MN10300: return "mn10300";
1083 case EM_CYGNUS_MN10200: return "mn10200";
1084 case EM_CYGNUS_FR30: return "Fujitsu FR30";
1085 case EM_PJ: return "picoJava";
1087 sprintf (buff, _("<unknown>: %x"), e_machine);
1093 get_machine_flags (e_flags, e_machine)
1097 static char buf [1024];
1108 if (e_flags & EF_CPU32)
1109 strcat (buf, ", cpu32");
1113 if (e_flags & EF_PPC_EMB)
1114 strcat (buf, ", emb");
1116 if (e_flags & EF_PPC_RELOCATABLE)
1117 strcat (buf, ", relocatable");
1119 if (e_flags & EF_PPC_RELOCATABLE_LIB)
1120 strcat (buf, ", relocatable-lib");
1123 case EM_CYGNUS_V850:
1124 switch (e_flags & EF_V850_ARCH)
1127 strcat (buf, ", v850e");
1130 strcat (buf, ", v850ea");
1133 strcat (buf, ", v850");
1136 strcat (buf, ", unknown v850 architecture variant");
1141 case EM_CYGNUS_M32R:
1142 if ((e_flags & EF_M32R_ARCH) == E_M32R_ARCH)
1143 strcat (buf, ", m32r");
1148 case EM_MIPS_RS4_BE:
1149 if (e_flags & EF_MIPS_NOREORDER)
1150 strcat (buf, ", noreorder");
1152 if (e_flags & EF_MIPS_PIC)
1153 strcat (buf, ", pic");
1155 if (e_flags & EF_MIPS_CPIC)
1156 strcat (buf, ", cpic");
1158 if (e_flags & EF_MIPS_ABI2)
1159 strcat (buf, ", abi2");
1161 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_1)
1162 strcat (buf, ", mips1");
1164 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_2)
1165 strcat (buf, ", mips2");
1167 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_3)
1168 strcat (buf, ", mips3");
1170 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_4)
1171 strcat (buf, ", mips4");
1175 if (e_flags & EF_SPARC_32PLUS)
1176 strcat (buf, ", v8+");
1178 if (e_flags & EF_SPARC_SUN_US1)
1179 strcat (buf, ", ultrasparcI");
1181 if (e_flags & EF_SPARC_SUN_US3)
1182 strcat (buf, ", ultrasparcIII");
1184 if (e_flags & EF_SPARC_HAL_R1)
1185 strcat (buf, ", halr1");
1187 if (e_flags & EF_SPARC_LEDATA)
1188 strcat (buf, ", ledata");
1190 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_TSO)
1191 strcat (buf, ", tso");
1193 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_PSO)
1194 strcat (buf, ", pso");
1196 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_RMO)
1197 strcat (buf, ", rmo");
1201 switch (e_flags & EF_PARISC_ARCH)
1203 case EFA_PARISC_1_0:
1204 strcpy (buf, ", PA-RISC 1.0");
1206 case EFA_PARISC_1_1:
1207 strcpy (buf, ", PA-RISC 1.1");
1209 case EFA_PARISC_2_0:
1210 strcpy (buf, ", PA-RISC 2.0");
1215 if (e_flags & EF_PARISC_TRAPNIL)
1216 strcat (buf, ", trapnil");
1217 if (e_flags & EF_PARISC_EXT)
1218 strcat (buf, ", ext");
1219 if (e_flags & EF_PARISC_LSB)
1220 strcat (buf, ", lsb");
1221 if (e_flags & EF_PARISC_WIDE)
1222 strcat (buf, ", wide");
1223 if (e_flags & EF_PARISC_NO_KABP)
1224 strcat (buf, ", no kabp");
1225 if (e_flags & EF_PARISC_LAZYSWAP)
1226 strcat (buf, ", lazyswap");
1229 if ((e_flags & EF_PICOJAVA_NEWCALLS) == EF_PICOJAVA_NEWCALLS)
1230 strcat (buf, ", new calling convention");
1232 if ((e_flags & EF_PICOJAVA_GNUCALLS) == EF_PICOJAVA_GNUCALLS)
1233 strcat (buf, ", gnu calling convention");
1242 get_mips_segment_type (type)
1247 case PT_MIPS_REGINFO:
1249 case PT_MIPS_RTPROC:
1251 case PT_MIPS_OPTIONS:
1261 get_parisc_segment_type (type)
1266 case PT_HP_TLS: return "HP_TLS";
1267 case PT_HP_CORE_NONE: return "HP_CORE_NONE";
1268 case PT_HP_CORE_VERSION: return "HP_CORE_VERSION";
1269 case PT_HP_CORE_KERNEL: return "HP_CORE_KERNEL";
1270 case PT_HP_CORE_COMM: return "HP_CORE_COMM";
1271 case PT_HP_CORE_PROC: return "HP_CORE_PROC";
1272 case PT_HP_CORE_LOADABLE: return "HP_CORE_LOADABLE";
1273 case PT_HP_CORE_STACK: return "HP_CORE_STACK";
1274 case PT_HP_CORE_SHM: return "HP_CORE_SHM";
1275 case PT_HP_CORE_MMF: return "HP_CORE_MMF";
1276 case PT_HP_PARALLEL: return "HP_PARALLEL";
1277 case PT_HP_FASTBIND: return "HP_FASTBIND";
1278 case PT_PARISC_ARCHEXT: return "PARISC_ARCHEXT";
1279 case PT_PARISC_UNWIND: return "PARISC_UNWIND";
1288 get_segment_type (p_type)
1289 unsigned long p_type;
1291 static char buff [32];
1295 case PT_NULL: return "NULL";
1296 case PT_LOAD: return "LOAD";
1297 case PT_DYNAMIC: return "DYNAMIC";
1298 case PT_INTERP: return "INTERP";
1299 case PT_NOTE: return "NOTE";
1300 case PT_SHLIB: return "SHLIB";
1301 case PT_PHDR: return "PHDR";
1304 if ((p_type >= PT_LOPROC) && (p_type <= PT_HIPROC))
1306 const char * result;
1308 switch (elf_header.e_machine)
1311 case EM_MIPS_RS4_BE:
1312 result = get_mips_segment_type (p_type);
1315 result = get_parisc_segment_type (p_type);
1325 sprintf (buff, "LOPROC+%lx", p_type - PT_LOPROC);
1327 else if ((p_type >= PT_LOOS) && (p_type <= PT_HIOS))
1329 const char * result;
1331 switch (elf_header.e_machine)
1334 result = get_parisc_segment_type (p_type);
1344 sprintf (buff, "LOOS+%lx", p_type - PT_LOOS);
1347 sprintf (buff, _("<unknown>: %lx"), p_type);
1354 get_mips_section_type_name (sh_type)
1355 unsigned int sh_type;
1359 case SHT_MIPS_LIBLIST: return "MIPS_LIBLIST";
1360 case SHT_MIPS_MSYM: return "MIPS_MSYM";
1361 case SHT_MIPS_CONFLICT: return "MIPS_CONFLICT";
1362 case SHT_MIPS_GPTAB: return "MIPS_GPTAB";
1363 case SHT_MIPS_UCODE: return "MIPS_UCODE";
1364 case SHT_MIPS_DEBUG: return "MIPS_DEBUG";
1365 case SHT_MIPS_REGINFO: return "MIPS_REGINFO";
1366 case SHT_MIPS_PACKAGE: return "MIPS_PACKAGE";
1367 case SHT_MIPS_PACKSYM: return "MIPS_PACKSYM";
1368 case SHT_MIPS_RELD: return "MIPS_RELD";
1369 case SHT_MIPS_IFACE: return "MIPS_IFACE";
1370 case SHT_MIPS_CONTENT: return "MIPS_CONTENT";
1371 case SHT_MIPS_OPTIONS: return "MIPS_OPTIONS";
1372 case SHT_MIPS_SHDR: return "MIPS_SHDR";
1373 case SHT_MIPS_FDESC: return "MIPS_FDESC";
1374 case SHT_MIPS_EXTSYM: return "MIPS_EXTSYM";
1375 case SHT_MIPS_DENSE: return "MIPS_DENSE";
1376 case SHT_MIPS_PDESC: return "MIPS_PDESC";
1377 case SHT_MIPS_LOCSYM: return "MIPS_LOCSYM";
1378 case SHT_MIPS_AUXSYM: return "MIPS_AUXSYM";
1379 case SHT_MIPS_OPTSYM: return "MIPS_OPTSYM";
1380 case SHT_MIPS_LOCSTR: return "MIPS_LOCSTR";
1381 case SHT_MIPS_LINE: return "MIPS_LINE";
1382 case SHT_MIPS_RFDESC: return "MIPS_RFDESC";
1383 case SHT_MIPS_DELTASYM: return "MIPS_DELTASYM";
1384 case SHT_MIPS_DELTAINST: return "MIPS_DELTAINST";
1385 case SHT_MIPS_DELTACLASS: return "MIPS_DELTACLASS";
1386 case SHT_MIPS_DWARF: return "MIPS_DWARF";
1387 case SHT_MIPS_DELTADECL: return "MIPS_DELTADECL";
1388 case SHT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB";
1389 case SHT_MIPS_EVENTS: return "MIPS_EVENTS";
1390 case SHT_MIPS_TRANSLATE: return "MIPS_TRANSLATE";
1391 case SHT_MIPS_PIXIE: return "MIPS_PIXIE";
1392 case SHT_MIPS_XLATE: return "MIPS_XLATE";
1393 case SHT_MIPS_XLATE_DEBUG: return "MIPS_XLATE_DEBUG";
1394 case SHT_MIPS_WHIRL: return "MIPS_WHIRL";
1395 case SHT_MIPS_EH_REGION: return "MIPS_EH_REGION";
1396 case SHT_MIPS_XLATE_OLD: return "MIPS_XLATE_OLD";
1397 case SHT_MIPS_PDR_EXCEPTION: return "MIPS_PDR_EXCEPTION";
1405 get_parisc_section_type_name (sh_type)
1406 unsigned int sh_type;
1410 case SHT_PARISC_EXT: return "PARISC_EXT";
1411 case SHT_PARISC_UNWIND: return "PARISC_UNWIND";
1412 case SHT_PARISC_DOC: return "PARISC_DOC";
1420 get_section_type_name (sh_type)
1421 unsigned int sh_type;
1423 static char buff [32];
1427 case SHT_NULL: return "NULL";
1428 case SHT_PROGBITS: return "PROGBITS";
1429 case SHT_SYMTAB: return "SYMTAB";
1430 case SHT_STRTAB: return "STRTAB";
1431 case SHT_RELA: return "RELA";
1432 case SHT_HASH: return "HASH";
1433 case SHT_DYNAMIC: return "DYNAMIC";
1434 case SHT_NOTE: return "NOTE";
1435 case SHT_NOBITS: return "NOBITS";
1436 case SHT_REL: return "REL";
1437 case SHT_SHLIB: return "SHLIB";
1438 case SHT_DYNSYM: return "DYNSYM";
1439 case SHT_GNU_verdef: return "VERDEF";
1440 case SHT_GNU_verneed: return "VERNEED";
1441 case SHT_GNU_versym: return "VERSYM";
1442 case 0x6ffffff0: return "VERSYM";
1443 case 0x6ffffffc: return "VERDEF";
1444 case 0x7ffffffd: return "AUXILIARY";
1445 case 0x7fffffff: return "FILTER";
1448 if ((sh_type >= SHT_LOPROC) && (sh_type <= SHT_HIPROC))
1450 const char * result;
1452 switch (elf_header.e_machine)
1455 case EM_MIPS_RS4_BE:
1456 result = get_mips_section_type_name (sh_type);
1459 result = get_parisc_section_type_name (sh_type);
1469 sprintf (buff, "SHT_LOPROC+%x", sh_type - SHT_LOPROC);
1471 else if ((sh_type >= SHT_LOOS) && (sh_type <= SHT_HIOS))
1472 sprintf (buff, "SHT_LOOS+%x", sh_type - SHT_LOOS);
1473 else if ((sh_type >= SHT_LOUSER) && (sh_type <= SHT_HIUSER))
1474 sprintf (buff, "SHT_LOUSER+%x", sh_type - SHT_LOUSER);
1476 sprintf (buff, _("<unknown>: %x"), sh_type);
1482 struct option options [] =
1484 {"all", no_argument, 0, 'a'},
1485 {"file-header", no_argument, 0, 'h'},
1486 {"program-headers", no_argument, 0, 'l'},
1487 {"headers", no_argument, 0, 'e'},
1488 {"histogram", no_argument, 0, 'I'},
1489 {"segments", no_argument, 0, 'l'},
1490 {"sections", no_argument, 0, 'S'},
1491 {"section-headers", no_argument, 0, 'S'},
1492 {"symbols", no_argument, 0, 's'},
1493 {"syms", no_argument, 0, 's'},
1494 {"relocs", no_argument, 0, 'r'},
1495 {"notes", no_argument, 0, 'n'},
1496 {"dynamic", no_argument, 0, 'd'},
1497 {"arch-specific", no_argument, 0, 'A'},
1498 {"version-info", no_argument, 0, 'V'},
1499 {"use-dynamic", no_argument, 0, 'D'},
1500 {"hex-dump", required_argument, 0, 'x'},
1501 {"debug-dump", optional_argument, 0, 'w'},
1502 #ifdef SUPPORT_DISASSEMBLY
1503 {"instruction-dump", required_argument, 0, 'i'},
1506 {"version", no_argument, 0, 'v'},
1507 {"help", no_argument, 0, 'H'},
1508 {0, no_argument, 0, 0}
1514 fprintf (stdout, _("Usage: readelf {options} elf-file(s)\n"));
1515 fprintf (stdout, _(" Options are:\n"));
1516 fprintf (stdout, _(" -a or --all Equivalent to: -h -l -S -s -r -d -V -A -I\n"));
1517 fprintf (stdout, _(" -h or --file-header Display the ELF file header\n"));
1518 fprintf (stdout, _(" -l or --program-headers or --segments\n"));
1519 fprintf (stdout, _(" Display the program headers\n"));
1520 fprintf (stdout, _(" -S or --section-headers or --sections\n"));
1521 fprintf (stdout, _(" Display the sections' header\n"));
1522 fprintf (stdout, _(" -e or --headers Equivalent to: -h -l -S\n"));
1523 fprintf (stdout, _(" -s or --syms or --symbols Display the symbol table\n"));
1524 fprintf (stdout, _(" -n or --notes Display the core notes (if present)\n"));
1525 fprintf (stdout, _(" -r or --relocs Display the relocations (if present)\n"));
1526 fprintf (stdout, _(" -d or --dynamic Display the dynamic segment (if present)\n"));
1527 fprintf (stdout, _(" -V or --version-info Display the version sections (if present)\n"));
1528 fprintf (stdout, _(" -A or --arch-specific Display architecture specific information (if any).\n"));
1529 fprintf (stdout, _(" -D or --use-dynamic Use the dynamic section info when displaying symbols\n"));
1530 fprintf (stdout, _(" -x <number> or --hex-dump=<number>\n"));
1531 fprintf (stdout, _(" Dump the contents of section <number>\n"));
1532 fprintf (stdout, _(" -w[liapr] or --debug-dump[=line,=info,=abbrev,=pubnames,=ranges]\n"));
1533 fprintf (stdout, _(" Display the contents of DWARF2 debug sections\n"));
1534 #ifdef SUPPORT_DISASSEMBLY
1535 fprintf (stdout, _(" -i <number> or --instruction-dump=<number>\n"));
1536 fprintf (stdout, _(" Disassemble the contents of section <number>\n"));
1538 fprintf (stdout, _(" -I or --histogram Display histogram of bucket list lengths\n"));
1539 fprintf (stdout, _(" -v or --version Display the version number of readelf\n"));
1540 fprintf (stdout, _(" -H or --help Display this information\n"));
1547 request_dump (section, type)
1548 unsigned int section;
1551 if (section >= num_dump_sects)
1553 char * new_dump_sects;
1555 new_dump_sects = (char *) calloc (section + 1, 1);
1557 if (new_dump_sects == NULL)
1558 error (_("Out of memory allocating dump request table."));
1561 /* Copy current flag settings. */
1562 memcpy (new_dump_sects, dump_sects, num_dump_sects);
1566 dump_sects = new_dump_sects;
1567 num_dump_sects = section + 1;
1572 dump_sects [section] |= type;
1578 parse_args (argc, argv)
1587 while ((c = getopt_long
1588 (argc, argv, "ersahnldSDAIw::x:i:vV", options, NULL)) != EOF)
1623 do_using_dynamic ++;
1651 section = strtoul (optarg, & cp, 0);
1652 if (! * cp && section >= 0)
1654 request_dump (section, HEX_DUMP);
1674 do_debug_abbrevs = 1;
1684 do_debug_pubnames = 1;
1689 do_debug_aranges = 1;
1693 warn (_("Unrecognised debug option '%s'\n"), optarg);
1698 #ifdef SUPPORT_DISASSEMBLY
1701 section = strtoul (optarg, & cp, 0);
1702 if (! * cp && section >= 0)
1704 request_dump (section, DISASS_DUMP);
1710 print_version (program_name);
1717 /* xgettext:c-format */
1718 error (_("Invalid option '-%c'\n"), c);
1725 if (!do_dynamic && !do_syms && !do_reloc && !do_sections
1726 && !do_segments && !do_header && !do_dump && !do_version
1727 && !do_histogram && !do_debugging && !do_arch && !do_notes)
1731 warn (_("Nothing to do.\n"));
1737 get_elf_class (elf_class)
1738 unsigned char elf_class;
1740 static char buff [32];
1744 case ELFCLASSNONE: return _("none");
1745 case ELFCLASS32: return _("ELF32");
1746 case ELFCLASS64: return _("ELF64");
1748 sprintf (buff, _("<unknown: %x>"), elf_class);
1754 get_data_encoding (encoding)
1755 unsigned char encoding;
1757 static char buff [32];
1761 case ELFDATANONE: return _("none");
1762 case ELFDATA2LSB: return _("2's complement, little endian");
1763 case ELFDATA2MSB: return _("2's complement, big endian");
1765 sprintf (buff, _("<unknown: %x>"), encoding);
1771 get_osabi_name (osabi)
1772 unsigned char osabi;
1774 static char buff [32];
1778 case ELFOSABI_SYSV: return _("UNIX - System V");
1779 case ELFOSABI_HPUX: return _("UNIX - HP-UX");
1780 case ELFOSABI_STANDALONE: return _("Standalone App");
1782 sprintf (buff, _("<unknown: %x>"), osabi);
1787 /* Decode the data held in 'elf_header'. */
1789 process_file_header ()
1791 if ( elf_header.e_ident [EI_MAG0] != ELFMAG0
1792 || elf_header.e_ident [EI_MAG1] != ELFMAG1
1793 || elf_header.e_ident [EI_MAG2] != ELFMAG2
1794 || elf_header.e_ident [EI_MAG3] != ELFMAG3)
1797 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
1805 printf (_("ELF Header:\n"));
1806 printf (_(" Magic: "));
1807 for (i = 0; i < EI_NIDENT; i ++)
1808 printf ("%2.2x ", elf_header.e_ident [i]);
1810 printf (_(" Class: %s\n"),
1811 get_elf_class (elf_header.e_ident [EI_CLASS]));
1812 printf (_(" Data: %s\n"),
1813 get_data_encoding (elf_header.e_ident [EI_DATA]));
1814 printf (_(" Version: %d %s\n"),
1815 elf_header.e_ident [EI_VERSION],
1816 (elf_header.e_ident [EI_VERSION] == EV_CURRENT
1818 : (elf_header.e_ident [EI_VERSION] != EV_NONE
1821 printf (_(" OS/ABI: %s\n"),
1822 get_osabi_name (elf_header.e_ident [EI_OSABI]));
1823 printf (_(" ABI Version: %d\n"),
1824 elf_header.e_ident [EI_ABIVERSION]);
1825 printf (_(" Type: %s\n"),
1826 get_file_type (elf_header.e_type));
1827 printf (_(" Machine: %s\n"),
1828 get_machine_name (elf_header.e_machine));
1829 printf (_(" Version: 0x%lx\n"),
1830 (unsigned long) elf_header.e_version);
1831 printf (_(" Entry point address: 0x%lx\n"),
1832 (unsigned long) elf_header.e_entry);
1833 printf (_(" Start of program headers: %ld (bytes into file)\n"),
1834 (long) elf_header.e_phoff);
1835 printf (_(" Start of section headers: %ld (bytes into file)\n"),
1836 (long) elf_header.e_shoff);
1837 printf (_(" Flags: 0x%lx%s\n"),
1838 (unsigned long) elf_header.e_flags,
1839 get_machine_flags (elf_header.e_flags, elf_header.e_machine));
1840 printf (_(" Size of this header: %ld (bytes)\n"),
1841 (long) elf_header.e_ehsize);
1842 printf (_(" Size of program headers: %ld (bytes)\n"),
1843 (long) elf_header.e_phentsize);
1844 printf (_(" Number of program headers: %ld\n"),
1845 (long) elf_header.e_phnum);
1846 printf (_(" Size of section headers: %ld (bytes)\n"),
1847 (long) elf_header.e_shentsize);
1848 printf (_(" Number of section headers: %ld\n"),
1849 (long) elf_header.e_shnum);
1850 printf (_(" Section header string table index: %ld\n"),
1851 (long) elf_header.e_shstrndx);
1859 get_32bit_program_headers (file, program_headers)
1861 Elf_Internal_Phdr * program_headers;
1863 Elf32_External_Phdr * phdrs;
1864 Elf32_External_Phdr * external;
1865 Elf32_Internal_Phdr * internal;
1868 GET_DATA_ALLOC (elf_header.e_phoff,
1869 elf_header.e_phentsize * elf_header.e_phnum,
1870 phdrs, Elf32_External_Phdr *, "program headers");
1872 for (i = 0, internal = program_headers, external = phdrs;
1873 i < elf_header.e_phnum;
1874 i ++, internal ++, external ++)
1876 internal->p_type = BYTE_GET (external->p_type);
1877 internal->p_offset = BYTE_GET (external->p_offset);
1878 internal->p_vaddr = BYTE_GET (external->p_vaddr);
1879 internal->p_paddr = BYTE_GET (external->p_paddr);
1880 internal->p_filesz = BYTE_GET (external->p_filesz);
1881 internal->p_memsz = BYTE_GET (external->p_memsz);
1882 internal->p_flags = BYTE_GET (external->p_flags);
1883 internal->p_align = BYTE_GET (external->p_align);
1892 get_64bit_program_headers (file, program_headers)
1894 Elf_Internal_Phdr * program_headers;
1896 Elf64_External_Phdr * phdrs;
1897 Elf64_External_Phdr * external;
1898 Elf64_Internal_Phdr * internal;
1901 GET_DATA_ALLOC (elf_header.e_phoff,
1902 elf_header.e_phentsize * elf_header.e_phnum,
1903 phdrs, Elf64_External_Phdr *, "program headers");
1905 for (i = 0, internal = program_headers, external = phdrs;
1906 i < elf_header.e_phnum;
1907 i ++, internal ++, external ++)
1909 internal->p_type = BYTE_GET (external->p_type);
1910 internal->p_flags = BYTE_GET (external->p_flags);
1911 internal->p_offset = BYTE_GET8 (external->p_offset);
1912 internal->p_vaddr = BYTE_GET8 (external->p_vaddr);
1913 internal->p_paddr = BYTE_GET8 (external->p_paddr);
1914 internal->p_filesz = BYTE_GET8 (external->p_filesz);
1915 internal->p_memsz = BYTE_GET8 (external->p_memsz);
1916 internal->p_align = BYTE_GET8 (external->p_align);
1925 process_program_headers (file)
1928 Elf_Internal_Phdr * program_headers;
1929 Elf_Internal_Phdr * segment;
1932 if (elf_header.e_phnum == 0)
1935 printf (_("\nThere are no program headers in this file.\n"));
1939 if (do_segments && !do_header)
1941 printf (_("\nElf file is %s\n"), get_file_type (elf_header.e_type));
1942 printf (_("Entry point 0x%lx\n"), (unsigned long) elf_header.e_entry);
1943 printf (_("There are %d program headers, starting at offset %lx:\n"),
1944 elf_header.e_phnum, (unsigned long) elf_header.e_phoff);
1947 program_headers = (Elf_Internal_Phdr *) malloc
1948 (elf_header.e_phnum * sizeof (Elf_Internal_Phdr));
1950 if (program_headers == NULL)
1952 error (_("Out of memory\n"));
1957 i = get_32bit_program_headers (file, program_headers);
1959 i = get_64bit_program_headers (file, program_headers);
1963 free (program_headers);
1970 (_("\nProgram Header%s:\n"), elf_header.e_phnum > 1 ? "s" : "");
1972 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
1979 for (i = 0, segment = program_headers;
1980 i < elf_header.e_phnum;
1985 printf (" %-14.14s ", get_segment_type (segment->p_type));
1986 printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
1987 printf ("0x%8.8lx ", (unsigned long) segment->p_vaddr);
1988 printf ("0x%8.8lx ", (unsigned long) segment->p_paddr);
1989 printf ("0x%5.5lx ", (unsigned long) segment->p_filesz);
1990 printf ("0x%5.5lx ", (unsigned long) segment->p_memsz);
1992 (segment->p_flags & PF_R ? 'R' : ' '),
1993 (segment->p_flags & PF_W ? 'W' : ' '),
1994 (segment->p_flags & PF_X ? 'E' : ' '));
1995 printf ("%#lx", (unsigned long) segment->p_align);
1998 switch (segment->p_type)
2002 loadaddr = (segment->p_vaddr & 0xfffff000)
2003 - (segment->p_offset & 0xfffff000);
2008 error (_("more than one dynamic segment\n"));
2010 dynamic_addr = segment->p_offset;
2011 dynamic_size = segment->p_filesz;
2015 if (fseek (file, segment->p_offset, SEEK_SET))
2016 error (_("Unable to find program interpreter name\n"));
2019 program_interpreter[0] = 0;
2020 fscanf (file, "%63s", program_interpreter);
2023 printf (_("\n [Requesting program interpreter: %s]"),
2024 program_interpreter);
2030 putc ('\n', stdout);
2039 if (do_segments && section_headers != NULL)
2041 printf (_("\n Section to Segment mapping:\n"));
2042 printf (_(" Segment Sections...\n"));
2044 assert (string_table != NULL);
2046 for (i = 0; i < elf_header.e_phnum; i++)
2049 Elf_Internal_Shdr * section;
2051 segment = program_headers + i;
2052 section = section_headers;
2054 printf (" %2.2d ", i);
2056 for (j = 0; j < elf_header.e_shnum; j++, section ++)
2058 if (section->sh_size > 0
2059 /* Compare allocated sections by VMA, unallocated
2060 sections by file offset. */
2061 && (section->sh_flags & SHF_ALLOC
2062 ? (section->sh_addr >= segment->p_vaddr
2063 && section->sh_addr + section->sh_size
2064 <= segment->p_vaddr + segment->p_memsz)
2065 : ((bfd_vma) section->sh_offset >= segment->p_offset
2066 && (section->sh_offset + section->sh_size
2067 <= segment->p_offset + segment->p_filesz))))
2068 printf ("%s ", SECTION_NAME (section));
2075 free (program_headers);
2082 get_32bit_section_headers (file)
2085 Elf32_External_Shdr * shdrs;
2086 Elf32_Internal_Shdr * internal;
2089 GET_DATA_ALLOC (elf_header.e_shoff,
2090 elf_header.e_shentsize * elf_header.e_shnum,
2091 shdrs, Elf32_External_Shdr *, "section headers");
2093 section_headers = (Elf_Internal_Shdr *) malloc
2094 (elf_header.e_shnum * sizeof (Elf_Internal_Shdr));
2096 if (section_headers == NULL)
2098 error (_("Out of memory\n"));
2102 for (i = 0, internal = section_headers;
2103 i < elf_header.e_shnum;
2106 internal->sh_name = BYTE_GET (shdrs[i].sh_name);
2107 internal->sh_type = BYTE_GET (shdrs[i].sh_type);
2108 internal->sh_flags = BYTE_GET (shdrs[i].sh_flags);
2109 internal->sh_addr = BYTE_GET (shdrs[i].sh_addr);
2110 internal->sh_offset = BYTE_GET (shdrs[i].sh_offset);
2111 internal->sh_size = BYTE_GET (shdrs[i].sh_size);
2112 internal->sh_link = BYTE_GET (shdrs[i].sh_link);
2113 internal->sh_info = BYTE_GET (shdrs[i].sh_info);
2114 internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
2115 internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize);
2124 get_64bit_section_headers (file)
2127 Elf64_External_Shdr * shdrs;
2128 Elf64_Internal_Shdr * internal;
2131 GET_DATA_ALLOC (elf_header.e_shoff,
2132 elf_header.e_shentsize * elf_header.e_shnum,
2133 shdrs, Elf64_External_Shdr *, "section headers");
2135 section_headers = (Elf_Internal_Shdr *) malloc
2136 (elf_header.e_shnum * sizeof (Elf_Internal_Shdr));
2138 if (section_headers == NULL)
2140 error (_("Out of memory\n"));
2144 for (i = 0, internal = section_headers;
2145 i < elf_header.e_shnum;
2148 internal->sh_name = BYTE_GET (shdrs[i].sh_name);
2149 internal->sh_type = BYTE_GET (shdrs[i].sh_type);
2150 internal->sh_flags = BYTE_GET8 (shdrs[i].sh_flags);
2151 internal->sh_addr = BYTE_GET8 (shdrs[i].sh_addr);
2152 internal->sh_size = BYTE_GET8 (shdrs[i].sh_size);
2153 internal->sh_entsize = BYTE_GET8 (shdrs[i].sh_entsize);
2154 internal->sh_link = BYTE_GET (shdrs[i].sh_link);
2155 internal->sh_info = BYTE_GET (shdrs[i].sh_info);
2156 internal->sh_offset = BYTE_GET (shdrs[i].sh_offset);
2157 internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
2165 static Elf_Internal_Sym *
2166 get_32bit_elf_symbols (file, offset, number)
2168 unsigned long offset;
2169 unsigned long number;
2171 Elf32_External_Sym * esyms;
2172 Elf_Internal_Sym * isyms;
2173 Elf_Internal_Sym * psym;
2176 GET_DATA_ALLOC (offset, number * sizeof (Elf32_External_Sym),
2177 esyms, Elf32_External_Sym *, "symbols");
2179 isyms = (Elf_Internal_Sym *) malloc (number * sizeof (Elf_Internal_Sym));
2183 error (_("Out of memory\n"));
2189 for (j = 0, psym = isyms;
2193 psym->st_name = BYTE_GET (esyms[j].st_name);
2194 psym->st_value = BYTE_GET (esyms[j].st_value);
2195 psym->st_size = BYTE_GET (esyms[j].st_size);
2196 psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
2197 psym->st_info = BYTE_GET (esyms[j].st_info);
2198 psym->st_other = BYTE_GET (esyms[j].st_other);
2206 static Elf_Internal_Sym *
2207 get_64bit_elf_symbols (file, offset, number)
2209 unsigned long offset;
2210 unsigned long number;
2212 Elf64_External_Sym * esyms;
2213 Elf_Internal_Sym * isyms;
2214 Elf_Internal_Sym * psym;
2217 GET_DATA_ALLOC (offset, number * sizeof (Elf64_External_Sym),
2218 esyms, Elf64_External_Sym *, "symbols");
2220 isyms = (Elf_Internal_Sym *) malloc (number * sizeof (Elf_Internal_Sym));
2224 error (_("Out of memory\n"));
2230 for (j = 0, psym = isyms;
2234 psym->st_name = BYTE_GET (esyms[j].st_name);
2235 psym->st_info = BYTE_GET (esyms[j].st_info);
2236 psym->st_other = BYTE_GET (esyms[j].st_other);
2237 psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
2238 psym->st_value = BYTE_GET8 (esyms[j].st_value);
2239 psym->st_size = BYTE_GET8 (esyms[j].st_size);
2248 process_section_headers (file)
2251 Elf_Internal_Shdr * section;
2254 section_headers = NULL;
2256 if (elf_header.e_shnum == 0)
2259 printf (_("\nThere are no sections in this file.\n"));
2264 if (do_sections && !do_header)
2265 printf (_("There are %d section headers, starting at offset 0x%lx:\n"),
2266 elf_header.e_shnum, (unsigned long) elf_header.e_shoff);
2270 if (! get_32bit_section_headers (file))
2273 else if (! get_64bit_section_headers (file))
2276 /* Read in the string table, so that we have names to display. */
2277 section = section_headers + elf_header.e_shstrndx;
2279 if (section->sh_size != 0)
2281 unsigned long string_table_offset;
2283 string_table_offset = section->sh_offset;
2285 GET_DATA_ALLOC (section->sh_offset, section->sh_size,
2286 string_table, char *, "string table");
2289 /* Scan the sections for the dynamic symbol table
2290 and dynamic string table and debug sections. */
2291 dynamic_symbols = NULL;
2292 dynamic_strings = NULL;
2293 dynamic_syminfo = NULL;
2295 for (i = 0, section = section_headers;
2296 i < elf_header.e_shnum;
2299 char * name = SECTION_NAME (section);
2301 if (section->sh_type == SHT_DYNSYM)
2303 if (dynamic_symbols != NULL)
2305 error (_("File contains multiple dynamic symbol tables\n"));
2309 num_dynamic_syms = section->sh_size / section->sh_entsize;
2311 GET_ELF_SYMBOLS (file, section->sh_offset, num_dynamic_syms);
2313 else if (section->sh_type == SHT_STRTAB
2314 && strcmp (name, ".dynstr") == 0)
2316 if (dynamic_strings != NULL)
2318 error (_("File contains multiple dynamic string tables\n"));
2322 GET_DATA_ALLOC (section->sh_offset, section->sh_size,
2323 dynamic_strings, char *, "dynamic strings");
2325 else if ((do_debugging || do_debug_info || do_debug_abbrevs
2326 || do_debug_lines || do_debug_pubnames || do_debug_aranges)
2327 && strncmp (name, ".debug_", 7) == 0)
2332 || (do_debug_info && (strcmp (name, "info") == 0))
2333 || (do_debug_abbrevs && (strcmp (name, "abbrev") == 0))
2334 || (do_debug_lines && (strcmp (name, "line") == 0))
2335 || (do_debug_pubnames && (strcmp (name, "pubnames") == 0))
2336 || (do_debug_aranges && (strcmp (name, "aranges") == 0))
2338 request_dump (i, DEBUG_DUMP);
2345 printf (_("\nSection Header%s:\n"), elf_header.e_shnum > 1 ? "s" : "");
2347 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
2349 for (i = 0, section = section_headers;
2350 i < elf_header.e_shnum;
2353 printf (" [%2d] %-17.17s %-15.15s ",
2355 SECTION_NAME (section),
2356 get_section_type_name (section->sh_type));
2358 printf ( "%8.8lx %6.6lx %6.6lx %2.2lx",
2359 (unsigned long) section->sh_addr,
2360 (unsigned long) section->sh_offset,
2361 (unsigned long) section->sh_size,
2362 (unsigned long) section->sh_entsize);
2364 printf (" %c%c%c %2ld %3lx %ld\n",
2365 (section->sh_flags & SHF_WRITE ? 'W' : ' '),
2366 (section->sh_flags & SHF_ALLOC ? 'A' : ' '),
2367 (section->sh_flags & SHF_EXECINSTR ? 'X' : ' '),
2368 (unsigned long) section->sh_link,
2369 (unsigned long) section->sh_info,
2370 (unsigned long) section->sh_addralign);
2376 /* Process the reloc section. */
2378 process_relocs (file)
2381 unsigned long rel_size;
2382 unsigned long rel_offset;
2388 if (do_using_dynamic)
2390 int is_rela = FALSE;
2395 if (dynamic_info[DT_REL])
2397 rel_offset = dynamic_info[DT_REL];
2398 rel_size = dynamic_info[DT_RELSZ];
2401 else if (dynamic_info [DT_RELA])
2403 rel_offset = dynamic_info[DT_RELA];
2404 rel_size = dynamic_info[DT_RELASZ];
2407 else if (dynamic_info[DT_JMPREL])
2409 rel_offset = dynamic_info[DT_JMPREL];
2410 rel_size = dynamic_info[DT_PLTRELSZ];
2412 switch (dynamic_info[DT_PLTREL])
2429 (_("\nRelocation section at offset 0x%lx contains %ld bytes:\n"),
2430 rel_offset, rel_size);
2432 dump_relocations (file, rel_offset - loadaddr, rel_size,
2433 dynamic_symbols, num_dynamic_syms, dynamic_strings, is_rela);
2436 printf (_("\nThere are no dynamic relocations in this file.\n"));
2440 Elf32_Internal_Shdr * section;
2444 for (i = 0, section = section_headers;
2445 i < elf_header.e_shnum;
2448 if ( section->sh_type != SHT_RELA
2449 && section->sh_type != SHT_REL)
2452 rel_offset = section->sh_offset;
2453 rel_size = section->sh_size;
2457 Elf32_Internal_Shdr * strsec;
2458 Elf32_Internal_Shdr * symsec;
2459 Elf_Internal_Sym * symtab;
2462 unsigned long nsyms;
2464 printf (_("\nRelocation section "));
2466 if (string_table == NULL)
2467 printf ("%d", section->sh_name);
2469 printf ("'%s'", SECTION_NAME (section));
2471 printf (_(" at offset 0x%lx contains %lu entries:\n"),
2472 rel_offset, (unsigned long) (rel_size / section->sh_entsize));
2474 symsec = section_headers + section->sh_link;
2476 nsyms = symsec->sh_size / symsec->sh_entsize;
2477 symtab = GET_ELF_SYMBOLS (file, symsec->sh_offset, nsyms);
2482 strsec = section_headers + symsec->sh_link;
2484 GET_DATA_ALLOC (strsec->sh_offset, strsec->sh_size, strtab,
2485 char *, "string table");
2487 is_rela = section->sh_type == SHT_RELA;
2489 dump_relocations (file, rel_offset, rel_size, symtab, nsyms, strtab, is_rela);
2499 printf (_("\nThere are no relocations in this file.\n"));
2507 dynamic_segment_mips_val (entry)
2508 Elf_Internal_Dyn * entry;
2510 switch (entry->d_tag)
2513 if (entry->d_un.d_val == 0)
2517 static const char * opts[] =
2519 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
2520 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
2521 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
2522 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
2527 for (cnt = 0; cnt < NUM_ELEM (opts); ++ cnt)
2528 if (entry->d_un.d_val & (1 << cnt))
2530 printf ("%s%s", first ? "" : " ", opts[cnt]);
2537 case DT_MIPS_IVERSION:
2538 if (dynamic_strings != NULL)
2539 printf ("Interface Version: %s\n",
2540 dynamic_strings + entry->d_un.d_val);
2542 printf ("%ld\n", (long) entry->d_un.d_ptr);
2545 case DT_MIPS_TIME_STAMP:
2548 time_t time = entry->d_un.d_val;
2549 strftime (timebuf, 20, "%Y-%m-%dT%H:%M:%S", gmtime (&time));
2550 printf ("Time Stamp: %s\n", timebuf);
2554 case DT_MIPS_RLD_VERSION:
2555 case DT_MIPS_LOCAL_GOTNO:
2556 case DT_MIPS_CONFLICTNO:
2557 case DT_MIPS_LIBLISTNO:
2558 case DT_MIPS_SYMTABNO:
2559 case DT_MIPS_UNREFEXTNO:
2560 case DT_MIPS_HIPAGENO:
2561 case DT_MIPS_DELTA_CLASS_NO:
2562 case DT_MIPS_DELTA_INSTANCE_NO:
2563 case DT_MIPS_DELTA_RELOC_NO:
2564 case DT_MIPS_DELTA_SYM_NO:
2565 case DT_MIPS_DELTA_CLASSSYM_NO:
2566 case DT_MIPS_COMPACT_SIZE:
2567 printf ("%ld\n", (long) entry->d_un.d_ptr);
2571 printf ("%#lx\n", (long) entry->d_un.d_ptr);
2577 dynamic_segment_parisc_val (entry)
2578 Elf_Internal_Dyn * entry;
2580 switch (entry->d_tag)
2582 case DT_HP_DLD_FLAGS:
2590 { DT_HP_DEBUG_PRIVATE, "HP_DEBUG_PRIVATE" },
2591 { DT_HP_DEBUG_CALLBACK, "HP_DEBUG_CALLBACK" },
2592 { DT_HP_DEBUG_CALLBACK_BOR, "HP_DEBUG_CALLBACK_BOR" },
2593 { DT_HP_NO_ENVVAR, "HP_NO_ENVVAR" },
2594 { DT_HP_BIND_NOW, "HP_BIND_NOW" },
2595 { DT_HP_BIND_NONFATAL, "HP_BIND_NONFATAL" },
2596 { DT_HP_BIND_VERBOSE, "HP_BIND_VERBOSE" },
2597 { DT_HP_BIND_RESTRICTED, "HP_BIND_RESTRICTED" },
2598 { DT_HP_BIND_SYMBOLIC, "HP_BIND_SYMBOLIC" },
2599 { DT_HP_RPATH_FIRST, "HP_RPATH_FIRST" },
2600 { DT_HP_BIND_DEPTH_FIRST, "HP_BIND_DEPTH_FIRST" }
2604 long int val = entry->d_un.d_val;
2606 for (cnt = 0; cnt < sizeof (flags) / sizeof (flags[0]); ++cnt)
2607 if (val & flags[cnt].bit)
2611 fputs (flags[cnt].str, stdout);
2613 val ^= flags[cnt].bit;
2615 if (val != 0 || first)
2616 printf ("%s%#lx", first ? "" : " ", val);
2622 printf ("%#lx\n", (long) entry->d_un.d_ptr);
2627 get_32bit_dynamic_segment (file)
2630 Elf32_External_Dyn * edyn;
2631 Elf_Internal_Dyn * entry;
2634 GET_DATA_ALLOC (dynamic_addr, dynamic_size,
2635 edyn, Elf32_External_Dyn *, "dynamic segment");
2637 /* SGI's ELF has more than one section in the DYNAMIC segment. Determine
2638 how large this .dynamic is now. We can do this even before the byte
2639 swapping since the DT_NULL tag is recognizable. */
2641 while (*(Elf32_Word *) edyn [dynamic_size++].d_tag != DT_NULL)
2644 dynamic_segment = (Elf_Internal_Dyn *)
2645 malloc (dynamic_size * sizeof (Elf_Internal_Dyn));
2647 if (dynamic_segment == NULL)
2649 error (_("Out of memory\n"));
2654 for (i = 0, entry = dynamic_segment;
2658 entry->d_tag = BYTE_GET (edyn [i].d_tag);
2659 entry->d_un.d_val = BYTE_GET (edyn [i].d_un.d_val);
2668 get_64bit_dynamic_segment (file)
2671 Elf64_External_Dyn * edyn;
2672 Elf_Internal_Dyn * entry;
2675 GET_DATA_ALLOC (dynamic_addr, dynamic_size,
2676 edyn, Elf64_External_Dyn *, "dynamic segment");
2678 /* SGI's ELF has more than one section in the DYNAMIC segment. Determine
2679 how large this .dynamic is now. We can do this even before the byte
2680 swapping since the DT_NULL tag is recognizable. */
2682 while (*(bfd_vma *) edyn [dynamic_size ++].d_tag != DT_NULL)
2685 dynamic_segment = (Elf_Internal_Dyn *)
2686 malloc (dynamic_size * sizeof (Elf_Internal_Dyn));
2688 if (dynamic_segment == NULL)
2690 error (_("Out of memory\n"));
2695 for (i = 0, entry = dynamic_segment;
2699 entry->d_tag = BYTE_GET8 (edyn [i].d_tag);
2700 entry->d_un.d_val = BYTE_GET8 (edyn [i].d_un.d_val);
2708 /* Parse and display the contents of the dynamic segment. */
2710 process_dynamic_segment (file)
2713 Elf_Internal_Dyn * entry;
2716 if (dynamic_size == 0)
2719 printf (_("\nThere is no dynamic segment in this file.\n"));
2726 if (! get_32bit_dynamic_segment (file))
2729 else if (! get_64bit_dynamic_segment (file))
2732 /* Find the appropriate symbol table. */
2733 if (dynamic_symbols == NULL)
2735 for (i = 0, entry = dynamic_segment;
2739 unsigned long offset;
2741 if (entry->d_tag != DT_SYMTAB)
2744 dynamic_info[DT_SYMTAB] = entry->d_un.d_val;
2746 /* Since we do not know how big the symbol table is,
2747 we default to reading in the entire file (!) and
2748 processing that. This is overkill, I know, but it
2750 offset = entry->d_un.d_val - loadaddr;
2752 if (fseek (file, 0, SEEK_END))
2753 error (_("Unable to seek to end of file!"));
2756 num_dynamic_syms = (ftell (file) - offset) / sizeof (Elf32_External_Sym);
2758 num_dynamic_syms = (ftell (file) - offset) / sizeof (Elf64_External_Sym);
2760 if (num_dynamic_syms < 1)
2762 error (_("Unable to determine the number of symbols to load\n"));
2766 dynamic_symbols = GET_ELF_SYMBOLS (file, offset, num_dynamic_syms);
2770 /* Similarly find a string table. */
2771 if (dynamic_strings == NULL)
2773 for (i = 0, entry = dynamic_segment;
2777 unsigned long offset;
2780 if (entry->d_tag != DT_STRTAB)
2783 dynamic_info[DT_STRTAB] = entry->d_un.d_val;
2785 /* Since we do not know how big the string table is,
2786 we default to reading in the entire file (!) and
2787 processing that. This is overkill, I know, but it
2790 offset = entry->d_un.d_val - loadaddr;
2791 if (fseek (file, 0, SEEK_END))
2792 error (_("Unable to seek to end of file\n"));
2793 str_tab_len = ftell (file) - offset;
2795 if (str_tab_len < 1)
2798 (_("Unable to determine the length of the dynamic string table\n"));
2802 GET_DATA_ALLOC (offset, str_tab_len, dynamic_strings, char *,
2803 "dynamic string table");
2809 /* And find the syminfo section if available. */
2810 if (dynamic_syminfo == NULL)
2812 unsigned int syminsz = 0;
2814 for (i = 0, entry = dynamic_segment;
2818 if (entry->d_tag == DT_SYMINENT)
2820 /* Note: these braces are necessary to avoid a syntax
2821 error from the SunOS4 C compiler. */
2822 assert (sizeof (Elf_External_Syminfo) == entry->d_un.d_val);
2824 else if (entry->d_tag == DT_SYMINSZ)
2825 syminsz = entry->d_un.d_val;
2826 else if (entry->d_tag == DT_SYMINFO)
2827 dynamic_syminfo_offset = entry->d_un.d_val - loadaddr;
2830 if (dynamic_syminfo_offset != 0 && syminsz != 0)
2832 Elf_External_Syminfo * extsyminfo;
2833 Elf_Internal_Syminfo * syminfo;
2835 /* There is a syminfo section. Read the data. */
2836 GET_DATA_ALLOC (dynamic_syminfo_offset, syminsz, extsyminfo,
2837 Elf_External_Syminfo *, "symbol information");
2839 dynamic_syminfo = (Elf_Internal_Syminfo *) malloc (syminsz);
2840 if (dynamic_syminfo == NULL)
2842 error (_("Out of memory\n"));
2846 dynamic_syminfo_nent = syminsz / sizeof (Elf_External_Syminfo);
2847 for (i = 0, syminfo = dynamic_syminfo; i < dynamic_syminfo_nent;
2850 syminfo->si_boundto = BYTE_GET (extsyminfo[i].si_boundto);
2851 syminfo->si_flags = BYTE_GET (extsyminfo[i].si_flags);
2858 if (do_dynamic && dynamic_addr)
2859 printf (_("\nDynamic segment at offset 0x%x contains %ld entries:\n"),
2860 dynamic_addr, (long) dynamic_size);
2862 printf (_(" Tag Type Name/Value\n"));
2864 for (i = 0, entry = dynamic_segment;
2869 printf (_(" 0x%-8.8lx (%s)%*s"),
2870 (unsigned long) entry->d_tag,
2871 get_dynamic_type (entry->d_tag),
2872 27 - strlen (get_dynamic_type (entry->d_tag)),
2875 switch (entry->d_tag)
2881 if (entry->d_tag == DT_AUXILIARY)
2882 printf (_("Auxiliary library"));
2884 printf (_("Filter library"));
2886 if (dynamic_strings)
2887 printf (": [%s]\n", dynamic_strings + entry->d_un.d_val);
2889 printf (": %#lx\n", (long) entry->d_un.d_val);
2896 printf (_("Flags:"));
2897 if (entry->d_un.d_val == 0)
2898 printf (_(" None\n"));
2901 unsigned long int val = entry->d_un.d_val;
2902 if (val & DTF_1_PARINIT)
2904 printf (" PARINIT");
2905 val ^= DTF_1_PARINIT;
2908 printf (" %lx", val);
2917 printf (_("Flags:"));
2918 if (entry->d_un.d_val == 0)
2919 printf (_(" None\n"));
2922 unsigned long int val = entry->d_un.d_val;
2923 if (val & DF_P1_LAZYLOAD)
2925 printf (" LAZYLOAD");
2926 val ^= DF_P1_LAZYLOAD;
2928 if (val & DF_P1_GROUPPERM)
2930 printf (" GROUPPERM");
2931 val ^= DF_P1_GROUPPERM;
2934 printf (" %lx", val);
2943 printf (_("Flags:"));
2944 if (entry->d_un.d_val == 0)
2945 printf (_(" None\n"));
2948 unsigned long int val = entry->d_un.d_val;
2954 if (val & DF_1_GLOBAL)
2959 if (val & DF_1_GROUP)
2964 if (val & DF_1_NODELETE)
2966 printf (" NODELETE");
2967 val ^= DF_1_NODELETE;
2969 if (val & DF_1_LOADFLTR)
2971 printf (" LOADFLTR");
2972 val ^= DF_1_LOADFLTR;
2974 if (val & DF_1_INITFIRST)
2976 printf (" INITFIRST");
2977 val ^= DF_1_INITFIRST;
2979 if (val & DF_1_NOOPEN)
2984 if (val & DF_1_ORIGIN)
2989 if (val & DF_1_DIRECT)
2994 if (val & DF_1_TRANS)
2999 if (val & DF_1_INTERPOSE)
3001 printf (" INTERPOSE");
3002 val ^= DF_1_INTERPOSE;
3005 printf (" %lx", val);
3013 puts (get_dynamic_type (entry->d_un.d_val));
3032 dynamic_info[entry->d_tag] = entry->d_un.d_val;
3038 if (dynamic_strings == NULL)
3041 name = dynamic_strings + entry->d_un.d_val;
3045 switch (entry->d_tag)
3048 printf (_("Shared library: [%s]"), name);
3050 if (strcmp (name, program_interpreter))
3053 printf (_(" program interpreter\n"));
3057 printf (_("Library soname: [%s]\n"), name);
3061 printf (_("Library rpath: [%s]\n"), name);
3065 printf ("%#lx\n", (long) entry->d_un.d_val);
3069 printf ("%#lx\n", (long) entry->d_un.d_val);
3083 case DT_INIT_ARRAYSZ:
3084 case DT_FINI_ARRAYSZ:
3086 printf ("%lu (bytes)\n", (unsigned long) entry->d_un.d_val);
3094 printf ("%lu\n", (unsigned long) entry->d_un.d_val);
3105 if (dynamic_strings != NULL && entry->d_tag == DT_USED)
3109 name = dynamic_strings + entry->d_un.d_val;
3113 printf (_("Not needed object: [%s]\n"), name);
3118 printf ("%#lx\n", (long) entry->d_un.d_val);
3123 /* The value of this entry is ignored. */
3127 if ((entry->d_tag >= DT_VERSYM) && (entry->d_tag <= DT_VERNEEDNUM))
3128 version_info [DT_VERSIONTAGIDX (entry->d_tag)] =
3133 switch (elf_header.e_machine)
3136 case EM_MIPS_RS4_BE:
3137 dynamic_segment_mips_val (entry);
3140 dynamic_segment_parisc_val (entry);
3143 printf ("%#lx\n", (long) entry->d_un.d_ptr);
3154 get_ver_flags (flags)
3157 static char buff [32];
3164 if (flags & VER_FLG_BASE)
3165 strcat (buff, "BASE ");
3167 if (flags & VER_FLG_WEAK)
3169 if (flags & VER_FLG_BASE)
3170 strcat (buff, "| ");
3172 strcat (buff, "WEAK ");
3175 if (flags & ~(VER_FLG_BASE | VER_FLG_WEAK))
3176 strcat (buff, "| <unknown>");
3181 /* Display the contents of the version sections. */
3183 process_version_sections (file)
3186 Elf32_Internal_Shdr * section;
3193 for (i = 0, section = section_headers;
3194 i < elf_header.e_shnum;
3197 switch (section->sh_type)
3199 case SHT_GNU_verdef:
3201 Elf_External_Verdef * edefs;
3208 (_("\nVersion definition section '%s' contains %ld entries:\n"),
3209 SECTION_NAME (section), section->sh_info);
3211 printf (_(" Addr: 0x"));
3212 printf_vma (section->sh_addr);
3213 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
3214 (unsigned long) section->sh_offset, section->sh_link,
3215 SECTION_NAME (section_headers + section->sh_link));
3217 GET_DATA_ALLOC (section->sh_offset, section->sh_size,
3218 edefs, Elf_External_Verdef *,
3219 "version definition section");
3221 for (idx = cnt = 0; cnt < section->sh_info; ++ cnt)
3224 Elf_External_Verdef * edef;
3225 Elf_Internal_Verdef ent;
3226 Elf_External_Verdaux * eaux;
3227 Elf_Internal_Verdaux aux;
3231 vstart = ((char *) edefs) + idx;
3233 edef = (Elf_External_Verdef *) vstart;
3235 ent.vd_version = BYTE_GET (edef->vd_version);
3236 ent.vd_flags = BYTE_GET (edef->vd_flags);
3237 ent.vd_ndx = BYTE_GET (edef->vd_ndx);
3238 ent.vd_cnt = BYTE_GET (edef->vd_cnt);
3239 ent.vd_hash = BYTE_GET (edef->vd_hash);
3240 ent.vd_aux = BYTE_GET (edef->vd_aux);
3241 ent.vd_next = BYTE_GET (edef->vd_next);
3243 printf (_(" %#06x: Rev: %d Flags: %s"),
3244 idx, ent.vd_version, get_ver_flags (ent.vd_flags));
3246 printf (_(" Index: %d Cnt: %d "),
3247 ent.vd_ndx, ent.vd_cnt);
3249 vstart += ent.vd_aux;
3251 eaux = (Elf_External_Verdaux *) vstart;
3253 aux.vda_name = BYTE_GET (eaux->vda_name);
3254 aux.vda_next = BYTE_GET (eaux->vda_next);
3256 if (dynamic_strings)
3257 printf (_("Name: %s\n"), dynamic_strings + aux.vda_name);
3259 printf (_("Name index: %ld\n"), aux.vda_name);
3261 isum = idx + ent.vd_aux;
3263 for (j = 1; j < ent.vd_cnt; j ++)
3265 isum += aux.vda_next;
3266 vstart += aux.vda_next;
3268 eaux = (Elf_External_Verdaux *) vstart;
3270 aux.vda_name = BYTE_GET (eaux->vda_name);
3271 aux.vda_next = BYTE_GET (eaux->vda_next);
3273 if (dynamic_strings)
3274 printf (_(" %#06x: Parent %d: %s\n"),
3275 isum, j, dynamic_strings + aux.vda_name);
3277 printf (_(" %#06x: Parent %d, name index: %ld\n"),
3278 isum, j, aux.vda_name);
3288 case SHT_GNU_verneed:
3290 Elf_External_Verneed * eneed;
3296 printf (_("\nVersion needs section '%s' contains %ld entries:\n"),
3297 SECTION_NAME (section), section->sh_info);
3299 printf (_(" Addr: 0x"));
3300 printf_vma (section->sh_addr);
3301 printf (_(" Offset: %#08lx Link to section: %ld (%s)\n"),
3302 (unsigned long) section->sh_offset, section->sh_link,
3303 SECTION_NAME (section_headers + section->sh_link));
3305 GET_DATA_ALLOC (section->sh_offset, section->sh_size,
3306 eneed, Elf_External_Verneed *,
3307 "version need section");
3309 for (idx = cnt = 0; cnt < section->sh_info; ++cnt)
3311 Elf_External_Verneed * entry;
3312 Elf_Internal_Verneed ent;
3317 vstart = ((char *) eneed) + idx;
3319 entry = (Elf_External_Verneed *) vstart;
3321 ent.vn_version = BYTE_GET (entry->vn_version);
3322 ent.vn_cnt = BYTE_GET (entry->vn_cnt);
3323 ent.vn_file = BYTE_GET (entry->vn_file);
3324 ent.vn_aux = BYTE_GET (entry->vn_aux);
3325 ent.vn_next = BYTE_GET (entry->vn_next);
3327 printf (_(" %#06x: Version: %d"), idx, ent.vn_version);
3329 if (dynamic_strings)
3330 printf (_(" File: %s"), dynamic_strings + ent.vn_file);
3332 printf (_(" File: %lx"), ent.vn_file);
3334 printf (_(" Cnt: %d\n"), ent.vn_cnt);
3336 vstart += ent.vn_aux;
3338 for (j = 0, isum = idx + ent.vn_aux; j < ent.vn_cnt; ++j)
3340 Elf_External_Vernaux * eaux;
3341 Elf_Internal_Vernaux aux;
3343 eaux = (Elf_External_Vernaux *) vstart;
3345 aux.vna_hash = BYTE_GET (eaux->vna_hash);
3346 aux.vna_flags = BYTE_GET (eaux->vna_flags);
3347 aux.vna_other = BYTE_GET (eaux->vna_other);
3348 aux.vna_name = BYTE_GET (eaux->vna_name);
3349 aux.vna_next = BYTE_GET (eaux->vna_next);
3351 if (dynamic_strings)
3352 printf (_(" %#06x: Name: %s"),
3353 isum, dynamic_strings + aux.vna_name);
3355 printf (_(" %#06x: Name index: %lx"),
3356 isum, aux.vna_name);
3358 printf (_(" Flags: %s Version: %d\n"),
3359 get_ver_flags (aux.vna_flags), aux.vna_other);
3361 isum += aux.vna_next;
3362 vstart += aux.vna_next;
3372 case SHT_GNU_versym:
3374 Elf32_Internal_Shdr * link_section;
3377 unsigned char * edata;
3378 unsigned short * data;
3380 Elf_Internal_Sym * symbols;
3381 Elf32_Internal_Shdr * string_sec;
3383 link_section = section_headers + section->sh_link;
3384 total = section->sh_size / section->sh_entsize;
3388 symbols = GET_ELF_SYMBOLS (file, link_section->sh_offset,
3389 link_section->sh_size / link_section->sh_entsize);
3391 string_sec = section_headers + link_section->sh_link;
3393 GET_DATA_ALLOC (string_sec->sh_offset, string_sec->sh_size,
3394 strtab, char *, "version string table");
3396 printf (_("\nVersion symbols section '%s' contains %d entries:\n"),
3397 SECTION_NAME (section), total);
3399 printf (_(" Addr: "));
3400 printf_vma (section->sh_addr);
3401 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
3402 (unsigned long) section->sh_offset, section->sh_link,
3403 SECTION_NAME (link_section));
3405 GET_DATA_ALLOC (version_info [DT_VERSIONTAGIDX (DT_VERSYM)]
3407 total * sizeof (short), edata,
3408 unsigned char *, "version symbol data");
3410 data = (unsigned short *) malloc (total * sizeof (short));
3412 for (cnt = total; cnt --;)
3413 data [cnt] = byte_get (edata + cnt * sizeof (short),
3418 for (cnt = 0; cnt < total; cnt += 4)
3422 printf (" %03x:", cnt);
3424 for (j = 0; (j < 4) && (cnt + j) < total; ++j)
3425 switch (data [cnt + j])
3428 fputs (_(" 0 (*local*) "), stdout);
3432 fputs (_(" 1 (*global*) "), stdout);
3436 nn = printf ("%4x%c", data [cnt + j] & 0x7fff,
3437 data [cnt + j] & 0x8000 ? 'h' : ' ');
3439 if (symbols [cnt + j].st_shndx < SHN_LORESERVE
3440 && section_headers[symbols [cnt + j].st_shndx].sh_type
3443 /* We must test both. */
3444 Elf_Internal_Verneed ivn;
3445 unsigned long offset;
3447 offset = version_info [DT_VERSIONTAGIDX (DT_VERNEED)]
3452 Elf_External_Verneed evn;
3453 Elf_External_Vernaux evna;
3454 Elf_Internal_Vernaux ivna;
3455 unsigned long vna_off;
3457 GET_DATA (offset, evn, "version need");
3459 ivn.vn_aux = BYTE_GET (evn.vn_aux);
3460 ivn.vn_next = BYTE_GET (evn.vn_next);
3462 vna_off = offset + ivn.vn_aux;
3466 GET_DATA (vna_off, evna,
3467 "version need aux (1)");
3469 ivna.vna_next = BYTE_GET (evna.vna_next);
3470 ivna.vna_other = BYTE_GET (evna.vna_other);
3472 vna_off += ivna.vna_next;
3474 while (ivna.vna_other != data [cnt + j]
3475 && ivna.vna_next != 0);
3477 if (ivna.vna_other == data [cnt + j])
3479 ivna.vna_name = BYTE_GET (evna.vna_name);
3481 nn += printf ("(%s%-*s",
3482 strtab + ivna.vna_name,
3488 else if (ivn.vn_next == 0)
3490 if (data [cnt + j] != 0x8001)
3492 Elf_Internal_Verdef ivd;
3493 Elf_External_Verdef evd;
3495 offset = version_info
3496 [DT_VERSIONTAGIDX (DT_VERDEF)]
3501 GET_DATA (offset, evd,
3502 "version definition");
3504 ivd.vd_next = BYTE_GET (evd.vd_next);
3505 ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
3507 offset += ivd.vd_next;
3510 != (data [cnt + j] & 0x7fff)
3511 && ivd.vd_next != 0);
3514 == (data [cnt + j] & 0x7fff))
3516 Elf_External_Verdaux evda;
3517 Elf_Internal_Verdaux ivda;
3519 ivd.vd_aux = BYTE_GET (evd.vd_aux);
3521 GET_DATA (offset + ivd.vd_aux, evda,
3522 "version definition aux");
3525 BYTE_GET (evda.vda_name);
3529 strtab + ivda.vda_name,
3540 offset += ivn.vn_next;
3542 while (ivn.vn_next);
3544 else if (symbols [cnt + j].st_shndx == SHN_UNDEF)
3546 Elf_Internal_Verneed ivn;
3547 unsigned long offset;
3549 offset = version_info [DT_VERSIONTAGIDX (DT_VERNEED)]
3554 Elf_Internal_Vernaux ivna;
3555 Elf_External_Verneed evn;
3556 Elf_External_Vernaux evna;
3557 unsigned long a_off;
3559 GET_DATA (offset, evn, "version need");
3561 ivn.vn_aux = BYTE_GET (evn.vn_aux);
3562 ivn.vn_next = BYTE_GET (evn.vn_next);
3564 a_off = offset + ivn.vn_aux;
3568 GET_DATA (a_off, evna,
3569 "version need aux (2)");
3571 ivna.vna_next = BYTE_GET (evna.vna_next);
3572 ivna.vna_other = BYTE_GET (evna.vna_other);
3574 a_off += ivna.vna_next;
3576 while (ivna.vna_other != data [cnt + j]
3577 && ivna.vna_next != 0);
3579 if (ivna.vna_other == data [cnt + j])
3581 ivna.vna_name = BYTE_GET (evna.vna_name);
3583 nn += printf ("(%s%-*s",
3584 strtab + ivna.vna_name,
3591 offset += ivn.vn_next;
3593 while (ivn.vn_next);
3595 else if (data [cnt + j] != 0x8001)
3597 Elf_Internal_Verdef ivd;
3598 Elf_External_Verdef evd;
3599 unsigned long offset;
3601 offset = version_info
3602 [DT_VERSIONTAGIDX (DT_VERDEF)] - loadaddr;
3606 GET_DATA (offset, evd, "version def");
3608 ivd.vd_next = BYTE_GET (evd.vd_next);
3609 ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
3611 offset += ivd.vd_next;
3613 while (ivd.vd_ndx != (data [cnt + j] & 0x7fff)
3614 && ivd.vd_next != 0);
3616 if (ivd.vd_ndx == (data [cnt + j] & 0x7fff))
3618 Elf_External_Verdaux evda;
3619 Elf_Internal_Verdaux ivda;
3621 ivd.vd_aux = BYTE_GET (evd.vd_aux);
3623 GET_DATA (offset - ivd.vd_next + ivd.vd_aux,
3624 evda, "version def aux");
3626 ivda.vda_name = BYTE_GET (evda.vda_name);
3628 nn += printf ("(%s%-*s",
3629 strtab + ivda.vda_name,
3637 printf ("%*c", 18 - nn, ' ');
3655 printf (_("\nNo version information found in this file.\n"));
3661 get_symbol_binding (binding)
3662 unsigned int binding;
3664 static char buff [32];
3668 case STB_LOCAL: return "LOCAL";
3669 case STB_GLOBAL: return "GLOBAL";
3670 case STB_WEAK: return "WEAK";
3672 if (binding >= STB_LOPROC && binding <= STB_HIPROC)
3673 sprintf (buff, _("<processor specific>: %d"), binding);
3674 else if (binding >= STB_LOOS && binding <= STB_HIOS)
3675 sprintf (buff, _("<OS specific>: %d"), binding);
3677 sprintf (buff, _("<unknown>: %d"), binding);
3683 get_symbol_type (type)
3686 static char buff [32];
3690 case STT_NOTYPE: return "NOTYPE";
3691 case STT_OBJECT: return "OBJECT";
3692 case STT_FUNC: return "FUNC";
3693 case STT_SECTION: return "SECTION";
3694 case STT_FILE: return "FILE";
3696 if (type >= STT_LOPROC && type <= STT_HIPROC)
3698 if (elf_header.e_machine == EM_ARM && type == STT_ARM_TFUNC)
3699 return "THUMB_FUNC";
3701 if (elf_header.e_machine == EM_SPARCV9 && type == STT_REGISTER)
3704 if (elf_header.e_machine == EM_PARISC && type == STT_PARISC_MILLI)
3705 return "PARISC_MILLI";
3707 sprintf (buff, _("<processor specific>: %d"), type);
3709 else if (type >= STT_LOOS && type <= STT_HIOS)
3711 if (elf_header.e_machine == EM_PARISC)
3713 if (type == STT_HP_OPAQUE)
3715 if (type == STT_HP_STUB)
3719 sprintf (buff, _("<OS specific>: %d"), type);
3722 sprintf (buff, _("<unknown>: %d"), type);
3728 get_symbol_index_type (type)
3733 case SHN_UNDEF: return "UND";
3734 case SHN_ABS: return "ABS";
3735 case SHN_COMMON: return "COM";
3737 if (type >= SHN_LOPROC && type <= SHN_HIPROC)
3739 else if (type >= SHN_LORESERVE && type <= SHN_HIRESERVE)
3741 else if (type >= SHN_LOOS && type <= SHN_HIOS)
3745 static char buff [32];
3747 sprintf (buff, "%3d", type);
3755 get_dynamic_data (file, number)
3757 unsigned int number;
3762 e_data = (char *) malloc (number * 4);
3766 error (_("Out of memory\n"));
3770 if (fread (e_data, 4, number, file) != number)
3772 error (_("Unable to read in dynamic data\n"));
3776 i_data = (int *) malloc (number * sizeof (* i_data));
3780 error (_("Out of memory\n"));
3786 i_data [number] = byte_get (e_data + number * 4, 4);
3793 /* Dump the symbol table */
3795 process_symbol_table (file)
3798 Elf32_Internal_Shdr * section;
3803 int * buckets = NULL;
3804 int * chains = NULL;
3806 if (! do_syms && !do_histogram)
3809 if (dynamic_info[DT_HASH] && ((do_using_dynamic && dynamic_strings != NULL)
3812 if (fseek (file, dynamic_info[DT_HASH] - loadaddr, SEEK_SET))
3814 error (_("Unable to seek to start of dynamic information"));
3818 if (fread (nb, sizeof (nb), 1, file) != 1)
3820 error (_("Failed to read in number of buckets\n"));
3824 if (fread (nc, sizeof (nc), 1, file) != 1)
3826 error (_("Failed to read in number of chains\n"));
3830 nbuckets = byte_get (nb, 4);
3831 nchains = byte_get (nc, 4);
3833 buckets = get_dynamic_data (file, nbuckets);
3834 chains = get_dynamic_data (file, nchains);
3836 if (buckets == NULL || chains == NULL)
3841 && dynamic_info[DT_HASH] && do_using_dynamic && dynamic_strings != NULL)
3846 printf (_("\nSymbol table for image:\n"));
3847 printf (_(" Num Buc: Value Size Type Bind Ot Ndx Name\n"));
3849 for (hn = 0; hn < nbuckets; hn++)
3854 for (si = buckets [hn]; si; si = chains [si])
3856 Elf_Internal_Sym * psym;
3858 psym = dynamic_symbols + si;
3860 printf (" %3d %3d: %8lx %5ld %6s %6s %2d ",
3862 (unsigned long) psym->st_value,
3863 (unsigned long) psym->st_size,
3864 get_symbol_type (ELF_ST_TYPE (psym->st_info)),
3865 get_symbol_binding (ELF_ST_BIND (psym->st_info)),
3868 printf ("%3.3s", get_symbol_index_type (psym->st_shndx));
3870 printf (" %s\n", dynamic_strings + psym->st_name);
3874 else if (do_syms && !do_using_dynamic)
3878 for (i = 0, section = section_headers;
3879 i < elf_header.e_shnum;
3884 Elf_Internal_Sym * symtab;
3885 Elf_Internal_Sym * psym;
3888 if ( section->sh_type != SHT_SYMTAB
3889 && section->sh_type != SHT_DYNSYM)
3892 printf (_("\nSymbol table '%s' contains %lu entries:\n"),
3893 SECTION_NAME (section),
3894 (unsigned long) (section->sh_size / section->sh_entsize));
3895 fputs (_(" Num: Value Size Type Bind Ot Ndx Name\n"),
3898 symtab = GET_ELF_SYMBOLS (file, section->sh_offset,
3899 section->sh_size / section->sh_entsize);
3903 if (section->sh_link == elf_header.e_shstrndx)
3904 strtab = string_table;
3907 Elf32_Internal_Shdr * string_sec;
3909 string_sec = section_headers + section->sh_link;
3911 GET_DATA_ALLOC (string_sec->sh_offset, string_sec->sh_size,
3912 strtab, char *, "string table");
3915 for (si = 0, psym = symtab;
3916 si < section->sh_size / section->sh_entsize;
3919 printf (" %3d: %8lx %5ld %-7s %-6s %2d ",
3921 (unsigned long) psym->st_value,
3922 (unsigned long) psym->st_size,
3923 get_symbol_type (ELF_ST_TYPE (psym->st_info)),
3924 get_symbol_binding (ELF_ST_BIND (psym->st_info)),
3927 printf ("%4s", get_symbol_index_type (psym->st_shndx));
3929 printf (" %s", strtab + psym->st_name);
3931 if (section->sh_type == SHT_DYNSYM &&
3932 version_info [DT_VERSIONTAGIDX (DT_VERSYM)] != 0)
3934 unsigned char data[2];
3935 unsigned short vers_data;
3936 unsigned long offset;
3940 offset = version_info [DT_VERSIONTAGIDX (DT_VERSYM)]
3943 GET_DATA (offset + si * sizeof (vers_data), data,
3946 vers_data = byte_get (data, 2);
3948 is_nobits = psym->st_shndx < SHN_LORESERVE ?
3949 (section_headers [psym->st_shndx].sh_type == SHT_NOBITS)
3952 check_def = (psym->st_shndx != SHN_UNDEF);
3954 if ((vers_data & 0x8000) || vers_data > 1)
3956 if (is_nobits || ! check_def)
3958 Elf_External_Verneed evn;
3959 Elf_Internal_Verneed ivn;
3960 Elf_Internal_Vernaux ivna;
3962 /* We must test both. */
3963 offset = version_info
3964 [DT_VERSIONTAGIDX (DT_VERNEED)] - loadaddr;
3966 GET_DATA (offset, evn, "version need");
3968 ivn.vn_aux = BYTE_GET (evn.vn_aux);
3969 ivn.vn_next = BYTE_GET (evn.vn_next);
3973 unsigned long vna_off;
3975 vna_off = offset + ivn.vn_aux;
3979 Elf_External_Vernaux evna;
3981 GET_DATA (vna_off, evna,
3982 "version need aux (3)");
3984 ivna.vna_other = BYTE_GET (evna.vna_other);
3985 ivna.vna_next = BYTE_GET (evna.vna_next);
3986 ivna.vna_name = BYTE_GET (evna.vna_name);
3988 vna_off += ivna.vna_next;
3990 while (ivna.vna_other != vers_data
3991 && ivna.vna_next != 0);
3993 if (ivna.vna_other == vers_data)
3996 offset += ivn.vn_next;
3998 while (ivn.vn_next != 0);
4000 if (ivna.vna_other == vers_data)
4003 strtab + ivna.vna_name, ivna.vna_other);
4006 else if (! is_nobits)
4007 error (_("bad dynamic symbol"));
4014 if (vers_data != 0x8001)
4016 Elf_Internal_Verdef ivd;
4017 Elf_Internal_Verdaux ivda;
4018 Elf_External_Verdaux evda;
4019 unsigned long offset;
4022 version_info [DT_VERSIONTAGIDX (DT_VERDEF)]
4027 Elf_External_Verdef evd;
4029 GET_DATA (offset, evd, "version def");
4031 ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
4032 ivd.vd_aux = BYTE_GET (evd.vd_aux);
4033 ivd.vd_next = BYTE_GET (evd.vd_next);
4035 offset += ivd.vd_next;
4037 while (ivd.vd_ndx != (vers_data & 0x7fff)
4038 && ivd.vd_next != 0);
4040 offset -= ivd.vd_next;
4041 offset += ivd.vd_aux;
4043 GET_DATA (offset, evda, "version def aux");
4045 ivda.vda_name = BYTE_GET (evda.vda_name);
4047 if (psym->st_name != ivda.vda_name)
4048 printf ((vers_data & 0x8000)
4050 strtab + ivda.vda_name);
4060 if (strtab != string_table)
4066 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
4068 if (do_histogram && buckets != NULL)
4075 int nzero_counts = 0;
4078 printf (_("\nHistogram for bucket list length (total of %d buckets):\n"),
4080 printf (_(" Length Number %% of total Coverage\n"));
4082 lengths = (int *) calloc (nbuckets, sizeof (int));
4083 if (lengths == NULL)
4085 error (_("Out of memory"));
4088 for (hn = 0; hn < nbuckets; ++hn)
4093 for (si = buckets[hn]; si; si = chains[si])
4096 if (maxlength < ++lengths[hn])
4101 counts = (int *) calloc (maxlength + 1, sizeof (int));
4104 error (_("Out of memory"));
4108 for (hn = 0; hn < nbuckets; ++hn)
4109 ++counts[lengths [hn]];
4113 printf (" 0 %-10d (%5.1f%%)\n",
4114 counts[0], (counts[0] * 100.0) / nbuckets);
4115 for (si = 1; si <= maxlength; ++si)
4117 nzero_counts += counts[si] * si;
4118 printf ("%7d %-10d (%5.1f%%) %5.1f%%\n",
4119 si, counts[si], (counts[si] * 100.0) / nbuckets,
4120 (nzero_counts * 100.0) / nsyms);
4128 if (buckets != NULL)
4138 process_syminfo (file)
4139 FILE * file ATTRIBUTE_UNUSED;
4143 if (dynamic_syminfo == NULL
4145 /* No syminfo, this is ok. */
4148 /* There better should be a dynamic symbol section. */
4149 if (dynamic_symbols == NULL || dynamic_strings == NULL)
4153 printf (_("\nDynamic info segment at offset 0x%lx contains %d entries:\n"),
4154 dynamic_syminfo_offset, dynamic_syminfo_nent);
4156 printf (_(" Num: Name BoundTo Flags\n"));
4157 for (i = 0; i < dynamic_syminfo_nent; ++i)
4159 unsigned short int flags = dynamic_syminfo[i].si_flags;
4161 printf ("%4d: %-30s ", i,
4162 dynamic_strings + dynamic_symbols[i].st_name);
4164 switch (dynamic_syminfo[i].si_boundto)
4166 case SYMINFO_BT_SELF:
4167 fputs ("SELF ", stdout);
4169 case SYMINFO_BT_PARENT:
4170 fputs ("PARENT ", stdout);
4173 if (dynamic_syminfo[i].si_boundto > 0
4174 && dynamic_syminfo[i].si_boundto < dynamic_size)
4177 + dynamic_segment[dynamic_syminfo[i].si_boundto].d_un.d_val);
4179 printf ("%-10d ", dynamic_syminfo[i].si_boundto);
4183 if (flags & SYMINFO_FLG_DIRECT)
4185 if (flags & SYMINFO_FLG_PASSTHRU)
4186 printf (" PASSTHRU");
4187 if (flags & SYMINFO_FLG_COPY)
4189 if (flags & SYMINFO_FLG_LAZYLOAD)
4190 printf (" LAZYLOAD");
4198 #ifdef SUPPORT_DISASSEMBLY
4200 disassemble_section (section, file)
4201 Elf32_Internal_Shdr * section;
4204 printf (_("\nAssembly dump of section %s\n"),
4205 SECTION_NAME (section));
4207 /* XXX -- to be done --- XXX */
4214 dump_section (section, file)
4215 Elf32_Internal_Shdr * section;
4218 bfd_size_type bytes;
4220 unsigned char * data;
4221 unsigned char * start;
4223 bytes = section->sh_size;
4227 printf (_("\nSection '%s' has no data to dump.\n"),
4228 SECTION_NAME (section));
4232 printf (_("\nHex dump of section '%s':\n"), SECTION_NAME (section));
4234 addr = section->sh_addr;
4236 GET_DATA_ALLOC (section->sh_offset, bytes, start, unsigned char *,
4247 lbytes = (bytes > 16 ? 16 : bytes);
4249 printf (" 0x%8.8lx ", (unsigned long) addr);
4251 switch (elf_header.e_ident [EI_DATA])
4255 for (j = 15; j >= 0; j --)
4258 printf ("%2.2x", data [j]);
4268 for (j = 0; j < 16; j++)
4271 printf ("%2.2x", data [j]);
4281 for (j = 0; j < lbytes; j++)
4284 if (k >= ' ' && k < 0x80)
4303 static unsigned long int
4304 read_leb128 (data, length_return, sign)
4305 unsigned char * data;
4306 int * length_return;
4309 unsigned long int result = 0;
4310 unsigned int num_read = 0;
4319 result |= (byte & 0x7f) << shift;
4324 while (byte & 0x80);
4326 if (length_return != NULL)
4327 * length_return = num_read;
4329 if (sign && (shift < 32) && (byte & 0x40))
4330 result |= -1 << shift;
4335 typedef struct State_Machine_Registers
4337 unsigned long address;
4340 unsigned int column;
4344 /* This variable hold the number of the last entry seen
4345 in the File Table. */
4346 unsigned int last_file_entry;
4349 static SMR state_machine_regs;
4352 reset_state_machine (is_stmt)
4355 state_machine_regs.address = 0;
4356 state_machine_regs.file = 1;
4357 state_machine_regs.line = 1;
4358 state_machine_regs.column = 0;
4359 state_machine_regs.is_stmt = is_stmt;
4360 state_machine_regs.basic_block = 0;
4361 state_machine_regs.end_sequence = 0;
4362 state_machine_regs.last_file_entry = 0;
4365 /* Handled an extend line op. Returns true if this is the end
4368 process_extended_line_op (data, is_stmt, pointer_size)
4369 unsigned char * data;
4373 unsigned char op_code;
4376 unsigned char * name;
4379 len = read_leb128 (data, & bytes_read, 0);
4384 warn (_("badly formed extended line op encountered!"));
4389 op_code = * data ++;
4391 printf (_(" Extended opcode %d: "), op_code);
4395 case DW_LNE_end_sequence:
4396 printf (_("End of Sequence\n\n"));
4397 reset_state_machine (is_stmt);
4400 case DW_LNE_set_address:
4401 adr = byte_get (data, pointer_size);
4402 printf (_("set Address to 0x%lx\n"), adr);
4403 state_machine_regs.address = adr;
4406 case DW_LNE_define_file:
4407 printf (_(" define new File Table entry\n"));
4408 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
4410 printf (_(" %d\t"), ++ state_machine_regs.last_file_entry);
4412 data += strlen (data) + 1;
4413 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
4415 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
4417 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
4418 printf (_("%s\n\n"), name);
4422 printf (_("UNKNOWN: length %d\n"), len - bytes_read);
4429 /* Size of pointers in the .debug_line section. This information is not
4430 really present in that section. It's obtained before dumping the debug
4431 sections by doing some pre-scan of the .debug_info section. */
4432 static int debug_line_pointer_size = 4;
4435 display_debug_lines (section, start, file)
4436 Elf32_Internal_Shdr * section;
4437 unsigned char * start;
4438 FILE * file ATTRIBUTE_UNUSED;
4440 DWARF2_External_LineInfo * external;
4441 DWARF2_Internal_LineInfo info;
4442 unsigned char * standard_opcodes;
4443 unsigned char * data = start;
4444 unsigned char * end = start + section->sh_size;
4445 unsigned char * end_of_sequence;
4448 printf (_("\nDump of debug contents of section %s:\n\n"),
4449 SECTION_NAME (section));
4453 external = (DWARF2_External_LineInfo *) data;
4455 /* Check the length of the block. */
4456 info.li_length = BYTE_GET (external->li_length);
4457 if (info.li_length > section->sh_size)
4460 (_("The line info appears to be corrupt - the section is too small\n"));
4464 /* Check its version number. */
4465 info.li_version = BYTE_GET (external->li_version);
4466 if (info.li_version != 2)
4468 warn (_("Only DWARF version 2 line info is currently supported.\n"));
4472 info.li_prologue_length = BYTE_GET (external->li_prologue_length);
4473 info.li_min_insn_length = BYTE_GET (external->li_min_insn_length);
4474 info.li_default_is_stmt = BYTE_GET (external->li_default_is_stmt);
4475 info.li_line_base = BYTE_GET (external->li_line_base);
4476 info.li_line_range = BYTE_GET (external->li_line_range);
4477 info.li_opcode_base = BYTE_GET (external->li_opcode_base);
4479 /* Sign extend the line base field. */
4480 info.li_line_base <<= 24;
4481 info.li_line_base >>= 24;
4483 printf (_(" Length: %ld\n"), info.li_length);
4484 printf (_(" DWARF Version: %d\n"), info.li_version);
4485 printf (_(" Prolgue Length: %d\n"), info.li_prologue_length);
4486 printf (_(" Minimum Instruction Length: %d\n"), info.li_min_insn_length);
4487 printf (_(" Initial value of 'is_stmt': %d\n"), info.li_default_is_stmt);
4488 printf (_(" Line Base: %d\n"), info.li_line_base);
4489 printf (_(" Line Range: %d\n"), info.li_line_range);
4490 printf (_(" Opcode Base: %d\n"), info.li_opcode_base);
4492 end_of_sequence = data + info.li_length + sizeof (info.li_length);
4494 reset_state_machine (info.li_default_is_stmt);
4496 /* Display the contents of the Opcodes table. */
4497 standard_opcodes = data + sizeof (* external);
4499 printf (_("\n Opcodes:\n"));
4501 for (i = 1; i < info.li_opcode_base; i++)
4502 printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]);
4504 /* Display the contents of the Directory table. */
4505 data = standard_opcodes + info.li_opcode_base - 1;
4508 printf (_("\n The Directory Table is empty.\n"));
4511 printf (_("\n The Directory Table:\n"));
4515 printf (_(" %s\n"), data);
4517 data += strlen (data) + 1;
4521 /* Skip the NUL at the end of the table. */
4524 /* Display the contents of the File Name table. */
4526 printf (_("\n The File Name Table is empty.\n"));
4529 printf (_("\n The File Name Table:\n"));
4530 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
4537 printf (_(" %d\t"), ++ state_machine_regs.last_file_entry);
4540 data += strlen (data) + 1;
4542 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
4544 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
4546 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
4548 printf (_("%s\n"), name);
4552 /* Skip the NUL at the end of the table. */
4555 /* Now display the statements. */
4556 printf (_("\n Line Number Statements:\n"));
4559 while (data < end_of_sequence)
4561 unsigned char op_code;
4565 op_code = * data ++;
4569 case DW_LNS_extended_op:
4570 data += process_extended_line_op (data, info.li_default_is_stmt,
4571 debug_line_pointer_size);
4575 printf (_(" Copy\n"));
4578 case DW_LNS_advance_pc:
4579 adv = info.li_min_insn_length * read_leb128 (data, & bytes_read, 0);
4581 state_machine_regs.address += adv;
4582 printf (_(" Advance PC by %d to %lx\n"), adv,
4583 state_machine_regs.address);
4586 case DW_LNS_advance_line:
4587 adv = read_leb128 (data, & bytes_read, 1);
4589 state_machine_regs.line += adv;
4590 printf (_(" Advance Line by %d to %d\n"), adv,
4591 state_machine_regs.line);
4594 case DW_LNS_set_file:
4595 adv = read_leb128 (data, & bytes_read, 0);
4597 printf (_(" Set File Name to entry %d in the File Name Table\n"),
4599 state_machine_regs.file = adv;
4602 case DW_LNS_set_column:
4603 adv = read_leb128 (data, & bytes_read, 0);
4605 printf (_(" Set column to %d\n"), adv);
4606 state_machine_regs.column = adv;
4609 case DW_LNS_negate_stmt:
4610 adv = state_machine_regs.is_stmt;
4612 printf (_(" Set is_stmt to %d\n"), adv);
4613 state_machine_regs.is_stmt = adv;
4616 case DW_LNS_set_basic_block:
4617 printf (_(" Set basic block\n"));
4618 state_machine_regs.basic_block = 1;
4621 case DW_LNS_const_add_pc:
4622 adv = (((255 - info.li_opcode_base) / info.li_line_range)
4623 * info.li_min_insn_length);
4624 state_machine_regs.address += adv;
4625 printf (_(" Advance PC by constant %d to 0x%lx\n"), adv,
4626 state_machine_regs.address);
4629 case DW_LNS_fixed_advance_pc:
4630 adv = byte_get (data, 2);
4632 state_machine_regs.address += adv;
4633 printf (_(" Advance PC by fixed size amount %d to 0x%lx\n"),
4634 adv, state_machine_regs.address);
4638 op_code -= info.li_opcode_base;
4639 adv = (op_code / info.li_line_range) * info.li_min_insn_length;
4640 state_machine_regs.address += adv;
4641 printf (_(" Special opcode %d: advance Address by %d to 0x%lx"),
4642 op_code, adv, state_machine_regs.address);
4643 adv = (op_code % info.li_line_range) + info.li_line_base;
4644 state_machine_regs.line += adv;
4645 printf (_(" and Line by %d to %d\n"),
4646 adv, state_machine_regs.line);
4657 display_debug_pubnames (section, start, file)
4658 Elf32_Internal_Shdr * section;
4659 unsigned char * start;
4660 FILE * file ATTRIBUTE_UNUSED;
4662 DWARF2_External_PubNames * external;
4663 DWARF2_Internal_PubNames pubnames;
4664 unsigned char * end;
4666 end = start + section->sh_size;
4668 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section));
4672 unsigned char * data;
4673 unsigned long offset;
4675 external = (DWARF2_External_PubNames *) start;
4677 pubnames.pn_length = BYTE_GET (external->pn_length);
4678 pubnames.pn_version = BYTE_GET (external->pn_version);
4679 pubnames.pn_offset = BYTE_GET (external->pn_offset);
4680 pubnames.pn_size = BYTE_GET (external->pn_size);
4682 data = start + sizeof (* external);
4683 start += pubnames.pn_length + sizeof (external->pn_length);
4685 if (pubnames.pn_version != 2)
4687 warn (_("Only DWARF 2 pubnames are currently supported"));
4691 printf (_(" Length: %ld\n"),
4692 pubnames.pn_length);
4693 printf (_(" Version: %d\n"),
4694 pubnames.pn_version);
4695 printf (_(" Offset into .debug_info section: %ld\n"),
4696 pubnames.pn_offset);
4697 printf (_(" Size of area in .debug_info section: %ld\n"),
4700 printf (_("\n Offset\tName\n"));
4704 offset = byte_get (data, 4);
4709 printf (" %ld\t\t%s\n", offset, data);
4710 data += strlen (data) + 1;
4713 while (offset != 0);
4726 case DW_TAG_padding: return "DW_TAG_padding";
4727 case DW_TAG_array_type: return "DW_TAG_array_type";
4728 case DW_TAG_class_type: return "DW_TAG_class_type";
4729 case DW_TAG_entry_point: return "DW_TAG_entry_point";
4730 case DW_TAG_enumeration_type: return "DW_TAG_enumeration_type";
4731 case DW_TAG_formal_parameter: return "DW_TAG_formal_parameter";
4732 case DW_TAG_imported_declaration: return "DW_TAG_imported_declaration";
4733 case DW_TAG_label: return "DW_TAG_label";
4734 case DW_TAG_lexical_block: return "DW_TAG_lexical_block";
4735 case DW_TAG_member: return "DW_TAG_member";
4736 case DW_TAG_pointer_type: return "DW_TAG_pointer_type";
4737 case DW_TAG_reference_type: return "DW_TAG_reference_type";
4738 case DW_TAG_compile_unit: return "DW_TAG_compile_unit";
4739 case DW_TAG_string_type: return "DW_TAG_string_type";
4740 case DW_TAG_structure_type: return "DW_TAG_structure_type";
4741 case DW_TAG_subroutine_type: return "DW_TAG_subroutine_type";
4742 case DW_TAG_typedef: return "DW_TAG_typedef";
4743 case DW_TAG_union_type: return "DW_TAG_union_type";
4744 case DW_TAG_unspecified_parameters: return "DW_TAG_unspecified_parameters";
4745 case DW_TAG_variant: return "DW_TAG_variant";
4746 case DW_TAG_common_block: return "DW_TAG_common_block";
4747 case DW_TAG_common_inclusion: return "DW_TAG_common_inclusion";
4748 case DW_TAG_inheritance: return "DW_TAG_inheritance";
4749 case DW_TAG_inlined_subroutine: return "DW_TAG_inlined_subroutine";
4750 case DW_TAG_module: return "DW_TAG_module";
4751 case DW_TAG_ptr_to_member_type: return "DW_TAG_ptr_to_member_type";
4752 case DW_TAG_set_type: return "DW_TAG_set_type";
4753 case DW_TAG_subrange_type: return "DW_TAG_subrange_type";
4754 case DW_TAG_with_stmt: return "DW_TAG_with_stmt";
4755 case DW_TAG_access_declaration: return "DW_TAG_access_declaration";
4756 case DW_TAG_base_type: return "DW_TAG_base_type";
4757 case DW_TAG_catch_block: return "DW_TAG_catch_block";
4758 case DW_TAG_const_type: return "DW_TAG_const_type";
4759 case DW_TAG_constant: return "DW_TAG_constant";
4760 case DW_TAG_enumerator: return "DW_TAG_enumerator";
4761 case DW_TAG_file_type: return "DW_TAG_file_type";
4762 case DW_TAG_friend: return "DW_TAG_friend";
4763 case DW_TAG_namelist: return "DW_TAG_namelist";
4764 case DW_TAG_namelist_item: return "DW_TAG_namelist_item";
4765 case DW_TAG_packed_type: return "DW_TAG_packed_type";
4766 case DW_TAG_subprogram: return "DW_TAG_subprogram";
4767 case DW_TAG_template_type_param: return "DW_TAG_template_type_param";
4768 case DW_TAG_template_value_param: return "DW_TAG_template_value_param";
4769 case DW_TAG_thrown_type: return "DW_TAG_thrown_type";
4770 case DW_TAG_try_block: return "DW_TAG_try_block";
4771 case DW_TAG_variant_part: return "DW_TAG_variant_part";
4772 case DW_TAG_variable: return "DW_TAG_variable";
4773 case DW_TAG_volatile_type: return "DW_TAG_volatile_type";
4774 case DW_TAG_MIPS_loop: return "DW_TAG_MIPS_loop";
4775 case DW_TAG_format_label: return "DW_TAG_format_label";
4776 case DW_TAG_function_template: return "DW_TAG_function_template";
4777 case DW_TAG_class_template: return "DW_TAG_class_template";
4780 static char buffer [100];
4782 sprintf (buffer, _("Unknown TAG value: %lx"), tag);
4789 get_AT_name (attribute)
4790 unsigned long attribute;
4794 case DW_AT_sibling: return "DW_AT_sibling";
4795 case DW_AT_location: return "DW_AT_location";
4796 case DW_AT_name: return "DW_AT_name";
4797 case DW_AT_ordering: return "DW_AT_ordering";
4798 case DW_AT_subscr_data: return "DW_AT_subscr_data";
4799 case DW_AT_byte_size: return "DW_AT_byte_size";
4800 case DW_AT_bit_offset: return "DW_AT_bit_offset";
4801 case DW_AT_bit_size: return "DW_AT_bit_size";
4802 case DW_AT_element_list: return "DW_AT_element_list";
4803 case DW_AT_stmt_list: return "DW_AT_stmt_list";
4804 case DW_AT_low_pc: return "DW_AT_low_pc";
4805 case DW_AT_high_pc: return "DW_AT_high_pc";
4806 case DW_AT_language: return "DW_AT_language";
4807 case DW_AT_member: return "DW_AT_member";
4808 case DW_AT_discr: return "DW_AT_discr";
4809 case DW_AT_discr_value: return "DW_AT_discr_value";
4810 case DW_AT_visibility: return "DW_AT_visibility";
4811 case DW_AT_import: return "DW_AT_import";
4812 case DW_AT_string_length: return "DW_AT_string_length";
4813 case DW_AT_common_reference: return "DW_AT_common_reference";
4814 case DW_AT_comp_dir: return "DW_AT_comp_dir";
4815 case DW_AT_const_value: return "DW_AT_const_value";
4816 case DW_AT_containing_type: return "DW_AT_containing_type";
4817 case DW_AT_default_value: return "DW_AT_default_value";
4818 case DW_AT_inline: return "DW_AT_inline";
4819 case DW_AT_is_optional: return "DW_AT_is_optional";
4820 case DW_AT_lower_bound: return "DW_AT_lower_bound";
4821 case DW_AT_producer: return "DW_AT_producer";
4822 case DW_AT_prototyped: return "DW_AT_prototyped";
4823 case DW_AT_return_addr: return "DW_AT_return_addr";
4824 case DW_AT_start_scope: return "DW_AT_start_scope";
4825 case DW_AT_stride_size: return "DW_AT_stride_size";
4826 case DW_AT_upper_bound: return "DW_AT_upper_bound";
4827 case DW_AT_abstract_origin: return "DW_AT_abstract_origin";
4828 case DW_AT_accessibility: return "DW_AT_accessibility";
4829 case DW_AT_address_class: return "DW_AT_address_class";
4830 case DW_AT_artificial: return "DW_AT_artificial";
4831 case DW_AT_base_types: return "DW_AT_base_types";
4832 case DW_AT_calling_convention: return "DW_AT_calling_convention";
4833 case DW_AT_count: return "DW_AT_count";
4834 case DW_AT_data_member_location: return "DW_AT_data_member_location";
4835 case DW_AT_decl_column: return "DW_AT_decl_column";
4836 case DW_AT_decl_file: return "DW_AT_decl_file";
4837 case DW_AT_decl_line: return "DW_AT_decl_line";
4838 case DW_AT_declaration: return "DW_AT_declaration";
4839 case DW_AT_discr_list: return "DW_AT_discr_list";
4840 case DW_AT_encoding: return "DW_AT_encoding";
4841 case DW_AT_external: return "DW_AT_external";
4842 case DW_AT_frame_base: return "DW_AT_frame_base";
4843 case DW_AT_friend: return "DW_AT_friend";
4844 case DW_AT_identifier_case: return "DW_AT_identifier_case";
4845 case DW_AT_macro_info: return "DW_AT_macro_info";
4846 case DW_AT_namelist_items: return "DW_AT_namelist_items";
4847 case DW_AT_priority: return "DW_AT_priority";
4848 case DW_AT_segment: return "DW_AT_segment";
4849 case DW_AT_specification: return "DW_AT_specification";
4850 case DW_AT_static_link: return "DW_AT_static_link";
4851 case DW_AT_type: return "DW_AT_type";
4852 case DW_AT_use_location: return "DW_AT_use_location";
4853 case DW_AT_variable_parameter: return "DW_AT_variable_parameter";
4854 case DW_AT_virtuality: return "DW_AT_virtuality";
4855 case DW_AT_vtable_elem_location: return "DW_AT_vtable_elem_location";
4856 case DW_AT_MIPS_fde: return "DW_AT_MIPS_fde";
4857 case DW_AT_MIPS_loop_begin: return "DW_AT_MIPS_loop_begin";
4858 case DW_AT_MIPS_tail_loop_begin: return "DW_AT_MIPS_tail_loop_begin";
4859 case DW_AT_MIPS_epilog_begin: return "DW_AT_MIPS_epilog_begin";
4860 case DW_AT_MIPS_loop_unroll_factor: return "DW_AT_MIPS_loop_unroll_factor";
4861 case DW_AT_MIPS_software_pipeline_depth: return "DW_AT_MIPS_software_pipeline_depth";
4862 case DW_AT_MIPS_linkage_name: return "DW_AT_MIPS_linkage_name";
4863 case DW_AT_MIPS_stride: return "DW_AT_MIPS_stride";
4864 case DW_AT_MIPS_abstract_name: return "DW_AT_MIPS_abstract_name";
4865 case DW_AT_MIPS_clone_origin: return "DW_AT_MIPS_clone_origin";
4866 case DW_AT_MIPS_has_inlines: return "DW_AT_MIPS_has_inlines";
4867 case DW_AT_sf_names: return "DW_AT_sf_names";
4868 case DW_AT_src_info: return "DW_AT_src_info";
4869 case DW_AT_mac_info: return "DW_AT_mac_info";
4870 case DW_AT_src_coords: return "DW_AT_src_coords";
4871 case DW_AT_body_begin: return "DW_AT_body_begin";
4872 case DW_AT_body_end: return "DW_AT_body_end";
4875 static char buffer [100];
4877 sprintf (buffer, _("Unknown AT value: %lx"), attribute);
4884 get_FORM_name (form)
4889 case DW_FORM_addr: return "DW_FORM_addr";
4890 case DW_FORM_block2: return "DW_FORM_block2";
4891 case DW_FORM_block4: return "DW_FORM_block4";
4892 case DW_FORM_data2: return "DW_FORM_data2";
4893 case DW_FORM_data4: return "DW_FORM_data4";
4894 case DW_FORM_data8: return "DW_FORM_data8";
4895 case DW_FORM_string: return "DW_FORM_string";
4896 case DW_FORM_block: return "DW_FORM_block";
4897 case DW_FORM_block1: return "DW_FORM_block1";
4898 case DW_FORM_data1: return "DW_FORM_data1";
4899 case DW_FORM_flag: return "DW_FORM_flag";
4900 case DW_FORM_sdata: return "DW_FORM_sdata";
4901 case DW_FORM_strp: return "DW_FORM_strp";
4902 case DW_FORM_udata: return "DW_FORM_udata";
4903 case DW_FORM_ref_addr: return "DW_FORM_ref_addr";
4904 case DW_FORM_ref1: return "DW_FORM_ref1";
4905 case DW_FORM_ref2: return "DW_FORM_ref2";
4906 case DW_FORM_ref4: return "DW_FORM_ref4";
4907 case DW_FORM_ref8: return "DW_FORM_ref8";
4908 case DW_FORM_ref_udata: return "DW_FORM_ref_udata";
4909 case DW_FORM_indirect: return "DW_FORM_indirect";
4912 static char buffer [100];
4914 sprintf (buffer, _("Unknown FORM value: %lx"), form);
4920 /* FIXME: There are better and more effiecint ways to handle
4921 these structures. For now though, I just want something that
4922 is simple to implement. */
4923 typedef struct abbrev_attr
4925 unsigned long attribute;
4927 struct abbrev_attr * next;
4931 typedef struct abbrev_entry
4933 unsigned long entry;
4936 struct abbrev_attr * first_attr;
4937 struct abbrev_attr * last_attr;
4938 struct abbrev_entry * next;
4942 static abbrev_entry * first_abbrev = NULL;
4943 static abbrev_entry * last_abbrev = NULL;
4946 free_abbrevs PARAMS ((void))
4948 abbrev_entry * abbrev;
4950 for (abbrev = first_abbrev; abbrev;)
4952 abbrev_entry * next = abbrev->next;
4955 for (attr = abbrev->first_attr; attr;)
4957 abbrev_attr * next = attr->next;
4967 last_abbrev = first_abbrev = NULL;
4971 add_abbrev (number, tag, children)
4972 unsigned long number;
4976 abbrev_entry * entry;
4978 entry = (abbrev_entry *) malloc (sizeof (* entry));
4984 entry->entry = number;
4986 entry->children = children;
4987 entry->first_attr = NULL;
4988 entry->last_attr = NULL;
4991 if (first_abbrev == NULL)
4992 first_abbrev = entry;
4994 last_abbrev->next = entry;
4996 last_abbrev = entry;
5000 add_abbrev_attr (attribute, form)
5001 unsigned long attribute;
5006 attr = (abbrev_attr *) malloc (sizeof (* attr));
5012 attr->attribute = attribute;
5016 if (last_abbrev->first_attr == NULL)
5017 last_abbrev->first_attr = attr;
5019 last_abbrev->last_attr->next = attr;
5021 last_abbrev->last_attr = attr;
5024 /* Processes the (partial) contents of a .debug_abbrev section.
5025 Returns NULL if the end of the section was encountered.
5026 Returns the address after the last byte read if the end of
5027 an abbreviation set was found. */
5029 static unsigned char *
5030 process_abbrev_section (start, end)
5031 unsigned char * start;
5032 unsigned char * end;
5034 if (first_abbrev != NULL)
5040 unsigned long entry;
5042 unsigned long attribute;
5045 entry = read_leb128 (start, & bytes_read, 0);
5046 start += bytes_read;
5048 /* A single zero is supposed to end the section according
5049 to the standard. If there's more, then signal that to
5052 return start == end ? NULL : start;
5054 tag = read_leb128 (start, & bytes_read, 0);
5055 start += bytes_read;
5057 children = * start ++;
5059 add_abbrev (entry, tag, children);
5065 attribute = read_leb128 (start, & bytes_read, 0);
5066 start += bytes_read;
5068 form = read_leb128 (start, & bytes_read, 0);
5069 start += bytes_read;
5072 add_abbrev_attr (attribute, form);
5074 while (attribute != 0);
5082 display_debug_abbrev (section, start, file)
5083 Elf32_Internal_Shdr * section;
5084 unsigned char * start;
5085 FILE * file ATTRIBUTE_UNUSED;
5087 abbrev_entry * entry;
5088 unsigned char * end = start + section->sh_size;
5090 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section));
5094 start = process_abbrev_section (start, end);
5096 printf (_(" Number TAG\n"));
5098 for (entry = first_abbrev; entry; entry = entry->next)
5102 printf (_(" %ld %s [%s]\n"),
5104 get_TAG_name (entry->tag),
5105 entry->children ? _("has children") : _("no children"));
5107 for (attr = entry->first_attr; attr; attr = attr->next)
5109 printf (_(" %-18s %s\n"),
5110 get_AT_name (attr->attribute),
5111 get_FORM_name (attr->form));
5123 static unsigned char *
5124 display_block (data, length)
5125 unsigned char * data;
5126 unsigned long length;
5128 printf (_(" %lu byte block: "), length);
5131 printf ("%lx ", (unsigned long) byte_get (data ++, 1));
5137 decode_location_expression (data, pointer_size)
5138 unsigned char * data;
5139 unsigned int pointer_size;
5143 unsigned long uvalue;
5150 printf ("DW_OP_addr: %lx", (unsigned long) byte_get (data, pointer_size));
5153 printf ("DW_OP_deref");
5156 printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data, 1));
5159 printf ("DW_OP_const1s: %ld", (long) byte_get (data, 1));
5162 printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data, 2));
5165 printf ("DW_OP_const2s: %ld", (long) byte_get (data, 2));
5168 printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data, 4));
5171 printf ("DW_OP_const4s: %ld", (long) byte_get (data, 4));
5174 printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data, 4),
5175 (unsigned long) byte_get (data + 4, 4));
5178 printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data, 4),
5179 (long) byte_get (data + 4, 4));
5182 printf ("DW_OP_constu: %lu", read_leb128 (data, NULL, 0));
5185 printf ("DW_OP_consts: %ld", read_leb128 (data, NULL, 1));
5188 printf ("DW_OP_dup");
5191 printf ("DW_OP_drop");
5194 printf ("DW_OP_over");
5197 printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data, 1));
5200 printf ("DW_OP_swap");
5203 printf ("DW_OP_rot");
5206 printf ("DW_OP_xderef");
5209 printf ("DW_OP_abs");
5212 printf ("DW_OP_and");
5215 printf ("DW_OP_div");
5218 printf ("DW_OP_minus");
5221 printf ("DW_OP_mod");
5224 printf ("DW_OP_mul");
5227 printf ("DW_OP_neg");
5230 printf ("DW_OP_not");
5233 printf ("DW_OP_or");
5236 printf ("DW_OP_plus");
5238 case DW_OP_plus_uconst:
5239 printf ("DW_OP_plus_uconst: %lu", read_leb128 (data, NULL, 0));
5242 printf ("DW_OP_shl");
5245 printf ("DW_OP_shr");
5248 printf ("DW_OP_shra");
5251 printf ("DW_OP_xor");
5254 printf ("DW_OP_bra: %ld", (long) byte_get (data, 2));
5257 printf ("DW_OP_eq");
5260 printf ("DW_OP_ge");
5263 printf ("DW_OP_gt");
5266 printf ("DW_OP_le");
5269 printf ("DW_OP_lt");
5272 printf ("DW_OP_ne");
5275 printf ("DW_OP_skip: %ld", (long) byte_get (data, 2));
5278 printf ("DW_OP_lit0");
5281 printf ("DW_OP_lit1");
5284 printf ("DW_OP_lit2");
5287 printf ("DW_OP_lit3");
5290 printf ("DW_OP_lit4");
5293 printf ("DW_OP_lit5");
5296 printf ("DW_OP_lit6");
5299 printf ("DW_OP_lit7");
5302 printf ("DW_OP_lit8");
5305 printf ("DW_OP_lit9");
5308 printf ("DW_OP_lit10");
5311 printf ("DW_OP_lit11");
5314 printf ("DW_OP_lit12");
5317 printf ("DW_OP_lit13");
5320 printf ("DW_OP_lit14");
5323 printf ("DW_OP_lit15");
5326 printf ("DW_OP_lit16");
5329 printf ("DW_OP_lit17");
5332 printf ("DW_OP_lit18");
5335 printf ("DW_OP_lit19");
5338 printf ("DW_OP_lit20");
5341 printf ("DW_OP_lit21");
5344 printf ("DW_OP_lit22");
5347 printf ("DW_OP_lit23");
5350 printf ("DW_OP_lit24");
5353 printf ("DW_OP_lit25");
5356 printf ("DW_OP_lit26");
5359 printf ("DW_OP_lit27");
5362 printf ("DW_OP_lit28");
5365 printf ("DW_OP_lit29");
5368 printf ("DW_OP_lit30");
5371 printf ("DW_OP_lit31");
5374 printf ("DW_OP_reg0");
5377 printf ("DW_OP_reg1");
5380 printf ("DW_OP_reg2");
5383 printf ("DW_OP_reg3");
5386 printf ("DW_OP_reg4");
5389 printf ("DW_OP_reg5");
5392 printf ("DW_OP_reg6");
5395 printf ("DW_OP_reg7");
5398 printf ("DW_OP_reg8");
5401 printf ("DW_OP_reg9");
5404 printf ("DW_OP_reg10");
5407 printf ("DW_OP_reg11");
5410 printf ("DW_OP_reg12");
5413 printf ("DW_OP_reg13");
5416 printf ("DW_OP_reg14");
5419 printf ("DW_OP_reg15");
5422 printf ("DW_OP_reg16");
5425 printf ("DW_OP_reg17");
5428 printf ("DW_OP_reg18");
5431 printf ("DW_OP_reg19");
5434 printf ("DW_OP_reg20");
5437 printf ("DW_OP_reg21");
5440 printf ("DW_OP_reg22");
5443 printf ("DW_OP_reg23");
5446 printf ("DW_OP_reg24");
5449 printf ("DW_OP_reg25");
5452 printf ("DW_OP_reg26");
5455 printf ("DW_OP_reg27");
5458 printf ("DW_OP_reg28");
5461 printf ("DW_OP_reg29");
5464 printf ("DW_OP_reg30");
5467 printf ("DW_OP_reg31");
5470 printf ("DW_OP_breg0: %ld", read_leb128 (data, NULL, 1));
5473 printf ("DW_OP_breg1: %ld", read_leb128 (data, NULL, 1));
5476 printf ("DW_OP_breg2: %ld", read_leb128 (data, NULL, 1));
5479 printf ("DW_OP_breg3: %ld", read_leb128 (data, NULL, 1));
5482 printf ("DW_OP_breg4: %ld", read_leb128 (data, NULL, 1));
5485 printf ("DW_OP_breg5: %ld", read_leb128 (data, NULL, 1));
5488 printf ("DW_OP_breg6: %ld", read_leb128 (data, NULL, 1));
5491 printf ("DW_OP_breg7: %ld", read_leb128 (data, NULL, 1));
5494 printf ("DW_OP_breg8: %ld", read_leb128 (data, NULL, 1));
5497 printf ("DW_OP_breg9: %ld", read_leb128 (data, NULL, 1));
5500 printf ("DW_OP_breg10: %ld", read_leb128 (data, NULL, 1));
5503 printf ("DW_OP_breg11: %ld", read_leb128 (data, NULL, 1));
5506 printf ("DW_OP_breg12: %ld", read_leb128 (data, NULL, 1));
5509 printf ("DW_OP_breg13: %ld", read_leb128 (data, NULL, 1));
5512 printf ("DW_OP_breg14: %ld", read_leb128 (data, NULL, 1));
5515 printf ("DW_OP_breg15: %ld", read_leb128 (data, NULL, 1));
5518 printf ("DW_OP_breg16: %ld", read_leb128 (data, NULL, 1));
5521 printf ("DW_OP_breg17: %ld", read_leb128 (data, NULL, 1));
5524 printf ("DW_OP_breg18: %ld", read_leb128 (data, NULL, 1));
5527 printf ("DW_OP_breg19: %ld", read_leb128 (data, NULL, 1));
5530 printf ("DW_OP_breg20: %ld", read_leb128 (data, NULL, 1));
5533 printf ("DW_OP_breg21: %ld", read_leb128 (data, NULL, 1));
5536 printf ("DW_OP_breg22: %ld", read_leb128 (data, NULL, 1));
5539 printf ("DW_OP_breg23: %ld", read_leb128 (data, NULL, 1));
5542 printf ("DW_OP_breg24: %ld", read_leb128 (data, NULL, 1));
5545 printf ("DW_OP_breg25: %ld", read_leb128 (data, NULL, 1));
5548 printf ("DW_OP_breg26: %ld", read_leb128 (data, NULL, 1));
5551 printf ("DW_OP_breg27: %ld", read_leb128 (data, NULL, 1));
5554 printf ("DW_OP_breg28: %ld", read_leb128 (data, NULL, 1));
5557 printf ("DW_OP_breg29: %ld", read_leb128 (data, NULL, 1));
5560 printf ("DW_OP_breg30: %ld", read_leb128 (data, NULL, 1));
5563 printf ("DW_OP_breg31: %ld", read_leb128 (data, NULL, 1));
5566 printf ("DW_OP_regx: %lu", read_leb128 (data, NULL, 0));
5569 printf ("DW_OP_fbreg: %ld", read_leb128 (data, NULL, 1));
5572 uvalue = read_leb128 (data, &bytes_read, 0);
5573 printf ("DW_OP_bregx: %lu %ld", uvalue,
5574 read_leb128 (data + bytes_read, NULL, 1));
5577 printf ("DW_OP_piece: %lu", read_leb128 (data, NULL, 0));
5579 case DW_OP_deref_size:
5580 printf ("DW_OP_deref_size: %ld", (long) byte_get (data, 1));
5582 case DW_OP_xderef_size:
5583 printf ("DW_OP_xderef_size: %ld", (long) byte_get (data, 1));
5586 printf ("DW_OP_nop");
5590 if (op >= DW_OP_lo_user
5591 && op <= DW_OP_hi_user)
5592 printf (_("(User defined location op)"));
5594 printf (_("(Unknown location op)"));
5600 static unsigned char *
5601 read_and_display_attr (attribute, form, data, pointer_size)
5602 unsigned long attribute;
5604 unsigned char * data;
5605 unsigned long pointer_size;
5607 unsigned long uvalue = 0;
5608 unsigned char * block_start = NULL;
5612 printf (" %-18s:", get_AT_name (attribute));
5616 case DW_FORM_ref_addr:
5621 case DW_FORM_ref_udata:
5627 case DW_FORM_ref_addr:
5629 uvalue = byte_get (data, pointer_size);
5630 printf (is_ref ? " <%x>" : " %#x", uvalue);
5631 data += pointer_size;
5637 uvalue = byte_get (data ++, 1);
5638 printf (is_ref ? " <%x>" : " %d", uvalue);
5643 uvalue = byte_get (data, 2);
5645 printf (is_ref ? " <%x>" : " %d", uvalue);
5650 uvalue = byte_get (data, 4);
5652 printf (is_ref ? " <%x>" : " %d", uvalue);
5657 uvalue = byte_get (data, 4);
5658 printf (" %lx", uvalue);
5659 printf (" %lx", (unsigned long) byte_get (data + 4, 4));
5663 case DW_FORM_string:
5664 printf (" %s", data);
5665 data += strlen (data) + 1;
5669 uvalue = read_leb128 (data, & bytes_read, 1);
5671 printf (" %ld", (long) uvalue);
5674 case DW_FORM_ref_udata:
5676 uvalue = read_leb128 (data, & bytes_read, 0);
5678 printf (is_ref ? " <%lx>" : " %ld", uvalue);
5682 uvalue = read_leb128 (data, & bytes_read, 0);
5683 block_start = data + bytes_read;
5684 data = display_block (block_start, uvalue);
5685 uvalue = * block_start;
5688 case DW_FORM_block1:
5689 uvalue = byte_get (data, 1);
5690 block_start = data + 1;
5691 data = display_block (block_start, uvalue);
5692 uvalue = * block_start;
5695 case DW_FORM_block2:
5696 uvalue = byte_get (data, 2);
5697 block_start = data + 2;
5698 data = display_block (block_start, uvalue);
5699 uvalue = * block_start;
5702 case DW_FORM_block4:
5703 uvalue = byte_get (data, 4);
5704 block_start = data + 4;
5705 data = display_block (block_start, uvalue);
5706 uvalue = * block_start;
5710 case DW_FORM_indirect:
5711 warn (_("Unable to handle FORM: %d"), form);
5715 warn (_("Unrecognised form: %d"), form);
5719 /* For some attributes we can display futher information. */
5728 case DW_INL_not_inlined: printf (_("(not inlined)")); break;
5729 case DW_INL_inlined: printf (_("(inlined)")); break;
5730 case DW_INL_declared_not_inlined: printf (_("(declared as inline but ignored)")); break;
5731 case DW_INL_declared_inlined: printf (_("(declared as inline and inlined)")); break;
5732 default: printf (_(" (Unknown inline attribute value: %lx)"), uvalue); break;
5736 case DW_AT_frame_base:
5737 if (uvalue >= DW_OP_reg0 && uvalue <= DW_OP_reg31)
5738 printf ("(reg %ld)", uvalue - DW_OP_reg0);
5741 case DW_AT_language:
5744 case DW_LANG_C: printf ("(non-ANSI C)"); break;
5745 case DW_LANG_C89: printf ("(ANSI C)"); break;
5746 case DW_LANG_C_plus_plus: printf ("(C++)"); break;
5747 case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break;
5748 case DW_LANG_Fortran90: printf ("(Fortran 90)"); break;
5749 case DW_LANG_Modula2: printf ("(Modula 2)"); break;
5750 case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break;
5751 case DW_LANG_Ada83: printf ("(Ada)"); break;
5752 case DW_LANG_Cobol74: printf ("(Cobol 74)"); break;
5753 case DW_LANG_Cobol85: printf ("(Cobol 85)"); break;
5754 case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break;
5755 default: printf ("(Unknown: %lx)", uvalue); break;
5759 case DW_AT_encoding:
5762 case DW_ATE_void: printf ("(void)"); break;
5763 case DW_ATE_address: printf ("(machine address)"); break;
5764 case DW_ATE_boolean: printf ("(boolean)"); break;
5765 case DW_ATE_complex_float: printf ("(complex float)"); break;
5766 case DW_ATE_float: printf ("(float)"); break;
5767 case DW_ATE_signed: printf ("(signed)"); break;
5768 case DW_ATE_signed_char: printf ("(signed char)"); break;
5769 case DW_ATE_unsigned: printf ("(unsigned)"); break;
5770 case DW_ATE_unsigned_char: printf ("(unsigned char)"); break;
5772 if (uvalue >= DW_ATE_lo_user
5773 && uvalue <= DW_ATE_hi_user)
5774 printf ("(user defined type)");
5776 printf ("(unknown type)");
5781 case DW_AT_accessibility:
5784 case DW_ACCESS_public: printf ("(public)"); break;
5785 case DW_ACCESS_protected: printf ("(protected)"); break;
5786 case DW_ACCESS_private: printf ("(private)"); break;
5787 default: printf ("(unknown accessibility)"); break;
5791 case DW_AT_visibility:
5794 case DW_VIS_local: printf ("(local)"); break;
5795 case DW_VIS_exported: printf ("(exported)"); break;
5796 case DW_VIS_qualified: printf ("(qualified)"); break;
5797 default: printf ("(unknown visibility)"); break;
5801 case DW_AT_virtuality:
5804 case DW_VIRTUALITY_none: printf ("(none)"); break;
5805 case DW_VIRTUALITY_virtual: printf ("(virtual)"); break;
5806 case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break;
5807 default: printf ("(unknown virtuality)"); break;
5811 case DW_AT_identifier_case:
5814 case DW_ID_case_sensitive: printf ("(case_sensitive)"); break;
5815 case DW_ID_up_case: printf ("(up_case)"); break;
5816 case DW_ID_down_case: printf ("(down_case)"); break;
5817 case DW_ID_case_insensitive: printf ("(case_insensitive)"); break;
5818 default: printf ("(unknown case)"); break;
5822 case DW_AT_calling_convention:
5825 case DW_CC_normal: printf ("(normal)"); break;
5826 case DW_CC_program: printf ("(program)"); break;
5827 case DW_CC_nocall: printf ("(nocall)"); break;
5829 if (uvalue >= DW_CC_lo_user
5830 && uvalue <= DW_CC_hi_user)
5831 printf ("(user defined)");
5833 printf ("(unknown convention)");
5837 case DW_AT_location:
5838 case DW_AT_data_member_location:
5839 case DW_AT_vtable_elem_location:
5841 decode_location_expression (block_start, pointer_size);
5854 display_debug_info (section, start, file)
5855 Elf32_Internal_Shdr * section;
5856 unsigned char * start;
5859 unsigned char * end = start + section->sh_size;
5860 unsigned char * section_begin = start;
5862 printf (_("The section %s contains:\n\n"), SECTION_NAME (section));
5866 DWARF2_External_CompUnit * external;
5867 DWARF2_Internal_CompUnit compunit;
5868 unsigned char * tags;
5872 external = (DWARF2_External_CompUnit *) start;
5874 compunit.cu_length = BYTE_GET (external->cu_length);
5875 compunit.cu_version = BYTE_GET (external->cu_version);
5876 compunit.cu_abbrev_offset = BYTE_GET (external->cu_abbrev_offset);
5877 compunit.cu_pointer_size = BYTE_GET (external->cu_pointer_size);
5879 tags = start + sizeof (* external);
5880 start += compunit.cu_length + sizeof (external->cu_length);
5882 if (compunit.cu_version != 2)
5884 warn (_("Only version 2 DWARF debug information is currently supported.\n"));
5888 printf (_(" Compilation Unit:\n"));
5889 printf (_(" Length: %ld\n"), compunit.cu_length);
5890 printf (_(" Version: %d\n"), compunit.cu_version);
5891 printf (_(" Abbrev Offset: %ld\n"), compunit.cu_abbrev_offset);
5892 printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size);
5894 if (first_abbrev != NULL)
5897 /* Read in the abbrevs used by this compilation unit. */
5900 Elf32_Internal_Shdr * sec;
5901 unsigned char * begin;
5903 /* Locate the .debug_abbrev section and process it. */
5904 for (i = 0, sec = section_headers;
5905 i < elf_header.e_shnum;
5907 if (strcmp (SECTION_NAME (sec), ".debug_abbrev") == 0)
5910 if (i == -1 || sec->sh_size == 0)
5912 warn (_("Unable to locate .debug_abbrev section!\n"));
5916 GET_DATA_ALLOC (sec->sh_offset, sec->sh_size, begin, unsigned char *,
5917 "debug_abbrev section data");
5919 process_abbrev_section (begin + compunit.cu_abbrev_offset,
5920 begin + sec->sh_size);
5926 while (tags < start)
5929 unsigned long abbrev_number;
5930 abbrev_entry * entry;
5933 abbrev_number = read_leb128 (tags, & bytes_read, 0);
5936 /* A null DIE marks the end of a list of children. */
5937 if (abbrev_number == 0)
5943 /* Scan through the abbreviation list until we reach the
5945 for (entry = first_abbrev;
5946 entry && entry->entry != abbrev_number;
5947 entry = entry->next)
5952 warn (_("Unable to locate entry %lu in the abbreviation table\n"),
5957 printf (_(" <%d><%x>: Abbrev Number: %lu (%s)\n"),
5958 level, tags - section_begin - bytes_read,
5960 get_TAG_name (entry->tag));
5962 for (attr = entry->first_attr; attr; attr = attr->next)
5963 tags = read_and_display_attr (attr->attribute,
5966 compunit.cu_pointer_size);
5968 if (entry->children)
5979 display_debug_aranges (section, start, file)
5980 Elf32_Internal_Shdr * section;
5981 unsigned char * start;
5982 FILE * file ATTRIBUTE_UNUSED;
5984 unsigned char * end = start + section->sh_size;
5986 printf (_("The section %s contains:\n\n"), SECTION_NAME (section));
5990 DWARF2_External_ARange * external;
5991 DWARF2_Internal_ARange arange;
5992 unsigned char * ranges;
5993 unsigned long length;
5994 unsigned long address;
5997 external = (DWARF2_External_ARange *) start;
5999 arange.ar_length = BYTE_GET (external->ar_length);
6000 arange.ar_version = BYTE_GET (external->ar_version);
6001 arange.ar_info_offset = BYTE_GET (external->ar_info_offset);
6002 arange.ar_pointer_size = BYTE_GET (external->ar_pointer_size);
6003 arange.ar_segment_size = BYTE_GET (external->ar_segment_size);
6005 printf (_(" Length: %ld\n"), arange.ar_length);
6006 printf (_(" Version: %d\n"), arange.ar_version);
6007 printf (_(" Offset into .debug_info: %lx\n"), arange.ar_info_offset);
6008 printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
6009 printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
6011 printf (_("\n Address Length\n"));
6013 ranges = start + sizeof (* external);
6015 /* Must pad to an alignment boundary that is twice the pointer size. */
6016 excess = sizeof (*external) % (2 * arange.ar_pointer_size);
6018 ranges += (2 * arange.ar_pointer_size) - excess;
6022 address = byte_get (ranges, arange.ar_pointer_size);
6024 ranges += arange.ar_pointer_size;
6026 length = byte_get (ranges, arange.ar_pointer_size);
6028 ranges += arange.ar_pointer_size;
6030 /* A pair of zeros marks the end of the list. */
6031 if (address == 0 && length == 0)
6034 printf (" %8.8lx %lu\n", address, length);
6037 start += arange.ar_length + sizeof (external->ar_length);
6047 display_debug_not_supported (section, start, file)
6048 Elf32_Internal_Shdr * section;
6049 unsigned char * start ATTRIBUTE_UNUSED;
6050 FILE * file ATTRIBUTE_UNUSED;
6052 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
6053 SECTION_NAME (section));
6058 /* Pre-scan the .debug_info section to record the size of address.
6059 When dumping the .debug_line, we use that size information, assuming
6060 that all compilation units have the same address size. */
6062 prescan_debug_info (section, start, file)
6063 Elf32_Internal_Shdr * section ATTRIBUTE_UNUSED;
6064 unsigned char * start;
6065 FILE * file ATTRIBUTE_UNUSED;
6067 DWARF2_External_CompUnit * external;
6069 external = (DWARF2_External_CompUnit *) start;
6071 debug_line_pointer_size = BYTE_GET (external->cu_pointer_size);
6075 /* A structure containing the name of a debug section and a pointer
6076 to a function that can decode it. The third field is a prescan
6077 function to be run over the section before displaying any of the
6082 int (* display) PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
6083 int (* prescan) PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
6087 { ".debug_info", display_debug_info, prescan_debug_info },
6088 { ".debug_abbrev", display_debug_abbrev, NULL },
6089 { ".debug_line", display_debug_lines, NULL },
6090 { ".debug_aranges", display_debug_aranges, NULL },
6091 { ".debug_pubnames", display_debug_pubnames, NULL },
6092 { ".debug_macinfo", display_debug_not_supported, NULL },
6093 { ".debug_frame", display_debug_not_supported, NULL },
6094 { ".debug_str", display_debug_not_supported, NULL },
6095 { ".debug_static_func", display_debug_not_supported, NULL },
6096 { ".debug_static_vars", display_debug_not_supported, NULL },
6097 { ".debug_types", display_debug_not_supported, NULL },
6098 { ".debug_weaknames", display_debug_not_supported, NULL }
6102 display_debug_section (section, file)
6103 Elf32_Internal_Shdr * section;
6106 char * name = SECTION_NAME (section);
6107 bfd_size_type length;
6108 unsigned char * start;
6111 length = section->sh_size;
6114 printf (_("\nSection '%s' has no debugging data.\n"), name);
6118 GET_DATA_ALLOC (section->sh_offset, length, start, unsigned char *,
6119 "debug section data");
6121 /* See if we know how to display the contents of this section. */
6122 for (i = NUM_ELEM (debug_displays); i--;)
6123 if (strcmp (debug_displays[i].name, name) == 0)
6125 debug_displays[i].display (section, start, file);
6130 printf (_("Unrecognised debug section: %s\n"), name);
6134 /* If we loaded in the abbrev section at some point,
6135 we must release it here. */
6136 if (first_abbrev != NULL)
6143 process_section_contents (file)
6146 Elf32_Internal_Shdr * section;
6152 /* Pre-scan the debug sections to find some debug information not
6153 present in some of them. For the .debug_line, we must find out the
6154 size of address (specified in .debug_info and .debug_aranges). */
6155 for (i = 0, section = section_headers;
6156 i < elf_header.e_shnum && i < num_dump_sects;
6159 char * name = SECTION_NAME (section);
6162 if (section->sh_size == 0)
6165 /* See if there is some pre-scan operation for this section. */
6166 for (j = NUM_ELEM (debug_displays); j--;)
6167 if (strcmp (debug_displays[j].name, name) == 0)
6169 if (debug_displays[j].prescan != NULL)
6171 bfd_size_type length;
6172 unsigned char * start;
6174 length = section->sh_size;
6175 GET_DATA_ALLOC (section->sh_offset, length, start, unsigned char *,
6176 "debug section data");
6178 debug_displays[j].prescan (section, start, file);
6186 for (i = 0, section = section_headers;
6187 i < elf_header.e_shnum && i < num_dump_sects;
6190 #ifdef SUPPORT_DISASSEMBLY
6191 if (dump_sects[i] & DISASS_DUMP)
6192 disassemble_section (section, file);
6194 if (dump_sects[i] & HEX_DUMP)
6195 dump_section (section, file);
6197 if (dump_sects[i] & DEBUG_DUMP)
6198 display_debug_section (section, file);
6201 if (i < num_dump_sects)
6202 warn (_("Some sections were not dumped because they do not exist!\n"));
6208 process_mips_fpe_exception (mask)
6214 if (mask & OEX_FPU_INEX)
6215 fputs ("INEX", stdout), first = 0;
6216 if (mask & OEX_FPU_UFLO)
6217 printf ("%sUFLO", first ? "" : "|"), first = 0;
6218 if (mask & OEX_FPU_OFLO)
6219 printf ("%sOFLO", first ? "" : "|"), first = 0;
6220 if (mask & OEX_FPU_DIV0)
6221 printf ("%sDIV0", first ? "" : "|"), first = 0;
6222 if (mask & OEX_FPU_INVAL)
6223 printf ("%sINVAL", first ? "" : "|");
6226 fputs ("0", stdout);
6230 process_mips_specific (file)
6233 Elf_Internal_Dyn * entry;
6234 size_t liblist_offset = 0;
6235 size_t liblistno = 0;
6236 size_t conflictsno = 0;
6237 size_t options_offset = 0;
6238 size_t conflicts_offset = 0;
6240 /* We have a lot of special sections. Thanks SGI! */
6241 if (dynamic_segment == NULL)
6242 /* No information available. */
6245 for (entry = dynamic_segment; entry->d_tag != DT_NULL; ++entry)
6246 switch (entry->d_tag)
6248 case DT_MIPS_LIBLIST:
6249 liblist_offset = entry->d_un.d_val - loadaddr;
6251 case DT_MIPS_LIBLISTNO:
6252 liblistno = entry->d_un.d_val;
6254 case DT_MIPS_OPTIONS:
6255 options_offset = entry->d_un.d_val - loadaddr;
6257 case DT_MIPS_CONFLICT:
6258 conflicts_offset = entry->d_un.d_val - loadaddr;
6260 case DT_MIPS_CONFLICTNO:
6261 conflictsno = entry->d_un.d_val;
6267 if (liblist_offset != 0 && liblistno != 0 && do_dynamic)
6269 Elf32_External_Lib * elib;
6272 GET_DATA_ALLOC (liblist_offset, liblistno * sizeof (Elf32_External_Lib),
6273 elib, Elf32_External_Lib *, "liblist");
6275 printf ("\nSection '.liblist' contains %d entries:\n", liblistno);
6276 fputs (" Library Time Stamp Checksum Version Flags\n",
6279 for (cnt = 0; cnt < liblistno; ++cnt)
6285 liblist.l_name = BYTE_GET (elib[cnt].l_name);
6286 time = BYTE_GET (elib[cnt].l_time_stamp);
6287 liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum);
6288 liblist.l_version = BYTE_GET (elib[cnt].l_version);
6289 liblist.l_flags = BYTE_GET (elib[cnt].l_flags);
6291 strftime (timebuf, 20, "%Y-%m-%dT%H:%M:%S", gmtime (&time));
6293 printf ("%3d: %-20s %s %#10lx %-7ld", cnt,
6294 dynamic_strings + liblist.l_name, timebuf,
6295 liblist.l_checksum, liblist.l_version);
6297 if (liblist.l_flags == 0)
6307 { " EXACT_MATCH", LL_EXACT_MATCH },
6308 { " IGNORE_INT_VER", LL_IGNORE_INT_VER },
6309 { " REQUIRE_MINOR", LL_REQUIRE_MINOR },
6310 { " EXPORTS", LL_EXPORTS },
6311 { " DELAY_LOAD", LL_DELAY_LOAD },
6312 { " DELTA", LL_DELTA }
6314 int flags = liblist.l_flags;
6318 fcnt < sizeof (l_flags_vals) / sizeof (l_flags_vals[0]);
6320 if ((flags & l_flags_vals[fcnt].bit) != 0)
6322 fputs (l_flags_vals[fcnt].name, stdout);
6323 flags ^= l_flags_vals[fcnt].bit;
6326 printf (" %#x", (unsigned int) flags);
6335 if (options_offset != 0)
6337 Elf_External_Options * eopt;
6338 Elf_Internal_Shdr * sect = section_headers;
6339 Elf_Internal_Options * iopt;
6340 Elf_Internal_Options * option;
6344 /* Find the section header so that we get the size. */
6345 while (sect->sh_type != SHT_MIPS_OPTIONS)
6348 GET_DATA_ALLOC (options_offset, sect->sh_size, eopt,
6349 Elf_External_Options *, "options");
6351 iopt = (Elf_Internal_Options *) malloc ((sect->sh_size / sizeof (eopt))
6355 error (_("Out of memory"));
6361 while (offset < sect->sh_size)
6363 Elf_External_Options * eoption;
6365 eoption = (Elf_External_Options *) ((char *) eopt + offset);
6367 option->kind = BYTE_GET (eoption->kind);
6368 option->size = BYTE_GET (eoption->size);
6369 option->section = BYTE_GET (eoption->section);
6370 option->info = BYTE_GET (eoption->info);
6372 offset += option->size;
6377 printf (_("\nSection '%s' contains %d entries:\n"),
6378 string_table + sect->sh_name, cnt);
6385 switch (option->kind)
6388 /* This shouldn't happen. */
6389 printf (" NULL %d %lx", option->section, option->info);
6392 printf (" REGINFO ");
6393 if (elf_header.e_machine == EM_MIPS)
6396 Elf32_External_RegInfo *ereg;
6397 Elf32_RegInfo reginfo;
6399 ereg = (Elf32_External_RegInfo *) (option + 1);
6400 reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask);
6401 reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
6402 reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
6403 reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
6404 reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
6405 reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value);
6407 printf ("GPR %08lx GP 0x%lx\n",
6409 (unsigned long) reginfo.ri_gp_value);
6410 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
6411 reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
6412 reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
6417 Elf64_External_RegInfo * ereg;
6418 Elf64_Internal_RegInfo reginfo;
6420 ereg = (Elf64_External_RegInfo *) (option + 1);
6421 reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask);
6422 reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
6423 reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
6424 reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
6425 reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
6426 reginfo.ri_gp_value = BYTE_GET8 (ereg->ri_gp_value);
6428 printf ("GPR %08lx GP 0x",
6429 reginfo.ri_gprmask);
6430 printf_vma (reginfo.ri_gp_value);
6433 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
6434 reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
6435 reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
6439 case ODK_EXCEPTIONS:
6440 fputs (" EXCEPTIONS fpe_min(", stdout);
6441 process_mips_fpe_exception (option->info & OEX_FPU_MIN);
6442 fputs (") fpe_max(", stdout);
6443 process_mips_fpe_exception ((option->info & OEX_FPU_MAX) >> 8);
6444 fputs (")", stdout);
6446 if (option->info & OEX_PAGE0)
6447 fputs (" PAGE0", stdout);
6448 if (option->info & OEX_SMM)
6449 fputs (" SMM", stdout);
6450 if (option->info & OEX_FPDBUG)
6451 fputs (" FPDBUG", stdout);
6452 if (option->info & OEX_DISMISS)
6453 fputs (" DISMISS", stdout);
6456 fputs (" PAD ", stdout);
6457 if (option->info & OPAD_PREFIX)
6458 fputs (" PREFIX", stdout);
6459 if (option->info & OPAD_POSTFIX)
6460 fputs (" POSTFIX", stdout);
6461 if (option->info & OPAD_SYMBOL)
6462 fputs (" SYMBOL", stdout);
6465 fputs (" HWPATCH ", stdout);
6466 if (option->info & OHW_R4KEOP)
6467 fputs (" R4KEOP", stdout);
6468 if (option->info & OHW_R8KPFETCH)
6469 fputs (" R8KPFETCH", stdout);
6470 if (option->info & OHW_R5KEOP)
6471 fputs (" R5KEOP", stdout);
6472 if (option->info & OHW_R5KCVTL)
6473 fputs (" R5KCVTL", stdout);
6476 fputs (" FILL ", stdout);
6477 /* XXX Print content of info word? */
6480 fputs (" TAGS ", stdout);
6481 /* XXX Print content of info word? */
6484 fputs (" HWAND ", stdout);
6485 if (option->info & OHWA0_R4KEOP_CHECKED)
6486 fputs (" R4KEOP_CHECKED", stdout);
6487 if (option->info & OHWA0_R4KEOP_CLEAN)
6488 fputs (" R4KEOP_CLEAN", stdout);
6491 fputs (" HWOR ", stdout);
6492 if (option->info & OHWA0_R4KEOP_CHECKED)
6493 fputs (" R4KEOP_CHECKED", stdout);
6494 if (option->info & OHWA0_R4KEOP_CLEAN)
6495 fputs (" R4KEOP_CLEAN", stdout);
6498 printf (" GP_GROUP %#06lx self-contained %#06lx",
6499 option->info & OGP_GROUP,
6500 (option->info & OGP_SELF) >> 16);
6503 printf (" IDENT %#06lx self-contained %#06lx",
6504 option->info & OGP_GROUP,
6505 (option->info & OGP_SELF) >> 16);
6508 /* This shouldn't happen. */
6509 printf (" %3d ??? %d %lx",
6510 option->kind, option->section, option->info);
6514 len = sizeof (*eopt);
6515 while (len < option->size)
6516 if (((char *) option)[len] >= ' '
6517 && ((char *) option)[len] < 0x7f)
6518 printf ("%c", ((char *) option)[len++]);
6520 printf ("\\%03o", ((char *) option)[len++]);
6522 fputs ("\n", stdout);
6529 if (conflicts_offset != 0 && conflictsno != 0)
6531 Elf32_External_Conflict * econf32;
6532 Elf64_External_Conflict * econf64;
6533 Elf32_Conflict * iconf;
6536 if (dynamic_symbols == NULL)
6538 error (_("conflict list with without table"));
6542 iconf = (Elf32_Conflict *) malloc (conflictsno * sizeof (*iconf));
6545 error (_("Out of memory"));
6551 GET_DATA_ALLOC (conflicts_offset, conflictsno * sizeof (*econf32),
6552 econf32, Elf32_External_Conflict *, "conflict");
6554 for (cnt = 0; cnt < conflictsno; ++cnt)
6555 iconf[cnt] = BYTE_GET (econf32[cnt]);
6559 GET_DATA_ALLOC (conflicts_offset, conflictsno * sizeof (*econf64),
6560 econf64, Elf64_External_Conflict *, "conflict");
6562 for (cnt = 0; cnt < conflictsno; ++cnt)
6563 iconf[cnt] = BYTE_GET (econf64[cnt]);
6566 printf (_("\nSection '.conflict' contains %d entries:\n"), conflictsno);
6567 puts (_(" Num: Index Value Name"));
6569 for (cnt = 0; cnt < conflictsno; ++cnt)
6571 Elf_Internal_Sym * psym = &dynamic_symbols[iconf[cnt]];
6573 printf ("%5u: %8lu %#10lx %s\n",
6574 cnt, iconf[cnt], (unsigned long) psym->st_value,
6575 dynamic_strings + psym->st_name);
6586 get_note_type (e_type)
6589 static char buff[64];
6593 case NT_PRSTATUS: return _("NT_PRSTATUS (prstatus structure)");
6594 case NT_FPREGSET: return _("NT_FPREGSET (floating point registers)");
6595 case NT_PRPSINFO: return _("NT_PRPSINFO (prpsinfo structure)");
6596 case NT_TASKSTRUCT: return _("NT_TASKSTRUCT (task structure)");
6597 case NT_PSTATUS: return _("NT_PSTATUS (pstatus structure)");
6598 case NT_FPREGS: return _("NT_FPREGS (floating point registers)");
6599 case NT_PSINFO: return _("NT_PSINFO (psinfo structure)");
6600 case NT_LWPSTATUS: return _("NT_LWPSTATUS (lwpstatus_t structure)");
6601 case NT_LWPSINFO: return _("NT_LWPSINFO (lwpsinfo_t structure)");
6603 sprintf (buff, _("Unknown note type: (0x%08x)"), e_type);
6608 /* Note that by the ELF standard, the name field is already null byte
6609 terminated, and namesz includes the terminating null byte.
6610 I.E. the value of namesz for the name "FSF" is 4.
6612 If the value of namesz is zero, there is no name present. */
6614 process_note (pnote)
6615 Elf32_Internal_Note * pnote;
6617 printf (" %s\t\t0x%08lx\t%s\n",
6618 pnote->namesz ? pnote->namedata : "(NONE)",
6619 pnote->descsz, get_note_type (pnote->type));
6625 process_corefile_note_segment (file, offset, length)
6627 unsigned long offset;
6628 unsigned long length;
6630 Elf_External_Note * pnotes;
6631 Elf_External_Note * external;
6637 GET_DATA_ALLOC (offset, length, pnotes, Elf_External_Note *, "notes");
6641 printf (_("\nNotes at offset 0x%08lx with length 0x%08lx:\n"), offset, length);
6642 printf (_(" Owner\t\tData size\tDescription\n"));
6644 while (external < (Elf_External_Note *)((char *) pnotes + length))
6646 Elf32_Internal_Note inote;
6649 inote.type = BYTE_GET (external->type);
6650 inote.namesz = BYTE_GET (external->namesz);
6651 inote.namedata = external->name;
6652 inote.descsz = BYTE_GET (external->descsz);
6653 inote.descdata = inote.namedata + align_power (inote.namesz, 2);
6654 inote.descpos = offset + (inote.descdata - (char *) pnotes);
6656 external = (Elf_External_Note *)(inote.descdata + align_power (inote.descsz, 2));
6658 /* Verify that name is null terminated. It appears that at least
6659 one version of Linux (RedHat 6.0) generates corefiles that don't
6660 comply with the ELF spec by failing to include the null byte in
6662 if (inote.namedata[inote.namesz] != '\0')
6664 temp = malloc (inote.namesz + 1);
6668 error (_("Out of memory\n"));
6673 strncpy (temp, inote.namedata, inote.namesz);
6674 temp[inote.namesz] = 0;
6676 /* warn (_("'%s' NOTE name not properly null terminated\n"), temp); */
6677 inote.namedata = temp;
6680 res &= process_note (& inote);
6695 process_corefile_note_segments (file)
6698 Elf_Internal_Phdr * program_headers;
6699 Elf_Internal_Phdr * segment;
6703 program_headers = (Elf_Internal_Phdr *) malloc
6704 (elf_header.e_phnum * sizeof (Elf_Internal_Phdr));
6706 if (program_headers == NULL)
6708 error (_("Out of memory\n"));
6713 i = get_32bit_program_headers (file, program_headers);
6715 i = get_64bit_program_headers (file, program_headers);
6719 free (program_headers);
6723 for (i = 0, segment = program_headers;
6724 i < elf_header.e_phnum;
6727 if (segment->p_type == PT_NOTE)
6728 res &= process_corefile_note_segment (file,
6729 (unsigned long)segment->p_offset,
6730 (unsigned long)segment->p_filesz);
6733 free (program_headers);
6739 process_corefile_contents (file)
6742 /* If we have not been asked to display the notes then do nothing. */
6746 /* If file is not a core file then exit. */
6747 if (elf_header.e_type != ET_CORE)
6750 /* No program headers means no NOTE segment. */
6751 if (elf_header.e_phnum == 0)
6753 printf (_("No note segments present in the core file.\n"));
6757 return process_corefile_note_segments (file);
6761 process_arch_specific (file)
6767 switch (elf_header.e_machine)
6770 case EM_MIPS_RS4_BE:
6771 return process_mips_specific (file);
6780 get_file_header (file)
6783 /* Read in the identity array. */
6784 if (fread (elf_header.e_ident, EI_NIDENT, 1, file) != 1)
6787 /* Determine how to read the rest of the header. */
6788 switch (elf_header.e_ident [EI_DATA])
6790 default: /* fall through */
6791 case ELFDATANONE: /* fall through */
6792 case ELFDATA2LSB: byte_get = byte_get_little_endian; break;
6793 case ELFDATA2MSB: byte_get = byte_get_big_endian; break;
6796 /* For now we only support 32 bit and 64 bit ELF files. */
6797 is_32bit_elf = (elf_header.e_ident [EI_CLASS] != ELFCLASS64);
6799 /* Read in the rest of the header. */
6802 Elf32_External_Ehdr ehdr32;
6804 if (fread (ehdr32.e_type, sizeof (ehdr32) - EI_NIDENT, 1, file) != 1)
6807 elf_header.e_type = BYTE_GET (ehdr32.e_type);
6808 elf_header.e_machine = BYTE_GET (ehdr32.e_machine);
6809 elf_header.e_version = BYTE_GET (ehdr32.e_version);
6810 elf_header.e_entry = BYTE_GET (ehdr32.e_entry);
6811 elf_header.e_phoff = BYTE_GET (ehdr32.e_phoff);
6812 elf_header.e_shoff = BYTE_GET (ehdr32.e_shoff);
6813 elf_header.e_flags = BYTE_GET (ehdr32.e_flags);
6814 elf_header.e_ehsize = BYTE_GET (ehdr32.e_ehsize);
6815 elf_header.e_phentsize = BYTE_GET (ehdr32.e_phentsize);
6816 elf_header.e_phnum = BYTE_GET (ehdr32.e_phnum);
6817 elf_header.e_shentsize = BYTE_GET (ehdr32.e_shentsize);
6818 elf_header.e_shnum = BYTE_GET (ehdr32.e_shnum);
6819 elf_header.e_shstrndx = BYTE_GET (ehdr32.e_shstrndx);
6823 Elf64_External_Ehdr ehdr64;
6825 /* If we have been compiled with sizeof (bfd_vma) == 4, then
6826 we will not be able to cope with the 64bit data found in
6827 64 ELF files. Detect this now and abort before we start
6828 overwritting things. */
6829 if (sizeof (bfd_vma) < 8)
6831 error (_("This instance of readelf has been built without support for a\n"));
6832 error (_("64 bit data type and so it cannot read 64 bit ELF files.\n"));
6836 if (fread (ehdr64.e_type, sizeof (ehdr64) - EI_NIDENT, 1, file) != 1)
6839 elf_header.e_type = BYTE_GET (ehdr64.e_type);
6840 elf_header.e_machine = BYTE_GET (ehdr64.e_machine);
6841 elf_header.e_version = BYTE_GET (ehdr64.e_version);
6842 elf_header.e_entry = BYTE_GET8 (ehdr64.e_entry);
6843 elf_header.e_phoff = BYTE_GET8 (ehdr64.e_phoff);
6844 elf_header.e_shoff = BYTE_GET8 (ehdr64.e_shoff);
6845 elf_header.e_flags = BYTE_GET (ehdr64.e_flags);
6846 elf_header.e_ehsize = BYTE_GET (ehdr64.e_ehsize);
6847 elf_header.e_phentsize = BYTE_GET (ehdr64.e_phentsize);
6848 elf_header.e_phnum = BYTE_GET (ehdr64.e_phnum);
6849 elf_header.e_shentsize = BYTE_GET (ehdr64.e_shentsize);
6850 elf_header.e_shnum = BYTE_GET (ehdr64.e_shnum);
6851 elf_header.e_shstrndx = BYTE_GET (ehdr64.e_shstrndx);
6858 process_file (file_name)
6862 struct stat statbuf;
6865 if (stat (file_name, & statbuf) < 0)
6867 error (_("Cannot stat input file %s.\n"), file_name);
6871 file = fopen (file_name, "rb");
6874 error (_("Input file %s not found.\n"), file_name);
6878 if (! get_file_header (file))
6880 error (_("%s: Failed to read file header\n"), file_name);
6885 /* Initialise per file variables. */
6886 for (i = NUM_ELEM (version_info); i--;)
6887 version_info[i] = 0;
6889 for (i = NUM_ELEM (dynamic_info); i--;)
6890 dynamic_info[i] = 0;
6892 /* Process the file. */
6894 printf (_("\nFile: %s\n"), file_name);
6896 if (! process_file_header ())
6902 process_section_headers (file);
6904 process_program_headers (file);
6906 process_dynamic_segment (file);
6908 process_relocs (file);
6910 process_symbol_table (file);
6912 process_syminfo (file);
6914 process_version_sections (file);
6916 process_section_contents (file);
6918 process_corefile_contents (file);
6920 process_arch_specific (file);
6924 if (section_headers)
6926 free (section_headers);
6927 section_headers = NULL;
6932 free (string_table);
6933 string_table = NULL;
6936 if (dynamic_strings)
6938 free (dynamic_strings);
6939 dynamic_strings = NULL;
6942 if (dynamic_symbols)
6944 free (dynamic_symbols);
6945 dynamic_symbols = NULL;
6946 num_dynamic_syms = 0;
6949 if (dynamic_syminfo)
6951 free (dynamic_syminfo);
6952 dynamic_syminfo = NULL;
6956 #ifdef SUPPORT_DISASSEMBLY
6957 /* Needed by the i386 disassembler. For extra credit, someone could
6958 fix this so that we insert symbolic addresses here, esp for GOT/PLT
6962 print_address (unsigned int addr, FILE * outfile)
6964 fprintf (outfile,"0x%8.8x", addr);
6967 /* Needed by the i386 disassembler. */
6969 db_task_printsym (unsigned int addr)
6971 print_address (addr, stderr);
6980 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
6981 setlocale (LC_MESSAGES, "");
6983 bindtextdomain (PACKAGE, LOCALEDIR);
6984 textdomain (PACKAGE);
6986 parse_args (argc, argv);
6988 if (optind < (argc - 1))
6991 while (optind < argc)
6992 process_file (argv [optind ++]);
6994 if (dump_sects != NULL)