1 /* readelf.c -- display contents of an ELF format file
2 Copyright 1998, 1999, 2000, 2001, 2002 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"
80 #include "elf/xstormy16.h"
85 char * program_name = "readelf";
86 unsigned int dynamic_addr;
87 bfd_size_type dynamic_size;
88 unsigned int rela_addr;
89 unsigned int rela_size;
90 char * dynamic_strings;
92 unsigned long string_table_length;
93 unsigned long num_dynamic_syms;
94 Elf_Internal_Sym * dynamic_symbols;
95 Elf_Internal_Syminfo * dynamic_syminfo;
96 unsigned long dynamic_syminfo_offset;
97 unsigned int dynamic_syminfo_nent;
98 char program_interpreter [64];
99 int dynamic_info[DT_JMPREL + 1];
100 int version_info[16];
102 Elf_Internal_Ehdr elf_header;
103 Elf_Internal_Shdr * section_headers;
104 Elf_Internal_Dyn * dynamic_segment;
105 Elf_Internal_Shdr * symtab_shndx_hdr;
113 int do_using_dynamic;
121 int do_debug_abbrevs;
123 int do_debug_pubnames;
124 int do_debug_aranges;
126 int do_debug_frames_interp;
127 int do_debug_macinfo;
133 /* A dynamic array of flags indicating which sections require dumping. */
134 char * dump_sects = NULL;
135 unsigned int num_dump_sects = 0;
137 #define HEX_DUMP (1 << 0)
138 #define DISASS_DUMP (1 << 1)
139 #define DEBUG_DUMP (1 << 2)
141 /* How to rpint a vma value. */
142 typedef enum print_mode
154 /* Forward declarations for dumb compilers. */
155 static void print_vma PARAMS ((bfd_vma, print_mode));
156 static void print_symbol PARAMS ((int, char *));
157 static bfd_vma (* byte_get) PARAMS ((unsigned char *, int));
158 static bfd_vma byte_get_little_endian PARAMS ((unsigned char *, int));
159 static bfd_vma byte_get_big_endian PARAMS ((unsigned char *, int));
160 static const char * get_mips_dynamic_type PARAMS ((unsigned long));
161 static const char * get_sparc64_dynamic_type PARAMS ((unsigned long));
162 static const char * get_ppc64_dynamic_type PARAMS ((unsigned long));
163 static const char * get_parisc_dynamic_type PARAMS ((unsigned long));
164 static const char * get_dynamic_type PARAMS ((unsigned long));
165 static int slurp_rela_relocs PARAMS ((FILE *, unsigned long, unsigned long, Elf_Internal_Rela **, unsigned long *));
166 static int slurp_rel_relocs PARAMS ((FILE *, unsigned long, unsigned long, Elf_Internal_Rel **, unsigned long *));
167 static int dump_relocations PARAMS ((FILE *, unsigned long, unsigned long, Elf_Internal_Sym *, unsigned long, char *, int));
168 static char * get_file_type PARAMS ((unsigned));
169 static char * get_machine_name PARAMS ((unsigned));
170 static void decode_ARM_machine_flags PARAMS ((unsigned, char []));
171 static char * get_machine_flags PARAMS ((unsigned, unsigned));
172 static const char * get_mips_segment_type PARAMS ((unsigned long));
173 static const char * get_parisc_segment_type PARAMS ((unsigned long));
174 static const char * get_ia64_segment_type PARAMS ((unsigned long));
175 static const char * get_segment_type PARAMS ((unsigned long));
176 static const char * get_mips_section_type_name PARAMS ((unsigned int));
177 static const char * get_parisc_section_type_name PARAMS ((unsigned int));
178 static const char * get_ia64_section_type_name PARAMS ((unsigned int));
179 static const char * get_section_type_name PARAMS ((unsigned int));
180 static const char * get_symbol_binding PARAMS ((unsigned int));
181 static const char * get_symbol_type PARAMS ((unsigned int));
182 static const char * get_symbol_visibility PARAMS ((unsigned int));
183 static const char * get_symbol_index_type PARAMS ((unsigned int));
184 static const char * get_dynamic_flags PARAMS ((bfd_vma));
185 static void usage PARAMS ((void));
186 static void parse_args PARAMS ((int, char **));
187 static int process_file_header PARAMS ((void));
188 static int process_program_headers PARAMS ((FILE *));
189 static int process_section_headers PARAMS ((FILE *));
190 static int process_unwind PARAMS ((FILE *));
191 static void dynamic_segment_mips_val PARAMS ((Elf_Internal_Dyn *));
192 static void dynamic_segment_parisc_val PARAMS ((Elf_Internal_Dyn *));
193 static int process_dynamic_segment PARAMS ((FILE *));
194 static int process_symbol_table PARAMS ((FILE *));
195 static int process_syminfo PARAMS ((FILE *));
196 static int process_section_contents PARAMS ((FILE *));
197 static void process_mips_fpe_exception PARAMS ((int));
198 static int process_mips_specific PARAMS ((FILE *));
199 static int process_file PARAMS ((char *));
200 static int process_relocs PARAMS ((FILE *));
201 static int process_version_sections PARAMS ((FILE *));
202 static char * get_ver_flags PARAMS ((unsigned int));
203 static int get_32bit_section_headers PARAMS ((FILE *, unsigned int));
204 static int get_64bit_section_headers PARAMS ((FILE *, unsigned int));
205 static int get_32bit_program_headers PARAMS ((FILE *, Elf_Internal_Phdr *));
206 static int get_64bit_program_headers PARAMS ((FILE *, Elf_Internal_Phdr *));
207 static int get_file_header PARAMS ((FILE *));
208 static Elf_Internal_Sym * get_32bit_elf_symbols PARAMS ((FILE *, Elf_Internal_Shdr *));
209 static Elf_Internal_Sym * get_64bit_elf_symbols PARAMS ((FILE *, Elf_Internal_Shdr *));
210 static const char * get_elf_section_flags PARAMS ((bfd_vma));
211 static int * get_dynamic_data PARAMS ((FILE *, unsigned int));
212 static int get_32bit_dynamic_segment PARAMS ((FILE *));
213 static int get_64bit_dynamic_segment PARAMS ((FILE *));
214 #ifdef SUPPORT_DISASSEMBLY
215 static int disassemble_section PARAMS ((Elf32_Internal_Shdr *, FILE *));
217 static int dump_section PARAMS ((Elf32_Internal_Shdr *, FILE *));
218 static int display_debug_section PARAMS ((Elf32_Internal_Shdr *, FILE *));
219 static int display_debug_info PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
220 static int display_debug_not_supported PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
221 static int prescan_debug_info PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
222 static int display_debug_lines PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
223 static int display_debug_pubnames PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
224 static int display_debug_abbrev PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
225 static int display_debug_aranges PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
226 static int display_debug_frames PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
227 static int display_debug_macinfo PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
228 static int display_debug_str PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
229 static unsigned char * process_abbrev_section PARAMS ((unsigned char *, unsigned char *));
230 static void load_debug_str PARAMS ((FILE *));
231 static void free_debug_str PARAMS ((void));
232 static const char * fetch_indirect_string PARAMS ((unsigned long));
233 static unsigned long read_leb128 PARAMS ((unsigned char *, int *, int));
234 static int process_extended_line_op PARAMS ((unsigned char *, int, int));
235 static void reset_state_machine PARAMS ((int));
236 static char * get_TAG_name PARAMS ((unsigned long));
237 static char * get_AT_name PARAMS ((unsigned long));
238 static char * get_FORM_name PARAMS ((unsigned long));
239 static void free_abbrevs PARAMS ((void));
240 static void add_abbrev PARAMS ((unsigned long, unsigned long, int));
241 static void add_abbrev_attr PARAMS ((unsigned long, unsigned long));
242 static unsigned char * read_and_display_attr PARAMS ((unsigned long, unsigned long, unsigned char *, unsigned long, unsigned long));
243 static unsigned char * read_and_display_attr_value PARAMS ((unsigned long, unsigned long, unsigned char *, unsigned long, unsigned long));
244 static unsigned char * display_block PARAMS ((unsigned char *, unsigned long));
245 static void decode_location_expression PARAMS ((unsigned char *, unsigned int, unsigned long));
246 static void request_dump PARAMS ((unsigned int, int));
247 static const char * get_elf_class PARAMS ((unsigned int));
248 static const char * get_data_encoding PARAMS ((unsigned int));
249 static const char * get_osabi_name PARAMS ((unsigned int));
250 static int guess_is_rela PARAMS ((unsigned long));
251 static const char * get_note_type PARAMS ((unsigned int));
252 static const char * get_netbsd_elfcore_note_type PARAMS ((unsigned int));
253 static int process_note PARAMS ((Elf32_Internal_Note *));
254 static int process_corefile_note_segment PARAMS ((FILE *, bfd_vma, bfd_vma));
255 static int process_corefile_note_segments PARAMS ((FILE *));
256 static int process_corefile_contents PARAMS ((FILE *));
257 static int process_arch_specific PARAMS ((FILE *));
259 typedef int Elf32_Word;
267 #define SECTION_NAME(X) ((X) == NULL ? "<none>" : \
268 ((X)->sh_name >= string_table_length \
269 ? "<corrupt>" : string_table + (X)->sh_name))
271 /* Given st_shndx I, map to section_headers index. */
272 #define SECTION_HEADER_INDEX(I) \
273 ((I) < SHN_LORESERVE \
275 : ((I) <= SHN_HIRESERVE \
277 : (I) - (SHN_HIRESERVE + 1 - SHN_LORESERVE)))
279 /* Reverse of the above. */
280 #define SECTION_HEADER_NUM(N) \
281 ((N) < SHN_LORESERVE \
283 : (N) + (SHN_HIRESERVE + 1 - SHN_LORESERVE))
285 #define SECTION_HEADER(I) (section_headers + SECTION_HEADER_INDEX (I))
287 #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
289 #define BYTE_GET(field) byte_get (field, sizeof (field))
291 /* If we can support a 64 bit data type then BFD64 should be defined
292 and sizeof (bfd_vma) == 8. In this case when translating from an
293 external 8 byte field to an internal field, we can assume that the
294 internal field is also 8 bytes wide and so we can extract all the data.
295 If, however, BFD64 is not defined, then we must assume that the
296 internal data structure only has 4 byte wide fields that are the
297 equivalent of the 8 byte wide external counterparts, and so we must
298 truncate the data. */
300 #define BYTE_GET8(field) byte_get (field, -8)
302 #define BYTE_GET8(field) byte_get (field, 8)
305 #define NUM_ELEM(array) (sizeof (array) / sizeof ((array)[0]))
307 #define GET_ELF_SYMBOLS(file, section) \
308 (is_32bit_elf ? get_32bit_elf_symbols (file, section) \
309 : get_64bit_elf_symbols (file, section))
313 error VPARAMS ((const char *message, ...))
315 VA_OPEN (args, message);
316 VA_FIXEDARG (args, const char *, message);
318 fprintf (stderr, _("%s: Error: "), program_name);
319 vfprintf (stderr, message, args);
324 warn VPARAMS ((const char *message, ...))
326 VA_OPEN (args, message);
327 VA_FIXEDARG (args, const char *, message);
329 fprintf (stderr, _("%s: Warning: "), program_name);
330 vfprintf (stderr, message, args);
334 static PTR get_data PARAMS ((PTR, FILE *, long, size_t, const char *));
337 get_data (var, file, offset, size, reason)
349 if (fseek (file, offset, SEEK_SET))
351 error (_("Unable to seek to %x for %s\n"), offset, reason);
358 mvar = (PTR) malloc (size);
362 error (_("Out of memory allocating %d bytes for %s\n"),
368 if (fread (mvar, size, 1, file) != 1)
370 error (_("Unable to read in %d bytes of %s\n"), size, reason);
380 byte_get_little_endian (field, size)
381 unsigned char * field;
390 return ((unsigned int) (field [0]))
391 | (((unsigned int) (field [1])) << 8);
395 /* We want to extract data from an 8 byte wide field and
396 place it into a 4 byte wide field. Since this is a little
397 endian source we can juts use the 4 byte extraction code. */
401 return ((unsigned long) (field [0]))
402 | (((unsigned long) (field [1])) << 8)
403 | (((unsigned long) (field [2])) << 16)
404 | (((unsigned long) (field [3])) << 24);
409 /* This is a special case, generated by the BYTE_GET8 macro.
410 It means that we are loading an 8 byte value from a field
411 in an external structure into an 8 byte value in a field
412 in an internal strcuture. */
413 return ((bfd_vma) (field [0]))
414 | (((bfd_vma) (field [1])) << 8)
415 | (((bfd_vma) (field [2])) << 16)
416 | (((bfd_vma) (field [3])) << 24)
417 | (((bfd_vma) (field [4])) << 32)
418 | (((bfd_vma) (field [5])) << 40)
419 | (((bfd_vma) (field [6])) << 48)
420 | (((bfd_vma) (field [7])) << 56);
423 error (_("Unhandled data length: %d\n"), size);
428 /* Print a VMA value. */
430 print_vma (vma, mode)
440 case FULL_HEX: printf ("0x"); /* drop through */
441 case LONG_HEX: printf ("%8.8lx", (unsigned long) vma); break;
442 case PREFIX_HEX: printf ("0x"); /* drop through */
443 case HEX: printf ("%lx", (unsigned long) vma); break;
444 case DEC: printf ("%ld", (unsigned long) vma); break;
445 case DEC_5: printf ("%5ld", (long) vma); break;
446 case UNSIGNED: printf ("%lu", (unsigned long) vma); break;
467 #if BFD_HOST_64BIT_LONG
470 if (_bfd_int64_high (vma))
471 printf ("%lx%8.8lx", _bfd_int64_high (vma), _bfd_int64_low (vma));
473 printf ("%lx", _bfd_int64_low (vma));
478 #if BFD_HOST_64BIT_LONG
481 if (_bfd_int64_high (vma))
483 printf ("++%ld", _bfd_int64_low (vma));
485 printf ("%ld", _bfd_int64_low (vma));
490 #if BFD_HOST_64BIT_LONG
491 printf ("%5ld", vma);
493 if (_bfd_int64_high (vma))
495 printf ("++%ld", _bfd_int64_low (vma));
497 printf ("%5ld", _bfd_int64_low (vma));
502 #if BFD_HOST_64BIT_LONG
505 if (_bfd_int64_high (vma))
507 printf ("++%lu", _bfd_int64_low (vma));
509 printf ("%lu", _bfd_int64_low (vma));
517 /* Display a symbol on stdout. If do_wide is not true then
518 format the symbol to be at most WIDTH characters,
519 truhncating as necessary. If WIDTH is negative then
520 format the string to be exactly - WIDTH characters,
521 truncating or padding as necessary. */
524 print_symbol (width, symbol)
531 printf ("%-*.*s", width, width, symbol);
533 printf ("%-.*s", width, symbol);
537 byte_get_big_endian (field, size)
538 unsigned char * field;
547 return ((unsigned int) (field [1])) | (((int) (field [0])) << 8);
550 return ((unsigned long) (field [3]))
551 | (((unsigned long) (field [2])) << 8)
552 | (((unsigned long) (field [1])) << 16)
553 | (((unsigned long) (field [0])) << 24);
557 /* Although we are extracing data from an 8 byte wide field, we
558 are returning only 4 bytes of data. */
559 return ((unsigned long) (field [7]))
560 | (((unsigned long) (field [6])) << 8)
561 | (((unsigned long) (field [5])) << 16)
562 | (((unsigned long) (field [4])) << 24);
566 /* This is a special case, generated by the BYTE_GET8 macro.
567 It means that we are loading an 8 byte value from a field
568 in an external structure into an 8 byte value in a field
569 in an internal strcuture. */
570 return ((bfd_vma) (field [7]))
571 | (((bfd_vma) (field [6])) << 8)
572 | (((bfd_vma) (field [5])) << 16)
573 | (((bfd_vma) (field [4])) << 24)
574 | (((bfd_vma) (field [3])) << 32)
575 | (((bfd_vma) (field [2])) << 40)
576 | (((bfd_vma) (field [1])) << 48)
577 | (((bfd_vma) (field [0])) << 56);
581 error (_("Unhandled data length: %d\n"), size);
586 /* Guess the relocation size commonly used by the specific machines. */
589 guess_is_rela (e_machine)
590 unsigned long e_machine;
594 /* Targets that use REL relocations. */
607 /* Targets that use RELA relocations. */
621 case EM_CYGNUS_MN10200:
623 case EM_CYGNUS_MN10300:
660 warn (_("Don't know about relocations on this machine architecture\n"));
666 slurp_rela_relocs (file, rel_offset, rel_size, relasp, nrelasp)
668 unsigned long rel_offset;
669 unsigned long rel_size;
670 Elf_Internal_Rela **relasp;
671 unsigned long *nrelasp;
673 Elf_Internal_Rela *relas;
674 unsigned long nrelas;
679 Elf32_External_Rela * erelas;
681 erelas = (Elf32_External_Rela *) get_data (NULL, file, rel_offset,
682 rel_size, _("relocs"));
686 nrelas = rel_size / sizeof (Elf32_External_Rela);
688 relas = (Elf_Internal_Rela *)
689 malloc (nrelas * sizeof (Elf_Internal_Rela));
693 error(_("out of memory parsing relocs"));
697 for (i = 0; i < nrelas; i++)
699 relas[i].r_offset = BYTE_GET (erelas[i].r_offset);
700 relas[i].r_info = BYTE_GET (erelas[i].r_info);
701 relas[i].r_addend = BYTE_GET (erelas[i].r_addend);
708 Elf64_External_Rela * erelas;
710 erelas = (Elf64_External_Rela *) get_data (NULL, file, rel_offset,
711 rel_size, _("relocs"));
715 nrelas = rel_size / sizeof (Elf64_External_Rela);
717 relas = (Elf_Internal_Rela *)
718 malloc (nrelas * sizeof (Elf_Internal_Rela));
722 error(_("out of memory parsing relocs"));
726 for (i = 0; i < nrelas; i++)
728 relas[i].r_offset = BYTE_GET8 (erelas[i].r_offset);
729 relas[i].r_info = BYTE_GET8 (erelas[i].r_info);
730 relas[i].r_addend = BYTE_GET8 (erelas[i].r_addend);
741 slurp_rel_relocs (file, rel_offset, rel_size, relsp, nrelsp)
743 unsigned long rel_offset;
744 unsigned long rel_size;
745 Elf_Internal_Rel **relsp;
746 unsigned long *nrelsp;
748 Elf_Internal_Rel *rels;
754 Elf32_External_Rel * erels;
756 erels = (Elf32_External_Rel *) get_data (NULL, file, rel_offset,
757 rel_size, _("relocs"));
761 nrels = rel_size / sizeof (Elf32_External_Rel);
763 rels = (Elf_Internal_Rel *) malloc (nrels * sizeof (Elf_Internal_Rel));
767 error(_("out of memory parsing relocs"));
771 for (i = 0; i < nrels; i++)
773 rels[i].r_offset = BYTE_GET (erels[i].r_offset);
774 rels[i].r_info = BYTE_GET (erels[i].r_info);
781 Elf64_External_Rel * erels;
783 erels = (Elf64_External_Rel *) get_data (NULL, file, rel_offset,
784 rel_size, _("relocs"));
788 nrels = rel_size / sizeof (Elf64_External_Rel);
790 rels = (Elf_Internal_Rel *) malloc (nrels * sizeof (Elf_Internal_Rel));
794 error(_("out of memory parsing relocs"));
798 for (i = 0; i < nrels; i++)
800 rels[i].r_offset = BYTE_GET8 (erels[i].r_offset);
801 rels[i].r_info = BYTE_GET8 (erels[i].r_info);
811 /* Display the contents of the relocation data found at the specified offset. */
813 dump_relocations (file, rel_offset, rel_size, symtab, nsyms, strtab, is_rela)
815 unsigned long rel_offset;
816 unsigned long rel_size;
817 Elf_Internal_Sym * symtab;
823 Elf_Internal_Rel * rels;
824 Elf_Internal_Rela * relas;
827 if (is_rela == UNKNOWN)
828 is_rela = guess_is_rela (elf_header.e_machine);
832 if (!slurp_rela_relocs (file, rel_offset, rel_size, &relas, &rel_size))
837 if (!slurp_rel_relocs (file, rel_offset, rel_size, &rels, &rel_size))
845 (_(" Offset Info Type Symbol's Value Symbol's Name Addend\n"));
848 (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
854 (_(" Offset Info Type Symbol's Value Symbol's Name Addend\n"));
857 (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
860 for (i = 0; i < rel_size; i++)
865 bfd_vma symtab_index;
870 offset = relas [i].r_offset;
871 info = relas [i].r_info;
875 offset = rels [i].r_offset;
876 info = rels [i].r_info;
881 type = ELF32_R_TYPE (info);
882 symtab_index = ELF32_R_SYM (info);
886 if (elf_header.e_machine == EM_SPARCV9)
887 type = ELF64_R_TYPE_ID (info);
889 type = ELF64_R_TYPE (info);
890 /* The #ifdef BFD64 below is to prevent a compile time warning.
891 We know that if we do not have a 64 bit data type that we
892 will never execute this code anyway. */
894 symtab_index = ELF64_R_SYM (info);
900 #ifdef _bfd_int64_low
901 printf ("%8.8lx %8.8lx ", _bfd_int64_low (offset), _bfd_int64_low (info));
903 printf ("%8.8lx %8.8lx ", offset, info);
908 #ifdef _bfd_int64_low
909 printf ("%8.8lx%8.8lx %8.8lx%8.8lx ",
910 _bfd_int64_high (offset),
911 _bfd_int64_low (offset),
912 _bfd_int64_high (info),
913 _bfd_int64_low (info));
915 printf ("%16.16lx %16.16lx ", offset, info);
919 switch (elf_header.e_machine)
927 rtype = elf_m32r_reloc_type (type);
932 rtype = elf_i386_reloc_type (type);
936 rtype = elf_m68k_reloc_type (type);
940 rtype = elf_i960_reloc_type (type);
945 rtype = elf_avr_reloc_type (type);
952 rtype = elf_sparc_reloc_type (type);
957 rtype = v850_reloc_type (type);
962 rtype = elf_d10v_reloc_type (type);
967 rtype = elf_d30v_reloc_type (type);
971 rtype = elf_sh_reloc_type (type);
975 case EM_CYGNUS_MN10300:
976 rtype = elf_mn10300_reloc_type (type);
980 case EM_CYGNUS_MN10200:
981 rtype = elf_mn10200_reloc_type (type);
986 rtype = elf_fr30_reloc_type (type);
990 rtype = elf_mcore_reloc_type (type);
994 rtype = elf_mmix_reloc_type (type);
999 rtype = elf_ppc_reloc_type (type);
1003 case EM_MIPS_RS3_LE:
1004 rtype = elf_mips_reloc_type (type);
1008 rtype = elf_alpha_reloc_type (type);
1012 rtype = elf_arm_reloc_type (type);
1016 rtype = elf_arc_reloc_type (type);
1020 rtype = elf_hppa_reloc_type (type);
1026 rtype = elf_h8_reloc_type (type);
1031 rtype = elf_pj_reloc_type (type);
1034 rtype = elf_ia64_reloc_type (type);
1038 rtype = elf_cris_reloc_type (type);
1042 rtype = elf_i860_reloc_type (type);
1046 rtype = elf_x86_64_reloc_type (type);
1051 rtype = elf_s390_reloc_type (type);
1055 rtype = elf_xstormy16_reloc_type (type);
1060 #ifdef _bfd_int64_low
1061 printf (_("unrecognised: %-7lx"), _bfd_int64_low (type));
1063 printf (_("unrecognised: %-7lx"), type);
1066 printf ("%-21.21s", rtype);
1070 if (symtab == NULL || symtab_index >= nsyms)
1071 printf (" bad symbol index: %08lx", (unsigned long) symtab_index);
1074 Elf_Internal_Sym * psym;
1076 psym = symtab + symtab_index;
1079 print_vma (psym->st_value, LONG_HEX);
1082 if (psym->st_name == 0)
1083 print_symbol (-25, SECTION_NAME (section_headers + psym->st_shndx));
1084 else if (strtab == NULL)
1085 printf (_("<string table index %3ld>"), psym->st_name);
1087 print_symbol (-25, strtab + psym->st_name);
1090 printf (" + %lx", (unsigned long) relas [i].r_addend);
1095 printf ("%*c", is_32bit_elf ? 34 : 26, ' ');
1096 print_vma (relas[i].r_addend, LONG_HEX);
1099 if (elf_header.e_machine == EM_SPARCV9
1100 && !strcmp (rtype, "R_SPARC_OLO10"))
1101 printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (info));
1115 get_mips_dynamic_type (type)
1120 case DT_MIPS_RLD_VERSION: return "MIPS_RLD_VERSION";
1121 case DT_MIPS_TIME_STAMP: return "MIPS_TIME_STAMP";
1122 case DT_MIPS_ICHECKSUM: return "MIPS_ICHECKSUM";
1123 case DT_MIPS_IVERSION: return "MIPS_IVERSION";
1124 case DT_MIPS_FLAGS: return "MIPS_FLAGS";
1125 case DT_MIPS_BASE_ADDRESS: return "MIPS_BASE_ADDRESS";
1126 case DT_MIPS_MSYM: return "MIPS_MSYM";
1127 case DT_MIPS_CONFLICT: return "MIPS_CONFLICT";
1128 case DT_MIPS_LIBLIST: return "MIPS_LIBLIST";
1129 case DT_MIPS_LOCAL_GOTNO: return "MIPS_LOCAL_GOTNO";
1130 case DT_MIPS_CONFLICTNO: return "MIPS_CONFLICTNO";
1131 case DT_MIPS_LIBLISTNO: return "MIPS_LIBLISTNO";
1132 case DT_MIPS_SYMTABNO: return "MIPS_SYMTABNO";
1133 case DT_MIPS_UNREFEXTNO: return "MIPS_UNREFEXTNO";
1134 case DT_MIPS_GOTSYM: return "MIPS_GOTSYM";
1135 case DT_MIPS_HIPAGENO: return "MIPS_HIPAGENO";
1136 case DT_MIPS_RLD_MAP: return "MIPS_RLD_MAP";
1137 case DT_MIPS_DELTA_CLASS: return "MIPS_DELTA_CLASS";
1138 case DT_MIPS_DELTA_CLASS_NO: return "MIPS_DELTA_CLASS_NO";
1139 case DT_MIPS_DELTA_INSTANCE: return "MIPS_DELTA_INSTANCE";
1140 case DT_MIPS_DELTA_INSTANCE_NO: return "MIPS_DELTA_INSTANCE_NO";
1141 case DT_MIPS_DELTA_RELOC: return "MIPS_DELTA_RELOC";
1142 case DT_MIPS_DELTA_RELOC_NO: return "MIPS_DELTA_RELOC_NO";
1143 case DT_MIPS_DELTA_SYM: return "MIPS_DELTA_SYM";
1144 case DT_MIPS_DELTA_SYM_NO: return "MIPS_DELTA_SYM_NO";
1145 case DT_MIPS_DELTA_CLASSSYM: return "MIPS_DELTA_CLASSSYM";
1146 case DT_MIPS_DELTA_CLASSSYM_NO: return "MIPS_DELTA_CLASSSYM_NO";
1147 case DT_MIPS_CXX_FLAGS: return "MIPS_CXX_FLAGS";
1148 case DT_MIPS_PIXIE_INIT: return "MIPS_PIXIE_INIT";
1149 case DT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB";
1150 case DT_MIPS_LOCALPAGE_GOTIDX: return "MIPS_LOCALPAGE_GOTIDX";
1151 case DT_MIPS_LOCAL_GOTIDX: return "MIPS_LOCAL_GOTIDX";
1152 case DT_MIPS_HIDDEN_GOTIDX: return "MIPS_HIDDEN_GOTIDX";
1153 case DT_MIPS_PROTECTED_GOTIDX: return "MIPS_PROTECTED_GOTIDX";
1154 case DT_MIPS_OPTIONS: return "MIPS_OPTIONS";
1155 case DT_MIPS_INTERFACE: return "MIPS_INTERFACE";
1156 case DT_MIPS_DYNSTR_ALIGN: return "MIPS_DYNSTR_ALIGN";
1157 case DT_MIPS_INTERFACE_SIZE: return "MIPS_INTERFACE_SIZE";
1158 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
1159 case DT_MIPS_PERF_SUFFIX: return "MIPS_PERF_SUFFIX";
1160 case DT_MIPS_COMPACT_SIZE: return "MIPS_COMPACT_SIZE";
1161 case DT_MIPS_GP_VALUE: return "MIPS_GP_VALUE";
1162 case DT_MIPS_AUX_DYNAMIC: return "MIPS_AUX_DYNAMIC";
1169 get_sparc64_dynamic_type (type)
1174 case DT_SPARC_REGISTER: return "SPARC_REGISTER";
1181 get_ppc64_dynamic_type (type)
1186 case DT_PPC64_GLINK: return "PPC64_GLINK";
1193 get_parisc_dynamic_type (type)
1198 case DT_HP_LOAD_MAP: return "HP_LOAD_MAP";
1199 case DT_HP_DLD_FLAGS: return "HP_DLD_FLAGS";
1200 case DT_HP_DLD_HOOK: return "HP_DLD_HOOK";
1201 case DT_HP_UX10_INIT: return "HP_UX10_INIT";
1202 case DT_HP_UX10_INITSZ: return "HP_UX10_INITSZ";
1203 case DT_HP_PREINIT: return "HP_PREINIT";
1204 case DT_HP_PREINITSZ: return "HP_PREINITSZ";
1205 case DT_HP_NEEDED: return "HP_NEEDED";
1206 case DT_HP_TIME_STAMP: return "HP_TIME_STAMP";
1207 case DT_HP_CHECKSUM: return "HP_CHECKSUM";
1208 case DT_HP_GST_SIZE: return "HP_GST_SIZE";
1209 case DT_HP_GST_VERSION: return "HP_GST_VERSION";
1210 case DT_HP_GST_HASHVAL: return "HP_GST_HASHVAL";
1217 get_dynamic_type (type)
1220 static char buff [32];
1224 case DT_NULL: return "NULL";
1225 case DT_NEEDED: return "NEEDED";
1226 case DT_PLTRELSZ: return "PLTRELSZ";
1227 case DT_PLTGOT: return "PLTGOT";
1228 case DT_HASH: return "HASH";
1229 case DT_STRTAB: return "STRTAB";
1230 case DT_SYMTAB: return "SYMTAB";
1231 case DT_RELA: return "RELA";
1232 case DT_RELASZ: return "RELASZ";
1233 case DT_RELAENT: return "RELAENT";
1234 case DT_STRSZ: return "STRSZ";
1235 case DT_SYMENT: return "SYMENT";
1236 case DT_INIT: return "INIT";
1237 case DT_FINI: return "FINI";
1238 case DT_SONAME: return "SONAME";
1239 case DT_RPATH: return "RPATH";
1240 case DT_SYMBOLIC: return "SYMBOLIC";
1241 case DT_REL: return "REL";
1242 case DT_RELSZ: return "RELSZ";
1243 case DT_RELENT: return "RELENT";
1244 case DT_PLTREL: return "PLTREL";
1245 case DT_DEBUG: return "DEBUG";
1246 case DT_TEXTREL: return "TEXTREL";
1247 case DT_JMPREL: return "JMPREL";
1248 case DT_BIND_NOW: return "BIND_NOW";
1249 case DT_INIT_ARRAY: return "INIT_ARRAY";
1250 case DT_FINI_ARRAY: return "FINI_ARRAY";
1251 case DT_INIT_ARRAYSZ: return "INIT_ARRAYSZ";
1252 case DT_FINI_ARRAYSZ: return "FINI_ARRAYSZ";
1253 case DT_RUNPATH: return "RUNPATH";
1254 case DT_FLAGS: return "FLAGS";
1256 case DT_PREINIT_ARRAY: return "PREINIT_ARRAY";
1257 case DT_PREINIT_ARRAYSZ: return "PREINIT_ARRAYSZ";
1259 case DT_CHECKSUM: return "CHECKSUM";
1260 case DT_PLTPADSZ: return "PLTPADSZ";
1261 case DT_MOVEENT: return "MOVEENT";
1262 case DT_MOVESZ: return "MOVESZ";
1263 case DT_FEATURE: return "FEATURE";
1264 case DT_POSFLAG_1: return "POSFLAG_1";
1265 case DT_SYMINSZ: return "SYMINSZ";
1266 case DT_SYMINENT: return "SYMINENT"; /* aka VALRNGHI */
1268 case DT_ADDRRNGLO: return "ADDRRNGLO";
1269 case DT_CONFIG: return "CONFIG";
1270 case DT_DEPAUDIT: return "DEPAUDIT";
1271 case DT_AUDIT: return "AUDIT";
1272 case DT_PLTPAD: return "PLTPAD";
1273 case DT_MOVETAB: return "MOVETAB";
1274 case DT_SYMINFO: return "SYMINFO"; /* aka ADDRRNGHI */
1276 case DT_VERSYM: return "VERSYM";
1278 case DT_RELACOUNT: return "RELACOUNT";
1279 case DT_RELCOUNT: return "RELCOUNT";
1280 case DT_FLAGS_1: return "FLAGS_1";
1281 case DT_VERDEF: return "VERDEF";
1282 case DT_VERDEFNUM: return "VERDEFNUM";
1283 case DT_VERNEED: return "VERNEED";
1284 case DT_VERNEEDNUM: return "VERNEEDNUM";
1286 case DT_AUXILIARY: return "AUXILIARY";
1287 case DT_USED: return "USED";
1288 case DT_FILTER: return "FILTER";
1291 if ((type >= DT_LOPROC) && (type <= DT_HIPROC))
1293 const char * result;
1295 switch (elf_header.e_machine)
1298 case EM_MIPS_RS3_LE:
1299 result = get_mips_dynamic_type (type);
1302 result = get_sparc64_dynamic_type (type);
1305 result = get_ppc64_dynamic_type (type);
1315 sprintf (buff, _("Processor Specific: %lx"), type);
1317 else if ((type >= DT_LOOS) && (type <= DT_HIOS))
1319 const char * result;
1321 switch (elf_header.e_machine)
1324 result = get_parisc_dynamic_type (type);
1334 sprintf (buff, _("Operating System specific: %lx"), type);
1337 sprintf (buff, _("<unknown>: %lx"), type);
1344 get_file_type (e_type)
1347 static char buff [32];
1351 case ET_NONE: return _("NONE (None)");
1352 case ET_REL: return _("REL (Relocatable file)");
1353 case ET_EXEC: return _("EXEC (Executable file)");
1354 case ET_DYN: return _("DYN (Shared object file)");
1355 case ET_CORE: return _("CORE (Core file)");
1358 if ((e_type >= ET_LOPROC) && (e_type <= ET_HIPROC))
1359 sprintf (buff, _("Processor Specific: (%x)"), e_type);
1360 else if ((e_type >= ET_LOOS) && (e_type <= ET_HIOS))
1361 sprintf (buff, _("OS Specific: (%x)"), e_type);
1363 sprintf (buff, _("<unknown>: %x"), e_type);
1369 get_machine_name (e_machine)
1372 static char buff [64]; /* XXX */
1376 case EM_NONE: return _("None");
1377 case EM_M32: return "WE32100";
1378 case EM_SPARC: return "Sparc";
1379 case EM_386: return "Intel 80386";
1380 case EM_68K: return "MC68000";
1381 case EM_88K: return "MC88000";
1382 case EM_486: return "Intel 80486";
1383 case EM_860: return "Intel 80860";
1384 case EM_MIPS: return "MIPS R3000";
1385 case EM_S370: return "IBM System/370";
1386 case EM_MIPS_RS3_LE: return "MIPS R4000 big-endian";
1387 case EM_OLD_SPARCV9: return "Sparc v9 (old)";
1388 case EM_PARISC: return "HPPA";
1389 case EM_PPC_OLD: return "Power PC (old)";
1390 case EM_SPARC32PLUS: return "Sparc v8+" ;
1391 case EM_960: return "Intel 90860";
1392 case EM_PPC: return "PowerPC";
1393 case EM_V800: return "NEC V800";
1394 case EM_FR20: return "Fujitsu FR20";
1395 case EM_RH32: return "TRW RH32";
1396 case EM_MCORE: return "MCORE";
1397 case EM_ARM: return "ARM";
1398 case EM_OLD_ALPHA: return "Digital Alpha (old)";
1399 case EM_SH: return "Hitachi SH";
1400 case EM_SPARCV9: return "Sparc v9";
1401 case EM_TRICORE: return "Siemens Tricore";
1402 case EM_ARC: return "ARC";
1403 case EM_H8_300: return "Hitachi H8/300";
1404 case EM_H8_300H: return "Hitachi H8/300H";
1405 case EM_H8S: return "Hitachi H8S";
1406 case EM_H8_500: return "Hitachi H8/500";
1407 case EM_IA_64: return "Intel IA-64";
1408 case EM_MIPS_X: return "Stanford MIPS-X";
1409 case EM_COLDFIRE: return "Motorola Coldfire";
1410 case EM_68HC12: return "Motorola M68HC12";
1411 case EM_ALPHA: return "Alpha";
1412 case EM_CYGNUS_D10V:
1413 case EM_D10V: return "d10v";
1414 case EM_CYGNUS_D30V:
1415 case EM_D30V: return "d30v";
1416 case EM_CYGNUS_M32R:
1417 case EM_M32R: return "Mitsubishi M32r";
1418 case EM_CYGNUS_V850:
1419 case EM_V850: return "NEC v850";
1420 case EM_CYGNUS_MN10300:
1421 case EM_MN10300: return "mn10300";
1422 case EM_CYGNUS_MN10200:
1423 case EM_MN10200: return "mn10200";
1424 case EM_CYGNUS_FR30:
1425 case EM_FR30: return "Fujitsu FR30";
1427 case EM_PJ: return "picoJava";
1428 case EM_MMA: return "Fujitsu Multimedia Accelerator";
1429 case EM_PCP: return "Siemens PCP";
1430 case EM_NCPU: return "Sony nCPU embedded RISC processor";
1431 case EM_NDR1: return "Denso NDR1 microprocesspr";
1432 case EM_STARCORE: return "Motorola Star*Core processor";
1433 case EM_ME16: return "Toyota ME16 processor";
1434 case EM_ST100: return "STMicroelectronics ST100 processor";
1435 case EM_TINYJ: return "Advanced Logic Corp. TinyJ embedded processor";
1436 case EM_FX66: return "Siemens FX66 microcontroller";
1437 case EM_ST9PLUS: return "STMicroelectronics ST9+ 8/16 bit microcontroller";
1438 case EM_ST7: return "STMicroelectronics ST7 8-bit microcontroller";
1439 case EM_68HC16: return "Motorola MC68HC16 Microcontroller";
1440 case EM_68HC11: return "Motorola MC68HC11 Microcontroller";
1441 case EM_68HC08: return "Motorola MC68HC08 Microcontroller";
1442 case EM_68HC05: return "Motorola MC68HC05 Microcontroller";
1443 case EM_SVX: return "Silicon Graphics SVx";
1444 case EM_ST19: return "STMicroelectronics ST19 8-bit microcontroller";
1445 case EM_VAX: return "Digital VAX";
1447 case EM_AVR: return "Atmel AVR 8-bit microcontroller";
1448 case EM_CRIS: return "Axis Communications 32-bit embedded processor";
1449 case EM_JAVELIN: return "Infineon Technologies 32-bit embedded cpu";
1450 case EM_FIREPATH: return "Element 14 64-bit DSP processor";
1451 case EM_ZSP: return "LSI Logic's 16-bit DSP processor";
1452 case EM_MMIX: return "Donald Knuth's educational 64-bit processor";
1453 case EM_HUANY: return "Harvard Universitys's machine-independent object format";
1454 case EM_PRISM: return "SiTera Prism";
1455 case EM_X86_64: return "Advanced Micro Devices X86-64";
1457 case EM_S390: return "IBM S/390";
1458 case EM_XSTORMY16: return "Sanyo Xstormy16 CPU core";
1460 sprintf (buff, _("<unknown>: %x"), e_machine);
1466 decode_ARM_machine_flags (e_flags, buf)
1473 eabi = EF_ARM_EABI_VERSION (e_flags);
1474 e_flags &= ~ EF_ARM_EABIMASK;
1476 /* Handle "generic" ARM flags. */
1477 if (e_flags & EF_ARM_RELEXEC)
1479 strcat (buf, ", relocatable executable");
1480 e_flags &= ~ EF_ARM_RELEXEC;
1483 if (e_flags & EF_ARM_HASENTRY)
1485 strcat (buf, ", has entry point");
1486 e_flags &= ~ EF_ARM_HASENTRY;
1489 /* Now handle EABI specific flags. */
1493 strcat (buf, ", <unrecognised EABI>");
1498 case EF_ARM_EABI_VER1:
1499 strcat (buf, ", Version1 EABI");
1504 /* Process flags one bit at a time. */
1505 flag = e_flags & - e_flags;
1510 case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK. */
1511 strcat (buf, ", sorted symbol tables");
1521 case EF_ARM_EABI_VER2:
1522 strcat (buf, ", Version2 EABI");
1527 /* Process flags one bit at a time. */
1528 flag = e_flags & - e_flags;
1533 case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK. */
1534 strcat (buf, ", sorted symbol tables");
1537 case EF_ARM_DYNSYMSUSESEGIDX:
1538 strcat (buf, ", dynamic symbols use segment index");
1541 case EF_ARM_MAPSYMSFIRST:
1542 strcat (buf, ", mapping symbols precede others");
1552 case EF_ARM_EABI_UNKNOWN:
1553 strcat (buf, ", GNU EABI");
1558 /* Process flags one bit at a time. */
1559 flag = e_flags & - e_flags;
1564 case EF_ARM_INTERWORK:
1565 strcat (buf, ", interworking enabled");
1568 case EF_ARM_APCS_26:
1569 strcat (buf, ", uses APCS/26");
1572 case EF_ARM_APCS_FLOAT:
1573 strcat (buf, ", uses APCS/float");
1577 strcat (buf, ", position independent");
1581 strcat (buf, ", 8 bit structure alignment");
1584 case EF_ARM_NEW_ABI:
1585 strcat (buf, ", uses new ABI");
1588 case EF_ARM_OLD_ABI:
1589 strcat (buf, ", uses old ABI");
1592 case EF_ARM_SOFT_FLOAT:
1593 strcat (buf, ", software FP");
1604 strcat (buf,", <unknown>");
1608 get_machine_flags (e_flags, e_machine)
1612 static char buf [1024];
1624 decode_ARM_machine_flags (e_flags, buf);
1628 if (e_flags & EF_CPU32)
1629 strcat (buf, ", cpu32");
1633 if (e_flags & EF_PPC_EMB)
1634 strcat (buf, ", emb");
1636 if (e_flags & EF_PPC_RELOCATABLE)
1637 strcat (buf, ", relocatable");
1639 if (e_flags & EF_PPC_RELOCATABLE_LIB)
1640 strcat (buf, ", relocatable-lib");
1644 case EM_CYGNUS_V850:
1645 switch (e_flags & EF_V850_ARCH)
1648 strcat (buf, ", v850e");
1651 strcat (buf, ", v850ea");
1654 strcat (buf, ", v850");
1657 strcat (buf, ", unknown v850 architecture variant");
1663 case EM_CYGNUS_M32R:
1664 if ((e_flags & EF_M32R_ARCH) == E_M32R_ARCH)
1665 strcat (buf, ", m32r");
1670 case EM_MIPS_RS3_LE:
1671 if (e_flags & EF_MIPS_NOREORDER)
1672 strcat (buf, ", noreorder");
1674 if (e_flags & EF_MIPS_PIC)
1675 strcat (buf, ", pic");
1677 if (e_flags & EF_MIPS_CPIC)
1678 strcat (buf, ", cpic");
1680 if (e_flags & EF_MIPS_UCODE)
1681 strcat (buf, ", ugen_reserved");
1683 if (e_flags & EF_MIPS_ABI2)
1684 strcat (buf, ", abi2");
1686 if (e_flags & EF_MIPS_OPTIONS_FIRST)
1687 strcat (buf, ", odk first");
1689 if (e_flags & EF_MIPS_32BITMODE)
1690 strcat (buf, ", 32bitmode");
1692 switch ((e_flags & EF_MIPS_MACH))
1694 case E_MIPS_MACH_3900: strcat (buf, ", 3900"); break;
1695 case E_MIPS_MACH_4010: strcat (buf, ", 4010"); break;
1696 case E_MIPS_MACH_4100: strcat (buf, ", 4100"); break;
1697 case E_MIPS_MACH_4650: strcat (buf, ", 4650"); break;
1698 case E_MIPS_MACH_4111: strcat (buf, ", 4111"); break;
1699 case E_MIPS_MACH_SB1: strcat (buf, ", sb1"); break;
1701 /* We simply ignore the field in this case to avoid confusion:
1702 MIPS ELF does not specify EF_MIPS_MACH, it is a GNU
1705 default: strcat (buf, ", unknown CPU"); break;
1708 switch ((e_flags & EF_MIPS_ABI))
1710 case E_MIPS_ABI_O32: strcat (buf, ", o32"); break;
1711 case E_MIPS_ABI_O64: strcat (buf, ", o64"); break;
1712 case E_MIPS_ABI_EABI32: strcat (buf, ", eabi32"); break;
1713 case E_MIPS_ABI_EABI64: strcat (buf, ", eabi64"); break;
1715 /* We simply ignore the field in this case to avoid confusion:
1716 MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension.
1717 This means it is likely to be an o32 file, but not for
1720 default: strcat (buf, ", unknown ABI"); break;
1723 if (e_flags & EF_MIPS_ARCH_ASE_MDMX)
1724 strcat (buf, ", mdmx");
1726 if (e_flags & EF_MIPS_ARCH_ASE_M16)
1727 strcat (buf, ", mips16");
1729 switch ((e_flags & EF_MIPS_ARCH))
1731 case E_MIPS_ARCH_1: strcat (buf, ", mips1"); break;
1732 case E_MIPS_ARCH_2: strcat (buf, ", mips2"); break;
1733 case E_MIPS_ARCH_3: strcat (buf, ", mips3"); break;
1734 case E_MIPS_ARCH_4: strcat (buf, ", mips4"); break;
1735 case E_MIPS_ARCH_5: strcat (buf, ", mips5"); break;
1736 case E_MIPS_ARCH_32: strcat (buf, ", mips32"); break;
1737 case E_MIPS_ARCH_64: strcat (buf, ", mips64"); break;
1738 default: strcat (buf, ", unknown ISA"); break;
1744 if (e_flags & EF_SPARC_32PLUS)
1745 strcat (buf, ", v8+");
1747 if (e_flags & EF_SPARC_SUN_US1)
1748 strcat (buf, ", ultrasparcI");
1750 if (e_flags & EF_SPARC_SUN_US3)
1751 strcat (buf, ", ultrasparcIII");
1753 if (e_flags & EF_SPARC_HAL_R1)
1754 strcat (buf, ", halr1");
1756 if (e_flags & EF_SPARC_LEDATA)
1757 strcat (buf, ", ledata");
1759 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_TSO)
1760 strcat (buf, ", tso");
1762 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_PSO)
1763 strcat (buf, ", pso");
1765 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_RMO)
1766 strcat (buf, ", rmo");
1770 switch (e_flags & EF_PARISC_ARCH)
1772 case EFA_PARISC_1_0:
1773 strcpy (buf, ", PA-RISC 1.0");
1775 case EFA_PARISC_1_1:
1776 strcpy (buf, ", PA-RISC 1.1");
1778 case EFA_PARISC_2_0:
1779 strcpy (buf, ", PA-RISC 2.0");
1784 if (e_flags & EF_PARISC_TRAPNIL)
1785 strcat (buf, ", trapnil");
1786 if (e_flags & EF_PARISC_EXT)
1787 strcat (buf, ", ext");
1788 if (e_flags & EF_PARISC_LSB)
1789 strcat (buf, ", lsb");
1790 if (e_flags & EF_PARISC_WIDE)
1791 strcat (buf, ", wide");
1792 if (e_flags & EF_PARISC_NO_KABP)
1793 strcat (buf, ", no kabp");
1794 if (e_flags & EF_PARISC_LAZYSWAP)
1795 strcat (buf, ", lazyswap");
1800 if ((e_flags & EF_PICOJAVA_NEWCALLS) == EF_PICOJAVA_NEWCALLS)
1801 strcat (buf, ", new calling convention");
1803 if ((e_flags & EF_PICOJAVA_GNUCALLS) == EF_PICOJAVA_GNUCALLS)
1804 strcat (buf, ", gnu calling convention");
1808 if ((e_flags & EF_IA_64_ABI64))
1809 strcat (buf, ", 64-bit");
1811 strcat (buf, ", 32-bit");
1812 if ((e_flags & EF_IA_64_REDUCEDFP))
1813 strcat (buf, ", reduced fp model");
1814 if ((e_flags & EF_IA_64_NOFUNCDESC_CONS_GP))
1815 strcat (buf, ", no function descriptors, constant gp");
1816 else if ((e_flags & EF_IA_64_CONS_GP))
1817 strcat (buf, ", constant gp");
1818 if ((e_flags & EF_IA_64_ABSOLUTE))
1819 strcat (buf, ", absolute");
1828 get_mips_segment_type (type)
1833 case PT_MIPS_REGINFO:
1835 case PT_MIPS_RTPROC:
1837 case PT_MIPS_OPTIONS:
1847 get_parisc_segment_type (type)
1852 case PT_HP_TLS: return "HP_TLS";
1853 case PT_HP_CORE_NONE: return "HP_CORE_NONE";
1854 case PT_HP_CORE_VERSION: return "HP_CORE_VERSION";
1855 case PT_HP_CORE_KERNEL: return "HP_CORE_KERNEL";
1856 case PT_HP_CORE_COMM: return "HP_CORE_COMM";
1857 case PT_HP_CORE_PROC: return "HP_CORE_PROC";
1858 case PT_HP_CORE_LOADABLE: return "HP_CORE_LOADABLE";
1859 case PT_HP_CORE_STACK: return "HP_CORE_STACK";
1860 case PT_HP_CORE_SHM: return "HP_CORE_SHM";
1861 case PT_HP_CORE_MMF: return "HP_CORE_MMF";
1862 case PT_HP_PARALLEL: return "HP_PARALLEL";
1863 case PT_HP_FASTBIND: return "HP_FASTBIND";
1864 case PT_PARISC_ARCHEXT: return "PARISC_ARCHEXT";
1865 case PT_PARISC_UNWIND: return "PARISC_UNWIND";
1874 get_ia64_segment_type (type)
1879 case PT_IA_64_ARCHEXT: return "IA_64_ARCHEXT";
1880 case PT_IA_64_UNWIND: return "IA_64_UNWIND";
1881 case PT_HP_TLS: return "HP_TLS";
1882 case PT_IA_64_HP_OPT_ANOT: return "HP_OPT_ANNOT";
1883 case PT_IA_64_HP_HSL_ANOT: return "HP_HSL_ANNOT";
1884 case PT_IA_64_HP_STACK: return "HP_STACK";
1893 get_segment_type (p_type)
1894 unsigned long p_type;
1896 static char buff [32];
1900 case PT_NULL: return "NULL";
1901 case PT_LOAD: return "LOAD";
1902 case PT_DYNAMIC: return "DYNAMIC";
1903 case PT_INTERP: return "INTERP";
1904 case PT_NOTE: return "NOTE";
1905 case PT_SHLIB: return "SHLIB";
1906 case PT_PHDR: return "PHDR";
1908 case PT_GNU_EH_FRAME:
1909 return "GNU_EH_FRAME";
1912 if ((p_type >= PT_LOPROC) && (p_type <= PT_HIPROC))
1914 const char * result;
1916 switch (elf_header.e_machine)
1919 case EM_MIPS_RS3_LE:
1920 result = get_mips_segment_type (p_type);
1923 result = get_parisc_segment_type (p_type);
1926 result = get_ia64_segment_type (p_type);
1936 sprintf (buff, "LOPROC+%lx", p_type - PT_LOPROC);
1938 else if ((p_type >= PT_LOOS) && (p_type <= PT_HIOS))
1940 const char * result;
1942 switch (elf_header.e_machine)
1945 result = get_parisc_segment_type (p_type);
1948 result = get_ia64_segment_type (p_type);
1958 sprintf (buff, "LOOS+%lx", p_type - PT_LOOS);
1961 sprintf (buff, _("<unknown>: %lx"), p_type);
1968 get_mips_section_type_name (sh_type)
1969 unsigned int sh_type;
1973 case SHT_MIPS_LIBLIST: return "MIPS_LIBLIST";
1974 case SHT_MIPS_MSYM: return "MIPS_MSYM";
1975 case SHT_MIPS_CONFLICT: return "MIPS_CONFLICT";
1976 case SHT_MIPS_GPTAB: return "MIPS_GPTAB";
1977 case SHT_MIPS_UCODE: return "MIPS_UCODE";
1978 case SHT_MIPS_DEBUG: return "MIPS_DEBUG";
1979 case SHT_MIPS_REGINFO: return "MIPS_REGINFO";
1980 case SHT_MIPS_PACKAGE: return "MIPS_PACKAGE";
1981 case SHT_MIPS_PACKSYM: return "MIPS_PACKSYM";
1982 case SHT_MIPS_RELD: return "MIPS_RELD";
1983 case SHT_MIPS_IFACE: return "MIPS_IFACE";
1984 case SHT_MIPS_CONTENT: return "MIPS_CONTENT";
1985 case SHT_MIPS_OPTIONS: return "MIPS_OPTIONS";
1986 case SHT_MIPS_SHDR: return "MIPS_SHDR";
1987 case SHT_MIPS_FDESC: return "MIPS_FDESC";
1988 case SHT_MIPS_EXTSYM: return "MIPS_EXTSYM";
1989 case SHT_MIPS_DENSE: return "MIPS_DENSE";
1990 case SHT_MIPS_PDESC: return "MIPS_PDESC";
1991 case SHT_MIPS_LOCSYM: return "MIPS_LOCSYM";
1992 case SHT_MIPS_AUXSYM: return "MIPS_AUXSYM";
1993 case SHT_MIPS_OPTSYM: return "MIPS_OPTSYM";
1994 case SHT_MIPS_LOCSTR: return "MIPS_LOCSTR";
1995 case SHT_MIPS_LINE: return "MIPS_LINE";
1996 case SHT_MIPS_RFDESC: return "MIPS_RFDESC";
1997 case SHT_MIPS_DELTASYM: return "MIPS_DELTASYM";
1998 case SHT_MIPS_DELTAINST: return "MIPS_DELTAINST";
1999 case SHT_MIPS_DELTACLASS: return "MIPS_DELTACLASS";
2000 case SHT_MIPS_DWARF: return "MIPS_DWARF";
2001 case SHT_MIPS_DELTADECL: return "MIPS_DELTADECL";
2002 case SHT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB";
2003 case SHT_MIPS_EVENTS: return "MIPS_EVENTS";
2004 case SHT_MIPS_TRANSLATE: return "MIPS_TRANSLATE";
2005 case SHT_MIPS_PIXIE: return "MIPS_PIXIE";
2006 case SHT_MIPS_XLATE: return "MIPS_XLATE";
2007 case SHT_MIPS_XLATE_DEBUG: return "MIPS_XLATE_DEBUG";
2008 case SHT_MIPS_WHIRL: return "MIPS_WHIRL";
2009 case SHT_MIPS_EH_REGION: return "MIPS_EH_REGION";
2010 case SHT_MIPS_XLATE_OLD: return "MIPS_XLATE_OLD";
2011 case SHT_MIPS_PDR_EXCEPTION: return "MIPS_PDR_EXCEPTION";
2019 get_parisc_section_type_name (sh_type)
2020 unsigned int sh_type;
2024 case SHT_PARISC_EXT: return "PARISC_EXT";
2025 case SHT_PARISC_UNWIND: return "PARISC_UNWIND";
2026 case SHT_PARISC_DOC: return "PARISC_DOC";
2034 get_ia64_section_type_name (sh_type)
2035 unsigned int sh_type;
2039 case SHT_IA_64_EXT: return "IA_64_EXT";
2040 case SHT_IA_64_UNWIND: return "IA_64_UNWIND";
2048 get_section_type_name (sh_type)
2049 unsigned int sh_type;
2051 static char buff [32];
2055 case SHT_NULL: return "NULL";
2056 case SHT_PROGBITS: return "PROGBITS";
2057 case SHT_SYMTAB: return "SYMTAB";
2058 case SHT_STRTAB: return "STRTAB";
2059 case SHT_RELA: return "RELA";
2060 case SHT_HASH: return "HASH";
2061 case SHT_DYNAMIC: return "DYNAMIC";
2062 case SHT_NOTE: return "NOTE";
2063 case SHT_NOBITS: return "NOBITS";
2064 case SHT_REL: return "REL";
2065 case SHT_SHLIB: return "SHLIB";
2066 case SHT_DYNSYM: return "DYNSYM";
2067 case SHT_INIT_ARRAY: return "INIT_ARRAY";
2068 case SHT_FINI_ARRAY: return "FINI_ARRAY";
2069 case SHT_PREINIT_ARRAY: return "PREINIT_ARRAY";
2070 case SHT_GROUP: return "GROUP";
2071 case SHT_SYMTAB_SHNDX: return "SYMTAB SECTION INDICIES";
2072 case SHT_GNU_verdef: return "VERDEF";
2073 case SHT_GNU_verneed: return "VERNEED";
2074 case SHT_GNU_versym: return "VERSYM";
2075 case 0x6ffffff0: return "VERSYM";
2076 case 0x6ffffffc: return "VERDEF";
2077 case 0x7ffffffd: return "AUXILIARY";
2078 case 0x7fffffff: return "FILTER";
2081 if ((sh_type >= SHT_LOPROC) && (sh_type <= SHT_HIPROC))
2083 const char * result;
2085 switch (elf_header.e_machine)
2088 case EM_MIPS_RS3_LE:
2089 result = get_mips_section_type_name (sh_type);
2092 result = get_parisc_section_type_name (sh_type);
2095 result = get_ia64_section_type_name (sh_type);
2105 sprintf (buff, "LOPROC+%x", sh_type - SHT_LOPROC);
2107 else if ((sh_type >= SHT_LOOS) && (sh_type <= SHT_HIOS))
2108 sprintf (buff, "LOOS+%x", sh_type - SHT_LOOS);
2109 else if ((sh_type >= SHT_LOUSER) && (sh_type <= SHT_HIUSER))
2110 sprintf (buff, "LOUSER+%x", sh_type - SHT_LOUSER);
2112 sprintf (buff, _("<unknown>: %x"), sh_type);
2118 struct option options [] =
2120 {"all", no_argument, 0, 'a'},
2121 {"file-header", no_argument, 0, 'h'},
2122 {"program-headers", no_argument, 0, 'l'},
2123 {"headers", no_argument, 0, 'e'},
2124 {"histogram", no_argument, 0, 'I'},
2125 {"segments", no_argument, 0, 'l'},
2126 {"sections", no_argument, 0, 'S'},
2127 {"section-headers", no_argument, 0, 'S'},
2128 {"symbols", no_argument, 0, 's'},
2129 {"syms", no_argument, 0, 's'},
2130 {"relocs", no_argument, 0, 'r'},
2131 {"notes", no_argument, 0, 'n'},
2132 {"dynamic", no_argument, 0, 'd'},
2133 {"arch-specific", no_argument, 0, 'A'},
2134 {"version-info", no_argument, 0, 'V'},
2135 {"use-dynamic", no_argument, 0, 'D'},
2136 {"hex-dump", required_argument, 0, 'x'},
2137 {"debug-dump", optional_argument, 0, 'w'},
2138 {"unwind", no_argument, 0, 'u'},
2139 #ifdef SUPPORT_DISASSEMBLY
2140 {"instruction-dump", required_argument, 0, 'i'},
2143 {"version", no_argument, 0, 'v'},
2144 {"wide", no_argument, 0, 'W'},
2145 {"help", no_argument, 0, 'H'},
2146 {0, no_argument, 0, 0}
2152 fprintf (stdout, _("Usage: readelf {options} elf-file(s)\n"));
2153 fprintf (stdout, _(" Options are:\n"));
2154 fprintf (stdout, _(" -a or --all Equivalent to: -h -l -S -s -r -d -V -A -I\n"));
2155 fprintf (stdout, _(" -h or --file-header Display the ELF file header\n"));
2156 fprintf (stdout, _(" -l or --program-headers or --segments\n"));
2157 fprintf (stdout, _(" Display the program headers\n"));
2158 fprintf (stdout, _(" -S or --section-headers or --sections\n"));
2159 fprintf (stdout, _(" Display the sections' header\n"));
2160 fprintf (stdout, _(" -e or --headers Equivalent to: -h -l -S\n"));
2161 fprintf (stdout, _(" -s or --syms or --symbols Display the symbol table\n"));
2162 fprintf (stdout, _(" -n or --notes Display the core notes (if present)\n"));
2163 fprintf (stdout, _(" -r or --relocs Display the relocations (if present)\n"));
2164 fprintf (stdout, _(" -u or --unwind Display the unwind info (if present)\n"));
2165 fprintf (stdout, _(" -d or --dynamic Display the dynamic segment (if present)\n"));
2166 fprintf (stdout, _(" -V or --version-info Display the version sections (if present)\n"));
2167 fprintf (stdout, _(" -A or --arch-specific Display architecture specific information (if any).\n"));
2168 fprintf (stdout, _(" -D or --use-dynamic Use the dynamic section info when displaying symbols\n"));
2169 fprintf (stdout, _(" -x <number> or --hex-dump=<number>\n"));
2170 fprintf (stdout, _(" Dump the contents of section <number>\n"));
2171 fprintf (stdout, _(" -w[liaprmfs] or --debug-dump[=line,=info,=abbrev,=pubnames,=ranges,=macro,=frames,=str]\n"));
2172 fprintf (stdout, _(" Display the contents of DWARF2 debug sections\n"));
2173 #ifdef SUPPORT_DISASSEMBLY
2174 fprintf (stdout, _(" -i <number> or --instruction-dump=<number>\n"));
2175 fprintf (stdout, _(" Disassemble the contents of section <number>\n"));
2177 fprintf (stdout, _(" -I or --histogram Display histogram of bucket list lengths\n"));
2178 fprintf (stdout, _(" -v or --version Display the version number of readelf\n"));
2179 fprintf (stdout, _(" -W or --wide Don't split lines or truncate symbols to fit into 80 columns\n"));
2180 fprintf (stdout, _(" -H or --help Display this information\n"));
2181 fprintf (stdout, _("Report bugs to %s\n"), REPORT_BUGS_TO);
2187 request_dump (section, type)
2188 unsigned int section;
2191 if (section >= num_dump_sects)
2193 char * new_dump_sects;
2195 new_dump_sects = (char *) calloc (section + 1, 1);
2197 if (new_dump_sects == NULL)
2198 error (_("Out of memory allocating dump request table."));
2201 /* Copy current flag settings. */
2202 memcpy (new_dump_sects, dump_sects, num_dump_sects);
2206 dump_sects = new_dump_sects;
2207 num_dump_sects = section + 1;
2212 dump_sects [section] |= type;
2218 parse_args (argc, argv)
2227 while ((c = getopt_long
2228 (argc, argv, "ersuahnldSDAIw::x:i:vVW", options, NULL)) != EOF)
2264 do_using_dynamic ++;
2295 section = strtoul (optarg, & cp, 0);
2296 if (! * cp && section >= 0)
2298 request_dump (section, HEX_DUMP);
2308 unsigned int index = 0;
2312 while (optarg[index])
2313 switch (optarg[index++])
2322 do_debug_abbrevs = 1;
2332 do_debug_pubnames = 1;
2337 do_debug_aranges = 1;
2341 do_debug_frames_interp = 1;
2343 do_debug_frames = 1;
2348 do_debug_macinfo = 1;
2357 warn (_("Unrecognised debug option '%s'\n"), optarg);
2362 #ifdef SUPPORT_DISASSEMBLY
2365 section = strtoul (optarg, & cp, 0);
2366 if (! * cp && section >= 0)
2368 request_dump (section, DISASS_DUMP);
2374 print_version (program_name);
2384 /* xgettext:c-format */
2385 error (_("Invalid option '-%c'\n"), c);
2392 if (!do_dynamic && !do_syms && !do_reloc && !do_unwind && !do_sections
2393 && !do_segments && !do_header && !do_dump && !do_version
2394 && !do_histogram && !do_debugging && !do_arch && !do_notes)
2398 warn (_("Nothing to do.\n"));
2404 get_elf_class (elf_class)
2405 unsigned int elf_class;
2407 static char buff [32];
2411 case ELFCLASSNONE: return _("none");
2412 case ELFCLASS32: return "ELF32";
2413 case ELFCLASS64: return "ELF64";
2415 sprintf (buff, _("<unknown: %x>"), elf_class);
2421 get_data_encoding (encoding)
2422 unsigned int encoding;
2424 static char buff [32];
2428 case ELFDATANONE: return _("none");
2429 case ELFDATA2LSB: return _("2's complement, little endian");
2430 case ELFDATA2MSB: return _("2's complement, big endian");
2432 sprintf (buff, _("<unknown: %x>"), encoding);
2438 get_osabi_name (osabi)
2441 static char buff [32];
2445 case ELFOSABI_NONE: return "UNIX - System V";
2446 case ELFOSABI_HPUX: return "UNIX - HP-UX";
2447 case ELFOSABI_NETBSD: return "UNIX - NetBSD";
2448 case ELFOSABI_LINUX: return "UNIX - Linux";
2449 case ELFOSABI_HURD: return "GNU/Hurd";
2450 case ELFOSABI_SOLARIS: return "UNIX - Solaris";
2451 case ELFOSABI_AIX: return "UNIX - AIX";
2452 case ELFOSABI_IRIX: return "UNIX - IRIX";
2453 case ELFOSABI_FREEBSD: return "UNIX - FreeBSD";
2454 case ELFOSABI_TRU64: return "UNIX - TRU64";
2455 case ELFOSABI_MODESTO: return "Novell - Modesto";
2456 case ELFOSABI_OPENBSD: return "UNIX - OpenBSD";
2457 case ELFOSABI_STANDALONE: return _("Standalone App");
2458 case ELFOSABI_ARM: return "ARM";
2460 sprintf (buff, _("<unknown: %x>"), osabi);
2465 /* Decode the data held in 'elf_header'. */
2467 process_file_header ()
2469 if ( elf_header.e_ident [EI_MAG0] != ELFMAG0
2470 || elf_header.e_ident [EI_MAG1] != ELFMAG1
2471 || elf_header.e_ident [EI_MAG2] != ELFMAG2
2472 || elf_header.e_ident [EI_MAG3] != ELFMAG3)
2475 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
2483 printf (_("ELF Header:\n"));
2484 printf (_(" Magic: "));
2485 for (i = 0; i < EI_NIDENT; i ++)
2486 printf ("%2.2x ", elf_header.e_ident [i]);
2488 printf (_(" Class: %s\n"),
2489 get_elf_class (elf_header.e_ident [EI_CLASS]));
2490 printf (_(" Data: %s\n"),
2491 get_data_encoding (elf_header.e_ident [EI_DATA]));
2492 printf (_(" Version: %d %s\n"),
2493 elf_header.e_ident [EI_VERSION],
2494 (elf_header.e_ident [EI_VERSION] == EV_CURRENT
2496 : (elf_header.e_ident [EI_VERSION] != EV_NONE
2499 printf (_(" OS/ABI: %s\n"),
2500 get_osabi_name (elf_header.e_ident [EI_OSABI]));
2501 printf (_(" ABI Version: %d\n"),
2502 elf_header.e_ident [EI_ABIVERSION]);
2503 printf (_(" Type: %s\n"),
2504 get_file_type (elf_header.e_type));
2505 printf (_(" Machine: %s\n"),
2506 get_machine_name (elf_header.e_machine));
2507 printf (_(" Version: 0x%lx\n"),
2508 (unsigned long) elf_header.e_version);
2510 printf (_(" Entry point address: "));
2511 print_vma ((bfd_vma) elf_header.e_entry, PREFIX_HEX);
2512 printf (_("\n Start of program headers: "));
2513 print_vma ((bfd_vma) elf_header.e_phoff, DEC);
2514 printf (_(" (bytes into file)\n Start of section headers: "));
2515 print_vma ((bfd_vma) elf_header.e_shoff, DEC);
2516 printf (_(" (bytes into file)\n"));
2518 printf (_(" Flags: 0x%lx%s\n"),
2519 (unsigned long) elf_header.e_flags,
2520 get_machine_flags (elf_header.e_flags, elf_header.e_machine));
2521 printf (_(" Size of this header: %ld (bytes)\n"),
2522 (long) elf_header.e_ehsize);
2523 printf (_(" Size of program headers: %ld (bytes)\n"),
2524 (long) elf_header.e_phentsize);
2525 printf (_(" Number of program headers: %ld\n"),
2526 (long) elf_header.e_phnum);
2527 printf (_(" Size of section headers: %ld (bytes)\n"),
2528 (long) elf_header.e_shentsize);
2529 printf (_(" Number of section headers: %ld"),
2530 (long) elf_header.e_shnum);
2531 if (section_headers != NULL && elf_header.e_shnum == 0)
2532 printf (" (%ld)", (long) section_headers[0].sh_size);
2533 putc ('\n', stdout);
2534 printf (_(" Section header string table index: %ld"),
2535 (long) elf_header.e_shstrndx);
2536 if (section_headers != NULL && elf_header.e_shstrndx == SHN_XINDEX)
2537 printf (" (%ld)", (long) section_headers[0].sh_link);
2538 putc ('\n', stdout);
2541 if (section_headers != NULL)
2543 if (elf_header.e_shnum == 0)
2544 elf_header.e_shnum = section_headers[0].sh_size;
2545 if (elf_header.e_shstrndx == SHN_XINDEX)
2546 elf_header.e_shstrndx = section_headers[0].sh_link;
2547 free (section_headers);
2548 section_headers = NULL;
2556 get_32bit_program_headers (file, program_headers)
2558 Elf_Internal_Phdr * program_headers;
2560 Elf32_External_Phdr * phdrs;
2561 Elf32_External_Phdr * external;
2562 Elf32_Internal_Phdr * internal;
2565 phdrs = ((Elf32_External_Phdr *)
2566 get_data (NULL, file, elf_header.e_phoff,
2567 elf_header.e_phentsize * elf_header.e_phnum,
2568 _("program headers")));
2572 for (i = 0, internal = program_headers, external = phdrs;
2573 i < elf_header.e_phnum;
2574 i ++, internal ++, external ++)
2576 internal->p_type = BYTE_GET (external->p_type);
2577 internal->p_offset = BYTE_GET (external->p_offset);
2578 internal->p_vaddr = BYTE_GET (external->p_vaddr);
2579 internal->p_paddr = BYTE_GET (external->p_paddr);
2580 internal->p_filesz = BYTE_GET (external->p_filesz);
2581 internal->p_memsz = BYTE_GET (external->p_memsz);
2582 internal->p_flags = BYTE_GET (external->p_flags);
2583 internal->p_align = BYTE_GET (external->p_align);
2592 get_64bit_program_headers (file, program_headers)
2594 Elf_Internal_Phdr * program_headers;
2596 Elf64_External_Phdr * phdrs;
2597 Elf64_External_Phdr * external;
2598 Elf64_Internal_Phdr * internal;
2601 phdrs = ((Elf64_External_Phdr *)
2602 get_data (NULL, file, elf_header.e_phoff,
2603 elf_header.e_phentsize * elf_header.e_phnum,
2604 _("program headers")));
2608 for (i = 0, internal = program_headers, external = phdrs;
2609 i < elf_header.e_phnum;
2610 i ++, internal ++, external ++)
2612 internal->p_type = BYTE_GET (external->p_type);
2613 internal->p_flags = BYTE_GET (external->p_flags);
2614 internal->p_offset = BYTE_GET8 (external->p_offset);
2615 internal->p_vaddr = BYTE_GET8 (external->p_vaddr);
2616 internal->p_paddr = BYTE_GET8 (external->p_paddr);
2617 internal->p_filesz = BYTE_GET8 (external->p_filesz);
2618 internal->p_memsz = BYTE_GET8 (external->p_memsz);
2619 internal->p_align = BYTE_GET8 (external->p_align);
2628 process_program_headers (file)
2631 Elf_Internal_Phdr * program_headers;
2632 Elf_Internal_Phdr * segment;
2635 if (elf_header.e_phnum == 0)
2638 printf (_("\nThere are no program headers in this file.\n"));
2642 if (do_segments && !do_header)
2644 printf (_("\nElf file type is %s\n"), get_file_type (elf_header.e_type));
2645 printf (_("Entry point "));
2646 print_vma ((bfd_vma) elf_header.e_entry, PREFIX_HEX);
2647 printf (_("\nThere are %d program headers, starting at offset "),
2648 elf_header.e_phnum);
2649 print_vma ((bfd_vma) elf_header.e_phoff, DEC);
2653 program_headers = (Elf_Internal_Phdr *) malloc
2654 (elf_header.e_phnum * sizeof (Elf_Internal_Phdr));
2656 if (program_headers == NULL)
2658 error (_("Out of memory\n"));
2663 i = get_32bit_program_headers (file, program_headers);
2665 i = get_64bit_program_headers (file, program_headers);
2669 free (program_headers);
2676 (_("\nProgram Header%s:\n"), elf_header.e_phnum > 1 ? "s" : "");
2680 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
2683 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
2687 (_(" Type Offset VirtAddr PhysAddr\n"));
2689 (_(" FileSiz MemSiz Flags Align\n"));
2697 for (i = 0, segment = program_headers;
2698 i < elf_header.e_phnum;
2703 printf (" %-14.14s ", get_segment_type (segment->p_type));
2707 printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
2708 printf ("0x%8.8lx ", (unsigned long) segment->p_vaddr);
2709 printf ("0x%8.8lx ", (unsigned long) segment->p_paddr);
2710 printf ("0x%5.5lx ", (unsigned long) segment->p_filesz);
2711 printf ("0x%5.5lx ", (unsigned long) segment->p_memsz);
2713 (segment->p_flags & PF_R ? 'R' : ' '),
2714 (segment->p_flags & PF_W ? 'W' : ' '),
2715 (segment->p_flags & PF_X ? 'E' : ' '));
2716 printf ("%#lx", (unsigned long) segment->p_align);
2720 if ((unsigned long) segment->p_offset == segment->p_offset)
2721 printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
2724 print_vma (segment->p_offset, FULL_HEX);
2728 print_vma (segment->p_vaddr, FULL_HEX);
2730 print_vma (segment->p_paddr, FULL_HEX);
2733 if ((unsigned long) segment->p_filesz == segment->p_filesz)
2734 printf ("0x%6.6lx ", (unsigned long) segment->p_filesz);
2737 print_vma (segment->p_filesz, FULL_HEX);
2741 if ((unsigned long) segment->p_memsz == segment->p_memsz)
2742 printf ("0x%6.6lx", (unsigned long) segment->p_memsz);
2745 print_vma (segment->p_offset, FULL_HEX);
2749 (segment->p_flags & PF_R ? 'R' : ' '),
2750 (segment->p_flags & PF_W ? 'W' : ' '),
2751 (segment->p_flags & PF_X ? 'E' : ' '));
2753 if ((unsigned long) segment->p_align == segment->p_align)
2754 printf ("%#lx", (unsigned long) segment->p_align);
2757 print_vma (segment->p_align, PREFIX_HEX);
2762 print_vma (segment->p_offset, FULL_HEX);
2764 print_vma (segment->p_vaddr, FULL_HEX);
2766 print_vma (segment->p_paddr, FULL_HEX);
2768 print_vma (segment->p_filesz, FULL_HEX);
2770 print_vma (segment->p_memsz, FULL_HEX);
2772 (segment->p_flags & PF_R ? 'R' : ' '),
2773 (segment->p_flags & PF_W ? 'W' : ' '),
2774 (segment->p_flags & PF_X ? 'E' : ' '));
2775 print_vma (segment->p_align, HEX);
2779 switch (segment->p_type)
2783 loadaddr = (segment->p_vaddr & 0xfffff000)
2784 - (segment->p_offset & 0xfffff000);
2789 error (_("more than one dynamic segment\n"));
2791 dynamic_addr = segment->p_offset;
2792 dynamic_size = segment->p_filesz;
2796 if (fseek (file, (long) segment->p_offset, SEEK_SET))
2797 error (_("Unable to find program interpreter name\n"));
2800 program_interpreter[0] = 0;
2801 fscanf (file, "%63s", program_interpreter);
2804 printf (_("\n [Requesting program interpreter: %s]"),
2805 program_interpreter);
2811 putc ('\n', stdout);
2820 if (do_segments && section_headers != NULL)
2822 printf (_("\n Section to Segment mapping:\n"));
2823 printf (_(" Segment Sections...\n"));
2825 assert (string_table != NULL);
2827 for (i = 0; i < elf_header.e_phnum; i++)
2830 Elf_Internal_Shdr * section;
2832 segment = program_headers + i;
2833 section = section_headers;
2835 printf (" %2.2d ", i);
2837 for (j = 1; j < elf_header.e_shnum; j++, section ++)
2839 if (section->sh_size > 0
2840 /* Compare allocated sections by VMA, unallocated
2841 sections by file offset. */
2842 && (section->sh_flags & SHF_ALLOC
2843 ? (section->sh_addr >= segment->p_vaddr
2844 && section->sh_addr + section->sh_size
2845 <= segment->p_vaddr + segment->p_memsz)
2846 : ((bfd_vma) section->sh_offset >= segment->p_offset
2847 && (section->sh_offset + section->sh_size
2848 <= segment->p_offset + segment->p_filesz))))
2849 printf ("%s ", SECTION_NAME (section));
2856 free (program_headers);
2863 get_32bit_section_headers (file, num)
2867 Elf32_External_Shdr * shdrs;
2868 Elf32_Internal_Shdr * internal;
2871 shdrs = ((Elf32_External_Shdr *)
2872 get_data (NULL, file, elf_header.e_shoff,
2873 elf_header.e_shentsize * num,
2874 _("section headers")));
2878 section_headers = ((Elf_Internal_Shdr *)
2879 malloc (num * sizeof (Elf_Internal_Shdr)));
2881 if (section_headers == NULL)
2883 error (_("Out of memory\n"));
2887 for (i = 0, internal = section_headers;
2891 internal->sh_name = BYTE_GET (shdrs[i].sh_name);
2892 internal->sh_type = BYTE_GET (shdrs[i].sh_type);
2893 internal->sh_flags = BYTE_GET (shdrs[i].sh_flags);
2894 internal->sh_addr = BYTE_GET (shdrs[i].sh_addr);
2895 internal->sh_offset = BYTE_GET (shdrs[i].sh_offset);
2896 internal->sh_size = BYTE_GET (shdrs[i].sh_size);
2897 internal->sh_link = BYTE_GET (shdrs[i].sh_link);
2898 internal->sh_info = BYTE_GET (shdrs[i].sh_info);
2899 internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
2900 internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize);
2909 get_64bit_section_headers (file, num)
2913 Elf64_External_Shdr * shdrs;
2914 Elf64_Internal_Shdr * internal;
2917 shdrs = ((Elf64_External_Shdr *)
2918 get_data (NULL, file, elf_header.e_shoff,
2919 elf_header.e_shentsize * num,
2920 _("section headers")));
2924 section_headers = ((Elf_Internal_Shdr *)
2925 malloc (num * sizeof (Elf_Internal_Shdr)));
2927 if (section_headers == NULL)
2929 error (_("Out of memory\n"));
2933 for (i = 0, internal = section_headers;
2937 internal->sh_name = BYTE_GET (shdrs[i].sh_name);
2938 internal->sh_type = BYTE_GET (shdrs[i].sh_type);
2939 internal->sh_flags = BYTE_GET8 (shdrs[i].sh_flags);
2940 internal->sh_addr = BYTE_GET8 (shdrs[i].sh_addr);
2941 internal->sh_size = BYTE_GET8 (shdrs[i].sh_size);
2942 internal->sh_entsize = BYTE_GET8 (shdrs[i].sh_entsize);
2943 internal->sh_link = BYTE_GET (shdrs[i].sh_link);
2944 internal->sh_info = BYTE_GET (shdrs[i].sh_info);
2945 internal->sh_offset = BYTE_GET (shdrs[i].sh_offset);
2946 internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
2954 static Elf_Internal_Sym *
2955 get_32bit_elf_symbols (file, section)
2957 Elf_Internal_Shdr *section;
2959 unsigned long number;
2960 Elf32_External_Sym * esyms;
2961 Elf_External_Sym_Shndx *shndx;
2962 Elf_Internal_Sym * isyms;
2963 Elf_Internal_Sym * psym;
2966 esyms = ((Elf32_External_Sym *)
2967 get_data (NULL, file, section->sh_offset,
2968 section->sh_size, _("symbols")));
2973 if (symtab_shndx_hdr != NULL
2974 && (symtab_shndx_hdr->sh_link
2975 == (unsigned long) SECTION_HEADER_NUM (section - section_headers)))
2977 shndx = ((Elf_External_Sym_Shndx *)
2978 get_data (NULL, file, symtab_shndx_hdr->sh_offset,
2979 symtab_shndx_hdr->sh_size, _("symtab shndx")));
2987 number = section->sh_size / section->sh_entsize;
2988 isyms = (Elf_Internal_Sym *) malloc (number * sizeof (Elf_Internal_Sym));
2992 error (_("Out of memory\n"));
2999 for (j = 0, psym = isyms;
3003 psym->st_name = BYTE_GET (esyms[j].st_name);
3004 psym->st_value = BYTE_GET (esyms[j].st_value);
3005 psym->st_size = BYTE_GET (esyms[j].st_size);
3006 psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
3007 if (psym->st_shndx == SHN_XINDEX && shndx != NULL)
3009 = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j]));
3010 psym->st_info = BYTE_GET (esyms[j].st_info);
3011 psym->st_other = BYTE_GET (esyms[j].st_other);
3021 static Elf_Internal_Sym *
3022 get_64bit_elf_symbols (file, section)
3024 Elf_Internal_Shdr *section;
3026 unsigned long number;
3027 Elf64_External_Sym * esyms;
3028 Elf_External_Sym_Shndx *shndx;
3029 Elf_Internal_Sym * isyms;
3030 Elf_Internal_Sym * psym;
3033 esyms = ((Elf64_External_Sym *)
3034 get_data (NULL, file, section->sh_offset,
3035 section->sh_size, _("symbols")));
3040 if (symtab_shndx_hdr != NULL
3041 && (symtab_shndx_hdr->sh_link
3042 == (unsigned long) SECTION_HEADER_NUM (section - section_headers)))
3044 shndx = ((Elf_External_Sym_Shndx *)
3045 get_data (NULL, file, symtab_shndx_hdr->sh_offset,
3046 symtab_shndx_hdr->sh_size, _("symtab shndx")));
3054 number = section->sh_size / section->sh_entsize;
3055 isyms = (Elf_Internal_Sym *) malloc (number * sizeof (Elf_Internal_Sym));
3059 error (_("Out of memory\n"));
3066 for (j = 0, psym = isyms;
3070 psym->st_name = BYTE_GET (esyms[j].st_name);
3071 psym->st_info = BYTE_GET (esyms[j].st_info);
3072 psym->st_other = BYTE_GET (esyms[j].st_other);
3073 psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
3074 if (psym->st_shndx == SHN_XINDEX && shndx != NULL)
3076 = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j]));
3077 psym->st_value = BYTE_GET8 (esyms[j].st_value);
3078 psym->st_size = BYTE_GET8 (esyms[j].st_size);
3089 get_elf_section_flags (sh_flags)
3092 static char buff [32];
3100 flag = sh_flags & - sh_flags;
3105 case SHF_WRITE: strcat (buff, "W"); break;
3106 case SHF_ALLOC: strcat (buff, "A"); break;
3107 case SHF_EXECINSTR: strcat (buff, "X"); break;
3108 case SHF_MERGE: strcat (buff, "M"); break;
3109 case SHF_STRINGS: strcat (buff, "S"); break;
3110 case SHF_INFO_LINK: strcat (buff, "I"); break;
3111 case SHF_LINK_ORDER: strcat (buff, "L"); break;
3112 case SHF_OS_NONCONFORMING: strcat (buff, "O"); break;
3113 case SHF_GROUP: strcat (buff, "G"); break;
3116 if (flag & SHF_MASKOS)
3119 sh_flags &= ~ SHF_MASKOS;
3121 else if (flag & SHF_MASKPROC)
3124 sh_flags &= ~ SHF_MASKPROC;
3136 process_section_headers (file)
3139 Elf_Internal_Shdr * section;
3142 section_headers = NULL;
3144 if (elf_header.e_shnum == 0)
3147 printf (_("\nThere are no sections in this file.\n"));
3152 if (do_sections && !do_header)
3153 printf (_("There are %d section headers, starting at offset 0x%lx:\n"),
3154 elf_header.e_shnum, (unsigned long) elf_header.e_shoff);
3158 if (! get_32bit_section_headers (file, elf_header.e_shnum))
3161 else if (! get_64bit_section_headers (file, elf_header.e_shnum))
3164 /* Read in the string table, so that we have names to display. */
3165 section = SECTION_HEADER (elf_header.e_shstrndx);
3167 if (section->sh_size != 0)
3169 string_table = (char *) get_data (NULL, file, section->sh_offset,
3170 section->sh_size, _("string table"));
3172 string_table_length = section->sh_size;
3175 /* Scan the sections for the dynamic symbol table
3176 and dynamic string table and debug sections. */
3177 dynamic_symbols = NULL;
3178 dynamic_strings = NULL;
3179 dynamic_syminfo = NULL;
3181 for (i = 0, section = section_headers;
3182 i < elf_header.e_shnum;
3185 char * name = SECTION_NAME (section);
3187 if (section->sh_type == SHT_DYNSYM)
3189 if (dynamic_symbols != NULL)
3191 error (_("File contains multiple dynamic symbol tables\n"));
3195 num_dynamic_syms = section->sh_size / section->sh_entsize;
3196 dynamic_symbols = GET_ELF_SYMBOLS (file, section);
3198 else if (section->sh_type == SHT_STRTAB
3199 && strcmp (name, ".dynstr") == 0)
3201 if (dynamic_strings != NULL)
3203 error (_("File contains multiple dynamic string tables\n"));
3207 dynamic_strings = (char *) get_data (NULL, file, section->sh_offset,
3209 _("dynamic strings"));
3211 else if (section->sh_type == SHT_SYMTAB_SHNDX)
3213 if (symtab_shndx_hdr != NULL)
3215 error (_("File contains multiple symtab shndx tables\n"));
3218 symtab_shndx_hdr = section;
3220 else if ((do_debugging || do_debug_info || do_debug_abbrevs
3221 || do_debug_lines || do_debug_pubnames || do_debug_aranges
3222 || do_debug_frames || do_debug_macinfo || do_debug_str)
3223 && strncmp (name, ".debug_", 7) == 0)
3228 || (do_debug_info && (strcmp (name, "info") == 0))
3229 || (do_debug_abbrevs && (strcmp (name, "abbrev") == 0))
3230 || (do_debug_lines && (strcmp (name, "line") == 0))
3231 || (do_debug_pubnames && (strcmp (name, "pubnames") == 0))
3232 || (do_debug_aranges && (strcmp (name, "aranges") == 0))
3233 || (do_debug_frames && (strcmp (name, "frame") == 0))
3234 || (do_debug_macinfo && (strcmp (name, "macinfo") == 0))
3235 || (do_debug_str && (strcmp (name, "str") == 0))
3237 request_dump (i, DEBUG_DUMP);
3239 /* linkonce section to be combined with .debug_info at link time. */
3240 else if ((do_debugging || do_debug_info)
3241 && strncmp (name, ".gnu.linkonce.wi.", 17) == 0)
3242 request_dump (i, DEBUG_DUMP);
3243 else if (do_debug_frames && strcmp (name, ".eh_frame") == 0)
3244 request_dump (i, DEBUG_DUMP);
3250 printf (_("\nSection Header%s:\n"), elf_header.e_shnum > 1 ? "s" : "");
3254 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
3257 (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n"));
3260 printf (_(" [Nr] Name Type Address Offset\n"));
3261 printf (_(" Size EntSize Flags Link Info Align\n"));
3264 for (i = 0, section = section_headers;
3265 i < elf_header.e_shnum;
3268 printf (" [%2u] %-17.17s %-15.15s ",
3269 SECTION_HEADER_NUM (i),
3270 SECTION_NAME (section),
3271 get_section_type_name (section->sh_type));
3275 print_vma (section->sh_addr, LONG_HEX);
3277 printf ( " %6.6lx %6.6lx %2.2lx",
3278 (unsigned long) section->sh_offset,
3279 (unsigned long) section->sh_size,
3280 (unsigned long) section->sh_entsize);
3282 printf (" %3s ", get_elf_section_flags (section->sh_flags));
3284 printf ("%2ld %3lx %2ld\n",
3285 (unsigned long) section->sh_link,
3286 (unsigned long) section->sh_info,
3287 (unsigned long) section->sh_addralign);
3291 print_vma (section->sh_addr, LONG_HEX);
3293 if ((long) section->sh_offset == section->sh_offset)
3294 printf (" %6.6lx", (unsigned long) section->sh_offset);
3298 print_vma (section->sh_offset, LONG_HEX);
3301 if ((unsigned long) section->sh_size == section->sh_size)
3302 printf (" %6.6lx", (unsigned long) section->sh_size);
3306 print_vma (section->sh_size, LONG_HEX);
3309 if ((unsigned long) section->sh_entsize == section->sh_entsize)
3310 printf (" %2.2lx", (unsigned long) section->sh_entsize);
3314 print_vma (section->sh_entsize, LONG_HEX);
3317 printf (" %3s ", get_elf_section_flags (section->sh_flags));
3319 printf ("%2ld %3lx ",
3320 (unsigned long) section->sh_link,
3321 (unsigned long) section->sh_info);
3323 if ((unsigned long) section->sh_addralign == section->sh_addralign)
3324 printf ("%2ld\n", (unsigned long) section->sh_addralign);
3327 print_vma (section->sh_addralign, DEC);
3334 print_vma (section->sh_addr, LONG_HEX);
3335 if ((long) section->sh_offset == section->sh_offset)
3336 printf (" %8.8lx", (unsigned long) section->sh_offset);
3340 print_vma (section->sh_offset, LONG_HEX);
3343 print_vma (section->sh_size, LONG_HEX);
3345 print_vma (section->sh_entsize, LONG_HEX);
3347 printf (" %3s ", get_elf_section_flags (section->sh_flags));
3349 printf (" %2ld %3lx %ld\n",
3350 (unsigned long) section->sh_link,
3351 (unsigned long) section->sh_info,
3352 (unsigned long) section->sh_addralign);
3356 printf (_("Key to Flags:\n\
3357 W (write), A (alloc), X (execute), M (merge), S (strings)\n\
3358 I (info), L (link order), G (group), x (unknown)\n\
3359 O (extra OS processing required) o (OS specific), p (processor specific)\n"));
3364 /* Process the reloc section. */
3366 process_relocs (file)
3369 unsigned long rel_size;
3370 unsigned long rel_offset;
3376 if (do_using_dynamic)
3378 int is_rela = FALSE;
3383 if (dynamic_info[DT_REL])
3385 rel_offset = dynamic_info[DT_REL];
3386 rel_size = dynamic_info[DT_RELSZ];
3389 else if (dynamic_info [DT_RELA])
3391 rel_offset = dynamic_info[DT_RELA];
3392 rel_size = dynamic_info[DT_RELASZ];
3395 else if (dynamic_info[DT_JMPREL])
3397 rel_offset = dynamic_info[DT_JMPREL];
3398 rel_size = dynamic_info[DT_PLTRELSZ];
3400 switch (dynamic_info[DT_PLTREL])
3417 (_("\nRelocation section at offset 0x%lx contains %ld bytes:\n"),
3418 rel_offset, rel_size);
3420 dump_relocations (file, rel_offset - loadaddr, rel_size,
3421 dynamic_symbols, num_dynamic_syms, dynamic_strings, is_rela);
3424 printf (_("\nThere are no dynamic relocations in this file.\n"));
3428 Elf32_Internal_Shdr * section;
3432 for (i = 0, section = section_headers;
3433 i < elf_header.e_shnum;
3436 if ( section->sh_type != SHT_RELA
3437 && section->sh_type != SHT_REL)
3440 rel_offset = section->sh_offset;
3441 rel_size = section->sh_size;
3445 Elf32_Internal_Shdr * strsec;
3446 Elf_Internal_Sym * symtab;
3449 unsigned long nsyms;
3451 printf (_("\nRelocation section "));
3453 if (string_table == NULL)
3454 printf ("%d", section->sh_name);
3456 printf ("'%s'", SECTION_NAME (section));
3458 printf (_(" at offset 0x%lx contains %lu entries:\n"),
3459 rel_offset, (unsigned long) (rel_size / section->sh_entsize));
3464 if (section->sh_link)
3466 Elf32_Internal_Shdr * symsec;
3468 symsec = SECTION_HEADER (section->sh_link);
3469 nsyms = symsec->sh_size / symsec->sh_entsize;
3470 symtab = GET_ELF_SYMBOLS (file, symsec);
3475 strsec = SECTION_HEADER (symsec->sh_link);
3477 strtab = (char *) get_data (NULL, file, strsec->sh_offset,
3481 is_rela = section->sh_type == SHT_RELA;
3483 dump_relocations (file, rel_offset, rel_size,
3484 symtab, nsyms, strtab, is_rela);
3496 printf (_("\nThere are no relocations in this file.\n"));
3502 #include "unwind-ia64.h"
3504 /* An absolute address consists of a section and an offset. If the
3505 section is NULL, the offset itself is the address, otherwise, the
3506 address equals to LOAD_ADDRESS(section) + offset. */
3510 unsigned short section;
3516 struct unw_table_entry
3518 struct absaddr start;
3520 struct absaddr info;
3522 *table; /* Unwind table. */
3523 unsigned long table_len; /* Length of unwind table. */
3524 unsigned char * info; /* Unwind info. */
3525 unsigned long info_size; /* Size of unwind info. */
3526 bfd_vma info_addr; /* starting address of unwind info. */
3527 bfd_vma seg_base; /* Starting address of segment. */
3528 Elf_Internal_Sym * symtab; /* The symbol table. */
3529 unsigned long nsyms; /* Number of symbols. */
3530 char * strtab; /* The string table. */
3531 unsigned long strtab_size; /* Size of string table. */
3534 static void find_symbol_for_address PARAMS ((struct unw_aux_info *,
3535 struct absaddr, const char **,
3537 static void dump_ia64_unwind PARAMS ((struct unw_aux_info *));
3538 static int slurp_ia64_unwind_table PARAMS ((FILE *, struct unw_aux_info *,
3539 Elf32_Internal_Shdr *));
3542 find_symbol_for_address (aux, addr, symname, offset)
3543 struct unw_aux_info *aux;
3544 struct absaddr addr;
3545 const char **symname;
3548 bfd_vma dist = (bfd_vma) 0x100000;
3549 Elf_Internal_Sym *sym, *best = NULL;
3552 for (i = 0, sym = aux->symtab; i < aux->nsyms; ++i, ++sym)
3554 if (ELF_ST_TYPE (sym->st_info) == STT_FUNC
3555 && sym->st_name != 0
3556 && (addr.section == SHN_UNDEF || addr.section == sym->st_shndx)
3557 && addr.offset >= sym->st_value
3558 && addr.offset - sym->st_value < dist)
3561 dist = addr.offset - sym->st_value;
3568 *symname = (best->st_name >= aux->strtab_size
3569 ? "<corrupt>" : aux->strtab + best->st_name);
3574 *offset = addr.offset;
3578 dump_ia64_unwind (aux)
3579 struct unw_aux_info *aux;
3582 struct unw_table_entry * tp;
3585 addr_size = is_32bit_elf ? 4 : 8;
3587 for (tp = aux->table; tp < aux->table + aux->table_len; ++tp)
3591 const unsigned char * dp;
3592 const unsigned char * head;
3593 const char * procname;
3595 find_symbol_for_address (aux, tp->start, &procname, &offset);
3597 fputs ("\n<", stdout);
3601 fputs (procname, stdout);
3604 printf ("+%lx", (unsigned long) offset);
3607 fputs (">: [", stdout);
3608 print_vma (tp->start.offset, PREFIX_HEX);
3609 fputc ('-', stdout);
3610 print_vma (tp->end.offset, PREFIX_HEX);
3611 printf ("), info at +0x%lx\n",
3612 (unsigned long) (tp->info.offset - aux->seg_base));
3614 head = aux->info + (tp->info.offset - aux->info_addr);
3615 stamp = BYTE_GET8 ((unsigned char *) head);
3617 printf (" v%u, flags=0x%lx (%s%s ), len=%lu bytes\n",
3618 (unsigned) UNW_VER (stamp),
3619 (unsigned long) ((stamp & UNW_FLAG_MASK) >> 32),
3620 UNW_FLAG_EHANDLER (stamp) ? " ehandler" : "",
3621 UNW_FLAG_UHANDLER (stamp) ? " uhandler" : "",
3622 (unsigned long) (addr_size * UNW_LENGTH (stamp)));
3624 if (UNW_VER (stamp) != 1)
3626 printf ("\tUnknown version.\n");
3631 for (dp = head + 8; dp < head + 8 + addr_size * UNW_LENGTH (stamp);)
3632 dp = unw_decode (dp, in_body, & in_body);
3637 slurp_ia64_unwind_table (file, aux, sec)
3639 struct unw_aux_info *aux;
3640 Elf32_Internal_Shdr *sec;
3642 unsigned long size, addr_size, nrelas, i;
3643 Elf_Internal_Phdr *prog_hdrs, *seg;
3644 struct unw_table_entry *tep;
3645 Elf32_Internal_Shdr *relsec;
3646 Elf_Internal_Rela *rela, *rp;
3647 unsigned char *table, *tp;
3648 Elf_Internal_Sym *sym;
3649 const char *relname;
3652 addr_size = is_32bit_elf ? 4 : 8;
3654 /* First, find the starting address of the segment that includes
3657 if (elf_header.e_phnum)
3659 prog_hdrs = (Elf_Internal_Phdr *)
3660 xmalloc (elf_header.e_phnum * sizeof (Elf_Internal_Phdr));
3663 result = get_32bit_program_headers (file, prog_hdrs);
3665 result = get_64bit_program_headers (file, prog_hdrs);
3673 for (seg = prog_hdrs; seg < prog_hdrs + elf_header.e_phnum; ++seg)
3675 if (seg->p_type != PT_LOAD)
3678 if (sec->sh_addr >= seg->p_vaddr
3679 && (sec->sh_addr + sec->sh_size <= seg->p_vaddr + seg->p_memsz))
3681 aux->seg_base = seg->p_vaddr;
3689 /* Second, build the unwind table from the contents of the unwind section: */
3690 size = sec->sh_size;
3691 table = (char *) get_data (NULL, file, sec->sh_offset,
3692 size, _("unwind table"));
3696 tep = aux->table = xmalloc (size / (3 * addr_size) * sizeof (aux->table[0]));
3697 for (tp = table; tp < table + size; tp += 3 * addr_size, ++ tep)
3699 tep->start.section = SHN_UNDEF;
3700 tep->end.section = SHN_UNDEF;
3701 tep->info.section = SHN_UNDEF;
3704 tep->start.offset = byte_get ((unsigned char *) tp + 0, 4);
3705 tep->end.offset = byte_get ((unsigned char *) tp + 4, 4);
3706 tep->info.offset = byte_get ((unsigned char *) tp + 8, 4);
3710 tep->start.offset = BYTE_GET8 ((unsigned char *) tp + 0);
3711 tep->end.offset = BYTE_GET8 ((unsigned char *) tp + 8);
3712 tep->info.offset = BYTE_GET8 ((unsigned char *) tp + 16);
3714 tep->start.offset += aux->seg_base;
3715 tep->end.offset += aux->seg_base;
3716 tep->info.offset += aux->seg_base;
3720 /* Third, apply any relocations to the unwind table: */
3722 for (relsec = section_headers;
3723 relsec < section_headers + elf_header.e_shnum;
3726 if (relsec->sh_type != SHT_RELA
3727 || SECTION_HEADER (relsec->sh_info) != sec)
3730 if (!slurp_rela_relocs (file, relsec->sh_offset, relsec->sh_size,
3734 for (rp = rela; rp < rela + nrelas; ++rp)
3738 relname = elf_ia64_reloc_type (ELF32_R_TYPE (rp->r_info));
3739 sym = aux->symtab + ELF32_R_SYM (rp->r_info);
3741 if (ELF32_ST_TYPE (sym->st_info) != STT_SECTION)
3743 warn (_("Skipping unexpected symbol type %u\n"),
3744 ELF32_ST_TYPE (sym->st_info));
3750 relname = elf_ia64_reloc_type (ELF64_R_TYPE (rp->r_info));
3751 sym = aux->symtab + ELF64_R_SYM (rp->r_info);
3753 if (ELF64_ST_TYPE (sym->st_info) != STT_SECTION)
3755 warn (_("Skipping unexpected symbol type %u\n"),
3756 ELF64_ST_TYPE (sym->st_info));
3761 if (strncmp (relname, "R_IA64_SEGREL", 13) != 0)
3763 warn (_("Skipping unexpected relocation type %s\n"), relname);
3767 i = rp->r_offset / (3 * addr_size);
3769 switch (rp->r_offset/addr_size % 3)
3772 aux->table[i].start.section = sym->st_shndx;
3773 aux->table[i].start.offset += rp->r_addend;
3776 aux->table[i].end.section = sym->st_shndx;
3777 aux->table[i].end.offset += rp->r_addend;
3780 aux->table[i].info.section = sym->st_shndx;
3781 aux->table[i].info.offset += rp->r_addend;
3791 aux->table_len = size / (3 * addr_size);
3796 process_unwind (file)
3799 Elf32_Internal_Shdr *sec, *unwsec = NULL, *strsec;
3800 unsigned long i, addr_size, unwcount = 0, unwstart = 0;
3801 struct unw_aux_info aux;
3806 if (elf_header.e_machine != EM_IA_64)
3808 printf (_("\nThere are no unwind sections in this file.\n"));
3812 memset (& aux, 0, sizeof (aux));
3814 addr_size = is_32bit_elf ? 4 : 8;
3816 for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec)
3818 if (sec->sh_type == SHT_SYMTAB)
3820 aux.nsyms = sec->sh_size / sec->sh_entsize;
3821 aux.symtab = GET_ELF_SYMBOLS (file, sec);
3823 strsec = SECTION_HEADER (sec->sh_link);
3824 aux.strtab_size = strsec->sh_size;
3825 aux.strtab = (char *) get_data (NULL, file, strsec->sh_offset,
3826 aux.strtab_size, _("string table"));
3828 else if (sec->sh_type == SHT_IA_64_UNWIND)
3833 printf (_("\nThere are no unwind sections in this file.\n"));
3835 while (unwcount-- > 0)
3840 for (i = unwstart, sec = section_headers + unwstart;
3841 i < elf_header.e_shnum; ++i, ++sec)
3842 if (sec->sh_type == SHT_IA_64_UNWIND)
3849 len = sizeof (ELF_STRING_ia64_unwind_once) - 1;
3851 if (strncmp (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind_once,
3854 /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO */
3855 len2 = sizeof (ELF_STRING_ia64_unwind_info_once) - 1;
3856 suffix = SECTION_NAME (unwsec) + len;
3857 for (i = 0, sec = section_headers; i < elf_header.e_shnum;
3859 if (strncmp (SECTION_NAME (sec),
3860 ELF_STRING_ia64_unwind_info_once, len2) == 0
3861 && strcmp (SECTION_NAME (sec) + len2, suffix) == 0)
3866 /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO
3867 .IA_64.unwind or BAR -> .IA_64.unwind_info */
3868 len = sizeof (ELF_STRING_ia64_unwind) - 1;
3869 len2 = sizeof (ELF_STRING_ia64_unwind_info) - 1;
3871 if (strncmp (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind,
3873 suffix = SECTION_NAME (unwsec) + len;
3874 for (i = 0, sec = section_headers; i < elf_header.e_shnum;
3876 if (strncmp (SECTION_NAME (sec),
3877 ELF_STRING_ia64_unwind_info, len2) == 0
3878 && strcmp (SECTION_NAME (sec) + len2, suffix) == 0)
3882 if (i == elf_header.e_shnum)
3884 printf (_("\nCould not find unwind info section for "));
3886 if (string_table == NULL)
3887 printf ("%d", unwsec->sh_name);
3889 printf ("'%s'", SECTION_NAME (unwsec));
3893 aux.info_size = sec->sh_size;
3894 aux.info_addr = sec->sh_addr;
3895 aux.info = (char *) get_data (NULL, file, sec->sh_offset,
3896 aux.info_size, _("unwind info"));
3898 printf (_("\nUnwind section "));
3900 if (string_table == NULL)
3901 printf ("%d", unwsec->sh_name);
3903 printf ("'%s'", SECTION_NAME (unwsec));
3905 printf (_(" at offset 0x%lx contains %lu entries:\n"),
3906 (unsigned long) unwsec->sh_offset,
3907 (unsigned long) (unwsec->sh_size / (3 * addr_size)));
3909 (void) slurp_ia64_unwind_table (file, & aux, unwsec);
3911 if (aux.table_len > 0)
3912 dump_ia64_unwind (& aux);
3915 free ((char *) aux.table);
3917 free ((char *) aux.info);
3926 free ((char *) aux.strtab);
3932 dynamic_segment_mips_val (entry)
3933 Elf_Internal_Dyn * entry;
3935 switch (entry->d_tag)
3938 if (entry->d_un.d_val == 0)
3942 static const char * opts[] =
3944 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
3945 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
3946 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
3947 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
3952 for (cnt = 0; cnt < NUM_ELEM (opts); ++ cnt)
3953 if (entry->d_un.d_val & (1 << cnt))
3955 printf ("%s%s", first ? "" : " ", opts[cnt]);
3962 case DT_MIPS_IVERSION:
3963 if (dynamic_strings != NULL)
3964 printf ("Interface Version: %s\n",
3965 dynamic_strings + entry->d_un.d_val);
3967 printf ("%ld\n", (long) entry->d_un.d_ptr);
3970 case DT_MIPS_TIME_STAMP:
3975 time_t time = entry->d_un.d_val;
3976 tmp = gmtime (&time);
3977 sprintf (timebuf, "%04u-%02u-%02uT%02u:%02u:%02u",
3978 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
3979 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
3980 printf ("Time Stamp: %s\n", timebuf);
3984 case DT_MIPS_RLD_VERSION:
3985 case DT_MIPS_LOCAL_GOTNO:
3986 case DT_MIPS_CONFLICTNO:
3987 case DT_MIPS_LIBLISTNO:
3988 case DT_MIPS_SYMTABNO:
3989 case DT_MIPS_UNREFEXTNO:
3990 case DT_MIPS_HIPAGENO:
3991 case DT_MIPS_DELTA_CLASS_NO:
3992 case DT_MIPS_DELTA_INSTANCE_NO:
3993 case DT_MIPS_DELTA_RELOC_NO:
3994 case DT_MIPS_DELTA_SYM_NO:
3995 case DT_MIPS_DELTA_CLASSSYM_NO:
3996 case DT_MIPS_COMPACT_SIZE:
3997 printf ("%ld\n", (long) entry->d_un.d_ptr);
4001 printf ("%#lx\n", (long) entry->d_un.d_ptr);
4007 dynamic_segment_parisc_val (entry)
4008 Elf_Internal_Dyn * entry;
4010 switch (entry->d_tag)
4012 case DT_HP_DLD_FLAGS:
4021 { DT_HP_DEBUG_PRIVATE, "HP_DEBUG_PRIVATE" },
4022 { DT_HP_DEBUG_CALLBACK, "HP_DEBUG_CALLBACK" },
4023 { DT_HP_DEBUG_CALLBACK_BOR, "HP_DEBUG_CALLBACK_BOR" },
4024 { DT_HP_NO_ENVVAR, "HP_NO_ENVVAR" },
4025 { DT_HP_BIND_NOW, "HP_BIND_NOW" },
4026 { DT_HP_BIND_NONFATAL, "HP_BIND_NONFATAL" },
4027 { DT_HP_BIND_VERBOSE, "HP_BIND_VERBOSE" },
4028 { DT_HP_BIND_RESTRICTED, "HP_BIND_RESTRICTED" },
4029 { DT_HP_BIND_SYMBOLIC, "HP_BIND_SYMBOLIC" },
4030 { DT_HP_RPATH_FIRST, "HP_RPATH_FIRST" },
4031 { DT_HP_BIND_DEPTH_FIRST, "HP_BIND_DEPTH_FIRST" }
4035 bfd_vma val = entry->d_un.d_val;
4037 for (cnt = 0; cnt < sizeof (flags) / sizeof (flags[0]); ++cnt)
4038 if (val & flags[cnt].bit)
4042 fputs (flags[cnt].str, stdout);
4044 val ^= flags[cnt].bit;
4047 if (val != 0 || first)
4051 print_vma (val, HEX);
4057 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
4063 get_32bit_dynamic_segment (file)
4066 Elf32_External_Dyn * edyn;
4067 Elf_Internal_Dyn * entry;
4070 edyn = (Elf32_External_Dyn *) get_data (NULL, file, dynamic_addr,
4071 dynamic_size, _("dynamic segment"));
4075 /* SGI's ELF has more than one section in the DYNAMIC segment. Determine
4076 how large this .dynamic is now. We can do this even before the byte
4077 swapping since the DT_NULL tag is recognizable. */
4079 while (*(Elf32_Word *) edyn [dynamic_size++].d_tag != DT_NULL)
4082 dynamic_segment = (Elf_Internal_Dyn *)
4083 malloc (dynamic_size * sizeof (Elf_Internal_Dyn));
4085 if (dynamic_segment == NULL)
4087 error (_("Out of memory\n"));
4092 for (i = 0, entry = dynamic_segment;
4096 entry->d_tag = BYTE_GET (edyn [i].d_tag);
4097 entry->d_un.d_val = BYTE_GET (edyn [i].d_un.d_val);
4106 get_64bit_dynamic_segment (file)
4109 Elf64_External_Dyn * edyn;
4110 Elf_Internal_Dyn * entry;
4113 edyn = (Elf64_External_Dyn *) get_data (NULL, file, dynamic_addr,
4114 dynamic_size, _("dynamic segment"));
4118 /* SGI's ELF has more than one section in the DYNAMIC segment. Determine
4119 how large this .dynamic is now. We can do this even before the byte
4120 swapping since the DT_NULL tag is recognizable. */
4122 while (*(bfd_vma *) edyn [dynamic_size ++].d_tag != DT_NULL)
4125 dynamic_segment = (Elf_Internal_Dyn *)
4126 malloc (dynamic_size * sizeof (Elf_Internal_Dyn));
4128 if (dynamic_segment == NULL)
4130 error (_("Out of memory\n"));
4135 for (i = 0, entry = dynamic_segment;
4139 entry->d_tag = BYTE_GET8 (edyn [i].d_tag);
4140 entry->d_un.d_val = BYTE_GET8 (edyn [i].d_un.d_val);
4149 get_dynamic_flags (flags)
4152 static char buff [64];
4157 flag = flags & - flags;
4162 case DF_ORIGIN: strcat (buff, "ORIGIN "); break;
4163 case DF_SYMBOLIC: strcat (buff, "SYMBOLIC "); break;
4164 case DF_TEXTREL: strcat (buff, "TEXTREL "); break;
4165 case DF_BIND_NOW: strcat (buff, "BIND_NOW "); break;
4166 default: strcat (buff, "unknown "); break;
4172 /* Parse and display the contents of the dynamic segment. */
4174 process_dynamic_segment (file)
4177 Elf_Internal_Dyn * entry;
4180 if (dynamic_size == 0)
4183 printf (_("\nThere is no dynamic segment in this file.\n"));
4190 if (! get_32bit_dynamic_segment (file))
4193 else if (! get_64bit_dynamic_segment (file))
4196 /* Find the appropriate symbol table. */
4197 if (dynamic_symbols == NULL)
4199 for (i = 0, entry = dynamic_segment;
4203 Elf32_Internal_Shdr section;
4205 if (entry->d_tag != DT_SYMTAB)
4208 dynamic_info[DT_SYMTAB] = entry->d_un.d_val;
4210 /* Since we do not know how big the symbol table is,
4211 we default to reading in the entire file (!) and
4212 processing that. This is overkill, I know, but it
4214 section.sh_offset = entry->d_un.d_val - loadaddr;
4216 if (fseek (file, 0, SEEK_END))
4217 error (_("Unable to seek to end of file!"));
4219 section.sh_size = ftell (file) - section.sh_offset;
4221 section.sh_entsize = sizeof (Elf32_External_Sym);
4223 section.sh_entsize = sizeof (Elf64_External_Sym);
4225 num_dynamic_syms = section.sh_size / section.sh_entsize;
4226 if (num_dynamic_syms < 1)
4228 error (_("Unable to determine the number of symbols to load\n"));
4232 dynamic_symbols = GET_ELF_SYMBOLS (file, §ion);
4236 /* Similarly find a string table. */
4237 if (dynamic_strings == NULL)
4239 for (i = 0, entry = dynamic_segment;
4243 unsigned long offset;
4246 if (entry->d_tag != DT_STRTAB)
4249 dynamic_info[DT_STRTAB] = entry->d_un.d_val;
4251 /* Since we do not know how big the string table is,
4252 we default to reading in the entire file (!) and
4253 processing that. This is overkill, I know, but it
4256 offset = entry->d_un.d_val - loadaddr;
4257 if (fseek (file, 0, SEEK_END))
4258 error (_("Unable to seek to end of file\n"));
4259 str_tab_len = ftell (file) - offset;
4261 if (str_tab_len < 1)
4264 (_("Unable to determine the length of the dynamic string table\n"));
4268 dynamic_strings = (char *) get_data (NULL, file, offset, str_tab_len,
4269 _("dynamic string table"));
4274 /* And find the syminfo section if available. */
4275 if (dynamic_syminfo == NULL)
4277 unsigned int syminsz = 0;
4279 for (i = 0, entry = dynamic_segment;
4283 if (entry->d_tag == DT_SYMINENT)
4285 /* Note: these braces are necessary to avoid a syntax
4286 error from the SunOS4 C compiler. */
4287 assert (sizeof (Elf_External_Syminfo) == entry->d_un.d_val);
4289 else if (entry->d_tag == DT_SYMINSZ)
4290 syminsz = entry->d_un.d_val;
4291 else if (entry->d_tag == DT_SYMINFO)
4292 dynamic_syminfo_offset = entry->d_un.d_val - loadaddr;
4295 if (dynamic_syminfo_offset != 0 && syminsz != 0)
4297 Elf_External_Syminfo * extsyminfo;
4298 Elf_Internal_Syminfo * syminfo;
4300 /* There is a syminfo section. Read the data. */
4301 extsyminfo = ((Elf_External_Syminfo *)
4302 get_data (NULL, file, dynamic_syminfo_offset,
4303 syminsz, _("symbol information")));
4307 dynamic_syminfo = (Elf_Internal_Syminfo *) malloc (syminsz);
4308 if (dynamic_syminfo == NULL)
4310 error (_("Out of memory\n"));
4314 dynamic_syminfo_nent = syminsz / sizeof (Elf_External_Syminfo);
4315 for (i = 0, syminfo = dynamic_syminfo; i < dynamic_syminfo_nent;
4318 syminfo->si_boundto = BYTE_GET (extsyminfo[i].si_boundto);
4319 syminfo->si_flags = BYTE_GET (extsyminfo[i].si_flags);
4326 if (do_dynamic && dynamic_addr)
4327 printf (_("\nDynamic segment at offset 0x%x contains %ld entries:\n"),
4328 dynamic_addr, (long) dynamic_size);
4330 printf (_(" Tag Type Name/Value\n"));
4332 for (i = 0, entry = dynamic_segment;
4341 print_vma (entry->d_tag, FULL_HEX);
4342 dtype = get_dynamic_type (entry->d_tag);
4343 printf (" (%s)%*s", dtype,
4344 ((is_32bit_elf ? 27 : 19)
4345 - (int) strlen (dtype)),
4349 switch (entry->d_tag)
4353 printf ("%s", get_dynamic_flags (entry->d_un.d_val));
4363 switch (entry->d_tag)
4366 printf (_("Auxiliary library"));
4370 printf (_("Filter library"));
4374 printf (_("Configuration file"));
4378 printf (_("Dependency audit library"));
4382 printf (_("Audit library"));
4386 if (dynamic_strings)
4387 printf (": [%s]\n", dynamic_strings + entry->d_un.d_val);
4391 print_vma (entry->d_un.d_val, PREFIX_HEX);
4400 printf (_("Flags:"));
4401 if (entry->d_un.d_val == 0)
4402 printf (_(" None\n"));
4405 unsigned long int val = entry->d_un.d_val;
4406 if (val & DTF_1_PARINIT)
4408 printf (" PARINIT");
4409 val ^= DTF_1_PARINIT;
4411 if (val & DTF_1_CONFEXP)
4413 printf (" CONFEXP");
4414 val ^= DTF_1_CONFEXP;
4417 printf (" %lx", val);
4426 printf (_("Flags:"));
4427 if (entry->d_un.d_val == 0)
4428 printf (_(" None\n"));
4431 unsigned long int val = entry->d_un.d_val;
4432 if (val & DF_P1_LAZYLOAD)
4434 printf (" LAZYLOAD");
4435 val ^= DF_P1_LAZYLOAD;
4437 if (val & DF_P1_GROUPPERM)
4439 printf (" GROUPPERM");
4440 val ^= DF_P1_GROUPPERM;
4443 printf (" %lx", val);
4452 printf (_("Flags:"));
4453 if (entry->d_un.d_val == 0)
4454 printf (_(" None\n"));
4457 unsigned long int val = entry->d_un.d_val;
4463 if (val & DF_1_GLOBAL)
4468 if (val & DF_1_GROUP)
4473 if (val & DF_1_NODELETE)
4475 printf (" NODELETE");
4476 val ^= DF_1_NODELETE;
4478 if (val & DF_1_LOADFLTR)
4480 printf (" LOADFLTR");
4481 val ^= DF_1_LOADFLTR;
4483 if (val & DF_1_INITFIRST)
4485 printf (" INITFIRST");
4486 val ^= DF_1_INITFIRST;
4488 if (val & DF_1_NOOPEN)
4493 if (val & DF_1_ORIGIN)
4498 if (val & DF_1_DIRECT)
4503 if (val & DF_1_TRANS)
4508 if (val & DF_1_INTERPOSE)
4510 printf (" INTERPOSE");
4511 val ^= DF_1_INTERPOSE;
4513 if (val & DF_1_NODEFLIB)
4515 printf (" NODEFLIB");
4516 val ^= DF_1_NODEFLIB;
4518 if (val & DF_1_NODUMP)
4523 if (val & DF_1_CONLFAT)
4525 printf (" CONLFAT");
4526 val ^= DF_1_CONLFAT;
4529 printf (" %lx", val);
4537 puts (get_dynamic_type (entry->d_un.d_val));
4557 dynamic_info[entry->d_tag] = entry->d_un.d_val;
4563 if (dynamic_strings == NULL)
4566 name = dynamic_strings + entry->d_un.d_val;
4570 switch (entry->d_tag)
4573 printf (_("Shared library: [%s]"), name);
4575 if (strcmp (name, program_interpreter) == 0)
4576 printf (_(" program interpreter"));
4580 printf (_("Library soname: [%s]"), name);
4584 printf (_("Library rpath: [%s]"), name);
4588 printf (_("Library runpath: [%s]"), name);
4592 print_vma (entry->d_un.d_val, PREFIX_HEX);
4597 print_vma (entry->d_un.d_val, PREFIX_HEX);
4613 case DT_INIT_ARRAYSZ:
4614 case DT_FINI_ARRAYSZ:
4617 print_vma (entry->d_un.d_val, UNSIGNED);
4618 printf (" (bytes)\n");
4628 print_vma (entry->d_un.d_val, UNSIGNED);
4641 if (dynamic_strings != NULL && entry->d_tag == DT_USED)
4645 name = dynamic_strings + entry->d_un.d_val;
4649 printf (_("Not needed object: [%s]\n"), name);
4654 print_vma (entry->d_un.d_val, PREFIX_HEX);
4660 /* The value of this entry is ignored. */
4664 if ((entry->d_tag >= DT_VERSYM) && (entry->d_tag <= DT_VERNEEDNUM))
4665 version_info [DT_VERSIONTAGIDX (entry->d_tag)] =
4670 switch (elf_header.e_machine)
4673 case EM_MIPS_RS3_LE:
4674 dynamic_segment_mips_val (entry);
4677 dynamic_segment_parisc_val (entry);
4680 print_vma (entry->d_un.d_val, PREFIX_HEX);
4692 get_ver_flags (flags)
4695 static char buff [32];
4702 if (flags & VER_FLG_BASE)
4703 strcat (buff, "BASE ");
4705 if (flags & VER_FLG_WEAK)
4707 if (flags & VER_FLG_BASE)
4708 strcat (buff, "| ");
4710 strcat (buff, "WEAK ");
4713 if (flags & ~(VER_FLG_BASE | VER_FLG_WEAK))
4714 strcat (buff, "| <unknown>");
4719 /* Display the contents of the version sections. */
4721 process_version_sections (file)
4724 Elf32_Internal_Shdr * section;
4731 for (i = 0, section = section_headers;
4732 i < elf_header.e_shnum;
4735 switch (section->sh_type)
4737 case SHT_GNU_verdef:
4739 Elf_External_Verdef * edefs;
4746 (_("\nVersion definition section '%s' contains %ld entries:\n"),
4747 SECTION_NAME (section), section->sh_info);
4749 printf (_(" Addr: 0x"));
4750 printf_vma (section->sh_addr);
4751 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
4752 (unsigned long) section->sh_offset, section->sh_link,
4753 SECTION_NAME (SECTION_HEADER (section->sh_link)));
4755 edefs = ((Elf_External_Verdef *)
4756 get_data (NULL, file, section->sh_offset,
4758 _("version definition section")));
4762 for (idx = cnt = 0; cnt < section->sh_info; ++ cnt)
4765 Elf_External_Verdef * edef;
4766 Elf_Internal_Verdef ent;
4767 Elf_External_Verdaux * eaux;
4768 Elf_Internal_Verdaux aux;
4772 vstart = ((char *) edefs) + idx;
4774 edef = (Elf_External_Verdef *) vstart;
4776 ent.vd_version = BYTE_GET (edef->vd_version);
4777 ent.vd_flags = BYTE_GET (edef->vd_flags);
4778 ent.vd_ndx = BYTE_GET (edef->vd_ndx);
4779 ent.vd_cnt = BYTE_GET (edef->vd_cnt);
4780 ent.vd_hash = BYTE_GET (edef->vd_hash);
4781 ent.vd_aux = BYTE_GET (edef->vd_aux);
4782 ent.vd_next = BYTE_GET (edef->vd_next);
4784 printf (_(" %#06x: Rev: %d Flags: %s"),
4785 idx, ent.vd_version, get_ver_flags (ent.vd_flags));
4787 printf (_(" Index: %d Cnt: %d "),
4788 ent.vd_ndx, ent.vd_cnt);
4790 vstart += ent.vd_aux;
4792 eaux = (Elf_External_Verdaux *) vstart;
4794 aux.vda_name = BYTE_GET (eaux->vda_name);
4795 aux.vda_next = BYTE_GET (eaux->vda_next);
4797 if (dynamic_strings)
4798 printf (_("Name: %s\n"), dynamic_strings + aux.vda_name);
4800 printf (_("Name index: %ld\n"), aux.vda_name);
4802 isum = idx + ent.vd_aux;
4804 for (j = 1; j < ent.vd_cnt; j ++)
4806 isum += aux.vda_next;
4807 vstart += aux.vda_next;
4809 eaux = (Elf_External_Verdaux *) vstart;
4811 aux.vda_name = BYTE_GET (eaux->vda_name);
4812 aux.vda_next = BYTE_GET (eaux->vda_next);
4814 if (dynamic_strings)
4815 printf (_(" %#06x: Parent %d: %s\n"),
4816 isum, j, dynamic_strings + aux.vda_name);
4818 printf (_(" %#06x: Parent %d, name index: %ld\n"),
4819 isum, j, aux.vda_name);
4829 case SHT_GNU_verneed:
4831 Elf_External_Verneed * eneed;
4837 printf (_("\nVersion needs section '%s' contains %ld entries:\n"),
4838 SECTION_NAME (section), section->sh_info);
4840 printf (_(" Addr: 0x"));
4841 printf_vma (section->sh_addr);
4842 printf (_(" Offset: %#08lx Link to section: %ld (%s)\n"),
4843 (unsigned long) section->sh_offset, section->sh_link,
4844 SECTION_NAME (SECTION_HEADER (section->sh_link)));
4846 eneed = ((Elf_External_Verneed *)
4847 get_data (NULL, file, section->sh_offset,
4848 section->sh_size, _("version need section")));
4852 for (idx = cnt = 0; cnt < section->sh_info; ++cnt)
4854 Elf_External_Verneed * entry;
4855 Elf_Internal_Verneed ent;
4860 vstart = ((char *) eneed) + idx;
4862 entry = (Elf_External_Verneed *) vstart;
4864 ent.vn_version = BYTE_GET (entry->vn_version);
4865 ent.vn_cnt = BYTE_GET (entry->vn_cnt);
4866 ent.vn_file = BYTE_GET (entry->vn_file);
4867 ent.vn_aux = BYTE_GET (entry->vn_aux);
4868 ent.vn_next = BYTE_GET (entry->vn_next);
4870 printf (_(" %#06x: Version: %d"), idx, ent.vn_version);
4872 if (dynamic_strings)
4873 printf (_(" File: %s"), dynamic_strings + ent.vn_file);
4875 printf (_(" File: %lx"), ent.vn_file);
4877 printf (_(" Cnt: %d\n"), ent.vn_cnt);
4879 vstart += ent.vn_aux;
4881 for (j = 0, isum = idx + ent.vn_aux; j < ent.vn_cnt; ++j)
4883 Elf_External_Vernaux * eaux;
4884 Elf_Internal_Vernaux aux;
4886 eaux = (Elf_External_Vernaux *) vstart;
4888 aux.vna_hash = BYTE_GET (eaux->vna_hash);
4889 aux.vna_flags = BYTE_GET (eaux->vna_flags);
4890 aux.vna_other = BYTE_GET (eaux->vna_other);
4891 aux.vna_name = BYTE_GET (eaux->vna_name);
4892 aux.vna_next = BYTE_GET (eaux->vna_next);
4894 if (dynamic_strings)
4895 printf (_(" %#06x: Name: %s"),
4896 isum, dynamic_strings + aux.vna_name);
4898 printf (_(" %#06x: Name index: %lx"),
4899 isum, aux.vna_name);
4901 printf (_(" Flags: %s Version: %d\n"),
4902 get_ver_flags (aux.vna_flags), aux.vna_other);
4904 isum += aux.vna_next;
4905 vstart += aux.vna_next;
4915 case SHT_GNU_versym:
4917 Elf32_Internal_Shdr * link_section;
4920 unsigned char * edata;
4921 unsigned short * data;
4923 Elf_Internal_Sym * symbols;
4924 Elf32_Internal_Shdr * string_sec;
4926 link_section = SECTION_HEADER (section->sh_link);
4927 total = section->sh_size / section->sh_entsize;
4931 symbols = GET_ELF_SYMBOLS (file, link_section);
4933 string_sec = SECTION_HEADER (link_section->sh_link);
4935 strtab = (char *) get_data (NULL, file, string_sec->sh_offset,
4936 string_sec->sh_size,
4937 _("version string table"));
4941 printf (_("\nVersion symbols section '%s' contains %d entries:\n"),
4942 SECTION_NAME (section), total);
4944 printf (_(" Addr: "));
4945 printf_vma (section->sh_addr);
4946 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
4947 (unsigned long) section->sh_offset, section->sh_link,
4948 SECTION_NAME (link_section));
4952 get_data (NULL, file,
4953 version_info[DT_VERSIONTAGIDX (DT_VERSYM)] - loadaddr,
4954 total * sizeof (short), _("version symbol data")));
4961 data = (unsigned short *) malloc (total * sizeof (short));
4963 for (cnt = total; cnt --;)
4964 data [cnt] = byte_get (edata + cnt * sizeof (short),
4969 for (cnt = 0; cnt < total; cnt += 4)
4972 int check_def, check_need;
4975 printf (" %03x:", cnt);
4977 for (j = 0; (j < 4) && (cnt + j) < total; ++j)
4978 switch (data [cnt + j])
4981 fputs (_(" 0 (*local*) "), stdout);
4985 fputs (_(" 1 (*global*) "), stdout);
4989 nn = printf ("%4x%c", data [cnt + j] & 0x7fff,
4990 data [cnt + j] & 0x8000 ? 'h' : ' ');
4994 if (SECTION_HEADER (symbols [cnt + j].st_shndx)->sh_type
4997 if (symbols [cnt + j].st_shndx == SHN_UNDEF)
5004 && version_info [DT_VERSIONTAGIDX (DT_VERNEED)])
5006 Elf_Internal_Verneed ivn;
5007 unsigned long offset;
5009 offset = version_info [DT_VERSIONTAGIDX (DT_VERNEED)]
5014 Elf_Internal_Vernaux ivna;
5015 Elf_External_Verneed evn;
5016 Elf_External_Vernaux evna;
5017 unsigned long a_off;
5019 get_data (&evn, file, offset, sizeof (evn),
5022 ivn.vn_aux = BYTE_GET (evn.vn_aux);
5023 ivn.vn_next = BYTE_GET (evn.vn_next);
5025 a_off = offset + ivn.vn_aux;
5029 get_data (&evna, file, a_off, sizeof (evna),
5030 _("version need aux (2)"));
5032 ivna.vna_next = BYTE_GET (evna.vna_next);
5033 ivna.vna_other = BYTE_GET (evna.vna_other);
5035 a_off += ivna.vna_next;
5037 while (ivna.vna_other != data [cnt + j]
5038 && ivna.vna_next != 0);
5040 if (ivna.vna_other == data [cnt + j])
5042 ivna.vna_name = BYTE_GET (evna.vna_name);
5044 name = strtab + ivna.vna_name;
5045 nn += printf ("(%s%-*s",
5047 12 - (int) strlen (name),
5053 offset += ivn.vn_next;
5055 while (ivn.vn_next);
5058 if (check_def && data [cnt + j] != 0x8001
5059 && version_info [DT_VERSIONTAGIDX (DT_VERDEF)])
5061 Elf_Internal_Verdef ivd;
5062 Elf_External_Verdef evd;
5063 unsigned long offset;
5065 offset = version_info
5066 [DT_VERSIONTAGIDX (DT_VERDEF)] - loadaddr;
5070 get_data (&evd, file, offset, sizeof (evd),
5073 ivd.vd_next = BYTE_GET (evd.vd_next);
5074 ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
5076 offset += ivd.vd_next;
5078 while (ivd.vd_ndx != (data [cnt + j] & 0x7fff)
5079 && ivd.vd_next != 0);
5081 if (ivd.vd_ndx == (data [cnt + j] & 0x7fff))
5083 Elf_External_Verdaux evda;
5084 Elf_Internal_Verdaux ivda;
5086 ivd.vd_aux = BYTE_GET (evd.vd_aux);
5088 get_data (&evda, file,
5089 offset - ivd.vd_next + ivd.vd_aux,
5090 sizeof (evda), _("version def aux"));
5092 ivda.vda_name = BYTE_GET (evda.vda_name);
5094 name = strtab + ivda.vda_name;
5095 nn += printf ("(%s%-*s",
5097 12 - (int) strlen (name),
5103 printf ("%*c", 18 - nn, ' ');
5121 printf (_("\nNo version information found in this file.\n"));
5127 get_symbol_binding (binding)
5128 unsigned int binding;
5130 static char buff [32];
5134 case STB_LOCAL: return "LOCAL";
5135 case STB_GLOBAL: return "GLOBAL";
5136 case STB_WEAK: return "WEAK";
5138 if (binding >= STB_LOPROC && binding <= STB_HIPROC)
5139 sprintf (buff, _("<processor specific>: %d"), binding);
5140 else if (binding >= STB_LOOS && binding <= STB_HIOS)
5141 sprintf (buff, _("<OS specific>: %d"), binding);
5143 sprintf (buff, _("<unknown>: %d"), binding);
5149 get_symbol_type (type)
5152 static char buff [32];
5156 case STT_NOTYPE: return "NOTYPE";
5157 case STT_OBJECT: return "OBJECT";
5158 case STT_FUNC: return "FUNC";
5159 case STT_SECTION: return "SECTION";
5160 case STT_FILE: return "FILE";
5161 case STT_COMMON: return "COMMON";
5163 if (type >= STT_LOPROC && type <= STT_HIPROC)
5165 if (elf_header.e_machine == EM_ARM && type == STT_ARM_TFUNC)
5166 return "THUMB_FUNC";
5168 if (elf_header.e_machine == EM_SPARCV9 && type == STT_REGISTER)
5171 if (elf_header.e_machine == EM_PARISC && type == STT_PARISC_MILLI)
5172 return "PARISC_MILLI";
5174 sprintf (buff, _("<processor specific>: %d"), type);
5176 else if (type >= STT_LOOS && type <= STT_HIOS)
5178 if (elf_header.e_machine == EM_PARISC)
5180 if (type == STT_HP_OPAQUE)
5182 if (type == STT_HP_STUB)
5186 sprintf (buff, _("<OS specific>: %d"), type);
5189 sprintf (buff, _("<unknown>: %d"), type);
5195 get_symbol_visibility (visibility)
5196 unsigned int visibility;
5200 case STV_DEFAULT: return "DEFAULT";
5201 case STV_INTERNAL: return "INTERNAL";
5202 case STV_HIDDEN: return "HIDDEN";
5203 case STV_PROTECTED: return "PROTECTED";
5209 get_symbol_index_type (type)
5214 case SHN_UNDEF: return "UND";
5215 case SHN_ABS: return "ABS";
5216 case SHN_COMMON: return "COM";
5218 if (type >= SHN_LOPROC && type <= SHN_HIPROC)
5220 else if (type >= SHN_LOOS && type <= SHN_HIOS)
5222 else if (type >= SHN_LORESERVE && type <= SHN_HIRESERVE)
5226 static char buff [32];
5228 sprintf (buff, "%3d", type);
5235 get_dynamic_data (file, number)
5237 unsigned int number;
5239 unsigned char * e_data;
5242 e_data = (unsigned char *) malloc (number * 4);
5246 error (_("Out of memory\n"));
5250 if (fread (e_data, 4, number, file) != number)
5252 error (_("Unable to read in dynamic data\n"));
5256 i_data = (int *) malloc (number * sizeof (* i_data));
5260 error (_("Out of memory\n"));
5266 i_data [number] = byte_get (e_data + number * 4, 4);
5273 /* Dump the symbol table. */
5275 process_symbol_table (file)
5278 Elf32_Internal_Shdr * section;
5279 unsigned char nb [4];
5280 unsigned char nc [4];
5283 int * buckets = NULL;
5284 int * chains = NULL;
5286 if (! do_syms && !do_histogram)
5289 if (dynamic_info[DT_HASH] && ((do_using_dynamic && dynamic_strings != NULL)
5292 if (fseek (file, dynamic_info[DT_HASH] - loadaddr, SEEK_SET))
5294 error (_("Unable to seek to start of dynamic information"));
5298 if (fread (nb, sizeof (nb), 1, file) != 1)
5300 error (_("Failed to read in number of buckets\n"));
5304 if (fread (nc, sizeof (nc), 1, file) != 1)
5306 error (_("Failed to read in number of chains\n"));
5310 nbuckets = byte_get (nb, 4);
5311 nchains = byte_get (nc, 4);
5313 buckets = get_dynamic_data (file, nbuckets);
5314 chains = get_dynamic_data (file, nchains);
5316 if (buckets == NULL || chains == NULL)
5321 && dynamic_info[DT_HASH] && do_using_dynamic && dynamic_strings != NULL)
5326 printf (_("\nSymbol table for image:\n"));
5328 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
5330 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
5332 for (hn = 0; hn < nbuckets; hn++)
5337 for (si = buckets [hn]; si < nchains && si > 0; si = chains [si])
5339 Elf_Internal_Sym * psym;
5341 psym = dynamic_symbols + si;
5343 printf (" %3d %3d: ", si, hn);
5344 print_vma (psym->st_value, LONG_HEX);
5346 print_vma (psym->st_size, DEC_5);
5348 printf (" %6s", get_symbol_type (ELF_ST_TYPE (psym->st_info)));
5349 printf (" %6s", get_symbol_binding (ELF_ST_BIND (psym->st_info)));
5350 printf (" %3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym->st_other)));
5351 printf (" %3.3s ", get_symbol_index_type (psym->st_shndx));
5352 print_symbol (25, dynamic_strings + psym->st_name);
5357 else if (do_syms && !do_using_dynamic)
5361 for (i = 0, section = section_headers;
5362 i < elf_header.e_shnum;
5367 Elf_Internal_Sym * symtab;
5368 Elf_Internal_Sym * psym;
5371 if ( section->sh_type != SHT_SYMTAB
5372 && section->sh_type != SHT_DYNSYM)
5375 printf (_("\nSymbol table '%s' contains %lu entries:\n"),
5376 SECTION_NAME (section),
5377 (unsigned long) (section->sh_size / section->sh_entsize));
5379 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
5381 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
5383 symtab = GET_ELF_SYMBOLS (file, section);
5387 if (section->sh_link == elf_header.e_shstrndx)
5388 strtab = string_table;
5391 Elf32_Internal_Shdr * string_sec;
5393 string_sec = SECTION_HEADER (section->sh_link);
5395 strtab = (char *) get_data (NULL, file, string_sec->sh_offset,
5396 string_sec->sh_size,
5400 for (si = 0, psym = symtab;
5401 si < section->sh_size / section->sh_entsize;
5404 printf ("%6d: ", si);
5405 print_vma (psym->st_value, LONG_HEX);
5407 print_vma (psym->st_size, DEC_5);
5408 printf (" %-7s", get_symbol_type (ELF_ST_TYPE (psym->st_info)));
5409 printf (" %-6s", get_symbol_binding (ELF_ST_BIND (psym->st_info)));
5410 printf (" %-3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym->st_other)));
5411 printf (" %4s ", get_symbol_index_type (psym->st_shndx));
5412 print_symbol (25, strtab + psym->st_name);
5414 if (section->sh_type == SHT_DYNSYM &&
5415 version_info [DT_VERSIONTAGIDX (DT_VERSYM)] != 0)
5417 unsigned char data[2];
5418 unsigned short vers_data;
5419 unsigned long offset;
5423 offset = version_info [DT_VERSIONTAGIDX (DT_VERSYM)]
5426 get_data (&data, file, offset + si * sizeof (vers_data),
5427 sizeof (data), _("version data"));
5429 vers_data = byte_get (data, 2);
5431 is_nobits = (SECTION_HEADER (psym->st_shndx)->sh_type
5434 check_def = (psym->st_shndx != SHN_UNDEF);
5436 if ((vers_data & 0x8000) || vers_data > 1)
5438 if (version_info [DT_VERSIONTAGIDX (DT_VERNEED)]
5439 && (is_nobits || ! check_def))
5441 Elf_External_Verneed evn;
5442 Elf_Internal_Verneed ivn;
5443 Elf_Internal_Vernaux ivna;
5445 /* We must test both. */
5446 offset = version_info
5447 [DT_VERSIONTAGIDX (DT_VERNEED)] - loadaddr;
5451 unsigned long vna_off;
5453 get_data (&evn, file, offset, sizeof (evn),
5456 ivn.vn_aux = BYTE_GET (evn.vn_aux);
5457 ivn.vn_next = BYTE_GET (evn.vn_next);
5459 vna_off = offset + ivn.vn_aux;
5463 Elf_External_Vernaux evna;
5465 get_data (&evna, file, vna_off,
5467 _("version need aux (3)"));
5469 ivna.vna_other = BYTE_GET (evna.vna_other);
5470 ivna.vna_next = BYTE_GET (evna.vna_next);
5471 ivna.vna_name = BYTE_GET (evna.vna_name);
5473 vna_off += ivna.vna_next;
5475 while (ivna.vna_other != vers_data
5476 && ivna.vna_next != 0);
5478 if (ivna.vna_other == vers_data)
5481 offset += ivn.vn_next;
5483 while (ivn.vn_next != 0);
5485 if (ivna.vna_other == vers_data)
5488 strtab + ivna.vna_name, ivna.vna_other);
5491 else if (! is_nobits)
5492 error (_("bad dynamic symbol"));
5499 if (vers_data != 0x8001
5500 && version_info [DT_VERSIONTAGIDX (DT_VERDEF)])
5502 Elf_Internal_Verdef ivd;
5503 Elf_Internal_Verdaux ivda;
5504 Elf_External_Verdaux evda;
5505 unsigned long offset;
5508 version_info [DT_VERSIONTAGIDX (DT_VERDEF)]
5513 Elf_External_Verdef evd;
5515 get_data (&evd, file, offset, sizeof (evd),
5518 ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
5519 ivd.vd_aux = BYTE_GET (evd.vd_aux);
5520 ivd.vd_next = BYTE_GET (evd.vd_next);
5522 offset += ivd.vd_next;
5524 while (ivd.vd_ndx != (vers_data & 0x7fff)
5525 && ivd.vd_next != 0);
5527 offset -= ivd.vd_next;
5528 offset += ivd.vd_aux;
5530 get_data (&evda, file, offset, sizeof (evda),
5531 _("version def aux"));
5533 ivda.vda_name = BYTE_GET (evda.vda_name);
5535 if (psym->st_name != ivda.vda_name)
5536 printf ((vers_data & 0x8000)
5538 strtab + ivda.vda_name);
5548 if (strtab != string_table)
5554 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
5556 if (do_histogram && buckets != NULL)
5563 int nzero_counts = 0;
5566 printf (_("\nHistogram for bucket list length (total of %d buckets):\n"),
5568 printf (_(" Length Number %% of total Coverage\n"));
5570 lengths = (int *) calloc (nbuckets, sizeof (int));
5571 if (lengths == NULL)
5573 error (_("Out of memory"));
5576 for (hn = 0; hn < nbuckets; ++hn)
5581 for (si = buckets[hn]; si > 0 && si < nchains; si = chains[si])
5584 if (maxlength < ++lengths[hn])
5589 counts = (int *) calloc (maxlength + 1, sizeof (int));
5592 error (_("Out of memory"));
5596 for (hn = 0; hn < nbuckets; ++hn)
5597 ++ counts [lengths [hn]];
5601 printf (" 0 %-10d (%5.1f%%)\n",
5602 counts[0], (counts[0] * 100.0) / nbuckets);
5603 for (si = 1; si <= maxlength; ++si)
5605 nzero_counts += counts[si] * si;
5606 printf ("%7d %-10d (%5.1f%%) %5.1f%%\n",
5607 si, counts[si], (counts[si] * 100.0) / nbuckets,
5608 (nzero_counts * 100.0) / nsyms);
5616 if (buckets != NULL)
5626 process_syminfo (file)
5627 FILE * file ATTRIBUTE_UNUSED;
5631 if (dynamic_syminfo == NULL
5633 /* No syminfo, this is ok. */
5636 /* There better should be a dynamic symbol section. */
5637 if (dynamic_symbols == NULL || dynamic_strings == NULL)
5641 printf (_("\nDynamic info segment at offset 0x%lx contains %d entries:\n"),
5642 dynamic_syminfo_offset, dynamic_syminfo_nent);
5644 printf (_(" Num: Name BoundTo Flags\n"));
5645 for (i = 0; i < dynamic_syminfo_nent; ++i)
5647 unsigned short int flags = dynamic_syminfo[i].si_flags;
5649 printf ("%4d: ", i);
5650 print_symbol (30, dynamic_strings + dynamic_symbols[i].st_name);
5653 switch (dynamic_syminfo[i].si_boundto)
5655 case SYMINFO_BT_SELF:
5656 fputs ("SELF ", stdout);
5658 case SYMINFO_BT_PARENT:
5659 fputs ("PARENT ", stdout);
5662 if (dynamic_syminfo[i].si_boundto > 0
5663 && dynamic_syminfo[i].si_boundto < dynamic_size)
5665 print_symbol (10, dynamic_strings
5667 [dynamic_syminfo[i].si_boundto].d_un.d_val);
5671 printf ("%-10d ", dynamic_syminfo[i].si_boundto);
5675 if (flags & SYMINFO_FLG_DIRECT)
5677 if (flags & SYMINFO_FLG_PASSTHRU)
5678 printf (" PASSTHRU");
5679 if (flags & SYMINFO_FLG_COPY)
5681 if (flags & SYMINFO_FLG_LAZYLOAD)
5682 printf (" LAZYLOAD");
5690 #ifdef SUPPORT_DISASSEMBLY
5692 disassemble_section (section, file)
5693 Elf32_Internal_Shdr * section;
5696 printf (_("\nAssembly dump of section %s\n"),
5697 SECTION_NAME (section));
5699 /* XXX -- to be done --- XXX */
5706 dump_section (section, file)
5707 Elf32_Internal_Shdr * section;
5710 bfd_size_type bytes;
5712 unsigned char * data;
5713 unsigned char * start;
5715 bytes = section->sh_size;
5719 printf (_("\nSection '%s' has no data to dump.\n"),
5720 SECTION_NAME (section));
5724 printf (_("\nHex dump of section '%s':\n"), SECTION_NAME (section));
5726 addr = section->sh_addr;
5728 start = (unsigned char *) get_data (NULL, file, section->sh_offset, bytes,
5741 lbytes = (bytes > 16 ? 16 : bytes);
5743 printf (" 0x%8.8lx ", (unsigned long) addr);
5745 switch (elf_header.e_ident [EI_DATA])
5749 for (j = 15; j >= 0; j --)
5752 printf ("%2.2x", data [j]);
5762 for (j = 0; j < 16; j++)
5765 printf ("%2.2x", data [j]);
5775 for (j = 0; j < lbytes; j++)
5778 if (k >= ' ' && k < 0x80)
5797 static unsigned long int
5798 read_leb128 (data, length_return, sign)
5799 unsigned char * data;
5800 int * length_return;
5803 unsigned long int result = 0;
5804 unsigned int num_read = 0;
5813 result |= (byte & 0x7f) << shift;
5818 while (byte & 0x80);
5820 if (length_return != NULL)
5821 * length_return = num_read;
5823 if (sign && (shift < 32) && (byte & 0x40))
5824 result |= -1 << shift;
5829 typedef struct State_Machine_Registers
5831 unsigned long address;
5834 unsigned int column;
5838 /* This variable hold the number of the last entry seen
5839 in the File Table. */
5840 unsigned int last_file_entry;
5843 static SMR state_machine_regs;
5846 reset_state_machine (is_stmt)
5849 state_machine_regs.address = 0;
5850 state_machine_regs.file = 1;
5851 state_machine_regs.line = 1;
5852 state_machine_regs.column = 0;
5853 state_machine_regs.is_stmt = is_stmt;
5854 state_machine_regs.basic_block = 0;
5855 state_machine_regs.end_sequence = 0;
5856 state_machine_regs.last_file_entry = 0;
5859 /* Handled an extend line op. Returns true if this is the end
5862 process_extended_line_op (data, is_stmt, pointer_size)
5863 unsigned char * data;
5867 unsigned char op_code;
5870 unsigned char * name;
5873 len = read_leb128 (data, & bytes_read, 0);
5878 warn (_("badly formed extended line op encountered!\n"));
5883 op_code = * data ++;
5885 printf (_(" Extended opcode %d: "), op_code);
5889 case DW_LNE_end_sequence:
5890 printf (_("End of Sequence\n\n"));
5891 reset_state_machine (is_stmt);
5894 case DW_LNE_set_address:
5895 adr = byte_get (data, pointer_size);
5896 printf (_("set Address to 0x%lx\n"), adr);
5897 state_machine_regs.address = adr;
5900 case DW_LNE_define_file:
5901 printf (_(" define new File Table entry\n"));
5902 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
5904 printf (_(" %d\t"), ++ state_machine_regs.last_file_entry);
5906 data += strlen ((char *) data) + 1;
5907 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
5909 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
5911 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
5912 printf (_("%s\n\n"), name);
5916 printf (_("UNKNOWN: length %d\n"), len - bytes_read);
5923 /* Size of pointers in the .debug_line section. This information is not
5924 really present in that section. It's obtained before dumping the debug
5925 sections by doing some pre-scan of the .debug_info section. */
5926 static int debug_line_pointer_size = 4;
5929 display_debug_lines (section, start, file)
5930 Elf32_Internal_Shdr * section;
5931 unsigned char * start;
5932 FILE * file ATTRIBUTE_UNUSED;
5934 DWARF2_External_LineInfo * external;
5935 DWARF2_Internal_LineInfo info;
5936 unsigned char * standard_opcodes;
5937 unsigned char * data = start;
5938 unsigned char * end = start + section->sh_size;
5939 unsigned char * end_of_sequence;
5942 printf (_("\nDump of debug contents of section %s:\n\n"),
5943 SECTION_NAME (section));
5947 external = (DWARF2_External_LineInfo *) data;
5949 /* Check the length of the block. */
5950 info.li_length = BYTE_GET (external->li_length);
5952 if (info.li_length == 0xffffffff)
5954 warn (_("64-bit DWARF line info is not supported yet.\n"));
5958 if (info.li_length + sizeof (external->li_length) > section->sh_size)
5961 (_("The line info appears to be corrupt - the section is too small\n"));
5965 /* Check its version number. */
5966 info.li_version = BYTE_GET (external->li_version);
5967 if (info.li_version != 2)
5969 warn (_("Only DWARF version 2 line info is currently supported.\n"));
5973 info.li_prologue_length = BYTE_GET (external->li_prologue_length);
5974 info.li_min_insn_length = BYTE_GET (external->li_min_insn_length);
5975 info.li_default_is_stmt = BYTE_GET (external->li_default_is_stmt);
5976 info.li_line_base = BYTE_GET (external->li_line_base);
5977 info.li_line_range = BYTE_GET (external->li_line_range);
5978 info.li_opcode_base = BYTE_GET (external->li_opcode_base);
5980 /* Sign extend the line base field. */
5981 info.li_line_base <<= 24;
5982 info.li_line_base >>= 24;
5984 printf (_(" Length: %ld\n"), info.li_length);
5985 printf (_(" DWARF Version: %d\n"), info.li_version);
5986 printf (_(" Prologue Length: %d\n"), info.li_prologue_length);
5987 printf (_(" Minimum Instruction Length: %d\n"), info.li_min_insn_length);
5988 printf (_(" Initial value of 'is_stmt': %d\n"), info.li_default_is_stmt);
5989 printf (_(" Line Base: %d\n"), info.li_line_base);
5990 printf (_(" Line Range: %d\n"), info.li_line_range);
5991 printf (_(" Opcode Base: %d\n"), info.li_opcode_base);
5993 end_of_sequence = data + info.li_length + sizeof (external->li_length);
5995 reset_state_machine (info.li_default_is_stmt);
5997 /* Display the contents of the Opcodes table. */
5998 standard_opcodes = data + sizeof (* external);
6000 printf (_("\n Opcodes:\n"));
6002 for (i = 1; i < info.li_opcode_base; i++)
6003 printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]);
6005 /* Display the contents of the Directory table. */
6006 data = standard_opcodes + info.li_opcode_base - 1;
6009 printf (_("\n The Directory Table is empty.\n"));
6012 printf (_("\n The Directory Table:\n"));
6016 printf (_(" %s\n"), data);
6018 data += strlen ((char *) data) + 1;
6022 /* Skip the NUL at the end of the table. */
6025 /* Display the contents of the File Name table. */
6027 printf (_("\n The File Name Table is empty.\n"));
6030 printf (_("\n The File Name Table:\n"));
6031 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
6035 unsigned char * name;
6038 printf (_(" %d\t"), ++ state_machine_regs.last_file_entry);
6041 data += strlen ((char *) data) + 1;
6043 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
6045 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
6047 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
6049 printf (_("%s\n"), name);
6053 /* Skip the NUL at the end of the table. */
6056 /* Now display the statements. */
6057 printf (_("\n Line Number Statements:\n"));
6060 while (data < end_of_sequence)
6062 unsigned char op_code;
6066 op_code = * data ++;
6068 if (op_code >= info.li_opcode_base)
6070 op_code -= info.li_opcode_base;
6071 adv = (op_code / info.li_line_range) * info.li_min_insn_length;
6072 state_machine_regs.address += adv;
6073 printf (_(" Special opcode %d: advance Address by %d to 0x%lx"),
6074 op_code, adv, state_machine_regs.address);
6075 adv = (op_code % info.li_line_range) + info.li_line_base;
6076 state_machine_regs.line += adv;
6077 printf (_(" and Line by %d to %d\n"),
6078 adv, state_machine_regs.line);
6080 else switch (op_code)
6082 case DW_LNS_extended_op:
6083 data += process_extended_line_op (data, info.li_default_is_stmt,
6084 debug_line_pointer_size);
6088 printf (_(" Copy\n"));
6091 case DW_LNS_advance_pc:
6092 adv = info.li_min_insn_length * read_leb128 (data, & bytes_read, 0);
6094 state_machine_regs.address += adv;
6095 printf (_(" Advance PC by %d to %lx\n"), adv,
6096 state_machine_regs.address);
6099 case DW_LNS_advance_line:
6100 adv = read_leb128 (data, & bytes_read, 1);
6102 state_machine_regs.line += adv;
6103 printf (_(" Advance Line by %d to %d\n"), adv,
6104 state_machine_regs.line);
6107 case DW_LNS_set_file:
6108 adv = read_leb128 (data, & bytes_read, 0);
6110 printf (_(" Set File Name to entry %d in the File Name Table\n"),
6112 state_machine_regs.file = adv;
6115 case DW_LNS_set_column:
6116 adv = read_leb128 (data, & bytes_read, 0);
6118 printf (_(" Set column to %d\n"), adv);
6119 state_machine_regs.column = adv;
6122 case DW_LNS_negate_stmt:
6123 adv = state_machine_regs.is_stmt;
6125 printf (_(" Set is_stmt to %d\n"), adv);
6126 state_machine_regs.is_stmt = adv;
6129 case DW_LNS_set_basic_block:
6130 printf (_(" Set basic block\n"));
6131 state_machine_regs.basic_block = 1;
6134 case DW_LNS_const_add_pc:
6135 adv = (((255 - info.li_opcode_base) / info.li_line_range)
6136 * info.li_min_insn_length);
6137 state_machine_regs.address += adv;
6138 printf (_(" Advance PC by constant %d to 0x%lx\n"), adv,
6139 state_machine_regs.address);
6142 case DW_LNS_fixed_advance_pc:
6143 adv = byte_get (data, 2);
6145 state_machine_regs.address += adv;
6146 printf (_(" Advance PC by fixed size amount %d to 0x%lx\n"),
6147 adv, state_machine_regs.address);
6150 case DW_LNS_set_prologue_end:
6151 printf (_(" Set prologue_end to true\n"));
6154 case DW_LNS_set_epilogue_begin:
6155 printf (_(" Set epilogue_begin to true\n"));
6158 case DW_LNS_set_isa:
6159 adv = read_leb128 (data, & bytes_read, 0);
6161 printf (_(" Set ISA to %d\n"), adv);
6165 printf (_(" Unknown opcode %d with operands: "), op_code);
6168 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
6170 printf ("0x%lx%s", read_leb128 (data, &bytes_read, 0),
6171 i == 1 ? "" : ", ");
6186 display_debug_pubnames (section, start, file)
6187 Elf32_Internal_Shdr * section;
6188 unsigned char * start;
6189 FILE * file ATTRIBUTE_UNUSED;
6191 DWARF2_External_PubNames * external;
6192 DWARF2_Internal_PubNames pubnames;
6193 unsigned char * end;
6195 end = start + section->sh_size;
6197 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section));
6201 unsigned char * data;
6202 unsigned long offset;
6204 external = (DWARF2_External_PubNames *) start;
6206 pubnames.pn_length = BYTE_GET (external->pn_length);
6207 pubnames.pn_version = BYTE_GET (external->pn_version);
6208 pubnames.pn_offset = BYTE_GET (external->pn_offset);
6209 pubnames.pn_size = BYTE_GET (external->pn_size);
6211 data = start + sizeof (* external);
6212 start += pubnames.pn_length + sizeof (external->pn_length);
6214 if (pubnames.pn_length == 0xffffffff)
6216 warn (_("64-bit DWARF pubnames are not supported yet.\n"));
6220 if (pubnames.pn_version != 2)
6222 static int warned = 0;
6226 warn (_("Only DWARF 2 pubnames are currently supported\n"));
6233 printf (_(" Length: %ld\n"),
6234 pubnames.pn_length);
6235 printf (_(" Version: %d\n"),
6236 pubnames.pn_version);
6237 printf (_(" Offset into .debug_info section: %ld\n"),
6238 pubnames.pn_offset);
6239 printf (_(" Size of area in .debug_info section: %ld\n"),
6242 printf (_("\n Offset\tName\n"));
6246 offset = byte_get (data, 4);
6251 printf (" %ld\t\t%s\n", offset, data);
6252 data += strlen ((char *) data) + 1;
6255 while (offset != 0);
6268 case DW_TAG_padding: return "DW_TAG_padding";
6269 case DW_TAG_array_type: return "DW_TAG_array_type";
6270 case DW_TAG_class_type: return "DW_TAG_class_type";
6271 case DW_TAG_entry_point: return "DW_TAG_entry_point";
6272 case DW_TAG_enumeration_type: return "DW_TAG_enumeration_type";
6273 case DW_TAG_formal_parameter: return "DW_TAG_formal_parameter";
6274 case DW_TAG_imported_declaration: return "DW_TAG_imported_declaration";
6275 case DW_TAG_label: return "DW_TAG_label";
6276 case DW_TAG_lexical_block: return "DW_TAG_lexical_block";
6277 case DW_TAG_member: return "DW_TAG_member";
6278 case DW_TAG_pointer_type: return "DW_TAG_pointer_type";
6279 case DW_TAG_reference_type: return "DW_TAG_reference_type";
6280 case DW_TAG_compile_unit: return "DW_TAG_compile_unit";
6281 case DW_TAG_string_type: return "DW_TAG_string_type";
6282 case DW_TAG_structure_type: return "DW_TAG_structure_type";
6283 case DW_TAG_subroutine_type: return "DW_TAG_subroutine_type";
6284 case DW_TAG_typedef: return "DW_TAG_typedef";
6285 case DW_TAG_union_type: return "DW_TAG_union_type";
6286 case DW_TAG_unspecified_parameters: return "DW_TAG_unspecified_parameters";
6287 case DW_TAG_variant: return "DW_TAG_variant";
6288 case DW_TAG_common_block: return "DW_TAG_common_block";
6289 case DW_TAG_common_inclusion: return "DW_TAG_common_inclusion";
6290 case DW_TAG_inheritance: return "DW_TAG_inheritance";
6291 case DW_TAG_inlined_subroutine: return "DW_TAG_inlined_subroutine";
6292 case DW_TAG_module: return "DW_TAG_module";
6293 case DW_TAG_ptr_to_member_type: return "DW_TAG_ptr_to_member_type";
6294 case DW_TAG_set_type: return "DW_TAG_set_type";
6295 case DW_TAG_subrange_type: return "DW_TAG_subrange_type";
6296 case DW_TAG_with_stmt: return "DW_TAG_with_stmt";
6297 case DW_TAG_access_declaration: return "DW_TAG_access_declaration";
6298 case DW_TAG_base_type: return "DW_TAG_base_type";
6299 case DW_TAG_catch_block: return "DW_TAG_catch_block";
6300 case DW_TAG_const_type: return "DW_TAG_const_type";
6301 case DW_TAG_constant: return "DW_TAG_constant";
6302 case DW_TAG_enumerator: return "DW_TAG_enumerator";
6303 case DW_TAG_file_type: return "DW_TAG_file_type";
6304 case DW_TAG_friend: return "DW_TAG_friend";
6305 case DW_TAG_namelist: return "DW_TAG_namelist";
6306 case DW_TAG_namelist_item: return "DW_TAG_namelist_item";
6307 case DW_TAG_packed_type: return "DW_TAG_packed_type";
6308 case DW_TAG_subprogram: return "DW_TAG_subprogram";
6309 case DW_TAG_template_type_param: return "DW_TAG_template_type_param";
6310 case DW_TAG_template_value_param: return "DW_TAG_template_value_param";
6311 case DW_TAG_thrown_type: return "DW_TAG_thrown_type";
6312 case DW_TAG_try_block: return "DW_TAG_try_block";
6313 case DW_TAG_variant_part: return "DW_TAG_variant_part";
6314 case DW_TAG_variable: return "DW_TAG_variable";
6315 case DW_TAG_volatile_type: return "DW_TAG_volatile_type";
6316 case DW_TAG_MIPS_loop: return "DW_TAG_MIPS_loop";
6317 case DW_TAG_format_label: return "DW_TAG_format_label";
6318 case DW_TAG_function_template: return "DW_TAG_function_template";
6319 case DW_TAG_class_template: return "DW_TAG_class_template";
6320 /* DWARF 2.1 values. */
6321 case DW_TAG_dwarf_procedure: return "DW_TAG_dwarf_procedure";
6322 case DW_TAG_restrict_type: return "DW_TAG_restrict_type";
6323 case DW_TAG_interface_type: return "DW_TAG_interface_type";
6324 case DW_TAG_namespace: return "DW_TAG_namespace";
6325 case DW_TAG_imported_module: return "DW_TAG_imported_module";
6326 case DW_TAG_unspecified_type: return "DW_TAG_unspecified_type";
6327 case DW_TAG_partial_unit: return "DW_TAG_partial_unit";
6328 case DW_TAG_imported_unit: return "DW_TAG_imported_unit";
6331 static char buffer [100];
6333 sprintf (buffer, _("Unknown TAG value: %lx"), tag);
6340 get_AT_name (attribute)
6341 unsigned long attribute;
6345 case DW_AT_sibling: return "DW_AT_sibling";
6346 case DW_AT_location: return "DW_AT_location";
6347 case DW_AT_name: return "DW_AT_name";
6348 case DW_AT_ordering: return "DW_AT_ordering";
6349 case DW_AT_subscr_data: return "DW_AT_subscr_data";
6350 case DW_AT_byte_size: return "DW_AT_byte_size";
6351 case DW_AT_bit_offset: return "DW_AT_bit_offset";
6352 case DW_AT_bit_size: return "DW_AT_bit_size";
6353 case DW_AT_element_list: return "DW_AT_element_list";
6354 case DW_AT_stmt_list: return "DW_AT_stmt_list";
6355 case DW_AT_low_pc: return "DW_AT_low_pc";
6356 case DW_AT_high_pc: return "DW_AT_high_pc";
6357 case DW_AT_language: return "DW_AT_language";
6358 case DW_AT_member: return "DW_AT_member";
6359 case DW_AT_discr: return "DW_AT_discr";
6360 case DW_AT_discr_value: return "DW_AT_discr_value";
6361 case DW_AT_visibility: return "DW_AT_visibility";
6362 case DW_AT_import: return "DW_AT_import";
6363 case DW_AT_string_length: return "DW_AT_string_length";
6364 case DW_AT_common_reference: return "DW_AT_common_reference";
6365 case DW_AT_comp_dir: return "DW_AT_comp_dir";
6366 case DW_AT_const_value: return "DW_AT_const_value";
6367 case DW_AT_containing_type: return "DW_AT_containing_type";
6368 case DW_AT_default_value: return "DW_AT_default_value";
6369 case DW_AT_inline: return "DW_AT_inline";
6370 case DW_AT_is_optional: return "DW_AT_is_optional";
6371 case DW_AT_lower_bound: return "DW_AT_lower_bound";
6372 case DW_AT_producer: return "DW_AT_producer";
6373 case DW_AT_prototyped: return "DW_AT_prototyped";
6374 case DW_AT_return_addr: return "DW_AT_return_addr";
6375 case DW_AT_start_scope: return "DW_AT_start_scope";
6376 case DW_AT_stride_size: return "DW_AT_stride_size";
6377 case DW_AT_upper_bound: return "DW_AT_upper_bound";
6378 case DW_AT_abstract_origin: return "DW_AT_abstract_origin";
6379 case DW_AT_accessibility: return "DW_AT_accessibility";
6380 case DW_AT_address_class: return "DW_AT_address_class";
6381 case DW_AT_artificial: return "DW_AT_artificial";
6382 case DW_AT_base_types: return "DW_AT_base_types";
6383 case DW_AT_calling_convention: return "DW_AT_calling_convention";
6384 case DW_AT_count: return "DW_AT_count";
6385 case DW_AT_data_member_location: return "DW_AT_data_member_location";
6386 case DW_AT_decl_column: return "DW_AT_decl_column";
6387 case DW_AT_decl_file: return "DW_AT_decl_file";
6388 case DW_AT_decl_line: return "DW_AT_decl_line";
6389 case DW_AT_declaration: return "DW_AT_declaration";
6390 case DW_AT_discr_list: return "DW_AT_discr_list";
6391 case DW_AT_encoding: return "DW_AT_encoding";
6392 case DW_AT_external: return "DW_AT_external";
6393 case DW_AT_frame_base: return "DW_AT_frame_base";
6394 case DW_AT_friend: return "DW_AT_friend";
6395 case DW_AT_identifier_case: return "DW_AT_identifier_case";
6396 case DW_AT_macro_info: return "DW_AT_macro_info";
6397 case DW_AT_namelist_items: return "DW_AT_namelist_items";
6398 case DW_AT_priority: return "DW_AT_priority";
6399 case DW_AT_segment: return "DW_AT_segment";
6400 case DW_AT_specification: return "DW_AT_specification";
6401 case DW_AT_static_link: return "DW_AT_static_link";
6402 case DW_AT_type: return "DW_AT_type";
6403 case DW_AT_use_location: return "DW_AT_use_location";
6404 case DW_AT_variable_parameter: return "DW_AT_variable_parameter";
6405 case DW_AT_virtuality: return "DW_AT_virtuality";
6406 case DW_AT_vtable_elem_location: return "DW_AT_vtable_elem_location";
6407 /* DWARF 2.1 values. */
6408 case DW_AT_allocated: return "DW_AT_allocated";
6409 case DW_AT_associated: return "DW_AT_associated";
6410 case DW_AT_data_location: return "DW_AT_data_location";
6411 case DW_AT_stride: return "DW_AT_stride";
6412 case DW_AT_entry_pc: return "DW_AT_entry_pc";
6413 case DW_AT_use_UTF8: return "DW_AT_use_UTF8";
6414 case DW_AT_extension: return "DW_AT_extension";
6415 case DW_AT_ranges: return "DW_AT_ranges";
6416 case DW_AT_trampoline: return "DW_AT_trampoline";
6417 case DW_AT_call_column: return "DW_AT_call_column";
6418 case DW_AT_call_file: return "DW_AT_call_file";
6419 case DW_AT_call_line: return "DW_AT_call_line";
6420 /* SGI/MIPS extensions. */
6421 case DW_AT_MIPS_fde: return "DW_AT_MIPS_fde";
6422 case DW_AT_MIPS_loop_begin: return "DW_AT_MIPS_loop_begin";
6423 case DW_AT_MIPS_tail_loop_begin: return "DW_AT_MIPS_tail_loop_begin";
6424 case DW_AT_MIPS_epilog_begin: return "DW_AT_MIPS_epilog_begin";
6425 case DW_AT_MIPS_loop_unroll_factor: return "DW_AT_MIPS_loop_unroll_factor";
6426 case DW_AT_MIPS_software_pipeline_depth: return "DW_AT_MIPS_software_pipeline_depth";
6427 case DW_AT_MIPS_linkage_name: return "DW_AT_MIPS_linkage_name";
6428 case DW_AT_MIPS_stride: return "DW_AT_MIPS_stride";
6429 case DW_AT_MIPS_abstract_name: return "DW_AT_MIPS_abstract_name";
6430 case DW_AT_MIPS_clone_origin: return "DW_AT_MIPS_clone_origin";
6431 case DW_AT_MIPS_has_inlines: return "DW_AT_MIPS_has_inlines";
6432 /* GNU extensions. */
6433 case DW_AT_sf_names: return "DW_AT_sf_names";
6434 case DW_AT_src_info: return "DW_AT_src_info";
6435 case DW_AT_mac_info: return "DW_AT_mac_info";
6436 case DW_AT_src_coords: return "DW_AT_src_coords";
6437 case DW_AT_body_begin: return "DW_AT_body_begin";
6438 case DW_AT_body_end: return "DW_AT_body_end";
6441 static char buffer [100];
6443 sprintf (buffer, _("Unknown AT value: %lx"), attribute);
6450 get_FORM_name (form)
6455 case DW_FORM_addr: return "DW_FORM_addr";
6456 case DW_FORM_block2: return "DW_FORM_block2";
6457 case DW_FORM_block4: return "DW_FORM_block4";
6458 case DW_FORM_data2: return "DW_FORM_data2";
6459 case DW_FORM_data4: return "DW_FORM_data4";
6460 case DW_FORM_data8: return "DW_FORM_data8";
6461 case DW_FORM_string: return "DW_FORM_string";
6462 case DW_FORM_block: return "DW_FORM_block";
6463 case DW_FORM_block1: return "DW_FORM_block1";
6464 case DW_FORM_data1: return "DW_FORM_data1";
6465 case DW_FORM_flag: return "DW_FORM_flag";
6466 case DW_FORM_sdata: return "DW_FORM_sdata";
6467 case DW_FORM_strp: return "DW_FORM_strp";
6468 case DW_FORM_udata: return "DW_FORM_udata";
6469 case DW_FORM_ref_addr: return "DW_FORM_ref_addr";
6470 case DW_FORM_ref1: return "DW_FORM_ref1";
6471 case DW_FORM_ref2: return "DW_FORM_ref2";
6472 case DW_FORM_ref4: return "DW_FORM_ref4";
6473 case DW_FORM_ref8: return "DW_FORM_ref8";
6474 case DW_FORM_ref_udata: return "DW_FORM_ref_udata";
6475 case DW_FORM_indirect: return "DW_FORM_indirect";
6478 static char buffer [100];
6480 sprintf (buffer, _("Unknown FORM value: %lx"), form);
6486 /* FIXME: There are better and more effiecint ways to handle
6487 these structures. For now though, I just want something that
6488 is simple to implement. */
6489 typedef struct abbrev_attr
6491 unsigned long attribute;
6493 struct abbrev_attr * next;
6497 typedef struct abbrev_entry
6499 unsigned long entry;
6502 struct abbrev_attr * first_attr;
6503 struct abbrev_attr * last_attr;
6504 struct abbrev_entry * next;
6508 static abbrev_entry * first_abbrev = NULL;
6509 static abbrev_entry * last_abbrev = NULL;
6512 free_abbrevs PARAMS ((void))
6514 abbrev_entry * abbrev;
6516 for (abbrev = first_abbrev; abbrev;)
6518 abbrev_entry * next = abbrev->next;
6521 for (attr = abbrev->first_attr; attr;)
6523 abbrev_attr * next = attr->next;
6533 last_abbrev = first_abbrev = NULL;
6537 add_abbrev (number, tag, children)
6538 unsigned long number;
6542 abbrev_entry * entry;
6544 entry = (abbrev_entry *) malloc (sizeof (* entry));
6550 entry->entry = number;
6552 entry->children = children;
6553 entry->first_attr = NULL;
6554 entry->last_attr = NULL;
6557 if (first_abbrev == NULL)
6558 first_abbrev = entry;
6560 last_abbrev->next = entry;
6562 last_abbrev = entry;
6566 add_abbrev_attr (attribute, form)
6567 unsigned long attribute;
6572 attr = (abbrev_attr *) malloc (sizeof (* attr));
6578 attr->attribute = attribute;
6582 if (last_abbrev->first_attr == NULL)
6583 last_abbrev->first_attr = attr;
6585 last_abbrev->last_attr->next = attr;
6587 last_abbrev->last_attr = attr;
6590 /* Processes the (partial) contents of a .debug_abbrev section.
6591 Returns NULL if the end of the section was encountered.
6592 Returns the address after the last byte read if the end of
6593 an abbreviation set was found. */
6595 static unsigned char *
6596 process_abbrev_section (start, end)
6597 unsigned char * start;
6598 unsigned char * end;
6600 if (first_abbrev != NULL)
6606 unsigned long entry;
6608 unsigned long attribute;
6611 entry = read_leb128 (start, & bytes_read, 0);
6612 start += bytes_read;
6614 /* A single zero is supposed to end the section according
6615 to the standard. If there's more, then signal that to
6618 return start == end ? NULL : start;
6620 tag = read_leb128 (start, & bytes_read, 0);
6621 start += bytes_read;
6623 children = * start ++;
6625 add_abbrev (entry, tag, children);
6631 attribute = read_leb128 (start, & bytes_read, 0);
6632 start += bytes_read;
6634 form = read_leb128 (start, & bytes_read, 0);
6635 start += bytes_read;
6638 add_abbrev_attr (attribute, form);
6640 while (attribute != 0);
6648 display_debug_macinfo (section, start, file)
6649 Elf32_Internal_Shdr * section;
6650 unsigned char * start;
6651 FILE * file ATTRIBUTE_UNUSED;
6653 unsigned char * end = start + section->sh_size;
6654 unsigned char * curr = start;
6655 unsigned int bytes_read;
6656 enum dwarf_macinfo_record_type op;
6658 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section));
6662 unsigned int lineno;
6663 const char * string;
6670 case DW_MACINFO_start_file:
6672 unsigned int filenum;
6674 lineno = read_leb128 (curr, & bytes_read, 0);
6676 filenum = read_leb128 (curr, & bytes_read, 0);
6679 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"), lineno, filenum);
6683 case DW_MACINFO_end_file:
6684 printf (_(" DW_MACINFO_end_file\n"));
6687 case DW_MACINFO_define:
6688 lineno = read_leb128 (curr, & bytes_read, 0);
6691 curr += strlen (string) + 1;
6692 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"), lineno, string);
6695 case DW_MACINFO_undef:
6696 lineno = read_leb128 (curr, & bytes_read, 0);
6699 curr += strlen (string) + 1;
6700 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"), lineno, string);
6703 case DW_MACINFO_vendor_ext:
6705 unsigned int constant;
6707 constant = read_leb128 (curr, & bytes_read, 0);
6710 curr += strlen (string) + 1;
6711 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"), constant, string);
6722 display_debug_abbrev (section, start, file)
6723 Elf32_Internal_Shdr * section;
6724 unsigned char * start;
6725 FILE * file ATTRIBUTE_UNUSED;
6727 abbrev_entry * entry;
6728 unsigned char * end = start + section->sh_size;
6730 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section));
6734 start = process_abbrev_section (start, end);
6736 if (first_abbrev == NULL)
6739 printf (_(" Number TAG\n"));
6741 for (entry = first_abbrev; entry; entry = entry->next)
6745 printf (_(" %ld %s [%s]\n"),
6747 get_TAG_name (entry->tag),
6748 entry->children ? _("has children") : _("no children"));
6750 for (attr = entry->first_attr; attr; attr = attr->next)
6752 printf (_(" %-18s %s\n"),
6753 get_AT_name (attr->attribute),
6754 get_FORM_name (attr->form));
6768 static unsigned char *
6769 display_block (data, length)
6770 unsigned char * data;
6771 unsigned long length;
6773 printf (_(" %lu byte block: "), length);
6776 printf ("%lx ", (unsigned long) byte_get (data ++, 1));
6782 decode_location_expression (data, pointer_size, length)
6783 unsigned char * data;
6784 unsigned int pointer_size;
6785 unsigned long length;
6789 unsigned long uvalue;
6790 unsigned char * end = data + length;
6799 printf ("DW_OP_addr: %lx",
6800 (unsigned long) byte_get (data, pointer_size));
6801 data += pointer_size;
6804 printf ("DW_OP_deref");
6807 printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data++, 1));
6810 printf ("DW_OP_const1s: %ld", (long) byte_get (data++, 1));
6813 printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data, 2));
6817 printf ("DW_OP_const2s: %ld", (long) byte_get (data, 2));
6821 printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data, 4));
6825 printf ("DW_OP_const4s: %ld", (long) byte_get (data, 4));
6829 printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data, 4),
6830 (unsigned long) byte_get (data + 4, 4));
6834 printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data, 4),
6835 (long) byte_get (data + 4, 4));
6839 printf ("DW_OP_constu: %lu", read_leb128 (data, &bytes_read, 0));
6843 printf ("DW_OP_consts: %ld", read_leb128 (data, &bytes_read, 1));
6847 printf ("DW_OP_dup");
6850 printf ("DW_OP_drop");
6853 printf ("DW_OP_over");
6856 printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data++, 1));
6859 printf ("DW_OP_swap");
6862 printf ("DW_OP_rot");
6865 printf ("DW_OP_xderef");
6868 printf ("DW_OP_abs");
6871 printf ("DW_OP_and");
6874 printf ("DW_OP_div");
6877 printf ("DW_OP_minus");
6880 printf ("DW_OP_mod");
6883 printf ("DW_OP_mul");
6886 printf ("DW_OP_neg");
6889 printf ("DW_OP_not");
6892 printf ("DW_OP_or");
6895 printf ("DW_OP_plus");
6897 case DW_OP_plus_uconst:
6898 printf ("DW_OP_plus_uconst: %lu",
6899 read_leb128 (data, &bytes_read, 0));
6903 printf ("DW_OP_shl");
6906 printf ("DW_OP_shr");
6909 printf ("DW_OP_shra");
6912 printf ("DW_OP_xor");
6915 printf ("DW_OP_bra: %ld", (long) byte_get (data, 2));
6919 printf ("DW_OP_eq");
6922 printf ("DW_OP_ge");
6925 printf ("DW_OP_gt");
6928 printf ("DW_OP_le");
6931 printf ("DW_OP_lt");
6934 printf ("DW_OP_ne");
6937 printf ("DW_OP_skip: %ld", (long) byte_get (data, 2));
6973 printf ("DW_OP_lit%d", op - DW_OP_lit0);
7008 printf ("DW_OP_reg%d", op - DW_OP_reg0);
7043 printf ("DW_OP_breg%d: %ld", op - DW_OP_breg0,
7044 read_leb128 (data, &bytes_read, 1));
7049 printf ("DW_OP_regx: %lu", read_leb128 (data, &bytes_read, 0));
7053 printf ("DW_OP_fbreg: %ld", read_leb128 (data, &bytes_read, 1));
7057 uvalue = read_leb128 (data, &bytes_read, 0);
7059 printf ("DW_OP_bregx: %lu %ld", uvalue,
7060 read_leb128 (data, &bytes_read, 1));
7064 printf ("DW_OP_piece: %lu", read_leb128 (data, &bytes_read, 0));
7067 case DW_OP_deref_size:
7068 printf ("DW_OP_deref_size: %ld", (long) byte_get (data++, 1));
7070 case DW_OP_xderef_size:
7071 printf ("DW_OP_xderef_size: %ld", (long) byte_get (data++, 1));
7074 printf ("DW_OP_nop");
7077 /* DWARF 2.1 extensions. */
7078 case DW_OP_push_object_address:
7079 printf ("DW_OP_push_object_address");
7082 printf ("DW_OP_call2: <%lx>", (long) byte_get (data, 2));
7086 printf ("DW_OP_call4: <%lx>", (long) byte_get (data, 4));
7090 printf ("DW_OP_calli");
7094 if (op >= DW_OP_lo_user
7095 && op <= DW_OP_hi_user)
7096 printf (_("(User defined location op)"));
7098 printf (_("(Unknown location op)"));
7099 /* No way to tell where the next op is, so just bail. */
7103 /* Separate the ops. */
7109 static const char * debug_str_contents;
7110 static bfd_vma debug_str_size;
7113 load_debug_str (file)
7116 Elf32_Internal_Shdr * sec;
7119 /* If it is already loaded, do nothing. */
7120 if (debug_str_contents != NULL)
7123 /* Locate the .debug_str section. */
7124 for (i = 0, sec = section_headers;
7125 i < elf_header.e_shnum;
7127 if (strcmp (SECTION_NAME (sec), ".debug_str") == 0)
7130 if (i == elf_header.e_shnum || sec->sh_size == 0)
7133 debug_str_size = sec->sh_size;
7135 debug_str_contents = ((char *)
7136 get_data (NULL, file, sec->sh_offset, sec->sh_size,
7137 _("debug_str section data")));
7143 if (debug_str_contents == NULL)
7146 free ((char *) debug_str_contents);
7147 debug_str_contents = NULL;
7152 fetch_indirect_string (offset)
7153 unsigned long offset;
7155 if (debug_str_contents == NULL)
7156 return _("<no .debug_str section>");
7158 if (offset > debug_str_size)
7159 return _("<offset is too big>");
7161 return debug_str_contents + offset;
7166 display_debug_str (section, start, file)
7167 Elf32_Internal_Shdr * section;
7168 unsigned char * start;
7169 FILE * file ATTRIBUTE_UNUSED;
7171 unsigned long bytes;
7174 addr = section->sh_addr;
7175 bytes = section->sh_size;
7179 printf (_("\nThe .debug_str section is empty.\n"));
7183 printf (_("Contents of the .debug_str section:\n\n"));
7191 lbytes = (bytes > 16 ? 16 : bytes);
7193 printf (" 0x%8.8lx ", (unsigned long) addr);
7195 for (j = 0; j < 16; j++)
7198 printf ("%2.2x", start [j]);
7206 for (j = 0; j < lbytes; j++)
7209 if (k >= ' ' && k < 0x80)
7226 static unsigned char *
7227 read_and_display_attr_value (attribute, form, data, cu_offset, pointer_size)
7228 unsigned long attribute;
7230 unsigned char * data;
7231 unsigned long cu_offset;
7232 unsigned long pointer_size;
7234 unsigned long uvalue = 0;
7235 unsigned char * block_start = NULL;
7243 case DW_FORM_ref_addr:
7245 uvalue = byte_get (data, pointer_size);
7246 data += pointer_size;
7250 uvalue = byte_get (data, /* offset_size */ 4);
7251 data += /* offset_size */ 4;
7257 uvalue = byte_get (data ++, 1);
7262 uvalue = byte_get (data, 2);
7268 uvalue = byte_get (data, 4);
7273 uvalue = read_leb128 (data, & bytes_read, 1);
7277 case DW_FORM_ref_udata:
7279 uvalue = read_leb128 (data, & bytes_read, 0);
7283 case DW_FORM_indirect:
7284 form = read_leb128 (data, & bytes_read, 0);
7286 printf (" %s", get_FORM_name (form));
7287 return read_and_display_attr_value (attribute, form, data, cu_offset,
7293 case DW_FORM_ref_addr:
7294 printf (" <#%lx>", uvalue);
7300 case DW_FORM_ref_udata:
7301 printf (" <%lx>", uvalue + cu_offset);
7305 printf (" %#lx", uvalue);
7313 printf (" %ld", uvalue);
7318 uvalue = byte_get (data, 4);
7319 printf (" %lx", uvalue);
7320 printf (" %lx", (unsigned long) byte_get (data + 4, 4));
7324 case DW_FORM_string:
7325 printf (" %s", data);
7326 data += strlen ((char *) data) + 1;
7330 uvalue = read_leb128 (data, & bytes_read, 0);
7331 block_start = data + bytes_read;
7332 data = display_block (block_start, uvalue);
7335 case DW_FORM_block1:
7336 uvalue = byte_get (data, 1);
7337 block_start = data + 1;
7338 data = display_block (block_start, uvalue);
7341 case DW_FORM_block2:
7342 uvalue = byte_get (data, 2);
7343 block_start = data + 2;
7344 data = display_block (block_start, uvalue);
7347 case DW_FORM_block4:
7348 uvalue = byte_get (data, 4);
7349 block_start = data + 4;
7350 data = display_block (block_start, uvalue);
7354 printf (_(" (indirect string, offset: 0x%lx): "), uvalue);
7355 printf (fetch_indirect_string (uvalue));
7358 case DW_FORM_indirect:
7359 /* Handled above. */
7363 warn (_("Unrecognised form: %d\n"), form);
7367 /* For some attributes we can display futher information. */
7376 case DW_INL_not_inlined: printf (_("(not inlined)")); break;
7377 case DW_INL_inlined: printf (_("(inlined)")); break;
7378 case DW_INL_declared_not_inlined: printf (_("(declared as inline but ignored)")); break;
7379 case DW_INL_declared_inlined: printf (_("(declared as inline and inlined)")); break;
7380 default: printf (_(" (Unknown inline attribute value: %lx)"), uvalue); break;
7384 case DW_AT_language:
7387 case DW_LANG_C: printf ("(non-ANSI C)"); break;
7388 case DW_LANG_C89: printf ("(ANSI C)"); break;
7389 case DW_LANG_C_plus_plus: printf ("(C++)"); break;
7390 case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break;
7391 case DW_LANG_Fortran90: printf ("(Fortran 90)"); break;
7392 case DW_LANG_Modula2: printf ("(Modula 2)"); break;
7393 case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break;
7394 case DW_LANG_Ada83: printf ("(Ada)"); break;
7395 case DW_LANG_Cobol74: printf ("(Cobol 74)"); break;
7396 case DW_LANG_Cobol85: printf ("(Cobol 85)"); break;
7397 /* DWARF 2.1 values. */
7398 case DW_LANG_C99: printf ("(ANSI C99)"); break;
7399 case DW_LANG_Ada95: printf ("(ADA 95)"); break;
7400 case DW_LANG_Fortran95: printf ("(Fortran 95)"); break;
7401 /* MIPS extension. */
7402 case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break;
7403 default: printf ("(Unknown: %lx)", uvalue); break;
7407 case DW_AT_encoding:
7410 case DW_ATE_void: printf ("(void)"); break;
7411 case DW_ATE_address: printf ("(machine address)"); break;
7412 case DW_ATE_boolean: printf ("(boolean)"); break;
7413 case DW_ATE_complex_float: printf ("(complex float)"); break;
7414 case DW_ATE_float: printf ("(float)"); break;
7415 case DW_ATE_signed: printf ("(signed)"); break;
7416 case DW_ATE_signed_char: printf ("(signed char)"); break;
7417 case DW_ATE_unsigned: printf ("(unsigned)"); break;
7418 case DW_ATE_unsigned_char: printf ("(unsigned char)"); break;
7419 /* DWARF 2.1 value. */
7420 case DW_ATE_imaginary_float: printf ("(imaginary float)"); break;
7422 if (uvalue >= DW_ATE_lo_user
7423 && uvalue <= DW_ATE_hi_user)
7424 printf ("(user defined type)");
7426 printf ("(unknown type)");
7431 case DW_AT_accessibility:
7434 case DW_ACCESS_public: printf ("(public)"); break;
7435 case DW_ACCESS_protected: printf ("(protected)"); break;
7436 case DW_ACCESS_private: printf ("(private)"); break;
7437 default: printf ("(unknown accessibility)"); break;
7441 case DW_AT_visibility:
7444 case DW_VIS_local: printf ("(local)"); break;
7445 case DW_VIS_exported: printf ("(exported)"); break;
7446 case DW_VIS_qualified: printf ("(qualified)"); break;
7447 default: printf ("(unknown visibility)"); break;
7451 case DW_AT_virtuality:
7454 case DW_VIRTUALITY_none: printf ("(none)"); break;
7455 case DW_VIRTUALITY_virtual: printf ("(virtual)"); break;
7456 case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break;
7457 default: printf ("(unknown virtuality)"); break;
7461 case DW_AT_identifier_case:
7464 case DW_ID_case_sensitive: printf ("(case_sensitive)"); break;
7465 case DW_ID_up_case: printf ("(up_case)"); break;
7466 case DW_ID_down_case: printf ("(down_case)"); break;
7467 case DW_ID_case_insensitive: printf ("(case_insensitive)"); break;
7468 default: printf ("(unknown case)"); break;
7472 case DW_AT_calling_convention:
7475 case DW_CC_normal: printf ("(normal)"); break;
7476 case DW_CC_program: printf ("(program)"); break;
7477 case DW_CC_nocall: printf ("(nocall)"); break;
7479 if (uvalue >= DW_CC_lo_user
7480 && uvalue <= DW_CC_hi_user)
7481 printf ("(user defined)");
7483 printf ("(unknown convention)");
7487 case DW_AT_ordering:
7490 case -1: printf ("(undefined)"); break;
7491 case 0: printf ("(row major)"); break;
7492 case 1: printf ("(column major)"); break;
7496 case DW_AT_frame_base:
7497 case DW_AT_location:
7498 case DW_AT_data_member_location:
7499 case DW_AT_vtable_elem_location:
7500 case DW_AT_allocated:
7501 case DW_AT_associated:
7502 case DW_AT_data_location:
7504 case DW_AT_upper_bound:
7505 case DW_AT_lower_bound:
7509 decode_location_expression (block_start, pointer_size, uvalue);
7521 static unsigned char *
7522 read_and_display_attr (attribute, form, data, cu_offset, pointer_size)
7523 unsigned long attribute;
7525 unsigned char * data;
7526 unsigned long cu_offset;
7527 unsigned long pointer_size;
7529 printf (" %-18s:", get_AT_name (attribute));
7530 data = read_and_display_attr_value (attribute, form, data, cu_offset,
7537 display_debug_info (section, start, file)
7538 Elf32_Internal_Shdr * section;
7539 unsigned char * start;
7542 unsigned char * end = start + section->sh_size;
7543 unsigned char * section_begin = start;
7545 printf (_("The section %s contains:\n\n"), SECTION_NAME (section));
7547 load_debug_str (file);
7551 DWARF2_External_CompUnit * external;
7552 DWARF2_Internal_CompUnit compunit;
7553 Elf32_Internal_Shdr * relsec;
7554 unsigned char * tags;
7557 unsigned long cu_offset;
7559 external = (DWARF2_External_CompUnit *) start;
7561 compunit.cu_length = BYTE_GET (external->cu_length);
7562 compunit.cu_version = BYTE_GET (external->cu_version);
7563 compunit.cu_abbrev_offset = BYTE_GET (external->cu_abbrev_offset);
7564 compunit.cu_pointer_size = BYTE_GET (external->cu_pointer_size);
7566 if (compunit.cu_length == 0xffffffff)
7568 warn (_("64-bit DWARF debug info is not supported yet.\n"));
7572 /* Check for RELA relocations in the abbrev_offset address, and
7574 for (relsec = section_headers;
7575 relsec < section_headers + elf_header.e_shnum;
7578 unsigned long nrelas;
7579 Elf_Internal_Rela *rela, *rp;
7580 Elf32_Internal_Shdr *symsec;
7581 Elf_Internal_Sym *symtab;
7582 Elf_Internal_Sym *sym;
7584 if (relsec->sh_type != SHT_RELA
7585 || SECTION_HEADER (relsec->sh_info) != section)
7588 if (!slurp_rela_relocs (file, relsec->sh_offset, relsec->sh_size,
7592 symsec = SECTION_HEADER (relsec->sh_link);
7593 symtab = GET_ELF_SYMBOLS (file, symsec);
7595 for (rp = rela; rp < rela + nrelas; ++rp)
7598 != (bfd_vma) ((unsigned char *) &external->cu_abbrev_offset
7604 sym = symtab + ELF32_R_SYM (rp->r_info);
7606 if (ELF32_ST_TYPE (sym->st_info) != STT_SECTION)
7608 warn (_("Skipping unexpected symbol type %u\n"),
7609 ELF32_ST_TYPE (sym->st_info));
7615 sym = symtab + ELF64_R_SYM (rp->r_info);
7617 if (ELF64_ST_TYPE (sym->st_info) != STT_SECTION)
7619 warn (_("Skipping unexpected symbol type %u\n"),
7620 ELF64_ST_TYPE (sym->st_info));
7625 compunit.cu_abbrev_offset += rp->r_addend;
7633 tags = start + sizeof (* external);
7634 cu_offset = start - section_begin;
7635 start += compunit.cu_length + sizeof (external->cu_length);
7637 printf (_(" Compilation Unit @ %lx:\n"), cu_offset);
7638 printf (_(" Length: %ld\n"), compunit.cu_length);
7639 printf (_(" Version: %d\n"), compunit.cu_version);
7640 printf (_(" Abbrev Offset: %ld\n"), compunit.cu_abbrev_offset);
7641 printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size);
7643 if (compunit.cu_version != 2)
7645 warn (_("Only version 2 DWARF debug information is currently supported.\n"));
7651 /* Read in the abbrevs used by this compilation unit. */
7654 Elf32_Internal_Shdr * sec;
7655 unsigned char * begin;
7657 /* Locate the .debug_abbrev section and process it. */
7658 for (i = 0, sec = section_headers;
7659 i < elf_header.e_shnum;
7661 if (strcmp (SECTION_NAME (sec), ".debug_abbrev") == 0)
7664 if (i == elf_header.e_shnum || sec->sh_size == 0)
7666 warn (_("Unable to locate .debug_abbrev section!\n"));
7670 begin = ((unsigned char *)
7671 get_data (NULL, file, sec->sh_offset, sec->sh_size,
7672 _("debug_abbrev section data")));
7676 process_abbrev_section (begin + compunit.cu_abbrev_offset,
7677 begin + sec->sh_size);
7683 while (tags < start)
7686 unsigned long abbrev_number;
7687 abbrev_entry * entry;
7690 abbrev_number = read_leb128 (tags, & bytes_read, 0);
7693 /* A null DIE marks the end of a list of children. */
7694 if (abbrev_number == 0)
7700 /* Scan through the abbreviation list until we reach the
7702 for (entry = first_abbrev;
7703 entry && entry->entry != abbrev_number;
7704 entry = entry->next)
7709 warn (_("Unable to locate entry %lu in the abbreviation table\n"),
7714 printf (_(" <%d><%lx>: Abbrev Number: %lu (%s)\n"),
7716 (unsigned long) (tags - section_begin - bytes_read),
7718 get_TAG_name (entry->tag));
7720 for (attr = entry->first_attr; attr; attr = attr->next)
7721 tags = read_and_display_attr (attr->attribute,
7724 compunit.cu_pointer_size);
7726 if (entry->children)
7739 display_debug_aranges (section, start, file)
7740 Elf32_Internal_Shdr * section;
7741 unsigned char * start;
7742 FILE * file ATTRIBUTE_UNUSED;
7744 unsigned char * end = start + section->sh_size;
7746 printf (_("The section %s contains:\n\n"), SECTION_NAME (section));
7750 DWARF2_External_ARange * external;
7751 DWARF2_Internal_ARange arange;
7752 unsigned char * ranges;
7753 unsigned long length;
7754 unsigned long address;
7757 external = (DWARF2_External_ARange *) start;
7759 arange.ar_length = BYTE_GET (external->ar_length);
7760 arange.ar_version = BYTE_GET (external->ar_version);
7761 arange.ar_info_offset = BYTE_GET (external->ar_info_offset);
7762 arange.ar_pointer_size = BYTE_GET (external->ar_pointer_size);
7763 arange.ar_segment_size = BYTE_GET (external->ar_segment_size);
7765 if (arange.ar_length == 0xffffffff)
7767 warn (_("64-bit DWARF aranges are not supported yet.\n"));
7771 if (arange.ar_version != 2)
7773 warn (_("Only DWARF 2 aranges are currently supported.\n"));
7777 printf (_(" Length: %ld\n"), arange.ar_length);
7778 printf (_(" Version: %d\n"), arange.ar_version);
7779 printf (_(" Offset into .debug_info: %lx\n"), arange.ar_info_offset);
7780 printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
7781 printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
7783 printf (_("\n Address Length\n"));
7785 ranges = start + sizeof (* external);
7787 /* Must pad to an alignment boundary that is twice the pointer size. */
7788 excess = sizeof (* external) % (2 * arange.ar_pointer_size);
7790 ranges += (2 * arange.ar_pointer_size) - excess;
7794 address = byte_get (ranges, arange.ar_pointer_size);
7796 ranges += arange.ar_pointer_size;
7798 length = byte_get (ranges, arange.ar_pointer_size);
7800 ranges += arange.ar_pointer_size;
7802 /* A pair of zeros marks the end of the list. */
7803 if (address == 0 && length == 0)
7806 printf (" %8.8lx %lu\n", address, length);
7809 start += arange.ar_length + sizeof (external->ar_length);
7817 typedef struct Frame_Chunk
7819 struct Frame_Chunk * next;
7820 unsigned char * chunk_start;
7822 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
7823 short int * col_type;
7825 char * augmentation;
7826 unsigned int code_factor;
7828 unsigned long pc_begin;
7829 unsigned long pc_range;
7833 unsigned char fde_encoding;
7837 /* A marker for a col_type that means this column was never referenced
7838 in the frame info. */
7839 #define DW_CFA_unreferenced (-1)
7841 static void frame_need_space PARAMS ((Frame_Chunk *, int));
7842 static void frame_display_row PARAMS ((Frame_Chunk *, int *, int *));
7843 static int size_of_encoded_value PARAMS ((int));
7846 frame_need_space (fc, reg)
7850 int prev = fc->ncols;
7852 if (reg < fc->ncols)
7855 fc->ncols = reg + 1;
7856 fc->col_type = (short int *) xrealloc (fc->col_type,
7857 fc->ncols * sizeof (short int));
7858 fc->col_offset = (int *) xrealloc (fc->col_offset,
7859 fc->ncols * sizeof (int));
7861 while (prev < fc->ncols)
7863 fc->col_type[prev] = DW_CFA_unreferenced;
7864 fc->col_offset[prev] = 0;
7870 frame_display_row (fc, need_col_headers, max_regs)
7872 int * need_col_headers;
7878 if (* max_regs < fc->ncols)
7879 * max_regs = fc->ncols;
7881 if (* need_col_headers)
7883 * need_col_headers = 0;
7885 printf (" LOC CFA ");
7887 for (r = 0; r < * max_regs; r++)
7888 if (fc->col_type[r] != DW_CFA_unreferenced)
7893 printf ("r%-4d", r);
7899 printf ("%08lx ", fc->pc_begin);
7900 sprintf (tmp, "r%d%+d", fc->cfa_reg, fc->cfa_offset);
7901 printf ("%-8s ", tmp);
7903 for (r = 0; r < fc->ncols; r++)
7905 if (fc->col_type[r] != DW_CFA_unreferenced)
7907 switch (fc->col_type[r])
7909 case DW_CFA_undefined:
7912 case DW_CFA_same_value:
7916 sprintf (tmp, "c%+d", fc->col_offset[r]);
7918 case DW_CFA_register:
7919 sprintf (tmp, "r%d", fc->col_offset[r]);
7922 strcpy (tmp, "n/a");
7925 printf ("%-5s", tmp);
7932 size_of_encoded_value (encoding)
7935 switch (encoding & 0x7)
7938 case 0: return is_32bit_elf ? 4 : 8;
7945 #define GET(N) byte_get (start, N); start += N
7946 #define LEB() read_leb128 (start, & length_return, 0); start += length_return
7947 #define SLEB() read_leb128 (start, & length_return, 1); start += length_return
7950 display_debug_frames (section, start, file)
7951 Elf32_Internal_Shdr * section;
7952 unsigned char * start;
7953 FILE * file ATTRIBUTE_UNUSED;
7955 unsigned char * end = start + section->sh_size;
7956 unsigned char * section_start = start;
7957 Frame_Chunk * chunks = 0;
7958 Frame_Chunk * remembered_state = 0;
7960 int is_eh = (strcmp (SECTION_NAME (section), ".eh_frame") == 0);
7963 int addr_size = is_32bit_elf ? 4 : 8;
7965 printf (_("The section %s contains:\n"), SECTION_NAME (section));
7969 unsigned char * saved_start;
7970 unsigned char * block_end;
7971 unsigned long length;
7972 unsigned long cie_id;
7975 int need_col_headers = 1;
7976 unsigned char * augmentation_data = NULL;
7977 unsigned long augmentation_data_len = 0;
7978 int encoded_ptr_size = addr_size;
7980 saved_start = start;
7981 length = byte_get (start, 4); start += 4;
7986 if (length == 0xffffffff)
7988 warn (_("64-bit DWARF format frames are not supported yet.\n"));
7992 block_end = saved_start + length + 4;
7993 cie_id = byte_get (start, 4); start += 4;
7995 if (is_eh ? (cie_id == 0) : (cie_id == DW_CIE_ID))
7999 fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
8000 memset (fc, 0, sizeof (Frame_Chunk));
8004 fc->chunk_start = saved_start;
8006 fc->col_type = (short int *) xmalloc (sizeof (short int));
8007 fc->col_offset = (int *) xmalloc (sizeof (int));
8008 frame_need_space (fc, max_regs-1);
8012 fc->augmentation = start;
8013 start = strchr (start, '\0') + 1;
8015 if (fc->augmentation[0] == 'z')
8017 fc->code_factor = LEB ();
8018 fc->data_factor = SLEB ();
8019 fc->ra = byte_get (start, 1); start += 1;
8020 augmentation_data_len = LEB ();
8021 augmentation_data = start;
8022 start += augmentation_data_len;
8024 else if (strcmp (fc->augmentation, "eh") == 0)
8027 fc->code_factor = LEB ();
8028 fc->data_factor = SLEB ();
8029 fc->ra = byte_get (start, 1); start += 1;
8033 fc->code_factor = LEB ();
8034 fc->data_factor = SLEB ();
8035 fc->ra = byte_get (start, 1); start += 1;
8039 if (do_debug_frames_interp)
8040 printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n",
8041 (unsigned long)(saved_start - section_start), length, cie_id,
8042 fc->augmentation, fc->code_factor, fc->data_factor,
8046 printf ("\n%08lx %08lx %08lx CIE\n",
8047 (unsigned long)(saved_start - section_start), length, cie_id);
8048 printf (" Version: %d\n", version);
8049 printf (" Augmentation: \"%s\"\n", fc->augmentation);
8050 printf (" Code alignment factor: %u\n", fc->code_factor);
8051 printf (" Data alignment factor: %d\n", fc->data_factor);
8052 printf (" Return address column: %d\n", fc->ra);
8054 if (augmentation_data_len)
8057 printf (" Augmentation data: ");
8058 for (i = 0; i < augmentation_data_len; ++i)
8059 printf (" %02x", augmentation_data[i]);
8065 if (augmentation_data_len)
8067 unsigned char *p, *q;
8068 p = fc->augmentation + 1;
8069 q = augmentation_data;
8076 q += 1 + size_of_encoded_value (*q);
8078 fc->fde_encoding = *q++;
8084 if (fc->fde_encoding)
8085 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
8088 frame_need_space (fc, fc->ra);
8092 unsigned char * look_for;
8093 static Frame_Chunk fde_fc;
8096 memset (fc, 0, sizeof (Frame_Chunk));
8098 look_for = is_eh ? start - 4 - cie_id : section_start + cie_id;
8100 for (cie = chunks; cie ; cie = cie->next)
8101 if (cie->chunk_start == look_for)
8106 warn ("Invalid CIE pointer %08lx in FDE at %08lx\n",
8107 cie_id, saved_start);
8110 fc->col_type = (short int *) xmalloc (sizeof (short int));
8111 fc->col_offset = (int *) xmalloc (sizeof (int));
8112 frame_need_space (fc, max_regs - 1);
8114 fc->augmentation = "";
8115 fc->fde_encoding = 0;
8119 fc->ncols = cie->ncols;
8120 fc->col_type = (short int *) xmalloc (fc->ncols * sizeof (short int));
8121 fc->col_offset = (int *) xmalloc (fc->ncols * sizeof (int));
8122 memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int));
8123 memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int));
8124 fc->augmentation = cie->augmentation;
8125 fc->code_factor = cie->code_factor;
8126 fc->data_factor = cie->data_factor;
8127 fc->cfa_reg = cie->cfa_reg;
8128 fc->cfa_offset = cie->cfa_offset;
8130 frame_need_space (fc, max_regs-1);
8131 fc->fde_encoding = cie->fde_encoding;
8134 if (fc->fde_encoding)
8135 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
8137 fc->pc_begin = byte_get (start, encoded_ptr_size);
8138 start += encoded_ptr_size;
8139 fc->pc_range = byte_get (start, encoded_ptr_size);
8140 start += encoded_ptr_size;
8142 if (cie->augmentation[0] == 'z')
8144 augmentation_data_len = LEB ();
8145 augmentation_data = start;
8146 start += augmentation_data_len;
8149 printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=%08lx..%08lx\n",
8150 (unsigned long)(saved_start - section_start), length, cie_id,
8151 (unsigned long)(cie->chunk_start - section_start),
8152 fc->pc_begin, fc->pc_begin + fc->pc_range);
8153 if (! do_debug_frames_interp && augmentation_data_len)
8156 printf (" Augmentation data: ");
8157 for (i = 0; i < augmentation_data_len; ++i)
8158 printf (" %02x", augmentation_data[i]);
8164 /* At this point, fc is the current chunk, cie (if any) is set, and we're
8165 about to interpret instructions for the chunk. */
8167 if (do_debug_frames_interp)
8169 /* Start by making a pass over the chunk, allocating storage
8170 and taking note of what registers are used. */
8171 unsigned char * tmp = start;
8173 while (start < block_end)
8183 /* Warning: if you add any more cases to this switch, be
8184 sure to add them to the corresponding switch below. */
8187 case DW_CFA_advance_loc:
8191 frame_need_space (fc, opa);
8192 fc->col_type[opa] = DW_CFA_undefined;
8194 case DW_CFA_restore:
8195 frame_need_space (fc, opa);
8196 fc->col_type[opa] = DW_CFA_undefined;
8198 case DW_CFA_set_loc:
8199 start += encoded_ptr_size;
8201 case DW_CFA_advance_loc1:
8204 case DW_CFA_advance_loc2:
8207 case DW_CFA_advance_loc4:
8210 case DW_CFA_offset_extended:
8211 reg = LEB (); LEB ();
8212 frame_need_space (fc, reg);
8213 fc->col_type[reg] = DW_CFA_undefined;
8215 case DW_CFA_restore_extended:
8217 frame_need_space (fc, reg);
8218 fc->col_type[reg] = DW_CFA_undefined;
8220 case DW_CFA_undefined:
8222 frame_need_space (fc, reg);
8223 fc->col_type[reg] = DW_CFA_undefined;
8225 case DW_CFA_same_value:
8227 frame_need_space (fc, reg);
8228 fc->col_type[reg] = DW_CFA_undefined;
8230 case DW_CFA_register:
8231 reg = LEB (); LEB ();
8232 frame_need_space (fc, reg);
8233 fc->col_type[reg] = DW_CFA_undefined;
8235 case DW_CFA_def_cfa:
8238 case DW_CFA_def_cfa_register:
8241 case DW_CFA_def_cfa_offset:
8244 #ifndef DW_CFA_GNU_args_size
8245 #define DW_CFA_GNU_args_size 0x2e
8247 case DW_CFA_GNU_args_size:
8250 #ifndef DW_CFA_GNU_negative_offset_extended
8251 #define DW_CFA_GNU_negative_offset_extended 0x2f
8253 case DW_CFA_GNU_negative_offset_extended:
8254 reg = LEB (); LEB ();
8255 frame_need_space (fc, reg);
8256 fc->col_type[reg] = DW_CFA_undefined;
8265 /* Now we know what registers are used, make a second pass over
8266 the chunk, this time actually printing out the info. */
8268 while (start < block_end)
8271 unsigned long ul, reg, roffs;
8280 /* Warning: if you add any more cases to this switch, be
8281 sure to add them to the corresponding switch above. */
8284 case DW_CFA_advance_loc:
8285 if (do_debug_frames_interp)
8286 frame_display_row (fc, &need_col_headers, &max_regs);
8288 printf (" DW_CFA_advance_loc: %d to %08lx\n",
8289 opa * fc->code_factor,
8290 fc->pc_begin + opa * fc->code_factor);
8291 fc->pc_begin += opa * fc->code_factor;
8296 if (! do_debug_frames_interp)
8297 printf (" DW_CFA_offset: r%d at cfa%+ld\n",
8298 opa, roffs * fc->data_factor);
8299 fc->col_type[opa] = DW_CFA_offset;
8300 fc->col_offset[opa] = roffs * fc->data_factor;
8303 case DW_CFA_restore:
8304 if (! do_debug_frames_interp)
8305 printf (" DW_CFA_restore: r%d\n", opa);
8306 fc->col_type[opa] = cie->col_type[opa];
8307 fc->col_offset[opa] = cie->col_offset[opa];
8310 case DW_CFA_set_loc:
8311 vma = byte_get (start, encoded_ptr_size);
8312 start += encoded_ptr_size;
8313 if (do_debug_frames_interp)
8314 frame_display_row (fc, &need_col_headers, &max_regs);
8316 printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma);
8320 case DW_CFA_advance_loc1:
8321 ofs = byte_get (start, 1); start += 1;
8322 if (do_debug_frames_interp)
8323 frame_display_row (fc, &need_col_headers, &max_regs);
8325 printf (" DW_CFA_advance_loc1: %ld to %08lx\n",
8326 ofs * fc->code_factor,
8327 fc->pc_begin + ofs * fc->code_factor);
8328 fc->pc_begin += ofs * fc->code_factor;
8331 case DW_CFA_advance_loc2:
8332 ofs = byte_get (start, 2); start += 2;
8333 if (do_debug_frames_interp)
8334 frame_display_row (fc, &need_col_headers, &max_regs);
8336 printf (" DW_CFA_advance_loc2: %ld to %08lx\n",
8337 ofs * fc->code_factor,
8338 fc->pc_begin + ofs * fc->code_factor);
8339 fc->pc_begin += ofs * fc->code_factor;
8342 case DW_CFA_advance_loc4:
8343 ofs = byte_get (start, 4); start += 4;
8344 if (do_debug_frames_interp)
8345 frame_display_row (fc, &need_col_headers, &max_regs);
8347 printf (" DW_CFA_advance_loc4: %ld to %08lx\n",
8348 ofs * fc->code_factor,
8349 fc->pc_begin + ofs * fc->code_factor);
8350 fc->pc_begin += ofs * fc->code_factor;
8353 case DW_CFA_offset_extended:
8356 if (! do_debug_frames_interp)
8357 printf (" DW_CFA_offset_extended: r%ld at cfa%+ld\n",
8358 reg, roffs * fc->data_factor);
8359 fc->col_type[reg] = DW_CFA_offset;
8360 fc->col_offset[reg] = roffs * fc->data_factor;
8363 case DW_CFA_restore_extended:
8365 if (! do_debug_frames_interp)
8366 printf (" DW_CFA_restore_extended: r%ld\n", reg);
8367 fc->col_type[reg] = cie->col_type[reg];
8368 fc->col_offset[reg] = cie->col_offset[reg];
8371 case DW_CFA_undefined:
8373 if (! do_debug_frames_interp)
8374 printf (" DW_CFA_undefined: r%ld\n", reg);
8375 fc->col_type[reg] = DW_CFA_undefined;
8376 fc->col_offset[reg] = 0;
8379 case DW_CFA_same_value:
8381 if (! do_debug_frames_interp)
8382 printf (" DW_CFA_same_value: r%ld\n", reg);
8383 fc->col_type[reg] = DW_CFA_same_value;
8384 fc->col_offset[reg] = 0;
8387 case DW_CFA_register:
8390 if (! do_debug_frames_interp)
8391 printf (" DW_CFA_register: r%ld\n", reg);
8392 fc->col_type[reg] = DW_CFA_register;
8393 fc->col_offset[reg] = roffs;
8396 case DW_CFA_remember_state:
8397 if (! do_debug_frames_interp)
8398 printf (" DW_CFA_remember_state\n");
8399 rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
8400 rs->ncols = fc->ncols;
8401 rs->col_type = (short int *) xmalloc (rs->ncols * sizeof (short int));
8402 rs->col_offset = (int *) xmalloc (rs->ncols * sizeof (int));
8403 memcpy (rs->col_type, fc->col_type, rs->ncols);
8404 memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (int));
8405 rs->next = remembered_state;
8406 remembered_state = rs;
8409 case DW_CFA_restore_state:
8410 if (! do_debug_frames_interp)
8411 printf (" DW_CFA_restore_state\n");
8412 rs = remembered_state;
8413 remembered_state = rs->next;
8414 frame_need_space (fc, rs->ncols-1);
8415 memcpy (fc->col_type, rs->col_type, rs->ncols);
8416 memcpy (fc->col_offset, rs->col_offset, rs->ncols * sizeof (int));
8417 free (rs->col_type);
8418 free (rs->col_offset);
8422 case DW_CFA_def_cfa:
8423 fc->cfa_reg = LEB ();
8424 fc->cfa_offset = LEB ();
8425 if (! do_debug_frames_interp)
8426 printf (" DW_CFA_def_cfa: r%d ofs %d\n",
8427 fc->cfa_reg, fc->cfa_offset);
8430 case DW_CFA_def_cfa_register:
8431 fc->cfa_reg = LEB ();
8432 if (! do_debug_frames_interp)
8433 printf (" DW_CFA_def_cfa_reg: r%d\n", fc->cfa_reg);
8436 case DW_CFA_def_cfa_offset:
8437 fc->cfa_offset = LEB ();
8438 if (! do_debug_frames_interp)
8439 printf (" DW_CFA_def_cfa_offset: %d\n", fc->cfa_offset);
8443 if (! do_debug_frames_interp)
8444 printf (" DW_CFA_nop\n");
8447 #ifndef DW_CFA_GNU_window_save
8448 #define DW_CFA_GNU_window_save 0x2d
8450 case DW_CFA_GNU_window_save:
8451 if (! do_debug_frames_interp)
8452 printf (" DW_CFA_GNU_window_save\n");
8455 case DW_CFA_GNU_args_size:
8457 if (! do_debug_frames_interp)
8458 printf (" DW_CFA_GNU_args_size: %ld\n", ul);
8461 case DW_CFA_GNU_negative_offset_extended:
8464 frame_need_space (fc, reg);
8465 if (! do_debug_frames_interp)
8466 printf (" DW_CFA_GNU_negative_offset_extended: r%ld at cfa%+ld\n",
8467 reg, l * fc->data_factor);
8468 fc->col_type[reg] = DW_CFA_offset;
8469 fc->col_offset[reg] = l * fc->data_factor;
8473 fprintf (stderr, "unsupported or unknown DW_CFA_%d\n", op);
8478 if (do_debug_frames_interp)
8479 frame_display_row (fc, &need_col_headers, &max_regs);
8494 display_debug_not_supported (section, start, file)
8495 Elf32_Internal_Shdr * section;
8496 unsigned char * start ATTRIBUTE_UNUSED;
8497 FILE * file ATTRIBUTE_UNUSED;
8499 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
8500 SECTION_NAME (section));
8505 /* Pre-scan the .debug_info section to record the size of address.
8506 When dumping the .debug_line, we use that size information, assuming
8507 that all compilation units have the same address size. */
8509 prescan_debug_info (section, start, file)
8510 Elf32_Internal_Shdr * section ATTRIBUTE_UNUSED;
8511 unsigned char * start;
8512 FILE * file ATTRIBUTE_UNUSED;
8514 DWARF2_External_CompUnit * external;
8516 external = (DWARF2_External_CompUnit *) start;
8518 debug_line_pointer_size = BYTE_GET (external->cu_pointer_size);
8522 /* A structure containing the name of a debug section and a pointer
8523 to a function that can decode it. The third field is a prescan
8524 function to be run over the section before displaying any of the
8528 const char * const name;
8529 int (* display) PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
8530 int (* prescan) PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
8534 { ".debug_abbrev", display_debug_abbrev, NULL },
8535 { ".debug_aranges", display_debug_aranges, NULL },
8536 { ".debug_frame", display_debug_frames, NULL },
8537 { ".debug_info", display_debug_info, prescan_debug_info },
8538 { ".debug_line", display_debug_lines, NULL },
8539 { ".debug_pubnames", display_debug_pubnames, NULL },
8540 { ".eh_frame", display_debug_frames, NULL },
8541 { ".debug_macinfo", display_debug_macinfo, NULL },
8542 { ".debug_str", display_debug_str, NULL },
8544 { ".debug_pubtypes", display_debug_not_supported, NULL },
8545 { ".debug_ranges", display_debug_not_supported, NULL },
8546 { ".debug_static_func", display_debug_not_supported, NULL },
8547 { ".debug_static_vars", display_debug_not_supported, NULL },
8548 { ".debug_types", display_debug_not_supported, NULL },
8549 { ".debug_weaknames", display_debug_not_supported, NULL }
8553 display_debug_section (section, file)
8554 Elf32_Internal_Shdr * section;
8557 char * name = SECTION_NAME (section);
8558 bfd_size_type length;
8559 unsigned char * start;
8562 length = section->sh_size;
8565 printf (_("\nSection '%s' has no debugging data.\n"), name);
8569 start = (unsigned char *) get_data (NULL, file, section->sh_offset, length,
8570 _("debug section data"));
8574 /* See if we know how to display the contents of this section. */
8575 if (strncmp (name, ".gnu.linkonce.wi.", 17) == 0)
8576 name = ".debug_info";
8578 for (i = NUM_ELEM (debug_displays); i--;)
8579 if (strcmp (debug_displays[i].name, name) == 0)
8581 debug_displays[i].display (section, start, file);
8586 printf (_("Unrecognised debug section: %s\n"), name);
8590 /* If we loaded in the abbrev section at some point,
8591 we must release it here. */
8598 process_section_contents (file)
8601 Elf32_Internal_Shdr * section;
8607 /* Pre-scan the debug sections to find some debug information not
8608 present in some of them. For the .debug_line, we must find out the
8609 size of address (specified in .debug_info and .debug_aranges). */
8610 for (i = 0, section = section_headers;
8611 i < elf_header.e_shnum && i < num_dump_sects;
8614 char * name = SECTION_NAME (section);
8617 if (section->sh_size == 0)
8620 /* See if there is some pre-scan operation for this section. */
8621 for (j = NUM_ELEM (debug_displays); j--;)
8622 if (strcmp (debug_displays[j].name, name) == 0)
8624 if (debug_displays[j].prescan != NULL)
8626 bfd_size_type length;
8627 unsigned char * start;
8629 length = section->sh_size;
8630 start = ((unsigned char *)
8631 get_data (NULL, file, section->sh_offset, length,
8632 _("debug section data")));
8636 debug_displays[j].prescan (section, start, file);
8644 for (i = 0, section = section_headers;
8645 i < elf_header.e_shnum && i < num_dump_sects;
8648 #ifdef SUPPORT_DISASSEMBLY
8649 if (dump_sects[i] & DISASS_DUMP)
8650 disassemble_section (section, file);
8652 if (dump_sects[i] & HEX_DUMP)
8653 dump_section (section, file);
8655 if (dump_sects[i] & DEBUG_DUMP)
8656 display_debug_section (section, file);
8659 if (i < num_dump_sects)
8660 warn (_("Some sections were not dumped because they do not exist!\n"));
8666 process_mips_fpe_exception (mask)
8672 if (mask & OEX_FPU_INEX)
8673 fputs ("INEX", stdout), first = 0;
8674 if (mask & OEX_FPU_UFLO)
8675 printf ("%sUFLO", first ? "" : "|"), first = 0;
8676 if (mask & OEX_FPU_OFLO)
8677 printf ("%sOFLO", first ? "" : "|"), first = 0;
8678 if (mask & OEX_FPU_DIV0)
8679 printf ("%sDIV0", first ? "" : "|"), first = 0;
8680 if (mask & OEX_FPU_INVAL)
8681 printf ("%sINVAL", first ? "" : "|");
8684 fputs ("0", stdout);
8688 process_mips_specific (file)
8691 Elf_Internal_Dyn * entry;
8692 size_t liblist_offset = 0;
8693 size_t liblistno = 0;
8694 size_t conflictsno = 0;
8695 size_t options_offset = 0;
8696 size_t conflicts_offset = 0;
8698 /* We have a lot of special sections. Thanks SGI! */
8699 if (dynamic_segment == NULL)
8700 /* No information available. */
8703 for (entry = dynamic_segment; entry->d_tag != DT_NULL; ++entry)
8704 switch (entry->d_tag)
8706 case DT_MIPS_LIBLIST:
8707 liblist_offset = entry->d_un.d_val - loadaddr;
8709 case DT_MIPS_LIBLISTNO:
8710 liblistno = entry->d_un.d_val;
8712 case DT_MIPS_OPTIONS:
8713 options_offset = entry->d_un.d_val - loadaddr;
8715 case DT_MIPS_CONFLICT:
8716 conflicts_offset = entry->d_un.d_val - loadaddr;
8718 case DT_MIPS_CONFLICTNO:
8719 conflictsno = entry->d_un.d_val;
8725 if (liblist_offset != 0 && liblistno != 0 && do_dynamic)
8727 Elf32_External_Lib * elib;
8730 elib = ((Elf32_External_Lib *)
8731 get_data (NULL, file, liblist_offset,
8732 liblistno * sizeof (Elf32_External_Lib),
8736 printf ("\nSection '.liblist' contains %lu entries:\n",
8737 (unsigned long) liblistno);
8738 fputs (" Library Time Stamp Checksum Version Flags\n",
8741 for (cnt = 0; cnt < liblistno; ++cnt)
8748 liblist.l_name = BYTE_GET (elib[cnt].l_name);
8749 time = BYTE_GET (elib[cnt].l_time_stamp);
8750 liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum);
8751 liblist.l_version = BYTE_GET (elib[cnt].l_version);
8752 liblist.l_flags = BYTE_GET (elib[cnt].l_flags);
8754 tmp = gmtime (&time);
8755 sprintf (timebuf, "%04u-%02u-%02uT%02u:%02u:%02u",
8756 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
8757 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
8759 printf ("%3lu: ", (unsigned long) cnt);
8760 print_symbol (20, dynamic_strings + liblist.l_name);
8761 printf (" %s %#10lx %-7ld", timebuf, liblist.l_checksum,
8764 if (liblist.l_flags == 0)
8775 { " EXACT_MATCH", LL_EXACT_MATCH },
8776 { " IGNORE_INT_VER", LL_IGNORE_INT_VER },
8777 { " REQUIRE_MINOR", LL_REQUIRE_MINOR },
8778 { " EXPORTS", LL_EXPORTS },
8779 { " DELAY_LOAD", LL_DELAY_LOAD },
8780 { " DELTA", LL_DELTA }
8782 int flags = liblist.l_flags;
8786 fcnt < sizeof (l_flags_vals) / sizeof (l_flags_vals[0]);
8788 if ((flags & l_flags_vals[fcnt].bit) != 0)
8790 fputs (l_flags_vals[fcnt].name, stdout);
8791 flags ^= l_flags_vals[fcnt].bit;
8794 printf (" %#x", (unsigned int) flags);
8804 if (options_offset != 0)
8806 Elf_External_Options * eopt;
8807 Elf_Internal_Shdr * sect = section_headers;
8808 Elf_Internal_Options * iopt;
8809 Elf_Internal_Options * option;
8813 /* Find the section header so that we get the size. */
8814 while (sect->sh_type != SHT_MIPS_OPTIONS)
8817 eopt = (Elf_External_Options *) get_data (NULL, file, options_offset,
8818 sect->sh_size, _("options"));
8821 iopt = ((Elf_Internal_Options *)
8822 malloc ((sect->sh_size / sizeof (eopt)) * sizeof (* iopt)));
8825 error (_("Out of memory"));
8832 while (offset < sect->sh_size)
8834 Elf_External_Options * eoption;
8836 eoption = (Elf_External_Options *) ((char *) eopt + offset);
8838 option->kind = BYTE_GET (eoption->kind);
8839 option->size = BYTE_GET (eoption->size);
8840 option->section = BYTE_GET (eoption->section);
8841 option->info = BYTE_GET (eoption->info);
8843 offset += option->size;
8849 printf (_("\nSection '%s' contains %d entries:\n"),
8850 SECTION_NAME (sect), cnt);
8858 switch (option->kind)
8861 /* This shouldn't happen. */
8862 printf (" NULL %d %lx", option->section, option->info);
8865 printf (" REGINFO ");
8866 if (elf_header.e_machine == EM_MIPS)
8869 Elf32_External_RegInfo * ereg;
8870 Elf32_RegInfo reginfo;
8872 ereg = (Elf32_External_RegInfo *) (option + 1);
8873 reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask);
8874 reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
8875 reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
8876 reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
8877 reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
8878 reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value);
8880 printf ("GPR %08lx GP 0x%lx\n",
8882 (unsigned long) reginfo.ri_gp_value);
8883 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
8884 reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
8885 reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
8890 Elf64_External_RegInfo * ereg;
8891 Elf64_Internal_RegInfo reginfo;
8893 ereg = (Elf64_External_RegInfo *) (option + 1);
8894 reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask);
8895 reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
8896 reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
8897 reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
8898 reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
8899 reginfo.ri_gp_value = BYTE_GET8 (ereg->ri_gp_value);
8901 printf ("GPR %08lx GP 0x",
8902 reginfo.ri_gprmask);
8903 printf_vma (reginfo.ri_gp_value);
8906 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
8907 reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
8908 reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
8912 case ODK_EXCEPTIONS:
8913 fputs (" EXCEPTIONS fpe_min(", stdout);
8914 process_mips_fpe_exception (option->info & OEX_FPU_MIN);
8915 fputs (") fpe_max(", stdout);
8916 process_mips_fpe_exception ((option->info & OEX_FPU_MAX) >> 8);
8917 fputs (")", stdout);
8919 if (option->info & OEX_PAGE0)
8920 fputs (" PAGE0", stdout);
8921 if (option->info & OEX_SMM)
8922 fputs (" SMM", stdout);
8923 if (option->info & OEX_FPDBUG)
8924 fputs (" FPDBUG", stdout);
8925 if (option->info & OEX_DISMISS)
8926 fputs (" DISMISS", stdout);
8929 fputs (" PAD ", stdout);
8930 if (option->info & OPAD_PREFIX)
8931 fputs (" PREFIX", stdout);
8932 if (option->info & OPAD_POSTFIX)
8933 fputs (" POSTFIX", stdout);
8934 if (option->info & OPAD_SYMBOL)
8935 fputs (" SYMBOL", stdout);
8938 fputs (" HWPATCH ", stdout);
8939 if (option->info & OHW_R4KEOP)
8940 fputs (" R4KEOP", stdout);
8941 if (option->info & OHW_R8KPFETCH)
8942 fputs (" R8KPFETCH", stdout);
8943 if (option->info & OHW_R5KEOP)
8944 fputs (" R5KEOP", stdout);
8945 if (option->info & OHW_R5KCVTL)
8946 fputs (" R5KCVTL", stdout);
8949 fputs (" FILL ", stdout);
8950 /* XXX Print content of info word? */
8953 fputs (" TAGS ", stdout);
8954 /* XXX Print content of info word? */
8957 fputs (" HWAND ", stdout);
8958 if (option->info & OHWA0_R4KEOP_CHECKED)
8959 fputs (" R4KEOP_CHECKED", stdout);
8960 if (option->info & OHWA0_R4KEOP_CLEAN)
8961 fputs (" R4KEOP_CLEAN", stdout);
8964 fputs (" HWOR ", stdout);
8965 if (option->info & OHWA0_R4KEOP_CHECKED)
8966 fputs (" R4KEOP_CHECKED", stdout);
8967 if (option->info & OHWA0_R4KEOP_CLEAN)
8968 fputs (" R4KEOP_CLEAN", stdout);
8971 printf (" GP_GROUP %#06lx self-contained %#06lx",
8972 option->info & OGP_GROUP,
8973 (option->info & OGP_SELF) >> 16);
8976 printf (" IDENT %#06lx self-contained %#06lx",
8977 option->info & OGP_GROUP,
8978 (option->info & OGP_SELF) >> 16);
8981 /* This shouldn't happen. */
8982 printf (" %3d ??? %d %lx",
8983 option->kind, option->section, option->info);
8987 len = sizeof (* eopt);
8988 while (len < option->size)
8989 if (((char *) option)[len] >= ' '
8990 && ((char *) option)[len] < 0x7f)
8991 printf ("%c", ((char *) option)[len++]);
8993 printf ("\\%03o", ((char *) option)[len++]);
8995 fputs ("\n", stdout);
9003 if (conflicts_offset != 0 && conflictsno != 0)
9005 Elf32_Conflict * iconf;
9008 if (dynamic_symbols == NULL)
9010 error (_("conflict list with without table"));
9014 iconf = (Elf32_Conflict *) malloc (conflictsno * sizeof (* iconf));
9017 error (_("Out of memory"));
9023 Elf32_External_Conflict * econf32;
9025 econf32 = ((Elf32_External_Conflict *)
9026 get_data (NULL, file, conflicts_offset,
9027 conflictsno * sizeof (* econf32),
9032 for (cnt = 0; cnt < conflictsno; ++cnt)
9033 iconf[cnt] = BYTE_GET (econf32[cnt]);
9039 Elf64_External_Conflict * econf64;
9041 econf64 = ((Elf64_External_Conflict *)
9042 get_data (NULL, file, conflicts_offset,
9043 conflictsno * sizeof (* econf64),
9048 for (cnt = 0; cnt < conflictsno; ++cnt)
9049 iconf[cnt] = BYTE_GET (econf64[cnt]);
9054 printf (_("\nSection '.conflict' contains %ld entries:\n"),
9055 (long) conflictsno);
9056 puts (_(" Num: Index Value Name"));
9058 for (cnt = 0; cnt < conflictsno; ++cnt)
9060 Elf_Internal_Sym * psym = & dynamic_symbols [iconf [cnt]];
9062 printf ("%5lu: %8lu ", (unsigned long) cnt, iconf [cnt]);
9063 print_vma (psym->st_value, FULL_HEX);
9065 print_symbol (25, dynamic_strings + psym->st_name);
9076 get_note_type (e_type)
9079 static char buff[64];
9083 case NT_PRSTATUS: return _("NT_PRSTATUS (prstatus structure)");
9084 case NT_FPREGSET: return _("NT_FPREGSET (floating point registers)");
9085 case NT_PRPSINFO: return _("NT_PRPSINFO (prpsinfo structure)");
9086 case NT_TASKSTRUCT: return _("NT_TASKSTRUCT (task structure)");
9087 case NT_PRXFPREG: return _("NT_PRXFPREG (user_xfpregs structure)");
9088 case NT_PSTATUS: return _("NT_PSTATUS (pstatus structure)");
9089 case NT_FPREGS: return _("NT_FPREGS (floating point registers)");
9090 case NT_PSINFO: return _("NT_PSINFO (psinfo structure)");
9091 case NT_LWPSTATUS: return _("NT_LWPSTATUS (lwpstatus_t structure)");
9092 case NT_LWPSINFO: return _("NT_LWPSINFO (lwpsinfo_t structure)");
9093 case NT_WIN32PSTATUS: return _("NT_WIN32PSTATUS (win32_pstatus strcuture)");
9095 sprintf (buff, _("Unknown note type: (0x%08x)"), e_type);
9101 get_netbsd_elfcore_note_type (e_type)
9104 static char buff[64];
9106 if (e_type == NT_NETBSDCORE_PROCINFO)
9108 /* NetBSD core "procinfo" structure. */
9109 return _("NetBSD procinfo structure");
9112 /* As of Jan 2002 there are no other machine-independent notes
9113 defined for NetBSD core files. If the note type is less
9114 than the start of the machine-dependent note types, we don't
9117 if (e_type < NT_NETBSDCORE_FIRSTMACH)
9119 sprintf (buff, _("Unknown note type: (0x%08x)"), e_type);
9123 switch (elf_header.e_machine)
9125 /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0
9126 and PT_GETFPREGS == mach+2. */
9131 case EM_SPARC32PLUS:
9135 case NT_NETBSDCORE_FIRSTMACH+0:
9136 return _("PT_GETREGS (reg structure)");
9137 case NT_NETBSDCORE_FIRSTMACH+2:
9138 return _("PT_GETFPREGS (fpreg structure)");
9144 /* On all other arch's, PT_GETREGS == mach+1 and
9145 PT_GETFPREGS == mach+3. */
9149 case NT_NETBSDCORE_FIRSTMACH+1:
9150 return _("PT_GETREGS (reg structure)");
9151 case NT_NETBSDCORE_FIRSTMACH+3:
9152 return _("PT_GETFPREGS (fpreg structure)");
9158 sprintf (buff, _("PT_FIRSTMACH+%d"), e_type - NT_NETBSDCORE_FIRSTMACH);
9162 /* Note that by the ELF standard, the name field is already null byte
9163 terminated, and namesz includes the terminating null byte.
9164 I.E. the value of namesz for the name "FSF" is 4.
9166 If the value of namesz is zero, there is no name present. */
9168 process_note (pnote)
9169 Elf32_Internal_Note * pnote;
9173 if (pnote->namesz == 0)
9175 /* If there is no note name, then use the default set of
9176 note type strings. */
9177 nt = get_note_type (pnote->type);
9179 else if (strncmp (pnote->namedata, "NetBSD-CORE", 11) == 0)
9181 /* NetBSD-specific core file notes. */
9182 nt = get_netbsd_elfcore_note_type (pnote->type);
9186 /* Don't recognize this note name; just use the default set of
9187 note type strings. */
9188 nt = get_note_type (pnote->type);
9191 printf (" %s\t\t0x%08lx\t%s\n",
9192 pnote->namesz ? pnote->namedata : "(NONE)",
9199 process_corefile_note_segment (file, offset, length)
9204 Elf_External_Note * pnotes;
9205 Elf_External_Note * external;
9211 pnotes = (Elf_External_Note *) get_data (NULL, file, offset, length,
9218 printf (_("\nNotes at offset 0x%08lx with length 0x%08lx:\n"),
9219 (unsigned long) offset, (unsigned long) length);
9220 printf (_(" Owner\t\tData size\tDescription\n"));
9222 while (external < (Elf_External_Note *)((char *) pnotes + length))
9224 Elf32_Internal_Note inote;
9227 inote.type = BYTE_GET (external->type);
9228 inote.namesz = BYTE_GET (external->namesz);
9229 inote.namedata = external->name;
9230 inote.descsz = BYTE_GET (external->descsz);
9231 inote.descdata = inote.namedata + align_power (inote.namesz, 2);
9232 inote.descpos = offset + (inote.descdata - (char *) pnotes);
9234 external = (Elf_External_Note *)(inote.descdata + align_power (inote.descsz, 2));
9236 /* Verify that name is null terminated. It appears that at least
9237 one version of Linux (RedHat 6.0) generates corefiles that don't
9238 comply with the ELF spec by failing to include the null byte in
9240 if (inote.namedata[inote.namesz] != '\0')
9242 temp = malloc (inote.namesz + 1);
9246 error (_("Out of memory\n"));
9251 strncpy (temp, inote.namedata, inote.namesz);
9252 temp[inote.namesz] = 0;
9254 /* warn (_("'%s' NOTE name not properly null terminated\n"), temp); */
9255 inote.namedata = temp;
9258 res &= process_note (& inote);
9273 process_corefile_note_segments (file)
9276 Elf_Internal_Phdr * program_headers;
9277 Elf_Internal_Phdr * segment;
9281 program_headers = (Elf_Internal_Phdr *) malloc
9282 (elf_header.e_phnum * sizeof (Elf_Internal_Phdr));
9284 if (program_headers == NULL)
9286 error (_("Out of memory\n"));
9291 i = get_32bit_program_headers (file, program_headers);
9293 i = get_64bit_program_headers (file, program_headers);
9297 free (program_headers);
9301 for (i = 0, segment = program_headers;
9302 i < elf_header.e_phnum;
9305 if (segment->p_type == PT_NOTE)
9306 res &= process_corefile_note_segment (file,
9307 (bfd_vma) segment->p_offset,
9308 (bfd_vma) segment->p_filesz);
9311 free (program_headers);
9317 process_corefile_contents (file)
9320 /* If we have not been asked to display the notes then do nothing. */
9324 /* If file is not a core file then exit. */
9325 if (elf_header.e_type != ET_CORE)
9328 /* No program headers means no NOTE segment. */
9329 if (elf_header.e_phnum == 0)
9331 printf (_("No note segments present in the core file.\n"));
9335 return process_corefile_note_segments (file);
9339 process_arch_specific (file)
9345 switch (elf_header.e_machine)
9348 case EM_MIPS_RS3_LE:
9349 return process_mips_specific (file);
9358 get_file_header (file)
9361 /* Read in the identity array. */
9362 if (fread (elf_header.e_ident, EI_NIDENT, 1, file) != 1)
9365 /* Determine how to read the rest of the header. */
9366 switch (elf_header.e_ident [EI_DATA])
9368 default: /* fall through */
9369 case ELFDATANONE: /* fall through */
9370 case ELFDATA2LSB: byte_get = byte_get_little_endian; break;
9371 case ELFDATA2MSB: byte_get = byte_get_big_endian; break;
9374 /* For now we only support 32 bit and 64 bit ELF files. */
9375 is_32bit_elf = (elf_header.e_ident [EI_CLASS] != ELFCLASS64);
9377 /* Read in the rest of the header. */
9380 Elf32_External_Ehdr ehdr32;
9382 if (fread (ehdr32.e_type, sizeof (ehdr32) - EI_NIDENT, 1, file) != 1)
9385 elf_header.e_type = BYTE_GET (ehdr32.e_type);
9386 elf_header.e_machine = BYTE_GET (ehdr32.e_machine);
9387 elf_header.e_version = BYTE_GET (ehdr32.e_version);
9388 elf_header.e_entry = BYTE_GET (ehdr32.e_entry);
9389 elf_header.e_phoff = BYTE_GET (ehdr32.e_phoff);
9390 elf_header.e_shoff = BYTE_GET (ehdr32.e_shoff);
9391 elf_header.e_flags = BYTE_GET (ehdr32.e_flags);
9392 elf_header.e_ehsize = BYTE_GET (ehdr32.e_ehsize);
9393 elf_header.e_phentsize = BYTE_GET (ehdr32.e_phentsize);
9394 elf_header.e_phnum = BYTE_GET (ehdr32.e_phnum);
9395 elf_header.e_shentsize = BYTE_GET (ehdr32.e_shentsize);
9396 elf_header.e_shnum = BYTE_GET (ehdr32.e_shnum);
9397 elf_header.e_shstrndx = BYTE_GET (ehdr32.e_shstrndx);
9401 Elf64_External_Ehdr ehdr64;
9403 /* If we have been compiled with sizeof (bfd_vma) == 4, then
9404 we will not be able to cope with the 64bit data found in
9405 64 ELF files. Detect this now and abort before we start
9406 overwritting things. */
9407 if (sizeof (bfd_vma) < 8)
9409 error (_("This instance of readelf has been built without support for a\n\
9410 64 bit data type and so it cannot read 64 bit ELF files.\n"));
9414 if (fread (ehdr64.e_type, sizeof (ehdr64) - EI_NIDENT, 1, file) != 1)
9417 elf_header.e_type = BYTE_GET (ehdr64.e_type);
9418 elf_header.e_machine = BYTE_GET (ehdr64.e_machine);
9419 elf_header.e_version = BYTE_GET (ehdr64.e_version);
9420 elf_header.e_entry = BYTE_GET8 (ehdr64.e_entry);
9421 elf_header.e_phoff = BYTE_GET8 (ehdr64.e_phoff);
9422 elf_header.e_shoff = BYTE_GET8 (ehdr64.e_shoff);
9423 elf_header.e_flags = BYTE_GET (ehdr64.e_flags);
9424 elf_header.e_ehsize = BYTE_GET (ehdr64.e_ehsize);
9425 elf_header.e_phentsize = BYTE_GET (ehdr64.e_phentsize);
9426 elf_header.e_phnum = BYTE_GET (ehdr64.e_phnum);
9427 elf_header.e_shentsize = BYTE_GET (ehdr64.e_shentsize);
9428 elf_header.e_shnum = BYTE_GET (ehdr64.e_shnum);
9429 elf_header.e_shstrndx = BYTE_GET (ehdr64.e_shstrndx);
9432 /* There may be some extensions in the first section header. Don't
9433 bomb if we can't read it. */
9435 get_32bit_section_headers (file, 1);
9437 get_64bit_section_headers (file, 1);
9443 process_file (file_name)
9447 struct stat statbuf;
9450 if (stat (file_name, & statbuf) < 0)
9452 error (_("Cannot stat input file %s.\n"), file_name);
9456 file = fopen (file_name, "rb");
9459 error (_("Input file %s not found.\n"), file_name);
9463 if (! get_file_header (file))
9465 error (_("%s: Failed to read file header\n"), file_name);
9470 /* Initialise per file variables. */
9471 for (i = NUM_ELEM (version_info); i--;)
9472 version_info[i] = 0;
9474 for (i = NUM_ELEM (dynamic_info); i--;)
9475 dynamic_info[i] = 0;
9477 /* Process the file. */
9479 printf (_("\nFile: %s\n"), file_name);
9481 if (! process_file_header ())
9487 process_section_headers (file);
9489 process_program_headers (file);
9491 process_dynamic_segment (file);
9493 process_relocs (file);
9495 process_unwind (file);
9497 process_symbol_table (file);
9499 process_syminfo (file);
9501 process_version_sections (file);
9503 process_section_contents (file);
9505 process_corefile_contents (file);
9507 process_arch_specific (file);
9511 if (section_headers)
9513 free (section_headers);
9514 section_headers = NULL;
9519 free (string_table);
9520 string_table = NULL;
9521 string_table_length = 0;
9524 if (dynamic_strings)
9526 free (dynamic_strings);
9527 dynamic_strings = NULL;
9530 if (dynamic_symbols)
9532 free (dynamic_symbols);
9533 dynamic_symbols = NULL;
9534 num_dynamic_syms = 0;
9537 if (dynamic_syminfo)
9539 free (dynamic_syminfo);
9540 dynamic_syminfo = NULL;
9546 #ifdef SUPPORT_DISASSEMBLY
9547 /* Needed by the i386 disassembler. For extra credit, someone could
9548 fix this so that we insert symbolic addresses here, esp for GOT/PLT
9552 print_address (unsigned int addr, FILE * outfile)
9554 fprintf (outfile,"0x%8.8x", addr);
9557 /* Needed by the i386 disassembler. */
9559 db_task_printsym (unsigned int addr)
9561 print_address (addr, stderr);
9565 int main PARAMS ((int, char **));
9574 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
9575 setlocale (LC_MESSAGES, "");
9577 #if defined (HAVE_SETLOCALE)
9578 setlocale (LC_CTYPE, "");
9580 bindtextdomain (PACKAGE, LOCALEDIR);
9581 textdomain (PACKAGE);
9583 parse_args (argc, argv);
9585 if (optind < (argc - 1))
9589 while (optind < argc)
9590 err |= process_file (argv [optind ++]);
9592 if (dump_sects != NULL)