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"
78 #include "elf/x86-64.h"
84 char * program_name = "readelf";
85 unsigned int dynamic_addr;
86 bfd_size_type dynamic_size;
87 unsigned int rela_addr;
88 unsigned int rela_size;
89 char * dynamic_strings;
91 unsigned long string_table_length;
92 unsigned long num_dynamic_syms;
93 Elf_Internal_Sym * dynamic_symbols;
94 Elf_Internal_Syminfo * dynamic_syminfo;
95 unsigned long dynamic_syminfo_offset;
96 unsigned int dynamic_syminfo_nent;
97 char program_interpreter [64];
98 int dynamic_info[DT_JMPREL + 1];
101 Elf_Internal_Ehdr elf_header;
102 Elf_Internal_Shdr * section_headers;
103 Elf_Internal_Dyn * dynamic_segment;
111 int do_using_dynamic;
119 int do_debug_abbrevs;
121 int do_debug_pubnames;
122 int do_debug_aranges;
124 int do_debug_frames_interp;
125 int do_debug_macinfo;
131 /* A dynamic array of flags indicating which sections require dumping. */
132 char * dump_sects = NULL;
133 unsigned int num_dump_sects = 0;
135 #define HEX_DUMP (1 << 0)
136 #define DISASS_DUMP (1 << 1)
137 #define DEBUG_DUMP (1 << 2)
139 /* How to rpint a vma value. */
140 typedef enum print_mode
152 /* Forward declarations for dumb compilers. */
153 static void print_vma PARAMS ((bfd_vma, print_mode));
154 static bfd_vma (* byte_get) PARAMS ((unsigned char *, int));
155 static bfd_vma byte_get_little_endian PARAMS ((unsigned char *, int));
156 static bfd_vma byte_get_big_endian PARAMS ((unsigned char *, int));
157 static const char * get_mips_dynamic_type PARAMS ((unsigned long));
158 static const char * get_sparc64_dynamic_type PARAMS ((unsigned long));
159 static const char * get_parisc_dynamic_type PARAMS ((unsigned long));
160 static const char * get_dynamic_type PARAMS ((unsigned long));
161 static int slurp_rela_relocs PARAMS ((FILE *, unsigned long, unsigned long, Elf_Internal_Rela **, unsigned long *));
162 static int slurp_rel_relocs PARAMS ((FILE *, unsigned long, unsigned long, Elf_Internal_Rel **, unsigned long *));
163 static int dump_relocations PARAMS ((FILE *, unsigned long, unsigned long, Elf_Internal_Sym *, unsigned long, char *, int));
164 static char * get_file_type PARAMS ((unsigned));
165 static char * get_machine_name PARAMS ((unsigned));
166 static void decode_ARM_machine_flags PARAMS ((unsigned, char []));
167 static char * get_machine_flags PARAMS ((unsigned, unsigned));
168 static const char * get_mips_segment_type PARAMS ((unsigned long));
169 static const char * get_parisc_segment_type PARAMS ((unsigned long));
170 static const char * get_ia64_segment_type PARAMS ((unsigned long));
171 static const char * get_segment_type PARAMS ((unsigned long));
172 static const char * get_mips_section_type_name PARAMS ((unsigned int));
173 static const char * get_parisc_section_type_name PARAMS ((unsigned int));
174 static const char * get_ia64_section_type_name PARAMS ((unsigned int));
175 static const char * get_section_type_name PARAMS ((unsigned int));
176 static const char * get_symbol_binding PARAMS ((unsigned int));
177 static const char * get_symbol_type PARAMS ((unsigned int));
178 static const char * get_symbol_visibility PARAMS ((unsigned int));
179 static const char * get_symbol_index_type PARAMS ((unsigned int));
180 static const char * get_dynamic_flags PARAMS ((bfd_vma));
181 static void usage PARAMS ((void));
182 static void parse_args PARAMS ((int, char **));
183 static int process_file_header PARAMS ((void));
184 static int process_program_headers PARAMS ((FILE *));
185 static int process_section_headers PARAMS ((FILE *));
186 static int process_unwind PARAMS ((FILE *));
187 static void dynamic_segment_mips_val PARAMS ((Elf_Internal_Dyn *));
188 static void dynamic_segment_parisc_val PARAMS ((Elf_Internal_Dyn *));
189 static int process_dynamic_segment PARAMS ((FILE *));
190 static int process_symbol_table PARAMS ((FILE *));
191 static int process_syminfo PARAMS ((FILE *));
192 static int process_section_contents PARAMS ((FILE *));
193 static void process_mips_fpe_exception PARAMS ((int));
194 static int process_mips_specific PARAMS ((FILE *));
195 static int process_file PARAMS ((char *));
196 static int process_relocs PARAMS ((FILE *));
197 static int process_version_sections PARAMS ((FILE *));
198 static char * get_ver_flags PARAMS ((unsigned int));
199 static int get_32bit_section_headers PARAMS ((FILE *));
200 static int get_64bit_section_headers PARAMS ((FILE *));
201 static int get_32bit_program_headers PARAMS ((FILE *, Elf_Internal_Phdr *));
202 static int get_64bit_program_headers PARAMS ((FILE *, Elf_Internal_Phdr *));
203 static int get_file_header PARAMS ((FILE *));
204 static Elf_Internal_Sym * get_32bit_elf_symbols PARAMS ((FILE *, unsigned long, unsigned long));
205 static Elf_Internal_Sym * get_64bit_elf_symbols PARAMS ((FILE *, unsigned long, unsigned long));
206 static const char * get_elf_section_flags PARAMS ((bfd_vma));
207 static int * get_dynamic_data PARAMS ((FILE *, unsigned int));
208 static int get_32bit_dynamic_segment PARAMS ((FILE *));
209 static int get_64bit_dynamic_segment PARAMS ((FILE *));
210 #ifdef SUPPORT_DISASSEMBLY
211 static int disassemble_section PARAMS ((Elf32_Internal_Shdr *, FILE *));
213 static int dump_section PARAMS ((Elf32_Internal_Shdr *, FILE *));
214 static int display_debug_section PARAMS ((Elf32_Internal_Shdr *, FILE *));
215 static int display_debug_info PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
216 static int display_debug_not_supported PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
217 static int prescan_debug_info PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
218 static int display_debug_lines PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
219 static int display_debug_pubnames PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
220 static int display_debug_abbrev PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
221 static int display_debug_aranges PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
222 static int display_debug_frames PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
223 static int display_debug_macinfo PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
224 static int display_debug_str PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
225 static unsigned char * process_abbrev_section PARAMS ((unsigned char *, unsigned char *));
226 static void load_debug_str PARAMS ((FILE *));
227 static void free_debug_str PARAMS ((void));
228 static const char * fetch_indirect_string PARAMS ((unsigned long));
229 static unsigned long read_leb128 PARAMS ((unsigned char *, int *, int));
230 static int process_extended_line_op PARAMS ((unsigned char *, int, int));
231 static void reset_state_machine PARAMS ((int));
232 static char * get_TAG_name PARAMS ((unsigned long));
233 static char * get_AT_name PARAMS ((unsigned long));
234 static char * get_FORM_name PARAMS ((unsigned long));
235 static void free_abbrevs PARAMS ((void));
236 static void add_abbrev PARAMS ((unsigned long, unsigned long, int));
237 static void add_abbrev_attr PARAMS ((unsigned long, unsigned long));
238 static unsigned char * read_and_display_attr PARAMS ((unsigned long, unsigned long, unsigned char *, unsigned long, unsigned long));
239 static unsigned char * read_and_display_attr_value PARAMS ((unsigned long, unsigned long, unsigned char *, unsigned long, unsigned long));
240 static unsigned char * display_block PARAMS ((unsigned char *, unsigned long));
241 static void decode_location_expression PARAMS ((unsigned char *, unsigned int, unsigned long));
242 static void request_dump PARAMS ((unsigned int, int));
243 static const char * get_elf_class PARAMS ((unsigned int));
244 static const char * get_data_encoding PARAMS ((unsigned int));
245 static const char * get_osabi_name PARAMS ((unsigned int));
246 static int guess_is_rela PARAMS ((unsigned long));
247 static char * get_note_type PARAMS ((unsigned int));
248 static int process_note PARAMS ((Elf32_Internal_Note *));
249 static int process_corefile_note_segment PARAMS ((FILE *, bfd_vma, bfd_vma));
250 static int process_corefile_note_segments PARAMS ((FILE *));
251 static int process_corefile_contents PARAMS ((FILE *));
252 static int process_arch_specific PARAMS ((FILE *));
254 typedef int Elf32_Word;
262 #define SECTION_NAME(X) ((X) == NULL ? "<none>" : \
263 ((X)->sh_name >= string_table_length \
264 ? "<corrupt>" : string_table + (X)->sh_name))
266 #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
268 #define BYTE_GET(field) byte_get (field, sizeof (field))
270 /* If we can support a 64 bit data type then BFD64 should be defined
271 and sizeof (bfd_vma) == 8. In this case when translating from an
272 external 8 byte field to an internal field, we can assume that the
273 internal field is also 8 bytes wide and so we can extract all the data.
274 If, however, BFD64 is not defined, then we must assume that the
275 internal data structure only has 4 byte wide fields that are the
276 equivalent of the 8 byte wide external counterparts, and so we must
277 truncate the data. */
279 #define BYTE_GET8(field) byte_get (field, -8)
281 #define BYTE_GET8(field) byte_get (field, 8)
284 #define NUM_ELEM(array) (sizeof (array) / sizeof ((array)[0]))
286 #define GET_ELF_SYMBOLS(file, offset, size) \
287 (is_32bit_elf ? get_32bit_elf_symbols (file, offset, size) \
288 : get_64bit_elf_symbols (file, offset, size))
292 error VPARAMS ((const char *message, ...))
294 VA_OPEN (args, message);
295 VA_FIXEDARG (args, const char *, message);
297 fprintf (stderr, _("%s: Error: "), program_name);
298 vfprintf (stderr, message, args);
303 warn VPARAMS ((const char *message, ...))
305 VA_OPEN (args, message);
306 VA_FIXEDARG (args, const char *, message);
308 fprintf (stderr, _("%s: Warning: "), program_name);
309 vfprintf (stderr, message, args);
313 static PTR get_data PARAMS ((PTR, FILE *, long, size_t, const char *));
316 get_data (var, file, offset, size, reason)
328 if (fseek (file, offset, SEEK_SET))
330 error (_("Unable to seek to %x for %s\n"), offset, reason);
337 mvar = (PTR) malloc (size);
341 error (_("Out of memory allocating %d bytes for %s\n"),
347 if (fread (mvar, size, 1, file) != 1)
349 error (_("Unable to read in %d bytes of %s\n"), size, reason);
359 byte_get_little_endian (field, size)
360 unsigned char * field;
369 return ((unsigned int) (field [0]))
370 | (((unsigned int) (field [1])) << 8);
374 /* We want to extract data from an 8 byte wide field and
375 place it into a 4 byte wide field. Since this is a little
376 endian source we can juts use the 4 byte extraction code. */
380 return ((unsigned long) (field [0]))
381 | (((unsigned long) (field [1])) << 8)
382 | (((unsigned long) (field [2])) << 16)
383 | (((unsigned long) (field [3])) << 24);
388 /* This is a special case, generated by the BYTE_GET8 macro.
389 It means that we are loading an 8 byte value from a field
390 in an external structure into an 8 byte value in a field
391 in an internal strcuture. */
392 return ((bfd_vma) (field [0]))
393 | (((bfd_vma) (field [1])) << 8)
394 | (((bfd_vma) (field [2])) << 16)
395 | (((bfd_vma) (field [3])) << 24)
396 | (((bfd_vma) (field [4])) << 32)
397 | (((bfd_vma) (field [5])) << 40)
398 | (((bfd_vma) (field [6])) << 48)
399 | (((bfd_vma) (field [7])) << 56);
402 error (_("Unhandled data length: %d\n"), size);
407 /* Print a VMA value. */
409 print_vma (vma, mode)
419 case FULL_HEX: printf ("0x"); /* drop through */
420 case LONG_HEX: printf ("%8.8lx", (unsigned long) vma); break;
421 case PREFIX_HEX: printf ("0x"); /* drop through */
422 case HEX: printf ("%lx", (unsigned long) vma); break;
423 case DEC: printf ("%ld", (unsigned long) vma); break;
424 case DEC_5: printf ("%5ld", (long) vma); break;
425 case UNSIGNED: printf ("%lu", (unsigned long) vma); break;
446 #if BFD_HOST_64BIT_LONG
449 if (_bfd_int64_high (vma))
450 printf ("%lx%8.8lx", _bfd_int64_high (vma), _bfd_int64_low (vma));
452 printf ("%lx", _bfd_int64_low (vma));
457 #if BFD_HOST_64BIT_LONG
460 if (_bfd_int64_high (vma))
462 printf ("++%ld", _bfd_int64_low (vma));
464 printf ("%ld", _bfd_int64_low (vma));
469 #if BFD_HOST_64BIT_LONG
470 printf ("%5ld", vma);
472 if (_bfd_int64_high (vma))
474 printf ("++%ld", _bfd_int64_low (vma));
476 printf ("%5ld", _bfd_int64_low (vma));
481 #if BFD_HOST_64BIT_LONG
484 if (_bfd_int64_high (vma))
486 printf ("++%lu", _bfd_int64_low (vma));
488 printf ("%lu", _bfd_int64_low (vma));
497 byte_get_big_endian (field, size)
498 unsigned char * field;
507 return ((unsigned int) (field [1])) | (((int) (field [0])) << 8);
510 return ((unsigned long) (field [3]))
511 | (((unsigned long) (field [2])) << 8)
512 | (((unsigned long) (field [1])) << 16)
513 | (((unsigned long) (field [0])) << 24);
517 /* Although we are extracing data from an 8 byte wide field, we
518 are returning only 4 bytes of data. */
519 return ((unsigned long) (field [7]))
520 | (((unsigned long) (field [6])) << 8)
521 | (((unsigned long) (field [5])) << 16)
522 | (((unsigned long) (field [4])) << 24);
526 /* This is a special case, generated by the BYTE_GET8 macro.
527 It means that we are loading an 8 byte value from a field
528 in an external structure into an 8 byte value in a field
529 in an internal strcuture. */
530 return ((bfd_vma) (field [7]))
531 | (((bfd_vma) (field [6])) << 8)
532 | (((bfd_vma) (field [5])) << 16)
533 | (((bfd_vma) (field [4])) << 24)
534 | (((bfd_vma) (field [3])) << 32)
535 | (((bfd_vma) (field [2])) << 40)
536 | (((bfd_vma) (field [1])) << 48)
537 | (((bfd_vma) (field [0])) << 56);
541 error (_("Unhandled data length: %d\n"), size);
546 /* Guess the relocation size commonly used by the specific machines. */
549 guess_is_rela (e_machine)
550 unsigned long e_machine;
554 /* Targets that use REL relocations. */
567 /* Targets that use RELA relocations. */
581 case EM_CYGNUS_MN10200:
583 case EM_CYGNUS_MN10300:
619 warn (_("Don't know about relocations on this machine architecture\n"));
625 slurp_rela_relocs (file, rel_offset, rel_size, relasp, nrelasp)
627 unsigned long rel_offset;
628 unsigned long rel_size;
629 Elf_Internal_Rela **relasp;
630 unsigned long *nrelasp;
632 Elf_Internal_Rela *relas;
633 unsigned long nrelas;
638 Elf32_External_Rela * erelas;
640 erelas = (Elf32_External_Rela *) get_data (NULL, file, rel_offset,
641 rel_size, _("relocs"));
645 nrelas = rel_size / sizeof (Elf32_External_Rela);
647 relas = (Elf_Internal_Rela *)
648 malloc (nrelas * sizeof (Elf_Internal_Rela));
652 error(_("out of memory parsing relocs"));
656 for (i = 0; i < nrelas; i++)
658 relas[i].r_offset = BYTE_GET (erelas[i].r_offset);
659 relas[i].r_info = BYTE_GET (erelas[i].r_info);
660 relas[i].r_addend = BYTE_GET (erelas[i].r_addend);
667 Elf64_External_Rela * erelas;
669 erelas = (Elf64_External_Rela *) get_data (NULL, file, rel_offset,
670 rel_size, _("relocs"));
674 nrelas = rel_size / sizeof (Elf64_External_Rela);
676 relas = (Elf_Internal_Rela *)
677 malloc (nrelas * sizeof (Elf_Internal_Rela));
681 error(_("out of memory parsing relocs"));
685 for (i = 0; i < nrelas; i++)
687 relas[i].r_offset = BYTE_GET8 (erelas[i].r_offset);
688 relas[i].r_info = BYTE_GET8 (erelas[i].r_info);
689 relas[i].r_addend = BYTE_GET8 (erelas[i].r_addend);
700 slurp_rel_relocs (file, rel_offset, rel_size, relsp, nrelsp)
702 unsigned long rel_offset;
703 unsigned long rel_size;
704 Elf_Internal_Rel **relsp;
705 unsigned long *nrelsp;
707 Elf_Internal_Rel *rels;
713 Elf32_External_Rel * erels;
715 erels = (Elf32_External_Rel *) get_data (NULL, file, rel_offset,
716 rel_size, _("relocs"));
720 nrels = rel_size / sizeof (Elf32_External_Rel);
722 rels = (Elf_Internal_Rel *) malloc (nrels * sizeof (Elf_Internal_Rel));
726 error(_("out of memory parsing relocs"));
730 for (i = 0; i < nrels; i++)
732 rels[i].r_offset = BYTE_GET (erels[i].r_offset);
733 rels[i].r_info = BYTE_GET (erels[i].r_info);
740 Elf64_External_Rel * erels;
742 erels = (Elf64_External_Rel *) get_data (NULL, file, rel_offset,
743 rel_size, _("relocs"));
747 nrels = rel_size / sizeof (Elf64_External_Rel);
749 rels = (Elf_Internal_Rel *) malloc (nrels * sizeof (Elf_Internal_Rel));
753 error(_("out of memory parsing relocs"));
757 for (i = 0; i < nrels; i++)
759 rels[i].r_offset = BYTE_GET8 (erels[i].r_offset);
760 rels[i].r_info = BYTE_GET8 (erels[i].r_info);
770 /* Display the contents of the relocation data found at the specified offset. */
772 dump_relocations (file, rel_offset, rel_size, symtab, nsyms, strtab, is_rela)
774 unsigned long rel_offset;
775 unsigned long rel_size;
776 Elf_Internal_Sym * symtab;
782 Elf_Internal_Rel * rels;
783 Elf_Internal_Rela * relas;
786 if (is_rela == UNKNOWN)
787 is_rela = guess_is_rela (elf_header.e_machine);
791 if (!slurp_rela_relocs (file, rel_offset, rel_size, &relas, &rel_size))
796 if (!slurp_rel_relocs (file, rel_offset, rel_size, &rels, &rel_size))
804 (_(" Offset Info Type Symbol's Value Symbol's Name Addend\n"));
807 (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
813 (_(" Offset Info Type Symbol's Value Symbol's Name Addend\n"));
816 (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
819 for (i = 0; i < rel_size; i++)
824 bfd_vma symtab_index;
829 offset = relas [i].r_offset;
830 info = relas [i].r_info;
834 offset = rels [i].r_offset;
835 info = rels [i].r_info;
840 type = ELF32_R_TYPE (info);
841 symtab_index = ELF32_R_SYM (info);
845 if (elf_header.e_machine == EM_SPARCV9)
846 type = ELF64_R_TYPE_ID (info);
848 type = ELF64_R_TYPE (info);
849 /* The #ifdef BFD64 below is to prevent a compile time warning.
850 We know that if we do not have a 64 bit data type that we
851 will never execute this code anyway. */
853 symtab_index = ELF64_R_SYM (info);
859 #ifdef _bfd_int64_low
860 printf ("%8.8lx %8.8lx ", _bfd_int64_low (offset), _bfd_int64_low (info));
862 printf ("%8.8lx %8.8lx ", offset, info);
867 #ifdef _bfd_int64_low
868 printf ("%8.8lx%8.8lx %8.8lx%8.8lx ",
869 _bfd_int64_high (offset),
870 _bfd_int64_low (offset),
871 _bfd_int64_high (info),
872 _bfd_int64_low (info));
874 printf ("%16.16lx %16.16lx ", offset, info);
878 switch (elf_header.e_machine)
886 rtype = elf_m32r_reloc_type (type);
891 rtype = elf_i386_reloc_type (type);
895 rtype = elf_m68k_reloc_type (type);
899 rtype = elf_i960_reloc_type (type);
904 rtype = elf_avr_reloc_type (type);
911 rtype = elf_sparc_reloc_type (type);
916 rtype = v850_reloc_type (type);
921 rtype = elf_d10v_reloc_type (type);
926 rtype = elf_d30v_reloc_type (type);
930 rtype = elf_sh_reloc_type (type);
934 case EM_CYGNUS_MN10300:
935 rtype = elf_mn10300_reloc_type (type);
939 case EM_CYGNUS_MN10200:
940 rtype = elf_mn10200_reloc_type (type);
945 rtype = elf_fr30_reloc_type (type);
949 rtype = elf_mcore_reloc_type (type);
953 rtype = elf_mmix_reloc_type (type);
958 rtype = elf_ppc_reloc_type (type);
963 rtype = elf_mips_reloc_type (type);
967 rtype = elf_alpha_reloc_type (type);
971 rtype = elf_arm_reloc_type (type);
975 rtype = elf_arc_reloc_type (type);
979 rtype = elf_hppa_reloc_type (type);
985 rtype = elf_h8_reloc_type (type);
990 rtype = elf_pj_reloc_type (type);
993 rtype = elf_ia64_reloc_type (type);
997 rtype = elf_cris_reloc_type (type);
1001 rtype = elf_i860_reloc_type (type);
1005 rtype = elf_x86_64_reloc_type (type);
1010 rtype = elf_s390_reloc_type (type);
1015 #ifdef _bfd_int64_low
1016 printf (_("unrecognised: %-7lx"), _bfd_int64_low (type));
1018 printf (_("unrecognised: %-7lx"), type);
1021 printf ("%-21.21s", rtype);
1025 if (symtab == NULL || symtab_index >= nsyms)
1026 printf (" bad symbol index: %08lx", (unsigned long) symtab_index);
1029 Elf_Internal_Sym * psym;
1031 psym = symtab + symtab_index;
1034 print_vma (psym->st_value, LONG_HEX);
1037 if (psym->st_name == 0)
1039 SECTION_NAME (section_headers + psym->st_shndx));
1040 else if (strtab == NULL)
1041 printf (_("<string table index %3ld>"), psym->st_name);
1043 printf ("%-25.25s", strtab + psym->st_name);
1046 printf (" + %lx", (unsigned long) relas [i].r_addend);
1051 printf ("%*c", is_32bit_elf ? 34 : 26, ' ');
1052 print_vma (relas[i].r_addend, LONG_HEX);
1055 if (elf_header.e_machine == EM_SPARCV9
1056 && !strcmp (rtype, "R_SPARC_OLO10"))
1057 printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (info));
1071 get_mips_dynamic_type (type)
1076 case DT_MIPS_RLD_VERSION: return "MIPS_RLD_VERSION";
1077 case DT_MIPS_TIME_STAMP: return "MIPS_TIME_STAMP";
1078 case DT_MIPS_ICHECKSUM: return "MIPS_ICHECKSUM";
1079 case DT_MIPS_IVERSION: return "MIPS_IVERSION";
1080 case DT_MIPS_FLAGS: return "MIPS_FLAGS";
1081 case DT_MIPS_BASE_ADDRESS: return "MIPS_BASE_ADDRESS";
1082 case DT_MIPS_MSYM: return "MIPS_MSYM";
1083 case DT_MIPS_CONFLICT: return "MIPS_CONFLICT";
1084 case DT_MIPS_LIBLIST: return "MIPS_LIBLIST";
1085 case DT_MIPS_LOCAL_GOTNO: return "MIPS_LOCAL_GOTNO";
1086 case DT_MIPS_CONFLICTNO: return "MIPS_CONFLICTNO";
1087 case DT_MIPS_LIBLISTNO: return "MIPS_LIBLISTNO";
1088 case DT_MIPS_SYMTABNO: return "MIPS_SYMTABNO";
1089 case DT_MIPS_UNREFEXTNO: return "MIPS_UNREFEXTNO";
1090 case DT_MIPS_GOTSYM: return "MIPS_GOTSYM";
1091 case DT_MIPS_HIPAGENO: return "MIPS_HIPAGENO";
1092 case DT_MIPS_RLD_MAP: return "MIPS_RLD_MAP";
1093 case DT_MIPS_DELTA_CLASS: return "MIPS_DELTA_CLASS";
1094 case DT_MIPS_DELTA_CLASS_NO: return "MIPS_DELTA_CLASS_NO";
1095 case DT_MIPS_DELTA_INSTANCE: return "MIPS_DELTA_INSTANCE";
1096 case DT_MIPS_DELTA_INSTANCE_NO: return "MIPS_DELTA_INSTANCE_NO";
1097 case DT_MIPS_DELTA_RELOC: return "MIPS_DELTA_RELOC";
1098 case DT_MIPS_DELTA_RELOC_NO: return "MIPS_DELTA_RELOC_NO";
1099 case DT_MIPS_DELTA_SYM: return "MIPS_DELTA_SYM";
1100 case DT_MIPS_DELTA_SYM_NO: return "MIPS_DELTA_SYM_NO";
1101 case DT_MIPS_DELTA_CLASSSYM: return "MIPS_DELTA_CLASSSYM";
1102 case DT_MIPS_DELTA_CLASSSYM_NO: return "MIPS_DELTA_CLASSSYM_NO";
1103 case DT_MIPS_CXX_FLAGS: return "MIPS_CXX_FLAGS";
1104 case DT_MIPS_PIXIE_INIT: return "MIPS_PIXIE_INIT";
1105 case DT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB";
1106 case DT_MIPS_LOCALPAGE_GOTIDX: return "MIPS_LOCALPAGE_GOTIDX";
1107 case DT_MIPS_LOCAL_GOTIDX: return "MIPS_LOCAL_GOTIDX";
1108 case DT_MIPS_HIDDEN_GOTIDX: return "MIPS_HIDDEN_GOTIDX";
1109 case DT_MIPS_PROTECTED_GOTIDX: return "MIPS_PROTECTED_GOTIDX";
1110 case DT_MIPS_OPTIONS: return "MIPS_OPTIONS";
1111 case DT_MIPS_INTERFACE: return "MIPS_INTERFACE";
1112 case DT_MIPS_DYNSTR_ALIGN: return "MIPS_DYNSTR_ALIGN";
1113 case DT_MIPS_INTERFACE_SIZE: return "MIPS_INTERFACE_SIZE";
1114 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
1115 case DT_MIPS_PERF_SUFFIX: return "MIPS_PERF_SUFFIX";
1116 case DT_MIPS_COMPACT_SIZE: return "MIPS_COMPACT_SIZE";
1117 case DT_MIPS_GP_VALUE: return "MIPS_GP_VALUE";
1118 case DT_MIPS_AUX_DYNAMIC: return "MIPS_AUX_DYNAMIC";
1125 get_sparc64_dynamic_type (type)
1130 case DT_SPARC_REGISTER: return "SPARC_REGISTER";
1137 get_parisc_dynamic_type (type)
1142 case DT_HP_LOAD_MAP: return "HP_LOAD_MAP";
1143 case DT_HP_DLD_FLAGS: return "HP_DLD_FLAGS";
1144 case DT_HP_DLD_HOOK: return "HP_DLD_HOOK";
1145 case DT_HP_UX10_INIT: return "HP_UX10_INIT";
1146 case DT_HP_UX10_INITSZ: return "HP_UX10_INITSZ";
1147 case DT_HP_PREINIT: return "HP_PREINIT";
1148 case DT_HP_PREINITSZ: return "HP_PREINITSZ";
1149 case DT_HP_NEEDED: return "HP_NEEDED";
1150 case DT_HP_TIME_STAMP: return "HP_TIME_STAMP";
1151 case DT_HP_CHECKSUM: return "HP_CHECKSUM";
1152 case DT_HP_GST_SIZE: return "HP_GST_SIZE";
1153 case DT_HP_GST_VERSION: return "HP_GST_VERSION";
1154 case DT_HP_GST_HASHVAL: return "HP_GST_HASHVAL";
1161 get_dynamic_type (type)
1164 static char buff [32];
1168 case DT_NULL: return "NULL";
1169 case DT_NEEDED: return "NEEDED";
1170 case DT_PLTRELSZ: return "PLTRELSZ";
1171 case DT_PLTGOT: return "PLTGOT";
1172 case DT_HASH: return "HASH";
1173 case DT_STRTAB: return "STRTAB";
1174 case DT_SYMTAB: return "SYMTAB";
1175 case DT_RELA: return "RELA";
1176 case DT_RELASZ: return "RELASZ";
1177 case DT_RELAENT: return "RELAENT";
1178 case DT_STRSZ: return "STRSZ";
1179 case DT_SYMENT: return "SYMENT";
1180 case DT_INIT: return "INIT";
1181 case DT_FINI: return "FINI";
1182 case DT_SONAME: return "SONAME";
1183 case DT_RPATH: return "RPATH";
1184 case DT_SYMBOLIC: return "SYMBOLIC";
1185 case DT_REL: return "REL";
1186 case DT_RELSZ: return "RELSZ";
1187 case DT_RELENT: return "RELENT";
1188 case DT_PLTREL: return "PLTREL";
1189 case DT_DEBUG: return "DEBUG";
1190 case DT_TEXTREL: return "TEXTREL";
1191 case DT_JMPREL: return "JMPREL";
1192 case DT_BIND_NOW: return "BIND_NOW";
1193 case DT_INIT_ARRAY: return "INIT_ARRAY";
1194 case DT_FINI_ARRAY: return "FINI_ARRAY";
1195 case DT_INIT_ARRAYSZ: return "INIT_ARRAYSZ";
1196 case DT_FINI_ARRAYSZ: return "FINI_ARRAYSZ";
1197 case DT_RUNPATH: return "RUNPATH";
1198 case DT_FLAGS: return "FLAGS";
1200 case DT_PREINIT_ARRAY: return "PREINIT_ARRAY";
1201 case DT_PREINIT_ARRAYSZ: return "PREINIT_ARRAYSZ";
1203 case DT_CHECKSUM: return "CHECKSUM";
1204 case DT_PLTPADSZ: return "PLTPADSZ";
1205 case DT_MOVEENT: return "MOVEENT";
1206 case DT_MOVESZ: return "MOVESZ";
1207 case DT_FEATURE: return "FEATURE";
1208 case DT_POSFLAG_1: return "POSFLAG_1";
1209 case DT_SYMINSZ: return "SYMINSZ";
1210 case DT_SYMINENT: return "SYMINENT"; /* aka VALRNGHI */
1212 case DT_ADDRRNGLO: return "ADDRRNGLO";
1213 case DT_CONFIG: return "CONFIG";
1214 case DT_DEPAUDIT: return "DEPAUDIT";
1215 case DT_AUDIT: return "AUDIT";
1216 case DT_PLTPAD: return "PLTPAD";
1217 case DT_MOVETAB: return "MOVETAB";
1218 case DT_SYMINFO: return "SYMINFO"; /* aka ADDRRNGHI */
1220 case DT_VERSYM: return "VERSYM";
1222 case DT_RELACOUNT: return "RELACOUNT";
1223 case DT_RELCOUNT: return "RELCOUNT";
1224 case DT_FLAGS_1: return "FLAGS_1";
1225 case DT_VERDEF: return "VERDEF";
1226 case DT_VERDEFNUM: return "VERDEFNUM";
1227 case DT_VERNEED: return "VERNEED";
1228 case DT_VERNEEDNUM: return "VERNEEDNUM";
1230 case DT_AUXILIARY: return "AUXILIARY";
1231 case DT_USED: return "USED";
1232 case DT_FILTER: return "FILTER";
1235 if ((type >= DT_LOPROC) && (type <= DT_HIPROC))
1237 const char * result;
1239 switch (elf_header.e_machine)
1242 case EM_MIPS_RS3_LE:
1243 result = get_mips_dynamic_type (type);
1246 result = get_sparc64_dynamic_type (type);
1256 sprintf (buff, _("Processor Specific: %lx"), type);
1258 else if ((type >= DT_LOOS) && (type <= DT_HIOS))
1260 const char * result;
1262 switch (elf_header.e_machine)
1265 result = get_parisc_dynamic_type (type);
1275 sprintf (buff, _("Operating System specific: %lx"), type);
1278 sprintf (buff, _("<unknown>: %lx"), type);
1285 get_file_type (e_type)
1288 static char buff [32];
1292 case ET_NONE: return _("NONE (None)");
1293 case ET_REL: return _("REL (Relocatable file)");
1294 case ET_EXEC: return _("EXEC (Executable file)");
1295 case ET_DYN: return _("DYN (Shared object file)");
1296 case ET_CORE: return _("CORE (Core file)");
1299 if ((e_type >= ET_LOPROC) && (e_type <= ET_HIPROC))
1300 sprintf (buff, _("Processor Specific: (%x)"), e_type);
1301 else if ((e_type >= ET_LOOS) && (e_type <= ET_HIOS))
1302 sprintf (buff, _("OS Specific: (%x)"), e_type);
1304 sprintf (buff, _("<unknown>: %x"), e_type);
1310 get_machine_name (e_machine)
1313 static char buff [64]; /* XXX */
1317 case EM_NONE: return _("None");
1318 case EM_M32: return "WE32100";
1319 case EM_SPARC: return "Sparc";
1320 case EM_386: return "Intel 80386";
1321 case EM_68K: return "MC68000";
1322 case EM_88K: return "MC88000";
1323 case EM_486: return "Intel 80486";
1324 case EM_860: return "Intel 80860";
1325 case EM_MIPS: return "MIPS R3000";
1326 case EM_S370: return "IBM System/370";
1327 case EM_MIPS_RS3_LE: return "MIPS R4000 big-endian";
1328 case EM_OLD_SPARCV9: return "Sparc v9 (old)";
1329 case EM_PARISC: return "HPPA";
1330 case EM_PPC_OLD: return "Power PC (old)";
1331 case EM_SPARC32PLUS: return "Sparc v8+" ;
1332 case EM_960: return "Intel 90860";
1333 case EM_PPC: return "PowerPC";
1334 case EM_V800: return "NEC V800";
1335 case EM_FR20: return "Fujitsu FR20";
1336 case EM_RH32: return "TRW RH32";
1337 case EM_MCORE: return "MCORE";
1338 case EM_ARM: return "ARM";
1339 case EM_OLD_ALPHA: return "Digital Alpha (old)";
1340 case EM_SH: return "Hitachi SH";
1341 case EM_SPARCV9: return "Sparc v9";
1342 case EM_TRICORE: return "Siemens Tricore";
1343 case EM_ARC: return "ARC";
1344 case EM_H8_300: return "Hitachi H8/300";
1345 case EM_H8_300H: return "Hitachi H8/300H";
1346 case EM_H8S: return "Hitachi H8S";
1347 case EM_H8_500: return "Hitachi H8/500";
1348 case EM_IA_64: return "Intel IA-64";
1349 case EM_MIPS_X: return "Stanford MIPS-X";
1350 case EM_COLDFIRE: return "Motorola Coldfire";
1351 case EM_68HC12: return "Motorola M68HC12";
1352 case EM_ALPHA: return "Alpha";
1353 case EM_CYGNUS_D10V:
1354 case EM_D10V: return "d10v";
1355 case EM_CYGNUS_D30V:
1356 case EM_D30V: return "d30v";
1357 case EM_CYGNUS_M32R:
1358 case EM_M32R: return "Mitsubishi M32r";
1359 case EM_CYGNUS_V850:
1360 case EM_V850: return "NEC v850";
1361 case EM_CYGNUS_MN10300:
1362 case EM_MN10300: return "mn10300";
1363 case EM_CYGNUS_MN10200:
1364 case EM_MN10200: return "mn10200";
1365 case EM_CYGNUS_FR30:
1366 case EM_FR30: return "Fujitsu FR30";
1368 case EM_PJ: return "picoJava";
1369 case EM_MMA: return "Fujitsu Multimedia Accelerator";
1370 case EM_PCP: return "Siemens PCP";
1371 case EM_NCPU: return "Sony nCPU embedded RISC processor";
1372 case EM_NDR1: return "Denso NDR1 microprocesspr";
1373 case EM_STARCORE: return "Motorola Star*Core processor";
1374 case EM_ME16: return "Toyota ME16 processor";
1375 case EM_ST100: return "STMicroelectronics ST100 processor";
1376 case EM_TINYJ: return "Advanced Logic Corp. TinyJ embedded processor";
1377 case EM_FX66: return "Siemens FX66 microcontroller";
1378 case EM_ST9PLUS: return "STMicroelectronics ST9+ 8/16 bit microcontroller";
1379 case EM_ST7: return "STMicroelectronics ST7 8-bit microcontroller";
1380 case EM_68HC16: return "Motorola MC68HC16 Microcontroller";
1381 case EM_68HC11: return "Motorola MC68HC11 Microcontroller";
1382 case EM_68HC08: return "Motorola MC68HC08 Microcontroller";
1383 case EM_68HC05: return "Motorola MC68HC05 Microcontroller";
1384 case EM_SVX: return "Silicon Graphics SVx";
1385 case EM_ST19: return "STMicroelectronics ST19 8-bit microcontroller";
1386 case EM_VAX: return "Digital VAX";
1388 case EM_AVR: return "Atmel AVR 8-bit microcontroller";
1389 case EM_CRIS: return "Axis Communications 32-bit embedded processor";
1390 case EM_JAVELIN: return "Infineon Technologies 32-bit embedded cpu";
1391 case EM_FIREPATH: return "Element 14 64-bit DSP processor";
1392 case EM_ZSP: return "LSI Logic's 16-bit DSP processor";
1393 case EM_MMIX: return "Donald Knuth's educational 64-bit processor";
1394 case EM_HUANY: return "Harvard Universitys's machine-independent object format";
1395 case EM_PRISM: return "SiTera Prism";
1396 case EM_X86_64: return "Advanced Micro Devices X86-64";
1398 case EM_S390: return "IBM S/390";
1400 sprintf (buff, _("<unknown>: %x"), e_machine);
1406 decode_ARM_machine_flags (e_flags, buf)
1413 eabi = EF_ARM_EABI_VERSION (e_flags);
1414 e_flags &= ~ EF_ARM_EABIMASK;
1416 /* Handle "generic" ARM flags. */
1417 if (e_flags & EF_ARM_RELEXEC)
1419 strcat (buf, ", relocatable executable");
1420 e_flags &= ~ EF_ARM_RELEXEC;
1423 if (e_flags & EF_ARM_HASENTRY)
1425 strcat (buf, ", has entry point");
1426 e_flags &= ~ EF_ARM_HASENTRY;
1429 /* Now handle EABI specific flags. */
1433 strcat (buf, ", <unrecognised EABI>");
1438 case EF_ARM_EABI_VER1:
1439 strcat (buf, ", Version1 EABI");
1444 /* Process flags one bit at a time. */
1445 flag = e_flags & - e_flags;
1450 case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK. */
1451 strcat (buf, ", sorted symbol tables");
1461 case EF_ARM_EABI_VER2:
1462 strcat (buf, ", Version2 EABI");
1467 /* Process flags one bit at a time. */
1468 flag = e_flags & - e_flags;
1473 case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK. */
1474 strcat (buf, ", sorted symbol tables");
1477 case EF_ARM_DYNSYMSUSESEGIDX:
1478 strcat (buf, ", dynamic symbols use segment index");
1481 case EF_ARM_MAPSYMSFIRST:
1482 strcat (buf, ", mapping symbols precede others");
1492 case EF_ARM_EABI_UNKNOWN:
1493 strcat (buf, ", GNU EABI");
1498 /* Process flags one bit at a time. */
1499 flag = e_flags & - e_flags;
1504 case EF_ARM_INTERWORK:
1505 strcat (buf, ", interworking enabled");
1508 case EF_ARM_APCS_26:
1509 strcat (buf, ", uses APCS/26");
1512 case EF_ARM_APCS_FLOAT:
1513 strcat (buf, ", uses APCS/float");
1517 strcat (buf, ", position independent");
1521 strcat (buf, ", 8 bit structure alignment");
1524 case EF_ARM_NEW_ABI:
1525 strcat (buf, ", uses new ABI");
1528 case EF_ARM_OLD_ABI:
1529 strcat (buf, ", uses old ABI");
1532 case EF_ARM_SOFT_FLOAT:
1533 strcat (buf, ", software FP");
1544 strcat (buf,", <unknown>");
1548 get_machine_flags (e_flags, e_machine)
1552 static char buf [1024];
1564 decode_ARM_machine_flags (e_flags, buf);
1568 if (e_flags & EF_CPU32)
1569 strcat (buf, ", cpu32");
1573 if (e_flags & EF_PPC_EMB)
1574 strcat (buf, ", emb");
1576 if (e_flags & EF_PPC_RELOCATABLE)
1577 strcat (buf, ", relocatable");
1579 if (e_flags & EF_PPC_RELOCATABLE_LIB)
1580 strcat (buf, ", relocatable-lib");
1584 case EM_CYGNUS_V850:
1585 switch (e_flags & EF_V850_ARCH)
1588 strcat (buf, ", v850e");
1591 strcat (buf, ", v850ea");
1594 strcat (buf, ", v850");
1597 strcat (buf, ", unknown v850 architecture variant");
1603 case EM_CYGNUS_M32R:
1604 if ((e_flags & EF_M32R_ARCH) == E_M32R_ARCH)
1605 strcat (buf, ", m32r");
1610 case EM_MIPS_RS3_LE:
1611 if (e_flags & EF_MIPS_NOREORDER)
1612 strcat (buf, ", noreorder");
1614 if (e_flags & EF_MIPS_PIC)
1615 strcat (buf, ", pic");
1617 if (e_flags & EF_MIPS_CPIC)
1618 strcat (buf, ", cpic");
1620 if (e_flags & EF_MIPS_UCODE)
1621 strcat (buf, ", ugen_reserved");
1623 if (e_flags & EF_MIPS_ABI2)
1624 strcat (buf, ", abi2");
1626 if (e_flags & EF_MIPS_32BITMODE)
1627 strcat (buf, ", 32bitmode");
1629 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_1)
1630 strcat (buf, ", mips1");
1632 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_2)
1633 strcat (buf, ", mips2");
1635 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_3)
1636 strcat (buf, ", mips3");
1638 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_4)
1639 strcat (buf, ", mips4");
1641 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_5)
1642 strcat (buf, ", mips5");
1644 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_32)
1645 strcat (buf, ", mips32");
1647 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_64)
1648 strcat (buf, ", mips64");
1650 switch ((e_flags & EF_MIPS_MACH))
1652 case E_MIPS_MACH_3900: strcat (buf, ", 3900"); break;
1653 case E_MIPS_MACH_4010: strcat (buf, ", 4010"); break;
1654 case E_MIPS_MACH_4100: strcat (buf, ", 4100"); break;
1655 case E_MIPS_MACH_4650: strcat (buf, ", 4650"); break;
1656 case E_MIPS_MACH_4111: strcat (buf, ", 4111"); break;
1657 case E_MIPS_MACH_SB1: strcat (buf, ", sb1"); break;
1658 default: strcat (buf, " UNKNOWN"); break;
1663 if (e_flags & EF_SPARC_32PLUS)
1664 strcat (buf, ", v8+");
1666 if (e_flags & EF_SPARC_SUN_US1)
1667 strcat (buf, ", ultrasparcI");
1669 if (e_flags & EF_SPARC_SUN_US3)
1670 strcat (buf, ", ultrasparcIII");
1672 if (e_flags & EF_SPARC_HAL_R1)
1673 strcat (buf, ", halr1");
1675 if (e_flags & EF_SPARC_LEDATA)
1676 strcat (buf, ", ledata");
1678 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_TSO)
1679 strcat (buf, ", tso");
1681 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_PSO)
1682 strcat (buf, ", pso");
1684 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_RMO)
1685 strcat (buf, ", rmo");
1689 switch (e_flags & EF_PARISC_ARCH)
1691 case EFA_PARISC_1_0:
1692 strcpy (buf, ", PA-RISC 1.0");
1694 case EFA_PARISC_1_1:
1695 strcpy (buf, ", PA-RISC 1.1");
1697 case EFA_PARISC_2_0:
1698 strcpy (buf, ", PA-RISC 2.0");
1703 if (e_flags & EF_PARISC_TRAPNIL)
1704 strcat (buf, ", trapnil");
1705 if (e_flags & EF_PARISC_EXT)
1706 strcat (buf, ", ext");
1707 if (e_flags & EF_PARISC_LSB)
1708 strcat (buf, ", lsb");
1709 if (e_flags & EF_PARISC_WIDE)
1710 strcat (buf, ", wide");
1711 if (e_flags & EF_PARISC_NO_KABP)
1712 strcat (buf, ", no kabp");
1713 if (e_flags & EF_PARISC_LAZYSWAP)
1714 strcat (buf, ", lazyswap");
1719 if ((e_flags & EF_PICOJAVA_NEWCALLS) == EF_PICOJAVA_NEWCALLS)
1720 strcat (buf, ", new calling convention");
1722 if ((e_flags & EF_PICOJAVA_GNUCALLS) == EF_PICOJAVA_GNUCALLS)
1723 strcat (buf, ", gnu calling convention");
1727 if ((e_flags & EF_IA_64_ABI64))
1728 strcat (buf, ", 64-bit");
1730 strcat (buf, ", 32-bit");
1731 if ((e_flags & EF_IA_64_REDUCEDFP))
1732 strcat (buf, ", reduced fp model");
1733 if ((e_flags & EF_IA_64_NOFUNCDESC_CONS_GP))
1734 strcat (buf, ", no function descriptors, constant gp");
1735 else if ((e_flags & EF_IA_64_CONS_GP))
1736 strcat (buf, ", constant gp");
1737 if ((e_flags & EF_IA_64_ABSOLUTE))
1738 strcat (buf, ", absolute");
1747 get_mips_segment_type (type)
1752 case PT_MIPS_REGINFO:
1754 case PT_MIPS_RTPROC:
1756 case PT_MIPS_OPTIONS:
1766 get_parisc_segment_type (type)
1771 case PT_HP_TLS: return "HP_TLS";
1772 case PT_HP_CORE_NONE: return "HP_CORE_NONE";
1773 case PT_HP_CORE_VERSION: return "HP_CORE_VERSION";
1774 case PT_HP_CORE_KERNEL: return "HP_CORE_KERNEL";
1775 case PT_HP_CORE_COMM: return "HP_CORE_COMM";
1776 case PT_HP_CORE_PROC: return "HP_CORE_PROC";
1777 case PT_HP_CORE_LOADABLE: return "HP_CORE_LOADABLE";
1778 case PT_HP_CORE_STACK: return "HP_CORE_STACK";
1779 case PT_HP_CORE_SHM: return "HP_CORE_SHM";
1780 case PT_HP_CORE_MMF: return "HP_CORE_MMF";
1781 case PT_HP_PARALLEL: return "HP_PARALLEL";
1782 case PT_HP_FASTBIND: return "HP_FASTBIND";
1783 case PT_PARISC_ARCHEXT: return "PARISC_ARCHEXT";
1784 case PT_PARISC_UNWIND: return "PARISC_UNWIND";
1793 get_ia64_segment_type (type)
1798 case PT_IA_64_ARCHEXT: return "IA_64_ARCHEXT";
1799 case PT_IA_64_UNWIND: return "IA_64_UNWIND";
1808 get_segment_type (p_type)
1809 unsigned long p_type;
1811 static char buff [32];
1815 case PT_NULL: return "NULL";
1816 case PT_LOAD: return "LOAD";
1817 case PT_DYNAMIC: return "DYNAMIC";
1818 case PT_INTERP: return "INTERP";
1819 case PT_NOTE: return "NOTE";
1820 case PT_SHLIB: return "SHLIB";
1821 case PT_PHDR: return "PHDR";
1824 if ((p_type >= PT_LOPROC) && (p_type <= PT_HIPROC))
1826 const char * result;
1828 switch (elf_header.e_machine)
1831 case EM_MIPS_RS3_LE:
1832 result = get_mips_segment_type (p_type);
1835 result = get_parisc_segment_type (p_type);
1838 result = get_ia64_segment_type (p_type);
1848 sprintf (buff, "LOPROC+%lx", p_type - PT_LOPROC);
1850 else if ((p_type >= PT_LOOS) && (p_type <= PT_HIOS))
1852 const char * result;
1854 switch (elf_header.e_machine)
1857 result = get_parisc_segment_type (p_type);
1867 sprintf (buff, "LOOS+%lx", p_type - PT_LOOS);
1870 sprintf (buff, _("<unknown>: %lx"), p_type);
1877 get_mips_section_type_name (sh_type)
1878 unsigned int sh_type;
1882 case SHT_MIPS_LIBLIST: return "MIPS_LIBLIST";
1883 case SHT_MIPS_MSYM: return "MIPS_MSYM";
1884 case SHT_MIPS_CONFLICT: return "MIPS_CONFLICT";
1885 case SHT_MIPS_GPTAB: return "MIPS_GPTAB";
1886 case SHT_MIPS_UCODE: return "MIPS_UCODE";
1887 case SHT_MIPS_DEBUG: return "MIPS_DEBUG";
1888 case SHT_MIPS_REGINFO: return "MIPS_REGINFO";
1889 case SHT_MIPS_PACKAGE: return "MIPS_PACKAGE";
1890 case SHT_MIPS_PACKSYM: return "MIPS_PACKSYM";
1891 case SHT_MIPS_RELD: return "MIPS_RELD";
1892 case SHT_MIPS_IFACE: return "MIPS_IFACE";
1893 case SHT_MIPS_CONTENT: return "MIPS_CONTENT";
1894 case SHT_MIPS_OPTIONS: return "MIPS_OPTIONS";
1895 case SHT_MIPS_SHDR: return "MIPS_SHDR";
1896 case SHT_MIPS_FDESC: return "MIPS_FDESC";
1897 case SHT_MIPS_EXTSYM: return "MIPS_EXTSYM";
1898 case SHT_MIPS_DENSE: return "MIPS_DENSE";
1899 case SHT_MIPS_PDESC: return "MIPS_PDESC";
1900 case SHT_MIPS_LOCSYM: return "MIPS_LOCSYM";
1901 case SHT_MIPS_AUXSYM: return "MIPS_AUXSYM";
1902 case SHT_MIPS_OPTSYM: return "MIPS_OPTSYM";
1903 case SHT_MIPS_LOCSTR: return "MIPS_LOCSTR";
1904 case SHT_MIPS_LINE: return "MIPS_LINE";
1905 case SHT_MIPS_RFDESC: return "MIPS_RFDESC";
1906 case SHT_MIPS_DELTASYM: return "MIPS_DELTASYM";
1907 case SHT_MIPS_DELTAINST: return "MIPS_DELTAINST";
1908 case SHT_MIPS_DELTACLASS: return "MIPS_DELTACLASS";
1909 case SHT_MIPS_DWARF: return "MIPS_DWARF";
1910 case SHT_MIPS_DELTADECL: return "MIPS_DELTADECL";
1911 case SHT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB";
1912 case SHT_MIPS_EVENTS: return "MIPS_EVENTS";
1913 case SHT_MIPS_TRANSLATE: return "MIPS_TRANSLATE";
1914 case SHT_MIPS_PIXIE: return "MIPS_PIXIE";
1915 case SHT_MIPS_XLATE: return "MIPS_XLATE";
1916 case SHT_MIPS_XLATE_DEBUG: return "MIPS_XLATE_DEBUG";
1917 case SHT_MIPS_WHIRL: return "MIPS_WHIRL";
1918 case SHT_MIPS_EH_REGION: return "MIPS_EH_REGION";
1919 case SHT_MIPS_XLATE_OLD: return "MIPS_XLATE_OLD";
1920 case SHT_MIPS_PDR_EXCEPTION: return "MIPS_PDR_EXCEPTION";
1928 get_parisc_section_type_name (sh_type)
1929 unsigned int sh_type;
1933 case SHT_PARISC_EXT: return "PARISC_EXT";
1934 case SHT_PARISC_UNWIND: return "PARISC_UNWIND";
1935 case SHT_PARISC_DOC: return "PARISC_DOC";
1943 get_ia64_section_type_name (sh_type)
1944 unsigned int sh_type;
1948 case SHT_IA_64_EXT: return "IA_64_EXT";
1949 case SHT_IA_64_UNWIND: return "IA_64_UNWIND";
1957 get_section_type_name (sh_type)
1958 unsigned int sh_type;
1960 static char buff [32];
1964 case SHT_NULL: return "NULL";
1965 case SHT_PROGBITS: return "PROGBITS";
1966 case SHT_SYMTAB: return "SYMTAB";
1967 case SHT_STRTAB: return "STRTAB";
1968 case SHT_RELA: return "RELA";
1969 case SHT_HASH: return "HASH";
1970 case SHT_DYNAMIC: return "DYNAMIC";
1971 case SHT_NOTE: return "NOTE";
1972 case SHT_NOBITS: return "NOBITS";
1973 case SHT_REL: return "REL";
1974 case SHT_SHLIB: return "SHLIB";
1975 case SHT_DYNSYM: return "DYNSYM";
1976 case SHT_INIT_ARRAY: return "INIT_ARRAY";
1977 case SHT_FINI_ARRAY: return "FINI_ARRAY";
1978 case SHT_PREINIT_ARRAY: return "PREINIT_ARRAY";
1979 case SHT_GROUP: return "GROUP";
1980 case SHT_SYMTAB_SHNDX: return "SYMTAB SECTION INDICIES";
1981 case SHT_GNU_verdef: return "VERDEF";
1982 case SHT_GNU_verneed: return "VERNEED";
1983 case SHT_GNU_versym: return "VERSYM";
1984 case 0x6ffffff0: return "VERSYM";
1985 case 0x6ffffffc: return "VERDEF";
1986 case 0x7ffffffd: return "AUXILIARY";
1987 case 0x7fffffff: return "FILTER";
1990 if ((sh_type >= SHT_LOPROC) && (sh_type <= SHT_HIPROC))
1992 const char * result;
1994 switch (elf_header.e_machine)
1997 case EM_MIPS_RS3_LE:
1998 result = get_mips_section_type_name (sh_type);
2001 result = get_parisc_section_type_name (sh_type);
2004 result = get_ia64_section_type_name (sh_type);
2014 sprintf (buff, "LOPROC+%x", sh_type - SHT_LOPROC);
2016 else if ((sh_type >= SHT_LOOS) && (sh_type <= SHT_HIOS))
2017 sprintf (buff, "LOOS+%x", sh_type - SHT_LOOS);
2018 else if ((sh_type >= SHT_LOUSER) && (sh_type <= SHT_HIUSER))
2019 sprintf (buff, "LOUSER+%x", sh_type - SHT_LOUSER);
2021 sprintf (buff, _("<unknown>: %x"), sh_type);
2027 struct option options [] =
2029 {"all", no_argument, 0, 'a'},
2030 {"file-header", no_argument, 0, 'h'},
2031 {"program-headers", no_argument, 0, 'l'},
2032 {"headers", no_argument, 0, 'e'},
2033 {"histogram", no_argument, 0, 'I'},
2034 {"segments", no_argument, 0, 'l'},
2035 {"sections", no_argument, 0, 'S'},
2036 {"section-headers", no_argument, 0, 'S'},
2037 {"symbols", no_argument, 0, 's'},
2038 {"syms", no_argument, 0, 's'},
2039 {"relocs", no_argument, 0, 'r'},
2040 {"notes", no_argument, 0, 'n'},
2041 {"dynamic", no_argument, 0, 'd'},
2042 {"arch-specific", no_argument, 0, 'A'},
2043 {"version-info", no_argument, 0, 'V'},
2044 {"use-dynamic", no_argument, 0, 'D'},
2045 {"hex-dump", required_argument, 0, 'x'},
2046 {"debug-dump", optional_argument, 0, 'w'},
2047 {"unwind", no_argument, 0, 'u'},
2048 #ifdef SUPPORT_DISASSEMBLY
2049 {"instruction-dump", required_argument, 0, 'i'},
2052 {"version", no_argument, 0, 'v'},
2053 {"wide", no_argument, 0, 'W'},
2054 {"help", no_argument, 0, 'H'},
2055 {0, no_argument, 0, 0}
2061 fprintf (stdout, _("Usage: readelf {options} elf-file(s)\n"));
2062 fprintf (stdout, _(" Options are:\n"));
2063 fprintf (stdout, _(" -a or --all Equivalent to: -h -l -S -s -r -d -V -A -I\n"));
2064 fprintf (stdout, _(" -h or --file-header Display the ELF file header\n"));
2065 fprintf (stdout, _(" -l or --program-headers or --segments\n"));
2066 fprintf (stdout, _(" Display the program headers\n"));
2067 fprintf (stdout, _(" -S or --section-headers or --sections\n"));
2068 fprintf (stdout, _(" Display the sections' header\n"));
2069 fprintf (stdout, _(" -e or --headers Equivalent to: -h -l -S\n"));
2070 fprintf (stdout, _(" -s or --syms or --symbols Display the symbol table\n"));
2071 fprintf (stdout, _(" -n or --notes Display the core notes (if present)\n"));
2072 fprintf (stdout, _(" -r or --relocs Display the relocations (if present)\n"));
2073 fprintf (stdout, _(" -u or --unwind Display the unwind info (if present)\n"));
2074 fprintf (stdout, _(" -d or --dynamic Display the dynamic segment (if present)\n"));
2075 fprintf (stdout, _(" -V or --version-info Display the version sections (if present)\n"));
2076 fprintf (stdout, _(" -A or --arch-specific Display architecture specific information (if any).\n"));
2077 fprintf (stdout, _(" -D or --use-dynamic Use the dynamic section info when displaying symbols\n"));
2078 fprintf (stdout, _(" -x <number> or --hex-dump=<number>\n"));
2079 fprintf (stdout, _(" Dump the contents of section <number>\n"));
2080 fprintf (stdout, _(" -w[liaprmfs] or --debug-dump[=line,=info,=abbrev,=pubnames,=ranges,=macro,=frames,=str]\n"));
2081 fprintf (stdout, _(" Display the contents of DWARF2 debug sections\n"));
2082 #ifdef SUPPORT_DISASSEMBLY
2083 fprintf (stdout, _(" -i <number> or --instruction-dump=<number>\n"));
2084 fprintf (stdout, _(" Disassemble the contents of section <number>\n"));
2086 fprintf (stdout, _(" -I or --histogram Display histogram of bucket list lengths\n"));
2087 fprintf (stdout, _(" -v or --version Display the version number of readelf\n"));
2088 fprintf (stdout, _(" -W or --wide Don't split lines to fit into 80 columns\n"));
2089 fprintf (stdout, _(" -H or --help Display this information\n"));
2090 fprintf (stdout, _("Report bugs to %s\n"), REPORT_BUGS_TO);
2096 request_dump (section, type)
2097 unsigned int section;
2100 if (section >= num_dump_sects)
2102 char * new_dump_sects;
2104 new_dump_sects = (char *) calloc (section + 1, 1);
2106 if (new_dump_sects == NULL)
2107 error (_("Out of memory allocating dump request table."));
2110 /* Copy current flag settings. */
2111 memcpy (new_dump_sects, dump_sects, num_dump_sects);
2115 dump_sects = new_dump_sects;
2116 num_dump_sects = section + 1;
2121 dump_sects [section] |= type;
2127 parse_args (argc, argv)
2136 while ((c = getopt_long
2137 (argc, argv, "ersuahnldSDAIw::x:i:vVW", options, NULL)) != EOF)
2173 do_using_dynamic ++;
2204 section = strtoul (optarg, & cp, 0);
2205 if (! * cp && section >= 0)
2207 request_dump (section, HEX_DUMP);
2217 unsigned int index = 0;
2221 while (optarg[index])
2222 switch (optarg[index++])
2231 do_debug_abbrevs = 1;
2241 do_debug_pubnames = 1;
2246 do_debug_aranges = 1;
2250 do_debug_frames_interp = 1;
2252 do_debug_frames = 1;
2257 do_debug_macinfo = 1;
2266 warn (_("Unrecognised debug option '%s'\n"), optarg);
2271 #ifdef SUPPORT_DISASSEMBLY
2274 section = strtoul (optarg, & cp, 0);
2275 if (! * cp && section >= 0)
2277 request_dump (section, DISASS_DUMP);
2283 print_version (program_name);
2293 /* xgettext:c-format */
2294 error (_("Invalid option '-%c'\n"), c);
2301 if (!do_dynamic && !do_syms && !do_reloc && !do_unwind && !do_sections
2302 && !do_segments && !do_header && !do_dump && !do_version
2303 && !do_histogram && !do_debugging && !do_arch && !do_notes)
2307 warn (_("Nothing to do.\n"));
2313 get_elf_class (elf_class)
2314 unsigned int elf_class;
2316 static char buff [32];
2320 case ELFCLASSNONE: return _("none");
2321 case ELFCLASS32: return "ELF32";
2322 case ELFCLASS64: return "ELF64";
2324 sprintf (buff, _("<unknown: %x>"), elf_class);
2330 get_data_encoding (encoding)
2331 unsigned int encoding;
2333 static char buff [32];
2337 case ELFDATANONE: return _("none");
2338 case ELFDATA2LSB: return _("2's complement, little endian");
2339 case ELFDATA2MSB: return _("2's complement, big endian");
2341 sprintf (buff, _("<unknown: %x>"), encoding);
2347 get_osabi_name (osabi)
2350 static char buff [32];
2354 case ELFOSABI_NONE: return "UNIX - System V";
2355 case ELFOSABI_HPUX: return "UNIX - HP-UX";
2356 case ELFOSABI_NETBSD: return "UNIX - NetBSD";
2357 case ELFOSABI_LINUX: return "UNIX - Linux";
2358 case ELFOSABI_HURD: return "GNU/Hurd";
2359 case ELFOSABI_SOLARIS: return "UNIX - Solaris";
2360 case ELFOSABI_AIX: return "UNIX - AIX";
2361 case ELFOSABI_IRIX: return "UNIX - IRIX";
2362 case ELFOSABI_FREEBSD: return "UNIX - FreeBSD";
2363 case ELFOSABI_TRU64: return "UNIX - TRU64";
2364 case ELFOSABI_MODESTO: return "Novell - Modesto";
2365 case ELFOSABI_OPENBSD: return "UNIX - OpenBSD";
2366 case ELFOSABI_STANDALONE: return _("Standalone App");
2367 case ELFOSABI_ARM: return "ARM";
2369 sprintf (buff, _("<unknown: %x>"), osabi);
2374 /* Decode the data held in 'elf_header'. */
2376 process_file_header ()
2378 if ( elf_header.e_ident [EI_MAG0] != ELFMAG0
2379 || elf_header.e_ident [EI_MAG1] != ELFMAG1
2380 || elf_header.e_ident [EI_MAG2] != ELFMAG2
2381 || elf_header.e_ident [EI_MAG3] != ELFMAG3)
2384 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
2392 printf (_("ELF Header:\n"));
2393 printf (_(" Magic: "));
2394 for (i = 0; i < EI_NIDENT; i ++)
2395 printf ("%2.2x ", elf_header.e_ident [i]);
2397 printf (_(" Class: %s\n"),
2398 get_elf_class (elf_header.e_ident [EI_CLASS]));
2399 printf (_(" Data: %s\n"),
2400 get_data_encoding (elf_header.e_ident [EI_DATA]));
2401 printf (_(" Version: %d %s\n"),
2402 elf_header.e_ident [EI_VERSION],
2403 (elf_header.e_ident [EI_VERSION] == EV_CURRENT
2405 : (elf_header.e_ident [EI_VERSION] != EV_NONE
2408 printf (_(" OS/ABI: %s\n"),
2409 get_osabi_name (elf_header.e_ident [EI_OSABI]));
2410 printf (_(" ABI Version: %d\n"),
2411 elf_header.e_ident [EI_ABIVERSION]);
2412 printf (_(" Type: %s\n"),
2413 get_file_type (elf_header.e_type));
2414 printf (_(" Machine: %s\n"),
2415 get_machine_name (elf_header.e_machine));
2416 printf (_(" Version: 0x%lx\n"),
2417 (unsigned long) elf_header.e_version);
2419 printf (_(" Entry point address: "));
2420 print_vma ((bfd_vma) elf_header.e_entry, PREFIX_HEX);
2421 printf (_("\n Start of program headers: "));
2422 print_vma ((bfd_vma) elf_header.e_phoff, DEC);
2423 printf (_(" (bytes into file)\n Start of section headers: "));
2424 print_vma ((bfd_vma) elf_header.e_shoff, DEC);
2425 printf (_(" (bytes into file)\n"));
2427 printf (_(" Flags: 0x%lx%s\n"),
2428 (unsigned long) elf_header.e_flags,
2429 get_machine_flags (elf_header.e_flags, elf_header.e_machine));
2430 printf (_(" Size of this header: %ld (bytes)\n"),
2431 (long) elf_header.e_ehsize);
2432 printf (_(" Size of program headers: %ld (bytes)\n"),
2433 (long) elf_header.e_phentsize);
2434 printf (_(" Number of program headers: %ld\n"),
2435 (long) elf_header.e_phnum);
2436 printf (_(" Size of section headers: %ld (bytes)\n"),
2437 (long) elf_header.e_shentsize);
2438 printf (_(" Number of section headers: %ld\n"),
2439 (long) elf_header.e_shnum);
2440 printf (_(" Section header string table index: %ld\n"),
2441 (long) elf_header.e_shstrndx);
2449 get_32bit_program_headers (file, program_headers)
2451 Elf_Internal_Phdr * program_headers;
2453 Elf32_External_Phdr * phdrs;
2454 Elf32_External_Phdr * external;
2455 Elf32_Internal_Phdr * internal;
2458 phdrs = ((Elf32_External_Phdr *)
2459 get_data (NULL, file, elf_header.e_phoff,
2460 elf_header.e_phentsize * elf_header.e_phnum,
2461 _("program headers")));
2465 for (i = 0, internal = program_headers, external = phdrs;
2466 i < elf_header.e_phnum;
2467 i ++, internal ++, external ++)
2469 internal->p_type = BYTE_GET (external->p_type);
2470 internal->p_offset = BYTE_GET (external->p_offset);
2471 internal->p_vaddr = BYTE_GET (external->p_vaddr);
2472 internal->p_paddr = BYTE_GET (external->p_paddr);
2473 internal->p_filesz = BYTE_GET (external->p_filesz);
2474 internal->p_memsz = BYTE_GET (external->p_memsz);
2475 internal->p_flags = BYTE_GET (external->p_flags);
2476 internal->p_align = BYTE_GET (external->p_align);
2485 get_64bit_program_headers (file, program_headers)
2487 Elf_Internal_Phdr * program_headers;
2489 Elf64_External_Phdr * phdrs;
2490 Elf64_External_Phdr * external;
2491 Elf64_Internal_Phdr * internal;
2494 phdrs = ((Elf64_External_Phdr *)
2495 get_data (NULL, file, elf_header.e_phoff,
2496 elf_header.e_phentsize * elf_header.e_phnum,
2497 _("program headers")));
2501 for (i = 0, internal = program_headers, external = phdrs;
2502 i < elf_header.e_phnum;
2503 i ++, internal ++, external ++)
2505 internal->p_type = BYTE_GET (external->p_type);
2506 internal->p_flags = BYTE_GET (external->p_flags);
2507 internal->p_offset = BYTE_GET8 (external->p_offset);
2508 internal->p_vaddr = BYTE_GET8 (external->p_vaddr);
2509 internal->p_paddr = BYTE_GET8 (external->p_paddr);
2510 internal->p_filesz = BYTE_GET8 (external->p_filesz);
2511 internal->p_memsz = BYTE_GET8 (external->p_memsz);
2512 internal->p_align = BYTE_GET8 (external->p_align);
2521 process_program_headers (file)
2524 Elf_Internal_Phdr * program_headers;
2525 Elf_Internal_Phdr * segment;
2528 if (elf_header.e_phnum == 0)
2531 printf (_("\nThere are no program headers in this file.\n"));
2535 if (do_segments && !do_header)
2537 printf (_("\nElf file type is %s\n"), get_file_type (elf_header.e_type));
2538 printf (_("Entry point "));
2539 print_vma ((bfd_vma) elf_header.e_entry, PREFIX_HEX);
2540 printf (_("\nThere are %d program headers, starting at offset "),
2541 elf_header.e_phnum);
2542 print_vma ((bfd_vma) elf_header.e_phoff, DEC);
2546 program_headers = (Elf_Internal_Phdr *) malloc
2547 (elf_header.e_phnum * sizeof (Elf_Internal_Phdr));
2549 if (program_headers == NULL)
2551 error (_("Out of memory\n"));
2556 i = get_32bit_program_headers (file, program_headers);
2558 i = get_64bit_program_headers (file, program_headers);
2562 free (program_headers);
2569 (_("\nProgram Header%s:\n"), elf_header.e_phnum > 1 ? "s" : "");
2573 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
2576 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
2580 (_(" Type Offset VirtAddr PhysAddr\n"));
2582 (_(" FileSiz MemSiz Flags Align\n"));
2590 for (i = 0, segment = program_headers;
2591 i < elf_header.e_phnum;
2596 printf (" %-14.14s ", get_segment_type (segment->p_type));
2600 printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
2601 printf ("0x%8.8lx ", (unsigned long) segment->p_vaddr);
2602 printf ("0x%8.8lx ", (unsigned long) segment->p_paddr);
2603 printf ("0x%5.5lx ", (unsigned long) segment->p_filesz);
2604 printf ("0x%5.5lx ", (unsigned long) segment->p_memsz);
2606 (segment->p_flags & PF_R ? 'R' : ' '),
2607 (segment->p_flags & PF_W ? 'W' : ' '),
2608 (segment->p_flags & PF_X ? 'E' : ' '));
2609 printf ("%#lx", (unsigned long) segment->p_align);
2613 if ((unsigned long) segment->p_offset == segment->p_offset)
2614 printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
2617 print_vma (segment->p_offset, FULL_HEX);
2621 print_vma (segment->p_vaddr, FULL_HEX);
2623 print_vma (segment->p_paddr, FULL_HEX);
2626 if ((unsigned long) segment->p_filesz == segment->p_filesz)
2627 printf ("0x%6.6lx ", (unsigned long) segment->p_filesz);
2630 print_vma (segment->p_filesz, FULL_HEX);
2634 if ((unsigned long) segment->p_memsz == segment->p_memsz)
2635 printf ("0x%6.6lx", (unsigned long) segment->p_memsz);
2638 print_vma (segment->p_offset, FULL_HEX);
2642 (segment->p_flags & PF_R ? 'R' : ' '),
2643 (segment->p_flags & PF_W ? 'W' : ' '),
2644 (segment->p_flags & PF_X ? 'E' : ' '));
2646 if ((unsigned long) segment->p_align == segment->p_align)
2647 printf ("%#lx", (unsigned long) segment->p_align);
2650 print_vma (segment->p_align, PREFIX_HEX);
2655 print_vma (segment->p_offset, FULL_HEX);
2657 print_vma (segment->p_vaddr, FULL_HEX);
2659 print_vma (segment->p_paddr, FULL_HEX);
2661 print_vma (segment->p_filesz, FULL_HEX);
2663 print_vma (segment->p_memsz, FULL_HEX);
2665 (segment->p_flags & PF_R ? 'R' : ' '),
2666 (segment->p_flags & PF_W ? 'W' : ' '),
2667 (segment->p_flags & PF_X ? 'E' : ' '));
2668 print_vma (segment->p_align, HEX);
2672 switch (segment->p_type)
2676 loadaddr = (segment->p_vaddr & 0xfffff000)
2677 - (segment->p_offset & 0xfffff000);
2682 error (_("more than one dynamic segment\n"));
2684 dynamic_addr = segment->p_offset;
2685 dynamic_size = segment->p_filesz;
2689 if (fseek (file, (long) segment->p_offset, SEEK_SET))
2690 error (_("Unable to find program interpreter name\n"));
2693 program_interpreter[0] = 0;
2694 fscanf (file, "%63s", program_interpreter);
2697 printf (_("\n [Requesting program interpreter: %s]"),
2698 program_interpreter);
2704 putc ('\n', stdout);
2713 if (do_segments && section_headers != NULL)
2715 printf (_("\n Section to Segment mapping:\n"));
2716 printf (_(" Segment Sections...\n"));
2718 assert (string_table != NULL);
2720 for (i = 0; i < elf_header.e_phnum; i++)
2723 Elf_Internal_Shdr * section;
2725 segment = program_headers + i;
2726 section = section_headers;
2728 printf (" %2.2d ", i);
2730 for (j = 0; j < elf_header.e_shnum; j++, section ++)
2732 if (section->sh_size > 0
2733 /* Compare allocated sections by VMA, unallocated
2734 sections by file offset. */
2735 && (section->sh_flags & SHF_ALLOC
2736 ? (section->sh_addr >= segment->p_vaddr
2737 && section->sh_addr + section->sh_size
2738 <= segment->p_vaddr + segment->p_memsz)
2739 : ((bfd_vma) section->sh_offset >= segment->p_offset
2740 && (section->sh_offset + section->sh_size
2741 <= segment->p_offset + segment->p_filesz))))
2742 printf ("%s ", SECTION_NAME (section));
2749 free (program_headers);
2756 get_32bit_section_headers (file)
2759 Elf32_External_Shdr * shdrs;
2760 Elf32_Internal_Shdr * internal;
2763 shdrs = ((Elf32_External_Shdr *)
2764 get_data (NULL, file, elf_header.e_shoff,
2765 elf_header.e_shentsize * elf_header.e_shnum,
2766 _("section headers")));
2770 section_headers = (Elf_Internal_Shdr *) malloc
2771 (elf_header.e_shnum * sizeof (Elf_Internal_Shdr));
2773 if (section_headers == NULL)
2775 error (_("Out of memory\n"));
2779 for (i = 0, internal = section_headers;
2780 i < elf_header.e_shnum;
2783 internal->sh_name = BYTE_GET (shdrs[i].sh_name);
2784 internal->sh_type = BYTE_GET (shdrs[i].sh_type);
2785 internal->sh_flags = BYTE_GET (shdrs[i].sh_flags);
2786 internal->sh_addr = BYTE_GET (shdrs[i].sh_addr);
2787 internal->sh_offset = BYTE_GET (shdrs[i].sh_offset);
2788 internal->sh_size = BYTE_GET (shdrs[i].sh_size);
2789 internal->sh_link = BYTE_GET (shdrs[i].sh_link);
2790 internal->sh_info = BYTE_GET (shdrs[i].sh_info);
2791 internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
2792 internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize);
2801 get_64bit_section_headers (file)
2804 Elf64_External_Shdr * shdrs;
2805 Elf64_Internal_Shdr * internal;
2808 shdrs = ((Elf64_External_Shdr *)
2809 get_data (NULL, file, elf_header.e_shoff,
2810 elf_header.e_shentsize * elf_header.e_shnum,
2811 _("section headers")));
2815 section_headers = (Elf_Internal_Shdr *) malloc
2816 (elf_header.e_shnum * sizeof (Elf_Internal_Shdr));
2818 if (section_headers == NULL)
2820 error (_("Out of memory\n"));
2824 for (i = 0, internal = section_headers;
2825 i < elf_header.e_shnum;
2828 internal->sh_name = BYTE_GET (shdrs[i].sh_name);
2829 internal->sh_type = BYTE_GET (shdrs[i].sh_type);
2830 internal->sh_flags = BYTE_GET8 (shdrs[i].sh_flags);
2831 internal->sh_addr = BYTE_GET8 (shdrs[i].sh_addr);
2832 internal->sh_size = BYTE_GET8 (shdrs[i].sh_size);
2833 internal->sh_entsize = BYTE_GET8 (shdrs[i].sh_entsize);
2834 internal->sh_link = BYTE_GET (shdrs[i].sh_link);
2835 internal->sh_info = BYTE_GET (shdrs[i].sh_info);
2836 internal->sh_offset = BYTE_GET (shdrs[i].sh_offset);
2837 internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
2845 static Elf_Internal_Sym *
2846 get_32bit_elf_symbols (file, offset, number)
2848 unsigned long offset;
2849 unsigned long number;
2851 Elf32_External_Sym * esyms;
2852 Elf_Internal_Sym * isyms;
2853 Elf_Internal_Sym * psym;
2856 esyms = ((Elf32_External_Sym *)
2857 get_data (NULL, file, offset,
2858 number * sizeof (Elf32_External_Sym), _("symbols")));
2862 isyms = (Elf_Internal_Sym *) malloc (number * sizeof (Elf_Internal_Sym));
2866 error (_("Out of memory\n"));
2872 for (j = 0, psym = isyms;
2876 psym->st_name = BYTE_GET (esyms[j].st_name);
2877 psym->st_value = BYTE_GET (esyms[j].st_value);
2878 psym->st_size = BYTE_GET (esyms[j].st_size);
2879 psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
2880 psym->st_info = BYTE_GET (esyms[j].st_info);
2881 psym->st_other = BYTE_GET (esyms[j].st_other);
2889 static Elf_Internal_Sym *
2890 get_64bit_elf_symbols (file, offset, number)
2892 unsigned long offset;
2893 unsigned long number;
2895 Elf64_External_Sym * esyms;
2896 Elf_Internal_Sym * isyms;
2897 Elf_Internal_Sym * psym;
2900 esyms = ((Elf64_External_Sym *)
2901 get_data (NULL, file, offset,
2902 number * sizeof (Elf64_External_Sym), _("symbols")));
2906 isyms = (Elf_Internal_Sym *) malloc (number * sizeof (Elf_Internal_Sym));
2910 error (_("Out of memory\n"));
2916 for (j = 0, psym = isyms;
2920 psym->st_name = BYTE_GET (esyms[j].st_name);
2921 psym->st_info = BYTE_GET (esyms[j].st_info);
2922 psym->st_other = BYTE_GET (esyms[j].st_other);
2923 psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
2924 psym->st_value = BYTE_GET8 (esyms[j].st_value);
2925 psym->st_size = BYTE_GET8 (esyms[j].st_size);
2934 get_elf_section_flags (sh_flags)
2937 static char buff [32];
2945 flag = sh_flags & - sh_flags;
2950 case SHF_WRITE: strcat (buff, "W"); break;
2951 case SHF_ALLOC: strcat (buff, "A"); break;
2952 case SHF_EXECINSTR: strcat (buff, "X"); break;
2953 case SHF_MERGE: strcat (buff, "M"); break;
2954 case SHF_STRINGS: strcat (buff, "S"); break;
2955 case SHF_INFO_LINK: strcat (buff, "I"); break;
2956 case SHF_LINK_ORDER: strcat (buff, "L"); break;
2957 case SHF_OS_NONCONFORMING: strcat (buff, "O"); break;
2958 case SHF_GROUP: strcat (buff, "G"); break;
2961 if (flag & SHF_MASKOS)
2964 sh_flags &= ~ SHF_MASKOS;
2966 else if (flag & SHF_MASKPROC)
2969 sh_flags &= ~ SHF_MASKPROC;
2981 process_section_headers (file)
2984 Elf_Internal_Shdr * section;
2987 section_headers = NULL;
2989 if (elf_header.e_shnum == 0)
2992 printf (_("\nThere are no sections in this file.\n"));
2997 if (do_sections && !do_header)
2998 printf (_("There are %d section headers, starting at offset 0x%lx:\n"),
2999 elf_header.e_shnum, (unsigned long) elf_header.e_shoff);
3003 if (! get_32bit_section_headers (file))
3006 else if (! get_64bit_section_headers (file))
3009 /* Read in the string table, so that we have names to display. */
3010 section = section_headers + elf_header.e_shstrndx;
3012 if (section->sh_size != 0)
3014 string_table = (char *) get_data (NULL, file, section->sh_offset,
3015 section->sh_size, _("string table"));
3017 string_table_length = section->sh_size;
3020 /* Scan the sections for the dynamic symbol table
3021 and dynamic string table and debug sections. */
3022 dynamic_symbols = NULL;
3023 dynamic_strings = NULL;
3024 dynamic_syminfo = NULL;
3026 for (i = 0, section = section_headers;
3027 i < elf_header.e_shnum;
3030 char * name = SECTION_NAME (section);
3032 if (section->sh_type == SHT_DYNSYM)
3034 if (dynamic_symbols != NULL)
3036 error (_("File contains multiple dynamic symbol tables\n"));
3040 num_dynamic_syms = section->sh_size / section->sh_entsize;
3042 GET_ELF_SYMBOLS (file, section->sh_offset, num_dynamic_syms);
3044 else if (section->sh_type == SHT_STRTAB
3045 && strcmp (name, ".dynstr") == 0)
3047 if (dynamic_strings != NULL)
3049 error (_("File contains multiple dynamic string tables\n"));
3053 dynamic_strings = (char *) get_data (NULL, file, section->sh_offset,
3055 _("dynamic strings"));
3057 else if ((do_debugging || do_debug_info || do_debug_abbrevs
3058 || do_debug_lines || do_debug_pubnames || do_debug_aranges
3059 || do_debug_frames || do_debug_macinfo || do_debug_str)
3060 && strncmp (name, ".debug_", 7) == 0)
3065 || (do_debug_info && (strcmp (name, "info") == 0))
3066 || (do_debug_abbrevs && (strcmp (name, "abbrev") == 0))
3067 || (do_debug_lines && (strcmp (name, "line") == 0))
3068 || (do_debug_pubnames && (strcmp (name, "pubnames") == 0))
3069 || (do_debug_aranges && (strcmp (name, "aranges") == 0))
3070 || (do_debug_frames && (strcmp (name, "frame") == 0))
3071 || (do_debug_macinfo && (strcmp (name, "macinfo") == 0))
3072 || (do_debug_str && (strcmp (name, "str") == 0))
3074 request_dump (i, DEBUG_DUMP);
3076 /* linkonce section to be combined with .debug_info at link time. */
3077 else if ((do_debugging || do_debug_info)
3078 && strncmp (name, ".gnu.linkonce.wi.", 17) == 0)
3079 request_dump (i, DEBUG_DUMP);
3080 else if (do_debug_frames && strcmp (name, ".eh_frame") == 0)
3081 request_dump (i, DEBUG_DUMP);
3087 printf (_("\nSection Header%s:\n"), elf_header.e_shnum > 1 ? "s" : "");
3091 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
3094 (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n"));
3097 printf (_(" [Nr] Name Type Address Offset\n"));
3098 printf (_(" Size EntSize Flags Link Info Align\n"));
3101 for (i = 0, section = section_headers;
3102 i < elf_header.e_shnum;
3105 printf (" [%2d] %-17.17s %-15.15s ",
3107 SECTION_NAME (section),
3108 get_section_type_name (section->sh_type));
3112 print_vma (section->sh_addr, LONG_HEX);
3114 printf ( " %6.6lx %6.6lx %2.2lx",
3115 (unsigned long) section->sh_offset,
3116 (unsigned long) section->sh_size,
3117 (unsigned long) section->sh_entsize);
3119 printf (" %3s ", get_elf_section_flags (section->sh_flags));
3121 printf ("%2ld %3lx %2ld\n",
3122 (unsigned long) section->sh_link,
3123 (unsigned long) section->sh_info,
3124 (unsigned long) section->sh_addralign);
3128 print_vma (section->sh_addr, LONG_HEX);
3130 if ((long) section->sh_offset == section->sh_offset)
3131 printf (" %6.6lx", (unsigned long) section->sh_offset);
3135 print_vma (section->sh_offset, LONG_HEX);
3138 if ((unsigned long) section->sh_size == section->sh_size)
3139 printf (" %6.6lx", (unsigned long) section->sh_size);
3143 print_vma (section->sh_size, LONG_HEX);
3146 if ((unsigned long) section->sh_entsize == section->sh_entsize)
3147 printf (" %2.2lx", (unsigned long) section->sh_entsize);
3151 print_vma (section->sh_entsize, LONG_HEX);
3154 printf (" %3s ", get_elf_section_flags (section->sh_flags));
3156 printf ("%2ld %3lx ",
3157 (unsigned long) section->sh_link,
3158 (unsigned long) section->sh_info);
3160 if ((unsigned long) section->sh_addralign == section->sh_addralign)
3161 printf ("%2ld\n", (unsigned long) section->sh_addralign);
3164 print_vma (section->sh_addralign, DEC);
3171 print_vma (section->sh_addr, LONG_HEX);
3172 if ((long) section->sh_offset == section->sh_offset)
3173 printf (" %8.8lx", (unsigned long) section->sh_offset);
3177 print_vma (section->sh_offset, LONG_HEX);
3180 print_vma (section->sh_size, LONG_HEX);
3182 print_vma (section->sh_entsize, LONG_HEX);
3184 printf (" %3s ", get_elf_section_flags (section->sh_flags));
3186 printf (" %2ld %3lx %ld\n",
3187 (unsigned long) section->sh_link,
3188 (unsigned long) section->sh_info,
3189 (unsigned long) section->sh_addralign);
3193 printf (_("Key to Flags:\n\
3194 W (write), A (alloc), X (execute), M (merge), S (strings)\n\
3195 I (info), L (link order), G (group), x (unknown)\n\
3196 O (extra OS processing required) o (OS specific), p (processor specific)\n"));
3201 /* Process the reloc section. */
3203 process_relocs (file)
3206 unsigned long rel_size;
3207 unsigned long rel_offset;
3213 if (do_using_dynamic)
3215 int is_rela = FALSE;
3220 if (dynamic_info[DT_REL])
3222 rel_offset = dynamic_info[DT_REL];
3223 rel_size = dynamic_info[DT_RELSZ];
3226 else if (dynamic_info [DT_RELA])
3228 rel_offset = dynamic_info[DT_RELA];
3229 rel_size = dynamic_info[DT_RELASZ];
3232 else if (dynamic_info[DT_JMPREL])
3234 rel_offset = dynamic_info[DT_JMPREL];
3235 rel_size = dynamic_info[DT_PLTRELSZ];
3237 switch (dynamic_info[DT_PLTREL])
3254 (_("\nRelocation section at offset 0x%lx contains %ld bytes:\n"),
3255 rel_offset, rel_size);
3257 dump_relocations (file, rel_offset - loadaddr, rel_size,
3258 dynamic_symbols, num_dynamic_syms, dynamic_strings, is_rela);
3261 printf (_("\nThere are no dynamic relocations in this file.\n"));
3265 Elf32_Internal_Shdr * section;
3269 for (i = 0, section = section_headers;
3270 i < elf_header.e_shnum;
3273 if ( section->sh_type != SHT_RELA
3274 && section->sh_type != SHT_REL)
3277 rel_offset = section->sh_offset;
3278 rel_size = section->sh_size;
3282 Elf32_Internal_Shdr * strsec;
3283 Elf_Internal_Sym * symtab;
3286 unsigned long nsyms;
3288 printf (_("\nRelocation section "));
3290 if (string_table == NULL)
3291 printf ("%d", section->sh_name);
3293 printf ("'%s'", SECTION_NAME (section));
3295 printf (_(" at offset 0x%lx contains %lu entries:\n"),
3296 rel_offset, (unsigned long) (rel_size / section->sh_entsize));
3301 if (section->sh_link)
3303 Elf32_Internal_Shdr * symsec;
3305 symsec = section_headers + section->sh_link;
3306 nsyms = symsec->sh_size / symsec->sh_entsize;
3307 symtab = GET_ELF_SYMBOLS (file, symsec->sh_offset, nsyms);
3312 strsec = section_headers + symsec->sh_link;
3314 strtab = (char *) get_data (NULL, file, strsec->sh_offset,
3318 is_rela = section->sh_type == SHT_RELA;
3320 dump_relocations (file, rel_offset, rel_size,
3321 symtab, nsyms, strtab, is_rela);
3333 printf (_("\nThere are no relocations in this file.\n"));
3339 #include "unwind-ia64.h"
3341 /* An absolute address consists of a section and an offset. If the
3342 section is NULL, the offset itself is the address, otherwise, the
3343 address equals to LOAD_ADDRESS(section) + offset. */
3347 unsigned short section;
3353 struct unw_table_entry
3355 struct absaddr start;
3357 struct absaddr info;
3359 *table; /* Unwind table. */
3360 unsigned long table_len; /* Length of unwind table. */
3361 unsigned char * info; /* Unwind info. */
3362 unsigned long info_size; /* Size of unwind info. */
3363 bfd_vma info_addr; /* starting address of unwind info. */
3364 bfd_vma seg_base; /* Starting address of segment. */
3365 Elf_Internal_Sym * symtab; /* The symbol table. */
3366 unsigned long nsyms; /* Number of symbols. */
3367 char * strtab; /* The string table. */
3368 unsigned long strtab_size; /* Size of string table. */
3371 static void find_symbol_for_address PARAMS ((struct unw_aux_info *,
3372 struct absaddr, const char **,
3374 static void dump_ia64_unwind PARAMS ((struct unw_aux_info *));
3375 static int slurp_ia64_unwind_table PARAMS ((FILE *, struct unw_aux_info *,
3376 Elf32_Internal_Shdr *));
3379 find_symbol_for_address (aux, addr, symname, offset)
3380 struct unw_aux_info *aux;
3381 struct absaddr addr;
3382 const char **symname;
3385 bfd_vma dist = (bfd_vma) 0x100000;
3386 Elf_Internal_Sym *sym, *best = NULL;
3389 for (i = 0, sym = aux->symtab; i < aux->nsyms; ++i, ++sym)
3391 if (ELF_ST_TYPE (sym->st_info) == STT_FUNC
3392 && sym->st_name != 0
3393 && (addr.section == SHN_UNDEF || addr.section == sym->st_shndx)
3394 && addr.offset >= sym->st_value
3395 && addr.offset - sym->st_value < dist)
3398 dist = addr.offset - sym->st_value;
3405 *symname = (best->st_name >= aux->strtab_size
3406 ? "<corrupt>" : aux->strtab + best->st_name);
3411 *offset = addr.offset;
3415 dump_ia64_unwind (aux)
3416 struct unw_aux_info *aux;
3419 struct unw_table_entry * tp;
3422 addr_size = is_32bit_elf ? 4 : 8;
3424 for (tp = aux->table; tp < aux->table + aux->table_len; ++tp)
3428 const unsigned char * dp;
3429 const unsigned char * head;
3430 const char * procname;
3432 find_symbol_for_address (aux, tp->start, &procname, &offset);
3434 fputs ("\n<", stdout);
3438 fputs (procname, stdout);
3441 printf ("+%lx", (unsigned long) offset);
3444 fputs (">: [", stdout);
3445 print_vma (tp->start.offset, PREFIX_HEX);
3446 fputc ('-', stdout);
3447 print_vma (tp->end.offset, PREFIX_HEX);
3448 printf ("), info at +0x%lx\n",
3449 (unsigned long) (tp->info.offset - aux->seg_base));
3451 head = aux->info + (tp->info.offset - aux->info_addr);
3452 stamp = BYTE_GET8 ((unsigned char *) head);
3454 printf (" v%u, flags=0x%lx (%s%s ), len=%lu bytes\n",
3455 (unsigned) UNW_VER (stamp),
3456 (unsigned long) ((stamp & UNW_FLAG_MASK) >> 32),
3457 UNW_FLAG_EHANDLER (stamp) ? " ehandler" : "",
3458 UNW_FLAG_UHANDLER (stamp) ? " uhandler" : "",
3459 (unsigned long) (addr_size * UNW_LENGTH (stamp)));
3461 if (UNW_VER (stamp) != 1)
3463 printf ("\tUnknown version.\n");
3468 for (dp = head + 8; dp < head + 8 + addr_size * UNW_LENGTH (stamp);)
3469 dp = unw_decode (dp, in_body, & in_body);
3474 slurp_ia64_unwind_table (file, aux, sec)
3476 struct unw_aux_info *aux;
3477 Elf32_Internal_Shdr *sec;
3479 unsigned long size, addr_size, nrelas, i;
3480 Elf_Internal_Phdr *prog_hdrs, *seg;
3481 struct unw_table_entry *tep;
3482 Elf32_Internal_Shdr *relsec;
3483 Elf_Internal_Rela *rela, *rp;
3484 unsigned char *table, *tp;
3485 Elf_Internal_Sym *sym;
3486 const char *relname;
3489 addr_size = is_32bit_elf ? 4 : 8;
3491 /* First, find the starting address of the segment that includes
3494 if (elf_header.e_phnum)
3496 prog_hdrs = (Elf_Internal_Phdr *)
3497 xmalloc (elf_header.e_phnum * sizeof (Elf_Internal_Phdr));
3500 result = get_32bit_program_headers (file, prog_hdrs);
3502 result = get_64bit_program_headers (file, prog_hdrs);
3510 for (seg = prog_hdrs; seg < prog_hdrs + elf_header.e_phnum; ++seg)
3512 if (seg->p_type != PT_LOAD)
3515 if (sec->sh_addr >= seg->p_vaddr
3516 && (sec->sh_addr + sec->sh_size <= seg->p_vaddr + seg->p_memsz))
3518 aux->seg_base = seg->p_vaddr;
3526 /* Second, build the unwind table from the contents of the unwind section: */
3527 size = sec->sh_size;
3528 table = (char *) get_data (NULL, file, sec->sh_offset,
3529 size, _("unwind table"));
3533 tep = aux->table = xmalloc (size / (3 * addr_size) * sizeof (aux->table[0]));
3534 for (tp = table; tp < table + size; tp += 3 * addr_size, ++ tep)
3536 tep->start.section = SHN_UNDEF;
3537 tep->end.section = SHN_UNDEF;
3538 tep->info.section = SHN_UNDEF;
3541 tep->start.offset = byte_get ((unsigned char *) tp + 0, 4);
3542 tep->end.offset = byte_get ((unsigned char *) tp + 4, 4);
3543 tep->info.offset = byte_get ((unsigned char *) tp + 8, 4);
3547 tep->start.offset = BYTE_GET8 ((unsigned char *) tp + 0);
3548 tep->end.offset = BYTE_GET8 ((unsigned char *) tp + 8);
3549 tep->info.offset = BYTE_GET8 ((unsigned char *) tp + 16);
3551 tep->start.offset += aux->seg_base;
3552 tep->end.offset += aux->seg_base;
3553 tep->info.offset += aux->seg_base;
3557 /* Third, apply any relocations to the unwind table: */
3559 for (relsec = section_headers;
3560 relsec < section_headers + elf_header.e_shnum;
3563 if (relsec->sh_type != SHT_RELA
3564 || section_headers + relsec->sh_info != sec)
3567 if (!slurp_rela_relocs (file, relsec->sh_offset, relsec->sh_size,
3571 for (rp = rela; rp < rela + nrelas; ++rp)
3575 relname = elf_ia64_reloc_type (ELF32_R_TYPE (rp->r_info));
3576 sym = aux->symtab + ELF32_R_SYM (rp->r_info);
3578 if (ELF32_ST_TYPE (sym->st_info) != STT_SECTION)
3580 warn (_("Skipping unexpected symbol type %u\n"),
3581 ELF32_ST_TYPE (sym->st_info));
3587 relname = elf_ia64_reloc_type (ELF64_R_TYPE (rp->r_info));
3588 sym = aux->symtab + ELF64_R_SYM (rp->r_info);
3590 if (ELF64_ST_TYPE (sym->st_info) != STT_SECTION)
3592 warn (_("Skipping unexpected symbol type %u\n"),
3593 ELF64_ST_TYPE (sym->st_info));
3598 if (strncmp (relname, "R_IA64_SEGREL", 13) != 0)
3600 warn (_("Skipping unexpected relocation type %s\n"), relname);
3604 i = rp->r_offset / (3 * addr_size);
3606 switch (rp->r_offset/addr_size % 3)
3609 aux->table[i].start.section = sym->st_shndx;
3610 aux->table[i].start.offset += rp->r_addend;
3613 aux->table[i].end.section = sym->st_shndx;
3614 aux->table[i].end.offset += rp->r_addend;
3617 aux->table[i].info.section = sym->st_shndx;
3618 aux->table[i].info.offset += rp->r_addend;
3628 aux->table_len = size / (3 * addr_size);
3633 process_unwind (file)
3636 Elf32_Internal_Shdr *sec, *unwsec = NULL, *strsec;
3637 unsigned long i, addr_size, unwcount = 0, unwstart = 0;
3638 struct unw_aux_info aux;
3643 if (elf_header.e_machine != EM_IA_64)
3645 printf (_("\nThere are no unwind sections in this file.\n"));
3649 memset (& aux, 0, sizeof (aux));
3651 addr_size = is_32bit_elf ? 4 : 8;
3653 for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec)
3655 if (sec->sh_type == SHT_SYMTAB)
3657 aux.nsyms = sec->sh_size / sec->sh_entsize;
3658 aux.symtab = GET_ELF_SYMBOLS (file, sec->sh_offset, aux.nsyms);
3660 strsec = section_headers + sec->sh_link;
3661 aux.strtab_size = strsec->sh_size;
3662 aux.strtab = (char *) get_data (NULL, file, strsec->sh_offset,
3663 aux.strtab_size, _("string table"));
3665 else if (sec->sh_type == SHT_IA_64_UNWIND)
3670 printf (_("\nThere are no unwind sections in this file.\n"));
3672 while (unwcount-- > 0)
3677 for (i = unwstart, sec = section_headers + unwstart;
3678 i < elf_header.e_shnum; ++i, ++sec)
3679 if (sec->sh_type == SHT_IA_64_UNWIND)
3686 len = sizeof (ELF_STRING_ia64_unwind_once) - 1;
3688 if (strncmp (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind_once,
3691 /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO */
3692 len2 = sizeof (ELF_STRING_ia64_unwind_info_once) - 1;
3693 suffix = SECTION_NAME (unwsec) + len;
3694 for (i = 0, sec = section_headers; i < elf_header.e_shnum;
3696 if (strncmp (SECTION_NAME (sec),
3697 ELF_STRING_ia64_unwind_info_once, len2) == 0
3698 && strcmp (SECTION_NAME (sec) + len2, suffix) == 0)
3703 /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO
3704 .IA_64.unwind or BAR -> .IA_64.unwind_info */
3705 len = sizeof (ELF_STRING_ia64_unwind) - 1;
3706 len2 = sizeof (ELF_STRING_ia64_unwind_info) - 1;
3708 if (strncmp (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind,
3710 suffix = SECTION_NAME (unwsec) + len;
3711 for (i = 0, sec = section_headers; i < elf_header.e_shnum;
3713 if (strncmp (SECTION_NAME (sec),
3714 ELF_STRING_ia64_unwind_info, len2) == 0
3715 && strcmp (SECTION_NAME (sec) + len2, suffix) == 0)
3719 if (i == elf_header.e_shnum)
3721 printf (_("\nCould not find unwind info section for "));
3723 if (string_table == NULL)
3724 printf ("%d", unwsec->sh_name);
3726 printf ("'%s'", SECTION_NAME (unwsec));
3730 aux.info_size = sec->sh_size;
3731 aux.info_addr = sec->sh_addr;
3732 aux.info = (char *) get_data (NULL, file, sec->sh_offset,
3733 aux.info_size, _("unwind info"));
3735 printf (_("\nUnwind section "));
3737 if (string_table == NULL)
3738 printf ("%d", unwsec->sh_name);
3740 printf ("'%s'", SECTION_NAME (unwsec));
3742 printf (_(" at offset 0x%lx contains %lu entries:\n"),
3743 (unsigned long) unwsec->sh_offset,
3744 (unsigned long) (unwsec->sh_size / (3 * addr_size)));
3746 (void) slurp_ia64_unwind_table (file, & aux, unwsec);
3748 if (aux.table_len > 0)
3749 dump_ia64_unwind (& aux);
3752 free ((char *) aux.table);
3754 free ((char *) aux.info);
3763 free ((char *) aux.strtab);
3769 dynamic_segment_mips_val (entry)
3770 Elf_Internal_Dyn * entry;
3772 switch (entry->d_tag)
3775 if (entry->d_un.d_val == 0)
3779 static const char * opts[] =
3781 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
3782 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
3783 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
3784 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
3789 for (cnt = 0; cnt < NUM_ELEM (opts); ++ cnt)
3790 if (entry->d_un.d_val & (1 << cnt))
3792 printf ("%s%s", first ? "" : " ", opts[cnt]);
3799 case DT_MIPS_IVERSION:
3800 if (dynamic_strings != NULL)
3801 printf ("Interface Version: %s\n",
3802 dynamic_strings + entry->d_un.d_val);
3804 printf ("%ld\n", (long) entry->d_un.d_ptr);
3807 case DT_MIPS_TIME_STAMP:
3812 time_t time = entry->d_un.d_val;
3813 tmp = gmtime (&time);
3814 sprintf (timebuf, "%04u-%02u-%02uT%02u:%02u:%02u",
3815 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
3816 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
3817 printf ("Time Stamp: %s\n", timebuf);
3821 case DT_MIPS_RLD_VERSION:
3822 case DT_MIPS_LOCAL_GOTNO:
3823 case DT_MIPS_CONFLICTNO:
3824 case DT_MIPS_LIBLISTNO:
3825 case DT_MIPS_SYMTABNO:
3826 case DT_MIPS_UNREFEXTNO:
3827 case DT_MIPS_HIPAGENO:
3828 case DT_MIPS_DELTA_CLASS_NO:
3829 case DT_MIPS_DELTA_INSTANCE_NO:
3830 case DT_MIPS_DELTA_RELOC_NO:
3831 case DT_MIPS_DELTA_SYM_NO:
3832 case DT_MIPS_DELTA_CLASSSYM_NO:
3833 case DT_MIPS_COMPACT_SIZE:
3834 printf ("%ld\n", (long) entry->d_un.d_ptr);
3838 printf ("%#lx\n", (long) entry->d_un.d_ptr);
3844 dynamic_segment_parisc_val (entry)
3845 Elf_Internal_Dyn * entry;
3847 switch (entry->d_tag)
3849 case DT_HP_DLD_FLAGS:
3858 { DT_HP_DEBUG_PRIVATE, "HP_DEBUG_PRIVATE" },
3859 { DT_HP_DEBUG_CALLBACK, "HP_DEBUG_CALLBACK" },
3860 { DT_HP_DEBUG_CALLBACK_BOR, "HP_DEBUG_CALLBACK_BOR" },
3861 { DT_HP_NO_ENVVAR, "HP_NO_ENVVAR" },
3862 { DT_HP_BIND_NOW, "HP_BIND_NOW" },
3863 { DT_HP_BIND_NONFATAL, "HP_BIND_NONFATAL" },
3864 { DT_HP_BIND_VERBOSE, "HP_BIND_VERBOSE" },
3865 { DT_HP_BIND_RESTRICTED, "HP_BIND_RESTRICTED" },
3866 { DT_HP_BIND_SYMBOLIC, "HP_BIND_SYMBOLIC" },
3867 { DT_HP_RPATH_FIRST, "HP_RPATH_FIRST" },
3868 { DT_HP_BIND_DEPTH_FIRST, "HP_BIND_DEPTH_FIRST" }
3872 bfd_vma val = entry->d_un.d_val;
3874 for (cnt = 0; cnt < sizeof (flags) / sizeof (flags[0]); ++cnt)
3875 if (val & flags[cnt].bit)
3879 fputs (flags[cnt].str, stdout);
3881 val ^= flags[cnt].bit;
3884 if (val != 0 || first)
3888 print_vma (val, HEX);
3894 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
3900 get_32bit_dynamic_segment (file)
3903 Elf32_External_Dyn * edyn;
3904 Elf_Internal_Dyn * entry;
3907 edyn = (Elf32_External_Dyn *) get_data (NULL, file, dynamic_addr,
3908 dynamic_size, _("dynamic segment"));
3912 /* SGI's ELF has more than one section in the DYNAMIC segment. Determine
3913 how large this .dynamic is now. We can do this even before the byte
3914 swapping since the DT_NULL tag is recognizable. */
3916 while (*(Elf32_Word *) edyn [dynamic_size++].d_tag != DT_NULL)
3919 dynamic_segment = (Elf_Internal_Dyn *)
3920 malloc (dynamic_size * sizeof (Elf_Internal_Dyn));
3922 if (dynamic_segment == NULL)
3924 error (_("Out of memory\n"));
3929 for (i = 0, entry = dynamic_segment;
3933 entry->d_tag = BYTE_GET (edyn [i].d_tag);
3934 entry->d_un.d_val = BYTE_GET (edyn [i].d_un.d_val);
3943 get_64bit_dynamic_segment (file)
3946 Elf64_External_Dyn * edyn;
3947 Elf_Internal_Dyn * entry;
3950 edyn = (Elf64_External_Dyn *) get_data (NULL, file, dynamic_addr,
3951 dynamic_size, _("dynamic segment"));
3955 /* SGI's ELF has more than one section in the DYNAMIC segment. Determine
3956 how large this .dynamic is now. We can do this even before the byte
3957 swapping since the DT_NULL tag is recognizable. */
3959 while (*(bfd_vma *) edyn [dynamic_size ++].d_tag != DT_NULL)
3962 dynamic_segment = (Elf_Internal_Dyn *)
3963 malloc (dynamic_size * sizeof (Elf_Internal_Dyn));
3965 if (dynamic_segment == NULL)
3967 error (_("Out of memory\n"));
3972 for (i = 0, entry = dynamic_segment;
3976 entry->d_tag = BYTE_GET8 (edyn [i].d_tag);
3977 entry->d_un.d_val = BYTE_GET8 (edyn [i].d_un.d_val);
3986 get_dynamic_flags (flags)
3989 static char buff [64];
3994 flag = flags & - flags;
3999 case DF_ORIGIN: strcat (buff, "ORIGIN "); break;
4000 case DF_SYMBOLIC: strcat (buff, "SYMBOLIC "); break;
4001 case DF_TEXTREL: strcat (buff, "TEXTREL "); break;
4002 case DF_BIND_NOW: strcat (buff, "BIND_NOW "); break;
4003 default: strcat (buff, "unknown "); break;
4009 /* Parse and display the contents of the dynamic segment. */
4011 process_dynamic_segment (file)
4014 Elf_Internal_Dyn * entry;
4017 if (dynamic_size == 0)
4020 printf (_("\nThere is no dynamic segment in this file.\n"));
4027 if (! get_32bit_dynamic_segment (file))
4030 else if (! get_64bit_dynamic_segment (file))
4033 /* Find the appropriate symbol table. */
4034 if (dynamic_symbols == NULL)
4036 for (i = 0, entry = dynamic_segment;
4040 unsigned long offset;
4042 if (entry->d_tag != DT_SYMTAB)
4045 dynamic_info[DT_SYMTAB] = entry->d_un.d_val;
4047 /* Since we do not know how big the symbol table is,
4048 we default to reading in the entire file (!) and
4049 processing that. This is overkill, I know, but it
4051 offset = entry->d_un.d_val - loadaddr;
4053 if (fseek (file, 0, SEEK_END))
4054 error (_("Unable to seek to end of file!"));
4057 num_dynamic_syms = (ftell (file) - offset) / sizeof (Elf32_External_Sym);
4059 num_dynamic_syms = (ftell (file) - offset) / sizeof (Elf64_External_Sym);
4061 if (num_dynamic_syms < 1)
4063 error (_("Unable to determine the number of symbols to load\n"));
4067 dynamic_symbols = GET_ELF_SYMBOLS (file, offset, num_dynamic_syms);
4071 /* Similarly find a string table. */
4072 if (dynamic_strings == NULL)
4074 for (i = 0, entry = dynamic_segment;
4078 unsigned long offset;
4081 if (entry->d_tag != DT_STRTAB)
4084 dynamic_info[DT_STRTAB] = entry->d_un.d_val;
4086 /* Since we do not know how big the string table is,
4087 we default to reading in the entire file (!) and
4088 processing that. This is overkill, I know, but it
4091 offset = entry->d_un.d_val - loadaddr;
4092 if (fseek (file, 0, SEEK_END))
4093 error (_("Unable to seek to end of file\n"));
4094 str_tab_len = ftell (file) - offset;
4096 if (str_tab_len < 1)
4099 (_("Unable to determine the length of the dynamic string table\n"));
4103 dynamic_strings = (char *) get_data (NULL, file, offset, str_tab_len,
4104 _("dynamic string table"));
4109 /* And find the syminfo section if available. */
4110 if (dynamic_syminfo == NULL)
4112 unsigned int syminsz = 0;
4114 for (i = 0, entry = dynamic_segment;
4118 if (entry->d_tag == DT_SYMINENT)
4120 /* Note: these braces are necessary to avoid a syntax
4121 error from the SunOS4 C compiler. */
4122 assert (sizeof (Elf_External_Syminfo) == entry->d_un.d_val);
4124 else if (entry->d_tag == DT_SYMINSZ)
4125 syminsz = entry->d_un.d_val;
4126 else if (entry->d_tag == DT_SYMINFO)
4127 dynamic_syminfo_offset = entry->d_un.d_val - loadaddr;
4130 if (dynamic_syminfo_offset != 0 && syminsz != 0)
4132 Elf_External_Syminfo * extsyminfo;
4133 Elf_Internal_Syminfo * syminfo;
4135 /* There is a syminfo section. Read the data. */
4136 extsyminfo = ((Elf_External_Syminfo *)
4137 get_data (NULL, file, dynamic_syminfo_offset,
4138 syminsz, _("symbol information")));
4142 dynamic_syminfo = (Elf_Internal_Syminfo *) malloc (syminsz);
4143 if (dynamic_syminfo == NULL)
4145 error (_("Out of memory\n"));
4149 dynamic_syminfo_nent = syminsz / sizeof (Elf_External_Syminfo);
4150 for (i = 0, syminfo = dynamic_syminfo; i < dynamic_syminfo_nent;
4153 syminfo->si_boundto = BYTE_GET (extsyminfo[i].si_boundto);
4154 syminfo->si_flags = BYTE_GET (extsyminfo[i].si_flags);
4161 if (do_dynamic && dynamic_addr)
4162 printf (_("\nDynamic segment at offset 0x%x contains %ld entries:\n"),
4163 dynamic_addr, (long) dynamic_size);
4165 printf (_(" Tag Type Name/Value\n"));
4167 for (i = 0, entry = dynamic_segment;
4176 print_vma (entry->d_tag, FULL_HEX);
4177 dtype = get_dynamic_type (entry->d_tag);
4178 printf (" (%s)%*s", dtype,
4179 ((is_32bit_elf ? 27 : 19)
4180 - (int) strlen (dtype)),
4184 switch (entry->d_tag)
4188 printf ("%s", get_dynamic_flags (entry->d_un.d_val));
4198 switch (entry->d_tag)
4201 printf (_("Auxiliary library"));
4205 printf (_("Filter library"));
4209 printf (_("Configuration file"));
4213 printf (_("Dependency audit library"));
4217 printf (_("Audit library"));
4221 if (dynamic_strings)
4222 printf (": [%s]\n", dynamic_strings + entry->d_un.d_val);
4226 print_vma (entry->d_un.d_val, PREFIX_HEX);
4235 printf (_("Flags:"));
4236 if (entry->d_un.d_val == 0)
4237 printf (_(" None\n"));
4240 unsigned long int val = entry->d_un.d_val;
4241 if (val & DTF_1_PARINIT)
4243 printf (" PARINIT");
4244 val ^= DTF_1_PARINIT;
4246 if (val & DTF_1_CONFEXP)
4248 printf (" CONFEXP");
4249 val ^= DTF_1_CONFEXP;
4252 printf (" %lx", val);
4261 printf (_("Flags:"));
4262 if (entry->d_un.d_val == 0)
4263 printf (_(" None\n"));
4266 unsigned long int val = entry->d_un.d_val;
4267 if (val & DF_P1_LAZYLOAD)
4269 printf (" LAZYLOAD");
4270 val ^= DF_P1_LAZYLOAD;
4272 if (val & DF_P1_GROUPPERM)
4274 printf (" GROUPPERM");
4275 val ^= DF_P1_GROUPPERM;
4278 printf (" %lx", val);
4287 printf (_("Flags:"));
4288 if (entry->d_un.d_val == 0)
4289 printf (_(" None\n"));
4292 unsigned long int val = entry->d_un.d_val;
4298 if (val & DF_1_GLOBAL)
4303 if (val & DF_1_GROUP)
4308 if (val & DF_1_NODELETE)
4310 printf (" NODELETE");
4311 val ^= DF_1_NODELETE;
4313 if (val & DF_1_LOADFLTR)
4315 printf (" LOADFLTR");
4316 val ^= DF_1_LOADFLTR;
4318 if (val & DF_1_INITFIRST)
4320 printf (" INITFIRST");
4321 val ^= DF_1_INITFIRST;
4323 if (val & DF_1_NOOPEN)
4328 if (val & DF_1_ORIGIN)
4333 if (val & DF_1_DIRECT)
4338 if (val & DF_1_TRANS)
4343 if (val & DF_1_INTERPOSE)
4345 printf (" INTERPOSE");
4346 val ^= DF_1_INTERPOSE;
4348 if (val & DF_1_NODEFLIB)
4350 printf (" NODEFLIB");
4351 val ^= DF_1_NODEFLIB;
4353 if (val & DF_1_NODUMP)
4358 if (val & DF_1_CONLFAT)
4360 printf (" CONLFAT");
4361 val ^= DF_1_CONLFAT;
4364 printf (" %lx", val);
4372 puts (get_dynamic_type (entry->d_un.d_val));
4392 dynamic_info[entry->d_tag] = entry->d_un.d_val;
4398 if (dynamic_strings == NULL)
4401 name = dynamic_strings + entry->d_un.d_val;
4405 switch (entry->d_tag)
4408 printf (_("Shared library: [%s]"), name);
4410 if (strcmp (name, program_interpreter) == 0)
4411 printf (_(" program interpreter"));
4415 printf (_("Library soname: [%s]"), name);
4419 printf (_("Library rpath: [%s]"), name);
4423 printf (_("Library runpath: [%s]"), name);
4427 print_vma (entry->d_un.d_val, PREFIX_HEX);
4432 print_vma (entry->d_un.d_val, PREFIX_HEX);
4448 case DT_INIT_ARRAYSZ:
4449 case DT_FINI_ARRAYSZ:
4452 print_vma (entry->d_un.d_val, UNSIGNED);
4453 printf (" (bytes)\n");
4463 print_vma (entry->d_un.d_val, UNSIGNED);
4476 if (dynamic_strings != NULL && entry->d_tag == DT_USED)
4480 name = dynamic_strings + entry->d_un.d_val;
4484 printf (_("Not needed object: [%s]\n"), name);
4489 print_vma (entry->d_un.d_val, PREFIX_HEX);
4495 /* The value of this entry is ignored. */
4499 if ((entry->d_tag >= DT_VERSYM) && (entry->d_tag <= DT_VERNEEDNUM))
4500 version_info [DT_VERSIONTAGIDX (entry->d_tag)] =
4505 switch (elf_header.e_machine)
4508 case EM_MIPS_RS3_LE:
4509 dynamic_segment_mips_val (entry);
4512 dynamic_segment_parisc_val (entry);
4515 print_vma (entry->d_un.d_val, PREFIX_HEX);
4527 get_ver_flags (flags)
4530 static char buff [32];
4537 if (flags & VER_FLG_BASE)
4538 strcat (buff, "BASE ");
4540 if (flags & VER_FLG_WEAK)
4542 if (flags & VER_FLG_BASE)
4543 strcat (buff, "| ");
4545 strcat (buff, "WEAK ");
4548 if (flags & ~(VER_FLG_BASE | VER_FLG_WEAK))
4549 strcat (buff, "| <unknown>");
4554 /* Display the contents of the version sections. */
4556 process_version_sections (file)
4559 Elf32_Internal_Shdr * section;
4566 for (i = 0, section = section_headers;
4567 i < elf_header.e_shnum;
4570 switch (section->sh_type)
4572 case SHT_GNU_verdef:
4574 Elf_External_Verdef * edefs;
4581 (_("\nVersion definition section '%s' contains %ld entries:\n"),
4582 SECTION_NAME (section), section->sh_info);
4584 printf (_(" Addr: 0x"));
4585 printf_vma (section->sh_addr);
4586 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
4587 (unsigned long) section->sh_offset, section->sh_link,
4588 SECTION_NAME (section_headers + section->sh_link));
4590 edefs = ((Elf_External_Verdef *)
4591 get_data (NULL, file, section->sh_offset,
4593 _("version definition section")));
4597 for (idx = cnt = 0; cnt < section->sh_info; ++ cnt)
4600 Elf_External_Verdef * edef;
4601 Elf_Internal_Verdef ent;
4602 Elf_External_Verdaux * eaux;
4603 Elf_Internal_Verdaux aux;
4607 vstart = ((char *) edefs) + idx;
4609 edef = (Elf_External_Verdef *) vstart;
4611 ent.vd_version = BYTE_GET (edef->vd_version);
4612 ent.vd_flags = BYTE_GET (edef->vd_flags);
4613 ent.vd_ndx = BYTE_GET (edef->vd_ndx);
4614 ent.vd_cnt = BYTE_GET (edef->vd_cnt);
4615 ent.vd_hash = BYTE_GET (edef->vd_hash);
4616 ent.vd_aux = BYTE_GET (edef->vd_aux);
4617 ent.vd_next = BYTE_GET (edef->vd_next);
4619 printf (_(" %#06x: Rev: %d Flags: %s"),
4620 idx, ent.vd_version, get_ver_flags (ent.vd_flags));
4622 printf (_(" Index: %d Cnt: %d "),
4623 ent.vd_ndx, ent.vd_cnt);
4625 vstart += ent.vd_aux;
4627 eaux = (Elf_External_Verdaux *) vstart;
4629 aux.vda_name = BYTE_GET (eaux->vda_name);
4630 aux.vda_next = BYTE_GET (eaux->vda_next);
4632 if (dynamic_strings)
4633 printf (_("Name: %s\n"), dynamic_strings + aux.vda_name);
4635 printf (_("Name index: %ld\n"), aux.vda_name);
4637 isum = idx + ent.vd_aux;
4639 for (j = 1; j < ent.vd_cnt; j ++)
4641 isum += aux.vda_next;
4642 vstart += aux.vda_next;
4644 eaux = (Elf_External_Verdaux *) vstart;
4646 aux.vda_name = BYTE_GET (eaux->vda_name);
4647 aux.vda_next = BYTE_GET (eaux->vda_next);
4649 if (dynamic_strings)
4650 printf (_(" %#06x: Parent %d: %s\n"),
4651 isum, j, dynamic_strings + aux.vda_name);
4653 printf (_(" %#06x: Parent %d, name index: %ld\n"),
4654 isum, j, aux.vda_name);
4664 case SHT_GNU_verneed:
4666 Elf_External_Verneed * eneed;
4672 printf (_("\nVersion needs section '%s' contains %ld entries:\n"),
4673 SECTION_NAME (section), section->sh_info);
4675 printf (_(" Addr: 0x"));
4676 printf_vma (section->sh_addr);
4677 printf (_(" Offset: %#08lx Link to section: %ld (%s)\n"),
4678 (unsigned long) section->sh_offset, section->sh_link,
4679 SECTION_NAME (section_headers + section->sh_link));
4681 eneed = ((Elf_External_Verneed *)
4682 get_data (NULL, file, section->sh_offset,
4683 section->sh_size, _("version need section")));
4687 for (idx = cnt = 0; cnt < section->sh_info; ++cnt)
4689 Elf_External_Verneed * entry;
4690 Elf_Internal_Verneed ent;
4695 vstart = ((char *) eneed) + idx;
4697 entry = (Elf_External_Verneed *) vstart;
4699 ent.vn_version = BYTE_GET (entry->vn_version);
4700 ent.vn_cnt = BYTE_GET (entry->vn_cnt);
4701 ent.vn_file = BYTE_GET (entry->vn_file);
4702 ent.vn_aux = BYTE_GET (entry->vn_aux);
4703 ent.vn_next = BYTE_GET (entry->vn_next);
4705 printf (_(" %#06x: Version: %d"), idx, ent.vn_version);
4707 if (dynamic_strings)
4708 printf (_(" File: %s"), dynamic_strings + ent.vn_file);
4710 printf (_(" File: %lx"), ent.vn_file);
4712 printf (_(" Cnt: %d\n"), ent.vn_cnt);
4714 vstart += ent.vn_aux;
4716 for (j = 0, isum = idx + ent.vn_aux; j < ent.vn_cnt; ++j)
4718 Elf_External_Vernaux * eaux;
4719 Elf_Internal_Vernaux aux;
4721 eaux = (Elf_External_Vernaux *) vstart;
4723 aux.vna_hash = BYTE_GET (eaux->vna_hash);
4724 aux.vna_flags = BYTE_GET (eaux->vna_flags);
4725 aux.vna_other = BYTE_GET (eaux->vna_other);
4726 aux.vna_name = BYTE_GET (eaux->vna_name);
4727 aux.vna_next = BYTE_GET (eaux->vna_next);
4729 if (dynamic_strings)
4730 printf (_(" %#06x: Name: %s"),
4731 isum, dynamic_strings + aux.vna_name);
4733 printf (_(" %#06x: Name index: %lx"),
4734 isum, aux.vna_name);
4736 printf (_(" Flags: %s Version: %d\n"),
4737 get_ver_flags (aux.vna_flags), aux.vna_other);
4739 isum += aux.vna_next;
4740 vstart += aux.vna_next;
4750 case SHT_GNU_versym:
4752 Elf32_Internal_Shdr * link_section;
4755 unsigned char * edata;
4756 unsigned short * data;
4758 Elf_Internal_Sym * symbols;
4759 Elf32_Internal_Shdr * string_sec;
4761 link_section = section_headers + section->sh_link;
4762 total = section->sh_size / section->sh_entsize;
4766 symbols = GET_ELF_SYMBOLS (file, link_section->sh_offset,
4767 link_section->sh_size / link_section->sh_entsize);
4769 string_sec = section_headers + link_section->sh_link;
4771 strtab = (char *) get_data (NULL, file, string_sec->sh_offset,
4772 string_sec->sh_size,
4773 _("version string table"));
4777 printf (_("\nVersion symbols section '%s' contains %d entries:\n"),
4778 SECTION_NAME (section), total);
4780 printf (_(" Addr: "));
4781 printf_vma (section->sh_addr);
4782 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
4783 (unsigned long) section->sh_offset, section->sh_link,
4784 SECTION_NAME (link_section));
4788 get_data (NULL, file,
4789 version_info[DT_VERSIONTAGIDX (DT_VERSYM)] - loadaddr,
4790 total * sizeof (short), _("version symbol data")));
4797 data = (unsigned short *) malloc (total * sizeof (short));
4799 for (cnt = total; cnt --;)
4800 data [cnt] = byte_get (edata + cnt * sizeof (short),
4805 for (cnt = 0; cnt < total; cnt += 4)
4808 int check_def, check_need;
4811 printf (" %03x:", cnt);
4813 for (j = 0; (j < 4) && (cnt + j) < total; ++j)
4814 switch (data [cnt + j])
4817 fputs (_(" 0 (*local*) "), stdout);
4821 fputs (_(" 1 (*global*) "), stdout);
4825 nn = printf ("%4x%c", data [cnt + j] & 0x7fff,
4826 data [cnt + j] & 0x8000 ? 'h' : ' ');
4830 if (symbols [cnt + j].st_shndx >= SHN_LORESERVE
4831 || section_headers[symbols [cnt + j].st_shndx].sh_type
4834 if (symbols [cnt + j].st_shndx == SHN_UNDEF)
4841 && version_info [DT_VERSIONTAGIDX (DT_VERNEED)])
4843 Elf_Internal_Verneed ivn;
4844 unsigned long offset;
4846 offset = version_info [DT_VERSIONTAGIDX (DT_VERNEED)]
4851 Elf_Internal_Vernaux ivna;
4852 Elf_External_Verneed evn;
4853 Elf_External_Vernaux evna;
4854 unsigned long a_off;
4856 get_data (&evn, file, offset, sizeof (evn),
4859 ivn.vn_aux = BYTE_GET (evn.vn_aux);
4860 ivn.vn_next = BYTE_GET (evn.vn_next);
4862 a_off = offset + ivn.vn_aux;
4866 get_data (&evna, file, a_off, sizeof (evna),
4867 _("version need aux (2)"));
4869 ivna.vna_next = BYTE_GET (evna.vna_next);
4870 ivna.vna_other = BYTE_GET (evna.vna_other);
4872 a_off += ivna.vna_next;
4874 while (ivna.vna_other != data [cnt + j]
4875 && ivna.vna_next != 0);
4877 if (ivna.vna_other == data [cnt + j])
4879 ivna.vna_name = BYTE_GET (evna.vna_name);
4881 name = strtab + ivna.vna_name;
4882 nn += printf ("(%s%-*s",
4884 12 - (int) strlen (name),
4890 offset += ivn.vn_next;
4892 while (ivn.vn_next);
4895 if (check_def && data [cnt + j] != 0x8001
4896 && version_info [DT_VERSIONTAGIDX (DT_VERDEF)])
4898 Elf_Internal_Verdef ivd;
4899 Elf_External_Verdef evd;
4900 unsigned long offset;
4902 offset = version_info
4903 [DT_VERSIONTAGIDX (DT_VERDEF)] - loadaddr;
4907 get_data (&evd, file, offset, sizeof (evd),
4910 ivd.vd_next = BYTE_GET (evd.vd_next);
4911 ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
4913 offset += ivd.vd_next;
4915 while (ivd.vd_ndx != (data [cnt + j] & 0x7fff)
4916 && ivd.vd_next != 0);
4918 if (ivd.vd_ndx == (data [cnt + j] & 0x7fff))
4920 Elf_External_Verdaux evda;
4921 Elf_Internal_Verdaux ivda;
4923 ivd.vd_aux = BYTE_GET (evd.vd_aux);
4925 get_data (&evda, file,
4926 offset - ivd.vd_next + ivd.vd_aux,
4927 sizeof (evda), _("version def aux"));
4929 ivda.vda_name = BYTE_GET (evda.vda_name);
4931 name = strtab + ivda.vda_name;
4932 nn += printf ("(%s%-*s",
4934 12 - (int) strlen (name),
4940 printf ("%*c", 18 - nn, ' ');
4958 printf (_("\nNo version information found in this file.\n"));
4964 get_symbol_binding (binding)
4965 unsigned int binding;
4967 static char buff [32];
4971 case STB_LOCAL: return "LOCAL";
4972 case STB_GLOBAL: return "GLOBAL";
4973 case STB_WEAK: return "WEAK";
4975 if (binding >= STB_LOPROC && binding <= STB_HIPROC)
4976 sprintf (buff, _("<processor specific>: %d"), binding);
4977 else if (binding >= STB_LOOS && binding <= STB_HIOS)
4978 sprintf (buff, _("<OS specific>: %d"), binding);
4980 sprintf (buff, _("<unknown>: %d"), binding);
4986 get_symbol_type (type)
4989 static char buff [32];
4993 case STT_NOTYPE: return "NOTYPE";
4994 case STT_OBJECT: return "OBJECT";
4995 case STT_FUNC: return "FUNC";
4996 case STT_SECTION: return "SECTION";
4997 case STT_FILE: return "FILE";
4998 case STT_COMMON: return "COMMON";
5000 if (type >= STT_LOPROC && type <= STT_HIPROC)
5002 if (elf_header.e_machine == EM_ARM && type == STT_ARM_TFUNC)
5003 return "THUMB_FUNC";
5005 if (elf_header.e_machine == EM_SPARCV9 && type == STT_REGISTER)
5008 if (elf_header.e_machine == EM_PARISC && type == STT_PARISC_MILLI)
5009 return "PARISC_MILLI";
5011 sprintf (buff, _("<processor specific>: %d"), type);
5013 else if (type >= STT_LOOS && type <= STT_HIOS)
5015 if (elf_header.e_machine == EM_PARISC)
5017 if (type == STT_HP_OPAQUE)
5019 if (type == STT_HP_STUB)
5023 sprintf (buff, _("<OS specific>: %d"), type);
5026 sprintf (buff, _("<unknown>: %d"), type);
5032 get_symbol_visibility (visibility)
5033 unsigned int visibility;
5037 case STV_DEFAULT: return "DEFAULT";
5038 case STV_INTERNAL: return "INTERNAL";
5039 case STV_HIDDEN: return "HIDDEN";
5040 case STV_PROTECTED: return "PROTECTED";
5046 get_symbol_index_type (type)
5051 case SHN_UNDEF: return "UND";
5052 case SHN_ABS: return "ABS";
5053 case SHN_COMMON: return "COM";
5055 if (type >= SHN_LOPROC && type <= SHN_HIPROC)
5057 else if (type >= SHN_LORESERVE && type <= SHN_HIRESERVE)
5059 else if (type >= SHN_LOOS && type <= SHN_HIOS)
5063 static char buff [32];
5065 sprintf (buff, "%3d", type);
5072 get_dynamic_data (file, number)
5074 unsigned int number;
5076 unsigned char * e_data;
5079 e_data = (unsigned char *) malloc (number * 4);
5083 error (_("Out of memory\n"));
5087 if (fread (e_data, 4, number, file) != number)
5089 error (_("Unable to read in dynamic data\n"));
5093 i_data = (int *) malloc (number * sizeof (* i_data));
5097 error (_("Out of memory\n"));
5103 i_data [number] = byte_get (e_data + number * 4, 4);
5110 /* Dump the symbol table. */
5112 process_symbol_table (file)
5115 Elf32_Internal_Shdr * section;
5116 unsigned char nb [4];
5117 unsigned char nc [4];
5120 int * buckets = NULL;
5121 int * chains = NULL;
5123 if (! do_syms && !do_histogram)
5126 if (dynamic_info[DT_HASH] && ((do_using_dynamic && dynamic_strings != NULL)
5129 if (fseek (file, dynamic_info[DT_HASH] - loadaddr, SEEK_SET))
5131 error (_("Unable to seek to start of dynamic information"));
5135 if (fread (nb, sizeof (nb), 1, file) != 1)
5137 error (_("Failed to read in number of buckets\n"));
5141 if (fread (nc, sizeof (nc), 1, file) != 1)
5143 error (_("Failed to read in number of chains\n"));
5147 nbuckets = byte_get (nb, 4);
5148 nchains = byte_get (nc, 4);
5150 buckets = get_dynamic_data (file, nbuckets);
5151 chains = get_dynamic_data (file, nchains);
5153 if (buckets == NULL || chains == NULL)
5158 && dynamic_info[DT_HASH] && do_using_dynamic && dynamic_strings != NULL)
5163 printf (_("\nSymbol table for image:\n"));
5165 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
5167 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
5169 for (hn = 0; hn < nbuckets; hn++)
5174 for (si = buckets [hn]; si < nchains && si > 0; si = chains [si])
5176 Elf_Internal_Sym * psym;
5178 psym = dynamic_symbols + si;
5180 printf (" %3d %3d: ", si, hn);
5181 print_vma (psym->st_value, LONG_HEX);
5183 print_vma (psym->st_size, DEC_5);
5185 printf (" %6s", get_symbol_type (ELF_ST_TYPE (psym->st_info)));
5186 printf (" %6s", get_symbol_binding (ELF_ST_BIND (psym->st_info)));
5187 printf (" %3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym->st_other)));
5188 printf (" %3.3s", get_symbol_index_type (psym->st_shndx));
5189 printf (" %s\n", dynamic_strings + psym->st_name);
5193 else if (do_syms && !do_using_dynamic)
5197 for (i = 0, section = section_headers;
5198 i < elf_header.e_shnum;
5203 Elf_Internal_Sym * symtab;
5204 Elf_Internal_Sym * psym;
5207 if ( section->sh_type != SHT_SYMTAB
5208 && section->sh_type != SHT_DYNSYM)
5211 printf (_("\nSymbol table '%s' contains %lu entries:\n"),
5212 SECTION_NAME (section),
5213 (unsigned long) (section->sh_size / section->sh_entsize));
5215 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
5217 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
5219 symtab = GET_ELF_SYMBOLS (file, section->sh_offset,
5220 section->sh_size / section->sh_entsize);
5224 if (section->sh_link == elf_header.e_shstrndx)
5225 strtab = string_table;
5228 Elf32_Internal_Shdr * string_sec;
5230 string_sec = section_headers + section->sh_link;
5232 strtab = (char *) get_data (NULL, file, string_sec->sh_offset,
5233 string_sec->sh_size,
5237 for (si = 0, psym = symtab;
5238 si < section->sh_size / section->sh_entsize;
5241 printf ("%6d: ", si);
5242 print_vma (psym->st_value, LONG_HEX);
5244 print_vma (psym->st_size, DEC_5);
5245 printf (" %-7s", get_symbol_type (ELF_ST_TYPE (psym->st_info)));
5246 printf (" %-6s", get_symbol_binding (ELF_ST_BIND (psym->st_info)));
5247 printf (" %-3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym->st_other)));
5248 printf (" %4s", get_symbol_index_type (psym->st_shndx));
5249 printf (" %s", strtab + psym->st_name);
5251 if (section->sh_type == SHT_DYNSYM &&
5252 version_info [DT_VERSIONTAGIDX (DT_VERSYM)] != 0)
5254 unsigned char data[2];
5255 unsigned short vers_data;
5256 unsigned long offset;
5260 offset = version_info [DT_VERSIONTAGIDX (DT_VERSYM)]
5263 get_data (&data, file, offset + si * sizeof (vers_data),
5264 sizeof (data), _("version data"));
5266 vers_data = byte_get (data, 2);
5268 is_nobits = psym->st_shndx < SHN_LORESERVE ?
5269 (section_headers [psym->st_shndx].sh_type == SHT_NOBITS)
5272 check_def = (psym->st_shndx != SHN_UNDEF);
5274 if ((vers_data & 0x8000) || vers_data > 1)
5276 if (version_info [DT_VERSIONTAGIDX (DT_VERNEED)]
5277 && (is_nobits || ! check_def))
5279 Elf_External_Verneed evn;
5280 Elf_Internal_Verneed ivn;
5281 Elf_Internal_Vernaux ivna;
5283 /* We must test both. */
5284 offset = version_info
5285 [DT_VERSIONTAGIDX (DT_VERNEED)] - loadaddr;
5289 unsigned long vna_off;
5291 get_data (&evn, file, offset, sizeof (evn),
5294 ivn.vn_aux = BYTE_GET (evn.vn_aux);
5295 ivn.vn_next = BYTE_GET (evn.vn_next);
5297 vna_off = offset + ivn.vn_aux;
5301 Elf_External_Vernaux evna;
5303 get_data (&evna, file, vna_off,
5305 _("version need aux (3)"));
5307 ivna.vna_other = BYTE_GET (evna.vna_other);
5308 ivna.vna_next = BYTE_GET (evna.vna_next);
5309 ivna.vna_name = BYTE_GET (evna.vna_name);
5311 vna_off += ivna.vna_next;
5313 while (ivna.vna_other != vers_data
5314 && ivna.vna_next != 0);
5316 if (ivna.vna_other == vers_data)
5319 offset += ivn.vn_next;
5321 while (ivn.vn_next != 0);
5323 if (ivna.vna_other == vers_data)
5326 strtab + ivna.vna_name, ivna.vna_other);
5329 else if (! is_nobits)
5330 error (_("bad dynamic symbol"));
5337 if (vers_data != 0x8001
5338 && version_info [DT_VERSIONTAGIDX (DT_VERDEF)])
5340 Elf_Internal_Verdef ivd;
5341 Elf_Internal_Verdaux ivda;
5342 Elf_External_Verdaux evda;
5343 unsigned long offset;
5346 version_info [DT_VERSIONTAGIDX (DT_VERDEF)]
5351 Elf_External_Verdef evd;
5353 get_data (&evd, file, offset, sizeof (evd),
5356 ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
5357 ivd.vd_aux = BYTE_GET (evd.vd_aux);
5358 ivd.vd_next = BYTE_GET (evd.vd_next);
5360 offset += ivd.vd_next;
5362 while (ivd.vd_ndx != (vers_data & 0x7fff)
5363 && ivd.vd_next != 0);
5365 offset -= ivd.vd_next;
5366 offset += ivd.vd_aux;
5368 get_data (&evda, file, offset, sizeof (evda),
5369 _("version def aux"));
5371 ivda.vda_name = BYTE_GET (evda.vda_name);
5373 if (psym->st_name != ivda.vda_name)
5374 printf ((vers_data & 0x8000)
5376 strtab + ivda.vda_name);
5386 if (strtab != string_table)
5392 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
5394 if (do_histogram && buckets != NULL)
5401 int nzero_counts = 0;
5404 printf (_("\nHistogram for bucket list length (total of %d buckets):\n"),
5406 printf (_(" Length Number %% of total Coverage\n"));
5408 lengths = (int *) calloc (nbuckets, sizeof (int));
5409 if (lengths == NULL)
5411 error (_("Out of memory"));
5414 for (hn = 0; hn < nbuckets; ++hn)
5419 for (si = buckets[hn]; si > 0 && si < nchains; si = chains[si])
5422 if (maxlength < ++lengths[hn])
5427 counts = (int *) calloc (maxlength + 1, sizeof (int));
5430 error (_("Out of memory"));
5434 for (hn = 0; hn < nbuckets; ++hn)
5435 ++ counts [lengths [hn]];
5439 printf (" 0 %-10d (%5.1f%%)\n",
5440 counts[0], (counts[0] * 100.0) / nbuckets);
5441 for (si = 1; si <= maxlength; ++si)
5443 nzero_counts += counts[si] * si;
5444 printf ("%7d %-10d (%5.1f%%) %5.1f%%\n",
5445 si, counts[si], (counts[si] * 100.0) / nbuckets,
5446 (nzero_counts * 100.0) / nsyms);
5454 if (buckets != NULL)
5464 process_syminfo (file)
5465 FILE * file ATTRIBUTE_UNUSED;
5469 if (dynamic_syminfo == NULL
5471 /* No syminfo, this is ok. */
5474 /* There better should be a dynamic symbol section. */
5475 if (dynamic_symbols == NULL || dynamic_strings == NULL)
5479 printf (_("\nDynamic info segment at offset 0x%lx contains %d entries:\n"),
5480 dynamic_syminfo_offset, dynamic_syminfo_nent);
5482 printf (_(" Num: Name BoundTo Flags\n"));
5483 for (i = 0; i < dynamic_syminfo_nent; ++i)
5485 unsigned short int flags = dynamic_syminfo[i].si_flags;
5487 printf ("%4d: %-30s ", i,
5488 dynamic_strings + dynamic_symbols[i].st_name);
5490 switch (dynamic_syminfo[i].si_boundto)
5492 case SYMINFO_BT_SELF:
5493 fputs ("SELF ", stdout);
5495 case SYMINFO_BT_PARENT:
5496 fputs ("PARENT ", stdout);
5499 if (dynamic_syminfo[i].si_boundto > 0
5500 && dynamic_syminfo[i].si_boundto < dynamic_size)
5503 + dynamic_segment[dynamic_syminfo[i].si_boundto].d_un.d_val);
5505 printf ("%-10d ", dynamic_syminfo[i].si_boundto);
5509 if (flags & SYMINFO_FLG_DIRECT)
5511 if (flags & SYMINFO_FLG_PASSTHRU)
5512 printf (" PASSTHRU");
5513 if (flags & SYMINFO_FLG_COPY)
5515 if (flags & SYMINFO_FLG_LAZYLOAD)
5516 printf (" LAZYLOAD");
5524 #ifdef SUPPORT_DISASSEMBLY
5526 disassemble_section (section, file)
5527 Elf32_Internal_Shdr * section;
5530 printf (_("\nAssembly dump of section %s\n"),
5531 SECTION_NAME (section));
5533 /* XXX -- to be done --- XXX */
5540 dump_section (section, file)
5541 Elf32_Internal_Shdr * section;
5544 bfd_size_type bytes;
5546 unsigned char * data;
5547 unsigned char * start;
5549 bytes = section->sh_size;
5553 printf (_("\nSection '%s' has no data to dump.\n"),
5554 SECTION_NAME (section));
5558 printf (_("\nHex dump of section '%s':\n"), SECTION_NAME (section));
5560 addr = section->sh_addr;
5562 start = (unsigned char *) get_data (NULL, file, section->sh_offset, bytes,
5575 lbytes = (bytes > 16 ? 16 : bytes);
5577 printf (" 0x%8.8lx ", (unsigned long) addr);
5579 switch (elf_header.e_ident [EI_DATA])
5583 for (j = 15; j >= 0; j --)
5586 printf ("%2.2x", data [j]);
5596 for (j = 0; j < 16; j++)
5599 printf ("%2.2x", data [j]);
5609 for (j = 0; j < lbytes; j++)
5612 if (k >= ' ' && k < 0x80)
5631 static unsigned long int
5632 read_leb128 (data, length_return, sign)
5633 unsigned char * data;
5634 int * length_return;
5637 unsigned long int result = 0;
5638 unsigned int num_read = 0;
5647 result |= (byte & 0x7f) << shift;
5652 while (byte & 0x80);
5654 if (length_return != NULL)
5655 * length_return = num_read;
5657 if (sign && (shift < 32) && (byte & 0x40))
5658 result |= -1 << shift;
5663 typedef struct State_Machine_Registers
5665 unsigned long address;
5668 unsigned int column;
5672 /* This variable hold the number of the last entry seen
5673 in the File Table. */
5674 unsigned int last_file_entry;
5677 static SMR state_machine_regs;
5680 reset_state_machine (is_stmt)
5683 state_machine_regs.address = 0;
5684 state_machine_regs.file = 1;
5685 state_machine_regs.line = 1;
5686 state_machine_regs.column = 0;
5687 state_machine_regs.is_stmt = is_stmt;
5688 state_machine_regs.basic_block = 0;
5689 state_machine_regs.end_sequence = 0;
5690 state_machine_regs.last_file_entry = 0;
5693 /* Handled an extend line op. Returns true if this is the end
5696 process_extended_line_op (data, is_stmt, pointer_size)
5697 unsigned char * data;
5701 unsigned char op_code;
5704 unsigned char * name;
5707 len = read_leb128 (data, & bytes_read, 0);
5712 warn (_("badly formed extended line op encountered!\n"));
5717 op_code = * data ++;
5719 printf (_(" Extended opcode %d: "), op_code);
5723 case DW_LNE_end_sequence:
5724 printf (_("End of Sequence\n\n"));
5725 reset_state_machine (is_stmt);
5728 case DW_LNE_set_address:
5729 adr = byte_get (data, pointer_size);
5730 printf (_("set Address to 0x%lx\n"), adr);
5731 state_machine_regs.address = adr;
5734 case DW_LNE_define_file:
5735 printf (_(" define new File Table entry\n"));
5736 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
5738 printf (_(" %d\t"), ++ state_machine_regs.last_file_entry);
5740 data += strlen ((char *) data) + 1;
5741 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
5743 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
5745 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
5746 printf (_("%s\n\n"), name);
5750 printf (_("UNKNOWN: length %d\n"), len - bytes_read);
5757 /* Size of pointers in the .debug_line section. This information is not
5758 really present in that section. It's obtained before dumping the debug
5759 sections by doing some pre-scan of the .debug_info section. */
5760 static int debug_line_pointer_size = 4;
5763 display_debug_lines (section, start, file)
5764 Elf32_Internal_Shdr * section;
5765 unsigned char * start;
5766 FILE * file ATTRIBUTE_UNUSED;
5768 DWARF2_External_LineInfo * external;
5769 DWARF2_Internal_LineInfo info;
5770 unsigned char * standard_opcodes;
5771 unsigned char * data = start;
5772 unsigned char * end = start + section->sh_size;
5773 unsigned char * end_of_sequence;
5776 printf (_("\nDump of debug contents of section %s:\n\n"),
5777 SECTION_NAME (section));
5781 external = (DWARF2_External_LineInfo *) data;
5783 /* Check the length of the block. */
5784 info.li_length = BYTE_GET (external->li_length);
5786 if (info.li_length == 0xffffffff)
5788 warn (_("64-bit DWARF line info is not supported yet.\n"));
5792 if (info.li_length + sizeof (external->li_length) > section->sh_size)
5795 (_("The line info appears to be corrupt - the section is too small\n"));
5799 /* Check its version number. */
5800 info.li_version = BYTE_GET (external->li_version);
5801 if (info.li_version != 2)
5803 warn (_("Only DWARF version 2 line info is currently supported.\n"));
5807 info.li_prologue_length = BYTE_GET (external->li_prologue_length);
5808 info.li_min_insn_length = BYTE_GET (external->li_min_insn_length);
5809 info.li_default_is_stmt = BYTE_GET (external->li_default_is_stmt);
5810 info.li_line_base = BYTE_GET (external->li_line_base);
5811 info.li_line_range = BYTE_GET (external->li_line_range);
5812 info.li_opcode_base = BYTE_GET (external->li_opcode_base);
5814 /* Sign extend the line base field. */
5815 info.li_line_base <<= 24;
5816 info.li_line_base >>= 24;
5818 printf (_(" Length: %ld\n"), info.li_length);
5819 printf (_(" DWARF Version: %d\n"), info.li_version);
5820 printf (_(" Prologue Length: %d\n"), info.li_prologue_length);
5821 printf (_(" Minimum Instruction Length: %d\n"), info.li_min_insn_length);
5822 printf (_(" Initial value of 'is_stmt': %d\n"), info.li_default_is_stmt);
5823 printf (_(" Line Base: %d\n"), info.li_line_base);
5824 printf (_(" Line Range: %d\n"), info.li_line_range);
5825 printf (_(" Opcode Base: %d\n"), info.li_opcode_base);
5827 end_of_sequence = data + info.li_length + sizeof (external->li_length);
5829 reset_state_machine (info.li_default_is_stmt);
5831 /* Display the contents of the Opcodes table. */
5832 standard_opcodes = data + sizeof (* external);
5834 printf (_("\n Opcodes:\n"));
5836 for (i = 1; i < info.li_opcode_base; i++)
5837 printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]);
5839 /* Display the contents of the Directory table. */
5840 data = standard_opcodes + info.li_opcode_base - 1;
5843 printf (_("\n The Directory Table is empty.\n"));
5846 printf (_("\n The Directory Table:\n"));
5850 printf (_(" %s\n"), data);
5852 data += strlen ((char *) data) + 1;
5856 /* Skip the NUL at the end of the table. */
5859 /* Display the contents of the File Name table. */
5861 printf (_("\n The File Name Table is empty.\n"));
5864 printf (_("\n The File Name Table:\n"));
5865 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
5869 unsigned char * name;
5872 printf (_(" %d\t"), ++ state_machine_regs.last_file_entry);
5875 data += strlen ((char *) data) + 1;
5877 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
5879 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
5881 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
5883 printf (_("%s\n"), name);
5887 /* Skip the NUL at the end of the table. */
5890 /* Now display the statements. */
5891 printf (_("\n Line Number Statements:\n"));
5894 while (data < end_of_sequence)
5896 unsigned char op_code;
5900 op_code = * data ++;
5902 if (op_code >= info.li_opcode_base)
5904 op_code -= info.li_opcode_base;
5905 adv = (op_code / info.li_line_range) * info.li_min_insn_length;
5906 state_machine_regs.address += adv;
5907 printf (_(" Special opcode %d: advance Address by %d to 0x%lx"),
5908 op_code, adv, state_machine_regs.address);
5909 adv = (op_code % info.li_line_range) + info.li_line_base;
5910 state_machine_regs.line += adv;
5911 printf (_(" and Line by %d to %d\n"),
5912 adv, state_machine_regs.line);
5914 else switch (op_code)
5916 case DW_LNS_extended_op:
5917 data += process_extended_line_op (data, info.li_default_is_stmt,
5918 debug_line_pointer_size);
5922 printf (_(" Copy\n"));
5925 case DW_LNS_advance_pc:
5926 adv = info.li_min_insn_length * read_leb128 (data, & bytes_read, 0);
5928 state_machine_regs.address += adv;
5929 printf (_(" Advance PC by %d to %lx\n"), adv,
5930 state_machine_regs.address);
5933 case DW_LNS_advance_line:
5934 adv = read_leb128 (data, & bytes_read, 1);
5936 state_machine_regs.line += adv;
5937 printf (_(" Advance Line by %d to %d\n"), adv,
5938 state_machine_regs.line);
5941 case DW_LNS_set_file:
5942 adv = read_leb128 (data, & bytes_read, 0);
5944 printf (_(" Set File Name to entry %d in the File Name Table\n"),
5946 state_machine_regs.file = adv;
5949 case DW_LNS_set_column:
5950 adv = read_leb128 (data, & bytes_read, 0);
5952 printf (_(" Set column to %d\n"), adv);
5953 state_machine_regs.column = adv;
5956 case DW_LNS_negate_stmt:
5957 adv = state_machine_regs.is_stmt;
5959 printf (_(" Set is_stmt to %d\n"), adv);
5960 state_machine_regs.is_stmt = adv;
5963 case DW_LNS_set_basic_block:
5964 printf (_(" Set basic block\n"));
5965 state_machine_regs.basic_block = 1;
5968 case DW_LNS_const_add_pc:
5969 adv = (((255 - info.li_opcode_base) / info.li_line_range)
5970 * info.li_min_insn_length);
5971 state_machine_regs.address += adv;
5972 printf (_(" Advance PC by constant %d to 0x%lx\n"), adv,
5973 state_machine_regs.address);
5976 case DW_LNS_fixed_advance_pc:
5977 adv = byte_get (data, 2);
5979 state_machine_regs.address += adv;
5980 printf (_(" Advance PC by fixed size amount %d to 0x%lx\n"),
5981 adv, state_machine_regs.address);
5984 case DW_LNS_set_prologue_end:
5985 printf (_(" Set prologue_end to true\n"));
5988 case DW_LNS_set_epilogue_begin:
5989 printf (_(" Set epilogue_begin to true\n"));
5992 case DW_LNS_set_isa:
5993 adv = read_leb128 (data, & bytes_read, 0);
5995 printf (_(" Set ISA to %d\n"), adv);
5999 printf (_(" Unknown opcode %d with operands: "), op_code);
6002 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
6004 printf ("0x%lx%s", read_leb128 (data, &bytes_read, 0),
6005 i == 1 ? "" : ", ");
6020 display_debug_pubnames (section, start, file)
6021 Elf32_Internal_Shdr * section;
6022 unsigned char * start;
6023 FILE * file ATTRIBUTE_UNUSED;
6025 DWARF2_External_PubNames * external;
6026 DWARF2_Internal_PubNames pubnames;
6027 unsigned char * end;
6029 end = start + section->sh_size;
6031 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section));
6035 unsigned char * data;
6036 unsigned long offset;
6038 external = (DWARF2_External_PubNames *) start;
6040 pubnames.pn_length = BYTE_GET (external->pn_length);
6041 pubnames.pn_version = BYTE_GET (external->pn_version);
6042 pubnames.pn_offset = BYTE_GET (external->pn_offset);
6043 pubnames.pn_size = BYTE_GET (external->pn_size);
6045 data = start + sizeof (* external);
6046 start += pubnames.pn_length + sizeof (external->pn_length);
6048 if (pubnames.pn_length == 0xffffffff)
6050 warn (_("64-bit DWARF pubnames are not supported yet.\n"));
6054 if (pubnames.pn_version != 2)
6056 static int warned = 0;
6060 warn (_("Only DWARF 2 pubnames are currently supported\n"));
6067 printf (_(" Length: %ld\n"),
6068 pubnames.pn_length);
6069 printf (_(" Version: %d\n"),
6070 pubnames.pn_version);
6071 printf (_(" Offset into .debug_info section: %ld\n"),
6072 pubnames.pn_offset);
6073 printf (_(" Size of area in .debug_info section: %ld\n"),
6076 printf (_("\n Offset\tName\n"));
6080 offset = byte_get (data, 4);
6085 printf (" %ld\t\t%s\n", offset, data);
6086 data += strlen ((char *) data) + 1;
6089 while (offset != 0);
6102 case DW_TAG_padding: return "DW_TAG_padding";
6103 case DW_TAG_array_type: return "DW_TAG_array_type";
6104 case DW_TAG_class_type: return "DW_TAG_class_type";
6105 case DW_TAG_entry_point: return "DW_TAG_entry_point";
6106 case DW_TAG_enumeration_type: return "DW_TAG_enumeration_type";
6107 case DW_TAG_formal_parameter: return "DW_TAG_formal_parameter";
6108 case DW_TAG_imported_declaration: return "DW_TAG_imported_declaration";
6109 case DW_TAG_label: return "DW_TAG_label";
6110 case DW_TAG_lexical_block: return "DW_TAG_lexical_block";
6111 case DW_TAG_member: return "DW_TAG_member";
6112 case DW_TAG_pointer_type: return "DW_TAG_pointer_type";
6113 case DW_TAG_reference_type: return "DW_TAG_reference_type";
6114 case DW_TAG_compile_unit: return "DW_TAG_compile_unit";
6115 case DW_TAG_string_type: return "DW_TAG_string_type";
6116 case DW_TAG_structure_type: return "DW_TAG_structure_type";
6117 case DW_TAG_subroutine_type: return "DW_TAG_subroutine_type";
6118 case DW_TAG_typedef: return "DW_TAG_typedef";
6119 case DW_TAG_union_type: return "DW_TAG_union_type";
6120 case DW_TAG_unspecified_parameters: return "DW_TAG_unspecified_parameters";
6121 case DW_TAG_variant: return "DW_TAG_variant";
6122 case DW_TAG_common_block: return "DW_TAG_common_block";
6123 case DW_TAG_common_inclusion: return "DW_TAG_common_inclusion";
6124 case DW_TAG_inheritance: return "DW_TAG_inheritance";
6125 case DW_TAG_inlined_subroutine: return "DW_TAG_inlined_subroutine";
6126 case DW_TAG_module: return "DW_TAG_module";
6127 case DW_TAG_ptr_to_member_type: return "DW_TAG_ptr_to_member_type";
6128 case DW_TAG_set_type: return "DW_TAG_set_type";
6129 case DW_TAG_subrange_type: return "DW_TAG_subrange_type";
6130 case DW_TAG_with_stmt: return "DW_TAG_with_stmt";
6131 case DW_TAG_access_declaration: return "DW_TAG_access_declaration";
6132 case DW_TAG_base_type: return "DW_TAG_base_type";
6133 case DW_TAG_catch_block: return "DW_TAG_catch_block";
6134 case DW_TAG_const_type: return "DW_TAG_const_type";
6135 case DW_TAG_constant: return "DW_TAG_constant";
6136 case DW_TAG_enumerator: return "DW_TAG_enumerator";
6137 case DW_TAG_file_type: return "DW_TAG_file_type";
6138 case DW_TAG_friend: return "DW_TAG_friend";
6139 case DW_TAG_namelist: return "DW_TAG_namelist";
6140 case DW_TAG_namelist_item: return "DW_TAG_namelist_item";
6141 case DW_TAG_packed_type: return "DW_TAG_packed_type";
6142 case DW_TAG_subprogram: return "DW_TAG_subprogram";
6143 case DW_TAG_template_type_param: return "DW_TAG_template_type_param";
6144 case DW_TAG_template_value_param: return "DW_TAG_template_value_param";
6145 case DW_TAG_thrown_type: return "DW_TAG_thrown_type";
6146 case DW_TAG_try_block: return "DW_TAG_try_block";
6147 case DW_TAG_variant_part: return "DW_TAG_variant_part";
6148 case DW_TAG_variable: return "DW_TAG_variable";
6149 case DW_TAG_volatile_type: return "DW_TAG_volatile_type";
6150 case DW_TAG_MIPS_loop: return "DW_TAG_MIPS_loop";
6151 case DW_TAG_format_label: return "DW_TAG_format_label";
6152 case DW_TAG_function_template: return "DW_TAG_function_template";
6153 case DW_TAG_class_template: return "DW_TAG_class_template";
6154 /* DWARF 2.1 values. */
6155 case DW_TAG_dwarf_procedure: return "DW_TAG_dwarf_procedure";
6156 case DW_TAG_restrict_type: return "DW_TAG_restrict_type";
6157 case DW_TAG_interface_type: return "DW_TAG_interface_type";
6158 case DW_TAG_namespace: return "DW_TAG_namespace";
6159 case DW_TAG_imported_module: return "DW_TAG_imported_module";
6160 case DW_TAG_unspecified_type: return "DW_TAG_unspecified_type";
6161 case DW_TAG_partial_unit: return "DW_TAG_partial_unit";
6162 case DW_TAG_imported_unit: return "DW_TAG_imported_unit";
6165 static char buffer [100];
6167 sprintf (buffer, _("Unknown TAG value: %lx"), tag);
6174 get_AT_name (attribute)
6175 unsigned long attribute;
6179 case DW_AT_sibling: return "DW_AT_sibling";
6180 case DW_AT_location: return "DW_AT_location";
6181 case DW_AT_name: return "DW_AT_name";
6182 case DW_AT_ordering: return "DW_AT_ordering";
6183 case DW_AT_subscr_data: return "DW_AT_subscr_data";
6184 case DW_AT_byte_size: return "DW_AT_byte_size";
6185 case DW_AT_bit_offset: return "DW_AT_bit_offset";
6186 case DW_AT_bit_size: return "DW_AT_bit_size";
6187 case DW_AT_element_list: return "DW_AT_element_list";
6188 case DW_AT_stmt_list: return "DW_AT_stmt_list";
6189 case DW_AT_low_pc: return "DW_AT_low_pc";
6190 case DW_AT_high_pc: return "DW_AT_high_pc";
6191 case DW_AT_language: return "DW_AT_language";
6192 case DW_AT_member: return "DW_AT_member";
6193 case DW_AT_discr: return "DW_AT_discr";
6194 case DW_AT_discr_value: return "DW_AT_discr_value";
6195 case DW_AT_visibility: return "DW_AT_visibility";
6196 case DW_AT_import: return "DW_AT_import";
6197 case DW_AT_string_length: return "DW_AT_string_length";
6198 case DW_AT_common_reference: return "DW_AT_common_reference";
6199 case DW_AT_comp_dir: return "DW_AT_comp_dir";
6200 case DW_AT_const_value: return "DW_AT_const_value";
6201 case DW_AT_containing_type: return "DW_AT_containing_type";
6202 case DW_AT_default_value: return "DW_AT_default_value";
6203 case DW_AT_inline: return "DW_AT_inline";
6204 case DW_AT_is_optional: return "DW_AT_is_optional";
6205 case DW_AT_lower_bound: return "DW_AT_lower_bound";
6206 case DW_AT_producer: return "DW_AT_producer";
6207 case DW_AT_prototyped: return "DW_AT_prototyped";
6208 case DW_AT_return_addr: return "DW_AT_return_addr";
6209 case DW_AT_start_scope: return "DW_AT_start_scope";
6210 case DW_AT_stride_size: return "DW_AT_stride_size";
6211 case DW_AT_upper_bound: return "DW_AT_upper_bound";
6212 case DW_AT_abstract_origin: return "DW_AT_abstract_origin";
6213 case DW_AT_accessibility: return "DW_AT_accessibility";
6214 case DW_AT_address_class: return "DW_AT_address_class";
6215 case DW_AT_artificial: return "DW_AT_artificial";
6216 case DW_AT_base_types: return "DW_AT_base_types";
6217 case DW_AT_calling_convention: return "DW_AT_calling_convention";
6218 case DW_AT_count: return "DW_AT_count";
6219 case DW_AT_data_member_location: return "DW_AT_data_member_location";
6220 case DW_AT_decl_column: return "DW_AT_decl_column";
6221 case DW_AT_decl_file: return "DW_AT_decl_file";
6222 case DW_AT_decl_line: return "DW_AT_decl_line";
6223 case DW_AT_declaration: return "DW_AT_declaration";
6224 case DW_AT_discr_list: return "DW_AT_discr_list";
6225 case DW_AT_encoding: return "DW_AT_encoding";
6226 case DW_AT_external: return "DW_AT_external";
6227 case DW_AT_frame_base: return "DW_AT_frame_base";
6228 case DW_AT_friend: return "DW_AT_friend";
6229 case DW_AT_identifier_case: return "DW_AT_identifier_case";
6230 case DW_AT_macro_info: return "DW_AT_macro_info";
6231 case DW_AT_namelist_items: return "DW_AT_namelist_items";
6232 case DW_AT_priority: return "DW_AT_priority";
6233 case DW_AT_segment: return "DW_AT_segment";
6234 case DW_AT_specification: return "DW_AT_specification";
6235 case DW_AT_static_link: return "DW_AT_static_link";
6236 case DW_AT_type: return "DW_AT_type";
6237 case DW_AT_use_location: return "DW_AT_use_location";
6238 case DW_AT_variable_parameter: return "DW_AT_variable_parameter";
6239 case DW_AT_virtuality: return "DW_AT_virtuality";
6240 case DW_AT_vtable_elem_location: return "DW_AT_vtable_elem_location";
6241 /* DWARF 2.1 values. */
6242 case DW_AT_allocated: return "DW_AT_allocated";
6243 case DW_AT_associated: return "DW_AT_associated";
6244 case DW_AT_data_location: return "DW_AT_data_location";
6245 case DW_AT_stride: return "DW_AT_stride";
6246 case DW_AT_entry_pc: return "DW_AT_entry_pc";
6247 case DW_AT_use_UTF8: return "DW_AT_use_UTF8";
6248 case DW_AT_extension: return "DW_AT_extension";
6249 case DW_AT_ranges: return "DW_AT_ranges";
6250 case DW_AT_trampoline: return "DW_AT_trampoline";
6251 case DW_AT_call_column: return "DW_AT_call_column";
6252 case DW_AT_call_file: return "DW_AT_call_file";
6253 case DW_AT_call_line: return "DW_AT_call_line";
6254 /* SGI/MIPS extensions. */
6255 case DW_AT_MIPS_fde: return "DW_AT_MIPS_fde";
6256 case DW_AT_MIPS_loop_begin: return "DW_AT_MIPS_loop_begin";
6257 case DW_AT_MIPS_tail_loop_begin: return "DW_AT_MIPS_tail_loop_begin";
6258 case DW_AT_MIPS_epilog_begin: return "DW_AT_MIPS_epilog_begin";
6259 case DW_AT_MIPS_loop_unroll_factor: return "DW_AT_MIPS_loop_unroll_factor";
6260 case DW_AT_MIPS_software_pipeline_depth: return "DW_AT_MIPS_software_pipeline_depth";
6261 case DW_AT_MIPS_linkage_name: return "DW_AT_MIPS_linkage_name";
6262 case DW_AT_MIPS_stride: return "DW_AT_MIPS_stride";
6263 case DW_AT_MIPS_abstract_name: return "DW_AT_MIPS_abstract_name";
6264 case DW_AT_MIPS_clone_origin: return "DW_AT_MIPS_clone_origin";
6265 case DW_AT_MIPS_has_inlines: return "DW_AT_MIPS_has_inlines";
6266 /* GNU extensions. */
6267 case DW_AT_sf_names: return "DW_AT_sf_names";
6268 case DW_AT_src_info: return "DW_AT_src_info";
6269 case DW_AT_mac_info: return "DW_AT_mac_info";
6270 case DW_AT_src_coords: return "DW_AT_src_coords";
6271 case DW_AT_body_begin: return "DW_AT_body_begin";
6272 case DW_AT_body_end: return "DW_AT_body_end";
6275 static char buffer [100];
6277 sprintf (buffer, _("Unknown AT value: %lx"), attribute);
6284 get_FORM_name (form)
6289 case DW_FORM_addr: return "DW_FORM_addr";
6290 case DW_FORM_block2: return "DW_FORM_block2";
6291 case DW_FORM_block4: return "DW_FORM_block4";
6292 case DW_FORM_data2: return "DW_FORM_data2";
6293 case DW_FORM_data4: return "DW_FORM_data4";
6294 case DW_FORM_data8: return "DW_FORM_data8";
6295 case DW_FORM_string: return "DW_FORM_string";
6296 case DW_FORM_block: return "DW_FORM_block";
6297 case DW_FORM_block1: return "DW_FORM_block1";
6298 case DW_FORM_data1: return "DW_FORM_data1";
6299 case DW_FORM_flag: return "DW_FORM_flag";
6300 case DW_FORM_sdata: return "DW_FORM_sdata";
6301 case DW_FORM_strp: return "DW_FORM_strp";
6302 case DW_FORM_udata: return "DW_FORM_udata";
6303 case DW_FORM_ref_addr: return "DW_FORM_ref_addr";
6304 case DW_FORM_ref1: return "DW_FORM_ref1";
6305 case DW_FORM_ref2: return "DW_FORM_ref2";
6306 case DW_FORM_ref4: return "DW_FORM_ref4";
6307 case DW_FORM_ref8: return "DW_FORM_ref8";
6308 case DW_FORM_ref_udata: return "DW_FORM_ref_udata";
6309 case DW_FORM_indirect: return "DW_FORM_indirect";
6312 static char buffer [100];
6314 sprintf (buffer, _("Unknown FORM value: %lx"), form);
6320 /* FIXME: There are better and more effiecint ways to handle
6321 these structures. For now though, I just want something that
6322 is simple to implement. */
6323 typedef struct abbrev_attr
6325 unsigned long attribute;
6327 struct abbrev_attr * next;
6331 typedef struct abbrev_entry
6333 unsigned long entry;
6336 struct abbrev_attr * first_attr;
6337 struct abbrev_attr * last_attr;
6338 struct abbrev_entry * next;
6342 static abbrev_entry * first_abbrev = NULL;
6343 static abbrev_entry * last_abbrev = NULL;
6346 free_abbrevs PARAMS ((void))
6348 abbrev_entry * abbrev;
6350 for (abbrev = first_abbrev; abbrev;)
6352 abbrev_entry * next = abbrev->next;
6355 for (attr = abbrev->first_attr; attr;)
6357 abbrev_attr * next = attr->next;
6367 last_abbrev = first_abbrev = NULL;
6371 add_abbrev (number, tag, children)
6372 unsigned long number;
6376 abbrev_entry * entry;
6378 entry = (abbrev_entry *) malloc (sizeof (* entry));
6384 entry->entry = number;
6386 entry->children = children;
6387 entry->first_attr = NULL;
6388 entry->last_attr = NULL;
6391 if (first_abbrev == NULL)
6392 first_abbrev = entry;
6394 last_abbrev->next = entry;
6396 last_abbrev = entry;
6400 add_abbrev_attr (attribute, form)
6401 unsigned long attribute;
6406 attr = (abbrev_attr *) malloc (sizeof (* attr));
6412 attr->attribute = attribute;
6416 if (last_abbrev->first_attr == NULL)
6417 last_abbrev->first_attr = attr;
6419 last_abbrev->last_attr->next = attr;
6421 last_abbrev->last_attr = attr;
6424 /* Processes the (partial) contents of a .debug_abbrev section.
6425 Returns NULL if the end of the section was encountered.
6426 Returns the address after the last byte read if the end of
6427 an abbreviation set was found. */
6429 static unsigned char *
6430 process_abbrev_section (start, end)
6431 unsigned char * start;
6432 unsigned char * end;
6434 if (first_abbrev != NULL)
6440 unsigned long entry;
6442 unsigned long attribute;
6445 entry = read_leb128 (start, & bytes_read, 0);
6446 start += bytes_read;
6448 /* A single zero is supposed to end the section according
6449 to the standard. If there's more, then signal that to
6452 return start == end ? NULL : start;
6454 tag = read_leb128 (start, & bytes_read, 0);
6455 start += bytes_read;
6457 children = * start ++;
6459 add_abbrev (entry, tag, children);
6465 attribute = read_leb128 (start, & bytes_read, 0);
6466 start += bytes_read;
6468 form = read_leb128 (start, & bytes_read, 0);
6469 start += bytes_read;
6472 add_abbrev_attr (attribute, form);
6474 while (attribute != 0);
6482 display_debug_macinfo (section, start, file)
6483 Elf32_Internal_Shdr * section;
6484 unsigned char * start;
6485 FILE * file ATTRIBUTE_UNUSED;
6487 unsigned char * end = start + section->sh_size;
6488 unsigned char * curr = start;
6489 unsigned int bytes_read;
6490 enum dwarf_macinfo_record_type op;
6492 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section));
6496 unsigned int lineno;
6497 const char * string;
6504 case DW_MACINFO_start_file:
6506 unsigned int filenum;
6508 lineno = read_leb128 (curr, & bytes_read, 0);
6510 filenum = read_leb128 (curr, & bytes_read, 0);
6513 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"), lineno, filenum);
6517 case DW_MACINFO_end_file:
6518 printf (_(" DW_MACINFO_end_file\n"));
6521 case DW_MACINFO_define:
6522 lineno = read_leb128 (curr, & bytes_read, 0);
6525 curr += strlen (string) + 1;
6526 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"), lineno, string);
6529 case DW_MACINFO_undef:
6530 lineno = read_leb128 (curr, & bytes_read, 0);
6533 curr += strlen (string) + 1;
6534 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"), lineno, string);
6537 case DW_MACINFO_vendor_ext:
6539 unsigned int constant;
6541 constant = read_leb128 (curr, & bytes_read, 0);
6544 curr += strlen (string) + 1;
6545 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"), constant, string);
6556 display_debug_abbrev (section, start, file)
6557 Elf32_Internal_Shdr * section;
6558 unsigned char * start;
6559 FILE * file ATTRIBUTE_UNUSED;
6561 abbrev_entry * entry;
6562 unsigned char * end = start + section->sh_size;
6564 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section));
6568 start = process_abbrev_section (start, end);
6570 if (first_abbrev == NULL)
6573 printf (_(" Number TAG\n"));
6575 for (entry = first_abbrev; entry; entry = entry->next)
6579 printf (_(" %ld %s [%s]\n"),
6581 get_TAG_name (entry->tag),
6582 entry->children ? _("has children") : _("no children"));
6584 for (attr = entry->first_attr; attr; attr = attr->next)
6586 printf (_(" %-18s %s\n"),
6587 get_AT_name (attr->attribute),
6588 get_FORM_name (attr->form));
6602 static unsigned char *
6603 display_block (data, length)
6604 unsigned char * data;
6605 unsigned long length;
6607 printf (_(" %lu byte block: "), length);
6610 printf ("%lx ", (unsigned long) byte_get (data ++, 1));
6616 decode_location_expression (data, pointer_size, length)
6617 unsigned char * data;
6618 unsigned int pointer_size;
6619 unsigned long length;
6623 unsigned long uvalue;
6624 unsigned char * end = data + length;
6633 printf ("DW_OP_addr: %lx",
6634 (unsigned long) byte_get (data, pointer_size));
6635 data += pointer_size;
6638 printf ("DW_OP_deref");
6641 printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data++, 1));
6644 printf ("DW_OP_const1s: %ld", (long) byte_get (data++, 1));
6647 printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data, 2));
6651 printf ("DW_OP_const2s: %ld", (long) byte_get (data, 2));
6655 printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data, 4));
6659 printf ("DW_OP_const4s: %ld", (long) byte_get (data, 4));
6663 printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data, 4),
6664 (unsigned long) byte_get (data + 4, 4));
6668 printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data, 4),
6669 (long) byte_get (data + 4, 4));
6673 printf ("DW_OP_constu: %lu", read_leb128 (data, &bytes_read, 0));
6677 printf ("DW_OP_consts: %ld", read_leb128 (data, &bytes_read, 1));
6681 printf ("DW_OP_dup");
6684 printf ("DW_OP_drop");
6687 printf ("DW_OP_over");
6690 printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data++, 1));
6693 printf ("DW_OP_swap");
6696 printf ("DW_OP_rot");
6699 printf ("DW_OP_xderef");
6702 printf ("DW_OP_abs");
6705 printf ("DW_OP_and");
6708 printf ("DW_OP_div");
6711 printf ("DW_OP_minus");
6714 printf ("DW_OP_mod");
6717 printf ("DW_OP_mul");
6720 printf ("DW_OP_neg");
6723 printf ("DW_OP_not");
6726 printf ("DW_OP_or");
6729 printf ("DW_OP_plus");
6731 case DW_OP_plus_uconst:
6732 printf ("DW_OP_plus_uconst: %lu",
6733 read_leb128 (data, &bytes_read, 0));
6737 printf ("DW_OP_shl");
6740 printf ("DW_OP_shr");
6743 printf ("DW_OP_shra");
6746 printf ("DW_OP_xor");
6749 printf ("DW_OP_bra: %ld", (long) byte_get (data, 2));
6753 printf ("DW_OP_eq");
6756 printf ("DW_OP_ge");
6759 printf ("DW_OP_gt");
6762 printf ("DW_OP_le");
6765 printf ("DW_OP_lt");
6768 printf ("DW_OP_ne");
6771 printf ("DW_OP_skip: %ld", (long) byte_get (data, 2));
6807 printf ("DW_OP_lit%d", op - DW_OP_lit0);
6842 printf ("DW_OP_reg%d", op - DW_OP_reg0);
6877 printf ("DW_OP_breg%d: %ld", op - DW_OP_breg0,
6878 read_leb128 (data, &bytes_read, 1));
6883 printf ("DW_OP_regx: %lu", read_leb128 (data, &bytes_read, 0));
6887 printf ("DW_OP_fbreg: %ld", read_leb128 (data, &bytes_read, 1));
6891 uvalue = read_leb128 (data, &bytes_read, 0);
6893 printf ("DW_OP_bregx: %lu %ld", uvalue,
6894 read_leb128 (data, &bytes_read, 1));
6898 printf ("DW_OP_piece: %lu", read_leb128 (data, &bytes_read, 0));
6901 case DW_OP_deref_size:
6902 printf ("DW_OP_deref_size: %ld", (long) byte_get (data++, 1));
6904 case DW_OP_xderef_size:
6905 printf ("DW_OP_xderef_size: %ld", (long) byte_get (data++, 1));
6908 printf ("DW_OP_nop");
6911 /* DWARF 2.1 extensions. */
6912 case DW_OP_push_object_address:
6913 printf ("DW_OP_push_object_address");
6916 printf ("DW_OP_call2: <%lx>", (long) byte_get (data, 2));
6920 printf ("DW_OP_call4: <%lx>", (long) byte_get (data, 4));
6924 printf ("DW_OP_calli");
6928 if (op >= DW_OP_lo_user
6929 && op <= DW_OP_hi_user)
6930 printf (_("(User defined location op)"));
6932 printf (_("(Unknown location op)"));
6933 /* No way to tell where the next op is, so just bail. */
6937 /* Separate the ops. */
6943 static const char * debug_str_contents;
6944 static bfd_vma debug_str_size;
6947 load_debug_str (file)
6950 Elf32_Internal_Shdr * sec;
6953 /* If it is already loaded, do nothing. */
6954 if (debug_str_contents != NULL)
6957 /* Locate the .debug_str section. */
6958 for (i = 0, sec = section_headers;
6959 i < elf_header.e_shnum;
6961 if (strcmp (SECTION_NAME (sec), ".debug_str") == 0)
6964 if (i == elf_header.e_shnum || sec->sh_size == 0)
6967 debug_str_size = sec->sh_size;
6969 debug_str_contents = ((char *)
6970 get_data (NULL, file, sec->sh_offset, sec->sh_size,
6971 _("debug_str section data")));
6977 if (debug_str_contents == NULL)
6980 free ((char *) debug_str_contents);
6981 debug_str_contents = NULL;
6986 fetch_indirect_string (offset)
6987 unsigned long offset;
6989 if (debug_str_contents == NULL)
6990 return _("<no .debug_str section>");
6992 if (offset > debug_str_size)
6993 return _("<offset is too big>");
6995 return debug_str_contents + offset;
7000 display_debug_str (section, start, file)
7001 Elf32_Internal_Shdr * section;
7002 unsigned char * start;
7003 FILE * file ATTRIBUTE_UNUSED;
7005 unsigned long bytes;
7008 addr = section->sh_addr;
7009 bytes = section->sh_size;
7013 printf (_("\nThe .debug_str section is empty.\n"));
7017 printf (_("Contents of the .debug_str section:\n\n"));
7025 lbytes = (bytes > 16 ? 16 : bytes);
7027 printf (" 0x%8.8lx ", (unsigned long) addr);
7029 for (j = 0; j < 16; j++)
7032 printf ("%2.2x", start [j]);
7040 for (j = 0; j < lbytes; j++)
7043 if (k >= ' ' && k < 0x80)
7060 static unsigned char *
7061 read_and_display_attr_value (attribute, form, data, cu_offset, pointer_size)
7062 unsigned long attribute;
7064 unsigned char * data;
7065 unsigned long cu_offset;
7066 unsigned long pointer_size;
7068 unsigned long uvalue = 0;
7069 unsigned char * block_start = NULL;
7077 case DW_FORM_ref_addr:
7079 uvalue = byte_get (data, pointer_size);
7080 data += pointer_size;
7084 uvalue = byte_get (data, /* offset_size */ 4);
7085 data += /* offset_size */ 4;
7091 uvalue = byte_get (data ++, 1);
7096 uvalue = byte_get (data, 2);
7102 uvalue = byte_get (data, 4);
7107 uvalue = read_leb128 (data, & bytes_read, 1);
7111 case DW_FORM_ref_udata:
7113 uvalue = read_leb128 (data, & bytes_read, 0);
7117 case DW_FORM_indirect:
7118 form = read_leb128 (data, & bytes_read, 0);
7120 printf (" %s", get_FORM_name (form));
7121 return read_and_display_attr_value (attribute, form, data, cu_offset,
7127 case DW_FORM_ref_addr:
7128 printf (" <#%lx>", uvalue);
7134 case DW_FORM_ref_udata:
7135 printf (" <%lx>", uvalue + cu_offset);
7139 printf (" %#lx", uvalue);
7147 printf (" %ld", uvalue);
7152 uvalue = byte_get (data, 4);
7153 printf (" %lx", uvalue);
7154 printf (" %lx", (unsigned long) byte_get (data + 4, 4));
7158 case DW_FORM_string:
7159 printf (" %s", data);
7160 data += strlen ((char *) data) + 1;
7164 uvalue = read_leb128 (data, & bytes_read, 0);
7165 block_start = data + bytes_read;
7166 data = display_block (block_start, uvalue);
7169 case DW_FORM_block1:
7170 uvalue = byte_get (data, 1);
7171 block_start = data + 1;
7172 data = display_block (block_start, uvalue);
7175 case DW_FORM_block2:
7176 uvalue = byte_get (data, 2);
7177 block_start = data + 2;
7178 data = display_block (block_start, uvalue);
7181 case DW_FORM_block4:
7182 uvalue = byte_get (data, 4);
7183 block_start = data + 4;
7184 data = display_block (block_start, uvalue);
7188 printf (_(" (indirect string, offset: 0x%lx): "), uvalue);
7189 printf (fetch_indirect_string (uvalue));
7192 case DW_FORM_indirect:
7193 /* Handled above. */
7197 warn (_("Unrecognised form: %d\n"), form);
7201 /* For some attributes we can display futher information. */
7210 case DW_INL_not_inlined: printf (_("(not inlined)")); break;
7211 case DW_INL_inlined: printf (_("(inlined)")); break;
7212 case DW_INL_declared_not_inlined: printf (_("(declared as inline but ignored)")); break;
7213 case DW_INL_declared_inlined: printf (_("(declared as inline and inlined)")); break;
7214 default: printf (_(" (Unknown inline attribute value: %lx)"), uvalue); break;
7218 case DW_AT_language:
7221 case DW_LANG_C: printf ("(non-ANSI C)"); break;
7222 case DW_LANG_C89: printf ("(ANSI C)"); break;
7223 case DW_LANG_C_plus_plus: printf ("(C++)"); break;
7224 case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break;
7225 case DW_LANG_Fortran90: printf ("(Fortran 90)"); break;
7226 case DW_LANG_Modula2: printf ("(Modula 2)"); break;
7227 case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break;
7228 case DW_LANG_Ada83: printf ("(Ada)"); break;
7229 case DW_LANG_Cobol74: printf ("(Cobol 74)"); break;
7230 case DW_LANG_Cobol85: printf ("(Cobol 85)"); break;
7231 /* DWARF 2.1 values. */
7232 case DW_LANG_C99: printf ("(ANSI C99)"); break;
7233 case DW_LANG_Ada95: printf ("(ADA 95)"); break;
7234 case DW_LANG_Fortran95: printf ("(Fortran 95)"); break;
7235 /* MIPS extension. */
7236 case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break;
7237 default: printf ("(Unknown: %lx)", uvalue); break;
7241 case DW_AT_encoding:
7244 case DW_ATE_void: printf ("(void)"); break;
7245 case DW_ATE_address: printf ("(machine address)"); break;
7246 case DW_ATE_boolean: printf ("(boolean)"); break;
7247 case DW_ATE_complex_float: printf ("(complex float)"); break;
7248 case DW_ATE_float: printf ("(float)"); break;
7249 case DW_ATE_signed: printf ("(signed)"); break;
7250 case DW_ATE_signed_char: printf ("(signed char)"); break;
7251 case DW_ATE_unsigned: printf ("(unsigned)"); break;
7252 case DW_ATE_unsigned_char: printf ("(unsigned char)"); break;
7253 /* DWARF 2.1 value. */
7254 case DW_ATE_imaginary_float: printf ("(imaginary float)"); break;
7256 if (uvalue >= DW_ATE_lo_user
7257 && uvalue <= DW_ATE_hi_user)
7258 printf ("(user defined type)");
7260 printf ("(unknown type)");
7265 case DW_AT_accessibility:
7268 case DW_ACCESS_public: printf ("(public)"); break;
7269 case DW_ACCESS_protected: printf ("(protected)"); break;
7270 case DW_ACCESS_private: printf ("(private)"); break;
7271 default: printf ("(unknown accessibility)"); break;
7275 case DW_AT_visibility:
7278 case DW_VIS_local: printf ("(local)"); break;
7279 case DW_VIS_exported: printf ("(exported)"); break;
7280 case DW_VIS_qualified: printf ("(qualified)"); break;
7281 default: printf ("(unknown visibility)"); break;
7285 case DW_AT_virtuality:
7288 case DW_VIRTUALITY_none: printf ("(none)"); break;
7289 case DW_VIRTUALITY_virtual: printf ("(virtual)"); break;
7290 case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break;
7291 default: printf ("(unknown virtuality)"); break;
7295 case DW_AT_identifier_case:
7298 case DW_ID_case_sensitive: printf ("(case_sensitive)"); break;
7299 case DW_ID_up_case: printf ("(up_case)"); break;
7300 case DW_ID_down_case: printf ("(down_case)"); break;
7301 case DW_ID_case_insensitive: printf ("(case_insensitive)"); break;
7302 default: printf ("(unknown case)"); break;
7306 case DW_AT_calling_convention:
7309 case DW_CC_normal: printf ("(normal)"); break;
7310 case DW_CC_program: printf ("(program)"); break;
7311 case DW_CC_nocall: printf ("(nocall)"); break;
7313 if (uvalue >= DW_CC_lo_user
7314 && uvalue <= DW_CC_hi_user)
7315 printf ("(user defined)");
7317 printf ("(unknown convention)");
7321 case DW_AT_ordering:
7324 case -1: printf ("(undefined)"); break;
7325 case 0: printf ("(row major)"); break;
7326 case 1: printf ("(column major)"); break;
7330 case DW_AT_frame_base:
7331 case DW_AT_location:
7332 case DW_AT_data_member_location:
7333 case DW_AT_vtable_elem_location:
7334 case DW_AT_allocated:
7335 case DW_AT_associated:
7336 case DW_AT_data_location:
7338 case DW_AT_upper_bound:
7339 case DW_AT_lower_bound:
7343 decode_location_expression (block_start, pointer_size, uvalue);
7355 static unsigned char *
7356 read_and_display_attr (attribute, form, data, cu_offset, pointer_size)
7357 unsigned long attribute;
7359 unsigned char * data;
7360 unsigned long cu_offset;
7361 unsigned long pointer_size;
7363 printf (" %-18s:", get_AT_name (attribute));
7364 data = read_and_display_attr_value (attribute, form, data, cu_offset,
7371 display_debug_info (section, start, file)
7372 Elf32_Internal_Shdr * section;
7373 unsigned char * start;
7376 unsigned char * end = start + section->sh_size;
7377 unsigned char * section_begin = start;
7379 printf (_("The section %s contains:\n\n"), SECTION_NAME (section));
7381 load_debug_str (file);
7385 DWARF2_External_CompUnit * external;
7386 DWARF2_Internal_CompUnit compunit;
7387 Elf32_Internal_Shdr * relsec;
7388 unsigned char * tags;
7391 unsigned long cu_offset;
7393 external = (DWARF2_External_CompUnit *) start;
7395 compunit.cu_length = BYTE_GET (external->cu_length);
7396 compunit.cu_version = BYTE_GET (external->cu_version);
7397 compunit.cu_abbrev_offset = BYTE_GET (external->cu_abbrev_offset);
7398 compunit.cu_pointer_size = BYTE_GET (external->cu_pointer_size);
7400 if (compunit.cu_length == 0xffffffff)
7402 warn (_("64-bit DWARF debug info is not supported yet.\n"));
7406 /* Check for RELA relocations in the abbrev_offset address, and
7408 for (relsec = section_headers;
7409 relsec < section_headers + elf_header.e_shnum;
7412 unsigned long nrelas, nsyms;
7413 Elf_Internal_Rela *rela, *rp;
7414 Elf32_Internal_Shdr *symsec;
7415 Elf_Internal_Sym *symtab;
7416 Elf_Internal_Sym *sym;
7418 if (relsec->sh_type != SHT_RELA
7419 || section_headers + relsec->sh_info != section)
7422 if (!slurp_rela_relocs (file, relsec->sh_offset, relsec->sh_size,
7426 symsec = section_headers + relsec->sh_link;
7427 nsyms = symsec->sh_size / symsec->sh_entsize;
7428 symtab = GET_ELF_SYMBOLS (file, symsec->sh_offset, nsyms);
7430 for (rp = rela; rp < rela + nrelas; ++rp)
7433 != (bfd_vma) ((unsigned char *) &external->cu_abbrev_offset
7439 sym = symtab + ELF32_R_SYM (rp->r_info);
7441 if (ELF32_ST_TYPE (sym->st_info) != STT_SECTION)
7443 warn (_("Skipping unexpected symbol type %u\n"),
7444 ELF32_ST_TYPE (sym->st_info));
7450 sym = symtab + ELF64_R_SYM (rp->r_info);
7452 if (ELF64_ST_TYPE (sym->st_info) != STT_SECTION)
7454 warn (_("Skipping unexpected symbol type %u\n"),
7455 ELF64_ST_TYPE (sym->st_info));
7460 compunit.cu_abbrev_offset += rp->r_addend;
7468 tags = start + sizeof (* external);
7469 cu_offset = start - section_begin;
7470 start += compunit.cu_length + sizeof (external->cu_length);
7472 printf (_(" Compilation Unit @ %lx:\n"), cu_offset);
7473 printf (_(" Length: %ld\n"), compunit.cu_length);
7474 printf (_(" Version: %d\n"), compunit.cu_version);
7475 printf (_(" Abbrev Offset: %ld\n"), compunit.cu_abbrev_offset);
7476 printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size);
7478 if (compunit.cu_version != 2)
7480 warn (_("Only version 2 DWARF debug information is currently supported.\n"));
7486 /* Read in the abbrevs used by this compilation unit. */
7489 Elf32_Internal_Shdr * sec;
7490 unsigned char * begin;
7492 /* Locate the .debug_abbrev section and process it. */
7493 for (i = 0, sec = section_headers;
7494 i < elf_header.e_shnum;
7496 if (strcmp (SECTION_NAME (sec), ".debug_abbrev") == 0)
7499 if (i == elf_header.e_shnum || sec->sh_size == 0)
7501 warn (_("Unable to locate .debug_abbrev section!\n"));
7505 begin = ((unsigned char *)
7506 get_data (NULL, file, sec->sh_offset, sec->sh_size,
7507 _("debug_abbrev section data")));
7511 process_abbrev_section (begin + compunit.cu_abbrev_offset,
7512 begin + sec->sh_size);
7518 while (tags < start)
7521 unsigned long abbrev_number;
7522 abbrev_entry * entry;
7525 abbrev_number = read_leb128 (tags, & bytes_read, 0);
7528 /* A null DIE marks the end of a list of children. */
7529 if (abbrev_number == 0)
7535 /* Scan through the abbreviation list until we reach the
7537 for (entry = first_abbrev;
7538 entry && entry->entry != abbrev_number;
7539 entry = entry->next)
7544 warn (_("Unable to locate entry %lu in the abbreviation table\n"),
7549 printf (_(" <%d><%lx>: Abbrev Number: %lu (%s)\n"),
7551 (unsigned long) (tags - section_begin - bytes_read),
7553 get_TAG_name (entry->tag));
7555 for (attr = entry->first_attr; attr; attr = attr->next)
7556 tags = read_and_display_attr (attr->attribute,
7559 compunit.cu_pointer_size);
7561 if (entry->children)
7574 display_debug_aranges (section, start, file)
7575 Elf32_Internal_Shdr * section;
7576 unsigned char * start;
7577 FILE * file ATTRIBUTE_UNUSED;
7579 unsigned char * end = start + section->sh_size;
7581 printf (_("The section %s contains:\n\n"), SECTION_NAME (section));
7585 DWARF2_External_ARange * external;
7586 DWARF2_Internal_ARange arange;
7587 unsigned char * ranges;
7588 unsigned long length;
7589 unsigned long address;
7592 external = (DWARF2_External_ARange *) start;
7594 arange.ar_length = BYTE_GET (external->ar_length);
7595 arange.ar_version = BYTE_GET (external->ar_version);
7596 arange.ar_info_offset = BYTE_GET (external->ar_info_offset);
7597 arange.ar_pointer_size = BYTE_GET (external->ar_pointer_size);
7598 arange.ar_segment_size = BYTE_GET (external->ar_segment_size);
7600 if (arange.ar_length == 0xffffffff)
7602 warn (_("64-bit DWARF aranges are not supported yet.\n"));
7606 if (arange.ar_version != 2)
7608 warn (_("Only DWARF 2 aranges are currently supported.\n"));
7612 printf (_(" Length: %ld\n"), arange.ar_length);
7613 printf (_(" Version: %d\n"), arange.ar_version);
7614 printf (_(" Offset into .debug_info: %lx\n"), arange.ar_info_offset);
7615 printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
7616 printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
7618 printf (_("\n Address Length\n"));
7620 ranges = start + sizeof (* external);
7622 /* Must pad to an alignment boundary that is twice the pointer size. */
7623 excess = sizeof (* external) % (2 * arange.ar_pointer_size);
7625 ranges += (2 * arange.ar_pointer_size) - excess;
7629 address = byte_get (ranges, arange.ar_pointer_size);
7631 ranges += arange.ar_pointer_size;
7633 length = byte_get (ranges, arange.ar_pointer_size);
7635 ranges += arange.ar_pointer_size;
7637 /* A pair of zeros marks the end of the list. */
7638 if (address == 0 && length == 0)
7641 printf (" %8.8lx %lu\n", address, length);
7644 start += arange.ar_length + sizeof (external->ar_length);
7652 typedef struct Frame_Chunk
7654 struct Frame_Chunk * next;
7655 unsigned char * chunk_start;
7657 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
7658 short int * col_type;
7660 char * augmentation;
7661 unsigned int code_factor;
7663 unsigned long pc_begin;
7664 unsigned long pc_range;
7668 unsigned char fde_encoding;
7672 /* A marker for a col_type that means this column was never referenced
7673 in the frame info. */
7674 #define DW_CFA_unreferenced (-1)
7676 static void frame_need_space PARAMS ((Frame_Chunk *, int));
7677 static void frame_display_row PARAMS ((Frame_Chunk *, int *, int *));
7678 static int size_of_encoded_value PARAMS ((int));
7681 frame_need_space (fc, reg)
7685 int prev = fc->ncols;
7687 if (reg < fc->ncols)
7690 fc->ncols = reg + 1;
7691 fc->col_type = (short int *) xrealloc (fc->col_type,
7692 fc->ncols * sizeof (short int));
7693 fc->col_offset = (int *) xrealloc (fc->col_offset,
7694 fc->ncols * sizeof (int));
7696 while (prev < fc->ncols)
7698 fc->col_type[prev] = DW_CFA_unreferenced;
7699 fc->col_offset[prev] = 0;
7705 frame_display_row (fc, need_col_headers, max_regs)
7707 int * need_col_headers;
7713 if (* max_regs < fc->ncols)
7714 * max_regs = fc->ncols;
7716 if (* need_col_headers)
7718 * need_col_headers = 0;
7720 printf (" LOC CFA ");
7722 for (r = 0; r < * max_regs; r++)
7723 if (fc->col_type[r] != DW_CFA_unreferenced)
7728 printf ("r%-4d", r);
7734 printf ("%08lx ", fc->pc_begin);
7735 sprintf (tmp, "r%d%+d", fc->cfa_reg, fc->cfa_offset);
7736 printf ("%-8s ", tmp);
7738 for (r = 0; r < fc->ncols; r++)
7740 if (fc->col_type[r] != DW_CFA_unreferenced)
7742 switch (fc->col_type[r])
7744 case DW_CFA_undefined:
7747 case DW_CFA_same_value:
7751 sprintf (tmp, "c%+d", fc->col_offset[r]);
7753 case DW_CFA_register:
7754 sprintf (tmp, "r%d", fc->col_offset[r]);
7757 strcpy (tmp, "n/a");
7760 printf ("%-5s", tmp);
7767 size_of_encoded_value (encoding)
7770 switch (encoding & 0x7)
7773 case 0: return is_32bit_elf ? 4 : 8;
7780 #define GET(N) byte_get (start, N); start += N
7781 #define LEB() read_leb128 (start, & length_return, 0); start += length_return
7782 #define SLEB() read_leb128 (start, & length_return, 1); start += length_return
7785 display_debug_frames (section, start, file)
7786 Elf32_Internal_Shdr * section;
7787 unsigned char * start;
7788 FILE * file ATTRIBUTE_UNUSED;
7790 unsigned char * end = start + section->sh_size;
7791 unsigned char * section_start = start;
7792 Frame_Chunk * chunks = 0;
7793 Frame_Chunk * remembered_state = 0;
7795 int is_eh = (strcmp (SECTION_NAME (section), ".eh_frame") == 0);
7798 int addr_size = is_32bit_elf ? 4 : 8;
7800 printf (_("The section %s contains:\n"), SECTION_NAME (section));
7804 unsigned char * saved_start;
7805 unsigned char * block_end;
7806 unsigned long length;
7807 unsigned long cie_id;
7810 int need_col_headers = 1;
7811 unsigned char * augmentation_data = NULL;
7812 unsigned long augmentation_data_len = 0;
7813 int encoded_ptr_size = addr_size;
7815 saved_start = start;
7816 length = byte_get (start, 4); start += 4;
7821 if (length == 0xffffffff)
7823 warn (_("64-bit DWARF format frames are not supported yet.\n"));
7827 block_end = saved_start + length + 4;
7828 cie_id = byte_get (start, 4); start += 4;
7830 if (is_eh ? (cie_id == 0) : (cie_id == DW_CIE_ID))
7834 fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
7835 memset (fc, 0, sizeof (Frame_Chunk));
7839 fc->chunk_start = saved_start;
7841 fc->col_type = (short int *) xmalloc (sizeof (short int));
7842 fc->col_offset = (int *) xmalloc (sizeof (int));
7843 frame_need_space (fc, max_regs-1);
7847 fc->augmentation = start;
7848 start = strchr (start, '\0') + 1;
7850 if (fc->augmentation[0] == 'z')
7852 fc->code_factor = LEB ();
7853 fc->data_factor = SLEB ();
7854 fc->ra = byte_get (start, 1); start += 1;
7855 augmentation_data_len = LEB ();
7856 augmentation_data = start;
7857 start += augmentation_data_len;
7859 else if (strcmp (fc->augmentation, "eh") == 0)
7862 fc->code_factor = LEB ();
7863 fc->data_factor = SLEB ();
7864 fc->ra = byte_get (start, 1); start += 1;
7868 fc->code_factor = LEB ();
7869 fc->data_factor = SLEB ();
7870 fc->ra = byte_get (start, 1); start += 1;
7874 if (do_debug_frames_interp)
7875 printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n",
7876 (unsigned long)(saved_start - section_start), length, cie_id,
7877 fc->augmentation, fc->code_factor, fc->data_factor,
7881 printf ("\n%08lx %08lx %08lx CIE\n",
7882 (unsigned long)(saved_start - section_start), length, cie_id);
7883 printf (" Version: %d\n", version);
7884 printf (" Augmentation: \"%s\"\n", fc->augmentation);
7885 printf (" Code alignment factor: %u\n", fc->code_factor);
7886 printf (" Data alignment factor: %d\n", fc->data_factor);
7887 printf (" Return address column: %d\n", fc->ra);
7889 if (augmentation_data_len)
7892 printf (" Augmentation data: ");
7893 for (i = 0; i < augmentation_data_len; ++i)
7894 printf (" %02x", augmentation_data[i]);
7900 if (augmentation_data_len)
7902 unsigned char *p, *q;
7903 p = fc->augmentation + 1;
7904 q = augmentation_data;
7911 q += 1 + size_of_encoded_value (*q);
7913 fc->fde_encoding = *q++;
7919 if (fc->fde_encoding)
7920 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
7923 frame_need_space (fc, fc->ra);
7927 unsigned char * look_for;
7928 static Frame_Chunk fde_fc;
7931 memset (fc, 0, sizeof (Frame_Chunk));
7933 look_for = is_eh ? start - 4 - cie_id : section_start + cie_id;
7935 for (cie = chunks; cie ; cie = cie->next)
7936 if (cie->chunk_start == look_for)
7941 warn ("Invalid CIE pointer %08lx in FDE at %08lx\n",
7942 cie_id, saved_start);
7945 fc->col_type = (short int *) xmalloc (sizeof (short int));
7946 fc->col_offset = (int *) xmalloc (sizeof (int));
7947 frame_need_space (fc, max_regs - 1);
7949 fc->augmentation = "";
7950 fc->fde_encoding = 0;
7954 fc->ncols = cie->ncols;
7955 fc->col_type = (short int *) xmalloc (fc->ncols * sizeof (short int));
7956 fc->col_offset = (int *) xmalloc (fc->ncols * sizeof (int));
7957 memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int));
7958 memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int));
7959 fc->augmentation = cie->augmentation;
7960 fc->code_factor = cie->code_factor;
7961 fc->data_factor = cie->data_factor;
7962 fc->cfa_reg = cie->cfa_reg;
7963 fc->cfa_offset = cie->cfa_offset;
7965 frame_need_space (fc, max_regs-1);
7966 fc->fde_encoding = cie->fde_encoding;
7969 if (fc->fde_encoding)
7970 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
7972 fc->pc_begin = byte_get (start, encoded_ptr_size);
7973 start += encoded_ptr_size;
7974 fc->pc_range = byte_get (start, encoded_ptr_size);
7975 start += encoded_ptr_size;
7977 if (cie->augmentation[0] == 'z')
7979 augmentation_data_len = LEB ();
7980 augmentation_data = start;
7981 start += augmentation_data_len;
7984 printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=%08lx..%08lx\n",
7985 (unsigned long)(saved_start - section_start), length, cie_id,
7986 (unsigned long)(cie->chunk_start - section_start),
7987 fc->pc_begin, fc->pc_begin + fc->pc_range);
7988 if (! do_debug_frames_interp && augmentation_data_len)
7991 printf (" Augmentation data: ");
7992 for (i = 0; i < augmentation_data_len; ++i)
7993 printf (" %02x", augmentation_data[i]);
7999 /* At this point, fc is the current chunk, cie (if any) is set, and we're
8000 about to interpret instructions for the chunk. */
8002 if (do_debug_frames_interp)
8004 /* Start by making a pass over the chunk, allocating storage
8005 and taking note of what registers are used. */
8006 unsigned char * tmp = start;
8008 while (start < block_end)
8018 /* Warning: if you add any more cases to this switch, be
8019 sure to add them to the corresponding switch below. */
8022 case DW_CFA_advance_loc:
8026 frame_need_space (fc, opa);
8027 fc->col_type[opa] = DW_CFA_undefined;
8029 case DW_CFA_restore:
8030 frame_need_space (fc, opa);
8031 fc->col_type[opa] = DW_CFA_undefined;
8033 case DW_CFA_set_loc:
8034 start += encoded_ptr_size;
8036 case DW_CFA_advance_loc1:
8039 case DW_CFA_advance_loc2:
8042 case DW_CFA_advance_loc4:
8045 case DW_CFA_offset_extended:
8046 reg = LEB (); LEB ();
8047 frame_need_space (fc, reg);
8048 fc->col_type[reg] = DW_CFA_undefined;
8050 case DW_CFA_restore_extended:
8052 frame_need_space (fc, reg);
8053 fc->col_type[reg] = DW_CFA_undefined;
8055 case DW_CFA_undefined:
8057 frame_need_space (fc, reg);
8058 fc->col_type[reg] = DW_CFA_undefined;
8060 case DW_CFA_same_value:
8062 frame_need_space (fc, reg);
8063 fc->col_type[reg] = DW_CFA_undefined;
8065 case DW_CFA_register:
8066 reg = LEB (); LEB ();
8067 frame_need_space (fc, reg);
8068 fc->col_type[reg] = DW_CFA_undefined;
8070 case DW_CFA_def_cfa:
8073 case DW_CFA_def_cfa_register:
8076 case DW_CFA_def_cfa_offset:
8079 #ifndef DW_CFA_GNU_args_size
8080 #define DW_CFA_GNU_args_size 0x2e
8082 case DW_CFA_GNU_args_size:
8085 #ifndef DW_CFA_GNU_negative_offset_extended
8086 #define DW_CFA_GNU_negative_offset_extended 0x2f
8088 case DW_CFA_GNU_negative_offset_extended:
8089 reg = LEB (); LEB ();
8090 frame_need_space (fc, reg);
8091 fc->col_type[reg] = DW_CFA_undefined;
8100 /* Now we know what registers are used, make a second pass over
8101 the chunk, this time actually printing out the info. */
8103 while (start < block_end)
8106 unsigned long ul, reg, roffs;
8115 /* Warning: if you add any more cases to this switch, be
8116 sure to add them to the corresponding switch above. */
8119 case DW_CFA_advance_loc:
8120 if (do_debug_frames_interp)
8121 frame_display_row (fc, &need_col_headers, &max_regs);
8123 printf (" DW_CFA_advance_loc: %d to %08lx\n",
8124 opa * fc->code_factor,
8125 fc->pc_begin + opa * fc->code_factor);
8126 fc->pc_begin += opa * fc->code_factor;
8131 if (! do_debug_frames_interp)
8132 printf (" DW_CFA_offset: r%d at cfa%+ld\n",
8133 opa, roffs * fc->data_factor);
8134 fc->col_type[opa] = DW_CFA_offset;
8135 fc->col_offset[opa] = roffs * fc->data_factor;
8138 case DW_CFA_restore:
8139 if (! do_debug_frames_interp)
8140 printf (" DW_CFA_restore: r%d\n", opa);
8141 fc->col_type[opa] = cie->col_type[opa];
8142 fc->col_offset[opa] = cie->col_offset[opa];
8145 case DW_CFA_set_loc:
8146 vma = byte_get (start, encoded_ptr_size);
8147 start += encoded_ptr_size;
8148 if (do_debug_frames_interp)
8149 frame_display_row (fc, &need_col_headers, &max_regs);
8151 printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma);
8155 case DW_CFA_advance_loc1:
8156 ofs = byte_get (start, 1); start += 1;
8157 if (do_debug_frames_interp)
8158 frame_display_row (fc, &need_col_headers, &max_regs);
8160 printf (" DW_CFA_advance_loc1: %ld to %08lx\n",
8161 ofs * fc->code_factor,
8162 fc->pc_begin + ofs * fc->code_factor);
8163 fc->pc_begin += ofs * fc->code_factor;
8166 case DW_CFA_advance_loc2:
8167 ofs = byte_get (start, 2); start += 2;
8168 if (do_debug_frames_interp)
8169 frame_display_row (fc, &need_col_headers, &max_regs);
8171 printf (" DW_CFA_advance_loc2: %ld to %08lx\n",
8172 ofs * fc->code_factor,
8173 fc->pc_begin + ofs * fc->code_factor);
8174 fc->pc_begin += ofs * fc->code_factor;
8177 case DW_CFA_advance_loc4:
8178 ofs = byte_get (start, 4); start += 4;
8179 if (do_debug_frames_interp)
8180 frame_display_row (fc, &need_col_headers, &max_regs);
8182 printf (" DW_CFA_advance_loc4: %ld to %08lx\n",
8183 ofs * fc->code_factor,
8184 fc->pc_begin + ofs * fc->code_factor);
8185 fc->pc_begin += ofs * fc->code_factor;
8188 case DW_CFA_offset_extended:
8191 if (! do_debug_frames_interp)
8192 printf (" DW_CFA_offset_extended: r%ld at cfa%+ld\n",
8193 reg, roffs * fc->data_factor);
8194 fc->col_type[reg] = DW_CFA_offset;
8195 fc->col_offset[reg] = roffs * fc->data_factor;
8198 case DW_CFA_restore_extended:
8200 if (! do_debug_frames_interp)
8201 printf (" DW_CFA_restore_extended: r%ld\n", reg);
8202 fc->col_type[reg] = cie->col_type[reg];
8203 fc->col_offset[reg] = cie->col_offset[reg];
8206 case DW_CFA_undefined:
8208 if (! do_debug_frames_interp)
8209 printf (" DW_CFA_undefined: r%ld\n", reg);
8210 fc->col_type[reg] = DW_CFA_undefined;
8211 fc->col_offset[reg] = 0;
8214 case DW_CFA_same_value:
8216 if (! do_debug_frames_interp)
8217 printf (" DW_CFA_same_value: r%ld\n", reg);
8218 fc->col_type[reg] = DW_CFA_same_value;
8219 fc->col_offset[reg] = 0;
8222 case DW_CFA_register:
8225 if (! do_debug_frames_interp)
8226 printf (" DW_CFA_register: r%ld\n", reg);
8227 fc->col_type[reg] = DW_CFA_register;
8228 fc->col_offset[reg] = roffs;
8231 case DW_CFA_remember_state:
8232 if (! do_debug_frames_interp)
8233 printf (" DW_CFA_remember_state\n");
8234 rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
8235 rs->ncols = fc->ncols;
8236 rs->col_type = (short int *) xmalloc (rs->ncols * sizeof (short int));
8237 rs->col_offset = (int *) xmalloc (rs->ncols * sizeof (int));
8238 memcpy (rs->col_type, fc->col_type, rs->ncols);
8239 memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (int));
8240 rs->next = remembered_state;
8241 remembered_state = rs;
8244 case DW_CFA_restore_state:
8245 if (! do_debug_frames_interp)
8246 printf (" DW_CFA_restore_state\n");
8247 rs = remembered_state;
8248 remembered_state = rs->next;
8249 frame_need_space (fc, rs->ncols-1);
8250 memcpy (fc->col_type, rs->col_type, rs->ncols);
8251 memcpy (fc->col_offset, rs->col_offset, rs->ncols * sizeof (int));
8252 free (rs->col_type);
8253 free (rs->col_offset);
8257 case DW_CFA_def_cfa:
8258 fc->cfa_reg = LEB ();
8259 fc->cfa_offset = LEB ();
8260 if (! do_debug_frames_interp)
8261 printf (" DW_CFA_def_cfa: r%d ofs %d\n",
8262 fc->cfa_reg, fc->cfa_offset);
8265 case DW_CFA_def_cfa_register:
8266 fc->cfa_reg = LEB ();
8267 if (! do_debug_frames_interp)
8268 printf (" DW_CFA_def_cfa_reg: r%d\n", fc->cfa_reg);
8271 case DW_CFA_def_cfa_offset:
8272 fc->cfa_offset = LEB ();
8273 if (! do_debug_frames_interp)
8274 printf (" DW_CFA_def_cfa_offset: %d\n", fc->cfa_offset);
8278 if (! do_debug_frames_interp)
8279 printf (" DW_CFA_nop\n");
8282 #ifndef DW_CFA_GNU_window_save
8283 #define DW_CFA_GNU_window_save 0x2d
8285 case DW_CFA_GNU_window_save:
8286 if (! do_debug_frames_interp)
8287 printf (" DW_CFA_GNU_window_save\n");
8290 case DW_CFA_GNU_args_size:
8292 if (! do_debug_frames_interp)
8293 printf (" DW_CFA_GNU_args_size: %ld\n", ul);
8296 case DW_CFA_GNU_negative_offset_extended:
8299 frame_need_space (fc, reg);
8300 if (! do_debug_frames_interp)
8301 printf (" DW_CFA_GNU_negative_offset_extended: r%ld at cfa%+ld\n",
8302 reg, l * fc->data_factor);
8303 fc->col_type[reg] = DW_CFA_offset;
8304 fc->col_offset[reg] = l * fc->data_factor;
8308 fprintf (stderr, "unsupported or unknown DW_CFA_%d\n", op);
8313 if (do_debug_frames_interp)
8314 frame_display_row (fc, &need_col_headers, &max_regs);
8329 display_debug_not_supported (section, start, file)
8330 Elf32_Internal_Shdr * section;
8331 unsigned char * start ATTRIBUTE_UNUSED;
8332 FILE * file ATTRIBUTE_UNUSED;
8334 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
8335 SECTION_NAME (section));
8340 /* Pre-scan the .debug_info section to record the size of address.
8341 When dumping the .debug_line, we use that size information, assuming
8342 that all compilation units have the same address size. */
8344 prescan_debug_info (section, start, file)
8345 Elf32_Internal_Shdr * section ATTRIBUTE_UNUSED;
8346 unsigned char * start;
8347 FILE * file ATTRIBUTE_UNUSED;
8349 DWARF2_External_CompUnit * external;
8351 external = (DWARF2_External_CompUnit *) start;
8353 debug_line_pointer_size = BYTE_GET (external->cu_pointer_size);
8357 /* A structure containing the name of a debug section and a pointer
8358 to a function that can decode it. The third field is a prescan
8359 function to be run over the section before displaying any of the
8363 const char * const name;
8364 int (* display) PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
8365 int (* prescan) PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
8369 { ".debug_abbrev", display_debug_abbrev, NULL },
8370 { ".debug_aranges", display_debug_aranges, NULL },
8371 { ".debug_frame", display_debug_frames, NULL },
8372 { ".debug_info", display_debug_info, prescan_debug_info },
8373 { ".debug_line", display_debug_lines, NULL },
8374 { ".debug_pubnames", display_debug_pubnames, NULL },
8375 { ".eh_frame", display_debug_frames, NULL },
8376 { ".debug_macinfo", display_debug_macinfo, NULL },
8377 { ".debug_str", display_debug_str, NULL },
8379 { ".debug_pubtypes", display_debug_not_supported, NULL },
8380 { ".debug_ranges", display_debug_not_supported, NULL },
8381 { ".debug_static_func", display_debug_not_supported, NULL },
8382 { ".debug_static_vars", display_debug_not_supported, NULL },
8383 { ".debug_types", display_debug_not_supported, NULL },
8384 { ".debug_weaknames", display_debug_not_supported, NULL }
8388 display_debug_section (section, file)
8389 Elf32_Internal_Shdr * section;
8392 char * name = SECTION_NAME (section);
8393 bfd_size_type length;
8394 unsigned char * start;
8397 length = section->sh_size;
8400 printf (_("\nSection '%s' has no debugging data.\n"), name);
8404 start = (unsigned char *) get_data (NULL, file, section->sh_offset, length,
8405 _("debug section data"));
8409 /* See if we know how to display the contents of this section. */
8410 if (strncmp (name, ".gnu.linkonce.wi.", 17) == 0)
8411 name = ".debug_info";
8413 for (i = NUM_ELEM (debug_displays); i--;)
8414 if (strcmp (debug_displays[i].name, name) == 0)
8416 debug_displays[i].display (section, start, file);
8421 printf (_("Unrecognised debug section: %s\n"), name);
8425 /* If we loaded in the abbrev section at some point,
8426 we must release it here. */
8433 process_section_contents (file)
8436 Elf32_Internal_Shdr * section;
8442 /* Pre-scan the debug sections to find some debug information not
8443 present in some of them. For the .debug_line, we must find out the
8444 size of address (specified in .debug_info and .debug_aranges). */
8445 for (i = 0, section = section_headers;
8446 i < elf_header.e_shnum && i < num_dump_sects;
8449 char * name = SECTION_NAME (section);
8452 if (section->sh_size == 0)
8455 /* See if there is some pre-scan operation for this section. */
8456 for (j = NUM_ELEM (debug_displays); j--;)
8457 if (strcmp (debug_displays[j].name, name) == 0)
8459 if (debug_displays[j].prescan != NULL)
8461 bfd_size_type length;
8462 unsigned char * start;
8464 length = section->sh_size;
8465 start = ((unsigned char *)
8466 get_data (NULL, file, section->sh_offset, length,
8467 _("debug section data")));
8471 debug_displays[j].prescan (section, start, file);
8479 for (i = 0, section = section_headers;
8480 i < elf_header.e_shnum && i < num_dump_sects;
8483 #ifdef SUPPORT_DISASSEMBLY
8484 if (dump_sects[i] & DISASS_DUMP)
8485 disassemble_section (section, file);
8487 if (dump_sects[i] & HEX_DUMP)
8488 dump_section (section, file);
8490 if (dump_sects[i] & DEBUG_DUMP)
8491 display_debug_section (section, file);
8494 if (i < num_dump_sects)
8495 warn (_("Some sections were not dumped because they do not exist!\n"));
8501 process_mips_fpe_exception (mask)
8507 if (mask & OEX_FPU_INEX)
8508 fputs ("INEX", stdout), first = 0;
8509 if (mask & OEX_FPU_UFLO)
8510 printf ("%sUFLO", first ? "" : "|"), first = 0;
8511 if (mask & OEX_FPU_OFLO)
8512 printf ("%sOFLO", first ? "" : "|"), first = 0;
8513 if (mask & OEX_FPU_DIV0)
8514 printf ("%sDIV0", first ? "" : "|"), first = 0;
8515 if (mask & OEX_FPU_INVAL)
8516 printf ("%sINVAL", first ? "" : "|");
8519 fputs ("0", stdout);
8523 process_mips_specific (file)
8526 Elf_Internal_Dyn * entry;
8527 size_t liblist_offset = 0;
8528 size_t liblistno = 0;
8529 size_t conflictsno = 0;
8530 size_t options_offset = 0;
8531 size_t conflicts_offset = 0;
8533 /* We have a lot of special sections. Thanks SGI! */
8534 if (dynamic_segment == NULL)
8535 /* No information available. */
8538 for (entry = dynamic_segment; entry->d_tag != DT_NULL; ++entry)
8539 switch (entry->d_tag)
8541 case DT_MIPS_LIBLIST:
8542 liblist_offset = entry->d_un.d_val - loadaddr;
8544 case DT_MIPS_LIBLISTNO:
8545 liblistno = entry->d_un.d_val;
8547 case DT_MIPS_OPTIONS:
8548 options_offset = entry->d_un.d_val - loadaddr;
8550 case DT_MIPS_CONFLICT:
8551 conflicts_offset = entry->d_un.d_val - loadaddr;
8553 case DT_MIPS_CONFLICTNO:
8554 conflictsno = entry->d_un.d_val;
8560 if (liblist_offset != 0 && liblistno != 0 && do_dynamic)
8562 Elf32_External_Lib * elib;
8565 elib = ((Elf32_External_Lib *)
8566 get_data (NULL, file, liblist_offset,
8567 liblistno * sizeof (Elf32_External_Lib),
8571 printf ("\nSection '.liblist' contains %lu entries:\n",
8572 (unsigned long) liblistno);
8573 fputs (" Library Time Stamp Checksum Version Flags\n",
8576 for (cnt = 0; cnt < liblistno; ++cnt)
8583 liblist.l_name = BYTE_GET (elib[cnt].l_name);
8584 time = BYTE_GET (elib[cnt].l_time_stamp);
8585 liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum);
8586 liblist.l_version = BYTE_GET (elib[cnt].l_version);
8587 liblist.l_flags = BYTE_GET (elib[cnt].l_flags);
8589 tmp = gmtime (&time);
8590 sprintf (timebuf, "%04u-%02u-%02uT%02u:%02u:%02u",
8591 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
8592 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
8594 printf ("%3lu: %-20s %s %#10lx %-7ld", (unsigned long) cnt,
8595 dynamic_strings + liblist.l_name, timebuf,
8596 liblist.l_checksum, liblist.l_version);
8598 if (liblist.l_flags == 0)
8609 { " EXACT_MATCH", LL_EXACT_MATCH },
8610 { " IGNORE_INT_VER", LL_IGNORE_INT_VER },
8611 { " REQUIRE_MINOR", LL_REQUIRE_MINOR },
8612 { " EXPORTS", LL_EXPORTS },
8613 { " DELAY_LOAD", LL_DELAY_LOAD },
8614 { " DELTA", LL_DELTA }
8616 int flags = liblist.l_flags;
8620 fcnt < sizeof (l_flags_vals) / sizeof (l_flags_vals[0]);
8622 if ((flags & l_flags_vals[fcnt].bit) != 0)
8624 fputs (l_flags_vals[fcnt].name, stdout);
8625 flags ^= l_flags_vals[fcnt].bit;
8628 printf (" %#x", (unsigned int) flags);
8638 if (options_offset != 0)
8640 Elf_External_Options * eopt;
8641 Elf_Internal_Shdr * sect = section_headers;
8642 Elf_Internal_Options * iopt;
8643 Elf_Internal_Options * option;
8647 /* Find the section header so that we get the size. */
8648 while (sect->sh_type != SHT_MIPS_OPTIONS)
8651 eopt = (Elf_External_Options *) get_data (NULL, file, options_offset,
8652 sect->sh_size, _("options"));
8655 iopt = ((Elf_Internal_Options *)
8656 malloc ((sect->sh_size / sizeof (eopt)) * sizeof (* iopt)));
8659 error (_("Out of memory"));
8666 while (offset < sect->sh_size)
8668 Elf_External_Options * eoption;
8670 eoption = (Elf_External_Options *) ((char *) eopt + offset);
8672 option->kind = BYTE_GET (eoption->kind);
8673 option->size = BYTE_GET (eoption->size);
8674 option->section = BYTE_GET (eoption->section);
8675 option->info = BYTE_GET (eoption->info);
8677 offset += option->size;
8683 printf (_("\nSection '%s' contains %d entries:\n"),
8684 SECTION_NAME (sect), cnt);
8692 switch (option->kind)
8695 /* This shouldn't happen. */
8696 printf (" NULL %d %lx", option->section, option->info);
8699 printf (" REGINFO ");
8700 if (elf_header.e_machine == EM_MIPS)
8703 Elf32_External_RegInfo * ereg;
8704 Elf32_RegInfo reginfo;
8706 ereg = (Elf32_External_RegInfo *) (option + 1);
8707 reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask);
8708 reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
8709 reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
8710 reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
8711 reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
8712 reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value);
8714 printf ("GPR %08lx GP 0x%lx\n",
8716 (unsigned long) reginfo.ri_gp_value);
8717 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
8718 reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
8719 reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
8724 Elf64_External_RegInfo * ereg;
8725 Elf64_Internal_RegInfo reginfo;
8727 ereg = (Elf64_External_RegInfo *) (option + 1);
8728 reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask);
8729 reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
8730 reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
8731 reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
8732 reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
8733 reginfo.ri_gp_value = BYTE_GET8 (ereg->ri_gp_value);
8735 printf ("GPR %08lx GP 0x",
8736 reginfo.ri_gprmask);
8737 printf_vma (reginfo.ri_gp_value);
8740 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
8741 reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
8742 reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
8746 case ODK_EXCEPTIONS:
8747 fputs (" EXCEPTIONS fpe_min(", stdout);
8748 process_mips_fpe_exception (option->info & OEX_FPU_MIN);
8749 fputs (") fpe_max(", stdout);
8750 process_mips_fpe_exception ((option->info & OEX_FPU_MAX) >> 8);
8751 fputs (")", stdout);
8753 if (option->info & OEX_PAGE0)
8754 fputs (" PAGE0", stdout);
8755 if (option->info & OEX_SMM)
8756 fputs (" SMM", stdout);
8757 if (option->info & OEX_FPDBUG)
8758 fputs (" FPDBUG", stdout);
8759 if (option->info & OEX_DISMISS)
8760 fputs (" DISMISS", stdout);
8763 fputs (" PAD ", stdout);
8764 if (option->info & OPAD_PREFIX)
8765 fputs (" PREFIX", stdout);
8766 if (option->info & OPAD_POSTFIX)
8767 fputs (" POSTFIX", stdout);
8768 if (option->info & OPAD_SYMBOL)
8769 fputs (" SYMBOL", stdout);
8772 fputs (" HWPATCH ", stdout);
8773 if (option->info & OHW_R4KEOP)
8774 fputs (" R4KEOP", stdout);
8775 if (option->info & OHW_R8KPFETCH)
8776 fputs (" R8KPFETCH", stdout);
8777 if (option->info & OHW_R5KEOP)
8778 fputs (" R5KEOP", stdout);
8779 if (option->info & OHW_R5KCVTL)
8780 fputs (" R5KCVTL", stdout);
8783 fputs (" FILL ", stdout);
8784 /* XXX Print content of info word? */
8787 fputs (" TAGS ", stdout);
8788 /* XXX Print content of info word? */
8791 fputs (" HWAND ", stdout);
8792 if (option->info & OHWA0_R4KEOP_CHECKED)
8793 fputs (" R4KEOP_CHECKED", stdout);
8794 if (option->info & OHWA0_R4KEOP_CLEAN)
8795 fputs (" R4KEOP_CLEAN", stdout);
8798 fputs (" HWOR ", stdout);
8799 if (option->info & OHWA0_R4KEOP_CHECKED)
8800 fputs (" R4KEOP_CHECKED", stdout);
8801 if (option->info & OHWA0_R4KEOP_CLEAN)
8802 fputs (" R4KEOP_CLEAN", stdout);
8805 printf (" GP_GROUP %#06lx self-contained %#06lx",
8806 option->info & OGP_GROUP,
8807 (option->info & OGP_SELF) >> 16);
8810 printf (" IDENT %#06lx self-contained %#06lx",
8811 option->info & OGP_GROUP,
8812 (option->info & OGP_SELF) >> 16);
8815 /* This shouldn't happen. */
8816 printf (" %3d ??? %d %lx",
8817 option->kind, option->section, option->info);
8821 len = sizeof (* eopt);
8822 while (len < option->size)
8823 if (((char *) option)[len] >= ' '
8824 && ((char *) option)[len] < 0x7f)
8825 printf ("%c", ((char *) option)[len++]);
8827 printf ("\\%03o", ((char *) option)[len++]);
8829 fputs ("\n", stdout);
8837 if (conflicts_offset != 0 && conflictsno != 0)
8839 Elf32_Conflict * iconf;
8842 if (dynamic_symbols == NULL)
8844 error (_("conflict list with without table"));
8848 iconf = (Elf32_Conflict *) malloc (conflictsno * sizeof (* iconf));
8851 error (_("Out of memory"));
8857 Elf32_External_Conflict * econf32;
8859 econf32 = ((Elf32_External_Conflict *)
8860 get_data (NULL, file, conflicts_offset,
8861 conflictsno * sizeof (* econf32),
8866 for (cnt = 0; cnt < conflictsno; ++cnt)
8867 iconf[cnt] = BYTE_GET (econf32[cnt]);
8873 Elf64_External_Conflict * econf64;
8875 econf64 = ((Elf64_External_Conflict *)
8876 get_data (NULL, file, conflicts_offset,
8877 conflictsno * sizeof (* econf64),
8882 for (cnt = 0; cnt < conflictsno; ++cnt)
8883 iconf[cnt] = BYTE_GET (econf64[cnt]);
8888 printf (_("\nSection '.conflict' contains %ld entries:\n"),
8889 (long) conflictsno);
8890 puts (_(" Num: Index Value Name"));
8892 for (cnt = 0; cnt < conflictsno; ++cnt)
8894 Elf_Internal_Sym * psym = &dynamic_symbols[iconf[cnt]];
8896 printf ("%5lu: %8lu ", (unsigned long) cnt, iconf[cnt]);
8897 print_vma (psym->st_value, FULL_HEX);
8898 printf (" %s\n", dynamic_strings + psym->st_name);
8908 get_note_type (e_type)
8911 static char buff[64];
8915 case NT_PRSTATUS: return _("NT_PRSTATUS (prstatus structure)");
8916 case NT_FPREGSET: return _("NT_FPREGSET (floating point registers)");
8917 case NT_PRPSINFO: return _("NT_PRPSINFO (prpsinfo structure)");
8918 case NT_TASKSTRUCT: return _("NT_TASKSTRUCT (task structure)");
8919 case NT_PRXFPREG: return _("NT_PRXFPREG (user_xfpregs structure)");
8920 case NT_PSTATUS: return _("NT_PSTATUS (pstatus structure)");
8921 case NT_FPREGS: return _("NT_FPREGS (floating point registers)");
8922 case NT_PSINFO: return _("NT_PSINFO (psinfo structure)");
8923 case NT_LWPSTATUS: return _("NT_LWPSTATUS (lwpstatus_t structure)");
8924 case NT_LWPSINFO: return _("NT_LWPSINFO (lwpsinfo_t structure)");
8925 case NT_WIN32PSTATUS: return _("NT_WIN32PSTATUS (win32_pstatus strcuture)");
8927 sprintf (buff, _("Unknown note type: (0x%08x)"), e_type);
8932 /* Note that by the ELF standard, the name field is already null byte
8933 terminated, and namesz includes the terminating null byte.
8934 I.E. the value of namesz for the name "FSF" is 4.
8936 If the value of namesz is zero, there is no name present. */
8938 process_note (pnote)
8939 Elf32_Internal_Note * pnote;
8941 printf (" %s\t\t0x%08lx\t%s\n",
8942 pnote->namesz ? pnote->namedata : "(NONE)",
8943 pnote->descsz, get_note_type (pnote->type));
8949 process_corefile_note_segment (file, offset, length)
8954 Elf_External_Note * pnotes;
8955 Elf_External_Note * external;
8961 pnotes = (Elf_External_Note *) get_data (NULL, file, offset, length,
8968 printf (_("\nNotes at offset 0x%08lx with length 0x%08lx:\n"),
8969 (unsigned long) offset, (unsigned long) length);
8970 printf (_(" Owner\t\tData size\tDescription\n"));
8972 while (external < (Elf_External_Note *)((char *) pnotes + length))
8974 Elf32_Internal_Note inote;
8977 inote.type = BYTE_GET (external->type);
8978 inote.namesz = BYTE_GET (external->namesz);
8979 inote.namedata = external->name;
8980 inote.descsz = BYTE_GET (external->descsz);
8981 inote.descdata = inote.namedata + align_power (inote.namesz, 2);
8982 inote.descpos = offset + (inote.descdata - (char *) pnotes);
8984 external = (Elf_External_Note *)(inote.descdata + align_power (inote.descsz, 2));
8986 /* Verify that name is null terminated. It appears that at least
8987 one version of Linux (RedHat 6.0) generates corefiles that don't
8988 comply with the ELF spec by failing to include the null byte in
8990 if (inote.namedata[inote.namesz] != '\0')
8992 temp = malloc (inote.namesz + 1);
8996 error (_("Out of memory\n"));
9001 strncpy (temp, inote.namedata, inote.namesz);
9002 temp[inote.namesz] = 0;
9004 /* warn (_("'%s' NOTE name not properly null terminated\n"), temp); */
9005 inote.namedata = temp;
9008 res &= process_note (& inote);
9023 process_corefile_note_segments (file)
9026 Elf_Internal_Phdr * program_headers;
9027 Elf_Internal_Phdr * segment;
9031 program_headers = (Elf_Internal_Phdr *) malloc
9032 (elf_header.e_phnum * sizeof (Elf_Internal_Phdr));
9034 if (program_headers == NULL)
9036 error (_("Out of memory\n"));
9041 i = get_32bit_program_headers (file, program_headers);
9043 i = get_64bit_program_headers (file, program_headers);
9047 free (program_headers);
9051 for (i = 0, segment = program_headers;
9052 i < elf_header.e_phnum;
9055 if (segment->p_type == PT_NOTE)
9056 res &= process_corefile_note_segment (file,
9057 (bfd_vma) segment->p_offset,
9058 (bfd_vma) segment->p_filesz);
9061 free (program_headers);
9067 process_corefile_contents (file)
9070 /* If we have not been asked to display the notes then do nothing. */
9074 /* If file is not a core file then exit. */
9075 if (elf_header.e_type != ET_CORE)
9078 /* No program headers means no NOTE segment. */
9079 if (elf_header.e_phnum == 0)
9081 printf (_("No note segments present in the core file.\n"));
9085 return process_corefile_note_segments (file);
9089 process_arch_specific (file)
9095 switch (elf_header.e_machine)
9098 case EM_MIPS_RS3_LE:
9099 return process_mips_specific (file);
9108 get_file_header (file)
9111 /* Read in the identity array. */
9112 if (fread (elf_header.e_ident, EI_NIDENT, 1, file) != 1)
9115 /* Determine how to read the rest of the header. */
9116 switch (elf_header.e_ident [EI_DATA])
9118 default: /* fall through */
9119 case ELFDATANONE: /* fall through */
9120 case ELFDATA2LSB: byte_get = byte_get_little_endian; break;
9121 case ELFDATA2MSB: byte_get = byte_get_big_endian; break;
9124 /* For now we only support 32 bit and 64 bit ELF files. */
9125 is_32bit_elf = (elf_header.e_ident [EI_CLASS] != ELFCLASS64);
9127 /* Read in the rest of the header. */
9130 Elf32_External_Ehdr ehdr32;
9132 if (fread (ehdr32.e_type, sizeof (ehdr32) - EI_NIDENT, 1, file) != 1)
9135 elf_header.e_type = BYTE_GET (ehdr32.e_type);
9136 elf_header.e_machine = BYTE_GET (ehdr32.e_machine);
9137 elf_header.e_version = BYTE_GET (ehdr32.e_version);
9138 elf_header.e_entry = BYTE_GET (ehdr32.e_entry);
9139 elf_header.e_phoff = BYTE_GET (ehdr32.e_phoff);
9140 elf_header.e_shoff = BYTE_GET (ehdr32.e_shoff);
9141 elf_header.e_flags = BYTE_GET (ehdr32.e_flags);
9142 elf_header.e_ehsize = BYTE_GET (ehdr32.e_ehsize);
9143 elf_header.e_phentsize = BYTE_GET (ehdr32.e_phentsize);
9144 elf_header.e_phnum = BYTE_GET (ehdr32.e_phnum);
9145 elf_header.e_shentsize = BYTE_GET (ehdr32.e_shentsize);
9146 elf_header.e_shnum = BYTE_GET (ehdr32.e_shnum);
9147 elf_header.e_shstrndx = BYTE_GET (ehdr32.e_shstrndx);
9151 Elf64_External_Ehdr ehdr64;
9153 /* If we have been compiled with sizeof (bfd_vma) == 4, then
9154 we will not be able to cope with the 64bit data found in
9155 64 ELF files. Detect this now and abort before we start
9156 overwritting things. */
9157 if (sizeof (bfd_vma) < 8)
9159 error (_("This instance of readelf has been built without support for a\n\
9160 64 bit data type and so it cannot read 64 bit ELF files.\n"));
9164 if (fread (ehdr64.e_type, sizeof (ehdr64) - EI_NIDENT, 1, file) != 1)
9167 elf_header.e_type = BYTE_GET (ehdr64.e_type);
9168 elf_header.e_machine = BYTE_GET (ehdr64.e_machine);
9169 elf_header.e_version = BYTE_GET (ehdr64.e_version);
9170 elf_header.e_entry = BYTE_GET8 (ehdr64.e_entry);
9171 elf_header.e_phoff = BYTE_GET8 (ehdr64.e_phoff);
9172 elf_header.e_shoff = BYTE_GET8 (ehdr64.e_shoff);
9173 elf_header.e_flags = BYTE_GET (ehdr64.e_flags);
9174 elf_header.e_ehsize = BYTE_GET (ehdr64.e_ehsize);
9175 elf_header.e_phentsize = BYTE_GET (ehdr64.e_phentsize);
9176 elf_header.e_phnum = BYTE_GET (ehdr64.e_phnum);
9177 elf_header.e_shentsize = BYTE_GET (ehdr64.e_shentsize);
9178 elf_header.e_shnum = BYTE_GET (ehdr64.e_shnum);
9179 elf_header.e_shstrndx = BYTE_GET (ehdr64.e_shstrndx);
9186 process_file (file_name)
9190 struct stat statbuf;
9193 if (stat (file_name, & statbuf) < 0)
9195 error (_("Cannot stat input file %s.\n"), file_name);
9199 file = fopen (file_name, "rb");
9202 error (_("Input file %s not found.\n"), file_name);
9206 if (! get_file_header (file))
9208 error (_("%s: Failed to read file header\n"), file_name);
9213 /* Initialise per file variables. */
9214 for (i = NUM_ELEM (version_info); i--;)
9215 version_info[i] = 0;
9217 for (i = NUM_ELEM (dynamic_info); i--;)
9218 dynamic_info[i] = 0;
9220 /* Process the file. */
9222 printf (_("\nFile: %s\n"), file_name);
9224 if (! process_file_header ())
9230 process_section_headers (file);
9232 process_program_headers (file);
9234 process_dynamic_segment (file);
9236 process_relocs (file);
9238 process_unwind (file);
9240 process_symbol_table (file);
9242 process_syminfo (file);
9244 process_version_sections (file);
9246 process_section_contents (file);
9248 process_corefile_contents (file);
9250 process_arch_specific (file);
9254 if (section_headers)
9256 free (section_headers);
9257 section_headers = NULL;
9262 free (string_table);
9263 string_table = NULL;
9264 string_table_length = 0;
9267 if (dynamic_strings)
9269 free (dynamic_strings);
9270 dynamic_strings = NULL;
9273 if (dynamic_symbols)
9275 free (dynamic_symbols);
9276 dynamic_symbols = NULL;
9277 num_dynamic_syms = 0;
9280 if (dynamic_syminfo)
9282 free (dynamic_syminfo);
9283 dynamic_syminfo = NULL;
9289 #ifdef SUPPORT_DISASSEMBLY
9290 /* Needed by the i386 disassembler. For extra credit, someone could
9291 fix this so that we insert symbolic addresses here, esp for GOT/PLT
9295 print_address (unsigned int addr, FILE * outfile)
9297 fprintf (outfile,"0x%8.8x", addr);
9300 /* Needed by the i386 disassembler. */
9302 db_task_printsym (unsigned int addr)
9304 print_address (addr, stderr);
9308 int main PARAMS ((int, char **));
9317 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
9318 setlocale (LC_MESSAGES, "");
9320 #if defined (HAVE_SETLOCALE)
9321 setlocale (LC_CTYPE, "");
9323 bindtextdomain (PACKAGE, LOCALEDIR);
9324 textdomain (PACKAGE);
9326 parse_args (argc, argv);
9328 if (optind < (argc - 1))
9332 while (optind < argc)
9333 err |= process_file (argv [optind ++]);
9335 if (dump_sects != NULL)