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"
70 #include "elf/mcore.h"
77 #include "elf/x86-64.h"
83 char * program_name = "readelf";
84 unsigned int dynamic_addr;
85 bfd_size_type dynamic_size;
86 unsigned int rela_addr;
87 unsigned int rela_size;
88 char * dynamic_strings;
90 unsigned long string_table_length;
91 unsigned long num_dynamic_syms;
92 Elf_Internal_Sym * dynamic_symbols;
93 Elf_Internal_Syminfo * dynamic_syminfo;
94 unsigned long dynamic_syminfo_offset;
95 unsigned int dynamic_syminfo_nent;
96 char program_interpreter [64];
97 int dynamic_info[DT_JMPREL + 1];
100 Elf_Internal_Ehdr elf_header;
101 Elf_Internal_Shdr * section_headers;
102 Elf_Internal_Dyn * dynamic_segment;
110 int do_using_dynamic;
117 int do_debug_abbrevs;
119 int do_debug_pubnames;
120 int do_debug_aranges;
122 int do_debug_frames_interp;
123 int do_debug_macinfo;
128 /* A dynamic array of flags indicating which sections require dumping. */
129 char * dump_sects = NULL;
130 unsigned int num_dump_sects = 0;
132 #define HEX_DUMP (1 << 0)
133 #define DISASS_DUMP (1 << 1)
134 #define DEBUG_DUMP (1 << 2)
136 /* How to rpint a vma value. */
137 typedef enum print_mode
149 /* Forward declarations for dumb compilers. */
150 static void print_vma PARAMS ((bfd_vma, print_mode));
151 static bfd_vma (* byte_get) PARAMS ((unsigned char *, int));
152 static bfd_vma byte_get_little_endian PARAMS ((unsigned char *, int));
153 static bfd_vma byte_get_big_endian PARAMS ((unsigned char *, int));
154 static const char * get_mips_dynamic_type PARAMS ((unsigned long));
155 static const char * get_sparc64_dynamic_type PARAMS ((unsigned long));
156 static const char * get_parisc_dynamic_type PARAMS ((unsigned long));
157 static const char * get_dynamic_type PARAMS ((unsigned long));
158 static int slurp_rela_relocs PARAMS ((FILE *, unsigned long, unsigned long, Elf_Internal_Rela **, unsigned long *));
159 static int slurp_rel_relocs PARAMS ((FILE *, unsigned long, unsigned long, Elf_Internal_Rel **, unsigned long *));
160 static int dump_relocations PARAMS ((FILE *, unsigned long, unsigned long, Elf_Internal_Sym *, unsigned long, char *, int));
161 static char * get_file_type PARAMS ((unsigned));
162 static char * get_machine_name PARAMS ((unsigned));
163 static void decode_ARM_machine_flags PARAMS ((unsigned, char []));
164 static char * get_machine_flags PARAMS ((unsigned, unsigned));
165 static const char * get_mips_segment_type PARAMS ((unsigned long));
166 static const char * get_parisc_segment_type PARAMS ((unsigned long));
167 static const char * get_ia64_segment_type PARAMS ((unsigned long));
168 static const char * get_segment_type PARAMS ((unsigned long));
169 static const char * get_mips_section_type_name PARAMS ((unsigned int));
170 static const char * get_parisc_section_type_name PARAMS ((unsigned int));
171 static const char * get_ia64_section_type_name PARAMS ((unsigned int));
172 static const char * get_section_type_name PARAMS ((unsigned int));
173 static const char * get_symbol_binding PARAMS ((unsigned int));
174 static const char * get_symbol_type PARAMS ((unsigned int));
175 static const char * get_symbol_visibility PARAMS ((unsigned int));
176 static const char * get_symbol_index_type PARAMS ((unsigned int));
177 static const char * get_dynamic_flags PARAMS ((bfd_vma));
178 static void usage PARAMS ((void));
179 static void parse_args PARAMS ((int, char **));
180 static int process_file_header PARAMS ((void));
181 static int process_program_headers PARAMS ((FILE *));
182 static int process_section_headers PARAMS ((FILE *));
183 static int process_unwind PARAMS ((FILE *));
184 static void dynamic_segment_mips_val PARAMS ((Elf_Internal_Dyn *));
185 static void dynamic_segment_parisc_val PARAMS ((Elf_Internal_Dyn *));
186 static int process_dynamic_segment PARAMS ((FILE *));
187 static int process_symbol_table PARAMS ((FILE *));
188 static int process_syminfo PARAMS ((FILE *));
189 static int process_section_contents PARAMS ((FILE *));
190 static void process_mips_fpe_exception PARAMS ((int));
191 static int process_mips_specific PARAMS ((FILE *));
192 static int process_file PARAMS ((char *));
193 static int process_relocs PARAMS ((FILE *));
194 static int process_version_sections PARAMS ((FILE *));
195 static char * get_ver_flags PARAMS ((unsigned int));
196 static int get_32bit_section_headers PARAMS ((FILE *));
197 static int get_64bit_section_headers PARAMS ((FILE *));
198 static int get_32bit_program_headers PARAMS ((FILE *, Elf_Internal_Phdr *));
199 static int get_64bit_program_headers PARAMS ((FILE *, Elf_Internal_Phdr *));
200 static int get_file_header PARAMS ((FILE *));
201 static Elf_Internal_Sym * get_32bit_elf_symbols PARAMS ((FILE *, unsigned long, unsigned long));
202 static Elf_Internal_Sym * get_64bit_elf_symbols PARAMS ((FILE *, unsigned long, unsigned long));
203 static const char * get_elf_section_flags PARAMS ((bfd_vma));
204 static int * get_dynamic_data PARAMS ((FILE *, unsigned int));
205 static int get_32bit_dynamic_segment PARAMS ((FILE *));
206 static int get_64bit_dynamic_segment PARAMS ((FILE *));
207 #ifdef SUPPORT_DISASSEMBLY
208 static int disassemble_section PARAMS ((Elf32_Internal_Shdr *, FILE *));
210 static int dump_section PARAMS ((Elf32_Internal_Shdr *, FILE *));
211 static int display_debug_section PARAMS ((Elf32_Internal_Shdr *, FILE *));
212 static int display_debug_info PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
213 static int display_debug_not_supported PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
214 static int prescan_debug_info PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
215 static int display_debug_lines PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
216 static int display_debug_pubnames PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
217 static int display_debug_abbrev PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
218 static int display_debug_aranges PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
219 static int display_debug_frames PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
220 static int display_debug_macinfo PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
221 static unsigned char * process_abbrev_section PARAMS ((unsigned char *, unsigned char *));
222 static unsigned long read_leb128 PARAMS ((unsigned char *, int *, int));
223 static int process_extended_line_op PARAMS ((unsigned char *, int, int));
224 static void reset_state_machine PARAMS ((int));
225 static char * get_TAG_name PARAMS ((unsigned long));
226 static char * get_AT_name PARAMS ((unsigned long));
227 static char * get_FORM_name PARAMS ((unsigned long));
228 static void free_abbrevs PARAMS ((void));
229 static void add_abbrev PARAMS ((unsigned long, unsigned long, int));
230 static void add_abbrev_attr PARAMS ((unsigned long, unsigned long));
231 static unsigned char * read_and_display_attr PARAMS ((unsigned long, unsigned long, unsigned char *, unsigned long, unsigned long));
232 static unsigned char * display_block PARAMS ((unsigned char *, unsigned long));
233 static void decode_location_expression PARAMS ((unsigned char *, unsigned int, unsigned long));
234 static void request_dump PARAMS ((unsigned int, char));
235 static const char * get_elf_class PARAMS ((unsigned char));
236 static const char * get_data_encoding PARAMS ((unsigned char));
237 static const char * get_osabi_name PARAMS ((unsigned char));
238 static int guess_is_rela PARAMS ((unsigned long));
239 static char * get_note_type PARAMS ((unsigned int));
240 static int process_note PARAMS ((Elf32_Internal_Note *));
241 static int process_corefile_note_segment PARAMS ((FILE *, bfd_vma, bfd_vma));
242 static int process_corefile_note_segments PARAMS ((FILE *));
243 static int process_corefile_contents PARAMS ((FILE *));
244 static int process_arch_specific PARAMS ((FILE *));
246 typedef int Elf32_Word;
254 #define SECTION_NAME(X) ((X) == NULL ? "<none>" : \
255 ((X)->sh_name >= string_table_length \
256 ? "<corrupt>" : string_table + (X)->sh_name))
258 #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
260 #define BYTE_GET(field) byte_get (field, sizeof (field))
262 /* If we can support a 64 bit data type then BFD64 should be defined
263 and sizeof (bfd_vma) == 8. In this case when translating from an
264 external 8 byte field to an internal field, we can assume that the
265 internal field is also 8 bytes wide and so we can extract all the data.
266 If, however, BFD64 is not defined, then we must assume that the
267 internal data structure only has 4 byte wide fields that are the
268 equivalent of the 8 byte wide external counterparts, and so we must
269 truncate the data. */
271 #define BYTE_GET8(field) byte_get (field, -8)
273 #define BYTE_GET8(field) byte_get (field, 8)
276 #define NUM_ELEM(array) (sizeof (array) / sizeof ((array)[0]))
278 #define GET_ELF_SYMBOLS(file, offset, size) \
279 (is_32bit_elf ? get_32bit_elf_symbols (file, offset, size) \
280 : get_64bit_elf_symbols (file, offset, size))
283 #ifdef ANSI_PROTOTYPES
285 error (const char * message, ...)
289 fprintf (stderr, _("%s: Error: "), program_name);
290 va_start (args, message);
291 vfprintf (stderr, message, args);
297 warn (const char * message, ...)
301 fprintf (stderr, _("%s: Warning: "), program_name);
302 va_start (args, message);
303 vfprintf (stderr, message, args);
315 fprintf (stderr, _("%s: Error: "), program_name);
317 message = va_arg (args, char *);
318 vfprintf (stderr, message, args);
330 fprintf (stderr, _("%s: Warning: "), program_name);
332 message = va_arg (args, char *);
333 vfprintf (stderr, message, args);
339 static PTR get_data PARAMS ((PTR, FILE *, long, size_t, const char *));
342 get_data (var, file, offset, size, reason)
354 if (fseek (file, offset, SEEK_SET))
356 error (_("Unable to seek to %x for %s\n"), offset, reason);
363 mvar = (PTR) malloc (size);
367 error (_("Out of memory allocating %d bytes for %s\n"),
373 if (fread (mvar, size, 1, file) != 1)
375 error (_("Unable to read in %d bytes of %s\n"), size, reason);
385 byte_get_little_endian (field, size)
386 unsigned char * field;
395 return ((unsigned int) (field [0]))
396 | (((unsigned int) (field [1])) << 8);
400 /* We want to extract data from an 8 byte wide field and
401 place it into a 4 byte wide field. Since this is a little
402 endian source we can juts use the 4 byte extraction code. */
406 return ((unsigned long) (field [0]))
407 | (((unsigned long) (field [1])) << 8)
408 | (((unsigned long) (field [2])) << 16)
409 | (((unsigned long) (field [3])) << 24);
414 /* This is a special case, generated by the BYTE_GET8 macro.
415 It means that we are loading an 8 byte value from a field
416 in an external structure into an 8 byte value in a field
417 in an internal strcuture. */
418 return ((bfd_vma) (field [0]))
419 | (((bfd_vma) (field [1])) << 8)
420 | (((bfd_vma) (field [2])) << 16)
421 | (((bfd_vma) (field [3])) << 24)
422 | (((bfd_vma) (field [4])) << 32)
423 | (((bfd_vma) (field [5])) << 40)
424 | (((bfd_vma) (field [6])) << 48)
425 | (((bfd_vma) (field [7])) << 56);
428 error (_("Unhandled data length: %d\n"), size);
433 /* Print a VMA value. */
435 print_vma (vma, mode)
445 case FULL_HEX: printf ("0x"); /* drop through */
446 case LONG_HEX: printf ("%8.8lx", (unsigned long) vma); break;
447 case PREFIX_HEX: printf ("0x"); /* drop through */
448 case HEX: printf ("%lx", (unsigned long) vma); break;
449 case DEC: printf ("%ld", (unsigned long) vma); break;
450 case DEC_5: printf ("%5ld", (long) vma); break;
451 case UNSIGNED: printf ("%lu", (unsigned long) vma); break;
472 #if BFD_HOST_64BIT_LONG
475 if (_bfd_int64_high (vma))
476 printf ("%lx%8.8lx", _bfd_int64_high (vma), _bfd_int64_low (vma));
478 printf ("%lx", _bfd_int64_low (vma));
483 #if BFD_HOST_64BIT_LONG
486 if (_bfd_int64_high (vma))
488 printf ("++%ld", _bfd_int64_low (vma));
490 printf ("%ld", _bfd_int64_low (vma));
495 #if BFD_HOST_64BIT_LONG
496 printf ("%5ld", vma);
498 if (_bfd_int64_high (vma))
500 printf ("++%ld", _bfd_int64_low (vma));
502 printf ("%5ld", _bfd_int64_low (vma));
507 #if BFD_HOST_64BIT_LONG
510 if (_bfd_int64_high (vma))
512 printf ("++%lu", _bfd_int64_low (vma));
514 printf ("%lu", _bfd_int64_low (vma));
523 byte_get_big_endian (field, size)
524 unsigned char * field;
533 return ((unsigned int) (field [1])) | (((int) (field [0])) << 8);
536 return ((unsigned long) (field [3]))
537 | (((unsigned long) (field [2])) << 8)
538 | (((unsigned long) (field [1])) << 16)
539 | (((unsigned long) (field [0])) << 24);
543 /* Although we are extracing data from an 8 byte wide field, we
544 are returning only 4 bytes of data. */
545 return ((unsigned long) (field [7]))
546 | (((unsigned long) (field [6])) << 8)
547 | (((unsigned long) (field [5])) << 16)
548 | (((unsigned long) (field [4])) << 24);
552 /* This is a special case, generated by the BYTE_GET8 macro.
553 It means that we are loading an 8 byte value from a field
554 in an external structure into an 8 byte value in a field
555 in an internal strcuture. */
556 return ((bfd_vma) (field [7]))
557 | (((bfd_vma) (field [6])) << 8)
558 | (((bfd_vma) (field [5])) << 16)
559 | (((bfd_vma) (field [4])) << 24)
560 | (((bfd_vma) (field [3])) << 32)
561 | (((bfd_vma) (field [2])) << 40)
562 | (((bfd_vma) (field [1])) << 48)
563 | (((bfd_vma) (field [0])) << 56);
567 error (_("Unhandled data length: %d\n"), size);
572 /* Guess the relocation size commonly used by the specific machines. */
575 guess_is_rela (e_machine)
576 unsigned long e_machine;
580 /* Targets that use REL relocations. */
593 /* Targets that use RELA relocations. */
607 case EM_CYGNUS_MN10200:
609 case EM_CYGNUS_MN10300:
644 warn (_("Don't know about relocations on this machine architecture\n"));
650 slurp_rela_relocs (file, rel_offset, rel_size, relasp, nrelasp)
652 unsigned long rel_offset;
653 unsigned long rel_size;
654 Elf_Internal_Rela **relasp;
655 unsigned long *nrelasp;
657 Elf_Internal_Rela *relas;
658 unsigned long nrelas;
663 Elf32_External_Rela * erelas;
665 erelas = (Elf32_External_Rela *) get_data (NULL, file, rel_offset,
666 rel_size, _("relocs"));
670 nrelas = rel_size / sizeof (Elf32_External_Rela);
672 relas = (Elf_Internal_Rela *)
673 malloc (nrelas * sizeof (Elf_Internal_Rela));
677 error(_("out of memory parsing relocs"));
681 for (i = 0; i < nrelas; i++)
683 relas[i].r_offset = BYTE_GET (erelas[i].r_offset);
684 relas[i].r_info = BYTE_GET (erelas[i].r_info);
685 relas[i].r_addend = BYTE_GET (erelas[i].r_addend);
692 Elf64_External_Rela * erelas;
694 erelas = (Elf64_External_Rela *) get_data (NULL, file, rel_offset,
695 rel_size, _("relocs"));
699 nrelas = rel_size / sizeof (Elf64_External_Rela);
701 relas = (Elf_Internal_Rela *)
702 malloc (nrelas * sizeof (Elf_Internal_Rela));
706 error(_("out of memory parsing relocs"));
710 for (i = 0; i < nrelas; i++)
712 relas[i].r_offset = BYTE_GET8 (erelas[i].r_offset);
713 relas[i].r_info = BYTE_GET8 (erelas[i].r_info);
714 relas[i].r_addend = BYTE_GET8 (erelas[i].r_addend);
725 slurp_rel_relocs (file, rel_offset, rel_size, relsp, nrelsp)
727 unsigned long rel_offset;
728 unsigned long rel_size;
729 Elf_Internal_Rel **relsp;
730 unsigned long *nrelsp;
732 Elf_Internal_Rel *rels;
738 Elf32_External_Rel * erels;
740 erels = (Elf32_External_Rel *) get_data (NULL, file, rel_offset,
741 rel_size, _("relocs"));
745 nrels = rel_size / sizeof (Elf32_External_Rel);
747 rels = (Elf_Internal_Rel *) malloc (nrels * sizeof (Elf_Internal_Rel));
751 error(_("out of memory parsing relocs"));
755 for (i = 0; i < nrels; i++)
757 rels[i].r_offset = BYTE_GET (erels[i].r_offset);
758 rels[i].r_info = BYTE_GET (erels[i].r_info);
765 Elf64_External_Rel * erels;
767 erels = (Elf64_External_Rel *) get_data (NULL, file, rel_offset,
768 rel_size, _("relocs"));
772 nrels = rel_size / sizeof (Elf64_External_Rel);
774 rels = (Elf_Internal_Rel *) malloc (nrels * sizeof (Elf_Internal_Rel));
778 error(_("out of memory parsing relocs"));
782 for (i = 0; i < nrels; i++)
784 rels[i].r_offset = BYTE_GET8 (erels[i].r_offset);
785 rels[i].r_info = BYTE_GET8 (erels[i].r_info);
795 /* Display the contents of the relocation data found at the specified offset. */
797 dump_relocations (file, rel_offset, rel_size, symtab, nsyms, strtab, is_rela)
799 unsigned long rel_offset;
800 unsigned long rel_size;
801 Elf_Internal_Sym * symtab;
807 Elf_Internal_Rel * rels;
808 Elf_Internal_Rela * relas;
811 if (is_rela == UNKNOWN)
812 is_rela = guess_is_rela (elf_header.e_machine);
816 if (!slurp_rela_relocs (file, rel_offset, rel_size, &relas, &rel_size))
821 if (!slurp_rel_relocs (file, rel_offset, rel_size, &rels, &rel_size))
829 (_(" Offset Info Type Symbol's Value Symbol's Name Addend\n"));
832 (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
838 (_(" Offset Info Type Symbol's Value Symbol's Name Addend\n"));
841 (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
844 for (i = 0; i < rel_size; i++)
849 bfd_vma symtab_index;
854 offset = relas [i].r_offset;
855 info = relas [i].r_info;
859 offset = rels [i].r_offset;
860 info = rels [i].r_info;
865 type = ELF32_R_TYPE (info);
866 symtab_index = ELF32_R_SYM (info);
870 if (elf_header.e_machine == EM_SPARCV9)
871 type = ELF64_R_TYPE_ID (info);
873 type = ELF64_R_TYPE (info);
874 /* The #ifdef BFD64 below is to prevent a compile time warning.
875 We know that if we do not have a 64 bit data type that we
876 will never execute this code anyway. */
878 symtab_index = ELF64_R_SYM (info);
884 #ifdef _bfd_int64_low
885 printf ("%8.8lx %8.8lx ", _bfd_int64_low (offset), _bfd_int64_low (info));
887 printf ("%8.8lx %8.8lx ", offset, info);
892 #ifdef _bfd_int64_low
893 printf ("%8.8lx%8.8lx %8.8lx%8.8lx ",
894 _bfd_int64_high (offset),
895 _bfd_int64_low (offset),
896 _bfd_int64_high (info),
897 _bfd_int64_low (info));
899 printf ("%16.16lx %16.16lx ", offset, info);
903 switch (elf_header.e_machine)
911 rtype = elf_m32r_reloc_type (type);
916 rtype = elf_i386_reloc_type (type);
920 rtype = elf_m68k_reloc_type (type);
924 rtype = elf_i960_reloc_type (type);
929 rtype = elf_avr_reloc_type (type);
936 rtype = elf_sparc_reloc_type (type);
941 rtype = v850_reloc_type (type);
946 rtype = elf_d10v_reloc_type (type);
951 rtype = elf_d30v_reloc_type (type);
955 rtype = elf_sh_reloc_type (type);
959 case EM_CYGNUS_MN10300:
960 rtype = elf_mn10300_reloc_type (type);
964 case EM_CYGNUS_MN10200:
965 rtype = elf_mn10200_reloc_type (type);
970 rtype = elf_fr30_reloc_type (type);
974 rtype = elf_mcore_reloc_type (type);
979 rtype = elf_ppc_reloc_type (type);
984 rtype = elf_mips_reloc_type (type);
988 rtype = elf_alpha_reloc_type (type);
992 rtype = elf_arm_reloc_type (type);
996 rtype = elf_arc_reloc_type (type);
1000 rtype = elf_hppa_reloc_type (type);
1006 rtype = elf_h8_reloc_type (type);
1011 rtype = elf_pj_reloc_type (type);
1014 rtype = elf_ia64_reloc_type (type);
1018 rtype = elf_cris_reloc_type (type);
1022 rtype = elf_i860_reloc_type (type);
1026 rtype = elf_x86_64_reloc_type (type);
1031 rtype = elf_s390_reloc_type (type);
1036 #ifdef _bfd_int64_low
1037 printf (_("unrecognised: %-7lx"), _bfd_int64_low (type));
1039 printf (_("unrecognised: %-7lx"), type);
1042 printf ("%-21.21s", rtype);
1046 if (symtab == NULL || symtab_index >= nsyms)
1047 printf (" bad symbol index: %08lx", (unsigned long) symtab_index);
1050 Elf_Internal_Sym * psym;
1052 psym = symtab + symtab_index;
1055 print_vma (psym->st_value, LONG_HEX);
1058 if (psym->st_name == 0)
1060 SECTION_NAME (section_headers + psym->st_shndx));
1061 else if (strtab == NULL)
1062 printf (_("<string table index %3ld>"), psym->st_name);
1064 printf ("%-25.25s", strtab + psym->st_name);
1067 printf (" + %lx", (unsigned long) relas [i].r_addend);
1072 printf ("%*c", is_32bit_elf ? 34 : 26, ' ');
1073 print_vma (relas[i].r_addend, LONG_HEX);
1076 if (elf_header.e_machine == EM_SPARCV9
1077 && !strcmp (rtype, "R_SPARC_OLO10"))
1078 printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (info));
1092 get_mips_dynamic_type (type)
1097 case DT_MIPS_RLD_VERSION: return "MIPS_RLD_VERSION";
1098 case DT_MIPS_TIME_STAMP: return "MIPS_TIME_STAMP";
1099 case DT_MIPS_ICHECKSUM: return "MIPS_ICHECKSUM";
1100 case DT_MIPS_IVERSION: return "MIPS_IVERSION";
1101 case DT_MIPS_FLAGS: return "MIPS_FLAGS";
1102 case DT_MIPS_BASE_ADDRESS: return "MIPS_BASE_ADDRESS";
1103 case DT_MIPS_MSYM: return "MIPS_MSYM";
1104 case DT_MIPS_CONFLICT: return "MIPS_CONFLICT";
1105 case DT_MIPS_LIBLIST: return "MIPS_LIBLIST";
1106 case DT_MIPS_LOCAL_GOTNO: return "MIPS_LOCAL_GOTNO";
1107 case DT_MIPS_CONFLICTNO: return "MIPS_CONFLICTNO";
1108 case DT_MIPS_LIBLISTNO: return "MIPS_LIBLISTNO";
1109 case DT_MIPS_SYMTABNO: return "MIPS_SYMTABNO";
1110 case DT_MIPS_UNREFEXTNO: return "MIPS_UNREFEXTNO";
1111 case DT_MIPS_GOTSYM: return "MIPS_GOTSYM";
1112 case DT_MIPS_HIPAGENO: return "MIPS_HIPAGENO";
1113 case DT_MIPS_RLD_MAP: return "MIPS_RLD_MAP";
1114 case DT_MIPS_DELTA_CLASS: return "MIPS_DELTA_CLASS";
1115 case DT_MIPS_DELTA_CLASS_NO: return "MIPS_DELTA_CLASS_NO";
1116 case DT_MIPS_DELTA_INSTANCE: return "MIPS_DELTA_INSTANCE";
1117 case DT_MIPS_DELTA_INSTANCE_NO: return "MIPS_DELTA_INSTANCE_NO";
1118 case DT_MIPS_DELTA_RELOC: return "MIPS_DELTA_RELOC";
1119 case DT_MIPS_DELTA_RELOC_NO: return "MIPS_DELTA_RELOC_NO";
1120 case DT_MIPS_DELTA_SYM: return "MIPS_DELTA_SYM";
1121 case DT_MIPS_DELTA_SYM_NO: return "MIPS_DELTA_SYM_NO";
1122 case DT_MIPS_DELTA_CLASSSYM: return "MIPS_DELTA_CLASSSYM";
1123 case DT_MIPS_DELTA_CLASSSYM_NO: return "MIPS_DELTA_CLASSSYM_NO";
1124 case DT_MIPS_CXX_FLAGS: return "MIPS_CXX_FLAGS";
1125 case DT_MIPS_PIXIE_INIT: return "MIPS_PIXIE_INIT";
1126 case DT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB";
1127 case DT_MIPS_LOCALPAGE_GOTIDX: return "MIPS_LOCALPAGE_GOTIDX";
1128 case DT_MIPS_LOCAL_GOTIDX: return "MIPS_LOCAL_GOTIDX";
1129 case DT_MIPS_HIDDEN_GOTIDX: return "MIPS_HIDDEN_GOTIDX";
1130 case DT_MIPS_PROTECTED_GOTIDX: return "MIPS_PROTECTED_GOTIDX";
1131 case DT_MIPS_OPTIONS: return "MIPS_OPTIONS";
1132 case DT_MIPS_INTERFACE: return "MIPS_INTERFACE";
1133 case DT_MIPS_DYNSTR_ALIGN: return "MIPS_DYNSTR_ALIGN";
1134 case DT_MIPS_INTERFACE_SIZE: return "MIPS_INTERFACE_SIZE";
1135 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
1136 case DT_MIPS_PERF_SUFFIX: return "MIPS_PERF_SUFFIX";
1137 case DT_MIPS_COMPACT_SIZE: return "MIPS_COMPACT_SIZE";
1138 case DT_MIPS_GP_VALUE: return "MIPS_GP_VALUE";
1139 case DT_MIPS_AUX_DYNAMIC: return "MIPS_AUX_DYNAMIC";
1146 get_sparc64_dynamic_type (type)
1151 case DT_SPARC_REGISTER: return "SPARC_REGISTER";
1158 get_parisc_dynamic_type (type)
1163 case DT_HP_LOAD_MAP: return "HP_LOAD_MAP";
1164 case DT_HP_DLD_FLAGS: return "HP_DLD_FLAGS";
1165 case DT_HP_DLD_HOOK: return "HP_DLD_HOOK";
1166 case DT_HP_UX10_INIT: return "HP_UX10_INIT";
1167 case DT_HP_UX10_INITSZ: return "HP_UX10_INITSZ";
1168 case DT_HP_PREINIT: return "HP_PREINIT";
1169 case DT_HP_PREINITSZ: return "HP_PREINITSZ";
1170 case DT_HP_NEEDED: return "HP_NEEDED";
1171 case DT_HP_TIME_STAMP: return "HP_TIME_STAMP";
1172 case DT_HP_CHECKSUM: return "HP_CHECKSUM";
1173 case DT_HP_GST_SIZE: return "HP_GST_SIZE";
1174 case DT_HP_GST_VERSION: return "HP_GST_VERSION";
1175 case DT_HP_GST_HASHVAL: return "HP_GST_HASHVAL";
1182 get_dynamic_type (type)
1185 static char buff [32];
1189 case DT_NULL: return "NULL";
1190 case DT_NEEDED: return "NEEDED";
1191 case DT_PLTRELSZ: return "PLTRELSZ";
1192 case DT_PLTGOT: return "PLTGOT";
1193 case DT_HASH: return "HASH";
1194 case DT_STRTAB: return "STRTAB";
1195 case DT_SYMTAB: return "SYMTAB";
1196 case DT_RELA: return "RELA";
1197 case DT_RELASZ: return "RELASZ";
1198 case DT_RELAENT: return "RELAENT";
1199 case DT_STRSZ: return "STRSZ";
1200 case DT_SYMENT: return "SYMENT";
1201 case DT_INIT: return "INIT";
1202 case DT_FINI: return "FINI";
1203 case DT_SONAME: return "SONAME";
1204 case DT_RPATH: return "RPATH";
1205 case DT_SYMBOLIC: return "SYMBOLIC";
1206 case DT_REL: return "REL";
1207 case DT_RELSZ: return "RELSZ";
1208 case DT_RELENT: return "RELENT";
1209 case DT_PLTREL: return "PLTREL";
1210 case DT_DEBUG: return "DEBUG";
1211 case DT_TEXTREL: return "TEXTREL";
1212 case DT_JMPREL: return "JMPREL";
1213 case DT_BIND_NOW: return "BIND_NOW";
1214 case DT_INIT_ARRAY: return "INIT_ARRAY";
1215 case DT_FINI_ARRAY: return "FINI_ARRAY";
1216 case DT_INIT_ARRAYSZ: return "INIT_ARRAYSZ";
1217 case DT_FINI_ARRAYSZ: return "FINI_ARRAYSZ";
1218 case DT_RUNPATH: return "RUNPATH";
1219 case DT_FLAGS: return "FLAGS";
1221 case DT_PREINIT_ARRAY: return "PREINIT_ARRAY";
1222 case DT_PREINIT_ARRAYSZ: return "PREINIT_ARRAYSZ";
1224 case DT_CHECKSUM: return "CHECKSUM";
1225 case DT_PLTPADSZ: return "PLTPADSZ";
1226 case DT_MOVEENT: return "MOVEENT";
1227 case DT_MOVESZ: return "MOVESZ";
1228 case DT_FEATURE: return "FEATURE";
1229 case DT_POSFLAG_1: return "POSFLAG_1";
1230 case DT_SYMINSZ: return "SYMINSZ";
1231 case DT_SYMINENT: return "SYMINENT"; /* aka VALRNGHI */
1233 case DT_ADDRRNGLO: return "ADDRRNGLO";
1234 case DT_CONFIG: return "CONFIG";
1235 case DT_DEPAUDIT: return "DEPAUDIT";
1236 case DT_AUDIT: return "AUDIT";
1237 case DT_PLTPAD: return "PLTPAD";
1238 case DT_MOVETAB: return "MOVETAB";
1239 case DT_SYMINFO: return "SYMINFO"; /* aka ADDRRNGHI */
1241 case DT_VERSYM: return "VERSYM";
1243 case DT_RELACOUNT: return "RELACOUNT";
1244 case DT_RELCOUNT: return "RELCOUNT";
1245 case DT_FLAGS_1: return "FLAGS_1";
1246 case DT_VERDEF: return "VERDEF";
1247 case DT_VERDEFNUM: return "VERDEFNUM";
1248 case DT_VERNEED: return "VERNEED";
1249 case DT_VERNEEDNUM: return "VERNEEDNUM";
1251 case DT_AUXILIARY: return "AUXILIARY";
1252 case DT_USED: return "USED";
1253 case DT_FILTER: return "FILTER";
1256 if ((type >= DT_LOPROC) && (type <= DT_HIPROC))
1258 const char * result;
1260 switch (elf_header.e_machine)
1263 case EM_MIPS_RS3_LE:
1264 result = get_mips_dynamic_type (type);
1267 result = get_sparc64_dynamic_type (type);
1277 sprintf (buff, _("Processor Specific: %lx"), type);
1279 else if ((type >= DT_LOOS) && (type <= DT_HIOS))
1281 const char * result;
1283 switch (elf_header.e_machine)
1286 result = get_parisc_dynamic_type (type);
1296 sprintf (buff, _("Operating System specific: %lx"), type);
1299 sprintf (buff, _("<unknown>: %lx"), type);
1306 get_file_type (e_type)
1309 static char buff [32];
1313 case ET_NONE: return _("NONE (None)");
1314 case ET_REL: return _("REL (Relocatable file)");
1315 case ET_EXEC: return _("EXEC (Executable file)");
1316 case ET_DYN: return _("DYN (Shared object file)");
1317 case ET_CORE: return _("CORE (Core file)");
1320 if ((e_type >= ET_LOPROC) && (e_type <= ET_HIPROC))
1321 sprintf (buff, _("Processor Specific: (%x)"), e_type);
1322 else if ((e_type >= ET_LOOS) && (e_type <= ET_HIOS))
1323 sprintf (buff, _("OS Specific: (%x)"), e_type);
1325 sprintf (buff, _("<unknown>: %x"), e_type);
1331 get_machine_name (e_machine)
1334 static char buff [64]; /* XXX */
1338 case EM_NONE: return _("None");
1339 case EM_M32: return "WE32100";
1340 case EM_SPARC: return "Sparc";
1341 case EM_386: return "Intel 80386";
1342 case EM_68K: return "MC68000";
1343 case EM_88K: return "MC88000";
1344 case EM_486: return "Intel 80486";
1345 case EM_860: return "Intel 80860";
1346 case EM_MIPS: return "MIPS R3000";
1347 case EM_S370: return "IBM System/370";
1348 case EM_MIPS_RS3_LE: return "MIPS R4000 big-endian";
1349 case EM_OLD_SPARCV9: return "Sparc v9 (old)";
1350 case EM_PARISC: return "HPPA";
1351 case EM_PPC_OLD: return "Power PC (old)";
1352 case EM_SPARC32PLUS: return "Sparc v8+" ;
1353 case EM_960: return "Intel 90860";
1354 case EM_PPC: return "PowerPC";
1355 case EM_V800: return "NEC V800";
1356 case EM_FR20: return "Fujitsu FR20";
1357 case EM_RH32: return "TRW RH32";
1358 case EM_MCORE: return "MCORE";
1359 case EM_ARM: return "ARM";
1360 case EM_OLD_ALPHA: return "Digital Alpha (old)";
1361 case EM_SH: return "Hitachi SH";
1362 case EM_SPARCV9: return "Sparc v9";
1363 case EM_TRICORE: return "Siemens Tricore";
1364 case EM_ARC: return "ARC";
1365 case EM_H8_300: return "Hitachi H8/300";
1366 case EM_H8_300H: return "Hitachi H8/300H";
1367 case EM_H8S: return "Hitachi H8S";
1368 case EM_H8_500: return "Hitachi H8/500";
1369 case EM_IA_64: return "Intel IA-64";
1370 case EM_MIPS_X: return "Stanford MIPS-X";
1371 case EM_COLDFIRE: return "Motorola Coldfire";
1372 case EM_68HC12: return "Motorola M68HC12";
1373 case EM_ALPHA: return "Alpha";
1374 case EM_CYGNUS_D10V:
1375 case EM_D10V: return "d10v";
1376 case EM_CYGNUS_D30V:
1377 case EM_D30V: return "d30v";
1378 case EM_CYGNUS_M32R:
1379 case EM_M32R: return "Mitsubishi M32r";
1380 case EM_CYGNUS_V850:
1381 case EM_V850: return "NEC v850";
1382 case EM_CYGNUS_MN10300:
1383 case EM_MN10300: return "mn10300";
1384 case EM_CYGNUS_MN10200:
1385 case EM_MN10200: return "mn10200";
1386 case EM_CYGNUS_FR30:
1387 case EM_FR30: return "Fujitsu FR30";
1389 case EM_PJ: return "picoJava";
1390 case EM_MMA: return "Fujitsu Multimedia Accelerator";
1391 case EM_PCP: return "Siemens PCP";
1392 case EM_NCPU: return "Sony nCPU embedded RISC processor";
1393 case EM_NDR1: return "Denso NDR1 microprocesspr";
1394 case EM_STARCORE: return "Motorola Star*Core processor";
1395 case EM_ME16: return "Toyota ME16 processor";
1396 case EM_ST100: return "STMicroelectronics ST100 processor";
1397 case EM_TINYJ: return "Advanced Logic Corp. TinyJ embedded processor";
1398 case EM_FX66: return "Siemens FX66 microcontroller";
1399 case EM_ST9PLUS: return "STMicroelectronics ST9+ 8/16 bit microcontroller";
1400 case EM_ST7: return "STMicroelectronics ST7 8-bit microcontroller";
1401 case EM_68HC16: return "Motorola MC68HC16 Microcontroller";
1402 case EM_68HC11: return "Motorola MC68HC11 Microcontroller";
1403 case EM_68HC08: return "Motorola MC68HC08 Microcontroller";
1404 case EM_68HC05: return "Motorola MC68HC05 Microcontroller";
1405 case EM_SVX: return "Silicon Graphics SVx";
1406 case EM_ST19: return "STMicroelectronics ST19 8-bit microcontroller";
1407 case EM_VAX: return "Digital VAX";
1409 case EM_AVR: return "Atmel AVR 8-bit microcontroller";
1410 case EM_CRIS: return "Axis Communications 32-bit embedded processor";
1411 case EM_JAVELIN: return "Infineon Technologies 32-bit embedded cpu";
1412 case EM_FIREPATH: return "Element 14 64-bit DSP processor";
1413 case EM_ZSP: return "LSI Logic's 16-bit DSP processor";
1414 case EM_MMIX: return "Donald Knuth's educational 64-bit processor";
1415 case EM_HUANY: return "Harvard Universitys's machine-independent object format";
1416 case EM_PRISM: return "SiTera Prism";
1417 case EM_X86_64: return "Advanced Micro Devices X86-64";
1419 case EM_S390: return "IBM S/390";
1421 sprintf (buff, _("<unknown>: %x"), e_machine);
1427 decode_ARM_machine_flags (e_flags, buf)
1434 eabi = EF_ARM_EABI_VERSION (e_flags);
1435 e_flags &= ~ EF_ARM_EABIMASK;
1437 /* Handle "generic" ARM flags. */
1438 if (e_flags & EF_ARM_RELEXEC)
1440 strcat (buf, ", relocatable executable");
1441 e_flags &= ~ EF_ARM_RELEXEC;
1444 if (e_flags & EF_ARM_HASENTRY)
1446 strcat (buf, ", has entry point");
1447 e_flags &= ~ EF_ARM_HASENTRY;
1450 /* Now handle EABI specific flags. */
1454 strcat (buf, ", <unrecognised EABI>");
1459 case EF_ARM_EABI_VER1:
1460 strcat (buf, ", Version1 EABI");
1465 /* Process flags one bit at a time. */
1466 flag = e_flags & - e_flags;
1471 case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK. */
1472 strcat (buf, ", sorted symbol tables");
1482 case EF_ARM_EABI_VER2:
1483 strcat (buf, ", Version2 EABI");
1488 /* Process flags one bit at a time. */
1489 flag = e_flags & - e_flags;
1494 case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK. */
1495 strcat (buf, ", sorted symbol tables");
1498 case EF_ARM_DYNSYMSUSESEGIDX:
1499 strcat (buf, ", dynamic symbols use segment index");
1502 case EF_ARM_MAPSYMSFIRST:
1503 strcat (buf, ", mapping symbols precede others");
1513 case EF_ARM_EABI_UNKNOWN:
1514 strcat (buf, ", GNU EABI");
1519 /* Process flags one bit at a time. */
1520 flag = e_flags & - e_flags;
1525 case EF_ARM_INTERWORK:
1526 strcat (buf, ", interworking enabled");
1529 case EF_ARM_APCS_26:
1530 strcat (buf, ", uses APCS/26");
1533 case EF_ARM_APCS_FLOAT:
1534 strcat (buf, ", uses APCS/float");
1538 strcat (buf, ", position independent");
1542 strcat (buf, ", 8 bit structure alignment");
1545 case EF_ARM_NEW_ABI:
1546 strcat (buf, ", uses new ABI");
1549 case EF_ARM_OLD_ABI:
1550 strcat (buf, ", uses old ABI");
1553 case EF_ARM_SOFT_FLOAT:
1554 strcat (buf, ", software FP");
1565 strcat (buf,", <unknown>");
1569 get_machine_flags (e_flags, e_machine)
1573 static char buf [1024];
1585 decode_ARM_machine_flags (e_flags, buf);
1589 if (e_flags & EF_CPU32)
1590 strcat (buf, ", cpu32");
1594 if (e_flags & EF_PPC_EMB)
1595 strcat (buf, ", emb");
1597 if (e_flags & EF_PPC_RELOCATABLE)
1598 strcat (buf, ", relocatable");
1600 if (e_flags & EF_PPC_RELOCATABLE_LIB)
1601 strcat (buf, ", relocatable-lib");
1605 case EM_CYGNUS_V850:
1606 switch (e_flags & EF_V850_ARCH)
1609 strcat (buf, ", v850e");
1612 strcat (buf, ", v850ea");
1615 strcat (buf, ", v850");
1618 strcat (buf, ", unknown v850 architecture variant");
1624 case EM_CYGNUS_M32R:
1625 if ((e_flags & EF_M32R_ARCH) == E_M32R_ARCH)
1626 strcat (buf, ", m32r");
1631 case EM_MIPS_RS3_LE:
1632 if (e_flags & EF_MIPS_NOREORDER)
1633 strcat (buf, ", noreorder");
1635 if (e_flags & EF_MIPS_PIC)
1636 strcat (buf, ", pic");
1638 if (e_flags & EF_MIPS_CPIC)
1639 strcat (buf, ", cpic");
1641 if (e_flags & EF_MIPS_UCODE)
1642 strcat (buf, ", ugen_reserved");
1644 if (e_flags & EF_MIPS_ABI2)
1645 strcat (buf, ", abi2");
1647 if (e_flags & EF_MIPS_32BITMODE)
1648 strcat (buf, ", 32bitmode");
1650 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_1)
1651 strcat (buf, ", mips1");
1653 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_2)
1654 strcat (buf, ", mips2");
1656 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_3)
1657 strcat (buf, ", mips3");
1659 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_4)
1660 strcat (buf, ", mips4");
1662 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_5)
1663 strcat (buf, ", mips5");
1665 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_32)
1666 strcat (buf, ", mips32");
1668 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_64)
1669 strcat (buf, ", mips64");
1671 switch ((e_flags & EF_MIPS_MACH))
1673 case E_MIPS_MACH_3900: strcat (buf, ", 3900"); break;
1674 case E_MIPS_MACH_4010: strcat (buf, ", 4010"); break;
1675 case E_MIPS_MACH_4100: strcat (buf, ", 4100"); break;
1676 case E_MIPS_MACH_4650: strcat (buf, ", 4650"); break;
1677 case E_MIPS_MACH_4111: strcat (buf, ", 4111"); break;
1678 case E_MIPS_MACH_SB1: strcat (buf, ", sb1"); break;
1679 default: strcat (buf, " UNKNOWN"); break;
1684 if (e_flags & EF_SPARC_32PLUS)
1685 strcat (buf, ", v8+");
1687 if (e_flags & EF_SPARC_SUN_US1)
1688 strcat (buf, ", ultrasparcI");
1690 if (e_flags & EF_SPARC_SUN_US3)
1691 strcat (buf, ", ultrasparcIII");
1693 if (e_flags & EF_SPARC_HAL_R1)
1694 strcat (buf, ", halr1");
1696 if (e_flags & EF_SPARC_LEDATA)
1697 strcat (buf, ", ledata");
1699 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_TSO)
1700 strcat (buf, ", tso");
1702 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_PSO)
1703 strcat (buf, ", pso");
1705 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_RMO)
1706 strcat (buf, ", rmo");
1710 switch (e_flags & EF_PARISC_ARCH)
1712 case EFA_PARISC_1_0:
1713 strcpy (buf, ", PA-RISC 1.0");
1715 case EFA_PARISC_1_1:
1716 strcpy (buf, ", PA-RISC 1.1");
1718 case EFA_PARISC_2_0:
1719 strcpy (buf, ", PA-RISC 2.0");
1724 if (e_flags & EF_PARISC_TRAPNIL)
1725 strcat (buf, ", trapnil");
1726 if (e_flags & EF_PARISC_EXT)
1727 strcat (buf, ", ext");
1728 if (e_flags & EF_PARISC_LSB)
1729 strcat (buf, ", lsb");
1730 if (e_flags & EF_PARISC_WIDE)
1731 strcat (buf, ", wide");
1732 if (e_flags & EF_PARISC_NO_KABP)
1733 strcat (buf, ", no kabp");
1734 if (e_flags & EF_PARISC_LAZYSWAP)
1735 strcat (buf, ", lazyswap");
1740 if ((e_flags & EF_PICOJAVA_NEWCALLS) == EF_PICOJAVA_NEWCALLS)
1741 strcat (buf, ", new calling convention");
1743 if ((e_flags & EF_PICOJAVA_GNUCALLS) == EF_PICOJAVA_GNUCALLS)
1744 strcat (buf, ", gnu calling convention");
1748 if ((e_flags & EF_IA_64_ABI64))
1749 strcat (buf, ", 64-bit");
1751 strcat (buf, ", 32-bit");
1752 if ((e_flags & EF_IA_64_REDUCEDFP))
1753 strcat (buf, ", reduced fp model");
1754 if ((e_flags & EF_IA_64_NOFUNCDESC_CONS_GP))
1755 strcat (buf, ", no function descriptors, constant gp");
1756 else if ((e_flags & EF_IA_64_CONS_GP))
1757 strcat (buf, ", constant gp");
1758 if ((e_flags & EF_IA_64_ABSOLUTE))
1759 strcat (buf, ", absolute");
1768 get_mips_segment_type (type)
1773 case PT_MIPS_REGINFO:
1775 case PT_MIPS_RTPROC:
1777 case PT_MIPS_OPTIONS:
1787 get_parisc_segment_type (type)
1792 case PT_HP_TLS: return "HP_TLS";
1793 case PT_HP_CORE_NONE: return "HP_CORE_NONE";
1794 case PT_HP_CORE_VERSION: return "HP_CORE_VERSION";
1795 case PT_HP_CORE_KERNEL: return "HP_CORE_KERNEL";
1796 case PT_HP_CORE_COMM: return "HP_CORE_COMM";
1797 case PT_HP_CORE_PROC: return "HP_CORE_PROC";
1798 case PT_HP_CORE_LOADABLE: return "HP_CORE_LOADABLE";
1799 case PT_HP_CORE_STACK: return "HP_CORE_STACK";
1800 case PT_HP_CORE_SHM: return "HP_CORE_SHM";
1801 case PT_HP_CORE_MMF: return "HP_CORE_MMF";
1802 case PT_HP_PARALLEL: return "HP_PARALLEL";
1803 case PT_HP_FASTBIND: return "HP_FASTBIND";
1804 case PT_PARISC_ARCHEXT: return "PARISC_ARCHEXT";
1805 case PT_PARISC_UNWIND: return "PARISC_UNWIND";
1814 get_ia64_segment_type (type)
1819 case PT_IA_64_ARCHEXT: return "IA_64_ARCHEXT";
1820 case PT_IA_64_UNWIND: return "IA_64_UNWIND";
1829 get_segment_type (p_type)
1830 unsigned long p_type;
1832 static char buff [32];
1836 case PT_NULL: return "NULL";
1837 case PT_LOAD: return "LOAD";
1838 case PT_DYNAMIC: return "DYNAMIC";
1839 case PT_INTERP: return "INTERP";
1840 case PT_NOTE: return "NOTE";
1841 case PT_SHLIB: return "SHLIB";
1842 case PT_PHDR: return "PHDR";
1845 if ((p_type >= PT_LOPROC) && (p_type <= PT_HIPROC))
1847 const char * result;
1849 switch (elf_header.e_machine)
1852 case EM_MIPS_RS3_LE:
1853 result = get_mips_segment_type (p_type);
1856 result = get_parisc_segment_type (p_type);
1859 result = get_ia64_segment_type (p_type);
1869 sprintf (buff, "LOPROC+%lx", p_type - PT_LOPROC);
1871 else if ((p_type >= PT_LOOS) && (p_type <= PT_HIOS))
1873 const char * result;
1875 switch (elf_header.e_machine)
1878 result = get_parisc_segment_type (p_type);
1888 sprintf (buff, "LOOS+%lx", p_type - PT_LOOS);
1891 sprintf (buff, _("<unknown>: %lx"), p_type);
1898 get_mips_section_type_name (sh_type)
1899 unsigned int sh_type;
1903 case SHT_MIPS_LIBLIST: return "MIPS_LIBLIST";
1904 case SHT_MIPS_MSYM: return "MIPS_MSYM";
1905 case SHT_MIPS_CONFLICT: return "MIPS_CONFLICT";
1906 case SHT_MIPS_GPTAB: return "MIPS_GPTAB";
1907 case SHT_MIPS_UCODE: return "MIPS_UCODE";
1908 case SHT_MIPS_DEBUG: return "MIPS_DEBUG";
1909 case SHT_MIPS_REGINFO: return "MIPS_REGINFO";
1910 case SHT_MIPS_PACKAGE: return "MIPS_PACKAGE";
1911 case SHT_MIPS_PACKSYM: return "MIPS_PACKSYM";
1912 case SHT_MIPS_RELD: return "MIPS_RELD";
1913 case SHT_MIPS_IFACE: return "MIPS_IFACE";
1914 case SHT_MIPS_CONTENT: return "MIPS_CONTENT";
1915 case SHT_MIPS_OPTIONS: return "MIPS_OPTIONS";
1916 case SHT_MIPS_SHDR: return "MIPS_SHDR";
1917 case SHT_MIPS_FDESC: return "MIPS_FDESC";
1918 case SHT_MIPS_EXTSYM: return "MIPS_EXTSYM";
1919 case SHT_MIPS_DENSE: return "MIPS_DENSE";
1920 case SHT_MIPS_PDESC: return "MIPS_PDESC";
1921 case SHT_MIPS_LOCSYM: return "MIPS_LOCSYM";
1922 case SHT_MIPS_AUXSYM: return "MIPS_AUXSYM";
1923 case SHT_MIPS_OPTSYM: return "MIPS_OPTSYM";
1924 case SHT_MIPS_LOCSTR: return "MIPS_LOCSTR";
1925 case SHT_MIPS_LINE: return "MIPS_LINE";
1926 case SHT_MIPS_RFDESC: return "MIPS_RFDESC";
1927 case SHT_MIPS_DELTASYM: return "MIPS_DELTASYM";
1928 case SHT_MIPS_DELTAINST: return "MIPS_DELTAINST";
1929 case SHT_MIPS_DELTACLASS: return "MIPS_DELTACLASS";
1930 case SHT_MIPS_DWARF: return "MIPS_DWARF";
1931 case SHT_MIPS_DELTADECL: return "MIPS_DELTADECL";
1932 case SHT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB";
1933 case SHT_MIPS_EVENTS: return "MIPS_EVENTS";
1934 case SHT_MIPS_TRANSLATE: return "MIPS_TRANSLATE";
1935 case SHT_MIPS_PIXIE: return "MIPS_PIXIE";
1936 case SHT_MIPS_XLATE: return "MIPS_XLATE";
1937 case SHT_MIPS_XLATE_DEBUG: return "MIPS_XLATE_DEBUG";
1938 case SHT_MIPS_WHIRL: return "MIPS_WHIRL";
1939 case SHT_MIPS_EH_REGION: return "MIPS_EH_REGION";
1940 case SHT_MIPS_XLATE_OLD: return "MIPS_XLATE_OLD";
1941 case SHT_MIPS_PDR_EXCEPTION: return "MIPS_PDR_EXCEPTION";
1949 get_parisc_section_type_name (sh_type)
1950 unsigned int sh_type;
1954 case SHT_PARISC_EXT: return "PARISC_EXT";
1955 case SHT_PARISC_UNWIND: return "PARISC_UNWIND";
1956 case SHT_PARISC_DOC: return "PARISC_DOC";
1964 get_ia64_section_type_name (sh_type)
1965 unsigned int sh_type;
1969 case SHT_IA_64_EXT: return "IA_64_EXT";
1970 case SHT_IA_64_UNWIND: return "IA_64_UNWIND";
1978 get_section_type_name (sh_type)
1979 unsigned int sh_type;
1981 static char buff [32];
1985 case SHT_NULL: return "NULL";
1986 case SHT_PROGBITS: return "PROGBITS";
1987 case SHT_SYMTAB: return "SYMTAB";
1988 case SHT_STRTAB: return "STRTAB";
1989 case SHT_RELA: return "RELA";
1990 case SHT_HASH: return "HASH";
1991 case SHT_DYNAMIC: return "DYNAMIC";
1992 case SHT_NOTE: return "NOTE";
1993 case SHT_NOBITS: return "NOBITS";
1994 case SHT_REL: return "REL";
1995 case SHT_SHLIB: return "SHLIB";
1996 case SHT_DYNSYM: return "DYNSYM";
1997 case SHT_INIT_ARRAY: return "INIT_ARRAY";
1998 case SHT_FINI_ARRAY: return "FINI_ARRAY";
1999 case SHT_PREINIT_ARRAY: return "PREINIT_ARRAY";
2000 case SHT_GROUP: return "GROUP";
2001 case SHT_SYMTAB_SHNDX: return "SYMTAB SECTION INDICIES";
2002 case SHT_GNU_verdef: return "VERDEF";
2003 case SHT_GNU_verneed: return "VERNEED";
2004 case SHT_GNU_versym: return "VERSYM";
2005 case 0x6ffffff0: return "VERSYM";
2006 case 0x6ffffffc: return "VERDEF";
2007 case 0x7ffffffd: return "AUXILIARY";
2008 case 0x7fffffff: return "FILTER";
2011 if ((sh_type >= SHT_LOPROC) && (sh_type <= SHT_HIPROC))
2013 const char * result;
2015 switch (elf_header.e_machine)
2018 case EM_MIPS_RS3_LE:
2019 result = get_mips_section_type_name (sh_type);
2022 result = get_parisc_section_type_name (sh_type);
2025 result = get_ia64_section_type_name (sh_type);
2035 sprintf (buff, "SHT_LOPROC+%x", sh_type - SHT_LOPROC);
2037 else if ((sh_type >= SHT_LOOS) && (sh_type <= SHT_HIOS))
2038 sprintf (buff, "SHT_LOOS+%x", sh_type - SHT_LOOS);
2039 else if ((sh_type >= SHT_LOUSER) && (sh_type <= SHT_HIUSER))
2040 sprintf (buff, "SHT_LOUSER+%x", sh_type - SHT_LOUSER);
2042 sprintf (buff, _("<unknown>: %x"), sh_type);
2048 struct option options [] =
2050 {"all", no_argument, 0, 'a'},
2051 {"file-header", no_argument, 0, 'h'},
2052 {"program-headers", no_argument, 0, 'l'},
2053 {"headers", no_argument, 0, 'e'},
2054 {"histogram", no_argument, 0, 'I'},
2055 {"segments", no_argument, 0, 'l'},
2056 {"sections", no_argument, 0, 'S'},
2057 {"section-headers", no_argument, 0, 'S'},
2058 {"symbols", no_argument, 0, 's'},
2059 {"syms", no_argument, 0, 's'},
2060 {"relocs", no_argument, 0, 'r'},
2061 {"notes", no_argument, 0, 'n'},
2062 {"dynamic", no_argument, 0, 'd'},
2063 {"arch-specific", no_argument, 0, 'A'},
2064 {"version-info", no_argument, 0, 'V'},
2065 {"use-dynamic", no_argument, 0, 'D'},
2066 {"hex-dump", required_argument, 0, 'x'},
2067 {"debug-dump", optional_argument, 0, 'w'},
2068 {"unwind", no_argument, 0, 'u'},
2069 #ifdef SUPPORT_DISASSEMBLY
2070 {"instruction-dump", required_argument, 0, 'i'},
2073 {"version", no_argument, 0, 'v'},
2074 {"help", no_argument, 0, 'H'},
2075 {0, no_argument, 0, 0}
2081 fprintf (stdout, _("Usage: readelf {options} elf-file(s)\n"));
2082 fprintf (stdout, _(" Options are:\n"));
2083 fprintf (stdout, _(" -a or --all Equivalent to: -h -l -S -s -r -d -V -A -I\n"));
2084 fprintf (stdout, _(" -h or --file-header Display the ELF file header\n"));
2085 fprintf (stdout, _(" -l or --program-headers or --segments\n"));
2086 fprintf (stdout, _(" Display the program headers\n"));
2087 fprintf (stdout, _(" -S or --section-headers or --sections\n"));
2088 fprintf (stdout, _(" Display the sections' header\n"));
2089 fprintf (stdout, _(" -e or --headers Equivalent to: -h -l -S\n"));
2090 fprintf (stdout, _(" -s or --syms or --symbols Display the symbol table\n"));
2091 fprintf (stdout, _(" -n or --notes Display the core notes (if present)\n"));
2092 fprintf (stdout, _(" -r or --relocs Display the relocations (if present)\n"));
2093 fprintf (stdout, _(" -u or --unwind Display the unwind info (if present)\n"));
2094 fprintf (stdout, _(" -d or --dynamic Display the dynamic segment (if present)\n"));
2095 fprintf (stdout, _(" -V or --version-info Display the version sections (if present)\n"));
2096 fprintf (stdout, _(" -A or --arch-specific Display architecture specific information (if any).\n"));
2097 fprintf (stdout, _(" -D or --use-dynamic Use the dynamic section info when displaying symbols\n"));
2098 fprintf (stdout, _(" -x <number> or --hex-dump=<number>\n"));
2099 fprintf (stdout, _(" Dump the contents of section <number>\n"));
2100 fprintf (stdout, _(" -w[liaprmf] or --debug-dump[=line,=info,=abbrev,=pubnames,=ranges,=macro,=frames]\n"));
2101 fprintf (stdout, _(" Display the contents of DWARF2 debug sections\n"));
2102 #ifdef SUPPORT_DISASSEMBLY
2103 fprintf (stdout, _(" -i <number> or --instruction-dump=<number>\n"));
2104 fprintf (stdout, _(" Disassemble the contents of section <number>\n"));
2106 fprintf (stdout, _(" -I or --histogram Display histogram of bucket list lengths\n"));
2107 fprintf (stdout, _(" -v or --version Display the version number of readelf\n"));
2108 fprintf (stdout, _(" -H or --help Display this information\n"));
2109 fprintf (stdout, _("Report bugs to %s\n"), REPORT_BUGS_TO);
2115 request_dump (section, type)
2116 unsigned int section;
2119 if (section >= num_dump_sects)
2121 char * new_dump_sects;
2123 new_dump_sects = (char *) calloc (section + 1, 1);
2125 if (new_dump_sects == NULL)
2126 error (_("Out of memory allocating dump request table."));
2129 /* Copy current flag settings. */
2130 memcpy (new_dump_sects, dump_sects, num_dump_sects);
2134 dump_sects = new_dump_sects;
2135 num_dump_sects = section + 1;
2140 dump_sects [section] |= type;
2146 parse_args (argc, argv)
2155 while ((c = getopt_long
2156 (argc, argv, "ersuahnldSDAIw::x:i:vV", options, NULL)) != EOF)
2192 do_using_dynamic ++;
2223 section = strtoul (optarg, & cp, 0);
2224 if (! * cp && section >= 0)
2226 request_dump (section, HEX_DUMP);
2246 do_debug_abbrevs = 1;
2256 do_debug_pubnames = 1;
2261 do_debug_aranges = 1;
2265 do_debug_frames_interp = 1;
2267 do_debug_frames = 1;
2272 do_debug_macinfo = 1;
2276 warn (_("Unrecognised debug option '%s'\n"), optarg);
2281 #ifdef SUPPORT_DISASSEMBLY
2284 section = strtoul (optarg, & cp, 0);
2285 if (! * cp && section >= 0)
2287 request_dump (section, DISASS_DUMP);
2293 print_version (program_name);
2300 /* xgettext:c-format */
2301 error (_("Invalid option '-%c'\n"), c);
2308 if (!do_dynamic && !do_syms && !do_reloc && !do_unwind && !do_sections
2309 && !do_segments && !do_header && !do_dump && !do_version
2310 && !do_histogram && !do_debugging && !do_arch && !do_notes)
2314 warn (_("Nothing to do.\n"));
2320 get_elf_class (elf_class)
2321 unsigned char elf_class;
2323 static char buff [32];
2327 case ELFCLASSNONE: return _("none");
2328 case ELFCLASS32: return _("ELF32");
2329 case ELFCLASS64: return _("ELF64");
2331 sprintf (buff, _("<unknown: %x>"), elf_class);
2337 get_data_encoding (encoding)
2338 unsigned char encoding;
2340 static char buff [32];
2344 case ELFDATANONE: return _("none");
2345 case ELFDATA2LSB: return _("2's complement, little endian");
2346 case ELFDATA2MSB: return _("2's complement, big endian");
2348 sprintf (buff, _("<unknown: %x>"), encoding);
2354 get_osabi_name (osabi)
2355 unsigned char osabi;
2357 static char buff [32];
2361 case ELFOSABI_NONE: return _("UNIX - System V");
2362 case ELFOSABI_HPUX: return _("UNIX - HP-UX");
2363 case ELFOSABI_NETBSD: return _("UNIX - NetBSD");
2364 case ELFOSABI_LINUX: return _("UNIX - Linux");
2365 case ELFOSABI_HURD: return _("GNU/Hurd");
2366 case ELFOSABI_SOLARIS: return _("UNIX - Solaris");
2367 case ELFOSABI_AIX: return _("UNIX - AIX");
2368 case ELFOSABI_IRIX: return _("UNIX - IRIX");
2369 case ELFOSABI_FREEBSD: return _("UNIX - FreeBSD");
2370 case ELFOSABI_TRU64: return _("UNIX - TRU64");
2371 case ELFOSABI_MODESTO: return _("Novell - Modesto");
2372 case ELFOSABI_OPENBSD: return _("UNIX - OpenBSD");
2373 case ELFOSABI_STANDALONE: return _("Standalone App");
2374 case ELFOSABI_ARM: return _("ARM");
2376 sprintf (buff, _("<unknown: %x>"), osabi);
2381 /* Decode the data held in 'elf_header'. */
2383 process_file_header ()
2385 if ( elf_header.e_ident [EI_MAG0] != ELFMAG0
2386 || elf_header.e_ident [EI_MAG1] != ELFMAG1
2387 || elf_header.e_ident [EI_MAG2] != ELFMAG2
2388 || elf_header.e_ident [EI_MAG3] != ELFMAG3)
2391 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
2399 printf (_("ELF Header:\n"));
2400 printf (_(" Magic: "));
2401 for (i = 0; i < EI_NIDENT; i ++)
2402 printf ("%2.2x ", elf_header.e_ident [i]);
2404 printf (_(" Class: %s\n"),
2405 get_elf_class (elf_header.e_ident [EI_CLASS]));
2406 printf (_(" Data: %s\n"),
2407 get_data_encoding (elf_header.e_ident [EI_DATA]));
2408 printf (_(" Version: %d %s\n"),
2409 elf_header.e_ident [EI_VERSION],
2410 (elf_header.e_ident [EI_VERSION] == EV_CURRENT
2412 : (elf_header.e_ident [EI_VERSION] != EV_NONE
2415 printf (_(" OS/ABI: %s\n"),
2416 get_osabi_name (elf_header.e_ident [EI_OSABI]));
2417 printf (_(" ABI Version: %d\n"),
2418 elf_header.e_ident [EI_ABIVERSION]);
2419 printf (_(" Type: %s\n"),
2420 get_file_type (elf_header.e_type));
2421 printf (_(" Machine: %s\n"),
2422 get_machine_name (elf_header.e_machine));
2423 printf (_(" Version: 0x%lx\n"),
2424 (unsigned long) elf_header.e_version);
2426 printf (_(" Entry point address: "));
2427 print_vma ((bfd_vma) elf_header.e_entry, PREFIX_HEX);
2428 printf (_("\n Start of program headers: "));
2429 print_vma ((bfd_vma) elf_header.e_phoff, DEC);
2430 printf (_(" (bytes into file)\n Start of section headers: "));
2431 print_vma ((bfd_vma) elf_header.e_shoff, DEC);
2432 printf (_(" (bytes into file)\n"));
2434 printf (_(" Flags: 0x%lx%s\n"),
2435 (unsigned long) elf_header.e_flags,
2436 get_machine_flags (elf_header.e_flags, elf_header.e_machine));
2437 printf (_(" Size of this header: %ld (bytes)\n"),
2438 (long) elf_header.e_ehsize);
2439 printf (_(" Size of program headers: %ld (bytes)\n"),
2440 (long) elf_header.e_phentsize);
2441 printf (_(" Number of program headers: %ld\n"),
2442 (long) elf_header.e_phnum);
2443 printf (_(" Size of section headers: %ld (bytes)\n"),
2444 (long) elf_header.e_shentsize);
2445 printf (_(" Number of section headers: %ld\n"),
2446 (long) elf_header.e_shnum);
2447 printf (_(" Section header string table index: %ld\n"),
2448 (long) elf_header.e_shstrndx);
2456 get_32bit_program_headers (file, program_headers)
2458 Elf_Internal_Phdr * program_headers;
2460 Elf32_External_Phdr * phdrs;
2461 Elf32_External_Phdr * external;
2462 Elf32_Internal_Phdr * internal;
2465 phdrs = ((Elf32_External_Phdr *)
2466 get_data (NULL, file, elf_header.e_phoff,
2467 elf_header.e_phentsize * elf_header.e_phnum,
2468 _("program headers")));
2472 for (i = 0, internal = program_headers, external = phdrs;
2473 i < elf_header.e_phnum;
2474 i ++, internal ++, external ++)
2476 internal->p_type = BYTE_GET (external->p_type);
2477 internal->p_offset = BYTE_GET (external->p_offset);
2478 internal->p_vaddr = BYTE_GET (external->p_vaddr);
2479 internal->p_paddr = BYTE_GET (external->p_paddr);
2480 internal->p_filesz = BYTE_GET (external->p_filesz);
2481 internal->p_memsz = BYTE_GET (external->p_memsz);
2482 internal->p_flags = BYTE_GET (external->p_flags);
2483 internal->p_align = BYTE_GET (external->p_align);
2492 get_64bit_program_headers (file, program_headers)
2494 Elf_Internal_Phdr * program_headers;
2496 Elf64_External_Phdr * phdrs;
2497 Elf64_External_Phdr * external;
2498 Elf64_Internal_Phdr * internal;
2501 phdrs = ((Elf64_External_Phdr *)
2502 get_data (NULL, file, elf_header.e_phoff,
2503 elf_header.e_phentsize * elf_header.e_phnum,
2504 _("program headers")));
2508 for (i = 0, internal = program_headers, external = phdrs;
2509 i < elf_header.e_phnum;
2510 i ++, internal ++, external ++)
2512 internal->p_type = BYTE_GET (external->p_type);
2513 internal->p_flags = BYTE_GET (external->p_flags);
2514 internal->p_offset = BYTE_GET8 (external->p_offset);
2515 internal->p_vaddr = BYTE_GET8 (external->p_vaddr);
2516 internal->p_paddr = BYTE_GET8 (external->p_paddr);
2517 internal->p_filesz = BYTE_GET8 (external->p_filesz);
2518 internal->p_memsz = BYTE_GET8 (external->p_memsz);
2519 internal->p_align = BYTE_GET8 (external->p_align);
2528 process_program_headers (file)
2531 Elf_Internal_Phdr * program_headers;
2532 Elf_Internal_Phdr * segment;
2535 if (elf_header.e_phnum == 0)
2538 printf (_("\nThere are no program headers in this file.\n"));
2542 if (do_segments && !do_header)
2544 printf (_("\nElf file type is %s\n"), get_file_type (elf_header.e_type));
2545 printf (_("Entry point "));
2546 print_vma ((bfd_vma) elf_header.e_entry, PREFIX_HEX);
2547 printf (_("\nThere are %d program headers, starting at offset "),
2548 elf_header.e_phnum);
2549 print_vma ((bfd_vma) elf_header.e_phoff, DEC);
2553 program_headers = (Elf_Internal_Phdr *) malloc
2554 (elf_header.e_phnum * sizeof (Elf_Internal_Phdr));
2556 if (program_headers == NULL)
2558 error (_("Out of memory\n"));
2563 i = get_32bit_program_headers (file, program_headers);
2565 i = get_64bit_program_headers (file, program_headers);
2569 free (program_headers);
2576 (_("\nProgram Header%s:\n"), elf_header.e_phnum > 1 ? "s" : "");
2580 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
2584 (_(" Type Offset VirtAddr PhysAddr\n"));
2586 (_(" FileSiz MemSiz Flags Align\n"));
2594 for (i = 0, segment = program_headers;
2595 i < elf_header.e_phnum;
2600 printf (" %-14.14s ", get_segment_type (segment->p_type));
2604 printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
2605 printf ("0x%8.8lx ", (unsigned long) segment->p_vaddr);
2606 printf ("0x%8.8lx ", (unsigned long) segment->p_paddr);
2607 printf ("0x%5.5lx ", (unsigned long) segment->p_filesz);
2608 printf ("0x%5.5lx ", (unsigned long) segment->p_memsz);
2610 (segment->p_flags & PF_R ? 'R' : ' '),
2611 (segment->p_flags & PF_W ? 'W' : ' '),
2612 (segment->p_flags & PF_X ? 'E' : ' '));
2613 printf ("%#lx", (unsigned long) segment->p_align);
2617 print_vma (segment->p_offset, FULL_HEX);
2619 print_vma (segment->p_vaddr, FULL_HEX);
2621 print_vma (segment->p_paddr, FULL_HEX);
2623 print_vma (segment->p_filesz, FULL_HEX);
2625 print_vma (segment->p_memsz, FULL_HEX);
2627 (segment->p_flags & PF_R ? 'R' : ' '),
2628 (segment->p_flags & PF_W ? 'W' : ' '),
2629 (segment->p_flags & PF_X ? 'E' : ' '));
2630 print_vma (segment->p_align, HEX);
2634 switch (segment->p_type)
2638 loadaddr = (segment->p_vaddr & 0xfffff000)
2639 - (segment->p_offset & 0xfffff000);
2644 error (_("more than one dynamic segment\n"));
2646 dynamic_addr = segment->p_offset;
2647 dynamic_size = segment->p_filesz;
2651 if (fseek (file, (long) segment->p_offset, SEEK_SET))
2652 error (_("Unable to find program interpreter name\n"));
2655 program_interpreter[0] = 0;
2656 fscanf (file, "%63s", program_interpreter);
2659 printf (_("\n [Requesting program interpreter: %s]"),
2660 program_interpreter);
2666 putc ('\n', stdout);
2675 if (do_segments && section_headers != NULL)
2677 printf (_("\n Section to Segment mapping:\n"));
2678 printf (_(" Segment Sections...\n"));
2680 assert (string_table != NULL);
2682 for (i = 0; i < elf_header.e_phnum; i++)
2685 Elf_Internal_Shdr * section;
2687 segment = program_headers + i;
2688 section = section_headers;
2690 printf (" %2.2d ", i);
2692 for (j = 0; j < elf_header.e_shnum; j++, section ++)
2694 if (section->sh_size > 0
2695 /* Compare allocated sections by VMA, unallocated
2696 sections by file offset. */
2697 && (section->sh_flags & SHF_ALLOC
2698 ? (section->sh_addr >= segment->p_vaddr
2699 && section->sh_addr + section->sh_size
2700 <= segment->p_vaddr + segment->p_memsz)
2701 : ((bfd_vma) section->sh_offset >= segment->p_offset
2702 && (section->sh_offset + section->sh_size
2703 <= segment->p_offset + segment->p_filesz))))
2704 printf ("%s ", SECTION_NAME (section));
2711 free (program_headers);
2718 get_32bit_section_headers (file)
2721 Elf32_External_Shdr * shdrs;
2722 Elf32_Internal_Shdr * internal;
2725 shdrs = ((Elf32_External_Shdr *)
2726 get_data (NULL, file, elf_header.e_shoff,
2727 elf_header.e_shentsize * elf_header.e_shnum,
2728 _("section headers")));
2732 section_headers = (Elf_Internal_Shdr *) malloc
2733 (elf_header.e_shnum * sizeof (Elf_Internal_Shdr));
2735 if (section_headers == NULL)
2737 error (_("Out of memory\n"));
2741 for (i = 0, internal = section_headers;
2742 i < elf_header.e_shnum;
2745 internal->sh_name = BYTE_GET (shdrs[i].sh_name);
2746 internal->sh_type = BYTE_GET (shdrs[i].sh_type);
2747 internal->sh_flags = BYTE_GET (shdrs[i].sh_flags);
2748 internal->sh_addr = BYTE_GET (shdrs[i].sh_addr);
2749 internal->sh_offset = BYTE_GET (shdrs[i].sh_offset);
2750 internal->sh_size = BYTE_GET (shdrs[i].sh_size);
2751 internal->sh_link = BYTE_GET (shdrs[i].sh_link);
2752 internal->sh_info = BYTE_GET (shdrs[i].sh_info);
2753 internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
2754 internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize);
2763 get_64bit_section_headers (file)
2766 Elf64_External_Shdr * shdrs;
2767 Elf64_Internal_Shdr * internal;
2770 shdrs = ((Elf64_External_Shdr *)
2771 get_data (NULL, file, elf_header.e_shoff,
2772 elf_header.e_shentsize * elf_header.e_shnum,
2773 _("section headers")));
2777 section_headers = (Elf_Internal_Shdr *) malloc
2778 (elf_header.e_shnum * sizeof (Elf_Internal_Shdr));
2780 if (section_headers == NULL)
2782 error (_("Out of memory\n"));
2786 for (i = 0, internal = section_headers;
2787 i < elf_header.e_shnum;
2790 internal->sh_name = BYTE_GET (shdrs[i].sh_name);
2791 internal->sh_type = BYTE_GET (shdrs[i].sh_type);
2792 internal->sh_flags = BYTE_GET8 (shdrs[i].sh_flags);
2793 internal->sh_addr = BYTE_GET8 (shdrs[i].sh_addr);
2794 internal->sh_size = BYTE_GET8 (shdrs[i].sh_size);
2795 internal->sh_entsize = BYTE_GET8 (shdrs[i].sh_entsize);
2796 internal->sh_link = BYTE_GET (shdrs[i].sh_link);
2797 internal->sh_info = BYTE_GET (shdrs[i].sh_info);
2798 internal->sh_offset = BYTE_GET (shdrs[i].sh_offset);
2799 internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
2807 static Elf_Internal_Sym *
2808 get_32bit_elf_symbols (file, offset, number)
2810 unsigned long offset;
2811 unsigned long number;
2813 Elf32_External_Sym * esyms;
2814 Elf_Internal_Sym * isyms;
2815 Elf_Internal_Sym * psym;
2818 esyms = ((Elf32_External_Sym *)
2819 get_data (NULL, file, offset,
2820 number * sizeof (Elf32_External_Sym), _("symbols")));
2824 isyms = (Elf_Internal_Sym *) malloc (number * sizeof (Elf_Internal_Sym));
2828 error (_("Out of memory\n"));
2834 for (j = 0, psym = isyms;
2838 psym->st_name = BYTE_GET (esyms[j].st_name);
2839 psym->st_value = BYTE_GET (esyms[j].st_value);
2840 psym->st_size = BYTE_GET (esyms[j].st_size);
2841 psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
2842 psym->st_info = BYTE_GET (esyms[j].st_info);
2843 psym->st_other = BYTE_GET (esyms[j].st_other);
2851 static Elf_Internal_Sym *
2852 get_64bit_elf_symbols (file, offset, number)
2854 unsigned long offset;
2855 unsigned long number;
2857 Elf64_External_Sym * esyms;
2858 Elf_Internal_Sym * isyms;
2859 Elf_Internal_Sym * psym;
2862 esyms = ((Elf64_External_Sym *)
2863 get_data (NULL, file, offset,
2864 number * sizeof (Elf64_External_Sym), _("symbols")));
2868 isyms = (Elf_Internal_Sym *) malloc (number * sizeof (Elf_Internal_Sym));
2872 error (_("Out of memory\n"));
2878 for (j = 0, psym = isyms;
2882 psym->st_name = BYTE_GET (esyms[j].st_name);
2883 psym->st_info = BYTE_GET (esyms[j].st_info);
2884 psym->st_other = BYTE_GET (esyms[j].st_other);
2885 psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
2886 psym->st_value = BYTE_GET8 (esyms[j].st_value);
2887 psym->st_size = BYTE_GET8 (esyms[j].st_size);
2896 get_elf_section_flags (sh_flags)
2899 static char buff [32];
2907 flag = sh_flags & - sh_flags;
2912 case SHF_WRITE: strcat (buff, "W"); break;
2913 case SHF_ALLOC: strcat (buff, "A"); break;
2914 case SHF_EXECINSTR: strcat (buff, "X"); break;
2915 case SHF_MERGE: strcat (buff, "M"); break;
2916 case SHF_STRINGS: strcat (buff, "S"); break;
2917 case SHF_INFO_LINK: strcat (buff, "I"); break;
2918 case SHF_LINK_ORDER: strcat (buff, "L"); break;
2919 case SHF_OS_NONCONFORMING: strcat (buff, "O"); break;
2920 case SHF_GROUP: strcat (buff, "G"); break;
2923 if (flag & SHF_MASKOS)
2926 sh_flags &= ~ SHF_MASKOS;
2928 else if (flag & SHF_MASKPROC)
2931 sh_flags &= ~ SHF_MASKPROC;
2943 process_section_headers (file)
2946 Elf_Internal_Shdr * section;
2949 section_headers = NULL;
2951 if (elf_header.e_shnum == 0)
2954 printf (_("\nThere are no sections in this file.\n"));
2959 if (do_sections && !do_header)
2960 printf (_("There are %d section headers, starting at offset 0x%lx:\n"),
2961 elf_header.e_shnum, (unsigned long) elf_header.e_shoff);
2965 if (! get_32bit_section_headers (file))
2968 else if (! get_64bit_section_headers (file))
2971 /* Read in the string table, so that we have names to display. */
2972 section = section_headers + elf_header.e_shstrndx;
2974 if (section->sh_size != 0)
2976 string_table = (char *) get_data (NULL, file, section->sh_offset,
2977 section->sh_size, _("string table"));
2979 string_table_length = section->sh_size;
2982 /* Scan the sections for the dynamic symbol table
2983 and dynamic string table and debug sections. */
2984 dynamic_symbols = NULL;
2985 dynamic_strings = NULL;
2986 dynamic_syminfo = NULL;
2988 for (i = 0, section = section_headers;
2989 i < elf_header.e_shnum;
2992 char * name = SECTION_NAME (section);
2994 if (section->sh_type == SHT_DYNSYM)
2996 if (dynamic_symbols != NULL)
2998 error (_("File contains multiple dynamic symbol tables\n"));
3002 num_dynamic_syms = section->sh_size / section->sh_entsize;
3004 GET_ELF_SYMBOLS (file, section->sh_offset, num_dynamic_syms);
3006 else if (section->sh_type == SHT_STRTAB
3007 && strcmp (name, ".dynstr") == 0)
3009 if (dynamic_strings != NULL)
3011 error (_("File contains multiple dynamic string tables\n"));
3015 dynamic_strings = (char *) get_data (NULL, file, section->sh_offset,
3017 _("dynamic strings"));
3019 else if ((do_debugging || do_debug_info || do_debug_abbrevs
3020 || do_debug_lines || do_debug_pubnames || do_debug_aranges
3021 || do_debug_frames || do_debug_macinfo)
3022 && strncmp (name, ".debug_", 7) == 0)
3027 || (do_debug_info && (strcmp (name, "info") == 0))
3028 || (do_debug_abbrevs && (strcmp (name, "abbrev") == 0))
3029 || (do_debug_lines && (strcmp (name, "line") == 0))
3030 || (do_debug_pubnames && (strcmp (name, "pubnames") == 0))
3031 || (do_debug_aranges && (strcmp (name, "aranges") == 0))
3032 || (do_debug_frames && (strcmp (name, "frame") == 0))
3033 || (do_debug_macinfo && (strcmp (name, "macinfo") == 0))
3035 request_dump (i, DEBUG_DUMP);
3037 /* linkonce section to be combined with .debug_info at link time. */
3038 else if ((do_debugging || do_debug_info)
3039 && strncmp (name, ".gnu.linkonce.wi.", 17) == 0)
3040 request_dump (i, DEBUG_DUMP);
3041 else if (do_debug_frames && strcmp (name, ".eh_frame") == 0)
3042 request_dump (i, DEBUG_DUMP);
3048 printf (_("\nSection Header%s:\n"), elf_header.e_shnum > 1 ? "s" : "");
3052 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
3055 printf (_(" [Nr] Name Type Address Offset\n"));
3056 printf (_(" Size EntSize Flags Link Info Align\n"));
3059 for (i = 0, section = section_headers;
3060 i < elf_header.e_shnum;
3063 printf (" [%2d] %-17.17s %-15.15s ",
3065 SECTION_NAME (section),
3066 get_section_type_name (section->sh_type));
3070 print_vma (section->sh_addr, LONG_HEX);
3072 printf ( " %6.6lx %6.6lx %2.2lx",
3073 (unsigned long) section->sh_offset,
3074 (unsigned long) section->sh_size,
3075 (unsigned long) section->sh_entsize);
3077 printf (" %3s ", get_elf_section_flags (section->sh_flags));
3079 printf ("%2ld %3lx %2ld\n",
3080 (unsigned long) section->sh_link,
3081 (unsigned long) section->sh_info,
3082 (unsigned long) section->sh_addralign);
3087 print_vma (section->sh_addr, LONG_HEX);
3088 printf (" %8.8lx", (unsigned long) section->sh_offset);
3090 print_vma (section->sh_size, LONG_HEX);
3092 print_vma (section->sh_entsize, LONG_HEX);
3094 printf (" %3s ", get_elf_section_flags (section->sh_flags));
3096 printf (" %2ld %3lx %ld\n",
3097 (unsigned long) section->sh_link,
3098 (unsigned long) section->sh_info,
3099 (unsigned long) section->sh_addralign);
3103 printf (_("Key to Flags:\n"));
3104 printf (_(" W (write), A (alloc), X (execute), M (merge), S (strings)\n"));
3105 printf (_(" I (info), L (link order), G (group), x (unknown)\n"));
3106 printf (_(" O (extra OS processing required) o (OS specific), p (processor specific)\n"));
3111 /* Process the reloc section. */
3113 process_relocs (file)
3116 unsigned long rel_size;
3117 unsigned long rel_offset;
3123 if (do_using_dynamic)
3125 int is_rela = FALSE;
3130 if (dynamic_info[DT_REL])
3132 rel_offset = dynamic_info[DT_REL];
3133 rel_size = dynamic_info[DT_RELSZ];
3136 else if (dynamic_info [DT_RELA])
3138 rel_offset = dynamic_info[DT_RELA];
3139 rel_size = dynamic_info[DT_RELASZ];
3142 else if (dynamic_info[DT_JMPREL])
3144 rel_offset = dynamic_info[DT_JMPREL];
3145 rel_size = dynamic_info[DT_PLTRELSZ];
3147 switch (dynamic_info[DT_PLTREL])
3164 (_("\nRelocation section at offset 0x%lx contains %ld bytes:\n"),
3165 rel_offset, rel_size);
3167 dump_relocations (file, rel_offset - loadaddr, rel_size,
3168 dynamic_symbols, num_dynamic_syms, dynamic_strings, is_rela);
3171 printf (_("\nThere are no dynamic relocations in this file.\n"));
3175 Elf32_Internal_Shdr * section;
3179 for (i = 0, section = section_headers;
3180 i < elf_header.e_shnum;
3183 if ( section->sh_type != SHT_RELA
3184 && section->sh_type != SHT_REL)
3187 rel_offset = section->sh_offset;
3188 rel_size = section->sh_size;
3192 Elf32_Internal_Shdr * strsec;
3193 Elf_Internal_Sym * symtab;
3196 unsigned long nsyms;
3198 printf (_("\nRelocation section "));
3200 if (string_table == NULL)
3201 printf ("%d", section->sh_name);
3203 printf ("'%s'", SECTION_NAME (section));
3205 printf (_(" at offset 0x%lx contains %lu entries:\n"),
3206 rel_offset, (unsigned long) (rel_size / section->sh_entsize));
3211 if (section->sh_link)
3213 Elf32_Internal_Shdr * symsec;
3215 symsec = section_headers + section->sh_link;
3216 nsyms = symsec->sh_size / symsec->sh_entsize;
3217 symtab = GET_ELF_SYMBOLS (file, symsec->sh_offset, nsyms);
3222 strsec = section_headers + symsec->sh_link;
3224 strtab = (char *) get_data (NULL, file, strsec->sh_offset,
3228 is_rela = section->sh_type == SHT_RELA;
3230 dump_relocations (file, rel_offset, rel_size,
3231 symtab, nsyms, strtab, is_rela);
3243 printf (_("\nThere are no relocations in this file.\n"));
3249 #include "unwind-ia64.h"
3251 /* An absolute address consists of a section and an offset. If the
3252 section is NULL, the offset itself is the address, otherwise, the
3253 address equals to LOAD_ADDRESS(section) + offset. */
3257 unsigned short section;
3263 struct unw_table_entry
3265 struct absaddr start;
3267 struct absaddr info;
3269 *table; /* Unwind table. */
3270 unsigned long table_len; /* Length of unwind table. */
3271 unsigned char * info; /* Unwind info. */
3272 unsigned long info_size; /* Size of unwind info. */
3273 bfd_vma info_addr; /* starting address of unwind info. */
3274 bfd_vma seg_base; /* Starting address of segment. */
3275 Elf_Internal_Sym * symtab; /* The symbol table. */
3276 unsigned long nsyms; /* Number of symbols. */
3277 char * strtab; /* The string table. */
3278 unsigned long strtab_size; /* Size of string table. */
3281 static void find_symbol_for_address PARAMS ((struct unw_aux_info *,
3282 struct absaddr, const char **,
3284 static void dump_ia64_unwind PARAMS ((struct unw_aux_info *));
3285 static int slurp_ia64_unwind_table PARAMS ((FILE *, struct unw_aux_info *,
3286 Elf32_Internal_Shdr *));
3289 find_symbol_for_address (aux, addr, symname, offset)
3290 struct unw_aux_info *aux;
3291 struct absaddr addr;
3292 const char **symname;
3295 bfd_vma dist = (bfd_vma) 0x100000;
3296 Elf_Internal_Sym *sym, *best = NULL;
3299 for (i = 0, sym = aux->symtab; i < aux->nsyms; ++i, ++sym)
3301 if (ELF_ST_TYPE (sym->st_info) == STT_FUNC
3302 && sym->st_name != 0
3303 && (addr.section == SHN_UNDEF || addr.section == sym->st_shndx)
3304 && addr.offset >= sym->st_value
3305 && addr.offset - sym->st_value < dist)
3308 dist = addr.offset - sym->st_value;
3315 *symname = (best->st_name >= aux->strtab_size
3316 ? "<corrupt>" : aux->strtab + best->st_name);
3321 *offset = addr.offset;
3325 dump_ia64_unwind (aux)
3326 struct unw_aux_info *aux;
3329 struct unw_table_entry * tp;
3332 addr_size = is_32bit_elf ? 4 : 8;
3334 for (tp = aux->table; tp < aux->table + aux->table_len; ++tp)
3338 const unsigned char * dp;
3339 const unsigned char * head;
3340 const char * procname;
3342 find_symbol_for_address (aux, tp->start, &procname, &offset);
3344 fputs ("\n<", stdout);
3348 fputs (procname, stdout);
3351 printf ("+%lx", (unsigned long) offset);
3354 fputs (">: [", stdout);
3355 print_vma (tp->start.offset, PREFIX_HEX);
3356 fputc ('-', stdout);
3357 print_vma (tp->end.offset, PREFIX_HEX);
3358 printf ("), info at +0x%lx\n",
3359 (unsigned long) (tp->info.offset - aux->seg_base));
3361 head = aux->info + (tp->info.offset - aux->info_addr);
3362 stamp = BYTE_GET8 ((unsigned char *) head);
3364 printf (" v%u, flags=0x%lx (%s%s ), len=%lu bytes\n",
3365 (unsigned) UNW_VER (stamp),
3366 (unsigned long) ((stamp & UNW_FLAG_MASK) >> 32),
3367 UNW_FLAG_EHANDLER (stamp) ? " ehandler" : "",
3368 UNW_FLAG_UHANDLER (stamp) ? " uhandler" : "",
3369 (unsigned long) (addr_size * UNW_LENGTH (stamp)));
3371 if (UNW_VER (stamp) != 1)
3373 printf ("\tUnknown version.\n");
3378 for (dp = head + 8; dp < head + 8 + addr_size * UNW_LENGTH (stamp);)
3379 dp = unw_decode (dp, in_body, & in_body);
3384 slurp_ia64_unwind_table (file, aux, sec)
3386 struct unw_aux_info *aux;
3387 Elf32_Internal_Shdr *sec;
3389 unsigned long size, addr_size, nrelas, i;
3390 Elf_Internal_Phdr *prog_hdrs, *seg;
3391 struct unw_table_entry *tep;
3392 Elf32_Internal_Shdr *relsec;
3393 Elf_Internal_Rela *rela, *rp;
3394 unsigned char *table, *tp;
3395 Elf_Internal_Sym *sym;
3396 const char *relname;
3399 addr_size = is_32bit_elf ? 4 : 8;
3401 /* First, find the starting address of the segment that includes
3404 if (elf_header.e_phnum)
3406 prog_hdrs = (Elf_Internal_Phdr *)
3407 xmalloc (elf_header.e_phnum * sizeof (Elf_Internal_Phdr));
3410 result = get_32bit_program_headers (file, prog_hdrs);
3412 result = get_64bit_program_headers (file, prog_hdrs);
3420 for (seg = prog_hdrs; seg < prog_hdrs + elf_header.e_phnum; ++seg)
3422 if (seg->p_type != PT_LOAD)
3425 if (sec->sh_addr >= seg->p_vaddr
3426 && (sec->sh_addr + sec->sh_size <= seg->p_vaddr + seg->p_memsz))
3428 aux->seg_base = seg->p_vaddr;
3436 /* Second, build the unwind table from the contents of the unwind section: */
3437 size = sec->sh_size;
3438 table = (char *) get_data (NULL, file, sec->sh_offset,
3439 size, _("unwind table"));
3443 tep = aux->table = xmalloc (size / (3 * addr_size) * sizeof (aux->table[0]));
3444 for (tp = table; tp < table + size; tp += 3 * addr_size, ++ tep)
3446 tep->start.section = SHN_UNDEF;
3447 tep->end.section = SHN_UNDEF;
3448 tep->info.section = SHN_UNDEF;
3451 tep->start.offset = byte_get ((unsigned char *) tp + 0, 4);
3452 tep->end.offset = byte_get ((unsigned char *) tp + 4, 4);
3453 tep->info.offset = byte_get ((unsigned char *) tp + 8, 4);
3457 tep->start.offset = BYTE_GET8 ((unsigned char *) tp + 0);
3458 tep->end.offset = BYTE_GET8 ((unsigned char *) tp + 8);
3459 tep->info.offset = BYTE_GET8 ((unsigned char *) tp + 16);
3461 tep->start.offset += aux->seg_base;
3462 tep->end.offset += aux->seg_base;
3463 tep->info.offset += aux->seg_base;
3467 /* Third, apply any relocations to the unwind table: */
3469 for (relsec = section_headers;
3470 relsec < section_headers + elf_header.e_shnum;
3473 if (relsec->sh_type != SHT_RELA
3474 || section_headers + relsec->sh_info != sec)
3477 if (!slurp_rela_relocs (file, relsec->sh_offset, relsec->sh_size,
3481 for (rp = rela; rp < rela + nrelas; ++rp)
3485 relname = elf_ia64_reloc_type (ELF32_R_TYPE (rp->r_info));
3486 sym = aux->symtab + ELF32_R_SYM (rp->r_info);
3488 if (ELF32_ST_TYPE (sym->st_info) != STT_SECTION)
3490 warn (_("Skipping unexpected symbol type %u"),
3491 ELF32_ST_TYPE (sym->st_info));
3497 relname = elf_ia64_reloc_type (ELF64_R_TYPE (rp->r_info));
3498 sym = aux->symtab + ELF64_R_SYM (rp->r_info);
3500 if (ELF64_ST_TYPE (sym->st_info) != STT_SECTION)
3502 warn (_("Skipping unexpected symbol type %u"),
3503 ELF64_ST_TYPE (sym->st_info));
3508 if (strncmp (relname, "R_IA64_SEGREL", 13) != 0)
3510 warn (_("Skipping unexpected relocation type %s"), relname);
3514 i = rp->r_offset / (3 * addr_size);
3516 switch (rp->r_offset/addr_size % 3)
3519 aux->table[i].start.section = sym->st_shndx;
3520 aux->table[i].start.offset += rp->r_addend;
3523 aux->table[i].end.section = sym->st_shndx;
3524 aux->table[i].end.offset += rp->r_addend;
3527 aux->table[i].info.section = sym->st_shndx;
3528 aux->table[i].info.offset += rp->r_addend;
3538 aux->table_len = size / (3 * addr_size);
3543 process_unwind (file)
3546 Elf32_Internal_Shdr *sec, *unwsec = NULL, *strsec;
3547 unsigned long i, addr_size, unwcount = 0, unwstart = 0;
3548 struct unw_aux_info aux;
3553 if (elf_header.e_machine != EM_IA_64)
3555 printf (_("\nThere are no unwind sections in this file.\n"));
3559 memset (& aux, 0, sizeof (aux));
3561 addr_size = is_32bit_elf ? 4 : 8;
3563 for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec)
3565 if (sec->sh_type == SHT_SYMTAB)
3567 aux.nsyms = sec->sh_size / sec->sh_entsize;
3568 aux.symtab = GET_ELF_SYMBOLS (file, sec->sh_offset, aux.nsyms);
3570 strsec = section_headers + sec->sh_link;
3571 aux.strtab_size = strsec->sh_size;
3572 aux.strtab = (char *) get_data (NULL, file, strsec->sh_offset,
3573 aux.strtab_size, _("string table"));
3575 else if (sec->sh_type == SHT_IA_64_UNWIND)
3580 printf (_("\nThere are no unwind sections in this file.\n"));
3582 while (unwcount-- > 0)
3587 for (i = unwstart, sec = section_headers + unwstart;
3588 i < elf_header.e_shnum; ++i, ++sec)
3589 if (sec->sh_type == SHT_IA_64_UNWIND)
3596 len = sizeof (ELF_STRING_ia64_unwind_once) - 1;
3598 if (strncmp (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind_once,
3601 /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO */
3602 len2 = sizeof (ELF_STRING_ia64_unwind_info_once) - 1;
3603 suffix = SECTION_NAME (unwsec) + len;
3604 for (i = 0, sec = section_headers; i < elf_header.e_shnum;
3606 if (strncmp (SECTION_NAME (sec),
3607 ELF_STRING_ia64_unwind_info_once, len2) == 0
3608 && strcmp (SECTION_NAME (sec) + len2, suffix) == 0)
3613 /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO
3614 .IA_64.unwind or BAR -> .IA_64.unwind_info */
3615 len = sizeof (ELF_STRING_ia64_unwind) - 1;
3616 len2 = sizeof (ELF_STRING_ia64_unwind_info) - 1;
3618 if (strncmp (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind,
3620 suffix = SECTION_NAME (unwsec) + len;
3621 for (i = 0, sec = section_headers; i < elf_header.e_shnum;
3623 if (strncmp (SECTION_NAME (sec),
3624 ELF_STRING_ia64_unwind_info, len2) == 0
3625 && strcmp (SECTION_NAME (sec) + len2, suffix) == 0)
3629 if (i == elf_header.e_shnum)
3631 printf (_("\nCould not find unwind info section for "));
3633 if (string_table == NULL)
3634 printf ("%d", unwsec->sh_name);
3636 printf ("'%s'", SECTION_NAME (unwsec));
3640 aux.info_size = sec->sh_size;
3641 aux.info_addr = sec->sh_addr;
3642 aux.info = (char *) get_data (NULL, file, sec->sh_offset,
3643 aux.info_size, _("unwind info"));
3645 printf (_("\nUnwind section "));
3647 if (string_table == NULL)
3648 printf ("%d", unwsec->sh_name);
3650 printf ("'%s'", SECTION_NAME (unwsec));
3652 printf (_(" at offset 0x%lx contains %lu entries:\n"),
3653 (unsigned long) unwsec->sh_offset,
3654 (unsigned long) (unwsec->sh_size / (3 * addr_size)));
3656 (void) slurp_ia64_unwind_table (file, & aux, unwsec);
3658 if (aux.table_len > 0)
3659 dump_ia64_unwind (& aux);
3662 free ((char *) aux.table);
3664 free ((char *) aux.info);
3673 free ((char *) aux.strtab);
3679 dynamic_segment_mips_val (entry)
3680 Elf_Internal_Dyn * entry;
3682 switch (entry->d_tag)
3685 if (entry->d_un.d_val == 0)
3689 static const char * opts[] =
3691 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
3692 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
3693 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
3694 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
3699 for (cnt = 0; cnt < NUM_ELEM (opts); ++ cnt)
3700 if (entry->d_un.d_val & (1 << cnt))
3702 printf ("%s%s", first ? "" : " ", opts[cnt]);
3709 case DT_MIPS_IVERSION:
3710 if (dynamic_strings != NULL)
3711 printf ("Interface Version: %s\n",
3712 dynamic_strings + entry->d_un.d_val);
3714 printf ("%ld\n", (long) entry->d_un.d_ptr);
3717 case DT_MIPS_TIME_STAMP:
3722 time_t time = entry->d_un.d_val;
3723 tmp = gmtime (&time);
3724 sprintf (timebuf, "%04u-%02u-%02uT%02u:%02u:%02u",
3725 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
3726 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
3727 printf ("Time Stamp: %s\n", timebuf);
3731 case DT_MIPS_RLD_VERSION:
3732 case DT_MIPS_LOCAL_GOTNO:
3733 case DT_MIPS_CONFLICTNO:
3734 case DT_MIPS_LIBLISTNO:
3735 case DT_MIPS_SYMTABNO:
3736 case DT_MIPS_UNREFEXTNO:
3737 case DT_MIPS_HIPAGENO:
3738 case DT_MIPS_DELTA_CLASS_NO:
3739 case DT_MIPS_DELTA_INSTANCE_NO:
3740 case DT_MIPS_DELTA_RELOC_NO:
3741 case DT_MIPS_DELTA_SYM_NO:
3742 case DT_MIPS_DELTA_CLASSSYM_NO:
3743 case DT_MIPS_COMPACT_SIZE:
3744 printf ("%ld\n", (long) entry->d_un.d_ptr);
3748 printf ("%#lx\n", (long) entry->d_un.d_ptr);
3754 dynamic_segment_parisc_val (entry)
3755 Elf_Internal_Dyn * entry;
3757 switch (entry->d_tag)
3759 case DT_HP_DLD_FLAGS:
3768 { DT_HP_DEBUG_PRIVATE, "HP_DEBUG_PRIVATE" },
3769 { DT_HP_DEBUG_CALLBACK, "HP_DEBUG_CALLBACK" },
3770 { DT_HP_DEBUG_CALLBACK_BOR, "HP_DEBUG_CALLBACK_BOR" },
3771 { DT_HP_NO_ENVVAR, "HP_NO_ENVVAR" },
3772 { DT_HP_BIND_NOW, "HP_BIND_NOW" },
3773 { DT_HP_BIND_NONFATAL, "HP_BIND_NONFATAL" },
3774 { DT_HP_BIND_VERBOSE, "HP_BIND_VERBOSE" },
3775 { DT_HP_BIND_RESTRICTED, "HP_BIND_RESTRICTED" },
3776 { DT_HP_BIND_SYMBOLIC, "HP_BIND_SYMBOLIC" },
3777 { DT_HP_RPATH_FIRST, "HP_RPATH_FIRST" },
3778 { DT_HP_BIND_DEPTH_FIRST, "HP_BIND_DEPTH_FIRST" }
3782 bfd_vma val = entry->d_un.d_val;
3784 for (cnt = 0; cnt < sizeof (flags) / sizeof (flags[0]); ++cnt)
3785 if (val & flags[cnt].bit)
3789 fputs (flags[cnt].str, stdout);
3791 val ^= flags[cnt].bit;
3794 if (val != 0 || first)
3798 print_vma (val, HEX);
3804 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
3810 get_32bit_dynamic_segment (file)
3813 Elf32_External_Dyn * edyn;
3814 Elf_Internal_Dyn * entry;
3817 edyn = (Elf32_External_Dyn *) get_data (NULL, file, dynamic_addr,
3818 dynamic_size, _("dynamic segment"));
3822 /* SGI's ELF has more than one section in the DYNAMIC segment. Determine
3823 how large this .dynamic is now. We can do this even before the byte
3824 swapping since the DT_NULL tag is recognizable. */
3826 while (*(Elf32_Word *) edyn [dynamic_size++].d_tag != DT_NULL)
3829 dynamic_segment = (Elf_Internal_Dyn *)
3830 malloc (dynamic_size * sizeof (Elf_Internal_Dyn));
3832 if (dynamic_segment == NULL)
3834 error (_("Out of memory\n"));
3839 for (i = 0, entry = dynamic_segment;
3843 entry->d_tag = BYTE_GET (edyn [i].d_tag);
3844 entry->d_un.d_val = BYTE_GET (edyn [i].d_un.d_val);
3853 get_64bit_dynamic_segment (file)
3856 Elf64_External_Dyn * edyn;
3857 Elf_Internal_Dyn * entry;
3860 edyn = (Elf64_External_Dyn *) get_data (NULL, file, dynamic_addr,
3861 dynamic_size, _("dynamic segment"));
3865 /* SGI's ELF has more than one section in the DYNAMIC segment. Determine
3866 how large this .dynamic is now. We can do this even before the byte
3867 swapping since the DT_NULL tag is recognizable. */
3869 while (*(bfd_vma *) edyn [dynamic_size ++].d_tag != DT_NULL)
3872 dynamic_segment = (Elf_Internal_Dyn *)
3873 malloc (dynamic_size * sizeof (Elf_Internal_Dyn));
3875 if (dynamic_segment == NULL)
3877 error (_("Out of memory\n"));
3882 for (i = 0, entry = dynamic_segment;
3886 entry->d_tag = BYTE_GET8 (edyn [i].d_tag);
3887 entry->d_un.d_val = BYTE_GET8 (edyn [i].d_un.d_val);
3896 get_dynamic_flags (flags)
3899 static char buff [64];
3904 flag = flags & - flags;
3909 case DF_ORIGIN: strcat (buff, "ORIGIN "); break;
3910 case DF_SYMBOLIC: strcat (buff, "SYMBOLIC "); break;
3911 case DF_TEXTREL: strcat (buff, "TEXTREL "); break;
3912 case DF_BIND_NOW: strcat (buff, "BIND_NOW "); break;
3913 default: strcat (buff, "unknown "); break;
3919 /* Parse and display the contents of the dynamic segment. */
3921 process_dynamic_segment (file)
3924 Elf_Internal_Dyn * entry;
3927 if (dynamic_size == 0)
3930 printf (_("\nThere is no dynamic segment in this file.\n"));
3937 if (! get_32bit_dynamic_segment (file))
3940 else if (! get_64bit_dynamic_segment (file))
3943 /* Find the appropriate symbol table. */
3944 if (dynamic_symbols == NULL)
3946 for (i = 0, entry = dynamic_segment;
3950 unsigned long offset;
3952 if (entry->d_tag != DT_SYMTAB)
3955 dynamic_info[DT_SYMTAB] = entry->d_un.d_val;
3957 /* Since we do not know how big the symbol table is,
3958 we default to reading in the entire file (!) and
3959 processing that. This is overkill, I know, but it
3961 offset = entry->d_un.d_val - loadaddr;
3963 if (fseek (file, 0, SEEK_END))
3964 error (_("Unable to seek to end of file!"));
3967 num_dynamic_syms = (ftell (file) - offset) / sizeof (Elf32_External_Sym);
3969 num_dynamic_syms = (ftell (file) - offset) / sizeof (Elf64_External_Sym);
3971 if (num_dynamic_syms < 1)
3973 error (_("Unable to determine the number of symbols to load\n"));
3977 dynamic_symbols = GET_ELF_SYMBOLS (file, offset, num_dynamic_syms);
3981 /* Similarly find a string table. */
3982 if (dynamic_strings == NULL)
3984 for (i = 0, entry = dynamic_segment;
3988 unsigned long offset;
3991 if (entry->d_tag != DT_STRTAB)
3994 dynamic_info[DT_STRTAB] = entry->d_un.d_val;
3996 /* Since we do not know how big the string table is,
3997 we default to reading in the entire file (!) and
3998 processing that. This is overkill, I know, but it
4001 offset = entry->d_un.d_val - loadaddr;
4002 if (fseek (file, 0, SEEK_END))
4003 error (_("Unable to seek to end of file\n"));
4004 str_tab_len = ftell (file) - offset;
4006 if (str_tab_len < 1)
4009 (_("Unable to determine the length of the dynamic string table\n"));
4013 dynamic_strings = (char *) get_data (NULL, file, offset, str_tab_len,
4014 _("dynamic string table"));
4020 /* And find the syminfo section if available. */
4021 if (dynamic_syminfo == NULL)
4023 unsigned int syminsz = 0;
4025 for (i = 0, entry = dynamic_segment;
4029 if (entry->d_tag == DT_SYMINENT)
4031 /* Note: these braces are necessary to avoid a syntax
4032 error from the SunOS4 C compiler. */
4033 assert (sizeof (Elf_External_Syminfo) == entry->d_un.d_val);
4035 else if (entry->d_tag == DT_SYMINSZ)
4036 syminsz = entry->d_un.d_val;
4037 else if (entry->d_tag == DT_SYMINFO)
4038 dynamic_syminfo_offset = entry->d_un.d_val - loadaddr;
4041 if (dynamic_syminfo_offset != 0 && syminsz != 0)
4043 Elf_External_Syminfo * extsyminfo;
4044 Elf_Internal_Syminfo * syminfo;
4046 /* There is a syminfo section. Read the data. */
4047 extsyminfo = ((Elf_External_Syminfo *)
4048 get_data (NULL, file, dynamic_syminfo_offset,
4049 syminsz, _("symbol information")));
4053 dynamic_syminfo = (Elf_Internal_Syminfo *) malloc (syminsz);
4054 if (dynamic_syminfo == NULL)
4056 error (_("Out of memory\n"));
4060 dynamic_syminfo_nent = syminsz / sizeof (Elf_External_Syminfo);
4061 for (i = 0, syminfo = dynamic_syminfo; i < dynamic_syminfo_nent;
4064 syminfo->si_boundto = BYTE_GET (extsyminfo[i].si_boundto);
4065 syminfo->si_flags = BYTE_GET (extsyminfo[i].si_flags);
4072 if (do_dynamic && dynamic_addr)
4073 printf (_("\nDynamic segment at offset 0x%x contains %ld entries:\n"),
4074 dynamic_addr, (long) dynamic_size);
4076 printf (_(" Tag Type Name/Value\n"));
4078 for (i = 0, entry = dynamic_segment;
4087 print_vma (entry->d_tag, FULL_HEX);
4088 dtype = get_dynamic_type (entry->d_tag);
4089 printf (" (%s)%*s", dtype,
4090 ((is_32bit_elf ? 27 : 19)
4091 - (int) strlen (dtype)),
4095 switch (entry->d_tag)
4099 printf ("%s", get_dynamic_flags (entry->d_un.d_val));
4109 switch (entry->d_tag)
4112 printf (_("Auxiliary library"));
4116 printf (_("Filter library"));
4120 printf (_("Configuration file"));
4124 printf (_("Dependency audit library"));
4128 printf (_("Audit library"));
4132 if (dynamic_strings)
4133 printf (": [%s]\n", dynamic_strings + entry->d_un.d_val);
4137 print_vma (entry->d_un.d_val, PREFIX_HEX);
4146 printf (_("Flags:"));
4147 if (entry->d_un.d_val == 0)
4148 printf (_(" None\n"));
4151 unsigned long int val = entry->d_un.d_val;
4152 if (val & DTF_1_PARINIT)
4154 printf (" PARINIT");
4155 val ^= DTF_1_PARINIT;
4157 if (val & DTF_1_CONFEXP)
4159 printf (" CONFEXP");
4160 val ^= DTF_1_CONFEXP;
4163 printf (" %lx", val);
4172 printf (_("Flags:"));
4173 if (entry->d_un.d_val == 0)
4174 printf (_(" None\n"));
4177 unsigned long int val = entry->d_un.d_val;
4178 if (val & DF_P1_LAZYLOAD)
4180 printf (" LAZYLOAD");
4181 val ^= DF_P1_LAZYLOAD;
4183 if (val & DF_P1_GROUPPERM)
4185 printf (" GROUPPERM");
4186 val ^= DF_P1_GROUPPERM;
4189 printf (" %lx", val);
4198 printf (_("Flags:"));
4199 if (entry->d_un.d_val == 0)
4200 printf (_(" None\n"));
4203 unsigned long int val = entry->d_un.d_val;
4209 if (val & DF_1_GLOBAL)
4214 if (val & DF_1_GROUP)
4219 if (val & DF_1_NODELETE)
4221 printf (" NODELETE");
4222 val ^= DF_1_NODELETE;
4224 if (val & DF_1_LOADFLTR)
4226 printf (" LOADFLTR");
4227 val ^= DF_1_LOADFLTR;
4229 if (val & DF_1_INITFIRST)
4231 printf (" INITFIRST");
4232 val ^= DF_1_INITFIRST;
4234 if (val & DF_1_NOOPEN)
4239 if (val & DF_1_ORIGIN)
4244 if (val & DF_1_DIRECT)
4249 if (val & DF_1_TRANS)
4254 if (val & DF_1_INTERPOSE)
4256 printf (" INTERPOSE");
4257 val ^= DF_1_INTERPOSE;
4259 if (val & DF_1_NODEFLIB)
4261 printf (" NODEFLIB");
4262 val ^= DF_1_NODEFLIB;
4264 if (val & DF_1_NODUMP)
4269 if (val & DF_1_CONLFAT)
4271 printf (" CONLFAT");
4272 val ^= DF_1_CONLFAT;
4275 printf (" %lx", val);
4283 puts (get_dynamic_type (entry->d_un.d_val));
4303 dynamic_info[entry->d_tag] = entry->d_un.d_val;
4309 if (dynamic_strings == NULL)
4312 name = dynamic_strings + entry->d_un.d_val;
4316 switch (entry->d_tag)
4319 printf (_("Shared library: [%s]"), name);
4321 if (strcmp (name, program_interpreter) == 0)
4322 printf (_(" program interpreter"));
4326 printf (_("Library soname: [%s]"), name);
4330 printf (_("Library rpath: [%s]"), name);
4334 printf (_("Library runpath: [%s]"), name);
4338 print_vma (entry->d_un.d_val, PREFIX_HEX);
4343 print_vma (entry->d_un.d_val, PREFIX_HEX);
4359 case DT_INIT_ARRAYSZ:
4360 case DT_FINI_ARRAYSZ:
4363 print_vma (entry->d_un.d_val, UNSIGNED);
4364 printf (" (bytes)\n");
4374 print_vma (entry->d_un.d_val, UNSIGNED);
4387 if (dynamic_strings != NULL && entry->d_tag == DT_USED)
4391 name = dynamic_strings + entry->d_un.d_val;
4395 printf (_("Not needed object: [%s]\n"), name);
4400 print_vma (entry->d_un.d_val, PREFIX_HEX);
4406 /* The value of this entry is ignored. */
4410 if ((entry->d_tag >= DT_VERSYM) && (entry->d_tag <= DT_VERNEEDNUM))
4411 version_info [DT_VERSIONTAGIDX (entry->d_tag)] =
4416 switch (elf_header.e_machine)
4419 case EM_MIPS_RS3_LE:
4420 dynamic_segment_mips_val (entry);
4423 dynamic_segment_parisc_val (entry);
4426 print_vma (entry->d_un.d_val, PREFIX_HEX);
4438 get_ver_flags (flags)
4441 static char buff [32];
4448 if (flags & VER_FLG_BASE)
4449 strcat (buff, "BASE ");
4451 if (flags & VER_FLG_WEAK)
4453 if (flags & VER_FLG_BASE)
4454 strcat (buff, "| ");
4456 strcat (buff, "WEAK ");
4459 if (flags & ~(VER_FLG_BASE | VER_FLG_WEAK))
4460 strcat (buff, "| <unknown>");
4465 /* Display the contents of the version sections. */
4467 process_version_sections (file)
4470 Elf32_Internal_Shdr * section;
4477 for (i = 0, section = section_headers;
4478 i < elf_header.e_shnum;
4481 switch (section->sh_type)
4483 case SHT_GNU_verdef:
4485 Elf_External_Verdef * edefs;
4492 (_("\nVersion definition section '%s' contains %ld entries:\n"),
4493 SECTION_NAME (section), section->sh_info);
4495 printf (_(" Addr: 0x"));
4496 printf_vma (section->sh_addr);
4497 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
4498 (unsigned long) section->sh_offset, section->sh_link,
4499 SECTION_NAME (section_headers + section->sh_link));
4501 edefs = ((Elf_External_Verdef *)
4502 get_data (NULL, file, section->sh_offset,
4504 _("version definition section")));
4508 for (idx = cnt = 0; cnt < section->sh_info; ++ cnt)
4511 Elf_External_Verdef * edef;
4512 Elf_Internal_Verdef ent;
4513 Elf_External_Verdaux * eaux;
4514 Elf_Internal_Verdaux aux;
4518 vstart = ((char *) edefs) + idx;
4520 edef = (Elf_External_Verdef *) vstart;
4522 ent.vd_version = BYTE_GET (edef->vd_version);
4523 ent.vd_flags = BYTE_GET (edef->vd_flags);
4524 ent.vd_ndx = BYTE_GET (edef->vd_ndx);
4525 ent.vd_cnt = BYTE_GET (edef->vd_cnt);
4526 ent.vd_hash = BYTE_GET (edef->vd_hash);
4527 ent.vd_aux = BYTE_GET (edef->vd_aux);
4528 ent.vd_next = BYTE_GET (edef->vd_next);
4530 printf (_(" %#06x: Rev: %d Flags: %s"),
4531 idx, ent.vd_version, get_ver_flags (ent.vd_flags));
4533 printf (_(" Index: %d Cnt: %d "),
4534 ent.vd_ndx, ent.vd_cnt);
4536 vstart += ent.vd_aux;
4538 eaux = (Elf_External_Verdaux *) vstart;
4540 aux.vda_name = BYTE_GET (eaux->vda_name);
4541 aux.vda_next = BYTE_GET (eaux->vda_next);
4543 if (dynamic_strings)
4544 printf (_("Name: %s\n"), dynamic_strings + aux.vda_name);
4546 printf (_("Name index: %ld\n"), aux.vda_name);
4548 isum = idx + ent.vd_aux;
4550 for (j = 1; j < ent.vd_cnt; j ++)
4552 isum += aux.vda_next;
4553 vstart += aux.vda_next;
4555 eaux = (Elf_External_Verdaux *) vstart;
4557 aux.vda_name = BYTE_GET (eaux->vda_name);
4558 aux.vda_next = BYTE_GET (eaux->vda_next);
4560 if (dynamic_strings)
4561 printf (_(" %#06x: Parent %d: %s\n"),
4562 isum, j, dynamic_strings + aux.vda_name);
4564 printf (_(" %#06x: Parent %d, name index: %ld\n"),
4565 isum, j, aux.vda_name);
4575 case SHT_GNU_verneed:
4577 Elf_External_Verneed * eneed;
4583 printf (_("\nVersion needs section '%s' contains %ld entries:\n"),
4584 SECTION_NAME (section), section->sh_info);
4586 printf (_(" Addr: 0x"));
4587 printf_vma (section->sh_addr);
4588 printf (_(" Offset: %#08lx Link to section: %ld (%s)\n"),
4589 (unsigned long) section->sh_offset, section->sh_link,
4590 SECTION_NAME (section_headers + section->sh_link));
4592 eneed = ((Elf_External_Verneed *)
4593 get_data (NULL, file, section->sh_offset,
4594 section->sh_size, _("version need section")));
4598 for (idx = cnt = 0; cnt < section->sh_info; ++cnt)
4600 Elf_External_Verneed * entry;
4601 Elf_Internal_Verneed ent;
4606 vstart = ((char *) eneed) + idx;
4608 entry = (Elf_External_Verneed *) vstart;
4610 ent.vn_version = BYTE_GET (entry->vn_version);
4611 ent.vn_cnt = BYTE_GET (entry->vn_cnt);
4612 ent.vn_file = BYTE_GET (entry->vn_file);
4613 ent.vn_aux = BYTE_GET (entry->vn_aux);
4614 ent.vn_next = BYTE_GET (entry->vn_next);
4616 printf (_(" %#06x: Version: %d"), idx, ent.vn_version);
4618 if (dynamic_strings)
4619 printf (_(" File: %s"), dynamic_strings + ent.vn_file);
4621 printf (_(" File: %lx"), ent.vn_file);
4623 printf (_(" Cnt: %d\n"), ent.vn_cnt);
4625 vstart += ent.vn_aux;
4627 for (j = 0, isum = idx + ent.vn_aux; j < ent.vn_cnt; ++j)
4629 Elf_External_Vernaux * eaux;
4630 Elf_Internal_Vernaux aux;
4632 eaux = (Elf_External_Vernaux *) vstart;
4634 aux.vna_hash = BYTE_GET (eaux->vna_hash);
4635 aux.vna_flags = BYTE_GET (eaux->vna_flags);
4636 aux.vna_other = BYTE_GET (eaux->vna_other);
4637 aux.vna_name = BYTE_GET (eaux->vna_name);
4638 aux.vna_next = BYTE_GET (eaux->vna_next);
4640 if (dynamic_strings)
4641 printf (_(" %#06x: Name: %s"),
4642 isum, dynamic_strings + aux.vna_name);
4644 printf (_(" %#06x: Name index: %lx"),
4645 isum, aux.vna_name);
4647 printf (_(" Flags: %s Version: %d\n"),
4648 get_ver_flags (aux.vna_flags), aux.vna_other);
4650 isum += aux.vna_next;
4651 vstart += aux.vna_next;
4661 case SHT_GNU_versym:
4663 Elf32_Internal_Shdr * link_section;
4666 unsigned char * edata;
4667 unsigned short * data;
4669 Elf_Internal_Sym * symbols;
4670 Elf32_Internal_Shdr * string_sec;
4672 link_section = section_headers + section->sh_link;
4673 total = section->sh_size / section->sh_entsize;
4677 symbols = GET_ELF_SYMBOLS (file, link_section->sh_offset,
4678 link_section->sh_size / link_section->sh_entsize);
4680 string_sec = section_headers + link_section->sh_link;
4682 strtab = (char *) get_data (NULL, file, string_sec->sh_offset,
4683 string_sec->sh_size,
4684 _("version string table"));
4688 printf (_("\nVersion symbols section '%s' contains %d entries:\n"),
4689 SECTION_NAME (section), total);
4691 printf (_(" Addr: "));
4692 printf_vma (section->sh_addr);
4693 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
4694 (unsigned long) section->sh_offset, section->sh_link,
4695 SECTION_NAME (link_section));
4699 get_data (NULL, file,
4700 version_info[DT_VERSIONTAGIDX (DT_VERSYM)] - loadaddr,
4701 total * sizeof (short), _("version symbol data")));
4708 data = (unsigned short *) malloc (total * sizeof (short));
4710 for (cnt = total; cnt --;)
4711 data [cnt] = byte_get (edata + cnt * sizeof (short),
4716 for (cnt = 0; cnt < total; cnt += 4)
4719 int check_def, check_need;
4722 printf (" %03x:", cnt);
4724 for (j = 0; (j < 4) && (cnt + j) < total; ++j)
4725 switch (data [cnt + j])
4728 fputs (_(" 0 (*local*) "), stdout);
4732 fputs (_(" 1 (*global*) "), stdout);
4736 nn = printf ("%4x%c", data [cnt + j] & 0x7fff,
4737 data [cnt + j] & 0x8000 ? 'h' : ' ');
4741 if (symbols [cnt + j].st_shndx >= SHN_LORESERVE
4742 || section_headers[symbols [cnt + j].st_shndx].sh_type
4745 if (symbols [cnt + j].st_shndx == SHN_UNDEF)
4752 && version_info [DT_VERSIONTAGIDX (DT_VERNEED)])
4754 Elf_Internal_Verneed ivn;
4755 unsigned long offset;
4757 offset = version_info [DT_VERSIONTAGIDX (DT_VERNEED)]
4762 Elf_Internal_Vernaux ivna;
4763 Elf_External_Verneed evn;
4764 Elf_External_Vernaux evna;
4765 unsigned long a_off;
4767 get_data (&evn, file, offset, sizeof (evn),
4770 ivn.vn_aux = BYTE_GET (evn.vn_aux);
4771 ivn.vn_next = BYTE_GET (evn.vn_next);
4773 a_off = offset + ivn.vn_aux;
4777 get_data (&evna, file, a_off, sizeof (evna),
4778 _("version need aux (2)"));
4780 ivna.vna_next = BYTE_GET (evna.vna_next);
4781 ivna.vna_other = BYTE_GET (evna.vna_other);
4783 a_off += ivna.vna_next;
4785 while (ivna.vna_other != data [cnt + j]
4786 && ivna.vna_next != 0);
4788 if (ivna.vna_other == data [cnt + j])
4790 ivna.vna_name = BYTE_GET (evna.vna_name);
4792 name = strtab + ivna.vna_name;
4793 nn += printf ("(%s%-*s",
4795 12 - (int) strlen (name),
4801 offset += ivn.vn_next;
4803 while (ivn.vn_next);
4806 if (check_def && data [cnt + j] != 0x8001
4807 && version_info [DT_VERSIONTAGIDX (DT_VERDEF)])
4809 Elf_Internal_Verdef ivd;
4810 Elf_External_Verdef evd;
4811 unsigned long offset;
4813 offset = version_info
4814 [DT_VERSIONTAGIDX (DT_VERDEF)] - loadaddr;
4818 get_data (&evd, file, offset, sizeof (evd),
4821 ivd.vd_next = BYTE_GET (evd.vd_next);
4822 ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
4824 offset += ivd.vd_next;
4826 while (ivd.vd_ndx != (data [cnt + j] & 0x7fff)
4827 && ivd.vd_next != 0);
4829 if (ivd.vd_ndx == (data [cnt + j] & 0x7fff))
4831 Elf_External_Verdaux evda;
4832 Elf_Internal_Verdaux ivda;
4834 ivd.vd_aux = BYTE_GET (evd.vd_aux);
4836 get_data (&evda, file,
4837 offset - ivd.vd_next + ivd.vd_aux,
4838 sizeof (evda), _("version def aux"));
4840 ivda.vda_name = BYTE_GET (evda.vda_name);
4842 name = strtab + ivda.vda_name;
4843 nn += printf ("(%s%-*s",
4845 12 - (int) strlen (name),
4851 printf ("%*c", 18 - nn, ' ');
4869 printf (_("\nNo version information found in this file.\n"));
4875 get_symbol_binding (binding)
4876 unsigned int binding;
4878 static char buff [32];
4882 case STB_LOCAL: return "LOCAL";
4883 case STB_GLOBAL: return "GLOBAL";
4884 case STB_WEAK: return "WEAK";
4886 if (binding >= STB_LOPROC && binding <= STB_HIPROC)
4887 sprintf (buff, _("<processor specific>: %d"), binding);
4888 else if (binding >= STB_LOOS && binding <= STB_HIOS)
4889 sprintf (buff, _("<OS specific>: %d"), binding);
4891 sprintf (buff, _("<unknown>: %d"), binding);
4897 get_symbol_type (type)
4900 static char buff [32];
4904 case STT_NOTYPE: return "NOTYPE";
4905 case STT_OBJECT: return "OBJECT";
4906 case STT_FUNC: return "FUNC";
4907 case STT_SECTION: return "SECTION";
4908 case STT_FILE: return "FILE";
4909 case STT_COMMON: return "COMMON";
4911 if (type >= STT_LOPROC && type <= STT_HIPROC)
4913 if (elf_header.e_machine == EM_ARM && type == STT_ARM_TFUNC)
4914 return "THUMB_FUNC";
4916 if (elf_header.e_machine == EM_SPARCV9 && type == STT_REGISTER)
4919 if (elf_header.e_machine == EM_PARISC && type == STT_PARISC_MILLI)
4920 return "PARISC_MILLI";
4922 sprintf (buff, _("<processor specific>: %d"), type);
4924 else if (type >= STT_LOOS && type <= STT_HIOS)
4926 if (elf_header.e_machine == EM_PARISC)
4928 if (type == STT_HP_OPAQUE)
4930 if (type == STT_HP_STUB)
4934 sprintf (buff, _("<OS specific>: %d"), type);
4937 sprintf (buff, _("<unknown>: %d"), type);
4943 get_symbol_visibility (visibility)
4944 unsigned int visibility;
4948 case STV_DEFAULT: return "DEFAULT";
4949 case STV_INTERNAL: return "INTERNAL";
4950 case STV_HIDDEN: return "HIDDEN";
4951 case STV_PROTECTED: return "PROTECTED";
4957 get_symbol_index_type (type)
4962 case SHN_UNDEF: return "UND";
4963 case SHN_ABS: return "ABS";
4964 case SHN_COMMON: return "COM";
4966 if (type >= SHN_LOPROC && type <= SHN_HIPROC)
4968 else if (type >= SHN_LORESERVE && type <= SHN_HIRESERVE)
4970 else if (type >= SHN_LOOS && type <= SHN_HIOS)
4974 static char buff [32];
4976 sprintf (buff, "%3d", type);
4983 get_dynamic_data (file, number)
4985 unsigned int number;
4987 unsigned char * e_data;
4990 e_data = (unsigned char *) malloc (number * 4);
4994 error (_("Out of memory\n"));
4998 if (fread (e_data, 4, number, file) != number)
5000 error (_("Unable to read in dynamic data\n"));
5004 i_data = (int *) malloc (number * sizeof (* i_data));
5008 error (_("Out of memory\n"));
5014 i_data [number] = byte_get (e_data + number * 4, 4);
5021 /* Dump the symbol table */
5023 process_symbol_table (file)
5026 Elf32_Internal_Shdr * section;
5027 unsigned char nb [4];
5028 unsigned char nc [4];
5031 int * buckets = NULL;
5032 int * chains = NULL;
5034 if (! do_syms && !do_histogram)
5037 if (dynamic_info[DT_HASH] && ((do_using_dynamic && dynamic_strings != NULL)
5040 if (fseek (file, dynamic_info[DT_HASH] - loadaddr, SEEK_SET))
5042 error (_("Unable to seek to start of dynamic information"));
5046 if (fread (nb, sizeof (nb), 1, file) != 1)
5048 error (_("Failed to read in number of buckets\n"));
5052 if (fread (nc, sizeof (nc), 1, file) != 1)
5054 error (_("Failed to read in number of chains\n"));
5058 nbuckets = byte_get (nb, 4);
5059 nchains = byte_get (nc, 4);
5061 buckets = get_dynamic_data (file, nbuckets);
5062 chains = get_dynamic_data (file, nchains);
5064 if (buckets == NULL || chains == NULL)
5069 && dynamic_info[DT_HASH] && do_using_dynamic && dynamic_strings != NULL)
5074 printf (_("\nSymbol table for image:\n"));
5076 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
5078 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
5080 for (hn = 0; hn < nbuckets; hn++)
5085 for (si = buckets [hn]; si < nchains && si > 0; si = chains [si])
5087 Elf_Internal_Sym * psym;
5089 psym = dynamic_symbols + si;
5091 printf (" %3d %3d: ", si, hn);
5092 print_vma (psym->st_value, LONG_HEX);
5094 print_vma (psym->st_size, DEC_5);
5096 printf (" %6s", get_symbol_type (ELF_ST_TYPE (psym->st_info)));
5097 printf (" %6s", get_symbol_binding (ELF_ST_BIND (psym->st_info)));
5098 printf (" %3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym->st_other)));
5099 printf (" %3.3s", get_symbol_index_type (psym->st_shndx));
5100 printf (" %s\n", dynamic_strings + psym->st_name);
5104 else if (do_syms && !do_using_dynamic)
5108 for (i = 0, section = section_headers;
5109 i < elf_header.e_shnum;
5114 Elf_Internal_Sym * symtab;
5115 Elf_Internal_Sym * psym;
5118 if ( section->sh_type != SHT_SYMTAB
5119 && section->sh_type != SHT_DYNSYM)
5122 printf (_("\nSymbol table '%s' contains %lu entries:\n"),
5123 SECTION_NAME (section),
5124 (unsigned long) (section->sh_size / section->sh_entsize));
5126 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
5128 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
5130 symtab = GET_ELF_SYMBOLS (file, section->sh_offset,
5131 section->sh_size / section->sh_entsize);
5135 if (section->sh_link == elf_header.e_shstrndx)
5136 strtab = string_table;
5139 Elf32_Internal_Shdr * string_sec;
5141 string_sec = section_headers + section->sh_link;
5143 strtab = (char *) get_data (NULL, file, string_sec->sh_offset,
5144 string_sec->sh_size,
5148 for (si = 0, psym = symtab;
5149 si < section->sh_size / section->sh_entsize;
5152 printf ("%6d: ", si);
5153 print_vma (psym->st_value, LONG_HEX);
5155 print_vma (psym->st_size, DEC_5);
5156 printf (" %-7s", get_symbol_type (ELF_ST_TYPE (psym->st_info)));
5157 printf (" %-6s", get_symbol_binding (ELF_ST_BIND (psym->st_info)));
5158 printf (" %-3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym->st_other)));
5159 printf (" %4s", get_symbol_index_type (psym->st_shndx));
5160 printf (" %s", strtab + psym->st_name);
5162 if (section->sh_type == SHT_DYNSYM &&
5163 version_info [DT_VERSIONTAGIDX (DT_VERSYM)] != 0)
5165 unsigned char data[2];
5166 unsigned short vers_data;
5167 unsigned long offset;
5171 offset = version_info [DT_VERSIONTAGIDX (DT_VERSYM)]
5174 get_data (&data, file, offset + si * sizeof (vers_data),
5175 sizeof (data), _("version data"));
5177 vers_data = byte_get (data, 2);
5179 is_nobits = psym->st_shndx < SHN_LORESERVE ?
5180 (section_headers [psym->st_shndx].sh_type == SHT_NOBITS)
5183 check_def = (psym->st_shndx != SHN_UNDEF);
5185 if ((vers_data & 0x8000) || vers_data > 1)
5187 if (version_info [DT_VERSIONTAGIDX (DT_VERNEED)]
5188 && (is_nobits || ! check_def))
5190 Elf_External_Verneed evn;
5191 Elf_Internal_Verneed ivn;
5192 Elf_Internal_Vernaux ivna;
5194 /* We must test both. */
5195 offset = version_info
5196 [DT_VERSIONTAGIDX (DT_VERNEED)] - loadaddr;
5200 unsigned long vna_off;
5202 get_data (&evn, file, offset, sizeof (evn),
5205 ivn.vn_aux = BYTE_GET (evn.vn_aux);
5206 ivn.vn_next = BYTE_GET (evn.vn_next);
5208 vna_off = offset + ivn.vn_aux;
5212 Elf_External_Vernaux evna;
5214 get_data (&evna, file, vna_off,
5216 _("version need aux (3)"));
5218 ivna.vna_other = BYTE_GET (evna.vna_other);
5219 ivna.vna_next = BYTE_GET (evna.vna_next);
5220 ivna.vna_name = BYTE_GET (evna.vna_name);
5222 vna_off += ivna.vna_next;
5224 while (ivna.vna_other != vers_data
5225 && ivna.vna_next != 0);
5227 if (ivna.vna_other == vers_data)
5230 offset += ivn.vn_next;
5232 while (ivn.vn_next != 0);
5234 if (ivna.vna_other == vers_data)
5237 strtab + ivna.vna_name, ivna.vna_other);
5240 else if (! is_nobits)
5241 error (_("bad dynamic symbol"));
5248 if (vers_data != 0x8001
5249 && version_info [DT_VERSIONTAGIDX (DT_VERDEF)])
5251 Elf_Internal_Verdef ivd;
5252 Elf_Internal_Verdaux ivda;
5253 Elf_External_Verdaux evda;
5254 unsigned long offset;
5257 version_info [DT_VERSIONTAGIDX (DT_VERDEF)]
5262 Elf_External_Verdef evd;
5264 get_data (&evd, file, offset, sizeof (evd),
5267 ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
5268 ivd.vd_aux = BYTE_GET (evd.vd_aux);
5269 ivd.vd_next = BYTE_GET (evd.vd_next);
5271 offset += ivd.vd_next;
5273 while (ivd.vd_ndx != (vers_data & 0x7fff)
5274 && ivd.vd_next != 0);
5276 offset -= ivd.vd_next;
5277 offset += ivd.vd_aux;
5279 get_data (&evda, file, offset, sizeof (evda),
5280 _("version def aux"));
5282 ivda.vda_name = BYTE_GET (evda.vda_name);
5284 if (psym->st_name != ivda.vda_name)
5285 printf ((vers_data & 0x8000)
5287 strtab + ivda.vda_name);
5297 if (strtab != string_table)
5303 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
5305 if (do_histogram && buckets != NULL)
5312 int nzero_counts = 0;
5315 printf (_("\nHistogram for bucket list length (total of %d buckets):\n"),
5317 printf (_(" Length Number %% of total Coverage\n"));
5319 lengths = (int *) calloc (nbuckets, sizeof (int));
5320 if (lengths == NULL)
5322 error (_("Out of memory"));
5325 for (hn = 0; hn < nbuckets; ++hn)
5330 for (si = buckets[hn]; si > 0 && si < nchains; si = chains[si])
5333 if (maxlength < ++lengths[hn])
5338 counts = (int *) calloc (maxlength + 1, sizeof (int));
5341 error (_("Out of memory"));
5345 for (hn = 0; hn < nbuckets; ++hn)
5346 ++ counts [lengths [hn]];
5350 printf (" 0 %-10d (%5.1f%%)\n",
5351 counts[0], (counts[0] * 100.0) / nbuckets);
5352 for (si = 1; si <= maxlength; ++si)
5354 nzero_counts += counts[si] * si;
5355 printf ("%7d %-10d (%5.1f%%) %5.1f%%\n",
5356 si, counts[si], (counts[si] * 100.0) / nbuckets,
5357 (nzero_counts * 100.0) / nsyms);
5365 if (buckets != NULL)
5375 process_syminfo (file)
5376 FILE * file ATTRIBUTE_UNUSED;
5380 if (dynamic_syminfo == NULL
5382 /* No syminfo, this is ok. */
5385 /* There better should be a dynamic symbol section. */
5386 if (dynamic_symbols == NULL || dynamic_strings == NULL)
5390 printf (_("\nDynamic info segment at offset 0x%lx contains %d entries:\n"),
5391 dynamic_syminfo_offset, dynamic_syminfo_nent);
5393 printf (_(" Num: Name BoundTo Flags\n"));
5394 for (i = 0; i < dynamic_syminfo_nent; ++i)
5396 unsigned short int flags = dynamic_syminfo[i].si_flags;
5398 printf ("%4d: %-30s ", i,
5399 dynamic_strings + dynamic_symbols[i].st_name);
5401 switch (dynamic_syminfo[i].si_boundto)
5403 case SYMINFO_BT_SELF:
5404 fputs ("SELF ", stdout);
5406 case SYMINFO_BT_PARENT:
5407 fputs ("PARENT ", stdout);
5410 if (dynamic_syminfo[i].si_boundto > 0
5411 && dynamic_syminfo[i].si_boundto < dynamic_size)
5414 + dynamic_segment[dynamic_syminfo[i].si_boundto].d_un.d_val);
5416 printf ("%-10d ", dynamic_syminfo[i].si_boundto);
5420 if (flags & SYMINFO_FLG_DIRECT)
5422 if (flags & SYMINFO_FLG_PASSTHRU)
5423 printf (" PASSTHRU");
5424 if (flags & SYMINFO_FLG_COPY)
5426 if (flags & SYMINFO_FLG_LAZYLOAD)
5427 printf (" LAZYLOAD");
5435 #ifdef SUPPORT_DISASSEMBLY
5437 disassemble_section (section, file)
5438 Elf32_Internal_Shdr * section;
5441 printf (_("\nAssembly dump of section %s\n"),
5442 SECTION_NAME (section));
5444 /* XXX -- to be done --- XXX */
5451 dump_section (section, file)
5452 Elf32_Internal_Shdr * section;
5455 bfd_size_type bytes;
5457 unsigned char * data;
5458 unsigned char * start;
5460 bytes = section->sh_size;
5464 printf (_("\nSection '%s' has no data to dump.\n"),
5465 SECTION_NAME (section));
5469 printf (_("\nHex dump of section '%s':\n"), SECTION_NAME (section));
5471 addr = section->sh_addr;
5473 start = (unsigned char *) get_data (NULL, file, section->sh_offset, bytes,
5486 lbytes = (bytes > 16 ? 16 : bytes);
5488 printf (" 0x%8.8lx ", (unsigned long) addr);
5490 switch (elf_header.e_ident [EI_DATA])
5494 for (j = 15; j >= 0; j --)
5497 printf ("%2.2x", data [j]);
5507 for (j = 0; j < 16; j++)
5510 printf ("%2.2x", data [j]);
5520 for (j = 0; j < lbytes; j++)
5523 if (k >= ' ' && k < 0x80)
5542 static unsigned long int
5543 read_leb128 (data, length_return, sign)
5544 unsigned char * data;
5545 int * length_return;
5548 unsigned long int result = 0;
5549 unsigned int num_read = 0;
5558 result |= (byte & 0x7f) << shift;
5563 while (byte & 0x80);
5565 if (length_return != NULL)
5566 * length_return = num_read;
5568 if (sign && (shift < 32) && (byte & 0x40))
5569 result |= -1 << shift;
5574 typedef struct State_Machine_Registers
5576 unsigned long address;
5579 unsigned int column;
5583 /* This variable hold the number of the last entry seen
5584 in the File Table. */
5585 unsigned int last_file_entry;
5588 static SMR state_machine_regs;
5591 reset_state_machine (is_stmt)
5594 state_machine_regs.address = 0;
5595 state_machine_regs.file = 1;
5596 state_machine_regs.line = 1;
5597 state_machine_regs.column = 0;
5598 state_machine_regs.is_stmt = is_stmt;
5599 state_machine_regs.basic_block = 0;
5600 state_machine_regs.end_sequence = 0;
5601 state_machine_regs.last_file_entry = 0;
5604 /* Handled an extend line op. Returns true if this is the end
5607 process_extended_line_op (data, is_stmt, pointer_size)
5608 unsigned char * data;
5612 unsigned char op_code;
5615 unsigned char * name;
5618 len = read_leb128 (data, & bytes_read, 0);
5623 warn (_("badly formed extended line op encountered!"));
5628 op_code = * data ++;
5630 printf (_(" Extended opcode %d: "), op_code);
5634 case DW_LNE_end_sequence:
5635 printf (_("End of Sequence\n\n"));
5636 reset_state_machine (is_stmt);
5639 case DW_LNE_set_address:
5640 adr = byte_get (data, pointer_size);
5641 printf (_("set Address to 0x%lx\n"), adr);
5642 state_machine_regs.address = adr;
5645 case DW_LNE_define_file:
5646 printf (_(" define new File Table entry\n"));
5647 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
5649 printf (_(" %d\t"), ++ state_machine_regs.last_file_entry);
5651 data += strlen ((char *) data) + 1;
5652 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
5654 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
5656 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
5657 printf (_("%s\n\n"), name);
5661 printf (_("UNKNOWN: length %d\n"), len - bytes_read);
5668 /* Size of pointers in the .debug_line section. This information is not
5669 really present in that section. It's obtained before dumping the debug
5670 sections by doing some pre-scan of the .debug_info section. */
5671 static int debug_line_pointer_size = 4;
5674 display_debug_lines (section, start, file)
5675 Elf32_Internal_Shdr * section;
5676 unsigned char * start;
5677 FILE * file ATTRIBUTE_UNUSED;
5679 DWARF2_External_LineInfo * external;
5680 DWARF2_Internal_LineInfo info;
5681 unsigned char * standard_opcodes;
5682 unsigned char * data = start;
5683 unsigned char * end = start + section->sh_size;
5684 unsigned char * end_of_sequence;
5687 printf (_("\nDump of debug contents of section %s:\n\n"),
5688 SECTION_NAME (section));
5692 external = (DWARF2_External_LineInfo *) data;
5694 /* Check the length of the block. */
5695 info.li_length = BYTE_GET (external->li_length);
5696 if (info.li_length + sizeof (external->li_length) > section->sh_size)
5699 (_("The line info appears to be corrupt - the section is too small\n"));
5703 /* Check its version number. */
5704 info.li_version = BYTE_GET (external->li_version);
5705 if (info.li_version != 2)
5707 warn (_("Only DWARF version 2 line info is currently supported.\n"));
5711 info.li_prologue_length = BYTE_GET (external->li_prologue_length);
5712 info.li_min_insn_length = BYTE_GET (external->li_min_insn_length);
5713 info.li_default_is_stmt = BYTE_GET (external->li_default_is_stmt);
5714 info.li_line_base = BYTE_GET (external->li_line_base);
5715 info.li_line_range = BYTE_GET (external->li_line_range);
5716 info.li_opcode_base = BYTE_GET (external->li_opcode_base);
5718 /* Sign extend the line base field. */
5719 info.li_line_base <<= 24;
5720 info.li_line_base >>= 24;
5722 printf (_(" Length: %ld\n"), info.li_length);
5723 printf (_(" DWARF Version: %d\n"), info.li_version);
5724 printf (_(" Prologue Length: %d\n"), info.li_prologue_length);
5725 printf (_(" Minimum Instruction Length: %d\n"), info.li_min_insn_length);
5726 printf (_(" Initial value of 'is_stmt': %d\n"), info.li_default_is_stmt);
5727 printf (_(" Line Base: %d\n"), info.li_line_base);
5728 printf (_(" Line Range: %d\n"), info.li_line_range);
5729 printf (_(" Opcode Base: %d\n"), info.li_opcode_base);
5731 end_of_sequence = data + info.li_length + sizeof (external->li_length);
5733 reset_state_machine (info.li_default_is_stmt);
5735 /* Display the contents of the Opcodes table. */
5736 standard_opcodes = data + sizeof (* external);
5738 printf (_("\n Opcodes:\n"));
5740 for (i = 1; i < info.li_opcode_base; i++)
5741 printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]);
5743 /* Display the contents of the Directory table. */
5744 data = standard_opcodes + info.li_opcode_base - 1;
5747 printf (_("\n The Directory Table is empty.\n"));
5750 printf (_("\n The Directory Table:\n"));
5754 printf (_(" %s\n"), data);
5756 data += strlen ((char *) data) + 1;
5760 /* Skip the NUL at the end of the table. */
5763 /* Display the contents of the File Name table. */
5765 printf (_("\n The File Name Table is empty.\n"));
5768 printf (_("\n The File Name Table:\n"));
5769 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
5773 unsigned char * name;
5776 printf (_(" %d\t"), ++ state_machine_regs.last_file_entry);
5779 data += strlen ((char *) data) + 1;
5781 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
5783 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
5785 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
5787 printf (_("%s\n"), name);
5791 /* Skip the NUL at the end of the table. */
5794 /* Now display the statements. */
5795 printf (_("\n Line Number Statements:\n"));
5798 while (data < end_of_sequence)
5800 unsigned char op_code;
5804 op_code = * data ++;
5808 case DW_LNS_extended_op:
5809 data += process_extended_line_op (data, info.li_default_is_stmt,
5810 debug_line_pointer_size);
5814 printf (_(" Copy\n"));
5817 case DW_LNS_advance_pc:
5818 adv = info.li_min_insn_length * read_leb128 (data, & bytes_read, 0);
5820 state_machine_regs.address += adv;
5821 printf (_(" Advance PC by %d to %lx\n"), adv,
5822 state_machine_regs.address);
5825 case DW_LNS_advance_line:
5826 adv = read_leb128 (data, & bytes_read, 1);
5828 state_machine_regs.line += adv;
5829 printf (_(" Advance Line by %d to %d\n"), adv,
5830 state_machine_regs.line);
5833 case DW_LNS_set_file:
5834 adv = read_leb128 (data, & bytes_read, 0);
5836 printf (_(" Set File Name to entry %d in the File Name Table\n"),
5838 state_machine_regs.file = adv;
5841 case DW_LNS_set_column:
5842 adv = read_leb128 (data, & bytes_read, 0);
5844 printf (_(" Set column to %d\n"), adv);
5845 state_machine_regs.column = adv;
5848 case DW_LNS_negate_stmt:
5849 adv = state_machine_regs.is_stmt;
5851 printf (_(" Set is_stmt to %d\n"), adv);
5852 state_machine_regs.is_stmt = adv;
5855 case DW_LNS_set_basic_block:
5856 printf (_(" Set basic block\n"));
5857 state_machine_regs.basic_block = 1;
5860 case DW_LNS_const_add_pc:
5861 adv = (((255 - info.li_opcode_base) / info.li_line_range)
5862 * info.li_min_insn_length);
5863 state_machine_regs.address += adv;
5864 printf (_(" Advance PC by constant %d to 0x%lx\n"), adv,
5865 state_machine_regs.address);
5868 case DW_LNS_fixed_advance_pc:
5869 adv = byte_get (data, 2);
5871 state_machine_regs.address += adv;
5872 printf (_(" Advance PC by fixed size amount %d to 0x%lx\n"),
5873 adv, state_machine_regs.address);
5877 op_code -= info.li_opcode_base;
5878 adv = (op_code / info.li_line_range) * info.li_min_insn_length;
5879 state_machine_regs.address += adv;
5880 printf (_(" Special opcode %d: advance Address by %d to 0x%lx"),
5881 op_code, adv, state_machine_regs.address);
5882 adv = (op_code % info.li_line_range) + info.li_line_base;
5883 state_machine_regs.line += adv;
5884 printf (_(" and Line by %d to %d\n"),
5885 adv, state_machine_regs.line);
5896 display_debug_pubnames (section, start, file)
5897 Elf32_Internal_Shdr * section;
5898 unsigned char * start;
5899 FILE * file ATTRIBUTE_UNUSED;
5901 DWARF2_External_PubNames * external;
5902 DWARF2_Internal_PubNames pubnames;
5903 unsigned char * end;
5905 end = start + section->sh_size;
5907 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section));
5911 unsigned char * data;
5912 unsigned long offset;
5914 external = (DWARF2_External_PubNames *) start;
5916 pubnames.pn_length = BYTE_GET (external->pn_length);
5917 pubnames.pn_version = BYTE_GET (external->pn_version);
5918 pubnames.pn_offset = BYTE_GET (external->pn_offset);
5919 pubnames.pn_size = BYTE_GET (external->pn_size);
5921 data = start + sizeof (* external);
5922 start += pubnames.pn_length + sizeof (external->pn_length);
5924 if (pubnames.pn_version != 2)
5926 static int warned = 0;
5930 warn (_("Only DWARF 2 pubnames are currently supported\n"));
5937 printf (_(" Length: %ld\n"),
5938 pubnames.pn_length);
5939 printf (_(" Version: %d\n"),
5940 pubnames.pn_version);
5941 printf (_(" Offset into .debug_info section: %ld\n"),
5942 pubnames.pn_offset);
5943 printf (_(" Size of area in .debug_info section: %ld\n"),
5946 printf (_("\n Offset\tName\n"));
5950 offset = byte_get (data, 4);
5955 printf (" %ld\t\t%s\n", offset, data);
5956 data += strlen ((char *) data) + 1;
5959 while (offset != 0);
5972 case DW_TAG_padding: return "DW_TAG_padding";
5973 case DW_TAG_array_type: return "DW_TAG_array_type";
5974 case DW_TAG_class_type: return "DW_TAG_class_type";
5975 case DW_TAG_entry_point: return "DW_TAG_entry_point";
5976 case DW_TAG_enumeration_type: return "DW_TAG_enumeration_type";
5977 case DW_TAG_formal_parameter: return "DW_TAG_formal_parameter";
5978 case DW_TAG_imported_declaration: return "DW_TAG_imported_declaration";
5979 case DW_TAG_label: return "DW_TAG_label";
5980 case DW_TAG_lexical_block: return "DW_TAG_lexical_block";
5981 case DW_TAG_member: return "DW_TAG_member";
5982 case DW_TAG_pointer_type: return "DW_TAG_pointer_type";
5983 case DW_TAG_reference_type: return "DW_TAG_reference_type";
5984 case DW_TAG_compile_unit: return "DW_TAG_compile_unit";
5985 case DW_TAG_string_type: return "DW_TAG_string_type";
5986 case DW_TAG_structure_type: return "DW_TAG_structure_type";
5987 case DW_TAG_subroutine_type: return "DW_TAG_subroutine_type";
5988 case DW_TAG_typedef: return "DW_TAG_typedef";
5989 case DW_TAG_union_type: return "DW_TAG_union_type";
5990 case DW_TAG_unspecified_parameters: return "DW_TAG_unspecified_parameters";
5991 case DW_TAG_variant: return "DW_TAG_variant";
5992 case DW_TAG_common_block: return "DW_TAG_common_block";
5993 case DW_TAG_common_inclusion: return "DW_TAG_common_inclusion";
5994 case DW_TAG_inheritance: return "DW_TAG_inheritance";
5995 case DW_TAG_inlined_subroutine: return "DW_TAG_inlined_subroutine";
5996 case DW_TAG_module: return "DW_TAG_module";
5997 case DW_TAG_ptr_to_member_type: return "DW_TAG_ptr_to_member_type";
5998 case DW_TAG_set_type: return "DW_TAG_set_type";
5999 case DW_TAG_subrange_type: return "DW_TAG_subrange_type";
6000 case DW_TAG_with_stmt: return "DW_TAG_with_stmt";
6001 case DW_TAG_access_declaration: return "DW_TAG_access_declaration";
6002 case DW_TAG_base_type: return "DW_TAG_base_type";
6003 case DW_TAG_catch_block: return "DW_TAG_catch_block";
6004 case DW_TAG_const_type: return "DW_TAG_const_type";
6005 case DW_TAG_constant: return "DW_TAG_constant";
6006 case DW_TAG_enumerator: return "DW_TAG_enumerator";
6007 case DW_TAG_file_type: return "DW_TAG_file_type";
6008 case DW_TAG_friend: return "DW_TAG_friend";
6009 case DW_TAG_namelist: return "DW_TAG_namelist";
6010 case DW_TAG_namelist_item: return "DW_TAG_namelist_item";
6011 case DW_TAG_packed_type: return "DW_TAG_packed_type";
6012 case DW_TAG_subprogram: return "DW_TAG_subprogram";
6013 case DW_TAG_template_type_param: return "DW_TAG_template_type_param";
6014 case DW_TAG_template_value_param: return "DW_TAG_template_value_param";
6015 case DW_TAG_thrown_type: return "DW_TAG_thrown_type";
6016 case DW_TAG_try_block: return "DW_TAG_try_block";
6017 case DW_TAG_variant_part: return "DW_TAG_variant_part";
6018 case DW_TAG_variable: return "DW_TAG_variable";
6019 case DW_TAG_volatile_type: return "DW_TAG_volatile_type";
6020 case DW_TAG_MIPS_loop: return "DW_TAG_MIPS_loop";
6021 case DW_TAG_format_label: return "DW_TAG_format_label";
6022 case DW_TAG_function_template: return "DW_TAG_function_template";
6023 case DW_TAG_class_template: return "DW_TAG_class_template";
6024 /* DWARF 2.1 values. */
6025 case DW_TAG_dwarf_procedure: return "DW_TAG_dwarf_procedure";
6026 case DW_TAG_restrict_type: return "DW_TAG_restrict_type";
6027 case DW_TAG_interface_type: return "DW_TAG_interface_type";
6028 case DW_TAG_namespace: return "DW_TAG_namespace";
6029 case DW_TAG_imported_module: return "DW_TAG_imported_module";
6030 case DW_TAG_unspecified_type: return "DW_TAG_unspecified_type";
6031 case DW_TAG_partial_unit: return "DW_TAG_partial_unit";
6032 case DW_TAG_imported_unit: return "DW_TAG_imported_unit";
6035 static char buffer [100];
6037 sprintf (buffer, _("Unknown TAG value: %lx"), tag);
6044 get_AT_name (attribute)
6045 unsigned long attribute;
6049 case DW_AT_sibling: return "DW_AT_sibling";
6050 case DW_AT_location: return "DW_AT_location";
6051 case DW_AT_name: return "DW_AT_name";
6052 case DW_AT_ordering: return "DW_AT_ordering";
6053 case DW_AT_subscr_data: return "DW_AT_subscr_data";
6054 case DW_AT_byte_size: return "DW_AT_byte_size";
6055 case DW_AT_bit_offset: return "DW_AT_bit_offset";
6056 case DW_AT_bit_size: return "DW_AT_bit_size";
6057 case DW_AT_element_list: return "DW_AT_element_list";
6058 case DW_AT_stmt_list: return "DW_AT_stmt_list";
6059 case DW_AT_low_pc: return "DW_AT_low_pc";
6060 case DW_AT_high_pc: return "DW_AT_high_pc";
6061 case DW_AT_language: return "DW_AT_language";
6062 case DW_AT_member: return "DW_AT_member";
6063 case DW_AT_discr: return "DW_AT_discr";
6064 case DW_AT_discr_value: return "DW_AT_discr_value";
6065 case DW_AT_visibility: return "DW_AT_visibility";
6066 case DW_AT_import: return "DW_AT_import";
6067 case DW_AT_string_length: return "DW_AT_string_length";
6068 case DW_AT_common_reference: return "DW_AT_common_reference";
6069 case DW_AT_comp_dir: return "DW_AT_comp_dir";
6070 case DW_AT_const_value: return "DW_AT_const_value";
6071 case DW_AT_containing_type: return "DW_AT_containing_type";
6072 case DW_AT_default_value: return "DW_AT_default_value";
6073 case DW_AT_inline: return "DW_AT_inline";
6074 case DW_AT_is_optional: return "DW_AT_is_optional";
6075 case DW_AT_lower_bound: return "DW_AT_lower_bound";
6076 case DW_AT_producer: return "DW_AT_producer";
6077 case DW_AT_prototyped: return "DW_AT_prototyped";
6078 case DW_AT_return_addr: return "DW_AT_return_addr";
6079 case DW_AT_start_scope: return "DW_AT_start_scope";
6080 case DW_AT_stride_size: return "DW_AT_stride_size";
6081 case DW_AT_upper_bound: return "DW_AT_upper_bound";
6082 case DW_AT_abstract_origin: return "DW_AT_abstract_origin";
6083 case DW_AT_accessibility: return "DW_AT_accessibility";
6084 case DW_AT_address_class: return "DW_AT_address_class";
6085 case DW_AT_artificial: return "DW_AT_artificial";
6086 case DW_AT_base_types: return "DW_AT_base_types";
6087 case DW_AT_calling_convention: return "DW_AT_calling_convention";
6088 case DW_AT_count: return "DW_AT_count";
6089 case DW_AT_data_member_location: return "DW_AT_data_member_location";
6090 case DW_AT_decl_column: return "DW_AT_decl_column";
6091 case DW_AT_decl_file: return "DW_AT_decl_file";
6092 case DW_AT_decl_line: return "DW_AT_decl_line";
6093 case DW_AT_declaration: return "DW_AT_declaration";
6094 case DW_AT_discr_list: return "DW_AT_discr_list";
6095 case DW_AT_encoding: return "DW_AT_encoding";
6096 case DW_AT_external: return "DW_AT_external";
6097 case DW_AT_frame_base: return "DW_AT_frame_base";
6098 case DW_AT_friend: return "DW_AT_friend";
6099 case DW_AT_identifier_case: return "DW_AT_identifier_case";
6100 case DW_AT_macro_info: return "DW_AT_macro_info";
6101 case DW_AT_namelist_items: return "DW_AT_namelist_items";
6102 case DW_AT_priority: return "DW_AT_priority";
6103 case DW_AT_segment: return "DW_AT_segment";
6104 case DW_AT_specification: return "DW_AT_specification";
6105 case DW_AT_static_link: return "DW_AT_static_link";
6106 case DW_AT_type: return "DW_AT_type";
6107 case DW_AT_use_location: return "DW_AT_use_location";
6108 case DW_AT_variable_parameter: return "DW_AT_variable_parameter";
6109 case DW_AT_virtuality: return "DW_AT_virtuality";
6110 case DW_AT_vtable_elem_location: return "DW_AT_vtable_elem_location";
6111 /* DWARF 2.1 values. */
6112 case DW_AT_allocated: return "DW_AT_allocated";
6113 case DW_AT_associated: return "DW_AT_associated";
6114 case DW_AT_data_location: return "DW_AT_data_location";
6115 case DW_AT_stride: return "DW_AT_stride";
6116 case DW_AT_entry_pc: return "DW_AT_entry_pc";
6117 case DW_AT_use_UTF8: return "DW_AT_use_UTF8";
6118 case DW_AT_extension: return "DW_AT_extension";
6119 case DW_AT_ranges: return "DW_AT_ranges";
6120 case DW_AT_trampoline: return "DW_AT_trampoline";
6121 case DW_AT_call_column: return "DW_AT_call_column";
6122 case DW_AT_call_file: return "DW_AT_call_file";
6123 case DW_AT_call_line: return "DW_AT_call_line";
6124 /* SGI/MIPS extensions. */
6125 case DW_AT_MIPS_fde: return "DW_AT_MIPS_fde";
6126 case DW_AT_MIPS_loop_begin: return "DW_AT_MIPS_loop_begin";
6127 case DW_AT_MIPS_tail_loop_begin: return "DW_AT_MIPS_tail_loop_begin";
6128 case DW_AT_MIPS_epilog_begin: return "DW_AT_MIPS_epilog_begin";
6129 case DW_AT_MIPS_loop_unroll_factor: return "DW_AT_MIPS_loop_unroll_factor";
6130 case DW_AT_MIPS_software_pipeline_depth: return "DW_AT_MIPS_software_pipeline_depth";
6131 case DW_AT_MIPS_linkage_name: return "DW_AT_MIPS_linkage_name";
6132 case DW_AT_MIPS_stride: return "DW_AT_MIPS_stride";
6133 case DW_AT_MIPS_abstract_name: return "DW_AT_MIPS_abstract_name";
6134 case DW_AT_MIPS_clone_origin: return "DW_AT_MIPS_clone_origin";
6135 case DW_AT_MIPS_has_inlines: return "DW_AT_MIPS_has_inlines";
6136 /* GNU extensions. */
6137 case DW_AT_sf_names: return "DW_AT_sf_names";
6138 case DW_AT_src_info: return "DW_AT_src_info";
6139 case DW_AT_mac_info: return "DW_AT_mac_info";
6140 case DW_AT_src_coords: return "DW_AT_src_coords";
6141 case DW_AT_body_begin: return "DW_AT_body_begin";
6142 case DW_AT_body_end: return "DW_AT_body_end";
6145 static char buffer [100];
6147 sprintf (buffer, _("Unknown AT value: %lx"), attribute);
6154 get_FORM_name (form)
6159 case DW_FORM_addr: return "DW_FORM_addr";
6160 case DW_FORM_block2: return "DW_FORM_block2";
6161 case DW_FORM_block4: return "DW_FORM_block4";
6162 case DW_FORM_data2: return "DW_FORM_data2";
6163 case DW_FORM_data4: return "DW_FORM_data4";
6164 case DW_FORM_data8: return "DW_FORM_data8";
6165 case DW_FORM_string: return "DW_FORM_string";
6166 case DW_FORM_block: return "DW_FORM_block";
6167 case DW_FORM_block1: return "DW_FORM_block1";
6168 case DW_FORM_data1: return "DW_FORM_data1";
6169 case DW_FORM_flag: return "DW_FORM_flag";
6170 case DW_FORM_sdata: return "DW_FORM_sdata";
6171 case DW_FORM_strp: return "DW_FORM_strp";
6172 case DW_FORM_udata: return "DW_FORM_udata";
6173 case DW_FORM_ref_addr: return "DW_FORM_ref_addr";
6174 case DW_FORM_ref1: return "DW_FORM_ref1";
6175 case DW_FORM_ref2: return "DW_FORM_ref2";
6176 case DW_FORM_ref4: return "DW_FORM_ref4";
6177 case DW_FORM_ref8: return "DW_FORM_ref8";
6178 case DW_FORM_ref_udata: return "DW_FORM_ref_udata";
6179 case DW_FORM_indirect: return "DW_FORM_indirect";
6182 static char buffer [100];
6184 sprintf (buffer, _("Unknown FORM value: %lx"), form);
6190 /* FIXME: There are better and more effiecint ways to handle
6191 these structures. For now though, I just want something that
6192 is simple to implement. */
6193 typedef struct abbrev_attr
6195 unsigned long attribute;
6197 struct abbrev_attr * next;
6201 typedef struct abbrev_entry
6203 unsigned long entry;
6206 struct abbrev_attr * first_attr;
6207 struct abbrev_attr * last_attr;
6208 struct abbrev_entry * next;
6212 static abbrev_entry * first_abbrev = NULL;
6213 static abbrev_entry * last_abbrev = NULL;
6216 free_abbrevs PARAMS ((void))
6218 abbrev_entry * abbrev;
6220 for (abbrev = first_abbrev; abbrev;)
6222 abbrev_entry * next = abbrev->next;
6225 for (attr = abbrev->first_attr; attr;)
6227 abbrev_attr * next = attr->next;
6237 last_abbrev = first_abbrev = NULL;
6241 add_abbrev (number, tag, children)
6242 unsigned long number;
6246 abbrev_entry * entry;
6248 entry = (abbrev_entry *) malloc (sizeof (* entry));
6254 entry->entry = number;
6256 entry->children = children;
6257 entry->first_attr = NULL;
6258 entry->last_attr = NULL;
6261 if (first_abbrev == NULL)
6262 first_abbrev = entry;
6264 last_abbrev->next = entry;
6266 last_abbrev = entry;
6270 add_abbrev_attr (attribute, form)
6271 unsigned long attribute;
6276 attr = (abbrev_attr *) malloc (sizeof (* attr));
6282 attr->attribute = attribute;
6286 if (last_abbrev->first_attr == NULL)
6287 last_abbrev->first_attr = attr;
6289 last_abbrev->last_attr->next = attr;
6291 last_abbrev->last_attr = attr;
6294 /* Processes the (partial) contents of a .debug_abbrev section.
6295 Returns NULL if the end of the section was encountered.
6296 Returns the address after the last byte read if the end of
6297 an abbreviation set was found. */
6299 static unsigned char *
6300 process_abbrev_section (start, end)
6301 unsigned char * start;
6302 unsigned char * end;
6304 if (first_abbrev != NULL)
6310 unsigned long entry;
6312 unsigned long attribute;
6315 entry = read_leb128 (start, & bytes_read, 0);
6316 start += bytes_read;
6318 /* A single zero is supposed to end the section according
6319 to the standard. If there's more, then signal that to
6322 return start == end ? NULL : start;
6324 tag = read_leb128 (start, & bytes_read, 0);
6325 start += bytes_read;
6327 children = * start ++;
6329 add_abbrev (entry, tag, children);
6335 attribute = read_leb128 (start, & bytes_read, 0);
6336 start += bytes_read;
6338 form = read_leb128 (start, & bytes_read, 0);
6339 start += bytes_read;
6342 add_abbrev_attr (attribute, form);
6344 while (attribute != 0);
6352 display_debug_macinfo (section, start, file)
6353 Elf32_Internal_Shdr * section;
6354 unsigned char * start;
6355 FILE * file ATTRIBUTE_UNUSED;
6357 unsigned char * end = start + section->sh_size;
6358 unsigned char * curr = start;
6359 unsigned int bytes_read;
6360 enum dwarf_macinfo_record_type op;
6362 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section));
6366 unsigned int lineno;
6367 const char * string;
6374 case DW_MACINFO_start_file:
6376 unsigned int filenum;
6378 lineno = read_leb128 (curr, & bytes_read, 0);
6380 filenum = read_leb128 (curr, & bytes_read, 0);
6383 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"), lineno, filenum);
6387 case DW_MACINFO_end_file:
6388 printf (_(" DW_MACINFO_end_file\n"));
6391 case DW_MACINFO_define:
6392 lineno = read_leb128 (curr, & bytes_read, 0);
6395 curr += strlen (string) + 1;
6396 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"), lineno, string);
6399 case DW_MACINFO_undef:
6400 lineno = read_leb128 (curr, & bytes_read, 0);
6403 curr += strlen (string) + 1;
6404 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"), lineno, string);
6407 case DW_MACINFO_vendor_ext:
6409 unsigned int constant;
6411 constant = read_leb128 (curr, & bytes_read, 0);
6414 curr += strlen (string) + 1;
6415 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"), constant, string);
6426 display_debug_abbrev (section, start, file)
6427 Elf32_Internal_Shdr * section;
6428 unsigned char * start;
6429 FILE * file ATTRIBUTE_UNUSED;
6431 abbrev_entry * entry;
6432 unsigned char * end = start + section->sh_size;
6434 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section));
6438 start = process_abbrev_section (start, end);
6440 printf (_(" Number TAG\n"));
6442 for (entry = first_abbrev; entry; entry = entry->next)
6446 printf (_(" %ld %s [%s]\n"),
6448 get_TAG_name (entry->tag),
6449 entry->children ? _("has children") : _("no children"));
6451 for (attr = entry->first_attr; attr; attr = attr->next)
6453 printf (_(" %-18s %s\n"),
6454 get_AT_name (attr->attribute),
6455 get_FORM_name (attr->form));
6467 static unsigned char *
6468 display_block (data, length)
6469 unsigned char * data;
6470 unsigned long length;
6472 printf (_(" %lu byte block: "), length);
6475 printf ("%lx ", (unsigned long) byte_get (data ++, 1));
6481 decode_location_expression (data, pointer_size, length)
6482 unsigned char * data;
6483 unsigned int pointer_size;
6484 unsigned long length;
6488 unsigned long uvalue;
6489 unsigned char * end = data + length;
6498 printf ("DW_OP_addr: %lx",
6499 (unsigned long) byte_get (data, pointer_size));
6500 data += pointer_size;
6503 printf ("DW_OP_deref");
6506 printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data++, 1));
6509 printf ("DW_OP_const1s: %ld", (long) byte_get (data++, 1));
6512 printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data, 2));
6516 printf ("DW_OP_const2s: %ld", (long) byte_get (data, 2));
6520 printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data, 4));
6524 printf ("DW_OP_const4s: %ld", (long) byte_get (data, 4));
6528 printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data, 4),
6529 (unsigned long) byte_get (data + 4, 4));
6533 printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data, 4),
6534 (long) byte_get (data + 4, 4));
6538 printf ("DW_OP_constu: %lu", read_leb128 (data, &bytes_read, 0));
6542 printf ("DW_OP_consts: %ld", read_leb128 (data, &bytes_read, 1));
6546 printf ("DW_OP_dup");
6549 printf ("DW_OP_drop");
6552 printf ("DW_OP_over");
6555 printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data++, 1));
6558 printf ("DW_OP_swap");
6561 printf ("DW_OP_rot");
6564 printf ("DW_OP_xderef");
6567 printf ("DW_OP_abs");
6570 printf ("DW_OP_and");
6573 printf ("DW_OP_div");
6576 printf ("DW_OP_minus");
6579 printf ("DW_OP_mod");
6582 printf ("DW_OP_mul");
6585 printf ("DW_OP_neg");
6588 printf ("DW_OP_not");
6591 printf ("DW_OP_or");
6594 printf ("DW_OP_plus");
6596 case DW_OP_plus_uconst:
6597 printf ("DW_OP_plus_uconst: %lu",
6598 read_leb128 (data, &bytes_read, 0));
6602 printf ("DW_OP_shl");
6605 printf ("DW_OP_shr");
6608 printf ("DW_OP_shra");
6611 printf ("DW_OP_xor");
6614 printf ("DW_OP_bra: %ld", (long) byte_get (data, 2));
6618 printf ("DW_OP_eq");
6621 printf ("DW_OP_ge");
6624 printf ("DW_OP_gt");
6627 printf ("DW_OP_le");
6630 printf ("DW_OP_lt");
6633 printf ("DW_OP_ne");
6636 printf ("DW_OP_skip: %ld", (long) byte_get (data, 2));
6672 printf ("DW_OP_lit%d", op - DW_OP_lit0);
6707 printf ("DW_OP_reg%d", op - DW_OP_reg0);
6742 printf ("DW_OP_breg%d: %ld", op - DW_OP_breg0,
6743 read_leb128 (data, &bytes_read, 1));
6748 printf ("DW_OP_regx: %lu", read_leb128 (data, &bytes_read, 0));
6752 printf ("DW_OP_fbreg: %ld", read_leb128 (data, &bytes_read, 1));
6756 uvalue = read_leb128 (data, &bytes_read, 0);
6758 printf ("DW_OP_bregx: %lu %ld", uvalue,
6759 read_leb128 (data, &bytes_read, 1));
6763 printf ("DW_OP_piece: %lu", read_leb128 (data, &bytes_read, 0));
6766 case DW_OP_deref_size:
6767 printf ("DW_OP_deref_size: %ld", (long) byte_get (data++, 1));
6769 case DW_OP_xderef_size:
6770 printf ("DW_OP_xderef_size: %ld", (long) byte_get (data++, 1));
6773 printf ("DW_OP_nop");
6776 /* DWARF 2.1 extensions. */
6777 case DW_OP_push_object_address:
6778 printf ("DW_OP_push_object_address");
6781 printf ("DW_OP_call2: <%lx>", (long) byte_get (data, 2));
6785 printf ("DW_OP_call4: <%lx>", (long) byte_get (data, 4));
6789 printf ("DW_OP_calli");
6793 if (op >= DW_OP_lo_user
6794 && op <= DW_OP_hi_user)
6795 printf (_("(User defined location op)"));
6797 printf (_("(Unknown location op)"));
6798 /* No way to tell where the next op is, so just bail. */
6802 /* Separate the ops. */
6808 static unsigned char *
6809 read_and_display_attr (attribute, form, data, cu_offset, pointer_size)
6810 unsigned long attribute;
6812 unsigned char * data;
6813 unsigned long cu_offset;
6814 unsigned long pointer_size;
6816 unsigned long uvalue = 0;
6817 unsigned char * block_start = NULL;
6820 printf (" %-18s:", get_AT_name (attribute));
6827 case DW_FORM_ref_addr:
6829 uvalue = byte_get (data, pointer_size);
6830 data += pointer_size;
6836 uvalue = byte_get (data ++, 1);
6841 uvalue = byte_get (data, 2);
6847 uvalue = byte_get (data, 4);
6852 uvalue = read_leb128 (data, & bytes_read, 1);
6856 case DW_FORM_ref_udata:
6858 uvalue = read_leb128 (data, & bytes_read, 0);
6865 case DW_FORM_ref_addr:
6866 printf (" <#%lx>", uvalue);
6872 case DW_FORM_ref_udata:
6873 printf (" <%lx>", uvalue + cu_offset);
6877 printf (" %#lx", uvalue);
6885 printf (" %ld", uvalue);
6890 uvalue = byte_get (data, 4);
6891 printf (" %lx", uvalue);
6892 printf (" %lx", (unsigned long) byte_get (data + 4, 4));
6896 case DW_FORM_string:
6897 printf (" %s", data);
6898 data += strlen ((char *) data) + 1;
6902 uvalue = read_leb128 (data, & bytes_read, 0);
6903 block_start = data + bytes_read;
6904 data = display_block (block_start, uvalue);
6907 case DW_FORM_block1:
6908 uvalue = byte_get (data, 1);
6909 block_start = data + 1;
6910 data = display_block (block_start, uvalue);
6913 case DW_FORM_block2:
6914 uvalue = byte_get (data, 2);
6915 block_start = data + 2;
6916 data = display_block (block_start, uvalue);
6919 case DW_FORM_block4:
6920 uvalue = byte_get (data, 4);
6921 block_start = data + 4;
6922 data = display_block (block_start, uvalue);
6926 case DW_FORM_indirect:
6927 warn (_("Unable to handle FORM: %d"), form);
6931 warn (_("Unrecognised form: %d"), form);
6935 /* For some attributes we can display futher information. */
6944 case DW_INL_not_inlined: printf (_("(not inlined)")); break;
6945 case DW_INL_inlined: printf (_("(inlined)")); break;
6946 case DW_INL_declared_not_inlined: printf (_("(declared as inline but ignored)")); break;
6947 case DW_INL_declared_inlined: printf (_("(declared as inline and inlined)")); break;
6948 default: printf (_(" (Unknown inline attribute value: %lx)"), uvalue); break;
6952 case DW_AT_language:
6955 case DW_LANG_C: printf ("(non-ANSI C)"); break;
6956 case DW_LANG_C89: printf ("(ANSI C)"); break;
6957 case DW_LANG_C_plus_plus: printf ("(C++)"); break;
6958 case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break;
6959 case DW_LANG_Fortran90: printf ("(Fortran 90)"); break;
6960 case DW_LANG_Modula2: printf ("(Modula 2)"); break;
6961 case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break;
6962 case DW_LANG_Ada83: printf ("(Ada)"); break;
6963 case DW_LANG_Cobol74: printf ("(Cobol 74)"); break;
6964 case DW_LANG_Cobol85: printf ("(Cobol 85)"); break;
6965 /* DWARF 2.1 values. */
6966 case DW_LANG_C99: printf ("(ANSI C99)"); break;
6967 case DW_LANG_Ada95: printf ("(ADA 95)"); break;
6968 case DW_LANG_Fortran95: printf ("(Fortran 95)"); break;
6969 /* MIPS extension. */
6970 case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break;
6971 default: printf ("(Unknown: %lx)", uvalue); break;
6975 case DW_AT_encoding:
6978 case DW_ATE_void: printf ("(void)"); break;
6979 case DW_ATE_address: printf ("(machine address)"); break;
6980 case DW_ATE_boolean: printf ("(boolean)"); break;
6981 case DW_ATE_complex_float: printf ("(complex float)"); break;
6982 case DW_ATE_float: printf ("(float)"); break;
6983 case DW_ATE_signed: printf ("(signed)"); break;
6984 case DW_ATE_signed_char: printf ("(signed char)"); break;
6985 case DW_ATE_unsigned: printf ("(unsigned)"); break;
6986 case DW_ATE_unsigned_char: printf ("(unsigned char)"); break;
6987 /* DWARF 2.1 value. */
6988 case DW_ATE_imaginary_float: printf ("(imaginary float)"); break;
6990 if (uvalue >= DW_ATE_lo_user
6991 && uvalue <= DW_ATE_hi_user)
6992 printf ("(user defined type)");
6994 printf ("(unknown type)");
6999 case DW_AT_accessibility:
7002 case DW_ACCESS_public: printf ("(public)"); break;
7003 case DW_ACCESS_protected: printf ("(protected)"); break;
7004 case DW_ACCESS_private: printf ("(private)"); break;
7005 default: printf ("(unknown accessibility)"); break;
7009 case DW_AT_visibility:
7012 case DW_VIS_local: printf ("(local)"); break;
7013 case DW_VIS_exported: printf ("(exported)"); break;
7014 case DW_VIS_qualified: printf ("(qualified)"); break;
7015 default: printf ("(unknown visibility)"); break;
7019 case DW_AT_virtuality:
7022 case DW_VIRTUALITY_none: printf ("(none)"); break;
7023 case DW_VIRTUALITY_virtual: printf ("(virtual)"); break;
7024 case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break;
7025 default: printf ("(unknown virtuality)"); break;
7029 case DW_AT_identifier_case:
7032 case DW_ID_case_sensitive: printf ("(case_sensitive)"); break;
7033 case DW_ID_up_case: printf ("(up_case)"); break;
7034 case DW_ID_down_case: printf ("(down_case)"); break;
7035 case DW_ID_case_insensitive: printf ("(case_insensitive)"); break;
7036 default: printf ("(unknown case)"); break;
7040 case DW_AT_calling_convention:
7043 case DW_CC_normal: printf ("(normal)"); break;
7044 case DW_CC_program: printf ("(program)"); break;
7045 case DW_CC_nocall: printf ("(nocall)"); break;
7047 if (uvalue >= DW_CC_lo_user
7048 && uvalue <= DW_CC_hi_user)
7049 printf ("(user defined)");
7051 printf ("(unknown convention)");
7055 case DW_AT_ordering:
7058 case -1: printf ("(undefined)"); break;
7059 case 0: printf ("(row major)"); break;
7060 case 1: printf ("(column major)"); break;
7064 case DW_AT_frame_base:
7065 case DW_AT_location:
7066 case DW_AT_data_member_location:
7067 case DW_AT_vtable_elem_location:
7068 case DW_AT_allocated:
7069 case DW_AT_associated:
7070 case DW_AT_data_location:
7072 case DW_AT_upper_bound:
7073 case DW_AT_lower_bound:
7077 decode_location_expression (block_start, pointer_size, uvalue);
7091 display_debug_info (section, start, file)
7092 Elf32_Internal_Shdr * section;
7093 unsigned char * start;
7096 unsigned char * end = start + section->sh_size;
7097 unsigned char * section_begin = start;
7099 printf (_("The section %s contains:\n\n"), SECTION_NAME (section));
7103 DWARF2_External_CompUnit * external;
7104 DWARF2_Internal_CompUnit compunit;
7105 Elf32_Internal_Shdr * relsec;
7106 unsigned char * tags;
7109 unsigned long cu_offset;
7111 external = (DWARF2_External_CompUnit *) start;
7113 compunit.cu_length = BYTE_GET (external->cu_length);
7114 compunit.cu_version = BYTE_GET (external->cu_version);
7115 compunit.cu_abbrev_offset = BYTE_GET (external->cu_abbrev_offset);
7116 compunit.cu_pointer_size = BYTE_GET (external->cu_pointer_size);
7118 /* Check for RELA relocations in the abbrev_offset address, and
7120 for (relsec = section_headers;
7121 relsec < section_headers + elf_header.e_shnum;
7124 unsigned long nrelas, nsyms;
7125 Elf_Internal_Rela *rela, *rp;
7126 Elf32_Internal_Shdr *symsec;
7127 Elf_Internal_Sym *symtab;
7128 Elf_Internal_Sym *sym;
7130 if (relsec->sh_type != SHT_RELA
7131 || section_headers + relsec->sh_info != section)
7134 if (!slurp_rela_relocs (file, relsec->sh_offset, relsec->sh_size,
7138 symsec = section_headers + relsec->sh_link;
7139 nsyms = symsec->sh_size / symsec->sh_entsize;
7140 symtab = GET_ELF_SYMBOLS (file, symsec->sh_offset, nsyms);
7142 for (rp = rela; rp < rela + nrelas; ++rp)
7145 != (bfd_vma) ((unsigned char *) &external->cu_abbrev_offset
7151 sym = symtab + ELF32_R_SYM (rp->r_info);
7153 if (ELF32_ST_TYPE (sym->st_info) != STT_SECTION)
7155 warn (_("Skipping unexpected symbol type %u"),
7156 ELF32_ST_TYPE (sym->st_info));
7162 sym = symtab + ELF64_R_SYM (rp->r_info);
7164 if (ELF64_ST_TYPE (sym->st_info) != STT_SECTION)
7166 warn (_("Skipping unexpected symbol type %u"),
7167 ELF64_ST_TYPE (sym->st_info));
7172 compunit.cu_abbrev_offset += rp->r_addend;
7180 tags = start + sizeof (* external);
7181 cu_offset = start - section_begin;
7182 start += compunit.cu_length + sizeof (external->cu_length);
7184 printf (_(" Compilation Unit @ %lx:\n"), cu_offset);
7185 printf (_(" Length: %ld\n"), compunit.cu_length);
7186 printf (_(" Version: %d\n"), compunit.cu_version);
7187 printf (_(" Abbrev Offset: %ld\n"), compunit.cu_abbrev_offset);
7188 printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size);
7190 if (compunit.cu_version != 2)
7192 warn (_("Only version 2 DWARF debug information is currently supported.\n"));
7196 if (first_abbrev != NULL)
7199 /* Read in the abbrevs used by this compilation unit. */
7202 Elf32_Internal_Shdr * sec;
7203 unsigned char * begin;
7205 /* Locate the .debug_abbrev section and process it. */
7206 for (i = 0, sec = section_headers;
7207 i < elf_header.e_shnum;
7209 if (strcmp (SECTION_NAME (sec), ".debug_abbrev") == 0)
7212 if (i == -1 || sec->sh_size == 0)
7214 warn (_("Unable to locate .debug_abbrev section!\n"));
7218 begin = ((unsigned char *)
7219 get_data (NULL, file, sec->sh_offset, sec->sh_size,
7220 _("debug_abbrev section data")));
7224 process_abbrev_section (begin + compunit.cu_abbrev_offset,
7225 begin + sec->sh_size);
7231 while (tags < start)
7234 unsigned long abbrev_number;
7235 abbrev_entry * entry;
7238 abbrev_number = read_leb128 (tags, & bytes_read, 0);
7241 /* A null DIE marks the end of a list of children. */
7242 if (abbrev_number == 0)
7248 /* Scan through the abbreviation list until we reach the
7250 for (entry = first_abbrev;
7251 entry && entry->entry != abbrev_number;
7252 entry = entry->next)
7257 warn (_("Unable to locate entry %lu in the abbreviation table\n"),
7262 printf (_(" <%d><%lx>: Abbrev Number: %lu (%s)\n"),
7264 (unsigned long) (tags - section_begin - bytes_read),
7266 get_TAG_name (entry->tag));
7268 for (attr = entry->first_attr; attr; attr = attr->next)
7269 tags = read_and_display_attr (attr->attribute,
7272 compunit.cu_pointer_size);
7274 if (entry->children)
7285 display_debug_aranges (section, start, file)
7286 Elf32_Internal_Shdr * section;
7287 unsigned char * start;
7288 FILE * file ATTRIBUTE_UNUSED;
7290 unsigned char * end = start + section->sh_size;
7292 printf (_("The section %s contains:\n\n"), SECTION_NAME (section));
7296 DWARF2_External_ARange * external;
7297 DWARF2_Internal_ARange arange;
7298 unsigned char * ranges;
7299 unsigned long length;
7300 unsigned long address;
7303 external = (DWARF2_External_ARange *) start;
7305 arange.ar_length = BYTE_GET (external->ar_length);
7306 arange.ar_version = BYTE_GET (external->ar_version);
7307 arange.ar_info_offset = BYTE_GET (external->ar_info_offset);
7308 arange.ar_pointer_size = BYTE_GET (external->ar_pointer_size);
7309 arange.ar_segment_size = BYTE_GET (external->ar_segment_size);
7311 if (arange.ar_version != 2)
7313 warn (_("Only DWARF 2 aranges are currently supported.\n"));
7317 printf (_(" Length: %ld\n"), arange.ar_length);
7318 printf (_(" Version: %d\n"), arange.ar_version);
7319 printf (_(" Offset into .debug_info: %lx\n"), arange.ar_info_offset);
7320 printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
7321 printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
7323 printf (_("\n Address Length\n"));
7325 ranges = start + sizeof (* external);
7327 /* Must pad to an alignment boundary that is twice the pointer size. */
7328 excess = sizeof (* external) % (2 * arange.ar_pointer_size);
7330 ranges += (2 * arange.ar_pointer_size) - excess;
7334 address = byte_get (ranges, arange.ar_pointer_size);
7336 ranges += arange.ar_pointer_size;
7338 length = byte_get (ranges, arange.ar_pointer_size);
7340 ranges += arange.ar_pointer_size;
7342 /* A pair of zeros marks the end of the list. */
7343 if (address == 0 && length == 0)
7346 printf (" %8.8lx %lu\n", address, length);
7349 start += arange.ar_length + sizeof (external->ar_length);
7357 typedef struct Frame_Chunk
7359 struct Frame_Chunk * next;
7360 unsigned char * chunk_start;
7362 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
7363 short int * col_type;
7365 char * augmentation;
7366 unsigned int code_factor;
7368 unsigned long pc_begin;
7369 unsigned long pc_range;
7373 unsigned char fde_encoding;
7377 /* A marker for a col_type that means this column was never referenced
7378 in the frame info. */
7379 #define DW_CFA_unreferenced (-1)
7381 static void frame_need_space PARAMS ((Frame_Chunk *, int));
7382 static void frame_display_row PARAMS ((Frame_Chunk *, int *, int *));
7383 static int size_of_encoded_value PARAMS ((int));
7386 frame_need_space (fc, reg)
7390 int prev = fc->ncols;
7392 if (reg < fc->ncols)
7395 fc->ncols = reg + 1;
7396 fc->col_type = (short int *) xrealloc (fc->col_type,
7397 fc->ncols * sizeof (short int));
7398 fc->col_offset = (int *) xrealloc (fc->col_offset,
7399 fc->ncols * sizeof (int));
7401 while (prev < fc->ncols)
7403 fc->col_type[prev] = DW_CFA_unreferenced;
7404 fc->col_offset[prev] = 0;
7410 frame_display_row (fc, need_col_headers, max_regs)
7412 int * need_col_headers;
7418 if (* max_regs < fc->ncols)
7419 * max_regs = fc->ncols;
7421 if (* need_col_headers)
7423 * need_col_headers = 0;
7425 printf (" LOC CFA ");
7427 for (r = 0; r < * max_regs; r++)
7428 if (fc->col_type[r] != DW_CFA_unreferenced)
7433 printf ("r%-4d", r);
7439 printf ("%08lx ", fc->pc_begin);
7440 sprintf (tmp, "r%d%+d", fc->cfa_reg, fc->cfa_offset);
7441 printf ("%-8s ", tmp);
7443 for (r = 0; r < fc->ncols; r++)
7445 if (fc->col_type[r] != DW_CFA_unreferenced)
7447 switch (fc->col_type[r])
7449 case DW_CFA_undefined:
7452 case DW_CFA_same_value:
7456 sprintf (tmp, "c%+d", fc->col_offset[r]);
7458 case DW_CFA_register:
7459 sprintf (tmp, "r%d", fc->col_offset[r]);
7462 strcpy (tmp, "n/a");
7465 printf ("%-5s", tmp);
7472 size_of_encoded_value (encoding)
7475 switch (encoding & 0x7)
7478 case 0: return is_32bit_elf ? 4 : 8;
7485 #define GET(N) byte_get (start, N); start += N
7486 #define LEB() read_leb128 (start, & length_return, 0); start += length_return
7487 #define SLEB() read_leb128 (start, & length_return, 1); start += length_return
7490 display_debug_frames (section, start, file)
7491 Elf32_Internal_Shdr * section;
7492 unsigned char * start;
7493 FILE * file ATTRIBUTE_UNUSED;
7495 unsigned char * end = start + section->sh_size;
7496 unsigned char * section_start = start;
7497 Frame_Chunk * chunks = 0;
7498 Frame_Chunk * remembered_state = 0;
7500 int is_eh = (strcmp (SECTION_NAME (section), ".eh_frame") == 0);
7503 int addr_size = is_32bit_elf ? 4 : 8;
7505 printf (_("The section %s contains:\n"), SECTION_NAME (section));
7509 unsigned char * saved_start;
7510 unsigned char * block_end;
7511 unsigned long length;
7512 unsigned long cie_id;
7515 int need_col_headers = 1;
7516 unsigned char * augmentation_data = NULL;
7517 unsigned long augmentation_data_len = 0;
7518 int encoded_ptr_size = addr_size;
7520 saved_start = start;
7521 length = byte_get (start, 4); start += 4;
7526 block_end = saved_start + length + 4;
7527 cie_id = byte_get (start, 4); start += 4;
7529 if (is_eh ? (cie_id == 0) : (cie_id == DW_CIE_ID))
7533 fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
7534 memset (fc, 0, sizeof (Frame_Chunk));
7538 fc->chunk_start = saved_start;
7540 fc->col_type = (short int *) xmalloc (sizeof (short int));
7541 fc->col_offset = (int *) xmalloc (sizeof (int));
7542 frame_need_space (fc, max_regs-1);
7546 fc->augmentation = start;
7547 start = strchr (start, '\0') + 1;
7549 if (fc->augmentation[0] == 'z')
7551 fc->code_factor = LEB ();
7552 fc->data_factor = SLEB ();
7553 fc->ra = byte_get (start, 1); start += 1;
7554 augmentation_data_len = LEB ();
7555 augmentation_data = start;
7556 start += augmentation_data_len;
7558 else if (strcmp (fc->augmentation, "eh") == 0)
7561 fc->code_factor = LEB ();
7562 fc->data_factor = SLEB ();
7563 fc->ra = byte_get (start, 1); start += 1;
7567 fc->code_factor = LEB ();
7568 fc->data_factor = SLEB ();
7569 fc->ra = byte_get (start, 1); start += 1;
7573 if (do_debug_frames_interp)
7574 printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n",
7575 (unsigned long)(saved_start - section_start), length, cie_id,
7576 fc->augmentation, fc->code_factor, fc->data_factor,
7580 printf ("\n%08lx %08lx %08lx CIE\n",
7581 (unsigned long)(saved_start - section_start), length, cie_id);
7582 printf (" Version: %d\n", version);
7583 printf (" Augmentation: \"%s\"\n", fc->augmentation);
7584 printf (" Code alignment factor: %u\n", fc->code_factor);
7585 printf (" Data alignment factor: %d\n", fc->data_factor);
7586 printf (" Return address column: %d\n", fc->ra);
7588 if (augmentation_data_len)
7591 printf (" Augmentation data: ");
7592 for (i = 0; i < augmentation_data_len; ++i)
7593 printf (" %02x", augmentation_data[i]);
7599 if (augmentation_data_len)
7601 unsigned char *p, *q;
7602 p = fc->augmentation + 1;
7603 q = augmentation_data;
7610 q += 1 + size_of_encoded_value (*q);
7612 fc->fde_encoding = *q++;
7618 if (fc->fde_encoding)
7619 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
7622 frame_need_space (fc, fc->ra);
7626 unsigned char * look_for;
7627 static Frame_Chunk fde_fc;
7630 memset (fc, 0, sizeof (Frame_Chunk));
7632 look_for = is_eh ? start - 4 - cie_id : section_start + cie_id;
7634 for (cie=chunks; cie ; cie = cie->next)
7635 if (cie->chunk_start == look_for)
7640 warn ("Invalid CIE pointer %08lx in FDE at %08lx\n",
7641 cie_id, saved_start);
7644 fc->col_type = (short int *) xmalloc (sizeof (short int));
7645 fc->col_offset = (int *) xmalloc (sizeof (int));
7646 frame_need_space (fc, max_regs - 1);
7648 fc->augmentation = "";
7649 fc->fde_encoding = 0;
7653 fc->ncols = cie->ncols;
7654 fc->col_type = (short int *) xmalloc (fc->ncols * sizeof (short int));
7655 fc->col_offset = (int *) xmalloc (fc->ncols * sizeof (int));
7656 memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int));
7657 memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int));
7658 fc->augmentation = cie->augmentation;
7659 fc->code_factor = cie->code_factor;
7660 fc->data_factor = cie->data_factor;
7661 fc->cfa_reg = cie->cfa_reg;
7662 fc->cfa_offset = cie->cfa_offset;
7664 frame_need_space (fc, max_regs-1);
7665 fc->fde_encoding = cie->fde_encoding;
7668 if (fc->fde_encoding)
7669 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
7671 fc->pc_begin = byte_get (start, encoded_ptr_size);
7672 start += encoded_ptr_size;
7673 fc->pc_range = byte_get (start, encoded_ptr_size);
7674 start += encoded_ptr_size;
7676 if (cie->augmentation[0] == 'z')
7678 augmentation_data_len = LEB ();
7679 augmentation_data = start;
7680 start += augmentation_data_len;
7683 printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=%08lx..%08lx\n",
7684 (unsigned long)(saved_start - section_start), length, cie_id,
7685 (unsigned long)(cie->chunk_start - section_start),
7686 fc->pc_begin, fc->pc_begin + fc->pc_range);
7687 if (! do_debug_frames_interp && augmentation_data_len)
7690 printf (" Augmentation data: ");
7691 for (i = 0; i < augmentation_data_len; ++i)
7692 printf (" %02x", augmentation_data[i]);
7698 /* At this point, fc is the current chunk, cie (if any) is set, and we're
7699 about to interpret instructions for the chunk. */
7701 if (do_debug_frames_interp)
7703 /* Start by making a pass over the chunk, allocating storage
7704 and taking note of what registers are used. */
7705 unsigned char * tmp = start;
7707 while (start < block_end)
7717 /* Warning: if you add any more cases to this switch, be
7718 sure to add them to the corresponding switch below. */
7721 case DW_CFA_advance_loc:
7725 frame_need_space (fc, opa);
7726 fc->col_type[opa] = DW_CFA_undefined;
7728 case DW_CFA_restore:
7729 frame_need_space (fc, opa);
7730 fc->col_type[opa] = DW_CFA_undefined;
7732 case DW_CFA_set_loc:
7733 start += encoded_ptr_size;
7735 case DW_CFA_advance_loc1:
7738 case DW_CFA_advance_loc2:
7741 case DW_CFA_advance_loc4:
7744 case DW_CFA_offset_extended:
7745 reg = LEB (); LEB ();
7746 frame_need_space (fc, reg);
7747 fc->col_type[reg] = DW_CFA_undefined;
7749 case DW_CFA_restore_extended:
7751 frame_need_space (fc, reg);
7752 fc->col_type[reg] = DW_CFA_undefined;
7754 case DW_CFA_undefined:
7756 frame_need_space (fc, reg);
7757 fc->col_type[reg] = DW_CFA_undefined;
7759 case DW_CFA_same_value:
7761 frame_need_space (fc, reg);
7762 fc->col_type[reg] = DW_CFA_undefined;
7764 case DW_CFA_register:
7765 reg = LEB (); LEB ();
7766 frame_need_space (fc, reg);
7767 fc->col_type[reg] = DW_CFA_undefined;
7769 case DW_CFA_def_cfa:
7772 case DW_CFA_def_cfa_register:
7775 case DW_CFA_def_cfa_offset:
7778 #ifndef DW_CFA_GNU_args_size
7779 #define DW_CFA_GNU_args_size 0x2e
7781 case DW_CFA_GNU_args_size:
7784 #ifndef DW_CFA_GNU_negative_offset_extended
7785 #define DW_CFA_GNU_negative_offset_extended 0x2f
7787 case DW_CFA_GNU_negative_offset_extended:
7788 reg = LEB (); LEB ();
7789 frame_need_space (fc, reg);
7790 fc->col_type[reg] = DW_CFA_undefined;
7799 /* Now we know what registers are used, make a second pass over
7800 the chunk, this time actually printing out the info. */
7802 while (start < block_end)
7805 unsigned long ul, reg, roffs;
7814 /* Warning: if you add any more cases to this switch, be
7815 sure to add them to the corresponding switch above. */
7818 case DW_CFA_advance_loc:
7819 if (do_debug_frames_interp)
7820 frame_display_row (fc, &need_col_headers, &max_regs);
7822 printf (" DW_CFA_advance_loc: %d to %08lx\n",
7823 opa * fc->code_factor,
7824 fc->pc_begin + opa * fc->code_factor);
7825 fc->pc_begin += opa * fc->code_factor;
7830 if (! do_debug_frames_interp)
7831 printf (" DW_CFA_offset: r%d at cfa%+ld\n",
7832 opa, roffs * fc->data_factor);
7833 fc->col_type[opa] = DW_CFA_offset;
7834 fc->col_offset[opa] = roffs * fc->data_factor;
7837 case DW_CFA_restore:
7838 if (! do_debug_frames_interp)
7839 printf (" DW_CFA_restore: r%d\n", opa);
7840 fc->col_type[opa] = cie->col_type[opa];
7841 fc->col_offset[opa] = cie->col_offset[opa];
7844 case DW_CFA_set_loc:
7845 vma = byte_get (start, encoded_ptr_size);
7846 start += encoded_ptr_size;
7847 if (do_debug_frames_interp)
7848 frame_display_row (fc, &need_col_headers, &max_regs);
7850 printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma);
7854 case DW_CFA_advance_loc1:
7855 ofs = byte_get (start, 1); start += 1;
7856 if (do_debug_frames_interp)
7857 frame_display_row (fc, &need_col_headers, &max_regs);
7859 printf (" DW_CFA_advance_loc1: %ld to %08lx\n",
7860 ofs * fc->code_factor,
7861 fc->pc_begin + ofs * fc->code_factor);
7862 fc->pc_begin += ofs * fc->code_factor;
7865 case DW_CFA_advance_loc2:
7866 ofs = byte_get (start, 2); start += 2;
7867 if (do_debug_frames_interp)
7868 frame_display_row (fc, &need_col_headers, &max_regs);
7870 printf (" DW_CFA_advance_loc2: %ld to %08lx\n",
7871 ofs * fc->code_factor,
7872 fc->pc_begin + ofs * fc->code_factor);
7873 fc->pc_begin += ofs * fc->code_factor;
7876 case DW_CFA_advance_loc4:
7877 ofs = byte_get (start, 4); start += 4;
7878 if (do_debug_frames_interp)
7879 frame_display_row (fc, &need_col_headers, &max_regs);
7881 printf (" DW_CFA_advance_loc4: %ld to %08lx\n",
7882 ofs * fc->code_factor,
7883 fc->pc_begin + ofs * fc->code_factor);
7884 fc->pc_begin += ofs * fc->code_factor;
7887 case DW_CFA_offset_extended:
7890 if (! do_debug_frames_interp)
7891 printf (" DW_CFA_offset_extended: r%ld at cfa%+ld\n",
7892 reg, roffs * fc->data_factor);
7893 fc->col_type[reg] = DW_CFA_offset;
7894 fc->col_offset[reg] = roffs * fc->data_factor;
7897 case DW_CFA_restore_extended:
7899 if (! do_debug_frames_interp)
7900 printf (" DW_CFA_restore_extended: r%ld\n", reg);
7901 fc->col_type[reg] = cie->col_type[reg];
7902 fc->col_offset[reg] = cie->col_offset[reg];
7905 case DW_CFA_undefined:
7907 if (! do_debug_frames_interp)
7908 printf (" DW_CFA_undefined: r%ld\n", reg);
7909 fc->col_type[reg] = DW_CFA_undefined;
7910 fc->col_offset[reg] = 0;
7913 case DW_CFA_same_value:
7915 if (! do_debug_frames_interp)
7916 printf (" DW_CFA_same_value: r%ld\n", reg);
7917 fc->col_type[reg] = DW_CFA_same_value;
7918 fc->col_offset[reg] = 0;
7921 case DW_CFA_register:
7924 if (! do_debug_frames_interp)
7925 printf (" DW_CFA_register: r%ld\n", reg);
7926 fc->col_type[reg] = DW_CFA_register;
7927 fc->col_offset[reg] = roffs;
7930 case DW_CFA_remember_state:
7931 if (! do_debug_frames_interp)
7932 printf (" DW_CFA_remember_state\n");
7933 rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
7934 rs->ncols = fc->ncols;
7935 rs->col_type = (short int *) xmalloc (rs->ncols * sizeof (short int));
7936 rs->col_offset = (int *) xmalloc (rs->ncols * sizeof (int));
7937 memcpy (rs->col_type, fc->col_type, rs->ncols);
7938 memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (int));
7939 rs->next = remembered_state;
7940 remembered_state = rs;
7943 case DW_CFA_restore_state:
7944 if (! do_debug_frames_interp)
7945 printf (" DW_CFA_restore_state\n");
7946 rs = remembered_state;
7947 remembered_state = rs->next;
7948 frame_need_space (fc, rs->ncols-1);
7949 memcpy (fc->col_type, rs->col_type, rs->ncols);
7950 memcpy (fc->col_offset, rs->col_offset, rs->ncols * sizeof (int));
7951 free (rs->col_type);
7952 free (rs->col_offset);
7956 case DW_CFA_def_cfa:
7957 fc->cfa_reg = LEB ();
7958 fc->cfa_offset = LEB ();
7959 if (! do_debug_frames_interp)
7960 printf (" DW_CFA_def_cfa: r%d ofs %d\n",
7961 fc->cfa_reg, fc->cfa_offset);
7964 case DW_CFA_def_cfa_register:
7965 fc->cfa_reg = LEB ();
7966 if (! do_debug_frames_interp)
7967 printf (" DW_CFA_def_cfa_reg: r%d\n", fc->cfa_reg);
7970 case DW_CFA_def_cfa_offset:
7971 fc->cfa_offset = LEB ();
7972 if (! do_debug_frames_interp)
7973 printf (" DW_CFA_def_cfa_offset: %d\n", fc->cfa_offset);
7977 if (! do_debug_frames_interp)
7978 printf (" DW_CFA_nop\n");
7981 #ifndef DW_CFA_GNU_window_save
7982 #define DW_CFA_GNU_window_save 0x2d
7984 case DW_CFA_GNU_window_save:
7985 if (! do_debug_frames_interp)
7986 printf (" DW_CFA_GNU_window_save\n");
7989 case DW_CFA_GNU_args_size:
7991 if (! do_debug_frames_interp)
7992 printf (" DW_CFA_GNU_args_size: %ld\n", ul);
7995 case DW_CFA_GNU_negative_offset_extended:
7998 frame_need_space (fc, reg);
7999 if (! do_debug_frames_interp)
8000 printf (" DW_CFA_GNU_negative_offset_extended: r%ld at cfa%+ld\n",
8001 reg, l * fc->data_factor);
8002 fc->col_type[reg] = DW_CFA_offset;
8003 fc->col_offset[reg] = l * fc->data_factor;
8007 fprintf (stderr, "unsupported or unknown DW_CFA_%d\n", op);
8012 if (do_debug_frames_interp)
8013 frame_display_row (fc, &need_col_headers, &max_regs);
8028 display_debug_not_supported (section, start, file)
8029 Elf32_Internal_Shdr * section;
8030 unsigned char * start ATTRIBUTE_UNUSED;
8031 FILE * file ATTRIBUTE_UNUSED;
8033 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
8034 SECTION_NAME (section));
8039 /* Pre-scan the .debug_info section to record the size of address.
8040 When dumping the .debug_line, we use that size information, assuming
8041 that all compilation units have the same address size. */
8043 prescan_debug_info (section, start, file)
8044 Elf32_Internal_Shdr * section ATTRIBUTE_UNUSED;
8045 unsigned char * start;
8046 FILE * file ATTRIBUTE_UNUSED;
8048 DWARF2_External_CompUnit * external;
8050 external = (DWARF2_External_CompUnit *) start;
8052 debug_line_pointer_size = BYTE_GET (external->cu_pointer_size);
8056 /* A structure containing the name of a debug section and a pointer
8057 to a function that can decode it. The third field is a prescan
8058 function to be run over the section before displaying any of the
8063 int (* display) PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
8064 int (* prescan) PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
8068 { ".debug_info", display_debug_info, prescan_debug_info },
8069 { ".debug_abbrev", display_debug_abbrev, NULL },
8070 { ".debug_line", display_debug_lines, NULL },
8071 { ".debug_aranges", display_debug_aranges, NULL },
8072 { ".debug_pubnames", display_debug_pubnames, NULL },
8073 { ".debug_frame", display_debug_frames, NULL },
8074 { ".eh_frame", display_debug_frames, NULL },
8075 { ".debug_macinfo", display_debug_macinfo, NULL },
8076 { ".debug_str", display_debug_not_supported, NULL },
8077 { ".debug_static_func", display_debug_not_supported, NULL },
8078 { ".debug_static_vars", display_debug_not_supported, NULL },
8079 { ".debug_types", display_debug_not_supported, NULL },
8080 { ".debug_weaknames", display_debug_not_supported, NULL }
8084 display_debug_section (section, file)
8085 Elf32_Internal_Shdr * section;
8088 char * name = SECTION_NAME (section);
8089 bfd_size_type length;
8090 unsigned char * start;
8093 length = section->sh_size;
8096 printf (_("\nSection '%s' has no debugging data.\n"), name);
8100 start = (unsigned char *) get_data (NULL, file, section->sh_offset, length,
8101 _("debug section data"));
8105 /* See if we know how to display the contents of this section. */
8106 if (strncmp (name, ".gnu.linkonce.wi.", 17) == 0)
8107 name = ".debug_info";
8109 for (i = NUM_ELEM (debug_displays); i--;)
8110 if (strcmp (debug_displays[i].name, name) == 0)
8112 debug_displays[i].display (section, start, file);
8117 printf (_("Unrecognised debug section: %s\n"), name);
8121 /* If we loaded in the abbrev section at some point,
8122 we must release it here. */
8123 if (first_abbrev != NULL)
8130 process_section_contents (file)
8133 Elf32_Internal_Shdr * section;
8139 /* Pre-scan the debug sections to find some debug information not
8140 present in some of them. For the .debug_line, we must find out the
8141 size of address (specified in .debug_info and .debug_aranges). */
8142 for (i = 0, section = section_headers;
8143 i < elf_header.e_shnum && i < num_dump_sects;
8146 char * name = SECTION_NAME (section);
8149 if (section->sh_size == 0)
8152 /* See if there is some pre-scan operation for this section. */
8153 for (j = NUM_ELEM (debug_displays); j--;)
8154 if (strcmp (debug_displays[j].name, name) == 0)
8156 if (debug_displays[j].prescan != NULL)
8158 bfd_size_type length;
8159 unsigned char * start;
8161 length = section->sh_size;
8162 start = ((unsigned char *)
8163 get_data (NULL, file, section->sh_offset, length,
8164 _("debug section data")));
8168 debug_displays[j].prescan (section, start, file);
8176 for (i = 0, section = section_headers;
8177 i < elf_header.e_shnum && i < num_dump_sects;
8180 #ifdef SUPPORT_DISASSEMBLY
8181 if (dump_sects[i] & DISASS_DUMP)
8182 disassemble_section (section, file);
8184 if (dump_sects[i] & HEX_DUMP)
8185 dump_section (section, file);
8187 if (dump_sects[i] & DEBUG_DUMP)
8188 display_debug_section (section, file);
8191 if (i < num_dump_sects)
8192 warn (_("Some sections were not dumped because they do not exist!\n"));
8198 process_mips_fpe_exception (mask)
8204 if (mask & OEX_FPU_INEX)
8205 fputs ("INEX", stdout), first = 0;
8206 if (mask & OEX_FPU_UFLO)
8207 printf ("%sUFLO", first ? "" : "|"), first = 0;
8208 if (mask & OEX_FPU_OFLO)
8209 printf ("%sOFLO", first ? "" : "|"), first = 0;
8210 if (mask & OEX_FPU_DIV0)
8211 printf ("%sDIV0", first ? "" : "|"), first = 0;
8212 if (mask & OEX_FPU_INVAL)
8213 printf ("%sINVAL", first ? "" : "|");
8216 fputs ("0", stdout);
8220 process_mips_specific (file)
8223 Elf_Internal_Dyn * entry;
8224 size_t liblist_offset = 0;
8225 size_t liblistno = 0;
8226 size_t conflictsno = 0;
8227 size_t options_offset = 0;
8228 size_t conflicts_offset = 0;
8230 /* We have a lot of special sections. Thanks SGI! */
8231 if (dynamic_segment == NULL)
8232 /* No information available. */
8235 for (entry = dynamic_segment; entry->d_tag != DT_NULL; ++entry)
8236 switch (entry->d_tag)
8238 case DT_MIPS_LIBLIST:
8239 liblist_offset = entry->d_un.d_val - loadaddr;
8241 case DT_MIPS_LIBLISTNO:
8242 liblistno = entry->d_un.d_val;
8244 case DT_MIPS_OPTIONS:
8245 options_offset = entry->d_un.d_val - loadaddr;
8247 case DT_MIPS_CONFLICT:
8248 conflicts_offset = entry->d_un.d_val - loadaddr;
8250 case DT_MIPS_CONFLICTNO:
8251 conflictsno = entry->d_un.d_val;
8257 if (liblist_offset != 0 && liblistno != 0 && do_dynamic)
8259 Elf32_External_Lib * elib;
8262 elib = ((Elf32_External_Lib *)
8263 get_data (NULL, file, liblist_offset,
8264 liblistno * sizeof (Elf32_External_Lib),
8268 printf ("\nSection '.liblist' contains %lu entries:\n",
8269 (unsigned long) liblistno);
8270 fputs (" Library Time Stamp Checksum Version Flags\n",
8273 for (cnt = 0; cnt < liblistno; ++cnt)
8280 liblist.l_name = BYTE_GET (elib[cnt].l_name);
8281 time = BYTE_GET (elib[cnt].l_time_stamp);
8282 liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum);
8283 liblist.l_version = BYTE_GET (elib[cnt].l_version);
8284 liblist.l_flags = BYTE_GET (elib[cnt].l_flags);
8286 tmp = gmtime (&time);
8287 sprintf (timebuf, "%04u-%02u-%02uT%02u:%02u:%02u",
8288 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
8289 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
8291 printf ("%3lu: %-20s %s %#10lx %-7ld", (unsigned long) cnt,
8292 dynamic_strings + liblist.l_name, timebuf,
8293 liblist.l_checksum, liblist.l_version);
8295 if (liblist.l_flags == 0)
8306 { " EXACT_MATCH", LL_EXACT_MATCH },
8307 { " IGNORE_INT_VER", LL_IGNORE_INT_VER },
8308 { " REQUIRE_MINOR", LL_REQUIRE_MINOR },
8309 { " EXPORTS", LL_EXPORTS },
8310 { " DELAY_LOAD", LL_DELAY_LOAD },
8311 { " DELTA", LL_DELTA }
8313 int flags = liblist.l_flags;
8317 fcnt < sizeof (l_flags_vals) / sizeof (l_flags_vals[0]);
8319 if ((flags & l_flags_vals[fcnt].bit) != 0)
8321 fputs (l_flags_vals[fcnt].name, stdout);
8322 flags ^= l_flags_vals[fcnt].bit;
8325 printf (" %#x", (unsigned int) flags);
8335 if (options_offset != 0)
8337 Elf_External_Options * eopt;
8338 Elf_Internal_Shdr * sect = section_headers;
8339 Elf_Internal_Options * iopt;
8340 Elf_Internal_Options * option;
8344 /* Find the section header so that we get the size. */
8345 while (sect->sh_type != SHT_MIPS_OPTIONS)
8348 eopt = (Elf_External_Options *) get_data (NULL, file, options_offset,
8349 sect->sh_size, _("options"));
8352 iopt = ((Elf_Internal_Options *)
8353 malloc ((sect->sh_size / sizeof (eopt)) * sizeof (* iopt)));
8356 error (_("Out of memory"));
8363 while (offset < sect->sh_size)
8365 Elf_External_Options * eoption;
8367 eoption = (Elf_External_Options *) ((char *) eopt + offset);
8369 option->kind = BYTE_GET (eoption->kind);
8370 option->size = BYTE_GET (eoption->size);
8371 option->section = BYTE_GET (eoption->section);
8372 option->info = BYTE_GET (eoption->info);
8374 offset += option->size;
8380 printf (_("\nSection '%s' contains %d entries:\n"),
8381 SECTION_NAME (sect), cnt);
8389 switch (option->kind)
8392 /* This shouldn't happen. */
8393 printf (" NULL %d %lx", option->section, option->info);
8396 printf (" REGINFO ");
8397 if (elf_header.e_machine == EM_MIPS)
8400 Elf32_External_RegInfo * ereg;
8401 Elf32_RegInfo reginfo;
8403 ereg = (Elf32_External_RegInfo *) (option + 1);
8404 reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask);
8405 reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
8406 reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
8407 reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
8408 reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
8409 reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value);
8411 printf ("GPR %08lx GP 0x%lx\n",
8413 (unsigned long) reginfo.ri_gp_value);
8414 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
8415 reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
8416 reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
8421 Elf64_External_RegInfo * ereg;
8422 Elf64_Internal_RegInfo reginfo;
8424 ereg = (Elf64_External_RegInfo *) (option + 1);
8425 reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask);
8426 reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
8427 reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
8428 reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
8429 reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
8430 reginfo.ri_gp_value = BYTE_GET8 (ereg->ri_gp_value);
8432 printf ("GPR %08lx GP 0x",
8433 reginfo.ri_gprmask);
8434 printf_vma (reginfo.ri_gp_value);
8437 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
8438 reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
8439 reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
8443 case ODK_EXCEPTIONS:
8444 fputs (" EXCEPTIONS fpe_min(", stdout);
8445 process_mips_fpe_exception (option->info & OEX_FPU_MIN);
8446 fputs (") fpe_max(", stdout);
8447 process_mips_fpe_exception ((option->info & OEX_FPU_MAX) >> 8);
8448 fputs (")", stdout);
8450 if (option->info & OEX_PAGE0)
8451 fputs (" PAGE0", stdout);
8452 if (option->info & OEX_SMM)
8453 fputs (" SMM", stdout);
8454 if (option->info & OEX_FPDBUG)
8455 fputs (" FPDBUG", stdout);
8456 if (option->info & OEX_DISMISS)
8457 fputs (" DISMISS", stdout);
8460 fputs (" PAD ", stdout);
8461 if (option->info & OPAD_PREFIX)
8462 fputs (" PREFIX", stdout);
8463 if (option->info & OPAD_POSTFIX)
8464 fputs (" POSTFIX", stdout);
8465 if (option->info & OPAD_SYMBOL)
8466 fputs (" SYMBOL", stdout);
8469 fputs (" HWPATCH ", stdout);
8470 if (option->info & OHW_R4KEOP)
8471 fputs (" R4KEOP", stdout);
8472 if (option->info & OHW_R8KPFETCH)
8473 fputs (" R8KPFETCH", stdout);
8474 if (option->info & OHW_R5KEOP)
8475 fputs (" R5KEOP", stdout);
8476 if (option->info & OHW_R5KCVTL)
8477 fputs (" R5KCVTL", stdout);
8480 fputs (" FILL ", stdout);
8481 /* XXX Print content of info word? */
8484 fputs (" TAGS ", stdout);
8485 /* XXX Print content of info word? */
8488 fputs (" HWAND ", stdout);
8489 if (option->info & OHWA0_R4KEOP_CHECKED)
8490 fputs (" R4KEOP_CHECKED", stdout);
8491 if (option->info & OHWA0_R4KEOP_CLEAN)
8492 fputs (" R4KEOP_CLEAN", stdout);
8495 fputs (" HWOR ", stdout);
8496 if (option->info & OHWA0_R4KEOP_CHECKED)
8497 fputs (" R4KEOP_CHECKED", stdout);
8498 if (option->info & OHWA0_R4KEOP_CLEAN)
8499 fputs (" R4KEOP_CLEAN", stdout);
8502 printf (" GP_GROUP %#06lx self-contained %#06lx",
8503 option->info & OGP_GROUP,
8504 (option->info & OGP_SELF) >> 16);
8507 printf (" IDENT %#06lx self-contained %#06lx",
8508 option->info & OGP_GROUP,
8509 (option->info & OGP_SELF) >> 16);
8512 /* This shouldn't happen. */
8513 printf (" %3d ??? %d %lx",
8514 option->kind, option->section, option->info);
8518 len = sizeof (* eopt);
8519 while (len < option->size)
8520 if (((char *) option)[len] >= ' '
8521 && ((char *) option)[len] < 0x7f)
8522 printf ("%c", ((char *) option)[len++]);
8524 printf ("\\%03o", ((char *) option)[len++]);
8526 fputs ("\n", stdout);
8534 if (conflicts_offset != 0 && conflictsno != 0)
8536 Elf32_Conflict * iconf;
8539 if (dynamic_symbols == NULL)
8541 error (_("conflict list with without table"));
8545 iconf = (Elf32_Conflict *) malloc (conflictsno * sizeof (* iconf));
8548 error (_("Out of memory"));
8554 Elf32_External_Conflict * econf32;
8556 econf32 = ((Elf32_External_Conflict *)
8557 get_data (NULL, file, conflicts_offset,
8558 conflictsno * sizeof (* econf32),
8563 for (cnt = 0; cnt < conflictsno; ++cnt)
8564 iconf[cnt] = BYTE_GET (econf32[cnt]);
8570 Elf64_External_Conflict * econf64;
8572 econf64 = ((Elf64_External_Conflict *)
8573 get_data (NULL, file, conflicts_offset,
8574 conflictsno * sizeof (* econf64),
8579 for (cnt = 0; cnt < conflictsno; ++cnt)
8580 iconf[cnt] = BYTE_GET (econf64[cnt]);
8585 printf (_("\nSection '.conflict' contains %ld entries:\n"),
8586 (long) conflictsno);
8587 puts (_(" Num: Index Value Name"));
8589 for (cnt = 0; cnt < conflictsno; ++cnt)
8591 Elf_Internal_Sym * psym = &dynamic_symbols[iconf[cnt]];
8593 printf ("%5lu: %8lu ", (unsigned long) cnt, iconf[cnt]);
8594 print_vma (psym->st_value, FULL_HEX);
8595 printf (" %s\n", dynamic_strings + psym->st_name);
8605 get_note_type (e_type)
8608 static char buff[64];
8612 case NT_PRSTATUS: return _("NT_PRSTATUS (prstatus structure)");
8613 case NT_FPREGSET: return _("NT_FPREGSET (floating point registers)");
8614 case NT_PRPSINFO: return _("NT_PRPSINFO (prpsinfo structure)");
8615 case NT_TASKSTRUCT: return _("NT_TASKSTRUCT (task structure)");
8616 case NT_PRXFPREG: return _("NT_PRXFPREG (user_xfpregs structure)");
8617 case NT_PSTATUS: return _("NT_PSTATUS (pstatus structure)");
8618 case NT_FPREGS: return _("NT_FPREGS (floating point registers)");
8619 case NT_PSINFO: return _("NT_PSINFO (psinfo structure)");
8620 case NT_LWPSTATUS: return _("NT_LWPSTATUS (lwpstatus_t structure)");
8621 case NT_LWPSINFO: return _("NT_LWPSINFO (lwpsinfo_t structure)");
8622 case NT_WIN32PSTATUS: return _("NT_WIN32PSTATUS (win32_pstatus strcuture)");
8624 sprintf (buff, _("Unknown note type: (0x%08x)"), e_type);
8629 /* Note that by the ELF standard, the name field is already null byte
8630 terminated, and namesz includes the terminating null byte.
8631 I.E. the value of namesz for the name "FSF" is 4.
8633 If the value of namesz is zero, there is no name present. */
8635 process_note (pnote)
8636 Elf32_Internal_Note * pnote;
8638 printf (" %s\t\t0x%08lx\t%s\n",
8639 pnote->namesz ? pnote->namedata : "(NONE)",
8640 pnote->descsz, get_note_type (pnote->type));
8646 process_corefile_note_segment (file, offset, length)
8651 Elf_External_Note * pnotes;
8652 Elf_External_Note * external;
8658 pnotes = (Elf_External_Note *) get_data (NULL, file, offset, length,
8665 printf (_("\nNotes at offset 0x%08lx with length 0x%08lx:\n"),
8666 (unsigned long) offset, (unsigned long) length);
8667 printf (_(" Owner\t\tData size\tDescription\n"));
8669 while (external < (Elf_External_Note *)((char *) pnotes + length))
8671 Elf32_Internal_Note inote;
8674 inote.type = BYTE_GET (external->type);
8675 inote.namesz = BYTE_GET (external->namesz);
8676 inote.namedata = external->name;
8677 inote.descsz = BYTE_GET (external->descsz);
8678 inote.descdata = inote.namedata + align_power (inote.namesz, 2);
8679 inote.descpos = offset + (inote.descdata - (char *) pnotes);
8681 external = (Elf_External_Note *)(inote.descdata + align_power (inote.descsz, 2));
8683 /* Verify that name is null terminated. It appears that at least
8684 one version of Linux (RedHat 6.0) generates corefiles that don't
8685 comply with the ELF spec by failing to include the null byte in
8687 if (inote.namedata[inote.namesz] != '\0')
8689 temp = malloc (inote.namesz + 1);
8693 error (_("Out of memory\n"));
8698 strncpy (temp, inote.namedata, inote.namesz);
8699 temp[inote.namesz] = 0;
8701 /* warn (_("'%s' NOTE name not properly null terminated\n"), temp); */
8702 inote.namedata = temp;
8705 res &= process_note (& inote);
8720 process_corefile_note_segments (file)
8723 Elf_Internal_Phdr * program_headers;
8724 Elf_Internal_Phdr * segment;
8728 program_headers = (Elf_Internal_Phdr *) malloc
8729 (elf_header.e_phnum * sizeof (Elf_Internal_Phdr));
8731 if (program_headers == NULL)
8733 error (_("Out of memory\n"));
8738 i = get_32bit_program_headers (file, program_headers);
8740 i = get_64bit_program_headers (file, program_headers);
8744 free (program_headers);
8748 for (i = 0, segment = program_headers;
8749 i < elf_header.e_phnum;
8752 if (segment->p_type == PT_NOTE)
8753 res &= process_corefile_note_segment (file,
8754 (bfd_vma) segment->p_offset,
8755 (bfd_vma) segment->p_filesz);
8758 free (program_headers);
8764 process_corefile_contents (file)
8767 /* If we have not been asked to display the notes then do nothing. */
8771 /* If file is not a core file then exit. */
8772 if (elf_header.e_type != ET_CORE)
8775 /* No program headers means no NOTE segment. */
8776 if (elf_header.e_phnum == 0)
8778 printf (_("No note segments present in the core file.\n"));
8782 return process_corefile_note_segments (file);
8786 process_arch_specific (file)
8792 switch (elf_header.e_machine)
8795 case EM_MIPS_RS3_LE:
8796 return process_mips_specific (file);
8805 get_file_header (file)
8808 /* Read in the identity array. */
8809 if (fread (elf_header.e_ident, EI_NIDENT, 1, file) != 1)
8812 /* Determine how to read the rest of the header. */
8813 switch (elf_header.e_ident [EI_DATA])
8815 default: /* fall through */
8816 case ELFDATANONE: /* fall through */
8817 case ELFDATA2LSB: byte_get = byte_get_little_endian; break;
8818 case ELFDATA2MSB: byte_get = byte_get_big_endian; break;
8821 /* For now we only support 32 bit and 64 bit ELF files. */
8822 is_32bit_elf = (elf_header.e_ident [EI_CLASS] != ELFCLASS64);
8824 /* Read in the rest of the header. */
8827 Elf32_External_Ehdr ehdr32;
8829 if (fread (ehdr32.e_type, sizeof (ehdr32) - EI_NIDENT, 1, file) != 1)
8832 elf_header.e_type = BYTE_GET (ehdr32.e_type);
8833 elf_header.e_machine = BYTE_GET (ehdr32.e_machine);
8834 elf_header.e_version = BYTE_GET (ehdr32.e_version);
8835 elf_header.e_entry = BYTE_GET (ehdr32.e_entry);
8836 elf_header.e_phoff = BYTE_GET (ehdr32.e_phoff);
8837 elf_header.e_shoff = BYTE_GET (ehdr32.e_shoff);
8838 elf_header.e_flags = BYTE_GET (ehdr32.e_flags);
8839 elf_header.e_ehsize = BYTE_GET (ehdr32.e_ehsize);
8840 elf_header.e_phentsize = BYTE_GET (ehdr32.e_phentsize);
8841 elf_header.e_phnum = BYTE_GET (ehdr32.e_phnum);
8842 elf_header.e_shentsize = BYTE_GET (ehdr32.e_shentsize);
8843 elf_header.e_shnum = BYTE_GET (ehdr32.e_shnum);
8844 elf_header.e_shstrndx = BYTE_GET (ehdr32.e_shstrndx);
8848 Elf64_External_Ehdr ehdr64;
8850 /* If we have been compiled with sizeof (bfd_vma) == 4, then
8851 we will not be able to cope with the 64bit data found in
8852 64 ELF files. Detect this now and abort before we start
8853 overwritting things. */
8854 if (sizeof (bfd_vma) < 8)
8856 error (_("This instance of readelf has been built without support for a\n"));
8857 error (_("64 bit data type and so it cannot read 64 bit ELF files.\n"));
8861 if (fread (ehdr64.e_type, sizeof (ehdr64) - EI_NIDENT, 1, file) != 1)
8864 elf_header.e_type = BYTE_GET (ehdr64.e_type);
8865 elf_header.e_machine = BYTE_GET (ehdr64.e_machine);
8866 elf_header.e_version = BYTE_GET (ehdr64.e_version);
8867 elf_header.e_entry = BYTE_GET8 (ehdr64.e_entry);
8868 elf_header.e_phoff = BYTE_GET8 (ehdr64.e_phoff);
8869 elf_header.e_shoff = BYTE_GET8 (ehdr64.e_shoff);
8870 elf_header.e_flags = BYTE_GET (ehdr64.e_flags);
8871 elf_header.e_ehsize = BYTE_GET (ehdr64.e_ehsize);
8872 elf_header.e_phentsize = BYTE_GET (ehdr64.e_phentsize);
8873 elf_header.e_phnum = BYTE_GET (ehdr64.e_phnum);
8874 elf_header.e_shentsize = BYTE_GET (ehdr64.e_shentsize);
8875 elf_header.e_shnum = BYTE_GET (ehdr64.e_shnum);
8876 elf_header.e_shstrndx = BYTE_GET (ehdr64.e_shstrndx);
8883 process_file (file_name)
8887 struct stat statbuf;
8890 if (stat (file_name, & statbuf) < 0)
8892 error (_("Cannot stat input file %s.\n"), file_name);
8896 file = fopen (file_name, "rb");
8899 error (_("Input file %s not found.\n"), file_name);
8903 if (! get_file_header (file))
8905 error (_("%s: Failed to read file header\n"), file_name);
8910 /* Initialise per file variables. */
8911 for (i = NUM_ELEM (version_info); i--;)
8912 version_info[i] = 0;
8914 for (i = NUM_ELEM (dynamic_info); i--;)
8915 dynamic_info[i] = 0;
8917 /* Process the file. */
8919 printf (_("\nFile: %s\n"), file_name);
8921 if (! process_file_header ())
8927 process_section_headers (file);
8929 process_program_headers (file);
8931 process_dynamic_segment (file);
8933 process_relocs (file);
8935 process_unwind (file);
8937 process_symbol_table (file);
8939 process_syminfo (file);
8941 process_version_sections (file);
8943 process_section_contents (file);
8945 process_corefile_contents (file);
8947 process_arch_specific (file);
8951 if (section_headers)
8953 free (section_headers);
8954 section_headers = NULL;
8959 free (string_table);
8960 string_table = NULL;
8961 string_table_length = 0;
8964 if (dynamic_strings)
8966 free (dynamic_strings);
8967 dynamic_strings = NULL;
8970 if (dynamic_symbols)
8972 free (dynamic_symbols);
8973 dynamic_symbols = NULL;
8974 num_dynamic_syms = 0;
8977 if (dynamic_syminfo)
8979 free (dynamic_syminfo);
8980 dynamic_syminfo = NULL;
8986 #ifdef SUPPORT_DISASSEMBLY
8987 /* Needed by the i386 disassembler. For extra credit, someone could
8988 fix this so that we insert symbolic addresses here, esp for GOT/PLT
8992 print_address (unsigned int addr, FILE * outfile)
8994 fprintf (outfile,"0x%8.8x", addr);
8997 /* Needed by the i386 disassembler. */
8999 db_task_printsym (unsigned int addr)
9001 print_address (addr, stderr);
9012 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
9013 setlocale (LC_MESSAGES, "");
9015 #if defined (HAVE_SETLOCALE)
9016 setlocale (LC_CTYPE, "");
9018 bindtextdomain (PACKAGE, LOCALEDIR);
9019 textdomain (PACKAGE);
9021 parse_args (argc, argv);
9023 if (optind < (argc - 1))
9027 while (optind < argc)
9028 err |= process_file (argv [optind ++]);
9030 if (dump_sects != NULL)