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. */
622 case EM_CYGNUS_MN10200:
624 case EM_CYGNUS_MN10300:
661 warn (_("Don't know about relocations on this machine architecture\n"));
667 slurp_rela_relocs (file, rel_offset, rel_size, relasp, nrelasp)
669 unsigned long rel_offset;
670 unsigned long rel_size;
671 Elf_Internal_Rela **relasp;
672 unsigned long *nrelasp;
674 Elf_Internal_Rela *relas;
675 unsigned long nrelas;
680 Elf32_External_Rela * erelas;
682 erelas = (Elf32_External_Rela *) get_data (NULL, file, rel_offset,
683 rel_size, _("relocs"));
687 nrelas = rel_size / sizeof (Elf32_External_Rela);
689 relas = (Elf_Internal_Rela *)
690 malloc (nrelas * sizeof (Elf_Internal_Rela));
694 error(_("out of memory parsing relocs"));
698 for (i = 0; i < nrelas; i++)
700 relas[i].r_offset = BYTE_GET (erelas[i].r_offset);
701 relas[i].r_info = BYTE_GET (erelas[i].r_info);
702 relas[i].r_addend = BYTE_GET (erelas[i].r_addend);
709 Elf64_External_Rela * erelas;
711 erelas = (Elf64_External_Rela *) get_data (NULL, file, rel_offset,
712 rel_size, _("relocs"));
716 nrelas = rel_size / sizeof (Elf64_External_Rela);
718 relas = (Elf_Internal_Rela *)
719 malloc (nrelas * sizeof (Elf_Internal_Rela));
723 error(_("out of memory parsing relocs"));
727 for (i = 0; i < nrelas; i++)
729 relas[i].r_offset = BYTE_GET8 (erelas[i].r_offset);
730 relas[i].r_info = BYTE_GET8 (erelas[i].r_info);
731 relas[i].r_addend = BYTE_GET8 (erelas[i].r_addend);
742 slurp_rel_relocs (file, rel_offset, rel_size, relsp, nrelsp)
744 unsigned long rel_offset;
745 unsigned long rel_size;
746 Elf_Internal_Rel **relsp;
747 unsigned long *nrelsp;
749 Elf_Internal_Rel *rels;
755 Elf32_External_Rel * erels;
757 erels = (Elf32_External_Rel *) get_data (NULL, file, rel_offset,
758 rel_size, _("relocs"));
762 nrels = rel_size / sizeof (Elf32_External_Rel);
764 rels = (Elf_Internal_Rel *) malloc (nrels * sizeof (Elf_Internal_Rel));
768 error(_("out of memory parsing relocs"));
772 for (i = 0; i < nrels; i++)
774 rels[i].r_offset = BYTE_GET (erels[i].r_offset);
775 rels[i].r_info = BYTE_GET (erels[i].r_info);
782 Elf64_External_Rel * erels;
784 erels = (Elf64_External_Rel *) get_data (NULL, file, rel_offset,
785 rel_size, _("relocs"));
789 nrels = rel_size / sizeof (Elf64_External_Rel);
791 rels = (Elf_Internal_Rel *) malloc (nrels * sizeof (Elf_Internal_Rel));
795 error(_("out of memory parsing relocs"));
799 for (i = 0; i < nrels; i++)
801 rels[i].r_offset = BYTE_GET8 (erels[i].r_offset);
802 rels[i].r_info = BYTE_GET8 (erels[i].r_info);
812 /* Display the contents of the relocation data found at the specified offset. */
814 dump_relocations (file, rel_offset, rel_size, symtab, nsyms, strtab, is_rela)
816 unsigned long rel_offset;
817 unsigned long rel_size;
818 Elf_Internal_Sym * symtab;
824 Elf_Internal_Rel * rels;
825 Elf_Internal_Rela * relas;
828 if (is_rela == UNKNOWN)
829 is_rela = guess_is_rela (elf_header.e_machine);
833 if (!slurp_rela_relocs (file, rel_offset, rel_size, &relas, &rel_size))
838 if (!slurp_rel_relocs (file, rel_offset, rel_size, &rels, &rel_size))
846 (_(" Offset Info Type Symbol's Value Symbol's Name Addend\n"));
849 (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
855 (_(" Offset Info Type Symbol's Value Symbol's Name Addend\n"));
858 (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
861 for (i = 0; i < rel_size; i++)
866 bfd_vma symtab_index;
871 offset = relas [i].r_offset;
872 info = relas [i].r_info;
876 offset = rels [i].r_offset;
877 info = rels [i].r_info;
882 type = ELF32_R_TYPE (info);
883 symtab_index = ELF32_R_SYM (info);
887 if (elf_header.e_machine == EM_SPARCV9)
888 type = ELF64_R_TYPE_ID (info);
890 type = ELF64_R_TYPE (info);
891 /* The #ifdef BFD64 below is to prevent a compile time warning.
892 We know that if we do not have a 64 bit data type that we
893 will never execute this code anyway. */
895 symtab_index = ELF64_R_SYM (info);
901 #ifdef _bfd_int64_low
902 printf ("%8.8lx %8.8lx ", _bfd_int64_low (offset), _bfd_int64_low (info));
904 printf ("%8.8lx %8.8lx ", offset, info);
909 #ifdef _bfd_int64_low
910 printf ("%8.8lx%8.8lx %8.8lx%8.8lx ",
911 _bfd_int64_high (offset),
912 _bfd_int64_low (offset),
913 _bfd_int64_high (info),
914 _bfd_int64_low (info));
916 printf ("%16.16lx %16.16lx ", offset, info);
920 switch (elf_header.e_machine)
928 rtype = elf_m32r_reloc_type (type);
933 rtype = elf_i386_reloc_type (type);
937 rtype = elf_m68k_reloc_type (type);
941 rtype = elf_i960_reloc_type (type);
946 rtype = elf_avr_reloc_type (type);
953 rtype = elf_sparc_reloc_type (type);
958 rtype = v850_reloc_type (type);
963 rtype = elf_d10v_reloc_type (type);
968 rtype = elf_d30v_reloc_type (type);
972 rtype = elf_sh_reloc_type (type);
976 case EM_CYGNUS_MN10300:
977 rtype = elf_mn10300_reloc_type (type);
981 case EM_CYGNUS_MN10200:
982 rtype = elf_mn10200_reloc_type (type);
987 rtype = elf_fr30_reloc_type (type);
991 rtype = elf_mcore_reloc_type (type);
995 rtype = elf_mmix_reloc_type (type);
1000 rtype = elf_ppc_reloc_type (type);
1004 case EM_MIPS_RS3_LE:
1005 rtype = elf_mips_reloc_type (type);
1009 rtype = elf_alpha_reloc_type (type);
1013 rtype = elf_arm_reloc_type (type);
1017 rtype = elf_arc_reloc_type (type);
1021 rtype = elf_hppa_reloc_type (type);
1027 rtype = elf_h8_reloc_type (type);
1032 rtype = elf_pj_reloc_type (type);
1035 rtype = elf_ia64_reloc_type (type);
1039 rtype = elf_cris_reloc_type (type);
1043 rtype = elf_i860_reloc_type (type);
1047 rtype = elf_x86_64_reloc_type (type);
1052 rtype = elf_s390_reloc_type (type);
1056 rtype = elf_xstormy16_reloc_type (type);
1061 #ifdef _bfd_int64_low
1062 printf (_("unrecognised: %-7lx"), _bfd_int64_low (type));
1064 printf (_("unrecognised: %-7lx"), type);
1067 printf ("%-21.21s", rtype);
1071 if (symtab == NULL || symtab_index >= nsyms)
1072 printf (" bad symbol index: %08lx", (unsigned long) symtab_index);
1075 Elf_Internal_Sym * psym;
1077 psym = symtab + symtab_index;
1080 print_vma (psym->st_value, LONG_HEX);
1083 if (psym->st_name == 0)
1084 print_symbol (-25, SECTION_NAME (section_headers + psym->st_shndx));
1085 else if (strtab == NULL)
1086 printf (_("<string table index %3ld>"), psym->st_name);
1088 print_symbol (-25, strtab + psym->st_name);
1091 printf (" + %lx", (unsigned long) relas [i].r_addend);
1096 printf ("%*c", is_32bit_elf ? 34 : 26, ' ');
1097 print_vma (relas[i].r_addend, LONG_HEX);
1100 if (elf_header.e_machine == EM_SPARCV9
1101 && !strcmp (rtype, "R_SPARC_OLO10"))
1102 printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (info));
1116 get_mips_dynamic_type (type)
1121 case DT_MIPS_RLD_VERSION: return "MIPS_RLD_VERSION";
1122 case DT_MIPS_TIME_STAMP: return "MIPS_TIME_STAMP";
1123 case DT_MIPS_ICHECKSUM: return "MIPS_ICHECKSUM";
1124 case DT_MIPS_IVERSION: return "MIPS_IVERSION";
1125 case DT_MIPS_FLAGS: return "MIPS_FLAGS";
1126 case DT_MIPS_BASE_ADDRESS: return "MIPS_BASE_ADDRESS";
1127 case DT_MIPS_MSYM: return "MIPS_MSYM";
1128 case DT_MIPS_CONFLICT: return "MIPS_CONFLICT";
1129 case DT_MIPS_LIBLIST: return "MIPS_LIBLIST";
1130 case DT_MIPS_LOCAL_GOTNO: return "MIPS_LOCAL_GOTNO";
1131 case DT_MIPS_CONFLICTNO: return "MIPS_CONFLICTNO";
1132 case DT_MIPS_LIBLISTNO: return "MIPS_LIBLISTNO";
1133 case DT_MIPS_SYMTABNO: return "MIPS_SYMTABNO";
1134 case DT_MIPS_UNREFEXTNO: return "MIPS_UNREFEXTNO";
1135 case DT_MIPS_GOTSYM: return "MIPS_GOTSYM";
1136 case DT_MIPS_HIPAGENO: return "MIPS_HIPAGENO";
1137 case DT_MIPS_RLD_MAP: return "MIPS_RLD_MAP";
1138 case DT_MIPS_DELTA_CLASS: return "MIPS_DELTA_CLASS";
1139 case DT_MIPS_DELTA_CLASS_NO: return "MIPS_DELTA_CLASS_NO";
1140 case DT_MIPS_DELTA_INSTANCE: return "MIPS_DELTA_INSTANCE";
1141 case DT_MIPS_DELTA_INSTANCE_NO: return "MIPS_DELTA_INSTANCE_NO";
1142 case DT_MIPS_DELTA_RELOC: return "MIPS_DELTA_RELOC";
1143 case DT_MIPS_DELTA_RELOC_NO: return "MIPS_DELTA_RELOC_NO";
1144 case DT_MIPS_DELTA_SYM: return "MIPS_DELTA_SYM";
1145 case DT_MIPS_DELTA_SYM_NO: return "MIPS_DELTA_SYM_NO";
1146 case DT_MIPS_DELTA_CLASSSYM: return "MIPS_DELTA_CLASSSYM";
1147 case DT_MIPS_DELTA_CLASSSYM_NO: return "MIPS_DELTA_CLASSSYM_NO";
1148 case DT_MIPS_CXX_FLAGS: return "MIPS_CXX_FLAGS";
1149 case DT_MIPS_PIXIE_INIT: return "MIPS_PIXIE_INIT";
1150 case DT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB";
1151 case DT_MIPS_LOCALPAGE_GOTIDX: return "MIPS_LOCALPAGE_GOTIDX";
1152 case DT_MIPS_LOCAL_GOTIDX: return "MIPS_LOCAL_GOTIDX";
1153 case DT_MIPS_HIDDEN_GOTIDX: return "MIPS_HIDDEN_GOTIDX";
1154 case DT_MIPS_PROTECTED_GOTIDX: return "MIPS_PROTECTED_GOTIDX";
1155 case DT_MIPS_OPTIONS: return "MIPS_OPTIONS";
1156 case DT_MIPS_INTERFACE: return "MIPS_INTERFACE";
1157 case DT_MIPS_DYNSTR_ALIGN: return "MIPS_DYNSTR_ALIGN";
1158 case DT_MIPS_INTERFACE_SIZE: return "MIPS_INTERFACE_SIZE";
1159 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
1160 case DT_MIPS_PERF_SUFFIX: return "MIPS_PERF_SUFFIX";
1161 case DT_MIPS_COMPACT_SIZE: return "MIPS_COMPACT_SIZE";
1162 case DT_MIPS_GP_VALUE: return "MIPS_GP_VALUE";
1163 case DT_MIPS_AUX_DYNAMIC: return "MIPS_AUX_DYNAMIC";
1170 get_sparc64_dynamic_type (type)
1175 case DT_SPARC_REGISTER: return "SPARC_REGISTER";
1182 get_ppc64_dynamic_type (type)
1187 case DT_PPC64_GLINK: return "PPC64_GLINK";
1194 get_parisc_dynamic_type (type)
1199 case DT_HP_LOAD_MAP: return "HP_LOAD_MAP";
1200 case DT_HP_DLD_FLAGS: return "HP_DLD_FLAGS";
1201 case DT_HP_DLD_HOOK: return "HP_DLD_HOOK";
1202 case DT_HP_UX10_INIT: return "HP_UX10_INIT";
1203 case DT_HP_UX10_INITSZ: return "HP_UX10_INITSZ";
1204 case DT_HP_PREINIT: return "HP_PREINIT";
1205 case DT_HP_PREINITSZ: return "HP_PREINITSZ";
1206 case DT_HP_NEEDED: return "HP_NEEDED";
1207 case DT_HP_TIME_STAMP: return "HP_TIME_STAMP";
1208 case DT_HP_CHECKSUM: return "HP_CHECKSUM";
1209 case DT_HP_GST_SIZE: return "HP_GST_SIZE";
1210 case DT_HP_GST_VERSION: return "HP_GST_VERSION";
1211 case DT_HP_GST_HASHVAL: return "HP_GST_HASHVAL";
1218 get_dynamic_type (type)
1221 static char buff [32];
1225 case DT_NULL: return "NULL";
1226 case DT_NEEDED: return "NEEDED";
1227 case DT_PLTRELSZ: return "PLTRELSZ";
1228 case DT_PLTGOT: return "PLTGOT";
1229 case DT_HASH: return "HASH";
1230 case DT_STRTAB: return "STRTAB";
1231 case DT_SYMTAB: return "SYMTAB";
1232 case DT_RELA: return "RELA";
1233 case DT_RELASZ: return "RELASZ";
1234 case DT_RELAENT: return "RELAENT";
1235 case DT_STRSZ: return "STRSZ";
1236 case DT_SYMENT: return "SYMENT";
1237 case DT_INIT: return "INIT";
1238 case DT_FINI: return "FINI";
1239 case DT_SONAME: return "SONAME";
1240 case DT_RPATH: return "RPATH";
1241 case DT_SYMBOLIC: return "SYMBOLIC";
1242 case DT_REL: return "REL";
1243 case DT_RELSZ: return "RELSZ";
1244 case DT_RELENT: return "RELENT";
1245 case DT_PLTREL: return "PLTREL";
1246 case DT_DEBUG: return "DEBUG";
1247 case DT_TEXTREL: return "TEXTREL";
1248 case DT_JMPREL: return "JMPREL";
1249 case DT_BIND_NOW: return "BIND_NOW";
1250 case DT_INIT_ARRAY: return "INIT_ARRAY";
1251 case DT_FINI_ARRAY: return "FINI_ARRAY";
1252 case DT_INIT_ARRAYSZ: return "INIT_ARRAYSZ";
1253 case DT_FINI_ARRAYSZ: return "FINI_ARRAYSZ";
1254 case DT_RUNPATH: return "RUNPATH";
1255 case DT_FLAGS: return "FLAGS";
1257 case DT_PREINIT_ARRAY: return "PREINIT_ARRAY";
1258 case DT_PREINIT_ARRAYSZ: return "PREINIT_ARRAYSZ";
1260 case DT_CHECKSUM: return "CHECKSUM";
1261 case DT_PLTPADSZ: return "PLTPADSZ";
1262 case DT_MOVEENT: return "MOVEENT";
1263 case DT_MOVESZ: return "MOVESZ";
1264 case DT_FEATURE: return "FEATURE";
1265 case DT_POSFLAG_1: return "POSFLAG_1";
1266 case DT_SYMINSZ: return "SYMINSZ";
1267 case DT_SYMINENT: return "SYMINENT"; /* aka VALRNGHI */
1269 case DT_ADDRRNGLO: return "ADDRRNGLO";
1270 case DT_CONFIG: return "CONFIG";
1271 case DT_DEPAUDIT: return "DEPAUDIT";
1272 case DT_AUDIT: return "AUDIT";
1273 case DT_PLTPAD: return "PLTPAD";
1274 case DT_MOVETAB: return "MOVETAB";
1275 case DT_SYMINFO: return "SYMINFO"; /* aka ADDRRNGHI */
1277 case DT_VERSYM: return "VERSYM";
1279 case DT_RELACOUNT: return "RELACOUNT";
1280 case DT_RELCOUNT: return "RELCOUNT";
1281 case DT_FLAGS_1: return "FLAGS_1";
1282 case DT_VERDEF: return "VERDEF";
1283 case DT_VERDEFNUM: return "VERDEFNUM";
1284 case DT_VERNEED: return "VERNEED";
1285 case DT_VERNEEDNUM: return "VERNEEDNUM";
1287 case DT_AUXILIARY: return "AUXILIARY";
1288 case DT_USED: return "USED";
1289 case DT_FILTER: return "FILTER";
1292 if ((type >= DT_LOPROC) && (type <= DT_HIPROC))
1294 const char * result;
1296 switch (elf_header.e_machine)
1299 case EM_MIPS_RS3_LE:
1300 result = get_mips_dynamic_type (type);
1303 result = get_sparc64_dynamic_type (type);
1306 result = get_ppc64_dynamic_type (type);
1316 sprintf (buff, _("Processor Specific: %lx"), type);
1318 else if ((type >= DT_LOOS) && (type <= DT_HIOS))
1320 const char * result;
1322 switch (elf_header.e_machine)
1325 result = get_parisc_dynamic_type (type);
1335 sprintf (buff, _("Operating System specific: %lx"), type);
1338 sprintf (buff, _("<unknown>: %lx"), type);
1345 get_file_type (e_type)
1348 static char buff [32];
1352 case ET_NONE: return _("NONE (None)");
1353 case ET_REL: return _("REL (Relocatable file)");
1354 case ET_EXEC: return _("EXEC (Executable file)");
1355 case ET_DYN: return _("DYN (Shared object file)");
1356 case ET_CORE: return _("CORE (Core file)");
1359 if ((e_type >= ET_LOPROC) && (e_type <= ET_HIPROC))
1360 sprintf (buff, _("Processor Specific: (%x)"), e_type);
1361 else if ((e_type >= ET_LOOS) && (e_type <= ET_HIOS))
1362 sprintf (buff, _("OS Specific: (%x)"), e_type);
1364 sprintf (buff, _("<unknown>: %x"), e_type);
1370 get_machine_name (e_machine)
1373 static char buff [64]; /* XXX */
1377 case EM_NONE: return _("None");
1378 case EM_M32: return "WE32100";
1379 case EM_SPARC: return "Sparc";
1380 case EM_386: return "Intel 80386";
1381 case EM_68K: return "MC68000";
1382 case EM_88K: return "MC88000";
1383 case EM_486: return "Intel 80486";
1384 case EM_860: return "Intel 80860";
1385 case EM_MIPS: return "MIPS R3000";
1386 case EM_S370: return "IBM System/370";
1387 case EM_MIPS_RS3_LE: return "MIPS R4000 big-endian";
1388 case EM_OLD_SPARCV9: return "Sparc v9 (old)";
1389 case EM_PARISC: return "HPPA";
1390 case EM_PPC_OLD: return "Power PC (old)";
1391 case EM_SPARC32PLUS: return "Sparc v8+" ;
1392 case EM_960: return "Intel 90860";
1393 case EM_PPC: return "PowerPC";
1394 case EM_PPC64: return "PowerPC64";
1395 case EM_V800: return "NEC V800";
1396 case EM_FR20: return "Fujitsu FR20";
1397 case EM_RH32: return "TRW RH32";
1398 case EM_MCORE: return "MCORE";
1399 case EM_ARM: return "ARM";
1400 case EM_OLD_ALPHA: return "Digital Alpha (old)";
1401 case EM_SH: return "Hitachi SH";
1402 case EM_SPARCV9: return "Sparc v9";
1403 case EM_TRICORE: return "Siemens Tricore";
1404 case EM_ARC: return "ARC";
1405 case EM_H8_300: return "Hitachi H8/300";
1406 case EM_H8_300H: return "Hitachi H8/300H";
1407 case EM_H8S: return "Hitachi H8S";
1408 case EM_H8_500: return "Hitachi H8/500";
1409 case EM_IA_64: return "Intel IA-64";
1410 case EM_MIPS_X: return "Stanford MIPS-X";
1411 case EM_COLDFIRE: return "Motorola Coldfire";
1412 case EM_68HC12: return "Motorola M68HC12";
1413 case EM_ALPHA: return "Alpha";
1414 case EM_CYGNUS_D10V:
1415 case EM_D10V: return "d10v";
1416 case EM_CYGNUS_D30V:
1417 case EM_D30V: return "d30v";
1418 case EM_CYGNUS_M32R:
1419 case EM_M32R: return "Mitsubishi M32r";
1420 case EM_CYGNUS_V850:
1421 case EM_V850: return "NEC v850";
1422 case EM_CYGNUS_MN10300:
1423 case EM_MN10300: return "mn10300";
1424 case EM_CYGNUS_MN10200:
1425 case EM_MN10200: return "mn10200";
1426 case EM_CYGNUS_FR30:
1427 case EM_FR30: return "Fujitsu FR30";
1429 case EM_PJ: return "picoJava";
1430 case EM_MMA: return "Fujitsu Multimedia Accelerator";
1431 case EM_PCP: return "Siemens PCP";
1432 case EM_NCPU: return "Sony nCPU embedded RISC processor";
1433 case EM_NDR1: return "Denso NDR1 microprocesspr";
1434 case EM_STARCORE: return "Motorola Star*Core processor";
1435 case EM_ME16: return "Toyota ME16 processor";
1436 case EM_ST100: return "STMicroelectronics ST100 processor";
1437 case EM_TINYJ: return "Advanced Logic Corp. TinyJ embedded processor";
1438 case EM_FX66: return "Siemens FX66 microcontroller";
1439 case EM_ST9PLUS: return "STMicroelectronics ST9+ 8/16 bit microcontroller";
1440 case EM_ST7: return "STMicroelectronics ST7 8-bit microcontroller";
1441 case EM_68HC16: return "Motorola MC68HC16 Microcontroller";
1442 case EM_68HC11: return "Motorola MC68HC11 Microcontroller";
1443 case EM_68HC08: return "Motorola MC68HC08 Microcontroller";
1444 case EM_68HC05: return "Motorola MC68HC05 Microcontroller";
1445 case EM_SVX: return "Silicon Graphics SVx";
1446 case EM_ST19: return "STMicroelectronics ST19 8-bit microcontroller";
1447 case EM_VAX: return "Digital VAX";
1449 case EM_AVR: return "Atmel AVR 8-bit microcontroller";
1450 case EM_CRIS: return "Axis Communications 32-bit embedded processor";
1451 case EM_JAVELIN: return "Infineon Technologies 32-bit embedded cpu";
1452 case EM_FIREPATH: return "Element 14 64-bit DSP processor";
1453 case EM_ZSP: return "LSI Logic's 16-bit DSP processor";
1454 case EM_MMIX: return "Donald Knuth's educational 64-bit processor";
1455 case EM_HUANY: return "Harvard Universitys's machine-independent object format";
1456 case EM_PRISM: return "SiTera Prism";
1457 case EM_X86_64: return "Advanced Micro Devices X86-64";
1459 case EM_S390: return "IBM S/390";
1460 case EM_XSTORMY16: return "Sanyo Xstormy16 CPU core";
1462 sprintf (buff, _("<unknown>: %x"), e_machine);
1468 decode_ARM_machine_flags (e_flags, buf)
1475 eabi = EF_ARM_EABI_VERSION (e_flags);
1476 e_flags &= ~ EF_ARM_EABIMASK;
1478 /* Handle "generic" ARM flags. */
1479 if (e_flags & EF_ARM_RELEXEC)
1481 strcat (buf, ", relocatable executable");
1482 e_flags &= ~ EF_ARM_RELEXEC;
1485 if (e_flags & EF_ARM_HASENTRY)
1487 strcat (buf, ", has entry point");
1488 e_flags &= ~ EF_ARM_HASENTRY;
1491 /* Now handle EABI specific flags. */
1495 strcat (buf, ", <unrecognised EABI>");
1500 case EF_ARM_EABI_VER1:
1501 strcat (buf, ", Version1 EABI");
1506 /* Process flags one bit at a time. */
1507 flag = e_flags & - e_flags;
1512 case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK. */
1513 strcat (buf, ", sorted symbol tables");
1523 case EF_ARM_EABI_VER2:
1524 strcat (buf, ", Version2 EABI");
1529 /* Process flags one bit at a time. */
1530 flag = e_flags & - e_flags;
1535 case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK. */
1536 strcat (buf, ", sorted symbol tables");
1539 case EF_ARM_DYNSYMSUSESEGIDX:
1540 strcat (buf, ", dynamic symbols use segment index");
1543 case EF_ARM_MAPSYMSFIRST:
1544 strcat (buf, ", mapping symbols precede others");
1554 case EF_ARM_EABI_UNKNOWN:
1555 strcat (buf, ", GNU EABI");
1560 /* Process flags one bit at a time. */
1561 flag = e_flags & - e_flags;
1566 case EF_ARM_INTERWORK:
1567 strcat (buf, ", interworking enabled");
1570 case EF_ARM_APCS_26:
1571 strcat (buf, ", uses APCS/26");
1574 case EF_ARM_APCS_FLOAT:
1575 strcat (buf, ", uses APCS/float");
1579 strcat (buf, ", position independent");
1583 strcat (buf, ", 8 bit structure alignment");
1586 case EF_ARM_NEW_ABI:
1587 strcat (buf, ", uses new ABI");
1590 case EF_ARM_OLD_ABI:
1591 strcat (buf, ", uses old ABI");
1594 case EF_ARM_SOFT_FLOAT:
1595 strcat (buf, ", software FP");
1606 strcat (buf,", <unknown>");
1610 get_machine_flags (e_flags, e_machine)
1614 static char buf [1024];
1626 decode_ARM_machine_flags (e_flags, buf);
1630 if (e_flags & EF_CPU32)
1631 strcat (buf, ", cpu32");
1635 if (e_flags & EF_PPC_EMB)
1636 strcat (buf, ", emb");
1638 if (e_flags & EF_PPC_RELOCATABLE)
1639 strcat (buf, ", relocatable");
1641 if (e_flags & EF_PPC_RELOCATABLE_LIB)
1642 strcat (buf, ", relocatable-lib");
1646 case EM_CYGNUS_V850:
1647 switch (e_flags & EF_V850_ARCH)
1650 strcat (buf, ", v850e");
1653 strcat (buf, ", v850ea");
1656 strcat (buf, ", v850");
1659 strcat (buf, ", unknown v850 architecture variant");
1665 case EM_CYGNUS_M32R:
1666 if ((e_flags & EF_M32R_ARCH) == E_M32R_ARCH)
1667 strcat (buf, ", m32r");
1672 case EM_MIPS_RS3_LE:
1673 if (e_flags & EF_MIPS_NOREORDER)
1674 strcat (buf, ", noreorder");
1676 if (e_flags & EF_MIPS_PIC)
1677 strcat (buf, ", pic");
1679 if (e_flags & EF_MIPS_CPIC)
1680 strcat (buf, ", cpic");
1682 if (e_flags & EF_MIPS_UCODE)
1683 strcat (buf, ", ugen_reserved");
1685 if (e_flags & EF_MIPS_ABI2)
1686 strcat (buf, ", abi2");
1688 if (e_flags & EF_MIPS_OPTIONS_FIRST)
1689 strcat (buf, ", odk first");
1691 if (e_flags & EF_MIPS_32BITMODE)
1692 strcat (buf, ", 32bitmode");
1694 switch ((e_flags & EF_MIPS_MACH))
1696 case E_MIPS_MACH_3900: strcat (buf, ", 3900"); break;
1697 case E_MIPS_MACH_4010: strcat (buf, ", 4010"); break;
1698 case E_MIPS_MACH_4100: strcat (buf, ", 4100"); break;
1699 case E_MIPS_MACH_4650: strcat (buf, ", 4650"); break;
1700 case E_MIPS_MACH_4111: strcat (buf, ", 4111"); break;
1701 case E_MIPS_MACH_SB1: strcat (buf, ", sb1"); break;
1703 /* We simply ignore the field in this case to avoid confusion:
1704 MIPS ELF does not specify EF_MIPS_MACH, it is a GNU
1707 default: strcat (buf, ", unknown CPU"); break;
1710 switch ((e_flags & EF_MIPS_ABI))
1712 case E_MIPS_ABI_O32: strcat (buf, ", o32"); break;
1713 case E_MIPS_ABI_O64: strcat (buf, ", o64"); break;
1714 case E_MIPS_ABI_EABI32: strcat (buf, ", eabi32"); break;
1715 case E_MIPS_ABI_EABI64: strcat (buf, ", eabi64"); break;
1717 /* We simply ignore the field in this case to avoid confusion:
1718 MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension.
1719 This means it is likely to be an o32 file, but not for
1722 default: strcat (buf, ", unknown ABI"); break;
1725 if (e_flags & EF_MIPS_ARCH_ASE_MDMX)
1726 strcat (buf, ", mdmx");
1728 if (e_flags & EF_MIPS_ARCH_ASE_M16)
1729 strcat (buf, ", mips16");
1731 switch ((e_flags & EF_MIPS_ARCH))
1733 case E_MIPS_ARCH_1: strcat (buf, ", mips1"); break;
1734 case E_MIPS_ARCH_2: strcat (buf, ", mips2"); break;
1735 case E_MIPS_ARCH_3: strcat (buf, ", mips3"); break;
1736 case E_MIPS_ARCH_4: strcat (buf, ", mips4"); break;
1737 case E_MIPS_ARCH_5: strcat (buf, ", mips5"); break;
1738 case E_MIPS_ARCH_32: strcat (buf, ", mips32"); break;
1739 case E_MIPS_ARCH_64: strcat (buf, ", mips64"); break;
1740 default: strcat (buf, ", unknown ISA"); break;
1746 if (e_flags & EF_SPARC_32PLUS)
1747 strcat (buf, ", v8+");
1749 if (e_flags & EF_SPARC_SUN_US1)
1750 strcat (buf, ", ultrasparcI");
1752 if (e_flags & EF_SPARC_SUN_US3)
1753 strcat (buf, ", ultrasparcIII");
1755 if (e_flags & EF_SPARC_HAL_R1)
1756 strcat (buf, ", halr1");
1758 if (e_flags & EF_SPARC_LEDATA)
1759 strcat (buf, ", ledata");
1761 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_TSO)
1762 strcat (buf, ", tso");
1764 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_PSO)
1765 strcat (buf, ", pso");
1767 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_RMO)
1768 strcat (buf, ", rmo");
1772 switch (e_flags & EF_PARISC_ARCH)
1774 case EFA_PARISC_1_0:
1775 strcpy (buf, ", PA-RISC 1.0");
1777 case EFA_PARISC_1_1:
1778 strcpy (buf, ", PA-RISC 1.1");
1780 case EFA_PARISC_2_0:
1781 strcpy (buf, ", PA-RISC 2.0");
1786 if (e_flags & EF_PARISC_TRAPNIL)
1787 strcat (buf, ", trapnil");
1788 if (e_flags & EF_PARISC_EXT)
1789 strcat (buf, ", ext");
1790 if (e_flags & EF_PARISC_LSB)
1791 strcat (buf, ", lsb");
1792 if (e_flags & EF_PARISC_WIDE)
1793 strcat (buf, ", wide");
1794 if (e_flags & EF_PARISC_NO_KABP)
1795 strcat (buf, ", no kabp");
1796 if (e_flags & EF_PARISC_LAZYSWAP)
1797 strcat (buf, ", lazyswap");
1802 if ((e_flags & EF_PICOJAVA_NEWCALLS) == EF_PICOJAVA_NEWCALLS)
1803 strcat (buf, ", new calling convention");
1805 if ((e_flags & EF_PICOJAVA_GNUCALLS) == EF_PICOJAVA_GNUCALLS)
1806 strcat (buf, ", gnu calling convention");
1810 if ((e_flags & EF_IA_64_ABI64))
1811 strcat (buf, ", 64-bit");
1813 strcat (buf, ", 32-bit");
1814 if ((e_flags & EF_IA_64_REDUCEDFP))
1815 strcat (buf, ", reduced fp model");
1816 if ((e_flags & EF_IA_64_NOFUNCDESC_CONS_GP))
1817 strcat (buf, ", no function descriptors, constant gp");
1818 else if ((e_flags & EF_IA_64_CONS_GP))
1819 strcat (buf, ", constant gp");
1820 if ((e_flags & EF_IA_64_ABSOLUTE))
1821 strcat (buf, ", absolute");
1830 get_mips_segment_type (type)
1835 case PT_MIPS_REGINFO:
1837 case PT_MIPS_RTPROC:
1839 case PT_MIPS_OPTIONS:
1849 get_parisc_segment_type (type)
1854 case PT_HP_TLS: return "HP_TLS";
1855 case PT_HP_CORE_NONE: return "HP_CORE_NONE";
1856 case PT_HP_CORE_VERSION: return "HP_CORE_VERSION";
1857 case PT_HP_CORE_KERNEL: return "HP_CORE_KERNEL";
1858 case PT_HP_CORE_COMM: return "HP_CORE_COMM";
1859 case PT_HP_CORE_PROC: return "HP_CORE_PROC";
1860 case PT_HP_CORE_LOADABLE: return "HP_CORE_LOADABLE";
1861 case PT_HP_CORE_STACK: return "HP_CORE_STACK";
1862 case PT_HP_CORE_SHM: return "HP_CORE_SHM";
1863 case PT_HP_CORE_MMF: return "HP_CORE_MMF";
1864 case PT_HP_PARALLEL: return "HP_PARALLEL";
1865 case PT_HP_FASTBIND: return "HP_FASTBIND";
1866 case PT_PARISC_ARCHEXT: return "PARISC_ARCHEXT";
1867 case PT_PARISC_UNWIND: return "PARISC_UNWIND";
1876 get_ia64_segment_type (type)
1881 case PT_IA_64_ARCHEXT: return "IA_64_ARCHEXT";
1882 case PT_IA_64_UNWIND: return "IA_64_UNWIND";
1883 case PT_HP_TLS: return "HP_TLS";
1884 case PT_IA_64_HP_OPT_ANOT: return "HP_OPT_ANNOT";
1885 case PT_IA_64_HP_HSL_ANOT: return "HP_HSL_ANNOT";
1886 case PT_IA_64_HP_STACK: return "HP_STACK";
1895 get_segment_type (p_type)
1896 unsigned long p_type;
1898 static char buff [32];
1902 case PT_NULL: return "NULL";
1903 case PT_LOAD: return "LOAD";
1904 case PT_DYNAMIC: return "DYNAMIC";
1905 case PT_INTERP: return "INTERP";
1906 case PT_NOTE: return "NOTE";
1907 case PT_SHLIB: return "SHLIB";
1908 case PT_PHDR: return "PHDR";
1910 case PT_GNU_EH_FRAME:
1911 return "GNU_EH_FRAME";
1914 if ((p_type >= PT_LOPROC) && (p_type <= PT_HIPROC))
1916 const char * result;
1918 switch (elf_header.e_machine)
1921 case EM_MIPS_RS3_LE:
1922 result = get_mips_segment_type (p_type);
1925 result = get_parisc_segment_type (p_type);
1928 result = get_ia64_segment_type (p_type);
1938 sprintf (buff, "LOPROC+%lx", p_type - PT_LOPROC);
1940 else if ((p_type >= PT_LOOS) && (p_type <= PT_HIOS))
1942 const char * result;
1944 switch (elf_header.e_machine)
1947 result = get_parisc_segment_type (p_type);
1950 result = get_ia64_segment_type (p_type);
1960 sprintf (buff, "LOOS+%lx", p_type - PT_LOOS);
1963 sprintf (buff, _("<unknown>: %lx"), p_type);
1970 get_mips_section_type_name (sh_type)
1971 unsigned int sh_type;
1975 case SHT_MIPS_LIBLIST: return "MIPS_LIBLIST";
1976 case SHT_MIPS_MSYM: return "MIPS_MSYM";
1977 case SHT_MIPS_CONFLICT: return "MIPS_CONFLICT";
1978 case SHT_MIPS_GPTAB: return "MIPS_GPTAB";
1979 case SHT_MIPS_UCODE: return "MIPS_UCODE";
1980 case SHT_MIPS_DEBUG: return "MIPS_DEBUG";
1981 case SHT_MIPS_REGINFO: return "MIPS_REGINFO";
1982 case SHT_MIPS_PACKAGE: return "MIPS_PACKAGE";
1983 case SHT_MIPS_PACKSYM: return "MIPS_PACKSYM";
1984 case SHT_MIPS_RELD: return "MIPS_RELD";
1985 case SHT_MIPS_IFACE: return "MIPS_IFACE";
1986 case SHT_MIPS_CONTENT: return "MIPS_CONTENT";
1987 case SHT_MIPS_OPTIONS: return "MIPS_OPTIONS";
1988 case SHT_MIPS_SHDR: return "MIPS_SHDR";
1989 case SHT_MIPS_FDESC: return "MIPS_FDESC";
1990 case SHT_MIPS_EXTSYM: return "MIPS_EXTSYM";
1991 case SHT_MIPS_DENSE: return "MIPS_DENSE";
1992 case SHT_MIPS_PDESC: return "MIPS_PDESC";
1993 case SHT_MIPS_LOCSYM: return "MIPS_LOCSYM";
1994 case SHT_MIPS_AUXSYM: return "MIPS_AUXSYM";
1995 case SHT_MIPS_OPTSYM: return "MIPS_OPTSYM";
1996 case SHT_MIPS_LOCSTR: return "MIPS_LOCSTR";
1997 case SHT_MIPS_LINE: return "MIPS_LINE";
1998 case SHT_MIPS_RFDESC: return "MIPS_RFDESC";
1999 case SHT_MIPS_DELTASYM: return "MIPS_DELTASYM";
2000 case SHT_MIPS_DELTAINST: return "MIPS_DELTAINST";
2001 case SHT_MIPS_DELTACLASS: return "MIPS_DELTACLASS";
2002 case SHT_MIPS_DWARF: return "MIPS_DWARF";
2003 case SHT_MIPS_DELTADECL: return "MIPS_DELTADECL";
2004 case SHT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB";
2005 case SHT_MIPS_EVENTS: return "MIPS_EVENTS";
2006 case SHT_MIPS_TRANSLATE: return "MIPS_TRANSLATE";
2007 case SHT_MIPS_PIXIE: return "MIPS_PIXIE";
2008 case SHT_MIPS_XLATE: return "MIPS_XLATE";
2009 case SHT_MIPS_XLATE_DEBUG: return "MIPS_XLATE_DEBUG";
2010 case SHT_MIPS_WHIRL: return "MIPS_WHIRL";
2011 case SHT_MIPS_EH_REGION: return "MIPS_EH_REGION";
2012 case SHT_MIPS_XLATE_OLD: return "MIPS_XLATE_OLD";
2013 case SHT_MIPS_PDR_EXCEPTION: return "MIPS_PDR_EXCEPTION";
2021 get_parisc_section_type_name (sh_type)
2022 unsigned int sh_type;
2026 case SHT_PARISC_EXT: return "PARISC_EXT";
2027 case SHT_PARISC_UNWIND: return "PARISC_UNWIND";
2028 case SHT_PARISC_DOC: return "PARISC_DOC";
2036 get_ia64_section_type_name (sh_type)
2037 unsigned int sh_type;
2041 case SHT_IA_64_EXT: return "IA_64_EXT";
2042 case SHT_IA_64_UNWIND: return "IA_64_UNWIND";
2050 get_section_type_name (sh_type)
2051 unsigned int sh_type;
2053 static char buff [32];
2057 case SHT_NULL: return "NULL";
2058 case SHT_PROGBITS: return "PROGBITS";
2059 case SHT_SYMTAB: return "SYMTAB";
2060 case SHT_STRTAB: return "STRTAB";
2061 case SHT_RELA: return "RELA";
2062 case SHT_HASH: return "HASH";
2063 case SHT_DYNAMIC: return "DYNAMIC";
2064 case SHT_NOTE: return "NOTE";
2065 case SHT_NOBITS: return "NOBITS";
2066 case SHT_REL: return "REL";
2067 case SHT_SHLIB: return "SHLIB";
2068 case SHT_DYNSYM: return "DYNSYM";
2069 case SHT_INIT_ARRAY: return "INIT_ARRAY";
2070 case SHT_FINI_ARRAY: return "FINI_ARRAY";
2071 case SHT_PREINIT_ARRAY: return "PREINIT_ARRAY";
2072 case SHT_GROUP: return "GROUP";
2073 case SHT_SYMTAB_SHNDX: return "SYMTAB SECTION INDICIES";
2074 case SHT_GNU_verdef: return "VERDEF";
2075 case SHT_GNU_verneed: return "VERNEED";
2076 case SHT_GNU_versym: return "VERSYM";
2077 case 0x6ffffff0: return "VERSYM";
2078 case 0x6ffffffc: return "VERDEF";
2079 case 0x7ffffffd: return "AUXILIARY";
2080 case 0x7fffffff: return "FILTER";
2083 if ((sh_type >= SHT_LOPROC) && (sh_type <= SHT_HIPROC))
2085 const char * result;
2087 switch (elf_header.e_machine)
2090 case EM_MIPS_RS3_LE:
2091 result = get_mips_section_type_name (sh_type);
2094 result = get_parisc_section_type_name (sh_type);
2097 result = get_ia64_section_type_name (sh_type);
2107 sprintf (buff, "LOPROC+%x", sh_type - SHT_LOPROC);
2109 else if ((sh_type >= SHT_LOOS) && (sh_type <= SHT_HIOS))
2110 sprintf (buff, "LOOS+%x", sh_type - SHT_LOOS);
2111 else if ((sh_type >= SHT_LOUSER) && (sh_type <= SHT_HIUSER))
2112 sprintf (buff, "LOUSER+%x", sh_type - SHT_LOUSER);
2114 sprintf (buff, _("<unknown>: %x"), sh_type);
2120 struct option options [] =
2122 {"all", no_argument, 0, 'a'},
2123 {"file-header", no_argument, 0, 'h'},
2124 {"program-headers", no_argument, 0, 'l'},
2125 {"headers", no_argument, 0, 'e'},
2126 {"histogram", no_argument, 0, 'I'},
2127 {"segments", no_argument, 0, 'l'},
2128 {"sections", no_argument, 0, 'S'},
2129 {"section-headers", no_argument, 0, 'S'},
2130 {"symbols", no_argument, 0, 's'},
2131 {"syms", no_argument, 0, 's'},
2132 {"relocs", no_argument, 0, 'r'},
2133 {"notes", no_argument, 0, 'n'},
2134 {"dynamic", no_argument, 0, 'd'},
2135 {"arch-specific", no_argument, 0, 'A'},
2136 {"version-info", no_argument, 0, 'V'},
2137 {"use-dynamic", no_argument, 0, 'D'},
2138 {"hex-dump", required_argument, 0, 'x'},
2139 {"debug-dump", optional_argument, 0, 'w'},
2140 {"unwind", no_argument, 0, 'u'},
2141 #ifdef SUPPORT_DISASSEMBLY
2142 {"instruction-dump", required_argument, 0, 'i'},
2145 {"version", no_argument, 0, 'v'},
2146 {"wide", no_argument, 0, 'W'},
2147 {"help", no_argument, 0, 'H'},
2148 {0, no_argument, 0, 0}
2154 fprintf (stdout, _("Usage: readelf <option(s)> elf-file(s)\n"));
2155 fprintf (stdout, _(" Display information about the contents of ELF format files\n"));
2156 fprintf (stdout, _(" Options are:\n\
2157 -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n\
2158 -h --file-header Display the ELF file header\n\
2159 -l --program-headers Display the program headers\n\
2160 --segments An alias for --program-headers\n\
2161 -S --section-headers Display the sections' header\n\
2162 --sections An alias for --section-headers\n\
2163 -e --headers Equivalent to: -h -l -S\n\
2164 -s --syms Display the symbol table\n\
2165 --symbols An alias for --syms\n\
2166 -n --notes Display the core notes (if present)\n\
2167 -r --relocs Display the relocations (if present)\n\
2168 -u --unwind Display the unwind info (if present)\n\
2169 -d --dynamic Display the dynamic segment (if present)\n\
2170 -V --version-info Display the version sections (if present)\n\
2171 -A --arch-specific Display architecture specific information (if any).\n\
2172 -D --use-dynamic Use the dynamic section info when displaying symbols\n\
2173 -x --hex-dump=<number> Dump the contents of section <number>\n\
2174 -w --debug-dump[=line,=info,=abbrev,=pubnames,=ranges,=macro,=frames,=str]\n\
2175 Display the contents of DWARF2 debug sections\n"));
2176 #ifdef SUPPORT_DISASSEMBLY
2177 fprintf (stdout, _("\
2178 -i --instruction-dump=<number>\n\
2179 Disassemble the contents of section <number>\n"));
2181 fprintf (stdout, _("\
2182 -I --histogram Display histogram of bucket list lengths\n\
2183 -W --wide Allow output width to exceed 80 characters\n\
2184 -H --help Display this information\n\
2185 -v --version Display the version number of readelf\n"));
2186 fprintf (stdout, _("Report bugs to %s\n"), REPORT_BUGS_TO);
2192 request_dump (section, type)
2193 unsigned int section;
2196 if (section >= num_dump_sects)
2198 char * new_dump_sects;
2200 new_dump_sects = (char *) calloc (section + 1, 1);
2202 if (new_dump_sects == NULL)
2203 error (_("Out of memory allocating dump request table."));
2206 /* Copy current flag settings. */
2207 memcpy (new_dump_sects, dump_sects, num_dump_sects);
2211 dump_sects = new_dump_sects;
2212 num_dump_sects = section + 1;
2217 dump_sects [section] |= type;
2223 parse_args (argc, argv)
2232 while ((c = getopt_long
2233 (argc, argv, "ersuahnldSDAIw::x:i:vVW", options, NULL)) != EOF)
2269 do_using_dynamic ++;
2300 section = strtoul (optarg, & cp, 0);
2301 if (! * cp && section >= 0)
2303 request_dump (section, HEX_DUMP);
2313 unsigned int index = 0;
2317 while (optarg[index])
2318 switch (optarg[index++])
2327 do_debug_abbrevs = 1;
2337 do_debug_pubnames = 1;
2342 do_debug_aranges = 1;
2346 do_debug_frames_interp = 1;
2348 do_debug_frames = 1;
2353 do_debug_macinfo = 1;
2362 warn (_("Unrecognised debug option '%s'\n"), optarg);
2367 #ifdef SUPPORT_DISASSEMBLY
2370 section = strtoul (optarg, & cp, 0);
2371 if (! * cp && section >= 0)
2373 request_dump (section, DISASS_DUMP);
2379 print_version (program_name);
2389 /* xgettext:c-format */
2390 error (_("Invalid option '-%c'\n"), c);
2397 if (!do_dynamic && !do_syms && !do_reloc && !do_unwind && !do_sections
2398 && !do_segments && !do_header && !do_dump && !do_version
2399 && !do_histogram && !do_debugging && !do_arch && !do_notes)
2403 warn (_("Nothing to do.\n"));
2409 get_elf_class (elf_class)
2410 unsigned int elf_class;
2412 static char buff [32];
2416 case ELFCLASSNONE: return _("none");
2417 case ELFCLASS32: return "ELF32";
2418 case ELFCLASS64: return "ELF64";
2420 sprintf (buff, _("<unknown: %x>"), elf_class);
2426 get_data_encoding (encoding)
2427 unsigned int encoding;
2429 static char buff [32];
2433 case ELFDATANONE: return _("none");
2434 case ELFDATA2LSB: return _("2's complement, little endian");
2435 case ELFDATA2MSB: return _("2's complement, big endian");
2437 sprintf (buff, _("<unknown: %x>"), encoding);
2443 get_osabi_name (osabi)
2446 static char buff [32];
2450 case ELFOSABI_NONE: return "UNIX - System V";
2451 case ELFOSABI_HPUX: return "UNIX - HP-UX";
2452 case ELFOSABI_NETBSD: return "UNIX - NetBSD";
2453 case ELFOSABI_LINUX: return "UNIX - Linux";
2454 case ELFOSABI_HURD: return "GNU/Hurd";
2455 case ELFOSABI_SOLARIS: return "UNIX - Solaris";
2456 case ELFOSABI_AIX: return "UNIX - AIX";
2457 case ELFOSABI_IRIX: return "UNIX - IRIX";
2458 case ELFOSABI_FREEBSD: return "UNIX - FreeBSD";
2459 case ELFOSABI_TRU64: return "UNIX - TRU64";
2460 case ELFOSABI_MODESTO: return "Novell - Modesto";
2461 case ELFOSABI_OPENBSD: return "UNIX - OpenBSD";
2462 case ELFOSABI_STANDALONE: return _("Standalone App");
2463 case ELFOSABI_ARM: return "ARM";
2465 sprintf (buff, _("<unknown: %x>"), osabi);
2470 /* Decode the data held in 'elf_header'. */
2472 process_file_header ()
2474 if ( elf_header.e_ident [EI_MAG0] != ELFMAG0
2475 || elf_header.e_ident [EI_MAG1] != ELFMAG1
2476 || elf_header.e_ident [EI_MAG2] != ELFMAG2
2477 || elf_header.e_ident [EI_MAG3] != ELFMAG3)
2480 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
2488 printf (_("ELF Header:\n"));
2489 printf (_(" Magic: "));
2490 for (i = 0; i < EI_NIDENT; i ++)
2491 printf ("%2.2x ", elf_header.e_ident [i]);
2493 printf (_(" Class: %s\n"),
2494 get_elf_class (elf_header.e_ident [EI_CLASS]));
2495 printf (_(" Data: %s\n"),
2496 get_data_encoding (elf_header.e_ident [EI_DATA]));
2497 printf (_(" Version: %d %s\n"),
2498 elf_header.e_ident [EI_VERSION],
2499 (elf_header.e_ident [EI_VERSION] == EV_CURRENT
2501 : (elf_header.e_ident [EI_VERSION] != EV_NONE
2504 printf (_(" OS/ABI: %s\n"),
2505 get_osabi_name (elf_header.e_ident [EI_OSABI]));
2506 printf (_(" ABI Version: %d\n"),
2507 elf_header.e_ident [EI_ABIVERSION]);
2508 printf (_(" Type: %s\n"),
2509 get_file_type (elf_header.e_type));
2510 printf (_(" Machine: %s\n"),
2511 get_machine_name (elf_header.e_machine));
2512 printf (_(" Version: 0x%lx\n"),
2513 (unsigned long) elf_header.e_version);
2515 printf (_(" Entry point address: "));
2516 print_vma ((bfd_vma) elf_header.e_entry, PREFIX_HEX);
2517 printf (_("\n Start of program headers: "));
2518 print_vma ((bfd_vma) elf_header.e_phoff, DEC);
2519 printf (_(" (bytes into file)\n Start of section headers: "));
2520 print_vma ((bfd_vma) elf_header.e_shoff, DEC);
2521 printf (_(" (bytes into file)\n"));
2523 printf (_(" Flags: 0x%lx%s\n"),
2524 (unsigned long) elf_header.e_flags,
2525 get_machine_flags (elf_header.e_flags, elf_header.e_machine));
2526 printf (_(" Size of this header: %ld (bytes)\n"),
2527 (long) elf_header.e_ehsize);
2528 printf (_(" Size of program headers: %ld (bytes)\n"),
2529 (long) elf_header.e_phentsize);
2530 printf (_(" Number of program headers: %ld\n"),
2531 (long) elf_header.e_phnum);
2532 printf (_(" Size of section headers: %ld (bytes)\n"),
2533 (long) elf_header.e_shentsize);
2534 printf (_(" Number of section headers: %ld"),
2535 (long) elf_header.e_shnum);
2536 if (section_headers != NULL && elf_header.e_shnum == 0)
2537 printf (" (%ld)", (long) section_headers[0].sh_size);
2538 putc ('\n', stdout);
2539 printf (_(" Section header string table index: %ld"),
2540 (long) elf_header.e_shstrndx);
2541 if (section_headers != NULL && elf_header.e_shstrndx == SHN_XINDEX)
2542 printf (" (%ld)", (long) section_headers[0].sh_link);
2543 putc ('\n', stdout);
2546 if (section_headers != NULL)
2548 if (elf_header.e_shnum == 0)
2549 elf_header.e_shnum = section_headers[0].sh_size;
2550 if (elf_header.e_shstrndx == SHN_XINDEX)
2551 elf_header.e_shstrndx = section_headers[0].sh_link;
2552 free (section_headers);
2553 section_headers = NULL;
2561 get_32bit_program_headers (file, program_headers)
2563 Elf_Internal_Phdr * program_headers;
2565 Elf32_External_Phdr * phdrs;
2566 Elf32_External_Phdr * external;
2567 Elf32_Internal_Phdr * internal;
2570 phdrs = ((Elf32_External_Phdr *)
2571 get_data (NULL, file, elf_header.e_phoff,
2572 elf_header.e_phentsize * elf_header.e_phnum,
2573 _("program headers")));
2577 for (i = 0, internal = program_headers, external = phdrs;
2578 i < elf_header.e_phnum;
2579 i ++, internal ++, external ++)
2581 internal->p_type = BYTE_GET (external->p_type);
2582 internal->p_offset = BYTE_GET (external->p_offset);
2583 internal->p_vaddr = BYTE_GET (external->p_vaddr);
2584 internal->p_paddr = BYTE_GET (external->p_paddr);
2585 internal->p_filesz = BYTE_GET (external->p_filesz);
2586 internal->p_memsz = BYTE_GET (external->p_memsz);
2587 internal->p_flags = BYTE_GET (external->p_flags);
2588 internal->p_align = BYTE_GET (external->p_align);
2597 get_64bit_program_headers (file, program_headers)
2599 Elf_Internal_Phdr * program_headers;
2601 Elf64_External_Phdr * phdrs;
2602 Elf64_External_Phdr * external;
2603 Elf64_Internal_Phdr * internal;
2606 phdrs = ((Elf64_External_Phdr *)
2607 get_data (NULL, file, elf_header.e_phoff,
2608 elf_header.e_phentsize * elf_header.e_phnum,
2609 _("program headers")));
2613 for (i = 0, internal = program_headers, external = phdrs;
2614 i < elf_header.e_phnum;
2615 i ++, internal ++, external ++)
2617 internal->p_type = BYTE_GET (external->p_type);
2618 internal->p_flags = BYTE_GET (external->p_flags);
2619 internal->p_offset = BYTE_GET8 (external->p_offset);
2620 internal->p_vaddr = BYTE_GET8 (external->p_vaddr);
2621 internal->p_paddr = BYTE_GET8 (external->p_paddr);
2622 internal->p_filesz = BYTE_GET8 (external->p_filesz);
2623 internal->p_memsz = BYTE_GET8 (external->p_memsz);
2624 internal->p_align = BYTE_GET8 (external->p_align);
2633 process_program_headers (file)
2636 Elf_Internal_Phdr * program_headers;
2637 Elf_Internal_Phdr * segment;
2640 if (elf_header.e_phnum == 0)
2643 printf (_("\nThere are no program headers in this file.\n"));
2647 if (do_segments && !do_header)
2649 printf (_("\nElf file type is %s\n"), get_file_type (elf_header.e_type));
2650 printf (_("Entry point "));
2651 print_vma ((bfd_vma) elf_header.e_entry, PREFIX_HEX);
2652 printf (_("\nThere are %d program headers, starting at offset "),
2653 elf_header.e_phnum);
2654 print_vma ((bfd_vma) elf_header.e_phoff, DEC);
2658 program_headers = (Elf_Internal_Phdr *) malloc
2659 (elf_header.e_phnum * sizeof (Elf_Internal_Phdr));
2661 if (program_headers == NULL)
2663 error (_("Out of memory\n"));
2668 i = get_32bit_program_headers (file, program_headers);
2670 i = get_64bit_program_headers (file, program_headers);
2674 free (program_headers);
2681 (_("\nProgram Header%s:\n"), elf_header.e_phnum > 1 ? "s" : "");
2685 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
2688 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
2692 (_(" Type Offset VirtAddr PhysAddr\n"));
2694 (_(" FileSiz MemSiz Flags Align\n"));
2702 for (i = 0, segment = program_headers;
2703 i < elf_header.e_phnum;
2708 printf (" %-14.14s ", get_segment_type (segment->p_type));
2712 printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
2713 printf ("0x%8.8lx ", (unsigned long) segment->p_vaddr);
2714 printf ("0x%8.8lx ", (unsigned long) segment->p_paddr);
2715 printf ("0x%5.5lx ", (unsigned long) segment->p_filesz);
2716 printf ("0x%5.5lx ", (unsigned long) segment->p_memsz);
2718 (segment->p_flags & PF_R ? 'R' : ' '),
2719 (segment->p_flags & PF_W ? 'W' : ' '),
2720 (segment->p_flags & PF_X ? 'E' : ' '));
2721 printf ("%#lx", (unsigned long) segment->p_align);
2725 if ((unsigned long) segment->p_offset == segment->p_offset)
2726 printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
2729 print_vma (segment->p_offset, FULL_HEX);
2733 print_vma (segment->p_vaddr, FULL_HEX);
2735 print_vma (segment->p_paddr, FULL_HEX);
2738 if ((unsigned long) segment->p_filesz == segment->p_filesz)
2739 printf ("0x%6.6lx ", (unsigned long) segment->p_filesz);
2742 print_vma (segment->p_filesz, FULL_HEX);
2746 if ((unsigned long) segment->p_memsz == segment->p_memsz)
2747 printf ("0x%6.6lx", (unsigned long) segment->p_memsz);
2750 print_vma (segment->p_offset, FULL_HEX);
2754 (segment->p_flags & PF_R ? 'R' : ' '),
2755 (segment->p_flags & PF_W ? 'W' : ' '),
2756 (segment->p_flags & PF_X ? 'E' : ' '));
2758 if ((unsigned long) segment->p_align == segment->p_align)
2759 printf ("%#lx", (unsigned long) segment->p_align);
2762 print_vma (segment->p_align, PREFIX_HEX);
2767 print_vma (segment->p_offset, FULL_HEX);
2769 print_vma (segment->p_vaddr, FULL_HEX);
2771 print_vma (segment->p_paddr, FULL_HEX);
2773 print_vma (segment->p_filesz, FULL_HEX);
2775 print_vma (segment->p_memsz, FULL_HEX);
2777 (segment->p_flags & PF_R ? 'R' : ' '),
2778 (segment->p_flags & PF_W ? 'W' : ' '),
2779 (segment->p_flags & PF_X ? 'E' : ' '));
2780 print_vma (segment->p_align, HEX);
2784 switch (segment->p_type)
2788 loadaddr = (segment->p_vaddr & 0xfffff000)
2789 - (segment->p_offset & 0xfffff000);
2794 error (_("more than one dynamic segment\n"));
2796 dynamic_addr = segment->p_offset;
2797 dynamic_size = segment->p_filesz;
2801 if (fseek (file, (long) segment->p_offset, SEEK_SET))
2802 error (_("Unable to find program interpreter name\n"));
2805 program_interpreter[0] = 0;
2806 fscanf (file, "%63s", program_interpreter);
2809 printf (_("\n [Requesting program interpreter: %s]"),
2810 program_interpreter);
2816 putc ('\n', stdout);
2825 if (do_segments && section_headers != NULL)
2827 printf (_("\n Section to Segment mapping:\n"));
2828 printf (_(" Segment Sections...\n"));
2830 assert (string_table != NULL);
2832 for (i = 0; i < elf_header.e_phnum; i++)
2835 Elf_Internal_Shdr * section;
2837 segment = program_headers + i;
2838 section = section_headers;
2840 printf (" %2.2d ", i);
2842 for (j = 1; j < elf_header.e_shnum; j++, section ++)
2844 if (section->sh_size > 0
2845 /* Compare allocated sections by VMA, unallocated
2846 sections by file offset. */
2847 && (section->sh_flags & SHF_ALLOC
2848 ? (section->sh_addr >= segment->p_vaddr
2849 && section->sh_addr + section->sh_size
2850 <= segment->p_vaddr + segment->p_memsz)
2851 : ((bfd_vma) section->sh_offset >= segment->p_offset
2852 && (section->sh_offset + section->sh_size
2853 <= segment->p_offset + segment->p_filesz))))
2854 printf ("%s ", SECTION_NAME (section));
2861 free (program_headers);
2868 get_32bit_section_headers (file, num)
2872 Elf32_External_Shdr * shdrs;
2873 Elf32_Internal_Shdr * internal;
2876 shdrs = ((Elf32_External_Shdr *)
2877 get_data (NULL, file, elf_header.e_shoff,
2878 elf_header.e_shentsize * num,
2879 _("section headers")));
2883 section_headers = ((Elf_Internal_Shdr *)
2884 malloc (num * sizeof (Elf_Internal_Shdr)));
2886 if (section_headers == NULL)
2888 error (_("Out of memory\n"));
2892 for (i = 0, internal = section_headers;
2896 internal->sh_name = BYTE_GET (shdrs[i].sh_name);
2897 internal->sh_type = BYTE_GET (shdrs[i].sh_type);
2898 internal->sh_flags = BYTE_GET (shdrs[i].sh_flags);
2899 internal->sh_addr = BYTE_GET (shdrs[i].sh_addr);
2900 internal->sh_offset = BYTE_GET (shdrs[i].sh_offset);
2901 internal->sh_size = BYTE_GET (shdrs[i].sh_size);
2902 internal->sh_link = BYTE_GET (shdrs[i].sh_link);
2903 internal->sh_info = BYTE_GET (shdrs[i].sh_info);
2904 internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
2905 internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize);
2914 get_64bit_section_headers (file, num)
2918 Elf64_External_Shdr * shdrs;
2919 Elf64_Internal_Shdr * internal;
2922 shdrs = ((Elf64_External_Shdr *)
2923 get_data (NULL, file, elf_header.e_shoff,
2924 elf_header.e_shentsize * num,
2925 _("section headers")));
2929 section_headers = ((Elf_Internal_Shdr *)
2930 malloc (num * sizeof (Elf_Internal_Shdr)));
2932 if (section_headers == NULL)
2934 error (_("Out of memory\n"));
2938 for (i = 0, internal = section_headers;
2942 internal->sh_name = BYTE_GET (shdrs[i].sh_name);
2943 internal->sh_type = BYTE_GET (shdrs[i].sh_type);
2944 internal->sh_flags = BYTE_GET8 (shdrs[i].sh_flags);
2945 internal->sh_addr = BYTE_GET8 (shdrs[i].sh_addr);
2946 internal->sh_size = BYTE_GET8 (shdrs[i].sh_size);
2947 internal->sh_entsize = BYTE_GET8 (shdrs[i].sh_entsize);
2948 internal->sh_link = BYTE_GET (shdrs[i].sh_link);
2949 internal->sh_info = BYTE_GET (shdrs[i].sh_info);
2950 internal->sh_offset = BYTE_GET (shdrs[i].sh_offset);
2951 internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
2959 static Elf_Internal_Sym *
2960 get_32bit_elf_symbols (file, section)
2962 Elf_Internal_Shdr *section;
2964 unsigned long number;
2965 Elf32_External_Sym * esyms;
2966 Elf_External_Sym_Shndx *shndx;
2967 Elf_Internal_Sym * isyms;
2968 Elf_Internal_Sym * psym;
2971 esyms = ((Elf32_External_Sym *)
2972 get_data (NULL, file, section->sh_offset,
2973 section->sh_size, _("symbols")));
2978 if (symtab_shndx_hdr != NULL
2979 && (symtab_shndx_hdr->sh_link
2980 == (unsigned long) SECTION_HEADER_NUM (section - section_headers)))
2982 shndx = ((Elf_External_Sym_Shndx *)
2983 get_data (NULL, file, symtab_shndx_hdr->sh_offset,
2984 symtab_shndx_hdr->sh_size, _("symtab shndx")));
2992 number = section->sh_size / section->sh_entsize;
2993 isyms = (Elf_Internal_Sym *) malloc (number * sizeof (Elf_Internal_Sym));
2997 error (_("Out of memory\n"));
3004 for (j = 0, psym = isyms;
3008 psym->st_name = BYTE_GET (esyms[j].st_name);
3009 psym->st_value = BYTE_GET (esyms[j].st_value);
3010 psym->st_size = BYTE_GET (esyms[j].st_size);
3011 psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
3012 if (psym->st_shndx == SHN_XINDEX && shndx != NULL)
3014 = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j]));
3015 psym->st_info = BYTE_GET (esyms[j].st_info);
3016 psym->st_other = BYTE_GET (esyms[j].st_other);
3026 static Elf_Internal_Sym *
3027 get_64bit_elf_symbols (file, section)
3029 Elf_Internal_Shdr *section;
3031 unsigned long number;
3032 Elf64_External_Sym * esyms;
3033 Elf_External_Sym_Shndx *shndx;
3034 Elf_Internal_Sym * isyms;
3035 Elf_Internal_Sym * psym;
3038 esyms = ((Elf64_External_Sym *)
3039 get_data (NULL, file, section->sh_offset,
3040 section->sh_size, _("symbols")));
3045 if (symtab_shndx_hdr != NULL
3046 && (symtab_shndx_hdr->sh_link
3047 == (unsigned long) SECTION_HEADER_NUM (section - section_headers)))
3049 shndx = ((Elf_External_Sym_Shndx *)
3050 get_data (NULL, file, symtab_shndx_hdr->sh_offset,
3051 symtab_shndx_hdr->sh_size, _("symtab shndx")));
3059 number = section->sh_size / section->sh_entsize;
3060 isyms = (Elf_Internal_Sym *) malloc (number * sizeof (Elf_Internal_Sym));
3064 error (_("Out of memory\n"));
3071 for (j = 0, psym = isyms;
3075 psym->st_name = BYTE_GET (esyms[j].st_name);
3076 psym->st_info = BYTE_GET (esyms[j].st_info);
3077 psym->st_other = BYTE_GET (esyms[j].st_other);
3078 psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
3079 if (psym->st_shndx == SHN_XINDEX && shndx != NULL)
3081 = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j]));
3082 psym->st_value = BYTE_GET8 (esyms[j].st_value);
3083 psym->st_size = BYTE_GET8 (esyms[j].st_size);
3094 get_elf_section_flags (sh_flags)
3097 static char buff [32];
3105 flag = sh_flags & - sh_flags;
3110 case SHF_WRITE: strcat (buff, "W"); break;
3111 case SHF_ALLOC: strcat (buff, "A"); break;
3112 case SHF_EXECINSTR: strcat (buff, "X"); break;
3113 case SHF_MERGE: strcat (buff, "M"); break;
3114 case SHF_STRINGS: strcat (buff, "S"); break;
3115 case SHF_INFO_LINK: strcat (buff, "I"); break;
3116 case SHF_LINK_ORDER: strcat (buff, "L"); break;
3117 case SHF_OS_NONCONFORMING: strcat (buff, "O"); break;
3118 case SHF_GROUP: strcat (buff, "G"); break;
3121 if (flag & SHF_MASKOS)
3124 sh_flags &= ~ SHF_MASKOS;
3126 else if (flag & SHF_MASKPROC)
3129 sh_flags &= ~ SHF_MASKPROC;
3141 process_section_headers (file)
3144 Elf_Internal_Shdr * section;
3147 section_headers = NULL;
3149 if (elf_header.e_shnum == 0)
3152 printf (_("\nThere are no sections in this file.\n"));
3157 if (do_sections && !do_header)
3158 printf (_("There are %d section headers, starting at offset 0x%lx:\n"),
3159 elf_header.e_shnum, (unsigned long) elf_header.e_shoff);
3163 if (! get_32bit_section_headers (file, elf_header.e_shnum))
3166 else if (! get_64bit_section_headers (file, elf_header.e_shnum))
3169 /* Read in the string table, so that we have names to display. */
3170 section = SECTION_HEADER (elf_header.e_shstrndx);
3172 if (section->sh_size != 0)
3174 string_table = (char *) get_data (NULL, file, section->sh_offset,
3175 section->sh_size, _("string table"));
3177 string_table_length = section->sh_size;
3180 /* Scan the sections for the dynamic symbol table
3181 and dynamic string table and debug sections. */
3182 dynamic_symbols = NULL;
3183 dynamic_strings = NULL;
3184 dynamic_syminfo = NULL;
3186 for (i = 0, section = section_headers;
3187 i < elf_header.e_shnum;
3190 char * name = SECTION_NAME (section);
3192 if (section->sh_type == SHT_DYNSYM)
3194 if (dynamic_symbols != NULL)
3196 error (_("File contains multiple dynamic symbol tables\n"));
3200 num_dynamic_syms = section->sh_size / section->sh_entsize;
3201 dynamic_symbols = GET_ELF_SYMBOLS (file, section);
3203 else if (section->sh_type == SHT_STRTAB
3204 && strcmp (name, ".dynstr") == 0)
3206 if (dynamic_strings != NULL)
3208 error (_("File contains multiple dynamic string tables\n"));
3212 dynamic_strings = (char *) get_data (NULL, file, section->sh_offset,
3214 _("dynamic strings"));
3216 else if (section->sh_type == SHT_SYMTAB_SHNDX)
3218 if (symtab_shndx_hdr != NULL)
3220 error (_("File contains multiple symtab shndx tables\n"));
3223 symtab_shndx_hdr = section;
3225 else if ((do_debugging || do_debug_info || do_debug_abbrevs
3226 || do_debug_lines || do_debug_pubnames || do_debug_aranges
3227 || do_debug_frames || do_debug_macinfo || do_debug_str)
3228 && strncmp (name, ".debug_", 7) == 0)
3233 || (do_debug_info && (strcmp (name, "info") == 0))
3234 || (do_debug_abbrevs && (strcmp (name, "abbrev") == 0))
3235 || (do_debug_lines && (strcmp (name, "line") == 0))
3236 || (do_debug_pubnames && (strcmp (name, "pubnames") == 0))
3237 || (do_debug_aranges && (strcmp (name, "aranges") == 0))
3238 || (do_debug_frames && (strcmp (name, "frame") == 0))
3239 || (do_debug_macinfo && (strcmp (name, "macinfo") == 0))
3240 || (do_debug_str && (strcmp (name, "str") == 0))
3242 request_dump (i, DEBUG_DUMP);
3244 /* linkonce section to be combined with .debug_info at link time. */
3245 else if ((do_debugging || do_debug_info)
3246 && strncmp (name, ".gnu.linkonce.wi.", 17) == 0)
3247 request_dump (i, DEBUG_DUMP);
3248 else if (do_debug_frames && strcmp (name, ".eh_frame") == 0)
3249 request_dump (i, DEBUG_DUMP);
3255 printf (_("\nSection Header%s:\n"), elf_header.e_shnum > 1 ? "s" : "");
3259 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
3262 (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n"));
3265 printf (_(" [Nr] Name Type Address Offset\n"));
3266 printf (_(" Size EntSize Flags Link Info Align\n"));
3269 for (i = 0, section = section_headers;
3270 i < elf_header.e_shnum;
3273 printf (" [%2u] %-17.17s %-15.15s ",
3274 SECTION_HEADER_NUM (i),
3275 SECTION_NAME (section),
3276 get_section_type_name (section->sh_type));
3280 print_vma (section->sh_addr, LONG_HEX);
3282 printf ( " %6.6lx %6.6lx %2.2lx",
3283 (unsigned long) section->sh_offset,
3284 (unsigned long) section->sh_size,
3285 (unsigned long) section->sh_entsize);
3287 printf (" %3s ", get_elf_section_flags (section->sh_flags));
3289 printf ("%2ld %3lx %2ld\n",
3290 (unsigned long) section->sh_link,
3291 (unsigned long) section->sh_info,
3292 (unsigned long) section->sh_addralign);
3296 print_vma (section->sh_addr, LONG_HEX);
3298 if ((long) section->sh_offset == section->sh_offset)
3299 printf (" %6.6lx", (unsigned long) section->sh_offset);
3303 print_vma (section->sh_offset, LONG_HEX);
3306 if ((unsigned long) section->sh_size == section->sh_size)
3307 printf (" %6.6lx", (unsigned long) section->sh_size);
3311 print_vma (section->sh_size, LONG_HEX);
3314 if ((unsigned long) section->sh_entsize == section->sh_entsize)
3315 printf (" %2.2lx", (unsigned long) section->sh_entsize);
3319 print_vma (section->sh_entsize, LONG_HEX);
3322 printf (" %3s ", get_elf_section_flags (section->sh_flags));
3324 printf ("%2ld %3lx ",
3325 (unsigned long) section->sh_link,
3326 (unsigned long) section->sh_info);
3328 if ((unsigned long) section->sh_addralign == section->sh_addralign)
3329 printf ("%2ld\n", (unsigned long) section->sh_addralign);
3332 print_vma (section->sh_addralign, DEC);
3339 print_vma (section->sh_addr, LONG_HEX);
3340 if ((long) section->sh_offset == section->sh_offset)
3341 printf (" %8.8lx", (unsigned long) section->sh_offset);
3345 print_vma (section->sh_offset, LONG_HEX);
3348 print_vma (section->sh_size, LONG_HEX);
3350 print_vma (section->sh_entsize, LONG_HEX);
3352 printf (" %3s ", get_elf_section_flags (section->sh_flags));
3354 printf (" %2ld %3lx %ld\n",
3355 (unsigned long) section->sh_link,
3356 (unsigned long) section->sh_info,
3357 (unsigned long) section->sh_addralign);
3361 printf (_("Key to Flags:\n\
3362 W (write), A (alloc), X (execute), M (merge), S (strings)\n\
3363 I (info), L (link order), G (group), x (unknown)\n\
3364 O (extra OS processing required) o (OS specific), p (processor specific)\n"));
3369 /* Process the reloc section. */
3371 process_relocs (file)
3374 unsigned long rel_size;
3375 unsigned long rel_offset;
3381 if (do_using_dynamic)
3383 int is_rela = FALSE;
3388 if (dynamic_info[DT_REL])
3390 rel_offset = dynamic_info[DT_REL];
3391 rel_size = dynamic_info[DT_RELSZ];
3394 else if (dynamic_info [DT_RELA])
3396 rel_offset = dynamic_info[DT_RELA];
3397 rel_size = dynamic_info[DT_RELASZ];
3400 else if (dynamic_info[DT_JMPREL])
3402 rel_offset = dynamic_info[DT_JMPREL];
3403 rel_size = dynamic_info[DT_PLTRELSZ];
3405 switch (dynamic_info[DT_PLTREL])
3422 (_("\nRelocation section at offset 0x%lx contains %ld bytes:\n"),
3423 rel_offset, rel_size);
3425 dump_relocations (file, rel_offset - loadaddr, rel_size,
3426 dynamic_symbols, num_dynamic_syms, dynamic_strings, is_rela);
3429 printf (_("\nThere are no dynamic relocations in this file.\n"));
3433 Elf32_Internal_Shdr * section;
3437 for (i = 0, section = section_headers;
3438 i < elf_header.e_shnum;
3441 if ( section->sh_type != SHT_RELA
3442 && section->sh_type != SHT_REL)
3445 rel_offset = section->sh_offset;
3446 rel_size = section->sh_size;
3450 Elf32_Internal_Shdr * strsec;
3451 Elf_Internal_Sym * symtab;
3454 unsigned long nsyms;
3456 printf (_("\nRelocation section "));
3458 if (string_table == NULL)
3459 printf ("%d", section->sh_name);
3461 printf ("'%s'", SECTION_NAME (section));
3463 printf (_(" at offset 0x%lx contains %lu entries:\n"),
3464 rel_offset, (unsigned long) (rel_size / section->sh_entsize));
3469 if (section->sh_link)
3471 Elf32_Internal_Shdr * symsec;
3473 symsec = SECTION_HEADER (section->sh_link);
3474 nsyms = symsec->sh_size / symsec->sh_entsize;
3475 symtab = GET_ELF_SYMBOLS (file, symsec);
3480 strsec = SECTION_HEADER (symsec->sh_link);
3482 strtab = (char *) get_data (NULL, file, strsec->sh_offset,
3486 is_rela = section->sh_type == SHT_RELA;
3488 dump_relocations (file, rel_offset, rel_size,
3489 symtab, nsyms, strtab, is_rela);
3501 printf (_("\nThere are no relocations in this file.\n"));
3507 #include "unwind-ia64.h"
3509 /* An absolute address consists of a section and an offset. If the
3510 section is NULL, the offset itself is the address, otherwise, the
3511 address equals to LOAD_ADDRESS(section) + offset. */
3515 unsigned short section;
3521 struct unw_table_entry
3523 struct absaddr start;
3525 struct absaddr info;
3527 *table; /* Unwind table. */
3528 unsigned long table_len; /* Length of unwind table. */
3529 unsigned char * info; /* Unwind info. */
3530 unsigned long info_size; /* Size of unwind info. */
3531 bfd_vma info_addr; /* starting address of unwind info. */
3532 bfd_vma seg_base; /* Starting address of segment. */
3533 Elf_Internal_Sym * symtab; /* The symbol table. */
3534 unsigned long nsyms; /* Number of symbols. */
3535 char * strtab; /* The string table. */
3536 unsigned long strtab_size; /* Size of string table. */
3539 static void find_symbol_for_address PARAMS ((struct unw_aux_info *,
3540 struct absaddr, const char **,
3542 static void dump_ia64_unwind PARAMS ((struct unw_aux_info *));
3543 static int slurp_ia64_unwind_table PARAMS ((FILE *, struct unw_aux_info *,
3544 Elf32_Internal_Shdr *));
3547 find_symbol_for_address (aux, addr, symname, offset)
3548 struct unw_aux_info *aux;
3549 struct absaddr addr;
3550 const char **symname;
3553 bfd_vma dist = (bfd_vma) 0x100000;
3554 Elf_Internal_Sym *sym, *best = NULL;
3557 for (i = 0, sym = aux->symtab; i < aux->nsyms; ++i, ++sym)
3559 if (ELF_ST_TYPE (sym->st_info) == STT_FUNC
3560 && sym->st_name != 0
3561 && (addr.section == SHN_UNDEF || addr.section == sym->st_shndx)
3562 && addr.offset >= sym->st_value
3563 && addr.offset - sym->st_value < dist)
3566 dist = addr.offset - sym->st_value;
3573 *symname = (best->st_name >= aux->strtab_size
3574 ? "<corrupt>" : aux->strtab + best->st_name);
3579 *offset = addr.offset;
3583 dump_ia64_unwind (aux)
3584 struct unw_aux_info *aux;
3587 struct unw_table_entry * tp;
3590 addr_size = is_32bit_elf ? 4 : 8;
3592 for (tp = aux->table; tp < aux->table + aux->table_len; ++tp)
3596 const unsigned char * dp;
3597 const unsigned char * head;
3598 const char * procname;
3600 find_symbol_for_address (aux, tp->start, &procname, &offset);
3602 fputs ("\n<", stdout);
3606 fputs (procname, stdout);
3609 printf ("+%lx", (unsigned long) offset);
3612 fputs (">: [", stdout);
3613 print_vma (tp->start.offset, PREFIX_HEX);
3614 fputc ('-', stdout);
3615 print_vma (tp->end.offset, PREFIX_HEX);
3616 printf ("), info at +0x%lx\n",
3617 (unsigned long) (tp->info.offset - aux->seg_base));
3619 head = aux->info + (tp->info.offset - aux->info_addr);
3620 stamp = BYTE_GET8 ((unsigned char *) head);
3622 printf (" v%u, flags=0x%lx (%s%s ), len=%lu bytes\n",
3623 (unsigned) UNW_VER (stamp),
3624 (unsigned long) ((stamp & UNW_FLAG_MASK) >> 32),
3625 UNW_FLAG_EHANDLER (stamp) ? " ehandler" : "",
3626 UNW_FLAG_UHANDLER (stamp) ? " uhandler" : "",
3627 (unsigned long) (addr_size * UNW_LENGTH (stamp)));
3629 if (UNW_VER (stamp) != 1)
3631 printf ("\tUnknown version.\n");
3636 for (dp = head + 8; dp < head + 8 + addr_size * UNW_LENGTH (stamp);)
3637 dp = unw_decode (dp, in_body, & in_body);
3642 slurp_ia64_unwind_table (file, aux, sec)
3644 struct unw_aux_info *aux;
3645 Elf32_Internal_Shdr *sec;
3647 unsigned long size, addr_size, nrelas, i;
3648 Elf_Internal_Phdr *prog_hdrs, *seg;
3649 struct unw_table_entry *tep;
3650 Elf32_Internal_Shdr *relsec;
3651 Elf_Internal_Rela *rela, *rp;
3652 unsigned char *table, *tp;
3653 Elf_Internal_Sym *sym;
3654 const char *relname;
3657 addr_size = is_32bit_elf ? 4 : 8;
3659 /* First, find the starting address of the segment that includes
3662 if (elf_header.e_phnum)
3664 prog_hdrs = (Elf_Internal_Phdr *)
3665 xmalloc (elf_header.e_phnum * sizeof (Elf_Internal_Phdr));
3668 result = get_32bit_program_headers (file, prog_hdrs);
3670 result = get_64bit_program_headers (file, prog_hdrs);
3678 for (seg = prog_hdrs; seg < prog_hdrs + elf_header.e_phnum; ++seg)
3680 if (seg->p_type != PT_LOAD)
3683 if (sec->sh_addr >= seg->p_vaddr
3684 && (sec->sh_addr + sec->sh_size <= seg->p_vaddr + seg->p_memsz))
3686 aux->seg_base = seg->p_vaddr;
3694 /* Second, build the unwind table from the contents of the unwind section: */
3695 size = sec->sh_size;
3696 table = (char *) get_data (NULL, file, sec->sh_offset,
3697 size, _("unwind table"));
3701 tep = aux->table = xmalloc (size / (3 * addr_size) * sizeof (aux->table[0]));
3702 for (tp = table; tp < table + size; tp += 3 * addr_size, ++ tep)
3704 tep->start.section = SHN_UNDEF;
3705 tep->end.section = SHN_UNDEF;
3706 tep->info.section = SHN_UNDEF;
3709 tep->start.offset = byte_get ((unsigned char *) tp + 0, 4);
3710 tep->end.offset = byte_get ((unsigned char *) tp + 4, 4);
3711 tep->info.offset = byte_get ((unsigned char *) tp + 8, 4);
3715 tep->start.offset = BYTE_GET8 ((unsigned char *) tp + 0);
3716 tep->end.offset = BYTE_GET8 ((unsigned char *) tp + 8);
3717 tep->info.offset = BYTE_GET8 ((unsigned char *) tp + 16);
3719 tep->start.offset += aux->seg_base;
3720 tep->end.offset += aux->seg_base;
3721 tep->info.offset += aux->seg_base;
3725 /* Third, apply any relocations to the unwind table: */
3727 for (relsec = section_headers;
3728 relsec < section_headers + elf_header.e_shnum;
3731 if (relsec->sh_type != SHT_RELA
3732 || SECTION_HEADER (relsec->sh_info) != sec)
3735 if (!slurp_rela_relocs (file, relsec->sh_offset, relsec->sh_size,
3739 for (rp = rela; rp < rela + nrelas; ++rp)
3743 relname = elf_ia64_reloc_type (ELF32_R_TYPE (rp->r_info));
3744 sym = aux->symtab + ELF32_R_SYM (rp->r_info);
3746 if (ELF32_ST_TYPE (sym->st_info) != STT_SECTION)
3748 warn (_("Skipping unexpected symbol type %u\n"),
3749 ELF32_ST_TYPE (sym->st_info));
3755 relname = elf_ia64_reloc_type (ELF64_R_TYPE (rp->r_info));
3756 sym = aux->symtab + ELF64_R_SYM (rp->r_info);
3758 if (ELF64_ST_TYPE (sym->st_info) != STT_SECTION)
3760 warn (_("Skipping unexpected symbol type %u\n"),
3761 ELF64_ST_TYPE (sym->st_info));
3766 if (strncmp (relname, "R_IA64_SEGREL", 13) != 0)
3768 warn (_("Skipping unexpected relocation type %s\n"), relname);
3772 i = rp->r_offset / (3 * addr_size);
3774 switch (rp->r_offset/addr_size % 3)
3777 aux->table[i].start.section = sym->st_shndx;
3778 aux->table[i].start.offset += rp->r_addend;
3781 aux->table[i].end.section = sym->st_shndx;
3782 aux->table[i].end.offset += rp->r_addend;
3785 aux->table[i].info.section = sym->st_shndx;
3786 aux->table[i].info.offset += rp->r_addend;
3796 aux->table_len = size / (3 * addr_size);
3801 process_unwind (file)
3804 Elf32_Internal_Shdr *sec, *unwsec = NULL, *strsec;
3805 unsigned long i, addr_size, unwcount = 0, unwstart = 0;
3806 struct unw_aux_info aux;
3811 if (elf_header.e_machine != EM_IA_64)
3813 printf (_("\nThere are no unwind sections in this file.\n"));
3817 memset (& aux, 0, sizeof (aux));
3819 addr_size = is_32bit_elf ? 4 : 8;
3821 for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec)
3823 if (sec->sh_type == SHT_SYMTAB)
3825 aux.nsyms = sec->sh_size / sec->sh_entsize;
3826 aux.symtab = GET_ELF_SYMBOLS (file, sec);
3828 strsec = SECTION_HEADER (sec->sh_link);
3829 aux.strtab_size = strsec->sh_size;
3830 aux.strtab = (char *) get_data (NULL, file, strsec->sh_offset,
3831 aux.strtab_size, _("string table"));
3833 else if (sec->sh_type == SHT_IA_64_UNWIND)
3838 printf (_("\nThere are no unwind sections in this file.\n"));
3840 while (unwcount-- > 0)
3845 for (i = unwstart, sec = section_headers + unwstart;
3846 i < elf_header.e_shnum; ++i, ++sec)
3847 if (sec->sh_type == SHT_IA_64_UNWIND)
3854 len = sizeof (ELF_STRING_ia64_unwind_once) - 1;
3856 if (strncmp (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind_once,
3859 /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO */
3860 len2 = sizeof (ELF_STRING_ia64_unwind_info_once) - 1;
3861 suffix = SECTION_NAME (unwsec) + len;
3862 for (i = 0, sec = section_headers; i < elf_header.e_shnum;
3864 if (strncmp (SECTION_NAME (sec),
3865 ELF_STRING_ia64_unwind_info_once, len2) == 0
3866 && strcmp (SECTION_NAME (sec) + len2, suffix) == 0)
3871 /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO
3872 .IA_64.unwind or BAR -> .IA_64.unwind_info */
3873 len = sizeof (ELF_STRING_ia64_unwind) - 1;
3874 len2 = sizeof (ELF_STRING_ia64_unwind_info) - 1;
3876 if (strncmp (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind,
3878 suffix = SECTION_NAME (unwsec) + len;
3879 for (i = 0, sec = section_headers; i < elf_header.e_shnum;
3881 if (strncmp (SECTION_NAME (sec),
3882 ELF_STRING_ia64_unwind_info, len2) == 0
3883 && strcmp (SECTION_NAME (sec) + len2, suffix) == 0)
3887 if (i == elf_header.e_shnum)
3889 printf (_("\nCould not find unwind info section for "));
3891 if (string_table == NULL)
3892 printf ("%d", unwsec->sh_name);
3894 printf ("'%s'", SECTION_NAME (unwsec));
3898 aux.info_size = sec->sh_size;
3899 aux.info_addr = sec->sh_addr;
3900 aux.info = (char *) get_data (NULL, file, sec->sh_offset,
3901 aux.info_size, _("unwind info"));
3903 printf (_("\nUnwind section "));
3905 if (string_table == NULL)
3906 printf ("%d", unwsec->sh_name);
3908 printf ("'%s'", SECTION_NAME (unwsec));
3910 printf (_(" at offset 0x%lx contains %lu entries:\n"),
3911 (unsigned long) unwsec->sh_offset,
3912 (unsigned long) (unwsec->sh_size / (3 * addr_size)));
3914 (void) slurp_ia64_unwind_table (file, & aux, unwsec);
3916 if (aux.table_len > 0)
3917 dump_ia64_unwind (& aux);
3920 free ((char *) aux.table);
3922 free ((char *) aux.info);
3931 free ((char *) aux.strtab);
3937 dynamic_segment_mips_val (entry)
3938 Elf_Internal_Dyn * entry;
3940 switch (entry->d_tag)
3943 if (entry->d_un.d_val == 0)
3947 static const char * opts[] =
3949 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
3950 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
3951 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
3952 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
3957 for (cnt = 0; cnt < NUM_ELEM (opts); ++ cnt)
3958 if (entry->d_un.d_val & (1 << cnt))
3960 printf ("%s%s", first ? "" : " ", opts[cnt]);
3967 case DT_MIPS_IVERSION:
3968 if (dynamic_strings != NULL)
3969 printf ("Interface Version: %s\n",
3970 dynamic_strings + entry->d_un.d_val);
3972 printf ("%ld\n", (long) entry->d_un.d_ptr);
3975 case DT_MIPS_TIME_STAMP:
3980 time_t time = entry->d_un.d_val;
3981 tmp = gmtime (&time);
3982 sprintf (timebuf, "%04u-%02u-%02uT%02u:%02u:%02u",
3983 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
3984 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
3985 printf ("Time Stamp: %s\n", timebuf);
3989 case DT_MIPS_RLD_VERSION:
3990 case DT_MIPS_LOCAL_GOTNO:
3991 case DT_MIPS_CONFLICTNO:
3992 case DT_MIPS_LIBLISTNO:
3993 case DT_MIPS_SYMTABNO:
3994 case DT_MIPS_UNREFEXTNO:
3995 case DT_MIPS_HIPAGENO:
3996 case DT_MIPS_DELTA_CLASS_NO:
3997 case DT_MIPS_DELTA_INSTANCE_NO:
3998 case DT_MIPS_DELTA_RELOC_NO:
3999 case DT_MIPS_DELTA_SYM_NO:
4000 case DT_MIPS_DELTA_CLASSSYM_NO:
4001 case DT_MIPS_COMPACT_SIZE:
4002 printf ("%ld\n", (long) entry->d_un.d_ptr);
4006 printf ("%#lx\n", (long) entry->d_un.d_ptr);
4012 dynamic_segment_parisc_val (entry)
4013 Elf_Internal_Dyn * entry;
4015 switch (entry->d_tag)
4017 case DT_HP_DLD_FLAGS:
4026 { DT_HP_DEBUG_PRIVATE, "HP_DEBUG_PRIVATE" },
4027 { DT_HP_DEBUG_CALLBACK, "HP_DEBUG_CALLBACK" },
4028 { DT_HP_DEBUG_CALLBACK_BOR, "HP_DEBUG_CALLBACK_BOR" },
4029 { DT_HP_NO_ENVVAR, "HP_NO_ENVVAR" },
4030 { DT_HP_BIND_NOW, "HP_BIND_NOW" },
4031 { DT_HP_BIND_NONFATAL, "HP_BIND_NONFATAL" },
4032 { DT_HP_BIND_VERBOSE, "HP_BIND_VERBOSE" },
4033 { DT_HP_BIND_RESTRICTED, "HP_BIND_RESTRICTED" },
4034 { DT_HP_BIND_SYMBOLIC, "HP_BIND_SYMBOLIC" },
4035 { DT_HP_RPATH_FIRST, "HP_RPATH_FIRST" },
4036 { DT_HP_BIND_DEPTH_FIRST, "HP_BIND_DEPTH_FIRST" }
4040 bfd_vma val = entry->d_un.d_val;
4042 for (cnt = 0; cnt < sizeof (flags) / sizeof (flags[0]); ++cnt)
4043 if (val & flags[cnt].bit)
4047 fputs (flags[cnt].str, stdout);
4049 val ^= flags[cnt].bit;
4052 if (val != 0 || first)
4056 print_vma (val, HEX);
4062 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
4068 get_32bit_dynamic_segment (file)
4071 Elf32_External_Dyn * edyn;
4072 Elf_Internal_Dyn * entry;
4075 edyn = (Elf32_External_Dyn *) get_data (NULL, file, dynamic_addr,
4076 dynamic_size, _("dynamic segment"));
4080 /* SGI's ELF has more than one section in the DYNAMIC segment. Determine
4081 how large this .dynamic is now. We can do this even before the byte
4082 swapping since the DT_NULL tag is recognizable. */
4084 while (*(Elf32_Word *) edyn [dynamic_size++].d_tag != DT_NULL)
4087 dynamic_segment = (Elf_Internal_Dyn *)
4088 malloc (dynamic_size * sizeof (Elf_Internal_Dyn));
4090 if (dynamic_segment == NULL)
4092 error (_("Out of memory\n"));
4097 for (i = 0, entry = dynamic_segment;
4101 entry->d_tag = BYTE_GET (edyn [i].d_tag);
4102 entry->d_un.d_val = BYTE_GET (edyn [i].d_un.d_val);
4111 get_64bit_dynamic_segment (file)
4114 Elf64_External_Dyn * edyn;
4115 Elf_Internal_Dyn * entry;
4118 edyn = (Elf64_External_Dyn *) get_data (NULL, file, dynamic_addr,
4119 dynamic_size, _("dynamic segment"));
4123 /* SGI's ELF has more than one section in the DYNAMIC segment. Determine
4124 how large this .dynamic is now. We can do this even before the byte
4125 swapping since the DT_NULL tag is recognizable. */
4127 while (*(bfd_vma *) edyn [dynamic_size ++].d_tag != DT_NULL)
4130 dynamic_segment = (Elf_Internal_Dyn *)
4131 malloc (dynamic_size * sizeof (Elf_Internal_Dyn));
4133 if (dynamic_segment == NULL)
4135 error (_("Out of memory\n"));
4140 for (i = 0, entry = dynamic_segment;
4144 entry->d_tag = BYTE_GET8 (edyn [i].d_tag);
4145 entry->d_un.d_val = BYTE_GET8 (edyn [i].d_un.d_val);
4154 get_dynamic_flags (flags)
4157 static char buff [64];
4162 flag = flags & - flags;
4167 case DF_ORIGIN: strcat (buff, "ORIGIN "); break;
4168 case DF_SYMBOLIC: strcat (buff, "SYMBOLIC "); break;
4169 case DF_TEXTREL: strcat (buff, "TEXTREL "); break;
4170 case DF_BIND_NOW: strcat (buff, "BIND_NOW "); break;
4171 default: strcat (buff, "unknown "); break;
4177 /* Parse and display the contents of the dynamic segment. */
4179 process_dynamic_segment (file)
4182 Elf_Internal_Dyn * entry;
4185 if (dynamic_size == 0)
4188 printf (_("\nThere is no dynamic segment in this file.\n"));
4195 if (! get_32bit_dynamic_segment (file))
4198 else if (! get_64bit_dynamic_segment (file))
4201 /* Find the appropriate symbol table. */
4202 if (dynamic_symbols == NULL)
4204 for (i = 0, entry = dynamic_segment;
4208 Elf32_Internal_Shdr section;
4210 if (entry->d_tag != DT_SYMTAB)
4213 dynamic_info[DT_SYMTAB] = entry->d_un.d_val;
4215 /* Since we do not know how big the symbol table is,
4216 we default to reading in the entire file (!) and
4217 processing that. This is overkill, I know, but it
4219 section.sh_offset = entry->d_un.d_val - loadaddr;
4221 if (fseek (file, 0, SEEK_END))
4222 error (_("Unable to seek to end of file!"));
4224 section.sh_size = ftell (file) - section.sh_offset;
4226 section.sh_entsize = sizeof (Elf32_External_Sym);
4228 section.sh_entsize = sizeof (Elf64_External_Sym);
4230 num_dynamic_syms = section.sh_size / section.sh_entsize;
4231 if (num_dynamic_syms < 1)
4233 error (_("Unable to determine the number of symbols to load\n"));
4237 dynamic_symbols = GET_ELF_SYMBOLS (file, §ion);
4241 /* Similarly find a string table. */
4242 if (dynamic_strings == NULL)
4244 for (i = 0, entry = dynamic_segment;
4248 unsigned long offset;
4251 if (entry->d_tag != DT_STRTAB)
4254 dynamic_info[DT_STRTAB] = entry->d_un.d_val;
4256 /* Since we do not know how big the string table is,
4257 we default to reading in the entire file (!) and
4258 processing that. This is overkill, I know, but it
4261 offset = entry->d_un.d_val - loadaddr;
4262 if (fseek (file, 0, SEEK_END))
4263 error (_("Unable to seek to end of file\n"));
4264 str_tab_len = ftell (file) - offset;
4266 if (str_tab_len < 1)
4269 (_("Unable to determine the length of the dynamic string table\n"));
4273 dynamic_strings = (char *) get_data (NULL, file, offset, str_tab_len,
4274 _("dynamic string table"));
4279 /* And find the syminfo section if available. */
4280 if (dynamic_syminfo == NULL)
4282 unsigned int syminsz = 0;
4284 for (i = 0, entry = dynamic_segment;
4288 if (entry->d_tag == DT_SYMINENT)
4290 /* Note: these braces are necessary to avoid a syntax
4291 error from the SunOS4 C compiler. */
4292 assert (sizeof (Elf_External_Syminfo) == entry->d_un.d_val);
4294 else if (entry->d_tag == DT_SYMINSZ)
4295 syminsz = entry->d_un.d_val;
4296 else if (entry->d_tag == DT_SYMINFO)
4297 dynamic_syminfo_offset = entry->d_un.d_val - loadaddr;
4300 if (dynamic_syminfo_offset != 0 && syminsz != 0)
4302 Elf_External_Syminfo * extsyminfo;
4303 Elf_Internal_Syminfo * syminfo;
4305 /* There is a syminfo section. Read the data. */
4306 extsyminfo = ((Elf_External_Syminfo *)
4307 get_data (NULL, file, dynamic_syminfo_offset,
4308 syminsz, _("symbol information")));
4312 dynamic_syminfo = (Elf_Internal_Syminfo *) malloc (syminsz);
4313 if (dynamic_syminfo == NULL)
4315 error (_("Out of memory\n"));
4319 dynamic_syminfo_nent = syminsz / sizeof (Elf_External_Syminfo);
4320 for (i = 0, syminfo = dynamic_syminfo; i < dynamic_syminfo_nent;
4323 syminfo->si_boundto = BYTE_GET (extsyminfo[i].si_boundto);
4324 syminfo->si_flags = BYTE_GET (extsyminfo[i].si_flags);
4331 if (do_dynamic && dynamic_addr)
4332 printf (_("\nDynamic segment at offset 0x%x contains %ld entries:\n"),
4333 dynamic_addr, (long) dynamic_size);
4335 printf (_(" Tag Type Name/Value\n"));
4337 for (i = 0, entry = dynamic_segment;
4346 print_vma (entry->d_tag, FULL_HEX);
4347 dtype = get_dynamic_type (entry->d_tag);
4348 printf (" (%s)%*s", dtype,
4349 ((is_32bit_elf ? 27 : 19)
4350 - (int) strlen (dtype)),
4354 switch (entry->d_tag)
4358 printf ("%s", get_dynamic_flags (entry->d_un.d_val));
4368 switch (entry->d_tag)
4371 printf (_("Auxiliary library"));
4375 printf (_("Filter library"));
4379 printf (_("Configuration file"));
4383 printf (_("Dependency audit library"));
4387 printf (_("Audit library"));
4391 if (dynamic_strings)
4392 printf (": [%s]\n", dynamic_strings + entry->d_un.d_val);
4396 print_vma (entry->d_un.d_val, PREFIX_HEX);
4405 printf (_("Flags:"));
4406 if (entry->d_un.d_val == 0)
4407 printf (_(" None\n"));
4410 unsigned long int val = entry->d_un.d_val;
4411 if (val & DTF_1_PARINIT)
4413 printf (" PARINIT");
4414 val ^= DTF_1_PARINIT;
4416 if (val & DTF_1_CONFEXP)
4418 printf (" CONFEXP");
4419 val ^= DTF_1_CONFEXP;
4422 printf (" %lx", val);
4431 printf (_("Flags:"));
4432 if (entry->d_un.d_val == 0)
4433 printf (_(" None\n"));
4436 unsigned long int val = entry->d_un.d_val;
4437 if (val & DF_P1_LAZYLOAD)
4439 printf (" LAZYLOAD");
4440 val ^= DF_P1_LAZYLOAD;
4442 if (val & DF_P1_GROUPPERM)
4444 printf (" GROUPPERM");
4445 val ^= DF_P1_GROUPPERM;
4448 printf (" %lx", val);
4457 printf (_("Flags:"));
4458 if (entry->d_un.d_val == 0)
4459 printf (_(" None\n"));
4462 unsigned long int val = entry->d_un.d_val;
4468 if (val & DF_1_GLOBAL)
4473 if (val & DF_1_GROUP)
4478 if (val & DF_1_NODELETE)
4480 printf (" NODELETE");
4481 val ^= DF_1_NODELETE;
4483 if (val & DF_1_LOADFLTR)
4485 printf (" LOADFLTR");
4486 val ^= DF_1_LOADFLTR;
4488 if (val & DF_1_INITFIRST)
4490 printf (" INITFIRST");
4491 val ^= DF_1_INITFIRST;
4493 if (val & DF_1_NOOPEN)
4498 if (val & DF_1_ORIGIN)
4503 if (val & DF_1_DIRECT)
4508 if (val & DF_1_TRANS)
4513 if (val & DF_1_INTERPOSE)
4515 printf (" INTERPOSE");
4516 val ^= DF_1_INTERPOSE;
4518 if (val & DF_1_NODEFLIB)
4520 printf (" NODEFLIB");
4521 val ^= DF_1_NODEFLIB;
4523 if (val & DF_1_NODUMP)
4528 if (val & DF_1_CONLFAT)
4530 printf (" CONLFAT");
4531 val ^= DF_1_CONLFAT;
4534 printf (" %lx", val);
4542 puts (get_dynamic_type (entry->d_un.d_val));
4562 dynamic_info[entry->d_tag] = entry->d_un.d_val;
4568 if (dynamic_strings == NULL)
4571 name = dynamic_strings + entry->d_un.d_val;
4575 switch (entry->d_tag)
4578 printf (_("Shared library: [%s]"), name);
4580 if (strcmp (name, program_interpreter) == 0)
4581 printf (_(" program interpreter"));
4585 printf (_("Library soname: [%s]"), name);
4589 printf (_("Library rpath: [%s]"), name);
4593 printf (_("Library runpath: [%s]"), name);
4597 print_vma (entry->d_un.d_val, PREFIX_HEX);
4602 print_vma (entry->d_un.d_val, PREFIX_HEX);
4618 case DT_INIT_ARRAYSZ:
4619 case DT_FINI_ARRAYSZ:
4622 print_vma (entry->d_un.d_val, UNSIGNED);
4623 printf (" (bytes)\n");
4633 print_vma (entry->d_un.d_val, UNSIGNED);
4646 if (dynamic_strings != NULL && entry->d_tag == DT_USED)
4650 name = dynamic_strings + entry->d_un.d_val;
4654 printf (_("Not needed object: [%s]\n"), name);
4659 print_vma (entry->d_un.d_val, PREFIX_HEX);
4665 /* The value of this entry is ignored. */
4669 if ((entry->d_tag >= DT_VERSYM) && (entry->d_tag <= DT_VERNEEDNUM))
4670 version_info [DT_VERSIONTAGIDX (entry->d_tag)] =
4675 switch (elf_header.e_machine)
4678 case EM_MIPS_RS3_LE:
4679 dynamic_segment_mips_val (entry);
4682 dynamic_segment_parisc_val (entry);
4685 print_vma (entry->d_un.d_val, PREFIX_HEX);
4697 get_ver_flags (flags)
4700 static char buff [32];
4707 if (flags & VER_FLG_BASE)
4708 strcat (buff, "BASE ");
4710 if (flags & VER_FLG_WEAK)
4712 if (flags & VER_FLG_BASE)
4713 strcat (buff, "| ");
4715 strcat (buff, "WEAK ");
4718 if (flags & ~(VER_FLG_BASE | VER_FLG_WEAK))
4719 strcat (buff, "| <unknown>");
4724 /* Display the contents of the version sections. */
4726 process_version_sections (file)
4729 Elf32_Internal_Shdr * section;
4736 for (i = 0, section = section_headers;
4737 i < elf_header.e_shnum;
4740 switch (section->sh_type)
4742 case SHT_GNU_verdef:
4744 Elf_External_Verdef * edefs;
4751 (_("\nVersion definition section '%s' contains %ld entries:\n"),
4752 SECTION_NAME (section), section->sh_info);
4754 printf (_(" Addr: 0x"));
4755 printf_vma (section->sh_addr);
4756 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
4757 (unsigned long) section->sh_offset, section->sh_link,
4758 SECTION_NAME (SECTION_HEADER (section->sh_link)));
4760 edefs = ((Elf_External_Verdef *)
4761 get_data (NULL, file, section->sh_offset,
4763 _("version definition section")));
4767 for (idx = cnt = 0; cnt < section->sh_info; ++ cnt)
4770 Elf_External_Verdef * edef;
4771 Elf_Internal_Verdef ent;
4772 Elf_External_Verdaux * eaux;
4773 Elf_Internal_Verdaux aux;
4777 vstart = ((char *) edefs) + idx;
4779 edef = (Elf_External_Verdef *) vstart;
4781 ent.vd_version = BYTE_GET (edef->vd_version);
4782 ent.vd_flags = BYTE_GET (edef->vd_flags);
4783 ent.vd_ndx = BYTE_GET (edef->vd_ndx);
4784 ent.vd_cnt = BYTE_GET (edef->vd_cnt);
4785 ent.vd_hash = BYTE_GET (edef->vd_hash);
4786 ent.vd_aux = BYTE_GET (edef->vd_aux);
4787 ent.vd_next = BYTE_GET (edef->vd_next);
4789 printf (_(" %#06x: Rev: %d Flags: %s"),
4790 idx, ent.vd_version, get_ver_flags (ent.vd_flags));
4792 printf (_(" Index: %d Cnt: %d "),
4793 ent.vd_ndx, ent.vd_cnt);
4795 vstart += ent.vd_aux;
4797 eaux = (Elf_External_Verdaux *) vstart;
4799 aux.vda_name = BYTE_GET (eaux->vda_name);
4800 aux.vda_next = BYTE_GET (eaux->vda_next);
4802 if (dynamic_strings)
4803 printf (_("Name: %s\n"), dynamic_strings + aux.vda_name);
4805 printf (_("Name index: %ld\n"), aux.vda_name);
4807 isum = idx + ent.vd_aux;
4809 for (j = 1; j < ent.vd_cnt; j ++)
4811 isum += aux.vda_next;
4812 vstart += aux.vda_next;
4814 eaux = (Elf_External_Verdaux *) vstart;
4816 aux.vda_name = BYTE_GET (eaux->vda_name);
4817 aux.vda_next = BYTE_GET (eaux->vda_next);
4819 if (dynamic_strings)
4820 printf (_(" %#06x: Parent %d: %s\n"),
4821 isum, j, dynamic_strings + aux.vda_name);
4823 printf (_(" %#06x: Parent %d, name index: %ld\n"),
4824 isum, j, aux.vda_name);
4834 case SHT_GNU_verneed:
4836 Elf_External_Verneed * eneed;
4842 printf (_("\nVersion needs section '%s' contains %ld entries:\n"),
4843 SECTION_NAME (section), section->sh_info);
4845 printf (_(" Addr: 0x"));
4846 printf_vma (section->sh_addr);
4847 printf (_(" Offset: %#08lx Link to section: %ld (%s)\n"),
4848 (unsigned long) section->sh_offset, section->sh_link,
4849 SECTION_NAME (SECTION_HEADER (section->sh_link)));
4851 eneed = ((Elf_External_Verneed *)
4852 get_data (NULL, file, section->sh_offset,
4853 section->sh_size, _("version need section")));
4857 for (idx = cnt = 0; cnt < section->sh_info; ++cnt)
4859 Elf_External_Verneed * entry;
4860 Elf_Internal_Verneed ent;
4865 vstart = ((char *) eneed) + idx;
4867 entry = (Elf_External_Verneed *) vstart;
4869 ent.vn_version = BYTE_GET (entry->vn_version);
4870 ent.vn_cnt = BYTE_GET (entry->vn_cnt);
4871 ent.vn_file = BYTE_GET (entry->vn_file);
4872 ent.vn_aux = BYTE_GET (entry->vn_aux);
4873 ent.vn_next = BYTE_GET (entry->vn_next);
4875 printf (_(" %#06x: Version: %d"), idx, ent.vn_version);
4877 if (dynamic_strings)
4878 printf (_(" File: %s"), dynamic_strings + ent.vn_file);
4880 printf (_(" File: %lx"), ent.vn_file);
4882 printf (_(" Cnt: %d\n"), ent.vn_cnt);
4884 vstart += ent.vn_aux;
4886 for (j = 0, isum = idx + ent.vn_aux; j < ent.vn_cnt; ++j)
4888 Elf_External_Vernaux * eaux;
4889 Elf_Internal_Vernaux aux;
4891 eaux = (Elf_External_Vernaux *) vstart;
4893 aux.vna_hash = BYTE_GET (eaux->vna_hash);
4894 aux.vna_flags = BYTE_GET (eaux->vna_flags);
4895 aux.vna_other = BYTE_GET (eaux->vna_other);
4896 aux.vna_name = BYTE_GET (eaux->vna_name);
4897 aux.vna_next = BYTE_GET (eaux->vna_next);
4899 if (dynamic_strings)
4900 printf (_(" %#06x: Name: %s"),
4901 isum, dynamic_strings + aux.vna_name);
4903 printf (_(" %#06x: Name index: %lx"),
4904 isum, aux.vna_name);
4906 printf (_(" Flags: %s Version: %d\n"),
4907 get_ver_flags (aux.vna_flags), aux.vna_other);
4909 isum += aux.vna_next;
4910 vstart += aux.vna_next;
4920 case SHT_GNU_versym:
4922 Elf32_Internal_Shdr * link_section;
4925 unsigned char * edata;
4926 unsigned short * data;
4928 Elf_Internal_Sym * symbols;
4929 Elf32_Internal_Shdr * string_sec;
4931 link_section = SECTION_HEADER (section->sh_link);
4932 total = section->sh_size / section->sh_entsize;
4936 symbols = GET_ELF_SYMBOLS (file, link_section);
4938 string_sec = SECTION_HEADER (link_section->sh_link);
4940 strtab = (char *) get_data (NULL, file, string_sec->sh_offset,
4941 string_sec->sh_size,
4942 _("version string table"));
4946 printf (_("\nVersion symbols section '%s' contains %d entries:\n"),
4947 SECTION_NAME (section), total);
4949 printf (_(" Addr: "));
4950 printf_vma (section->sh_addr);
4951 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
4952 (unsigned long) section->sh_offset, section->sh_link,
4953 SECTION_NAME (link_section));
4957 get_data (NULL, file,
4958 version_info[DT_VERSIONTAGIDX (DT_VERSYM)] - loadaddr,
4959 total * sizeof (short), _("version symbol data")));
4966 data = (unsigned short *) malloc (total * sizeof (short));
4968 for (cnt = total; cnt --;)
4969 data [cnt] = byte_get (edata + cnt * sizeof (short),
4974 for (cnt = 0; cnt < total; cnt += 4)
4977 int check_def, check_need;
4980 printf (" %03x:", cnt);
4982 for (j = 0; (j < 4) && (cnt + j) < total; ++j)
4983 switch (data [cnt + j])
4986 fputs (_(" 0 (*local*) "), stdout);
4990 fputs (_(" 1 (*global*) "), stdout);
4994 nn = printf ("%4x%c", data [cnt + j] & 0x7fff,
4995 data [cnt + j] & 0x8000 ? 'h' : ' ');
4999 if (SECTION_HEADER (symbols [cnt + j].st_shndx)->sh_type
5002 if (symbols [cnt + j].st_shndx == SHN_UNDEF)
5009 && version_info [DT_VERSIONTAGIDX (DT_VERNEED)])
5011 Elf_Internal_Verneed ivn;
5012 unsigned long offset;
5014 offset = version_info [DT_VERSIONTAGIDX (DT_VERNEED)]
5019 Elf_Internal_Vernaux ivna;
5020 Elf_External_Verneed evn;
5021 Elf_External_Vernaux evna;
5022 unsigned long a_off;
5024 get_data (&evn, file, offset, sizeof (evn),
5027 ivn.vn_aux = BYTE_GET (evn.vn_aux);
5028 ivn.vn_next = BYTE_GET (evn.vn_next);
5030 a_off = offset + ivn.vn_aux;
5034 get_data (&evna, file, a_off, sizeof (evna),
5035 _("version need aux (2)"));
5037 ivna.vna_next = BYTE_GET (evna.vna_next);
5038 ivna.vna_other = BYTE_GET (evna.vna_other);
5040 a_off += ivna.vna_next;
5042 while (ivna.vna_other != data [cnt + j]
5043 && ivna.vna_next != 0);
5045 if (ivna.vna_other == data [cnt + j])
5047 ivna.vna_name = BYTE_GET (evna.vna_name);
5049 name = strtab + ivna.vna_name;
5050 nn += printf ("(%s%-*s",
5052 12 - (int) strlen (name),
5058 offset += ivn.vn_next;
5060 while (ivn.vn_next);
5063 if (check_def && data [cnt + j] != 0x8001
5064 && version_info [DT_VERSIONTAGIDX (DT_VERDEF)])
5066 Elf_Internal_Verdef ivd;
5067 Elf_External_Verdef evd;
5068 unsigned long offset;
5070 offset = version_info
5071 [DT_VERSIONTAGIDX (DT_VERDEF)] - loadaddr;
5075 get_data (&evd, file, offset, sizeof (evd),
5078 ivd.vd_next = BYTE_GET (evd.vd_next);
5079 ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
5081 offset += ivd.vd_next;
5083 while (ivd.vd_ndx != (data [cnt + j] & 0x7fff)
5084 && ivd.vd_next != 0);
5086 if (ivd.vd_ndx == (data [cnt + j] & 0x7fff))
5088 Elf_External_Verdaux evda;
5089 Elf_Internal_Verdaux ivda;
5091 ivd.vd_aux = BYTE_GET (evd.vd_aux);
5093 get_data (&evda, file,
5094 offset - ivd.vd_next + ivd.vd_aux,
5095 sizeof (evda), _("version def aux"));
5097 ivda.vda_name = BYTE_GET (evda.vda_name);
5099 name = strtab + ivda.vda_name;
5100 nn += printf ("(%s%-*s",
5102 12 - (int) strlen (name),
5108 printf ("%*c", 18 - nn, ' ');
5126 printf (_("\nNo version information found in this file.\n"));
5132 get_symbol_binding (binding)
5133 unsigned int binding;
5135 static char buff [32];
5139 case STB_LOCAL: return "LOCAL";
5140 case STB_GLOBAL: return "GLOBAL";
5141 case STB_WEAK: return "WEAK";
5143 if (binding >= STB_LOPROC && binding <= STB_HIPROC)
5144 sprintf (buff, _("<processor specific>: %d"), binding);
5145 else if (binding >= STB_LOOS && binding <= STB_HIOS)
5146 sprintf (buff, _("<OS specific>: %d"), binding);
5148 sprintf (buff, _("<unknown>: %d"), binding);
5154 get_symbol_type (type)
5157 static char buff [32];
5161 case STT_NOTYPE: return "NOTYPE";
5162 case STT_OBJECT: return "OBJECT";
5163 case STT_FUNC: return "FUNC";
5164 case STT_SECTION: return "SECTION";
5165 case STT_FILE: return "FILE";
5166 case STT_COMMON: return "COMMON";
5168 if (type >= STT_LOPROC && type <= STT_HIPROC)
5170 if (elf_header.e_machine == EM_ARM && type == STT_ARM_TFUNC)
5171 return "THUMB_FUNC";
5173 if (elf_header.e_machine == EM_SPARCV9 && type == STT_REGISTER)
5176 if (elf_header.e_machine == EM_PARISC && type == STT_PARISC_MILLI)
5177 return "PARISC_MILLI";
5179 sprintf (buff, _("<processor specific>: %d"), type);
5181 else if (type >= STT_LOOS && type <= STT_HIOS)
5183 if (elf_header.e_machine == EM_PARISC)
5185 if (type == STT_HP_OPAQUE)
5187 if (type == STT_HP_STUB)
5191 sprintf (buff, _("<OS specific>: %d"), type);
5194 sprintf (buff, _("<unknown>: %d"), type);
5200 get_symbol_visibility (visibility)
5201 unsigned int visibility;
5205 case STV_DEFAULT: return "DEFAULT";
5206 case STV_INTERNAL: return "INTERNAL";
5207 case STV_HIDDEN: return "HIDDEN";
5208 case STV_PROTECTED: return "PROTECTED";
5214 get_symbol_index_type (type)
5219 case SHN_UNDEF: return "UND";
5220 case SHN_ABS: return "ABS";
5221 case SHN_COMMON: return "COM";
5223 if (type >= SHN_LOPROC && type <= SHN_HIPROC)
5225 else if (type >= SHN_LOOS && type <= SHN_HIOS)
5227 else if (type >= SHN_LORESERVE && type <= SHN_HIRESERVE)
5231 static char buff [32];
5233 sprintf (buff, "%3d", type);
5240 get_dynamic_data (file, number)
5242 unsigned int number;
5244 unsigned char * e_data;
5247 e_data = (unsigned char *) malloc (number * 4);
5251 error (_("Out of memory\n"));
5255 if (fread (e_data, 4, number, file) != number)
5257 error (_("Unable to read in dynamic data\n"));
5261 i_data = (int *) malloc (number * sizeof (* i_data));
5265 error (_("Out of memory\n"));
5271 i_data [number] = byte_get (e_data + number * 4, 4);
5278 /* Dump the symbol table. */
5280 process_symbol_table (file)
5283 Elf32_Internal_Shdr * section;
5284 unsigned char nb [4];
5285 unsigned char nc [4];
5288 int * buckets = NULL;
5289 int * chains = NULL;
5291 if (! do_syms && !do_histogram)
5294 if (dynamic_info[DT_HASH] && ((do_using_dynamic && dynamic_strings != NULL)
5297 if (fseek (file, dynamic_info[DT_HASH] - loadaddr, SEEK_SET))
5299 error (_("Unable to seek to start of dynamic information"));
5303 if (fread (nb, sizeof (nb), 1, file) != 1)
5305 error (_("Failed to read in number of buckets\n"));
5309 if (fread (nc, sizeof (nc), 1, file) != 1)
5311 error (_("Failed to read in number of chains\n"));
5315 nbuckets = byte_get (nb, 4);
5316 nchains = byte_get (nc, 4);
5318 buckets = get_dynamic_data (file, nbuckets);
5319 chains = get_dynamic_data (file, nchains);
5321 if (buckets == NULL || chains == NULL)
5326 && dynamic_info[DT_HASH] && do_using_dynamic && dynamic_strings != NULL)
5331 printf (_("\nSymbol table for image:\n"));
5333 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
5335 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
5337 for (hn = 0; hn < nbuckets; hn++)
5342 for (si = buckets [hn]; si < nchains && si > 0; si = chains [si])
5344 Elf_Internal_Sym * psym;
5346 psym = dynamic_symbols + si;
5348 printf (" %3d %3d: ", si, hn);
5349 print_vma (psym->st_value, LONG_HEX);
5351 print_vma (psym->st_size, DEC_5);
5353 printf (" %6s", get_symbol_type (ELF_ST_TYPE (psym->st_info)));
5354 printf (" %6s", get_symbol_binding (ELF_ST_BIND (psym->st_info)));
5355 printf (" %3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym->st_other)));
5356 printf (" %3.3s ", get_symbol_index_type (psym->st_shndx));
5357 print_symbol (25, dynamic_strings + psym->st_name);
5362 else if (do_syms && !do_using_dynamic)
5366 for (i = 0, section = section_headers;
5367 i < elf_header.e_shnum;
5372 Elf_Internal_Sym * symtab;
5373 Elf_Internal_Sym * psym;
5376 if ( section->sh_type != SHT_SYMTAB
5377 && section->sh_type != SHT_DYNSYM)
5380 printf (_("\nSymbol table '%s' contains %lu entries:\n"),
5381 SECTION_NAME (section),
5382 (unsigned long) (section->sh_size / section->sh_entsize));
5384 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
5386 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
5388 symtab = GET_ELF_SYMBOLS (file, section);
5392 if (section->sh_link == elf_header.e_shstrndx)
5393 strtab = string_table;
5396 Elf32_Internal_Shdr * string_sec;
5398 string_sec = SECTION_HEADER (section->sh_link);
5400 strtab = (char *) get_data (NULL, file, string_sec->sh_offset,
5401 string_sec->sh_size,
5405 for (si = 0, psym = symtab;
5406 si < section->sh_size / section->sh_entsize;
5409 printf ("%6d: ", si);
5410 print_vma (psym->st_value, LONG_HEX);
5412 print_vma (psym->st_size, DEC_5);
5413 printf (" %-7s", get_symbol_type (ELF_ST_TYPE (psym->st_info)));
5414 printf (" %-6s", get_symbol_binding (ELF_ST_BIND (psym->st_info)));
5415 printf (" %-3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym->st_other)));
5416 printf (" %4s ", get_symbol_index_type (psym->st_shndx));
5417 print_symbol (25, strtab + psym->st_name);
5419 if (section->sh_type == SHT_DYNSYM &&
5420 version_info [DT_VERSIONTAGIDX (DT_VERSYM)] != 0)
5422 unsigned char data[2];
5423 unsigned short vers_data;
5424 unsigned long offset;
5428 offset = version_info [DT_VERSIONTAGIDX (DT_VERSYM)]
5431 get_data (&data, file, offset + si * sizeof (vers_data),
5432 sizeof (data), _("version data"));
5434 vers_data = byte_get (data, 2);
5436 is_nobits = (SECTION_HEADER (psym->st_shndx)->sh_type
5439 check_def = (psym->st_shndx != SHN_UNDEF);
5441 if ((vers_data & 0x8000) || vers_data > 1)
5443 if (version_info [DT_VERSIONTAGIDX (DT_VERNEED)]
5444 && (is_nobits || ! check_def))
5446 Elf_External_Verneed evn;
5447 Elf_Internal_Verneed ivn;
5448 Elf_Internal_Vernaux ivna;
5450 /* We must test both. */
5451 offset = version_info
5452 [DT_VERSIONTAGIDX (DT_VERNEED)] - loadaddr;
5456 unsigned long vna_off;
5458 get_data (&evn, file, offset, sizeof (evn),
5461 ivn.vn_aux = BYTE_GET (evn.vn_aux);
5462 ivn.vn_next = BYTE_GET (evn.vn_next);
5464 vna_off = offset + ivn.vn_aux;
5468 Elf_External_Vernaux evna;
5470 get_data (&evna, file, vna_off,
5472 _("version need aux (3)"));
5474 ivna.vna_other = BYTE_GET (evna.vna_other);
5475 ivna.vna_next = BYTE_GET (evna.vna_next);
5476 ivna.vna_name = BYTE_GET (evna.vna_name);
5478 vna_off += ivna.vna_next;
5480 while (ivna.vna_other != vers_data
5481 && ivna.vna_next != 0);
5483 if (ivna.vna_other == vers_data)
5486 offset += ivn.vn_next;
5488 while (ivn.vn_next != 0);
5490 if (ivna.vna_other == vers_data)
5493 strtab + ivna.vna_name, ivna.vna_other);
5496 else if (! is_nobits)
5497 error (_("bad dynamic symbol"));
5504 if (vers_data != 0x8001
5505 && version_info [DT_VERSIONTAGIDX (DT_VERDEF)])
5507 Elf_Internal_Verdef ivd;
5508 Elf_Internal_Verdaux ivda;
5509 Elf_External_Verdaux evda;
5510 unsigned long offset;
5513 version_info [DT_VERSIONTAGIDX (DT_VERDEF)]
5518 Elf_External_Verdef evd;
5520 get_data (&evd, file, offset, sizeof (evd),
5523 ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
5524 ivd.vd_aux = BYTE_GET (evd.vd_aux);
5525 ivd.vd_next = BYTE_GET (evd.vd_next);
5527 offset += ivd.vd_next;
5529 while (ivd.vd_ndx != (vers_data & 0x7fff)
5530 && ivd.vd_next != 0);
5532 offset -= ivd.vd_next;
5533 offset += ivd.vd_aux;
5535 get_data (&evda, file, offset, sizeof (evda),
5536 _("version def aux"));
5538 ivda.vda_name = BYTE_GET (evda.vda_name);
5540 if (psym->st_name != ivda.vda_name)
5541 printf ((vers_data & 0x8000)
5543 strtab + ivda.vda_name);
5553 if (strtab != string_table)
5559 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
5561 if (do_histogram && buckets != NULL)
5568 int nzero_counts = 0;
5571 printf (_("\nHistogram for bucket list length (total of %d buckets):\n"),
5573 printf (_(" Length Number %% of total Coverage\n"));
5575 lengths = (int *) calloc (nbuckets, sizeof (int));
5576 if (lengths == NULL)
5578 error (_("Out of memory"));
5581 for (hn = 0; hn < nbuckets; ++hn)
5586 for (si = buckets[hn]; si > 0 && si < nchains; si = chains[si])
5589 if (maxlength < ++lengths[hn])
5594 counts = (int *) calloc (maxlength + 1, sizeof (int));
5597 error (_("Out of memory"));
5601 for (hn = 0; hn < nbuckets; ++hn)
5602 ++ counts [lengths [hn]];
5606 printf (" 0 %-10d (%5.1f%%)\n",
5607 counts[0], (counts[0] * 100.0) / nbuckets);
5608 for (si = 1; si <= maxlength; ++si)
5610 nzero_counts += counts[si] * si;
5611 printf ("%7d %-10d (%5.1f%%) %5.1f%%\n",
5612 si, counts[si], (counts[si] * 100.0) / nbuckets,
5613 (nzero_counts * 100.0) / nsyms);
5621 if (buckets != NULL)
5631 process_syminfo (file)
5632 FILE * file ATTRIBUTE_UNUSED;
5636 if (dynamic_syminfo == NULL
5638 /* No syminfo, this is ok. */
5641 /* There better should be a dynamic symbol section. */
5642 if (dynamic_symbols == NULL || dynamic_strings == NULL)
5646 printf (_("\nDynamic info segment at offset 0x%lx contains %d entries:\n"),
5647 dynamic_syminfo_offset, dynamic_syminfo_nent);
5649 printf (_(" Num: Name BoundTo Flags\n"));
5650 for (i = 0; i < dynamic_syminfo_nent; ++i)
5652 unsigned short int flags = dynamic_syminfo[i].si_flags;
5654 printf ("%4d: ", i);
5655 print_symbol (30, dynamic_strings + dynamic_symbols[i].st_name);
5658 switch (dynamic_syminfo[i].si_boundto)
5660 case SYMINFO_BT_SELF:
5661 fputs ("SELF ", stdout);
5663 case SYMINFO_BT_PARENT:
5664 fputs ("PARENT ", stdout);
5667 if (dynamic_syminfo[i].si_boundto > 0
5668 && dynamic_syminfo[i].si_boundto < dynamic_size)
5670 print_symbol (10, dynamic_strings
5672 [dynamic_syminfo[i].si_boundto].d_un.d_val);
5676 printf ("%-10d ", dynamic_syminfo[i].si_boundto);
5680 if (flags & SYMINFO_FLG_DIRECT)
5682 if (flags & SYMINFO_FLG_PASSTHRU)
5683 printf (" PASSTHRU");
5684 if (flags & SYMINFO_FLG_COPY)
5686 if (flags & SYMINFO_FLG_LAZYLOAD)
5687 printf (" LAZYLOAD");
5695 #ifdef SUPPORT_DISASSEMBLY
5697 disassemble_section (section, file)
5698 Elf32_Internal_Shdr * section;
5701 printf (_("\nAssembly dump of section %s\n"),
5702 SECTION_NAME (section));
5704 /* XXX -- to be done --- XXX */
5711 dump_section (section, file)
5712 Elf32_Internal_Shdr * section;
5715 bfd_size_type bytes;
5717 unsigned char * data;
5718 unsigned char * start;
5720 bytes = section->sh_size;
5724 printf (_("\nSection '%s' has no data to dump.\n"),
5725 SECTION_NAME (section));
5729 printf (_("\nHex dump of section '%s':\n"), SECTION_NAME (section));
5731 addr = section->sh_addr;
5733 start = (unsigned char *) get_data (NULL, file, section->sh_offset, bytes,
5746 lbytes = (bytes > 16 ? 16 : bytes);
5748 printf (" 0x%8.8lx ", (unsigned long) addr);
5750 switch (elf_header.e_ident [EI_DATA])
5754 for (j = 15; j >= 0; j --)
5757 printf ("%2.2x", data [j]);
5767 for (j = 0; j < 16; j++)
5770 printf ("%2.2x", data [j]);
5780 for (j = 0; j < lbytes; j++)
5783 if (k >= ' ' && k < 0x80)
5802 static unsigned long int
5803 read_leb128 (data, length_return, sign)
5804 unsigned char * data;
5805 int * length_return;
5808 unsigned long int result = 0;
5809 unsigned int num_read = 0;
5818 result |= (byte & 0x7f) << shift;
5823 while (byte & 0x80);
5825 if (length_return != NULL)
5826 * length_return = num_read;
5828 if (sign && (shift < 32) && (byte & 0x40))
5829 result |= -1 << shift;
5834 typedef struct State_Machine_Registers
5836 unsigned long address;
5839 unsigned int column;
5843 /* This variable hold the number of the last entry seen
5844 in the File Table. */
5845 unsigned int last_file_entry;
5848 static SMR state_machine_regs;
5851 reset_state_machine (is_stmt)
5854 state_machine_regs.address = 0;
5855 state_machine_regs.file = 1;
5856 state_machine_regs.line = 1;
5857 state_machine_regs.column = 0;
5858 state_machine_regs.is_stmt = is_stmt;
5859 state_machine_regs.basic_block = 0;
5860 state_machine_regs.end_sequence = 0;
5861 state_machine_regs.last_file_entry = 0;
5864 /* Handled an extend line op. Returns true if this is the end
5867 process_extended_line_op (data, is_stmt, pointer_size)
5868 unsigned char * data;
5872 unsigned char op_code;
5875 unsigned char * name;
5878 len = read_leb128 (data, & bytes_read, 0);
5883 warn (_("badly formed extended line op encountered!\n"));
5888 op_code = * data ++;
5890 printf (_(" Extended opcode %d: "), op_code);
5894 case DW_LNE_end_sequence:
5895 printf (_("End of Sequence\n\n"));
5896 reset_state_machine (is_stmt);
5899 case DW_LNE_set_address:
5900 adr = byte_get (data, pointer_size);
5901 printf (_("set Address to 0x%lx\n"), adr);
5902 state_machine_regs.address = adr;
5905 case DW_LNE_define_file:
5906 printf (_(" define new File Table entry\n"));
5907 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
5909 printf (_(" %d\t"), ++ state_machine_regs.last_file_entry);
5911 data += strlen ((char *) data) + 1;
5912 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
5914 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
5916 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
5917 printf (_("%s\n\n"), name);
5921 printf (_("UNKNOWN: length %d\n"), len - bytes_read);
5928 /* Size of pointers in the .debug_line section. This information is not
5929 really present in that section. It's obtained before dumping the debug
5930 sections by doing some pre-scan of the .debug_info section. */
5931 static int debug_line_pointer_size = 4;
5934 display_debug_lines (section, start, file)
5935 Elf32_Internal_Shdr * section;
5936 unsigned char * start;
5937 FILE * file ATTRIBUTE_UNUSED;
5939 DWARF2_External_LineInfo * external;
5940 DWARF2_Internal_LineInfo info;
5941 unsigned char * standard_opcodes;
5942 unsigned char * data = start;
5943 unsigned char * end = start + section->sh_size;
5944 unsigned char * end_of_sequence;
5947 printf (_("\nDump of debug contents of section %s:\n\n"),
5948 SECTION_NAME (section));
5952 external = (DWARF2_External_LineInfo *) data;
5954 /* Check the length of the block. */
5955 info.li_length = BYTE_GET (external->li_length);
5957 if (info.li_length == 0xffffffff)
5959 warn (_("64-bit DWARF line info is not supported yet.\n"));
5963 if (info.li_length + sizeof (external->li_length) > section->sh_size)
5966 (_("The line info appears to be corrupt - the section is too small\n"));
5970 /* Check its version number. */
5971 info.li_version = BYTE_GET (external->li_version);
5972 if (info.li_version != 2)
5974 warn (_("Only DWARF version 2 line info is currently supported.\n"));
5978 info.li_prologue_length = BYTE_GET (external->li_prologue_length);
5979 info.li_min_insn_length = BYTE_GET (external->li_min_insn_length);
5980 info.li_default_is_stmt = BYTE_GET (external->li_default_is_stmt);
5981 info.li_line_base = BYTE_GET (external->li_line_base);
5982 info.li_line_range = BYTE_GET (external->li_line_range);
5983 info.li_opcode_base = BYTE_GET (external->li_opcode_base);
5985 /* Sign extend the line base field. */
5986 info.li_line_base <<= 24;
5987 info.li_line_base >>= 24;
5989 printf (_(" Length: %ld\n"), info.li_length);
5990 printf (_(" DWARF Version: %d\n"), info.li_version);
5991 printf (_(" Prologue Length: %d\n"), info.li_prologue_length);
5992 printf (_(" Minimum Instruction Length: %d\n"), info.li_min_insn_length);
5993 printf (_(" Initial value of 'is_stmt': %d\n"), info.li_default_is_stmt);
5994 printf (_(" Line Base: %d\n"), info.li_line_base);
5995 printf (_(" Line Range: %d\n"), info.li_line_range);
5996 printf (_(" Opcode Base: %d\n"), info.li_opcode_base);
5998 end_of_sequence = data + info.li_length + sizeof (external->li_length);
6000 reset_state_machine (info.li_default_is_stmt);
6002 /* Display the contents of the Opcodes table. */
6003 standard_opcodes = data + sizeof (* external);
6005 printf (_("\n Opcodes:\n"));
6007 for (i = 1; i < info.li_opcode_base; i++)
6008 printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]);
6010 /* Display the contents of the Directory table. */
6011 data = standard_opcodes + info.li_opcode_base - 1;
6014 printf (_("\n The Directory Table is empty.\n"));
6017 printf (_("\n The Directory Table:\n"));
6021 printf (_(" %s\n"), data);
6023 data += strlen ((char *) data) + 1;
6027 /* Skip the NUL at the end of the table. */
6030 /* Display the contents of the File Name table. */
6032 printf (_("\n The File Name Table is empty.\n"));
6035 printf (_("\n The File Name Table:\n"));
6036 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
6040 unsigned char * name;
6043 printf (_(" %d\t"), ++ state_machine_regs.last_file_entry);
6046 data += strlen ((char *) data) + 1;
6048 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
6050 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
6052 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
6054 printf (_("%s\n"), name);
6058 /* Skip the NUL at the end of the table. */
6061 /* Now display the statements. */
6062 printf (_("\n Line Number Statements:\n"));
6065 while (data < end_of_sequence)
6067 unsigned char op_code;
6071 op_code = * data ++;
6073 if (op_code >= info.li_opcode_base)
6075 op_code -= info.li_opcode_base;
6076 adv = (op_code / info.li_line_range) * info.li_min_insn_length;
6077 state_machine_regs.address += adv;
6078 printf (_(" Special opcode %d: advance Address by %d to 0x%lx"),
6079 op_code, adv, state_machine_regs.address);
6080 adv = (op_code % info.li_line_range) + info.li_line_base;
6081 state_machine_regs.line += adv;
6082 printf (_(" and Line by %d to %d\n"),
6083 adv, state_machine_regs.line);
6085 else switch (op_code)
6087 case DW_LNS_extended_op:
6088 data += process_extended_line_op (data, info.li_default_is_stmt,
6089 debug_line_pointer_size);
6093 printf (_(" Copy\n"));
6096 case DW_LNS_advance_pc:
6097 adv = info.li_min_insn_length * read_leb128 (data, & bytes_read, 0);
6099 state_machine_regs.address += adv;
6100 printf (_(" Advance PC by %d to %lx\n"), adv,
6101 state_machine_regs.address);
6104 case DW_LNS_advance_line:
6105 adv = read_leb128 (data, & bytes_read, 1);
6107 state_machine_regs.line += adv;
6108 printf (_(" Advance Line by %d to %d\n"), adv,
6109 state_machine_regs.line);
6112 case DW_LNS_set_file:
6113 adv = read_leb128 (data, & bytes_read, 0);
6115 printf (_(" Set File Name to entry %d in the File Name Table\n"),
6117 state_machine_regs.file = adv;
6120 case DW_LNS_set_column:
6121 adv = read_leb128 (data, & bytes_read, 0);
6123 printf (_(" Set column to %d\n"), adv);
6124 state_machine_regs.column = adv;
6127 case DW_LNS_negate_stmt:
6128 adv = state_machine_regs.is_stmt;
6130 printf (_(" Set is_stmt to %d\n"), adv);
6131 state_machine_regs.is_stmt = adv;
6134 case DW_LNS_set_basic_block:
6135 printf (_(" Set basic block\n"));
6136 state_machine_regs.basic_block = 1;
6139 case DW_LNS_const_add_pc:
6140 adv = (((255 - info.li_opcode_base) / info.li_line_range)
6141 * info.li_min_insn_length);
6142 state_machine_regs.address += adv;
6143 printf (_(" Advance PC by constant %d to 0x%lx\n"), adv,
6144 state_machine_regs.address);
6147 case DW_LNS_fixed_advance_pc:
6148 adv = byte_get (data, 2);
6150 state_machine_regs.address += adv;
6151 printf (_(" Advance PC by fixed size amount %d to 0x%lx\n"),
6152 adv, state_machine_regs.address);
6155 case DW_LNS_set_prologue_end:
6156 printf (_(" Set prologue_end to true\n"));
6159 case DW_LNS_set_epilogue_begin:
6160 printf (_(" Set epilogue_begin to true\n"));
6163 case DW_LNS_set_isa:
6164 adv = read_leb128 (data, & bytes_read, 0);
6166 printf (_(" Set ISA to %d\n"), adv);
6170 printf (_(" Unknown opcode %d with operands: "), op_code);
6173 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
6175 printf ("0x%lx%s", read_leb128 (data, &bytes_read, 0),
6176 i == 1 ? "" : ", ");
6191 display_debug_pubnames (section, start, file)
6192 Elf32_Internal_Shdr * section;
6193 unsigned char * start;
6194 FILE * file ATTRIBUTE_UNUSED;
6196 DWARF2_External_PubNames * external;
6197 DWARF2_Internal_PubNames pubnames;
6198 unsigned char * end;
6200 end = start + section->sh_size;
6202 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section));
6206 unsigned char * data;
6207 unsigned long offset;
6209 external = (DWARF2_External_PubNames *) start;
6211 pubnames.pn_length = BYTE_GET (external->pn_length);
6212 pubnames.pn_version = BYTE_GET (external->pn_version);
6213 pubnames.pn_offset = BYTE_GET (external->pn_offset);
6214 pubnames.pn_size = BYTE_GET (external->pn_size);
6216 data = start + sizeof (* external);
6217 start += pubnames.pn_length + sizeof (external->pn_length);
6219 if (pubnames.pn_length == 0xffffffff)
6221 warn (_("64-bit DWARF pubnames are not supported yet.\n"));
6225 if (pubnames.pn_version != 2)
6227 static int warned = 0;
6231 warn (_("Only DWARF 2 pubnames are currently supported\n"));
6238 printf (_(" Length: %ld\n"),
6239 pubnames.pn_length);
6240 printf (_(" Version: %d\n"),
6241 pubnames.pn_version);
6242 printf (_(" Offset into .debug_info section: %ld\n"),
6243 pubnames.pn_offset);
6244 printf (_(" Size of area in .debug_info section: %ld\n"),
6247 printf (_("\n Offset\tName\n"));
6251 offset = byte_get (data, 4);
6256 printf (" %ld\t\t%s\n", offset, data);
6257 data += strlen ((char *) data) + 1;
6260 while (offset != 0);
6273 case DW_TAG_padding: return "DW_TAG_padding";
6274 case DW_TAG_array_type: return "DW_TAG_array_type";
6275 case DW_TAG_class_type: return "DW_TAG_class_type";
6276 case DW_TAG_entry_point: return "DW_TAG_entry_point";
6277 case DW_TAG_enumeration_type: return "DW_TAG_enumeration_type";
6278 case DW_TAG_formal_parameter: return "DW_TAG_formal_parameter";
6279 case DW_TAG_imported_declaration: return "DW_TAG_imported_declaration";
6280 case DW_TAG_label: return "DW_TAG_label";
6281 case DW_TAG_lexical_block: return "DW_TAG_lexical_block";
6282 case DW_TAG_member: return "DW_TAG_member";
6283 case DW_TAG_pointer_type: return "DW_TAG_pointer_type";
6284 case DW_TAG_reference_type: return "DW_TAG_reference_type";
6285 case DW_TAG_compile_unit: return "DW_TAG_compile_unit";
6286 case DW_TAG_string_type: return "DW_TAG_string_type";
6287 case DW_TAG_structure_type: return "DW_TAG_structure_type";
6288 case DW_TAG_subroutine_type: return "DW_TAG_subroutine_type";
6289 case DW_TAG_typedef: return "DW_TAG_typedef";
6290 case DW_TAG_union_type: return "DW_TAG_union_type";
6291 case DW_TAG_unspecified_parameters: return "DW_TAG_unspecified_parameters";
6292 case DW_TAG_variant: return "DW_TAG_variant";
6293 case DW_TAG_common_block: return "DW_TAG_common_block";
6294 case DW_TAG_common_inclusion: return "DW_TAG_common_inclusion";
6295 case DW_TAG_inheritance: return "DW_TAG_inheritance";
6296 case DW_TAG_inlined_subroutine: return "DW_TAG_inlined_subroutine";
6297 case DW_TAG_module: return "DW_TAG_module";
6298 case DW_TAG_ptr_to_member_type: return "DW_TAG_ptr_to_member_type";
6299 case DW_TAG_set_type: return "DW_TAG_set_type";
6300 case DW_TAG_subrange_type: return "DW_TAG_subrange_type";
6301 case DW_TAG_with_stmt: return "DW_TAG_with_stmt";
6302 case DW_TAG_access_declaration: return "DW_TAG_access_declaration";
6303 case DW_TAG_base_type: return "DW_TAG_base_type";
6304 case DW_TAG_catch_block: return "DW_TAG_catch_block";
6305 case DW_TAG_const_type: return "DW_TAG_const_type";
6306 case DW_TAG_constant: return "DW_TAG_constant";
6307 case DW_TAG_enumerator: return "DW_TAG_enumerator";
6308 case DW_TAG_file_type: return "DW_TAG_file_type";
6309 case DW_TAG_friend: return "DW_TAG_friend";
6310 case DW_TAG_namelist: return "DW_TAG_namelist";
6311 case DW_TAG_namelist_item: return "DW_TAG_namelist_item";
6312 case DW_TAG_packed_type: return "DW_TAG_packed_type";
6313 case DW_TAG_subprogram: return "DW_TAG_subprogram";
6314 case DW_TAG_template_type_param: return "DW_TAG_template_type_param";
6315 case DW_TAG_template_value_param: return "DW_TAG_template_value_param";
6316 case DW_TAG_thrown_type: return "DW_TAG_thrown_type";
6317 case DW_TAG_try_block: return "DW_TAG_try_block";
6318 case DW_TAG_variant_part: return "DW_TAG_variant_part";
6319 case DW_TAG_variable: return "DW_TAG_variable";
6320 case DW_TAG_volatile_type: return "DW_TAG_volatile_type";
6321 case DW_TAG_MIPS_loop: return "DW_TAG_MIPS_loop";
6322 case DW_TAG_format_label: return "DW_TAG_format_label";
6323 case DW_TAG_function_template: return "DW_TAG_function_template";
6324 case DW_TAG_class_template: return "DW_TAG_class_template";
6325 /* DWARF 2.1 values. */
6326 case DW_TAG_dwarf_procedure: return "DW_TAG_dwarf_procedure";
6327 case DW_TAG_restrict_type: return "DW_TAG_restrict_type";
6328 case DW_TAG_interface_type: return "DW_TAG_interface_type";
6329 case DW_TAG_namespace: return "DW_TAG_namespace";
6330 case DW_TAG_imported_module: return "DW_TAG_imported_module";
6331 case DW_TAG_unspecified_type: return "DW_TAG_unspecified_type";
6332 case DW_TAG_partial_unit: return "DW_TAG_partial_unit";
6333 case DW_TAG_imported_unit: return "DW_TAG_imported_unit";
6336 static char buffer [100];
6338 sprintf (buffer, _("Unknown TAG value: %lx"), tag);
6345 get_AT_name (attribute)
6346 unsigned long attribute;
6350 case DW_AT_sibling: return "DW_AT_sibling";
6351 case DW_AT_location: return "DW_AT_location";
6352 case DW_AT_name: return "DW_AT_name";
6353 case DW_AT_ordering: return "DW_AT_ordering";
6354 case DW_AT_subscr_data: return "DW_AT_subscr_data";
6355 case DW_AT_byte_size: return "DW_AT_byte_size";
6356 case DW_AT_bit_offset: return "DW_AT_bit_offset";
6357 case DW_AT_bit_size: return "DW_AT_bit_size";
6358 case DW_AT_element_list: return "DW_AT_element_list";
6359 case DW_AT_stmt_list: return "DW_AT_stmt_list";
6360 case DW_AT_low_pc: return "DW_AT_low_pc";
6361 case DW_AT_high_pc: return "DW_AT_high_pc";
6362 case DW_AT_language: return "DW_AT_language";
6363 case DW_AT_member: return "DW_AT_member";
6364 case DW_AT_discr: return "DW_AT_discr";
6365 case DW_AT_discr_value: return "DW_AT_discr_value";
6366 case DW_AT_visibility: return "DW_AT_visibility";
6367 case DW_AT_import: return "DW_AT_import";
6368 case DW_AT_string_length: return "DW_AT_string_length";
6369 case DW_AT_common_reference: return "DW_AT_common_reference";
6370 case DW_AT_comp_dir: return "DW_AT_comp_dir";
6371 case DW_AT_const_value: return "DW_AT_const_value";
6372 case DW_AT_containing_type: return "DW_AT_containing_type";
6373 case DW_AT_default_value: return "DW_AT_default_value";
6374 case DW_AT_inline: return "DW_AT_inline";
6375 case DW_AT_is_optional: return "DW_AT_is_optional";
6376 case DW_AT_lower_bound: return "DW_AT_lower_bound";
6377 case DW_AT_producer: return "DW_AT_producer";
6378 case DW_AT_prototyped: return "DW_AT_prototyped";
6379 case DW_AT_return_addr: return "DW_AT_return_addr";
6380 case DW_AT_start_scope: return "DW_AT_start_scope";
6381 case DW_AT_stride_size: return "DW_AT_stride_size";
6382 case DW_AT_upper_bound: return "DW_AT_upper_bound";
6383 case DW_AT_abstract_origin: return "DW_AT_abstract_origin";
6384 case DW_AT_accessibility: return "DW_AT_accessibility";
6385 case DW_AT_address_class: return "DW_AT_address_class";
6386 case DW_AT_artificial: return "DW_AT_artificial";
6387 case DW_AT_base_types: return "DW_AT_base_types";
6388 case DW_AT_calling_convention: return "DW_AT_calling_convention";
6389 case DW_AT_count: return "DW_AT_count";
6390 case DW_AT_data_member_location: return "DW_AT_data_member_location";
6391 case DW_AT_decl_column: return "DW_AT_decl_column";
6392 case DW_AT_decl_file: return "DW_AT_decl_file";
6393 case DW_AT_decl_line: return "DW_AT_decl_line";
6394 case DW_AT_declaration: return "DW_AT_declaration";
6395 case DW_AT_discr_list: return "DW_AT_discr_list";
6396 case DW_AT_encoding: return "DW_AT_encoding";
6397 case DW_AT_external: return "DW_AT_external";
6398 case DW_AT_frame_base: return "DW_AT_frame_base";
6399 case DW_AT_friend: return "DW_AT_friend";
6400 case DW_AT_identifier_case: return "DW_AT_identifier_case";
6401 case DW_AT_macro_info: return "DW_AT_macro_info";
6402 case DW_AT_namelist_items: return "DW_AT_namelist_items";
6403 case DW_AT_priority: return "DW_AT_priority";
6404 case DW_AT_segment: return "DW_AT_segment";
6405 case DW_AT_specification: return "DW_AT_specification";
6406 case DW_AT_static_link: return "DW_AT_static_link";
6407 case DW_AT_type: return "DW_AT_type";
6408 case DW_AT_use_location: return "DW_AT_use_location";
6409 case DW_AT_variable_parameter: return "DW_AT_variable_parameter";
6410 case DW_AT_virtuality: return "DW_AT_virtuality";
6411 case DW_AT_vtable_elem_location: return "DW_AT_vtable_elem_location";
6412 /* DWARF 2.1 values. */
6413 case DW_AT_allocated: return "DW_AT_allocated";
6414 case DW_AT_associated: return "DW_AT_associated";
6415 case DW_AT_data_location: return "DW_AT_data_location";
6416 case DW_AT_stride: return "DW_AT_stride";
6417 case DW_AT_entry_pc: return "DW_AT_entry_pc";
6418 case DW_AT_use_UTF8: return "DW_AT_use_UTF8";
6419 case DW_AT_extension: return "DW_AT_extension";
6420 case DW_AT_ranges: return "DW_AT_ranges";
6421 case DW_AT_trampoline: return "DW_AT_trampoline";
6422 case DW_AT_call_column: return "DW_AT_call_column";
6423 case DW_AT_call_file: return "DW_AT_call_file";
6424 case DW_AT_call_line: return "DW_AT_call_line";
6425 /* SGI/MIPS extensions. */
6426 case DW_AT_MIPS_fde: return "DW_AT_MIPS_fde";
6427 case DW_AT_MIPS_loop_begin: return "DW_AT_MIPS_loop_begin";
6428 case DW_AT_MIPS_tail_loop_begin: return "DW_AT_MIPS_tail_loop_begin";
6429 case DW_AT_MIPS_epilog_begin: return "DW_AT_MIPS_epilog_begin";
6430 case DW_AT_MIPS_loop_unroll_factor: return "DW_AT_MIPS_loop_unroll_factor";
6431 case DW_AT_MIPS_software_pipeline_depth: return "DW_AT_MIPS_software_pipeline_depth";
6432 case DW_AT_MIPS_linkage_name: return "DW_AT_MIPS_linkage_name";
6433 case DW_AT_MIPS_stride: return "DW_AT_MIPS_stride";
6434 case DW_AT_MIPS_abstract_name: return "DW_AT_MIPS_abstract_name";
6435 case DW_AT_MIPS_clone_origin: return "DW_AT_MIPS_clone_origin";
6436 case DW_AT_MIPS_has_inlines: return "DW_AT_MIPS_has_inlines";
6437 /* GNU extensions. */
6438 case DW_AT_sf_names: return "DW_AT_sf_names";
6439 case DW_AT_src_info: return "DW_AT_src_info";
6440 case DW_AT_mac_info: return "DW_AT_mac_info";
6441 case DW_AT_src_coords: return "DW_AT_src_coords";
6442 case DW_AT_body_begin: return "DW_AT_body_begin";
6443 case DW_AT_body_end: return "DW_AT_body_end";
6446 static char buffer [100];
6448 sprintf (buffer, _("Unknown AT value: %lx"), attribute);
6455 get_FORM_name (form)
6460 case DW_FORM_addr: return "DW_FORM_addr";
6461 case DW_FORM_block2: return "DW_FORM_block2";
6462 case DW_FORM_block4: return "DW_FORM_block4";
6463 case DW_FORM_data2: return "DW_FORM_data2";
6464 case DW_FORM_data4: return "DW_FORM_data4";
6465 case DW_FORM_data8: return "DW_FORM_data8";
6466 case DW_FORM_string: return "DW_FORM_string";
6467 case DW_FORM_block: return "DW_FORM_block";
6468 case DW_FORM_block1: return "DW_FORM_block1";
6469 case DW_FORM_data1: return "DW_FORM_data1";
6470 case DW_FORM_flag: return "DW_FORM_flag";
6471 case DW_FORM_sdata: return "DW_FORM_sdata";
6472 case DW_FORM_strp: return "DW_FORM_strp";
6473 case DW_FORM_udata: return "DW_FORM_udata";
6474 case DW_FORM_ref_addr: return "DW_FORM_ref_addr";
6475 case DW_FORM_ref1: return "DW_FORM_ref1";
6476 case DW_FORM_ref2: return "DW_FORM_ref2";
6477 case DW_FORM_ref4: return "DW_FORM_ref4";
6478 case DW_FORM_ref8: return "DW_FORM_ref8";
6479 case DW_FORM_ref_udata: return "DW_FORM_ref_udata";
6480 case DW_FORM_indirect: return "DW_FORM_indirect";
6483 static char buffer [100];
6485 sprintf (buffer, _("Unknown FORM value: %lx"), form);
6491 /* FIXME: There are better and more effiecint ways to handle
6492 these structures. For now though, I just want something that
6493 is simple to implement. */
6494 typedef struct abbrev_attr
6496 unsigned long attribute;
6498 struct abbrev_attr * next;
6502 typedef struct abbrev_entry
6504 unsigned long entry;
6507 struct abbrev_attr * first_attr;
6508 struct abbrev_attr * last_attr;
6509 struct abbrev_entry * next;
6513 static abbrev_entry * first_abbrev = NULL;
6514 static abbrev_entry * last_abbrev = NULL;
6517 free_abbrevs PARAMS ((void))
6519 abbrev_entry * abbrev;
6521 for (abbrev = first_abbrev; abbrev;)
6523 abbrev_entry * next = abbrev->next;
6526 for (attr = abbrev->first_attr; attr;)
6528 abbrev_attr * next = attr->next;
6538 last_abbrev = first_abbrev = NULL;
6542 add_abbrev (number, tag, children)
6543 unsigned long number;
6547 abbrev_entry * entry;
6549 entry = (abbrev_entry *) malloc (sizeof (* entry));
6555 entry->entry = number;
6557 entry->children = children;
6558 entry->first_attr = NULL;
6559 entry->last_attr = NULL;
6562 if (first_abbrev == NULL)
6563 first_abbrev = entry;
6565 last_abbrev->next = entry;
6567 last_abbrev = entry;
6571 add_abbrev_attr (attribute, form)
6572 unsigned long attribute;
6577 attr = (abbrev_attr *) malloc (sizeof (* attr));
6583 attr->attribute = attribute;
6587 if (last_abbrev->first_attr == NULL)
6588 last_abbrev->first_attr = attr;
6590 last_abbrev->last_attr->next = attr;
6592 last_abbrev->last_attr = attr;
6595 /* Processes the (partial) contents of a .debug_abbrev section.
6596 Returns NULL if the end of the section was encountered.
6597 Returns the address after the last byte read if the end of
6598 an abbreviation set was found. */
6600 static unsigned char *
6601 process_abbrev_section (start, end)
6602 unsigned char * start;
6603 unsigned char * end;
6605 if (first_abbrev != NULL)
6611 unsigned long entry;
6613 unsigned long attribute;
6616 entry = read_leb128 (start, & bytes_read, 0);
6617 start += bytes_read;
6619 /* A single zero is supposed to end the section according
6620 to the standard. If there's more, then signal that to
6623 return start == end ? NULL : start;
6625 tag = read_leb128 (start, & bytes_read, 0);
6626 start += bytes_read;
6628 children = * start ++;
6630 add_abbrev (entry, tag, children);
6636 attribute = read_leb128 (start, & bytes_read, 0);
6637 start += bytes_read;
6639 form = read_leb128 (start, & bytes_read, 0);
6640 start += bytes_read;
6643 add_abbrev_attr (attribute, form);
6645 while (attribute != 0);
6653 display_debug_macinfo (section, start, file)
6654 Elf32_Internal_Shdr * section;
6655 unsigned char * start;
6656 FILE * file ATTRIBUTE_UNUSED;
6658 unsigned char * end = start + section->sh_size;
6659 unsigned char * curr = start;
6660 unsigned int bytes_read;
6661 enum dwarf_macinfo_record_type op;
6663 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section));
6667 unsigned int lineno;
6668 const char * string;
6675 case DW_MACINFO_start_file:
6677 unsigned int filenum;
6679 lineno = read_leb128 (curr, & bytes_read, 0);
6681 filenum = read_leb128 (curr, & bytes_read, 0);
6684 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"), lineno, filenum);
6688 case DW_MACINFO_end_file:
6689 printf (_(" DW_MACINFO_end_file\n"));
6692 case DW_MACINFO_define:
6693 lineno = read_leb128 (curr, & bytes_read, 0);
6696 curr += strlen (string) + 1;
6697 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"), lineno, string);
6700 case DW_MACINFO_undef:
6701 lineno = read_leb128 (curr, & bytes_read, 0);
6704 curr += strlen (string) + 1;
6705 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"), lineno, string);
6708 case DW_MACINFO_vendor_ext:
6710 unsigned int constant;
6712 constant = read_leb128 (curr, & bytes_read, 0);
6715 curr += strlen (string) + 1;
6716 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"), constant, string);
6727 display_debug_abbrev (section, start, file)
6728 Elf32_Internal_Shdr * section;
6729 unsigned char * start;
6730 FILE * file ATTRIBUTE_UNUSED;
6732 abbrev_entry * entry;
6733 unsigned char * end = start + section->sh_size;
6735 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section));
6739 start = process_abbrev_section (start, end);
6741 if (first_abbrev == NULL)
6744 printf (_(" Number TAG\n"));
6746 for (entry = first_abbrev; entry; entry = entry->next)
6750 printf (_(" %ld %s [%s]\n"),
6752 get_TAG_name (entry->tag),
6753 entry->children ? _("has children") : _("no children"));
6755 for (attr = entry->first_attr; attr; attr = attr->next)
6757 printf (_(" %-18s %s\n"),
6758 get_AT_name (attr->attribute),
6759 get_FORM_name (attr->form));
6773 static unsigned char *
6774 display_block (data, length)
6775 unsigned char * data;
6776 unsigned long length;
6778 printf (_(" %lu byte block: "), length);
6781 printf ("%lx ", (unsigned long) byte_get (data ++, 1));
6787 decode_location_expression (data, pointer_size, length)
6788 unsigned char * data;
6789 unsigned int pointer_size;
6790 unsigned long length;
6794 unsigned long uvalue;
6795 unsigned char * end = data + length;
6804 printf ("DW_OP_addr: %lx",
6805 (unsigned long) byte_get (data, pointer_size));
6806 data += pointer_size;
6809 printf ("DW_OP_deref");
6812 printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data++, 1));
6815 printf ("DW_OP_const1s: %ld", (long) byte_get (data++, 1));
6818 printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data, 2));
6822 printf ("DW_OP_const2s: %ld", (long) byte_get (data, 2));
6826 printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data, 4));
6830 printf ("DW_OP_const4s: %ld", (long) byte_get (data, 4));
6834 printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data, 4),
6835 (unsigned long) byte_get (data + 4, 4));
6839 printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data, 4),
6840 (long) byte_get (data + 4, 4));
6844 printf ("DW_OP_constu: %lu", read_leb128 (data, &bytes_read, 0));
6848 printf ("DW_OP_consts: %ld", read_leb128 (data, &bytes_read, 1));
6852 printf ("DW_OP_dup");
6855 printf ("DW_OP_drop");
6858 printf ("DW_OP_over");
6861 printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data++, 1));
6864 printf ("DW_OP_swap");
6867 printf ("DW_OP_rot");
6870 printf ("DW_OP_xderef");
6873 printf ("DW_OP_abs");
6876 printf ("DW_OP_and");
6879 printf ("DW_OP_div");
6882 printf ("DW_OP_minus");
6885 printf ("DW_OP_mod");
6888 printf ("DW_OP_mul");
6891 printf ("DW_OP_neg");
6894 printf ("DW_OP_not");
6897 printf ("DW_OP_or");
6900 printf ("DW_OP_plus");
6902 case DW_OP_plus_uconst:
6903 printf ("DW_OP_plus_uconst: %lu",
6904 read_leb128 (data, &bytes_read, 0));
6908 printf ("DW_OP_shl");
6911 printf ("DW_OP_shr");
6914 printf ("DW_OP_shra");
6917 printf ("DW_OP_xor");
6920 printf ("DW_OP_bra: %ld", (long) byte_get (data, 2));
6924 printf ("DW_OP_eq");
6927 printf ("DW_OP_ge");
6930 printf ("DW_OP_gt");
6933 printf ("DW_OP_le");
6936 printf ("DW_OP_lt");
6939 printf ("DW_OP_ne");
6942 printf ("DW_OP_skip: %ld", (long) byte_get (data, 2));
6978 printf ("DW_OP_lit%d", op - DW_OP_lit0);
7013 printf ("DW_OP_reg%d", op - DW_OP_reg0);
7048 printf ("DW_OP_breg%d: %ld", op - DW_OP_breg0,
7049 read_leb128 (data, &bytes_read, 1));
7054 printf ("DW_OP_regx: %lu", read_leb128 (data, &bytes_read, 0));
7058 printf ("DW_OP_fbreg: %ld", read_leb128 (data, &bytes_read, 1));
7062 uvalue = read_leb128 (data, &bytes_read, 0);
7064 printf ("DW_OP_bregx: %lu %ld", uvalue,
7065 read_leb128 (data, &bytes_read, 1));
7069 printf ("DW_OP_piece: %lu", read_leb128 (data, &bytes_read, 0));
7072 case DW_OP_deref_size:
7073 printf ("DW_OP_deref_size: %ld", (long) byte_get (data++, 1));
7075 case DW_OP_xderef_size:
7076 printf ("DW_OP_xderef_size: %ld", (long) byte_get (data++, 1));
7079 printf ("DW_OP_nop");
7082 /* DWARF 2.1 extensions. */
7083 case DW_OP_push_object_address:
7084 printf ("DW_OP_push_object_address");
7087 printf ("DW_OP_call2: <%lx>", (long) byte_get (data, 2));
7091 printf ("DW_OP_call4: <%lx>", (long) byte_get (data, 4));
7095 printf ("DW_OP_calli");
7099 if (op >= DW_OP_lo_user
7100 && op <= DW_OP_hi_user)
7101 printf (_("(User defined location op)"));
7103 printf (_("(Unknown location op)"));
7104 /* No way to tell where the next op is, so just bail. */
7108 /* Separate the ops. */
7114 static const char * debug_str_contents;
7115 static bfd_vma debug_str_size;
7118 load_debug_str (file)
7121 Elf32_Internal_Shdr * sec;
7124 /* If it is already loaded, do nothing. */
7125 if (debug_str_contents != NULL)
7128 /* Locate the .debug_str section. */
7129 for (i = 0, sec = section_headers;
7130 i < elf_header.e_shnum;
7132 if (strcmp (SECTION_NAME (sec), ".debug_str") == 0)
7135 if (i == elf_header.e_shnum || sec->sh_size == 0)
7138 debug_str_size = sec->sh_size;
7140 debug_str_contents = ((char *)
7141 get_data (NULL, file, sec->sh_offset, sec->sh_size,
7142 _("debug_str section data")));
7148 if (debug_str_contents == NULL)
7151 free ((char *) debug_str_contents);
7152 debug_str_contents = NULL;
7157 fetch_indirect_string (offset)
7158 unsigned long offset;
7160 if (debug_str_contents == NULL)
7161 return _("<no .debug_str section>");
7163 if (offset > debug_str_size)
7164 return _("<offset is too big>");
7166 return debug_str_contents + offset;
7171 display_debug_str (section, start, file)
7172 Elf32_Internal_Shdr * section;
7173 unsigned char * start;
7174 FILE * file ATTRIBUTE_UNUSED;
7176 unsigned long bytes;
7179 addr = section->sh_addr;
7180 bytes = section->sh_size;
7184 printf (_("\nThe .debug_str section is empty.\n"));
7188 printf (_("Contents of the .debug_str section:\n\n"));
7196 lbytes = (bytes > 16 ? 16 : bytes);
7198 printf (" 0x%8.8lx ", (unsigned long) addr);
7200 for (j = 0; j < 16; j++)
7203 printf ("%2.2x", start [j]);
7211 for (j = 0; j < lbytes; j++)
7214 if (k >= ' ' && k < 0x80)
7231 static unsigned char *
7232 read_and_display_attr_value (attribute, form, data, cu_offset, pointer_size)
7233 unsigned long attribute;
7235 unsigned char * data;
7236 unsigned long cu_offset;
7237 unsigned long pointer_size;
7239 unsigned long uvalue = 0;
7240 unsigned char * block_start = NULL;
7248 case DW_FORM_ref_addr:
7250 uvalue = byte_get (data, pointer_size);
7251 data += pointer_size;
7255 uvalue = byte_get (data, /* offset_size */ 4);
7256 data += /* offset_size */ 4;
7262 uvalue = byte_get (data ++, 1);
7267 uvalue = byte_get (data, 2);
7273 uvalue = byte_get (data, 4);
7278 uvalue = read_leb128 (data, & bytes_read, 1);
7282 case DW_FORM_ref_udata:
7284 uvalue = read_leb128 (data, & bytes_read, 0);
7288 case DW_FORM_indirect:
7289 form = read_leb128 (data, & bytes_read, 0);
7291 printf (" %s", get_FORM_name (form));
7292 return read_and_display_attr_value (attribute, form, data, cu_offset,
7298 case DW_FORM_ref_addr:
7299 printf (" <#%lx>", uvalue);
7305 case DW_FORM_ref_udata:
7306 printf (" <%lx>", uvalue + cu_offset);
7310 printf (" %#lx", uvalue);
7318 printf (" %ld", uvalue);
7323 uvalue = byte_get (data, 4);
7324 printf (" %lx", uvalue);
7325 printf (" %lx", (unsigned long) byte_get (data + 4, 4));
7329 case DW_FORM_string:
7330 printf (" %s", data);
7331 data += strlen ((char *) data) + 1;
7335 uvalue = read_leb128 (data, & bytes_read, 0);
7336 block_start = data + bytes_read;
7337 data = display_block (block_start, uvalue);
7340 case DW_FORM_block1:
7341 uvalue = byte_get (data, 1);
7342 block_start = data + 1;
7343 data = display_block (block_start, uvalue);
7346 case DW_FORM_block2:
7347 uvalue = byte_get (data, 2);
7348 block_start = data + 2;
7349 data = display_block (block_start, uvalue);
7352 case DW_FORM_block4:
7353 uvalue = byte_get (data, 4);
7354 block_start = data + 4;
7355 data = display_block (block_start, uvalue);
7359 printf (_(" (indirect string, offset: 0x%lx): "), uvalue);
7360 printf (fetch_indirect_string (uvalue));
7363 case DW_FORM_indirect:
7364 /* Handled above. */
7368 warn (_("Unrecognised form: %d\n"), form);
7372 /* For some attributes we can display futher information. */
7381 case DW_INL_not_inlined: printf (_("(not inlined)")); break;
7382 case DW_INL_inlined: printf (_("(inlined)")); break;
7383 case DW_INL_declared_not_inlined: printf (_("(declared as inline but ignored)")); break;
7384 case DW_INL_declared_inlined: printf (_("(declared as inline and inlined)")); break;
7385 default: printf (_(" (Unknown inline attribute value: %lx)"), uvalue); break;
7389 case DW_AT_language:
7392 case DW_LANG_C: printf ("(non-ANSI C)"); break;
7393 case DW_LANG_C89: printf ("(ANSI C)"); break;
7394 case DW_LANG_C_plus_plus: printf ("(C++)"); break;
7395 case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break;
7396 case DW_LANG_Fortran90: printf ("(Fortran 90)"); break;
7397 case DW_LANG_Modula2: printf ("(Modula 2)"); break;
7398 case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break;
7399 case DW_LANG_Ada83: printf ("(Ada)"); break;
7400 case DW_LANG_Cobol74: printf ("(Cobol 74)"); break;
7401 case DW_LANG_Cobol85: printf ("(Cobol 85)"); break;
7402 /* DWARF 2.1 values. */
7403 case DW_LANG_C99: printf ("(ANSI C99)"); break;
7404 case DW_LANG_Ada95: printf ("(ADA 95)"); break;
7405 case DW_LANG_Fortran95: printf ("(Fortran 95)"); break;
7406 /* MIPS extension. */
7407 case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break;
7408 default: printf ("(Unknown: %lx)", uvalue); break;
7412 case DW_AT_encoding:
7415 case DW_ATE_void: printf ("(void)"); break;
7416 case DW_ATE_address: printf ("(machine address)"); break;
7417 case DW_ATE_boolean: printf ("(boolean)"); break;
7418 case DW_ATE_complex_float: printf ("(complex float)"); break;
7419 case DW_ATE_float: printf ("(float)"); break;
7420 case DW_ATE_signed: printf ("(signed)"); break;
7421 case DW_ATE_signed_char: printf ("(signed char)"); break;
7422 case DW_ATE_unsigned: printf ("(unsigned)"); break;
7423 case DW_ATE_unsigned_char: printf ("(unsigned char)"); break;
7424 /* DWARF 2.1 value. */
7425 case DW_ATE_imaginary_float: printf ("(imaginary float)"); break;
7427 if (uvalue >= DW_ATE_lo_user
7428 && uvalue <= DW_ATE_hi_user)
7429 printf ("(user defined type)");
7431 printf ("(unknown type)");
7436 case DW_AT_accessibility:
7439 case DW_ACCESS_public: printf ("(public)"); break;
7440 case DW_ACCESS_protected: printf ("(protected)"); break;
7441 case DW_ACCESS_private: printf ("(private)"); break;
7442 default: printf ("(unknown accessibility)"); break;
7446 case DW_AT_visibility:
7449 case DW_VIS_local: printf ("(local)"); break;
7450 case DW_VIS_exported: printf ("(exported)"); break;
7451 case DW_VIS_qualified: printf ("(qualified)"); break;
7452 default: printf ("(unknown visibility)"); break;
7456 case DW_AT_virtuality:
7459 case DW_VIRTUALITY_none: printf ("(none)"); break;
7460 case DW_VIRTUALITY_virtual: printf ("(virtual)"); break;
7461 case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break;
7462 default: printf ("(unknown virtuality)"); break;
7466 case DW_AT_identifier_case:
7469 case DW_ID_case_sensitive: printf ("(case_sensitive)"); break;
7470 case DW_ID_up_case: printf ("(up_case)"); break;
7471 case DW_ID_down_case: printf ("(down_case)"); break;
7472 case DW_ID_case_insensitive: printf ("(case_insensitive)"); break;
7473 default: printf ("(unknown case)"); break;
7477 case DW_AT_calling_convention:
7480 case DW_CC_normal: printf ("(normal)"); break;
7481 case DW_CC_program: printf ("(program)"); break;
7482 case DW_CC_nocall: printf ("(nocall)"); break;
7484 if (uvalue >= DW_CC_lo_user
7485 && uvalue <= DW_CC_hi_user)
7486 printf ("(user defined)");
7488 printf ("(unknown convention)");
7492 case DW_AT_ordering:
7495 case -1: printf ("(undefined)"); break;
7496 case 0: printf ("(row major)"); break;
7497 case 1: printf ("(column major)"); break;
7501 case DW_AT_frame_base:
7502 case DW_AT_location:
7503 case DW_AT_data_member_location:
7504 case DW_AT_vtable_elem_location:
7505 case DW_AT_allocated:
7506 case DW_AT_associated:
7507 case DW_AT_data_location:
7509 case DW_AT_upper_bound:
7510 case DW_AT_lower_bound:
7514 decode_location_expression (block_start, pointer_size, uvalue);
7526 static unsigned char *
7527 read_and_display_attr (attribute, form, data, cu_offset, pointer_size)
7528 unsigned long attribute;
7530 unsigned char * data;
7531 unsigned long cu_offset;
7532 unsigned long pointer_size;
7534 printf (" %-18s:", get_AT_name (attribute));
7535 data = read_and_display_attr_value (attribute, form, data, cu_offset,
7542 display_debug_info (section, start, file)
7543 Elf32_Internal_Shdr * section;
7544 unsigned char * start;
7547 unsigned char * end = start + section->sh_size;
7548 unsigned char * section_begin = start;
7550 printf (_("The section %s contains:\n\n"), SECTION_NAME (section));
7552 load_debug_str (file);
7556 DWARF2_External_CompUnit * external;
7557 DWARF2_Internal_CompUnit compunit;
7558 Elf32_Internal_Shdr * relsec;
7559 unsigned char * tags;
7562 unsigned long cu_offset;
7564 external = (DWARF2_External_CompUnit *) start;
7566 compunit.cu_length = BYTE_GET (external->cu_length);
7567 compunit.cu_version = BYTE_GET (external->cu_version);
7568 compunit.cu_abbrev_offset = BYTE_GET (external->cu_abbrev_offset);
7569 compunit.cu_pointer_size = BYTE_GET (external->cu_pointer_size);
7571 if (compunit.cu_length == 0xffffffff)
7573 warn (_("64-bit DWARF debug info is not supported yet.\n"));
7577 /* Check for RELA relocations in the abbrev_offset address, and
7579 for (relsec = section_headers;
7580 relsec < section_headers + elf_header.e_shnum;
7583 unsigned long nrelas;
7584 Elf_Internal_Rela *rela, *rp;
7585 Elf32_Internal_Shdr *symsec;
7586 Elf_Internal_Sym *symtab;
7587 Elf_Internal_Sym *sym;
7589 if (relsec->sh_type != SHT_RELA
7590 || SECTION_HEADER (relsec->sh_info) != section)
7593 if (!slurp_rela_relocs (file, relsec->sh_offset, relsec->sh_size,
7597 symsec = SECTION_HEADER (relsec->sh_link);
7598 symtab = GET_ELF_SYMBOLS (file, symsec);
7600 for (rp = rela; rp < rela + nrelas; ++rp)
7603 != (bfd_vma) ((unsigned char *) &external->cu_abbrev_offset
7609 sym = symtab + ELF32_R_SYM (rp->r_info);
7611 if (ELF32_ST_TYPE (sym->st_info) != STT_SECTION)
7613 warn (_("Skipping unexpected symbol type %u\n"),
7614 ELF32_ST_TYPE (sym->st_info));
7620 sym = symtab + ELF64_R_SYM (rp->r_info);
7622 if (ELF64_ST_TYPE (sym->st_info) != STT_SECTION)
7624 warn (_("Skipping unexpected symbol type %u\n"),
7625 ELF64_ST_TYPE (sym->st_info));
7630 compunit.cu_abbrev_offset += rp->r_addend;
7638 tags = start + sizeof (* external);
7639 cu_offset = start - section_begin;
7640 start += compunit.cu_length + sizeof (external->cu_length);
7642 printf (_(" Compilation Unit @ %lx:\n"), cu_offset);
7643 printf (_(" Length: %ld\n"), compunit.cu_length);
7644 printf (_(" Version: %d\n"), compunit.cu_version);
7645 printf (_(" Abbrev Offset: %ld\n"), compunit.cu_abbrev_offset);
7646 printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size);
7648 if (compunit.cu_version != 2)
7650 warn (_("Only version 2 DWARF debug information is currently supported.\n"));
7656 /* Read in the abbrevs used by this compilation unit. */
7659 Elf32_Internal_Shdr * sec;
7660 unsigned char * begin;
7662 /* Locate the .debug_abbrev section and process it. */
7663 for (i = 0, sec = section_headers;
7664 i < elf_header.e_shnum;
7666 if (strcmp (SECTION_NAME (sec), ".debug_abbrev") == 0)
7669 if (i == elf_header.e_shnum || sec->sh_size == 0)
7671 warn (_("Unable to locate .debug_abbrev section!\n"));
7675 begin = ((unsigned char *)
7676 get_data (NULL, file, sec->sh_offset, sec->sh_size,
7677 _("debug_abbrev section data")));
7681 process_abbrev_section (begin + compunit.cu_abbrev_offset,
7682 begin + sec->sh_size);
7688 while (tags < start)
7691 unsigned long abbrev_number;
7692 abbrev_entry * entry;
7695 abbrev_number = read_leb128 (tags, & bytes_read, 0);
7698 /* A null DIE marks the end of a list of children. */
7699 if (abbrev_number == 0)
7705 /* Scan through the abbreviation list until we reach the
7707 for (entry = first_abbrev;
7708 entry && entry->entry != abbrev_number;
7709 entry = entry->next)
7714 warn (_("Unable to locate entry %lu in the abbreviation table\n"),
7719 printf (_(" <%d><%lx>: Abbrev Number: %lu (%s)\n"),
7721 (unsigned long) (tags - section_begin - bytes_read),
7723 get_TAG_name (entry->tag));
7725 for (attr = entry->first_attr; attr; attr = attr->next)
7726 tags = read_and_display_attr (attr->attribute,
7729 compunit.cu_pointer_size);
7731 if (entry->children)
7744 display_debug_aranges (section, start, file)
7745 Elf32_Internal_Shdr * section;
7746 unsigned char * start;
7747 FILE * file ATTRIBUTE_UNUSED;
7749 unsigned char * end = start + section->sh_size;
7751 printf (_("The section %s contains:\n\n"), SECTION_NAME (section));
7755 DWARF2_External_ARange * external;
7756 DWARF2_Internal_ARange arange;
7757 unsigned char * ranges;
7758 unsigned long length;
7759 unsigned long address;
7762 external = (DWARF2_External_ARange *) start;
7764 arange.ar_length = BYTE_GET (external->ar_length);
7765 arange.ar_version = BYTE_GET (external->ar_version);
7766 arange.ar_info_offset = BYTE_GET (external->ar_info_offset);
7767 arange.ar_pointer_size = BYTE_GET (external->ar_pointer_size);
7768 arange.ar_segment_size = BYTE_GET (external->ar_segment_size);
7770 if (arange.ar_length == 0xffffffff)
7772 warn (_("64-bit DWARF aranges are not supported yet.\n"));
7776 if (arange.ar_version != 2)
7778 warn (_("Only DWARF 2 aranges are currently supported.\n"));
7782 printf (_(" Length: %ld\n"), arange.ar_length);
7783 printf (_(" Version: %d\n"), arange.ar_version);
7784 printf (_(" Offset into .debug_info: %lx\n"), arange.ar_info_offset);
7785 printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
7786 printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
7788 printf (_("\n Address Length\n"));
7790 ranges = start + sizeof (* external);
7792 /* Must pad to an alignment boundary that is twice the pointer size. */
7793 excess = sizeof (* external) % (2 * arange.ar_pointer_size);
7795 ranges += (2 * arange.ar_pointer_size) - excess;
7799 address = byte_get (ranges, arange.ar_pointer_size);
7801 ranges += arange.ar_pointer_size;
7803 length = byte_get (ranges, arange.ar_pointer_size);
7805 ranges += arange.ar_pointer_size;
7807 /* A pair of zeros marks the end of the list. */
7808 if (address == 0 && length == 0)
7811 printf (" %8.8lx %lu\n", address, length);
7814 start += arange.ar_length + sizeof (external->ar_length);
7822 typedef struct Frame_Chunk
7824 struct Frame_Chunk * next;
7825 unsigned char * chunk_start;
7827 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
7828 short int * col_type;
7830 char * augmentation;
7831 unsigned int code_factor;
7833 unsigned long pc_begin;
7834 unsigned long pc_range;
7838 unsigned char fde_encoding;
7842 /* A marker for a col_type that means this column was never referenced
7843 in the frame info. */
7844 #define DW_CFA_unreferenced (-1)
7846 static void frame_need_space PARAMS ((Frame_Chunk *, int));
7847 static void frame_display_row PARAMS ((Frame_Chunk *, int *, int *));
7848 static int size_of_encoded_value PARAMS ((int));
7851 frame_need_space (fc, reg)
7855 int prev = fc->ncols;
7857 if (reg < fc->ncols)
7860 fc->ncols = reg + 1;
7861 fc->col_type = (short int *) xrealloc (fc->col_type,
7862 fc->ncols * sizeof (short int));
7863 fc->col_offset = (int *) xrealloc (fc->col_offset,
7864 fc->ncols * sizeof (int));
7866 while (prev < fc->ncols)
7868 fc->col_type[prev] = DW_CFA_unreferenced;
7869 fc->col_offset[prev] = 0;
7875 frame_display_row (fc, need_col_headers, max_regs)
7877 int * need_col_headers;
7883 if (* max_regs < fc->ncols)
7884 * max_regs = fc->ncols;
7886 if (* need_col_headers)
7888 * need_col_headers = 0;
7890 printf (" LOC CFA ");
7892 for (r = 0; r < * max_regs; r++)
7893 if (fc->col_type[r] != DW_CFA_unreferenced)
7898 printf ("r%-4d", r);
7904 printf ("%08lx ", fc->pc_begin);
7905 sprintf (tmp, "r%d%+d", fc->cfa_reg, fc->cfa_offset);
7906 printf ("%-8s ", tmp);
7908 for (r = 0; r < fc->ncols; r++)
7910 if (fc->col_type[r] != DW_CFA_unreferenced)
7912 switch (fc->col_type[r])
7914 case DW_CFA_undefined:
7917 case DW_CFA_same_value:
7921 sprintf (tmp, "c%+d", fc->col_offset[r]);
7923 case DW_CFA_register:
7924 sprintf (tmp, "r%d", fc->col_offset[r]);
7927 strcpy (tmp, "n/a");
7930 printf ("%-5s", tmp);
7937 size_of_encoded_value (encoding)
7940 switch (encoding & 0x7)
7943 case 0: return is_32bit_elf ? 4 : 8;
7950 #define GET(N) byte_get (start, N); start += N
7951 #define LEB() read_leb128 (start, & length_return, 0); start += length_return
7952 #define SLEB() read_leb128 (start, & length_return, 1); start += length_return
7955 display_debug_frames (section, start, file)
7956 Elf32_Internal_Shdr * section;
7957 unsigned char * start;
7958 FILE * file ATTRIBUTE_UNUSED;
7960 unsigned char * end = start + section->sh_size;
7961 unsigned char * section_start = start;
7962 Frame_Chunk * chunks = 0;
7963 Frame_Chunk * remembered_state = 0;
7965 int is_eh = (strcmp (SECTION_NAME (section), ".eh_frame") == 0);
7968 int addr_size = is_32bit_elf ? 4 : 8;
7970 printf (_("The section %s contains:\n"), SECTION_NAME (section));
7974 unsigned char * saved_start;
7975 unsigned char * block_end;
7976 unsigned long length;
7977 unsigned long cie_id;
7980 int need_col_headers = 1;
7981 unsigned char * augmentation_data = NULL;
7982 unsigned long augmentation_data_len = 0;
7983 int encoded_ptr_size = addr_size;
7985 saved_start = start;
7986 length = byte_get (start, 4); start += 4;
7991 if (length == 0xffffffff)
7993 warn (_("64-bit DWARF format frames are not supported yet.\n"));
7997 block_end = saved_start + length + 4;
7998 cie_id = byte_get (start, 4); start += 4;
8000 if (is_eh ? (cie_id == 0) : (cie_id == DW_CIE_ID))
8004 fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
8005 memset (fc, 0, sizeof (Frame_Chunk));
8009 fc->chunk_start = saved_start;
8011 fc->col_type = (short int *) xmalloc (sizeof (short int));
8012 fc->col_offset = (int *) xmalloc (sizeof (int));
8013 frame_need_space (fc, max_regs-1);
8017 fc->augmentation = start;
8018 start = strchr (start, '\0') + 1;
8020 if (fc->augmentation[0] == 'z')
8022 fc->code_factor = LEB ();
8023 fc->data_factor = SLEB ();
8024 fc->ra = byte_get (start, 1); start += 1;
8025 augmentation_data_len = LEB ();
8026 augmentation_data = start;
8027 start += augmentation_data_len;
8029 else if (strcmp (fc->augmentation, "eh") == 0)
8032 fc->code_factor = LEB ();
8033 fc->data_factor = SLEB ();
8034 fc->ra = byte_get (start, 1); start += 1;
8038 fc->code_factor = LEB ();
8039 fc->data_factor = SLEB ();
8040 fc->ra = byte_get (start, 1); start += 1;
8044 if (do_debug_frames_interp)
8045 printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n",
8046 (unsigned long)(saved_start - section_start), length, cie_id,
8047 fc->augmentation, fc->code_factor, fc->data_factor,
8051 printf ("\n%08lx %08lx %08lx CIE\n",
8052 (unsigned long)(saved_start - section_start), length, cie_id);
8053 printf (" Version: %d\n", version);
8054 printf (" Augmentation: \"%s\"\n", fc->augmentation);
8055 printf (" Code alignment factor: %u\n", fc->code_factor);
8056 printf (" Data alignment factor: %d\n", fc->data_factor);
8057 printf (" Return address column: %d\n", fc->ra);
8059 if (augmentation_data_len)
8062 printf (" Augmentation data: ");
8063 for (i = 0; i < augmentation_data_len; ++i)
8064 printf (" %02x", augmentation_data[i]);
8070 if (augmentation_data_len)
8072 unsigned char *p, *q;
8073 p = fc->augmentation + 1;
8074 q = augmentation_data;
8081 q += 1 + size_of_encoded_value (*q);
8083 fc->fde_encoding = *q++;
8089 if (fc->fde_encoding)
8090 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
8093 frame_need_space (fc, fc->ra);
8097 unsigned char * look_for;
8098 static Frame_Chunk fde_fc;
8101 memset (fc, 0, sizeof (Frame_Chunk));
8103 look_for = is_eh ? start - 4 - cie_id : section_start + cie_id;
8105 for (cie = chunks; cie ; cie = cie->next)
8106 if (cie->chunk_start == look_for)
8111 warn ("Invalid CIE pointer %08lx in FDE at %08lx\n",
8112 cie_id, saved_start);
8115 fc->col_type = (short int *) xmalloc (sizeof (short int));
8116 fc->col_offset = (int *) xmalloc (sizeof (int));
8117 frame_need_space (fc, max_regs - 1);
8119 fc->augmentation = "";
8120 fc->fde_encoding = 0;
8124 fc->ncols = cie->ncols;
8125 fc->col_type = (short int *) xmalloc (fc->ncols * sizeof (short int));
8126 fc->col_offset = (int *) xmalloc (fc->ncols * sizeof (int));
8127 memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int));
8128 memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int));
8129 fc->augmentation = cie->augmentation;
8130 fc->code_factor = cie->code_factor;
8131 fc->data_factor = cie->data_factor;
8132 fc->cfa_reg = cie->cfa_reg;
8133 fc->cfa_offset = cie->cfa_offset;
8135 frame_need_space (fc, max_regs-1);
8136 fc->fde_encoding = cie->fde_encoding;
8139 if (fc->fde_encoding)
8140 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
8142 fc->pc_begin = byte_get (start, encoded_ptr_size);
8143 start += encoded_ptr_size;
8144 fc->pc_range = byte_get (start, encoded_ptr_size);
8145 start += encoded_ptr_size;
8147 if (cie->augmentation[0] == 'z')
8149 augmentation_data_len = LEB ();
8150 augmentation_data = start;
8151 start += augmentation_data_len;
8154 printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=%08lx..%08lx\n",
8155 (unsigned long)(saved_start - section_start), length, cie_id,
8156 (unsigned long)(cie->chunk_start - section_start),
8157 fc->pc_begin, fc->pc_begin + fc->pc_range);
8158 if (! do_debug_frames_interp && augmentation_data_len)
8161 printf (" Augmentation data: ");
8162 for (i = 0; i < augmentation_data_len; ++i)
8163 printf (" %02x", augmentation_data[i]);
8169 /* At this point, fc is the current chunk, cie (if any) is set, and we're
8170 about to interpret instructions for the chunk. */
8172 if (do_debug_frames_interp)
8174 /* Start by making a pass over the chunk, allocating storage
8175 and taking note of what registers are used. */
8176 unsigned char * tmp = start;
8178 while (start < block_end)
8188 /* Warning: if you add any more cases to this switch, be
8189 sure to add them to the corresponding switch below. */
8192 case DW_CFA_advance_loc:
8196 frame_need_space (fc, opa);
8197 fc->col_type[opa] = DW_CFA_undefined;
8199 case DW_CFA_restore:
8200 frame_need_space (fc, opa);
8201 fc->col_type[opa] = DW_CFA_undefined;
8203 case DW_CFA_set_loc:
8204 start += encoded_ptr_size;
8206 case DW_CFA_advance_loc1:
8209 case DW_CFA_advance_loc2:
8212 case DW_CFA_advance_loc4:
8215 case DW_CFA_offset_extended:
8216 reg = LEB (); LEB ();
8217 frame_need_space (fc, reg);
8218 fc->col_type[reg] = DW_CFA_undefined;
8220 case DW_CFA_restore_extended:
8222 frame_need_space (fc, reg);
8223 fc->col_type[reg] = DW_CFA_undefined;
8225 case DW_CFA_undefined:
8227 frame_need_space (fc, reg);
8228 fc->col_type[reg] = DW_CFA_undefined;
8230 case DW_CFA_same_value:
8232 frame_need_space (fc, reg);
8233 fc->col_type[reg] = DW_CFA_undefined;
8235 case DW_CFA_register:
8236 reg = LEB (); LEB ();
8237 frame_need_space (fc, reg);
8238 fc->col_type[reg] = DW_CFA_undefined;
8240 case DW_CFA_def_cfa:
8243 case DW_CFA_def_cfa_register:
8246 case DW_CFA_def_cfa_offset:
8249 #ifndef DW_CFA_GNU_args_size
8250 #define DW_CFA_GNU_args_size 0x2e
8252 case DW_CFA_GNU_args_size:
8255 #ifndef DW_CFA_GNU_negative_offset_extended
8256 #define DW_CFA_GNU_negative_offset_extended 0x2f
8258 case DW_CFA_GNU_negative_offset_extended:
8259 reg = LEB (); LEB ();
8260 frame_need_space (fc, reg);
8261 fc->col_type[reg] = DW_CFA_undefined;
8270 /* Now we know what registers are used, make a second pass over
8271 the chunk, this time actually printing out the info. */
8273 while (start < block_end)
8276 unsigned long ul, reg, roffs;
8285 /* Warning: if you add any more cases to this switch, be
8286 sure to add them to the corresponding switch above. */
8289 case DW_CFA_advance_loc:
8290 if (do_debug_frames_interp)
8291 frame_display_row (fc, &need_col_headers, &max_regs);
8293 printf (" DW_CFA_advance_loc: %d to %08lx\n",
8294 opa * fc->code_factor,
8295 fc->pc_begin + opa * fc->code_factor);
8296 fc->pc_begin += opa * fc->code_factor;
8301 if (! do_debug_frames_interp)
8302 printf (" DW_CFA_offset: r%d at cfa%+ld\n",
8303 opa, roffs * fc->data_factor);
8304 fc->col_type[opa] = DW_CFA_offset;
8305 fc->col_offset[opa] = roffs * fc->data_factor;
8308 case DW_CFA_restore:
8309 if (! do_debug_frames_interp)
8310 printf (" DW_CFA_restore: r%d\n", opa);
8311 fc->col_type[opa] = cie->col_type[opa];
8312 fc->col_offset[opa] = cie->col_offset[opa];
8315 case DW_CFA_set_loc:
8316 vma = byte_get (start, encoded_ptr_size);
8317 start += encoded_ptr_size;
8318 if (do_debug_frames_interp)
8319 frame_display_row (fc, &need_col_headers, &max_regs);
8321 printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma);
8325 case DW_CFA_advance_loc1:
8326 ofs = byte_get (start, 1); start += 1;
8327 if (do_debug_frames_interp)
8328 frame_display_row (fc, &need_col_headers, &max_regs);
8330 printf (" DW_CFA_advance_loc1: %ld to %08lx\n",
8331 ofs * fc->code_factor,
8332 fc->pc_begin + ofs * fc->code_factor);
8333 fc->pc_begin += ofs * fc->code_factor;
8336 case DW_CFA_advance_loc2:
8337 ofs = byte_get (start, 2); start += 2;
8338 if (do_debug_frames_interp)
8339 frame_display_row (fc, &need_col_headers, &max_regs);
8341 printf (" DW_CFA_advance_loc2: %ld to %08lx\n",
8342 ofs * fc->code_factor,
8343 fc->pc_begin + ofs * fc->code_factor);
8344 fc->pc_begin += ofs * fc->code_factor;
8347 case DW_CFA_advance_loc4:
8348 ofs = byte_get (start, 4); start += 4;
8349 if (do_debug_frames_interp)
8350 frame_display_row (fc, &need_col_headers, &max_regs);
8352 printf (" DW_CFA_advance_loc4: %ld to %08lx\n",
8353 ofs * fc->code_factor,
8354 fc->pc_begin + ofs * fc->code_factor);
8355 fc->pc_begin += ofs * fc->code_factor;
8358 case DW_CFA_offset_extended:
8361 if (! do_debug_frames_interp)
8362 printf (" DW_CFA_offset_extended: r%ld at cfa%+ld\n",
8363 reg, roffs * fc->data_factor);
8364 fc->col_type[reg] = DW_CFA_offset;
8365 fc->col_offset[reg] = roffs * fc->data_factor;
8368 case DW_CFA_restore_extended:
8370 if (! do_debug_frames_interp)
8371 printf (" DW_CFA_restore_extended: r%ld\n", reg);
8372 fc->col_type[reg] = cie->col_type[reg];
8373 fc->col_offset[reg] = cie->col_offset[reg];
8376 case DW_CFA_undefined:
8378 if (! do_debug_frames_interp)
8379 printf (" DW_CFA_undefined: r%ld\n", reg);
8380 fc->col_type[reg] = DW_CFA_undefined;
8381 fc->col_offset[reg] = 0;
8384 case DW_CFA_same_value:
8386 if (! do_debug_frames_interp)
8387 printf (" DW_CFA_same_value: r%ld\n", reg);
8388 fc->col_type[reg] = DW_CFA_same_value;
8389 fc->col_offset[reg] = 0;
8392 case DW_CFA_register:
8395 if (! do_debug_frames_interp)
8396 printf (" DW_CFA_register: r%ld\n", reg);
8397 fc->col_type[reg] = DW_CFA_register;
8398 fc->col_offset[reg] = roffs;
8401 case DW_CFA_remember_state:
8402 if (! do_debug_frames_interp)
8403 printf (" DW_CFA_remember_state\n");
8404 rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
8405 rs->ncols = fc->ncols;
8406 rs->col_type = (short int *) xmalloc (rs->ncols * sizeof (short int));
8407 rs->col_offset = (int *) xmalloc (rs->ncols * sizeof (int));
8408 memcpy (rs->col_type, fc->col_type, rs->ncols);
8409 memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (int));
8410 rs->next = remembered_state;
8411 remembered_state = rs;
8414 case DW_CFA_restore_state:
8415 if (! do_debug_frames_interp)
8416 printf (" DW_CFA_restore_state\n");
8417 rs = remembered_state;
8418 remembered_state = rs->next;
8419 frame_need_space (fc, rs->ncols-1);
8420 memcpy (fc->col_type, rs->col_type, rs->ncols);
8421 memcpy (fc->col_offset, rs->col_offset, rs->ncols * sizeof (int));
8422 free (rs->col_type);
8423 free (rs->col_offset);
8427 case DW_CFA_def_cfa:
8428 fc->cfa_reg = LEB ();
8429 fc->cfa_offset = LEB ();
8430 if (! do_debug_frames_interp)
8431 printf (" DW_CFA_def_cfa: r%d ofs %d\n",
8432 fc->cfa_reg, fc->cfa_offset);
8435 case DW_CFA_def_cfa_register:
8436 fc->cfa_reg = LEB ();
8437 if (! do_debug_frames_interp)
8438 printf (" DW_CFA_def_cfa_reg: r%d\n", fc->cfa_reg);
8441 case DW_CFA_def_cfa_offset:
8442 fc->cfa_offset = LEB ();
8443 if (! do_debug_frames_interp)
8444 printf (" DW_CFA_def_cfa_offset: %d\n", fc->cfa_offset);
8448 if (! do_debug_frames_interp)
8449 printf (" DW_CFA_nop\n");
8452 #ifndef DW_CFA_GNU_window_save
8453 #define DW_CFA_GNU_window_save 0x2d
8455 case DW_CFA_GNU_window_save:
8456 if (! do_debug_frames_interp)
8457 printf (" DW_CFA_GNU_window_save\n");
8460 case DW_CFA_GNU_args_size:
8462 if (! do_debug_frames_interp)
8463 printf (" DW_CFA_GNU_args_size: %ld\n", ul);
8466 case DW_CFA_GNU_negative_offset_extended:
8469 frame_need_space (fc, reg);
8470 if (! do_debug_frames_interp)
8471 printf (" DW_CFA_GNU_negative_offset_extended: r%ld at cfa%+ld\n",
8472 reg, l * fc->data_factor);
8473 fc->col_type[reg] = DW_CFA_offset;
8474 fc->col_offset[reg] = l * fc->data_factor;
8478 fprintf (stderr, "unsupported or unknown DW_CFA_%d\n", op);
8483 if (do_debug_frames_interp)
8484 frame_display_row (fc, &need_col_headers, &max_regs);
8499 display_debug_not_supported (section, start, file)
8500 Elf32_Internal_Shdr * section;
8501 unsigned char * start ATTRIBUTE_UNUSED;
8502 FILE * file ATTRIBUTE_UNUSED;
8504 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
8505 SECTION_NAME (section));
8510 /* Pre-scan the .debug_info section to record the size of address.
8511 When dumping the .debug_line, we use that size information, assuming
8512 that all compilation units have the same address size. */
8514 prescan_debug_info (section, start, file)
8515 Elf32_Internal_Shdr * section ATTRIBUTE_UNUSED;
8516 unsigned char * start;
8517 FILE * file ATTRIBUTE_UNUSED;
8519 DWARF2_External_CompUnit * external;
8521 external = (DWARF2_External_CompUnit *) start;
8523 debug_line_pointer_size = BYTE_GET (external->cu_pointer_size);
8527 /* A structure containing the name of a debug section and a pointer
8528 to a function that can decode it. The third field is a prescan
8529 function to be run over the section before displaying any of the
8533 const char * const name;
8534 int (* display) PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
8535 int (* prescan) PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
8539 { ".debug_abbrev", display_debug_abbrev, NULL },
8540 { ".debug_aranges", display_debug_aranges, NULL },
8541 { ".debug_frame", display_debug_frames, NULL },
8542 { ".debug_info", display_debug_info, prescan_debug_info },
8543 { ".debug_line", display_debug_lines, NULL },
8544 { ".debug_pubnames", display_debug_pubnames, NULL },
8545 { ".eh_frame", display_debug_frames, NULL },
8546 { ".debug_macinfo", display_debug_macinfo, NULL },
8547 { ".debug_str", display_debug_str, NULL },
8549 { ".debug_pubtypes", display_debug_not_supported, NULL },
8550 { ".debug_ranges", display_debug_not_supported, NULL },
8551 { ".debug_static_func", display_debug_not_supported, NULL },
8552 { ".debug_static_vars", display_debug_not_supported, NULL },
8553 { ".debug_types", display_debug_not_supported, NULL },
8554 { ".debug_weaknames", display_debug_not_supported, NULL }
8558 display_debug_section (section, file)
8559 Elf32_Internal_Shdr * section;
8562 char * name = SECTION_NAME (section);
8563 bfd_size_type length;
8564 unsigned char * start;
8567 length = section->sh_size;
8570 printf (_("\nSection '%s' has no debugging data.\n"), name);
8574 start = (unsigned char *) get_data (NULL, file, section->sh_offset, length,
8575 _("debug section data"));
8579 /* See if we know how to display the contents of this section. */
8580 if (strncmp (name, ".gnu.linkonce.wi.", 17) == 0)
8581 name = ".debug_info";
8583 for (i = NUM_ELEM (debug_displays); i--;)
8584 if (strcmp (debug_displays[i].name, name) == 0)
8586 debug_displays[i].display (section, start, file);
8591 printf (_("Unrecognised debug section: %s\n"), name);
8595 /* If we loaded in the abbrev section at some point,
8596 we must release it here. */
8603 process_section_contents (file)
8606 Elf32_Internal_Shdr * section;
8612 /* Pre-scan the debug sections to find some debug information not
8613 present in some of them. For the .debug_line, we must find out the
8614 size of address (specified in .debug_info and .debug_aranges). */
8615 for (i = 0, section = section_headers;
8616 i < elf_header.e_shnum && i < num_dump_sects;
8619 char * name = SECTION_NAME (section);
8622 if (section->sh_size == 0)
8625 /* See if there is some pre-scan operation for this section. */
8626 for (j = NUM_ELEM (debug_displays); j--;)
8627 if (strcmp (debug_displays[j].name, name) == 0)
8629 if (debug_displays[j].prescan != NULL)
8631 bfd_size_type length;
8632 unsigned char * start;
8634 length = section->sh_size;
8635 start = ((unsigned char *)
8636 get_data (NULL, file, section->sh_offset, length,
8637 _("debug section data")));
8641 debug_displays[j].prescan (section, start, file);
8649 for (i = 0, section = section_headers;
8650 i < elf_header.e_shnum && i < num_dump_sects;
8653 #ifdef SUPPORT_DISASSEMBLY
8654 if (dump_sects[i] & DISASS_DUMP)
8655 disassemble_section (section, file);
8657 if (dump_sects[i] & HEX_DUMP)
8658 dump_section (section, file);
8660 if (dump_sects[i] & DEBUG_DUMP)
8661 display_debug_section (section, file);
8664 if (i < num_dump_sects)
8665 warn (_("Some sections were not dumped because they do not exist!\n"));
8671 process_mips_fpe_exception (mask)
8677 if (mask & OEX_FPU_INEX)
8678 fputs ("INEX", stdout), first = 0;
8679 if (mask & OEX_FPU_UFLO)
8680 printf ("%sUFLO", first ? "" : "|"), first = 0;
8681 if (mask & OEX_FPU_OFLO)
8682 printf ("%sOFLO", first ? "" : "|"), first = 0;
8683 if (mask & OEX_FPU_DIV0)
8684 printf ("%sDIV0", first ? "" : "|"), first = 0;
8685 if (mask & OEX_FPU_INVAL)
8686 printf ("%sINVAL", first ? "" : "|");
8689 fputs ("0", stdout);
8693 process_mips_specific (file)
8696 Elf_Internal_Dyn * entry;
8697 size_t liblist_offset = 0;
8698 size_t liblistno = 0;
8699 size_t conflictsno = 0;
8700 size_t options_offset = 0;
8701 size_t conflicts_offset = 0;
8703 /* We have a lot of special sections. Thanks SGI! */
8704 if (dynamic_segment == NULL)
8705 /* No information available. */
8708 for (entry = dynamic_segment; entry->d_tag != DT_NULL; ++entry)
8709 switch (entry->d_tag)
8711 case DT_MIPS_LIBLIST:
8712 liblist_offset = entry->d_un.d_val - loadaddr;
8714 case DT_MIPS_LIBLISTNO:
8715 liblistno = entry->d_un.d_val;
8717 case DT_MIPS_OPTIONS:
8718 options_offset = entry->d_un.d_val - loadaddr;
8720 case DT_MIPS_CONFLICT:
8721 conflicts_offset = entry->d_un.d_val - loadaddr;
8723 case DT_MIPS_CONFLICTNO:
8724 conflictsno = entry->d_un.d_val;
8730 if (liblist_offset != 0 && liblistno != 0 && do_dynamic)
8732 Elf32_External_Lib * elib;
8735 elib = ((Elf32_External_Lib *)
8736 get_data (NULL, file, liblist_offset,
8737 liblistno * sizeof (Elf32_External_Lib),
8741 printf ("\nSection '.liblist' contains %lu entries:\n",
8742 (unsigned long) liblistno);
8743 fputs (" Library Time Stamp Checksum Version Flags\n",
8746 for (cnt = 0; cnt < liblistno; ++cnt)
8753 liblist.l_name = BYTE_GET (elib[cnt].l_name);
8754 time = BYTE_GET (elib[cnt].l_time_stamp);
8755 liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum);
8756 liblist.l_version = BYTE_GET (elib[cnt].l_version);
8757 liblist.l_flags = BYTE_GET (elib[cnt].l_flags);
8759 tmp = gmtime (&time);
8760 sprintf (timebuf, "%04u-%02u-%02uT%02u:%02u:%02u",
8761 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
8762 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
8764 printf ("%3lu: ", (unsigned long) cnt);
8765 print_symbol (20, dynamic_strings + liblist.l_name);
8766 printf (" %s %#10lx %-7ld", timebuf, liblist.l_checksum,
8769 if (liblist.l_flags == 0)
8780 { " EXACT_MATCH", LL_EXACT_MATCH },
8781 { " IGNORE_INT_VER", LL_IGNORE_INT_VER },
8782 { " REQUIRE_MINOR", LL_REQUIRE_MINOR },
8783 { " EXPORTS", LL_EXPORTS },
8784 { " DELAY_LOAD", LL_DELAY_LOAD },
8785 { " DELTA", LL_DELTA }
8787 int flags = liblist.l_flags;
8791 fcnt < sizeof (l_flags_vals) / sizeof (l_flags_vals[0]);
8793 if ((flags & l_flags_vals[fcnt].bit) != 0)
8795 fputs (l_flags_vals[fcnt].name, stdout);
8796 flags ^= l_flags_vals[fcnt].bit;
8799 printf (" %#x", (unsigned int) flags);
8809 if (options_offset != 0)
8811 Elf_External_Options * eopt;
8812 Elf_Internal_Shdr * sect = section_headers;
8813 Elf_Internal_Options * iopt;
8814 Elf_Internal_Options * option;
8818 /* Find the section header so that we get the size. */
8819 while (sect->sh_type != SHT_MIPS_OPTIONS)
8822 eopt = (Elf_External_Options *) get_data (NULL, file, options_offset,
8823 sect->sh_size, _("options"));
8826 iopt = ((Elf_Internal_Options *)
8827 malloc ((sect->sh_size / sizeof (eopt)) * sizeof (* iopt)));
8830 error (_("Out of memory"));
8837 while (offset < sect->sh_size)
8839 Elf_External_Options * eoption;
8841 eoption = (Elf_External_Options *) ((char *) eopt + offset);
8843 option->kind = BYTE_GET (eoption->kind);
8844 option->size = BYTE_GET (eoption->size);
8845 option->section = BYTE_GET (eoption->section);
8846 option->info = BYTE_GET (eoption->info);
8848 offset += option->size;
8854 printf (_("\nSection '%s' contains %d entries:\n"),
8855 SECTION_NAME (sect), cnt);
8863 switch (option->kind)
8866 /* This shouldn't happen. */
8867 printf (" NULL %d %lx", option->section, option->info);
8870 printf (" REGINFO ");
8871 if (elf_header.e_machine == EM_MIPS)
8874 Elf32_External_RegInfo * ereg;
8875 Elf32_RegInfo reginfo;
8877 ereg = (Elf32_External_RegInfo *) (option + 1);
8878 reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask);
8879 reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
8880 reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
8881 reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
8882 reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
8883 reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value);
8885 printf ("GPR %08lx GP 0x%lx\n",
8887 (unsigned long) reginfo.ri_gp_value);
8888 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
8889 reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
8890 reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
8895 Elf64_External_RegInfo * ereg;
8896 Elf64_Internal_RegInfo reginfo;
8898 ereg = (Elf64_External_RegInfo *) (option + 1);
8899 reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask);
8900 reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
8901 reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
8902 reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
8903 reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
8904 reginfo.ri_gp_value = BYTE_GET8 (ereg->ri_gp_value);
8906 printf ("GPR %08lx GP 0x",
8907 reginfo.ri_gprmask);
8908 printf_vma (reginfo.ri_gp_value);
8911 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
8912 reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
8913 reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
8917 case ODK_EXCEPTIONS:
8918 fputs (" EXCEPTIONS fpe_min(", stdout);
8919 process_mips_fpe_exception (option->info & OEX_FPU_MIN);
8920 fputs (") fpe_max(", stdout);
8921 process_mips_fpe_exception ((option->info & OEX_FPU_MAX) >> 8);
8922 fputs (")", stdout);
8924 if (option->info & OEX_PAGE0)
8925 fputs (" PAGE0", stdout);
8926 if (option->info & OEX_SMM)
8927 fputs (" SMM", stdout);
8928 if (option->info & OEX_FPDBUG)
8929 fputs (" FPDBUG", stdout);
8930 if (option->info & OEX_DISMISS)
8931 fputs (" DISMISS", stdout);
8934 fputs (" PAD ", stdout);
8935 if (option->info & OPAD_PREFIX)
8936 fputs (" PREFIX", stdout);
8937 if (option->info & OPAD_POSTFIX)
8938 fputs (" POSTFIX", stdout);
8939 if (option->info & OPAD_SYMBOL)
8940 fputs (" SYMBOL", stdout);
8943 fputs (" HWPATCH ", stdout);
8944 if (option->info & OHW_R4KEOP)
8945 fputs (" R4KEOP", stdout);
8946 if (option->info & OHW_R8KPFETCH)
8947 fputs (" R8KPFETCH", stdout);
8948 if (option->info & OHW_R5KEOP)
8949 fputs (" R5KEOP", stdout);
8950 if (option->info & OHW_R5KCVTL)
8951 fputs (" R5KCVTL", stdout);
8954 fputs (" FILL ", stdout);
8955 /* XXX Print content of info word? */
8958 fputs (" TAGS ", stdout);
8959 /* XXX Print content of info word? */
8962 fputs (" HWAND ", stdout);
8963 if (option->info & OHWA0_R4KEOP_CHECKED)
8964 fputs (" R4KEOP_CHECKED", stdout);
8965 if (option->info & OHWA0_R4KEOP_CLEAN)
8966 fputs (" R4KEOP_CLEAN", stdout);
8969 fputs (" HWOR ", stdout);
8970 if (option->info & OHWA0_R4KEOP_CHECKED)
8971 fputs (" R4KEOP_CHECKED", stdout);
8972 if (option->info & OHWA0_R4KEOP_CLEAN)
8973 fputs (" R4KEOP_CLEAN", stdout);
8976 printf (" GP_GROUP %#06lx self-contained %#06lx",
8977 option->info & OGP_GROUP,
8978 (option->info & OGP_SELF) >> 16);
8981 printf (" IDENT %#06lx self-contained %#06lx",
8982 option->info & OGP_GROUP,
8983 (option->info & OGP_SELF) >> 16);
8986 /* This shouldn't happen. */
8987 printf (" %3d ??? %d %lx",
8988 option->kind, option->section, option->info);
8992 len = sizeof (* eopt);
8993 while (len < option->size)
8994 if (((char *) option)[len] >= ' '
8995 && ((char *) option)[len] < 0x7f)
8996 printf ("%c", ((char *) option)[len++]);
8998 printf ("\\%03o", ((char *) option)[len++]);
9000 fputs ("\n", stdout);
9008 if (conflicts_offset != 0 && conflictsno != 0)
9010 Elf32_Conflict * iconf;
9013 if (dynamic_symbols == NULL)
9015 error (_("conflict list with without table"));
9019 iconf = (Elf32_Conflict *) malloc (conflictsno * sizeof (* iconf));
9022 error (_("Out of memory"));
9028 Elf32_External_Conflict * econf32;
9030 econf32 = ((Elf32_External_Conflict *)
9031 get_data (NULL, file, conflicts_offset,
9032 conflictsno * sizeof (* econf32),
9037 for (cnt = 0; cnt < conflictsno; ++cnt)
9038 iconf[cnt] = BYTE_GET (econf32[cnt]);
9044 Elf64_External_Conflict * econf64;
9046 econf64 = ((Elf64_External_Conflict *)
9047 get_data (NULL, file, conflicts_offset,
9048 conflictsno * sizeof (* econf64),
9053 for (cnt = 0; cnt < conflictsno; ++cnt)
9054 iconf[cnt] = BYTE_GET (econf64[cnt]);
9059 printf (_("\nSection '.conflict' contains %ld entries:\n"),
9060 (long) conflictsno);
9061 puts (_(" Num: Index Value Name"));
9063 for (cnt = 0; cnt < conflictsno; ++cnt)
9065 Elf_Internal_Sym * psym = & dynamic_symbols [iconf [cnt]];
9067 printf ("%5lu: %8lu ", (unsigned long) cnt, iconf [cnt]);
9068 print_vma (psym->st_value, FULL_HEX);
9070 print_symbol (25, dynamic_strings + psym->st_name);
9081 get_note_type (e_type)
9084 static char buff[64];
9088 case NT_PRSTATUS: return _("NT_PRSTATUS (prstatus structure)");
9089 case NT_FPREGSET: return _("NT_FPREGSET (floating point registers)");
9090 case NT_PRPSINFO: return _("NT_PRPSINFO (prpsinfo structure)");
9091 case NT_TASKSTRUCT: return _("NT_TASKSTRUCT (task structure)");
9092 case NT_PRXFPREG: return _("NT_PRXFPREG (user_xfpregs structure)");
9093 case NT_PSTATUS: return _("NT_PSTATUS (pstatus structure)");
9094 case NT_FPREGS: return _("NT_FPREGS (floating point registers)");
9095 case NT_PSINFO: return _("NT_PSINFO (psinfo structure)");
9096 case NT_LWPSTATUS: return _("NT_LWPSTATUS (lwpstatus_t structure)");
9097 case NT_LWPSINFO: return _("NT_LWPSINFO (lwpsinfo_t structure)");
9098 case NT_WIN32PSTATUS: return _("NT_WIN32PSTATUS (win32_pstatus strcuture)");
9100 sprintf (buff, _("Unknown note type: (0x%08x)"), e_type);
9106 get_netbsd_elfcore_note_type (e_type)
9109 static char buff[64];
9111 if (e_type == NT_NETBSDCORE_PROCINFO)
9113 /* NetBSD core "procinfo" structure. */
9114 return _("NetBSD procinfo structure");
9117 /* As of Jan 2002 there are no other machine-independent notes
9118 defined for NetBSD core files. If the note type is less
9119 than the start of the machine-dependent note types, we don't
9122 if (e_type < NT_NETBSDCORE_FIRSTMACH)
9124 sprintf (buff, _("Unknown note type: (0x%08x)"), e_type);
9128 switch (elf_header.e_machine)
9130 /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0
9131 and PT_GETFPREGS == mach+2. */
9136 case EM_SPARC32PLUS:
9140 case NT_NETBSDCORE_FIRSTMACH+0:
9141 return _("PT_GETREGS (reg structure)");
9142 case NT_NETBSDCORE_FIRSTMACH+2:
9143 return _("PT_GETFPREGS (fpreg structure)");
9149 /* On all other arch's, PT_GETREGS == mach+1 and
9150 PT_GETFPREGS == mach+3. */
9154 case NT_NETBSDCORE_FIRSTMACH+1:
9155 return _("PT_GETREGS (reg structure)");
9156 case NT_NETBSDCORE_FIRSTMACH+3:
9157 return _("PT_GETFPREGS (fpreg structure)");
9163 sprintf (buff, _("PT_FIRSTMACH+%d"), e_type - NT_NETBSDCORE_FIRSTMACH);
9167 /* Note that by the ELF standard, the name field is already null byte
9168 terminated, and namesz includes the terminating null byte.
9169 I.E. the value of namesz for the name "FSF" is 4.
9171 If the value of namesz is zero, there is no name present. */
9173 process_note (pnote)
9174 Elf32_Internal_Note * pnote;
9178 if (pnote->namesz == 0)
9180 /* If there is no note name, then use the default set of
9181 note type strings. */
9182 nt = get_note_type (pnote->type);
9184 else if (strncmp (pnote->namedata, "NetBSD-CORE", 11) == 0)
9186 /* NetBSD-specific core file notes. */
9187 nt = get_netbsd_elfcore_note_type (pnote->type);
9191 /* Don't recognize this note name; just use the default set of
9192 note type strings. */
9193 nt = get_note_type (pnote->type);
9196 printf (" %s\t\t0x%08lx\t%s\n",
9197 pnote->namesz ? pnote->namedata : "(NONE)",
9204 process_corefile_note_segment (file, offset, length)
9209 Elf_External_Note * pnotes;
9210 Elf_External_Note * external;
9216 pnotes = (Elf_External_Note *) get_data (NULL, file, offset, length,
9223 printf (_("\nNotes at offset 0x%08lx with length 0x%08lx:\n"),
9224 (unsigned long) offset, (unsigned long) length);
9225 printf (_(" Owner\t\tData size\tDescription\n"));
9227 while (external < (Elf_External_Note *)((char *) pnotes + length))
9229 Elf32_Internal_Note inote;
9232 inote.type = BYTE_GET (external->type);
9233 inote.namesz = BYTE_GET (external->namesz);
9234 inote.namedata = external->name;
9235 inote.descsz = BYTE_GET (external->descsz);
9236 inote.descdata = inote.namedata + align_power (inote.namesz, 2);
9237 inote.descpos = offset + (inote.descdata - (char *) pnotes);
9239 external = (Elf_External_Note *)(inote.descdata + align_power (inote.descsz, 2));
9241 /* Verify that name is null terminated. It appears that at least
9242 one version of Linux (RedHat 6.0) generates corefiles that don't
9243 comply with the ELF spec by failing to include the null byte in
9245 if (inote.namedata[inote.namesz] != '\0')
9247 temp = malloc (inote.namesz + 1);
9251 error (_("Out of memory\n"));
9256 strncpy (temp, inote.namedata, inote.namesz);
9257 temp[inote.namesz] = 0;
9259 /* warn (_("'%s' NOTE name not properly null terminated\n"), temp); */
9260 inote.namedata = temp;
9263 res &= process_note (& inote);
9278 process_corefile_note_segments (file)
9281 Elf_Internal_Phdr * program_headers;
9282 Elf_Internal_Phdr * segment;
9286 program_headers = (Elf_Internal_Phdr *) malloc
9287 (elf_header.e_phnum * sizeof (Elf_Internal_Phdr));
9289 if (program_headers == NULL)
9291 error (_("Out of memory\n"));
9296 i = get_32bit_program_headers (file, program_headers);
9298 i = get_64bit_program_headers (file, program_headers);
9302 free (program_headers);
9306 for (i = 0, segment = program_headers;
9307 i < elf_header.e_phnum;
9310 if (segment->p_type == PT_NOTE)
9311 res &= process_corefile_note_segment (file,
9312 (bfd_vma) segment->p_offset,
9313 (bfd_vma) segment->p_filesz);
9316 free (program_headers);
9322 process_corefile_contents (file)
9325 /* If we have not been asked to display the notes then do nothing. */
9329 /* If file is not a core file then exit. */
9330 if (elf_header.e_type != ET_CORE)
9333 /* No program headers means no NOTE segment. */
9334 if (elf_header.e_phnum == 0)
9336 printf (_("No note segments present in the core file.\n"));
9340 return process_corefile_note_segments (file);
9344 process_arch_specific (file)
9350 switch (elf_header.e_machine)
9353 case EM_MIPS_RS3_LE:
9354 return process_mips_specific (file);
9363 get_file_header (file)
9366 /* Read in the identity array. */
9367 if (fread (elf_header.e_ident, EI_NIDENT, 1, file) != 1)
9370 /* Determine how to read the rest of the header. */
9371 switch (elf_header.e_ident [EI_DATA])
9373 default: /* fall through */
9374 case ELFDATANONE: /* fall through */
9375 case ELFDATA2LSB: byte_get = byte_get_little_endian; break;
9376 case ELFDATA2MSB: byte_get = byte_get_big_endian; break;
9379 /* For now we only support 32 bit and 64 bit ELF files. */
9380 is_32bit_elf = (elf_header.e_ident [EI_CLASS] != ELFCLASS64);
9382 /* Read in the rest of the header. */
9385 Elf32_External_Ehdr ehdr32;
9387 if (fread (ehdr32.e_type, sizeof (ehdr32) - EI_NIDENT, 1, file) != 1)
9390 elf_header.e_type = BYTE_GET (ehdr32.e_type);
9391 elf_header.e_machine = BYTE_GET (ehdr32.e_machine);
9392 elf_header.e_version = BYTE_GET (ehdr32.e_version);
9393 elf_header.e_entry = BYTE_GET (ehdr32.e_entry);
9394 elf_header.e_phoff = BYTE_GET (ehdr32.e_phoff);
9395 elf_header.e_shoff = BYTE_GET (ehdr32.e_shoff);
9396 elf_header.e_flags = BYTE_GET (ehdr32.e_flags);
9397 elf_header.e_ehsize = BYTE_GET (ehdr32.e_ehsize);
9398 elf_header.e_phentsize = BYTE_GET (ehdr32.e_phentsize);
9399 elf_header.e_phnum = BYTE_GET (ehdr32.e_phnum);
9400 elf_header.e_shentsize = BYTE_GET (ehdr32.e_shentsize);
9401 elf_header.e_shnum = BYTE_GET (ehdr32.e_shnum);
9402 elf_header.e_shstrndx = BYTE_GET (ehdr32.e_shstrndx);
9406 Elf64_External_Ehdr ehdr64;
9408 /* If we have been compiled with sizeof (bfd_vma) == 4, then
9409 we will not be able to cope with the 64bit data found in
9410 64 ELF files. Detect this now and abort before we start
9411 overwritting things. */
9412 if (sizeof (bfd_vma) < 8)
9414 error (_("This instance of readelf has been built without support for a\n\
9415 64 bit data type and so it cannot read 64 bit ELF files.\n"));
9419 if (fread (ehdr64.e_type, sizeof (ehdr64) - EI_NIDENT, 1, file) != 1)
9422 elf_header.e_type = BYTE_GET (ehdr64.e_type);
9423 elf_header.e_machine = BYTE_GET (ehdr64.e_machine);
9424 elf_header.e_version = BYTE_GET (ehdr64.e_version);
9425 elf_header.e_entry = BYTE_GET8 (ehdr64.e_entry);
9426 elf_header.e_phoff = BYTE_GET8 (ehdr64.e_phoff);
9427 elf_header.e_shoff = BYTE_GET8 (ehdr64.e_shoff);
9428 elf_header.e_flags = BYTE_GET (ehdr64.e_flags);
9429 elf_header.e_ehsize = BYTE_GET (ehdr64.e_ehsize);
9430 elf_header.e_phentsize = BYTE_GET (ehdr64.e_phentsize);
9431 elf_header.e_phnum = BYTE_GET (ehdr64.e_phnum);
9432 elf_header.e_shentsize = BYTE_GET (ehdr64.e_shentsize);
9433 elf_header.e_shnum = BYTE_GET (ehdr64.e_shnum);
9434 elf_header.e_shstrndx = BYTE_GET (ehdr64.e_shstrndx);
9437 /* There may be some extensions in the first section header. Don't
9438 bomb if we can't read it. */
9440 get_32bit_section_headers (file, 1);
9442 get_64bit_section_headers (file, 1);
9448 process_file (file_name)
9452 struct stat statbuf;
9455 if (stat (file_name, & statbuf) < 0)
9457 error (_("Cannot stat input file %s.\n"), file_name);
9461 file = fopen (file_name, "rb");
9464 error (_("Input file %s not found.\n"), file_name);
9468 if (! get_file_header (file))
9470 error (_("%s: Failed to read file header\n"), file_name);
9475 /* Initialise per file variables. */
9476 for (i = NUM_ELEM (version_info); i--;)
9477 version_info[i] = 0;
9479 for (i = NUM_ELEM (dynamic_info); i--;)
9480 dynamic_info[i] = 0;
9482 /* Process the file. */
9484 printf (_("\nFile: %s\n"), file_name);
9486 if (! process_file_header ())
9492 process_section_headers (file);
9494 process_program_headers (file);
9496 process_dynamic_segment (file);
9498 process_relocs (file);
9500 process_unwind (file);
9502 process_symbol_table (file);
9504 process_syminfo (file);
9506 process_version_sections (file);
9508 process_section_contents (file);
9510 process_corefile_contents (file);
9512 process_arch_specific (file);
9516 if (section_headers)
9518 free (section_headers);
9519 section_headers = NULL;
9524 free (string_table);
9525 string_table = NULL;
9526 string_table_length = 0;
9529 if (dynamic_strings)
9531 free (dynamic_strings);
9532 dynamic_strings = NULL;
9535 if (dynamic_symbols)
9537 free (dynamic_symbols);
9538 dynamic_symbols = NULL;
9539 num_dynamic_syms = 0;
9542 if (dynamic_syminfo)
9544 free (dynamic_syminfo);
9545 dynamic_syminfo = NULL;
9551 #ifdef SUPPORT_DISASSEMBLY
9552 /* Needed by the i386 disassembler. For extra credit, someone could
9553 fix this so that we insert symbolic addresses here, esp for GOT/PLT
9557 print_address (unsigned int addr, FILE * outfile)
9559 fprintf (outfile,"0x%8.8x", addr);
9562 /* Needed by the i386 disassembler. */
9564 db_task_printsym (unsigned int addr)
9566 print_address (addr, stderr);
9570 int main PARAMS ((int, char **));
9579 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
9580 setlocale (LC_MESSAGES, "");
9582 #if defined (HAVE_SETLOCALE)
9583 setlocale (LC_CTYPE, "");
9585 bindtextdomain (PACKAGE, LOCALEDIR);
9586 textdomain (PACKAGE);
9588 parse_args (argc, argv);
9590 if (optind < (argc - 1))
9594 while (optind < argc)
9595 err |= process_file (argv [optind ++]);
9597 if (dump_sects != NULL)