1 /* readelf.c -- display contents of an ELF format file
2 Copyright 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
4 Originally developed by Eric Youngdale <eric@andante.jic.com>
5 Modifications by Nick Clifton <nickc@cygnus.com>
7 This file is part of GNU Binutils.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26 #include <sys/types.h>
32 /* Define BFD64 here, even if our default architecture is 32 bit ELF
33 as this will allow us to read in and parse 64bit and 32bit ELF files.
34 Only do this if we belive that the compiler can support a 64 bit
35 data type. For now we only rely on GCC being able to do this. */
41 #include "elf/common.h"
42 #include "elf/external.h"
43 #include "elf/internal.h"
44 #include "elf/dwarf2.h"
46 /* The following headers use the elf/reloc-macros.h file to
47 automatically generate relocation recognition functions
48 such as elf_mips_reloc_type() */
50 #define RELOC_MACROS_GEN_FUNC
56 #include "elf/alpha.h"
59 #include "elf/sparc.h"
64 #include "elf/mn10200.h"
65 #include "elf/mn10300.h"
69 #include "elf/mcore.h"
76 #include "elf/x86-64.h"
82 char * program_name = "readelf";
83 unsigned int dynamic_addr;
84 bfd_size_type dynamic_size;
85 unsigned int rela_addr;
86 unsigned int rela_size;
87 char * dynamic_strings;
89 unsigned long string_table_length;
90 unsigned long num_dynamic_syms;
91 Elf_Internal_Sym * dynamic_symbols;
92 Elf_Internal_Syminfo * dynamic_syminfo;
93 unsigned long dynamic_syminfo_offset;
94 unsigned int dynamic_syminfo_nent;
95 char program_interpreter [64];
96 int dynamic_info[DT_JMPREL + 1];
99 Elf_Internal_Ehdr elf_header;
100 Elf_Internal_Shdr * section_headers;
101 Elf_Internal_Dyn * dynamic_segment;
109 int do_using_dynamic;
116 int do_debug_abbrevs;
118 int do_debug_pubnames;
119 int do_debug_aranges;
121 int do_debug_frames_interp;
126 /* A dynamic array of flags indicating which sections require dumping. */
127 char * dump_sects = NULL;
128 unsigned int num_dump_sects = 0;
130 #define HEX_DUMP (1 << 0)
131 #define DISASS_DUMP (1 << 1)
132 #define DEBUG_DUMP (1 << 2)
134 /* How to rpint a vma value. */
135 typedef enum print_mode
147 /* Forward declarations for dumb compilers. */
148 static void print_vma PARAMS ((bfd_vma, print_mode));
149 static bfd_vma (* byte_get) PARAMS ((unsigned char *, int));
150 static bfd_vma byte_get_little_endian PARAMS ((unsigned char *, int));
151 static bfd_vma byte_get_big_endian PARAMS ((unsigned char *, int));
152 static const char * get_mips_dynamic_type PARAMS ((unsigned long));
153 static const char * get_sparc64_dynamic_type PARAMS ((unsigned long));
154 static const char * get_parisc_dynamic_type PARAMS ((unsigned long));
155 static const char * get_dynamic_type PARAMS ((unsigned long));
156 static int slurp_rela_relocs PARAMS ((FILE *, unsigned long, unsigned long, Elf_Internal_Rela **, unsigned long *));
157 static int slurp_rel_relocs PARAMS ((FILE *, unsigned long, unsigned long, Elf_Internal_Rel **, unsigned long *));
158 static int dump_relocations PARAMS ((FILE *, unsigned long, unsigned long, Elf_Internal_Sym *, unsigned long, char *, int));
159 static char * get_file_type PARAMS ((unsigned));
160 static char * get_machine_name PARAMS ((unsigned));
161 static void decode_ARM_machine_flags PARAMS ((unsigned, char []));
162 static char * get_machine_flags PARAMS ((unsigned, unsigned));
163 static const char * get_mips_segment_type PARAMS ((unsigned long));
164 static const char * get_parisc_segment_type PARAMS ((unsigned long));
165 static const char * get_ia64_segment_type PARAMS ((unsigned long));
166 static const char * get_segment_type PARAMS ((unsigned long));
167 static const char * get_mips_section_type_name PARAMS ((unsigned int));
168 static const char * get_parisc_section_type_name PARAMS ((unsigned int));
169 static const char * get_ia64_section_type_name PARAMS ((unsigned int));
170 static const char * get_section_type_name PARAMS ((unsigned int));
171 static const char * get_symbol_binding PARAMS ((unsigned int));
172 static const char * get_symbol_type PARAMS ((unsigned int));
173 static const char * get_symbol_visibility PARAMS ((unsigned int));
174 static const char * get_symbol_index_type PARAMS ((unsigned int));
175 static const char * get_dynamic_flags PARAMS ((bfd_vma));
176 static void usage PARAMS ((void));
177 static void parse_args PARAMS ((int, char **));
178 static int process_file_header PARAMS ((void));
179 static int process_program_headers PARAMS ((FILE *));
180 static int process_section_headers PARAMS ((FILE *));
181 static int process_unwind PARAMS ((FILE *));
182 static void dynamic_segment_mips_val PARAMS ((Elf_Internal_Dyn *));
183 static void dynamic_segment_parisc_val PARAMS ((Elf_Internal_Dyn *));
184 static int process_dynamic_segment PARAMS ((FILE *));
185 static int process_symbol_table PARAMS ((FILE *));
186 static int process_section_contents PARAMS ((FILE *));
187 static void process_file PARAMS ((char *));
188 static int process_relocs PARAMS ((FILE *));
189 static int process_version_sections PARAMS ((FILE *));
190 static char * get_ver_flags PARAMS ((unsigned int));
191 static int get_32bit_section_headers PARAMS ((FILE *));
192 static int get_64bit_section_headers PARAMS ((FILE *));
193 static int get_32bit_program_headers PARAMS ((FILE *, Elf_Internal_Phdr *));
194 static int get_64bit_program_headers PARAMS ((FILE *, Elf_Internal_Phdr *));
195 static int get_file_header PARAMS ((FILE *));
196 static Elf_Internal_Sym * get_32bit_elf_symbols PARAMS ((FILE *, unsigned long, unsigned long));
197 static Elf_Internal_Sym * get_64bit_elf_symbols PARAMS ((FILE *, unsigned long, unsigned long));
198 static const char * get_elf_section_flags PARAMS ((bfd_vma));
199 static int * get_dynamic_data PARAMS ((FILE *, unsigned int));
200 static int get_32bit_dynamic_segment PARAMS ((FILE *));
201 static int get_64bit_dynamic_segment PARAMS ((FILE *));
202 #ifdef SUPPORT_DISASSEMBLY
203 static int disassemble_section PARAMS ((Elf32_Internal_Shdr *, FILE *));
205 static int dump_section PARAMS ((Elf32_Internal_Shdr *, FILE *));
206 static int display_debug_section PARAMS ((Elf32_Internal_Shdr *, FILE *));
207 static int display_debug_info PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
208 static int display_debug_not_supported PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
209 static int display_debug_lines PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
210 static int display_debug_abbrev PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
211 static int display_debug_aranges PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
212 static int display_debug_frames PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
213 static unsigned char * process_abbrev_section PARAMS ((unsigned char *, unsigned char *));
214 static unsigned long read_leb128 PARAMS ((unsigned char *, int *, int));
215 static int process_extended_line_op PARAMS ((unsigned char *, int, int));
216 static void reset_state_machine PARAMS ((int));
217 static char * get_TAG_name PARAMS ((unsigned long));
218 static char * get_AT_name PARAMS ((unsigned long));
219 static char * get_FORM_name PARAMS ((unsigned long));
220 static void free_abbrevs PARAMS ((void));
221 static void add_abbrev PARAMS ((unsigned long, unsigned long, int));
222 static void add_abbrev_attr PARAMS ((unsigned long, unsigned long));
223 static unsigned char * read_and_display_attr PARAMS ((unsigned long, unsigned long, unsigned char *, unsigned long, unsigned long));
224 static unsigned char * display_block PARAMS ((unsigned char *, unsigned long));
225 static void decode_location_expression PARAMS ((unsigned char *, unsigned int, unsigned long));
226 static void request_dump PARAMS ((unsigned int, char));
227 static const char * get_elf_class PARAMS ((unsigned char));
228 static const char * get_data_encoding PARAMS ((unsigned char));
229 static const char * get_osabi_name PARAMS ((unsigned char));
230 static int guess_is_rela PARAMS ((unsigned long));
231 static char * get_note_type PARAMS ((unsigned int));
232 static int process_note PARAMS ((Elf32_Internal_Note *));
233 static int process_corefile_note_segment PARAMS ((FILE *, bfd_vma, bfd_vma));
234 static int process_corefile_note_segments PARAMS ((FILE *));
235 static int process_corefile_contents PARAMS ((FILE *));
237 typedef int Elf32_Word;
245 #define SECTION_NAME(X) ((X) == NULL ? "<none>" : \
246 ((X)->sh_name >= string_table_length \
247 ? "<corrupt>" : string_table + (X)->sh_name))
249 #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
251 #define BYTE_GET(field) byte_get (field, sizeof (field))
253 /* If we can support a 64 bit data type then BFD64 should be defined
254 and sizeof (bfd_vma) == 8. In this case when translating from an
255 external 8 byte field to an internal field, we can assume that the
256 internal field is also 8 bytes wide and so we can extract all the data.
257 If, however, BFD64 is not defined, then we must assume that the
258 internal data structure only has 4 byte wide fields that are the
259 equivalent of the 8 byte wide external counterparts, and so we must
260 truncate the data. */
262 #define BYTE_GET8(field) byte_get (field, -8)
264 #define BYTE_GET8(field) byte_get (field, 8)
267 #define NUM_ELEM(array) (sizeof (array) / sizeof ((array)[0]))
269 #define GET_ELF_SYMBOLS(file, offset, size) \
270 (is_32bit_elf ? get_32bit_elf_symbols (file, offset, size) \
271 : get_64bit_elf_symbols (file, offset, size))
274 #ifdef ANSI_PROTOTYPES
276 error (const char * message, ...)
280 fprintf (stderr, _("%s: Error: "), program_name);
281 va_start (args, message);
282 vfprintf (stderr, message, args);
288 warn (const char * message, ...)
292 fprintf (stderr, _("%s: Warning: "), program_name);
293 va_start (args, message);
294 vfprintf (stderr, message, args);
306 fprintf (stderr, _("%s: Error: "), program_name);
308 message = va_arg (args, char *);
309 vfprintf (stderr, message, args);
321 fprintf (stderr, _("%s: Warning: "), program_name);
323 message = va_arg (args, char *);
324 vfprintf (stderr, message, args);
330 static PTR get_data PARAMS ((PTR, FILE *, long, size_t, const char *));
333 get_data (var, file, offset, size, reason)
345 if (fseek (file, offset, SEEK_SET))
347 error (_("Unable to seek to %x for %s\n"), offset, reason);
354 mvar = (PTR) malloc (size);
358 error (_("Out of memory allocating %d bytes for %s\n"),
364 if (fread (mvar, size, 1, file) != 1)
366 error (_("Unable to read in %d bytes of %s\n"), size, reason);
376 byte_get_little_endian (field, size)
377 unsigned char * field;
386 return ((unsigned int) (field [0]))
387 | (((unsigned int) (field [1])) << 8);
391 /* We want to extract data from an 8 byte wide field and
392 place it into a 4 byte wide field. Since this is a little
393 endian source we can juts use the 4 byte extraction code. */
397 return ((unsigned long) (field [0]))
398 | (((unsigned long) (field [1])) << 8)
399 | (((unsigned long) (field [2])) << 16)
400 | (((unsigned long) (field [3])) << 24);
405 /* This is a special case, generated by the BYTE_GET8 macro.
406 It means that we are loading an 8 byte value from a field
407 in an external structure into an 8 byte value in a field
408 in an internal strcuture. */
409 return ((bfd_vma) (field [0]))
410 | (((bfd_vma) (field [1])) << 8)
411 | (((bfd_vma) (field [2])) << 16)
412 | (((bfd_vma) (field [3])) << 24)
413 | (((bfd_vma) (field [4])) << 32)
414 | (((bfd_vma) (field [5])) << 40)
415 | (((bfd_vma) (field [6])) << 48)
416 | (((bfd_vma) (field [7])) << 56);
419 error (_("Unhandled data length: %d\n"), size);
424 /* Print a VMA value. */
426 print_vma (vma, mode)
436 case FULL_HEX: printf ("0x"); /* drop through */
437 case LONG_HEX: printf ("%8.8lx", (unsigned long) vma); break;
438 case PREFIX_HEX: printf ("0x"); /* drop through */
439 case HEX: printf ("%lx", (unsigned long) vma); break;
440 case DEC: printf ("%ld", (unsigned long) vma); break;
441 case DEC_5: printf ("%5ld", (long) vma); break;
442 case UNSIGNED: printf ("%lu", (unsigned long) vma); break;
463 #if BFD_HOST_64BIT_LONG
466 if (_bfd_int64_high (vma))
467 printf ("%lx%lx", _bfd_int64_high (vma), _bfd_int64_low (vma));
469 printf ("%lx", _bfd_int64_low (vma));
474 #if BFD_HOST_64BIT_LONG
477 if (_bfd_int64_high (vma))
479 printf ("++%ld", _bfd_int64_low (vma));
481 printf ("%ld", _bfd_int64_low (vma));
486 #if BFD_HOST_64BIT_LONG
487 printf ("%5ld", vma);
489 if (_bfd_int64_high (vma))
491 printf ("++%ld", _bfd_int64_low (vma));
493 printf ("%5ld", _bfd_int64_low (vma));
498 #if BFD_HOST_64BIT_LONG
501 if (_bfd_int64_high (vma))
503 printf ("++%lu", _bfd_int64_low (vma));
505 printf ("%lu", _bfd_int64_low (vma));
514 byte_get_big_endian (field, size)
515 unsigned char * field;
524 return ((unsigned int) (field [1])) | (((int) (field [0])) << 8);
527 return ((unsigned long) (field [3]))
528 | (((unsigned long) (field [2])) << 8)
529 | (((unsigned long) (field [1])) << 16)
530 | (((unsigned long) (field [0])) << 24);
534 /* Although we are extracing data from an 8 byte wide field, we
535 are returning only 4 bytes of data. */
536 return ((unsigned long) (field [7]))
537 | (((unsigned long) (field [6])) << 8)
538 | (((unsigned long) (field [5])) << 16)
539 | (((unsigned long) (field [4])) << 24);
543 /* This is a special case, generated by the BYTE_GET8 macro.
544 It means that we are loading an 8 byte value from a field
545 in an external structure into an 8 byte value in a field
546 in an internal strcuture. */
547 return ((bfd_vma) (field [7]))
548 | (((bfd_vma) (field [6])) << 8)
549 | (((bfd_vma) (field [5])) << 16)
550 | (((bfd_vma) (field [4])) << 24)
551 | (((bfd_vma) (field [3])) << 32)
552 | (((bfd_vma) (field [2])) << 40)
553 | (((bfd_vma) (field [1])) << 48)
554 | (((bfd_vma) (field [0])) << 56);
558 error (_("Unhandled data length: %d\n"), size);
563 /* Guess the relocation size commonly used by the specific machines. */
566 guess_is_rela (e_machine)
567 unsigned long e_machine;
571 /* Targets that use REL relocations. */
582 /* Targets that use RELA relocations. */
590 case EM_CYGNUS_MN10200:
591 case EM_CYGNUS_MN10300:
624 warn (_("Don't know about relocations on this machine architecture\n"));
630 slurp_rela_relocs (file, rel_offset, rel_size, relasp, nrelasp)
632 unsigned long rel_offset;
633 unsigned long rel_size;
634 Elf_Internal_Rela **relasp;
635 unsigned long *nrelasp;
637 Elf_Internal_Rela *relas;
638 unsigned long nrelas;
643 Elf32_External_Rela * erelas;
645 erelas = (Elf32_External_Rela *) get_data (NULL, file, rel_offset,
646 rel_size, _("relocs"));
650 nrelas = rel_size / sizeof (Elf32_External_Rela);
652 relas = (Elf_Internal_Rela *)
653 malloc (nrelas * sizeof (Elf_Internal_Rela));
657 error(_("out of memory parsing relocs"));
661 for (i = 0; i < nrelas; i++)
663 relas[i].r_offset = BYTE_GET (erelas[i].r_offset);
664 relas[i].r_info = BYTE_GET (erelas[i].r_info);
665 relas[i].r_addend = BYTE_GET (erelas[i].r_addend);
672 Elf64_External_Rela * erelas;
674 erelas = (Elf64_External_Rela *) get_data (NULL, file, rel_offset,
675 rel_size, _("relocs"));
679 nrelas = rel_size / sizeof (Elf64_External_Rela);
681 relas = (Elf_Internal_Rela *)
682 malloc (nrelas * sizeof (Elf_Internal_Rela));
686 error(_("out of memory parsing relocs"));
690 for (i = 0; i < nrelas; i++)
692 relas[i].r_offset = BYTE_GET8 (erelas[i].r_offset);
693 relas[i].r_info = BYTE_GET8 (erelas[i].r_info);
694 relas[i].r_addend = BYTE_GET8 (erelas[i].r_addend);
705 slurp_rel_relocs (file, rel_offset, rel_size, relsp, nrelsp)
707 unsigned long rel_offset;
708 unsigned long rel_size;
709 Elf_Internal_Rel **relsp;
710 unsigned long *nrelsp;
712 Elf_Internal_Rel *rels;
718 Elf32_External_Rel * erels;
720 erels = (Elf32_External_Rel *) get_data (NULL, file, rel_offset,
721 rel_size, _("relocs"));
725 nrels = rel_size / sizeof (Elf32_External_Rel);
727 rels = (Elf_Internal_Rel *) malloc (nrels * sizeof (Elf_Internal_Rel));
731 error(_("out of memory parsing relocs"));
735 for (i = 0; i < nrels; i++)
737 rels[i].r_offset = BYTE_GET (erels[i].r_offset);
738 rels[i].r_info = BYTE_GET (erels[i].r_info);
745 Elf64_External_Rel * erels;
747 erels = (Elf64_External_Rel *) get_data (NULL, file, rel_offset,
748 rel_size, _("relocs"));
752 nrels = rel_size / sizeof (Elf64_External_Rel);
754 rels = (Elf_Internal_Rel *) malloc (nrels * sizeof (Elf_Internal_Rel));
758 error(_("out of memory parsing relocs"));
762 for (i = 0; i < nrels; i++)
764 rels[i].r_offset = BYTE_GET8 (erels[i].r_offset);
765 rels[i].r_info = BYTE_GET8 (erels[i].r_info);
775 /* Display the contents of the relocation data found at the specified offset. */
777 dump_relocations (file, rel_offset, rel_size, symtab, nsyms, strtab, is_rela)
779 unsigned long rel_offset;
780 unsigned long rel_size;
781 Elf_Internal_Sym * symtab;
787 Elf_Internal_Rel * rels;
788 Elf_Internal_Rela * relas;
791 if (is_rela == UNKNOWN)
792 is_rela = guess_is_rela (elf_header.e_machine);
796 if (!slurp_rela_relocs (file, rel_offset, rel_size, &relas, &rel_size))
801 if (!slurp_rel_relocs (file, rel_offset, rel_size, &rels, &rel_size))
807 (_(" Offset Info Type Symbol's Value Symbol's Name Addend\n"));
810 (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
812 for (i = 0; i < rel_size; i++)
817 bfd_vma symtab_index;
822 offset = relas [i].r_offset;
823 info = relas [i].r_info;
827 offset = rels [i].r_offset;
828 info = rels [i].r_info;
833 type = ELF32_R_TYPE (info);
834 symtab_index = ELF32_R_SYM (info);
838 if (elf_header.e_machine == EM_SPARCV9)
839 type = ELF64_R_TYPE_ID (info);
841 type = ELF64_R_TYPE (info);
842 /* The #ifdef BFD64 below is to prevent a compile time warning.
843 We know that if we do not have a 64 bit data type that we
844 will never execute this code anyway. */
846 symtab_index = ELF64_R_SYM (info);
850 #ifdef _bfd_int64_low
851 printf (" %8.8lx %5.5lx ", _bfd_int64_low (offset), _bfd_int64_low (info));
853 printf (" %8.8lx %5.5lx ", offset, info);
856 switch (elf_header.e_machine)
863 rtype = elf_m32r_reloc_type (type);
868 rtype = elf_i386_reloc_type (type);
872 rtype = elf_m68k_reloc_type (type);
876 rtype = elf_i960_reloc_type (type);
880 rtype = elf_avr_reloc_type (type);
887 rtype = elf_sparc_reloc_type (type);
891 rtype = v850_reloc_type (type);
895 rtype = elf_d10v_reloc_type (type);
899 rtype = elf_d30v_reloc_type (type);
903 rtype = elf_sh_reloc_type (type);
906 case EM_CYGNUS_MN10300:
907 rtype = elf_mn10300_reloc_type (type);
910 case EM_CYGNUS_MN10200:
911 rtype = elf_mn10200_reloc_type (type);
915 rtype = elf_fr30_reloc_type (type);
919 rtype = elf_mcore_reloc_type (type);
923 rtype = elf_ppc_reloc_type (type);
928 rtype = elf_mips_reloc_type (type);
932 rtype = elf_alpha_reloc_type (type);
936 rtype = elf_arm_reloc_type (type);
941 rtype = elf_arc_reloc_type (type);
945 rtype = elf_hppa_reloc_type (type);
949 rtype = elf_pj_reloc_type (type);
952 rtype = elf_ia64_reloc_type (type);
956 rtype = elf_cris_reloc_type (type);
960 rtype = elf_i860_reloc_type (type);
964 rtype = elf_x86_64_reloc_type (type);
969 rtype = elf_s390_reloc_type (type);
974 #ifdef _bfd_int64_low
975 printf (_("unrecognised: %-7lx"), _bfd_int64_low (type));
977 printf (_("unrecognised: %-7lx"), type);
980 printf ("%-21.21s", rtype);
984 if (symtab == NULL || symtab_index >= nsyms)
985 printf (" bad symbol index: %08lx", (unsigned long) symtab_index);
988 Elf_Internal_Sym * psym;
990 psym = symtab + symtab_index;
993 print_vma (psym->st_value, LONG_HEX);
996 if (psym->st_name == 0)
998 SECTION_NAME (section_headers + psym->st_shndx));
999 else if (strtab == NULL)
1000 printf (_("<string table index %3ld>"), psym->st_name);
1002 printf ("%-25.25s", strtab + psym->st_name);
1005 printf (" + %lx", (unsigned long) relas [i].r_addend);
1010 printf ("%*c", is_32bit_elf ? 34 : 26, ' ');
1011 print_vma (relas[i].r_addend, LONG_HEX);
1014 if (elf_header.e_machine == EM_SPARCV9
1015 && !strcmp (rtype, "R_SPARC_OLO10"))
1016 printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (info));
1030 get_mips_dynamic_type (type)
1035 case DT_MIPS_RLD_VERSION: return "MIPS_RLD_VERSION";
1036 case DT_MIPS_TIME_STAMP: return "MIPS_TIME_STAMP";
1037 case DT_MIPS_ICHECKSUM: return "MIPS_ICHECKSUM";
1038 case DT_MIPS_IVERSION: return "MIPS_IVERSION";
1039 case DT_MIPS_FLAGS: return "MIPS_FLAGS";
1040 case DT_MIPS_BASE_ADDRESS: return "MIPS_BASE_ADDRESS";
1041 case DT_MIPS_MSYM: return "MIPS_MSYM";
1042 case DT_MIPS_CONFLICT: return "MIPS_CONFLICT";
1043 case DT_MIPS_LIBLIST: return "MIPS_LIBLIST";
1044 case DT_MIPS_LOCAL_GOTNO: return "MIPS_LOCAL_GOTNO";
1045 case DT_MIPS_CONFLICTNO: return "MIPS_CONFLICTNO";
1046 case DT_MIPS_LIBLISTNO: return "MIPS_LIBLISTNO";
1047 case DT_MIPS_SYMTABNO: return "MIPS_SYMTABNO";
1048 case DT_MIPS_UNREFEXTNO: return "MIPS_UNREFEXTNO";
1049 case DT_MIPS_GOTSYM: return "MIPS_GOTSYM";
1050 case DT_MIPS_HIPAGENO: return "MIPS_HIPAGENO";
1051 case DT_MIPS_RLD_MAP: return "MIPS_RLD_MAP";
1052 case DT_MIPS_DELTA_CLASS: return "MIPS_DELTA_CLASS";
1053 case DT_MIPS_DELTA_CLASS_NO: return "MIPS_DELTA_CLASS_NO";
1054 case DT_MIPS_DELTA_INSTANCE: return "MIPS_DELTA_INSTANCE";
1055 case DT_MIPS_DELTA_INSTANCE_NO: return "MIPS_DELTA_INSTANCE_NO";
1056 case DT_MIPS_DELTA_RELOC: return "MIPS_DELTA_RELOC";
1057 case DT_MIPS_DELTA_RELOC_NO: return "MIPS_DELTA_RELOC_NO";
1058 case DT_MIPS_DELTA_SYM: return "MIPS_DELTA_SYM";
1059 case DT_MIPS_DELTA_SYM_NO: return "MIPS_DELTA_SYM_NO";
1060 case DT_MIPS_DELTA_CLASSSYM: return "MIPS_DELTA_CLASSSYM";
1061 case DT_MIPS_DELTA_CLASSSYM_NO: return "MIPS_DELTA_CLASSSYM_NO";
1062 case DT_MIPS_CXX_FLAGS: return "MIPS_CXX_FLAGS";
1063 case DT_MIPS_PIXIE_INIT: return "MIPS_PIXIE_INIT";
1064 case DT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB";
1065 case DT_MIPS_LOCALPAGE_GOTIDX: return "MIPS_LOCALPAGE_GOTIDX";
1066 case DT_MIPS_LOCAL_GOTIDX: return "MIPS_LOCAL_GOTIDX";
1067 case DT_MIPS_HIDDEN_GOTIDX: return "MIPS_HIDDEN_GOTIDX";
1068 case DT_MIPS_PROTECTED_GOTIDX: return "MIPS_PROTECTED_GOTIDX";
1069 case DT_MIPS_OPTIONS: return "MIPS_OPTIONS";
1070 case DT_MIPS_INTERFACE: return "MIPS_INTERFACE";
1071 case DT_MIPS_DYNSTR_ALIGN: return "MIPS_DYNSTR_ALIGN";
1072 case DT_MIPS_INTERFACE_SIZE: return "MIPS_INTERFACE_SIZE";
1073 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
1074 case DT_MIPS_PERF_SUFFIX: return "MIPS_PERF_SUFFIX";
1075 case DT_MIPS_COMPACT_SIZE: return "MIPS_COMPACT_SIZE";
1076 case DT_MIPS_GP_VALUE: return "MIPS_GP_VALUE";
1077 case DT_MIPS_AUX_DYNAMIC: return "MIPS_AUX_DYNAMIC";
1084 get_sparc64_dynamic_type (type)
1089 case DT_SPARC_REGISTER: return "SPARC_REGISTER";
1096 get_parisc_dynamic_type (type)
1101 case DT_HP_LOAD_MAP: return "HP_LOAD_MAP";
1102 case DT_HP_DLD_FLAGS: return "HP_DLD_FLAGS";
1103 case DT_HP_DLD_HOOK: return "HP_DLD_HOOK";
1104 case DT_HP_UX10_INIT: return "HP_UX10_INIT";
1105 case DT_HP_UX10_INITSZ: return "HP_UX10_INITSZ";
1106 case DT_HP_PREINIT: return "HP_PREINIT";
1107 case DT_HP_PREINITSZ: return "HP_PREINITSZ";
1108 case DT_HP_NEEDED: return "HP_NEEDED";
1109 case DT_HP_TIME_STAMP: return "HP_TIME_STAMP";
1110 case DT_HP_CHECKSUM: return "HP_CHECKSUM";
1111 case DT_HP_GST_SIZE: return "HP_GST_SIZE";
1112 case DT_HP_GST_VERSION: return "HP_GST_VERSION";
1113 case DT_HP_GST_HASHVAL: return "HP_GST_HASHVAL";
1120 get_dynamic_type (type)
1123 static char buff [32];
1127 case DT_NULL: return "NULL";
1128 case DT_NEEDED: return "NEEDED";
1129 case DT_PLTRELSZ: return "PLTRELSZ";
1130 case DT_PLTGOT: return "PLTGOT";
1131 case DT_HASH: return "HASH";
1132 case DT_STRTAB: return "STRTAB";
1133 case DT_SYMTAB: return "SYMTAB";
1134 case DT_RELA: return "RELA";
1135 case DT_RELASZ: return "RELASZ";
1136 case DT_RELAENT: return "RELAENT";
1137 case DT_STRSZ: return "STRSZ";
1138 case DT_SYMENT: return "SYMENT";
1139 case DT_INIT: return "INIT";
1140 case DT_FINI: return "FINI";
1141 case DT_SONAME: return "SONAME";
1142 case DT_RPATH: return "RPATH";
1143 case DT_SYMBOLIC: return "SYMBOLIC";
1144 case DT_REL: return "REL";
1145 case DT_RELSZ: return "RELSZ";
1146 case DT_RELENT: return "RELENT";
1147 case DT_PLTREL: return "PLTREL";
1148 case DT_DEBUG: return "DEBUG";
1149 case DT_TEXTREL: return "TEXTREL";
1150 case DT_JMPREL: return "JMPREL";
1151 case DT_BIND_NOW: return "BIND_NOW";
1152 case DT_INIT_ARRAY: return "INIT_ARRAY";
1153 case DT_FINI_ARRAY: return "FINI_ARRAY";
1154 case DT_INIT_ARRAYSZ: return "INIT_ARRAYSZ";
1155 case DT_FINI_ARRAYSZ: return "FINI_ARRAYSZ";
1156 case DT_RUNPATH: return "RUNPATH";
1157 case DT_FLAGS: return "FLAGS";
1159 case DT_PREINIT_ARRAY: return "PREINIT_ARRAY";
1160 case DT_PREINIT_ARRAYSZ: return "PREINIT_ARRAYSZ";
1162 case DT_CHECKSUM: return "CHECKSUM";
1163 case DT_PLTPADSZ: return "PLTPADSZ";
1164 case DT_MOVEENT: return "MOVEENT";
1165 case DT_MOVESZ: return "MOVESZ";
1166 case DT_FEATURE: return "FEATURE";
1167 case DT_POSFLAG_1: return "POSFLAG_1";
1168 case DT_SYMINSZ: return "SYMINSZ";
1169 case DT_SYMINENT: return "SYMINENT"; /* aka VALRNGHI */
1171 case DT_ADDRRNGLO: return "ADDRRNGLO";
1172 case DT_CONFIG: return "CONFIG";
1173 case DT_DEPAUDIT: return "DEPAUDIT";
1174 case DT_AUDIT: return "AUDIT";
1175 case DT_PLTPAD: return "PLTPAD";
1176 case DT_MOVETAB: return "MOVETAB";
1177 case DT_SYMINFO: return "SYMINFO"; /* aka ADDRRNGHI */
1179 case DT_VERSYM: return "VERSYM";
1181 case DT_RELACOUNT: return "RELACOUNT";
1182 case DT_RELCOUNT: return "RELCOUNT";
1183 case DT_FLAGS_1: return "FLAGS_1";
1184 case DT_VERDEF: return "VERDEF";
1185 case DT_VERDEFNUM: return "VERDEFNUM";
1186 case DT_VERNEED: return "VERNEED";
1187 case DT_VERNEEDNUM: return "VERNEEDNUM";
1189 case DT_AUXILIARY: return "AUXILIARY";
1190 case DT_USED: return "USED";
1191 case DT_FILTER: return "FILTER";
1194 if ((type >= DT_LOPROC) && (type <= DT_HIPROC))
1196 const char * result;
1198 switch (elf_header.e_machine)
1201 case EM_MIPS_RS3_LE:
1202 result = get_mips_dynamic_type (type);
1205 result = get_sparc64_dynamic_type (type);
1215 sprintf (buff, _("Processor Specific: %lx"), type);
1217 else if ((type >= DT_LOOS) && (type <= DT_HIOS))
1219 const char * result;
1221 switch (elf_header.e_machine)
1224 result = get_parisc_dynamic_type (type);
1234 sprintf (buff, _("Operating System specific: %lx"), type);
1237 sprintf (buff, _("<unknown>: %lx"), type);
1244 get_file_type (e_type)
1247 static char buff [32];
1251 case ET_NONE: return _("NONE (None)");
1252 case ET_REL: return _("REL (Relocatable file)");
1253 case ET_EXEC: return _("EXEC (Executable file)");
1254 case ET_DYN: return _("DYN (Shared object file)");
1255 case ET_CORE: return _("CORE (Core file)");
1258 if ((e_type >= ET_LOPROC) && (e_type <= ET_HIPROC))
1259 sprintf (buff, _("Processor Specific: (%x)"), e_type);
1260 else if ((e_type >= ET_LOOS) && (e_type <= ET_HIOS))
1261 sprintf (buff, _("OS Specific: (%x)"), e_type);
1263 sprintf (buff, _("<unknown>: %x"), e_type);
1269 get_machine_name (e_machine)
1272 static char buff [64]; /* XXX */
1276 case EM_NONE: return _("None");
1277 case EM_M32: return "WE32100";
1278 case EM_SPARC: return "Sparc";
1279 case EM_386: return "Intel 80386";
1280 case EM_68K: return "MC68000";
1281 case EM_88K: return "MC88000";
1282 case EM_486: return "Intel 80486";
1283 case EM_860: return "Intel 80860";
1284 case EM_MIPS: return "MIPS R3000";
1285 case EM_S370: return "IBM System/370";
1286 case EM_MIPS_RS3_LE: return "MIPS R4000 big-endian";
1287 case EM_OLD_SPARCV9: return "Sparc v9 (old)";
1288 case EM_PARISC: return "HPPA";
1289 case EM_PPC_OLD: return "Power PC (old)";
1290 case EM_SPARC32PLUS: return "Sparc v8+" ;
1291 case EM_960: return "Intel 90860";
1292 case EM_PPC: return "PowerPC";
1293 case EM_V800: return "NEC V800";
1294 case EM_FR20: return "Fujitsu FR20";
1295 case EM_RH32: return "TRW RH32";
1296 case EM_MCORE: return "MCORE";
1297 case EM_ARM: return "ARM";
1298 case EM_OLD_ALPHA: return "Digital Alpha (old)";
1299 case EM_SH: return "Hitachi SH";
1300 case EM_SPARCV9: return "Sparc v9";
1301 case EM_TRICORE: return "Siemens Tricore";
1302 case EM_ARC: return "ARC";
1303 case EM_H8_300: return "Hitachi H8/300";
1304 case EM_H8_300H: return "Hitachi H8/300H";
1305 case EM_H8S: return "Hitachi H8S";
1306 case EM_H8_500: return "Hitachi H8/500";
1307 case EM_IA_64: return "Intel IA-64";
1308 case EM_MIPS_X: return "Stanford MIPS-X";
1309 case EM_COLDFIRE: return "Motorola Coldfire";
1310 case EM_68HC12: return "Motorola M68HC12";
1311 case EM_ALPHA: return "Alpha";
1312 case EM_CYGNUS_D10V: return "d10v";
1313 case EM_CYGNUS_D30V: return "d30v";
1314 case EM_CYGNUS_ARC: return "ARC";
1315 case EM_CYGNUS_M32R: return "Mitsubishi M32r";
1316 case EM_CYGNUS_V850: return "NEC v850";
1317 case EM_CYGNUS_MN10300: return "mn10300";
1318 case EM_CYGNUS_MN10200: return "mn10200";
1319 case EM_CYGNUS_FR30: return "Fujitsu FR30";
1320 case EM_PJ: return "picoJava";
1321 case EM_MMA: return "Fujitsu Multimedia Accelerator";
1322 case EM_PCP: return "Siemens PCP";
1323 case EM_NCPU: return "Sony nCPU embedded RISC processor";
1324 case EM_NDR1: return "Denso NDR1 microprocesspr";
1325 case EM_STARCORE: return "Motorola Star*Core processor";
1326 case EM_ME16: return "Toyota ME16 processor";
1327 case EM_ST100: return "STMicroelectronics ST100 processor";
1328 case EM_TINYJ: return "Advanced Logic Corp. TinyJ embedded processor";
1329 case EM_FX66: return "Siemens FX66 microcontroller";
1330 case EM_ST9PLUS: return "STMicroelectronics ST9+ 8/16 bit microcontroller";
1331 case EM_ST7: return "STMicroelectronics ST7 8-bit microcontroller";
1332 case EM_68HC16: return "Motorola MC68HC16 Microcontroller";
1333 case EM_68HC11: return "Motorola MC68HC11 Microcontroller";
1334 case EM_68HC08: return "Motorola MC68HC08 Microcontroller";
1335 case EM_68HC05: return "Motorola MC68HC05 Microcontroller";
1336 case EM_SVX: return "Silicon Graphics SVx";
1337 case EM_ST19: return "STMicroelectronics ST19 8-bit microcontroller";
1338 case EM_VAX: return "Digital VAX";
1339 case EM_AVR: return "Atmel AVR 8-bit microcontroller";
1340 case EM_CRIS: return "Axis Communications 32-bit embedded processor";
1341 case EM_JAVELIN: return "Infineon Technologies 32-bit embedded cpu";
1342 case EM_FIREPATH: return "Element 14 64-bit DSP processor";
1343 case EM_ZSP: return "LSI Logic's 16-bit DSP processor";
1344 case EM_MMIX: return "Donald Knuth's educational 64-bit processor";
1345 case EM_HUANY: return "Harvard Universitys's machine-independent object format";
1346 case EM_PRISM: return "SiTera Prism";
1347 case EM_X86_64: return "Advanced Micro Devices X86-64";
1349 case EM_S390: return "IBM S/390";
1351 sprintf (buff, _("<unknown>: %x"), e_machine);
1357 decode_ARM_machine_flags (e_flags, buf)
1364 eabi = EF_ARM_EABI_VERSION (e_flags);
1365 e_flags &= ~ EF_ARM_EABIMASK;
1367 /* Handle "generic" ARM flags. */
1368 if (e_flags & EF_ARM_RELEXEC)
1370 strcat (buf, ", relocatable executable");
1371 e_flags &= ~ EF_ARM_RELEXEC;
1374 if (e_flags & EF_ARM_HASENTRY)
1376 strcat (buf, ", has entry point");
1377 e_flags &= ~ EF_ARM_HASENTRY;
1380 /* Now handle EABI specific flags. */
1384 strcat (buf, ", <unrecognised EABI>");
1389 case EF_ARM_EABI_VER1:
1390 strcat (buf, ", Version1 EABI");
1395 /* Process flags one bit at a time. */
1396 flag = e_flags & - e_flags;
1401 case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK. */
1402 strcat (buf, ", sorted symbol tables");
1412 case EF_ARM_EABI_VER2:
1413 strcat (buf, ", Version2 EABI");
1418 /* Process flags one bit at a time. */
1419 flag = e_flags & - e_flags;
1424 case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK. */
1425 strcat (buf, ", sorted symbol tables");
1428 case EF_ARM_DYNSYMSUSESEGIDX:
1429 strcat (buf, ", dynamic symbols use segment index");
1432 case EF_ARM_MAPSYMSFIRST:
1433 strcat (buf, ", mapping symbols precede others");
1443 case EF_ARM_EABI_UNKNOWN:
1444 strcat (buf, ", GNU EABI");
1449 /* Process flags one bit at a time. */
1450 flag = e_flags & - e_flags;
1455 case EF_ARM_INTERWORK:
1456 strcat (buf, ", interworking enabled");
1459 case EF_ARM_APCS_26:
1460 strcat (buf, ", uses APCS/26");
1463 case EF_ARM_APCS_FLOAT:
1464 strcat (buf, ", uses APCS/float");
1468 strcat (buf, ", position independent");
1472 strcat (buf, ", 8 bit structure alignment");
1475 case EF_ARM_NEW_ABI:
1476 strcat (buf, ", uses new ABI");
1479 case EF_ARM_OLD_ABI:
1480 strcat (buf, ", uses old ABI");
1483 case EF_ARM_SOFT_FLOAT:
1484 strcat (buf, ", software FP");
1495 strcat (buf,", <unknown>");
1499 get_machine_flags (e_flags, e_machine)
1503 static char buf [1024];
1515 decode_ARM_machine_flags (e_flags, buf);
1519 if (e_flags & EF_CPU32)
1520 strcat (buf, ", cpu32");
1524 if (e_flags & EF_PPC_EMB)
1525 strcat (buf, ", emb");
1527 if (e_flags & EF_PPC_RELOCATABLE)
1528 strcat (buf, ", relocatable");
1530 if (e_flags & EF_PPC_RELOCATABLE_LIB)
1531 strcat (buf, ", relocatable-lib");
1534 case EM_CYGNUS_V850:
1535 switch (e_flags & EF_V850_ARCH)
1538 strcat (buf, ", v850e");
1541 strcat (buf, ", v850ea");
1544 strcat (buf, ", v850");
1547 strcat (buf, ", unknown v850 architecture variant");
1552 case EM_CYGNUS_M32R:
1553 if ((e_flags & EF_M32R_ARCH) == E_M32R_ARCH)
1554 strcat (buf, ", m32r");
1559 case EM_MIPS_RS3_LE:
1560 if (e_flags & EF_MIPS_NOREORDER)
1561 strcat (buf, ", noreorder");
1563 if (e_flags & EF_MIPS_PIC)
1564 strcat (buf, ", pic");
1566 if (e_flags & EF_MIPS_CPIC)
1567 strcat (buf, ", cpic");
1569 if (e_flags & EF_MIPS_ABI2)
1570 strcat (buf, ", abi2");
1572 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_1)
1573 strcat (buf, ", mips1");
1575 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_2)
1576 strcat (buf, ", mips2");
1578 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_3)
1579 strcat (buf, ", mips3");
1581 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_4)
1582 strcat (buf, ", mips4");
1584 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_5)
1585 strcat (buf, ", mips5");
1587 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_32)
1588 strcat (buf, ", mips32");
1590 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_64)
1591 strcat (buf, ", mips64");
1593 switch ((e_flags & EF_MIPS_MACH))
1595 case E_MIPS_MACH_3900: strcat (buf, ", 3900"); break;
1596 case E_MIPS_MACH_4010: strcat (buf, ", 4010"); break;
1597 case E_MIPS_MACH_4100: strcat (buf, ", 4100"); break;
1598 case E_MIPS_MACH_4650: strcat (buf, ", 4650"); break;
1599 case E_MIPS_MACH_4111: strcat (buf, ", 4111"); break;
1600 case E_MIPS_MACH_MIPS32_4K: strcat (buf, ", mips32-4k"); break;
1601 case E_MIPS_MACH_SB1: strcat (buf, ", sb1"); break;
1602 default: strcat (buf, " UNKNOWN"); break;
1607 if (e_flags & EF_SPARC_32PLUS)
1608 strcat (buf, ", v8+");
1610 if (e_flags & EF_SPARC_SUN_US1)
1611 strcat (buf, ", ultrasparcI");
1613 if (e_flags & EF_SPARC_SUN_US3)
1614 strcat (buf, ", ultrasparcIII");
1616 if (e_flags & EF_SPARC_HAL_R1)
1617 strcat (buf, ", halr1");
1619 if (e_flags & EF_SPARC_LEDATA)
1620 strcat (buf, ", ledata");
1622 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_TSO)
1623 strcat (buf, ", tso");
1625 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_PSO)
1626 strcat (buf, ", pso");
1628 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_RMO)
1629 strcat (buf, ", rmo");
1633 switch (e_flags & EF_PARISC_ARCH)
1635 case EFA_PARISC_1_0:
1636 strcpy (buf, ", PA-RISC 1.0");
1638 case EFA_PARISC_1_1:
1639 strcpy (buf, ", PA-RISC 1.1");
1641 case EFA_PARISC_2_0:
1642 strcpy (buf, ", PA-RISC 2.0");
1647 if (e_flags & EF_PARISC_TRAPNIL)
1648 strcat (buf, ", trapnil");
1649 if (e_flags & EF_PARISC_EXT)
1650 strcat (buf, ", ext");
1651 if (e_flags & EF_PARISC_LSB)
1652 strcat (buf, ", lsb");
1653 if (e_flags & EF_PARISC_WIDE)
1654 strcat (buf, ", wide");
1655 if (e_flags & EF_PARISC_NO_KABP)
1656 strcat (buf, ", no kabp");
1657 if (e_flags & EF_PARISC_LAZYSWAP)
1658 strcat (buf, ", lazyswap");
1662 if ((e_flags & EF_PICOJAVA_NEWCALLS) == EF_PICOJAVA_NEWCALLS)
1663 strcat (buf, ", new calling convention");
1665 if ((e_flags & EF_PICOJAVA_GNUCALLS) == EF_PICOJAVA_GNUCALLS)
1666 strcat (buf, ", gnu calling convention");
1670 if ((e_flags & EF_IA_64_ABI64))
1671 strcat (buf, ", 64-bit");
1673 strcat (buf, ", 32-bit");
1674 if ((e_flags & EF_IA_64_REDUCEDFP))
1675 strcat (buf, ", reduced fp model");
1676 if ((e_flags & EF_IA_64_NOFUNCDESC_CONS_GP))
1677 strcat (buf, ", no function descriptors, constant gp");
1678 else if ((e_flags & EF_IA_64_CONS_GP))
1679 strcat (buf, ", constant gp");
1680 if ((e_flags & EF_IA_64_ABSOLUTE))
1681 strcat (buf, ", absolute");
1690 get_mips_segment_type (type)
1695 case PT_MIPS_REGINFO:
1697 case PT_MIPS_RTPROC:
1699 case PT_MIPS_OPTIONS:
1709 get_parisc_segment_type (type)
1714 case PT_HP_TLS: return "HP_TLS";
1715 case PT_HP_CORE_NONE: return "HP_CORE_NONE";
1716 case PT_HP_CORE_VERSION: return "HP_CORE_VERSION";
1717 case PT_HP_CORE_KERNEL: return "HP_CORE_KERNEL";
1718 case PT_HP_CORE_COMM: return "HP_CORE_COMM";
1719 case PT_HP_CORE_PROC: return "HP_CORE_PROC";
1720 case PT_HP_CORE_LOADABLE: return "HP_CORE_LOADABLE";
1721 case PT_HP_CORE_STACK: return "HP_CORE_STACK";
1722 case PT_HP_CORE_SHM: return "HP_CORE_SHM";
1723 case PT_HP_CORE_MMF: return "HP_CORE_MMF";
1724 case PT_HP_PARALLEL: return "HP_PARALLEL";
1725 case PT_HP_FASTBIND: return "HP_FASTBIND";
1726 case PT_PARISC_ARCHEXT: return "PARISC_ARCHEXT";
1727 case PT_PARISC_UNWIND: return "PARISC_UNWIND";
1736 get_ia64_segment_type (type)
1741 case PT_IA_64_ARCHEXT: return "IA_64_ARCHEXT";
1742 case PT_IA_64_UNWIND: return "IA_64_UNWIND";
1751 get_segment_type (p_type)
1752 unsigned long p_type;
1754 static char buff [32];
1758 case PT_NULL: return "NULL";
1759 case PT_LOAD: return "LOAD";
1760 case PT_DYNAMIC: return "DYNAMIC";
1761 case PT_INTERP: return "INTERP";
1762 case PT_NOTE: return "NOTE";
1763 case PT_SHLIB: return "SHLIB";
1764 case PT_PHDR: return "PHDR";
1767 if ((p_type >= PT_LOPROC) && (p_type <= PT_HIPROC))
1769 const char * result;
1771 switch (elf_header.e_machine)
1774 case EM_MIPS_RS3_LE:
1775 result = get_mips_segment_type (p_type);
1778 result = get_parisc_segment_type (p_type);
1781 result = get_ia64_segment_type (p_type);
1791 sprintf (buff, "LOPROC+%lx", p_type - PT_LOPROC);
1793 else if ((p_type >= PT_LOOS) && (p_type <= PT_HIOS))
1795 const char * result;
1797 switch (elf_header.e_machine)
1800 result = get_parisc_segment_type (p_type);
1810 sprintf (buff, "LOOS+%lx", p_type - PT_LOOS);
1813 sprintf (buff, _("<unknown>: %lx"), p_type);
1820 get_mips_section_type_name (sh_type)
1821 unsigned int sh_type;
1825 case SHT_MIPS_LIBLIST: return "MIPS_LIBLIST";
1826 case SHT_MIPS_MSYM: return "MIPS_MSYM";
1827 case SHT_MIPS_CONFLICT: return "MIPS_CONFLICT";
1828 case SHT_MIPS_GPTAB: return "MIPS_GPTAB";
1829 case SHT_MIPS_UCODE: return "MIPS_UCODE";
1830 case SHT_MIPS_DEBUG: return "MIPS_DEBUG";
1831 case SHT_MIPS_REGINFO: return "MIPS_REGINFO";
1832 case SHT_MIPS_PACKAGE: return "MIPS_PACKAGE";
1833 case SHT_MIPS_PACKSYM: return "MIPS_PACKSYM";
1834 case SHT_MIPS_RELD: return "MIPS_RELD";
1835 case SHT_MIPS_IFACE: return "MIPS_IFACE";
1836 case SHT_MIPS_CONTENT: return "MIPS_CONTENT";
1837 case SHT_MIPS_OPTIONS: return "MIPS_OPTIONS";
1838 case SHT_MIPS_SHDR: return "MIPS_SHDR";
1839 case SHT_MIPS_FDESC: return "MIPS_FDESC";
1840 case SHT_MIPS_EXTSYM: return "MIPS_EXTSYM";
1841 case SHT_MIPS_DENSE: return "MIPS_DENSE";
1842 case SHT_MIPS_PDESC: return "MIPS_PDESC";
1843 case SHT_MIPS_LOCSYM: return "MIPS_LOCSYM";
1844 case SHT_MIPS_AUXSYM: return "MIPS_AUXSYM";
1845 case SHT_MIPS_OPTSYM: return "MIPS_OPTSYM";
1846 case SHT_MIPS_LOCSTR: return "MIPS_LOCSTR";
1847 case SHT_MIPS_LINE: return "MIPS_LINE";
1848 case SHT_MIPS_RFDESC: return "MIPS_RFDESC";
1849 case SHT_MIPS_DELTASYM: return "MIPS_DELTASYM";
1850 case SHT_MIPS_DELTAINST: return "MIPS_DELTAINST";
1851 case SHT_MIPS_DELTACLASS: return "MIPS_DELTACLASS";
1852 case SHT_MIPS_DWARF: return "MIPS_DWARF";
1853 case SHT_MIPS_DELTADECL: return "MIPS_DELTADECL";
1854 case SHT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB";
1855 case SHT_MIPS_EVENTS: return "MIPS_EVENTS";
1856 case SHT_MIPS_TRANSLATE: return "MIPS_TRANSLATE";
1857 case SHT_MIPS_PIXIE: return "MIPS_PIXIE";
1858 case SHT_MIPS_XLATE: return "MIPS_XLATE";
1859 case SHT_MIPS_XLATE_DEBUG: return "MIPS_XLATE_DEBUG";
1860 case SHT_MIPS_WHIRL: return "MIPS_WHIRL";
1861 case SHT_MIPS_EH_REGION: return "MIPS_EH_REGION";
1862 case SHT_MIPS_XLATE_OLD: return "MIPS_XLATE_OLD";
1863 case SHT_MIPS_PDR_EXCEPTION: return "MIPS_PDR_EXCEPTION";
1871 get_parisc_section_type_name (sh_type)
1872 unsigned int sh_type;
1876 case SHT_PARISC_EXT: return "PARISC_EXT";
1877 case SHT_PARISC_UNWIND: return "PARISC_UNWIND";
1878 case SHT_PARISC_DOC: return "PARISC_DOC";
1886 get_ia64_section_type_name (sh_type)
1887 unsigned int sh_type;
1891 case SHT_IA_64_EXT: return "IA_64_EXT";
1892 case SHT_IA_64_UNWIND: return "IA_64_UNWIND";
1900 get_section_type_name (sh_type)
1901 unsigned int sh_type;
1903 static char buff [32];
1907 case SHT_NULL: return "NULL";
1908 case SHT_PROGBITS: return "PROGBITS";
1909 case SHT_SYMTAB: return "SYMTAB";
1910 case SHT_STRTAB: return "STRTAB";
1911 case SHT_RELA: return "RELA";
1912 case SHT_HASH: return "HASH";
1913 case SHT_DYNAMIC: return "DYNAMIC";
1914 case SHT_NOTE: return "NOTE";
1915 case SHT_NOBITS: return "NOBITS";
1916 case SHT_REL: return "REL";
1917 case SHT_SHLIB: return "SHLIB";
1918 case SHT_DYNSYM: return "DYNSYM";
1919 case SHT_INIT_ARRAY: return "INIT_ARRAY";
1920 case SHT_FINI_ARRAY: return "FINI_ARRAY";
1921 case SHT_PREINIT_ARRAY: return "PREINIT_ARRAY";
1922 case SHT_GROUP: return "GROUP";
1923 case SHT_SYMTAB_SHNDX: return "SYMTAB SECTION INDICIES";
1924 case SHT_GNU_verdef: return "VERDEF";
1925 case SHT_GNU_verneed: return "VERNEED";
1926 case SHT_GNU_versym: return "VERSYM";
1927 case 0x6ffffff0: return "VERSYM";
1928 case 0x6ffffffc: return "VERDEF";
1929 case 0x7ffffffd: return "AUXILIARY";
1930 case 0x7fffffff: return "FILTER";
1933 if ((sh_type >= SHT_LOPROC) && (sh_type <= SHT_HIPROC))
1935 const char * result;
1937 switch (elf_header.e_machine)
1940 case EM_MIPS_RS3_LE:
1941 result = get_mips_section_type_name (sh_type);
1944 result = get_parisc_section_type_name (sh_type);
1947 result = get_ia64_section_type_name (sh_type);
1957 sprintf (buff, "SHT_LOPROC+%x", sh_type - SHT_LOPROC);
1959 else if ((sh_type >= SHT_LOOS) && (sh_type <= SHT_HIOS))
1960 sprintf (buff, "SHT_LOOS+%x", sh_type - SHT_LOOS);
1961 else if ((sh_type >= SHT_LOUSER) && (sh_type <= SHT_HIUSER))
1962 sprintf (buff, "SHT_LOUSER+%x", sh_type - SHT_LOUSER);
1964 sprintf (buff, _("<unknown>: %x"), sh_type);
1970 struct option options [] =
1972 {"all", no_argument, 0, 'a'},
1973 {"file-header", no_argument, 0, 'h'},
1974 {"program-headers", no_argument, 0, 'l'},
1975 {"headers", no_argument, 0, 'e'},
1976 {"histogram", no_argument, 0, 'I'},
1977 {"segments", no_argument, 0, 'l'},
1978 {"sections", no_argument, 0, 'S'},
1979 {"section-headers", no_argument, 0, 'S'},
1980 {"symbols", no_argument, 0, 's'},
1981 {"syms", no_argument, 0, 's'},
1982 {"relocs", no_argument, 0, 'r'},
1983 {"notes", no_argument, 0, 'n'},
1984 {"dynamic", no_argument, 0, 'd'},
1985 {"arch-specific", no_argument, 0, 'A'},
1986 {"version-info", no_argument, 0, 'V'},
1987 {"use-dynamic", no_argument, 0, 'D'},
1988 {"hex-dump", required_argument, 0, 'x'},
1989 {"debug-dump", optional_argument, 0, 'w'},
1990 {"unwind", no_argument, 0, 'u'},
1991 #ifdef SUPPORT_DISASSEMBLY
1992 {"instruction-dump", required_argument, 0, 'i'},
1995 {"version", no_argument, 0, 'v'},
1996 {"help", no_argument, 0, 'H'},
1997 {0, no_argument, 0, 0}
2003 fprintf (stdout, _("Usage: readelf {options} elf-file(s)\n"));
2004 fprintf (stdout, _(" Options are:\n"));
2005 fprintf (stdout, _(" -a or --all Equivalent to: -h -l -S -s -r -d -V -A -I\n"));
2006 fprintf (stdout, _(" -h or --file-header Display the ELF file header\n"));
2007 fprintf (stdout, _(" -l or --program-headers or --segments\n"));
2008 fprintf (stdout, _(" Display the program headers\n"));
2009 fprintf (stdout, _(" -S or --section-headers or --sections\n"));
2010 fprintf (stdout, _(" Display the sections' header\n"));
2011 fprintf (stdout, _(" -e or --headers Equivalent to: -h -l -S\n"));
2012 fprintf (stdout, _(" -s or --syms or --symbols Display the symbol table\n"));
2013 fprintf (stdout, _(" -n or --notes Display the core notes (if present)\n"));
2014 fprintf (stdout, _(" -r or --relocs Display the relocations (if present)\n"));
2015 fprintf (stdout, _(" -u or --unwind Display the unwind info (if present)\n"));
2016 fprintf (stdout, _(" -d or --dynamic Display the dynamic segment (if present)\n"));
2017 fprintf (stdout, _(" -V or --version-info Display the version sections (if present)\n"));
2018 fprintf (stdout, _(" -A or --arch-specific Display architecture specific information (if any).\n"));
2019 fprintf (stdout, _(" -D or --use-dynamic Use the dynamic section info when displaying symbols\n"));
2020 fprintf (stdout, _(" -x <number> or --hex-dump=<number>\n"));
2021 fprintf (stdout, _(" Dump the contents of section <number>\n"));
2022 fprintf (stdout, _(" -w[liaprf] or --debug-dump[=line,=info,=abbrev,=pubnames,=ranges,=frames]\n"));
2023 fprintf (stdout, _(" Display the contents of DWARF2 debug sections\n"));
2024 #ifdef SUPPORT_DISASSEMBLY
2025 fprintf (stdout, _(" -i <number> or --instruction-dump=<number>\n"));
2026 fprintf (stdout, _(" Disassemble the contents of section <number>\n"));
2028 fprintf (stdout, _(" -I or --histogram Display histogram of bucket list lengths\n"));
2029 fprintf (stdout, _(" -v or --version Display the version number of readelf\n"));
2030 fprintf (stdout, _(" -H or --help Display this information\n"));
2031 fprintf (stdout, _("Report bugs to %s\n"), REPORT_BUGS_TO);
2037 request_dump (section, type)
2038 unsigned int section;
2041 if (section >= num_dump_sects)
2043 char * new_dump_sects;
2045 new_dump_sects = (char *) calloc (section + 1, 1);
2047 if (new_dump_sects == NULL)
2048 error (_("Out of memory allocating dump request table."));
2051 /* Copy current flag settings. */
2052 memcpy (new_dump_sects, dump_sects, num_dump_sects);
2056 dump_sects = new_dump_sects;
2057 num_dump_sects = section + 1;
2062 dump_sects [section] |= type;
2068 parse_args (argc, argv)
2077 while ((c = getopt_long
2078 (argc, argv, "ersuahnldSDAIw::x:i:vV", options, NULL)) != EOF)
2114 do_using_dynamic ++;
2145 section = strtoul (optarg, & cp, 0);
2146 if (! * cp && section >= 0)
2148 request_dump (section, HEX_DUMP);
2168 do_debug_abbrevs = 1;
2178 do_debug_pubnames = 1;
2183 do_debug_aranges = 1;
2187 do_debug_frames_interp = 1;
2189 do_debug_frames = 1;
2193 warn (_("Unrecognised debug option '%s'\n"), optarg);
2198 #ifdef SUPPORT_DISASSEMBLY
2201 section = strtoul (optarg, & cp, 0);
2202 if (! * cp && section >= 0)
2204 request_dump (section, DISASS_DUMP);
2210 print_version (program_name);
2217 /* xgettext:c-format */
2218 error (_("Invalid option '-%c'\n"), c);
2225 if (!do_dynamic && !do_syms && !do_reloc && !do_unwind && !do_sections
2226 && !do_segments && !do_header && !do_dump && !do_version
2227 && !do_histogram && !do_debugging && !do_arch && !do_notes)
2231 warn (_("Nothing to do.\n"));
2237 get_elf_class (elf_class)
2238 unsigned char elf_class;
2240 static char buff [32];
2244 case ELFCLASSNONE: return _("none");
2245 case ELFCLASS32: return _("ELF32");
2246 case ELFCLASS64: return _("ELF64");
2248 sprintf (buff, _("<unknown: %x>"), elf_class);
2254 get_data_encoding (encoding)
2255 unsigned char encoding;
2257 static char buff [32];
2261 case ELFDATANONE: return _("none");
2262 case ELFDATA2LSB: return _("2's complement, little endian");
2263 case ELFDATA2MSB: return _("2's complement, big endian");
2265 sprintf (buff, _("<unknown: %x>"), encoding);
2271 get_osabi_name (osabi)
2272 unsigned char osabi;
2274 static char buff [32];
2278 case ELFOSABI_NONE: return _("UNIX - System V");
2279 case ELFOSABI_HPUX: return _("UNIX - HP-UX");
2280 case ELFOSABI_NETBSD: return _("UNIX - NetBSD");
2281 case ELFOSABI_LINUX: return _("UNIX - Linux");
2282 case ELFOSABI_HURD: return _("GNU/Hurd");
2283 case ELFOSABI_SOLARIS: return _("UNIX - Solaris");
2284 case ELFOSABI_AIX: return _("UNIX - AIX");
2285 case ELFOSABI_IRIX: return _("UNIX - IRIX");
2286 case ELFOSABI_FREEBSD: return _("UNIX - FreeBSD");
2287 case ELFOSABI_TRU64: return _("UNIX - TRU64");
2288 case ELFOSABI_MODESTO: return _("Novell - Modesto");
2289 case ELFOSABI_OPENBSD: return _("UNIX - OpenBSD");
2290 case ELFOSABI_STANDALONE: return _("Standalone App");
2291 case ELFOSABI_ARM: return _("ARM");
2293 sprintf (buff, _("<unknown: %x>"), osabi);
2298 /* Decode the data held in 'elf_header'. */
2300 process_file_header ()
2302 if ( elf_header.e_ident [EI_MAG0] != ELFMAG0
2303 || elf_header.e_ident [EI_MAG1] != ELFMAG1
2304 || elf_header.e_ident [EI_MAG2] != ELFMAG2
2305 || elf_header.e_ident [EI_MAG3] != ELFMAG3)
2308 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
2316 printf (_("ELF Header:\n"));
2317 printf (_(" Magic: "));
2318 for (i = 0; i < EI_NIDENT; i ++)
2319 printf ("%2.2x ", elf_header.e_ident [i]);
2321 printf (_(" Class: %s\n"),
2322 get_elf_class (elf_header.e_ident [EI_CLASS]));
2323 printf (_(" Data: %s\n"),
2324 get_data_encoding (elf_header.e_ident [EI_DATA]));
2325 printf (_(" Version: %d %s\n"),
2326 elf_header.e_ident [EI_VERSION],
2327 (elf_header.e_ident [EI_VERSION] == EV_CURRENT
2329 : (elf_header.e_ident [EI_VERSION] != EV_NONE
2332 printf (_(" OS/ABI: %s\n"),
2333 get_osabi_name (elf_header.e_ident [EI_OSABI]));
2334 printf (_(" ABI Version: %d\n"),
2335 elf_header.e_ident [EI_ABIVERSION]);
2336 printf (_(" Type: %s\n"),
2337 get_file_type (elf_header.e_type));
2338 printf (_(" Machine: %s\n"),
2339 get_machine_name (elf_header.e_machine));
2340 printf (_(" Version: 0x%lx\n"),
2341 (unsigned long) elf_header.e_version);
2343 printf (_(" Entry point address: "));
2344 print_vma ((bfd_vma) elf_header.e_entry, PREFIX_HEX);
2345 printf (_("\n Start of program headers: "));
2346 print_vma ((bfd_vma) elf_header.e_phoff, DEC);
2347 printf (_(" (bytes into file)\n Start of section headers: "));
2348 print_vma ((bfd_vma) elf_header.e_shoff, DEC);
2349 printf (_(" (bytes into file)\n"));
2351 printf (_(" Flags: 0x%lx%s\n"),
2352 (unsigned long) elf_header.e_flags,
2353 get_machine_flags (elf_header.e_flags, elf_header.e_machine));
2354 printf (_(" Size of this header: %ld (bytes)\n"),
2355 (long) elf_header.e_ehsize);
2356 printf (_(" Size of program headers: %ld (bytes)\n"),
2357 (long) elf_header.e_phentsize);
2358 printf (_(" Number of program headers: %ld\n"),
2359 (long) elf_header.e_phnum);
2360 printf (_(" Size of section headers: %ld (bytes)\n"),
2361 (long) elf_header.e_shentsize);
2362 printf (_(" Number of section headers: %ld\n"),
2363 (long) elf_header.e_shnum);
2364 printf (_(" Section header string table index: %ld\n"),
2365 (long) elf_header.e_shstrndx);
2373 get_32bit_program_headers (file, program_headers)
2375 Elf_Internal_Phdr * program_headers;
2377 Elf32_External_Phdr * phdrs;
2378 Elf32_External_Phdr * external;
2379 Elf32_Internal_Phdr * internal;
2382 phdrs = ((Elf32_External_Phdr *)
2383 get_data (NULL, file, elf_header.e_phoff,
2384 elf_header.e_phentsize * elf_header.e_phnum,
2385 _("program headers")));
2389 for (i = 0, internal = program_headers, external = phdrs;
2390 i < elf_header.e_phnum;
2391 i ++, internal ++, external ++)
2393 internal->p_type = BYTE_GET (external->p_type);
2394 internal->p_offset = BYTE_GET (external->p_offset);
2395 internal->p_vaddr = BYTE_GET (external->p_vaddr);
2396 internal->p_paddr = BYTE_GET (external->p_paddr);
2397 internal->p_filesz = BYTE_GET (external->p_filesz);
2398 internal->p_memsz = BYTE_GET (external->p_memsz);
2399 internal->p_flags = BYTE_GET (external->p_flags);
2400 internal->p_align = BYTE_GET (external->p_align);
2409 get_64bit_program_headers (file, program_headers)
2411 Elf_Internal_Phdr * program_headers;
2413 Elf64_External_Phdr * phdrs;
2414 Elf64_External_Phdr * external;
2415 Elf64_Internal_Phdr * internal;
2418 phdrs = ((Elf64_External_Phdr *)
2419 get_data (NULL, file, elf_header.e_phoff,
2420 elf_header.e_phentsize * elf_header.e_phnum,
2421 _("program headers")));
2425 for (i = 0, internal = program_headers, external = phdrs;
2426 i < elf_header.e_phnum;
2427 i ++, internal ++, external ++)
2429 internal->p_type = BYTE_GET (external->p_type);
2430 internal->p_flags = BYTE_GET (external->p_flags);
2431 internal->p_offset = BYTE_GET8 (external->p_offset);
2432 internal->p_vaddr = BYTE_GET8 (external->p_vaddr);
2433 internal->p_paddr = BYTE_GET8 (external->p_paddr);
2434 internal->p_filesz = BYTE_GET8 (external->p_filesz);
2435 internal->p_memsz = BYTE_GET8 (external->p_memsz);
2436 internal->p_align = BYTE_GET8 (external->p_align);
2445 process_program_headers (file)
2448 Elf_Internal_Phdr * program_headers;
2449 Elf_Internal_Phdr * segment;
2452 if (elf_header.e_phnum == 0)
2455 printf (_("\nThere are no program headers in this file.\n"));
2459 if (do_segments && !do_header)
2461 printf (_("\nElf file type is %s\n"), get_file_type (elf_header.e_type));
2462 printf (_("Entry point "));
2463 print_vma ((bfd_vma) elf_header.e_entry, PREFIX_HEX);
2464 printf (_("\nThere are %d program headers, starting at offset "),
2465 elf_header.e_phnum);
2466 print_vma ((bfd_vma) elf_header.e_phoff, DEC);
2470 program_headers = (Elf_Internal_Phdr *) malloc
2471 (elf_header.e_phnum * sizeof (Elf_Internal_Phdr));
2473 if (program_headers == NULL)
2475 error (_("Out of memory\n"));
2480 i = get_32bit_program_headers (file, program_headers);
2482 i = get_64bit_program_headers (file, program_headers);
2486 free (program_headers);
2493 (_("\nProgram Header%s:\n"), elf_header.e_phnum > 1 ? "s" : "");
2497 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
2501 (_(" Type Offset VirtAddr PhysAddr\n"));
2503 (_(" FileSiz MemSiz Flags Align\n"));
2511 for (i = 0, segment = program_headers;
2512 i < elf_header.e_phnum;
2517 printf (" %-14.14s ", get_segment_type (segment->p_type));
2521 printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
2522 printf ("0x%8.8lx ", (unsigned long) segment->p_vaddr);
2523 printf ("0x%8.8lx ", (unsigned long) segment->p_paddr);
2524 printf ("0x%5.5lx ", (unsigned long) segment->p_filesz);
2525 printf ("0x%5.5lx ", (unsigned long) segment->p_memsz);
2527 (segment->p_flags & PF_R ? 'R' : ' '),
2528 (segment->p_flags & PF_W ? 'W' : ' '),
2529 (segment->p_flags & PF_X ? 'E' : ' '));
2530 printf ("%#lx", (unsigned long) segment->p_align);
2534 print_vma (segment->p_offset, FULL_HEX);
2536 print_vma (segment->p_vaddr, FULL_HEX);
2538 print_vma (segment->p_paddr, FULL_HEX);
2540 print_vma (segment->p_filesz, FULL_HEX);
2542 print_vma (segment->p_memsz, FULL_HEX);
2544 (segment->p_flags & PF_R ? 'R' : ' '),
2545 (segment->p_flags & PF_W ? 'W' : ' '),
2546 (segment->p_flags & PF_X ? 'E' : ' '));
2547 print_vma (segment->p_align, HEX);
2551 switch (segment->p_type)
2555 loadaddr = (segment->p_vaddr & 0xfffff000)
2556 - (segment->p_offset & 0xfffff000);
2561 error (_("more than one dynamic segment\n"));
2563 dynamic_addr = segment->p_offset;
2564 dynamic_size = segment->p_filesz;
2568 if (fseek (file, (long) segment->p_offset, SEEK_SET))
2569 error (_("Unable to find program interpreter name\n"));
2572 program_interpreter[0] = 0;
2573 fscanf (file, "%63s", program_interpreter);
2576 printf (_("\n [Requesting program interpreter: %s]"),
2577 program_interpreter);
2583 putc ('\n', stdout);
2592 if (do_segments && section_headers != NULL)
2594 printf (_("\n Section to Segment mapping:\n"));
2595 printf (_(" Segment Sections...\n"));
2597 assert (string_table != NULL);
2599 for (i = 0; i < elf_header.e_phnum; i++)
2602 Elf_Internal_Shdr * section;
2604 segment = program_headers + i;
2605 section = section_headers;
2607 printf (" %2.2d ", i);
2609 for (j = 0; j < elf_header.e_shnum; j++, section ++)
2611 if (section->sh_size > 0
2612 /* Compare allocated sections by VMA, unallocated
2613 sections by file offset. */
2614 && (section->sh_flags & SHF_ALLOC
2615 ? (section->sh_addr >= segment->p_vaddr
2616 && section->sh_addr + section->sh_size
2617 <= segment->p_vaddr + segment->p_memsz)
2618 : ((bfd_vma) section->sh_offset >= segment->p_offset
2619 && (section->sh_offset + section->sh_size
2620 <= segment->p_offset + segment->p_filesz))))
2621 printf ("%s ", SECTION_NAME (section));
2628 free (program_headers);
2635 get_32bit_section_headers (file)
2638 Elf32_External_Shdr * shdrs;
2639 Elf32_Internal_Shdr * internal;
2642 shdrs = ((Elf32_External_Shdr *)
2643 get_data (NULL, file, elf_header.e_shoff,
2644 elf_header.e_shentsize * elf_header.e_shnum,
2645 _("section headers")));
2649 section_headers = (Elf_Internal_Shdr *) malloc
2650 (elf_header.e_shnum * sizeof (Elf_Internal_Shdr));
2652 if (section_headers == NULL)
2654 error (_("Out of memory\n"));
2658 for (i = 0, internal = section_headers;
2659 i < elf_header.e_shnum;
2662 internal->sh_name = BYTE_GET (shdrs[i].sh_name);
2663 internal->sh_type = BYTE_GET (shdrs[i].sh_type);
2664 internal->sh_flags = BYTE_GET (shdrs[i].sh_flags);
2665 internal->sh_addr = BYTE_GET (shdrs[i].sh_addr);
2666 internal->sh_offset = BYTE_GET (shdrs[i].sh_offset);
2667 internal->sh_size = BYTE_GET (shdrs[i].sh_size);
2668 internal->sh_link = BYTE_GET (shdrs[i].sh_link);
2669 internal->sh_info = BYTE_GET (shdrs[i].sh_info);
2670 internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
2671 internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize);
2680 get_64bit_section_headers (file)
2683 Elf64_External_Shdr * shdrs;
2684 Elf64_Internal_Shdr * internal;
2687 shdrs = ((Elf64_External_Shdr *)
2688 get_data (NULL, file, elf_header.e_shoff,
2689 elf_header.e_shentsize * elf_header.e_shnum,
2690 _("section headers")));
2694 section_headers = (Elf_Internal_Shdr *) malloc
2695 (elf_header.e_shnum * sizeof (Elf_Internal_Shdr));
2697 if (section_headers == NULL)
2699 error (_("Out of memory\n"));
2703 for (i = 0, internal = section_headers;
2704 i < elf_header.e_shnum;
2707 internal->sh_name = BYTE_GET (shdrs[i].sh_name);
2708 internal->sh_type = BYTE_GET (shdrs[i].sh_type);
2709 internal->sh_flags = BYTE_GET8 (shdrs[i].sh_flags);
2710 internal->sh_addr = BYTE_GET8 (shdrs[i].sh_addr);
2711 internal->sh_size = BYTE_GET8 (shdrs[i].sh_size);
2712 internal->sh_entsize = BYTE_GET8 (shdrs[i].sh_entsize);
2713 internal->sh_link = BYTE_GET (shdrs[i].sh_link);
2714 internal->sh_info = BYTE_GET (shdrs[i].sh_info);
2715 internal->sh_offset = BYTE_GET (shdrs[i].sh_offset);
2716 internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
2724 static Elf_Internal_Sym *
2725 get_32bit_elf_symbols (file, offset, number)
2727 unsigned long offset;
2728 unsigned long number;
2730 Elf32_External_Sym * esyms;
2731 Elf_Internal_Sym * isyms;
2732 Elf_Internal_Sym * psym;
2735 esyms = ((Elf32_External_Sym *)
2736 get_data (NULL, file, offset,
2737 number * sizeof (Elf32_External_Sym), _("symbols")));
2741 isyms = (Elf_Internal_Sym *) malloc (number * sizeof (Elf_Internal_Sym));
2745 error (_("Out of memory\n"));
2751 for (j = 0, psym = isyms;
2755 psym->st_name = BYTE_GET (esyms[j].st_name);
2756 psym->st_value = BYTE_GET (esyms[j].st_value);
2757 psym->st_size = BYTE_GET (esyms[j].st_size);
2758 psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
2759 psym->st_info = BYTE_GET (esyms[j].st_info);
2760 psym->st_other = BYTE_GET (esyms[j].st_other);
2768 static Elf_Internal_Sym *
2769 get_64bit_elf_symbols (file, offset, number)
2771 unsigned long offset;
2772 unsigned long number;
2774 Elf64_External_Sym * esyms;
2775 Elf_Internal_Sym * isyms;
2776 Elf_Internal_Sym * psym;
2779 esyms = ((Elf64_External_Sym *)
2780 get_data (NULL, file, offset,
2781 number * sizeof (Elf64_External_Sym), _("symbols")));
2785 isyms = (Elf_Internal_Sym *) malloc (number * sizeof (Elf_Internal_Sym));
2789 error (_("Out of memory\n"));
2795 for (j = 0, psym = isyms;
2799 psym->st_name = BYTE_GET (esyms[j].st_name);
2800 psym->st_info = BYTE_GET (esyms[j].st_info);
2801 psym->st_other = BYTE_GET (esyms[j].st_other);
2802 psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
2803 psym->st_value = BYTE_GET8 (esyms[j].st_value);
2804 psym->st_size = BYTE_GET8 (esyms[j].st_size);
2813 get_elf_section_flags (sh_flags)
2816 static char buff [32];
2824 flag = sh_flags & - sh_flags;
2829 case SHF_WRITE: strcat (buff, "W"); break;
2830 case SHF_ALLOC: strcat (buff, "A"); break;
2831 case SHF_EXECINSTR: strcat (buff, "X"); break;
2832 case SHF_MERGE: strcat (buff, "M"); break;
2833 case SHF_STRINGS: strcat (buff, "S"); break;
2834 case SHF_INFO_LINK: strcat (buff, "I"); break;
2835 case SHF_LINK_ORDER: strcat (buff, "L"); break;
2836 case SHF_OS_NONCONFORMING: strcat (buff, "O"); break;
2837 case SHF_GROUP: strcat (buff, "G"); break;
2840 if (flag & SHF_MASKOS)
2843 sh_flags &= ~ SHF_MASKOS;
2845 else if (flag & SHF_MASKPROC)
2848 sh_flags &= ~ SHF_MASKPROC;
2860 process_section_headers (file)
2863 Elf_Internal_Shdr * section;
2866 section_headers = NULL;
2868 if (elf_header.e_shnum == 0)
2871 printf (_("\nThere are no sections in this file.\n"));
2876 if (do_sections && !do_header)
2877 printf (_("There are %d section headers, starting at offset 0x%lx:\n"),
2878 elf_header.e_shnum, (unsigned long) elf_header.e_shoff);
2882 if (! get_32bit_section_headers (file))
2885 else if (! get_64bit_section_headers (file))
2888 /* Read in the string table, so that we have names to display. */
2889 section = section_headers + elf_header.e_shstrndx;
2891 if (section->sh_size != 0)
2893 string_table = (char *) get_data (NULL, file, section->sh_offset,
2894 section->sh_size, _("string table"));
2896 string_table_length = section->sh_size;
2899 /* Scan the sections for the dynamic symbol table
2900 and dynamic string table and debug sections. */
2901 dynamic_symbols = NULL;
2902 dynamic_strings = NULL;
2903 dynamic_syminfo = NULL;
2905 for (i = 0, section = section_headers;
2906 i < elf_header.e_shnum;
2909 char * name = SECTION_NAME (section);
2911 if (section->sh_type == SHT_DYNSYM)
2913 if (dynamic_symbols != NULL)
2915 error (_("File contains multiple dynamic symbol tables\n"));
2919 num_dynamic_syms = section->sh_size / section->sh_entsize;
2921 GET_ELF_SYMBOLS (file, section->sh_offset, num_dynamic_syms);
2923 else if (section->sh_type == SHT_STRTAB
2924 && strcmp (name, ".dynstr") == 0)
2926 if (dynamic_strings != NULL)
2928 error (_("File contains multiple dynamic string tables\n"));
2932 dynamic_strings = (char *) get_data (NULL, file, section->sh_offset,
2934 _("dynamic strings"));
2936 else if ((do_debugging || do_debug_info || do_debug_abbrevs
2937 || do_debug_lines || do_debug_pubnames || do_debug_aranges
2939 && strncmp (name, ".debug_", 7) == 0)
2944 || (do_debug_info && (strcmp (name, "info") == 0))
2945 || (do_debug_abbrevs && (strcmp (name, "abbrev") == 0))
2946 || (do_debug_lines && (strcmp (name, "line") == 0))
2947 || (do_debug_pubnames && (strcmp (name, "pubnames") == 0))
2948 || (do_debug_aranges && (strcmp (name, "aranges") == 0))
2949 || (do_debug_frames && (strcmp (name, "frame") == 0))
2951 request_dump (i, DEBUG_DUMP);
2953 /* linkonce section to be combined with .debug_info at link time. */
2954 else if ((do_debugging || do_debug_info)
2955 && strncmp (name, ".gnu.linkonce.wi.", 17) == 0)
2956 request_dump (i, DEBUG_DUMP);
2957 else if (do_debug_frames && strcmp (name, ".eh_frame") == 0)
2958 request_dump (i, DEBUG_DUMP);
2964 printf (_("\nSection Header%s:\n"), elf_header.e_shnum > 1 ? "s" : "");
2968 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
2971 printf (_(" [Nr] Name Type Address Offset\n"));
2972 printf (_(" Size EntSize Flags Link Info Align\n"));
2975 for (i = 0, section = section_headers;
2976 i < elf_header.e_shnum;
2979 printf (" [%2d] %-17.17s %-15.15s ",
2981 SECTION_NAME (section),
2982 get_section_type_name (section->sh_type));
2986 print_vma (section->sh_addr, LONG_HEX);
2988 printf ( " %6.6lx %6.6lx %2.2lx",
2989 (unsigned long) section->sh_offset,
2990 (unsigned long) section->sh_size,
2991 (unsigned long) section->sh_entsize);
2993 printf (" %3s ", get_elf_section_flags (section->sh_flags));
2995 printf ("%2ld %3lx %2ld\n",
2996 (unsigned long) section->sh_link,
2997 (unsigned long) section->sh_info,
2998 (unsigned long) section->sh_addralign);
3003 print_vma (section->sh_addr, LONG_HEX);
3004 printf (" %8.8lx", section->sh_offset);
3006 print_vma (section->sh_size, LONG_HEX);
3008 print_vma (section->sh_entsize, LONG_HEX);
3010 printf (" %3s ", get_elf_section_flags (section->sh_flags));
3012 printf (" %2ld %3lx %ld\n",
3013 (unsigned long) section->sh_link,
3014 (unsigned long) section->sh_info,
3015 (unsigned long) section->sh_addralign);
3019 printf (_("Key to Flags:\n"));
3020 printf (_(" W (write), A (alloc), X (execute), M (merge), S (strings)\n"));
3021 printf (_(" I (info), L (link order), G (group), x (unknown)\n"));
3022 printf (_(" O (extra OS processing required) o (OS specific), p (processor specific)\n"));
3027 /* Process the reloc section. */
3029 process_relocs (file)
3032 unsigned long rel_size;
3033 unsigned long rel_offset;
3039 if (do_using_dynamic)
3041 int is_rela = FALSE;
3046 if (dynamic_info[DT_REL])
3048 rel_offset = dynamic_info[DT_REL];
3049 rel_size = dynamic_info[DT_RELSZ];
3052 else if (dynamic_info [DT_RELA])
3054 rel_offset = dynamic_info[DT_RELA];
3055 rel_size = dynamic_info[DT_RELASZ];
3058 else if (dynamic_info[DT_JMPREL])
3060 rel_offset = dynamic_info[DT_JMPREL];
3061 rel_size = dynamic_info[DT_PLTRELSZ];
3063 switch (dynamic_info[DT_PLTREL])
3080 (_("\nRelocation section at offset 0x%lx contains %ld bytes:\n"),
3081 rel_offset, rel_size);
3083 dump_relocations (file, rel_offset - loadaddr, rel_size,
3084 dynamic_symbols, num_dynamic_syms, dynamic_strings, is_rela);
3087 printf (_("\nThere are no dynamic relocations in this file.\n"));
3091 Elf32_Internal_Shdr * section;
3095 for (i = 0, section = section_headers;
3096 i < elf_header.e_shnum;
3099 if ( section->sh_type != SHT_RELA
3100 && section->sh_type != SHT_REL)
3103 rel_offset = section->sh_offset;
3104 rel_size = section->sh_size;
3108 Elf32_Internal_Shdr * strsec;
3109 Elf_Internal_Sym * symtab;
3112 unsigned long nsyms;
3114 printf (_("\nRelocation section "));
3116 if (string_table == NULL)
3117 printf ("%d", section->sh_name);
3119 printf ("'%s'", SECTION_NAME (section));
3121 printf (_(" at offset 0x%lx contains %lu entries:\n"),
3122 rel_offset, (unsigned long) (rel_size / section->sh_entsize));
3127 if (section->sh_link)
3129 Elf32_Internal_Shdr * symsec;
3131 symsec = section_headers + section->sh_link;
3132 nsyms = symsec->sh_size / symsec->sh_entsize;
3133 symtab = GET_ELF_SYMBOLS (file, symsec->sh_offset, nsyms);
3138 strsec = section_headers + symsec->sh_link;
3140 strtab = (char *) get_data (NULL, file, strsec->sh_offset,
3144 is_rela = section->sh_type == SHT_RELA;
3146 dump_relocations (file, rel_offset, rel_size,
3147 symtab, nsyms, strtab, is_rela);
3159 printf (_("\nThere are no relocations in this file.\n"));
3165 #include "unwind-ia64.h"
3167 /* An absolute address consists of a section and an offset. If the
3168 section is NULL, the offset itself is the address, otherwise, the
3169 address equals to LOAD_ADDRESS(section) + offset. */
3173 unsigned short section;
3179 struct unw_table_entry
3181 struct absaddr start;
3183 struct absaddr info;
3185 *table; /* Unwind table. */
3186 unsigned long table_len; /* Length of unwind table. */
3187 unsigned char * info; /* Unwind info. */
3188 unsigned long info_size; /* Size of unwind info. */
3189 bfd_vma info_addr; /* starting address of unwind info. */
3190 bfd_vma seg_base; /* Starting address of segment. */
3191 Elf_Internal_Sym * symtab; /* The symbol table. */
3192 unsigned long nsyms; /* Number of symbols. */
3193 char * strtab; /* The string table. */
3194 unsigned long strtab_size; /* Size of string table. */
3197 static void find_symbol_for_address PARAMS ((struct unw_aux_info *,
3198 struct absaddr, const char **,
3200 static void dump_ia64_unwind PARAMS ((struct unw_aux_info *));
3201 static int slurp_ia64_unwind_table PARAMS ((FILE *, struct unw_aux_info *,
3202 Elf32_Internal_Shdr *));
3205 find_symbol_for_address (aux, addr, symname, offset)
3206 struct unw_aux_info *aux;
3207 struct absaddr addr;
3208 const char **symname;
3211 bfd_vma dist = (bfd_vma) 0x100000;
3212 Elf_Internal_Sym *sym, *best = NULL;
3215 for (i = 0, sym = aux->symtab; i < aux->nsyms; ++i, ++sym)
3217 if (ELF_ST_TYPE (sym->st_info) == STT_FUNC
3218 && sym->st_name != 0
3219 && (addr.section == SHN_UNDEF || addr.section == sym->st_shndx)
3220 && addr.offset >= sym->st_value
3221 && addr.offset - sym->st_value < dist)
3224 dist = addr.offset - sym->st_value;
3231 *symname = (best->st_name >= aux->strtab_size
3232 ? "<corrupt>" : aux->strtab + best->st_name);
3237 *offset = addr.offset;
3241 dump_ia64_unwind (aux)
3242 struct unw_aux_info *aux;
3245 struct unw_table_entry * tp;
3248 addr_size = is_32bit_elf ? 4 : 8;
3250 for (tp = aux->table; tp < aux->table + aux->table_len; ++tp)
3254 const unsigned char * dp;
3255 const unsigned char * head;
3256 const char * procname;
3258 find_symbol_for_address (aux, tp->start, &procname, &offset);
3260 fputs ("\n<", stdout);
3264 fputs (procname, stdout);
3267 printf ("+%lx", (unsigned long) offset);
3270 fputs (">: [", stdout);
3271 print_vma (tp->start.offset, PREFIX_HEX);
3272 fputc ('-', stdout);
3273 print_vma (tp->end.offset, PREFIX_HEX);
3274 printf ("), info at +0x%lx\n",
3275 (unsigned long) (tp->info.offset - aux->seg_base));
3277 head = aux->info + (tp->info.offset - aux->info_addr);
3278 stamp = BYTE_GET8 ((unsigned char *) head);
3280 printf (" v%u, flags=0x%lx (%s%s ), len=%lu bytes\n",
3281 (unsigned) UNW_VER (stamp),
3282 (unsigned long) ((stamp & UNW_FLAG_MASK) >> 32),
3283 UNW_FLAG_EHANDLER (stamp) ? " ehandler" : "",
3284 UNW_FLAG_UHANDLER (stamp) ? " uhandler" : "",
3285 (unsigned long) (addr_size * UNW_LENGTH (stamp)));
3287 if (UNW_VER (stamp) != 1)
3289 printf ("\tUnknown version.\n");
3294 for (dp = head + 8; dp < head + 8 + addr_size * UNW_LENGTH (stamp);)
3295 dp = unw_decode (dp, in_body, & in_body);
3300 slurp_ia64_unwind_table (file, aux, sec)
3302 struct unw_aux_info *aux;
3303 Elf32_Internal_Shdr *sec;
3305 unsigned long size, addr_size, nrelas, i;
3306 Elf_Internal_Phdr *prog_hdrs, *seg;
3307 struct unw_table_entry *tep;
3308 Elf32_Internal_Shdr *relsec;
3309 Elf_Internal_Rela *rela, *rp;
3310 unsigned char *table, *tp;
3311 Elf_Internal_Sym *sym;
3312 const char *relname;
3315 addr_size = is_32bit_elf ? 4 : 8;
3317 /* First, find the starting address of the segment that includes
3320 if (elf_header.e_phnum)
3322 prog_hdrs = (Elf_Internal_Phdr *)
3323 xmalloc (elf_header.e_phnum * sizeof (Elf_Internal_Phdr));
3326 result = get_32bit_program_headers (file, prog_hdrs);
3328 result = get_64bit_program_headers (file, prog_hdrs);
3336 for (seg = prog_hdrs; seg < prog_hdrs + elf_header.e_phnum; ++seg)
3338 if (seg->p_type != PT_LOAD)
3341 if (sec->sh_addr >= seg->p_vaddr
3342 && (sec->sh_addr + sec->sh_size <= seg->p_vaddr + seg->p_memsz))
3344 aux->seg_base = seg->p_vaddr;
3352 /* Second, build the unwind table from the contents of the unwind section: */
3353 size = sec->sh_size;
3354 table = (char *) get_data (NULL, file, sec->sh_offset,
3355 size, _("unwind table"));
3359 tep = aux->table = xmalloc (size / (3 * addr_size) * sizeof (aux->table[0]));
3360 for (tp = table; tp < table + size; tp += 3 * addr_size, ++ tep)
3362 tep->start.section = SHN_UNDEF;
3363 tep->end.section = SHN_UNDEF;
3364 tep->info.section = SHN_UNDEF;
3367 tep->start.offset = byte_get ((unsigned char *) tp + 0, 4);
3368 tep->end.offset = byte_get ((unsigned char *) tp + 4, 4);
3369 tep->info.offset = byte_get ((unsigned char *) tp + 8, 4);
3373 tep->start.offset = BYTE_GET8 ((unsigned char *) tp + 0);
3374 tep->end.offset = BYTE_GET8 ((unsigned char *) tp + 8);
3375 tep->info.offset = BYTE_GET8 ((unsigned char *) tp + 16);
3377 tep->start.offset += aux->seg_base;
3378 tep->end.offset += aux->seg_base;
3379 tep->info.offset += aux->seg_base;
3383 /* Third, apply any relocations to the unwind table: */
3385 for (relsec = section_headers;
3386 relsec < section_headers + elf_header.e_shnum;
3389 if (relsec->sh_type != SHT_RELA
3390 || section_headers + relsec->sh_info != sec)
3393 if (!slurp_rela_relocs (file, relsec->sh_offset, relsec->sh_size,
3397 for (rp = rela; rp < rela + nrelas; ++rp)
3401 relname = elf_ia64_reloc_type (ELF32_R_TYPE (rp->r_info));
3402 sym = aux->symtab + ELF32_R_SYM (rp->r_info);
3404 if (ELF32_ST_TYPE (sym->st_info) != STT_SECTION)
3406 warn (_("Skipping unexpected symbol type %u"),
3407 ELF32_ST_TYPE (sym->st_info));
3413 relname = elf_ia64_reloc_type (ELF64_R_TYPE (rp->r_info));
3414 sym = aux->symtab + ELF64_R_SYM (rp->r_info);
3416 if (ELF64_ST_TYPE (sym->st_info) != STT_SECTION)
3418 warn (_("Skipping unexpected symbol type %u"),
3419 ELF64_ST_TYPE (sym->st_info));
3424 if (strncmp (relname, "R_IA64_SEGREL", 13) != 0)
3426 warn (_("Skipping unexpected relocation type %s"), relname);
3430 i = rp->r_offset / (3 * addr_size);
3432 switch (rp->r_offset/addr_size % 3)
3435 aux->table[i].start.section = sym->st_shndx;
3436 aux->table[i].start.offset += rp->r_addend;
3439 aux->table[i].end.section = sym->st_shndx;
3440 aux->table[i].end.offset += rp->r_addend;
3443 aux->table[i].info.section = sym->st_shndx;
3444 aux->table[i].info.offset += rp->r_addend;
3454 aux->table_len = size / (3 * addr_size);
3459 process_unwind (file)
3462 Elf32_Internal_Shdr *sec, *unwsec = NULL, *strsec;
3463 unsigned long i, addr_size, unwcount = 0, unwstart = 0;
3464 struct unw_aux_info aux;
3469 if (elf_header.e_machine != EM_IA_64)
3471 printf (_("\nThere are no unwind sections in this file.\n"));
3475 memset (& aux, 0, sizeof (aux));
3477 addr_size = is_32bit_elf ? 4 : 8;
3479 for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec)
3481 if (sec->sh_type == SHT_SYMTAB)
3483 aux.nsyms = sec->sh_size / sec->sh_entsize;
3484 aux.symtab = GET_ELF_SYMBOLS (file, sec->sh_offset, aux.nsyms);
3486 strsec = section_headers + sec->sh_link;
3487 aux.strtab_size = strsec->sh_size;
3488 aux.strtab = (char *) get_data (NULL, file, strsec->sh_offset,
3489 aux.strtab_size, _("string table"));
3491 else if (sec->sh_type == SHT_IA_64_UNWIND)
3496 printf (_("\nThere are no unwind sections in this file.\n"));
3498 while (unwcount-- > 0)
3503 for (i = unwstart, sec = section_headers + unwstart;
3504 i < elf_header.e_shnum; ++i, ++sec)
3505 if (sec->sh_type == SHT_IA_64_UNWIND)
3512 len = sizeof (ELF_STRING_ia64_unwind_once) - 1;
3514 if (strncmp (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind_once,
3517 /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO */
3518 len2 = sizeof (ELF_STRING_ia64_unwind_info_once) - 1;
3519 suffix = SECTION_NAME (unwsec) + len;
3520 for (i = 0, sec = section_headers; i < elf_header.e_shnum;
3522 if (strncmp (SECTION_NAME (sec),
3523 ELF_STRING_ia64_unwind_info_once, len2) == 0
3524 && strcmp (SECTION_NAME (sec) + len2, suffix) == 0)
3529 /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO
3530 .IA_64.unwind or BAR -> .IA_64.unwind_info */
3531 len = sizeof (ELF_STRING_ia64_unwind) - 1;
3532 len2 = sizeof (ELF_STRING_ia64_unwind_info) - 1;
3534 if (strncmp (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind,
3536 suffix = SECTION_NAME (unwsec) + len;
3537 for (i = 0, sec = section_headers; i < elf_header.e_shnum;
3539 if (strncmp (SECTION_NAME (sec),
3540 ELF_STRING_ia64_unwind_info, len2) == 0
3541 && strcmp (SECTION_NAME (sec) + len2, suffix) == 0)
3545 if (i == elf_header.e_shnum)
3547 printf (_("\nCould not find unwind info section for "));
3549 if (string_table == NULL)
3550 printf ("%d", unwsec->sh_name);
3552 printf ("'%s'", SECTION_NAME (unwsec));
3556 aux.info_size = sec->sh_size;
3557 aux.info_addr = sec->sh_addr;
3558 aux.info = (char *) get_data (NULL, file, sec->sh_offset,
3559 aux.info_size, _("unwind info"));
3561 printf (_("\nUnwind section "));
3563 if (string_table == NULL)
3564 printf ("%d", unwsec->sh_name);
3566 printf ("'%s'", SECTION_NAME (unwsec));
3568 printf (_(" at offset 0x%lx contains %lu entries:\n"),
3570 (unsigned long) (unwsec->sh_size / (3 * addr_size)));
3572 (void) slurp_ia64_unwind_table (file, & aux, unwsec);
3574 if (aux.table_len > 0)
3575 dump_ia64_unwind (& aux);
3578 free ((char *) aux.table);
3580 free ((char *) aux.info);
3589 free ((char *) aux.strtab);
3595 dynamic_segment_mips_val (entry)
3596 Elf_Internal_Dyn * entry;
3598 switch (entry->d_tag)
3601 if (entry->d_un.d_val == 0)
3605 static const char * opts[] =
3607 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
3608 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
3609 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
3610 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
3615 for (cnt = 0; cnt < NUM_ELEM (opts); ++ cnt)
3616 if (entry->d_un.d_val & (1 << cnt))
3618 printf ("%s%s", first ? "" : " ", opts[cnt]);
3625 case DT_MIPS_IVERSION:
3626 if (dynamic_strings != NULL)
3627 printf ("Interface Version: %s\n",
3628 dynamic_strings + entry->d_un.d_val);
3630 printf ("%ld\n", (long) entry->d_un.d_ptr);
3633 case DT_MIPS_TIME_STAMP:
3638 time_t time = entry->d_un.d_val;
3639 tmp = gmtime (&time);
3640 sprintf (timebuf, "%04u-%02u-%02uT%02u:%02u:%02u",
3641 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
3642 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
3643 printf ("Time Stamp: %s\n", timebuf);
3647 case DT_MIPS_RLD_VERSION:
3648 case DT_MIPS_LOCAL_GOTNO:
3649 case DT_MIPS_CONFLICTNO:
3650 case DT_MIPS_LIBLISTNO:
3651 case DT_MIPS_SYMTABNO:
3652 case DT_MIPS_UNREFEXTNO:
3653 case DT_MIPS_HIPAGENO:
3654 case DT_MIPS_DELTA_CLASS_NO:
3655 case DT_MIPS_DELTA_INSTANCE_NO:
3656 case DT_MIPS_DELTA_RELOC_NO:
3657 case DT_MIPS_DELTA_SYM_NO:
3658 case DT_MIPS_DELTA_CLASSSYM_NO:
3659 case DT_MIPS_COMPACT_SIZE:
3660 printf ("%ld\n", (long) entry->d_un.d_ptr);
3664 printf ("%#lx\n", (long) entry->d_un.d_ptr);
3670 dynamic_segment_parisc_val (entry)
3671 Elf_Internal_Dyn * entry;
3673 switch (entry->d_tag)
3675 case DT_HP_DLD_FLAGS:
3684 { DT_HP_DEBUG_PRIVATE, "HP_DEBUG_PRIVATE" },
3685 { DT_HP_DEBUG_CALLBACK, "HP_DEBUG_CALLBACK" },
3686 { DT_HP_DEBUG_CALLBACK_BOR, "HP_DEBUG_CALLBACK_BOR" },
3687 { DT_HP_NO_ENVVAR, "HP_NO_ENVVAR" },
3688 { DT_HP_BIND_NOW, "HP_BIND_NOW" },
3689 { DT_HP_BIND_NONFATAL, "HP_BIND_NONFATAL" },
3690 { DT_HP_BIND_VERBOSE, "HP_BIND_VERBOSE" },
3691 { DT_HP_BIND_RESTRICTED, "HP_BIND_RESTRICTED" },
3692 { DT_HP_BIND_SYMBOLIC, "HP_BIND_SYMBOLIC" },
3693 { DT_HP_RPATH_FIRST, "HP_RPATH_FIRST" },
3694 { DT_HP_BIND_DEPTH_FIRST, "HP_BIND_DEPTH_FIRST" }
3698 bfd_vma val = entry->d_un.d_val;
3700 for (cnt = 0; cnt < sizeof (flags) / sizeof (flags[0]); ++cnt)
3701 if (val & flags[cnt].bit)
3705 fputs (flags[cnt].str, stdout);
3707 val ^= flags[cnt].bit;
3710 if (val != 0 || first)
3714 print_vma (val, HEX);
3720 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
3726 get_32bit_dynamic_segment (file)
3729 Elf32_External_Dyn * edyn;
3730 Elf_Internal_Dyn * entry;
3733 edyn = (Elf32_External_Dyn *) get_data (NULL, file, dynamic_addr,
3734 dynamic_size, _("dynamic segment"));
3738 /* SGI's ELF has more than one section in the DYNAMIC segment. Determine
3739 how large this .dynamic is now. We can do this even before the byte
3740 swapping since the DT_NULL tag is recognizable. */
3742 while (*(Elf32_Word *) edyn [dynamic_size++].d_tag != DT_NULL)
3745 dynamic_segment = (Elf_Internal_Dyn *)
3746 malloc (dynamic_size * sizeof (Elf_Internal_Dyn));
3748 if (dynamic_segment == NULL)
3750 error (_("Out of memory\n"));
3755 for (i = 0, entry = dynamic_segment;
3759 entry->d_tag = BYTE_GET (edyn [i].d_tag);
3760 entry->d_un.d_val = BYTE_GET (edyn [i].d_un.d_val);
3769 get_64bit_dynamic_segment (file)
3772 Elf64_External_Dyn * edyn;
3773 Elf_Internal_Dyn * entry;
3776 edyn = (Elf64_External_Dyn *) get_data (NULL, file, dynamic_addr,
3777 dynamic_size, _("dynamic segment"));
3781 /* SGI's ELF has more than one section in the DYNAMIC segment. Determine
3782 how large this .dynamic is now. We can do this even before the byte
3783 swapping since the DT_NULL tag is recognizable. */
3785 while (*(bfd_vma *) edyn [dynamic_size ++].d_tag != DT_NULL)
3788 dynamic_segment = (Elf_Internal_Dyn *)
3789 malloc (dynamic_size * sizeof (Elf_Internal_Dyn));
3791 if (dynamic_segment == NULL)
3793 error (_("Out of memory\n"));
3798 for (i = 0, entry = dynamic_segment;
3802 entry->d_tag = BYTE_GET8 (edyn [i].d_tag);
3803 entry->d_un.d_val = BYTE_GET8 (edyn [i].d_un.d_val);
3812 get_dynamic_flags (flags)
3815 static char buff [64];
3820 flag = flags & - flags;
3825 case DF_ORIGIN: strcat (buff, "ORIGIN "); break;
3826 case DF_SYMBOLIC: strcat (buff, "SYMBOLIC "); break;
3827 case DF_TEXTREL: strcat (buff, "TEXTREL "); break;
3828 case DF_BIND_NOW: strcat (buff, "BIND_NOW "); break;
3829 default: strcat (buff, "unknown "); break;
3835 /* Parse and display the contents of the dynamic segment. */
3837 process_dynamic_segment (file)
3840 Elf_Internal_Dyn * entry;
3843 if (dynamic_size == 0)
3846 printf (_("\nThere is no dynamic segment in this file.\n"));
3853 if (! get_32bit_dynamic_segment (file))
3856 else if (! get_64bit_dynamic_segment (file))
3859 /* Find the appropriate symbol table. */
3860 if (dynamic_symbols == NULL)
3862 for (i = 0, entry = dynamic_segment;
3866 unsigned long offset;
3868 if (entry->d_tag != DT_SYMTAB)
3871 dynamic_info[DT_SYMTAB] = entry->d_un.d_val;
3873 /* Since we do not know how big the symbol table is,
3874 we default to reading in the entire file (!) and
3875 processing that. This is overkill, I know, but it
3877 offset = entry->d_un.d_val - loadaddr;
3879 if (fseek (file, 0, SEEK_END))
3880 error (_("Unable to seek to end of file!"));
3883 num_dynamic_syms = (ftell (file) - offset) / sizeof (Elf32_External_Sym);
3885 num_dynamic_syms = (ftell (file) - offset) / sizeof (Elf64_External_Sym);
3887 if (num_dynamic_syms < 1)
3889 error (_("Unable to determine the number of symbols to load\n"));
3893 dynamic_symbols = GET_ELF_SYMBOLS (file, offset, num_dynamic_syms);
3897 /* Similarly find a string table. */
3898 if (dynamic_strings == NULL)
3900 for (i = 0, entry = dynamic_segment;
3904 unsigned long offset;
3907 if (entry->d_tag != DT_STRTAB)
3910 dynamic_info[DT_STRTAB] = entry->d_un.d_val;
3912 /* Since we do not know how big the string table is,
3913 we default to reading in the entire file (!) and
3914 processing that. This is overkill, I know, but it
3917 offset = entry->d_un.d_val - loadaddr;
3918 if (fseek (file, 0, SEEK_END))
3919 error (_("Unable to seek to end of file\n"));
3920 str_tab_len = ftell (file) - offset;
3922 if (str_tab_len < 1)
3925 (_("Unable to determine the length of the dynamic string table\n"));
3929 dynamic_strings = (char *) get_data (NULL, file, offset, str_tab_len,
3930 _("dynamic string table"));
3936 /* And find the syminfo section if available. */
3937 if (dynamic_syminfo == NULL)
3939 unsigned int syminsz = 0;
3941 for (i = 0, entry = dynamic_segment;
3945 if (entry->d_tag == DT_SYMINENT)
3947 /* Note: these braces are necessary to avoid a syntax
3948 error from the SunOS4 C compiler. */
3949 assert (sizeof (Elf_External_Syminfo) == entry->d_un.d_val);
3951 else if (entry->d_tag == DT_SYMINSZ)
3952 syminsz = entry->d_un.d_val;
3953 else if (entry->d_tag == DT_SYMINFO)
3954 dynamic_syminfo_offset = entry->d_un.d_val - loadaddr;
3957 if (dynamic_syminfo_offset != 0 && syminsz != 0)
3959 Elf_External_Syminfo * extsyminfo;
3960 Elf_Internal_Syminfo * syminfo;
3962 /* There is a syminfo section. Read the data. */
3963 extsyminfo = ((Elf_External_Syminfo *)
3964 get_data (NULL, file, dynamic_syminfo_offset,
3965 syminsz, _("symbol information")));
3969 dynamic_syminfo = (Elf_Internal_Syminfo *) malloc (syminsz);
3970 if (dynamic_syminfo == NULL)
3972 error (_("Out of memory\n"));
3976 dynamic_syminfo_nent = syminsz / sizeof (Elf_External_Syminfo);
3977 for (i = 0, syminfo = dynamic_syminfo; i < dynamic_syminfo_nent;
3980 syminfo->si_boundto = BYTE_GET (extsyminfo[i].si_boundto);
3981 syminfo->si_flags = BYTE_GET (extsyminfo[i].si_flags);
3988 if (do_dynamic && dynamic_addr)
3989 printf (_("\nDynamic segment at offset 0x%x contains %ld entries:\n"),
3990 dynamic_addr, (long) dynamic_size);
3992 printf (_(" Tag Type Name/Value\n"));
3994 for (i = 0, entry = dynamic_segment;
4003 print_vma (entry->d_tag, FULL_HEX);
4004 dtype = get_dynamic_type (entry->d_tag);
4005 printf (" (%s)%*s", dtype,
4006 ((is_32bit_elf ? 27 : 19)
4007 - (int) strlen (dtype)),
4011 switch (entry->d_tag)
4015 printf ("%s", get_dynamic_flags (entry->d_un.d_val));
4025 switch (entry->d_tag)
4028 printf (_("Auxiliary library"));
4032 printf (_("Filter library"));
4036 printf (_("Configuration file"));
4040 printf (_("Dependency audit library"));
4044 printf (_("Audit library"));
4048 if (dynamic_strings)
4049 printf (": [%s]\n", dynamic_strings + entry->d_un.d_val);
4053 print_vma (entry->d_un.d_val, PREFIX_HEX);
4062 printf (_("Flags:"));
4063 if (entry->d_un.d_val == 0)
4064 printf (_(" None\n"));
4067 unsigned long int val = entry->d_un.d_val;
4068 if (val & DTF_1_PARINIT)
4070 printf (" PARINIT");
4071 val ^= DTF_1_PARINIT;
4073 if (val & DTF_1_CONFEXP)
4075 printf (" CONFEXP");
4076 val ^= DTF_1_CONFEXP;
4079 printf (" %lx", val);
4088 printf (_("Flags:"));
4089 if (entry->d_un.d_val == 0)
4090 printf (_(" None\n"));
4093 unsigned long int val = entry->d_un.d_val;
4094 if (val & DF_P1_LAZYLOAD)
4096 printf (" LAZYLOAD");
4097 val ^= DF_P1_LAZYLOAD;
4099 if (val & DF_P1_GROUPPERM)
4101 printf (" GROUPPERM");
4102 val ^= DF_P1_GROUPPERM;
4105 printf (" %lx", val);
4114 printf (_("Flags:"));
4115 if (entry->d_un.d_val == 0)
4116 printf (_(" None\n"));
4119 unsigned long int val = entry->d_un.d_val;
4125 if (val & DF_1_GLOBAL)
4130 if (val & DF_1_GROUP)
4135 if (val & DF_1_NODELETE)
4137 printf (" NODELETE");
4138 val ^= DF_1_NODELETE;
4140 if (val & DF_1_LOADFLTR)
4142 printf (" LOADFLTR");
4143 val ^= DF_1_LOADFLTR;
4145 if (val & DF_1_INITFIRST)
4147 printf (" INITFIRST");
4148 val ^= DF_1_INITFIRST;
4150 if (val & DF_1_NOOPEN)
4155 if (val & DF_1_ORIGIN)
4160 if (val & DF_1_DIRECT)
4165 if (val & DF_1_TRANS)
4170 if (val & DF_1_INTERPOSE)
4172 printf (" INTERPOSE");
4173 val ^= DF_1_INTERPOSE;
4175 if (val & DF_1_NODEFLIB)
4177 printf (" NODEFLIB");
4178 val ^= DF_1_NODEFLIB;
4180 if (val & DF_1_NODUMP)
4185 if (val & DF_1_CONLFAT)
4187 printf (" CONLFAT");
4188 val ^= DF_1_CONLFAT;
4191 printf (" %lx", val);
4199 puts (get_dynamic_type (entry->d_un.d_val));
4219 dynamic_info[entry->d_tag] = entry->d_un.d_val;
4225 if (dynamic_strings == NULL)
4228 name = dynamic_strings + entry->d_un.d_val;
4232 switch (entry->d_tag)
4235 printf (_("Shared library: [%s]"), name);
4237 if (strcmp (name, program_interpreter) == 0)
4238 printf (_(" program interpreter"));
4242 printf (_("Library soname: [%s]"), name);
4246 printf (_("Library rpath: [%s]"), name);
4250 printf (_("Library runpath: [%s]"), name);
4254 print_vma (entry->d_un.d_val, PREFIX_HEX);
4259 print_vma (entry->d_un.d_val, PREFIX_HEX);
4275 case DT_INIT_ARRAYSZ:
4276 case DT_FINI_ARRAYSZ:
4279 print_vma (entry->d_un.d_val, UNSIGNED);
4280 printf (" (bytes)\n");
4290 print_vma (entry->d_un.d_val, UNSIGNED);
4303 if (dynamic_strings != NULL && entry->d_tag == DT_USED)
4307 name = dynamic_strings + entry->d_un.d_val;
4311 printf (_("Not needed object: [%s]\n"), name);
4316 print_vma (entry->d_un.d_val, PREFIX_HEX);
4322 /* The value of this entry is ignored. */
4326 if ((entry->d_tag >= DT_VERSYM) && (entry->d_tag <= DT_VERNEEDNUM))
4327 version_info [DT_VERSIONTAGIDX (entry->d_tag)] =
4332 switch (elf_header.e_machine)
4335 case EM_MIPS_RS3_LE:
4336 dynamic_segment_mips_val (entry);
4339 dynamic_segment_parisc_val (entry);
4342 print_vma (entry->d_un.d_val, PREFIX_HEX);
4354 get_ver_flags (flags)
4357 static char buff [32];
4364 if (flags & VER_FLG_BASE)
4365 strcat (buff, "BASE ");
4367 if (flags & VER_FLG_WEAK)
4369 if (flags & VER_FLG_BASE)
4370 strcat (buff, "| ");
4372 strcat (buff, "WEAK ");
4375 if (flags & ~(VER_FLG_BASE | VER_FLG_WEAK))
4376 strcat (buff, "| <unknown>");
4381 /* Display the contents of the version sections. */
4383 process_version_sections (file)
4386 Elf32_Internal_Shdr * section;
4393 for (i = 0, section = section_headers;
4394 i < elf_header.e_shnum;
4397 switch (section->sh_type)
4399 case SHT_GNU_verdef:
4401 Elf_External_Verdef * edefs;
4408 (_("\nVersion definition section '%s' contains %ld entries:\n"),
4409 SECTION_NAME (section), section->sh_info);
4411 printf (_(" Addr: 0x"));
4412 printf_vma (section->sh_addr);
4413 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
4414 (unsigned long) section->sh_offset, section->sh_link,
4415 SECTION_NAME (section_headers + section->sh_link));
4417 edefs = ((Elf_External_Verdef *)
4418 get_data (NULL, file, section->sh_offset,
4420 _("version definition section")));
4424 for (idx = cnt = 0; cnt < section->sh_info; ++ cnt)
4427 Elf_External_Verdef * edef;
4428 Elf_Internal_Verdef ent;
4429 Elf_External_Verdaux * eaux;
4430 Elf_Internal_Verdaux aux;
4434 vstart = ((char *) edefs) + idx;
4436 edef = (Elf_External_Verdef *) vstart;
4438 ent.vd_version = BYTE_GET (edef->vd_version);
4439 ent.vd_flags = BYTE_GET (edef->vd_flags);
4440 ent.vd_ndx = BYTE_GET (edef->vd_ndx);
4441 ent.vd_cnt = BYTE_GET (edef->vd_cnt);
4442 ent.vd_hash = BYTE_GET (edef->vd_hash);
4443 ent.vd_aux = BYTE_GET (edef->vd_aux);
4444 ent.vd_next = BYTE_GET (edef->vd_next);
4446 printf (_(" %#06x: Rev: %d Flags: %s"),
4447 idx, ent.vd_version, get_ver_flags (ent.vd_flags));
4449 printf (_(" Index: %d Cnt: %d "),
4450 ent.vd_ndx, ent.vd_cnt);
4452 vstart += ent.vd_aux;
4454 eaux = (Elf_External_Verdaux *) vstart;
4456 aux.vda_name = BYTE_GET (eaux->vda_name);
4457 aux.vda_next = BYTE_GET (eaux->vda_next);
4459 if (dynamic_strings)
4460 printf (_("Name: %s\n"), dynamic_strings + aux.vda_name);
4462 printf (_("Name index: %ld\n"), aux.vda_name);
4464 isum = idx + ent.vd_aux;
4466 for (j = 1; j < ent.vd_cnt; j ++)
4468 isum += aux.vda_next;
4469 vstart += aux.vda_next;
4471 eaux = (Elf_External_Verdaux *) vstart;
4473 aux.vda_name = BYTE_GET (eaux->vda_name);
4474 aux.vda_next = BYTE_GET (eaux->vda_next);
4476 if (dynamic_strings)
4477 printf (_(" %#06x: Parent %d: %s\n"),
4478 isum, j, dynamic_strings + aux.vda_name);
4480 printf (_(" %#06x: Parent %d, name index: %ld\n"),
4481 isum, j, aux.vda_name);
4491 case SHT_GNU_verneed:
4493 Elf_External_Verneed * eneed;
4499 printf (_("\nVersion needs section '%s' contains %ld entries:\n"),
4500 SECTION_NAME (section), section->sh_info);
4502 printf (_(" Addr: 0x"));
4503 printf_vma (section->sh_addr);
4504 printf (_(" Offset: %#08lx Link to section: %ld (%s)\n"),
4505 (unsigned long) section->sh_offset, section->sh_link,
4506 SECTION_NAME (section_headers + section->sh_link));
4508 eneed = ((Elf_External_Verneed *)
4509 get_data (NULL, file, section->sh_offset,
4510 section->sh_size, _("version need section")));
4514 for (idx = cnt = 0; cnt < section->sh_info; ++cnt)
4516 Elf_External_Verneed * entry;
4517 Elf_Internal_Verneed ent;
4522 vstart = ((char *) eneed) + idx;
4524 entry = (Elf_External_Verneed *) vstart;
4526 ent.vn_version = BYTE_GET (entry->vn_version);
4527 ent.vn_cnt = BYTE_GET (entry->vn_cnt);
4528 ent.vn_file = BYTE_GET (entry->vn_file);
4529 ent.vn_aux = BYTE_GET (entry->vn_aux);
4530 ent.vn_next = BYTE_GET (entry->vn_next);
4532 printf (_(" %#06x: Version: %d"), idx, ent.vn_version);
4534 if (dynamic_strings)
4535 printf (_(" File: %s"), dynamic_strings + ent.vn_file);
4537 printf (_(" File: %lx"), ent.vn_file);
4539 printf (_(" Cnt: %d\n"), ent.vn_cnt);
4541 vstart += ent.vn_aux;
4543 for (j = 0, isum = idx + ent.vn_aux; j < ent.vn_cnt; ++j)
4545 Elf_External_Vernaux * eaux;
4546 Elf_Internal_Vernaux aux;
4548 eaux = (Elf_External_Vernaux *) vstart;
4550 aux.vna_hash = BYTE_GET (eaux->vna_hash);
4551 aux.vna_flags = BYTE_GET (eaux->vna_flags);
4552 aux.vna_other = BYTE_GET (eaux->vna_other);
4553 aux.vna_name = BYTE_GET (eaux->vna_name);
4554 aux.vna_next = BYTE_GET (eaux->vna_next);
4556 if (dynamic_strings)
4557 printf (_(" %#06x: Name: %s"),
4558 isum, dynamic_strings + aux.vna_name);
4560 printf (_(" %#06x: Name index: %lx"),
4561 isum, aux.vna_name);
4563 printf (_(" Flags: %s Version: %d\n"),
4564 get_ver_flags (aux.vna_flags), aux.vna_other);
4566 isum += aux.vna_next;
4567 vstart += aux.vna_next;
4577 case SHT_GNU_versym:
4579 Elf32_Internal_Shdr * link_section;
4582 unsigned char * edata;
4583 unsigned short * data;
4585 Elf_Internal_Sym * symbols;
4586 Elf32_Internal_Shdr * string_sec;
4588 link_section = section_headers + section->sh_link;
4589 total = section->sh_size / section->sh_entsize;
4593 symbols = GET_ELF_SYMBOLS (file, link_section->sh_offset,
4594 link_section->sh_size / link_section->sh_entsize);
4596 string_sec = section_headers + link_section->sh_link;
4598 strtab = (char *) get_data (NULL, file, string_sec->sh_offset,
4599 string_sec->sh_size,
4600 _("version string table"));
4604 printf (_("\nVersion symbols section '%s' contains %d entries:\n"),
4605 SECTION_NAME (section), total);
4607 printf (_(" Addr: "));
4608 printf_vma (section->sh_addr);
4609 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
4610 (unsigned long) section->sh_offset, section->sh_link,
4611 SECTION_NAME (link_section));
4615 get_data (NULL, file,
4616 version_info[DT_VERSIONTAGIDX (DT_VERSYM)] - loadaddr,
4617 total * sizeof (short), _("version symbol data")));
4624 data = (unsigned short *) malloc (total * sizeof (short));
4626 for (cnt = total; cnt --;)
4627 data [cnt] = byte_get (edata + cnt * sizeof (short),
4632 for (cnt = 0; cnt < total; cnt += 4)
4635 int check_def, check_need;
4638 printf (" %03x:", cnt);
4640 for (j = 0; (j < 4) && (cnt + j) < total; ++j)
4641 switch (data [cnt + j])
4644 fputs (_(" 0 (*local*) "), stdout);
4648 fputs (_(" 1 (*global*) "), stdout);
4652 nn = printf ("%4x%c", data [cnt + j] & 0x7fff,
4653 data [cnt + j] & 0x8000 ? 'h' : ' ');
4657 if (symbols [cnt + j].st_shndx >= SHN_LORESERVE
4658 || section_headers[symbols [cnt + j].st_shndx].sh_type
4661 if (symbols [cnt + j].st_shndx == SHN_UNDEF)
4668 && version_info [DT_VERSIONTAGIDX (DT_VERNEED)])
4670 Elf_Internal_Verneed ivn;
4671 unsigned long offset;
4673 offset = version_info [DT_VERSIONTAGIDX (DT_VERNEED)]
4678 Elf_Internal_Vernaux ivna;
4679 Elf_External_Verneed evn;
4680 Elf_External_Vernaux evna;
4681 unsigned long a_off;
4683 get_data (&evn, file, offset, sizeof (evn),
4686 ivn.vn_aux = BYTE_GET (evn.vn_aux);
4687 ivn.vn_next = BYTE_GET (evn.vn_next);
4689 a_off = offset + ivn.vn_aux;
4693 get_data (&evna, file, a_off, sizeof (evna),
4694 _("version need aux (2)"));
4696 ivna.vna_next = BYTE_GET (evna.vna_next);
4697 ivna.vna_other = BYTE_GET (evna.vna_other);
4699 a_off += ivna.vna_next;
4701 while (ivna.vna_other != data [cnt + j]
4702 && ivna.vna_next != 0);
4704 if (ivna.vna_other == data [cnt + j])
4706 ivna.vna_name = BYTE_GET (evna.vna_name);
4708 name = strtab + ivna.vna_name;
4709 nn += printf ("(%s%-*s",
4711 12 - (int) strlen (name),
4717 offset += ivn.vn_next;
4719 while (ivn.vn_next);
4722 if (check_def && data [cnt + j] != 0x8001
4723 && version_info [DT_VERSIONTAGIDX (DT_VERDEF)])
4725 Elf_Internal_Verdef ivd;
4726 Elf_External_Verdef evd;
4727 unsigned long offset;
4729 offset = version_info
4730 [DT_VERSIONTAGIDX (DT_VERDEF)] - loadaddr;
4734 get_data (&evd, file, offset, sizeof (evd),
4737 ivd.vd_next = BYTE_GET (evd.vd_next);
4738 ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
4740 offset += ivd.vd_next;
4742 while (ivd.vd_ndx != (data [cnt + j] & 0x7fff)
4743 && ivd.vd_next != 0);
4745 if (ivd.vd_ndx == (data [cnt + j] & 0x7fff))
4747 Elf_External_Verdaux evda;
4748 Elf_Internal_Verdaux ivda;
4750 ivd.vd_aux = BYTE_GET (evd.vd_aux);
4752 get_data (&evda, file,
4753 offset - ivd.vd_next + ivd.vd_aux,
4754 sizeof (evda), _("version def aux"));
4756 ivda.vda_name = BYTE_GET (evda.vda_name);
4758 name = strtab + ivda.vda_name;
4759 nn += printf ("(%s%-*s",
4761 12 - (int) strlen (name),
4767 printf ("%*c", 18 - nn, ' ');
4785 printf (_("\nNo version information found in this file.\n"));
4791 get_symbol_binding (binding)
4792 unsigned int binding;
4794 static char buff [32];
4798 case STB_LOCAL: return "LOCAL";
4799 case STB_GLOBAL: return "GLOBAL";
4800 case STB_WEAK: return "WEAK";
4802 if (binding >= STB_LOPROC && binding <= STB_HIPROC)
4803 sprintf (buff, _("<processor specific>: %d"), binding);
4804 else if (binding >= STB_LOOS && binding <= STB_HIOS)
4805 sprintf (buff, _("<OS specific>: %d"), binding);
4807 sprintf (buff, _("<unknown>: %d"), binding);
4813 get_symbol_type (type)
4816 static char buff [32];
4820 case STT_NOTYPE: return "NOTYPE";
4821 case STT_OBJECT: return "OBJECT";
4822 case STT_FUNC: return "FUNC";
4823 case STT_SECTION: return "SECTION";
4824 case STT_FILE: return "FILE";
4825 case STT_COMMON: return "COMMON";
4827 if (type >= STT_LOPROC && type <= STT_HIPROC)
4829 if (elf_header.e_machine == EM_ARM && type == STT_ARM_TFUNC)
4830 return "THUMB_FUNC";
4832 if (elf_header.e_machine == EM_SPARCV9 && type == STT_REGISTER)
4835 if (elf_header.e_machine == EM_PARISC && type == STT_PARISC_MILLI)
4836 return "PARISC_MILLI";
4838 sprintf (buff, _("<processor specific>: %d"), type);
4840 else if (type >= STT_LOOS && type <= STT_HIOS)
4842 if (elf_header.e_machine == EM_PARISC)
4844 if (type == STT_HP_OPAQUE)
4846 if (type == STT_HP_STUB)
4850 sprintf (buff, _("<OS specific>: %d"), type);
4853 sprintf (buff, _("<unknown>: %d"), type);
4859 get_symbol_visibility (visibility)
4860 unsigned int visibility;
4864 case STV_DEFAULT: return "DEFAULT";
4865 case STV_INTERNAL: return "INTERNAL";
4866 case STV_HIDDEN: return "HIDDEN";
4867 case STV_PROTECTED: return "PROTECTED";
4873 get_symbol_index_type (type)
4878 case SHN_UNDEF: return "UND";
4879 case SHN_ABS: return "ABS";
4880 case SHN_COMMON: return "COM";
4882 if (type >= SHN_LOPROC && type <= SHN_HIPROC)
4884 else if (type >= SHN_LORESERVE && type <= SHN_HIRESERVE)
4886 else if (type >= SHN_LOOS && type <= SHN_HIOS)
4890 static char buff [32];
4892 sprintf (buff, "%3d", type);
4899 get_dynamic_data (file, number)
4901 unsigned int number;
4903 unsigned char * e_data;
4906 e_data = (unsigned char *) malloc (number * 4);
4910 error (_("Out of memory\n"));
4914 if (fread (e_data, 4, number, file) != number)
4916 error (_("Unable to read in dynamic data\n"));
4920 i_data = (int *) malloc (number * sizeof (* i_data));
4924 error (_("Out of memory\n"));
4930 i_data [number] = byte_get (e_data + number * 4, 4);
4937 /* Dump the symbol table */
4939 process_symbol_table (file)
4942 Elf32_Internal_Shdr * section;
4943 unsigned char nb [4];
4944 unsigned char nc [4];
4947 int * buckets = NULL;
4948 int * chains = NULL;
4950 if (! do_syms && !do_histogram)
4953 if (dynamic_info[DT_HASH] && ((do_using_dynamic && dynamic_strings != NULL)
4956 if (fseek (file, dynamic_info[DT_HASH] - loadaddr, SEEK_SET))
4958 error (_("Unable to seek to start of dynamic information"));
4962 if (fread (nb, sizeof (nb), 1, file) != 1)
4964 error (_("Failed to read in number of buckets\n"));
4968 if (fread (nc, sizeof (nc), 1, file) != 1)
4970 error (_("Failed to read in number of chains\n"));
4974 nbuckets = byte_get (nb, 4);
4975 nchains = byte_get (nc, 4);
4977 buckets = get_dynamic_data (file, nbuckets);
4978 chains = get_dynamic_data (file, nchains);
4980 if (buckets == NULL || chains == NULL)
4985 && dynamic_info[DT_HASH] && do_using_dynamic && dynamic_strings != NULL)
4990 printf (_("\nSymbol table for image:\n"));
4992 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
4994 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
4996 for (hn = 0; hn < nbuckets; hn++)
5001 for (si = buckets [hn]; si < nchains && si > 0; si = chains [si])
5003 Elf_Internal_Sym * psym;
5005 psym = dynamic_symbols + si;
5007 printf (" %3d %3d: ", si, hn);
5008 print_vma (psym->st_value, LONG_HEX);
5010 print_vma (psym->st_size, DEC_5);
5012 printf (" %6s", get_symbol_type (ELF_ST_TYPE (psym->st_info)));
5013 printf (" %6s", get_symbol_binding (ELF_ST_BIND (psym->st_info)));
5014 printf (" %3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym->st_other)));
5015 printf (" %3.3s", get_symbol_index_type (psym->st_shndx));
5016 printf (" %s\n", dynamic_strings + psym->st_name);
5020 else if (do_syms && !do_using_dynamic)
5024 for (i = 0, section = section_headers;
5025 i < elf_header.e_shnum;
5030 Elf_Internal_Sym * symtab;
5031 Elf_Internal_Sym * psym;
5034 if ( section->sh_type != SHT_SYMTAB
5035 && section->sh_type != SHT_DYNSYM)
5038 printf (_("\nSymbol table '%s' contains %lu entries:\n"),
5039 SECTION_NAME (section),
5040 (unsigned long) (section->sh_size / section->sh_entsize));
5042 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
5044 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
5046 symtab = GET_ELF_SYMBOLS (file, section->sh_offset,
5047 section->sh_size / section->sh_entsize);
5051 if (section->sh_link == elf_header.e_shstrndx)
5052 strtab = string_table;
5055 Elf32_Internal_Shdr * string_sec;
5057 string_sec = section_headers + section->sh_link;
5059 strtab = (char *) get_data (NULL, file, string_sec->sh_offset,
5060 string_sec->sh_size,
5064 for (si = 0, psym = symtab;
5065 si < section->sh_size / section->sh_entsize;
5068 printf ("%6d: ", si);
5069 print_vma (psym->st_value, LONG_HEX);
5071 print_vma (psym->st_size, DEC_5);
5072 printf (" %-7s", get_symbol_type (ELF_ST_TYPE (psym->st_info)));
5073 printf (" %-6s", get_symbol_binding (ELF_ST_BIND (psym->st_info)));
5074 printf (" %-3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym->st_other)));
5075 printf (" %4s", get_symbol_index_type (psym->st_shndx));
5076 printf (" %s", strtab + psym->st_name);
5078 if (section->sh_type == SHT_DYNSYM &&
5079 version_info [DT_VERSIONTAGIDX (DT_VERSYM)] != 0)
5081 unsigned char data[2];
5082 unsigned short vers_data;
5083 unsigned long offset;
5087 offset = version_info [DT_VERSIONTAGIDX (DT_VERSYM)]
5090 get_data (&data, file, offset + si * sizeof (vers_data),
5091 sizeof (data), _("version data"));
5093 vers_data = byte_get (data, 2);
5095 is_nobits = psym->st_shndx < SHN_LORESERVE ?
5096 (section_headers [psym->st_shndx].sh_type == SHT_NOBITS)
5099 check_def = (psym->st_shndx != SHN_UNDEF);
5101 if ((vers_data & 0x8000) || vers_data > 1)
5103 if (version_info [DT_VERSIONTAGIDX (DT_VERNEED)]
5104 && (is_nobits || ! check_def))
5106 Elf_External_Verneed evn;
5107 Elf_Internal_Verneed ivn;
5108 Elf_Internal_Vernaux ivna;
5110 /* We must test both. */
5111 offset = version_info
5112 [DT_VERSIONTAGIDX (DT_VERNEED)] - loadaddr;
5116 unsigned long vna_off;
5118 get_data (&evn, file, offset, sizeof (evn),
5121 ivn.vn_aux = BYTE_GET (evn.vn_aux);
5122 ivn.vn_next = BYTE_GET (evn.vn_next);
5124 vna_off = offset + ivn.vn_aux;
5128 Elf_External_Vernaux evna;
5130 get_data (&evna, file, vna_off,
5132 _("version need aux (3)"));
5134 ivna.vna_other = BYTE_GET (evna.vna_other);
5135 ivna.vna_next = BYTE_GET (evna.vna_next);
5136 ivna.vna_name = BYTE_GET (evna.vna_name);
5138 vna_off += ivna.vna_next;
5140 while (ivna.vna_other != vers_data
5141 && ivna.vna_next != 0);
5143 if (ivna.vna_other == vers_data)
5146 offset += ivn.vn_next;
5148 while (ivn.vn_next != 0);
5150 if (ivna.vna_other == vers_data)
5153 strtab + ivna.vna_name, ivna.vna_other);
5156 else if (! is_nobits)
5157 error (_("bad dynamic symbol"));
5164 if (vers_data != 0x8001
5165 && version_info [DT_VERSIONTAGIDX (DT_VERDEF)])
5167 Elf_Internal_Verdef ivd;
5168 Elf_Internal_Verdaux ivda;
5169 Elf_External_Verdaux evda;
5170 unsigned long offset;
5173 version_info [DT_VERSIONTAGIDX (DT_VERDEF)]
5178 Elf_External_Verdef evd;
5180 get_data (&evd, file, offset, sizeof (evd),
5183 ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
5184 ivd.vd_aux = BYTE_GET (evd.vd_aux);
5185 ivd.vd_next = BYTE_GET (evd.vd_next);
5187 offset += ivd.vd_next;
5189 while (ivd.vd_ndx != (vers_data & 0x7fff)
5190 && ivd.vd_next != 0);
5192 offset -= ivd.vd_next;
5193 offset += ivd.vd_aux;
5195 get_data (&evda, file, offset, sizeof (evda),
5196 _("version def aux"));
5198 ivda.vda_name = BYTE_GET (evda.vda_name);
5200 if (psym->st_name != ivda.vda_name)
5201 printf ((vers_data & 0x8000)
5203 strtab + ivda.vda_name);
5213 if (strtab != string_table)
5219 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
5221 if (do_histogram && buckets != NULL)
5228 int nzero_counts = 0;
5231 printf (_("\nHistogram for bucket list length (total of %d buckets):\n"),
5233 printf (_(" Length Number %% of total Coverage\n"));
5235 lengths = (int *) calloc (nbuckets, sizeof (int));
5236 if (lengths == NULL)
5238 error (_("Out of memory"));
5241 for (hn = 0; hn < nbuckets; ++hn)
5246 for (si = buckets[hn]; si > 0 && si < nchains; si = chains[si])
5249 if (maxlength < ++lengths[hn])
5254 counts = (int *) calloc (maxlength + 1, sizeof (int));
5257 error (_("Out of memory"));
5261 for (hn = 0; hn < nbuckets; ++hn)
5262 ++ counts [lengths [hn]];
5266 printf (" 0 %-10d (%5.1f%%)\n",
5267 counts[0], (counts[0] * 100.0) / nbuckets);
5268 for (si = 1; si <= maxlength; ++si)
5270 nzero_counts += counts[si] * si;
5271 printf ("%7d %-10d (%5.1f%%) %5.1f%%\n",
5272 si, counts[si], (counts[si] * 100.0) / nbuckets,
5273 (nzero_counts * 100.0) / nsyms);
5281 if (buckets != NULL)
5291 process_syminfo (file)
5292 FILE * file ATTRIBUTE_UNUSED;
5296 if (dynamic_syminfo == NULL
5298 /* No syminfo, this is ok. */
5301 /* There better should be a dynamic symbol section. */
5302 if (dynamic_symbols == NULL || dynamic_strings == NULL)
5306 printf (_("\nDynamic info segment at offset 0x%lx contains %d entries:\n"),
5307 dynamic_syminfo_offset, dynamic_syminfo_nent);
5309 printf (_(" Num: Name BoundTo Flags\n"));
5310 for (i = 0; i < dynamic_syminfo_nent; ++i)
5312 unsigned short int flags = dynamic_syminfo[i].si_flags;
5314 printf ("%4d: %-30s ", i,
5315 dynamic_strings + dynamic_symbols[i].st_name);
5317 switch (dynamic_syminfo[i].si_boundto)
5319 case SYMINFO_BT_SELF:
5320 fputs ("SELF ", stdout);
5322 case SYMINFO_BT_PARENT:
5323 fputs ("PARENT ", stdout);
5326 if (dynamic_syminfo[i].si_boundto > 0
5327 && dynamic_syminfo[i].si_boundto < dynamic_size)
5330 + dynamic_segment[dynamic_syminfo[i].si_boundto].d_un.d_val);
5332 printf ("%-10d ", dynamic_syminfo[i].si_boundto);
5336 if (flags & SYMINFO_FLG_DIRECT)
5338 if (flags & SYMINFO_FLG_PASSTHRU)
5339 printf (" PASSTHRU");
5340 if (flags & SYMINFO_FLG_COPY)
5342 if (flags & SYMINFO_FLG_LAZYLOAD)
5343 printf (" LAZYLOAD");
5351 #ifdef SUPPORT_DISASSEMBLY
5353 disassemble_section (section, file)
5354 Elf32_Internal_Shdr * section;
5357 printf (_("\nAssembly dump of section %s\n"),
5358 SECTION_NAME (section));
5360 /* XXX -- to be done --- XXX */
5367 dump_section (section, file)
5368 Elf32_Internal_Shdr * section;
5371 bfd_size_type bytes;
5373 unsigned char * data;
5374 unsigned char * start;
5376 bytes = section->sh_size;
5380 printf (_("\nSection '%s' has no data to dump.\n"),
5381 SECTION_NAME (section));
5385 printf (_("\nHex dump of section '%s':\n"), SECTION_NAME (section));
5387 addr = section->sh_addr;
5389 start = (unsigned char *) get_data (NULL, file, section->sh_offset, bytes,
5402 lbytes = (bytes > 16 ? 16 : bytes);
5404 printf (" 0x%8.8lx ", (unsigned long) addr);
5406 switch (elf_header.e_ident [EI_DATA])
5410 for (j = 15; j >= 0; j --)
5413 printf ("%2.2x", data [j]);
5423 for (j = 0; j < 16; j++)
5426 printf ("%2.2x", data [j]);
5436 for (j = 0; j < lbytes; j++)
5439 if (k >= ' ' && k < 0x80)
5458 static unsigned long int
5459 read_leb128 (data, length_return, sign)
5460 unsigned char * data;
5461 int * length_return;
5464 unsigned long int result = 0;
5465 unsigned int num_read = 0;
5474 result |= (byte & 0x7f) << shift;
5479 while (byte & 0x80);
5481 if (length_return != NULL)
5482 * length_return = num_read;
5484 if (sign && (shift < 32) && (byte & 0x40))
5485 result |= -1 << shift;
5490 typedef struct State_Machine_Registers
5492 unsigned long address;
5495 unsigned int column;
5499 /* This variable hold the number of the last entry seen
5500 in the File Table. */
5501 unsigned int last_file_entry;
5504 static SMR state_machine_regs;
5507 reset_state_machine (is_stmt)
5510 state_machine_regs.address = 0;
5511 state_machine_regs.file = 1;
5512 state_machine_regs.line = 1;
5513 state_machine_regs.column = 0;
5514 state_machine_regs.is_stmt = is_stmt;
5515 state_machine_regs.basic_block = 0;
5516 state_machine_regs.end_sequence = 0;
5517 state_machine_regs.last_file_entry = 0;
5520 /* Handled an extend line op. Returns true if this is the end
5523 process_extended_line_op (data, is_stmt, pointer_size)
5524 unsigned char * data;
5528 unsigned char op_code;
5531 unsigned char * name;
5534 len = read_leb128 (data, & bytes_read, 0);
5539 warn (_("badly formed extended line op encountered!"));
5544 op_code = * data ++;
5546 printf (_(" Extended opcode %d: "), op_code);
5550 case DW_LNE_end_sequence:
5551 printf (_("End of Sequence\n\n"));
5552 reset_state_machine (is_stmt);
5555 case DW_LNE_set_address:
5556 adr = byte_get (data, pointer_size);
5557 printf (_("set Address to 0x%lx\n"), adr);
5558 state_machine_regs.address = adr;
5561 case DW_LNE_define_file:
5562 printf (_(" define new File Table entry\n"));
5563 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
5565 printf (_(" %d\t"), ++ state_machine_regs.last_file_entry);
5567 data += strlen ((char *) data) + 1;
5568 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
5570 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
5572 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
5573 printf (_("%s\n\n"), name);
5577 printf (_("UNKNOWN: length %d\n"), len - bytes_read);
5584 /* Size of pointers in the .debug_line section. This information is not
5585 really present in that section. It's obtained before dumping the debug
5586 sections by doing some pre-scan of the .debug_info section. */
5587 static int debug_line_pointer_size = 4;
5590 display_debug_lines (section, start, file)
5591 Elf32_Internal_Shdr * section;
5592 unsigned char * start;
5593 FILE * file ATTRIBUTE_UNUSED;
5595 DWARF2_External_LineInfo * external;
5596 DWARF2_Internal_LineInfo info;
5597 unsigned char * standard_opcodes;
5598 unsigned char * data = start;
5599 unsigned char * end = start + section->sh_size;
5600 unsigned char * end_of_sequence;
5603 printf (_("\nDump of debug contents of section %s:\n\n"),
5604 SECTION_NAME (section));
5608 external = (DWARF2_External_LineInfo *) data;
5610 /* Check the length of the block. */
5611 info.li_length = BYTE_GET (external->li_length);
5612 if (info.li_length + sizeof (external->li_length) > section->sh_size)
5615 (_("The line info appears to be corrupt - the section is too small\n"));
5619 /* Check its version number. */
5620 info.li_version = BYTE_GET (external->li_version);
5621 if (info.li_version != 2)
5623 warn (_("Only DWARF version 2 line info is currently supported.\n"));
5627 info.li_prologue_length = BYTE_GET (external->li_prologue_length);
5628 info.li_min_insn_length = BYTE_GET (external->li_min_insn_length);
5629 info.li_default_is_stmt = BYTE_GET (external->li_default_is_stmt);
5630 info.li_line_base = BYTE_GET (external->li_line_base);
5631 info.li_line_range = BYTE_GET (external->li_line_range);
5632 info.li_opcode_base = BYTE_GET (external->li_opcode_base);
5634 /* Sign extend the line base field. */
5635 info.li_line_base <<= 24;
5636 info.li_line_base >>= 24;
5638 printf (_(" Length: %ld\n"), info.li_length);
5639 printf (_(" DWARF Version: %d\n"), info.li_version);
5640 printf (_(" Prologue Length: %d\n"), info.li_prologue_length);
5641 printf (_(" Minimum Instruction Length: %d\n"), info.li_min_insn_length);
5642 printf (_(" Initial value of 'is_stmt': %d\n"), info.li_default_is_stmt);
5643 printf (_(" Line Base: %d\n"), info.li_line_base);
5644 printf (_(" Line Range: %d\n"), info.li_line_range);
5645 printf (_(" Opcode Base: %d\n"), info.li_opcode_base);
5647 end_of_sequence = data + info.li_length + sizeof (external->li_length);
5649 reset_state_machine (info.li_default_is_stmt);
5651 /* Display the contents of the Opcodes table. */
5652 standard_opcodes = data + sizeof (* external);
5654 printf (_("\n Opcodes:\n"));
5656 for (i = 1; i < info.li_opcode_base; i++)
5657 printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]);
5659 /* Display the contents of the Directory table. */
5660 data = standard_opcodes + info.li_opcode_base - 1;
5663 printf (_("\n The Directory Table is empty.\n"));
5666 printf (_("\n The Directory Table:\n"));
5670 printf (_(" %s\n"), data);
5672 data += strlen ((char *) data) + 1;
5676 /* Skip the NUL at the end of the table. */
5679 /* Display the contents of the File Name table. */
5681 printf (_("\n The File Name Table is empty.\n"));
5684 printf (_("\n The File Name Table:\n"));
5685 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
5689 unsigned char * name;
5692 printf (_(" %d\t"), ++ state_machine_regs.last_file_entry);
5695 data += strlen ((char *) data) + 1;
5697 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
5699 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
5701 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
5703 printf (_("%s\n"), name);
5707 /* Skip the NUL at the end of the table. */
5710 /* Now display the statements. */
5711 printf (_("\n Line Number Statements:\n"));
5714 while (data < end_of_sequence)
5716 unsigned char op_code;
5720 op_code = * data ++;
5724 case DW_LNS_extended_op:
5725 data += process_extended_line_op (data, info.li_default_is_stmt,
5726 debug_line_pointer_size);
5730 printf (_(" Copy\n"));
5733 case DW_LNS_advance_pc:
5734 adv = info.li_min_insn_length * read_leb128 (data, & bytes_read, 0);
5736 state_machine_regs.address += adv;
5737 printf (_(" Advance PC by %d to %lx\n"), adv,
5738 state_machine_regs.address);
5741 case DW_LNS_advance_line:
5742 adv = read_leb128 (data, & bytes_read, 1);
5744 state_machine_regs.line += adv;
5745 printf (_(" Advance Line by %d to %d\n"), adv,
5746 state_machine_regs.line);
5749 case DW_LNS_set_file:
5750 adv = read_leb128 (data, & bytes_read, 0);
5752 printf (_(" Set File Name to entry %d in the File Name Table\n"),
5754 state_machine_regs.file = adv;
5757 case DW_LNS_set_column:
5758 adv = read_leb128 (data, & bytes_read, 0);
5760 printf (_(" Set column to %d\n"), adv);
5761 state_machine_regs.column = adv;
5764 case DW_LNS_negate_stmt:
5765 adv = state_machine_regs.is_stmt;
5767 printf (_(" Set is_stmt to %d\n"), adv);
5768 state_machine_regs.is_stmt = adv;
5771 case DW_LNS_set_basic_block:
5772 printf (_(" Set basic block\n"));
5773 state_machine_regs.basic_block = 1;
5776 case DW_LNS_const_add_pc:
5777 adv = (((255 - info.li_opcode_base) / info.li_line_range)
5778 * info.li_min_insn_length);
5779 state_machine_regs.address += adv;
5780 printf (_(" Advance PC by constant %d to 0x%lx\n"), adv,
5781 state_machine_regs.address);
5784 case DW_LNS_fixed_advance_pc:
5785 adv = byte_get (data, 2);
5787 state_machine_regs.address += adv;
5788 printf (_(" Advance PC by fixed size amount %d to 0x%lx\n"),
5789 adv, state_machine_regs.address);
5793 op_code -= info.li_opcode_base;
5794 adv = (op_code / info.li_line_range) * info.li_min_insn_length;
5795 state_machine_regs.address += adv;
5796 printf (_(" Special opcode %d: advance Address by %d to 0x%lx"),
5797 op_code, adv, state_machine_regs.address);
5798 adv = (op_code % info.li_line_range) + info.li_line_base;
5799 state_machine_regs.line += adv;
5800 printf (_(" and Line by %d to %d\n"),
5801 adv, state_machine_regs.line);
5812 display_debug_pubnames (section, start, file)
5813 Elf32_Internal_Shdr * section;
5814 unsigned char * start;
5815 FILE * file ATTRIBUTE_UNUSED;
5817 DWARF2_External_PubNames * external;
5818 DWARF2_Internal_PubNames pubnames;
5819 unsigned char * end;
5821 end = start + section->sh_size;
5823 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section));
5827 unsigned char * data;
5828 unsigned long offset;
5830 external = (DWARF2_External_PubNames *) start;
5832 pubnames.pn_length = BYTE_GET (external->pn_length);
5833 pubnames.pn_version = BYTE_GET (external->pn_version);
5834 pubnames.pn_offset = BYTE_GET (external->pn_offset);
5835 pubnames.pn_size = BYTE_GET (external->pn_size);
5837 data = start + sizeof (* external);
5838 start += pubnames.pn_length + sizeof (external->pn_length);
5840 if (pubnames.pn_version != 2)
5842 static int warned = 0;
5846 warn (_("Only DWARF 2 pubnames are currently supported\n"));
5853 printf (_(" Length: %ld\n"),
5854 pubnames.pn_length);
5855 printf (_(" Version: %d\n"),
5856 pubnames.pn_version);
5857 printf (_(" Offset into .debug_info section: %ld\n"),
5858 pubnames.pn_offset);
5859 printf (_(" Size of area in .debug_info section: %ld\n"),
5862 printf (_("\n Offset\tName\n"));
5866 offset = byte_get (data, 4);
5871 printf (" %ld\t\t%s\n", offset, data);
5872 data += strlen ((char *) data) + 1;
5875 while (offset != 0);
5888 case DW_TAG_padding: return "DW_TAG_padding";
5889 case DW_TAG_array_type: return "DW_TAG_array_type";
5890 case DW_TAG_class_type: return "DW_TAG_class_type";
5891 case DW_TAG_entry_point: return "DW_TAG_entry_point";
5892 case DW_TAG_enumeration_type: return "DW_TAG_enumeration_type";
5893 case DW_TAG_formal_parameter: return "DW_TAG_formal_parameter";
5894 case DW_TAG_imported_declaration: return "DW_TAG_imported_declaration";
5895 case DW_TAG_label: return "DW_TAG_label";
5896 case DW_TAG_lexical_block: return "DW_TAG_lexical_block";
5897 case DW_TAG_member: return "DW_TAG_member";
5898 case DW_TAG_pointer_type: return "DW_TAG_pointer_type";
5899 case DW_TAG_reference_type: return "DW_TAG_reference_type";
5900 case DW_TAG_compile_unit: return "DW_TAG_compile_unit";
5901 case DW_TAG_string_type: return "DW_TAG_string_type";
5902 case DW_TAG_structure_type: return "DW_TAG_structure_type";
5903 case DW_TAG_subroutine_type: return "DW_TAG_subroutine_type";
5904 case DW_TAG_typedef: return "DW_TAG_typedef";
5905 case DW_TAG_union_type: return "DW_TAG_union_type";
5906 case DW_TAG_unspecified_parameters: return "DW_TAG_unspecified_parameters";
5907 case DW_TAG_variant: return "DW_TAG_variant";
5908 case DW_TAG_common_block: return "DW_TAG_common_block";
5909 case DW_TAG_common_inclusion: return "DW_TAG_common_inclusion";
5910 case DW_TAG_inheritance: return "DW_TAG_inheritance";
5911 case DW_TAG_inlined_subroutine: return "DW_TAG_inlined_subroutine";
5912 case DW_TAG_module: return "DW_TAG_module";
5913 case DW_TAG_ptr_to_member_type: return "DW_TAG_ptr_to_member_type";
5914 case DW_TAG_set_type: return "DW_TAG_set_type";
5915 case DW_TAG_subrange_type: return "DW_TAG_subrange_type";
5916 case DW_TAG_with_stmt: return "DW_TAG_with_stmt";
5917 case DW_TAG_access_declaration: return "DW_TAG_access_declaration";
5918 case DW_TAG_base_type: return "DW_TAG_base_type";
5919 case DW_TAG_catch_block: return "DW_TAG_catch_block";
5920 case DW_TAG_const_type: return "DW_TAG_const_type";
5921 case DW_TAG_constant: return "DW_TAG_constant";
5922 case DW_TAG_enumerator: return "DW_TAG_enumerator";
5923 case DW_TAG_file_type: return "DW_TAG_file_type";
5924 case DW_TAG_friend: return "DW_TAG_friend";
5925 case DW_TAG_namelist: return "DW_TAG_namelist";
5926 case DW_TAG_namelist_item: return "DW_TAG_namelist_item";
5927 case DW_TAG_packed_type: return "DW_TAG_packed_type";
5928 case DW_TAG_subprogram: return "DW_TAG_subprogram";
5929 case DW_TAG_template_type_param: return "DW_TAG_template_type_param";
5930 case DW_TAG_template_value_param: return "DW_TAG_template_value_param";
5931 case DW_TAG_thrown_type: return "DW_TAG_thrown_type";
5932 case DW_TAG_try_block: return "DW_TAG_try_block";
5933 case DW_TAG_variant_part: return "DW_TAG_variant_part";
5934 case DW_TAG_variable: return "DW_TAG_variable";
5935 case DW_TAG_volatile_type: return "DW_TAG_volatile_type";
5936 case DW_TAG_MIPS_loop: return "DW_TAG_MIPS_loop";
5937 case DW_TAG_format_label: return "DW_TAG_format_label";
5938 case DW_TAG_function_template: return "DW_TAG_function_template";
5939 case DW_TAG_class_template: return "DW_TAG_class_template";
5942 static char buffer [100];
5944 sprintf (buffer, _("Unknown TAG value: %lx"), tag);
5951 get_AT_name (attribute)
5952 unsigned long attribute;
5956 case DW_AT_sibling: return "DW_AT_sibling";
5957 case DW_AT_location: return "DW_AT_location";
5958 case DW_AT_name: return "DW_AT_name";
5959 case DW_AT_ordering: return "DW_AT_ordering";
5960 case DW_AT_subscr_data: return "DW_AT_subscr_data";
5961 case DW_AT_byte_size: return "DW_AT_byte_size";
5962 case DW_AT_bit_offset: return "DW_AT_bit_offset";
5963 case DW_AT_bit_size: return "DW_AT_bit_size";
5964 case DW_AT_element_list: return "DW_AT_element_list";
5965 case DW_AT_stmt_list: return "DW_AT_stmt_list";
5966 case DW_AT_low_pc: return "DW_AT_low_pc";
5967 case DW_AT_high_pc: return "DW_AT_high_pc";
5968 case DW_AT_language: return "DW_AT_language";
5969 case DW_AT_member: return "DW_AT_member";
5970 case DW_AT_discr: return "DW_AT_discr";
5971 case DW_AT_discr_value: return "DW_AT_discr_value";
5972 case DW_AT_visibility: return "DW_AT_visibility";
5973 case DW_AT_import: return "DW_AT_import";
5974 case DW_AT_string_length: return "DW_AT_string_length";
5975 case DW_AT_common_reference: return "DW_AT_common_reference";
5976 case DW_AT_comp_dir: return "DW_AT_comp_dir";
5977 case DW_AT_const_value: return "DW_AT_const_value";
5978 case DW_AT_containing_type: return "DW_AT_containing_type";
5979 case DW_AT_default_value: return "DW_AT_default_value";
5980 case DW_AT_inline: return "DW_AT_inline";
5981 case DW_AT_is_optional: return "DW_AT_is_optional";
5982 case DW_AT_lower_bound: return "DW_AT_lower_bound";
5983 case DW_AT_producer: return "DW_AT_producer";
5984 case DW_AT_prototyped: return "DW_AT_prototyped";
5985 case DW_AT_return_addr: return "DW_AT_return_addr";
5986 case DW_AT_start_scope: return "DW_AT_start_scope";
5987 case DW_AT_stride_size: return "DW_AT_stride_size";
5988 case DW_AT_upper_bound: return "DW_AT_upper_bound";
5989 case DW_AT_abstract_origin: return "DW_AT_abstract_origin";
5990 case DW_AT_accessibility: return "DW_AT_accessibility";
5991 case DW_AT_address_class: return "DW_AT_address_class";
5992 case DW_AT_artificial: return "DW_AT_artificial";
5993 case DW_AT_base_types: return "DW_AT_base_types";
5994 case DW_AT_calling_convention: return "DW_AT_calling_convention";
5995 case DW_AT_count: return "DW_AT_count";
5996 case DW_AT_data_member_location: return "DW_AT_data_member_location";
5997 case DW_AT_decl_column: return "DW_AT_decl_column";
5998 case DW_AT_decl_file: return "DW_AT_decl_file";
5999 case DW_AT_decl_line: return "DW_AT_decl_line";
6000 case DW_AT_declaration: return "DW_AT_declaration";
6001 case DW_AT_discr_list: return "DW_AT_discr_list";
6002 case DW_AT_encoding: return "DW_AT_encoding";
6003 case DW_AT_external: return "DW_AT_external";
6004 case DW_AT_frame_base: return "DW_AT_frame_base";
6005 case DW_AT_friend: return "DW_AT_friend";
6006 case DW_AT_identifier_case: return "DW_AT_identifier_case";
6007 case DW_AT_macro_info: return "DW_AT_macro_info";
6008 case DW_AT_namelist_items: return "DW_AT_namelist_items";
6009 case DW_AT_priority: return "DW_AT_priority";
6010 case DW_AT_segment: return "DW_AT_segment";
6011 case DW_AT_specification: return "DW_AT_specification";
6012 case DW_AT_static_link: return "DW_AT_static_link";
6013 case DW_AT_type: return "DW_AT_type";
6014 case DW_AT_use_location: return "DW_AT_use_location";
6015 case DW_AT_variable_parameter: return "DW_AT_variable_parameter";
6016 case DW_AT_virtuality: return "DW_AT_virtuality";
6017 case DW_AT_vtable_elem_location: return "DW_AT_vtable_elem_location";
6018 case DW_AT_MIPS_fde: return "DW_AT_MIPS_fde";
6019 case DW_AT_MIPS_loop_begin: return "DW_AT_MIPS_loop_begin";
6020 case DW_AT_MIPS_tail_loop_begin: return "DW_AT_MIPS_tail_loop_begin";
6021 case DW_AT_MIPS_epilog_begin: return "DW_AT_MIPS_epilog_begin";
6022 case DW_AT_MIPS_loop_unroll_factor: return "DW_AT_MIPS_loop_unroll_factor";
6023 case DW_AT_MIPS_software_pipeline_depth: return "DW_AT_MIPS_software_pipeline_depth";
6024 case DW_AT_MIPS_linkage_name: return "DW_AT_MIPS_linkage_name";
6025 case DW_AT_MIPS_stride: return "DW_AT_MIPS_stride";
6026 case DW_AT_MIPS_abstract_name: return "DW_AT_MIPS_abstract_name";
6027 case DW_AT_MIPS_clone_origin: return "DW_AT_MIPS_clone_origin";
6028 case DW_AT_MIPS_has_inlines: return "DW_AT_MIPS_has_inlines";
6029 case DW_AT_sf_names: return "DW_AT_sf_names";
6030 case DW_AT_src_info: return "DW_AT_src_info";
6031 case DW_AT_mac_info: return "DW_AT_mac_info";
6032 case DW_AT_src_coords: return "DW_AT_src_coords";
6033 case DW_AT_body_begin: return "DW_AT_body_begin";
6034 case DW_AT_body_end: return "DW_AT_body_end";
6037 static char buffer [100];
6039 sprintf (buffer, _("Unknown AT value: %lx"), attribute);
6046 get_FORM_name (form)
6051 case DW_FORM_addr: return "DW_FORM_addr";
6052 case DW_FORM_block2: return "DW_FORM_block2";
6053 case DW_FORM_block4: return "DW_FORM_block4";
6054 case DW_FORM_data2: return "DW_FORM_data2";
6055 case DW_FORM_data4: return "DW_FORM_data4";
6056 case DW_FORM_data8: return "DW_FORM_data8";
6057 case DW_FORM_string: return "DW_FORM_string";
6058 case DW_FORM_block: return "DW_FORM_block";
6059 case DW_FORM_block1: return "DW_FORM_block1";
6060 case DW_FORM_data1: return "DW_FORM_data1";
6061 case DW_FORM_flag: return "DW_FORM_flag";
6062 case DW_FORM_sdata: return "DW_FORM_sdata";
6063 case DW_FORM_strp: return "DW_FORM_strp";
6064 case DW_FORM_udata: return "DW_FORM_udata";
6065 case DW_FORM_ref_addr: return "DW_FORM_ref_addr";
6066 case DW_FORM_ref1: return "DW_FORM_ref1";
6067 case DW_FORM_ref2: return "DW_FORM_ref2";
6068 case DW_FORM_ref4: return "DW_FORM_ref4";
6069 case DW_FORM_ref8: return "DW_FORM_ref8";
6070 case DW_FORM_ref_udata: return "DW_FORM_ref_udata";
6071 case DW_FORM_indirect: return "DW_FORM_indirect";
6074 static char buffer [100];
6076 sprintf (buffer, _("Unknown FORM value: %lx"), form);
6082 /* FIXME: There are better and more effiecint ways to handle
6083 these structures. For now though, I just want something that
6084 is simple to implement. */
6085 typedef struct abbrev_attr
6087 unsigned long attribute;
6089 struct abbrev_attr * next;
6093 typedef struct abbrev_entry
6095 unsigned long entry;
6098 struct abbrev_attr * first_attr;
6099 struct abbrev_attr * last_attr;
6100 struct abbrev_entry * next;
6104 static abbrev_entry * first_abbrev = NULL;
6105 static abbrev_entry * last_abbrev = NULL;
6108 free_abbrevs PARAMS ((void))
6110 abbrev_entry * abbrev;
6112 for (abbrev = first_abbrev; abbrev;)
6114 abbrev_entry * next = abbrev->next;
6117 for (attr = abbrev->first_attr; attr;)
6119 abbrev_attr * next = attr->next;
6129 last_abbrev = first_abbrev = NULL;
6133 add_abbrev (number, tag, children)
6134 unsigned long number;
6138 abbrev_entry * entry;
6140 entry = (abbrev_entry *) malloc (sizeof (* entry));
6146 entry->entry = number;
6148 entry->children = children;
6149 entry->first_attr = NULL;
6150 entry->last_attr = NULL;
6153 if (first_abbrev == NULL)
6154 first_abbrev = entry;
6156 last_abbrev->next = entry;
6158 last_abbrev = entry;
6162 add_abbrev_attr (attribute, form)
6163 unsigned long attribute;
6168 attr = (abbrev_attr *) malloc (sizeof (* attr));
6174 attr->attribute = attribute;
6178 if (last_abbrev->first_attr == NULL)
6179 last_abbrev->first_attr = attr;
6181 last_abbrev->last_attr->next = attr;
6183 last_abbrev->last_attr = attr;
6186 /* Processes the (partial) contents of a .debug_abbrev section.
6187 Returns NULL if the end of the section was encountered.
6188 Returns the address after the last byte read if the end of
6189 an abbreviation set was found. */
6191 static unsigned char *
6192 process_abbrev_section (start, end)
6193 unsigned char * start;
6194 unsigned char * end;
6196 if (first_abbrev != NULL)
6202 unsigned long entry;
6204 unsigned long attribute;
6207 entry = read_leb128 (start, & bytes_read, 0);
6208 start += bytes_read;
6210 /* A single zero is supposed to end the section according
6211 to the standard. If there's more, then signal that to
6214 return start == end ? NULL : start;
6216 tag = read_leb128 (start, & bytes_read, 0);
6217 start += bytes_read;
6219 children = * start ++;
6221 add_abbrev (entry, tag, children);
6227 attribute = read_leb128 (start, & bytes_read, 0);
6228 start += bytes_read;
6230 form = read_leb128 (start, & bytes_read, 0);
6231 start += bytes_read;
6234 add_abbrev_attr (attribute, form);
6236 while (attribute != 0);
6244 display_debug_abbrev (section, start, file)
6245 Elf32_Internal_Shdr * section;
6246 unsigned char * start;
6247 FILE * file ATTRIBUTE_UNUSED;
6249 abbrev_entry * entry;
6250 unsigned char * end = start + section->sh_size;
6252 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section));
6256 start = process_abbrev_section (start, end);
6258 printf (_(" Number TAG\n"));
6260 for (entry = first_abbrev; entry; entry = entry->next)
6264 printf (_(" %ld %s [%s]\n"),
6266 get_TAG_name (entry->tag),
6267 entry->children ? _("has children") : _("no children"));
6269 for (attr = entry->first_attr; attr; attr = attr->next)
6271 printf (_(" %-18s %s\n"),
6272 get_AT_name (attr->attribute),
6273 get_FORM_name (attr->form));
6285 static unsigned char *
6286 display_block (data, length)
6287 unsigned char * data;
6288 unsigned long length;
6290 printf (_(" %lu byte block: "), length);
6293 printf ("%lx ", (unsigned long) byte_get (data ++, 1));
6299 decode_location_expression (data, pointer_size, length)
6300 unsigned char * data;
6301 unsigned int pointer_size;
6302 unsigned long length;
6306 unsigned long uvalue;
6307 unsigned char * end = data + length;
6316 printf ("DW_OP_addr: %lx",
6317 (unsigned long) byte_get (data, pointer_size));
6318 data += pointer_size;
6321 printf ("DW_OP_deref");
6324 printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data++, 1));
6327 printf ("DW_OP_const1s: %ld", (long) byte_get (data++, 1));
6330 printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data, 2));
6334 printf ("DW_OP_const2s: %ld", (long) byte_get (data, 2));
6338 printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data, 4));
6342 printf ("DW_OP_const4s: %ld", (long) byte_get (data, 4));
6346 printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data, 4),
6347 (unsigned long) byte_get (data + 4, 4));
6351 printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data, 4),
6352 (long) byte_get (data + 4, 4));
6356 printf ("DW_OP_constu: %lu", read_leb128 (data, &bytes_read, 0));
6360 printf ("DW_OP_consts: %ld", read_leb128 (data, &bytes_read, 1));
6364 printf ("DW_OP_dup");
6367 printf ("DW_OP_drop");
6370 printf ("DW_OP_over");
6373 printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data++, 1));
6376 printf ("DW_OP_swap");
6379 printf ("DW_OP_rot");
6382 printf ("DW_OP_xderef");
6385 printf ("DW_OP_abs");
6388 printf ("DW_OP_and");
6391 printf ("DW_OP_div");
6394 printf ("DW_OP_minus");
6397 printf ("DW_OP_mod");
6400 printf ("DW_OP_mul");
6403 printf ("DW_OP_neg");
6406 printf ("DW_OP_not");
6409 printf ("DW_OP_or");
6412 printf ("DW_OP_plus");
6414 case DW_OP_plus_uconst:
6415 printf ("DW_OP_plus_uconst: %lu",
6416 read_leb128 (data, &bytes_read, 0));
6420 printf ("DW_OP_shl");
6423 printf ("DW_OP_shr");
6426 printf ("DW_OP_shra");
6429 printf ("DW_OP_xor");
6432 printf ("DW_OP_bra: %ld", (long) byte_get (data, 2));
6436 printf ("DW_OP_eq");
6439 printf ("DW_OP_ge");
6442 printf ("DW_OP_gt");
6445 printf ("DW_OP_le");
6448 printf ("DW_OP_lt");
6451 printf ("DW_OP_ne");
6454 printf ("DW_OP_skip: %ld", (long) byte_get (data, 2));
6490 printf ("DW_OP_lit%d", op - DW_OP_lit0);
6525 printf ("DW_OP_reg%d", op - DW_OP_reg0);
6560 printf ("DW_OP_breg%d: %ld", op - DW_OP_breg0,
6561 read_leb128 (data, &bytes_read, 1));
6566 printf ("DW_OP_regx: %lu", read_leb128 (data, &bytes_read, 0));
6570 printf ("DW_OP_fbreg: %ld", read_leb128 (data, &bytes_read, 1));
6574 uvalue = read_leb128 (data, &bytes_read, 0);
6576 printf ("DW_OP_bregx: %lu %ld", uvalue,
6577 read_leb128 (data, &bytes_read, 1));
6581 printf ("DW_OP_piece: %lu", read_leb128 (data, &bytes_read, 0));
6584 case DW_OP_deref_size:
6585 printf ("DW_OP_deref_size: %ld", (long) byte_get (data++, 1));
6587 case DW_OP_xderef_size:
6588 printf ("DW_OP_xderef_size: %ld", (long) byte_get (data++, 1));
6591 printf ("DW_OP_nop");
6595 if (op >= DW_OP_lo_user
6596 && op <= DW_OP_hi_user)
6597 printf (_("(User defined location op)"));
6599 printf (_("(Unknown location op)"));
6600 /* No way to tell where the next op is, so just bail. */
6607 static unsigned char *
6608 read_and_display_attr (attribute, form, data, cu_offset, pointer_size)
6609 unsigned long attribute;
6611 unsigned char * data;
6612 unsigned long cu_offset;
6613 unsigned long pointer_size;
6615 unsigned long uvalue = 0;
6616 unsigned char * block_start = NULL;
6619 printf (" %-18s:", get_AT_name (attribute));
6626 case DW_FORM_ref_addr:
6628 uvalue = byte_get (data, pointer_size);
6629 data += pointer_size;
6635 uvalue = byte_get (data ++, 1);
6640 uvalue = byte_get (data, 2);
6646 uvalue = byte_get (data, 4);
6651 uvalue = read_leb128 (data, & bytes_read, 1);
6655 case DW_FORM_ref_udata:
6657 uvalue = read_leb128 (data, & bytes_read, 0);
6664 case DW_FORM_ref_addr:
6665 printf (" <#%lx>", uvalue);
6671 case DW_FORM_ref_udata:
6672 printf (" <%lx>", uvalue + cu_offset);
6676 printf (" %#lx", uvalue);
6684 printf (" %ld", uvalue);
6689 uvalue = byte_get (data, 4);
6690 printf (" %lx", uvalue);
6691 printf (" %lx", (unsigned long) byte_get (data + 4, 4));
6695 case DW_FORM_string:
6696 printf (" %s", data);
6697 data += strlen ((char *) data) + 1;
6701 uvalue = read_leb128 (data, & bytes_read, 0);
6702 block_start = data + bytes_read;
6703 data = display_block (block_start, uvalue);
6706 case DW_FORM_block1:
6707 uvalue = byte_get (data, 1);
6708 block_start = data + 1;
6709 data = display_block (block_start, uvalue);
6712 case DW_FORM_block2:
6713 uvalue = byte_get (data, 2);
6714 block_start = data + 2;
6715 data = display_block (block_start, uvalue);
6718 case DW_FORM_block4:
6719 uvalue = byte_get (data, 4);
6720 block_start = data + 4;
6721 data = display_block (block_start, uvalue);
6725 case DW_FORM_indirect:
6726 warn (_("Unable to handle FORM: %d"), form);
6730 warn (_("Unrecognised form: %d"), form);
6734 /* For some attributes we can display futher information. */
6743 case DW_INL_not_inlined: printf (_("(not inlined)")); break;
6744 case DW_INL_inlined: printf (_("(inlined)")); break;
6745 case DW_INL_declared_not_inlined: printf (_("(declared as inline but ignored)")); break;
6746 case DW_INL_declared_inlined: printf (_("(declared as inline and inlined)")); break;
6747 default: printf (_(" (Unknown inline attribute value: %lx)"), uvalue); break;
6751 case DW_AT_language:
6754 case DW_LANG_C: printf ("(non-ANSI C)"); break;
6755 case DW_LANG_C89: printf ("(ANSI C)"); break;
6756 case DW_LANG_C_plus_plus: printf ("(C++)"); break;
6757 case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break;
6758 case DW_LANG_Fortran90: printf ("(Fortran 90)"); break;
6759 case DW_LANG_Modula2: printf ("(Modula 2)"); break;
6760 case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break;
6761 case DW_LANG_Ada83: printf ("(Ada)"); break;
6762 case DW_LANG_Cobol74: printf ("(Cobol 74)"); break;
6763 case DW_LANG_Cobol85: printf ("(Cobol 85)"); break;
6764 case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break;
6765 default: printf ("(Unknown: %lx)", uvalue); break;
6769 case DW_AT_encoding:
6772 case DW_ATE_void: printf ("(void)"); break;
6773 case DW_ATE_address: printf ("(machine address)"); break;
6774 case DW_ATE_boolean: printf ("(boolean)"); break;
6775 case DW_ATE_complex_float: printf ("(complex float)"); break;
6776 case DW_ATE_float: printf ("(float)"); break;
6777 case DW_ATE_signed: printf ("(signed)"); break;
6778 case DW_ATE_signed_char: printf ("(signed char)"); break;
6779 case DW_ATE_unsigned: printf ("(unsigned)"); break;
6780 case DW_ATE_unsigned_char: printf ("(unsigned char)"); break;
6782 if (uvalue >= DW_ATE_lo_user
6783 && uvalue <= DW_ATE_hi_user)
6784 printf ("(user defined type)");
6786 printf ("(unknown type)");
6791 case DW_AT_accessibility:
6794 case DW_ACCESS_public: printf ("(public)"); break;
6795 case DW_ACCESS_protected: printf ("(protected)"); break;
6796 case DW_ACCESS_private: printf ("(private)"); break;
6797 default: printf ("(unknown accessibility)"); break;
6801 case DW_AT_visibility:
6804 case DW_VIS_local: printf ("(local)"); break;
6805 case DW_VIS_exported: printf ("(exported)"); break;
6806 case DW_VIS_qualified: printf ("(qualified)"); break;
6807 default: printf ("(unknown visibility)"); break;
6811 case DW_AT_virtuality:
6814 case DW_VIRTUALITY_none: printf ("(none)"); break;
6815 case DW_VIRTUALITY_virtual: printf ("(virtual)"); break;
6816 case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break;
6817 default: printf ("(unknown virtuality)"); break;
6821 case DW_AT_identifier_case:
6824 case DW_ID_case_sensitive: printf ("(case_sensitive)"); break;
6825 case DW_ID_up_case: printf ("(up_case)"); break;
6826 case DW_ID_down_case: printf ("(down_case)"); break;
6827 case DW_ID_case_insensitive: printf ("(case_insensitive)"); break;
6828 default: printf ("(unknown case)"); break;
6832 case DW_AT_calling_convention:
6835 case DW_CC_normal: printf ("(normal)"); break;
6836 case DW_CC_program: printf ("(program)"); break;
6837 case DW_CC_nocall: printf ("(nocall)"); break;
6839 if (uvalue >= DW_CC_lo_user
6840 && uvalue <= DW_CC_hi_user)
6841 printf ("(user defined)");
6843 printf ("(unknown convention)");
6847 case DW_AT_frame_base:
6848 case DW_AT_location:
6849 case DW_AT_data_member_location:
6850 case DW_AT_vtable_elem_location:
6854 decode_location_expression (block_start, pointer_size, uvalue);
6868 display_debug_info (section, start, file)
6869 Elf32_Internal_Shdr * section;
6870 unsigned char * start;
6873 unsigned char * end = start + section->sh_size;
6874 unsigned char * section_begin = start;
6876 printf (_("The section %s contains:\n\n"), SECTION_NAME (section));
6880 DWARF2_External_CompUnit * external;
6881 DWARF2_Internal_CompUnit compunit;
6882 unsigned char * tags;
6885 unsigned long cu_offset;
6887 external = (DWARF2_External_CompUnit *) start;
6889 compunit.cu_length = BYTE_GET (external->cu_length);
6890 compunit.cu_version = BYTE_GET (external->cu_version);
6891 compunit.cu_abbrev_offset = BYTE_GET (external->cu_abbrev_offset);
6892 compunit.cu_pointer_size = BYTE_GET (external->cu_pointer_size);
6894 tags = start + sizeof (* external);
6895 cu_offset = start - section_begin;
6896 start += compunit.cu_length + sizeof (external->cu_length);
6898 printf (_(" Compilation Unit @ %lx:\n"), cu_offset);
6899 printf (_(" Length: %ld\n"), compunit.cu_length);
6900 printf (_(" Version: %d\n"), compunit.cu_version);
6901 printf (_(" Abbrev Offset: %ld\n"), compunit.cu_abbrev_offset);
6902 printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size);
6904 if (compunit.cu_version != 2)
6906 warn (_("Only version 2 DWARF debug information is currently supported.\n"));
6910 if (first_abbrev != NULL)
6913 /* Read in the abbrevs used by this compilation unit. */
6916 Elf32_Internal_Shdr * sec;
6917 unsigned char * begin;
6919 /* Locate the .debug_abbrev section and process it. */
6920 for (i = 0, sec = section_headers;
6921 i < elf_header.e_shnum;
6923 if (strcmp (SECTION_NAME (sec), ".debug_abbrev") == 0)
6926 if (i == -1 || sec->sh_size == 0)
6928 warn (_("Unable to locate .debug_abbrev section!\n"));
6932 begin = ((unsigned char *)
6933 get_data (NULL, file, sec->sh_offset, sec->sh_size,
6934 _("debug_abbrev section data")));
6938 process_abbrev_section (begin + compunit.cu_abbrev_offset,
6939 begin + sec->sh_size);
6945 while (tags < start)
6948 unsigned long abbrev_number;
6949 abbrev_entry * entry;
6952 abbrev_number = read_leb128 (tags, & bytes_read, 0);
6955 /* A null DIE marks the end of a list of children. */
6956 if (abbrev_number == 0)
6962 /* Scan through the abbreviation list until we reach the
6964 for (entry = first_abbrev;
6965 entry && entry->entry != abbrev_number;
6966 entry = entry->next)
6971 warn (_("Unable to locate entry %lu in the abbreviation table\n"),
6976 printf (_(" <%d><%x>: Abbrev Number: %lu (%s)\n"),
6977 level, tags - section_begin - bytes_read,
6979 get_TAG_name (entry->tag));
6981 for (attr = entry->first_attr; attr; attr = attr->next)
6982 tags = read_and_display_attr (attr->attribute,
6985 compunit.cu_pointer_size);
6987 if (entry->children)
6998 display_debug_aranges (section, start, file)
6999 Elf32_Internal_Shdr * section;
7000 unsigned char * start;
7001 FILE * file ATTRIBUTE_UNUSED;
7003 unsigned char * end = start + section->sh_size;
7005 printf (_("The section %s contains:\n\n"), SECTION_NAME (section));
7009 DWARF2_External_ARange * external;
7010 DWARF2_Internal_ARange arange;
7011 unsigned char * ranges;
7012 unsigned long length;
7013 unsigned long address;
7016 external = (DWARF2_External_ARange *) start;
7018 arange.ar_length = BYTE_GET (external->ar_length);
7019 arange.ar_version = BYTE_GET (external->ar_version);
7020 arange.ar_info_offset = BYTE_GET (external->ar_info_offset);
7021 arange.ar_pointer_size = BYTE_GET (external->ar_pointer_size);
7022 arange.ar_segment_size = BYTE_GET (external->ar_segment_size);
7024 if (arange.ar_version != 2)
7026 warn (_("Only DWARF 2 aranges are currently supported.\n"));
7030 printf (_(" Length: %ld\n"), arange.ar_length);
7031 printf (_(" Version: %d\n"), arange.ar_version);
7032 printf (_(" Offset into .debug_info: %lx\n"), arange.ar_info_offset);
7033 printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
7034 printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
7036 printf (_("\n Address Length\n"));
7038 ranges = start + sizeof (* external);
7040 /* Must pad to an alignment boundary that is twice the pointer size. */
7041 excess = sizeof (* external) % (2 * arange.ar_pointer_size);
7043 ranges += (2 * arange.ar_pointer_size) - excess;
7047 address = byte_get (ranges, arange.ar_pointer_size);
7049 ranges += arange.ar_pointer_size;
7051 length = byte_get (ranges, arange.ar_pointer_size);
7053 ranges += arange.ar_pointer_size;
7055 /* A pair of zeros marks the end of the list. */
7056 if (address == 0 && length == 0)
7059 printf (" %8.8lx %lu\n", address, length);
7062 start += arange.ar_length + sizeof (external->ar_length);
7070 typedef struct Frame_Chunk
7072 struct Frame_Chunk * next;
7073 unsigned char * chunk_start;
7075 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
7076 short int * col_type;
7078 char * augmentation;
7079 unsigned int code_factor;
7081 unsigned long pc_begin;
7082 unsigned long pc_range;
7086 unsigned char fde_encoding;
7090 /* A marker for a col_type that means this column was never referenced
7091 in the frame info. */
7092 #define DW_CFA_unreferenced (-1)
7095 frame_need_space (fc, reg)
7099 int prev = fc->ncols;
7101 if (reg < fc->ncols)
7104 fc->ncols = reg + 1;
7105 fc->col_type = (short int *) xrealloc (fc->col_type,
7106 fc->ncols * sizeof (short int));
7107 fc->col_offset = (int *) xrealloc (fc->col_offset,
7108 fc->ncols * sizeof (int));
7110 while (prev < fc->ncols)
7112 fc->col_type[prev] = DW_CFA_unreferenced;
7113 fc->col_offset[prev] = 0;
7119 frame_display_row (fc, need_col_headers, max_regs)
7121 int * need_col_headers;
7127 if (* max_regs < fc->ncols)
7128 * max_regs = fc->ncols;
7130 if (* need_col_headers)
7132 * need_col_headers = 0;
7134 printf (" LOC CFA ");
7136 for (r = 0; r < * max_regs; r++)
7137 if (fc->col_type[r] != DW_CFA_unreferenced)
7142 printf ("r%-4d", r);
7148 printf ("%08lx ", fc->pc_begin);
7149 sprintf (tmp, "r%d%+d", fc->cfa_reg, fc->cfa_offset);
7150 printf ("%-8s ", tmp);
7152 for (r = 0; r < fc->ncols; r++)
7154 if (fc->col_type[r] != DW_CFA_unreferenced)
7156 switch (fc->col_type[r])
7158 case DW_CFA_undefined:
7161 case DW_CFA_same_value:
7165 sprintf (tmp, "c%+d", fc->col_offset[r]);
7167 case DW_CFA_register:
7168 sprintf (tmp, "r%d", fc->col_offset[r]);
7171 strcpy (tmp, "n/a");
7174 printf ("%-5s", tmp);
7181 size_of_encoded_value (encoding)
7184 switch (encoding & 0x7)
7187 case 0: return is_32bit_elf ? 4 : 8;
7194 #define GET(N) byte_get (start, N); start += N
7195 #define LEB() read_leb128 (start, & length_return, 0); start += length_return
7196 #define SLEB() read_leb128 (start, & length_return, 1); start += length_return
7199 display_debug_frames (section, start, file)
7200 Elf32_Internal_Shdr * section;
7201 unsigned char * start;
7202 FILE * file ATTRIBUTE_UNUSED;
7204 unsigned char * end = start + section->sh_size;
7205 unsigned char * section_start = start;
7206 Frame_Chunk * chunks = 0;
7207 Frame_Chunk * remembered_state = 0;
7209 int is_eh = (strcmp (SECTION_NAME (section), ".eh_frame") == 0);
7212 int addr_size = is_32bit_elf ? 4 : 8;
7214 printf (_("The section %s contains:\n"), SECTION_NAME (section));
7218 unsigned char * saved_start;
7219 unsigned char * block_end;
7220 unsigned long length;
7221 unsigned long cie_id;
7224 int need_col_headers = 1;
7225 unsigned char * augmentation_data = NULL;
7226 unsigned long augmentation_data_len = 0;
7227 int encoded_ptr_size = addr_size;
7229 saved_start = start;
7230 length = byte_get (start, 4); start += 4;
7235 block_end = saved_start + length + 4;
7236 cie_id = byte_get (start, 4); start += 4;
7238 if (is_eh ? (cie_id == 0) : (cie_id == DW_CIE_ID))
7242 fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
7243 memset (fc, 0, sizeof (Frame_Chunk));
7247 fc->chunk_start = saved_start;
7249 fc->col_type = (short int *) xmalloc (sizeof (short int));
7250 fc->col_offset = (int *) xmalloc (sizeof (int));
7251 frame_need_space (fc, max_regs-1);
7255 fc->augmentation = start;
7256 start = strchr (start, '\0') + 1;
7258 if (fc->augmentation[0] == 'z')
7260 fc->code_factor = LEB ();
7261 fc->data_factor = SLEB ();
7262 fc->ra = byte_get (start, 1); start += 1;
7263 augmentation_data_len = LEB ();
7264 augmentation_data = start;
7265 start += augmentation_data_len;
7267 else if (strcmp (fc->augmentation, "eh") == 0)
7270 fc->code_factor = LEB ();
7271 fc->data_factor = SLEB ();
7272 fc->ra = byte_get (start, 1); start += 1;
7276 fc->code_factor = LEB ();
7277 fc->data_factor = SLEB ();
7278 fc->ra = byte_get (start, 1); start += 1;
7282 if (do_debug_frames_interp)
7283 printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n",
7284 (unsigned long)(saved_start - section_start), length, cie_id,
7285 fc->augmentation, fc->code_factor, fc->data_factor,
7289 printf ("\n%08lx %08lx %08lx CIE\n",
7290 (unsigned long)(saved_start - section_start), length, cie_id);
7291 printf (" Version: %d\n", version);
7292 printf (" Augmentation: \"%s\"\n", fc->augmentation);
7293 printf (" Code alignment factor: %u\n", fc->code_factor);
7294 printf (" Data alignment factor: %d\n", fc->data_factor);
7295 printf (" Return address column: %d\n", fc->ra);
7297 if (augmentation_data_len)
7300 printf (" Augmentation data: ");
7301 for (i = 0; i < augmentation_data_len; ++i)
7302 printf (" %02x", augmentation_data[i]);
7308 if (augmentation_data_len)
7310 unsigned char *p, *q;
7311 p = fc->augmentation + 1;
7312 q = augmentation_data;
7319 q += 1 + size_of_encoded_value (*q);
7321 fc->fde_encoding = *q++;
7327 if (fc->fde_encoding)
7328 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
7331 frame_need_space (fc, fc->ra);
7335 unsigned char * look_for;
7336 static Frame_Chunk fde_fc;
7339 memset (fc, 0, sizeof (Frame_Chunk));
7341 look_for = is_eh ? start - 4 - cie_id : section_start + cie_id;
7343 for (cie=chunks; cie ; cie = cie->next)
7344 if (cie->chunk_start == look_for)
7349 warn ("Invalid CIE pointer %08lx in FDE at %08lx\n",
7350 cie_id, saved_start);
7353 fc->col_type = (short int *) xmalloc (sizeof (short int));
7354 fc->col_offset = (int *) xmalloc (sizeof (int));
7355 frame_need_space (fc, max_regs - 1);
7357 fc->augmentation = "";
7358 fc->fde_encoding = 0;
7362 fc->ncols = cie->ncols;
7363 fc->col_type = (short int *) xmalloc (fc->ncols * sizeof (short int));
7364 fc->col_offset = (int *) xmalloc (fc->ncols * sizeof (int));
7365 memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int));
7366 memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int));
7367 fc->augmentation = cie->augmentation;
7368 fc->code_factor = cie->code_factor;
7369 fc->data_factor = cie->data_factor;
7370 fc->cfa_reg = cie->cfa_reg;
7371 fc->cfa_offset = cie->cfa_offset;
7373 frame_need_space (fc, max_regs-1);
7374 fc->fde_encoding = cie->fde_encoding;
7377 if (fc->fde_encoding)
7378 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
7380 fc->pc_begin = byte_get (start, encoded_ptr_size);
7381 start += encoded_ptr_size;
7382 fc->pc_range = byte_get (start, encoded_ptr_size);
7383 start += encoded_ptr_size;
7385 if (cie->augmentation[0] == 'z')
7387 augmentation_data_len = LEB ();
7388 augmentation_data = start;
7389 start += augmentation_data_len;
7392 printf ("\n%08lx %08lx %08lx FDE cie=%08x pc=%08lx..%08lx\n",
7393 (unsigned long)(saved_start - section_start), length, cie_id,
7394 cie->chunk_start - section_start, fc->pc_begin,
7395 fc->pc_begin + fc->pc_range);
7396 if (! do_debug_frames_interp && augmentation_data_len)
7399 printf (" Augmentation data: ");
7400 for (i = 0; i < augmentation_data_len; ++i)
7401 printf (" %02x", augmentation_data[i]);
7407 /* At this point, fc is the current chunk, cie (if any) is set, and we're
7408 about to interpret instructions for the chunk. */
7410 if (do_debug_frames_interp)
7412 /* Start by making a pass over the chunk, allocating storage
7413 and taking note of what registers are used. */
7414 unsigned char * tmp = start;
7416 while (start < block_end)
7426 /* Warning: if you add any more cases to this switch, be
7427 sure to add them to the corresponding switch below. */
7430 case DW_CFA_advance_loc:
7434 frame_need_space (fc, opa);
7435 fc->col_type[opa] = DW_CFA_undefined;
7437 case DW_CFA_restore:
7438 frame_need_space (fc, opa);
7439 fc->col_type[opa] = DW_CFA_undefined;
7441 case DW_CFA_set_loc:
7442 start += encoded_ptr_size;
7444 case DW_CFA_advance_loc1:
7447 case DW_CFA_advance_loc2:
7450 case DW_CFA_advance_loc4:
7453 case DW_CFA_offset_extended:
7454 reg = LEB (); LEB ();
7455 frame_need_space (fc, reg);
7456 fc->col_type[reg] = DW_CFA_undefined;
7458 case DW_CFA_restore_extended:
7460 frame_need_space (fc, reg);
7461 fc->col_type[reg] = DW_CFA_undefined;
7463 case DW_CFA_undefined:
7465 frame_need_space (fc, reg);
7466 fc->col_type[reg] = DW_CFA_undefined;
7468 case DW_CFA_same_value:
7470 frame_need_space (fc, reg);
7471 fc->col_type[reg] = DW_CFA_undefined;
7473 case DW_CFA_register:
7474 reg = LEB (); LEB ();
7475 frame_need_space (fc, reg);
7476 fc->col_type[reg] = DW_CFA_undefined;
7478 case DW_CFA_def_cfa:
7481 case DW_CFA_def_cfa_register:
7484 case DW_CFA_def_cfa_offset:
7487 #ifndef DW_CFA_GNU_args_size
7488 #define DW_CFA_GNU_args_size 0x2e
7490 case DW_CFA_GNU_args_size:
7493 #ifndef DW_CFA_GNU_negative_offset_extended
7494 #define DW_CFA_GNU_negative_offset_extended 0x2f
7496 case DW_CFA_GNU_negative_offset_extended:
7497 reg = LEB (); LEB ();
7498 frame_need_space (fc, reg);
7499 fc->col_type[reg] = DW_CFA_undefined;
7508 /* Now we know what registers are used, make a second pass over
7509 the chunk, this time actually printing out the info. */
7511 while (start < block_end)
7514 unsigned long ul, reg, roffs;
7523 /* Warning: if you add any more cases to this switch, be
7524 sure to add them to the corresponding switch above. */
7527 case DW_CFA_advance_loc:
7528 if (do_debug_frames_interp)
7529 frame_display_row (fc, &need_col_headers, &max_regs);
7531 printf (" DW_CFA_advance_loc: %d to %08lx\n",
7532 opa * fc->code_factor,
7533 fc->pc_begin + opa * fc->code_factor);
7534 fc->pc_begin += opa * fc->code_factor;
7539 if (! do_debug_frames_interp)
7540 printf (" DW_CFA_offset: r%d at cfa%+ld\n",
7541 opa, roffs * fc->data_factor);
7542 fc->col_type[opa] = DW_CFA_offset;
7543 fc->col_offset[opa] = roffs * fc->data_factor;
7546 case DW_CFA_restore:
7547 if (! do_debug_frames_interp)
7548 printf (" DW_CFA_restore: r%d\n", opa);
7549 fc->col_type[opa] = cie->col_type[opa];
7550 fc->col_offset[opa] = cie->col_offset[opa];
7553 case DW_CFA_set_loc:
7554 vma = byte_get (start, encoded_ptr_size);
7555 start += encoded_ptr_size;
7556 if (do_debug_frames_interp)
7557 frame_display_row (fc, &need_col_headers, &max_regs);
7559 printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma);
7563 case DW_CFA_advance_loc1:
7564 ofs = byte_get (start, 1); start += 1;
7565 if (do_debug_frames_interp)
7566 frame_display_row (fc, &need_col_headers, &max_regs);
7568 printf (" DW_CFA_advance_loc1: %ld to %08lx\n",
7569 ofs * fc->code_factor,
7570 fc->pc_begin + ofs * fc->code_factor);
7571 fc->pc_begin += ofs * fc->code_factor;
7574 case DW_CFA_advance_loc2:
7575 ofs = byte_get (start, 2); start += 2;
7576 if (do_debug_frames_interp)
7577 frame_display_row (fc, &need_col_headers, &max_regs);
7579 printf (" DW_CFA_advance_loc2: %ld to %08lx\n",
7580 ofs * fc->code_factor,
7581 fc->pc_begin + ofs * fc->code_factor);
7582 fc->pc_begin += ofs * fc->code_factor;
7585 case DW_CFA_advance_loc4:
7586 ofs = byte_get (start, 4); start += 4;
7587 if (do_debug_frames_interp)
7588 frame_display_row (fc, &need_col_headers, &max_regs);
7590 printf (" DW_CFA_advance_loc4: %ld to %08lx\n",
7591 ofs * fc->code_factor,
7592 fc->pc_begin + ofs * fc->code_factor);
7593 fc->pc_begin += ofs * fc->code_factor;
7596 case DW_CFA_offset_extended:
7599 if (! do_debug_frames_interp)
7600 printf (" DW_CFA_offset_extended: r%ld at cfa%+ld\n",
7601 reg, roffs * fc->data_factor);
7602 fc->col_type[reg] = DW_CFA_offset;
7603 fc->col_offset[reg] = roffs * fc->data_factor;
7606 case DW_CFA_restore_extended:
7608 if (! do_debug_frames_interp)
7609 printf (" DW_CFA_restore_extended: r%ld\n", reg);
7610 fc->col_type[reg] = cie->col_type[reg];
7611 fc->col_offset[reg] = cie->col_offset[reg];
7614 case DW_CFA_undefined:
7616 if (! do_debug_frames_interp)
7617 printf (" DW_CFA_undefined: r%ld\n", reg);
7618 fc->col_type[reg] = DW_CFA_undefined;
7619 fc->col_offset[reg] = 0;
7622 case DW_CFA_same_value:
7624 if (! do_debug_frames_interp)
7625 printf (" DW_CFA_same_value: r%ld\n", reg);
7626 fc->col_type[reg] = DW_CFA_same_value;
7627 fc->col_offset[reg] = 0;
7630 case DW_CFA_register:
7633 if (! do_debug_frames_interp)
7634 printf (" DW_CFA_register: r%ld\n", reg);
7635 fc->col_type[reg] = DW_CFA_register;
7636 fc->col_offset[reg] = roffs;
7639 case DW_CFA_remember_state:
7640 if (! do_debug_frames_interp)
7641 printf (" DW_CFA_remember_state\n");
7642 rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
7643 rs->ncols = fc->ncols;
7644 rs->col_type = (short int *) xmalloc (rs->ncols * sizeof (short int));
7645 rs->col_offset = (int *) xmalloc (rs->ncols * sizeof (int));
7646 memcpy (rs->col_type, fc->col_type, rs->ncols);
7647 memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (int));
7648 rs->next = remembered_state;
7649 remembered_state = rs;
7652 case DW_CFA_restore_state:
7653 if (! do_debug_frames_interp)
7654 printf (" DW_CFA_restore_state\n");
7655 rs = remembered_state;
7656 remembered_state = rs->next;
7657 frame_need_space (fc, rs->ncols-1);
7658 memcpy (fc->col_type, rs->col_type, rs->ncols);
7659 memcpy (fc->col_offset, rs->col_offset, rs->ncols * sizeof (int));
7660 free (rs->col_type);
7661 free (rs->col_offset);
7665 case DW_CFA_def_cfa:
7666 fc->cfa_reg = LEB ();
7667 fc->cfa_offset = LEB ();
7668 if (! do_debug_frames_interp)
7669 printf (" DW_CFA_def_cfa: r%d ofs %d\n",
7670 fc->cfa_reg, fc->cfa_offset);
7673 case DW_CFA_def_cfa_register:
7674 fc->cfa_reg = LEB ();
7675 if (! do_debug_frames_interp)
7676 printf (" DW_CFA_def_cfa_reg: r%d\n", fc->cfa_reg);
7679 case DW_CFA_def_cfa_offset:
7680 fc->cfa_offset = LEB ();
7681 if (! do_debug_frames_interp)
7682 printf (" DW_CFA_def_cfa_offset: %d\n", fc->cfa_offset);
7686 if (! do_debug_frames_interp)
7687 printf (" DW_CFA_nop\n");
7690 #ifndef DW_CFA_GNU_window_save
7691 #define DW_CFA_GNU_window_save 0x2d
7693 case DW_CFA_GNU_window_save:
7694 if (! do_debug_frames_interp)
7695 printf (" DW_CFA_GNU_window_save\n");
7698 case DW_CFA_GNU_args_size:
7700 if (! do_debug_frames_interp)
7701 printf (" DW_CFA_GNU_args_size: %ld\n", ul);
7704 case DW_CFA_GNU_negative_offset_extended:
7707 frame_need_space (fc, reg);
7708 if (! do_debug_frames_interp)
7709 printf (" DW_CFA_GNU_negative_offset_extended: r%ld at cfa%+ld\n",
7710 reg, l * fc->data_factor);
7711 fc->col_type[reg] = DW_CFA_offset;
7712 fc->col_offset[reg] = l * fc->data_factor;
7716 fprintf (stderr, "unsupported or unknown DW_CFA_%d\n", op);
7721 if (do_debug_frames_interp)
7722 frame_display_row (fc, &need_col_headers, &max_regs);
7737 display_debug_not_supported (section, start, file)
7738 Elf32_Internal_Shdr * section;
7739 unsigned char * start ATTRIBUTE_UNUSED;
7740 FILE * file ATTRIBUTE_UNUSED;
7742 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
7743 SECTION_NAME (section));
7748 /* Pre-scan the .debug_info section to record the size of address.
7749 When dumping the .debug_line, we use that size information, assuming
7750 that all compilation units have the same address size. */
7752 prescan_debug_info (section, start, file)
7753 Elf32_Internal_Shdr * section ATTRIBUTE_UNUSED;
7754 unsigned char * start;
7755 FILE * file ATTRIBUTE_UNUSED;
7757 DWARF2_External_CompUnit * external;
7759 external = (DWARF2_External_CompUnit *) start;
7761 debug_line_pointer_size = BYTE_GET (external->cu_pointer_size);
7765 /* A structure containing the name of a debug section and a pointer
7766 to a function that can decode it. The third field is a prescan
7767 function to be run over the section before displaying any of the
7772 int (* display) PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
7773 int (* prescan) PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
7777 { ".debug_info", display_debug_info, prescan_debug_info },
7778 { ".debug_abbrev", display_debug_abbrev, NULL },
7779 { ".debug_line", display_debug_lines, NULL },
7780 { ".debug_aranges", display_debug_aranges, NULL },
7781 { ".debug_pubnames", display_debug_pubnames, NULL },
7782 { ".debug_frame", display_debug_frames, NULL },
7783 { ".eh_frame", display_debug_frames, NULL },
7784 { ".debug_macinfo", display_debug_not_supported, NULL },
7785 { ".debug_str", display_debug_not_supported, NULL },
7786 { ".debug_static_func", display_debug_not_supported, NULL },
7787 { ".debug_static_vars", display_debug_not_supported, NULL },
7788 { ".debug_types", display_debug_not_supported, NULL },
7789 { ".debug_weaknames", display_debug_not_supported, NULL }
7793 display_debug_section (section, file)
7794 Elf32_Internal_Shdr * section;
7797 char * name = SECTION_NAME (section);
7798 bfd_size_type length;
7799 unsigned char * start;
7802 length = section->sh_size;
7805 printf (_("\nSection '%s' has no debugging data.\n"), name);
7809 start = (unsigned char *) get_data (NULL, file, section->sh_offset, length,
7810 _("debug section data"));
7814 /* See if we know how to display the contents of this section. */
7815 if (strncmp (name, ".gnu.linkonce.wi.", 17) == 0)
7816 name = ".debug_info";
7818 for (i = NUM_ELEM (debug_displays); i--;)
7819 if (strcmp (debug_displays[i].name, name) == 0)
7821 debug_displays[i].display (section, start, file);
7826 printf (_("Unrecognised debug section: %s\n"), name);
7830 /* If we loaded in the abbrev section at some point,
7831 we must release it here. */
7832 if (first_abbrev != NULL)
7839 process_section_contents (file)
7842 Elf32_Internal_Shdr * section;
7848 /* Pre-scan the debug sections to find some debug information not
7849 present in some of them. For the .debug_line, we must find out the
7850 size of address (specified in .debug_info and .debug_aranges). */
7851 for (i = 0, section = section_headers;
7852 i < elf_header.e_shnum && i < num_dump_sects;
7855 char * name = SECTION_NAME (section);
7858 if (section->sh_size == 0)
7861 /* See if there is some pre-scan operation for this section. */
7862 for (j = NUM_ELEM (debug_displays); j--;)
7863 if (strcmp (debug_displays[j].name, name) == 0)
7865 if (debug_displays[j].prescan != NULL)
7867 bfd_size_type length;
7868 unsigned char * start;
7870 length = section->sh_size;
7871 start = ((unsigned char *)
7872 get_data (NULL, file, section->sh_offset, length,
7873 _("debug section data")));
7877 debug_displays[j].prescan (section, start, file);
7885 for (i = 0, section = section_headers;
7886 i < elf_header.e_shnum && i < num_dump_sects;
7889 #ifdef SUPPORT_DISASSEMBLY
7890 if (dump_sects[i] & DISASS_DUMP)
7891 disassemble_section (section, file);
7893 if (dump_sects[i] & HEX_DUMP)
7894 dump_section (section, file);
7896 if (dump_sects[i] & DEBUG_DUMP)
7897 display_debug_section (section, file);
7900 if (i < num_dump_sects)
7901 warn (_("Some sections were not dumped because they do not exist!\n"));
7907 process_mips_fpe_exception (mask)
7913 if (mask & OEX_FPU_INEX)
7914 fputs ("INEX", stdout), first = 0;
7915 if (mask & OEX_FPU_UFLO)
7916 printf ("%sUFLO", first ? "" : "|"), first = 0;
7917 if (mask & OEX_FPU_OFLO)
7918 printf ("%sOFLO", first ? "" : "|"), first = 0;
7919 if (mask & OEX_FPU_DIV0)
7920 printf ("%sDIV0", first ? "" : "|"), first = 0;
7921 if (mask & OEX_FPU_INVAL)
7922 printf ("%sINVAL", first ? "" : "|");
7925 fputs ("0", stdout);
7929 process_mips_specific (file)
7932 Elf_Internal_Dyn * entry;
7933 size_t liblist_offset = 0;
7934 size_t liblistno = 0;
7935 size_t conflictsno = 0;
7936 size_t options_offset = 0;
7937 size_t conflicts_offset = 0;
7939 /* We have a lot of special sections. Thanks SGI! */
7940 if (dynamic_segment == NULL)
7941 /* No information available. */
7944 for (entry = dynamic_segment; entry->d_tag != DT_NULL; ++entry)
7945 switch (entry->d_tag)
7947 case DT_MIPS_LIBLIST:
7948 liblist_offset = entry->d_un.d_val - loadaddr;
7950 case DT_MIPS_LIBLISTNO:
7951 liblistno = entry->d_un.d_val;
7953 case DT_MIPS_OPTIONS:
7954 options_offset = entry->d_un.d_val - loadaddr;
7956 case DT_MIPS_CONFLICT:
7957 conflicts_offset = entry->d_un.d_val - loadaddr;
7959 case DT_MIPS_CONFLICTNO:
7960 conflictsno = entry->d_un.d_val;
7966 if (liblist_offset != 0 && liblistno != 0 && do_dynamic)
7968 Elf32_External_Lib * elib;
7971 elib = ((Elf32_External_Lib *)
7972 get_data (NULL, file, liblist_offset,
7973 liblistno * sizeof (Elf32_External_Lib),
7977 printf ("\nSection '.liblist' contains %lu entries:\n",
7978 (unsigned long) liblistno);
7979 fputs (" Library Time Stamp Checksum Version Flags\n",
7982 for (cnt = 0; cnt < liblistno; ++cnt)
7989 liblist.l_name = BYTE_GET (elib[cnt].l_name);
7990 time = BYTE_GET (elib[cnt].l_time_stamp);
7991 liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum);
7992 liblist.l_version = BYTE_GET (elib[cnt].l_version);
7993 liblist.l_flags = BYTE_GET (elib[cnt].l_flags);
7995 tmp = gmtime (&time);
7996 sprintf (timebuf, "%04u-%02u-%02uT%02u:%02u:%02u",
7997 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
7998 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
8000 printf ("%3lu: %-20s %s %#10lx %-7ld", (unsigned long) cnt,
8001 dynamic_strings + liblist.l_name, timebuf,
8002 liblist.l_checksum, liblist.l_version);
8004 if (liblist.l_flags == 0)
8015 { " EXACT_MATCH", LL_EXACT_MATCH },
8016 { " IGNORE_INT_VER", LL_IGNORE_INT_VER },
8017 { " REQUIRE_MINOR", LL_REQUIRE_MINOR },
8018 { " EXPORTS", LL_EXPORTS },
8019 { " DELAY_LOAD", LL_DELAY_LOAD },
8020 { " DELTA", LL_DELTA }
8022 int flags = liblist.l_flags;
8026 fcnt < sizeof (l_flags_vals) / sizeof (l_flags_vals[0]);
8028 if ((flags & l_flags_vals[fcnt].bit) != 0)
8030 fputs (l_flags_vals[fcnt].name, stdout);
8031 flags ^= l_flags_vals[fcnt].bit;
8034 printf (" %#x", (unsigned int) flags);
8044 if (options_offset != 0)
8046 Elf_External_Options * eopt;
8047 Elf_Internal_Shdr * sect = section_headers;
8048 Elf_Internal_Options * iopt;
8049 Elf_Internal_Options * option;
8053 /* Find the section header so that we get the size. */
8054 while (sect->sh_type != SHT_MIPS_OPTIONS)
8057 eopt = (Elf_External_Options *) get_data (NULL, file, options_offset,
8058 sect->sh_size, _("options"));
8061 iopt = ((Elf_Internal_Options *)
8062 malloc ((sect->sh_size / sizeof (eopt)) * sizeof (* iopt)));
8065 error (_("Out of memory"));
8072 while (offset < sect->sh_size)
8074 Elf_External_Options * eoption;
8076 eoption = (Elf_External_Options *) ((char *) eopt + offset);
8078 option->kind = BYTE_GET (eoption->kind);
8079 option->size = BYTE_GET (eoption->size);
8080 option->section = BYTE_GET (eoption->section);
8081 option->info = BYTE_GET (eoption->info);
8083 offset += option->size;
8089 printf (_("\nSection '%s' contains %d entries:\n"),
8090 SECTION_NAME (sect), cnt);
8098 switch (option->kind)
8101 /* This shouldn't happen. */
8102 printf (" NULL %d %lx", option->section, option->info);
8105 printf (" REGINFO ");
8106 if (elf_header.e_machine == EM_MIPS)
8109 Elf32_External_RegInfo * ereg;
8110 Elf32_RegInfo reginfo;
8112 ereg = (Elf32_External_RegInfo *) (option + 1);
8113 reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask);
8114 reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
8115 reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
8116 reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
8117 reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
8118 reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value);
8120 printf ("GPR %08lx GP 0x%lx\n",
8122 (unsigned long) reginfo.ri_gp_value);
8123 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
8124 reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
8125 reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
8130 Elf64_External_RegInfo * ereg;
8131 Elf64_Internal_RegInfo reginfo;
8133 ereg = (Elf64_External_RegInfo *) (option + 1);
8134 reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask);
8135 reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
8136 reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
8137 reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
8138 reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
8139 reginfo.ri_gp_value = BYTE_GET8 (ereg->ri_gp_value);
8141 printf ("GPR %08lx GP 0x",
8142 reginfo.ri_gprmask);
8143 printf_vma (reginfo.ri_gp_value);
8146 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
8147 reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
8148 reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
8152 case ODK_EXCEPTIONS:
8153 fputs (" EXCEPTIONS fpe_min(", stdout);
8154 process_mips_fpe_exception (option->info & OEX_FPU_MIN);
8155 fputs (") fpe_max(", stdout);
8156 process_mips_fpe_exception ((option->info & OEX_FPU_MAX) >> 8);
8157 fputs (")", stdout);
8159 if (option->info & OEX_PAGE0)
8160 fputs (" PAGE0", stdout);
8161 if (option->info & OEX_SMM)
8162 fputs (" SMM", stdout);
8163 if (option->info & OEX_FPDBUG)
8164 fputs (" FPDBUG", stdout);
8165 if (option->info & OEX_DISMISS)
8166 fputs (" DISMISS", stdout);
8169 fputs (" PAD ", stdout);
8170 if (option->info & OPAD_PREFIX)
8171 fputs (" PREFIX", stdout);
8172 if (option->info & OPAD_POSTFIX)
8173 fputs (" POSTFIX", stdout);
8174 if (option->info & OPAD_SYMBOL)
8175 fputs (" SYMBOL", stdout);
8178 fputs (" HWPATCH ", stdout);
8179 if (option->info & OHW_R4KEOP)
8180 fputs (" R4KEOP", stdout);
8181 if (option->info & OHW_R8KPFETCH)
8182 fputs (" R8KPFETCH", stdout);
8183 if (option->info & OHW_R5KEOP)
8184 fputs (" R5KEOP", stdout);
8185 if (option->info & OHW_R5KCVTL)
8186 fputs (" R5KCVTL", stdout);
8189 fputs (" FILL ", stdout);
8190 /* XXX Print content of info word? */
8193 fputs (" TAGS ", stdout);
8194 /* XXX Print content of info word? */
8197 fputs (" HWAND ", stdout);
8198 if (option->info & OHWA0_R4KEOP_CHECKED)
8199 fputs (" R4KEOP_CHECKED", stdout);
8200 if (option->info & OHWA0_R4KEOP_CLEAN)
8201 fputs (" R4KEOP_CLEAN", stdout);
8204 fputs (" HWOR ", stdout);
8205 if (option->info & OHWA0_R4KEOP_CHECKED)
8206 fputs (" R4KEOP_CHECKED", stdout);
8207 if (option->info & OHWA0_R4KEOP_CLEAN)
8208 fputs (" R4KEOP_CLEAN", stdout);
8211 printf (" GP_GROUP %#06lx self-contained %#06lx",
8212 option->info & OGP_GROUP,
8213 (option->info & OGP_SELF) >> 16);
8216 printf (" IDENT %#06lx self-contained %#06lx",
8217 option->info & OGP_GROUP,
8218 (option->info & OGP_SELF) >> 16);
8221 /* This shouldn't happen. */
8222 printf (" %3d ??? %d %lx",
8223 option->kind, option->section, option->info);
8227 len = sizeof (* eopt);
8228 while (len < option->size)
8229 if (((char *) option)[len] >= ' '
8230 && ((char *) option)[len] < 0x7f)
8231 printf ("%c", ((char *) option)[len++]);
8233 printf ("\\%03o", ((char *) option)[len++]);
8235 fputs ("\n", stdout);
8243 if (conflicts_offset != 0 && conflictsno != 0)
8245 Elf32_Conflict * iconf;
8248 if (dynamic_symbols == NULL)
8250 error (_("conflict list with without table"));
8254 iconf = (Elf32_Conflict *) malloc (conflictsno * sizeof (* iconf));
8257 error (_("Out of memory"));
8263 Elf32_External_Conflict * econf32;
8265 econf32 = ((Elf32_External_Conflict *)
8266 get_data (NULL, file, conflicts_offset,
8267 conflictsno * sizeof (* econf32),
8272 for (cnt = 0; cnt < conflictsno; ++cnt)
8273 iconf[cnt] = BYTE_GET (econf32[cnt]);
8279 Elf64_External_Conflict * econf64;
8281 econf64 = ((Elf64_External_Conflict *)
8282 get_data (NULL, file, conflicts_offset,
8283 conflictsno * sizeof (* econf64),
8288 for (cnt = 0; cnt < conflictsno; ++cnt)
8289 iconf[cnt] = BYTE_GET (econf64[cnt]);
8294 printf (_("\nSection '.conflict' contains %d entries:\n"), conflictsno);
8295 puts (_(" Num: Index Value Name"));
8297 for (cnt = 0; cnt < conflictsno; ++cnt)
8299 Elf_Internal_Sym * psym = &dynamic_symbols[iconf[cnt]];
8301 printf ("%5lu: %8lu ", (unsigned long) cnt, iconf[cnt]);
8302 print_vma (psym->st_value, FULL_HEX);
8303 printf (" %s\n", dynamic_strings + psym->st_name);
8313 get_note_type (e_type)
8316 static char buff[64];
8320 case NT_PRSTATUS: return _("NT_PRSTATUS (prstatus structure)");
8321 case NT_FPREGSET: return _("NT_FPREGSET (floating point registers)");
8322 case NT_PRPSINFO: return _("NT_PRPSINFO (prpsinfo structure)");
8323 case NT_TASKSTRUCT: return _("NT_TASKSTRUCT (task structure)");
8324 case NT_PRXFPREG: return _("NT_PRXFPREG (user_xfpregs structure)");
8325 case NT_PSTATUS: return _("NT_PSTATUS (pstatus structure)");
8326 case NT_FPREGS: return _("NT_FPREGS (floating point registers)");
8327 case NT_PSINFO: return _("NT_PSINFO (psinfo structure)");
8328 case NT_LWPSTATUS: return _("NT_LWPSTATUS (lwpstatus_t structure)");
8329 case NT_LWPSINFO: return _("NT_LWPSINFO (lwpsinfo_t structure)");
8330 case NT_WIN32PSTATUS: return _("NT_WIN32PSTATUS (win32_pstatus strcuture)");
8332 sprintf (buff, _("Unknown note type: (0x%08x)"), e_type);
8337 /* Note that by the ELF standard, the name field is already null byte
8338 terminated, and namesz includes the terminating null byte.
8339 I.E. the value of namesz for the name "FSF" is 4.
8341 If the value of namesz is zero, there is no name present. */
8343 process_note (pnote)
8344 Elf32_Internal_Note * pnote;
8346 printf (" %s\t\t0x%08lx\t%s\n",
8347 pnote->namesz ? pnote->namedata : "(NONE)",
8348 pnote->descsz, get_note_type (pnote->type));
8354 process_corefile_note_segment (file, offset, length)
8359 Elf_External_Note * pnotes;
8360 Elf_External_Note * external;
8366 pnotes = (Elf_External_Note *) get_data (NULL, file, offset, length,
8373 printf (_("\nNotes at offset 0x%08lx with length 0x%08lx:\n"),
8374 (unsigned long) offset, (unsigned long) length);
8375 printf (_(" Owner\t\tData size\tDescription\n"));
8377 while (external < (Elf_External_Note *)((char *) pnotes + length))
8379 Elf32_Internal_Note inote;
8382 inote.type = BYTE_GET (external->type);
8383 inote.namesz = BYTE_GET (external->namesz);
8384 inote.namedata = external->name;
8385 inote.descsz = BYTE_GET (external->descsz);
8386 inote.descdata = inote.namedata + align_power (inote.namesz, 2);
8387 inote.descpos = offset + (inote.descdata - (char *) pnotes);
8389 external = (Elf_External_Note *)(inote.descdata + align_power (inote.descsz, 2));
8391 /* Verify that name is null terminated. It appears that at least
8392 one version of Linux (RedHat 6.0) generates corefiles that don't
8393 comply with the ELF spec by failing to include the null byte in
8395 if (inote.namedata[inote.namesz] != '\0')
8397 temp = malloc (inote.namesz + 1);
8401 error (_("Out of memory\n"));
8406 strncpy (temp, inote.namedata, inote.namesz);
8407 temp[inote.namesz] = 0;
8409 /* warn (_("'%s' NOTE name not properly null terminated\n"), temp); */
8410 inote.namedata = temp;
8413 res &= process_note (& inote);
8428 process_corefile_note_segments (file)
8431 Elf_Internal_Phdr * program_headers;
8432 Elf_Internal_Phdr * segment;
8436 program_headers = (Elf_Internal_Phdr *) malloc
8437 (elf_header.e_phnum * sizeof (Elf_Internal_Phdr));
8439 if (program_headers == NULL)
8441 error (_("Out of memory\n"));
8446 i = get_32bit_program_headers (file, program_headers);
8448 i = get_64bit_program_headers (file, program_headers);
8452 free (program_headers);
8456 for (i = 0, segment = program_headers;
8457 i < elf_header.e_phnum;
8460 if (segment->p_type == PT_NOTE)
8461 res &= process_corefile_note_segment (file,
8462 (bfd_vma) segment->p_offset,
8463 (bfd_vma) segment->p_filesz);
8466 free (program_headers);
8472 process_corefile_contents (file)
8475 /* If we have not been asked to display the notes then do nothing. */
8479 /* If file is not a core file then exit. */
8480 if (elf_header.e_type != ET_CORE)
8483 /* No program headers means no NOTE segment. */
8484 if (elf_header.e_phnum == 0)
8486 printf (_("No note segments present in the core file.\n"));
8490 return process_corefile_note_segments (file);
8494 process_arch_specific (file)
8500 switch (elf_header.e_machine)
8503 case EM_MIPS_RS3_LE:
8504 return process_mips_specific (file);
8513 get_file_header (file)
8516 /* Read in the identity array. */
8517 if (fread (elf_header.e_ident, EI_NIDENT, 1, file) != 1)
8520 /* Determine how to read the rest of the header. */
8521 switch (elf_header.e_ident [EI_DATA])
8523 default: /* fall through */
8524 case ELFDATANONE: /* fall through */
8525 case ELFDATA2LSB: byte_get = byte_get_little_endian; break;
8526 case ELFDATA2MSB: byte_get = byte_get_big_endian; break;
8529 /* For now we only support 32 bit and 64 bit ELF files. */
8530 is_32bit_elf = (elf_header.e_ident [EI_CLASS] != ELFCLASS64);
8532 /* Read in the rest of the header. */
8535 Elf32_External_Ehdr ehdr32;
8537 if (fread (ehdr32.e_type, sizeof (ehdr32) - EI_NIDENT, 1, file) != 1)
8540 elf_header.e_type = BYTE_GET (ehdr32.e_type);
8541 elf_header.e_machine = BYTE_GET (ehdr32.e_machine);
8542 elf_header.e_version = BYTE_GET (ehdr32.e_version);
8543 elf_header.e_entry = BYTE_GET (ehdr32.e_entry);
8544 elf_header.e_phoff = BYTE_GET (ehdr32.e_phoff);
8545 elf_header.e_shoff = BYTE_GET (ehdr32.e_shoff);
8546 elf_header.e_flags = BYTE_GET (ehdr32.e_flags);
8547 elf_header.e_ehsize = BYTE_GET (ehdr32.e_ehsize);
8548 elf_header.e_phentsize = BYTE_GET (ehdr32.e_phentsize);
8549 elf_header.e_phnum = BYTE_GET (ehdr32.e_phnum);
8550 elf_header.e_shentsize = BYTE_GET (ehdr32.e_shentsize);
8551 elf_header.e_shnum = BYTE_GET (ehdr32.e_shnum);
8552 elf_header.e_shstrndx = BYTE_GET (ehdr32.e_shstrndx);
8556 Elf64_External_Ehdr ehdr64;
8558 /* If we have been compiled with sizeof (bfd_vma) == 4, then
8559 we will not be able to cope with the 64bit data found in
8560 64 ELF files. Detect this now and abort before we start
8561 overwritting things. */
8562 if (sizeof (bfd_vma) < 8)
8564 error (_("This instance of readelf has been built without support for a\n"));
8565 error (_("64 bit data type and so it cannot read 64 bit ELF files.\n"));
8569 if (fread (ehdr64.e_type, sizeof (ehdr64) - EI_NIDENT, 1, file) != 1)
8572 elf_header.e_type = BYTE_GET (ehdr64.e_type);
8573 elf_header.e_machine = BYTE_GET (ehdr64.e_machine);
8574 elf_header.e_version = BYTE_GET (ehdr64.e_version);
8575 elf_header.e_entry = BYTE_GET8 (ehdr64.e_entry);
8576 elf_header.e_phoff = BYTE_GET8 (ehdr64.e_phoff);
8577 elf_header.e_shoff = BYTE_GET8 (ehdr64.e_shoff);
8578 elf_header.e_flags = BYTE_GET (ehdr64.e_flags);
8579 elf_header.e_ehsize = BYTE_GET (ehdr64.e_ehsize);
8580 elf_header.e_phentsize = BYTE_GET (ehdr64.e_phentsize);
8581 elf_header.e_phnum = BYTE_GET (ehdr64.e_phnum);
8582 elf_header.e_shentsize = BYTE_GET (ehdr64.e_shentsize);
8583 elf_header.e_shnum = BYTE_GET (ehdr64.e_shnum);
8584 elf_header.e_shstrndx = BYTE_GET (ehdr64.e_shstrndx);
8591 process_file (file_name)
8595 struct stat statbuf;
8598 if (stat (file_name, & statbuf) < 0)
8600 error (_("Cannot stat input file %s.\n"), file_name);
8604 file = fopen (file_name, "rb");
8607 error (_("Input file %s not found.\n"), file_name);
8611 if (! get_file_header (file))
8613 error (_("%s: Failed to read file header\n"), file_name);
8618 /* Initialise per file variables. */
8619 for (i = NUM_ELEM (version_info); i--;)
8620 version_info[i] = 0;
8622 for (i = NUM_ELEM (dynamic_info); i--;)
8623 dynamic_info[i] = 0;
8625 /* Process the file. */
8627 printf (_("\nFile: %s\n"), file_name);
8629 if (! process_file_header ())
8635 process_section_headers (file);
8637 process_program_headers (file);
8639 process_dynamic_segment (file);
8641 process_relocs (file);
8643 process_unwind (file);
8645 process_symbol_table (file);
8647 process_syminfo (file);
8649 process_version_sections (file);
8651 process_section_contents (file);
8653 process_corefile_contents (file);
8655 process_arch_specific (file);
8659 if (section_headers)
8661 free (section_headers);
8662 section_headers = NULL;
8667 free (string_table);
8668 string_table = NULL;
8669 string_table_length = 0;
8672 if (dynamic_strings)
8674 free (dynamic_strings);
8675 dynamic_strings = NULL;
8678 if (dynamic_symbols)
8680 free (dynamic_symbols);
8681 dynamic_symbols = NULL;
8682 num_dynamic_syms = 0;
8685 if (dynamic_syminfo)
8687 free (dynamic_syminfo);
8688 dynamic_syminfo = NULL;
8692 #ifdef SUPPORT_DISASSEMBLY
8693 /* Needed by the i386 disassembler. For extra credit, someone could
8694 fix this so that we insert symbolic addresses here, esp for GOT/PLT
8698 print_address (unsigned int addr, FILE * outfile)
8700 fprintf (outfile,"0x%8.8x", addr);
8703 /* Needed by the i386 disassembler. */
8705 db_task_printsym (unsigned int addr)
8707 print_address (addr, stderr);
8716 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
8717 setlocale (LC_MESSAGES, "");
8719 bindtextdomain (PACKAGE, LOCALEDIR);
8720 textdomain (PACKAGE);
8722 parse_args (argc, argv);
8724 if (optind < (argc - 1))
8727 while (optind < argc)
8728 process_file (argv [optind ++]);
8730 if (dump_sects != NULL)