1 /* readelf.c -- display contents of an ELF format file
2 Copyright (C) 1998, 99, 2000 Free Software Foundation, Inc.
4 Originally developed by Eric Youngdale <eric@andante.jic.com>
5 Modifications by Nick Clifton <nickc@cygnus.com>
7 This file is part of GNU Binutils.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26 #include <sys/types.h>
32 /* Define BFD64 here, even if our default architecture is 32 bit ELF
33 as this will allow us to read in and parse 64bit and 32bit ELF files.
34 Only do this if we belive that the compiler can support a 64 bit
35 data type. For now we only rely on GCC being able to do this. */
41 #include "elf/common.h"
42 #include "elf/external.h"
43 #include "elf/internal.h"
44 #include "elf/dwarf2.h"
46 /* The following headers use the elf/reloc-macros.h file to
47 automatically generate relocation recognition functions
48 such as elf_mips_reloc_type() */
50 #define RELOC_MACROS_GEN_FUNC
56 #include "elf/alpha.h"
59 #include "elf/sparc.h"
64 #include "elf/mn10200.h"
65 #include "elf/mn10300.h"
69 #include "elf/mcore.h"
76 #include "elf/x86-64.h"
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;
122 /* A dynamic array of flags indicating which sections require dumping. */
123 char * dump_sects = NULL;
124 unsigned int num_dump_sects = 0;
126 #define HEX_DUMP (1 << 0)
127 #define DISASS_DUMP (1 << 1)
128 #define DEBUG_DUMP (1 << 2)
130 /* How to rpint a vma value. */
131 typedef enum print_mode
143 /* Forward declarations for dumb compilers. */
144 static void print_vma PARAMS ((bfd_vma, print_mode));
145 static bfd_vma (* byte_get) PARAMS ((unsigned char *, int));
146 static bfd_vma byte_get_little_endian PARAMS ((unsigned char *, int));
147 static bfd_vma byte_get_big_endian PARAMS ((unsigned char *, int));
148 static const char * get_mips_dynamic_type PARAMS ((unsigned long));
149 static const char * get_sparc64_dynamic_type PARAMS ((unsigned long));
150 static const char * get_parisc_dynamic_type PARAMS ((unsigned long));
151 static const char * get_dynamic_type PARAMS ((unsigned long));
152 static int dump_relocations PARAMS ((FILE *, unsigned long, unsigned long, Elf_Internal_Sym *, unsigned long, char *, int));
153 static char * get_file_type PARAMS ((unsigned));
154 static char * get_machine_name PARAMS ((unsigned));
155 static void decode_ARM_machine_flags PARAMS ((unsigned, char []));
156 static char * get_machine_flags PARAMS ((unsigned, unsigned));
157 static const char * get_mips_segment_type PARAMS ((unsigned long));
158 static const char * get_parisc_segment_type PARAMS ((unsigned long));
159 static const char * get_segment_type PARAMS ((unsigned long));
160 static const char * get_mips_section_type_name PARAMS ((unsigned int));
161 static const char * get_parisc_section_type_name PARAMS ((unsigned int));
162 static const char * get_section_type_name PARAMS ((unsigned int));
163 static const char * get_symbol_binding PARAMS ((unsigned int));
164 static const char * get_symbol_type PARAMS ((unsigned int));
165 static const char * get_symbol_visibility PARAMS ((unsigned int));
166 static const char * get_symbol_index_type PARAMS ((unsigned int));
167 static const char * get_dynamic_flags PARAMS ((bfd_vma));
168 static void usage PARAMS ((void));
169 static void parse_args PARAMS ((int, char **));
170 static int process_file_header PARAMS ((void));
171 static int process_program_headers PARAMS ((FILE *));
172 static int process_section_headers PARAMS ((FILE *));
173 static void dynamic_segment_mips_val PARAMS ((Elf_Internal_Dyn *));
174 static void dynamic_segment_parisc_val PARAMS ((Elf_Internal_Dyn *));
175 static int process_dynamic_segment PARAMS ((FILE *));
176 static int process_symbol_table PARAMS ((FILE *));
177 static int process_section_contents PARAMS ((FILE *));
178 static void process_file PARAMS ((char *));
179 static int process_relocs PARAMS ((FILE *));
180 static int process_version_sections PARAMS ((FILE *));
181 static char * get_ver_flags PARAMS ((unsigned int));
182 static int get_32bit_section_headers PARAMS ((FILE *));
183 static int get_64bit_section_headers PARAMS ((FILE *));
184 static int get_32bit_program_headers PARAMS ((FILE *, Elf_Internal_Phdr *));
185 static int get_64bit_program_headers PARAMS ((FILE *, Elf_Internal_Phdr *));
186 static int get_file_header PARAMS ((FILE *));
187 static Elf_Internal_Sym * get_32bit_elf_symbols PARAMS ((FILE *, unsigned long, unsigned long));
188 static Elf_Internal_Sym * get_64bit_elf_symbols PARAMS ((FILE *, unsigned long, unsigned long));
189 static int * get_dynamic_data PARAMS ((FILE *, unsigned int));
190 static int get_32bit_dynamic_segment PARAMS ((FILE *));
191 static int get_64bit_dynamic_segment PARAMS ((FILE *));
192 #ifdef SUPPORT_DISASSEMBLY
193 static int disassemble_section PARAMS ((Elf32_Internal_Shdr *, FILE *));
195 static int dump_section PARAMS ((Elf32_Internal_Shdr *, FILE *));
196 static int display_debug_section PARAMS ((Elf32_Internal_Shdr *, FILE *));
197 static int display_debug_info PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
198 static int display_debug_not_supported PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
199 static int display_debug_lines PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
200 static int display_debug_abbrev PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
201 static int display_debug_aranges PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
202 static int display_debug_frames PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
203 static unsigned char * process_abbrev_section PARAMS ((unsigned char *, unsigned char *));
204 static unsigned long read_leb128 PARAMS ((unsigned char *, int *, int));
205 static int process_extended_line_op PARAMS ((unsigned char *, int, int));
206 static void reset_state_machine PARAMS ((int));
207 static char * get_TAG_name PARAMS ((unsigned long));
208 static char * get_AT_name PARAMS ((unsigned long));
209 static char * get_FORM_name PARAMS ((unsigned long));
210 static void free_abbrevs PARAMS ((void));
211 static void add_abbrev PARAMS ((unsigned long, unsigned long, int));
212 static void add_abbrev_attr PARAMS ((unsigned long, unsigned long));
213 static unsigned char * read_and_display_attr PARAMS ((unsigned long, unsigned long, unsigned char *, unsigned long, unsigned long));
214 static unsigned char * display_block PARAMS ((unsigned char *, unsigned long));
215 static void decode_location_expression PARAMS ((unsigned char *, unsigned int, unsigned long));
216 static void request_dump PARAMS ((unsigned int, char));
217 static const char * get_elf_class PARAMS ((unsigned char));
218 static const char * get_data_encoding PARAMS ((unsigned char));
219 static const char * get_osabi_name PARAMS ((unsigned char));
220 static int guess_is_rela PARAMS ((unsigned long));
221 static char * get_note_type PARAMS ((unsigned int));
222 static int process_note PARAMS ((Elf32_Internal_Note *));
223 static int process_corefile_note_segment PARAMS ((FILE *, bfd_vma, bfd_vma));
224 static int process_corefile_note_segments PARAMS ((FILE *));
225 static int process_corefile_contents PARAMS ((FILE *));
227 typedef int Elf32_Word;
235 #define SECTION_NAME(X) (string_table + (X)->sh_name)
237 #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
239 #define BYTE_GET(field) byte_get (field, sizeof (field))
241 /* If we can support a 64 bit data type then BFD64 should be defined
242 and sizeof (bfd_vma) == 8. In this case when translating from an
243 external 8 byte field to an internal field, we can assume that the
244 internal field is also 8 bytes wide and so we can extact all the data.
245 If, however, BFD64 is not defined, then we must assume that the
246 internal data structure only has 4 byte wide fields that are the
247 equivalent of the 8 byte wide external counterparts, and so we must
248 truncate the data. */
250 #define BYTE_GET8(field) byte_get (field, -8)
252 #define BYTE_GET8(field) byte_get (field, 8)
255 #define NUM_ELEM(array) (sizeof (array) / sizeof ((array)[0]))
257 #define GET_DATA_ALLOC(offset, size, var, type, reason) \
258 if (fseek (file, offset, SEEK_SET)) \
260 error (_("Unable to seek to start of %s at %x\n"), reason, offset); \
264 var = (type) malloc (size); \
268 error (_("Out of memory allocating %d bytes for %s\n"), size, reason); \
272 if (fread (var, size, 1, file) != 1) \
274 error (_("Unable to read in %d bytes of %s\n"), size, reason); \
281 #define GET_DATA(offset, var, reason) \
282 if (fseek (file, offset, SEEK_SET)) \
284 error (_("Unable to seek to %x for %s\n"), offset, reason); \
287 else if (fread (& var, sizeof (var), 1, file) != 1) \
289 error (_("Unable to read data at %x for %s\n"), offset, reason); \
293 #define GET_ELF_SYMBOLS(file, offset, size) \
294 (is_32bit_elf ? get_32bit_elf_symbols (file, offset, size) \
295 : get_64bit_elf_symbols (file, offset, size))
298 #ifdef ANSI_PROTOTYPES
300 error (const char * message, ...)
304 fprintf (stderr, _("%s: Error: "), program_name);
305 va_start (args, message);
306 vfprintf (stderr, message, args);
312 warn (const char * message, ...)
316 fprintf (stderr, _("%s: Warning: "), program_name);
317 va_start (args, message);
318 vfprintf (stderr, message, args);
330 fprintf (stderr, _("%s: Error: "), program_name);
332 message = va_arg (args, char *);
333 vfprintf (stderr, message, args);
345 fprintf (stderr, _("%s: Warning: "), program_name);
347 message = va_arg (args, char *);
348 vfprintf (stderr, message, args);
355 byte_get_little_endian (field, size)
356 unsigned char * field;
365 return ((unsigned int) (field [0]))
366 | (((unsigned int) (field [1])) << 8);
369 /* We want to extract data from an 8 byte wide field and
370 place it into a 4 byte wide field. Since this is a little
371 endian source we can juts use the 4 byte extraction code. */
374 return ((unsigned long) (field [0]))
375 | (((unsigned long) (field [1])) << 8)
376 | (((unsigned long) (field [2])) << 16)
377 | (((unsigned long) (field [3])) << 24);
381 /* This is a special case, generated by the BYTE_GET8 macro.
382 It means that we are loading an 8 byte value from a field
383 in an external structure into an 8 byte value in a field
384 in an internal strcuture. */
385 return ((bfd_vma) (field [0]))
386 | (((bfd_vma) (field [1])) << 8)
387 | (((bfd_vma) (field [2])) << 16)
388 | (((bfd_vma) (field [3])) << 24)
389 | (((bfd_vma) (field [4])) << 32)
390 | (((bfd_vma) (field [5])) << 40)
391 | (((bfd_vma) (field [6])) << 48)
392 | (((bfd_vma) (field [7])) << 56);
395 error (_("Unhandled data length: %d\n"), size);
400 /* Print a VMA value. */
402 print_vma (vma, mode)
412 case FULL_HEX: printf ("0x"); /* drop through */
413 case LONG_HEX: printf ("%8.8lx", (unsigned long) vma); break;
414 case PREFIX_HEX: printf ("0x"); /* drop through */
415 case HEX: printf ("%lx", (unsigned long) vma); break;
416 case DEC: printf ("%ld", (unsigned long) vma); break;
417 case DEC_5: printf ("%5ld", (long) vma); break;
418 case UNSIGNED: printf ("%lu", (unsigned long) vma); break;
439 #if BFD_HOST_64BIT_LONG
442 if (_bfd_int64_high (vma))
443 printf ("%lx%lx", _bfd_int64_high (vma), _bfd_int64_low (vma));
445 printf ("%lx", _bfd_int64_low (vma));
450 #if BFD_HOST_64BIT_LONG
453 if (_bfd_int64_high (vma))
455 printf ("++%ld", _bfd_int64_low (vma));
457 printf ("%ld", _bfd_int64_low (vma));
462 #if BFD_HOST_64BIT_LONG
463 printf ("%5ld", vma);
465 if (_bfd_int64_high (vma))
467 printf ("++%ld", _bfd_int64_low (vma));
469 printf ("%5ld", _bfd_int64_low (vma));
474 #if BFD_HOST_64BIT_LONG
477 if (_bfd_int64_high (vma))
479 printf ("++%lu", _bfd_int64_low (vma));
481 printf ("%lu", _bfd_int64_low (vma));
490 byte_get_big_endian (field, size)
491 unsigned char * field;
500 return ((unsigned int) (field [1])) | (((int) (field [0])) << 8);
503 return ((unsigned long) (field [3]))
504 | (((unsigned long) (field [2])) << 8)
505 | (((unsigned long) (field [1])) << 16)
506 | (((unsigned long) (field [0])) << 24);
509 /* Although we are extracing data from an 8 byte wide field, we
510 are returning only 4 bytes of data. */
511 return ((unsigned long) (field [7]))
512 | (((unsigned long) (field [6])) << 8)
513 | (((unsigned long) (field [5])) << 16)
514 | (((unsigned long) (field [4])) << 24);
518 /* This is a special case, generated by the BYTE_GET8 macro.
519 It means that we are loading an 8 byte value from a field
520 in an external structure into an 8 byte value in a field
521 in an internal strcuture. */
522 return ((bfd_vma) (field [7]))
523 | (((bfd_vma) (field [6])) << 8)
524 | (((bfd_vma) (field [5])) << 16)
525 | (((bfd_vma) (field [4])) << 24)
526 | (((bfd_vma) (field [3])) << 32)
527 | (((bfd_vma) (field [2])) << 40)
528 | (((bfd_vma) (field [1])) << 48)
529 | (((bfd_vma) (field [0])) << 56);
533 error (_("Unhandled data length: %d\n"), size);
538 /* Guess the relocation size commonly used by the specific machines. */
541 guess_is_rela (e_machine)
542 unsigned long e_machine;
546 /* Targets that use REL relocations. */
557 /* Targets that use RELA relocations. */
565 case EM_CYGNUS_MN10200:
566 case EM_CYGNUS_MN10300:
597 warn (_("Don't know about relocations on this machine architecture\n"));
602 /* Display the contents of the relocation data found at the specified offset. */
604 dump_relocations (file, rel_offset, rel_size, symtab, nsyms, strtab, is_rela)
606 unsigned long rel_offset;
607 unsigned long rel_size;
608 Elf_Internal_Sym * symtab;
614 Elf_Internal_Rel * rels;
615 Elf_Internal_Rela * relas;
618 if (is_rela == UNKNOWN)
619 is_rela = guess_is_rela (elf_header.e_machine);
625 Elf32_External_Rela * erelas;
627 GET_DATA_ALLOC (rel_offset, rel_size, erelas,
628 Elf32_External_Rela *, "relocs");
630 rel_size = rel_size / sizeof (Elf32_External_Rela);
632 relas = (Elf_Internal_Rela *)
633 malloc (rel_size * sizeof (Elf_Internal_Rela));
637 error(_("out of memory parsing relocs"));
641 for (i = 0; i < rel_size; i++)
643 relas[i].r_offset = BYTE_GET (erelas[i].r_offset);
644 relas[i].r_info = BYTE_GET (erelas[i].r_info);
645 relas[i].r_addend = BYTE_GET (erelas[i].r_addend);
650 rels = (Elf_Internal_Rel *) relas;
654 Elf64_External_Rela * erelas;
656 GET_DATA_ALLOC (rel_offset, rel_size, erelas,
657 Elf64_External_Rela *, "relocs");
659 rel_size = rel_size / sizeof (Elf64_External_Rela);
661 relas = (Elf_Internal_Rela *)
662 malloc (rel_size * sizeof (Elf_Internal_Rela));
666 error(_("out of memory parsing relocs"));
670 for (i = 0; i < rel_size; i++)
672 relas[i].r_offset = BYTE_GET8 (erelas[i].r_offset);
673 relas[i].r_info = BYTE_GET8 (erelas[i].r_info);
674 relas[i].r_addend = BYTE_GET8 (erelas[i].r_addend);
679 rels = (Elf_Internal_Rel *) relas;
686 Elf32_External_Rel * erels;
688 GET_DATA_ALLOC (rel_offset, rel_size, erels,
689 Elf32_External_Rel *, "relocs");
691 rel_size = rel_size / sizeof (Elf32_External_Rel);
693 rels = (Elf_Internal_Rel *)
694 malloc (rel_size * sizeof (Elf_Internal_Rel));
698 error(_("out of memory parsing relocs"));
702 for (i = 0; i < rel_size; i++)
704 rels[i].r_offset = BYTE_GET (erels[i].r_offset);
705 rels[i].r_info = BYTE_GET (erels[i].r_info);
710 relas = (Elf_Internal_Rela *) rels;
714 Elf64_External_Rel * erels;
716 GET_DATA_ALLOC (rel_offset, rel_size, erels,
717 Elf64_External_Rel *, "relocs");
719 rel_size = rel_size / sizeof (Elf64_External_Rel);
721 rels = (Elf_Internal_Rel *)
722 malloc (rel_size * sizeof (Elf_Internal_Rel));
726 error(_("out of memory parsing relocs"));
730 for (i = 0; i < rel_size; i++)
732 rels[i].r_offset = BYTE_GET8 (erels[i].r_offset);
733 rels[i].r_info = BYTE_GET8 (erels[i].r_info);
738 relas = (Elf_Internal_Rela *) rels;
744 (_(" Offset Info Type Symbol's Value Symbol's Name Addend\n"));
747 (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
749 for (i = 0; i < rel_size; i++)
754 bfd_vma symtab_index;
759 offset = relas [i].r_offset;
760 info = relas [i].r_info;
764 offset = rels [i].r_offset;
765 info = rels [i].r_info;
770 type = ELF32_R_TYPE (info);
771 symtab_index = ELF32_R_SYM (info);
775 if (elf_header.e_machine == EM_SPARCV9)
776 type = ELF64_R_TYPE_ID (info);
778 type = ELF64_R_TYPE (info);
779 /* The #ifdef BFD64 below is to prevent a compile time warning.
780 We know that if we do not have a 64 bit data type that we
781 will never execute this code anyway. */
783 symtab_index = ELF64_R_SYM (info);
787 #ifdef _bfd_int64_low
788 printf (" %8.8lx %5.5lx ", _bfd_int64_low (offset), _bfd_int64_low (info));
790 printf (" %8.8lx %5.5lx ", offset, info);
793 switch (elf_header.e_machine)
800 rtype = elf_m32r_reloc_type (type);
805 rtype = elf_i386_reloc_type (type);
809 rtype = elf_m68k_reloc_type (type);
813 rtype = elf_i960_reloc_type (type);
817 rtype = elf_avr_reloc_type (type);
824 rtype = elf_sparc_reloc_type (type);
828 rtype = v850_reloc_type (type);
832 rtype = elf_d10v_reloc_type (type);
836 rtype = elf_d30v_reloc_type (type);
840 rtype = elf_sh_reloc_type (type);
843 case EM_CYGNUS_MN10300:
844 rtype = elf_mn10300_reloc_type (type);
847 case EM_CYGNUS_MN10200:
848 rtype = elf_mn10200_reloc_type (type);
852 rtype = elf_fr30_reloc_type (type);
856 rtype = elf_mcore_reloc_type (type);
860 rtype = elf_ppc_reloc_type (type);
865 rtype = elf_mips_reloc_type (type);
869 rtype = elf_alpha_reloc_type (type);
873 rtype = elf_arm_reloc_type (type);
878 rtype = elf_arc_reloc_type (type);
882 rtype = elf_hppa_reloc_type (type);
886 rtype = elf_pj_reloc_type (type);
889 rtype = elf_ia64_reloc_type (type);
893 rtype = elf_cris_reloc_type (type);
897 rtype = elf_i860_reloc_type (type);
901 rtype = elf_x86_64_reloc_type (type);
906 #ifdef _bfd_int64_low
907 printf (_("unrecognised: %-7lx"), _bfd_int64_low (type));
909 printf (_("unrecognised: %-7lx"), type);
912 printf ("%-21.21s", rtype);
918 if (symtab_index >= nsyms)
919 printf (" bad symbol index: %08lx", (unsigned long) symtab_index);
922 Elf_Internal_Sym * psym;
924 psym = symtab + symtab_index;
927 print_vma (psym->st_value, LONG_HEX);
930 if (psym->st_name == 0)
932 SECTION_NAME (section_headers + psym->st_shndx));
933 else if (strtab == NULL)
934 printf (_("<string table index %3ld>"), psym->st_name);
936 printf ("%-25.25s", strtab + psym->st_name);
939 printf (" + %lx", (unsigned long) relas [i].r_addend);
945 printf ("%*c", is_32bit_elf ? 34 : 26, ' ');
946 print_vma (relas[i].r_addend, LONG_HEX);
949 if (elf_header.e_machine == EM_SPARCV9
950 && !strcmp (rtype, "R_SPARC_OLO10"))
951 printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (info));
962 get_mips_dynamic_type (type)
967 case DT_MIPS_RLD_VERSION: return "MIPS_RLD_VERSION";
968 case DT_MIPS_TIME_STAMP: return "MIPS_TIME_STAMP";
969 case DT_MIPS_ICHECKSUM: return "MIPS_ICHECKSUM";
970 case DT_MIPS_IVERSION: return "MIPS_IVERSION";
971 case DT_MIPS_FLAGS: return "MIPS_FLAGS";
972 case DT_MIPS_BASE_ADDRESS: return "MIPS_BASE_ADDRESS";
973 case DT_MIPS_MSYM: return "MIPS_MSYM";
974 case DT_MIPS_CONFLICT: return "MIPS_CONFLICT";
975 case DT_MIPS_LIBLIST: return "MIPS_LIBLIST";
976 case DT_MIPS_LOCAL_GOTNO: return "MIPS_LOCAL_GOTNO";
977 case DT_MIPS_CONFLICTNO: return "MIPS_CONFLICTNO";
978 case DT_MIPS_LIBLISTNO: return "MIPS_LIBLISTNO";
979 case DT_MIPS_SYMTABNO: return "MIPS_SYMTABNO";
980 case DT_MIPS_UNREFEXTNO: return "MIPS_UNREFEXTNO";
981 case DT_MIPS_GOTSYM: return "MIPS_GOTSYM";
982 case DT_MIPS_HIPAGENO: return "MIPS_HIPAGENO";
983 case DT_MIPS_RLD_MAP: return "MIPS_RLD_MAP";
984 case DT_MIPS_DELTA_CLASS: return "MIPS_DELTA_CLASS";
985 case DT_MIPS_DELTA_CLASS_NO: return "MIPS_DELTA_CLASS_NO";
986 case DT_MIPS_DELTA_INSTANCE: return "MIPS_DELTA_INSTANCE";
987 case DT_MIPS_DELTA_INSTANCE_NO: return "MIPS_DELTA_INSTANCE_NO";
988 case DT_MIPS_DELTA_RELOC: return "MIPS_DELTA_RELOC";
989 case DT_MIPS_DELTA_RELOC_NO: return "MIPS_DELTA_RELOC_NO";
990 case DT_MIPS_DELTA_SYM: return "MIPS_DELTA_SYM";
991 case DT_MIPS_DELTA_SYM_NO: return "MIPS_DELTA_SYM_NO";
992 case DT_MIPS_DELTA_CLASSSYM: return "MIPS_DELTA_CLASSSYM";
993 case DT_MIPS_DELTA_CLASSSYM_NO: return "MIPS_DELTA_CLASSSYM_NO";
994 case DT_MIPS_CXX_FLAGS: return "MIPS_CXX_FLAGS";
995 case DT_MIPS_PIXIE_INIT: return "MIPS_PIXIE_INIT";
996 case DT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB";
997 case DT_MIPS_LOCALPAGE_GOTIDX: return "MIPS_LOCALPAGE_GOTIDX";
998 case DT_MIPS_LOCAL_GOTIDX: return "MIPS_LOCAL_GOTIDX";
999 case DT_MIPS_HIDDEN_GOTIDX: return "MIPS_HIDDEN_GOTIDX";
1000 case DT_MIPS_PROTECTED_GOTIDX: return "MIPS_PROTECTED_GOTIDX";
1001 case DT_MIPS_OPTIONS: return "MIPS_OPTIONS";
1002 case DT_MIPS_INTERFACE: return "MIPS_INTERFACE";
1003 case DT_MIPS_DYNSTR_ALIGN: return "MIPS_DYNSTR_ALIGN";
1004 case DT_MIPS_INTERFACE_SIZE: return "MIPS_INTERFACE_SIZE";
1005 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
1006 case DT_MIPS_PERF_SUFFIX: return "MIPS_PERF_SUFFIX";
1007 case DT_MIPS_COMPACT_SIZE: return "MIPS_COMPACT_SIZE";
1008 case DT_MIPS_GP_VALUE: return "MIPS_GP_VALUE";
1009 case DT_MIPS_AUX_DYNAMIC: return "MIPS_AUX_DYNAMIC";
1016 get_sparc64_dynamic_type (type)
1021 case DT_SPARC_REGISTER: return "SPARC_REGISTER";
1028 get_parisc_dynamic_type (type)
1033 case DT_HP_LOAD_MAP: return "HP_LOAD_MAP";
1034 case DT_HP_DLD_FLAGS: return "HP_DLD_FLAGS";
1035 case DT_HP_DLD_HOOK: return "HP_DLD_HOOK";
1036 case DT_HP_UX10_INIT: return "HP_UX10_INIT";
1037 case DT_HP_UX10_INITSZ: return "HP_UX10_INITSZ";
1038 case DT_HP_PREINIT: return "HP_PREINIT";
1039 case DT_HP_PREINITSZ: return "HP_PREINITSZ";
1040 case DT_HP_NEEDED: return "HP_NEEDED";
1041 case DT_HP_TIME_STAMP: return "HP_TIME_STAMP";
1042 case DT_HP_CHECKSUM: return "HP_CHECKSUM";
1043 case DT_HP_GST_SIZE: return "HP_GST_SIZE";
1044 case DT_HP_GST_VERSION: return "HP_GST_VERSION";
1045 case DT_HP_GST_HASHVAL: return "HP_GST_HASHVAL";
1052 get_dynamic_type (type)
1055 static char buff [32];
1059 case DT_NULL: return "NULL";
1060 case DT_NEEDED: return "NEEDED";
1061 case DT_PLTRELSZ: return "PLTRELSZ";
1062 case DT_PLTGOT: return "PLTGOT";
1063 case DT_HASH: return "HASH";
1064 case DT_STRTAB: return "STRTAB";
1065 case DT_SYMTAB: return "SYMTAB";
1066 case DT_RELA: return "RELA";
1067 case DT_RELASZ: return "RELASZ";
1068 case DT_RELAENT: return "RELAENT";
1069 case DT_STRSZ: return "STRSZ";
1070 case DT_SYMENT: return "SYMENT";
1071 case DT_INIT: return "INIT";
1072 case DT_FINI: return "FINI";
1073 case DT_SONAME: return "SONAME";
1074 case DT_RPATH: return "RPATH";
1075 case DT_SYMBOLIC: return "SYMBOLIC";
1076 case DT_REL: return "REL";
1077 case DT_RELSZ: return "RELSZ";
1078 case DT_RELENT: return "RELENT";
1079 case DT_PLTREL: return "PLTREL";
1080 case DT_DEBUG: return "DEBUG";
1081 case DT_TEXTREL: return "TEXTREL";
1082 case DT_JMPREL: return "JMPREL";
1083 case DT_BIND_NOW: return "BIND_NOW";
1084 case DT_INIT_ARRAY: return "INIT_ARRAY";
1085 case DT_FINI_ARRAY: return "FINI_ARRAY";
1086 case DT_INIT_ARRAYSZ: return "INIT_ARRAYSZ";
1087 case DT_FINI_ARRAYSZ: return "FINI_ARRAYSZ";
1088 case DT_RUNPATH: return "RUNPATH";
1089 case DT_FLAGS: return "FLAGS";
1091 case DT_PREINIT_ARRAY: return "PREINIT_ARRAY";
1092 case DT_PREINIT_ARRAYSZ: return "PREINIT_ARRAYSZ";
1094 case DT_CHECKSUM: return "CHECKSUM";
1095 case DT_PLTPADSZ: return "PLTPADSZ";
1096 case DT_MOVEENT: return "MOVEENT";
1097 case DT_MOVESZ: return "MOVESZ";
1098 case DT_FEATURE: return "FEATURE";
1099 case DT_POSFLAG_1: return "POSFLAG_1";
1100 case DT_SYMINSZ: return "SYMINSZ";
1101 case DT_SYMINENT: return "SYMINENT"; /* aka VALRNGHI */
1103 case DT_ADDRRNGLO: return "ADDRRNGLO";
1104 case DT_CONFIG: return "CONFIG";
1105 case DT_DEPAUDIT: return "DEPAUDIT";
1106 case DT_AUDIT: return "AUDIT";
1107 case DT_PLTPAD: return "PLTPAD";
1108 case DT_MOVETAB: return "MOVETAB";
1109 case DT_SYMINFO: return "SYMINFO"; /* aka ADDRRNGHI */
1111 case DT_VERSYM: return "VERSYM";
1113 case DT_RELACOUNT: return "RELACOUNT";
1114 case DT_RELCOUNT: return "RELCOUNT";
1115 case DT_FLAGS_1: return "FLAGS_1";
1116 case DT_VERDEF: return "VERDEF";
1117 case DT_VERDEFNUM: return "VERDEFNUM";
1118 case DT_VERNEED: return "VERNEED";
1119 case DT_VERNEEDNUM: return "VERNEEDNUM";
1121 case DT_AUXILIARY: return "AUXILIARY";
1122 case DT_USED: return "USED";
1123 case DT_FILTER: return "FILTER";
1126 if ((type >= DT_LOPROC) && (type <= DT_HIPROC))
1128 const char * result;
1130 switch (elf_header.e_machine)
1133 case EM_MIPS_RS4_BE:
1134 result = get_mips_dynamic_type (type);
1137 result = get_sparc64_dynamic_type (type);
1147 sprintf (buff, _("Processor Specific: %lx"), type);
1149 else if ((type >= DT_LOOS) && (type <= DT_HIOS))
1151 const char * result;
1153 switch (elf_header.e_machine)
1156 result = get_parisc_dynamic_type (type);
1166 sprintf (buff, _("Operating System specific: %lx"), type);
1169 sprintf (buff, _("<unknown>: %lx"), type);
1176 get_file_type (e_type)
1179 static char buff [32];
1183 case ET_NONE: return _("NONE (None)");
1184 case ET_REL: return _("REL (Relocatable file)");
1185 case ET_EXEC: return _("EXEC (Executable file)");
1186 case ET_DYN: return _("DYN (Shared object file)");
1187 case ET_CORE: return _("CORE (Core file)");
1190 if ((e_type >= ET_LOPROC) && (e_type <= ET_HIPROC))
1191 sprintf (buff, _("Processor Specific: (%x)"), e_type);
1192 else if ((e_type >= ET_LOOS) && (e_type <= ET_HIOS))
1193 sprintf (buff, _("OS Specific: (%x)"), e_type);
1195 sprintf (buff, _("<unknown>: %x"), e_type);
1201 get_machine_name (e_machine)
1204 static char buff [64]; /* XXX */
1208 case EM_NONE: return _("None");
1209 case EM_M32: return "WE32100";
1210 case EM_SPARC: return "Sparc";
1211 case EM_386: return "Intel 80386";
1212 case EM_68K: return "MC68000";
1213 case EM_88K: return "MC88000";
1214 case EM_486: return "Intel 80486";
1215 case EM_860: return "Intel 80860";
1216 case EM_MIPS: return "MIPS R3000";
1217 case EM_S370: return "IBM System/370";
1218 case EM_MIPS_RS4_BE: return "MIPS R4000 big-endian";
1219 case EM_OLD_SPARCV9: return "Sparc v9 (old)";
1220 case EM_PARISC: return "HPPA";
1221 case EM_PPC_OLD: return "Power PC (old)";
1222 case EM_SPARC32PLUS: return "Sparc v8+" ;
1223 case EM_960: return "Intel 90860";
1224 case EM_PPC: return "PowerPC";
1225 case EM_V800: return "NEC V800";
1226 case EM_FR20: return "Fujitsu FR20";
1227 case EM_RH32: return "TRW RH32";
1228 case EM_MCORE: return "MCORE";
1229 case EM_ARM: return "ARM";
1230 case EM_OLD_ALPHA: return "Digital Alpha (old)";
1231 case EM_SH: return "Hitachi SH";
1232 case EM_SPARCV9: return "Sparc v9";
1233 case EM_TRICORE: return "Siemens Tricore";
1234 case EM_ARC: return "ARC";
1235 case EM_H8_300: return "Hitachi H8/300";
1236 case EM_H8_300H: return "Hitachi H8/300H";
1237 case EM_H8S: return "Hitachi H8S";
1238 case EM_H8_500: return "Hitachi H8/500";
1239 case EM_IA_64: return "Intel IA-64";
1240 case EM_MIPS_X: return "Stanford MIPS-X";
1241 case EM_COLDFIRE: return "Motorola Coldfire";
1242 case EM_68HC12: return "Motorola M68HC12";
1243 case EM_ALPHA: return "Alpha";
1244 case EM_CYGNUS_D10V: return "d10v";
1245 case EM_CYGNUS_D30V: return "d30v";
1246 case EM_CYGNUS_ARC: return "ARC";
1247 case EM_CYGNUS_M32R: return "Mitsubishi M32r";
1248 case EM_CYGNUS_V850: return "NEC v850";
1249 case EM_CYGNUS_MN10300: return "mn10300";
1250 case EM_CYGNUS_MN10200: return "mn10200";
1251 case EM_CYGNUS_FR30: return "Fujitsu FR30";
1252 case EM_PJ: return "picoJava";
1253 case EM_MMA: return "Fujitsu Multimedia Accelerator";
1254 case EM_PCP: return "Siemens PCP";
1255 case EM_NCPU: return "Sony nCPU embedded RISC processor";
1256 case EM_NDR1: return "Denso NDR1 microprocesspr";
1257 case EM_STARCORE: return "Motorola Star*Core processor";
1258 case EM_ME16: return "Toyota ME16 processor";
1259 case EM_ST100: return "STMicroelectronics ST100 processor";
1260 case EM_TINYJ: return "Advanced Logic Corp. TinyJ embedded processor";
1261 case EM_FX66: return "Siemens FX66 microcontroller";
1262 case EM_ST9PLUS: return "STMicroelectronics ST9+ 8/16 bit microcontroller";
1263 case EM_ST7: return "STMicroelectronics ST7 8-bit microcontroller";
1264 case EM_68HC16: return "Motorola MC68HC16 Microcontroller";
1265 case EM_68HC11: return "Motorola MC68HC11 Microcontroller";
1266 case EM_68HC08: return "Motorola MC68HC08 Microcontroller";
1267 case EM_68HC05: return "Motorola MC68HC05 Microcontroller";
1268 case EM_SVX: return "Silicon Graphics SVx";
1269 case EM_ST19: return "STMicroelectronics ST19 8-bit microcontroller";
1270 case EM_VAX: return "Digital VAX";
1271 case EM_AVR: return "Atmel AVR 8-bit microcontroller";
1272 case EM_CRIS: return "Axis Communications 32-bit embedded processor";
1273 case EM_JAVELIN: return "Infineon Technologies 32-bit embedded cpu";
1274 case EM_FIREPATH: return "Element 14 64-bit DSP processor";
1275 case EM_ZSP: return "LSI Logic's 16-bit DSP processor";
1276 case EM_MMIX: return "Donald Knuth's educational 64-bit processor";
1277 case EM_HUANY: return "Harvard Universitys's machine-independent object format";
1278 case EM_PRISM: return "SiTera Prism";
1279 case EM_X86_64: return "Advanced Micro Devices X86-64";
1281 sprintf (buff, _("<unknown>: %x"), e_machine);
1287 decode_ARM_machine_flags (e_flags, buf)
1294 eabi = EF_ARM_EABI_VERSION (e_flags);
1295 e_flags &= ~ EF_ARM_EABIMASK;
1297 /* Handle "generic" ARM flags. */
1298 if (e_flags & EF_ARM_RELEXEC)
1300 strcat (buf, ", relocatable executable");
1301 e_flags &= ~ EF_ARM_RELEXEC;
1304 if (e_flags & EF_ARM_HASENTRY)
1306 strcat (buf, ", has entry point");
1307 e_flags &= ~ EF_ARM_HASENTRY;
1310 /* Now handle EABI specific flags. */
1314 strcat (buf, ", <unknown EABI>");
1319 case EF_ARM_EABI_VER1:
1324 /* Process flags one bit at a time. */
1325 flag = e_flags & - e_flags;
1330 case EF_ARM_SYMSARESORTED: /* Conflicts with EF_INTERWORK. */
1331 strcat (buf, ", sorted symbol tables");
1341 case EF_ARM_EABI_UNKNOWN:
1346 /* Process flags one bit at a time. */
1347 flag = e_flags & - e_flags;
1353 strcat (buf, ", interworking enabled");
1357 strcat (buf, ", uses APCS/26");
1361 strcat (buf, ", uses APCS/float");
1365 strcat (buf, ", position independent");
1369 strcat (buf, ", 8 bit structure alignment");
1373 strcat (buf, ", uses new ABI");
1377 strcat (buf, ", uses old ABI");
1381 strcat (buf, ", software FP");
1392 strcat (buf,", <unknown>");
1396 get_machine_flags (e_flags, e_machine)
1400 static char buf [1024];
1412 decode_ARM_machine_flags (e_flags, buf);
1416 if (e_flags & EF_CPU32)
1417 strcat (buf, ", cpu32");
1421 if (e_flags & EF_PPC_EMB)
1422 strcat (buf, ", emb");
1424 if (e_flags & EF_PPC_RELOCATABLE)
1425 strcat (buf, ", relocatable");
1427 if (e_flags & EF_PPC_RELOCATABLE_LIB)
1428 strcat (buf, ", relocatable-lib");
1431 case EM_CYGNUS_V850:
1432 switch (e_flags & EF_V850_ARCH)
1435 strcat (buf, ", v850e");
1438 strcat (buf, ", v850ea");
1441 strcat (buf, ", v850");
1444 strcat (buf, ", unknown v850 architecture variant");
1449 case EM_CYGNUS_M32R:
1450 if ((e_flags & EF_M32R_ARCH) == E_M32R_ARCH)
1451 strcat (buf, ", m32r");
1456 case EM_MIPS_RS4_BE:
1457 if (e_flags & EF_MIPS_NOREORDER)
1458 strcat (buf, ", noreorder");
1460 if (e_flags & EF_MIPS_PIC)
1461 strcat (buf, ", pic");
1463 if (e_flags & EF_MIPS_CPIC)
1464 strcat (buf, ", cpic");
1466 if (e_flags & EF_MIPS_ABI2)
1467 strcat (buf, ", abi2");
1469 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_1)
1470 strcat (buf, ", mips1");
1472 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_2)
1473 strcat (buf, ", mips2");
1475 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_3)
1476 strcat (buf, ", mips3");
1478 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_4)
1479 strcat (buf, ", mips4");
1481 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_5)
1482 strcat (buf, ", mips5");
1484 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_32)
1485 strcat (buf, ", mips32");
1487 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_64)
1488 strcat (buf, ", mips64");
1490 switch ((e_flags & EF_MIPS_MACH))
1492 case E_MIPS_MACH_3900: strcat (buf, ", 3900"); break;
1493 case E_MIPS_MACH_4010: strcat (buf, ", 4010"); break;
1494 case E_MIPS_MACH_4100: strcat (buf, ", 4100"); break;
1495 case E_MIPS_MACH_4650: strcat (buf, ", 4650"); break;
1496 case E_MIPS_MACH_4111: strcat (buf, ", 4111"); break;
1497 case E_MIPS_MACH_MIPS32_4K: strcat (buf, ", mips32-4k"); break;
1498 case E_MIPS_MACH_SB1: strcat (buf, ", sb1"); break;
1499 default: strcat (buf, " UNKNOWN"); break;
1504 if (e_flags & EF_SPARC_32PLUS)
1505 strcat (buf, ", v8+");
1507 if (e_flags & EF_SPARC_SUN_US1)
1508 strcat (buf, ", ultrasparcI");
1510 if (e_flags & EF_SPARC_SUN_US3)
1511 strcat (buf, ", ultrasparcIII");
1513 if (e_flags & EF_SPARC_HAL_R1)
1514 strcat (buf, ", halr1");
1516 if (e_flags & EF_SPARC_LEDATA)
1517 strcat (buf, ", ledata");
1519 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_TSO)
1520 strcat (buf, ", tso");
1522 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_PSO)
1523 strcat (buf, ", pso");
1525 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_RMO)
1526 strcat (buf, ", rmo");
1530 switch (e_flags & EF_PARISC_ARCH)
1532 case EFA_PARISC_1_0:
1533 strcpy (buf, ", PA-RISC 1.0");
1535 case EFA_PARISC_1_1:
1536 strcpy (buf, ", PA-RISC 1.1");
1538 case EFA_PARISC_2_0:
1539 strcpy (buf, ", PA-RISC 2.0");
1544 if (e_flags & EF_PARISC_TRAPNIL)
1545 strcat (buf, ", trapnil");
1546 if (e_flags & EF_PARISC_EXT)
1547 strcat (buf, ", ext");
1548 if (e_flags & EF_PARISC_LSB)
1549 strcat (buf, ", lsb");
1550 if (e_flags & EF_PARISC_WIDE)
1551 strcat (buf, ", wide");
1552 if (e_flags & EF_PARISC_NO_KABP)
1553 strcat (buf, ", no kabp");
1554 if (e_flags & EF_PARISC_LAZYSWAP)
1555 strcat (buf, ", lazyswap");
1559 if ((e_flags & EF_PICOJAVA_NEWCALLS) == EF_PICOJAVA_NEWCALLS)
1560 strcat (buf, ", new calling convention");
1562 if ((e_flags & EF_PICOJAVA_GNUCALLS) == EF_PICOJAVA_GNUCALLS)
1563 strcat (buf, ", gnu calling convention");
1572 get_mips_segment_type (type)
1577 case PT_MIPS_REGINFO:
1579 case PT_MIPS_RTPROC:
1581 case PT_MIPS_OPTIONS:
1591 get_parisc_segment_type (type)
1596 case PT_HP_TLS: return "HP_TLS";
1597 case PT_HP_CORE_NONE: return "HP_CORE_NONE";
1598 case PT_HP_CORE_VERSION: return "HP_CORE_VERSION";
1599 case PT_HP_CORE_KERNEL: return "HP_CORE_KERNEL";
1600 case PT_HP_CORE_COMM: return "HP_CORE_COMM";
1601 case PT_HP_CORE_PROC: return "HP_CORE_PROC";
1602 case PT_HP_CORE_LOADABLE: return "HP_CORE_LOADABLE";
1603 case PT_HP_CORE_STACK: return "HP_CORE_STACK";
1604 case PT_HP_CORE_SHM: return "HP_CORE_SHM";
1605 case PT_HP_CORE_MMF: return "HP_CORE_MMF";
1606 case PT_HP_PARALLEL: return "HP_PARALLEL";
1607 case PT_HP_FASTBIND: return "HP_FASTBIND";
1608 case PT_PARISC_ARCHEXT: return "PARISC_ARCHEXT";
1609 case PT_PARISC_UNWIND: return "PARISC_UNWIND";
1618 get_segment_type (p_type)
1619 unsigned long p_type;
1621 static char buff [32];
1625 case PT_NULL: return "NULL";
1626 case PT_LOAD: return "LOAD";
1627 case PT_DYNAMIC: return "DYNAMIC";
1628 case PT_INTERP: return "INTERP";
1629 case PT_NOTE: return "NOTE";
1630 case PT_SHLIB: return "SHLIB";
1631 case PT_PHDR: return "PHDR";
1634 if ((p_type >= PT_LOPROC) && (p_type <= PT_HIPROC))
1636 const char * result;
1638 switch (elf_header.e_machine)
1641 case EM_MIPS_RS4_BE:
1642 result = get_mips_segment_type (p_type);
1645 result = get_parisc_segment_type (p_type);
1655 sprintf (buff, "LOPROC+%lx", p_type - PT_LOPROC);
1657 else if ((p_type >= PT_LOOS) && (p_type <= PT_HIOS))
1659 const char * result;
1661 switch (elf_header.e_machine)
1664 result = get_parisc_segment_type (p_type);
1674 sprintf (buff, "LOOS+%lx", p_type - PT_LOOS);
1677 sprintf (buff, _("<unknown>: %lx"), p_type);
1684 get_mips_section_type_name (sh_type)
1685 unsigned int sh_type;
1689 case SHT_MIPS_LIBLIST: return "MIPS_LIBLIST";
1690 case SHT_MIPS_MSYM: return "MIPS_MSYM";
1691 case SHT_MIPS_CONFLICT: return "MIPS_CONFLICT";
1692 case SHT_MIPS_GPTAB: return "MIPS_GPTAB";
1693 case SHT_MIPS_UCODE: return "MIPS_UCODE";
1694 case SHT_MIPS_DEBUG: return "MIPS_DEBUG";
1695 case SHT_MIPS_REGINFO: return "MIPS_REGINFO";
1696 case SHT_MIPS_PACKAGE: return "MIPS_PACKAGE";
1697 case SHT_MIPS_PACKSYM: return "MIPS_PACKSYM";
1698 case SHT_MIPS_RELD: return "MIPS_RELD";
1699 case SHT_MIPS_IFACE: return "MIPS_IFACE";
1700 case SHT_MIPS_CONTENT: return "MIPS_CONTENT";
1701 case SHT_MIPS_OPTIONS: return "MIPS_OPTIONS";
1702 case SHT_MIPS_SHDR: return "MIPS_SHDR";
1703 case SHT_MIPS_FDESC: return "MIPS_FDESC";
1704 case SHT_MIPS_EXTSYM: return "MIPS_EXTSYM";
1705 case SHT_MIPS_DENSE: return "MIPS_DENSE";
1706 case SHT_MIPS_PDESC: return "MIPS_PDESC";
1707 case SHT_MIPS_LOCSYM: return "MIPS_LOCSYM";
1708 case SHT_MIPS_AUXSYM: return "MIPS_AUXSYM";
1709 case SHT_MIPS_OPTSYM: return "MIPS_OPTSYM";
1710 case SHT_MIPS_LOCSTR: return "MIPS_LOCSTR";
1711 case SHT_MIPS_LINE: return "MIPS_LINE";
1712 case SHT_MIPS_RFDESC: return "MIPS_RFDESC";
1713 case SHT_MIPS_DELTASYM: return "MIPS_DELTASYM";
1714 case SHT_MIPS_DELTAINST: return "MIPS_DELTAINST";
1715 case SHT_MIPS_DELTACLASS: return "MIPS_DELTACLASS";
1716 case SHT_MIPS_DWARF: return "MIPS_DWARF";
1717 case SHT_MIPS_DELTADECL: return "MIPS_DELTADECL";
1718 case SHT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB";
1719 case SHT_MIPS_EVENTS: return "MIPS_EVENTS";
1720 case SHT_MIPS_TRANSLATE: return "MIPS_TRANSLATE";
1721 case SHT_MIPS_PIXIE: return "MIPS_PIXIE";
1722 case SHT_MIPS_XLATE: return "MIPS_XLATE";
1723 case SHT_MIPS_XLATE_DEBUG: return "MIPS_XLATE_DEBUG";
1724 case SHT_MIPS_WHIRL: return "MIPS_WHIRL";
1725 case SHT_MIPS_EH_REGION: return "MIPS_EH_REGION";
1726 case SHT_MIPS_XLATE_OLD: return "MIPS_XLATE_OLD";
1727 case SHT_MIPS_PDR_EXCEPTION: return "MIPS_PDR_EXCEPTION";
1735 get_parisc_section_type_name (sh_type)
1736 unsigned int sh_type;
1740 case SHT_PARISC_EXT: return "PARISC_EXT";
1741 case SHT_PARISC_UNWIND: return "PARISC_UNWIND";
1742 case SHT_PARISC_DOC: return "PARISC_DOC";
1750 get_section_type_name (sh_type)
1751 unsigned int sh_type;
1753 static char buff [32];
1757 case SHT_NULL: return "NULL";
1758 case SHT_PROGBITS: return "PROGBITS";
1759 case SHT_SYMTAB: return "SYMTAB";
1760 case SHT_STRTAB: return "STRTAB";
1761 case SHT_RELA: return "RELA";
1762 case SHT_HASH: return "HASH";
1763 case SHT_DYNAMIC: return "DYNAMIC";
1764 case SHT_NOTE: return "NOTE";
1765 case SHT_NOBITS: return "NOBITS";
1766 case SHT_REL: return "REL";
1767 case SHT_SHLIB: return "SHLIB";
1768 case SHT_DYNSYM: return "DYNSYM";
1769 case SHT_INIT_ARRAY: return "INIT_ARRAY";
1770 case SHT_FINI_ARRAY: return "FINI_ARRAY";
1771 case SHT_PREINIT_ARRAY: return "PREINIT_ARRAY";
1772 case SHT_GROUP: return "GROUP";
1773 case SHT_SYMTAB_SHNDX: return "SYMTAB SECTION INDICIES";
1774 case SHT_GNU_verdef: return "VERDEF";
1775 case SHT_GNU_verneed: return "VERNEED";
1776 case SHT_GNU_versym: return "VERSYM";
1777 case 0x6ffffff0: return "VERSYM";
1778 case 0x6ffffffc: return "VERDEF";
1779 case 0x7ffffffd: return "AUXILIARY";
1780 case 0x7fffffff: return "FILTER";
1783 if ((sh_type >= SHT_LOPROC) && (sh_type <= SHT_HIPROC))
1785 const char * result;
1787 switch (elf_header.e_machine)
1790 case EM_MIPS_RS4_BE:
1791 result = get_mips_section_type_name (sh_type);
1794 result = get_parisc_section_type_name (sh_type);
1804 sprintf (buff, "SHT_LOPROC+%x", sh_type - SHT_LOPROC);
1806 else if ((sh_type >= SHT_LOOS) && (sh_type <= SHT_HIOS))
1807 sprintf (buff, "SHT_LOOS+%x", sh_type - SHT_LOOS);
1808 else if ((sh_type >= SHT_LOUSER) && (sh_type <= SHT_HIUSER))
1809 sprintf (buff, "SHT_LOUSER+%x", sh_type - SHT_LOUSER);
1811 sprintf (buff, _("<unknown>: %x"), sh_type);
1817 struct option options [] =
1819 {"all", no_argument, 0, 'a'},
1820 {"file-header", no_argument, 0, 'h'},
1821 {"program-headers", no_argument, 0, 'l'},
1822 {"headers", no_argument, 0, 'e'},
1823 {"histogram", no_argument, 0, 'I'},
1824 {"segments", no_argument, 0, 'l'},
1825 {"sections", no_argument, 0, 'S'},
1826 {"section-headers", no_argument, 0, 'S'},
1827 {"symbols", no_argument, 0, 's'},
1828 {"syms", no_argument, 0, 's'},
1829 {"relocs", no_argument, 0, 'r'},
1830 {"notes", no_argument, 0, 'n'},
1831 {"dynamic", no_argument, 0, 'd'},
1832 {"arch-specific", no_argument, 0, 'A'},
1833 {"version-info", no_argument, 0, 'V'},
1834 {"use-dynamic", no_argument, 0, 'D'},
1835 {"hex-dump", required_argument, 0, 'x'},
1836 {"debug-dump", optional_argument, 0, 'w'},
1837 #ifdef SUPPORT_DISASSEMBLY
1838 {"instruction-dump", required_argument, 0, 'i'},
1841 {"version", no_argument, 0, 'v'},
1842 {"help", no_argument, 0, 'H'},
1843 {0, no_argument, 0, 0}
1849 fprintf (stdout, _("Usage: readelf {options} elf-file(s)\n"));
1850 fprintf (stdout, _(" Options are:\n"));
1851 fprintf (stdout, _(" -a or --all Equivalent to: -h -l -S -s -r -d -V -A -I\n"));
1852 fprintf (stdout, _(" -h or --file-header Display the ELF file header\n"));
1853 fprintf (stdout, _(" -l or --program-headers or --segments\n"));
1854 fprintf (stdout, _(" Display the program headers\n"));
1855 fprintf (stdout, _(" -S or --section-headers or --sections\n"));
1856 fprintf (stdout, _(" Display the sections' header\n"));
1857 fprintf (stdout, _(" -e or --headers Equivalent to: -h -l -S\n"));
1858 fprintf (stdout, _(" -s or --syms or --symbols Display the symbol table\n"));
1859 fprintf (stdout, _(" -n or --notes Display the core notes (if present)\n"));
1860 fprintf (stdout, _(" -r or --relocs Display the relocations (if present)\n"));
1861 fprintf (stdout, _(" -d or --dynamic Display the dynamic segment (if present)\n"));
1862 fprintf (stdout, _(" -V or --version-info Display the version sections (if present)\n"));
1863 fprintf (stdout, _(" -A or --arch-specific Display architecture specific information (if any).\n"));
1864 fprintf (stdout, _(" -D or --use-dynamic Use the dynamic section info when displaying symbols\n"));
1865 fprintf (stdout, _(" -x <number> or --hex-dump=<number>\n"));
1866 fprintf (stdout, _(" Dump the contents of section <number>\n"));
1867 fprintf (stdout, _(" -w[liaprf] or --debug-dump[=line,=info,=abbrev,=pubnames,=ranges,=frames]\n"));
1868 fprintf (stdout, _(" Display the contents of DWARF2 debug sections\n"));
1869 #ifdef SUPPORT_DISASSEMBLY
1870 fprintf (stdout, _(" -i <number> or --instruction-dump=<number>\n"));
1871 fprintf (stdout, _(" Disassemble the contents of section <number>\n"));
1873 fprintf (stdout, _(" -I or --histogram Display histogram of bucket list lengths\n"));
1874 fprintf (stdout, _(" -v or --version Display the version number of readelf\n"));
1875 fprintf (stdout, _(" -H or --help Display this information\n"));
1876 fprintf (stdout, _("Report bugs to %s\n"), REPORT_BUGS_TO);
1882 request_dump (section, type)
1883 unsigned int section;
1886 if (section >= num_dump_sects)
1888 char * new_dump_sects;
1890 new_dump_sects = (char *) calloc (section + 1, 1);
1892 if (new_dump_sects == NULL)
1893 error (_("Out of memory allocating dump request table."));
1896 /* Copy current flag settings. */
1897 memcpy (new_dump_sects, dump_sects, num_dump_sects);
1901 dump_sects = new_dump_sects;
1902 num_dump_sects = section + 1;
1907 dump_sects [section] |= type;
1913 parse_args (argc, argv)
1922 while ((c = getopt_long
1923 (argc, argv, "ersahnldSDAIw::x:i:vV", options, NULL)) != EOF)
1958 do_using_dynamic ++;
1986 section = strtoul (optarg, & cp, 0);
1987 if (! * cp && section >= 0)
1989 request_dump (section, HEX_DUMP);
2009 do_debug_abbrevs = 1;
2019 do_debug_pubnames = 1;
2024 do_debug_aranges = 1;
2029 do_debug_frames = 1;
2033 warn (_("Unrecognised debug option '%s'\n"), optarg);
2038 #ifdef SUPPORT_DISASSEMBLY
2041 section = strtoul (optarg, & cp, 0);
2042 if (! * cp && section >= 0)
2044 request_dump (section, DISASS_DUMP);
2050 print_version (program_name);
2057 /* xgettext:c-format */
2058 error (_("Invalid option '-%c'\n"), c);
2065 if (!do_dynamic && !do_syms && !do_reloc && !do_sections
2066 && !do_segments && !do_header && !do_dump && !do_version
2067 && !do_histogram && !do_debugging && !do_arch && !do_notes)
2071 warn (_("Nothing to do.\n"));
2077 get_elf_class (elf_class)
2078 unsigned char elf_class;
2080 static char buff [32];
2084 case ELFCLASSNONE: return _("none");
2085 case ELFCLASS32: return _("ELF32");
2086 case ELFCLASS64: return _("ELF64");
2088 sprintf (buff, _("<unknown: %x>"), elf_class);
2094 get_data_encoding (encoding)
2095 unsigned char encoding;
2097 static char buff [32];
2101 case ELFDATANONE: return _("none");
2102 case ELFDATA2LSB: return _("2's complement, little endian");
2103 case ELFDATA2MSB: return _("2's complement, big endian");
2105 sprintf (buff, _("<unknown: %x>"), encoding);
2111 get_osabi_name (osabi)
2112 unsigned char osabi;
2114 static char buff [32];
2118 case ELFOSABI_NONE: return _("UNIX - System V");
2119 case ELFOSABI_HPUX: return _("UNIX - HP-UX");
2120 case ELFOSABI_NETBSD: return _("UNIX - NetBSD");
2121 case ELFOSABI_LINUX: return _("UNIX - Linux");
2122 case ELFOSABI_HURD: return _("GNU/Hurd");
2123 case ELFOSABI_SOLARIS: return _("UNIX - Solaris");
2124 case ELFOSABI_AIX: return _("UNIX - AIX");
2125 case ELFOSABI_IRIX: return _("UNIX - IRIX");
2126 case ELFOSABI_FREEBSD: return _("UNIX - FreeBSD");
2127 case ELFOSABI_TRU64: return _("UNIX - TRU64");
2128 case ELFOSABI_MODESTO: return _("Novell - Modesto");
2129 case ELFOSABI_OPENBSD: return _("UNIX - OpenBSD");
2130 case ELFOSABI_STANDALONE: return _("Standalone App");
2131 case ELFOSABI_ARM: return _("ARM");
2133 sprintf (buff, _("<unknown: %x>"), osabi);
2138 /* Decode the data held in 'elf_header'. */
2140 process_file_header ()
2142 if ( elf_header.e_ident [EI_MAG0] != ELFMAG0
2143 || elf_header.e_ident [EI_MAG1] != ELFMAG1
2144 || elf_header.e_ident [EI_MAG2] != ELFMAG2
2145 || elf_header.e_ident [EI_MAG3] != ELFMAG3)
2148 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
2156 printf (_("ELF Header:\n"));
2157 printf (_(" Magic: "));
2158 for (i = 0; i < EI_NIDENT; i ++)
2159 printf ("%2.2x ", elf_header.e_ident [i]);
2161 printf (_(" Class: %s\n"),
2162 get_elf_class (elf_header.e_ident [EI_CLASS]));
2163 printf (_(" Data: %s\n"),
2164 get_data_encoding (elf_header.e_ident [EI_DATA]));
2165 printf (_(" Version: %d %s\n"),
2166 elf_header.e_ident [EI_VERSION],
2167 (elf_header.e_ident [EI_VERSION] == EV_CURRENT
2169 : (elf_header.e_ident [EI_VERSION] != EV_NONE
2172 printf (_(" OS/ABI: %s\n"),
2173 get_osabi_name (elf_header.e_ident [EI_OSABI]));
2174 printf (_(" ABI Version: %d\n"),
2175 elf_header.e_ident [EI_ABIVERSION]);
2176 printf (_(" Type: %s\n"),
2177 get_file_type (elf_header.e_type));
2178 printf (_(" Machine: %s\n"),
2179 get_machine_name (elf_header.e_machine));
2180 printf (_(" Version: 0x%lx\n"),
2181 (unsigned long) elf_header.e_version);
2183 printf (_(" Entry point address: "));
2184 print_vma ((bfd_vma) elf_header.e_entry, PREFIX_HEX);
2185 printf (_("\n Start of program headers: "));
2186 print_vma ((bfd_vma) elf_header.e_phoff, DEC);
2187 printf (_(" (bytes into file)\n Start of section headers: "));
2188 print_vma ((bfd_vma) elf_header.e_shoff, DEC);
2189 printf (_(" (bytes into file)\n"));
2191 printf (_(" Flags: 0x%lx%s\n"),
2192 (unsigned long) elf_header.e_flags,
2193 get_machine_flags (elf_header.e_flags, elf_header.e_machine));
2194 printf (_(" Size of this header: %ld (bytes)\n"),
2195 (long) elf_header.e_ehsize);
2196 printf (_(" Size of program headers: %ld (bytes)\n"),
2197 (long) elf_header.e_phentsize);
2198 printf (_(" Number of program headers: %ld\n"),
2199 (long) elf_header.e_phnum);
2200 printf (_(" Size of section headers: %ld (bytes)\n"),
2201 (long) elf_header.e_shentsize);
2202 printf (_(" Number of section headers: %ld\n"),
2203 (long) elf_header.e_shnum);
2204 printf (_(" Section header string table index: %ld\n"),
2205 (long) elf_header.e_shstrndx);
2213 get_32bit_program_headers (file, program_headers)
2215 Elf_Internal_Phdr * program_headers;
2217 Elf32_External_Phdr * phdrs;
2218 Elf32_External_Phdr * external;
2219 Elf32_Internal_Phdr * internal;
2222 GET_DATA_ALLOC (elf_header.e_phoff,
2223 elf_header.e_phentsize * elf_header.e_phnum,
2224 phdrs, Elf32_External_Phdr *, "program headers");
2226 for (i = 0, internal = program_headers, external = phdrs;
2227 i < elf_header.e_phnum;
2228 i ++, internal ++, external ++)
2230 internal->p_type = BYTE_GET (external->p_type);
2231 internal->p_offset = BYTE_GET (external->p_offset);
2232 internal->p_vaddr = BYTE_GET (external->p_vaddr);
2233 internal->p_paddr = BYTE_GET (external->p_paddr);
2234 internal->p_filesz = BYTE_GET (external->p_filesz);
2235 internal->p_memsz = BYTE_GET (external->p_memsz);
2236 internal->p_flags = BYTE_GET (external->p_flags);
2237 internal->p_align = BYTE_GET (external->p_align);
2246 get_64bit_program_headers (file, program_headers)
2248 Elf_Internal_Phdr * program_headers;
2250 Elf64_External_Phdr * phdrs;
2251 Elf64_External_Phdr * external;
2252 Elf64_Internal_Phdr * internal;
2255 GET_DATA_ALLOC (elf_header.e_phoff,
2256 elf_header.e_phentsize * elf_header.e_phnum,
2257 phdrs, Elf64_External_Phdr *, "program headers");
2259 for (i = 0, internal = program_headers, external = phdrs;
2260 i < elf_header.e_phnum;
2261 i ++, internal ++, external ++)
2263 internal->p_type = BYTE_GET (external->p_type);
2264 internal->p_flags = BYTE_GET (external->p_flags);
2265 internal->p_offset = BYTE_GET8 (external->p_offset);
2266 internal->p_vaddr = BYTE_GET8 (external->p_vaddr);
2267 internal->p_paddr = BYTE_GET8 (external->p_paddr);
2268 internal->p_filesz = BYTE_GET8 (external->p_filesz);
2269 internal->p_memsz = BYTE_GET8 (external->p_memsz);
2270 internal->p_align = BYTE_GET8 (external->p_align);
2279 process_program_headers (file)
2282 Elf_Internal_Phdr * program_headers;
2283 Elf_Internal_Phdr * segment;
2286 if (elf_header.e_phnum == 0)
2289 printf (_("\nThere are no program headers in this file.\n"));
2293 if (do_segments && !do_header)
2295 printf (_("\nElf file type is %s\n"), get_file_type (elf_header.e_type));
2296 printf (_("Entry point "));
2297 print_vma ((bfd_vma) elf_header.e_entry, PREFIX_HEX);
2298 printf (_("\nThere are %d program headers, starting at offset "),
2299 elf_header.e_phnum);
2300 print_vma ((bfd_vma) elf_header.e_phoff, DEC);
2304 program_headers = (Elf_Internal_Phdr *) malloc
2305 (elf_header.e_phnum * sizeof (Elf_Internal_Phdr));
2307 if (program_headers == NULL)
2309 error (_("Out of memory\n"));
2314 i = get_32bit_program_headers (file, program_headers);
2316 i = get_64bit_program_headers (file, program_headers);
2320 free (program_headers);
2327 (_("\nProgram Header%s:\n"), elf_header.e_phnum > 1 ? "s" : "");
2331 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
2335 (_(" Type Offset VirtAddr PhysAddr\n"));
2337 (_(" FileSiz MemSiz Flags Align\n"));
2345 for (i = 0, segment = program_headers;
2346 i < elf_header.e_phnum;
2351 printf (" %-14.14s ", get_segment_type (segment->p_type));
2355 printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
2356 printf ("0x%8.8lx ", (unsigned long) segment->p_vaddr);
2357 printf ("0x%8.8lx ", (unsigned long) segment->p_paddr);
2358 printf ("0x%5.5lx ", (unsigned long) segment->p_filesz);
2359 printf ("0x%5.5lx ", (unsigned long) segment->p_memsz);
2361 (segment->p_flags & PF_R ? 'R' : ' '),
2362 (segment->p_flags & PF_W ? 'W' : ' '),
2363 (segment->p_flags & PF_X ? 'E' : ' '));
2364 printf ("%#lx", (unsigned long) segment->p_align);
2368 print_vma (segment->p_offset, FULL_HEX);
2370 print_vma (segment->p_vaddr, FULL_HEX);
2372 print_vma (segment->p_paddr, FULL_HEX);
2374 print_vma (segment->p_filesz, FULL_HEX);
2376 print_vma (segment->p_memsz, FULL_HEX);
2378 (segment->p_flags & PF_R ? 'R' : ' '),
2379 (segment->p_flags & PF_W ? 'W' : ' '),
2380 (segment->p_flags & PF_X ? 'E' : ' '));
2381 print_vma (segment->p_align, HEX);
2385 switch (segment->p_type)
2389 loadaddr = (segment->p_vaddr & 0xfffff000)
2390 - (segment->p_offset & 0xfffff000);
2395 error (_("more than one dynamic segment\n"));
2397 dynamic_addr = segment->p_offset;
2398 dynamic_size = segment->p_filesz;
2402 if (fseek (file, (long) segment->p_offset, SEEK_SET))
2403 error (_("Unable to find program interpreter name\n"));
2406 program_interpreter[0] = 0;
2407 fscanf (file, "%63s", program_interpreter);
2410 printf (_("\n [Requesting program interpreter: %s]"),
2411 program_interpreter);
2417 putc ('\n', stdout);
2426 if (do_segments && section_headers != NULL)
2428 printf (_("\n Section to Segment mapping:\n"));
2429 printf (_(" Segment Sections...\n"));
2431 assert (string_table != NULL);
2433 for (i = 0; i < elf_header.e_phnum; i++)
2436 Elf_Internal_Shdr * section;
2438 segment = program_headers + i;
2439 section = section_headers;
2441 printf (" %2.2d ", i);
2443 for (j = 0; j < elf_header.e_shnum; j++, section ++)
2445 if (section->sh_size > 0
2446 /* Compare allocated sections by VMA, unallocated
2447 sections by file offset. */
2448 && (section->sh_flags & SHF_ALLOC
2449 ? (section->sh_addr >= segment->p_vaddr
2450 && section->sh_addr + section->sh_size
2451 <= segment->p_vaddr + segment->p_memsz)
2452 : ((bfd_vma) section->sh_offset >= segment->p_offset
2453 && (section->sh_offset + section->sh_size
2454 <= segment->p_offset + segment->p_filesz))))
2455 printf ("%s ", SECTION_NAME (section));
2462 free (program_headers);
2469 get_32bit_section_headers (file)
2472 Elf32_External_Shdr * shdrs;
2473 Elf32_Internal_Shdr * internal;
2476 GET_DATA_ALLOC (elf_header.e_shoff,
2477 elf_header.e_shentsize * elf_header.e_shnum,
2478 shdrs, Elf32_External_Shdr *, "section headers");
2480 section_headers = (Elf_Internal_Shdr *) malloc
2481 (elf_header.e_shnum * sizeof (Elf_Internal_Shdr));
2483 if (section_headers == NULL)
2485 error (_("Out of memory\n"));
2489 for (i = 0, internal = section_headers;
2490 i < elf_header.e_shnum;
2493 internal->sh_name = BYTE_GET (shdrs[i].sh_name);
2494 internal->sh_type = BYTE_GET (shdrs[i].sh_type);
2495 internal->sh_flags = BYTE_GET (shdrs[i].sh_flags);
2496 internal->sh_addr = BYTE_GET (shdrs[i].sh_addr);
2497 internal->sh_offset = BYTE_GET (shdrs[i].sh_offset);
2498 internal->sh_size = BYTE_GET (shdrs[i].sh_size);
2499 internal->sh_link = BYTE_GET (shdrs[i].sh_link);
2500 internal->sh_info = BYTE_GET (shdrs[i].sh_info);
2501 internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
2502 internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize);
2511 get_64bit_section_headers (file)
2514 Elf64_External_Shdr * shdrs;
2515 Elf64_Internal_Shdr * internal;
2518 GET_DATA_ALLOC (elf_header.e_shoff,
2519 elf_header.e_shentsize * elf_header.e_shnum,
2520 shdrs, Elf64_External_Shdr *, "section headers");
2522 section_headers = (Elf_Internal_Shdr *) malloc
2523 (elf_header.e_shnum * sizeof (Elf_Internal_Shdr));
2525 if (section_headers == NULL)
2527 error (_("Out of memory\n"));
2531 for (i = 0, internal = section_headers;
2532 i < elf_header.e_shnum;
2535 internal->sh_name = BYTE_GET (shdrs[i].sh_name);
2536 internal->sh_type = BYTE_GET (shdrs[i].sh_type);
2537 internal->sh_flags = BYTE_GET8 (shdrs[i].sh_flags);
2538 internal->sh_addr = BYTE_GET8 (shdrs[i].sh_addr);
2539 internal->sh_size = BYTE_GET8 (shdrs[i].sh_size);
2540 internal->sh_entsize = BYTE_GET8 (shdrs[i].sh_entsize);
2541 internal->sh_link = BYTE_GET (shdrs[i].sh_link);
2542 internal->sh_info = BYTE_GET (shdrs[i].sh_info);
2543 internal->sh_offset = BYTE_GET (shdrs[i].sh_offset);
2544 internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
2552 static Elf_Internal_Sym *
2553 get_32bit_elf_symbols (file, offset, number)
2555 unsigned long offset;
2556 unsigned long number;
2558 Elf32_External_Sym * esyms;
2559 Elf_Internal_Sym * isyms;
2560 Elf_Internal_Sym * psym;
2563 GET_DATA_ALLOC (offset, number * sizeof (Elf32_External_Sym),
2564 esyms, Elf32_External_Sym *, "symbols");
2566 isyms = (Elf_Internal_Sym *) malloc (number * sizeof (Elf_Internal_Sym));
2570 error (_("Out of memory\n"));
2576 for (j = 0, psym = isyms;
2580 psym->st_name = BYTE_GET (esyms[j].st_name);
2581 psym->st_value = BYTE_GET (esyms[j].st_value);
2582 psym->st_size = BYTE_GET (esyms[j].st_size);
2583 psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
2584 psym->st_info = BYTE_GET (esyms[j].st_info);
2585 psym->st_other = BYTE_GET (esyms[j].st_other);
2593 static Elf_Internal_Sym *
2594 get_64bit_elf_symbols (file, offset, number)
2596 unsigned long offset;
2597 unsigned long number;
2599 Elf64_External_Sym * esyms;
2600 Elf_Internal_Sym * isyms;
2601 Elf_Internal_Sym * psym;
2604 GET_DATA_ALLOC (offset, number * sizeof (Elf64_External_Sym),
2605 esyms, Elf64_External_Sym *, "symbols");
2607 isyms = (Elf_Internal_Sym *) malloc (number * sizeof (Elf_Internal_Sym));
2611 error (_("Out of memory\n"));
2617 for (j = 0, psym = isyms;
2621 psym->st_name = BYTE_GET (esyms[j].st_name);
2622 psym->st_info = BYTE_GET (esyms[j].st_info);
2623 psym->st_other = BYTE_GET (esyms[j].st_other);
2624 psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
2625 psym->st_value = BYTE_GET8 (esyms[j].st_value);
2626 psym->st_size = BYTE_GET8 (esyms[j].st_size);
2635 get_elf_section_flags (sh_flags)
2638 static char buff [32];
2646 flag = sh_flags & - sh_flags;
2651 case SHF_WRITE: strcat (buff, "W"); break;
2652 case SHF_ALLOC: strcat (buff, "A"); break;
2653 case SHF_EXECINSTR: strcat (buff, "X"); break;
2654 case SHF_MERGE: strcat (buff, "M"); break;
2655 case SHF_STRINGS: strcat (buff, "S"); break;
2656 case SHF_INFO_LINK: strcat (buff, "I"); break;
2657 case SHF_LINK_ORDER: strcat (buff, "L"); break;
2658 case SHF_OS_NONCONFORMING: strcat (buff, "O"); break;
2659 case SHF_GROUP: strcat (buff, "G"); break;
2662 if (flag & SHF_MASKOS)
2665 sh_flags &= ~ SHF_MASKOS;
2667 else if (flag & SHF_MASKPROC)
2670 sh_flags &= ~ SHF_MASKPROC;
2682 process_section_headers (file)
2685 Elf_Internal_Shdr * section;
2688 section_headers = NULL;
2690 if (elf_header.e_shnum == 0)
2693 printf (_("\nThere are no sections in this file.\n"));
2698 if (do_sections && !do_header)
2699 printf (_("There are %d section headers, starting at offset 0x%lx:\n"),
2700 elf_header.e_shnum, (unsigned long) elf_header.e_shoff);
2704 if (! get_32bit_section_headers (file))
2707 else if (! get_64bit_section_headers (file))
2710 /* Read in the string table, so that we have names to display. */
2711 section = section_headers + elf_header.e_shstrndx;
2713 if (section->sh_size != 0)
2715 unsigned long string_table_offset;
2717 string_table_offset = section->sh_offset;
2719 GET_DATA_ALLOC (section->sh_offset, section->sh_size,
2720 string_table, char *, "string table");
2723 /* Scan the sections for the dynamic symbol table
2724 and dynamic string table and debug sections. */
2725 dynamic_symbols = NULL;
2726 dynamic_strings = NULL;
2727 dynamic_syminfo = NULL;
2729 for (i = 0, section = section_headers;
2730 i < elf_header.e_shnum;
2733 char * name = SECTION_NAME (section);
2735 if (section->sh_type == SHT_DYNSYM)
2737 if (dynamic_symbols != NULL)
2739 error (_("File contains multiple dynamic symbol tables\n"));
2743 num_dynamic_syms = section->sh_size / section->sh_entsize;
2745 GET_ELF_SYMBOLS (file, section->sh_offset, num_dynamic_syms);
2747 else if (section->sh_type == SHT_STRTAB
2748 && strcmp (name, ".dynstr") == 0)
2750 if (dynamic_strings != NULL)
2752 error (_("File contains multiple dynamic string tables\n"));
2756 GET_DATA_ALLOC (section->sh_offset, section->sh_size,
2757 dynamic_strings, char *, "dynamic strings");
2759 else if ((do_debugging || do_debug_info || do_debug_abbrevs
2760 || do_debug_lines || do_debug_pubnames || do_debug_aranges || do_debug_frames)
2761 && strncmp (name, ".debug_", 7) == 0)
2766 || (do_debug_info && (strcmp (name, "info") == 0))
2767 || (do_debug_abbrevs && (strcmp (name, "abbrev") == 0))
2768 || (do_debug_lines && (strcmp (name, "line") == 0))
2769 || (do_debug_pubnames && (strcmp (name, "pubnames") == 0))
2770 || (do_debug_aranges && (strcmp (name, "aranges") == 0))
2771 || (do_debug_frames && (strcmp (name, "frame") == 0))
2773 request_dump (i, DEBUG_DUMP);
2775 /* linkonce section to be combined with .debug_info at link time. */
2776 else if ((do_debugging || do_debug_info)
2777 && strncmp (name, ".gnu.linkonce.wi.", 17) == 0)
2778 request_dump (i, DEBUG_DUMP);
2779 else if (do_debug_frames && strcmp (name, ".eh_frame") == 0)
2780 request_dump (i, DEBUG_DUMP);
2786 printf (_("\nSection Header%s:\n"), elf_header.e_shnum > 1 ? "s" : "");
2790 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
2793 printf (_(" [Nr] Name Type Address Offset\n"));
2794 printf (_(" Size EntSize Flags Link Info Align\n"));
2797 for (i = 0, section = section_headers;
2798 i < elf_header.e_shnum;
2801 printf (" [%2d] %-17.17s %-15.15s ",
2803 SECTION_NAME (section),
2804 get_section_type_name (section->sh_type));
2808 print_vma (section->sh_addr, LONG_HEX);
2810 printf ( " %6.6lx %6.6lx %2.2lx",
2811 (unsigned long) section->sh_offset,
2812 (unsigned long) section->sh_size,
2813 (unsigned long) section->sh_entsize);
2815 printf (" %3s ", get_elf_section_flags (section->sh_flags));
2817 printf ("%2ld %3lx %2ld\n",
2818 (unsigned long) section->sh_link,
2819 (unsigned long) section->sh_info,
2820 (unsigned long) section->sh_addralign);
2825 print_vma (section->sh_addr, LONG_HEX);
2826 printf (" %8.8lx", section->sh_offset);
2828 print_vma (section->sh_size, LONG_HEX);
2830 print_vma (section->sh_entsize, LONG_HEX);
2832 printf (" %3s ", get_elf_section_flags (section->sh_flags));
2834 printf (" %2ld %3lx %ld\n",
2835 (unsigned long) section->sh_link,
2836 (unsigned long) section->sh_info,
2837 (unsigned long) section->sh_addralign);
2841 printf (_("Key to Flags:\n"));
2842 printf (_(" W (write), A (alloc), X (execute), M (merge), S (strings)\n"));
2843 printf (_(" I (info), L (link order), G (group), x (unknown)\n"));
2844 printf (_(" O (extra OS processing required) o (OS specific), p (processor specific)\n"));
2849 /* Process the reloc section. */
2851 process_relocs (file)
2854 unsigned long rel_size;
2855 unsigned long rel_offset;
2861 if (do_using_dynamic)
2863 int is_rela = FALSE;
2868 if (dynamic_info[DT_REL])
2870 rel_offset = dynamic_info[DT_REL];
2871 rel_size = dynamic_info[DT_RELSZ];
2874 else if (dynamic_info [DT_RELA])
2876 rel_offset = dynamic_info[DT_RELA];
2877 rel_size = dynamic_info[DT_RELASZ];
2880 else if (dynamic_info[DT_JMPREL])
2882 rel_offset = dynamic_info[DT_JMPREL];
2883 rel_size = dynamic_info[DT_PLTRELSZ];
2885 switch (dynamic_info[DT_PLTREL])
2902 (_("\nRelocation section at offset 0x%lx contains %ld bytes:\n"),
2903 rel_offset, rel_size);
2905 dump_relocations (file, rel_offset - loadaddr, rel_size,
2906 dynamic_symbols, num_dynamic_syms, dynamic_strings, is_rela);
2909 printf (_("\nThere are no dynamic relocations in this file.\n"));
2913 Elf32_Internal_Shdr * section;
2917 for (i = 0, section = section_headers;
2918 i < elf_header.e_shnum;
2921 if ( section->sh_type != SHT_RELA
2922 && section->sh_type != SHT_REL)
2925 rel_offset = section->sh_offset;
2926 rel_size = section->sh_size;
2930 Elf32_Internal_Shdr * strsec;
2931 Elf32_Internal_Shdr * symsec;
2932 Elf_Internal_Sym * symtab;
2935 unsigned long nsyms;
2937 printf (_("\nRelocation section "));
2939 if (string_table == NULL)
2940 printf ("%d", section->sh_name);
2942 printf ("'%s'", SECTION_NAME (section));
2944 printf (_(" at offset 0x%lx contains %lu entries:\n"),
2945 rel_offset, (unsigned long) (rel_size / section->sh_entsize));
2947 symsec = section_headers + section->sh_link;
2949 nsyms = symsec->sh_size / symsec->sh_entsize;
2950 symtab = GET_ELF_SYMBOLS (file, symsec->sh_offset, nsyms);
2955 strsec = section_headers + symsec->sh_link;
2957 GET_DATA_ALLOC (strsec->sh_offset, strsec->sh_size, strtab,
2958 char *, "string table");
2960 is_rela = section->sh_type == SHT_RELA;
2962 dump_relocations (file, rel_offset, rel_size, symtab, nsyms, strtab, is_rela);
2972 printf (_("\nThere are no relocations in this file.\n"));
2980 dynamic_segment_mips_val (entry)
2981 Elf_Internal_Dyn * entry;
2983 switch (entry->d_tag)
2986 if (entry->d_un.d_val == 0)
2990 static const char * opts[] =
2992 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
2993 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
2994 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
2995 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
3000 for (cnt = 0; cnt < NUM_ELEM (opts); ++ cnt)
3001 if (entry->d_un.d_val & (1 << cnt))
3003 printf ("%s%s", first ? "" : " ", opts[cnt]);
3010 case DT_MIPS_IVERSION:
3011 if (dynamic_strings != NULL)
3012 printf ("Interface Version: %s\n",
3013 dynamic_strings + entry->d_un.d_val);
3015 printf ("%ld\n", (long) entry->d_un.d_ptr);
3018 case DT_MIPS_TIME_STAMP:
3023 time_t time = entry->d_un.d_val;
3024 tmp = gmtime (&time);
3025 sprintf (timebuf, "%04u-%02u-%02uT%02u:%02u:%02u",
3026 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
3027 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
3028 printf ("Time Stamp: %s\n", timebuf);
3032 case DT_MIPS_RLD_VERSION:
3033 case DT_MIPS_LOCAL_GOTNO:
3034 case DT_MIPS_CONFLICTNO:
3035 case DT_MIPS_LIBLISTNO:
3036 case DT_MIPS_SYMTABNO:
3037 case DT_MIPS_UNREFEXTNO:
3038 case DT_MIPS_HIPAGENO:
3039 case DT_MIPS_DELTA_CLASS_NO:
3040 case DT_MIPS_DELTA_INSTANCE_NO:
3041 case DT_MIPS_DELTA_RELOC_NO:
3042 case DT_MIPS_DELTA_SYM_NO:
3043 case DT_MIPS_DELTA_CLASSSYM_NO:
3044 case DT_MIPS_COMPACT_SIZE:
3045 printf ("%ld\n", (long) entry->d_un.d_ptr);
3049 printf ("%#lx\n", (long) entry->d_un.d_ptr);
3055 dynamic_segment_parisc_val (entry)
3056 Elf_Internal_Dyn * entry;
3058 switch (entry->d_tag)
3060 case DT_HP_DLD_FLAGS:
3069 { DT_HP_DEBUG_PRIVATE, "HP_DEBUG_PRIVATE" },
3070 { DT_HP_DEBUG_CALLBACK, "HP_DEBUG_CALLBACK" },
3071 { DT_HP_DEBUG_CALLBACK_BOR, "HP_DEBUG_CALLBACK_BOR" },
3072 { DT_HP_NO_ENVVAR, "HP_NO_ENVVAR" },
3073 { DT_HP_BIND_NOW, "HP_BIND_NOW" },
3074 { DT_HP_BIND_NONFATAL, "HP_BIND_NONFATAL" },
3075 { DT_HP_BIND_VERBOSE, "HP_BIND_VERBOSE" },
3076 { DT_HP_BIND_RESTRICTED, "HP_BIND_RESTRICTED" },
3077 { DT_HP_BIND_SYMBOLIC, "HP_BIND_SYMBOLIC" },
3078 { DT_HP_RPATH_FIRST, "HP_RPATH_FIRST" },
3079 { DT_HP_BIND_DEPTH_FIRST, "HP_BIND_DEPTH_FIRST" }
3083 bfd_vma val = entry->d_un.d_val;
3085 for (cnt = 0; cnt < sizeof (flags) / sizeof (flags[0]); ++cnt)
3086 if (val & flags[cnt].bit)
3090 fputs (flags[cnt].str, stdout);
3092 val ^= flags[cnt].bit;
3095 if (val != 0 || first)
3099 print_vma (val, HEX);
3105 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
3111 get_32bit_dynamic_segment (file)
3114 Elf32_External_Dyn * edyn;
3115 Elf_Internal_Dyn * entry;
3118 GET_DATA_ALLOC (dynamic_addr, dynamic_size,
3119 edyn, Elf32_External_Dyn *, "dynamic segment");
3121 /* SGI's ELF has more than one section in the DYNAMIC segment. Determine
3122 how large this .dynamic is now. We can do this even before the byte
3123 swapping since the DT_NULL tag is recognizable. */
3125 while (*(Elf32_Word *) edyn [dynamic_size++].d_tag != DT_NULL)
3128 dynamic_segment = (Elf_Internal_Dyn *)
3129 malloc (dynamic_size * sizeof (Elf_Internal_Dyn));
3131 if (dynamic_segment == NULL)
3133 error (_("Out of memory\n"));
3138 for (i = 0, entry = dynamic_segment;
3142 entry->d_tag = BYTE_GET (edyn [i].d_tag);
3143 entry->d_un.d_val = BYTE_GET (edyn [i].d_un.d_val);
3152 get_64bit_dynamic_segment (file)
3155 Elf64_External_Dyn * edyn;
3156 Elf_Internal_Dyn * entry;
3159 GET_DATA_ALLOC (dynamic_addr, dynamic_size,
3160 edyn, Elf64_External_Dyn *, "dynamic segment");
3162 /* SGI's ELF has more than one section in the DYNAMIC segment. Determine
3163 how large this .dynamic is now. We can do this even before the byte
3164 swapping since the DT_NULL tag is recognizable. */
3166 while (*(bfd_vma *) edyn [dynamic_size ++].d_tag != DT_NULL)
3169 dynamic_segment = (Elf_Internal_Dyn *)
3170 malloc (dynamic_size * sizeof (Elf_Internal_Dyn));
3172 if (dynamic_segment == NULL)
3174 error (_("Out of memory\n"));
3179 for (i = 0, entry = dynamic_segment;
3183 entry->d_tag = BYTE_GET8 (edyn [i].d_tag);
3184 entry->d_un.d_val = BYTE_GET8 (edyn [i].d_un.d_val);
3193 get_dynamic_flags (flags)
3196 static char buff [64];
3201 flag = flags & - flags;
3206 case DF_ORIGIN: strcat (buff, "ORIGIN "); break;
3207 case DF_SYMBOLIC: strcat (buff, "SYMBOLIC "); break;
3208 case DF_TEXTREL: strcat (buff, "TEXTREL "); break;
3209 case DF_BIND_NOW: strcat (buff, "BIND_NOW "); break;
3210 default: strcat (buff, "unknown "); break;
3216 /* Parse and display the contents of the dynamic segment. */
3218 process_dynamic_segment (file)
3221 Elf_Internal_Dyn * entry;
3224 if (dynamic_size == 0)
3227 printf (_("\nThere is no dynamic segment in this file.\n"));
3234 if (! get_32bit_dynamic_segment (file))
3237 else if (! get_64bit_dynamic_segment (file))
3240 /* Find the appropriate symbol table. */
3241 if (dynamic_symbols == NULL)
3243 for (i = 0, entry = dynamic_segment;
3247 unsigned long offset;
3249 if (entry->d_tag != DT_SYMTAB)
3252 dynamic_info[DT_SYMTAB] = entry->d_un.d_val;
3254 /* Since we do not know how big the symbol table is,
3255 we default to reading in the entire file (!) and
3256 processing that. This is overkill, I know, but it
3258 offset = entry->d_un.d_val - loadaddr;
3260 if (fseek (file, 0, SEEK_END))
3261 error (_("Unable to seek to end of file!"));
3264 num_dynamic_syms = (ftell (file) - offset) / sizeof (Elf32_External_Sym);
3266 num_dynamic_syms = (ftell (file) - offset) / sizeof (Elf64_External_Sym);
3268 if (num_dynamic_syms < 1)
3270 error (_("Unable to determine the number of symbols to load\n"));
3274 dynamic_symbols = GET_ELF_SYMBOLS (file, offset, num_dynamic_syms);
3278 /* Similarly find a string table. */
3279 if (dynamic_strings == NULL)
3281 for (i = 0, entry = dynamic_segment;
3285 unsigned long offset;
3288 if (entry->d_tag != DT_STRTAB)
3291 dynamic_info[DT_STRTAB] = entry->d_un.d_val;
3293 /* Since we do not know how big the string table is,
3294 we default to reading in the entire file (!) and
3295 processing that. This is overkill, I know, but it
3298 offset = entry->d_un.d_val - loadaddr;
3299 if (fseek (file, 0, SEEK_END))
3300 error (_("Unable to seek to end of file\n"));
3301 str_tab_len = ftell (file) - offset;
3303 if (str_tab_len < 1)
3306 (_("Unable to determine the length of the dynamic string table\n"));
3310 GET_DATA_ALLOC (offset, str_tab_len, dynamic_strings, char *,
3311 "dynamic string table");
3317 /* And find the syminfo section if available. */
3318 if (dynamic_syminfo == NULL)
3320 unsigned int syminsz = 0;
3322 for (i = 0, entry = dynamic_segment;
3326 if (entry->d_tag == DT_SYMINENT)
3328 /* Note: these braces are necessary to avoid a syntax
3329 error from the SunOS4 C compiler. */
3330 assert (sizeof (Elf_External_Syminfo) == entry->d_un.d_val);
3332 else if (entry->d_tag == DT_SYMINSZ)
3333 syminsz = entry->d_un.d_val;
3334 else if (entry->d_tag == DT_SYMINFO)
3335 dynamic_syminfo_offset = entry->d_un.d_val - loadaddr;
3338 if (dynamic_syminfo_offset != 0 && syminsz != 0)
3340 Elf_External_Syminfo * extsyminfo;
3341 Elf_Internal_Syminfo * syminfo;
3343 /* There is a syminfo section. Read the data. */
3344 GET_DATA_ALLOC (dynamic_syminfo_offset, syminsz, extsyminfo,
3345 Elf_External_Syminfo *, "symbol information");
3347 dynamic_syminfo = (Elf_Internal_Syminfo *) malloc (syminsz);
3348 if (dynamic_syminfo == NULL)
3350 error (_("Out of memory\n"));
3354 dynamic_syminfo_nent = syminsz / sizeof (Elf_External_Syminfo);
3355 for (i = 0, syminfo = dynamic_syminfo; i < dynamic_syminfo_nent;
3358 syminfo->si_boundto = BYTE_GET (extsyminfo[i].si_boundto);
3359 syminfo->si_flags = BYTE_GET (extsyminfo[i].si_flags);
3366 if (do_dynamic && dynamic_addr)
3367 printf (_("\nDynamic segment at offset 0x%x contains %ld entries:\n"),
3368 dynamic_addr, (long) dynamic_size);
3370 printf (_(" Tag Type Name/Value\n"));
3372 for (i = 0, entry = dynamic_segment;
3381 print_vma (entry->d_tag, FULL_HEX);
3382 dtype = get_dynamic_type (entry->d_tag);
3383 printf (" (%s)%*s", dtype,
3384 ((is_32bit_elf ? 27 : 19)
3385 - (int) strlen (dtype)),
3389 switch (entry->d_tag)
3393 printf ("%s", get_dynamic_flags (entry->d_un.d_val));
3403 switch (entry->d_tag)
3406 printf (_("Auxiliary library"));
3410 printf (_("Filter library"));
3414 printf (_("Configuration file"));
3418 printf (_("Dependency audit library"));
3422 printf (_("Audit library"));
3426 if (dynamic_strings)
3427 printf (": [%s]\n", dynamic_strings + entry->d_un.d_val);
3431 print_vma (entry->d_un.d_val, PREFIX_HEX);
3440 printf (_("Flags:"));
3441 if (entry->d_un.d_val == 0)
3442 printf (_(" None\n"));
3445 unsigned long int val = entry->d_un.d_val;
3446 if (val & DTF_1_PARINIT)
3448 printf (" PARINIT");
3449 val ^= DTF_1_PARINIT;
3451 if (val & DTF_1_CONFEXP)
3453 printf (" CONFEXP");
3454 val ^= DTF_1_CONFEXP;
3457 printf (" %lx", val);
3466 printf (_("Flags:"));
3467 if (entry->d_un.d_val == 0)
3468 printf (_(" None\n"));
3471 unsigned long int val = entry->d_un.d_val;
3472 if (val & DF_P1_LAZYLOAD)
3474 printf (" LAZYLOAD");
3475 val ^= DF_P1_LAZYLOAD;
3477 if (val & DF_P1_GROUPPERM)
3479 printf (" GROUPPERM");
3480 val ^= DF_P1_GROUPPERM;
3483 printf (" %lx", val);
3492 printf (_("Flags:"));
3493 if (entry->d_un.d_val == 0)
3494 printf (_(" None\n"));
3497 unsigned long int val = entry->d_un.d_val;
3503 if (val & DF_1_GLOBAL)
3508 if (val & DF_1_GROUP)
3513 if (val & DF_1_NODELETE)
3515 printf (" NODELETE");
3516 val ^= DF_1_NODELETE;
3518 if (val & DF_1_LOADFLTR)
3520 printf (" LOADFLTR");
3521 val ^= DF_1_LOADFLTR;
3523 if (val & DF_1_INITFIRST)
3525 printf (" INITFIRST");
3526 val ^= DF_1_INITFIRST;
3528 if (val & DF_1_NOOPEN)
3533 if (val & DF_1_ORIGIN)
3538 if (val & DF_1_DIRECT)
3543 if (val & DF_1_TRANS)
3548 if (val & DF_1_INTERPOSE)
3550 printf (" INTERPOSE");
3551 val ^= DF_1_INTERPOSE;
3553 if (val & DF_1_NODEFLIB)
3555 printf (" NODEFLIB");
3556 val ^= DF_1_NODEFLIB;
3558 if (val & DF_1_NODUMP)
3563 if (val & DF_1_CONLFAT)
3565 printf (" CONLFAT");
3566 val ^= DF_1_CONLFAT;
3569 printf (" %lx", val);
3577 puts (get_dynamic_type (entry->d_un.d_val));
3597 dynamic_info[entry->d_tag] = entry->d_un.d_val;
3603 if (dynamic_strings == NULL)
3606 name = dynamic_strings + entry->d_un.d_val;
3610 switch (entry->d_tag)
3613 printf (_("Shared library: [%s]"), name);
3615 if (strcmp (name, program_interpreter) == 0)
3616 printf (_(" program interpreter"));
3620 printf (_("Library soname: [%s]"), name);
3624 printf (_("Library rpath: [%s]"), name);
3628 printf (_("Library runpath: [%s]"), name);
3632 print_vma (entry->d_un.d_val, PREFIX_HEX);
3637 print_vma (entry->d_un.d_val, PREFIX_HEX);
3653 case DT_INIT_ARRAYSZ:
3654 case DT_FINI_ARRAYSZ:
3657 print_vma (entry->d_un.d_val, UNSIGNED);
3658 printf (" (bytes)\n");
3668 print_vma (entry->d_un.d_val, UNSIGNED);
3681 if (dynamic_strings != NULL && entry->d_tag == DT_USED)
3685 name = dynamic_strings + entry->d_un.d_val;
3689 printf (_("Not needed object: [%s]\n"), name);
3694 print_vma (entry->d_un.d_val, PREFIX_HEX);
3700 /* The value of this entry is ignored. */
3704 if ((entry->d_tag >= DT_VERSYM) && (entry->d_tag <= DT_VERNEEDNUM))
3705 version_info [DT_VERSIONTAGIDX (entry->d_tag)] =
3710 switch (elf_header.e_machine)
3713 case EM_MIPS_RS4_BE:
3714 dynamic_segment_mips_val (entry);
3717 dynamic_segment_parisc_val (entry);
3720 print_vma (entry->d_un.d_val, PREFIX_HEX);
3732 get_ver_flags (flags)
3735 static char buff [32];
3742 if (flags & VER_FLG_BASE)
3743 strcat (buff, "BASE ");
3745 if (flags & VER_FLG_WEAK)
3747 if (flags & VER_FLG_BASE)
3748 strcat (buff, "| ");
3750 strcat (buff, "WEAK ");
3753 if (flags & ~(VER_FLG_BASE | VER_FLG_WEAK))
3754 strcat (buff, "| <unknown>");
3759 /* Display the contents of the version sections. */
3761 process_version_sections (file)
3764 Elf32_Internal_Shdr * section;
3771 for (i = 0, section = section_headers;
3772 i < elf_header.e_shnum;
3775 switch (section->sh_type)
3777 case SHT_GNU_verdef:
3779 Elf_External_Verdef * edefs;
3786 (_("\nVersion definition section '%s' contains %ld entries:\n"),
3787 SECTION_NAME (section), section->sh_info);
3789 printf (_(" Addr: 0x"));
3790 printf_vma (section->sh_addr);
3791 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
3792 (unsigned long) section->sh_offset, section->sh_link,
3793 SECTION_NAME (section_headers + section->sh_link));
3795 GET_DATA_ALLOC (section->sh_offset, section->sh_size,
3796 edefs, Elf_External_Verdef *,
3797 "version definition section");
3799 for (idx = cnt = 0; cnt < section->sh_info; ++ cnt)
3802 Elf_External_Verdef * edef;
3803 Elf_Internal_Verdef ent;
3804 Elf_External_Verdaux * eaux;
3805 Elf_Internal_Verdaux aux;
3809 vstart = ((char *) edefs) + idx;
3811 edef = (Elf_External_Verdef *) vstart;
3813 ent.vd_version = BYTE_GET (edef->vd_version);
3814 ent.vd_flags = BYTE_GET (edef->vd_flags);
3815 ent.vd_ndx = BYTE_GET (edef->vd_ndx);
3816 ent.vd_cnt = BYTE_GET (edef->vd_cnt);
3817 ent.vd_hash = BYTE_GET (edef->vd_hash);
3818 ent.vd_aux = BYTE_GET (edef->vd_aux);
3819 ent.vd_next = BYTE_GET (edef->vd_next);
3821 printf (_(" %#06x: Rev: %d Flags: %s"),
3822 idx, ent.vd_version, get_ver_flags (ent.vd_flags));
3824 printf (_(" Index: %d Cnt: %d "),
3825 ent.vd_ndx, ent.vd_cnt);
3827 vstart += ent.vd_aux;
3829 eaux = (Elf_External_Verdaux *) vstart;
3831 aux.vda_name = BYTE_GET (eaux->vda_name);
3832 aux.vda_next = BYTE_GET (eaux->vda_next);
3834 if (dynamic_strings)
3835 printf (_("Name: %s\n"), dynamic_strings + aux.vda_name);
3837 printf (_("Name index: %ld\n"), aux.vda_name);
3839 isum = idx + ent.vd_aux;
3841 for (j = 1; j < ent.vd_cnt; j ++)
3843 isum += aux.vda_next;
3844 vstart += aux.vda_next;
3846 eaux = (Elf_External_Verdaux *) vstart;
3848 aux.vda_name = BYTE_GET (eaux->vda_name);
3849 aux.vda_next = BYTE_GET (eaux->vda_next);
3851 if (dynamic_strings)
3852 printf (_(" %#06x: Parent %d: %s\n"),
3853 isum, j, dynamic_strings + aux.vda_name);
3855 printf (_(" %#06x: Parent %d, name index: %ld\n"),
3856 isum, j, aux.vda_name);
3866 case SHT_GNU_verneed:
3868 Elf_External_Verneed * eneed;
3874 printf (_("\nVersion needs section '%s' contains %ld entries:\n"),
3875 SECTION_NAME (section), section->sh_info);
3877 printf (_(" Addr: 0x"));
3878 printf_vma (section->sh_addr);
3879 printf (_(" Offset: %#08lx Link to section: %ld (%s)\n"),
3880 (unsigned long) section->sh_offset, section->sh_link,
3881 SECTION_NAME (section_headers + section->sh_link));
3883 GET_DATA_ALLOC (section->sh_offset, section->sh_size,
3884 eneed, Elf_External_Verneed *,
3885 "version need section");
3887 for (idx = cnt = 0; cnt < section->sh_info; ++cnt)
3889 Elf_External_Verneed * entry;
3890 Elf_Internal_Verneed ent;
3895 vstart = ((char *) eneed) + idx;
3897 entry = (Elf_External_Verneed *) vstart;
3899 ent.vn_version = BYTE_GET (entry->vn_version);
3900 ent.vn_cnt = BYTE_GET (entry->vn_cnt);
3901 ent.vn_file = BYTE_GET (entry->vn_file);
3902 ent.vn_aux = BYTE_GET (entry->vn_aux);
3903 ent.vn_next = BYTE_GET (entry->vn_next);
3905 printf (_(" %#06x: Version: %d"), idx, ent.vn_version);
3907 if (dynamic_strings)
3908 printf (_(" File: %s"), dynamic_strings + ent.vn_file);
3910 printf (_(" File: %lx"), ent.vn_file);
3912 printf (_(" Cnt: %d\n"), ent.vn_cnt);
3914 vstart += ent.vn_aux;
3916 for (j = 0, isum = idx + ent.vn_aux; j < ent.vn_cnt; ++j)
3918 Elf_External_Vernaux * eaux;
3919 Elf_Internal_Vernaux aux;
3921 eaux = (Elf_External_Vernaux *) vstart;
3923 aux.vna_hash = BYTE_GET (eaux->vna_hash);
3924 aux.vna_flags = BYTE_GET (eaux->vna_flags);
3925 aux.vna_other = BYTE_GET (eaux->vna_other);
3926 aux.vna_name = BYTE_GET (eaux->vna_name);
3927 aux.vna_next = BYTE_GET (eaux->vna_next);
3929 if (dynamic_strings)
3930 printf (_(" %#06x: Name: %s"),
3931 isum, dynamic_strings + aux.vna_name);
3933 printf (_(" %#06x: Name index: %lx"),
3934 isum, aux.vna_name);
3936 printf (_(" Flags: %s Version: %d\n"),
3937 get_ver_flags (aux.vna_flags), aux.vna_other);
3939 isum += aux.vna_next;
3940 vstart += aux.vna_next;
3950 case SHT_GNU_versym:
3952 Elf32_Internal_Shdr * link_section;
3955 unsigned char * edata;
3956 unsigned short * data;
3958 Elf_Internal_Sym * symbols;
3959 Elf32_Internal_Shdr * string_sec;
3961 link_section = section_headers + section->sh_link;
3962 total = section->sh_size / section->sh_entsize;
3966 symbols = GET_ELF_SYMBOLS (file, link_section->sh_offset,
3967 link_section->sh_size / link_section->sh_entsize);
3969 string_sec = section_headers + link_section->sh_link;
3971 GET_DATA_ALLOC (string_sec->sh_offset, string_sec->sh_size,
3972 strtab, char *, "version string table");
3974 printf (_("\nVersion symbols section '%s' contains %d entries:\n"),
3975 SECTION_NAME (section), total);
3977 printf (_(" Addr: "));
3978 printf_vma (section->sh_addr);
3979 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
3980 (unsigned long) section->sh_offset, section->sh_link,
3981 SECTION_NAME (link_section));
3983 GET_DATA_ALLOC (version_info [DT_VERSIONTAGIDX (DT_VERSYM)]
3985 total * sizeof (short), edata,
3986 unsigned char *, "version symbol data");
3988 data = (unsigned short *) malloc (total * sizeof (short));
3990 for (cnt = total; cnt --;)
3991 data [cnt] = byte_get (edata + cnt * sizeof (short),
3996 for (cnt = 0; cnt < total; cnt += 4)
4001 printf (" %03x:", cnt);
4003 for (j = 0; (j < 4) && (cnt + j) < total; ++j)
4004 switch (data [cnt + j])
4007 fputs (_(" 0 (*local*) "), stdout);
4011 fputs (_(" 1 (*global*) "), stdout);
4015 nn = printf ("%4x%c", data [cnt + j] & 0x7fff,
4016 data [cnt + j] & 0x8000 ? 'h' : ' ');
4018 if (symbols [cnt + j].st_shndx < SHN_LORESERVE
4019 && section_headers[symbols [cnt + j].st_shndx].sh_type
4022 /* We must test both. */
4023 Elf_Internal_Verneed ivn;
4024 unsigned long offset;
4026 offset = version_info [DT_VERSIONTAGIDX (DT_VERNEED)]
4031 Elf_External_Verneed evn;
4032 Elf_External_Vernaux evna;
4033 Elf_Internal_Vernaux ivna;
4034 unsigned long vna_off;
4036 GET_DATA (offset, evn, "version need");
4038 ivn.vn_aux = BYTE_GET (evn.vn_aux);
4039 ivn.vn_next = BYTE_GET (evn.vn_next);
4041 vna_off = offset + ivn.vn_aux;
4045 GET_DATA (vna_off, evna,
4046 "version need aux (1)");
4048 ivna.vna_next = BYTE_GET (evna.vna_next);
4049 ivna.vna_other = BYTE_GET (evna.vna_other);
4051 vna_off += ivna.vna_next;
4053 while (ivna.vna_other != data [cnt + j]
4054 && ivna.vna_next != 0);
4056 if (ivna.vna_other == data [cnt + j])
4058 ivna.vna_name = BYTE_GET (evna.vna_name);
4060 name = strtab + ivna.vna_name;
4061 nn += printf ("(%s%-*s",
4063 12 - (int) strlen (name),
4067 else if (ivn.vn_next == 0)
4069 if (data [cnt + j] != 0x8001)
4071 Elf_Internal_Verdef ivd;
4072 Elf_External_Verdef evd;
4074 offset = version_info
4075 [DT_VERSIONTAGIDX (DT_VERDEF)]
4080 GET_DATA (offset, evd,
4081 "version definition");
4083 ivd.vd_next = BYTE_GET (evd.vd_next);
4084 ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
4086 offset += ivd.vd_next;
4089 != (data [cnt + j] & 0x7fff)
4090 && ivd.vd_next != 0);
4093 == (data [cnt + j] & 0x7fff))
4095 Elf_External_Verdaux evda;
4096 Elf_Internal_Verdaux ivda;
4098 ivd.vd_aux = BYTE_GET (evd.vd_aux);
4100 GET_DATA (offset + ivd.vd_aux, evda,
4101 "version definition aux");
4104 BYTE_GET (evda.vda_name);
4106 name = strtab + ivda.vda_name;
4110 12 - (int) strlen (name),
4118 offset += ivn.vn_next;
4120 while (ivn.vn_next);
4122 else if (symbols [cnt + j].st_shndx == SHN_UNDEF)
4124 Elf_Internal_Verneed ivn;
4125 unsigned long offset;
4127 offset = version_info [DT_VERSIONTAGIDX (DT_VERNEED)]
4132 Elf_Internal_Vernaux ivna;
4133 Elf_External_Verneed evn;
4134 Elf_External_Vernaux evna;
4135 unsigned long a_off;
4137 GET_DATA (offset, evn, "version need");
4139 ivn.vn_aux = BYTE_GET (evn.vn_aux);
4140 ivn.vn_next = BYTE_GET (evn.vn_next);
4142 a_off = offset + ivn.vn_aux;
4146 GET_DATA (a_off, evna,
4147 "version need aux (2)");
4149 ivna.vna_next = BYTE_GET (evna.vna_next);
4150 ivna.vna_other = BYTE_GET (evna.vna_other);
4152 a_off += ivna.vna_next;
4154 while (ivna.vna_other != data [cnt + j]
4155 && ivna.vna_next != 0);
4157 if (ivna.vna_other == data [cnt + j])
4159 ivna.vna_name = BYTE_GET (evna.vna_name);
4161 name = strtab + ivna.vna_name;
4162 nn += printf ("(%s%-*s",
4164 12 - (int) strlen (name),
4169 offset += ivn.vn_next;
4171 while (ivn.vn_next);
4173 else if (data [cnt + j] != 0x8001)
4175 Elf_Internal_Verdef ivd;
4176 Elf_External_Verdef evd;
4177 unsigned long offset;
4179 offset = version_info
4180 [DT_VERSIONTAGIDX (DT_VERDEF)] - loadaddr;
4184 GET_DATA (offset, evd, "version def");
4186 ivd.vd_next = BYTE_GET (evd.vd_next);
4187 ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
4189 offset += ivd.vd_next;
4191 while (ivd.vd_ndx != (data [cnt + j] & 0x7fff)
4192 && ivd.vd_next != 0);
4194 if (ivd.vd_ndx == (data [cnt + j] & 0x7fff))
4196 Elf_External_Verdaux evda;
4197 Elf_Internal_Verdaux ivda;
4199 ivd.vd_aux = BYTE_GET (evd.vd_aux);
4201 GET_DATA (offset - ivd.vd_next + ivd.vd_aux,
4202 evda, "version def aux");
4204 ivda.vda_name = BYTE_GET (evda.vda_name);
4206 name = strtab + ivda.vda_name;
4207 nn += printf ("(%s%-*s",
4209 12 - (int) strlen (name),
4215 printf ("%*c", 18 - nn, ' ');
4233 printf (_("\nNo version information found in this file.\n"));
4239 get_symbol_binding (binding)
4240 unsigned int binding;
4242 static char buff [32];
4246 case STB_LOCAL: return "LOCAL";
4247 case STB_GLOBAL: return "GLOBAL";
4248 case STB_WEAK: return "WEAK";
4250 if (binding >= STB_LOPROC && binding <= STB_HIPROC)
4251 sprintf (buff, _("<processor specific>: %d"), binding);
4252 else if (binding >= STB_LOOS && binding <= STB_HIOS)
4253 sprintf (buff, _("<OS specific>: %d"), binding);
4255 sprintf (buff, _("<unknown>: %d"), binding);
4261 get_symbol_type (type)
4264 static char buff [32];
4268 case STT_NOTYPE: return "NOTYPE";
4269 case STT_OBJECT: return "OBJECT";
4270 case STT_FUNC: return "FUNC";
4271 case STT_SECTION: return "SECTION";
4272 case STT_FILE: return "FILE";
4273 case STT_COMMON: return "COMMON";
4275 if (type >= STT_LOPROC && type <= STT_HIPROC)
4277 if (elf_header.e_machine == EM_ARM && type == STT_ARM_TFUNC)
4278 return "THUMB_FUNC";
4280 if (elf_header.e_machine == EM_SPARCV9 && type == STT_REGISTER)
4283 if (elf_header.e_machine == EM_PARISC && type == STT_PARISC_MILLI)
4284 return "PARISC_MILLI";
4286 sprintf (buff, _("<processor specific>: %d"), type);
4288 else if (type >= STT_LOOS && type <= STT_HIOS)
4290 if (elf_header.e_machine == EM_PARISC)
4292 if (type == STT_HP_OPAQUE)
4294 if (type == STT_HP_STUB)
4298 sprintf (buff, _("<OS specific>: %d"), type);
4301 sprintf (buff, _("<unknown>: %d"), type);
4307 get_symbol_visibility (visibility)
4308 unsigned int visibility;
4312 case STV_DEFAULT: return "DEFAULT";
4313 case STV_INTERNAL: return "INTERNAL";
4314 case STV_HIDDEN: return "HIDDEN";
4315 case STV_PROTECTED: return "PROTECTED";
4321 get_symbol_index_type (type)
4326 case SHN_UNDEF: return "UND";
4327 case SHN_ABS: return "ABS";
4328 case SHN_COMMON: return "COM";
4330 if (type >= SHN_LOPROC && type <= SHN_HIPROC)
4332 else if (type >= SHN_LORESERVE && type <= SHN_HIRESERVE)
4334 else if (type >= SHN_LOOS && type <= SHN_HIOS)
4338 static char buff [32];
4340 sprintf (buff, "%3d", type);
4347 get_dynamic_data (file, number)
4349 unsigned int number;
4351 unsigned char * e_data;
4354 e_data = (unsigned char *) malloc (number * 4);
4358 error (_("Out of memory\n"));
4362 if (fread (e_data, 4, number, file) != number)
4364 error (_("Unable to read in dynamic data\n"));
4368 i_data = (int *) malloc (number * sizeof (* i_data));
4372 error (_("Out of memory\n"));
4378 i_data [number] = byte_get (e_data + number * 4, 4);
4385 /* Dump the symbol table */
4387 process_symbol_table (file)
4390 Elf32_Internal_Shdr * section;
4391 unsigned char nb [4];
4392 unsigned char nc [4];
4395 int * buckets = NULL;
4396 int * chains = NULL;
4398 if (! do_syms && !do_histogram)
4401 if (dynamic_info[DT_HASH] && ((do_using_dynamic && dynamic_strings != NULL)
4404 if (fseek (file, dynamic_info[DT_HASH] - loadaddr, SEEK_SET))
4406 error (_("Unable to seek to start of dynamic information"));
4410 if (fread (nb, sizeof (nb), 1, file) != 1)
4412 error (_("Failed to read in number of buckets\n"));
4416 if (fread (nc, sizeof (nc), 1, file) != 1)
4418 error (_("Failed to read in number of chains\n"));
4422 nbuckets = byte_get (nb, 4);
4423 nchains = byte_get (nc, 4);
4425 buckets = get_dynamic_data (file, nbuckets);
4426 chains = get_dynamic_data (file, nchains);
4428 if (buckets == NULL || chains == NULL)
4433 && dynamic_info[DT_HASH] && do_using_dynamic && dynamic_strings != NULL)
4438 printf (_("\nSymbol table for image:\n"));
4440 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
4442 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
4444 for (hn = 0; hn < nbuckets; hn++)
4449 for (si = buckets [hn]; si < nchains && si > 0; si = chains [si])
4451 Elf_Internal_Sym * psym;
4453 psym = dynamic_symbols + si;
4455 printf (" %3d %3d: ", si, hn);
4456 print_vma (psym->st_value, LONG_HEX);
4458 print_vma (psym->st_size, DEC_5);
4460 printf (" %6s", get_symbol_type (ELF_ST_TYPE (psym->st_info)));
4461 printf (" %6s", get_symbol_binding (ELF_ST_BIND (psym->st_info)));
4462 printf (" %3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym->st_other)));
4463 printf (" %3.3s", get_symbol_index_type (psym->st_shndx));
4464 printf (" %s\n", dynamic_strings + psym->st_name);
4468 else if (do_syms && !do_using_dynamic)
4472 for (i = 0, section = section_headers;
4473 i < elf_header.e_shnum;
4478 Elf_Internal_Sym * symtab;
4479 Elf_Internal_Sym * psym;
4482 if ( section->sh_type != SHT_SYMTAB
4483 && section->sh_type != SHT_DYNSYM)
4486 printf (_("\nSymbol table '%s' contains %lu entries:\n"),
4487 SECTION_NAME (section),
4488 (unsigned long) (section->sh_size / section->sh_entsize));
4490 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
4492 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
4494 symtab = GET_ELF_SYMBOLS (file, section->sh_offset,
4495 section->sh_size / section->sh_entsize);
4499 if (section->sh_link == elf_header.e_shstrndx)
4500 strtab = string_table;
4503 Elf32_Internal_Shdr * string_sec;
4505 string_sec = section_headers + section->sh_link;
4507 GET_DATA_ALLOC (string_sec->sh_offset, string_sec->sh_size,
4508 strtab, char *, "string table");
4511 for (si = 0, psym = symtab;
4512 si < section->sh_size / section->sh_entsize;
4515 printf ("%6d: ", si);
4516 print_vma (psym->st_value, LONG_HEX);
4518 print_vma (psym->st_size, DEC_5);
4519 printf (" %-7s", get_symbol_type (ELF_ST_TYPE (psym->st_info)));
4520 printf (" %-6s", get_symbol_binding (ELF_ST_BIND (psym->st_info)));
4521 printf (" %-3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym->st_other)));
4522 printf (" %4s", get_symbol_index_type (psym->st_shndx));
4523 printf (" %s", strtab + psym->st_name);
4525 if (section->sh_type == SHT_DYNSYM &&
4526 version_info [DT_VERSIONTAGIDX (DT_VERSYM)] != 0)
4528 unsigned char data[2];
4529 unsigned short vers_data;
4530 unsigned long offset;
4534 offset = version_info [DT_VERSIONTAGIDX (DT_VERSYM)]
4537 GET_DATA (offset + si * sizeof (vers_data), data,
4540 vers_data = byte_get (data, 2);
4542 is_nobits = psym->st_shndx < SHN_LORESERVE ?
4543 (section_headers [psym->st_shndx].sh_type == SHT_NOBITS)
4546 check_def = (psym->st_shndx != SHN_UNDEF);
4548 if ((vers_data & 0x8000) || vers_data > 1)
4550 if (is_nobits || ! check_def)
4552 Elf_External_Verneed evn;
4553 Elf_Internal_Verneed ivn;
4554 Elf_Internal_Vernaux ivna;
4556 /* We must test both. */
4557 offset = version_info
4558 [DT_VERSIONTAGIDX (DT_VERNEED)] - loadaddr;
4562 unsigned long vna_off;
4564 GET_DATA (offset, evn, "version need");
4566 ivn.vn_aux = BYTE_GET (evn.vn_aux);
4567 ivn.vn_next = BYTE_GET (evn.vn_next);
4569 vna_off = offset + ivn.vn_aux;
4573 Elf_External_Vernaux evna;
4575 GET_DATA (vna_off, evna,
4576 "version need aux (3)");
4578 ivna.vna_other = BYTE_GET (evna.vna_other);
4579 ivna.vna_next = BYTE_GET (evna.vna_next);
4580 ivna.vna_name = BYTE_GET (evna.vna_name);
4582 vna_off += ivna.vna_next;
4584 while (ivna.vna_other != vers_data
4585 && ivna.vna_next != 0);
4587 if (ivna.vna_other == vers_data)
4590 offset += ivn.vn_next;
4592 while (ivn.vn_next != 0);
4594 if (ivna.vna_other == vers_data)
4597 strtab + ivna.vna_name, ivna.vna_other);
4600 else if (! is_nobits)
4601 error (_("bad dynamic symbol"));
4608 if (vers_data != 0x8001)
4610 Elf_Internal_Verdef ivd;
4611 Elf_Internal_Verdaux ivda;
4612 Elf_External_Verdaux evda;
4613 unsigned long offset;
4616 version_info [DT_VERSIONTAGIDX (DT_VERDEF)]
4621 Elf_External_Verdef evd;
4623 GET_DATA (offset, evd, "version def");
4625 ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
4626 ivd.vd_aux = BYTE_GET (evd.vd_aux);
4627 ivd.vd_next = BYTE_GET (evd.vd_next);
4629 offset += ivd.vd_next;
4631 while (ivd.vd_ndx != (vers_data & 0x7fff)
4632 && ivd.vd_next != 0);
4634 offset -= ivd.vd_next;
4635 offset += ivd.vd_aux;
4637 GET_DATA (offset, evda, "version def aux");
4639 ivda.vda_name = BYTE_GET (evda.vda_name);
4641 if (psym->st_name != ivda.vda_name)
4642 printf ((vers_data & 0x8000)
4644 strtab + ivda.vda_name);
4654 if (strtab != string_table)
4660 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
4662 if (do_histogram && buckets != NULL)
4669 int nzero_counts = 0;
4672 printf (_("\nHistogram for bucket list length (total of %d buckets):\n"),
4674 printf (_(" Length Number %% of total Coverage\n"));
4676 lengths = (int *) calloc (nbuckets, sizeof (int));
4677 if (lengths == NULL)
4679 error (_("Out of memory"));
4682 for (hn = 0; hn < nbuckets; ++hn)
4687 for (si = buckets[hn]; si > 0 && si < nchains; si = chains[si])
4690 if (maxlength < ++lengths[hn])
4695 counts = (int *) calloc (maxlength + 1, sizeof (int));
4698 error (_("Out of memory"));
4702 for (hn = 0; hn < nbuckets; ++hn)
4703 ++ counts [lengths [hn]];
4707 printf (" 0 %-10d (%5.1f%%)\n",
4708 counts[0], (counts[0] * 100.0) / nbuckets);
4709 for (si = 1; si <= maxlength; ++si)
4711 nzero_counts += counts[si] * si;
4712 printf ("%7d %-10d (%5.1f%%) %5.1f%%\n",
4713 si, counts[si], (counts[si] * 100.0) / nbuckets,
4714 (nzero_counts * 100.0) / nsyms);
4722 if (buckets != NULL)
4732 process_syminfo (file)
4733 FILE * file ATTRIBUTE_UNUSED;
4737 if (dynamic_syminfo == NULL
4739 /* No syminfo, this is ok. */
4742 /* There better should be a dynamic symbol section. */
4743 if (dynamic_symbols == NULL || dynamic_strings == NULL)
4747 printf (_("\nDynamic info segment at offset 0x%lx contains %d entries:\n"),
4748 dynamic_syminfo_offset, dynamic_syminfo_nent);
4750 printf (_(" Num: Name BoundTo Flags\n"));
4751 for (i = 0; i < dynamic_syminfo_nent; ++i)
4753 unsigned short int flags = dynamic_syminfo[i].si_flags;
4755 printf ("%4d: %-30s ", i,
4756 dynamic_strings + dynamic_symbols[i].st_name);
4758 switch (dynamic_syminfo[i].si_boundto)
4760 case SYMINFO_BT_SELF:
4761 fputs ("SELF ", stdout);
4763 case SYMINFO_BT_PARENT:
4764 fputs ("PARENT ", stdout);
4767 if (dynamic_syminfo[i].si_boundto > 0
4768 && dynamic_syminfo[i].si_boundto < dynamic_size)
4771 + dynamic_segment[dynamic_syminfo[i].si_boundto].d_un.d_val);
4773 printf ("%-10d ", dynamic_syminfo[i].si_boundto);
4777 if (flags & SYMINFO_FLG_DIRECT)
4779 if (flags & SYMINFO_FLG_PASSTHRU)
4780 printf (" PASSTHRU");
4781 if (flags & SYMINFO_FLG_COPY)
4783 if (flags & SYMINFO_FLG_LAZYLOAD)
4784 printf (" LAZYLOAD");
4792 #ifdef SUPPORT_DISASSEMBLY
4794 disassemble_section (section, file)
4795 Elf32_Internal_Shdr * section;
4798 printf (_("\nAssembly dump of section %s\n"),
4799 SECTION_NAME (section));
4801 /* XXX -- to be done --- XXX */
4808 dump_section (section, file)
4809 Elf32_Internal_Shdr * section;
4812 bfd_size_type bytes;
4814 unsigned char * data;
4815 unsigned char * start;
4817 bytes = section->sh_size;
4821 printf (_("\nSection '%s' has no data to dump.\n"),
4822 SECTION_NAME (section));
4826 printf (_("\nHex dump of section '%s':\n"), SECTION_NAME (section));
4828 addr = section->sh_addr;
4830 GET_DATA_ALLOC (section->sh_offset, bytes, start, unsigned char *,
4841 lbytes = (bytes > 16 ? 16 : bytes);
4843 printf (" 0x%8.8lx ", (unsigned long) addr);
4845 switch (elf_header.e_ident [EI_DATA])
4849 for (j = 15; j >= 0; j --)
4852 printf ("%2.2x", data [j]);
4862 for (j = 0; j < 16; j++)
4865 printf ("%2.2x", data [j]);
4875 for (j = 0; j < lbytes; j++)
4878 if (k >= ' ' && k < 0x80)
4897 static unsigned long int
4898 read_leb128 (data, length_return, sign)
4899 unsigned char * data;
4900 int * length_return;
4903 unsigned long int result = 0;
4904 unsigned int num_read = 0;
4913 result |= (byte & 0x7f) << shift;
4918 while (byte & 0x80);
4920 if (length_return != NULL)
4921 * length_return = num_read;
4923 if (sign && (shift < 32) && (byte & 0x40))
4924 result |= -1 << shift;
4929 typedef struct State_Machine_Registers
4931 unsigned long address;
4934 unsigned int column;
4938 /* This variable hold the number of the last entry seen
4939 in the File Table. */
4940 unsigned int last_file_entry;
4943 static SMR state_machine_regs;
4946 reset_state_machine (is_stmt)
4949 state_machine_regs.address = 0;
4950 state_machine_regs.file = 1;
4951 state_machine_regs.line = 1;
4952 state_machine_regs.column = 0;
4953 state_machine_regs.is_stmt = is_stmt;
4954 state_machine_regs.basic_block = 0;
4955 state_machine_regs.end_sequence = 0;
4956 state_machine_regs.last_file_entry = 0;
4959 /* Handled an extend line op. Returns true if this is the end
4962 process_extended_line_op (data, is_stmt, pointer_size)
4963 unsigned char * data;
4967 unsigned char op_code;
4970 unsigned char * name;
4973 len = read_leb128 (data, & bytes_read, 0);
4978 warn (_("badly formed extended line op encountered!"));
4983 op_code = * data ++;
4985 printf (_(" Extended opcode %d: "), op_code);
4989 case DW_LNE_end_sequence:
4990 printf (_("End of Sequence\n\n"));
4991 reset_state_machine (is_stmt);
4994 case DW_LNE_set_address:
4995 adr = byte_get (data, pointer_size);
4996 printf (_("set Address to 0x%lx\n"), adr);
4997 state_machine_regs.address = adr;
5000 case DW_LNE_define_file:
5001 printf (_(" define new File Table entry\n"));
5002 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
5004 printf (_(" %d\t"), ++ state_machine_regs.last_file_entry);
5006 data += strlen ((char *) data) + 1;
5007 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
5009 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
5011 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
5012 printf (_("%s\n\n"), name);
5016 printf (_("UNKNOWN: length %d\n"), len - bytes_read);
5023 /* Size of pointers in the .debug_line section. This information is not
5024 really present in that section. It's obtained before dumping the debug
5025 sections by doing some pre-scan of the .debug_info section. */
5026 static int debug_line_pointer_size = 4;
5029 display_debug_lines (section, start, file)
5030 Elf32_Internal_Shdr * section;
5031 unsigned char * start;
5032 FILE * file ATTRIBUTE_UNUSED;
5034 DWARF2_External_LineInfo * external;
5035 DWARF2_Internal_LineInfo info;
5036 unsigned char * standard_opcodes;
5037 unsigned char * data = start;
5038 unsigned char * end = start + section->sh_size;
5039 unsigned char * end_of_sequence;
5042 printf (_("\nDump of debug contents of section %s:\n\n"),
5043 SECTION_NAME (section));
5047 external = (DWARF2_External_LineInfo *) data;
5049 /* Check the length of the block. */
5050 info.li_length = BYTE_GET (external->li_length);
5051 if (info.li_length + sizeof (external->li_length) > section->sh_size)
5054 (_("The line info appears to be corrupt - the section is too small\n"));
5058 /* Check its version number. */
5059 info.li_version = BYTE_GET (external->li_version);
5060 if (info.li_version != 2)
5062 warn (_("Only DWARF version 2 line info is currently supported.\n"));
5066 info.li_prologue_length = BYTE_GET (external->li_prologue_length);
5067 info.li_min_insn_length = BYTE_GET (external->li_min_insn_length);
5068 info.li_default_is_stmt = BYTE_GET (external->li_default_is_stmt);
5069 info.li_line_base = BYTE_GET (external->li_line_base);
5070 info.li_line_range = BYTE_GET (external->li_line_range);
5071 info.li_opcode_base = BYTE_GET (external->li_opcode_base);
5073 /* Sign extend the line base field. */
5074 info.li_line_base <<= 24;
5075 info.li_line_base >>= 24;
5077 printf (_(" Length: %ld\n"), info.li_length);
5078 printf (_(" DWARF Version: %d\n"), info.li_version);
5079 printf (_(" Prolgue Length: %d\n"), info.li_prologue_length);
5080 printf (_(" Minimum Instruction Length: %d\n"), info.li_min_insn_length);
5081 printf (_(" Initial value of 'is_stmt': %d\n"), info.li_default_is_stmt);
5082 printf (_(" Line Base: %d\n"), info.li_line_base);
5083 printf (_(" Line Range: %d\n"), info.li_line_range);
5084 printf (_(" Opcode Base: %d\n"), info.li_opcode_base);
5086 end_of_sequence = data + info.li_length + sizeof (external->li_length);
5088 reset_state_machine (info.li_default_is_stmt);
5090 /* Display the contents of the Opcodes table. */
5091 standard_opcodes = data + sizeof (* external);
5093 printf (_("\n Opcodes:\n"));
5095 for (i = 1; i < info.li_opcode_base; i++)
5096 printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]);
5098 /* Display the contents of the Directory table. */
5099 data = standard_opcodes + info.li_opcode_base - 1;
5102 printf (_("\n The Directory Table is empty.\n"));
5105 printf (_("\n The Directory Table:\n"));
5109 printf (_(" %s\n"), data);
5111 data += strlen ((char *) data) + 1;
5115 /* Skip the NUL at the end of the table. */
5118 /* Display the contents of the File Name table. */
5120 printf (_("\n The File Name Table is empty.\n"));
5123 printf (_("\n The File Name Table:\n"));
5124 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
5128 unsigned char * name;
5131 printf (_(" %d\t"), ++ state_machine_regs.last_file_entry);
5134 data += strlen ((char *) data) + 1;
5136 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
5138 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
5140 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
5142 printf (_("%s\n"), name);
5146 /* Skip the NUL at the end of the table. */
5149 /* Now display the statements. */
5150 printf (_("\n Line Number Statements:\n"));
5153 while (data < end_of_sequence)
5155 unsigned char op_code;
5159 op_code = * data ++;
5163 case DW_LNS_extended_op:
5164 data += process_extended_line_op (data, info.li_default_is_stmt,
5165 debug_line_pointer_size);
5169 printf (_(" Copy\n"));
5172 case DW_LNS_advance_pc:
5173 adv = info.li_min_insn_length * read_leb128 (data, & bytes_read, 0);
5175 state_machine_regs.address += adv;
5176 printf (_(" Advance PC by %d to %lx\n"), adv,
5177 state_machine_regs.address);
5180 case DW_LNS_advance_line:
5181 adv = read_leb128 (data, & bytes_read, 1);
5183 state_machine_regs.line += adv;
5184 printf (_(" Advance Line by %d to %d\n"), adv,
5185 state_machine_regs.line);
5188 case DW_LNS_set_file:
5189 adv = read_leb128 (data, & bytes_read, 0);
5191 printf (_(" Set File Name to entry %d in the File Name Table\n"),
5193 state_machine_regs.file = adv;
5196 case DW_LNS_set_column:
5197 adv = read_leb128 (data, & bytes_read, 0);
5199 printf (_(" Set column to %d\n"), adv);
5200 state_machine_regs.column = adv;
5203 case DW_LNS_negate_stmt:
5204 adv = state_machine_regs.is_stmt;
5206 printf (_(" Set is_stmt to %d\n"), adv);
5207 state_machine_regs.is_stmt = adv;
5210 case DW_LNS_set_basic_block:
5211 printf (_(" Set basic block\n"));
5212 state_machine_regs.basic_block = 1;
5215 case DW_LNS_const_add_pc:
5216 adv = (((255 - info.li_opcode_base) / info.li_line_range)
5217 * info.li_min_insn_length);
5218 state_machine_regs.address += adv;
5219 printf (_(" Advance PC by constant %d to 0x%lx\n"), adv,
5220 state_machine_regs.address);
5223 case DW_LNS_fixed_advance_pc:
5224 adv = byte_get (data, 2);
5226 state_machine_regs.address += adv;
5227 printf (_(" Advance PC by fixed size amount %d to 0x%lx\n"),
5228 adv, state_machine_regs.address);
5232 op_code -= info.li_opcode_base;
5233 adv = (op_code / info.li_line_range) * info.li_min_insn_length;
5234 state_machine_regs.address += adv;
5235 printf (_(" Special opcode %d: advance Address by %d to 0x%lx"),
5236 op_code, adv, state_machine_regs.address);
5237 adv = (op_code % info.li_line_range) + info.li_line_base;
5238 state_machine_regs.line += adv;
5239 printf (_(" and Line by %d to %d\n"),
5240 adv, state_machine_regs.line);
5251 display_debug_pubnames (section, start, file)
5252 Elf32_Internal_Shdr * section;
5253 unsigned char * start;
5254 FILE * file ATTRIBUTE_UNUSED;
5256 DWARF2_External_PubNames * external;
5257 DWARF2_Internal_PubNames pubnames;
5258 unsigned char * end;
5260 end = start + section->sh_size;
5262 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section));
5266 unsigned char * data;
5267 unsigned long offset;
5269 external = (DWARF2_External_PubNames *) start;
5271 pubnames.pn_length = BYTE_GET (external->pn_length);
5272 pubnames.pn_version = BYTE_GET (external->pn_version);
5273 pubnames.pn_offset = BYTE_GET (external->pn_offset);
5274 pubnames.pn_size = BYTE_GET (external->pn_size);
5276 data = start + sizeof (* external);
5277 start += pubnames.pn_length + sizeof (external->pn_length);
5279 if (pubnames.pn_version != 2)
5281 static int warned = 0;
5285 warn (_("Only DWARF 2 pubnames are currently supported\n"));
5292 printf (_(" Length: %ld\n"),
5293 pubnames.pn_length);
5294 printf (_(" Version: %d\n"),
5295 pubnames.pn_version);
5296 printf (_(" Offset into .debug_info section: %ld\n"),
5297 pubnames.pn_offset);
5298 printf (_(" Size of area in .debug_info section: %ld\n"),
5301 printf (_("\n Offset\tName\n"));
5305 offset = byte_get (data, 4);
5310 printf (" %ld\t\t%s\n", offset, data);
5311 data += strlen ((char *) data) + 1;
5314 while (offset != 0);
5327 case DW_TAG_padding: return "DW_TAG_padding";
5328 case DW_TAG_array_type: return "DW_TAG_array_type";
5329 case DW_TAG_class_type: return "DW_TAG_class_type";
5330 case DW_TAG_entry_point: return "DW_TAG_entry_point";
5331 case DW_TAG_enumeration_type: return "DW_TAG_enumeration_type";
5332 case DW_TAG_formal_parameter: return "DW_TAG_formal_parameter";
5333 case DW_TAG_imported_declaration: return "DW_TAG_imported_declaration";
5334 case DW_TAG_label: return "DW_TAG_label";
5335 case DW_TAG_lexical_block: return "DW_TAG_lexical_block";
5336 case DW_TAG_member: return "DW_TAG_member";
5337 case DW_TAG_pointer_type: return "DW_TAG_pointer_type";
5338 case DW_TAG_reference_type: return "DW_TAG_reference_type";
5339 case DW_TAG_compile_unit: return "DW_TAG_compile_unit";
5340 case DW_TAG_string_type: return "DW_TAG_string_type";
5341 case DW_TAG_structure_type: return "DW_TAG_structure_type";
5342 case DW_TAG_subroutine_type: return "DW_TAG_subroutine_type";
5343 case DW_TAG_typedef: return "DW_TAG_typedef";
5344 case DW_TAG_union_type: return "DW_TAG_union_type";
5345 case DW_TAG_unspecified_parameters: return "DW_TAG_unspecified_parameters";
5346 case DW_TAG_variant: return "DW_TAG_variant";
5347 case DW_TAG_common_block: return "DW_TAG_common_block";
5348 case DW_TAG_common_inclusion: return "DW_TAG_common_inclusion";
5349 case DW_TAG_inheritance: return "DW_TAG_inheritance";
5350 case DW_TAG_inlined_subroutine: return "DW_TAG_inlined_subroutine";
5351 case DW_TAG_module: return "DW_TAG_module";
5352 case DW_TAG_ptr_to_member_type: return "DW_TAG_ptr_to_member_type";
5353 case DW_TAG_set_type: return "DW_TAG_set_type";
5354 case DW_TAG_subrange_type: return "DW_TAG_subrange_type";
5355 case DW_TAG_with_stmt: return "DW_TAG_with_stmt";
5356 case DW_TAG_access_declaration: return "DW_TAG_access_declaration";
5357 case DW_TAG_base_type: return "DW_TAG_base_type";
5358 case DW_TAG_catch_block: return "DW_TAG_catch_block";
5359 case DW_TAG_const_type: return "DW_TAG_const_type";
5360 case DW_TAG_constant: return "DW_TAG_constant";
5361 case DW_TAG_enumerator: return "DW_TAG_enumerator";
5362 case DW_TAG_file_type: return "DW_TAG_file_type";
5363 case DW_TAG_friend: return "DW_TAG_friend";
5364 case DW_TAG_namelist: return "DW_TAG_namelist";
5365 case DW_TAG_namelist_item: return "DW_TAG_namelist_item";
5366 case DW_TAG_packed_type: return "DW_TAG_packed_type";
5367 case DW_TAG_subprogram: return "DW_TAG_subprogram";
5368 case DW_TAG_template_type_param: return "DW_TAG_template_type_param";
5369 case DW_TAG_template_value_param: return "DW_TAG_template_value_param";
5370 case DW_TAG_thrown_type: return "DW_TAG_thrown_type";
5371 case DW_TAG_try_block: return "DW_TAG_try_block";
5372 case DW_TAG_variant_part: return "DW_TAG_variant_part";
5373 case DW_TAG_variable: return "DW_TAG_variable";
5374 case DW_TAG_volatile_type: return "DW_TAG_volatile_type";
5375 case DW_TAG_MIPS_loop: return "DW_TAG_MIPS_loop";
5376 case DW_TAG_format_label: return "DW_TAG_format_label";
5377 case DW_TAG_function_template: return "DW_TAG_function_template";
5378 case DW_TAG_class_template: return "DW_TAG_class_template";
5381 static char buffer [100];
5383 sprintf (buffer, _("Unknown TAG value: %lx"), tag);
5390 get_AT_name (attribute)
5391 unsigned long attribute;
5395 case DW_AT_sibling: return "DW_AT_sibling";
5396 case DW_AT_location: return "DW_AT_location";
5397 case DW_AT_name: return "DW_AT_name";
5398 case DW_AT_ordering: return "DW_AT_ordering";
5399 case DW_AT_subscr_data: return "DW_AT_subscr_data";
5400 case DW_AT_byte_size: return "DW_AT_byte_size";
5401 case DW_AT_bit_offset: return "DW_AT_bit_offset";
5402 case DW_AT_bit_size: return "DW_AT_bit_size";
5403 case DW_AT_element_list: return "DW_AT_element_list";
5404 case DW_AT_stmt_list: return "DW_AT_stmt_list";
5405 case DW_AT_low_pc: return "DW_AT_low_pc";
5406 case DW_AT_high_pc: return "DW_AT_high_pc";
5407 case DW_AT_language: return "DW_AT_language";
5408 case DW_AT_member: return "DW_AT_member";
5409 case DW_AT_discr: return "DW_AT_discr";
5410 case DW_AT_discr_value: return "DW_AT_discr_value";
5411 case DW_AT_visibility: return "DW_AT_visibility";
5412 case DW_AT_import: return "DW_AT_import";
5413 case DW_AT_string_length: return "DW_AT_string_length";
5414 case DW_AT_common_reference: return "DW_AT_common_reference";
5415 case DW_AT_comp_dir: return "DW_AT_comp_dir";
5416 case DW_AT_const_value: return "DW_AT_const_value";
5417 case DW_AT_containing_type: return "DW_AT_containing_type";
5418 case DW_AT_default_value: return "DW_AT_default_value";
5419 case DW_AT_inline: return "DW_AT_inline";
5420 case DW_AT_is_optional: return "DW_AT_is_optional";
5421 case DW_AT_lower_bound: return "DW_AT_lower_bound";
5422 case DW_AT_producer: return "DW_AT_producer";
5423 case DW_AT_prototyped: return "DW_AT_prototyped";
5424 case DW_AT_return_addr: return "DW_AT_return_addr";
5425 case DW_AT_start_scope: return "DW_AT_start_scope";
5426 case DW_AT_stride_size: return "DW_AT_stride_size";
5427 case DW_AT_upper_bound: return "DW_AT_upper_bound";
5428 case DW_AT_abstract_origin: return "DW_AT_abstract_origin";
5429 case DW_AT_accessibility: return "DW_AT_accessibility";
5430 case DW_AT_address_class: return "DW_AT_address_class";
5431 case DW_AT_artificial: return "DW_AT_artificial";
5432 case DW_AT_base_types: return "DW_AT_base_types";
5433 case DW_AT_calling_convention: return "DW_AT_calling_convention";
5434 case DW_AT_count: return "DW_AT_count";
5435 case DW_AT_data_member_location: return "DW_AT_data_member_location";
5436 case DW_AT_decl_column: return "DW_AT_decl_column";
5437 case DW_AT_decl_file: return "DW_AT_decl_file";
5438 case DW_AT_decl_line: return "DW_AT_decl_line";
5439 case DW_AT_declaration: return "DW_AT_declaration";
5440 case DW_AT_discr_list: return "DW_AT_discr_list";
5441 case DW_AT_encoding: return "DW_AT_encoding";
5442 case DW_AT_external: return "DW_AT_external";
5443 case DW_AT_frame_base: return "DW_AT_frame_base";
5444 case DW_AT_friend: return "DW_AT_friend";
5445 case DW_AT_identifier_case: return "DW_AT_identifier_case";
5446 case DW_AT_macro_info: return "DW_AT_macro_info";
5447 case DW_AT_namelist_items: return "DW_AT_namelist_items";
5448 case DW_AT_priority: return "DW_AT_priority";
5449 case DW_AT_segment: return "DW_AT_segment";
5450 case DW_AT_specification: return "DW_AT_specification";
5451 case DW_AT_static_link: return "DW_AT_static_link";
5452 case DW_AT_type: return "DW_AT_type";
5453 case DW_AT_use_location: return "DW_AT_use_location";
5454 case DW_AT_variable_parameter: return "DW_AT_variable_parameter";
5455 case DW_AT_virtuality: return "DW_AT_virtuality";
5456 case DW_AT_vtable_elem_location: return "DW_AT_vtable_elem_location";
5457 case DW_AT_MIPS_fde: return "DW_AT_MIPS_fde";
5458 case DW_AT_MIPS_loop_begin: return "DW_AT_MIPS_loop_begin";
5459 case DW_AT_MIPS_tail_loop_begin: return "DW_AT_MIPS_tail_loop_begin";
5460 case DW_AT_MIPS_epilog_begin: return "DW_AT_MIPS_epilog_begin";
5461 case DW_AT_MIPS_loop_unroll_factor: return "DW_AT_MIPS_loop_unroll_factor";
5462 case DW_AT_MIPS_software_pipeline_depth: return "DW_AT_MIPS_software_pipeline_depth";
5463 case DW_AT_MIPS_linkage_name: return "DW_AT_MIPS_linkage_name";
5464 case DW_AT_MIPS_stride: return "DW_AT_MIPS_stride";
5465 case DW_AT_MIPS_abstract_name: return "DW_AT_MIPS_abstract_name";
5466 case DW_AT_MIPS_clone_origin: return "DW_AT_MIPS_clone_origin";
5467 case DW_AT_MIPS_has_inlines: return "DW_AT_MIPS_has_inlines";
5468 case DW_AT_sf_names: return "DW_AT_sf_names";
5469 case DW_AT_src_info: return "DW_AT_src_info";
5470 case DW_AT_mac_info: return "DW_AT_mac_info";
5471 case DW_AT_src_coords: return "DW_AT_src_coords";
5472 case DW_AT_body_begin: return "DW_AT_body_begin";
5473 case DW_AT_body_end: return "DW_AT_body_end";
5476 static char buffer [100];
5478 sprintf (buffer, _("Unknown AT value: %lx"), attribute);
5485 get_FORM_name (form)
5490 case DW_FORM_addr: return "DW_FORM_addr";
5491 case DW_FORM_block2: return "DW_FORM_block2";
5492 case DW_FORM_block4: return "DW_FORM_block4";
5493 case DW_FORM_data2: return "DW_FORM_data2";
5494 case DW_FORM_data4: return "DW_FORM_data4";
5495 case DW_FORM_data8: return "DW_FORM_data8";
5496 case DW_FORM_string: return "DW_FORM_string";
5497 case DW_FORM_block: return "DW_FORM_block";
5498 case DW_FORM_block1: return "DW_FORM_block1";
5499 case DW_FORM_data1: return "DW_FORM_data1";
5500 case DW_FORM_flag: return "DW_FORM_flag";
5501 case DW_FORM_sdata: return "DW_FORM_sdata";
5502 case DW_FORM_strp: return "DW_FORM_strp";
5503 case DW_FORM_udata: return "DW_FORM_udata";
5504 case DW_FORM_ref_addr: return "DW_FORM_ref_addr";
5505 case DW_FORM_ref1: return "DW_FORM_ref1";
5506 case DW_FORM_ref2: return "DW_FORM_ref2";
5507 case DW_FORM_ref4: return "DW_FORM_ref4";
5508 case DW_FORM_ref8: return "DW_FORM_ref8";
5509 case DW_FORM_ref_udata: return "DW_FORM_ref_udata";
5510 case DW_FORM_indirect: return "DW_FORM_indirect";
5513 static char buffer [100];
5515 sprintf (buffer, _("Unknown FORM value: %lx"), form);
5521 /* FIXME: There are better and more effiecint ways to handle
5522 these structures. For now though, I just want something that
5523 is simple to implement. */
5524 typedef struct abbrev_attr
5526 unsigned long attribute;
5528 struct abbrev_attr * next;
5532 typedef struct abbrev_entry
5534 unsigned long entry;
5537 struct abbrev_attr * first_attr;
5538 struct abbrev_attr * last_attr;
5539 struct abbrev_entry * next;
5543 static abbrev_entry * first_abbrev = NULL;
5544 static abbrev_entry * last_abbrev = NULL;
5547 free_abbrevs PARAMS ((void))
5549 abbrev_entry * abbrev;
5551 for (abbrev = first_abbrev; abbrev;)
5553 abbrev_entry * next = abbrev->next;
5556 for (attr = abbrev->first_attr; attr;)
5558 abbrev_attr * next = attr->next;
5568 last_abbrev = first_abbrev = NULL;
5572 add_abbrev (number, tag, children)
5573 unsigned long number;
5577 abbrev_entry * entry;
5579 entry = (abbrev_entry *) malloc (sizeof (* entry));
5585 entry->entry = number;
5587 entry->children = children;
5588 entry->first_attr = NULL;
5589 entry->last_attr = NULL;
5592 if (first_abbrev == NULL)
5593 first_abbrev = entry;
5595 last_abbrev->next = entry;
5597 last_abbrev = entry;
5601 add_abbrev_attr (attribute, form)
5602 unsigned long attribute;
5607 attr = (abbrev_attr *) malloc (sizeof (* attr));
5613 attr->attribute = attribute;
5617 if (last_abbrev->first_attr == NULL)
5618 last_abbrev->first_attr = attr;
5620 last_abbrev->last_attr->next = attr;
5622 last_abbrev->last_attr = attr;
5625 /* Processes the (partial) contents of a .debug_abbrev section.
5626 Returns NULL if the end of the section was encountered.
5627 Returns the address after the last byte read if the end of
5628 an abbreviation set was found. */
5630 static unsigned char *
5631 process_abbrev_section (start, end)
5632 unsigned char * start;
5633 unsigned char * end;
5635 if (first_abbrev != NULL)
5641 unsigned long entry;
5643 unsigned long attribute;
5646 entry = read_leb128 (start, & bytes_read, 0);
5647 start += bytes_read;
5649 /* A single zero is supposed to end the section according
5650 to the standard. If there's more, then signal that to
5653 return start == end ? NULL : start;
5655 tag = read_leb128 (start, & bytes_read, 0);
5656 start += bytes_read;
5658 children = * start ++;
5660 add_abbrev (entry, tag, children);
5666 attribute = read_leb128 (start, & bytes_read, 0);
5667 start += bytes_read;
5669 form = read_leb128 (start, & bytes_read, 0);
5670 start += bytes_read;
5673 add_abbrev_attr (attribute, form);
5675 while (attribute != 0);
5683 display_debug_abbrev (section, start, file)
5684 Elf32_Internal_Shdr * section;
5685 unsigned char * start;
5686 FILE * file ATTRIBUTE_UNUSED;
5688 abbrev_entry * entry;
5689 unsigned char * end = start + section->sh_size;
5691 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section));
5695 start = process_abbrev_section (start, end);
5697 printf (_(" Number TAG\n"));
5699 for (entry = first_abbrev; entry; entry = entry->next)
5703 printf (_(" %ld %s [%s]\n"),
5705 get_TAG_name (entry->tag),
5706 entry->children ? _("has children") : _("no children"));
5708 for (attr = entry->first_attr; attr; attr = attr->next)
5710 printf (_(" %-18s %s\n"),
5711 get_AT_name (attr->attribute),
5712 get_FORM_name (attr->form));
5724 static unsigned char *
5725 display_block (data, length)
5726 unsigned char * data;
5727 unsigned long length;
5729 printf (_(" %lu byte block: "), length);
5732 printf ("%lx ", (unsigned long) byte_get (data ++, 1));
5738 decode_location_expression (data, pointer_size, length)
5739 unsigned char * data;
5740 unsigned int pointer_size;
5741 unsigned long length;
5745 unsigned long uvalue;
5746 unsigned char * end = data + length;
5755 printf ("DW_OP_addr: %lx",
5756 (unsigned long) byte_get (data, pointer_size));
5757 data += pointer_size;
5760 printf ("DW_OP_deref");
5763 printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data++, 1));
5766 printf ("DW_OP_const1s: %ld", (long) byte_get (data++, 1));
5769 printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data, 2));
5773 printf ("DW_OP_const2s: %ld", (long) byte_get (data, 2));
5777 printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data, 4));
5781 printf ("DW_OP_const4s: %ld", (long) byte_get (data, 4));
5785 printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data, 4),
5786 (unsigned long) byte_get (data + 4, 4));
5790 printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data, 4),
5791 (long) byte_get (data + 4, 4));
5795 printf ("DW_OP_constu: %lu", read_leb128 (data, &bytes_read, 0));
5799 printf ("DW_OP_consts: %ld", read_leb128 (data, &bytes_read, 1));
5803 printf ("DW_OP_dup");
5806 printf ("DW_OP_drop");
5809 printf ("DW_OP_over");
5812 printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data++, 1));
5815 printf ("DW_OP_swap");
5818 printf ("DW_OP_rot");
5821 printf ("DW_OP_xderef");
5824 printf ("DW_OP_abs");
5827 printf ("DW_OP_and");
5830 printf ("DW_OP_div");
5833 printf ("DW_OP_minus");
5836 printf ("DW_OP_mod");
5839 printf ("DW_OP_mul");
5842 printf ("DW_OP_neg");
5845 printf ("DW_OP_not");
5848 printf ("DW_OP_or");
5851 printf ("DW_OP_plus");
5853 case DW_OP_plus_uconst:
5854 printf ("DW_OP_plus_uconst: %lu",
5855 read_leb128 (data, &bytes_read, 0));
5859 printf ("DW_OP_shl");
5862 printf ("DW_OP_shr");
5865 printf ("DW_OP_shra");
5868 printf ("DW_OP_xor");
5871 printf ("DW_OP_bra: %ld", (long) byte_get (data, 2));
5875 printf ("DW_OP_eq");
5878 printf ("DW_OP_ge");
5881 printf ("DW_OP_gt");
5884 printf ("DW_OP_le");
5887 printf ("DW_OP_lt");
5890 printf ("DW_OP_ne");
5893 printf ("DW_OP_skip: %ld", (long) byte_get (data, 2));
5929 printf ("DW_OP_lit%d", op - DW_OP_lit0);
5964 printf ("DW_OP_reg%d", op - DW_OP_reg0);
5999 printf ("DW_OP_breg%d: %ld", op - DW_OP_breg0,
6000 read_leb128 (data, &bytes_read, 1));
6005 printf ("DW_OP_regx: %lu", read_leb128 (data, &bytes_read, 0));
6009 printf ("DW_OP_fbreg: %ld", read_leb128 (data, &bytes_read, 1));
6013 uvalue = read_leb128 (data, &bytes_read, 0);
6015 printf ("DW_OP_bregx: %lu %ld", uvalue,
6016 read_leb128 (data, &bytes_read, 1));
6020 printf ("DW_OP_piece: %lu", read_leb128 (data, &bytes_read, 0));
6023 case DW_OP_deref_size:
6024 printf ("DW_OP_deref_size: %ld", (long) byte_get (data++, 1));
6026 case DW_OP_xderef_size:
6027 printf ("DW_OP_xderef_size: %ld", (long) byte_get (data++, 1));
6030 printf ("DW_OP_nop");
6034 if (op >= DW_OP_lo_user
6035 && op <= DW_OP_hi_user)
6036 printf (_("(User defined location op)"));
6038 printf (_("(Unknown location op)"));
6039 /* No way to tell where the next op is, so just bail. */
6046 static unsigned char *
6047 read_and_display_attr (attribute, form, data, cu_offset, pointer_size)
6048 unsigned long attribute;
6050 unsigned char * data;
6051 unsigned long cu_offset;
6052 unsigned long pointer_size;
6054 unsigned long uvalue = 0;
6055 unsigned char * block_start = NULL;
6058 printf (" %-18s:", get_AT_name (attribute));
6065 case DW_FORM_ref_addr:
6067 uvalue = byte_get (data, pointer_size);
6068 data += pointer_size;
6074 uvalue = byte_get (data ++, 1);
6079 uvalue = byte_get (data, 2);
6085 uvalue = byte_get (data, 4);
6090 uvalue = read_leb128 (data, & bytes_read, 1);
6094 case DW_FORM_ref_udata:
6096 uvalue = read_leb128 (data, & bytes_read, 0);
6103 case DW_FORM_ref_addr:
6104 printf (" <#%lx>", uvalue);
6110 case DW_FORM_ref_udata:
6111 printf (" <%lx>", uvalue + cu_offset);
6115 printf (" %#lx", uvalue);
6123 printf (" %ld", uvalue);
6128 uvalue = byte_get (data, 4);
6129 printf (" %lx", uvalue);
6130 printf (" %lx", (unsigned long) byte_get (data + 4, 4));
6134 case DW_FORM_string:
6135 printf (" %s", data);
6136 data += strlen ((char *) data) + 1;
6140 uvalue = read_leb128 (data, & bytes_read, 0);
6141 block_start = data + bytes_read;
6142 data = display_block (block_start, uvalue);
6145 case DW_FORM_block1:
6146 uvalue = byte_get (data, 1);
6147 block_start = data + 1;
6148 data = display_block (block_start, uvalue);
6151 case DW_FORM_block2:
6152 uvalue = byte_get (data, 2);
6153 block_start = data + 2;
6154 data = display_block (block_start, uvalue);
6157 case DW_FORM_block4:
6158 uvalue = byte_get (data, 4);
6159 block_start = data + 4;
6160 data = display_block (block_start, uvalue);
6164 case DW_FORM_indirect:
6165 warn (_("Unable to handle FORM: %d"), form);
6169 warn (_("Unrecognised form: %d"), form);
6173 /* For some attributes we can display futher information. */
6182 case DW_INL_not_inlined: printf (_("(not inlined)")); break;
6183 case DW_INL_inlined: printf (_("(inlined)")); break;
6184 case DW_INL_declared_not_inlined: printf (_("(declared as inline but ignored)")); break;
6185 case DW_INL_declared_inlined: printf (_("(declared as inline and inlined)")); break;
6186 default: printf (_(" (Unknown inline attribute value: %lx)"), uvalue); break;
6190 case DW_AT_language:
6193 case DW_LANG_C: printf ("(non-ANSI C)"); break;
6194 case DW_LANG_C89: printf ("(ANSI C)"); break;
6195 case DW_LANG_C_plus_plus: printf ("(C++)"); break;
6196 case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break;
6197 case DW_LANG_Fortran90: printf ("(Fortran 90)"); break;
6198 case DW_LANG_Modula2: printf ("(Modula 2)"); break;
6199 case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break;
6200 case DW_LANG_Ada83: printf ("(Ada)"); break;
6201 case DW_LANG_Cobol74: printf ("(Cobol 74)"); break;
6202 case DW_LANG_Cobol85: printf ("(Cobol 85)"); break;
6203 case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break;
6204 default: printf ("(Unknown: %lx)", uvalue); break;
6208 case DW_AT_encoding:
6211 case DW_ATE_void: printf ("(void)"); break;
6212 case DW_ATE_address: printf ("(machine address)"); break;
6213 case DW_ATE_boolean: printf ("(boolean)"); break;
6214 case DW_ATE_complex_float: printf ("(complex float)"); break;
6215 case DW_ATE_float: printf ("(float)"); break;
6216 case DW_ATE_signed: printf ("(signed)"); break;
6217 case DW_ATE_signed_char: printf ("(signed char)"); break;
6218 case DW_ATE_unsigned: printf ("(unsigned)"); break;
6219 case DW_ATE_unsigned_char: printf ("(unsigned char)"); break;
6221 if (uvalue >= DW_ATE_lo_user
6222 && uvalue <= DW_ATE_hi_user)
6223 printf ("(user defined type)");
6225 printf ("(unknown type)");
6230 case DW_AT_accessibility:
6233 case DW_ACCESS_public: printf ("(public)"); break;
6234 case DW_ACCESS_protected: printf ("(protected)"); break;
6235 case DW_ACCESS_private: printf ("(private)"); break;
6236 default: printf ("(unknown accessibility)"); break;
6240 case DW_AT_visibility:
6243 case DW_VIS_local: printf ("(local)"); break;
6244 case DW_VIS_exported: printf ("(exported)"); break;
6245 case DW_VIS_qualified: printf ("(qualified)"); break;
6246 default: printf ("(unknown visibility)"); break;
6250 case DW_AT_virtuality:
6253 case DW_VIRTUALITY_none: printf ("(none)"); break;
6254 case DW_VIRTUALITY_virtual: printf ("(virtual)"); break;
6255 case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break;
6256 default: printf ("(unknown virtuality)"); break;
6260 case DW_AT_identifier_case:
6263 case DW_ID_case_sensitive: printf ("(case_sensitive)"); break;
6264 case DW_ID_up_case: printf ("(up_case)"); break;
6265 case DW_ID_down_case: printf ("(down_case)"); break;
6266 case DW_ID_case_insensitive: printf ("(case_insensitive)"); break;
6267 default: printf ("(unknown case)"); break;
6271 case DW_AT_calling_convention:
6274 case DW_CC_normal: printf ("(normal)"); break;
6275 case DW_CC_program: printf ("(program)"); break;
6276 case DW_CC_nocall: printf ("(nocall)"); break;
6278 if (uvalue >= DW_CC_lo_user
6279 && uvalue <= DW_CC_hi_user)
6280 printf ("(user defined)");
6282 printf ("(unknown convention)");
6286 case DW_AT_frame_base:
6287 case DW_AT_location:
6288 case DW_AT_data_member_location:
6289 case DW_AT_vtable_elem_location:
6293 decode_location_expression (block_start, pointer_size, uvalue);
6307 display_debug_info (section, start, file)
6308 Elf32_Internal_Shdr * section;
6309 unsigned char * start;
6312 unsigned char * end = start + section->sh_size;
6313 unsigned char * section_begin = start;
6315 printf (_("The section %s contains:\n\n"), SECTION_NAME (section));
6319 DWARF2_External_CompUnit * external;
6320 DWARF2_Internal_CompUnit compunit;
6321 unsigned char * tags;
6324 unsigned long cu_offset;
6326 external = (DWARF2_External_CompUnit *) start;
6328 compunit.cu_length = BYTE_GET (external->cu_length);
6329 compunit.cu_version = BYTE_GET (external->cu_version);
6330 compunit.cu_abbrev_offset = BYTE_GET (external->cu_abbrev_offset);
6331 compunit.cu_pointer_size = BYTE_GET (external->cu_pointer_size);
6333 tags = start + sizeof (* external);
6334 cu_offset = start - section_begin;
6335 start += compunit.cu_length + sizeof (external->cu_length);
6337 printf (_(" Compilation Unit @ %lx:\n"), cu_offset);
6338 printf (_(" Length: %ld\n"), compunit.cu_length);
6339 printf (_(" Version: %d\n"), compunit.cu_version);
6340 printf (_(" Abbrev Offset: %ld\n"), compunit.cu_abbrev_offset);
6341 printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size);
6343 if (compunit.cu_version != 2)
6345 warn (_("Only version 2 DWARF debug information is currently supported.\n"));
6349 if (first_abbrev != NULL)
6352 /* Read in the abbrevs used by this compilation unit. */
6355 Elf32_Internal_Shdr * sec;
6356 unsigned char * begin;
6358 /* Locate the .debug_abbrev section and process it. */
6359 for (i = 0, sec = section_headers;
6360 i < elf_header.e_shnum;
6362 if (strcmp (SECTION_NAME (sec), ".debug_abbrev") == 0)
6365 if (i == -1 || sec->sh_size == 0)
6367 warn (_("Unable to locate .debug_abbrev section!\n"));
6371 GET_DATA_ALLOC (sec->sh_offset, sec->sh_size, begin, unsigned char *,
6372 "debug_abbrev section data");
6374 process_abbrev_section (begin + compunit.cu_abbrev_offset,
6375 begin + sec->sh_size);
6381 while (tags < start)
6384 unsigned long abbrev_number;
6385 abbrev_entry * entry;
6388 abbrev_number = read_leb128 (tags, & bytes_read, 0);
6391 /* A null DIE marks the end of a list of children. */
6392 if (abbrev_number == 0)
6398 /* Scan through the abbreviation list until we reach the
6400 for (entry = first_abbrev;
6401 entry && entry->entry != abbrev_number;
6402 entry = entry->next)
6407 warn (_("Unable to locate entry %lu in the abbreviation table\n"),
6412 printf (_(" <%d><%x>: Abbrev Number: %lu (%s)\n"),
6413 level, tags - section_begin - bytes_read,
6415 get_TAG_name (entry->tag));
6417 for (attr = entry->first_attr; attr; attr = attr->next)
6418 tags = read_and_display_attr (attr->attribute,
6421 compunit.cu_pointer_size);
6423 if (entry->children)
6434 display_debug_aranges (section, start, file)
6435 Elf32_Internal_Shdr * section;
6436 unsigned char * start;
6437 FILE * file ATTRIBUTE_UNUSED;
6439 unsigned char * end = start + section->sh_size;
6441 printf (_("The section %s contains:\n\n"), SECTION_NAME (section));
6445 DWARF2_External_ARange * external;
6446 DWARF2_Internal_ARange arange;
6447 unsigned char * ranges;
6448 unsigned long length;
6449 unsigned long address;
6452 external = (DWARF2_External_ARange *) start;
6454 arange.ar_length = BYTE_GET (external->ar_length);
6455 arange.ar_version = BYTE_GET (external->ar_version);
6456 arange.ar_info_offset = BYTE_GET (external->ar_info_offset);
6457 arange.ar_pointer_size = BYTE_GET (external->ar_pointer_size);
6458 arange.ar_segment_size = BYTE_GET (external->ar_segment_size);
6460 if (arange.ar_version != 2)
6462 warn (_("Only DWARF 2 aranges are currently supported.\n"));
6466 printf (_(" Length: %ld\n"), arange.ar_length);
6467 printf (_(" Version: %d\n"), arange.ar_version);
6468 printf (_(" Offset into .debug_info: %lx\n"), arange.ar_info_offset);
6469 printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
6470 printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
6472 printf (_("\n Address Length\n"));
6474 ranges = start + sizeof (* external);
6476 /* Must pad to an alignment boundary that is twice the pointer size. */
6477 excess = sizeof (* external) % (2 * arange.ar_pointer_size);
6479 ranges += (2 * arange.ar_pointer_size) - excess;
6483 address = byte_get (ranges, arange.ar_pointer_size);
6485 ranges += arange.ar_pointer_size;
6487 length = byte_get (ranges, arange.ar_pointer_size);
6489 ranges += arange.ar_pointer_size;
6491 /* A pair of zeros marks the end of the list. */
6492 if (address == 0 && length == 0)
6495 printf (" %8.8lx %lu\n", address, length);
6498 start += arange.ar_length + sizeof (external->ar_length);
6506 typedef struct Frame_Chunk
6508 struct Frame_Chunk * next;
6509 unsigned char * chunk_start;
6511 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
6512 short int * col_type;
6514 char * augmentation;
6515 unsigned int code_factor;
6516 unsigned int data_factor;
6517 unsigned long pc_begin;
6518 unsigned long pc_range;
6525 /* A marker for a col_type that means this column was never referenced
6526 in the frame info. */
6527 #define DW_CFA_unreferenced (-1)
6530 frame_need_space (fc, reg)
6534 int prev = fc->ncols;
6536 if (reg < fc->ncols)
6539 fc->ncols = reg + 1;
6540 fc->col_type = (short int *) xrealloc (fc->col_type,
6541 fc->ncols * sizeof (short int));
6542 fc->col_offset = (int *) xrealloc (fc->col_offset,
6543 fc->ncols * sizeof (int));
6545 while (prev < fc->ncols)
6547 fc->col_type[prev] = DW_CFA_unreferenced;
6548 fc->col_offset[prev] = 0;
6554 frame_display_row (fc, need_col_headers, max_regs)
6556 int * need_col_headers;
6562 if (* max_regs < fc->ncols)
6563 * max_regs = fc->ncols;
6565 if (* need_col_headers)
6567 * need_col_headers = 0;
6569 printf (" LOC CFA ");
6571 for (r = 0; r < * max_regs; r++)
6572 if (fc->col_type[r] != DW_CFA_unreferenced)
6577 printf ("r%-4d", r);
6583 printf ("%08x ", (unsigned int) fc->pc_begin);
6584 sprintf (tmp, "r%d%+d", fc->cfa_reg, fc->cfa_offset);
6585 printf ("%-8s ", tmp);
6587 for (r = 0; r < fc->ncols; r++)
6589 if (fc->col_type[r] != DW_CFA_unreferenced)
6591 switch (fc->col_type[r])
6593 case DW_CFA_undefined:
6596 case DW_CFA_same_value:
6600 sprintf (tmp, "c%+d", fc->col_offset[r]);
6602 case DW_CFA_register:
6603 sprintf (tmp, "r%d", fc->col_offset[r]);
6606 strcpy (tmp, "n/a");
6609 printf ("%-5s", tmp);
6615 #define GET(N) byte_get (start, N); start += N
6616 #define LEB() read_leb128 (start, & length_return, 0); start += length_return
6617 #define SLEB() read_leb128 (start, & length_return, 1); start += length_return
6620 display_debug_frames (section, start, file)
6621 Elf32_Internal_Shdr * section;
6622 unsigned char * start;
6623 FILE * file ATTRIBUTE_UNUSED;
6625 unsigned char * end = start + section->sh_size;
6626 unsigned char * section_start = start;
6627 Frame_Chunk * chunks = 0;
6628 Frame_Chunk * remembered_state = 0;
6630 int is_eh = (strcmp (SECTION_NAME (section), ".eh_frame") == 0);
6634 printf (_("The section %s contains:\n"), SECTION_NAME (section));
6638 unsigned char * saved_start;
6639 unsigned char * block_end;
6640 unsigned long length;
6641 unsigned long cie_id;
6644 int need_col_headers = 1;
6646 saved_start = start;
6647 length = byte_get (start, 4); start += 4;
6652 block_end = saved_start + length + 4;
6653 cie_id = byte_get (start, 4); start += 4;
6655 printf ("\n%08x %08lx %08lx ", saved_start - section_start, length, cie_id);
6657 if (is_eh ? (cie_id == 0) : (cie_id == DW_CIE_ID))
6659 fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
6660 memset (fc, 0, sizeof (Frame_Chunk));
6664 fc->chunk_start = saved_start;
6666 fc->col_type = (short int *) xmalloc (sizeof (short int));
6667 fc->col_offset = (int *) xmalloc (sizeof (int));
6668 frame_need_space (fc, max_regs-1);
6670 start ++; /* version */
6671 fc->augmentation = start;
6676 start++; /* skip past NUL */
6678 if (fc->augmentation[0] == 'z')
6681 fc->code_factor = LEB ();
6682 fc->data_factor = SLEB ();
6683 fc->ra = byte_get (start, 1); start += 1;
6685 printf ("skipping %d extra bytes\n", xtra);
6688 else if (strcmp (fc->augmentation, "eh") == 0)
6691 fc->code_factor = LEB ();
6692 fc->data_factor = SLEB ();
6693 fc->ra = byte_get (start, 1); start += 1;
6697 fc->code_factor = LEB ();
6698 fc->data_factor = SLEB ();
6699 fc->ra = byte_get (start, 1); start += 1;
6702 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n",
6703 fc->augmentation, fc->code_factor, fc->data_factor, fc->ra);
6705 frame_need_space (fc, fc->ra);
6709 unsigned char * look_for;
6710 static Frame_Chunk fde_fc;
6713 memset (fc, 0, sizeof (Frame_Chunk));
6715 look_for = is_eh ? start-4-cie_id : (unsigned char *) cie_id;
6717 fc->pc_begin = byte_get (start, 4); start += 4;
6718 fc->pc_range = byte_get (start, 4); start += 4;
6720 for (cie=chunks; cie && (cie->chunk_start != look_for); cie = cie->next);
6723 warn ("Invalid CIE pointer %08x in FDE at %08x\n", cie_id, saved_start);
6726 fc->col_type = (short int *) xmalloc (sizeof (short int));
6727 fc->col_offset = (int *) xmalloc (sizeof (int));
6728 frame_need_space (fc, max_regs - 1);
6730 fc->augmentation = "";
6734 fc->ncols = cie->ncols;
6735 fc->col_type = (short int *) xmalloc (fc->ncols * sizeof (short int));
6736 fc->col_offset = (int *) xmalloc (fc->ncols * sizeof (int));
6737 memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int));
6738 memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int));
6739 fc->augmentation = cie->augmentation;
6740 fc->code_factor = cie->code_factor;
6741 fc->data_factor = cie->data_factor;
6742 fc->cfa_reg = cie->cfa_reg;
6743 fc->cfa_offset = cie->cfa_offset;
6745 frame_need_space (fc, max_regs-1);
6748 if (cie->augmentation[0] == 'z')
6750 unsigned long l = LEB ();
6754 printf ("FDE cie=%08x pc=%08lx..%08lx\n",
6755 cie->chunk_start-section_start, fc->pc_begin,
6756 fc->pc_begin + fc->pc_range);
6759 /* At this point, fc is the current chunk, cie (if any) is set, and we're
6760 about to interpret instructions for the chunk. */
6762 /* This exists for readelf maintainers. */
6766 /* Start by making a pass over the chunk, allocating storage
6767 and taking note of what registers are used. */
6768 unsigned char * tmp = start;
6770 while (start < block_end)
6781 /* Warning: if you add any more cases to this switch, be
6782 sure to add them to the corresponding switch below. */
6785 case DW_CFA_advance_loc:
6789 frame_need_space (fc, opa);
6790 fc->col_type[opa] = DW_CFA_undefined;
6792 case DW_CFA_restore:
6793 frame_need_space (fc, opa);
6794 fc->col_type[opa] = DW_CFA_undefined;
6796 case DW_CFA_set_loc:
6797 start += sizeof (vma);
6799 case DW_CFA_advance_loc1:
6802 case DW_CFA_advance_loc2:
6805 case DW_CFA_advance_loc4:
6808 case DW_CFA_offset_extended:
6809 reg = LEB (); LEB ();
6810 frame_need_space (fc, reg);
6811 fc->col_type[reg] = DW_CFA_undefined;
6813 case DW_CFA_restore_extended:
6815 frame_need_space (fc, reg);
6816 fc->col_type[reg] = DW_CFA_undefined;
6818 case DW_CFA_undefined:
6820 frame_need_space (fc, reg);
6821 fc->col_type[reg] = DW_CFA_undefined;
6823 case DW_CFA_same_value:
6825 frame_need_space (fc, reg);
6826 fc->col_type[reg] = DW_CFA_undefined;
6828 case DW_CFA_register:
6829 reg = LEB (); LEB ();
6830 frame_need_space (fc, reg);
6831 fc->col_type[reg] = DW_CFA_undefined;
6833 case DW_CFA_def_cfa:
6836 case DW_CFA_def_cfa_register:
6839 case DW_CFA_def_cfa_offset:
6842 #ifndef DW_CFA_GNU_args_size
6843 #define DW_CFA_GNU_args_size 0x2e
6845 case DW_CFA_GNU_args_size:
6848 #ifndef DW_CFA_GNU_negative_offset_extended
6849 #define DW_CFA_GNU_negative_offset_extended 0x2f
6851 case DW_CFA_GNU_negative_offset_extended:
6852 reg = LEB (); LEB ();
6853 frame_need_space (fc, reg);
6854 fc->col_type[reg] = DW_CFA_undefined;
6863 /* Now we know what registers are used, make a second pass over
6864 the chunk, this time actually printing out the info. */
6866 while (start < block_end)
6869 unsigned long ul, reg, roffs;
6878 /* Warning: if you add any more cases to this switch, be
6879 sure to add them to the corresponding switch above. */
6882 case DW_CFA_advance_loc:
6883 frame_display_row (fc, &need_col_headers, &max_regs);
6885 printf (" DW_CFA_advance_loc: %08x = %08x + %d*%d\n",
6886 fc->pc_begin + opa * fc->code_factor, fc->pc_begin, opa, fc->code_factor);
6888 fc->pc_begin += opa * fc->code_factor;
6894 printf (" DW_CFA_offset: r%d = cfa[%d*%d]\n", opa, roffs, fc->data_factor);
6896 fc->col_type[opa] = DW_CFA_offset;
6897 fc->col_offset[opa] = roffs * fc->data_factor;
6900 case DW_CFA_restore:
6902 printf (" DW_CFA_restore: r%d\n", opa);
6904 fc->col_type[opa] = cie->col_type[opa];
6905 fc->col_offset[opa] = cie->col_offset[opa];
6908 case DW_CFA_set_loc:
6909 frame_display_row (fc, &need_col_headers, &max_regs);
6910 vma = byte_get (start, sizeof (vma)); start += sizeof (vma);
6912 printf (" DW_CFA_set_loc: %08x\n", vma);
6917 case DW_CFA_advance_loc1:
6918 frame_display_row (fc, &need_col_headers, &max_regs);
6919 ofs = byte_get (start, 1); start += 1;
6921 printf (" DW_CFA_advance_loc1: %08x = %08x + %d*%d\n",
6922 fc->pc_begin + ofs * fc->code_factor, fc->pc_begin, ofs, fc->code_factor);
6924 fc->pc_begin += ofs * fc->code_factor;
6927 case DW_CFA_advance_loc2:
6928 frame_display_row (fc, &need_col_headers, &max_regs);
6929 ofs = byte_get (start, 2); start += 2;
6931 printf (" DW_CFA_advance_loc2: %08x = %08x + %d*%d\n",
6932 fc->pc_begin + ofs * fc->code_factor, fc->pc_begin, ofs, fc->code_factor);
6934 fc->pc_begin += ofs * fc->code_factor;
6937 case DW_CFA_advance_loc4:
6938 frame_display_row (fc, &need_col_headers, &max_regs);
6939 ofs = byte_get (start, 4); start += 4;
6941 printf (" DW_CFA_advance_loc4: %08x = %08x + %d*%d\n",
6942 fc->pc_begin + ofs * fc->code_factor, fc->pc_begin, ofs, fc->code_factor);
6944 fc->pc_begin += ofs * fc->code_factor;
6947 case DW_CFA_offset_extended:
6951 printf (" DW_CFA_offset_extended: r%d = cfa[%d*%d]\n", reg, roffs, fc->data_factor);
6953 fc->col_type[reg] = DW_CFA_offset;
6954 fc->col_offset[reg] = roffs * fc->data_factor;
6957 case DW_CFA_restore_extended:
6960 printf (" DW_CFA_restore_extended: r%d\n", reg);
6962 fc->col_type[reg] = cie->col_type[reg];
6963 fc->col_offset[reg] = cie->col_offset[reg];
6966 case DW_CFA_undefined:
6969 printf (" DW_CFA_undefined: r%d\n", reg);
6971 fc->col_type[reg] = DW_CFA_undefined;
6972 fc->col_offset[reg] = 0;
6975 case DW_CFA_same_value:
6978 printf (" DW_CFA_same_value: r%d\n", reg);
6980 fc->col_type[reg] = DW_CFA_same_value;
6981 fc->col_offset[reg] = 0;
6984 case DW_CFA_register:
6988 printf (" DW_CFA_register: r%d\n", reg);
6990 fc->col_type[reg] = DW_CFA_register;
6991 fc->col_offset[reg] = roffs;
6994 case DW_CFA_remember_state:
6996 printf (" DW_CFA_remember_state\n");
6998 rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
6999 rs->ncols = fc->ncols;
7000 rs->col_type = (short int *) xmalloc (rs->ncols * sizeof (short int));
7001 rs->col_offset = (int *) xmalloc (rs->ncols * sizeof (int));
7002 memcpy (rs->col_type, fc->col_type, rs->ncols);
7003 memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (int));
7004 rs->next = remembered_state;
7005 remembered_state = rs;
7008 case DW_CFA_restore_state:
7010 printf (" DW_CFA_restore_state\n");
7012 rs = remembered_state;
7013 remembered_state = rs->next;
7014 frame_need_space (fc, rs->ncols-1);
7015 memcpy (fc->col_type, rs->col_type, rs->ncols);
7016 memcpy (fc->col_offset, rs->col_offset, rs->ncols * sizeof (int));
7017 free (rs->col_type);
7018 free (rs->col_offset);
7022 case DW_CFA_def_cfa:
7023 fc->cfa_reg = LEB ();
7024 fc->cfa_offset = LEB ();
7026 printf (" DW_CFA_def_cfa: reg %d ofs %d\n", fc->cfa_reg, fc->cfa_offset);
7030 case DW_CFA_def_cfa_register:
7031 fc->cfa_reg = LEB ();
7033 printf (" DW_CFA_def_cfa_reg: %d\n", fc->cfa_reg);
7037 case DW_CFA_def_cfa_offset:
7038 fc->cfa_offset = LEB ();
7040 printf (" DW_CFA_def_cfa_offset: %d\n", fc->cfa_offset);
7046 printf (" DW_CFA_nop\n");
7050 #ifndef DW_CFA_GNU_window_save
7051 #define DW_CFA_GNU_window_save 0x2d
7053 case DW_CFA_GNU_window_save:
7055 printf (" DW_CFA_GNU_window_save\n");
7059 #ifndef DW_CFA_GNU_args_size
7060 #define DW_CFA_GNU_args_size 0x2e
7062 case DW_CFA_GNU_args_size:
7065 printf (" DW_CFA_GNU_args_size: %d\n", ul);
7069 #ifndef DW_CFA_GNU_negative_offset_extended
7070 #define DW_CFA_GNU_negative_offset_extended 0x2f
7072 case DW_CFA_GNU_negative_offset_extended:
7075 frame_need_space (fc, reg);
7077 printf (" DW_CFA_GNU_negative_offset_extended: r%d = cfa[%d*%d]\n", reg, l, fc->data_factor);
7079 fc->col_type[reg] = DW_CFA_offset;
7080 fc->col_offset[reg] = l * fc->data_factor;
7084 fprintf (stderr, "unsupported or unknown DW_CFA_%d\n", op);
7089 frame_display_row (fc, &need_col_headers, &max_regs);
7104 display_debug_not_supported (section, start, file)
7105 Elf32_Internal_Shdr * section;
7106 unsigned char * start ATTRIBUTE_UNUSED;
7107 FILE * file ATTRIBUTE_UNUSED;
7109 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
7110 SECTION_NAME (section));
7115 /* Pre-scan the .debug_info section to record the size of address.
7116 When dumping the .debug_line, we use that size information, assuming
7117 that all compilation units have the same address size. */
7119 prescan_debug_info (section, start, file)
7120 Elf32_Internal_Shdr * section ATTRIBUTE_UNUSED;
7121 unsigned char * start;
7122 FILE * file ATTRIBUTE_UNUSED;
7124 DWARF2_External_CompUnit * external;
7126 external = (DWARF2_External_CompUnit *) start;
7128 debug_line_pointer_size = BYTE_GET (external->cu_pointer_size);
7132 /* A structure containing the name of a debug section and a pointer
7133 to a function that can decode it. The third field is a prescan
7134 function to be run over the section before displaying any of the
7139 int (* display) PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
7140 int (* prescan) PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
7144 { ".debug_info", display_debug_info, prescan_debug_info },
7145 { ".debug_abbrev", display_debug_abbrev, NULL },
7146 { ".debug_line", display_debug_lines, NULL },
7147 { ".debug_aranges", display_debug_aranges, NULL },
7148 { ".debug_pubnames", display_debug_pubnames, NULL },
7149 { ".debug_frame", display_debug_frames, NULL },
7150 { ".eh_frame", display_debug_frames, NULL },
7151 { ".debug_macinfo", display_debug_not_supported, NULL },
7152 { ".debug_frame", display_debug_not_supported, NULL },
7153 { ".debug_str", display_debug_not_supported, NULL },
7154 { ".debug_static_func", display_debug_not_supported, NULL },
7155 { ".debug_static_vars", display_debug_not_supported, NULL },
7156 { ".debug_types", display_debug_not_supported, NULL },
7157 { ".debug_weaknames", display_debug_not_supported, NULL }
7161 display_debug_section (section, file)
7162 Elf32_Internal_Shdr * section;
7165 char * name = SECTION_NAME (section);
7166 bfd_size_type length;
7167 unsigned char * start;
7170 length = section->sh_size;
7173 printf (_("\nSection '%s' has no debugging data.\n"), name);
7177 GET_DATA_ALLOC (section->sh_offset, length, start, unsigned char *,
7178 "debug section data");
7180 /* See if we know how to display the contents of this section. */
7181 if (strncmp (name, ".gnu.linkonce.wi.", 17) == 0)
7182 name = ".debug_info";
7184 for (i = NUM_ELEM (debug_displays); i--;)
7185 if (strcmp (debug_displays[i].name, name) == 0)
7187 debug_displays[i].display (section, start, file);
7192 printf (_("Unrecognised debug section: %s\n"), name);
7196 /* If we loaded in the abbrev section at some point,
7197 we must release it here. */
7198 if (first_abbrev != NULL)
7205 process_section_contents (file)
7208 Elf32_Internal_Shdr * section;
7214 /* Pre-scan the debug sections to find some debug information not
7215 present in some of them. For the .debug_line, we must find out the
7216 size of address (specified in .debug_info and .debug_aranges). */
7217 for (i = 0, section = section_headers;
7218 i < elf_header.e_shnum && i < num_dump_sects;
7221 char * name = SECTION_NAME (section);
7224 if (section->sh_size == 0)
7227 /* See if there is some pre-scan operation for this section. */
7228 for (j = NUM_ELEM (debug_displays); j--;)
7229 if (strcmp (debug_displays[j].name, name) == 0)
7231 if (debug_displays[j].prescan != NULL)
7233 bfd_size_type length;
7234 unsigned char * start;
7236 length = section->sh_size;
7237 GET_DATA_ALLOC (section->sh_offset, length, start, unsigned char *,
7238 "debug section data");
7240 debug_displays[j].prescan (section, start, file);
7248 for (i = 0, section = section_headers;
7249 i < elf_header.e_shnum && i < num_dump_sects;
7252 #ifdef SUPPORT_DISASSEMBLY
7253 if (dump_sects[i] & DISASS_DUMP)
7254 disassemble_section (section, file);
7256 if (dump_sects[i] & HEX_DUMP)
7257 dump_section (section, file);
7259 if (dump_sects[i] & DEBUG_DUMP)
7260 display_debug_section (section, file);
7263 if (i < num_dump_sects)
7264 warn (_("Some sections were not dumped because they do not exist!\n"));
7270 process_mips_fpe_exception (mask)
7276 if (mask & OEX_FPU_INEX)
7277 fputs ("INEX", stdout), first = 0;
7278 if (mask & OEX_FPU_UFLO)
7279 printf ("%sUFLO", first ? "" : "|"), first = 0;
7280 if (mask & OEX_FPU_OFLO)
7281 printf ("%sOFLO", first ? "" : "|"), first = 0;
7282 if (mask & OEX_FPU_DIV0)
7283 printf ("%sDIV0", first ? "" : "|"), first = 0;
7284 if (mask & OEX_FPU_INVAL)
7285 printf ("%sINVAL", first ? "" : "|");
7288 fputs ("0", stdout);
7292 process_mips_specific (file)
7295 Elf_Internal_Dyn * entry;
7296 size_t liblist_offset = 0;
7297 size_t liblistno = 0;
7298 size_t conflictsno = 0;
7299 size_t options_offset = 0;
7300 size_t conflicts_offset = 0;
7302 /* We have a lot of special sections. Thanks SGI! */
7303 if (dynamic_segment == NULL)
7304 /* No information available. */
7307 for (entry = dynamic_segment; entry->d_tag != DT_NULL; ++entry)
7308 switch (entry->d_tag)
7310 case DT_MIPS_LIBLIST:
7311 liblist_offset = entry->d_un.d_val - loadaddr;
7313 case DT_MIPS_LIBLISTNO:
7314 liblistno = entry->d_un.d_val;
7316 case DT_MIPS_OPTIONS:
7317 options_offset = entry->d_un.d_val - loadaddr;
7319 case DT_MIPS_CONFLICT:
7320 conflicts_offset = entry->d_un.d_val - loadaddr;
7322 case DT_MIPS_CONFLICTNO:
7323 conflictsno = entry->d_un.d_val;
7329 if (liblist_offset != 0 && liblistno != 0 && do_dynamic)
7331 Elf32_External_Lib * elib;
7334 GET_DATA_ALLOC (liblist_offset, liblistno * sizeof (Elf32_External_Lib),
7335 elib, Elf32_External_Lib *, "liblist");
7337 printf ("\nSection '.liblist' contains %lu entries:\n",
7338 (unsigned long) liblistno);
7339 fputs (" Library Time Stamp Checksum Version Flags\n",
7342 for (cnt = 0; cnt < liblistno; ++cnt)
7349 liblist.l_name = BYTE_GET (elib[cnt].l_name);
7350 time = BYTE_GET (elib[cnt].l_time_stamp);
7351 liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum);
7352 liblist.l_version = BYTE_GET (elib[cnt].l_version);
7353 liblist.l_flags = BYTE_GET (elib[cnt].l_flags);
7355 tmp = gmtime (&time);
7356 sprintf (timebuf, "%04u-%02u-%02uT%02u:%02u:%02u",
7357 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
7358 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
7360 printf ("%3lu: %-20s %s %#10lx %-7ld", (unsigned long) cnt,
7361 dynamic_strings + liblist.l_name, timebuf,
7362 liblist.l_checksum, liblist.l_version);
7364 if (liblist.l_flags == 0)
7375 { " EXACT_MATCH", LL_EXACT_MATCH },
7376 { " IGNORE_INT_VER", LL_IGNORE_INT_VER },
7377 { " REQUIRE_MINOR", LL_REQUIRE_MINOR },
7378 { " EXPORTS", LL_EXPORTS },
7379 { " DELAY_LOAD", LL_DELAY_LOAD },
7380 { " DELTA", LL_DELTA }
7382 int flags = liblist.l_flags;
7386 fcnt < sizeof (l_flags_vals) / sizeof (l_flags_vals[0]);
7388 if ((flags & l_flags_vals[fcnt].bit) != 0)
7390 fputs (l_flags_vals[fcnt].name, stdout);
7391 flags ^= l_flags_vals[fcnt].bit;
7394 printf (" %#x", (unsigned int) flags);
7403 if (options_offset != 0)
7405 Elf_External_Options * eopt;
7406 Elf_Internal_Shdr * sect = section_headers;
7407 Elf_Internal_Options * iopt;
7408 Elf_Internal_Options * option;
7412 /* Find the section header so that we get the size. */
7413 while (sect->sh_type != SHT_MIPS_OPTIONS)
7416 GET_DATA_ALLOC (options_offset, sect->sh_size, eopt,
7417 Elf_External_Options *, "options");
7419 iopt = (Elf_Internal_Options *) malloc ((sect->sh_size / sizeof (eopt))
7423 error (_("Out of memory"));
7430 while (offset < sect->sh_size)
7432 Elf_External_Options * eoption;
7434 eoption = (Elf_External_Options *) ((char *) eopt + offset);
7436 option->kind = BYTE_GET (eoption->kind);
7437 option->size = BYTE_GET (eoption->size);
7438 option->section = BYTE_GET (eoption->section);
7439 option->info = BYTE_GET (eoption->info);
7441 offset += option->size;
7447 printf (_("\nSection '%s' contains %d entries:\n"),
7448 string_table + sect->sh_name, cnt);
7456 switch (option->kind)
7459 /* This shouldn't happen. */
7460 printf (" NULL %d %lx", option->section, option->info);
7463 printf (" REGINFO ");
7464 if (elf_header.e_machine == EM_MIPS)
7467 Elf32_External_RegInfo * ereg;
7468 Elf32_RegInfo reginfo;
7470 ereg = (Elf32_External_RegInfo *) (option + 1);
7471 reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask);
7472 reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
7473 reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
7474 reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
7475 reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
7476 reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value);
7478 printf ("GPR %08lx GP 0x%lx\n",
7480 (unsigned long) reginfo.ri_gp_value);
7481 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
7482 reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
7483 reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
7488 Elf64_External_RegInfo * ereg;
7489 Elf64_Internal_RegInfo reginfo;
7491 ereg = (Elf64_External_RegInfo *) (option + 1);
7492 reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask);
7493 reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
7494 reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
7495 reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
7496 reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
7497 reginfo.ri_gp_value = BYTE_GET8 (ereg->ri_gp_value);
7499 printf ("GPR %08lx GP 0x",
7500 reginfo.ri_gprmask);
7501 printf_vma (reginfo.ri_gp_value);
7504 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
7505 reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
7506 reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
7510 case ODK_EXCEPTIONS:
7511 fputs (" EXCEPTIONS fpe_min(", stdout);
7512 process_mips_fpe_exception (option->info & OEX_FPU_MIN);
7513 fputs (") fpe_max(", stdout);
7514 process_mips_fpe_exception ((option->info & OEX_FPU_MAX) >> 8);
7515 fputs (")", stdout);
7517 if (option->info & OEX_PAGE0)
7518 fputs (" PAGE0", stdout);
7519 if (option->info & OEX_SMM)
7520 fputs (" SMM", stdout);
7521 if (option->info & OEX_FPDBUG)
7522 fputs (" FPDBUG", stdout);
7523 if (option->info & OEX_DISMISS)
7524 fputs (" DISMISS", stdout);
7527 fputs (" PAD ", stdout);
7528 if (option->info & OPAD_PREFIX)
7529 fputs (" PREFIX", stdout);
7530 if (option->info & OPAD_POSTFIX)
7531 fputs (" POSTFIX", stdout);
7532 if (option->info & OPAD_SYMBOL)
7533 fputs (" SYMBOL", stdout);
7536 fputs (" HWPATCH ", stdout);
7537 if (option->info & OHW_R4KEOP)
7538 fputs (" R4KEOP", stdout);
7539 if (option->info & OHW_R8KPFETCH)
7540 fputs (" R8KPFETCH", stdout);
7541 if (option->info & OHW_R5KEOP)
7542 fputs (" R5KEOP", stdout);
7543 if (option->info & OHW_R5KCVTL)
7544 fputs (" R5KCVTL", stdout);
7547 fputs (" FILL ", stdout);
7548 /* XXX Print content of info word? */
7551 fputs (" TAGS ", stdout);
7552 /* XXX Print content of info word? */
7555 fputs (" HWAND ", stdout);
7556 if (option->info & OHWA0_R4KEOP_CHECKED)
7557 fputs (" R4KEOP_CHECKED", stdout);
7558 if (option->info & OHWA0_R4KEOP_CLEAN)
7559 fputs (" R4KEOP_CLEAN", stdout);
7562 fputs (" HWOR ", stdout);
7563 if (option->info & OHWA0_R4KEOP_CHECKED)
7564 fputs (" R4KEOP_CHECKED", stdout);
7565 if (option->info & OHWA0_R4KEOP_CLEAN)
7566 fputs (" R4KEOP_CLEAN", stdout);
7569 printf (" GP_GROUP %#06lx self-contained %#06lx",
7570 option->info & OGP_GROUP,
7571 (option->info & OGP_SELF) >> 16);
7574 printf (" IDENT %#06lx self-contained %#06lx",
7575 option->info & OGP_GROUP,
7576 (option->info & OGP_SELF) >> 16);
7579 /* This shouldn't happen. */
7580 printf (" %3d ??? %d %lx",
7581 option->kind, option->section, option->info);
7585 len = sizeof (* eopt);
7586 while (len < option->size)
7587 if (((char *) option)[len] >= ' '
7588 && ((char *) option)[len] < 0x7f)
7589 printf ("%c", ((char *) option)[len++]);
7591 printf ("\\%03o", ((char *) option)[len++]);
7593 fputs ("\n", stdout);
7600 if (conflicts_offset != 0 && conflictsno != 0)
7602 Elf32_External_Conflict * econf32;
7603 Elf64_External_Conflict * econf64;
7604 Elf32_Conflict * iconf;
7607 if (dynamic_symbols == NULL)
7609 error (_("conflict list with without table"));
7613 iconf = (Elf32_Conflict *) malloc (conflictsno * sizeof (* iconf));
7616 error (_("Out of memory"));
7622 GET_DATA_ALLOC (conflicts_offset, conflictsno * sizeof (* econf32),
7623 econf32, Elf32_External_Conflict *, "conflict");
7625 for (cnt = 0; cnt < conflictsno; ++cnt)
7626 iconf[cnt] = BYTE_GET (econf32[cnt]);
7630 GET_DATA_ALLOC (conflicts_offset, conflictsno * sizeof (* econf64),
7631 econf64, Elf64_External_Conflict *, "conflict");
7633 for (cnt = 0; cnt < conflictsno; ++cnt)
7634 iconf[cnt] = BYTE_GET (econf64[cnt]);
7637 printf (_("\nSection '.conflict' contains %d entries:\n"), conflictsno);
7638 puts (_(" Num: Index Value Name"));
7640 for (cnt = 0; cnt < conflictsno; ++cnt)
7642 Elf_Internal_Sym * psym = &dynamic_symbols[iconf[cnt]];
7644 printf ("%5lu: %8lu ", (unsigned long) cnt, iconf[cnt]);
7645 print_vma (psym->st_value, FULL_HEX);
7646 printf (" %s\n", dynamic_strings + psym->st_name);
7656 get_note_type (e_type)
7659 static char buff[64];
7663 case NT_PRSTATUS: return _("NT_PRSTATUS (prstatus structure)");
7664 case NT_FPREGSET: return _("NT_FPREGSET (floating point registers)");
7665 case NT_PRPSINFO: return _("NT_PRPSINFO (prpsinfo structure)");
7666 case NT_TASKSTRUCT: return _("NT_TASKSTRUCT (task structure)");
7667 case NT_PRXFPREG: return _("NT_PRXFPREG (user_xfpregs structure)");
7668 case NT_PSTATUS: return _("NT_PSTATUS (pstatus structure)");
7669 case NT_FPREGS: return _("NT_FPREGS (floating point registers)");
7670 case NT_PSINFO: return _("NT_PSINFO (psinfo structure)");
7671 case NT_LWPSTATUS: return _("NT_LWPSTATUS (lwpstatus_t structure)");
7672 case NT_LWPSINFO: return _("NT_LWPSINFO (lwpsinfo_t structure)");
7673 case NT_WIN32PSTATUS: return _("NT_WIN32PSTATUS (win32_pstatus strcuture)");
7675 sprintf (buff, _("Unknown note type: (0x%08x)"), e_type);
7680 /* Note that by the ELF standard, the name field is already null byte
7681 terminated, and namesz includes the terminating null byte.
7682 I.E. the value of namesz for the name "FSF" is 4.
7684 If the value of namesz is zero, there is no name present. */
7686 process_note (pnote)
7687 Elf32_Internal_Note * pnote;
7689 printf (" %s\t\t0x%08lx\t%s\n",
7690 pnote->namesz ? pnote->namedata : "(NONE)",
7691 pnote->descsz, get_note_type (pnote->type));
7697 process_corefile_note_segment (file, offset, length)
7702 Elf_External_Note * pnotes;
7703 Elf_External_Note * external;
7709 GET_DATA_ALLOC (offset, length, pnotes, Elf_External_Note *, "notes");
7713 printf (_("\nNotes at offset 0x%08lx with length 0x%08lx:\n"),
7714 (unsigned long) offset, (unsigned long) length);
7715 printf (_(" Owner\t\tData size\tDescription\n"));
7717 while (external < (Elf_External_Note *)((char *) pnotes + length))
7719 Elf32_Internal_Note inote;
7722 inote.type = BYTE_GET (external->type);
7723 inote.namesz = BYTE_GET (external->namesz);
7724 inote.namedata = external->name;
7725 inote.descsz = BYTE_GET (external->descsz);
7726 inote.descdata = inote.namedata + align_power (inote.namesz, 2);
7727 inote.descpos = offset + (inote.descdata - (char *) pnotes);
7729 external = (Elf_External_Note *)(inote.descdata + align_power (inote.descsz, 2));
7731 /* Verify that name is null terminated. It appears that at least
7732 one version of Linux (RedHat 6.0) generates corefiles that don't
7733 comply with the ELF spec by failing to include the null byte in
7735 if (inote.namedata[inote.namesz] != '\0')
7737 temp = malloc (inote.namesz + 1);
7741 error (_("Out of memory\n"));
7746 strncpy (temp, inote.namedata, inote.namesz);
7747 temp[inote.namesz] = 0;
7749 /* warn (_("'%s' NOTE name not properly null terminated\n"), temp); */
7750 inote.namedata = temp;
7753 res &= process_note (& inote);
7768 process_corefile_note_segments (file)
7771 Elf_Internal_Phdr * program_headers;
7772 Elf_Internal_Phdr * segment;
7776 program_headers = (Elf_Internal_Phdr *) malloc
7777 (elf_header.e_phnum * sizeof (Elf_Internal_Phdr));
7779 if (program_headers == NULL)
7781 error (_("Out of memory\n"));
7786 i = get_32bit_program_headers (file, program_headers);
7788 i = get_64bit_program_headers (file, program_headers);
7792 free (program_headers);
7796 for (i = 0, segment = program_headers;
7797 i < elf_header.e_phnum;
7800 if (segment->p_type == PT_NOTE)
7801 res &= process_corefile_note_segment (file,
7802 (bfd_vma) segment->p_offset,
7803 (bfd_vma) segment->p_filesz);
7806 free (program_headers);
7812 process_corefile_contents (file)
7815 /* If we have not been asked to display the notes then do nothing. */
7819 /* If file is not a core file then exit. */
7820 if (elf_header.e_type != ET_CORE)
7823 /* No program headers means no NOTE segment. */
7824 if (elf_header.e_phnum == 0)
7826 printf (_("No note segments present in the core file.\n"));
7830 return process_corefile_note_segments (file);
7834 process_arch_specific (file)
7840 switch (elf_header.e_machine)
7843 case EM_MIPS_RS4_BE:
7844 return process_mips_specific (file);
7853 get_file_header (file)
7856 /* Read in the identity array. */
7857 if (fread (elf_header.e_ident, EI_NIDENT, 1, file) != 1)
7860 /* Determine how to read the rest of the header. */
7861 switch (elf_header.e_ident [EI_DATA])
7863 default: /* fall through */
7864 case ELFDATANONE: /* fall through */
7865 case ELFDATA2LSB: byte_get = byte_get_little_endian; break;
7866 case ELFDATA2MSB: byte_get = byte_get_big_endian; break;
7869 /* For now we only support 32 bit and 64 bit ELF files. */
7870 is_32bit_elf = (elf_header.e_ident [EI_CLASS] != ELFCLASS64);
7872 /* Read in the rest of the header. */
7875 Elf32_External_Ehdr ehdr32;
7877 if (fread (ehdr32.e_type, sizeof (ehdr32) - EI_NIDENT, 1, file) != 1)
7880 elf_header.e_type = BYTE_GET (ehdr32.e_type);
7881 elf_header.e_machine = BYTE_GET (ehdr32.e_machine);
7882 elf_header.e_version = BYTE_GET (ehdr32.e_version);
7883 elf_header.e_entry = BYTE_GET (ehdr32.e_entry);
7884 elf_header.e_phoff = BYTE_GET (ehdr32.e_phoff);
7885 elf_header.e_shoff = BYTE_GET (ehdr32.e_shoff);
7886 elf_header.e_flags = BYTE_GET (ehdr32.e_flags);
7887 elf_header.e_ehsize = BYTE_GET (ehdr32.e_ehsize);
7888 elf_header.e_phentsize = BYTE_GET (ehdr32.e_phentsize);
7889 elf_header.e_phnum = BYTE_GET (ehdr32.e_phnum);
7890 elf_header.e_shentsize = BYTE_GET (ehdr32.e_shentsize);
7891 elf_header.e_shnum = BYTE_GET (ehdr32.e_shnum);
7892 elf_header.e_shstrndx = BYTE_GET (ehdr32.e_shstrndx);
7896 Elf64_External_Ehdr ehdr64;
7898 /* If we have been compiled with sizeof (bfd_vma) == 4, then
7899 we will not be able to cope with the 64bit data found in
7900 64 ELF files. Detect this now and abort before we start
7901 overwritting things. */
7902 if (sizeof (bfd_vma) < 8)
7904 error (_("This instance of readelf has been built without support for a\n"));
7905 error (_("64 bit data type and so it cannot read 64 bit ELF files.\n"));
7909 if (fread (ehdr64.e_type, sizeof (ehdr64) - EI_NIDENT, 1, file) != 1)
7912 elf_header.e_type = BYTE_GET (ehdr64.e_type);
7913 elf_header.e_machine = BYTE_GET (ehdr64.e_machine);
7914 elf_header.e_version = BYTE_GET (ehdr64.e_version);
7915 elf_header.e_entry = BYTE_GET8 (ehdr64.e_entry);
7916 elf_header.e_phoff = BYTE_GET8 (ehdr64.e_phoff);
7917 elf_header.e_shoff = BYTE_GET8 (ehdr64.e_shoff);
7918 elf_header.e_flags = BYTE_GET (ehdr64.e_flags);
7919 elf_header.e_ehsize = BYTE_GET (ehdr64.e_ehsize);
7920 elf_header.e_phentsize = BYTE_GET (ehdr64.e_phentsize);
7921 elf_header.e_phnum = BYTE_GET (ehdr64.e_phnum);
7922 elf_header.e_shentsize = BYTE_GET (ehdr64.e_shentsize);
7923 elf_header.e_shnum = BYTE_GET (ehdr64.e_shnum);
7924 elf_header.e_shstrndx = BYTE_GET (ehdr64.e_shstrndx);
7931 process_file (file_name)
7935 struct stat statbuf;
7938 if (stat (file_name, & statbuf) < 0)
7940 error (_("Cannot stat input file %s.\n"), file_name);
7944 file = fopen (file_name, "rb");
7947 error (_("Input file %s not found.\n"), file_name);
7951 if (! get_file_header (file))
7953 error (_("%s: Failed to read file header\n"), file_name);
7958 /* Initialise per file variables. */
7959 for (i = NUM_ELEM (version_info); i--;)
7960 version_info[i] = 0;
7962 for (i = NUM_ELEM (dynamic_info); i--;)
7963 dynamic_info[i] = 0;
7965 /* Process the file. */
7967 printf (_("\nFile: %s\n"), file_name);
7969 if (! process_file_header ())
7975 process_section_headers (file);
7977 process_program_headers (file);
7979 process_dynamic_segment (file);
7981 process_relocs (file);
7983 process_symbol_table (file);
7985 process_syminfo (file);
7987 process_version_sections (file);
7989 process_section_contents (file);
7991 process_corefile_contents (file);
7993 process_arch_specific (file);
7997 if (section_headers)
7999 free (section_headers);
8000 section_headers = NULL;
8005 free (string_table);
8006 string_table = NULL;
8009 if (dynamic_strings)
8011 free (dynamic_strings);
8012 dynamic_strings = NULL;
8015 if (dynamic_symbols)
8017 free (dynamic_symbols);
8018 dynamic_symbols = NULL;
8019 num_dynamic_syms = 0;
8022 if (dynamic_syminfo)
8024 free (dynamic_syminfo);
8025 dynamic_syminfo = NULL;
8029 #ifdef SUPPORT_DISASSEMBLY
8030 /* Needed by the i386 disassembler. For extra credit, someone could
8031 fix this so that we insert symbolic addresses here, esp for GOT/PLT
8035 print_address (unsigned int addr, FILE * outfile)
8037 fprintf (outfile,"0x%8.8x", addr);
8040 /* Needed by the i386 disassembler. */
8042 db_task_printsym (unsigned int addr)
8044 print_address (addr, stderr);
8053 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
8054 setlocale (LC_MESSAGES, "");
8056 bindtextdomain (PACKAGE, LOCALEDIR);
8057 textdomain (PACKAGE);
8059 parse_args (argc, argv);
8061 if (optind < (argc - 1))
8064 while (optind < argc)
8065 process_file (argv [optind ++]);
8067 if (dump_sects != NULL)