1 /* readelf.c -- display contents of an ELF format file
2 Copyright 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
4 Originally developed by Eric Youngdale <eric@andante.jic.com>
5 Modifications by Nick Clifton <nickc@redhat.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"
82 char * program_name = "readelf";
83 unsigned int dynamic_addr;
84 bfd_size_type dynamic_size;
85 unsigned int rela_addr;
86 unsigned int rela_size;
87 char * dynamic_strings;
89 unsigned long string_table_length;
90 unsigned long num_dynamic_syms;
91 Elf_Internal_Sym * dynamic_symbols;
92 Elf_Internal_Syminfo * dynamic_syminfo;
93 unsigned long dynamic_syminfo_offset;
94 unsigned int dynamic_syminfo_nent;
95 char program_interpreter [64];
96 int dynamic_info[DT_JMPREL + 1];
99 Elf_Internal_Ehdr elf_header;
100 Elf_Internal_Shdr * section_headers;
101 Elf_Internal_Dyn * dynamic_segment;
109 int do_using_dynamic;
116 int do_debug_abbrevs;
118 int do_debug_pubnames;
119 int do_debug_aranges;
121 int do_debug_frames_interp;
122 int do_debug_macinfo;
127 /* A dynamic array of flags indicating which sections require dumping. */
128 char * dump_sects = NULL;
129 unsigned int num_dump_sects = 0;
131 #define HEX_DUMP (1 << 0)
132 #define DISASS_DUMP (1 << 1)
133 #define DEBUG_DUMP (1 << 2)
135 /* How to rpint a vma value. */
136 typedef enum print_mode
148 /* Forward declarations for dumb compilers. */
149 static void print_vma PARAMS ((bfd_vma, print_mode));
150 static bfd_vma (* byte_get) PARAMS ((unsigned char *, int));
151 static bfd_vma byte_get_little_endian PARAMS ((unsigned char *, int));
152 static bfd_vma byte_get_big_endian PARAMS ((unsigned char *, int));
153 static const char * get_mips_dynamic_type PARAMS ((unsigned long));
154 static const char * get_sparc64_dynamic_type PARAMS ((unsigned long));
155 static const char * get_parisc_dynamic_type PARAMS ((unsigned long));
156 static const char * get_dynamic_type PARAMS ((unsigned long));
157 static int slurp_rela_relocs PARAMS ((FILE *, unsigned long, unsigned long, Elf_Internal_Rela **, unsigned long *));
158 static int slurp_rel_relocs PARAMS ((FILE *, unsigned long, unsigned long, Elf_Internal_Rel **, unsigned long *));
159 static int dump_relocations PARAMS ((FILE *, unsigned long, unsigned long, Elf_Internal_Sym *, unsigned long, char *, int));
160 static char * get_file_type PARAMS ((unsigned));
161 static char * get_machine_name PARAMS ((unsigned));
162 static void decode_ARM_machine_flags PARAMS ((unsigned, char []));
163 static char * get_machine_flags PARAMS ((unsigned, unsigned));
164 static const char * get_mips_segment_type PARAMS ((unsigned long));
165 static const char * get_parisc_segment_type PARAMS ((unsigned long));
166 static const char * get_ia64_segment_type PARAMS ((unsigned long));
167 static const char * get_segment_type PARAMS ((unsigned long));
168 static const char * get_mips_section_type_name PARAMS ((unsigned int));
169 static const char * get_parisc_section_type_name PARAMS ((unsigned int));
170 static const char * get_ia64_section_type_name PARAMS ((unsigned int));
171 static const char * get_section_type_name PARAMS ((unsigned int));
172 static const char * get_symbol_binding PARAMS ((unsigned int));
173 static const char * get_symbol_type PARAMS ((unsigned int));
174 static const char * get_symbol_visibility PARAMS ((unsigned int));
175 static const char * get_symbol_index_type PARAMS ((unsigned int));
176 static const char * get_dynamic_flags PARAMS ((bfd_vma));
177 static void usage PARAMS ((void));
178 static void parse_args PARAMS ((int, char **));
179 static int process_file_header PARAMS ((void));
180 static int process_program_headers PARAMS ((FILE *));
181 static int process_section_headers PARAMS ((FILE *));
182 static int process_unwind PARAMS ((FILE *));
183 static void dynamic_segment_mips_val PARAMS ((Elf_Internal_Dyn *));
184 static void dynamic_segment_parisc_val PARAMS ((Elf_Internal_Dyn *));
185 static int process_dynamic_segment PARAMS ((FILE *));
186 static int process_symbol_table PARAMS ((FILE *));
187 static int process_section_contents PARAMS ((FILE *));
188 static int process_file PARAMS ((char *));
189 static int process_relocs PARAMS ((FILE *));
190 static int process_version_sections PARAMS ((FILE *));
191 static char * get_ver_flags PARAMS ((unsigned int));
192 static int get_32bit_section_headers PARAMS ((FILE *));
193 static int get_64bit_section_headers PARAMS ((FILE *));
194 static int get_32bit_program_headers PARAMS ((FILE *, Elf_Internal_Phdr *));
195 static int get_64bit_program_headers PARAMS ((FILE *, Elf_Internal_Phdr *));
196 static int get_file_header PARAMS ((FILE *));
197 static Elf_Internal_Sym * get_32bit_elf_symbols PARAMS ((FILE *, unsigned long, unsigned long));
198 static Elf_Internal_Sym * get_64bit_elf_symbols PARAMS ((FILE *, unsigned long, unsigned long));
199 static const char * get_elf_section_flags PARAMS ((bfd_vma));
200 static int * get_dynamic_data PARAMS ((FILE *, unsigned int));
201 static int get_32bit_dynamic_segment PARAMS ((FILE *));
202 static int get_64bit_dynamic_segment PARAMS ((FILE *));
203 #ifdef SUPPORT_DISASSEMBLY
204 static int disassemble_section PARAMS ((Elf32_Internal_Shdr *, FILE *));
206 static int dump_section PARAMS ((Elf32_Internal_Shdr *, FILE *));
207 static int display_debug_section PARAMS ((Elf32_Internal_Shdr *, FILE *));
208 static int display_debug_info PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
209 static int display_debug_not_supported PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
210 static int display_debug_lines PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
211 static int display_debug_abbrev PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
212 static int display_debug_aranges PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
213 static int display_debug_frames PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
214 static int display_debug_macinfo PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
215 static unsigned char * process_abbrev_section PARAMS ((unsigned char *, unsigned char *));
216 static unsigned long read_leb128 PARAMS ((unsigned char *, int *, int));
217 static int process_extended_line_op PARAMS ((unsigned char *, int, int));
218 static void reset_state_machine PARAMS ((int));
219 static char * get_TAG_name PARAMS ((unsigned long));
220 static char * get_AT_name PARAMS ((unsigned long));
221 static char * get_FORM_name PARAMS ((unsigned long));
222 static void free_abbrevs PARAMS ((void));
223 static void add_abbrev PARAMS ((unsigned long, unsigned long, int));
224 static void add_abbrev_attr PARAMS ((unsigned long, unsigned long));
225 static unsigned char * read_and_display_attr PARAMS ((unsigned long, unsigned long, unsigned char *, unsigned long, unsigned long));
226 static unsigned char * display_block PARAMS ((unsigned char *, unsigned long));
227 static void decode_location_expression PARAMS ((unsigned char *, unsigned int, unsigned long));
228 static void request_dump PARAMS ((unsigned int, char));
229 static const char * get_elf_class PARAMS ((unsigned char));
230 static const char * get_data_encoding PARAMS ((unsigned char));
231 static const char * get_osabi_name PARAMS ((unsigned char));
232 static int guess_is_rela PARAMS ((unsigned long));
233 static char * get_note_type PARAMS ((unsigned int));
234 static int process_note PARAMS ((Elf32_Internal_Note *));
235 static int process_corefile_note_segment PARAMS ((FILE *, bfd_vma, bfd_vma));
236 static int process_corefile_note_segments PARAMS ((FILE *));
237 static int process_corefile_contents PARAMS ((FILE *));
239 typedef int Elf32_Word;
247 #define SECTION_NAME(X) ((X) == NULL ? "<none>" : \
248 ((X)->sh_name >= string_table_length \
249 ? "<corrupt>" : string_table + (X)->sh_name))
251 #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
253 #define BYTE_GET(field) byte_get (field, sizeof (field))
255 /* If we can support a 64 bit data type then BFD64 should be defined
256 and sizeof (bfd_vma) == 8. In this case when translating from an
257 external 8 byte field to an internal field, we can assume that the
258 internal field is also 8 bytes wide and so we can extract all the data.
259 If, however, BFD64 is not defined, then we must assume that the
260 internal data structure only has 4 byte wide fields that are the
261 equivalent of the 8 byte wide external counterparts, and so we must
262 truncate the data. */
264 #define BYTE_GET8(field) byte_get (field, -8)
266 #define BYTE_GET8(field) byte_get (field, 8)
269 #define NUM_ELEM(array) (sizeof (array) / sizeof ((array)[0]))
271 #define GET_ELF_SYMBOLS(file, offset, size) \
272 (is_32bit_elf ? get_32bit_elf_symbols (file, offset, size) \
273 : get_64bit_elf_symbols (file, offset, size))
276 #ifdef ANSI_PROTOTYPES
278 error (const char * message, ...)
282 fprintf (stderr, _("%s: Error: "), program_name);
283 va_start (args, message);
284 vfprintf (stderr, message, args);
290 warn (const char * message, ...)
294 fprintf (stderr, _("%s: Warning: "), program_name);
295 va_start (args, message);
296 vfprintf (stderr, message, args);
308 fprintf (stderr, _("%s: Error: "), program_name);
310 message = va_arg (args, char *);
311 vfprintf (stderr, message, args);
323 fprintf (stderr, _("%s: Warning: "), program_name);
325 message = va_arg (args, char *);
326 vfprintf (stderr, message, args);
332 static PTR get_data PARAMS ((PTR, FILE *, long, size_t, const char *));
335 get_data (var, file, offset, size, reason)
347 if (fseek (file, offset, SEEK_SET))
349 error (_("Unable to seek to %x for %s\n"), offset, reason);
356 mvar = (PTR) malloc (size);
360 error (_("Out of memory allocating %d bytes for %s\n"),
366 if (fread (mvar, size, 1, file) != 1)
368 error (_("Unable to read in %d bytes of %s\n"), size, reason);
378 byte_get_little_endian (field, size)
379 unsigned char * field;
388 return ((unsigned int) (field [0]))
389 | (((unsigned int) (field [1])) << 8);
393 /* We want to extract data from an 8 byte wide field and
394 place it into a 4 byte wide field. Since this is a little
395 endian source we can juts use the 4 byte extraction code. */
399 return ((unsigned long) (field [0]))
400 | (((unsigned long) (field [1])) << 8)
401 | (((unsigned long) (field [2])) << 16)
402 | (((unsigned long) (field [3])) << 24);
407 /* This is a special case, generated by the BYTE_GET8 macro.
408 It means that we are loading an 8 byte value from a field
409 in an external structure into an 8 byte value in a field
410 in an internal strcuture. */
411 return ((bfd_vma) (field [0]))
412 | (((bfd_vma) (field [1])) << 8)
413 | (((bfd_vma) (field [2])) << 16)
414 | (((bfd_vma) (field [3])) << 24)
415 | (((bfd_vma) (field [4])) << 32)
416 | (((bfd_vma) (field [5])) << 40)
417 | (((bfd_vma) (field [6])) << 48)
418 | (((bfd_vma) (field [7])) << 56);
421 error (_("Unhandled data length: %d\n"), size);
426 /* Print a VMA value. */
428 print_vma (vma, mode)
438 case FULL_HEX: printf ("0x"); /* drop through */
439 case LONG_HEX: printf ("%8.8lx", (unsigned long) vma); break;
440 case PREFIX_HEX: printf ("0x"); /* drop through */
441 case HEX: printf ("%lx", (unsigned long) vma); break;
442 case DEC: printf ("%ld", (unsigned long) vma); break;
443 case DEC_5: printf ("%5ld", (long) vma); break;
444 case UNSIGNED: printf ("%lu", (unsigned long) vma); break;
465 #if BFD_HOST_64BIT_LONG
468 if (_bfd_int64_high (vma))
469 printf ("%lx%lx", _bfd_int64_high (vma), _bfd_int64_low (vma));
471 printf ("%lx", _bfd_int64_low (vma));
476 #if BFD_HOST_64BIT_LONG
479 if (_bfd_int64_high (vma))
481 printf ("++%ld", _bfd_int64_low (vma));
483 printf ("%ld", _bfd_int64_low (vma));
488 #if BFD_HOST_64BIT_LONG
489 printf ("%5ld", vma);
491 if (_bfd_int64_high (vma))
493 printf ("++%ld", _bfd_int64_low (vma));
495 printf ("%5ld", _bfd_int64_low (vma));
500 #if BFD_HOST_64BIT_LONG
503 if (_bfd_int64_high (vma))
505 printf ("++%lu", _bfd_int64_low (vma));
507 printf ("%lu", _bfd_int64_low (vma));
516 byte_get_big_endian (field, size)
517 unsigned char * field;
526 return ((unsigned int) (field [1])) | (((int) (field [0])) << 8);
529 return ((unsigned long) (field [3]))
530 | (((unsigned long) (field [2])) << 8)
531 | (((unsigned long) (field [1])) << 16)
532 | (((unsigned long) (field [0])) << 24);
536 /* Although we are extracing data from an 8 byte wide field, we
537 are returning only 4 bytes of data. */
538 return ((unsigned long) (field [7]))
539 | (((unsigned long) (field [6])) << 8)
540 | (((unsigned long) (field [5])) << 16)
541 | (((unsigned long) (field [4])) << 24);
545 /* This is a special case, generated by the BYTE_GET8 macro.
546 It means that we are loading an 8 byte value from a field
547 in an external structure into an 8 byte value in a field
548 in an internal strcuture. */
549 return ((bfd_vma) (field [7]))
550 | (((bfd_vma) (field [6])) << 8)
551 | (((bfd_vma) (field [5])) << 16)
552 | (((bfd_vma) (field [4])) << 24)
553 | (((bfd_vma) (field [3])) << 32)
554 | (((bfd_vma) (field [2])) << 40)
555 | (((bfd_vma) (field [1])) << 48)
556 | (((bfd_vma) (field [0])) << 56);
560 error (_("Unhandled data length: %d\n"), size);
565 /* Guess the relocation size commonly used by the specific machines. */
568 guess_is_rela (e_machine)
569 unsigned long e_machine;
573 /* Targets that use REL relocations. */
584 /* Targets that use RELA relocations. */
592 case EM_CYGNUS_MN10200:
593 case EM_CYGNUS_MN10300:
626 warn (_("Don't know about relocations on this machine architecture\n"));
632 slurp_rela_relocs (file, rel_offset, rel_size, relasp, nrelasp)
634 unsigned long rel_offset;
635 unsigned long rel_size;
636 Elf_Internal_Rela **relasp;
637 unsigned long *nrelasp;
639 Elf_Internal_Rela *relas;
640 unsigned long nrelas;
645 Elf32_External_Rela * erelas;
647 erelas = (Elf32_External_Rela *) get_data (NULL, file, rel_offset,
648 rel_size, _("relocs"));
652 nrelas = rel_size / sizeof (Elf32_External_Rela);
654 relas = (Elf_Internal_Rela *)
655 malloc (nrelas * sizeof (Elf_Internal_Rela));
659 error(_("out of memory parsing relocs"));
663 for (i = 0; i < nrelas; i++)
665 relas[i].r_offset = BYTE_GET (erelas[i].r_offset);
666 relas[i].r_info = BYTE_GET (erelas[i].r_info);
667 relas[i].r_addend = BYTE_GET (erelas[i].r_addend);
674 Elf64_External_Rela * erelas;
676 erelas = (Elf64_External_Rela *) get_data (NULL, file, rel_offset,
677 rel_size, _("relocs"));
681 nrelas = rel_size / sizeof (Elf64_External_Rela);
683 relas = (Elf_Internal_Rela *)
684 malloc (nrelas * sizeof (Elf_Internal_Rela));
688 error(_("out of memory parsing relocs"));
692 for (i = 0; i < nrelas; i++)
694 relas[i].r_offset = BYTE_GET8 (erelas[i].r_offset);
695 relas[i].r_info = BYTE_GET8 (erelas[i].r_info);
696 relas[i].r_addend = BYTE_GET8 (erelas[i].r_addend);
707 slurp_rel_relocs (file, rel_offset, rel_size, relsp, nrelsp)
709 unsigned long rel_offset;
710 unsigned long rel_size;
711 Elf_Internal_Rel **relsp;
712 unsigned long *nrelsp;
714 Elf_Internal_Rel *rels;
720 Elf32_External_Rel * erels;
722 erels = (Elf32_External_Rel *) get_data (NULL, file, rel_offset,
723 rel_size, _("relocs"));
727 nrels = rel_size / sizeof (Elf32_External_Rel);
729 rels = (Elf_Internal_Rel *) malloc (nrels * sizeof (Elf_Internal_Rel));
733 error(_("out of memory parsing relocs"));
737 for (i = 0; i < nrels; i++)
739 rels[i].r_offset = BYTE_GET (erels[i].r_offset);
740 rels[i].r_info = BYTE_GET (erels[i].r_info);
747 Elf64_External_Rel * erels;
749 erels = (Elf64_External_Rel *) get_data (NULL, file, rel_offset,
750 rel_size, _("relocs"));
754 nrels = rel_size / sizeof (Elf64_External_Rel);
756 rels = (Elf_Internal_Rel *) malloc (nrels * sizeof (Elf_Internal_Rel));
760 error(_("out of memory parsing relocs"));
764 for (i = 0; i < nrels; i++)
766 rels[i].r_offset = BYTE_GET8 (erels[i].r_offset);
767 rels[i].r_info = BYTE_GET8 (erels[i].r_info);
777 /* Display the contents of the relocation data found at the specified offset. */
779 dump_relocations (file, rel_offset, rel_size, symtab, nsyms, strtab, is_rela)
781 unsigned long rel_offset;
782 unsigned long rel_size;
783 Elf_Internal_Sym * symtab;
789 Elf_Internal_Rel * rels;
790 Elf_Internal_Rela * relas;
793 if (is_rela == UNKNOWN)
794 is_rela = guess_is_rela (elf_header.e_machine);
798 if (!slurp_rela_relocs (file, rel_offset, rel_size, &relas, &rel_size))
803 if (!slurp_rel_relocs (file, rel_offset, rel_size, &rels, &rel_size))
809 (_(" Offset Info Type Symbol's Value Symbol's Name Addend\n"));
812 (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
814 for (i = 0; i < rel_size; i++)
819 bfd_vma symtab_index;
824 offset = relas [i].r_offset;
825 info = relas [i].r_info;
829 offset = rels [i].r_offset;
830 info = rels [i].r_info;
835 type = ELF32_R_TYPE (info);
836 symtab_index = ELF32_R_SYM (info);
840 if (elf_header.e_machine == EM_SPARCV9)
841 type = ELF64_R_TYPE_ID (info);
843 type = ELF64_R_TYPE (info);
844 /* The #ifdef BFD64 below is to prevent a compile time warning.
845 We know that if we do not have a 64 bit data type that we
846 will never execute this code anyway. */
848 symtab_index = ELF64_R_SYM (info);
852 #ifdef _bfd_int64_low
853 printf (" %8.8lx %5.5lx ", _bfd_int64_low (offset), _bfd_int64_low (info));
855 printf (" %8.8lx %5.5lx ", offset, info);
858 switch (elf_header.e_machine)
865 rtype = elf_m32r_reloc_type (type);
870 rtype = elf_i386_reloc_type (type);
874 rtype = elf_m68k_reloc_type (type);
878 rtype = elf_i960_reloc_type (type);
882 rtype = elf_avr_reloc_type (type);
889 rtype = elf_sparc_reloc_type (type);
893 rtype = v850_reloc_type (type);
897 rtype = elf_d10v_reloc_type (type);
901 rtype = elf_d30v_reloc_type (type);
905 rtype = elf_sh_reloc_type (type);
908 case EM_CYGNUS_MN10300:
909 rtype = elf_mn10300_reloc_type (type);
912 case EM_CYGNUS_MN10200:
913 rtype = elf_mn10200_reloc_type (type);
917 rtype = elf_fr30_reloc_type (type);
921 rtype = elf_mcore_reloc_type (type);
925 rtype = elf_ppc_reloc_type (type);
930 rtype = elf_mips_reloc_type (type);
934 rtype = elf_alpha_reloc_type (type);
938 rtype = elf_arm_reloc_type (type);
943 rtype = elf_arc_reloc_type (type);
947 rtype = elf_hppa_reloc_type (type);
951 rtype = elf_pj_reloc_type (type);
954 rtype = elf_ia64_reloc_type (type);
958 rtype = elf_cris_reloc_type (type);
962 rtype = elf_i860_reloc_type (type);
966 rtype = elf_x86_64_reloc_type (type);
971 rtype = elf_s390_reloc_type (type);
976 #ifdef _bfd_int64_low
977 printf (_("unrecognised: %-7lx"), _bfd_int64_low (type));
979 printf (_("unrecognised: %-7lx"), type);
982 printf ("%-21.21s", rtype);
986 if (symtab == NULL || symtab_index >= nsyms)
987 printf (" bad symbol index: %08lx", (unsigned long) symtab_index);
990 Elf_Internal_Sym * psym;
992 psym = symtab + symtab_index;
995 print_vma (psym->st_value, LONG_HEX);
998 if (psym->st_name == 0)
1000 SECTION_NAME (section_headers + psym->st_shndx));
1001 else if (strtab == NULL)
1002 printf (_("<string table index %3ld>"), psym->st_name);
1004 printf ("%-25.25s", strtab + psym->st_name);
1007 printf (" + %lx", (unsigned long) relas [i].r_addend);
1012 printf ("%*c", is_32bit_elf ? 34 : 26, ' ');
1013 print_vma (relas[i].r_addend, LONG_HEX);
1016 if (elf_header.e_machine == EM_SPARCV9
1017 && !strcmp (rtype, "R_SPARC_OLO10"))
1018 printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (info));
1032 get_mips_dynamic_type (type)
1037 case DT_MIPS_RLD_VERSION: return "MIPS_RLD_VERSION";
1038 case DT_MIPS_TIME_STAMP: return "MIPS_TIME_STAMP";
1039 case DT_MIPS_ICHECKSUM: return "MIPS_ICHECKSUM";
1040 case DT_MIPS_IVERSION: return "MIPS_IVERSION";
1041 case DT_MIPS_FLAGS: return "MIPS_FLAGS";
1042 case DT_MIPS_BASE_ADDRESS: return "MIPS_BASE_ADDRESS";
1043 case DT_MIPS_MSYM: return "MIPS_MSYM";
1044 case DT_MIPS_CONFLICT: return "MIPS_CONFLICT";
1045 case DT_MIPS_LIBLIST: return "MIPS_LIBLIST";
1046 case DT_MIPS_LOCAL_GOTNO: return "MIPS_LOCAL_GOTNO";
1047 case DT_MIPS_CONFLICTNO: return "MIPS_CONFLICTNO";
1048 case DT_MIPS_LIBLISTNO: return "MIPS_LIBLISTNO";
1049 case DT_MIPS_SYMTABNO: return "MIPS_SYMTABNO";
1050 case DT_MIPS_UNREFEXTNO: return "MIPS_UNREFEXTNO";
1051 case DT_MIPS_GOTSYM: return "MIPS_GOTSYM";
1052 case DT_MIPS_HIPAGENO: return "MIPS_HIPAGENO";
1053 case DT_MIPS_RLD_MAP: return "MIPS_RLD_MAP";
1054 case DT_MIPS_DELTA_CLASS: return "MIPS_DELTA_CLASS";
1055 case DT_MIPS_DELTA_CLASS_NO: return "MIPS_DELTA_CLASS_NO";
1056 case DT_MIPS_DELTA_INSTANCE: return "MIPS_DELTA_INSTANCE";
1057 case DT_MIPS_DELTA_INSTANCE_NO: return "MIPS_DELTA_INSTANCE_NO";
1058 case DT_MIPS_DELTA_RELOC: return "MIPS_DELTA_RELOC";
1059 case DT_MIPS_DELTA_RELOC_NO: return "MIPS_DELTA_RELOC_NO";
1060 case DT_MIPS_DELTA_SYM: return "MIPS_DELTA_SYM";
1061 case DT_MIPS_DELTA_SYM_NO: return "MIPS_DELTA_SYM_NO";
1062 case DT_MIPS_DELTA_CLASSSYM: return "MIPS_DELTA_CLASSSYM";
1063 case DT_MIPS_DELTA_CLASSSYM_NO: return "MIPS_DELTA_CLASSSYM_NO";
1064 case DT_MIPS_CXX_FLAGS: return "MIPS_CXX_FLAGS";
1065 case DT_MIPS_PIXIE_INIT: return "MIPS_PIXIE_INIT";
1066 case DT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB";
1067 case DT_MIPS_LOCALPAGE_GOTIDX: return "MIPS_LOCALPAGE_GOTIDX";
1068 case DT_MIPS_LOCAL_GOTIDX: return "MIPS_LOCAL_GOTIDX";
1069 case DT_MIPS_HIDDEN_GOTIDX: return "MIPS_HIDDEN_GOTIDX";
1070 case DT_MIPS_PROTECTED_GOTIDX: return "MIPS_PROTECTED_GOTIDX";
1071 case DT_MIPS_OPTIONS: return "MIPS_OPTIONS";
1072 case DT_MIPS_INTERFACE: return "MIPS_INTERFACE";
1073 case DT_MIPS_DYNSTR_ALIGN: return "MIPS_DYNSTR_ALIGN";
1074 case DT_MIPS_INTERFACE_SIZE: return "MIPS_INTERFACE_SIZE";
1075 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
1076 case DT_MIPS_PERF_SUFFIX: return "MIPS_PERF_SUFFIX";
1077 case DT_MIPS_COMPACT_SIZE: return "MIPS_COMPACT_SIZE";
1078 case DT_MIPS_GP_VALUE: return "MIPS_GP_VALUE";
1079 case DT_MIPS_AUX_DYNAMIC: return "MIPS_AUX_DYNAMIC";
1086 get_sparc64_dynamic_type (type)
1091 case DT_SPARC_REGISTER: return "SPARC_REGISTER";
1098 get_parisc_dynamic_type (type)
1103 case DT_HP_LOAD_MAP: return "HP_LOAD_MAP";
1104 case DT_HP_DLD_FLAGS: return "HP_DLD_FLAGS";
1105 case DT_HP_DLD_HOOK: return "HP_DLD_HOOK";
1106 case DT_HP_UX10_INIT: return "HP_UX10_INIT";
1107 case DT_HP_UX10_INITSZ: return "HP_UX10_INITSZ";
1108 case DT_HP_PREINIT: return "HP_PREINIT";
1109 case DT_HP_PREINITSZ: return "HP_PREINITSZ";
1110 case DT_HP_NEEDED: return "HP_NEEDED";
1111 case DT_HP_TIME_STAMP: return "HP_TIME_STAMP";
1112 case DT_HP_CHECKSUM: return "HP_CHECKSUM";
1113 case DT_HP_GST_SIZE: return "HP_GST_SIZE";
1114 case DT_HP_GST_VERSION: return "HP_GST_VERSION";
1115 case DT_HP_GST_HASHVAL: return "HP_GST_HASHVAL";
1122 get_dynamic_type (type)
1125 static char buff [32];
1129 case DT_NULL: return "NULL";
1130 case DT_NEEDED: return "NEEDED";
1131 case DT_PLTRELSZ: return "PLTRELSZ";
1132 case DT_PLTGOT: return "PLTGOT";
1133 case DT_HASH: return "HASH";
1134 case DT_STRTAB: return "STRTAB";
1135 case DT_SYMTAB: return "SYMTAB";
1136 case DT_RELA: return "RELA";
1137 case DT_RELASZ: return "RELASZ";
1138 case DT_RELAENT: return "RELAENT";
1139 case DT_STRSZ: return "STRSZ";
1140 case DT_SYMENT: return "SYMENT";
1141 case DT_INIT: return "INIT";
1142 case DT_FINI: return "FINI";
1143 case DT_SONAME: return "SONAME";
1144 case DT_RPATH: return "RPATH";
1145 case DT_SYMBOLIC: return "SYMBOLIC";
1146 case DT_REL: return "REL";
1147 case DT_RELSZ: return "RELSZ";
1148 case DT_RELENT: return "RELENT";
1149 case DT_PLTREL: return "PLTREL";
1150 case DT_DEBUG: return "DEBUG";
1151 case DT_TEXTREL: return "TEXTREL";
1152 case DT_JMPREL: return "JMPREL";
1153 case DT_BIND_NOW: return "BIND_NOW";
1154 case DT_INIT_ARRAY: return "INIT_ARRAY";
1155 case DT_FINI_ARRAY: return "FINI_ARRAY";
1156 case DT_INIT_ARRAYSZ: return "INIT_ARRAYSZ";
1157 case DT_FINI_ARRAYSZ: return "FINI_ARRAYSZ";
1158 case DT_RUNPATH: return "RUNPATH";
1159 case DT_FLAGS: return "FLAGS";
1161 case DT_PREINIT_ARRAY: return "PREINIT_ARRAY";
1162 case DT_PREINIT_ARRAYSZ: return "PREINIT_ARRAYSZ";
1164 case DT_CHECKSUM: return "CHECKSUM";
1165 case DT_PLTPADSZ: return "PLTPADSZ";
1166 case DT_MOVEENT: return "MOVEENT";
1167 case DT_MOVESZ: return "MOVESZ";
1168 case DT_FEATURE: return "FEATURE";
1169 case DT_POSFLAG_1: return "POSFLAG_1";
1170 case DT_SYMINSZ: return "SYMINSZ";
1171 case DT_SYMINENT: return "SYMINENT"; /* aka VALRNGHI */
1173 case DT_ADDRRNGLO: return "ADDRRNGLO";
1174 case DT_CONFIG: return "CONFIG";
1175 case DT_DEPAUDIT: return "DEPAUDIT";
1176 case DT_AUDIT: return "AUDIT";
1177 case DT_PLTPAD: return "PLTPAD";
1178 case DT_MOVETAB: return "MOVETAB";
1179 case DT_SYMINFO: return "SYMINFO"; /* aka ADDRRNGHI */
1181 case DT_VERSYM: return "VERSYM";
1183 case DT_RELACOUNT: return "RELACOUNT";
1184 case DT_RELCOUNT: return "RELCOUNT";
1185 case DT_FLAGS_1: return "FLAGS_1";
1186 case DT_VERDEF: return "VERDEF";
1187 case DT_VERDEFNUM: return "VERDEFNUM";
1188 case DT_VERNEED: return "VERNEED";
1189 case DT_VERNEEDNUM: return "VERNEEDNUM";
1191 case DT_AUXILIARY: return "AUXILIARY";
1192 case DT_USED: return "USED";
1193 case DT_FILTER: return "FILTER";
1196 if ((type >= DT_LOPROC) && (type <= DT_HIPROC))
1198 const char * result;
1200 switch (elf_header.e_machine)
1203 case EM_MIPS_RS3_LE:
1204 result = get_mips_dynamic_type (type);
1207 result = get_sparc64_dynamic_type (type);
1217 sprintf (buff, _("Processor Specific: %lx"), type);
1219 else if ((type >= DT_LOOS) && (type <= DT_HIOS))
1221 const char * result;
1223 switch (elf_header.e_machine)
1226 result = get_parisc_dynamic_type (type);
1236 sprintf (buff, _("Operating System specific: %lx"), type);
1239 sprintf (buff, _("<unknown>: %lx"), type);
1246 get_file_type (e_type)
1249 static char buff [32];
1253 case ET_NONE: return _("NONE (None)");
1254 case ET_REL: return _("REL (Relocatable file)");
1255 case ET_EXEC: return _("EXEC (Executable file)");
1256 case ET_DYN: return _("DYN (Shared object file)");
1257 case ET_CORE: return _("CORE (Core file)");
1260 if ((e_type >= ET_LOPROC) && (e_type <= ET_HIPROC))
1261 sprintf (buff, _("Processor Specific: (%x)"), e_type);
1262 else if ((e_type >= ET_LOOS) && (e_type <= ET_HIOS))
1263 sprintf (buff, _("OS Specific: (%x)"), e_type);
1265 sprintf (buff, _("<unknown>: %x"), e_type);
1271 get_machine_name (e_machine)
1274 static char buff [64]; /* XXX */
1278 case EM_NONE: return _("None");
1279 case EM_M32: return "WE32100";
1280 case EM_SPARC: return "Sparc";
1281 case EM_386: return "Intel 80386";
1282 case EM_68K: return "MC68000";
1283 case EM_88K: return "MC88000";
1284 case EM_486: return "Intel 80486";
1285 case EM_860: return "Intel 80860";
1286 case EM_MIPS: return "MIPS R3000";
1287 case EM_S370: return "IBM System/370";
1288 case EM_MIPS_RS3_LE: return "MIPS R4000 big-endian";
1289 case EM_OLD_SPARCV9: return "Sparc v9 (old)";
1290 case EM_PARISC: return "HPPA";
1291 case EM_PPC_OLD: return "Power PC (old)";
1292 case EM_SPARC32PLUS: return "Sparc v8+" ;
1293 case EM_960: return "Intel 90860";
1294 case EM_PPC: return "PowerPC";
1295 case EM_V800: return "NEC V800";
1296 case EM_FR20: return "Fujitsu FR20";
1297 case EM_RH32: return "TRW RH32";
1298 case EM_MCORE: return "MCORE";
1299 case EM_ARM: return "ARM";
1300 case EM_OLD_ALPHA: return "Digital Alpha (old)";
1301 case EM_SH: return "Hitachi SH";
1302 case EM_SPARCV9: return "Sparc v9";
1303 case EM_TRICORE: return "Siemens Tricore";
1304 case EM_ARC: return "ARC";
1305 case EM_H8_300: return "Hitachi H8/300";
1306 case EM_H8_300H: return "Hitachi H8/300H";
1307 case EM_H8S: return "Hitachi H8S";
1308 case EM_H8_500: return "Hitachi H8/500";
1309 case EM_IA_64: return "Intel IA-64";
1310 case EM_MIPS_X: return "Stanford MIPS-X";
1311 case EM_COLDFIRE: return "Motorola Coldfire";
1312 case EM_68HC12: return "Motorola M68HC12";
1313 case EM_ALPHA: return "Alpha";
1314 case EM_CYGNUS_D10V: return "d10v";
1315 case EM_CYGNUS_D30V: return "d30v";
1316 case EM_CYGNUS_ARC: return "ARC";
1317 case EM_CYGNUS_M32R: return "Mitsubishi M32r";
1318 case EM_CYGNUS_V850: return "NEC v850";
1319 case EM_CYGNUS_MN10300: return "mn10300";
1320 case EM_CYGNUS_MN10200: return "mn10200";
1321 case EM_CYGNUS_FR30: return "Fujitsu FR30";
1322 case EM_PJ: return "picoJava";
1323 case EM_MMA: return "Fujitsu Multimedia Accelerator";
1324 case EM_PCP: return "Siemens PCP";
1325 case EM_NCPU: return "Sony nCPU embedded RISC processor";
1326 case EM_NDR1: return "Denso NDR1 microprocesspr";
1327 case EM_STARCORE: return "Motorola Star*Core processor";
1328 case EM_ME16: return "Toyota ME16 processor";
1329 case EM_ST100: return "STMicroelectronics ST100 processor";
1330 case EM_TINYJ: return "Advanced Logic Corp. TinyJ embedded processor";
1331 case EM_FX66: return "Siemens FX66 microcontroller";
1332 case EM_ST9PLUS: return "STMicroelectronics ST9+ 8/16 bit microcontroller";
1333 case EM_ST7: return "STMicroelectronics ST7 8-bit microcontroller";
1334 case EM_68HC16: return "Motorola MC68HC16 Microcontroller";
1335 case EM_68HC11: return "Motorola MC68HC11 Microcontroller";
1336 case EM_68HC08: return "Motorola MC68HC08 Microcontroller";
1337 case EM_68HC05: return "Motorola MC68HC05 Microcontroller";
1338 case EM_SVX: return "Silicon Graphics SVx";
1339 case EM_ST19: return "STMicroelectronics ST19 8-bit microcontroller";
1340 case EM_VAX: return "Digital VAX";
1341 case EM_AVR: return "Atmel AVR 8-bit microcontroller";
1342 case EM_CRIS: return "Axis Communications 32-bit embedded processor";
1343 case EM_JAVELIN: return "Infineon Technologies 32-bit embedded cpu";
1344 case EM_FIREPATH: return "Element 14 64-bit DSP processor";
1345 case EM_ZSP: return "LSI Logic's 16-bit DSP processor";
1346 case EM_MMIX: return "Donald Knuth's educational 64-bit processor";
1347 case EM_HUANY: return "Harvard Universitys's machine-independent object format";
1348 case EM_PRISM: return "SiTera Prism";
1349 case EM_X86_64: return "Advanced Micro Devices X86-64";
1351 case EM_S390: return "IBM S/390";
1353 sprintf (buff, _("<unknown>: %x"), e_machine);
1359 decode_ARM_machine_flags (e_flags, buf)
1366 eabi = EF_ARM_EABI_VERSION (e_flags);
1367 e_flags &= ~ EF_ARM_EABIMASK;
1369 /* Handle "generic" ARM flags. */
1370 if (e_flags & EF_ARM_RELEXEC)
1372 strcat (buf, ", relocatable executable");
1373 e_flags &= ~ EF_ARM_RELEXEC;
1376 if (e_flags & EF_ARM_HASENTRY)
1378 strcat (buf, ", has entry point");
1379 e_flags &= ~ EF_ARM_HASENTRY;
1382 /* Now handle EABI specific flags. */
1386 strcat (buf, ", <unrecognised EABI>");
1391 case EF_ARM_EABI_VER1:
1392 strcat (buf, ", Version1 EABI");
1397 /* Process flags one bit at a time. */
1398 flag = e_flags & - e_flags;
1403 case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK. */
1404 strcat (buf, ", sorted symbol tables");
1414 case EF_ARM_EABI_VER2:
1415 strcat (buf, ", Version2 EABI");
1420 /* Process flags one bit at a time. */
1421 flag = e_flags & - e_flags;
1426 case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK. */
1427 strcat (buf, ", sorted symbol tables");
1430 case EF_ARM_DYNSYMSUSESEGIDX:
1431 strcat (buf, ", dynamic symbols use segment index");
1434 case EF_ARM_MAPSYMSFIRST:
1435 strcat (buf, ", mapping symbols precede others");
1445 case EF_ARM_EABI_UNKNOWN:
1446 strcat (buf, ", GNU EABI");
1451 /* Process flags one bit at a time. */
1452 flag = e_flags & - e_flags;
1457 case EF_ARM_INTERWORK:
1458 strcat (buf, ", interworking enabled");
1461 case EF_ARM_APCS_26:
1462 strcat (buf, ", uses APCS/26");
1465 case EF_ARM_APCS_FLOAT:
1466 strcat (buf, ", uses APCS/float");
1470 strcat (buf, ", position independent");
1474 strcat (buf, ", 8 bit structure alignment");
1477 case EF_ARM_NEW_ABI:
1478 strcat (buf, ", uses new ABI");
1481 case EF_ARM_OLD_ABI:
1482 strcat (buf, ", uses old ABI");
1485 case EF_ARM_SOFT_FLOAT:
1486 strcat (buf, ", software FP");
1497 strcat (buf,", <unknown>");
1501 get_machine_flags (e_flags, e_machine)
1505 static char buf [1024];
1517 decode_ARM_machine_flags (e_flags, buf);
1521 if (e_flags & EF_CPU32)
1522 strcat (buf, ", cpu32");
1526 if (e_flags & EF_PPC_EMB)
1527 strcat (buf, ", emb");
1529 if (e_flags & EF_PPC_RELOCATABLE)
1530 strcat (buf, ", relocatable");
1532 if (e_flags & EF_PPC_RELOCATABLE_LIB)
1533 strcat (buf, ", relocatable-lib");
1536 case EM_CYGNUS_V850:
1537 switch (e_flags & EF_V850_ARCH)
1540 strcat (buf, ", v850e");
1543 strcat (buf, ", v850ea");
1546 strcat (buf, ", v850");
1549 strcat (buf, ", unknown v850 architecture variant");
1554 case EM_CYGNUS_M32R:
1555 if ((e_flags & EF_M32R_ARCH) == E_M32R_ARCH)
1556 strcat (buf, ", m32r");
1561 case EM_MIPS_RS3_LE:
1562 if (e_flags & EF_MIPS_NOREORDER)
1563 strcat (buf, ", noreorder");
1565 if (e_flags & EF_MIPS_PIC)
1566 strcat (buf, ", pic");
1568 if (e_flags & EF_MIPS_CPIC)
1569 strcat (buf, ", cpic");
1571 if (e_flags & EF_MIPS_ABI2)
1572 strcat (buf, ", abi2");
1574 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_1)
1575 strcat (buf, ", mips1");
1577 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_2)
1578 strcat (buf, ", mips2");
1580 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_3)
1581 strcat (buf, ", mips3");
1583 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_4)
1584 strcat (buf, ", mips4");
1586 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_5)
1587 strcat (buf, ", mips5");
1589 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_32)
1590 strcat (buf, ", mips32");
1592 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_64)
1593 strcat (buf, ", mips64");
1595 switch ((e_flags & EF_MIPS_MACH))
1597 case E_MIPS_MACH_3900: strcat (buf, ", 3900"); break;
1598 case E_MIPS_MACH_4010: strcat (buf, ", 4010"); break;
1599 case E_MIPS_MACH_4100: strcat (buf, ", 4100"); break;
1600 case E_MIPS_MACH_4650: strcat (buf, ", 4650"); break;
1601 case E_MIPS_MACH_4111: strcat (buf, ", 4111"); break;
1602 case E_MIPS_MACH_MIPS32_4K: strcat (buf, ", mips32-4k"); break;
1603 case E_MIPS_MACH_SB1: strcat (buf, ", sb1"); break;
1604 default: strcat (buf, " UNKNOWN"); break;
1609 if (e_flags & EF_SPARC_32PLUS)
1610 strcat (buf, ", v8+");
1612 if (e_flags & EF_SPARC_SUN_US1)
1613 strcat (buf, ", ultrasparcI");
1615 if (e_flags & EF_SPARC_SUN_US3)
1616 strcat (buf, ", ultrasparcIII");
1618 if (e_flags & EF_SPARC_HAL_R1)
1619 strcat (buf, ", halr1");
1621 if (e_flags & EF_SPARC_LEDATA)
1622 strcat (buf, ", ledata");
1624 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_TSO)
1625 strcat (buf, ", tso");
1627 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_PSO)
1628 strcat (buf, ", pso");
1630 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_RMO)
1631 strcat (buf, ", rmo");
1635 switch (e_flags & EF_PARISC_ARCH)
1637 case EFA_PARISC_1_0:
1638 strcpy (buf, ", PA-RISC 1.0");
1640 case EFA_PARISC_1_1:
1641 strcpy (buf, ", PA-RISC 1.1");
1643 case EFA_PARISC_2_0:
1644 strcpy (buf, ", PA-RISC 2.0");
1649 if (e_flags & EF_PARISC_TRAPNIL)
1650 strcat (buf, ", trapnil");
1651 if (e_flags & EF_PARISC_EXT)
1652 strcat (buf, ", ext");
1653 if (e_flags & EF_PARISC_LSB)
1654 strcat (buf, ", lsb");
1655 if (e_flags & EF_PARISC_WIDE)
1656 strcat (buf, ", wide");
1657 if (e_flags & EF_PARISC_NO_KABP)
1658 strcat (buf, ", no kabp");
1659 if (e_flags & EF_PARISC_LAZYSWAP)
1660 strcat (buf, ", lazyswap");
1664 if ((e_flags & EF_PICOJAVA_NEWCALLS) == EF_PICOJAVA_NEWCALLS)
1665 strcat (buf, ", new calling convention");
1667 if ((e_flags & EF_PICOJAVA_GNUCALLS) == EF_PICOJAVA_GNUCALLS)
1668 strcat (buf, ", gnu calling convention");
1672 if ((e_flags & EF_IA_64_ABI64))
1673 strcat (buf, ", 64-bit");
1675 strcat (buf, ", 32-bit");
1676 if ((e_flags & EF_IA_64_REDUCEDFP))
1677 strcat (buf, ", reduced fp model");
1678 if ((e_flags & EF_IA_64_NOFUNCDESC_CONS_GP))
1679 strcat (buf, ", no function descriptors, constant gp");
1680 else if ((e_flags & EF_IA_64_CONS_GP))
1681 strcat (buf, ", constant gp");
1682 if ((e_flags & EF_IA_64_ABSOLUTE))
1683 strcat (buf, ", absolute");
1692 get_mips_segment_type (type)
1697 case PT_MIPS_REGINFO:
1699 case PT_MIPS_RTPROC:
1701 case PT_MIPS_OPTIONS:
1711 get_parisc_segment_type (type)
1716 case PT_HP_TLS: return "HP_TLS";
1717 case PT_HP_CORE_NONE: return "HP_CORE_NONE";
1718 case PT_HP_CORE_VERSION: return "HP_CORE_VERSION";
1719 case PT_HP_CORE_KERNEL: return "HP_CORE_KERNEL";
1720 case PT_HP_CORE_COMM: return "HP_CORE_COMM";
1721 case PT_HP_CORE_PROC: return "HP_CORE_PROC";
1722 case PT_HP_CORE_LOADABLE: return "HP_CORE_LOADABLE";
1723 case PT_HP_CORE_STACK: return "HP_CORE_STACK";
1724 case PT_HP_CORE_SHM: return "HP_CORE_SHM";
1725 case PT_HP_CORE_MMF: return "HP_CORE_MMF";
1726 case PT_HP_PARALLEL: return "HP_PARALLEL";
1727 case PT_HP_FASTBIND: return "HP_FASTBIND";
1728 case PT_PARISC_ARCHEXT: return "PARISC_ARCHEXT";
1729 case PT_PARISC_UNWIND: return "PARISC_UNWIND";
1738 get_ia64_segment_type (type)
1743 case PT_IA_64_ARCHEXT: return "IA_64_ARCHEXT";
1744 case PT_IA_64_UNWIND: return "IA_64_UNWIND";
1753 get_segment_type (p_type)
1754 unsigned long p_type;
1756 static char buff [32];
1760 case PT_NULL: return "NULL";
1761 case PT_LOAD: return "LOAD";
1762 case PT_DYNAMIC: return "DYNAMIC";
1763 case PT_INTERP: return "INTERP";
1764 case PT_NOTE: return "NOTE";
1765 case PT_SHLIB: return "SHLIB";
1766 case PT_PHDR: return "PHDR";
1769 if ((p_type >= PT_LOPROC) && (p_type <= PT_HIPROC))
1771 const char * result;
1773 switch (elf_header.e_machine)
1776 case EM_MIPS_RS3_LE:
1777 result = get_mips_segment_type (p_type);
1780 result = get_parisc_segment_type (p_type);
1783 result = get_ia64_segment_type (p_type);
1793 sprintf (buff, "LOPROC+%lx", p_type - PT_LOPROC);
1795 else if ((p_type >= PT_LOOS) && (p_type <= PT_HIOS))
1797 const char * result;
1799 switch (elf_header.e_machine)
1802 result = get_parisc_segment_type (p_type);
1812 sprintf (buff, "LOOS+%lx", p_type - PT_LOOS);
1815 sprintf (buff, _("<unknown>: %lx"), p_type);
1822 get_mips_section_type_name (sh_type)
1823 unsigned int sh_type;
1827 case SHT_MIPS_LIBLIST: return "MIPS_LIBLIST";
1828 case SHT_MIPS_MSYM: return "MIPS_MSYM";
1829 case SHT_MIPS_CONFLICT: return "MIPS_CONFLICT";
1830 case SHT_MIPS_GPTAB: return "MIPS_GPTAB";
1831 case SHT_MIPS_UCODE: return "MIPS_UCODE";
1832 case SHT_MIPS_DEBUG: return "MIPS_DEBUG";
1833 case SHT_MIPS_REGINFO: return "MIPS_REGINFO";
1834 case SHT_MIPS_PACKAGE: return "MIPS_PACKAGE";
1835 case SHT_MIPS_PACKSYM: return "MIPS_PACKSYM";
1836 case SHT_MIPS_RELD: return "MIPS_RELD";
1837 case SHT_MIPS_IFACE: return "MIPS_IFACE";
1838 case SHT_MIPS_CONTENT: return "MIPS_CONTENT";
1839 case SHT_MIPS_OPTIONS: return "MIPS_OPTIONS";
1840 case SHT_MIPS_SHDR: return "MIPS_SHDR";
1841 case SHT_MIPS_FDESC: return "MIPS_FDESC";
1842 case SHT_MIPS_EXTSYM: return "MIPS_EXTSYM";
1843 case SHT_MIPS_DENSE: return "MIPS_DENSE";
1844 case SHT_MIPS_PDESC: return "MIPS_PDESC";
1845 case SHT_MIPS_LOCSYM: return "MIPS_LOCSYM";
1846 case SHT_MIPS_AUXSYM: return "MIPS_AUXSYM";
1847 case SHT_MIPS_OPTSYM: return "MIPS_OPTSYM";
1848 case SHT_MIPS_LOCSTR: return "MIPS_LOCSTR";
1849 case SHT_MIPS_LINE: return "MIPS_LINE";
1850 case SHT_MIPS_RFDESC: return "MIPS_RFDESC";
1851 case SHT_MIPS_DELTASYM: return "MIPS_DELTASYM";
1852 case SHT_MIPS_DELTAINST: return "MIPS_DELTAINST";
1853 case SHT_MIPS_DELTACLASS: return "MIPS_DELTACLASS";
1854 case SHT_MIPS_DWARF: return "MIPS_DWARF";
1855 case SHT_MIPS_DELTADECL: return "MIPS_DELTADECL";
1856 case SHT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB";
1857 case SHT_MIPS_EVENTS: return "MIPS_EVENTS";
1858 case SHT_MIPS_TRANSLATE: return "MIPS_TRANSLATE";
1859 case SHT_MIPS_PIXIE: return "MIPS_PIXIE";
1860 case SHT_MIPS_XLATE: return "MIPS_XLATE";
1861 case SHT_MIPS_XLATE_DEBUG: return "MIPS_XLATE_DEBUG";
1862 case SHT_MIPS_WHIRL: return "MIPS_WHIRL";
1863 case SHT_MIPS_EH_REGION: return "MIPS_EH_REGION";
1864 case SHT_MIPS_XLATE_OLD: return "MIPS_XLATE_OLD";
1865 case SHT_MIPS_PDR_EXCEPTION: return "MIPS_PDR_EXCEPTION";
1873 get_parisc_section_type_name (sh_type)
1874 unsigned int sh_type;
1878 case SHT_PARISC_EXT: return "PARISC_EXT";
1879 case SHT_PARISC_UNWIND: return "PARISC_UNWIND";
1880 case SHT_PARISC_DOC: return "PARISC_DOC";
1888 get_ia64_section_type_name (sh_type)
1889 unsigned int sh_type;
1893 case SHT_IA_64_EXT: return "IA_64_EXT";
1894 case SHT_IA_64_UNWIND: return "IA_64_UNWIND";
1902 get_section_type_name (sh_type)
1903 unsigned int sh_type;
1905 static char buff [32];
1909 case SHT_NULL: return "NULL";
1910 case SHT_PROGBITS: return "PROGBITS";
1911 case SHT_SYMTAB: return "SYMTAB";
1912 case SHT_STRTAB: return "STRTAB";
1913 case SHT_RELA: return "RELA";
1914 case SHT_HASH: return "HASH";
1915 case SHT_DYNAMIC: return "DYNAMIC";
1916 case SHT_NOTE: return "NOTE";
1917 case SHT_NOBITS: return "NOBITS";
1918 case SHT_REL: return "REL";
1919 case SHT_SHLIB: return "SHLIB";
1920 case SHT_DYNSYM: return "DYNSYM";
1921 case SHT_INIT_ARRAY: return "INIT_ARRAY";
1922 case SHT_FINI_ARRAY: return "FINI_ARRAY";
1923 case SHT_PREINIT_ARRAY: return "PREINIT_ARRAY";
1924 case SHT_GROUP: return "GROUP";
1925 case SHT_SYMTAB_SHNDX: return "SYMTAB SECTION INDICIES";
1926 case SHT_GNU_verdef: return "VERDEF";
1927 case SHT_GNU_verneed: return "VERNEED";
1928 case SHT_GNU_versym: return "VERSYM";
1929 case 0x6ffffff0: return "VERSYM";
1930 case 0x6ffffffc: return "VERDEF";
1931 case 0x7ffffffd: return "AUXILIARY";
1932 case 0x7fffffff: return "FILTER";
1935 if ((sh_type >= SHT_LOPROC) && (sh_type <= SHT_HIPROC))
1937 const char * result;
1939 switch (elf_header.e_machine)
1942 case EM_MIPS_RS3_LE:
1943 result = get_mips_section_type_name (sh_type);
1946 result = get_parisc_section_type_name (sh_type);
1949 result = get_ia64_section_type_name (sh_type);
1959 sprintf (buff, "SHT_LOPROC+%x", sh_type - SHT_LOPROC);
1961 else if ((sh_type >= SHT_LOOS) && (sh_type <= SHT_HIOS))
1962 sprintf (buff, "SHT_LOOS+%x", sh_type - SHT_LOOS);
1963 else if ((sh_type >= SHT_LOUSER) && (sh_type <= SHT_HIUSER))
1964 sprintf (buff, "SHT_LOUSER+%x", sh_type - SHT_LOUSER);
1966 sprintf (buff, _("<unknown>: %x"), sh_type);
1972 struct option options [] =
1974 {"all", no_argument, 0, 'a'},
1975 {"file-header", no_argument, 0, 'h'},
1976 {"program-headers", no_argument, 0, 'l'},
1977 {"headers", no_argument, 0, 'e'},
1978 {"histogram", no_argument, 0, 'I'},
1979 {"segments", no_argument, 0, 'l'},
1980 {"sections", no_argument, 0, 'S'},
1981 {"section-headers", no_argument, 0, 'S'},
1982 {"symbols", no_argument, 0, 's'},
1983 {"syms", no_argument, 0, 's'},
1984 {"relocs", no_argument, 0, 'r'},
1985 {"notes", no_argument, 0, 'n'},
1986 {"dynamic", no_argument, 0, 'd'},
1987 {"arch-specific", no_argument, 0, 'A'},
1988 {"version-info", no_argument, 0, 'V'},
1989 {"use-dynamic", no_argument, 0, 'D'},
1990 {"hex-dump", required_argument, 0, 'x'},
1991 {"debug-dump", optional_argument, 0, 'w'},
1992 {"unwind", no_argument, 0, 'u'},
1993 #ifdef SUPPORT_DISASSEMBLY
1994 {"instruction-dump", required_argument, 0, 'i'},
1997 {"version", no_argument, 0, 'v'},
1998 {"help", no_argument, 0, 'H'},
1999 {0, no_argument, 0, 0}
2005 fprintf (stdout, _("Usage: readelf {options} elf-file(s)\n"));
2006 fprintf (stdout, _(" Options are:\n"));
2007 fprintf (stdout, _(" -a or --all Equivalent to: -h -l -S -s -r -d -V -A -I\n"));
2008 fprintf (stdout, _(" -h or --file-header Display the ELF file header\n"));
2009 fprintf (stdout, _(" -l or --program-headers or --segments\n"));
2010 fprintf (stdout, _(" Display the program headers\n"));
2011 fprintf (stdout, _(" -S or --section-headers or --sections\n"));
2012 fprintf (stdout, _(" Display the sections' header\n"));
2013 fprintf (stdout, _(" -e or --headers Equivalent to: -h -l -S\n"));
2014 fprintf (stdout, _(" -s or --syms or --symbols Display the symbol table\n"));
2015 fprintf (stdout, _(" -n or --notes Display the core notes (if present)\n"));
2016 fprintf (stdout, _(" -r or --relocs Display the relocations (if present)\n"));
2017 fprintf (stdout, _(" -u or --unwind Display the unwind info (if present)\n"));
2018 fprintf (stdout, _(" -d or --dynamic Display the dynamic segment (if present)\n"));
2019 fprintf (stdout, _(" -V or --version-info Display the version sections (if present)\n"));
2020 fprintf (stdout, _(" -A or --arch-specific Display architecture specific information (if any).\n"));
2021 fprintf (stdout, _(" -D or --use-dynamic Use the dynamic section info when displaying symbols\n"));
2022 fprintf (stdout, _(" -x <number> or --hex-dump=<number>\n"));
2023 fprintf (stdout, _(" Dump the contents of section <number>\n"));
2024 fprintf (stdout, _(" -w[liaprmf] or --debug-dump[=line,=info,=abbrev,=pubnames,=ranges,=macro,=frames]\n"));
2025 fprintf (stdout, _(" Display the contents of DWARF2 debug sections\n"));
2026 #ifdef SUPPORT_DISASSEMBLY
2027 fprintf (stdout, _(" -i <number> or --instruction-dump=<number>\n"));
2028 fprintf (stdout, _(" Disassemble the contents of section <number>\n"));
2030 fprintf (stdout, _(" -I or --histogram Display histogram of bucket list lengths\n"));
2031 fprintf (stdout, _(" -v or --version Display the version number of readelf\n"));
2032 fprintf (stdout, _(" -H or --help Display this information\n"));
2033 fprintf (stdout, _("Report bugs to %s\n"), REPORT_BUGS_TO);
2039 request_dump (section, type)
2040 unsigned int section;
2043 if (section >= num_dump_sects)
2045 char * new_dump_sects;
2047 new_dump_sects = (char *) calloc (section + 1, 1);
2049 if (new_dump_sects == NULL)
2050 error (_("Out of memory allocating dump request table."));
2053 /* Copy current flag settings. */
2054 memcpy (new_dump_sects, dump_sects, num_dump_sects);
2058 dump_sects = new_dump_sects;
2059 num_dump_sects = section + 1;
2064 dump_sects [section] |= type;
2070 parse_args (argc, argv)
2079 while ((c = getopt_long
2080 (argc, argv, "ersuahnldSDAIw::x:i:vV", options, NULL)) != EOF)
2116 do_using_dynamic ++;
2147 section = strtoul (optarg, & cp, 0);
2148 if (! * cp && section >= 0)
2150 request_dump (section, HEX_DUMP);
2170 do_debug_abbrevs = 1;
2180 do_debug_pubnames = 1;
2185 do_debug_aranges = 1;
2189 do_debug_frames_interp = 1;
2191 do_debug_frames = 1;
2196 do_debug_macinfo = 1;
2200 warn (_("Unrecognised debug option '%s'\n"), optarg);
2205 #ifdef SUPPORT_DISASSEMBLY
2208 section = strtoul (optarg, & cp, 0);
2209 if (! * cp && section >= 0)
2211 request_dump (section, DISASS_DUMP);
2217 print_version (program_name);
2224 /* xgettext:c-format */
2225 error (_("Invalid option '-%c'\n"), c);
2232 if (!do_dynamic && !do_syms && !do_reloc && !do_unwind && !do_sections
2233 && !do_segments && !do_header && !do_dump && !do_version
2234 && !do_histogram && !do_debugging && !do_arch && !do_notes)
2238 warn (_("Nothing to do.\n"));
2244 get_elf_class (elf_class)
2245 unsigned char elf_class;
2247 static char buff [32];
2251 case ELFCLASSNONE: return _("none");
2252 case ELFCLASS32: return _("ELF32");
2253 case ELFCLASS64: return _("ELF64");
2255 sprintf (buff, _("<unknown: %x>"), elf_class);
2261 get_data_encoding (encoding)
2262 unsigned char encoding;
2264 static char buff [32];
2268 case ELFDATANONE: return _("none");
2269 case ELFDATA2LSB: return _("2's complement, little endian");
2270 case ELFDATA2MSB: return _("2's complement, big endian");
2272 sprintf (buff, _("<unknown: %x>"), encoding);
2278 get_osabi_name (osabi)
2279 unsigned char osabi;
2281 static char buff [32];
2285 case ELFOSABI_NONE: return _("UNIX - System V");
2286 case ELFOSABI_HPUX: return _("UNIX - HP-UX");
2287 case ELFOSABI_NETBSD: return _("UNIX - NetBSD");
2288 case ELFOSABI_LINUX: return _("UNIX - Linux");
2289 case ELFOSABI_HURD: return _("GNU/Hurd");
2290 case ELFOSABI_SOLARIS: return _("UNIX - Solaris");
2291 case ELFOSABI_AIX: return _("UNIX - AIX");
2292 case ELFOSABI_IRIX: return _("UNIX - IRIX");
2293 case ELFOSABI_FREEBSD: return _("UNIX - FreeBSD");
2294 case ELFOSABI_TRU64: return _("UNIX - TRU64");
2295 case ELFOSABI_MODESTO: return _("Novell - Modesto");
2296 case ELFOSABI_OPENBSD: return _("UNIX - OpenBSD");
2297 case ELFOSABI_STANDALONE: return _("Standalone App");
2298 case ELFOSABI_ARM: return _("ARM");
2300 sprintf (buff, _("<unknown: %x>"), osabi);
2305 /* Decode the data held in 'elf_header'. */
2307 process_file_header ()
2309 if ( elf_header.e_ident [EI_MAG0] != ELFMAG0
2310 || elf_header.e_ident [EI_MAG1] != ELFMAG1
2311 || elf_header.e_ident [EI_MAG2] != ELFMAG2
2312 || elf_header.e_ident [EI_MAG3] != ELFMAG3)
2315 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
2323 printf (_("ELF Header:\n"));
2324 printf (_(" Magic: "));
2325 for (i = 0; i < EI_NIDENT; i ++)
2326 printf ("%2.2x ", elf_header.e_ident [i]);
2328 printf (_(" Class: %s\n"),
2329 get_elf_class (elf_header.e_ident [EI_CLASS]));
2330 printf (_(" Data: %s\n"),
2331 get_data_encoding (elf_header.e_ident [EI_DATA]));
2332 printf (_(" Version: %d %s\n"),
2333 elf_header.e_ident [EI_VERSION],
2334 (elf_header.e_ident [EI_VERSION] == EV_CURRENT
2336 : (elf_header.e_ident [EI_VERSION] != EV_NONE
2339 printf (_(" OS/ABI: %s\n"),
2340 get_osabi_name (elf_header.e_ident [EI_OSABI]));
2341 printf (_(" ABI Version: %d\n"),
2342 elf_header.e_ident [EI_ABIVERSION]);
2343 printf (_(" Type: %s\n"),
2344 get_file_type (elf_header.e_type));
2345 printf (_(" Machine: %s\n"),
2346 get_machine_name (elf_header.e_machine));
2347 printf (_(" Version: 0x%lx\n"),
2348 (unsigned long) elf_header.e_version);
2350 printf (_(" Entry point address: "));
2351 print_vma ((bfd_vma) elf_header.e_entry, PREFIX_HEX);
2352 printf (_("\n Start of program headers: "));
2353 print_vma ((bfd_vma) elf_header.e_phoff, DEC);
2354 printf (_(" (bytes into file)\n Start of section headers: "));
2355 print_vma ((bfd_vma) elf_header.e_shoff, DEC);
2356 printf (_(" (bytes into file)\n"));
2358 printf (_(" Flags: 0x%lx%s\n"),
2359 (unsigned long) elf_header.e_flags,
2360 get_machine_flags (elf_header.e_flags, elf_header.e_machine));
2361 printf (_(" Size of this header: %ld (bytes)\n"),
2362 (long) elf_header.e_ehsize);
2363 printf (_(" Size of program headers: %ld (bytes)\n"),
2364 (long) elf_header.e_phentsize);
2365 printf (_(" Number of program headers: %ld\n"),
2366 (long) elf_header.e_phnum);
2367 printf (_(" Size of section headers: %ld (bytes)\n"),
2368 (long) elf_header.e_shentsize);
2369 printf (_(" Number of section headers: %ld\n"),
2370 (long) elf_header.e_shnum);
2371 printf (_(" Section header string table index: %ld\n"),
2372 (long) elf_header.e_shstrndx);
2380 get_32bit_program_headers (file, program_headers)
2382 Elf_Internal_Phdr * program_headers;
2384 Elf32_External_Phdr * phdrs;
2385 Elf32_External_Phdr * external;
2386 Elf32_Internal_Phdr * internal;
2389 phdrs = ((Elf32_External_Phdr *)
2390 get_data (NULL, file, elf_header.e_phoff,
2391 elf_header.e_phentsize * elf_header.e_phnum,
2392 _("program headers")));
2396 for (i = 0, internal = program_headers, external = phdrs;
2397 i < elf_header.e_phnum;
2398 i ++, internal ++, external ++)
2400 internal->p_type = BYTE_GET (external->p_type);
2401 internal->p_offset = BYTE_GET (external->p_offset);
2402 internal->p_vaddr = BYTE_GET (external->p_vaddr);
2403 internal->p_paddr = BYTE_GET (external->p_paddr);
2404 internal->p_filesz = BYTE_GET (external->p_filesz);
2405 internal->p_memsz = BYTE_GET (external->p_memsz);
2406 internal->p_flags = BYTE_GET (external->p_flags);
2407 internal->p_align = BYTE_GET (external->p_align);
2416 get_64bit_program_headers (file, program_headers)
2418 Elf_Internal_Phdr * program_headers;
2420 Elf64_External_Phdr * phdrs;
2421 Elf64_External_Phdr * external;
2422 Elf64_Internal_Phdr * internal;
2425 phdrs = ((Elf64_External_Phdr *)
2426 get_data (NULL, file, elf_header.e_phoff,
2427 elf_header.e_phentsize * elf_header.e_phnum,
2428 _("program headers")));
2432 for (i = 0, internal = program_headers, external = phdrs;
2433 i < elf_header.e_phnum;
2434 i ++, internal ++, external ++)
2436 internal->p_type = BYTE_GET (external->p_type);
2437 internal->p_flags = BYTE_GET (external->p_flags);
2438 internal->p_offset = BYTE_GET8 (external->p_offset);
2439 internal->p_vaddr = BYTE_GET8 (external->p_vaddr);
2440 internal->p_paddr = BYTE_GET8 (external->p_paddr);
2441 internal->p_filesz = BYTE_GET8 (external->p_filesz);
2442 internal->p_memsz = BYTE_GET8 (external->p_memsz);
2443 internal->p_align = BYTE_GET8 (external->p_align);
2452 process_program_headers (file)
2455 Elf_Internal_Phdr * program_headers;
2456 Elf_Internal_Phdr * segment;
2459 if (elf_header.e_phnum == 0)
2462 printf (_("\nThere are no program headers in this file.\n"));
2466 if (do_segments && !do_header)
2468 printf (_("\nElf file type is %s\n"), get_file_type (elf_header.e_type));
2469 printf (_("Entry point "));
2470 print_vma ((bfd_vma) elf_header.e_entry, PREFIX_HEX);
2471 printf (_("\nThere are %d program headers, starting at offset "),
2472 elf_header.e_phnum);
2473 print_vma ((bfd_vma) elf_header.e_phoff, DEC);
2477 program_headers = (Elf_Internal_Phdr *) malloc
2478 (elf_header.e_phnum * sizeof (Elf_Internal_Phdr));
2480 if (program_headers == NULL)
2482 error (_("Out of memory\n"));
2487 i = get_32bit_program_headers (file, program_headers);
2489 i = get_64bit_program_headers (file, program_headers);
2493 free (program_headers);
2500 (_("\nProgram Header%s:\n"), elf_header.e_phnum > 1 ? "s" : "");
2504 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
2508 (_(" Type Offset VirtAddr PhysAddr\n"));
2510 (_(" FileSiz MemSiz Flags Align\n"));
2518 for (i = 0, segment = program_headers;
2519 i < elf_header.e_phnum;
2524 printf (" %-14.14s ", get_segment_type (segment->p_type));
2528 printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
2529 printf ("0x%8.8lx ", (unsigned long) segment->p_vaddr);
2530 printf ("0x%8.8lx ", (unsigned long) segment->p_paddr);
2531 printf ("0x%5.5lx ", (unsigned long) segment->p_filesz);
2532 printf ("0x%5.5lx ", (unsigned long) segment->p_memsz);
2534 (segment->p_flags & PF_R ? 'R' : ' '),
2535 (segment->p_flags & PF_W ? 'W' : ' '),
2536 (segment->p_flags & PF_X ? 'E' : ' '));
2537 printf ("%#lx", (unsigned long) segment->p_align);
2541 print_vma (segment->p_offset, FULL_HEX);
2543 print_vma (segment->p_vaddr, FULL_HEX);
2545 print_vma (segment->p_paddr, FULL_HEX);
2547 print_vma (segment->p_filesz, FULL_HEX);
2549 print_vma (segment->p_memsz, FULL_HEX);
2551 (segment->p_flags & PF_R ? 'R' : ' '),
2552 (segment->p_flags & PF_W ? 'W' : ' '),
2553 (segment->p_flags & PF_X ? 'E' : ' '));
2554 print_vma (segment->p_align, HEX);
2558 switch (segment->p_type)
2562 loadaddr = (segment->p_vaddr & 0xfffff000)
2563 - (segment->p_offset & 0xfffff000);
2568 error (_("more than one dynamic segment\n"));
2570 dynamic_addr = segment->p_offset;
2571 dynamic_size = segment->p_filesz;
2575 if (fseek (file, (long) segment->p_offset, SEEK_SET))
2576 error (_("Unable to find program interpreter name\n"));
2579 program_interpreter[0] = 0;
2580 fscanf (file, "%63s", program_interpreter);
2583 printf (_("\n [Requesting program interpreter: %s]"),
2584 program_interpreter);
2590 putc ('\n', stdout);
2599 if (do_segments && section_headers != NULL)
2601 printf (_("\n Section to Segment mapping:\n"));
2602 printf (_(" Segment Sections...\n"));
2604 assert (string_table != NULL);
2606 for (i = 0; i < elf_header.e_phnum; i++)
2609 Elf_Internal_Shdr * section;
2611 segment = program_headers + i;
2612 section = section_headers;
2614 printf (" %2.2d ", i);
2616 for (j = 0; j < elf_header.e_shnum; j++, section ++)
2618 if (section->sh_size > 0
2619 /* Compare allocated sections by VMA, unallocated
2620 sections by file offset. */
2621 && (section->sh_flags & SHF_ALLOC
2622 ? (section->sh_addr >= segment->p_vaddr
2623 && section->sh_addr + section->sh_size
2624 <= segment->p_vaddr + segment->p_memsz)
2625 : ((bfd_vma) section->sh_offset >= segment->p_offset
2626 && (section->sh_offset + section->sh_size
2627 <= segment->p_offset + segment->p_filesz))))
2628 printf ("%s ", SECTION_NAME (section));
2635 free (program_headers);
2642 get_32bit_section_headers (file)
2645 Elf32_External_Shdr * shdrs;
2646 Elf32_Internal_Shdr * internal;
2649 shdrs = ((Elf32_External_Shdr *)
2650 get_data (NULL, file, elf_header.e_shoff,
2651 elf_header.e_shentsize * elf_header.e_shnum,
2652 _("section headers")));
2656 section_headers = (Elf_Internal_Shdr *) malloc
2657 (elf_header.e_shnum * sizeof (Elf_Internal_Shdr));
2659 if (section_headers == NULL)
2661 error (_("Out of memory\n"));
2665 for (i = 0, internal = section_headers;
2666 i < elf_header.e_shnum;
2669 internal->sh_name = BYTE_GET (shdrs[i].sh_name);
2670 internal->sh_type = BYTE_GET (shdrs[i].sh_type);
2671 internal->sh_flags = BYTE_GET (shdrs[i].sh_flags);
2672 internal->sh_addr = BYTE_GET (shdrs[i].sh_addr);
2673 internal->sh_offset = BYTE_GET (shdrs[i].sh_offset);
2674 internal->sh_size = BYTE_GET (shdrs[i].sh_size);
2675 internal->sh_link = BYTE_GET (shdrs[i].sh_link);
2676 internal->sh_info = BYTE_GET (shdrs[i].sh_info);
2677 internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
2678 internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize);
2687 get_64bit_section_headers (file)
2690 Elf64_External_Shdr * shdrs;
2691 Elf64_Internal_Shdr * internal;
2694 shdrs = ((Elf64_External_Shdr *)
2695 get_data (NULL, file, elf_header.e_shoff,
2696 elf_header.e_shentsize * elf_header.e_shnum,
2697 _("section headers")));
2701 section_headers = (Elf_Internal_Shdr *) malloc
2702 (elf_header.e_shnum * sizeof (Elf_Internal_Shdr));
2704 if (section_headers == NULL)
2706 error (_("Out of memory\n"));
2710 for (i = 0, internal = section_headers;
2711 i < elf_header.e_shnum;
2714 internal->sh_name = BYTE_GET (shdrs[i].sh_name);
2715 internal->sh_type = BYTE_GET (shdrs[i].sh_type);
2716 internal->sh_flags = BYTE_GET8 (shdrs[i].sh_flags);
2717 internal->sh_addr = BYTE_GET8 (shdrs[i].sh_addr);
2718 internal->sh_size = BYTE_GET8 (shdrs[i].sh_size);
2719 internal->sh_entsize = BYTE_GET8 (shdrs[i].sh_entsize);
2720 internal->sh_link = BYTE_GET (shdrs[i].sh_link);
2721 internal->sh_info = BYTE_GET (shdrs[i].sh_info);
2722 internal->sh_offset = BYTE_GET (shdrs[i].sh_offset);
2723 internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
2731 static Elf_Internal_Sym *
2732 get_32bit_elf_symbols (file, offset, number)
2734 unsigned long offset;
2735 unsigned long number;
2737 Elf32_External_Sym * esyms;
2738 Elf_Internal_Sym * isyms;
2739 Elf_Internal_Sym * psym;
2742 esyms = ((Elf32_External_Sym *)
2743 get_data (NULL, file, offset,
2744 number * sizeof (Elf32_External_Sym), _("symbols")));
2748 isyms = (Elf_Internal_Sym *) malloc (number * sizeof (Elf_Internal_Sym));
2752 error (_("Out of memory\n"));
2758 for (j = 0, psym = isyms;
2762 psym->st_name = BYTE_GET (esyms[j].st_name);
2763 psym->st_value = BYTE_GET (esyms[j].st_value);
2764 psym->st_size = BYTE_GET (esyms[j].st_size);
2765 psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
2766 psym->st_info = BYTE_GET (esyms[j].st_info);
2767 psym->st_other = BYTE_GET (esyms[j].st_other);
2775 static Elf_Internal_Sym *
2776 get_64bit_elf_symbols (file, offset, number)
2778 unsigned long offset;
2779 unsigned long number;
2781 Elf64_External_Sym * esyms;
2782 Elf_Internal_Sym * isyms;
2783 Elf_Internal_Sym * psym;
2786 esyms = ((Elf64_External_Sym *)
2787 get_data (NULL, file, offset,
2788 number * sizeof (Elf64_External_Sym), _("symbols")));
2792 isyms = (Elf_Internal_Sym *) malloc (number * sizeof (Elf_Internal_Sym));
2796 error (_("Out of memory\n"));
2802 for (j = 0, psym = isyms;
2806 psym->st_name = BYTE_GET (esyms[j].st_name);
2807 psym->st_info = BYTE_GET (esyms[j].st_info);
2808 psym->st_other = BYTE_GET (esyms[j].st_other);
2809 psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
2810 psym->st_value = BYTE_GET8 (esyms[j].st_value);
2811 psym->st_size = BYTE_GET8 (esyms[j].st_size);
2820 get_elf_section_flags (sh_flags)
2823 static char buff [32];
2831 flag = sh_flags & - sh_flags;
2836 case SHF_WRITE: strcat (buff, "W"); break;
2837 case SHF_ALLOC: strcat (buff, "A"); break;
2838 case SHF_EXECINSTR: strcat (buff, "X"); break;
2839 case SHF_MERGE: strcat (buff, "M"); break;
2840 case SHF_STRINGS: strcat (buff, "S"); break;
2841 case SHF_INFO_LINK: strcat (buff, "I"); break;
2842 case SHF_LINK_ORDER: strcat (buff, "L"); break;
2843 case SHF_OS_NONCONFORMING: strcat (buff, "O"); break;
2844 case SHF_GROUP: strcat (buff, "G"); break;
2847 if (flag & SHF_MASKOS)
2850 sh_flags &= ~ SHF_MASKOS;
2852 else if (flag & SHF_MASKPROC)
2855 sh_flags &= ~ SHF_MASKPROC;
2867 process_section_headers (file)
2870 Elf_Internal_Shdr * section;
2873 section_headers = NULL;
2875 if (elf_header.e_shnum == 0)
2878 printf (_("\nThere are no sections in this file.\n"));
2883 if (do_sections && !do_header)
2884 printf (_("There are %d section headers, starting at offset 0x%lx:\n"),
2885 elf_header.e_shnum, (unsigned long) elf_header.e_shoff);
2889 if (! get_32bit_section_headers (file))
2892 else if (! get_64bit_section_headers (file))
2895 /* Read in the string table, so that we have names to display. */
2896 section = section_headers + elf_header.e_shstrndx;
2898 if (section->sh_size != 0)
2900 string_table = (char *) get_data (NULL, file, section->sh_offset,
2901 section->sh_size, _("string table"));
2903 string_table_length = section->sh_size;
2906 /* Scan the sections for the dynamic symbol table
2907 and dynamic string table and debug sections. */
2908 dynamic_symbols = NULL;
2909 dynamic_strings = NULL;
2910 dynamic_syminfo = NULL;
2912 for (i = 0, section = section_headers;
2913 i < elf_header.e_shnum;
2916 char * name = SECTION_NAME (section);
2918 if (section->sh_type == SHT_DYNSYM)
2920 if (dynamic_symbols != NULL)
2922 error (_("File contains multiple dynamic symbol tables\n"));
2926 num_dynamic_syms = section->sh_size / section->sh_entsize;
2928 GET_ELF_SYMBOLS (file, section->sh_offset, num_dynamic_syms);
2930 else if (section->sh_type == SHT_STRTAB
2931 && strcmp (name, ".dynstr") == 0)
2933 if (dynamic_strings != NULL)
2935 error (_("File contains multiple dynamic string tables\n"));
2939 dynamic_strings = (char *) get_data (NULL, file, section->sh_offset,
2941 _("dynamic strings"));
2943 else if ((do_debugging || do_debug_info || do_debug_abbrevs
2944 || do_debug_lines || do_debug_pubnames || do_debug_aranges
2945 || do_debug_frames || do_debug_macinfo)
2946 && strncmp (name, ".debug_", 7) == 0)
2951 || (do_debug_info && (strcmp (name, "info") == 0))
2952 || (do_debug_abbrevs && (strcmp (name, "abbrev") == 0))
2953 || (do_debug_lines && (strcmp (name, "line") == 0))
2954 || (do_debug_pubnames && (strcmp (name, "pubnames") == 0))
2955 || (do_debug_aranges && (strcmp (name, "aranges") == 0))
2956 || (do_debug_frames && (strcmp (name, "frame") == 0))
2957 || (do_debug_macinfo && (strcmp (name, "macinfo") == 0))
2959 request_dump (i, DEBUG_DUMP);
2961 /* linkonce section to be combined with .debug_info at link time. */
2962 else if ((do_debugging || do_debug_info)
2963 && strncmp (name, ".gnu.linkonce.wi.", 17) == 0)
2964 request_dump (i, DEBUG_DUMP);
2965 else if (do_debug_frames && strcmp (name, ".eh_frame") == 0)
2966 request_dump (i, DEBUG_DUMP);
2972 printf (_("\nSection Header%s:\n"), elf_header.e_shnum > 1 ? "s" : "");
2976 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
2979 printf (_(" [Nr] Name Type Address Offset\n"));
2980 printf (_(" Size EntSize Flags Link Info Align\n"));
2983 for (i = 0, section = section_headers;
2984 i < elf_header.e_shnum;
2987 printf (" [%2d] %-17.17s %-15.15s ",
2989 SECTION_NAME (section),
2990 get_section_type_name (section->sh_type));
2994 print_vma (section->sh_addr, LONG_HEX);
2996 printf ( " %6.6lx %6.6lx %2.2lx",
2997 (unsigned long) section->sh_offset,
2998 (unsigned long) section->sh_size,
2999 (unsigned long) section->sh_entsize);
3001 printf (" %3s ", get_elf_section_flags (section->sh_flags));
3003 printf ("%2ld %3lx %2ld\n",
3004 (unsigned long) section->sh_link,
3005 (unsigned long) section->sh_info,
3006 (unsigned long) section->sh_addralign);
3011 print_vma (section->sh_addr, LONG_HEX);
3012 printf (" %8.8lx", section->sh_offset);
3014 print_vma (section->sh_size, LONG_HEX);
3016 print_vma (section->sh_entsize, LONG_HEX);
3018 printf (" %3s ", get_elf_section_flags (section->sh_flags));
3020 printf (" %2ld %3lx %ld\n",
3021 (unsigned long) section->sh_link,
3022 (unsigned long) section->sh_info,
3023 (unsigned long) section->sh_addralign);
3027 printf (_("Key to Flags:\n"));
3028 printf (_(" W (write), A (alloc), X (execute), M (merge), S (strings)\n"));
3029 printf (_(" I (info), L (link order), G (group), x (unknown)\n"));
3030 printf (_(" O (extra OS processing required) o (OS specific), p (processor specific)\n"));
3035 /* Process the reloc section. */
3037 process_relocs (file)
3040 unsigned long rel_size;
3041 unsigned long rel_offset;
3047 if (do_using_dynamic)
3049 int is_rela = FALSE;
3054 if (dynamic_info[DT_REL])
3056 rel_offset = dynamic_info[DT_REL];
3057 rel_size = dynamic_info[DT_RELSZ];
3060 else if (dynamic_info [DT_RELA])
3062 rel_offset = dynamic_info[DT_RELA];
3063 rel_size = dynamic_info[DT_RELASZ];
3066 else if (dynamic_info[DT_JMPREL])
3068 rel_offset = dynamic_info[DT_JMPREL];
3069 rel_size = dynamic_info[DT_PLTRELSZ];
3071 switch (dynamic_info[DT_PLTREL])
3088 (_("\nRelocation section at offset 0x%lx contains %ld bytes:\n"),
3089 rel_offset, rel_size);
3091 dump_relocations (file, rel_offset - loadaddr, rel_size,
3092 dynamic_symbols, num_dynamic_syms, dynamic_strings, is_rela);
3095 printf (_("\nThere are no dynamic relocations in this file.\n"));
3099 Elf32_Internal_Shdr * section;
3103 for (i = 0, section = section_headers;
3104 i < elf_header.e_shnum;
3107 if ( section->sh_type != SHT_RELA
3108 && section->sh_type != SHT_REL)
3111 rel_offset = section->sh_offset;
3112 rel_size = section->sh_size;
3116 Elf32_Internal_Shdr * strsec;
3117 Elf_Internal_Sym * symtab;
3120 unsigned long nsyms;
3122 printf (_("\nRelocation section "));
3124 if (string_table == NULL)
3125 printf ("%d", section->sh_name);
3127 printf ("'%s'", SECTION_NAME (section));
3129 printf (_(" at offset 0x%lx contains %lu entries:\n"),
3130 rel_offset, (unsigned long) (rel_size / section->sh_entsize));
3135 if (section->sh_link)
3137 Elf32_Internal_Shdr * symsec;
3139 symsec = section_headers + section->sh_link;
3140 nsyms = symsec->sh_size / symsec->sh_entsize;
3141 symtab = GET_ELF_SYMBOLS (file, symsec->sh_offset, nsyms);
3146 strsec = section_headers + symsec->sh_link;
3148 strtab = (char *) get_data (NULL, file, strsec->sh_offset,
3152 is_rela = section->sh_type == SHT_RELA;
3154 dump_relocations (file, rel_offset, rel_size,
3155 symtab, nsyms, strtab, is_rela);
3167 printf (_("\nThere are no relocations in this file.\n"));
3173 #include "unwind-ia64.h"
3175 /* An absolute address consists of a section and an offset. If the
3176 section is NULL, the offset itself is the address, otherwise, the
3177 address equals to LOAD_ADDRESS(section) + offset. */
3181 unsigned short section;
3187 struct unw_table_entry
3189 struct absaddr start;
3191 struct absaddr info;
3193 *table; /* Unwind table. */
3194 unsigned long table_len; /* Length of unwind table. */
3195 unsigned char * info; /* Unwind info. */
3196 unsigned long info_size; /* Size of unwind info. */
3197 bfd_vma info_addr; /* starting address of unwind info. */
3198 bfd_vma seg_base; /* Starting address of segment. */
3199 Elf_Internal_Sym * symtab; /* The symbol table. */
3200 unsigned long nsyms; /* Number of symbols. */
3201 char * strtab; /* The string table. */
3202 unsigned long strtab_size; /* Size of string table. */
3205 static void find_symbol_for_address PARAMS ((struct unw_aux_info *,
3206 struct absaddr, const char **,
3208 static void dump_ia64_unwind PARAMS ((struct unw_aux_info *));
3209 static int slurp_ia64_unwind_table PARAMS ((FILE *, struct unw_aux_info *,
3210 Elf32_Internal_Shdr *));
3213 find_symbol_for_address (aux, addr, symname, offset)
3214 struct unw_aux_info *aux;
3215 struct absaddr addr;
3216 const char **symname;
3219 bfd_vma dist = (bfd_vma) 0x100000;
3220 Elf_Internal_Sym *sym, *best = NULL;
3223 for (i = 0, sym = aux->symtab; i < aux->nsyms; ++i, ++sym)
3225 if (ELF_ST_TYPE (sym->st_info) == STT_FUNC
3226 && sym->st_name != 0
3227 && (addr.section == SHN_UNDEF || addr.section == sym->st_shndx)
3228 && addr.offset >= sym->st_value
3229 && addr.offset - sym->st_value < dist)
3232 dist = addr.offset - sym->st_value;
3239 *symname = (best->st_name >= aux->strtab_size
3240 ? "<corrupt>" : aux->strtab + best->st_name);
3245 *offset = addr.offset;
3249 dump_ia64_unwind (aux)
3250 struct unw_aux_info *aux;
3253 struct unw_table_entry * tp;
3256 addr_size = is_32bit_elf ? 4 : 8;
3258 for (tp = aux->table; tp < aux->table + aux->table_len; ++tp)
3262 const unsigned char * dp;
3263 const unsigned char * head;
3264 const char * procname;
3266 find_symbol_for_address (aux, tp->start, &procname, &offset);
3268 fputs ("\n<", stdout);
3272 fputs (procname, stdout);
3275 printf ("+%lx", (unsigned long) offset);
3278 fputs (">: [", stdout);
3279 print_vma (tp->start.offset, PREFIX_HEX);
3280 fputc ('-', stdout);
3281 print_vma (tp->end.offset, PREFIX_HEX);
3282 printf ("), info at +0x%lx\n",
3283 (unsigned long) (tp->info.offset - aux->seg_base));
3285 head = aux->info + (tp->info.offset - aux->info_addr);
3286 stamp = BYTE_GET8 ((unsigned char *) head);
3288 printf (" v%u, flags=0x%lx (%s%s ), len=%lu bytes\n",
3289 (unsigned) UNW_VER (stamp),
3290 (unsigned long) ((stamp & UNW_FLAG_MASK) >> 32),
3291 UNW_FLAG_EHANDLER (stamp) ? " ehandler" : "",
3292 UNW_FLAG_UHANDLER (stamp) ? " uhandler" : "",
3293 (unsigned long) (addr_size * UNW_LENGTH (stamp)));
3295 if (UNW_VER (stamp) != 1)
3297 printf ("\tUnknown version.\n");
3302 for (dp = head + 8; dp < head + 8 + addr_size * UNW_LENGTH (stamp);)
3303 dp = unw_decode (dp, in_body, & in_body);
3308 slurp_ia64_unwind_table (file, aux, sec)
3310 struct unw_aux_info *aux;
3311 Elf32_Internal_Shdr *sec;
3313 unsigned long size, addr_size, nrelas, i;
3314 Elf_Internal_Phdr *prog_hdrs, *seg;
3315 struct unw_table_entry *tep;
3316 Elf32_Internal_Shdr *relsec;
3317 Elf_Internal_Rela *rela, *rp;
3318 unsigned char *table, *tp;
3319 Elf_Internal_Sym *sym;
3320 const char *relname;
3323 addr_size = is_32bit_elf ? 4 : 8;
3325 /* First, find the starting address of the segment that includes
3328 if (elf_header.e_phnum)
3330 prog_hdrs = (Elf_Internal_Phdr *)
3331 xmalloc (elf_header.e_phnum * sizeof (Elf_Internal_Phdr));
3334 result = get_32bit_program_headers (file, prog_hdrs);
3336 result = get_64bit_program_headers (file, prog_hdrs);
3344 for (seg = prog_hdrs; seg < prog_hdrs + elf_header.e_phnum; ++seg)
3346 if (seg->p_type != PT_LOAD)
3349 if (sec->sh_addr >= seg->p_vaddr
3350 && (sec->sh_addr + sec->sh_size <= seg->p_vaddr + seg->p_memsz))
3352 aux->seg_base = seg->p_vaddr;
3360 /* Second, build the unwind table from the contents of the unwind section: */
3361 size = sec->sh_size;
3362 table = (char *) get_data (NULL, file, sec->sh_offset,
3363 size, _("unwind table"));
3367 tep = aux->table = xmalloc (size / (3 * addr_size) * sizeof (aux->table[0]));
3368 for (tp = table; tp < table + size; tp += 3 * addr_size, ++ tep)
3370 tep->start.section = SHN_UNDEF;
3371 tep->end.section = SHN_UNDEF;
3372 tep->info.section = SHN_UNDEF;
3375 tep->start.offset = byte_get ((unsigned char *) tp + 0, 4);
3376 tep->end.offset = byte_get ((unsigned char *) tp + 4, 4);
3377 tep->info.offset = byte_get ((unsigned char *) tp + 8, 4);
3381 tep->start.offset = BYTE_GET8 ((unsigned char *) tp + 0);
3382 tep->end.offset = BYTE_GET8 ((unsigned char *) tp + 8);
3383 tep->info.offset = BYTE_GET8 ((unsigned char *) tp + 16);
3385 tep->start.offset += aux->seg_base;
3386 tep->end.offset += aux->seg_base;
3387 tep->info.offset += aux->seg_base;
3391 /* Third, apply any relocations to the unwind table: */
3393 for (relsec = section_headers;
3394 relsec < section_headers + elf_header.e_shnum;
3397 if (relsec->sh_type != SHT_RELA
3398 || section_headers + relsec->sh_info != sec)
3401 if (!slurp_rela_relocs (file, relsec->sh_offset, relsec->sh_size,
3405 for (rp = rela; rp < rela + nrelas; ++rp)
3409 relname = elf_ia64_reloc_type (ELF32_R_TYPE (rp->r_info));
3410 sym = aux->symtab + ELF32_R_SYM (rp->r_info);
3412 if (ELF32_ST_TYPE (sym->st_info) != STT_SECTION)
3414 warn (_("Skipping unexpected symbol type %u"),
3415 ELF32_ST_TYPE (sym->st_info));
3421 relname = elf_ia64_reloc_type (ELF64_R_TYPE (rp->r_info));
3422 sym = aux->symtab + ELF64_R_SYM (rp->r_info);
3424 if (ELF64_ST_TYPE (sym->st_info) != STT_SECTION)
3426 warn (_("Skipping unexpected symbol type %u"),
3427 ELF64_ST_TYPE (sym->st_info));
3432 if (strncmp (relname, "R_IA64_SEGREL", 13) != 0)
3434 warn (_("Skipping unexpected relocation type %s"), relname);
3438 i = rp->r_offset / (3 * addr_size);
3440 switch (rp->r_offset/addr_size % 3)
3443 aux->table[i].start.section = sym->st_shndx;
3444 aux->table[i].start.offset += rp->r_addend;
3447 aux->table[i].end.section = sym->st_shndx;
3448 aux->table[i].end.offset += rp->r_addend;
3451 aux->table[i].info.section = sym->st_shndx;
3452 aux->table[i].info.offset += rp->r_addend;
3462 aux->table_len = size / (3 * addr_size);
3467 process_unwind (file)
3470 Elf32_Internal_Shdr *sec, *unwsec = NULL, *strsec;
3471 unsigned long i, addr_size, unwcount = 0, unwstart = 0;
3472 struct unw_aux_info aux;
3477 if (elf_header.e_machine != EM_IA_64)
3479 printf (_("\nThere are no unwind sections in this file.\n"));
3483 memset (& aux, 0, sizeof (aux));
3485 addr_size = is_32bit_elf ? 4 : 8;
3487 for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec)
3489 if (sec->sh_type == SHT_SYMTAB)
3491 aux.nsyms = sec->sh_size / sec->sh_entsize;
3492 aux.symtab = GET_ELF_SYMBOLS (file, sec->sh_offset, aux.nsyms);
3494 strsec = section_headers + sec->sh_link;
3495 aux.strtab_size = strsec->sh_size;
3496 aux.strtab = (char *) get_data (NULL, file, strsec->sh_offset,
3497 aux.strtab_size, _("string table"));
3499 else if (sec->sh_type == SHT_IA_64_UNWIND)
3504 printf (_("\nThere are no unwind sections in this file.\n"));
3506 while (unwcount-- > 0)
3511 for (i = unwstart, sec = section_headers + unwstart;
3512 i < elf_header.e_shnum; ++i, ++sec)
3513 if (sec->sh_type == SHT_IA_64_UNWIND)
3520 len = sizeof (ELF_STRING_ia64_unwind_once) - 1;
3522 if (strncmp (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind_once,
3525 /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO */
3526 len2 = sizeof (ELF_STRING_ia64_unwind_info_once) - 1;
3527 suffix = SECTION_NAME (unwsec) + len;
3528 for (i = 0, sec = section_headers; i < elf_header.e_shnum;
3530 if (strncmp (SECTION_NAME (sec),
3531 ELF_STRING_ia64_unwind_info_once, len2) == 0
3532 && strcmp (SECTION_NAME (sec) + len2, suffix) == 0)
3537 /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO
3538 .IA_64.unwind or BAR -> .IA_64.unwind_info */
3539 len = sizeof (ELF_STRING_ia64_unwind) - 1;
3540 len2 = sizeof (ELF_STRING_ia64_unwind_info) - 1;
3542 if (strncmp (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind,
3544 suffix = SECTION_NAME (unwsec) + len;
3545 for (i = 0, sec = section_headers; i < elf_header.e_shnum;
3547 if (strncmp (SECTION_NAME (sec),
3548 ELF_STRING_ia64_unwind_info, len2) == 0
3549 && strcmp (SECTION_NAME (sec) + len2, suffix) == 0)
3553 if (i == elf_header.e_shnum)
3555 printf (_("\nCould not find unwind info section for "));
3557 if (string_table == NULL)
3558 printf ("%d", unwsec->sh_name);
3560 printf ("'%s'", SECTION_NAME (unwsec));
3564 aux.info_size = sec->sh_size;
3565 aux.info_addr = sec->sh_addr;
3566 aux.info = (char *) get_data (NULL, file, sec->sh_offset,
3567 aux.info_size, _("unwind info"));
3569 printf (_("\nUnwind section "));
3571 if (string_table == NULL)
3572 printf ("%d", unwsec->sh_name);
3574 printf ("'%s'", SECTION_NAME (unwsec));
3576 printf (_(" at offset 0x%lx contains %lu entries:\n"),
3578 (unsigned long) (unwsec->sh_size / (3 * addr_size)));
3580 (void) slurp_ia64_unwind_table (file, & aux, unwsec);
3582 if (aux.table_len > 0)
3583 dump_ia64_unwind (& aux);
3586 free ((char *) aux.table);
3588 free ((char *) aux.info);
3597 free ((char *) aux.strtab);
3603 dynamic_segment_mips_val (entry)
3604 Elf_Internal_Dyn * entry;
3606 switch (entry->d_tag)
3609 if (entry->d_un.d_val == 0)
3613 static const char * opts[] =
3615 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
3616 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
3617 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
3618 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
3623 for (cnt = 0; cnt < NUM_ELEM (opts); ++ cnt)
3624 if (entry->d_un.d_val & (1 << cnt))
3626 printf ("%s%s", first ? "" : " ", opts[cnt]);
3633 case DT_MIPS_IVERSION:
3634 if (dynamic_strings != NULL)
3635 printf ("Interface Version: %s\n",
3636 dynamic_strings + entry->d_un.d_val);
3638 printf ("%ld\n", (long) entry->d_un.d_ptr);
3641 case DT_MIPS_TIME_STAMP:
3646 time_t time = entry->d_un.d_val;
3647 tmp = gmtime (&time);
3648 sprintf (timebuf, "%04u-%02u-%02uT%02u:%02u:%02u",
3649 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
3650 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
3651 printf ("Time Stamp: %s\n", timebuf);
3655 case DT_MIPS_RLD_VERSION:
3656 case DT_MIPS_LOCAL_GOTNO:
3657 case DT_MIPS_CONFLICTNO:
3658 case DT_MIPS_LIBLISTNO:
3659 case DT_MIPS_SYMTABNO:
3660 case DT_MIPS_UNREFEXTNO:
3661 case DT_MIPS_HIPAGENO:
3662 case DT_MIPS_DELTA_CLASS_NO:
3663 case DT_MIPS_DELTA_INSTANCE_NO:
3664 case DT_MIPS_DELTA_RELOC_NO:
3665 case DT_MIPS_DELTA_SYM_NO:
3666 case DT_MIPS_DELTA_CLASSSYM_NO:
3667 case DT_MIPS_COMPACT_SIZE:
3668 printf ("%ld\n", (long) entry->d_un.d_ptr);
3672 printf ("%#lx\n", (long) entry->d_un.d_ptr);
3678 dynamic_segment_parisc_val (entry)
3679 Elf_Internal_Dyn * entry;
3681 switch (entry->d_tag)
3683 case DT_HP_DLD_FLAGS:
3692 { DT_HP_DEBUG_PRIVATE, "HP_DEBUG_PRIVATE" },
3693 { DT_HP_DEBUG_CALLBACK, "HP_DEBUG_CALLBACK" },
3694 { DT_HP_DEBUG_CALLBACK_BOR, "HP_DEBUG_CALLBACK_BOR" },
3695 { DT_HP_NO_ENVVAR, "HP_NO_ENVVAR" },
3696 { DT_HP_BIND_NOW, "HP_BIND_NOW" },
3697 { DT_HP_BIND_NONFATAL, "HP_BIND_NONFATAL" },
3698 { DT_HP_BIND_VERBOSE, "HP_BIND_VERBOSE" },
3699 { DT_HP_BIND_RESTRICTED, "HP_BIND_RESTRICTED" },
3700 { DT_HP_BIND_SYMBOLIC, "HP_BIND_SYMBOLIC" },
3701 { DT_HP_RPATH_FIRST, "HP_RPATH_FIRST" },
3702 { DT_HP_BIND_DEPTH_FIRST, "HP_BIND_DEPTH_FIRST" }
3706 bfd_vma val = entry->d_un.d_val;
3708 for (cnt = 0; cnt < sizeof (flags) / sizeof (flags[0]); ++cnt)
3709 if (val & flags[cnt].bit)
3713 fputs (flags[cnt].str, stdout);
3715 val ^= flags[cnt].bit;
3718 if (val != 0 || first)
3722 print_vma (val, HEX);
3728 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
3734 get_32bit_dynamic_segment (file)
3737 Elf32_External_Dyn * edyn;
3738 Elf_Internal_Dyn * entry;
3741 edyn = (Elf32_External_Dyn *) get_data (NULL, file, dynamic_addr,
3742 dynamic_size, _("dynamic segment"));
3746 /* SGI's ELF has more than one section in the DYNAMIC segment. Determine
3747 how large this .dynamic is now. We can do this even before the byte
3748 swapping since the DT_NULL tag is recognizable. */
3750 while (*(Elf32_Word *) edyn [dynamic_size++].d_tag != DT_NULL)
3753 dynamic_segment = (Elf_Internal_Dyn *)
3754 malloc (dynamic_size * sizeof (Elf_Internal_Dyn));
3756 if (dynamic_segment == NULL)
3758 error (_("Out of memory\n"));
3763 for (i = 0, entry = dynamic_segment;
3767 entry->d_tag = BYTE_GET (edyn [i].d_tag);
3768 entry->d_un.d_val = BYTE_GET (edyn [i].d_un.d_val);
3777 get_64bit_dynamic_segment (file)
3780 Elf64_External_Dyn * edyn;
3781 Elf_Internal_Dyn * entry;
3784 edyn = (Elf64_External_Dyn *) get_data (NULL, file, dynamic_addr,
3785 dynamic_size, _("dynamic segment"));
3789 /* SGI's ELF has more than one section in the DYNAMIC segment. Determine
3790 how large this .dynamic is now. We can do this even before the byte
3791 swapping since the DT_NULL tag is recognizable. */
3793 while (*(bfd_vma *) edyn [dynamic_size ++].d_tag != DT_NULL)
3796 dynamic_segment = (Elf_Internal_Dyn *)
3797 malloc (dynamic_size * sizeof (Elf_Internal_Dyn));
3799 if (dynamic_segment == NULL)
3801 error (_("Out of memory\n"));
3806 for (i = 0, entry = dynamic_segment;
3810 entry->d_tag = BYTE_GET8 (edyn [i].d_tag);
3811 entry->d_un.d_val = BYTE_GET8 (edyn [i].d_un.d_val);
3820 get_dynamic_flags (flags)
3823 static char buff [64];
3828 flag = flags & - flags;
3833 case DF_ORIGIN: strcat (buff, "ORIGIN "); break;
3834 case DF_SYMBOLIC: strcat (buff, "SYMBOLIC "); break;
3835 case DF_TEXTREL: strcat (buff, "TEXTREL "); break;
3836 case DF_BIND_NOW: strcat (buff, "BIND_NOW "); break;
3837 default: strcat (buff, "unknown "); break;
3843 /* Parse and display the contents of the dynamic segment. */
3845 process_dynamic_segment (file)
3848 Elf_Internal_Dyn * entry;
3851 if (dynamic_size == 0)
3854 printf (_("\nThere is no dynamic segment in this file.\n"));
3861 if (! get_32bit_dynamic_segment (file))
3864 else if (! get_64bit_dynamic_segment (file))
3867 /* Find the appropriate symbol table. */
3868 if (dynamic_symbols == NULL)
3870 for (i = 0, entry = dynamic_segment;
3874 unsigned long offset;
3876 if (entry->d_tag != DT_SYMTAB)
3879 dynamic_info[DT_SYMTAB] = entry->d_un.d_val;
3881 /* Since we do not know how big the symbol table is,
3882 we default to reading in the entire file (!) and
3883 processing that. This is overkill, I know, but it
3885 offset = entry->d_un.d_val - loadaddr;
3887 if (fseek (file, 0, SEEK_END))
3888 error (_("Unable to seek to end of file!"));
3891 num_dynamic_syms = (ftell (file) - offset) / sizeof (Elf32_External_Sym);
3893 num_dynamic_syms = (ftell (file) - offset) / sizeof (Elf64_External_Sym);
3895 if (num_dynamic_syms < 1)
3897 error (_("Unable to determine the number of symbols to load\n"));
3901 dynamic_symbols = GET_ELF_SYMBOLS (file, offset, num_dynamic_syms);
3905 /* Similarly find a string table. */
3906 if (dynamic_strings == NULL)
3908 for (i = 0, entry = dynamic_segment;
3912 unsigned long offset;
3915 if (entry->d_tag != DT_STRTAB)
3918 dynamic_info[DT_STRTAB] = entry->d_un.d_val;
3920 /* Since we do not know how big the string table is,
3921 we default to reading in the entire file (!) and
3922 processing that. This is overkill, I know, but it
3925 offset = entry->d_un.d_val - loadaddr;
3926 if (fseek (file, 0, SEEK_END))
3927 error (_("Unable to seek to end of file\n"));
3928 str_tab_len = ftell (file) - offset;
3930 if (str_tab_len < 1)
3933 (_("Unable to determine the length of the dynamic string table\n"));
3937 dynamic_strings = (char *) get_data (NULL, file, offset, str_tab_len,
3938 _("dynamic string table"));
3944 /* And find the syminfo section if available. */
3945 if (dynamic_syminfo == NULL)
3947 unsigned int syminsz = 0;
3949 for (i = 0, entry = dynamic_segment;
3953 if (entry->d_tag == DT_SYMINENT)
3955 /* Note: these braces are necessary to avoid a syntax
3956 error from the SunOS4 C compiler. */
3957 assert (sizeof (Elf_External_Syminfo) == entry->d_un.d_val);
3959 else if (entry->d_tag == DT_SYMINSZ)
3960 syminsz = entry->d_un.d_val;
3961 else if (entry->d_tag == DT_SYMINFO)
3962 dynamic_syminfo_offset = entry->d_un.d_val - loadaddr;
3965 if (dynamic_syminfo_offset != 0 && syminsz != 0)
3967 Elf_External_Syminfo * extsyminfo;
3968 Elf_Internal_Syminfo * syminfo;
3970 /* There is a syminfo section. Read the data. */
3971 extsyminfo = ((Elf_External_Syminfo *)
3972 get_data (NULL, file, dynamic_syminfo_offset,
3973 syminsz, _("symbol information")));
3977 dynamic_syminfo = (Elf_Internal_Syminfo *) malloc (syminsz);
3978 if (dynamic_syminfo == NULL)
3980 error (_("Out of memory\n"));
3984 dynamic_syminfo_nent = syminsz / sizeof (Elf_External_Syminfo);
3985 for (i = 0, syminfo = dynamic_syminfo; i < dynamic_syminfo_nent;
3988 syminfo->si_boundto = BYTE_GET (extsyminfo[i].si_boundto);
3989 syminfo->si_flags = BYTE_GET (extsyminfo[i].si_flags);
3996 if (do_dynamic && dynamic_addr)
3997 printf (_("\nDynamic segment at offset 0x%x contains %ld entries:\n"),
3998 dynamic_addr, (long) dynamic_size);
4000 printf (_(" Tag Type Name/Value\n"));
4002 for (i = 0, entry = dynamic_segment;
4011 print_vma (entry->d_tag, FULL_HEX);
4012 dtype = get_dynamic_type (entry->d_tag);
4013 printf (" (%s)%*s", dtype,
4014 ((is_32bit_elf ? 27 : 19)
4015 - (int) strlen (dtype)),
4019 switch (entry->d_tag)
4023 printf ("%s", get_dynamic_flags (entry->d_un.d_val));
4033 switch (entry->d_tag)
4036 printf (_("Auxiliary library"));
4040 printf (_("Filter library"));
4044 printf (_("Configuration file"));
4048 printf (_("Dependency audit library"));
4052 printf (_("Audit library"));
4056 if (dynamic_strings)
4057 printf (": [%s]\n", dynamic_strings + entry->d_un.d_val);
4061 print_vma (entry->d_un.d_val, PREFIX_HEX);
4070 printf (_("Flags:"));
4071 if (entry->d_un.d_val == 0)
4072 printf (_(" None\n"));
4075 unsigned long int val = entry->d_un.d_val;
4076 if (val & DTF_1_PARINIT)
4078 printf (" PARINIT");
4079 val ^= DTF_1_PARINIT;
4081 if (val & DTF_1_CONFEXP)
4083 printf (" CONFEXP");
4084 val ^= DTF_1_CONFEXP;
4087 printf (" %lx", val);
4096 printf (_("Flags:"));
4097 if (entry->d_un.d_val == 0)
4098 printf (_(" None\n"));
4101 unsigned long int val = entry->d_un.d_val;
4102 if (val & DF_P1_LAZYLOAD)
4104 printf (" LAZYLOAD");
4105 val ^= DF_P1_LAZYLOAD;
4107 if (val & DF_P1_GROUPPERM)
4109 printf (" GROUPPERM");
4110 val ^= DF_P1_GROUPPERM;
4113 printf (" %lx", val);
4122 printf (_("Flags:"));
4123 if (entry->d_un.d_val == 0)
4124 printf (_(" None\n"));
4127 unsigned long int val = entry->d_un.d_val;
4133 if (val & DF_1_GLOBAL)
4138 if (val & DF_1_GROUP)
4143 if (val & DF_1_NODELETE)
4145 printf (" NODELETE");
4146 val ^= DF_1_NODELETE;
4148 if (val & DF_1_LOADFLTR)
4150 printf (" LOADFLTR");
4151 val ^= DF_1_LOADFLTR;
4153 if (val & DF_1_INITFIRST)
4155 printf (" INITFIRST");
4156 val ^= DF_1_INITFIRST;
4158 if (val & DF_1_NOOPEN)
4163 if (val & DF_1_ORIGIN)
4168 if (val & DF_1_DIRECT)
4173 if (val & DF_1_TRANS)
4178 if (val & DF_1_INTERPOSE)
4180 printf (" INTERPOSE");
4181 val ^= DF_1_INTERPOSE;
4183 if (val & DF_1_NODEFLIB)
4185 printf (" NODEFLIB");
4186 val ^= DF_1_NODEFLIB;
4188 if (val & DF_1_NODUMP)
4193 if (val & DF_1_CONLFAT)
4195 printf (" CONLFAT");
4196 val ^= DF_1_CONLFAT;
4199 printf (" %lx", val);
4207 puts (get_dynamic_type (entry->d_un.d_val));
4227 dynamic_info[entry->d_tag] = entry->d_un.d_val;
4233 if (dynamic_strings == NULL)
4236 name = dynamic_strings + entry->d_un.d_val;
4240 switch (entry->d_tag)
4243 printf (_("Shared library: [%s]"), name);
4245 if (strcmp (name, program_interpreter) == 0)
4246 printf (_(" program interpreter"));
4250 printf (_("Library soname: [%s]"), name);
4254 printf (_("Library rpath: [%s]"), name);
4258 printf (_("Library runpath: [%s]"), name);
4262 print_vma (entry->d_un.d_val, PREFIX_HEX);
4267 print_vma (entry->d_un.d_val, PREFIX_HEX);
4283 case DT_INIT_ARRAYSZ:
4284 case DT_FINI_ARRAYSZ:
4287 print_vma (entry->d_un.d_val, UNSIGNED);
4288 printf (" (bytes)\n");
4298 print_vma (entry->d_un.d_val, UNSIGNED);
4311 if (dynamic_strings != NULL && entry->d_tag == DT_USED)
4315 name = dynamic_strings + entry->d_un.d_val;
4319 printf (_("Not needed object: [%s]\n"), name);
4324 print_vma (entry->d_un.d_val, PREFIX_HEX);
4330 /* The value of this entry is ignored. */
4334 if ((entry->d_tag >= DT_VERSYM) && (entry->d_tag <= DT_VERNEEDNUM))
4335 version_info [DT_VERSIONTAGIDX (entry->d_tag)] =
4340 switch (elf_header.e_machine)
4343 case EM_MIPS_RS3_LE:
4344 dynamic_segment_mips_val (entry);
4347 dynamic_segment_parisc_val (entry);
4350 print_vma (entry->d_un.d_val, PREFIX_HEX);
4362 get_ver_flags (flags)
4365 static char buff [32];
4372 if (flags & VER_FLG_BASE)
4373 strcat (buff, "BASE ");
4375 if (flags & VER_FLG_WEAK)
4377 if (flags & VER_FLG_BASE)
4378 strcat (buff, "| ");
4380 strcat (buff, "WEAK ");
4383 if (flags & ~(VER_FLG_BASE | VER_FLG_WEAK))
4384 strcat (buff, "| <unknown>");
4389 /* Display the contents of the version sections. */
4391 process_version_sections (file)
4394 Elf32_Internal_Shdr * section;
4401 for (i = 0, section = section_headers;
4402 i < elf_header.e_shnum;
4405 switch (section->sh_type)
4407 case SHT_GNU_verdef:
4409 Elf_External_Verdef * edefs;
4416 (_("\nVersion definition section '%s' contains %ld entries:\n"),
4417 SECTION_NAME (section), section->sh_info);
4419 printf (_(" Addr: 0x"));
4420 printf_vma (section->sh_addr);
4421 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
4422 (unsigned long) section->sh_offset, section->sh_link,
4423 SECTION_NAME (section_headers + section->sh_link));
4425 edefs = ((Elf_External_Verdef *)
4426 get_data (NULL, file, section->sh_offset,
4428 _("version definition section")));
4432 for (idx = cnt = 0; cnt < section->sh_info; ++ cnt)
4435 Elf_External_Verdef * edef;
4436 Elf_Internal_Verdef ent;
4437 Elf_External_Verdaux * eaux;
4438 Elf_Internal_Verdaux aux;
4442 vstart = ((char *) edefs) + idx;
4444 edef = (Elf_External_Verdef *) vstart;
4446 ent.vd_version = BYTE_GET (edef->vd_version);
4447 ent.vd_flags = BYTE_GET (edef->vd_flags);
4448 ent.vd_ndx = BYTE_GET (edef->vd_ndx);
4449 ent.vd_cnt = BYTE_GET (edef->vd_cnt);
4450 ent.vd_hash = BYTE_GET (edef->vd_hash);
4451 ent.vd_aux = BYTE_GET (edef->vd_aux);
4452 ent.vd_next = BYTE_GET (edef->vd_next);
4454 printf (_(" %#06x: Rev: %d Flags: %s"),
4455 idx, ent.vd_version, get_ver_flags (ent.vd_flags));
4457 printf (_(" Index: %d Cnt: %d "),
4458 ent.vd_ndx, ent.vd_cnt);
4460 vstart += ent.vd_aux;
4462 eaux = (Elf_External_Verdaux *) vstart;
4464 aux.vda_name = BYTE_GET (eaux->vda_name);
4465 aux.vda_next = BYTE_GET (eaux->vda_next);
4467 if (dynamic_strings)
4468 printf (_("Name: %s\n"), dynamic_strings + aux.vda_name);
4470 printf (_("Name index: %ld\n"), aux.vda_name);
4472 isum = idx + ent.vd_aux;
4474 for (j = 1; j < ent.vd_cnt; j ++)
4476 isum += aux.vda_next;
4477 vstart += aux.vda_next;
4479 eaux = (Elf_External_Verdaux *) vstart;
4481 aux.vda_name = BYTE_GET (eaux->vda_name);
4482 aux.vda_next = BYTE_GET (eaux->vda_next);
4484 if (dynamic_strings)
4485 printf (_(" %#06x: Parent %d: %s\n"),
4486 isum, j, dynamic_strings + aux.vda_name);
4488 printf (_(" %#06x: Parent %d, name index: %ld\n"),
4489 isum, j, aux.vda_name);
4499 case SHT_GNU_verneed:
4501 Elf_External_Verneed * eneed;
4507 printf (_("\nVersion needs section '%s' contains %ld entries:\n"),
4508 SECTION_NAME (section), section->sh_info);
4510 printf (_(" Addr: 0x"));
4511 printf_vma (section->sh_addr);
4512 printf (_(" Offset: %#08lx Link to section: %ld (%s)\n"),
4513 (unsigned long) section->sh_offset, section->sh_link,
4514 SECTION_NAME (section_headers + section->sh_link));
4516 eneed = ((Elf_External_Verneed *)
4517 get_data (NULL, file, section->sh_offset,
4518 section->sh_size, _("version need section")));
4522 for (idx = cnt = 0; cnt < section->sh_info; ++cnt)
4524 Elf_External_Verneed * entry;
4525 Elf_Internal_Verneed ent;
4530 vstart = ((char *) eneed) + idx;
4532 entry = (Elf_External_Verneed *) vstart;
4534 ent.vn_version = BYTE_GET (entry->vn_version);
4535 ent.vn_cnt = BYTE_GET (entry->vn_cnt);
4536 ent.vn_file = BYTE_GET (entry->vn_file);
4537 ent.vn_aux = BYTE_GET (entry->vn_aux);
4538 ent.vn_next = BYTE_GET (entry->vn_next);
4540 printf (_(" %#06x: Version: %d"), idx, ent.vn_version);
4542 if (dynamic_strings)
4543 printf (_(" File: %s"), dynamic_strings + ent.vn_file);
4545 printf (_(" File: %lx"), ent.vn_file);
4547 printf (_(" Cnt: %d\n"), ent.vn_cnt);
4549 vstart += ent.vn_aux;
4551 for (j = 0, isum = idx + ent.vn_aux; j < ent.vn_cnt; ++j)
4553 Elf_External_Vernaux * eaux;
4554 Elf_Internal_Vernaux aux;
4556 eaux = (Elf_External_Vernaux *) vstart;
4558 aux.vna_hash = BYTE_GET (eaux->vna_hash);
4559 aux.vna_flags = BYTE_GET (eaux->vna_flags);
4560 aux.vna_other = BYTE_GET (eaux->vna_other);
4561 aux.vna_name = BYTE_GET (eaux->vna_name);
4562 aux.vna_next = BYTE_GET (eaux->vna_next);
4564 if (dynamic_strings)
4565 printf (_(" %#06x: Name: %s"),
4566 isum, dynamic_strings + aux.vna_name);
4568 printf (_(" %#06x: Name index: %lx"),
4569 isum, aux.vna_name);
4571 printf (_(" Flags: %s Version: %d\n"),
4572 get_ver_flags (aux.vna_flags), aux.vna_other);
4574 isum += aux.vna_next;
4575 vstart += aux.vna_next;
4585 case SHT_GNU_versym:
4587 Elf32_Internal_Shdr * link_section;
4590 unsigned char * edata;
4591 unsigned short * data;
4593 Elf_Internal_Sym * symbols;
4594 Elf32_Internal_Shdr * string_sec;
4596 link_section = section_headers + section->sh_link;
4597 total = section->sh_size / section->sh_entsize;
4601 symbols = GET_ELF_SYMBOLS (file, link_section->sh_offset,
4602 link_section->sh_size / link_section->sh_entsize);
4604 string_sec = section_headers + link_section->sh_link;
4606 strtab = (char *) get_data (NULL, file, string_sec->sh_offset,
4607 string_sec->sh_size,
4608 _("version string table"));
4612 printf (_("\nVersion symbols section '%s' contains %d entries:\n"),
4613 SECTION_NAME (section), total);
4615 printf (_(" Addr: "));
4616 printf_vma (section->sh_addr);
4617 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
4618 (unsigned long) section->sh_offset, section->sh_link,
4619 SECTION_NAME (link_section));
4623 get_data (NULL, file,
4624 version_info[DT_VERSIONTAGIDX (DT_VERSYM)] - loadaddr,
4625 total * sizeof (short), _("version symbol data")));
4632 data = (unsigned short *) malloc (total * sizeof (short));
4634 for (cnt = total; cnt --;)
4635 data [cnt] = byte_get (edata + cnt * sizeof (short),
4640 for (cnt = 0; cnt < total; cnt += 4)
4643 int check_def, check_need;
4646 printf (" %03x:", cnt);
4648 for (j = 0; (j < 4) && (cnt + j) < total; ++j)
4649 switch (data [cnt + j])
4652 fputs (_(" 0 (*local*) "), stdout);
4656 fputs (_(" 1 (*global*) "), stdout);
4660 nn = printf ("%4x%c", data [cnt + j] & 0x7fff,
4661 data [cnt + j] & 0x8000 ? 'h' : ' ');
4665 if (symbols [cnt + j].st_shndx >= SHN_LORESERVE
4666 || section_headers[symbols [cnt + j].st_shndx].sh_type
4669 if (symbols [cnt + j].st_shndx == SHN_UNDEF)
4676 && version_info [DT_VERSIONTAGIDX (DT_VERNEED)])
4678 Elf_Internal_Verneed ivn;
4679 unsigned long offset;
4681 offset = version_info [DT_VERSIONTAGIDX (DT_VERNEED)]
4686 Elf_Internal_Vernaux ivna;
4687 Elf_External_Verneed evn;
4688 Elf_External_Vernaux evna;
4689 unsigned long a_off;
4691 get_data (&evn, file, offset, sizeof (evn),
4694 ivn.vn_aux = BYTE_GET (evn.vn_aux);
4695 ivn.vn_next = BYTE_GET (evn.vn_next);
4697 a_off = offset + ivn.vn_aux;
4701 get_data (&evna, file, a_off, sizeof (evna),
4702 _("version need aux (2)"));
4704 ivna.vna_next = BYTE_GET (evna.vna_next);
4705 ivna.vna_other = BYTE_GET (evna.vna_other);
4707 a_off += ivna.vna_next;
4709 while (ivna.vna_other != data [cnt + j]
4710 && ivna.vna_next != 0);
4712 if (ivna.vna_other == data [cnt + j])
4714 ivna.vna_name = BYTE_GET (evna.vna_name);
4716 name = strtab + ivna.vna_name;
4717 nn += printf ("(%s%-*s",
4719 12 - (int) strlen (name),
4725 offset += ivn.vn_next;
4727 while (ivn.vn_next);
4730 if (check_def && data [cnt + j] != 0x8001
4731 && version_info [DT_VERSIONTAGIDX (DT_VERDEF)])
4733 Elf_Internal_Verdef ivd;
4734 Elf_External_Verdef evd;
4735 unsigned long offset;
4737 offset = version_info
4738 [DT_VERSIONTAGIDX (DT_VERDEF)] - loadaddr;
4742 get_data (&evd, file, offset, sizeof (evd),
4745 ivd.vd_next = BYTE_GET (evd.vd_next);
4746 ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
4748 offset += ivd.vd_next;
4750 while (ivd.vd_ndx != (data [cnt + j] & 0x7fff)
4751 && ivd.vd_next != 0);
4753 if (ivd.vd_ndx == (data [cnt + j] & 0x7fff))
4755 Elf_External_Verdaux evda;
4756 Elf_Internal_Verdaux ivda;
4758 ivd.vd_aux = BYTE_GET (evd.vd_aux);
4760 get_data (&evda, file,
4761 offset - ivd.vd_next + ivd.vd_aux,
4762 sizeof (evda), _("version def aux"));
4764 ivda.vda_name = BYTE_GET (evda.vda_name);
4766 name = strtab + ivda.vda_name;
4767 nn += printf ("(%s%-*s",
4769 12 - (int) strlen (name),
4775 printf ("%*c", 18 - nn, ' ');
4793 printf (_("\nNo version information found in this file.\n"));
4799 get_symbol_binding (binding)
4800 unsigned int binding;
4802 static char buff [32];
4806 case STB_LOCAL: return "LOCAL";
4807 case STB_GLOBAL: return "GLOBAL";
4808 case STB_WEAK: return "WEAK";
4810 if (binding >= STB_LOPROC && binding <= STB_HIPROC)
4811 sprintf (buff, _("<processor specific>: %d"), binding);
4812 else if (binding >= STB_LOOS && binding <= STB_HIOS)
4813 sprintf (buff, _("<OS specific>: %d"), binding);
4815 sprintf (buff, _("<unknown>: %d"), binding);
4821 get_symbol_type (type)
4824 static char buff [32];
4828 case STT_NOTYPE: return "NOTYPE";
4829 case STT_OBJECT: return "OBJECT";
4830 case STT_FUNC: return "FUNC";
4831 case STT_SECTION: return "SECTION";
4832 case STT_FILE: return "FILE";
4833 case STT_COMMON: return "COMMON";
4835 if (type >= STT_LOPROC && type <= STT_HIPROC)
4837 if (elf_header.e_machine == EM_ARM && type == STT_ARM_TFUNC)
4838 return "THUMB_FUNC";
4840 if (elf_header.e_machine == EM_SPARCV9 && type == STT_REGISTER)
4843 if (elf_header.e_machine == EM_PARISC && type == STT_PARISC_MILLI)
4844 return "PARISC_MILLI";
4846 sprintf (buff, _("<processor specific>: %d"), type);
4848 else if (type >= STT_LOOS && type <= STT_HIOS)
4850 if (elf_header.e_machine == EM_PARISC)
4852 if (type == STT_HP_OPAQUE)
4854 if (type == STT_HP_STUB)
4858 sprintf (buff, _("<OS specific>: %d"), type);
4861 sprintf (buff, _("<unknown>: %d"), type);
4867 get_symbol_visibility (visibility)
4868 unsigned int visibility;
4872 case STV_DEFAULT: return "DEFAULT";
4873 case STV_INTERNAL: return "INTERNAL";
4874 case STV_HIDDEN: return "HIDDEN";
4875 case STV_PROTECTED: return "PROTECTED";
4881 get_symbol_index_type (type)
4886 case SHN_UNDEF: return "UND";
4887 case SHN_ABS: return "ABS";
4888 case SHN_COMMON: return "COM";
4890 if (type >= SHN_LOPROC && type <= SHN_HIPROC)
4892 else if (type >= SHN_LORESERVE && type <= SHN_HIRESERVE)
4894 else if (type >= SHN_LOOS && type <= SHN_HIOS)
4898 static char buff [32];
4900 sprintf (buff, "%3d", type);
4907 get_dynamic_data (file, number)
4909 unsigned int number;
4911 unsigned char * e_data;
4914 e_data = (unsigned char *) malloc (number * 4);
4918 error (_("Out of memory\n"));
4922 if (fread (e_data, 4, number, file) != number)
4924 error (_("Unable to read in dynamic data\n"));
4928 i_data = (int *) malloc (number * sizeof (* i_data));
4932 error (_("Out of memory\n"));
4938 i_data [number] = byte_get (e_data + number * 4, 4);
4945 /* Dump the symbol table */
4947 process_symbol_table (file)
4950 Elf32_Internal_Shdr * section;
4951 unsigned char nb [4];
4952 unsigned char nc [4];
4955 int * buckets = NULL;
4956 int * chains = NULL;
4958 if (! do_syms && !do_histogram)
4961 if (dynamic_info[DT_HASH] && ((do_using_dynamic && dynamic_strings != NULL)
4964 if (fseek (file, dynamic_info[DT_HASH] - loadaddr, SEEK_SET))
4966 error (_("Unable to seek to start of dynamic information"));
4970 if (fread (nb, sizeof (nb), 1, file) != 1)
4972 error (_("Failed to read in number of buckets\n"));
4976 if (fread (nc, sizeof (nc), 1, file) != 1)
4978 error (_("Failed to read in number of chains\n"));
4982 nbuckets = byte_get (nb, 4);
4983 nchains = byte_get (nc, 4);
4985 buckets = get_dynamic_data (file, nbuckets);
4986 chains = get_dynamic_data (file, nchains);
4988 if (buckets == NULL || chains == NULL)
4993 && dynamic_info[DT_HASH] && do_using_dynamic && dynamic_strings != NULL)
4998 printf (_("\nSymbol table for image:\n"));
5000 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
5002 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
5004 for (hn = 0; hn < nbuckets; hn++)
5009 for (si = buckets [hn]; si < nchains && si > 0; si = chains [si])
5011 Elf_Internal_Sym * psym;
5013 psym = dynamic_symbols + si;
5015 printf (" %3d %3d: ", si, hn);
5016 print_vma (psym->st_value, LONG_HEX);
5018 print_vma (psym->st_size, DEC_5);
5020 printf (" %6s", get_symbol_type (ELF_ST_TYPE (psym->st_info)));
5021 printf (" %6s", get_symbol_binding (ELF_ST_BIND (psym->st_info)));
5022 printf (" %3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym->st_other)));
5023 printf (" %3.3s", get_symbol_index_type (psym->st_shndx));
5024 printf (" %s\n", dynamic_strings + psym->st_name);
5028 else if (do_syms && !do_using_dynamic)
5032 for (i = 0, section = section_headers;
5033 i < elf_header.e_shnum;
5038 Elf_Internal_Sym * symtab;
5039 Elf_Internal_Sym * psym;
5042 if ( section->sh_type != SHT_SYMTAB
5043 && section->sh_type != SHT_DYNSYM)
5046 printf (_("\nSymbol table '%s' contains %lu entries:\n"),
5047 SECTION_NAME (section),
5048 (unsigned long) (section->sh_size / section->sh_entsize));
5050 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
5052 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
5054 symtab = GET_ELF_SYMBOLS (file, section->sh_offset,
5055 section->sh_size / section->sh_entsize);
5059 if (section->sh_link == elf_header.e_shstrndx)
5060 strtab = string_table;
5063 Elf32_Internal_Shdr * string_sec;
5065 string_sec = section_headers + section->sh_link;
5067 strtab = (char *) get_data (NULL, file, string_sec->sh_offset,
5068 string_sec->sh_size,
5072 for (si = 0, psym = symtab;
5073 si < section->sh_size / section->sh_entsize;
5076 printf ("%6d: ", si);
5077 print_vma (psym->st_value, LONG_HEX);
5079 print_vma (psym->st_size, DEC_5);
5080 printf (" %-7s", get_symbol_type (ELF_ST_TYPE (psym->st_info)));
5081 printf (" %-6s", get_symbol_binding (ELF_ST_BIND (psym->st_info)));
5082 printf (" %-3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym->st_other)));
5083 printf (" %4s", get_symbol_index_type (psym->st_shndx));
5084 printf (" %s", strtab + psym->st_name);
5086 if (section->sh_type == SHT_DYNSYM &&
5087 version_info [DT_VERSIONTAGIDX (DT_VERSYM)] != 0)
5089 unsigned char data[2];
5090 unsigned short vers_data;
5091 unsigned long offset;
5095 offset = version_info [DT_VERSIONTAGIDX (DT_VERSYM)]
5098 get_data (&data, file, offset + si * sizeof (vers_data),
5099 sizeof (data), _("version data"));
5101 vers_data = byte_get (data, 2);
5103 is_nobits = psym->st_shndx < SHN_LORESERVE ?
5104 (section_headers [psym->st_shndx].sh_type == SHT_NOBITS)
5107 check_def = (psym->st_shndx != SHN_UNDEF);
5109 if ((vers_data & 0x8000) || vers_data > 1)
5111 if (version_info [DT_VERSIONTAGIDX (DT_VERNEED)]
5112 && (is_nobits || ! check_def))
5114 Elf_External_Verneed evn;
5115 Elf_Internal_Verneed ivn;
5116 Elf_Internal_Vernaux ivna;
5118 /* We must test both. */
5119 offset = version_info
5120 [DT_VERSIONTAGIDX (DT_VERNEED)] - loadaddr;
5124 unsigned long vna_off;
5126 get_data (&evn, file, offset, sizeof (evn),
5129 ivn.vn_aux = BYTE_GET (evn.vn_aux);
5130 ivn.vn_next = BYTE_GET (evn.vn_next);
5132 vna_off = offset + ivn.vn_aux;
5136 Elf_External_Vernaux evna;
5138 get_data (&evna, file, vna_off,
5140 _("version need aux (3)"));
5142 ivna.vna_other = BYTE_GET (evna.vna_other);
5143 ivna.vna_next = BYTE_GET (evna.vna_next);
5144 ivna.vna_name = BYTE_GET (evna.vna_name);
5146 vna_off += ivna.vna_next;
5148 while (ivna.vna_other != vers_data
5149 && ivna.vna_next != 0);
5151 if (ivna.vna_other == vers_data)
5154 offset += ivn.vn_next;
5156 while (ivn.vn_next != 0);
5158 if (ivna.vna_other == vers_data)
5161 strtab + ivna.vna_name, ivna.vna_other);
5164 else if (! is_nobits)
5165 error (_("bad dynamic symbol"));
5172 if (vers_data != 0x8001
5173 && version_info [DT_VERSIONTAGIDX (DT_VERDEF)])
5175 Elf_Internal_Verdef ivd;
5176 Elf_Internal_Verdaux ivda;
5177 Elf_External_Verdaux evda;
5178 unsigned long offset;
5181 version_info [DT_VERSIONTAGIDX (DT_VERDEF)]
5186 Elf_External_Verdef evd;
5188 get_data (&evd, file, offset, sizeof (evd),
5191 ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
5192 ivd.vd_aux = BYTE_GET (evd.vd_aux);
5193 ivd.vd_next = BYTE_GET (evd.vd_next);
5195 offset += ivd.vd_next;
5197 while (ivd.vd_ndx != (vers_data & 0x7fff)
5198 && ivd.vd_next != 0);
5200 offset -= ivd.vd_next;
5201 offset += ivd.vd_aux;
5203 get_data (&evda, file, offset, sizeof (evda),
5204 _("version def aux"));
5206 ivda.vda_name = BYTE_GET (evda.vda_name);
5208 if (psym->st_name != ivda.vda_name)
5209 printf ((vers_data & 0x8000)
5211 strtab + ivda.vda_name);
5221 if (strtab != string_table)
5227 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
5229 if (do_histogram && buckets != NULL)
5236 int nzero_counts = 0;
5239 printf (_("\nHistogram for bucket list length (total of %d buckets):\n"),
5241 printf (_(" Length Number %% of total Coverage\n"));
5243 lengths = (int *) calloc (nbuckets, sizeof (int));
5244 if (lengths == NULL)
5246 error (_("Out of memory"));
5249 for (hn = 0; hn < nbuckets; ++hn)
5254 for (si = buckets[hn]; si > 0 && si < nchains; si = chains[si])
5257 if (maxlength < ++lengths[hn])
5262 counts = (int *) calloc (maxlength + 1, sizeof (int));
5265 error (_("Out of memory"));
5269 for (hn = 0; hn < nbuckets; ++hn)
5270 ++ counts [lengths [hn]];
5274 printf (" 0 %-10d (%5.1f%%)\n",
5275 counts[0], (counts[0] * 100.0) / nbuckets);
5276 for (si = 1; si <= maxlength; ++si)
5278 nzero_counts += counts[si] * si;
5279 printf ("%7d %-10d (%5.1f%%) %5.1f%%\n",
5280 si, counts[si], (counts[si] * 100.0) / nbuckets,
5281 (nzero_counts * 100.0) / nsyms);
5289 if (buckets != NULL)
5299 process_syminfo (file)
5300 FILE * file ATTRIBUTE_UNUSED;
5304 if (dynamic_syminfo == NULL
5306 /* No syminfo, this is ok. */
5309 /* There better should be a dynamic symbol section. */
5310 if (dynamic_symbols == NULL || dynamic_strings == NULL)
5314 printf (_("\nDynamic info segment at offset 0x%lx contains %d entries:\n"),
5315 dynamic_syminfo_offset, dynamic_syminfo_nent);
5317 printf (_(" Num: Name BoundTo Flags\n"));
5318 for (i = 0; i < dynamic_syminfo_nent; ++i)
5320 unsigned short int flags = dynamic_syminfo[i].si_flags;
5322 printf ("%4d: %-30s ", i,
5323 dynamic_strings + dynamic_symbols[i].st_name);
5325 switch (dynamic_syminfo[i].si_boundto)
5327 case SYMINFO_BT_SELF:
5328 fputs ("SELF ", stdout);
5330 case SYMINFO_BT_PARENT:
5331 fputs ("PARENT ", stdout);
5334 if (dynamic_syminfo[i].si_boundto > 0
5335 && dynamic_syminfo[i].si_boundto < dynamic_size)
5338 + dynamic_segment[dynamic_syminfo[i].si_boundto].d_un.d_val);
5340 printf ("%-10d ", dynamic_syminfo[i].si_boundto);
5344 if (flags & SYMINFO_FLG_DIRECT)
5346 if (flags & SYMINFO_FLG_PASSTHRU)
5347 printf (" PASSTHRU");
5348 if (flags & SYMINFO_FLG_COPY)
5350 if (flags & SYMINFO_FLG_LAZYLOAD)
5351 printf (" LAZYLOAD");
5359 #ifdef SUPPORT_DISASSEMBLY
5361 disassemble_section (section, file)
5362 Elf32_Internal_Shdr * section;
5365 printf (_("\nAssembly dump of section %s\n"),
5366 SECTION_NAME (section));
5368 /* XXX -- to be done --- XXX */
5375 dump_section (section, file)
5376 Elf32_Internal_Shdr * section;
5379 bfd_size_type bytes;
5381 unsigned char * data;
5382 unsigned char * start;
5384 bytes = section->sh_size;
5388 printf (_("\nSection '%s' has no data to dump.\n"),
5389 SECTION_NAME (section));
5393 printf (_("\nHex dump of section '%s':\n"), SECTION_NAME (section));
5395 addr = section->sh_addr;
5397 start = (unsigned char *) get_data (NULL, file, section->sh_offset, bytes,
5410 lbytes = (bytes > 16 ? 16 : bytes);
5412 printf (" 0x%8.8lx ", (unsigned long) addr);
5414 switch (elf_header.e_ident [EI_DATA])
5418 for (j = 15; j >= 0; j --)
5421 printf ("%2.2x", data [j]);
5431 for (j = 0; j < 16; j++)
5434 printf ("%2.2x", data [j]);
5444 for (j = 0; j < lbytes; j++)
5447 if (k >= ' ' && k < 0x80)
5466 static unsigned long int
5467 read_leb128 (data, length_return, sign)
5468 unsigned char * data;
5469 int * length_return;
5472 unsigned long int result = 0;
5473 unsigned int num_read = 0;
5482 result |= (byte & 0x7f) << shift;
5487 while (byte & 0x80);
5489 if (length_return != NULL)
5490 * length_return = num_read;
5492 if (sign && (shift < 32) && (byte & 0x40))
5493 result |= -1 << shift;
5498 typedef struct State_Machine_Registers
5500 unsigned long address;
5503 unsigned int column;
5507 /* This variable hold the number of the last entry seen
5508 in the File Table. */
5509 unsigned int last_file_entry;
5512 static SMR state_machine_regs;
5515 reset_state_machine (is_stmt)
5518 state_machine_regs.address = 0;
5519 state_machine_regs.file = 1;
5520 state_machine_regs.line = 1;
5521 state_machine_regs.column = 0;
5522 state_machine_regs.is_stmt = is_stmt;
5523 state_machine_regs.basic_block = 0;
5524 state_machine_regs.end_sequence = 0;
5525 state_machine_regs.last_file_entry = 0;
5528 /* Handled an extend line op. Returns true if this is the end
5531 process_extended_line_op (data, is_stmt, pointer_size)
5532 unsigned char * data;
5536 unsigned char op_code;
5539 unsigned char * name;
5542 len = read_leb128 (data, & bytes_read, 0);
5547 warn (_("badly formed extended line op encountered!"));
5552 op_code = * data ++;
5554 printf (_(" Extended opcode %d: "), op_code);
5558 case DW_LNE_end_sequence:
5559 printf (_("End of Sequence\n\n"));
5560 reset_state_machine (is_stmt);
5563 case DW_LNE_set_address:
5564 adr = byte_get (data, pointer_size);
5565 printf (_("set Address to 0x%lx\n"), adr);
5566 state_machine_regs.address = adr;
5569 case DW_LNE_define_file:
5570 printf (_(" define new File Table entry\n"));
5571 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
5573 printf (_(" %d\t"), ++ state_machine_regs.last_file_entry);
5575 data += strlen ((char *) data) + 1;
5576 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
5578 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
5580 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
5581 printf (_("%s\n\n"), name);
5585 printf (_("UNKNOWN: length %d\n"), len - bytes_read);
5592 /* Size of pointers in the .debug_line section. This information is not
5593 really present in that section. It's obtained before dumping the debug
5594 sections by doing some pre-scan of the .debug_info section. */
5595 static int debug_line_pointer_size = 4;
5598 display_debug_lines (section, start, file)
5599 Elf32_Internal_Shdr * section;
5600 unsigned char * start;
5601 FILE * file ATTRIBUTE_UNUSED;
5603 DWARF2_External_LineInfo * external;
5604 DWARF2_Internal_LineInfo info;
5605 unsigned char * standard_opcodes;
5606 unsigned char * data = start;
5607 unsigned char * end = start + section->sh_size;
5608 unsigned char * end_of_sequence;
5611 printf (_("\nDump of debug contents of section %s:\n\n"),
5612 SECTION_NAME (section));
5616 external = (DWARF2_External_LineInfo *) data;
5618 /* Check the length of the block. */
5619 info.li_length = BYTE_GET (external->li_length);
5620 if (info.li_length + sizeof (external->li_length) > section->sh_size)
5623 (_("The line info appears to be corrupt - the section is too small\n"));
5627 /* Check its version number. */
5628 info.li_version = BYTE_GET (external->li_version);
5629 if (info.li_version != 2)
5631 warn (_("Only DWARF version 2 line info is currently supported.\n"));
5635 info.li_prologue_length = BYTE_GET (external->li_prologue_length);
5636 info.li_min_insn_length = BYTE_GET (external->li_min_insn_length);
5637 info.li_default_is_stmt = BYTE_GET (external->li_default_is_stmt);
5638 info.li_line_base = BYTE_GET (external->li_line_base);
5639 info.li_line_range = BYTE_GET (external->li_line_range);
5640 info.li_opcode_base = BYTE_GET (external->li_opcode_base);
5642 /* Sign extend the line base field. */
5643 info.li_line_base <<= 24;
5644 info.li_line_base >>= 24;
5646 printf (_(" Length: %ld\n"), info.li_length);
5647 printf (_(" DWARF Version: %d\n"), info.li_version);
5648 printf (_(" Prologue Length: %d\n"), info.li_prologue_length);
5649 printf (_(" Minimum Instruction Length: %d\n"), info.li_min_insn_length);
5650 printf (_(" Initial value of 'is_stmt': %d\n"), info.li_default_is_stmt);
5651 printf (_(" Line Base: %d\n"), info.li_line_base);
5652 printf (_(" Line Range: %d\n"), info.li_line_range);
5653 printf (_(" Opcode Base: %d\n"), info.li_opcode_base);
5655 end_of_sequence = data + info.li_length + sizeof (external->li_length);
5657 reset_state_machine (info.li_default_is_stmt);
5659 /* Display the contents of the Opcodes table. */
5660 standard_opcodes = data + sizeof (* external);
5662 printf (_("\n Opcodes:\n"));
5664 for (i = 1; i < info.li_opcode_base; i++)
5665 printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]);
5667 /* Display the contents of the Directory table. */
5668 data = standard_opcodes + info.li_opcode_base - 1;
5671 printf (_("\n The Directory Table is empty.\n"));
5674 printf (_("\n The Directory Table:\n"));
5678 printf (_(" %s\n"), data);
5680 data += strlen ((char *) data) + 1;
5684 /* Skip the NUL at the end of the table. */
5687 /* Display the contents of the File Name table. */
5689 printf (_("\n The File Name Table is empty.\n"));
5692 printf (_("\n The File Name Table:\n"));
5693 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
5697 unsigned char * name;
5700 printf (_(" %d\t"), ++ state_machine_regs.last_file_entry);
5703 data += strlen ((char *) data) + 1;
5705 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
5707 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
5709 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
5711 printf (_("%s\n"), name);
5715 /* Skip the NUL at the end of the table. */
5718 /* Now display the statements. */
5719 printf (_("\n Line Number Statements:\n"));
5722 while (data < end_of_sequence)
5724 unsigned char op_code;
5728 op_code = * data ++;
5732 case DW_LNS_extended_op:
5733 data += process_extended_line_op (data, info.li_default_is_stmt,
5734 debug_line_pointer_size);
5738 printf (_(" Copy\n"));
5741 case DW_LNS_advance_pc:
5742 adv = info.li_min_insn_length * read_leb128 (data, & bytes_read, 0);
5744 state_machine_regs.address += adv;
5745 printf (_(" Advance PC by %d to %lx\n"), adv,
5746 state_machine_regs.address);
5749 case DW_LNS_advance_line:
5750 adv = read_leb128 (data, & bytes_read, 1);
5752 state_machine_regs.line += adv;
5753 printf (_(" Advance Line by %d to %d\n"), adv,
5754 state_machine_regs.line);
5757 case DW_LNS_set_file:
5758 adv = read_leb128 (data, & bytes_read, 0);
5760 printf (_(" Set File Name to entry %d in the File Name Table\n"),
5762 state_machine_regs.file = adv;
5765 case DW_LNS_set_column:
5766 adv = read_leb128 (data, & bytes_read, 0);
5768 printf (_(" Set column to %d\n"), adv);
5769 state_machine_regs.column = adv;
5772 case DW_LNS_negate_stmt:
5773 adv = state_machine_regs.is_stmt;
5775 printf (_(" Set is_stmt to %d\n"), adv);
5776 state_machine_regs.is_stmt = adv;
5779 case DW_LNS_set_basic_block:
5780 printf (_(" Set basic block\n"));
5781 state_machine_regs.basic_block = 1;
5784 case DW_LNS_const_add_pc:
5785 adv = (((255 - info.li_opcode_base) / info.li_line_range)
5786 * info.li_min_insn_length);
5787 state_machine_regs.address += adv;
5788 printf (_(" Advance PC by constant %d to 0x%lx\n"), adv,
5789 state_machine_regs.address);
5792 case DW_LNS_fixed_advance_pc:
5793 adv = byte_get (data, 2);
5795 state_machine_regs.address += adv;
5796 printf (_(" Advance PC by fixed size amount %d to 0x%lx\n"),
5797 adv, state_machine_regs.address);
5801 op_code -= info.li_opcode_base;
5802 adv = (op_code / info.li_line_range) * info.li_min_insn_length;
5803 state_machine_regs.address += adv;
5804 printf (_(" Special opcode %d: advance Address by %d to 0x%lx"),
5805 op_code, adv, state_machine_regs.address);
5806 adv = (op_code % info.li_line_range) + info.li_line_base;
5807 state_machine_regs.line += adv;
5808 printf (_(" and Line by %d to %d\n"),
5809 adv, state_machine_regs.line);
5820 display_debug_pubnames (section, start, file)
5821 Elf32_Internal_Shdr * section;
5822 unsigned char * start;
5823 FILE * file ATTRIBUTE_UNUSED;
5825 DWARF2_External_PubNames * external;
5826 DWARF2_Internal_PubNames pubnames;
5827 unsigned char * end;
5829 end = start + section->sh_size;
5831 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section));
5835 unsigned char * data;
5836 unsigned long offset;
5838 external = (DWARF2_External_PubNames *) start;
5840 pubnames.pn_length = BYTE_GET (external->pn_length);
5841 pubnames.pn_version = BYTE_GET (external->pn_version);
5842 pubnames.pn_offset = BYTE_GET (external->pn_offset);
5843 pubnames.pn_size = BYTE_GET (external->pn_size);
5845 data = start + sizeof (* external);
5846 start += pubnames.pn_length + sizeof (external->pn_length);
5848 if (pubnames.pn_version != 2)
5850 static int warned = 0;
5854 warn (_("Only DWARF 2 pubnames are currently supported\n"));
5861 printf (_(" Length: %ld\n"),
5862 pubnames.pn_length);
5863 printf (_(" Version: %d\n"),
5864 pubnames.pn_version);
5865 printf (_(" Offset into .debug_info section: %ld\n"),
5866 pubnames.pn_offset);
5867 printf (_(" Size of area in .debug_info section: %ld\n"),
5870 printf (_("\n Offset\tName\n"));
5874 offset = byte_get (data, 4);
5879 printf (" %ld\t\t%s\n", offset, data);
5880 data += strlen ((char *) data) + 1;
5883 while (offset != 0);
5896 case DW_TAG_padding: return "DW_TAG_padding";
5897 case DW_TAG_array_type: return "DW_TAG_array_type";
5898 case DW_TAG_class_type: return "DW_TAG_class_type";
5899 case DW_TAG_entry_point: return "DW_TAG_entry_point";
5900 case DW_TAG_enumeration_type: return "DW_TAG_enumeration_type";
5901 case DW_TAG_formal_parameter: return "DW_TAG_formal_parameter";
5902 case DW_TAG_imported_declaration: return "DW_TAG_imported_declaration";
5903 case DW_TAG_label: return "DW_TAG_label";
5904 case DW_TAG_lexical_block: return "DW_TAG_lexical_block";
5905 case DW_TAG_member: return "DW_TAG_member";
5906 case DW_TAG_pointer_type: return "DW_TAG_pointer_type";
5907 case DW_TAG_reference_type: return "DW_TAG_reference_type";
5908 case DW_TAG_compile_unit: return "DW_TAG_compile_unit";
5909 case DW_TAG_string_type: return "DW_TAG_string_type";
5910 case DW_TAG_structure_type: return "DW_TAG_structure_type";
5911 case DW_TAG_subroutine_type: return "DW_TAG_subroutine_type";
5912 case DW_TAG_typedef: return "DW_TAG_typedef";
5913 case DW_TAG_union_type: return "DW_TAG_union_type";
5914 case DW_TAG_unspecified_parameters: return "DW_TAG_unspecified_parameters";
5915 case DW_TAG_variant: return "DW_TAG_variant";
5916 case DW_TAG_common_block: return "DW_TAG_common_block";
5917 case DW_TAG_common_inclusion: return "DW_TAG_common_inclusion";
5918 case DW_TAG_inheritance: return "DW_TAG_inheritance";
5919 case DW_TAG_inlined_subroutine: return "DW_TAG_inlined_subroutine";
5920 case DW_TAG_module: return "DW_TAG_module";
5921 case DW_TAG_ptr_to_member_type: return "DW_TAG_ptr_to_member_type";
5922 case DW_TAG_set_type: return "DW_TAG_set_type";
5923 case DW_TAG_subrange_type: return "DW_TAG_subrange_type";
5924 case DW_TAG_with_stmt: return "DW_TAG_with_stmt";
5925 case DW_TAG_access_declaration: return "DW_TAG_access_declaration";
5926 case DW_TAG_base_type: return "DW_TAG_base_type";
5927 case DW_TAG_catch_block: return "DW_TAG_catch_block";
5928 case DW_TAG_const_type: return "DW_TAG_const_type";
5929 case DW_TAG_constant: return "DW_TAG_constant";
5930 case DW_TAG_enumerator: return "DW_TAG_enumerator";
5931 case DW_TAG_file_type: return "DW_TAG_file_type";
5932 case DW_TAG_friend: return "DW_TAG_friend";
5933 case DW_TAG_namelist: return "DW_TAG_namelist";
5934 case DW_TAG_namelist_item: return "DW_TAG_namelist_item";
5935 case DW_TAG_packed_type: return "DW_TAG_packed_type";
5936 case DW_TAG_subprogram: return "DW_TAG_subprogram";
5937 case DW_TAG_template_type_param: return "DW_TAG_template_type_param";
5938 case DW_TAG_template_value_param: return "DW_TAG_template_value_param";
5939 case DW_TAG_thrown_type: return "DW_TAG_thrown_type";
5940 case DW_TAG_try_block: return "DW_TAG_try_block";
5941 case DW_TAG_variant_part: return "DW_TAG_variant_part";
5942 case DW_TAG_variable: return "DW_TAG_variable";
5943 case DW_TAG_volatile_type: return "DW_TAG_volatile_type";
5944 case DW_TAG_MIPS_loop: return "DW_TAG_MIPS_loop";
5945 case DW_TAG_format_label: return "DW_TAG_format_label";
5946 case DW_TAG_function_template: return "DW_TAG_function_template";
5947 case DW_TAG_class_template: return "DW_TAG_class_template";
5948 /* DWARF 2.1 values. */
5949 case DW_TAG_dwarf_procedure: return "DW_TAG_dwarf_procedure";
5950 case DW_TAG_restrict_type: return "DW_TAG_restrict_type";
5951 case DW_TAG_interface_type: return "DW_TAG_interface_type";
5952 case DW_TAG_namespace: return "DW_TAG_namespace";
5953 case DW_TAG_imported_module: return "DW_TAG_imported_module";
5954 case DW_TAG_unspecified_type: return "DW_TAG_unspecified_type";
5955 case DW_TAG_partial_unit: return "DW_TAG_partial_unit";
5956 case DW_TAG_imported_unit: return "DW_TAG_imported_unit";
5959 static char buffer [100];
5961 sprintf (buffer, _("Unknown TAG value: %lx"), tag);
5968 get_AT_name (attribute)
5969 unsigned long attribute;
5973 case DW_AT_sibling: return "DW_AT_sibling";
5974 case DW_AT_location: return "DW_AT_location";
5975 case DW_AT_name: return "DW_AT_name";
5976 case DW_AT_ordering: return "DW_AT_ordering";
5977 case DW_AT_subscr_data: return "DW_AT_subscr_data";
5978 case DW_AT_byte_size: return "DW_AT_byte_size";
5979 case DW_AT_bit_offset: return "DW_AT_bit_offset";
5980 case DW_AT_bit_size: return "DW_AT_bit_size";
5981 case DW_AT_element_list: return "DW_AT_element_list";
5982 case DW_AT_stmt_list: return "DW_AT_stmt_list";
5983 case DW_AT_low_pc: return "DW_AT_low_pc";
5984 case DW_AT_high_pc: return "DW_AT_high_pc";
5985 case DW_AT_language: return "DW_AT_language";
5986 case DW_AT_member: return "DW_AT_member";
5987 case DW_AT_discr: return "DW_AT_discr";
5988 case DW_AT_discr_value: return "DW_AT_discr_value";
5989 case DW_AT_visibility: return "DW_AT_visibility";
5990 case DW_AT_import: return "DW_AT_import";
5991 case DW_AT_string_length: return "DW_AT_string_length";
5992 case DW_AT_common_reference: return "DW_AT_common_reference";
5993 case DW_AT_comp_dir: return "DW_AT_comp_dir";
5994 case DW_AT_const_value: return "DW_AT_const_value";
5995 case DW_AT_containing_type: return "DW_AT_containing_type";
5996 case DW_AT_default_value: return "DW_AT_default_value";
5997 case DW_AT_inline: return "DW_AT_inline";
5998 case DW_AT_is_optional: return "DW_AT_is_optional";
5999 case DW_AT_lower_bound: return "DW_AT_lower_bound";
6000 case DW_AT_producer: return "DW_AT_producer";
6001 case DW_AT_prototyped: return "DW_AT_prototyped";
6002 case DW_AT_return_addr: return "DW_AT_return_addr";
6003 case DW_AT_start_scope: return "DW_AT_start_scope";
6004 case DW_AT_stride_size: return "DW_AT_stride_size";
6005 case DW_AT_upper_bound: return "DW_AT_upper_bound";
6006 case DW_AT_abstract_origin: return "DW_AT_abstract_origin";
6007 case DW_AT_accessibility: return "DW_AT_accessibility";
6008 case DW_AT_address_class: return "DW_AT_address_class";
6009 case DW_AT_artificial: return "DW_AT_artificial";
6010 case DW_AT_base_types: return "DW_AT_base_types";
6011 case DW_AT_calling_convention: return "DW_AT_calling_convention";
6012 case DW_AT_count: return "DW_AT_count";
6013 case DW_AT_data_member_location: return "DW_AT_data_member_location";
6014 case DW_AT_decl_column: return "DW_AT_decl_column";
6015 case DW_AT_decl_file: return "DW_AT_decl_file";
6016 case DW_AT_decl_line: return "DW_AT_decl_line";
6017 case DW_AT_declaration: return "DW_AT_declaration";
6018 case DW_AT_discr_list: return "DW_AT_discr_list";
6019 case DW_AT_encoding: return "DW_AT_encoding";
6020 case DW_AT_external: return "DW_AT_external";
6021 case DW_AT_frame_base: return "DW_AT_frame_base";
6022 case DW_AT_friend: return "DW_AT_friend";
6023 case DW_AT_identifier_case: return "DW_AT_identifier_case";
6024 case DW_AT_macro_info: return "DW_AT_macro_info";
6025 case DW_AT_namelist_items: return "DW_AT_namelist_items";
6026 case DW_AT_priority: return "DW_AT_priority";
6027 case DW_AT_segment: return "DW_AT_segment";
6028 case DW_AT_specification: return "DW_AT_specification";
6029 case DW_AT_static_link: return "DW_AT_static_link";
6030 case DW_AT_type: return "DW_AT_type";
6031 case DW_AT_use_location: return "DW_AT_use_location";
6032 case DW_AT_variable_parameter: return "DW_AT_variable_parameter";
6033 case DW_AT_virtuality: return "DW_AT_virtuality";
6034 case DW_AT_vtable_elem_location: return "DW_AT_vtable_elem_location";
6035 /* DWARF 2.1 values. */
6036 case DW_AT_allocated: return "DW_AT_allocated";
6037 case DW_AT_associated: return "DW_AT_associated";
6038 case DW_AT_data_location: return "DW_AT_data_location";
6039 case DW_AT_stride: return "DW_AT_stride";
6040 case DW_AT_entry_pc: return "DW_AT_entry_pc";
6041 case DW_AT_use_UTF8: return "DW_AT_use_UTF8";
6042 case DW_AT_extension: return "DW_AT_extension";
6043 case DW_AT_ranges: return "DW_AT_ranges";
6044 case DW_AT_trampoline: return "DW_AT_trampoline";
6045 case DW_AT_call_column: return "DW_AT_call_column";
6046 case DW_AT_call_file: return "DW_AT_call_file";
6047 case DW_AT_call_line: return "DW_AT_call_line";
6048 /* SGI/MIPS extensions. */
6049 case DW_AT_MIPS_fde: return "DW_AT_MIPS_fde";
6050 case DW_AT_MIPS_loop_begin: return "DW_AT_MIPS_loop_begin";
6051 case DW_AT_MIPS_tail_loop_begin: return "DW_AT_MIPS_tail_loop_begin";
6052 case DW_AT_MIPS_epilog_begin: return "DW_AT_MIPS_epilog_begin";
6053 case DW_AT_MIPS_loop_unroll_factor: return "DW_AT_MIPS_loop_unroll_factor";
6054 case DW_AT_MIPS_software_pipeline_depth: return "DW_AT_MIPS_software_pipeline_depth";
6055 case DW_AT_MIPS_linkage_name: return "DW_AT_MIPS_linkage_name";
6056 case DW_AT_MIPS_stride: return "DW_AT_MIPS_stride";
6057 case DW_AT_MIPS_abstract_name: return "DW_AT_MIPS_abstract_name";
6058 case DW_AT_MIPS_clone_origin: return "DW_AT_MIPS_clone_origin";
6059 case DW_AT_MIPS_has_inlines: return "DW_AT_MIPS_has_inlines";
6060 /* GNU extensions. */
6061 case DW_AT_sf_names: return "DW_AT_sf_names";
6062 case DW_AT_src_info: return "DW_AT_src_info";
6063 case DW_AT_mac_info: return "DW_AT_mac_info";
6064 case DW_AT_src_coords: return "DW_AT_src_coords";
6065 case DW_AT_body_begin: return "DW_AT_body_begin";
6066 case DW_AT_body_end: return "DW_AT_body_end";
6069 static char buffer [100];
6071 sprintf (buffer, _("Unknown AT value: %lx"), attribute);
6078 get_FORM_name (form)
6083 case DW_FORM_addr: return "DW_FORM_addr";
6084 case DW_FORM_block2: return "DW_FORM_block2";
6085 case DW_FORM_block4: return "DW_FORM_block4";
6086 case DW_FORM_data2: return "DW_FORM_data2";
6087 case DW_FORM_data4: return "DW_FORM_data4";
6088 case DW_FORM_data8: return "DW_FORM_data8";
6089 case DW_FORM_string: return "DW_FORM_string";
6090 case DW_FORM_block: return "DW_FORM_block";
6091 case DW_FORM_block1: return "DW_FORM_block1";
6092 case DW_FORM_data1: return "DW_FORM_data1";
6093 case DW_FORM_flag: return "DW_FORM_flag";
6094 case DW_FORM_sdata: return "DW_FORM_sdata";
6095 case DW_FORM_strp: return "DW_FORM_strp";
6096 case DW_FORM_udata: return "DW_FORM_udata";
6097 case DW_FORM_ref_addr: return "DW_FORM_ref_addr";
6098 case DW_FORM_ref1: return "DW_FORM_ref1";
6099 case DW_FORM_ref2: return "DW_FORM_ref2";
6100 case DW_FORM_ref4: return "DW_FORM_ref4";
6101 case DW_FORM_ref8: return "DW_FORM_ref8";
6102 case DW_FORM_ref_udata: return "DW_FORM_ref_udata";
6103 case DW_FORM_indirect: return "DW_FORM_indirect";
6106 static char buffer [100];
6108 sprintf (buffer, _("Unknown FORM value: %lx"), form);
6114 /* FIXME: There are better and more effiecint ways to handle
6115 these structures. For now though, I just want something that
6116 is simple to implement. */
6117 typedef struct abbrev_attr
6119 unsigned long attribute;
6121 struct abbrev_attr * next;
6125 typedef struct abbrev_entry
6127 unsigned long entry;
6130 struct abbrev_attr * first_attr;
6131 struct abbrev_attr * last_attr;
6132 struct abbrev_entry * next;
6136 static abbrev_entry * first_abbrev = NULL;
6137 static abbrev_entry * last_abbrev = NULL;
6140 free_abbrevs PARAMS ((void))
6142 abbrev_entry * abbrev;
6144 for (abbrev = first_abbrev; abbrev;)
6146 abbrev_entry * next = abbrev->next;
6149 for (attr = abbrev->first_attr; attr;)
6151 abbrev_attr * next = attr->next;
6161 last_abbrev = first_abbrev = NULL;
6165 add_abbrev (number, tag, children)
6166 unsigned long number;
6170 abbrev_entry * entry;
6172 entry = (abbrev_entry *) malloc (sizeof (* entry));
6178 entry->entry = number;
6180 entry->children = children;
6181 entry->first_attr = NULL;
6182 entry->last_attr = NULL;
6185 if (first_abbrev == NULL)
6186 first_abbrev = entry;
6188 last_abbrev->next = entry;
6190 last_abbrev = entry;
6194 add_abbrev_attr (attribute, form)
6195 unsigned long attribute;
6200 attr = (abbrev_attr *) malloc (sizeof (* attr));
6206 attr->attribute = attribute;
6210 if (last_abbrev->first_attr == NULL)
6211 last_abbrev->first_attr = attr;
6213 last_abbrev->last_attr->next = attr;
6215 last_abbrev->last_attr = attr;
6218 /* Processes the (partial) contents of a .debug_abbrev section.
6219 Returns NULL if the end of the section was encountered.
6220 Returns the address after the last byte read if the end of
6221 an abbreviation set was found. */
6223 static unsigned char *
6224 process_abbrev_section (start, end)
6225 unsigned char * start;
6226 unsigned char * end;
6228 if (first_abbrev != NULL)
6234 unsigned long entry;
6236 unsigned long attribute;
6239 entry = read_leb128 (start, & bytes_read, 0);
6240 start += bytes_read;
6242 /* A single zero is supposed to end the section according
6243 to the standard. If there's more, then signal that to
6246 return start == end ? NULL : start;
6248 tag = read_leb128 (start, & bytes_read, 0);
6249 start += bytes_read;
6251 children = * start ++;
6253 add_abbrev (entry, tag, children);
6259 attribute = read_leb128 (start, & bytes_read, 0);
6260 start += bytes_read;
6262 form = read_leb128 (start, & bytes_read, 0);
6263 start += bytes_read;
6266 add_abbrev_attr (attribute, form);
6268 while (attribute != 0);
6276 display_debug_macinfo (section, start, file)
6277 Elf32_Internal_Shdr * section;
6278 unsigned char * start;
6279 FILE * file ATTRIBUTE_UNUSED;
6281 unsigned char * end = start + section->sh_size;
6282 unsigned char * curr = start;
6283 unsigned int bytes_read;
6284 enum dwarf_macinfo_record_type op;
6286 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section));
6290 unsigned int lineno;
6291 const char * string;
6298 case DW_MACINFO_start_file:
6300 unsigned int filenum;
6302 lineno = read_leb128 (curr, & bytes_read, 0);
6304 filenum = read_leb128 (curr, & bytes_read, 0);
6307 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"), lineno, filenum);
6311 case DW_MACINFO_end_file:
6312 printf (_(" DW_MACINFO_end_file\n"));
6315 case DW_MACINFO_define:
6316 lineno = read_leb128 (curr, & bytes_read, 0);
6319 curr += strlen (string) + 1;
6320 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"), lineno, string);
6323 case DW_MACINFO_undef:
6324 lineno = read_leb128 (curr, & bytes_read, 0);
6327 curr += strlen (string) + 1;
6328 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"), lineno, string);
6331 case DW_MACINFO_vendor_ext:
6333 unsigned int constant;
6335 constant = read_leb128 (curr, & bytes_read, 0);
6338 curr += strlen (string) + 1;
6339 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"), constant, string);
6350 display_debug_abbrev (section, start, file)
6351 Elf32_Internal_Shdr * section;
6352 unsigned char * start;
6353 FILE * file ATTRIBUTE_UNUSED;
6355 abbrev_entry * entry;
6356 unsigned char * end = start + section->sh_size;
6358 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section));
6362 start = process_abbrev_section (start, end);
6364 printf (_(" Number TAG\n"));
6366 for (entry = first_abbrev; entry; entry = entry->next)
6370 printf (_(" %ld %s [%s]\n"),
6372 get_TAG_name (entry->tag),
6373 entry->children ? _("has children") : _("no children"));
6375 for (attr = entry->first_attr; attr; attr = attr->next)
6377 printf (_(" %-18s %s\n"),
6378 get_AT_name (attr->attribute),
6379 get_FORM_name (attr->form));
6391 static unsigned char *
6392 display_block (data, length)
6393 unsigned char * data;
6394 unsigned long length;
6396 printf (_(" %lu byte block: "), length);
6399 printf ("%lx ", (unsigned long) byte_get (data ++, 1));
6405 decode_location_expression (data, pointer_size, length)
6406 unsigned char * data;
6407 unsigned int pointer_size;
6408 unsigned long length;
6412 unsigned long uvalue;
6413 unsigned char * end = data + length;
6422 printf ("DW_OP_addr: %lx",
6423 (unsigned long) byte_get (data, pointer_size));
6424 data += pointer_size;
6427 printf ("DW_OP_deref");
6430 printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data++, 1));
6433 printf ("DW_OP_const1s: %ld", (long) byte_get (data++, 1));
6436 printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data, 2));
6440 printf ("DW_OP_const2s: %ld", (long) byte_get (data, 2));
6444 printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data, 4));
6448 printf ("DW_OP_const4s: %ld", (long) byte_get (data, 4));
6452 printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data, 4),
6453 (unsigned long) byte_get (data + 4, 4));
6457 printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data, 4),
6458 (long) byte_get (data + 4, 4));
6462 printf ("DW_OP_constu: %lu", read_leb128 (data, &bytes_read, 0));
6466 printf ("DW_OP_consts: %ld", read_leb128 (data, &bytes_read, 1));
6470 printf ("DW_OP_dup");
6473 printf ("DW_OP_drop");
6476 printf ("DW_OP_over");
6479 printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data++, 1));
6482 printf ("DW_OP_swap");
6485 printf ("DW_OP_rot");
6488 printf ("DW_OP_xderef");
6491 printf ("DW_OP_abs");
6494 printf ("DW_OP_and");
6497 printf ("DW_OP_div");
6500 printf ("DW_OP_minus");
6503 printf ("DW_OP_mod");
6506 printf ("DW_OP_mul");
6509 printf ("DW_OP_neg");
6512 printf ("DW_OP_not");
6515 printf ("DW_OP_or");
6518 printf ("DW_OP_plus");
6520 case DW_OP_plus_uconst:
6521 printf ("DW_OP_plus_uconst: %lu",
6522 read_leb128 (data, &bytes_read, 0));
6526 printf ("DW_OP_shl");
6529 printf ("DW_OP_shr");
6532 printf ("DW_OP_shra");
6535 printf ("DW_OP_xor");
6538 printf ("DW_OP_bra: %ld", (long) byte_get (data, 2));
6542 printf ("DW_OP_eq");
6545 printf ("DW_OP_ge");
6548 printf ("DW_OP_gt");
6551 printf ("DW_OP_le");
6554 printf ("DW_OP_lt");
6557 printf ("DW_OP_ne");
6560 printf ("DW_OP_skip: %ld", (long) byte_get (data, 2));
6596 printf ("DW_OP_lit%d", op - DW_OP_lit0);
6631 printf ("DW_OP_reg%d", op - DW_OP_reg0);
6666 printf ("DW_OP_breg%d: %ld", op - DW_OP_breg0,
6667 read_leb128 (data, &bytes_read, 1));
6672 printf ("DW_OP_regx: %lu", read_leb128 (data, &bytes_read, 0));
6676 printf ("DW_OP_fbreg: %ld", read_leb128 (data, &bytes_read, 1));
6680 uvalue = read_leb128 (data, &bytes_read, 0);
6682 printf ("DW_OP_bregx: %lu %ld", uvalue,
6683 read_leb128 (data, &bytes_read, 1));
6687 printf ("DW_OP_piece: %lu", read_leb128 (data, &bytes_read, 0));
6690 case DW_OP_deref_size:
6691 printf ("DW_OP_deref_size: %ld", (long) byte_get (data++, 1));
6693 case DW_OP_xderef_size:
6694 printf ("DW_OP_xderef_size: %ld", (long) byte_get (data++, 1));
6697 printf ("DW_OP_nop");
6700 /* DWARF 2.1 extensions. */
6701 case DW_OP_push_object_address:
6702 printf ("DW_OP_push_object_address");
6705 printf ("DW_OP_call2: <%lx>", (long) byte_get (data, 2));
6709 printf ("DW_OP_call4: <%lx>", (long) byte_get (data, 4));
6713 printf ("DW_OP_calli");
6717 if (op >= DW_OP_lo_user
6718 && op <= DW_OP_hi_user)
6719 printf (_("(User defined location op)"));
6721 printf (_("(Unknown location op)"));
6722 /* No way to tell where the next op is, so just bail. */
6726 /* Separate the ops. */
6732 static unsigned char *
6733 read_and_display_attr (attribute, form, data, cu_offset, pointer_size)
6734 unsigned long attribute;
6736 unsigned char * data;
6737 unsigned long cu_offset;
6738 unsigned long pointer_size;
6740 unsigned long uvalue = 0;
6741 unsigned char * block_start = NULL;
6744 printf (" %-18s:", get_AT_name (attribute));
6751 case DW_FORM_ref_addr:
6753 uvalue = byte_get (data, pointer_size);
6754 data += pointer_size;
6760 uvalue = byte_get (data ++, 1);
6765 uvalue = byte_get (data, 2);
6771 uvalue = byte_get (data, 4);
6776 uvalue = read_leb128 (data, & bytes_read, 1);
6780 case DW_FORM_ref_udata:
6782 uvalue = read_leb128 (data, & bytes_read, 0);
6789 case DW_FORM_ref_addr:
6790 printf (" <#%lx>", uvalue);
6796 case DW_FORM_ref_udata:
6797 printf (" <%lx>", uvalue + cu_offset);
6801 printf (" %#lx", uvalue);
6809 printf (" %ld", uvalue);
6814 uvalue = byte_get (data, 4);
6815 printf (" %lx", uvalue);
6816 printf (" %lx", (unsigned long) byte_get (data + 4, 4));
6820 case DW_FORM_string:
6821 printf (" %s", data);
6822 data += strlen ((char *) data) + 1;
6826 uvalue = read_leb128 (data, & bytes_read, 0);
6827 block_start = data + bytes_read;
6828 data = display_block (block_start, uvalue);
6831 case DW_FORM_block1:
6832 uvalue = byte_get (data, 1);
6833 block_start = data + 1;
6834 data = display_block (block_start, uvalue);
6837 case DW_FORM_block2:
6838 uvalue = byte_get (data, 2);
6839 block_start = data + 2;
6840 data = display_block (block_start, uvalue);
6843 case DW_FORM_block4:
6844 uvalue = byte_get (data, 4);
6845 block_start = data + 4;
6846 data = display_block (block_start, uvalue);
6850 case DW_FORM_indirect:
6851 warn (_("Unable to handle FORM: %d"), form);
6855 warn (_("Unrecognised form: %d"), form);
6859 /* For some attributes we can display futher information. */
6868 case DW_INL_not_inlined: printf (_("(not inlined)")); break;
6869 case DW_INL_inlined: printf (_("(inlined)")); break;
6870 case DW_INL_declared_not_inlined: printf (_("(declared as inline but ignored)")); break;
6871 case DW_INL_declared_inlined: printf (_("(declared as inline and inlined)")); break;
6872 default: printf (_(" (Unknown inline attribute value: %lx)"), uvalue); break;
6876 case DW_AT_language:
6879 case DW_LANG_C: printf ("(non-ANSI C)"); break;
6880 case DW_LANG_C89: printf ("(ANSI C)"); break;
6881 case DW_LANG_C_plus_plus: printf ("(C++)"); break;
6882 case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break;
6883 case DW_LANG_Fortran90: printf ("(Fortran 90)"); break;
6884 case DW_LANG_Modula2: printf ("(Modula 2)"); break;
6885 case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break;
6886 case DW_LANG_Ada83: printf ("(Ada)"); break;
6887 case DW_LANG_Cobol74: printf ("(Cobol 74)"); break;
6888 case DW_LANG_Cobol85: printf ("(Cobol 85)"); break;
6889 /* DWARF 2.1 values. */
6890 case DW_LANG_C99: printf ("(ANSI C99)"); break;
6891 case DW_LANG_Ada95: printf ("(ADA 95)"); break;
6892 case DW_LANG_Fortran95: printf ("(Fortran 95)"); break;
6893 /* MIPS extension. */
6894 case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break;
6895 default: printf ("(Unknown: %lx)", uvalue); break;
6899 case DW_AT_encoding:
6902 case DW_ATE_void: printf ("(void)"); break;
6903 case DW_ATE_address: printf ("(machine address)"); break;
6904 case DW_ATE_boolean: printf ("(boolean)"); break;
6905 case DW_ATE_complex_float: printf ("(complex float)"); break;
6906 case DW_ATE_float: printf ("(float)"); break;
6907 case DW_ATE_signed: printf ("(signed)"); break;
6908 case DW_ATE_signed_char: printf ("(signed char)"); break;
6909 case DW_ATE_unsigned: printf ("(unsigned)"); break;
6910 case DW_ATE_unsigned_char: printf ("(unsigned char)"); break;
6911 /* DWARF 2.1 value. */
6912 case DW_ATE_imaginary_float: printf ("(imaginary float)"); break;
6914 if (uvalue >= DW_ATE_lo_user
6915 && uvalue <= DW_ATE_hi_user)
6916 printf ("(user defined type)");
6918 printf ("(unknown type)");
6923 case DW_AT_accessibility:
6926 case DW_ACCESS_public: printf ("(public)"); break;
6927 case DW_ACCESS_protected: printf ("(protected)"); break;
6928 case DW_ACCESS_private: printf ("(private)"); break;
6929 default: printf ("(unknown accessibility)"); break;
6933 case DW_AT_visibility:
6936 case DW_VIS_local: printf ("(local)"); break;
6937 case DW_VIS_exported: printf ("(exported)"); break;
6938 case DW_VIS_qualified: printf ("(qualified)"); break;
6939 default: printf ("(unknown visibility)"); break;
6943 case DW_AT_virtuality:
6946 case DW_VIRTUALITY_none: printf ("(none)"); break;
6947 case DW_VIRTUALITY_virtual: printf ("(virtual)"); break;
6948 case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break;
6949 default: printf ("(unknown virtuality)"); break;
6953 case DW_AT_identifier_case:
6956 case DW_ID_case_sensitive: printf ("(case_sensitive)"); break;
6957 case DW_ID_up_case: printf ("(up_case)"); break;
6958 case DW_ID_down_case: printf ("(down_case)"); break;
6959 case DW_ID_case_insensitive: printf ("(case_insensitive)"); break;
6960 default: printf ("(unknown case)"); break;
6964 case DW_AT_calling_convention:
6967 case DW_CC_normal: printf ("(normal)"); break;
6968 case DW_CC_program: printf ("(program)"); break;
6969 case DW_CC_nocall: printf ("(nocall)"); break;
6971 if (uvalue >= DW_CC_lo_user
6972 && uvalue <= DW_CC_hi_user)
6973 printf ("(user defined)");
6975 printf ("(unknown convention)");
6979 case DW_AT_ordering:
6982 case -1: printf ("(undefined)"); break;
6983 case 0: printf ("(row major)"); break;
6984 case 1: printf ("(column major)"); break;
6988 case DW_AT_frame_base:
6989 case DW_AT_location:
6990 case DW_AT_data_member_location:
6991 case DW_AT_vtable_elem_location:
6992 case DW_AT_allocated:
6993 case DW_AT_associated:
6994 case DW_AT_data_location:
6996 case DW_AT_upper_bound:
6997 case DW_AT_lower_bound:
7001 decode_location_expression (block_start, pointer_size, uvalue);
7015 display_debug_info (section, start, file)
7016 Elf32_Internal_Shdr * section;
7017 unsigned char * start;
7020 unsigned char * end = start + section->sh_size;
7021 unsigned char * section_begin = start;
7023 printf (_("The section %s contains:\n\n"), SECTION_NAME (section));
7027 DWARF2_External_CompUnit * external;
7028 DWARF2_Internal_CompUnit compunit;
7029 Elf32_Internal_Shdr * relsec;
7030 unsigned char * tags;
7033 unsigned long cu_offset;
7035 external = (DWARF2_External_CompUnit *) start;
7037 compunit.cu_length = BYTE_GET (external->cu_length);
7038 compunit.cu_version = BYTE_GET (external->cu_version);
7039 compunit.cu_abbrev_offset = BYTE_GET (external->cu_abbrev_offset);
7040 compunit.cu_pointer_size = BYTE_GET (external->cu_pointer_size);
7042 /* Check for RELA relocations in the abbrev_offset address, and
7044 for (relsec = section_headers;
7045 relsec < section_headers + elf_header.e_shnum;
7048 unsigned long nrelas, nsyms;
7049 Elf_Internal_Rela *rela, *rp;
7050 Elf32_Internal_Shdr *symsec;
7051 Elf_Internal_Sym *symtab;
7052 Elf_Internal_Sym *sym;
7054 if (relsec->sh_type != SHT_RELA
7055 || section_headers + relsec->sh_info != section)
7058 if (!slurp_rela_relocs (file, relsec->sh_offset, relsec->sh_size,
7062 symsec = section_headers + relsec->sh_link;
7063 nsyms = symsec->sh_size / symsec->sh_entsize;
7064 symtab = GET_ELF_SYMBOLS (file, symsec->sh_offset, nsyms);
7066 for (rp = rela; rp < rela + nrelas; ++rp)
7069 != (bfd_vma) ((unsigned char *) &external->cu_abbrev_offset
7075 sym = symtab + ELF32_R_SYM (rp->r_info);
7077 if (ELF32_ST_TYPE (sym->st_info) != STT_SECTION)
7079 warn (_("Skipping unexpected symbol type %u"),
7080 ELF32_ST_TYPE (sym->st_info));
7086 sym = symtab + ELF64_R_SYM (rp->r_info);
7088 if (ELF64_ST_TYPE (sym->st_info) != STT_SECTION)
7090 warn (_("Skipping unexpected symbol type %u"),
7091 ELF64_ST_TYPE (sym->st_info));
7096 compunit.cu_abbrev_offset += rp->r_addend;
7104 tags = start + sizeof (* external);
7105 cu_offset = start - section_begin;
7106 start += compunit.cu_length + sizeof (external->cu_length);
7108 printf (_(" Compilation Unit @ %lx:\n"), cu_offset);
7109 printf (_(" Length: %ld\n"), compunit.cu_length);
7110 printf (_(" Version: %d\n"), compunit.cu_version);
7111 printf (_(" Abbrev Offset: %ld\n"), compunit.cu_abbrev_offset);
7112 printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size);
7114 if (compunit.cu_version != 2)
7116 warn (_("Only version 2 DWARF debug information is currently supported.\n"));
7120 if (first_abbrev != NULL)
7123 /* Read in the abbrevs used by this compilation unit. */
7126 Elf32_Internal_Shdr * sec;
7127 unsigned char * begin;
7129 /* Locate the .debug_abbrev section and process it. */
7130 for (i = 0, sec = section_headers;
7131 i < elf_header.e_shnum;
7133 if (strcmp (SECTION_NAME (sec), ".debug_abbrev") == 0)
7136 if (i == -1 || sec->sh_size == 0)
7138 warn (_("Unable to locate .debug_abbrev section!\n"));
7142 begin = ((unsigned char *)
7143 get_data (NULL, file, sec->sh_offset, sec->sh_size,
7144 _("debug_abbrev section data")));
7148 process_abbrev_section (begin + compunit.cu_abbrev_offset,
7149 begin + sec->sh_size);
7155 while (tags < start)
7158 unsigned long abbrev_number;
7159 abbrev_entry * entry;
7162 abbrev_number = read_leb128 (tags, & bytes_read, 0);
7165 /* A null DIE marks the end of a list of children. */
7166 if (abbrev_number == 0)
7172 /* Scan through the abbreviation list until we reach the
7174 for (entry = first_abbrev;
7175 entry && entry->entry != abbrev_number;
7176 entry = entry->next)
7181 warn (_("Unable to locate entry %lu in the abbreviation table\n"),
7186 printf (_(" <%d><%x>: Abbrev Number: %lu (%s)\n"),
7187 level, tags - section_begin - bytes_read,
7189 get_TAG_name (entry->tag));
7191 for (attr = entry->first_attr; attr; attr = attr->next)
7192 tags = read_and_display_attr (attr->attribute,
7195 compunit.cu_pointer_size);
7197 if (entry->children)
7208 display_debug_aranges (section, start, file)
7209 Elf32_Internal_Shdr * section;
7210 unsigned char * start;
7211 FILE * file ATTRIBUTE_UNUSED;
7213 unsigned char * end = start + section->sh_size;
7215 printf (_("The section %s contains:\n\n"), SECTION_NAME (section));
7219 DWARF2_External_ARange * external;
7220 DWARF2_Internal_ARange arange;
7221 unsigned char * ranges;
7222 unsigned long length;
7223 unsigned long address;
7226 external = (DWARF2_External_ARange *) start;
7228 arange.ar_length = BYTE_GET (external->ar_length);
7229 arange.ar_version = BYTE_GET (external->ar_version);
7230 arange.ar_info_offset = BYTE_GET (external->ar_info_offset);
7231 arange.ar_pointer_size = BYTE_GET (external->ar_pointer_size);
7232 arange.ar_segment_size = BYTE_GET (external->ar_segment_size);
7234 if (arange.ar_version != 2)
7236 warn (_("Only DWARF 2 aranges are currently supported.\n"));
7240 printf (_(" Length: %ld\n"), arange.ar_length);
7241 printf (_(" Version: %d\n"), arange.ar_version);
7242 printf (_(" Offset into .debug_info: %lx\n"), arange.ar_info_offset);
7243 printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
7244 printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
7246 printf (_("\n Address Length\n"));
7248 ranges = start + sizeof (* external);
7250 /* Must pad to an alignment boundary that is twice the pointer size. */
7251 excess = sizeof (* external) % (2 * arange.ar_pointer_size);
7253 ranges += (2 * arange.ar_pointer_size) - excess;
7257 address = byte_get (ranges, arange.ar_pointer_size);
7259 ranges += arange.ar_pointer_size;
7261 length = byte_get (ranges, arange.ar_pointer_size);
7263 ranges += arange.ar_pointer_size;
7265 /* A pair of zeros marks the end of the list. */
7266 if (address == 0 && length == 0)
7269 printf (" %8.8lx %lu\n", address, length);
7272 start += arange.ar_length + sizeof (external->ar_length);
7280 typedef struct Frame_Chunk
7282 struct Frame_Chunk * next;
7283 unsigned char * chunk_start;
7285 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
7286 short int * col_type;
7288 char * augmentation;
7289 unsigned int code_factor;
7291 unsigned long pc_begin;
7292 unsigned long pc_range;
7296 unsigned char fde_encoding;
7300 /* A marker for a col_type that means this column was never referenced
7301 in the frame info. */
7302 #define DW_CFA_unreferenced (-1)
7305 frame_need_space (fc, reg)
7309 int prev = fc->ncols;
7311 if (reg < fc->ncols)
7314 fc->ncols = reg + 1;
7315 fc->col_type = (short int *) xrealloc (fc->col_type,
7316 fc->ncols * sizeof (short int));
7317 fc->col_offset = (int *) xrealloc (fc->col_offset,
7318 fc->ncols * sizeof (int));
7320 while (prev < fc->ncols)
7322 fc->col_type[prev] = DW_CFA_unreferenced;
7323 fc->col_offset[prev] = 0;
7329 frame_display_row (fc, need_col_headers, max_regs)
7331 int * need_col_headers;
7337 if (* max_regs < fc->ncols)
7338 * max_regs = fc->ncols;
7340 if (* need_col_headers)
7342 * need_col_headers = 0;
7344 printf (" LOC CFA ");
7346 for (r = 0; r < * max_regs; r++)
7347 if (fc->col_type[r] != DW_CFA_unreferenced)
7352 printf ("r%-4d", r);
7358 printf ("%08lx ", fc->pc_begin);
7359 sprintf (tmp, "r%d%+d", fc->cfa_reg, fc->cfa_offset);
7360 printf ("%-8s ", tmp);
7362 for (r = 0; r < fc->ncols; r++)
7364 if (fc->col_type[r] != DW_CFA_unreferenced)
7366 switch (fc->col_type[r])
7368 case DW_CFA_undefined:
7371 case DW_CFA_same_value:
7375 sprintf (tmp, "c%+d", fc->col_offset[r]);
7377 case DW_CFA_register:
7378 sprintf (tmp, "r%d", fc->col_offset[r]);
7381 strcpy (tmp, "n/a");
7384 printf ("%-5s", tmp);
7391 size_of_encoded_value (encoding)
7394 switch (encoding & 0x7)
7397 case 0: return is_32bit_elf ? 4 : 8;
7404 #define GET(N) byte_get (start, N); start += N
7405 #define LEB() read_leb128 (start, & length_return, 0); start += length_return
7406 #define SLEB() read_leb128 (start, & length_return, 1); start += length_return
7409 display_debug_frames (section, start, file)
7410 Elf32_Internal_Shdr * section;
7411 unsigned char * start;
7412 FILE * file ATTRIBUTE_UNUSED;
7414 unsigned char * end = start + section->sh_size;
7415 unsigned char * section_start = start;
7416 Frame_Chunk * chunks = 0;
7417 Frame_Chunk * remembered_state = 0;
7419 int is_eh = (strcmp (SECTION_NAME (section), ".eh_frame") == 0);
7422 int addr_size = is_32bit_elf ? 4 : 8;
7424 printf (_("The section %s contains:\n"), SECTION_NAME (section));
7428 unsigned char * saved_start;
7429 unsigned char * block_end;
7430 unsigned long length;
7431 unsigned long cie_id;
7434 int need_col_headers = 1;
7435 unsigned char * augmentation_data = NULL;
7436 unsigned long augmentation_data_len = 0;
7437 int encoded_ptr_size = addr_size;
7439 saved_start = start;
7440 length = byte_get (start, 4); start += 4;
7445 block_end = saved_start + length + 4;
7446 cie_id = byte_get (start, 4); start += 4;
7448 if (is_eh ? (cie_id == 0) : (cie_id == DW_CIE_ID))
7452 fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
7453 memset (fc, 0, sizeof (Frame_Chunk));
7457 fc->chunk_start = saved_start;
7459 fc->col_type = (short int *) xmalloc (sizeof (short int));
7460 fc->col_offset = (int *) xmalloc (sizeof (int));
7461 frame_need_space (fc, max_regs-1);
7465 fc->augmentation = start;
7466 start = strchr (start, '\0') + 1;
7468 if (fc->augmentation[0] == 'z')
7470 fc->code_factor = LEB ();
7471 fc->data_factor = SLEB ();
7472 fc->ra = byte_get (start, 1); start += 1;
7473 augmentation_data_len = LEB ();
7474 augmentation_data = start;
7475 start += augmentation_data_len;
7477 else if (strcmp (fc->augmentation, "eh") == 0)
7480 fc->code_factor = LEB ();
7481 fc->data_factor = SLEB ();
7482 fc->ra = byte_get (start, 1); start += 1;
7486 fc->code_factor = LEB ();
7487 fc->data_factor = SLEB ();
7488 fc->ra = byte_get (start, 1); start += 1;
7492 if (do_debug_frames_interp)
7493 printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n",
7494 (unsigned long)(saved_start - section_start), length, cie_id,
7495 fc->augmentation, fc->code_factor, fc->data_factor,
7499 printf ("\n%08lx %08lx %08lx CIE\n",
7500 (unsigned long)(saved_start - section_start), length, cie_id);
7501 printf (" Version: %d\n", version);
7502 printf (" Augmentation: \"%s\"\n", fc->augmentation);
7503 printf (" Code alignment factor: %u\n", fc->code_factor);
7504 printf (" Data alignment factor: %d\n", fc->data_factor);
7505 printf (" Return address column: %d\n", fc->ra);
7507 if (augmentation_data_len)
7510 printf (" Augmentation data: ");
7511 for (i = 0; i < augmentation_data_len; ++i)
7512 printf (" %02x", augmentation_data[i]);
7518 if (augmentation_data_len)
7520 unsigned char *p, *q;
7521 p = fc->augmentation + 1;
7522 q = augmentation_data;
7529 q += 1 + size_of_encoded_value (*q);
7531 fc->fde_encoding = *q++;
7537 if (fc->fde_encoding)
7538 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
7541 frame_need_space (fc, fc->ra);
7545 unsigned char * look_for;
7546 static Frame_Chunk fde_fc;
7549 memset (fc, 0, sizeof (Frame_Chunk));
7551 look_for = is_eh ? start - 4 - cie_id : section_start + cie_id;
7553 for (cie=chunks; cie ; cie = cie->next)
7554 if (cie->chunk_start == look_for)
7559 warn ("Invalid CIE pointer %08lx in FDE at %08lx\n",
7560 cie_id, saved_start);
7563 fc->col_type = (short int *) xmalloc (sizeof (short int));
7564 fc->col_offset = (int *) xmalloc (sizeof (int));
7565 frame_need_space (fc, max_regs - 1);
7567 fc->augmentation = "";
7568 fc->fde_encoding = 0;
7572 fc->ncols = cie->ncols;
7573 fc->col_type = (short int *) xmalloc (fc->ncols * sizeof (short int));
7574 fc->col_offset = (int *) xmalloc (fc->ncols * sizeof (int));
7575 memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int));
7576 memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int));
7577 fc->augmentation = cie->augmentation;
7578 fc->code_factor = cie->code_factor;
7579 fc->data_factor = cie->data_factor;
7580 fc->cfa_reg = cie->cfa_reg;
7581 fc->cfa_offset = cie->cfa_offset;
7583 frame_need_space (fc, max_regs-1);
7584 fc->fde_encoding = cie->fde_encoding;
7587 if (fc->fde_encoding)
7588 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
7590 fc->pc_begin = byte_get (start, encoded_ptr_size);
7591 start += encoded_ptr_size;
7592 fc->pc_range = byte_get (start, encoded_ptr_size);
7593 start += encoded_ptr_size;
7595 if (cie->augmentation[0] == 'z')
7597 augmentation_data_len = LEB ();
7598 augmentation_data = start;
7599 start += augmentation_data_len;
7602 printf ("\n%08lx %08lx %08lx FDE cie=%08x pc=%08lx..%08lx\n",
7603 (unsigned long)(saved_start - section_start), length, cie_id,
7604 cie->chunk_start - section_start, fc->pc_begin,
7605 fc->pc_begin + fc->pc_range);
7606 if (! do_debug_frames_interp && augmentation_data_len)
7609 printf (" Augmentation data: ");
7610 for (i = 0; i < augmentation_data_len; ++i)
7611 printf (" %02x", augmentation_data[i]);
7617 /* At this point, fc is the current chunk, cie (if any) is set, and we're
7618 about to interpret instructions for the chunk. */
7620 if (do_debug_frames_interp)
7622 /* Start by making a pass over the chunk, allocating storage
7623 and taking note of what registers are used. */
7624 unsigned char * tmp = start;
7626 while (start < block_end)
7636 /* Warning: if you add any more cases to this switch, be
7637 sure to add them to the corresponding switch below. */
7640 case DW_CFA_advance_loc:
7644 frame_need_space (fc, opa);
7645 fc->col_type[opa] = DW_CFA_undefined;
7647 case DW_CFA_restore:
7648 frame_need_space (fc, opa);
7649 fc->col_type[opa] = DW_CFA_undefined;
7651 case DW_CFA_set_loc:
7652 start += encoded_ptr_size;
7654 case DW_CFA_advance_loc1:
7657 case DW_CFA_advance_loc2:
7660 case DW_CFA_advance_loc4:
7663 case DW_CFA_offset_extended:
7664 reg = LEB (); LEB ();
7665 frame_need_space (fc, reg);
7666 fc->col_type[reg] = DW_CFA_undefined;
7668 case DW_CFA_restore_extended:
7670 frame_need_space (fc, reg);
7671 fc->col_type[reg] = DW_CFA_undefined;
7673 case DW_CFA_undefined:
7675 frame_need_space (fc, reg);
7676 fc->col_type[reg] = DW_CFA_undefined;
7678 case DW_CFA_same_value:
7680 frame_need_space (fc, reg);
7681 fc->col_type[reg] = DW_CFA_undefined;
7683 case DW_CFA_register:
7684 reg = LEB (); LEB ();
7685 frame_need_space (fc, reg);
7686 fc->col_type[reg] = DW_CFA_undefined;
7688 case DW_CFA_def_cfa:
7691 case DW_CFA_def_cfa_register:
7694 case DW_CFA_def_cfa_offset:
7697 #ifndef DW_CFA_GNU_args_size
7698 #define DW_CFA_GNU_args_size 0x2e
7700 case DW_CFA_GNU_args_size:
7703 #ifndef DW_CFA_GNU_negative_offset_extended
7704 #define DW_CFA_GNU_negative_offset_extended 0x2f
7706 case DW_CFA_GNU_negative_offset_extended:
7707 reg = LEB (); LEB ();
7708 frame_need_space (fc, reg);
7709 fc->col_type[reg] = DW_CFA_undefined;
7718 /* Now we know what registers are used, make a second pass over
7719 the chunk, this time actually printing out the info. */
7721 while (start < block_end)
7724 unsigned long ul, reg, roffs;
7733 /* Warning: if you add any more cases to this switch, be
7734 sure to add them to the corresponding switch above. */
7737 case DW_CFA_advance_loc:
7738 if (do_debug_frames_interp)
7739 frame_display_row (fc, &need_col_headers, &max_regs);
7741 printf (" DW_CFA_advance_loc: %d to %08lx\n",
7742 opa * fc->code_factor,
7743 fc->pc_begin + opa * fc->code_factor);
7744 fc->pc_begin += opa * fc->code_factor;
7749 if (! do_debug_frames_interp)
7750 printf (" DW_CFA_offset: r%d at cfa%+ld\n",
7751 opa, roffs * fc->data_factor);
7752 fc->col_type[opa] = DW_CFA_offset;
7753 fc->col_offset[opa] = roffs * fc->data_factor;
7756 case DW_CFA_restore:
7757 if (! do_debug_frames_interp)
7758 printf (" DW_CFA_restore: r%d\n", opa);
7759 fc->col_type[opa] = cie->col_type[opa];
7760 fc->col_offset[opa] = cie->col_offset[opa];
7763 case DW_CFA_set_loc:
7764 vma = byte_get (start, encoded_ptr_size);
7765 start += encoded_ptr_size;
7766 if (do_debug_frames_interp)
7767 frame_display_row (fc, &need_col_headers, &max_regs);
7769 printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma);
7773 case DW_CFA_advance_loc1:
7774 ofs = byte_get (start, 1); start += 1;
7775 if (do_debug_frames_interp)
7776 frame_display_row (fc, &need_col_headers, &max_regs);
7778 printf (" DW_CFA_advance_loc1: %ld to %08lx\n",
7779 ofs * fc->code_factor,
7780 fc->pc_begin + ofs * fc->code_factor);
7781 fc->pc_begin += ofs * fc->code_factor;
7784 case DW_CFA_advance_loc2:
7785 ofs = byte_get (start, 2); start += 2;
7786 if (do_debug_frames_interp)
7787 frame_display_row (fc, &need_col_headers, &max_regs);
7789 printf (" DW_CFA_advance_loc2: %ld to %08lx\n",
7790 ofs * fc->code_factor,
7791 fc->pc_begin + ofs * fc->code_factor);
7792 fc->pc_begin += ofs * fc->code_factor;
7795 case DW_CFA_advance_loc4:
7796 ofs = byte_get (start, 4); start += 4;
7797 if (do_debug_frames_interp)
7798 frame_display_row (fc, &need_col_headers, &max_regs);
7800 printf (" DW_CFA_advance_loc4: %ld to %08lx\n",
7801 ofs * fc->code_factor,
7802 fc->pc_begin + ofs * fc->code_factor);
7803 fc->pc_begin += ofs * fc->code_factor;
7806 case DW_CFA_offset_extended:
7809 if (! do_debug_frames_interp)
7810 printf (" DW_CFA_offset_extended: r%ld at cfa%+ld\n",
7811 reg, roffs * fc->data_factor);
7812 fc->col_type[reg] = DW_CFA_offset;
7813 fc->col_offset[reg] = roffs * fc->data_factor;
7816 case DW_CFA_restore_extended:
7818 if (! do_debug_frames_interp)
7819 printf (" DW_CFA_restore_extended: r%ld\n", reg);
7820 fc->col_type[reg] = cie->col_type[reg];
7821 fc->col_offset[reg] = cie->col_offset[reg];
7824 case DW_CFA_undefined:
7826 if (! do_debug_frames_interp)
7827 printf (" DW_CFA_undefined: r%ld\n", reg);
7828 fc->col_type[reg] = DW_CFA_undefined;
7829 fc->col_offset[reg] = 0;
7832 case DW_CFA_same_value:
7834 if (! do_debug_frames_interp)
7835 printf (" DW_CFA_same_value: r%ld\n", reg);
7836 fc->col_type[reg] = DW_CFA_same_value;
7837 fc->col_offset[reg] = 0;
7840 case DW_CFA_register:
7843 if (! do_debug_frames_interp)
7844 printf (" DW_CFA_register: r%ld\n", reg);
7845 fc->col_type[reg] = DW_CFA_register;
7846 fc->col_offset[reg] = roffs;
7849 case DW_CFA_remember_state:
7850 if (! do_debug_frames_interp)
7851 printf (" DW_CFA_remember_state\n");
7852 rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
7853 rs->ncols = fc->ncols;
7854 rs->col_type = (short int *) xmalloc (rs->ncols * sizeof (short int));
7855 rs->col_offset = (int *) xmalloc (rs->ncols * sizeof (int));
7856 memcpy (rs->col_type, fc->col_type, rs->ncols);
7857 memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (int));
7858 rs->next = remembered_state;
7859 remembered_state = rs;
7862 case DW_CFA_restore_state:
7863 if (! do_debug_frames_interp)
7864 printf (" DW_CFA_restore_state\n");
7865 rs = remembered_state;
7866 remembered_state = rs->next;
7867 frame_need_space (fc, rs->ncols-1);
7868 memcpy (fc->col_type, rs->col_type, rs->ncols);
7869 memcpy (fc->col_offset, rs->col_offset, rs->ncols * sizeof (int));
7870 free (rs->col_type);
7871 free (rs->col_offset);
7875 case DW_CFA_def_cfa:
7876 fc->cfa_reg = LEB ();
7877 fc->cfa_offset = LEB ();
7878 if (! do_debug_frames_interp)
7879 printf (" DW_CFA_def_cfa: r%d ofs %d\n",
7880 fc->cfa_reg, fc->cfa_offset);
7883 case DW_CFA_def_cfa_register:
7884 fc->cfa_reg = LEB ();
7885 if (! do_debug_frames_interp)
7886 printf (" DW_CFA_def_cfa_reg: r%d\n", fc->cfa_reg);
7889 case DW_CFA_def_cfa_offset:
7890 fc->cfa_offset = LEB ();
7891 if (! do_debug_frames_interp)
7892 printf (" DW_CFA_def_cfa_offset: %d\n", fc->cfa_offset);
7896 if (! do_debug_frames_interp)
7897 printf (" DW_CFA_nop\n");
7900 #ifndef DW_CFA_GNU_window_save
7901 #define DW_CFA_GNU_window_save 0x2d
7903 case DW_CFA_GNU_window_save:
7904 if (! do_debug_frames_interp)
7905 printf (" DW_CFA_GNU_window_save\n");
7908 case DW_CFA_GNU_args_size:
7910 if (! do_debug_frames_interp)
7911 printf (" DW_CFA_GNU_args_size: %ld\n", ul);
7914 case DW_CFA_GNU_negative_offset_extended:
7917 frame_need_space (fc, reg);
7918 if (! do_debug_frames_interp)
7919 printf (" DW_CFA_GNU_negative_offset_extended: r%ld at cfa%+ld\n",
7920 reg, l * fc->data_factor);
7921 fc->col_type[reg] = DW_CFA_offset;
7922 fc->col_offset[reg] = l * fc->data_factor;
7926 fprintf (stderr, "unsupported or unknown DW_CFA_%d\n", op);
7931 if (do_debug_frames_interp)
7932 frame_display_row (fc, &need_col_headers, &max_regs);
7947 display_debug_not_supported (section, start, file)
7948 Elf32_Internal_Shdr * section;
7949 unsigned char * start ATTRIBUTE_UNUSED;
7950 FILE * file ATTRIBUTE_UNUSED;
7952 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
7953 SECTION_NAME (section));
7958 /* Pre-scan the .debug_info section to record the size of address.
7959 When dumping the .debug_line, we use that size information, assuming
7960 that all compilation units have the same address size. */
7962 prescan_debug_info (section, start, file)
7963 Elf32_Internal_Shdr * section ATTRIBUTE_UNUSED;
7964 unsigned char * start;
7965 FILE * file ATTRIBUTE_UNUSED;
7967 DWARF2_External_CompUnit * external;
7969 external = (DWARF2_External_CompUnit *) start;
7971 debug_line_pointer_size = BYTE_GET (external->cu_pointer_size);
7975 /* A structure containing the name of a debug section and a pointer
7976 to a function that can decode it. The third field is a prescan
7977 function to be run over the section before displaying any of the
7982 int (* display) PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
7983 int (* prescan) PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
7987 { ".debug_info", display_debug_info, prescan_debug_info },
7988 { ".debug_abbrev", display_debug_abbrev, NULL },
7989 { ".debug_line", display_debug_lines, NULL },
7990 { ".debug_aranges", display_debug_aranges, NULL },
7991 { ".debug_pubnames", display_debug_pubnames, NULL },
7992 { ".debug_frame", display_debug_frames, NULL },
7993 { ".eh_frame", display_debug_frames, NULL },
7994 { ".debug_macinfo", display_debug_macinfo, NULL },
7995 { ".debug_str", display_debug_not_supported, NULL },
7996 { ".debug_static_func", display_debug_not_supported, NULL },
7997 { ".debug_static_vars", display_debug_not_supported, NULL },
7998 { ".debug_types", display_debug_not_supported, NULL },
7999 { ".debug_weaknames", display_debug_not_supported, NULL }
8003 display_debug_section (section, file)
8004 Elf32_Internal_Shdr * section;
8007 char * name = SECTION_NAME (section);
8008 bfd_size_type length;
8009 unsigned char * start;
8012 length = section->sh_size;
8015 printf (_("\nSection '%s' has no debugging data.\n"), name);
8019 start = (unsigned char *) get_data (NULL, file, section->sh_offset, length,
8020 _("debug section data"));
8024 /* See if we know how to display the contents of this section. */
8025 if (strncmp (name, ".gnu.linkonce.wi.", 17) == 0)
8026 name = ".debug_info";
8028 for (i = NUM_ELEM (debug_displays); i--;)
8029 if (strcmp (debug_displays[i].name, name) == 0)
8031 debug_displays[i].display (section, start, file);
8036 printf (_("Unrecognised debug section: %s\n"), name);
8040 /* If we loaded in the abbrev section at some point,
8041 we must release it here. */
8042 if (first_abbrev != NULL)
8049 process_section_contents (file)
8052 Elf32_Internal_Shdr * section;
8058 /* Pre-scan the debug sections to find some debug information not
8059 present in some of them. For the .debug_line, we must find out the
8060 size of address (specified in .debug_info and .debug_aranges). */
8061 for (i = 0, section = section_headers;
8062 i < elf_header.e_shnum && i < num_dump_sects;
8065 char * name = SECTION_NAME (section);
8068 if (section->sh_size == 0)
8071 /* See if there is some pre-scan operation for this section. */
8072 for (j = NUM_ELEM (debug_displays); j--;)
8073 if (strcmp (debug_displays[j].name, name) == 0)
8075 if (debug_displays[j].prescan != NULL)
8077 bfd_size_type length;
8078 unsigned char * start;
8080 length = section->sh_size;
8081 start = ((unsigned char *)
8082 get_data (NULL, file, section->sh_offset, length,
8083 _("debug section data")));
8087 debug_displays[j].prescan (section, start, file);
8095 for (i = 0, section = section_headers;
8096 i < elf_header.e_shnum && i < num_dump_sects;
8099 #ifdef SUPPORT_DISASSEMBLY
8100 if (dump_sects[i] & DISASS_DUMP)
8101 disassemble_section (section, file);
8103 if (dump_sects[i] & HEX_DUMP)
8104 dump_section (section, file);
8106 if (dump_sects[i] & DEBUG_DUMP)
8107 display_debug_section (section, file);
8110 if (i < num_dump_sects)
8111 warn (_("Some sections were not dumped because they do not exist!\n"));
8117 process_mips_fpe_exception (mask)
8123 if (mask & OEX_FPU_INEX)
8124 fputs ("INEX", stdout), first = 0;
8125 if (mask & OEX_FPU_UFLO)
8126 printf ("%sUFLO", first ? "" : "|"), first = 0;
8127 if (mask & OEX_FPU_OFLO)
8128 printf ("%sOFLO", first ? "" : "|"), first = 0;
8129 if (mask & OEX_FPU_DIV0)
8130 printf ("%sDIV0", first ? "" : "|"), first = 0;
8131 if (mask & OEX_FPU_INVAL)
8132 printf ("%sINVAL", first ? "" : "|");
8135 fputs ("0", stdout);
8139 process_mips_specific (file)
8142 Elf_Internal_Dyn * entry;
8143 size_t liblist_offset = 0;
8144 size_t liblistno = 0;
8145 size_t conflictsno = 0;
8146 size_t options_offset = 0;
8147 size_t conflicts_offset = 0;
8149 /* We have a lot of special sections. Thanks SGI! */
8150 if (dynamic_segment == NULL)
8151 /* No information available. */
8154 for (entry = dynamic_segment; entry->d_tag != DT_NULL; ++entry)
8155 switch (entry->d_tag)
8157 case DT_MIPS_LIBLIST:
8158 liblist_offset = entry->d_un.d_val - loadaddr;
8160 case DT_MIPS_LIBLISTNO:
8161 liblistno = entry->d_un.d_val;
8163 case DT_MIPS_OPTIONS:
8164 options_offset = entry->d_un.d_val - loadaddr;
8166 case DT_MIPS_CONFLICT:
8167 conflicts_offset = entry->d_un.d_val - loadaddr;
8169 case DT_MIPS_CONFLICTNO:
8170 conflictsno = entry->d_un.d_val;
8176 if (liblist_offset != 0 && liblistno != 0 && do_dynamic)
8178 Elf32_External_Lib * elib;
8181 elib = ((Elf32_External_Lib *)
8182 get_data (NULL, file, liblist_offset,
8183 liblistno * sizeof (Elf32_External_Lib),
8187 printf ("\nSection '.liblist' contains %lu entries:\n",
8188 (unsigned long) liblistno);
8189 fputs (" Library Time Stamp Checksum Version Flags\n",
8192 for (cnt = 0; cnt < liblistno; ++cnt)
8199 liblist.l_name = BYTE_GET (elib[cnt].l_name);
8200 time = BYTE_GET (elib[cnt].l_time_stamp);
8201 liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum);
8202 liblist.l_version = BYTE_GET (elib[cnt].l_version);
8203 liblist.l_flags = BYTE_GET (elib[cnt].l_flags);
8205 tmp = gmtime (&time);
8206 sprintf (timebuf, "%04u-%02u-%02uT%02u:%02u:%02u",
8207 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
8208 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
8210 printf ("%3lu: %-20s %s %#10lx %-7ld", (unsigned long) cnt,
8211 dynamic_strings + liblist.l_name, timebuf,
8212 liblist.l_checksum, liblist.l_version);
8214 if (liblist.l_flags == 0)
8225 { " EXACT_MATCH", LL_EXACT_MATCH },
8226 { " IGNORE_INT_VER", LL_IGNORE_INT_VER },
8227 { " REQUIRE_MINOR", LL_REQUIRE_MINOR },
8228 { " EXPORTS", LL_EXPORTS },
8229 { " DELAY_LOAD", LL_DELAY_LOAD },
8230 { " DELTA", LL_DELTA }
8232 int flags = liblist.l_flags;
8236 fcnt < sizeof (l_flags_vals) / sizeof (l_flags_vals[0]);
8238 if ((flags & l_flags_vals[fcnt].bit) != 0)
8240 fputs (l_flags_vals[fcnt].name, stdout);
8241 flags ^= l_flags_vals[fcnt].bit;
8244 printf (" %#x", (unsigned int) flags);
8254 if (options_offset != 0)
8256 Elf_External_Options * eopt;
8257 Elf_Internal_Shdr * sect = section_headers;
8258 Elf_Internal_Options * iopt;
8259 Elf_Internal_Options * option;
8263 /* Find the section header so that we get the size. */
8264 while (sect->sh_type != SHT_MIPS_OPTIONS)
8267 eopt = (Elf_External_Options *) get_data (NULL, file, options_offset,
8268 sect->sh_size, _("options"));
8271 iopt = ((Elf_Internal_Options *)
8272 malloc ((sect->sh_size / sizeof (eopt)) * sizeof (* iopt)));
8275 error (_("Out of memory"));
8282 while (offset < sect->sh_size)
8284 Elf_External_Options * eoption;
8286 eoption = (Elf_External_Options *) ((char *) eopt + offset);
8288 option->kind = BYTE_GET (eoption->kind);
8289 option->size = BYTE_GET (eoption->size);
8290 option->section = BYTE_GET (eoption->section);
8291 option->info = BYTE_GET (eoption->info);
8293 offset += option->size;
8299 printf (_("\nSection '%s' contains %d entries:\n"),
8300 SECTION_NAME (sect), cnt);
8308 switch (option->kind)
8311 /* This shouldn't happen. */
8312 printf (" NULL %d %lx", option->section, option->info);
8315 printf (" REGINFO ");
8316 if (elf_header.e_machine == EM_MIPS)
8319 Elf32_External_RegInfo * ereg;
8320 Elf32_RegInfo reginfo;
8322 ereg = (Elf32_External_RegInfo *) (option + 1);
8323 reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask);
8324 reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
8325 reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
8326 reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
8327 reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
8328 reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value);
8330 printf ("GPR %08lx GP 0x%lx\n",
8332 (unsigned long) reginfo.ri_gp_value);
8333 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
8334 reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
8335 reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
8340 Elf64_External_RegInfo * ereg;
8341 Elf64_Internal_RegInfo reginfo;
8343 ereg = (Elf64_External_RegInfo *) (option + 1);
8344 reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask);
8345 reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
8346 reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
8347 reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
8348 reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
8349 reginfo.ri_gp_value = BYTE_GET8 (ereg->ri_gp_value);
8351 printf ("GPR %08lx GP 0x",
8352 reginfo.ri_gprmask);
8353 printf_vma (reginfo.ri_gp_value);
8356 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
8357 reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
8358 reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
8362 case ODK_EXCEPTIONS:
8363 fputs (" EXCEPTIONS fpe_min(", stdout);
8364 process_mips_fpe_exception (option->info & OEX_FPU_MIN);
8365 fputs (") fpe_max(", stdout);
8366 process_mips_fpe_exception ((option->info & OEX_FPU_MAX) >> 8);
8367 fputs (")", stdout);
8369 if (option->info & OEX_PAGE0)
8370 fputs (" PAGE0", stdout);
8371 if (option->info & OEX_SMM)
8372 fputs (" SMM", stdout);
8373 if (option->info & OEX_FPDBUG)
8374 fputs (" FPDBUG", stdout);
8375 if (option->info & OEX_DISMISS)
8376 fputs (" DISMISS", stdout);
8379 fputs (" PAD ", stdout);
8380 if (option->info & OPAD_PREFIX)
8381 fputs (" PREFIX", stdout);
8382 if (option->info & OPAD_POSTFIX)
8383 fputs (" POSTFIX", stdout);
8384 if (option->info & OPAD_SYMBOL)
8385 fputs (" SYMBOL", stdout);
8388 fputs (" HWPATCH ", stdout);
8389 if (option->info & OHW_R4KEOP)
8390 fputs (" R4KEOP", stdout);
8391 if (option->info & OHW_R8KPFETCH)
8392 fputs (" R8KPFETCH", stdout);
8393 if (option->info & OHW_R5KEOP)
8394 fputs (" R5KEOP", stdout);
8395 if (option->info & OHW_R5KCVTL)
8396 fputs (" R5KCVTL", stdout);
8399 fputs (" FILL ", stdout);
8400 /* XXX Print content of info word? */
8403 fputs (" TAGS ", stdout);
8404 /* XXX Print content of info word? */
8407 fputs (" HWAND ", stdout);
8408 if (option->info & OHWA0_R4KEOP_CHECKED)
8409 fputs (" R4KEOP_CHECKED", stdout);
8410 if (option->info & OHWA0_R4KEOP_CLEAN)
8411 fputs (" R4KEOP_CLEAN", stdout);
8414 fputs (" HWOR ", stdout);
8415 if (option->info & OHWA0_R4KEOP_CHECKED)
8416 fputs (" R4KEOP_CHECKED", stdout);
8417 if (option->info & OHWA0_R4KEOP_CLEAN)
8418 fputs (" R4KEOP_CLEAN", stdout);
8421 printf (" GP_GROUP %#06lx self-contained %#06lx",
8422 option->info & OGP_GROUP,
8423 (option->info & OGP_SELF) >> 16);
8426 printf (" IDENT %#06lx self-contained %#06lx",
8427 option->info & OGP_GROUP,
8428 (option->info & OGP_SELF) >> 16);
8431 /* This shouldn't happen. */
8432 printf (" %3d ??? %d %lx",
8433 option->kind, option->section, option->info);
8437 len = sizeof (* eopt);
8438 while (len < option->size)
8439 if (((char *) option)[len] >= ' '
8440 && ((char *) option)[len] < 0x7f)
8441 printf ("%c", ((char *) option)[len++]);
8443 printf ("\\%03o", ((char *) option)[len++]);
8445 fputs ("\n", stdout);
8453 if (conflicts_offset != 0 && conflictsno != 0)
8455 Elf32_Conflict * iconf;
8458 if (dynamic_symbols == NULL)
8460 error (_("conflict list with without table"));
8464 iconf = (Elf32_Conflict *) malloc (conflictsno * sizeof (* iconf));
8467 error (_("Out of memory"));
8473 Elf32_External_Conflict * econf32;
8475 econf32 = ((Elf32_External_Conflict *)
8476 get_data (NULL, file, conflicts_offset,
8477 conflictsno * sizeof (* econf32),
8482 for (cnt = 0; cnt < conflictsno; ++cnt)
8483 iconf[cnt] = BYTE_GET (econf32[cnt]);
8489 Elf64_External_Conflict * econf64;
8491 econf64 = ((Elf64_External_Conflict *)
8492 get_data (NULL, file, conflicts_offset,
8493 conflictsno * sizeof (* econf64),
8498 for (cnt = 0; cnt < conflictsno; ++cnt)
8499 iconf[cnt] = BYTE_GET (econf64[cnt]);
8504 printf (_("\nSection '.conflict' contains %d entries:\n"), conflictsno);
8505 puts (_(" Num: Index Value Name"));
8507 for (cnt = 0; cnt < conflictsno; ++cnt)
8509 Elf_Internal_Sym * psym = &dynamic_symbols[iconf[cnt]];
8511 printf ("%5lu: %8lu ", (unsigned long) cnt, iconf[cnt]);
8512 print_vma (psym->st_value, FULL_HEX);
8513 printf (" %s\n", dynamic_strings + psym->st_name);
8523 get_note_type (e_type)
8526 static char buff[64];
8530 case NT_PRSTATUS: return _("NT_PRSTATUS (prstatus structure)");
8531 case NT_FPREGSET: return _("NT_FPREGSET (floating point registers)");
8532 case NT_PRPSINFO: return _("NT_PRPSINFO (prpsinfo structure)");
8533 case NT_TASKSTRUCT: return _("NT_TASKSTRUCT (task structure)");
8534 case NT_PRXFPREG: return _("NT_PRXFPREG (user_xfpregs structure)");
8535 case NT_PSTATUS: return _("NT_PSTATUS (pstatus structure)");
8536 case NT_FPREGS: return _("NT_FPREGS (floating point registers)");
8537 case NT_PSINFO: return _("NT_PSINFO (psinfo structure)");
8538 case NT_LWPSTATUS: return _("NT_LWPSTATUS (lwpstatus_t structure)");
8539 case NT_LWPSINFO: return _("NT_LWPSINFO (lwpsinfo_t structure)");
8540 case NT_WIN32PSTATUS: return _("NT_WIN32PSTATUS (win32_pstatus strcuture)");
8542 sprintf (buff, _("Unknown note type: (0x%08x)"), e_type);
8547 /* Note that by the ELF standard, the name field is already null byte
8548 terminated, and namesz includes the terminating null byte.
8549 I.E. the value of namesz for the name "FSF" is 4.
8551 If the value of namesz is zero, there is no name present. */
8553 process_note (pnote)
8554 Elf32_Internal_Note * pnote;
8556 printf (" %s\t\t0x%08lx\t%s\n",
8557 pnote->namesz ? pnote->namedata : "(NONE)",
8558 pnote->descsz, get_note_type (pnote->type));
8564 process_corefile_note_segment (file, offset, length)
8569 Elf_External_Note * pnotes;
8570 Elf_External_Note * external;
8576 pnotes = (Elf_External_Note *) get_data (NULL, file, offset, length,
8583 printf (_("\nNotes at offset 0x%08lx with length 0x%08lx:\n"),
8584 (unsigned long) offset, (unsigned long) length);
8585 printf (_(" Owner\t\tData size\tDescription\n"));
8587 while (external < (Elf_External_Note *)((char *) pnotes + length))
8589 Elf32_Internal_Note inote;
8592 inote.type = BYTE_GET (external->type);
8593 inote.namesz = BYTE_GET (external->namesz);
8594 inote.namedata = external->name;
8595 inote.descsz = BYTE_GET (external->descsz);
8596 inote.descdata = inote.namedata + align_power (inote.namesz, 2);
8597 inote.descpos = offset + (inote.descdata - (char *) pnotes);
8599 external = (Elf_External_Note *)(inote.descdata + align_power (inote.descsz, 2));
8601 /* Verify that name is null terminated. It appears that at least
8602 one version of Linux (RedHat 6.0) generates corefiles that don't
8603 comply with the ELF spec by failing to include the null byte in
8605 if (inote.namedata[inote.namesz] != '\0')
8607 temp = malloc (inote.namesz + 1);
8611 error (_("Out of memory\n"));
8616 strncpy (temp, inote.namedata, inote.namesz);
8617 temp[inote.namesz] = 0;
8619 /* warn (_("'%s' NOTE name not properly null terminated\n"), temp); */
8620 inote.namedata = temp;
8623 res &= process_note (& inote);
8638 process_corefile_note_segments (file)
8641 Elf_Internal_Phdr * program_headers;
8642 Elf_Internal_Phdr * segment;
8646 program_headers = (Elf_Internal_Phdr *) malloc
8647 (elf_header.e_phnum * sizeof (Elf_Internal_Phdr));
8649 if (program_headers == NULL)
8651 error (_("Out of memory\n"));
8656 i = get_32bit_program_headers (file, program_headers);
8658 i = get_64bit_program_headers (file, program_headers);
8662 free (program_headers);
8666 for (i = 0, segment = program_headers;
8667 i < elf_header.e_phnum;
8670 if (segment->p_type == PT_NOTE)
8671 res &= process_corefile_note_segment (file,
8672 (bfd_vma) segment->p_offset,
8673 (bfd_vma) segment->p_filesz);
8676 free (program_headers);
8682 process_corefile_contents (file)
8685 /* If we have not been asked to display the notes then do nothing. */
8689 /* If file is not a core file then exit. */
8690 if (elf_header.e_type != ET_CORE)
8693 /* No program headers means no NOTE segment. */
8694 if (elf_header.e_phnum == 0)
8696 printf (_("No note segments present in the core file.\n"));
8700 return process_corefile_note_segments (file);
8704 process_arch_specific (file)
8710 switch (elf_header.e_machine)
8713 case EM_MIPS_RS3_LE:
8714 return process_mips_specific (file);
8723 get_file_header (file)
8726 /* Read in the identity array. */
8727 if (fread (elf_header.e_ident, EI_NIDENT, 1, file) != 1)
8730 /* Determine how to read the rest of the header. */
8731 switch (elf_header.e_ident [EI_DATA])
8733 default: /* fall through */
8734 case ELFDATANONE: /* fall through */
8735 case ELFDATA2LSB: byte_get = byte_get_little_endian; break;
8736 case ELFDATA2MSB: byte_get = byte_get_big_endian; break;
8739 /* For now we only support 32 bit and 64 bit ELF files. */
8740 is_32bit_elf = (elf_header.e_ident [EI_CLASS] != ELFCLASS64);
8742 /* Read in the rest of the header. */
8745 Elf32_External_Ehdr ehdr32;
8747 if (fread (ehdr32.e_type, sizeof (ehdr32) - EI_NIDENT, 1, file) != 1)
8750 elf_header.e_type = BYTE_GET (ehdr32.e_type);
8751 elf_header.e_machine = BYTE_GET (ehdr32.e_machine);
8752 elf_header.e_version = BYTE_GET (ehdr32.e_version);
8753 elf_header.e_entry = BYTE_GET (ehdr32.e_entry);
8754 elf_header.e_phoff = BYTE_GET (ehdr32.e_phoff);
8755 elf_header.e_shoff = BYTE_GET (ehdr32.e_shoff);
8756 elf_header.e_flags = BYTE_GET (ehdr32.e_flags);
8757 elf_header.e_ehsize = BYTE_GET (ehdr32.e_ehsize);
8758 elf_header.e_phentsize = BYTE_GET (ehdr32.e_phentsize);
8759 elf_header.e_phnum = BYTE_GET (ehdr32.e_phnum);
8760 elf_header.e_shentsize = BYTE_GET (ehdr32.e_shentsize);
8761 elf_header.e_shnum = BYTE_GET (ehdr32.e_shnum);
8762 elf_header.e_shstrndx = BYTE_GET (ehdr32.e_shstrndx);
8766 Elf64_External_Ehdr ehdr64;
8768 /* If we have been compiled with sizeof (bfd_vma) == 4, then
8769 we will not be able to cope with the 64bit data found in
8770 64 ELF files. Detect this now and abort before we start
8771 overwritting things. */
8772 if (sizeof (bfd_vma) < 8)
8774 error (_("This instance of readelf has been built without support for a\n"));
8775 error (_("64 bit data type and so it cannot read 64 bit ELF files.\n"));
8779 if (fread (ehdr64.e_type, sizeof (ehdr64) - EI_NIDENT, 1, file) != 1)
8782 elf_header.e_type = BYTE_GET (ehdr64.e_type);
8783 elf_header.e_machine = BYTE_GET (ehdr64.e_machine);
8784 elf_header.e_version = BYTE_GET (ehdr64.e_version);
8785 elf_header.e_entry = BYTE_GET8 (ehdr64.e_entry);
8786 elf_header.e_phoff = BYTE_GET8 (ehdr64.e_phoff);
8787 elf_header.e_shoff = BYTE_GET8 (ehdr64.e_shoff);
8788 elf_header.e_flags = BYTE_GET (ehdr64.e_flags);
8789 elf_header.e_ehsize = BYTE_GET (ehdr64.e_ehsize);
8790 elf_header.e_phentsize = BYTE_GET (ehdr64.e_phentsize);
8791 elf_header.e_phnum = BYTE_GET (ehdr64.e_phnum);
8792 elf_header.e_shentsize = BYTE_GET (ehdr64.e_shentsize);
8793 elf_header.e_shnum = BYTE_GET (ehdr64.e_shnum);
8794 elf_header.e_shstrndx = BYTE_GET (ehdr64.e_shstrndx);
8801 process_file (file_name)
8805 struct stat statbuf;
8808 if (stat (file_name, & statbuf) < 0)
8810 error (_("Cannot stat input file %s.\n"), file_name);
8814 file = fopen (file_name, "rb");
8817 error (_("Input file %s not found.\n"), file_name);
8821 if (! get_file_header (file))
8823 error (_("%s: Failed to read file header\n"), file_name);
8828 /* Initialise per file variables. */
8829 for (i = NUM_ELEM (version_info); i--;)
8830 version_info[i] = 0;
8832 for (i = NUM_ELEM (dynamic_info); i--;)
8833 dynamic_info[i] = 0;
8835 /* Process the file. */
8837 printf (_("\nFile: %s\n"), file_name);
8839 if (! process_file_header ())
8845 process_section_headers (file);
8847 process_program_headers (file);
8849 process_dynamic_segment (file);
8851 process_relocs (file);
8853 process_unwind (file);
8855 process_symbol_table (file);
8857 process_syminfo (file);
8859 process_version_sections (file);
8861 process_section_contents (file);
8863 process_corefile_contents (file);
8865 process_arch_specific (file);
8869 if (section_headers)
8871 free (section_headers);
8872 section_headers = NULL;
8877 free (string_table);
8878 string_table = NULL;
8879 string_table_length = 0;
8882 if (dynamic_strings)
8884 free (dynamic_strings);
8885 dynamic_strings = NULL;
8888 if (dynamic_symbols)
8890 free (dynamic_symbols);
8891 dynamic_symbols = NULL;
8892 num_dynamic_syms = 0;
8895 if (dynamic_syminfo)
8897 free (dynamic_syminfo);
8898 dynamic_syminfo = NULL;
8904 #ifdef SUPPORT_DISASSEMBLY
8905 /* Needed by the i386 disassembler. For extra credit, someone could
8906 fix this so that we insert symbolic addresses here, esp for GOT/PLT
8910 print_address (unsigned int addr, FILE * outfile)
8912 fprintf (outfile,"0x%8.8x", addr);
8915 /* Needed by the i386 disassembler. */
8917 db_task_printsym (unsigned int addr)
8919 print_address (addr, stderr);
8930 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
8931 setlocale (LC_MESSAGES, "");
8933 bindtextdomain (PACKAGE, LOCALEDIR);
8934 textdomain (PACKAGE);
8936 parse_args (argc, argv);
8938 if (optind < (argc - 1))
8942 while (optind < argc)
8943 err |= process_file (argv [optind ++]);
8945 if (dump_sects != NULL)