1 /* readelf.c -- display contents of an ELF format file
2 Copyright (C) 1998, 99, 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"
81 char * program_name = "readelf";
82 unsigned int dynamic_addr;
83 bfd_size_type dynamic_size;
84 unsigned int rela_addr;
85 unsigned int rela_size;
86 char * dynamic_strings;
88 unsigned long string_table_length;
89 unsigned long num_dynamic_syms;
90 Elf_Internal_Sym * dynamic_symbols;
91 Elf_Internal_Syminfo * dynamic_syminfo;
92 unsigned long dynamic_syminfo_offset;
93 unsigned int dynamic_syminfo_nent;
94 char program_interpreter [64];
95 int dynamic_info[DT_JMPREL + 1];
98 Elf_Internal_Ehdr elf_header;
99 Elf_Internal_Shdr * section_headers;
100 Elf_Internal_Dyn * dynamic_segment;
107 int do_using_dynamic;
114 int do_debug_abbrevs;
116 int do_debug_pubnames;
117 int do_debug_aranges;
123 /* A dynamic array of flags indicating which sections require dumping. */
124 char * dump_sects = NULL;
125 unsigned int num_dump_sects = 0;
127 #define HEX_DUMP (1 << 0)
128 #define DISASS_DUMP (1 << 1)
129 #define DEBUG_DUMP (1 << 2)
131 /* How to rpint a vma value. */
132 typedef enum print_mode
144 /* Forward declarations for dumb compilers. */
145 static void print_vma PARAMS ((bfd_vma, print_mode));
146 static bfd_vma (* byte_get) PARAMS ((unsigned char *, int));
147 static bfd_vma byte_get_little_endian PARAMS ((unsigned char *, int));
148 static bfd_vma byte_get_big_endian PARAMS ((unsigned char *, int));
149 static const char * get_mips_dynamic_type PARAMS ((unsigned long));
150 static const char * get_sparc64_dynamic_type PARAMS ((unsigned long));
151 static const char * get_parisc_dynamic_type PARAMS ((unsigned long));
152 static const char * get_dynamic_type PARAMS ((unsigned long));
153 static int dump_relocations PARAMS ((FILE *, unsigned long, unsigned long, Elf_Internal_Sym *, unsigned long, char *, int));
154 static char * get_file_type PARAMS ((unsigned));
155 static char * get_machine_name PARAMS ((unsigned));
156 static void decode_ARM_machine_flags PARAMS ((unsigned, char []));
157 static char * get_machine_flags PARAMS ((unsigned, unsigned));
158 static const char * get_mips_segment_type PARAMS ((unsigned long));
159 static const char * get_parisc_segment_type PARAMS ((unsigned long));
160 static const char * get_segment_type PARAMS ((unsigned long));
161 static const char * get_mips_section_type_name PARAMS ((unsigned int));
162 static const char * get_parisc_section_type_name PARAMS ((unsigned int));
163 static const char * get_section_type_name PARAMS ((unsigned int));
164 static const char * get_symbol_binding PARAMS ((unsigned int));
165 static const char * get_symbol_type PARAMS ((unsigned int));
166 static const char * get_symbol_visibility PARAMS ((unsigned int));
167 static const char * get_symbol_index_type PARAMS ((unsigned int));
168 static const char * get_dynamic_flags PARAMS ((bfd_vma));
169 static void usage PARAMS ((void));
170 static void parse_args PARAMS ((int, char **));
171 static int process_file_header PARAMS ((void));
172 static int process_program_headers PARAMS ((FILE *));
173 static int process_section_headers PARAMS ((FILE *));
174 static void dynamic_segment_mips_val PARAMS ((Elf_Internal_Dyn *));
175 static void dynamic_segment_parisc_val PARAMS ((Elf_Internal_Dyn *));
176 static int process_dynamic_segment PARAMS ((FILE *));
177 static int process_symbol_table PARAMS ((FILE *));
178 static int process_section_contents PARAMS ((FILE *));
179 static void process_file PARAMS ((char *));
180 static int process_relocs PARAMS ((FILE *));
181 static int process_version_sections PARAMS ((FILE *));
182 static char * get_ver_flags PARAMS ((unsigned int));
183 static int get_32bit_section_headers PARAMS ((FILE *));
184 static int get_64bit_section_headers PARAMS ((FILE *));
185 static int get_32bit_program_headers PARAMS ((FILE *, Elf_Internal_Phdr *));
186 static int get_64bit_program_headers PARAMS ((FILE *, Elf_Internal_Phdr *));
187 static int get_file_header PARAMS ((FILE *));
188 static Elf_Internal_Sym * get_32bit_elf_symbols PARAMS ((FILE *, unsigned long, unsigned long));
189 static Elf_Internal_Sym * get_64bit_elf_symbols PARAMS ((FILE *, unsigned long, unsigned long));
190 static int * get_dynamic_data PARAMS ((FILE *, unsigned int));
191 static int get_32bit_dynamic_segment PARAMS ((FILE *));
192 static int get_64bit_dynamic_segment PARAMS ((FILE *));
193 #ifdef SUPPORT_DISASSEMBLY
194 static int disassemble_section PARAMS ((Elf32_Internal_Shdr *, FILE *));
196 static int dump_section PARAMS ((Elf32_Internal_Shdr *, FILE *));
197 static int display_debug_section PARAMS ((Elf32_Internal_Shdr *, FILE *));
198 static int display_debug_info PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
199 static int display_debug_not_supported PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
200 static int display_debug_lines PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
201 static int display_debug_abbrev PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
202 static int display_debug_aranges PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
203 static int display_debug_frames PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
204 static unsigned char * process_abbrev_section PARAMS ((unsigned char *, unsigned char *));
205 static unsigned long read_leb128 PARAMS ((unsigned char *, int *, int));
206 static int process_extended_line_op PARAMS ((unsigned char *, int, int));
207 static void reset_state_machine PARAMS ((int));
208 static char * get_TAG_name PARAMS ((unsigned long));
209 static char * get_AT_name PARAMS ((unsigned long));
210 static char * get_FORM_name PARAMS ((unsigned long));
211 static void free_abbrevs PARAMS ((void));
212 static void add_abbrev PARAMS ((unsigned long, unsigned long, int));
213 static void add_abbrev_attr PARAMS ((unsigned long, unsigned long));
214 static unsigned char * read_and_display_attr PARAMS ((unsigned long, unsigned long, unsigned char *, unsigned long, unsigned long));
215 static unsigned char * display_block PARAMS ((unsigned char *, unsigned long));
216 static void decode_location_expression PARAMS ((unsigned char *, unsigned int, unsigned long));
217 static void request_dump PARAMS ((unsigned int, char));
218 static const char * get_elf_class PARAMS ((unsigned char));
219 static const char * get_data_encoding PARAMS ((unsigned char));
220 static const char * get_osabi_name PARAMS ((unsigned char));
221 static int guess_is_rela PARAMS ((unsigned long));
222 static char * get_note_type PARAMS ((unsigned int));
223 static int process_note PARAMS ((Elf32_Internal_Note *));
224 static int process_corefile_note_segment PARAMS ((FILE *, bfd_vma, bfd_vma));
225 static int process_corefile_note_segments PARAMS ((FILE *));
226 static int process_corefile_contents PARAMS ((FILE *));
228 typedef int Elf32_Word;
236 #define SECTION_NAME(X) ((X) == NULL ? "<none>" : \
237 ((X)->sh_name >= string_table_length \
238 ? "<corrupt>" : string_table + (X)->sh_name))
240 #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
242 #define BYTE_GET(field) byte_get (field, sizeof (field))
244 /* If we can support a 64 bit data type then BFD64 should be defined
245 and sizeof (bfd_vma) == 8. In this case when translating from an
246 external 8 byte field to an internal field, we can assume that the
247 internal field is also 8 bytes wide and so we can extact all the data.
248 If, however, BFD64 is not defined, then we must assume that the
249 internal data structure only has 4 byte wide fields that are the
250 equivalent of the 8 byte wide external counterparts, and so we must
251 truncate the data. */
253 #define BYTE_GET8(field) byte_get (field, -8)
255 #define BYTE_GET8(field) byte_get (field, 8)
258 #define NUM_ELEM(array) (sizeof (array) / sizeof ((array)[0]))
260 #define GET_DATA_ALLOC(offset, size, var, type, reason) \
261 if (fseek (file, offset, SEEK_SET)) \
263 error (_("Unable to seek to start of %s at %x\n"), reason, offset); \
267 var = (type) malloc (size); \
271 error (_("Out of memory allocating %d bytes for %s\n"), size, reason); \
275 if (fread (var, size, 1, file) != 1) \
277 error (_("Unable to read in %d bytes of %s\n"), size, reason); \
284 #define GET_DATA(offset, var, reason) \
285 if (fseek (file, offset, SEEK_SET)) \
287 error (_("Unable to seek to %x for %s\n"), offset, reason); \
290 else if (fread (& var, sizeof (var), 1, file) != 1) \
292 error (_("Unable to read data at %x for %s\n"), offset, reason); \
296 #define GET_ELF_SYMBOLS(file, offset, size) \
297 (is_32bit_elf ? get_32bit_elf_symbols (file, offset, size) \
298 : get_64bit_elf_symbols (file, offset, size))
301 #ifdef ANSI_PROTOTYPES
303 error (const char * message, ...)
307 fprintf (stderr, _("%s: Error: "), program_name);
308 va_start (args, message);
309 vfprintf (stderr, message, args);
315 warn (const char * message, ...)
319 fprintf (stderr, _("%s: Warning: "), program_name);
320 va_start (args, message);
321 vfprintf (stderr, message, args);
333 fprintf (stderr, _("%s: Error: "), program_name);
335 message = va_arg (args, char *);
336 vfprintf (stderr, message, args);
348 fprintf (stderr, _("%s: Warning: "), program_name);
350 message = va_arg (args, char *);
351 vfprintf (stderr, message, args);
358 byte_get_little_endian (field, size)
359 unsigned char * field;
368 return ((unsigned int) (field [0]))
369 | (((unsigned int) (field [1])) << 8);
372 /* We want to extract data from an 8 byte wide field and
373 place it into a 4 byte wide field. Since this is a little
374 endian source we can juts use the 4 byte extraction code. */
377 return ((unsigned long) (field [0]))
378 | (((unsigned long) (field [1])) << 8)
379 | (((unsigned long) (field [2])) << 16)
380 | (((unsigned long) (field [3])) << 24);
384 /* This is a special case, generated by the BYTE_GET8 macro.
385 It means that we are loading an 8 byte value from a field
386 in an external structure into an 8 byte value in a field
387 in an internal strcuture. */
388 return ((bfd_vma) (field [0]))
389 | (((bfd_vma) (field [1])) << 8)
390 | (((bfd_vma) (field [2])) << 16)
391 | (((bfd_vma) (field [3])) << 24)
392 | (((bfd_vma) (field [4])) << 32)
393 | (((bfd_vma) (field [5])) << 40)
394 | (((bfd_vma) (field [6])) << 48)
395 | (((bfd_vma) (field [7])) << 56);
398 error (_("Unhandled data length: %d\n"), size);
403 /* Print a VMA value. */
405 print_vma (vma, mode)
415 case FULL_HEX: printf ("0x"); /* drop through */
416 case LONG_HEX: printf ("%8.8lx", (unsigned long) vma); break;
417 case PREFIX_HEX: printf ("0x"); /* drop through */
418 case HEX: printf ("%lx", (unsigned long) vma); break;
419 case DEC: printf ("%ld", (unsigned long) vma); break;
420 case DEC_5: printf ("%5ld", (long) vma); break;
421 case UNSIGNED: printf ("%lu", (unsigned long) vma); break;
442 #if BFD_HOST_64BIT_LONG
445 if (_bfd_int64_high (vma))
446 printf ("%lx%lx", _bfd_int64_high (vma), _bfd_int64_low (vma));
448 printf ("%lx", _bfd_int64_low (vma));
453 #if BFD_HOST_64BIT_LONG
456 if (_bfd_int64_high (vma))
458 printf ("++%ld", _bfd_int64_low (vma));
460 printf ("%ld", _bfd_int64_low (vma));
465 #if BFD_HOST_64BIT_LONG
466 printf ("%5ld", vma);
468 if (_bfd_int64_high (vma))
470 printf ("++%ld", _bfd_int64_low (vma));
472 printf ("%5ld", _bfd_int64_low (vma));
477 #if BFD_HOST_64BIT_LONG
480 if (_bfd_int64_high (vma))
482 printf ("++%lu", _bfd_int64_low (vma));
484 printf ("%lu", _bfd_int64_low (vma));
493 byte_get_big_endian (field, size)
494 unsigned char * field;
503 return ((unsigned int) (field [1])) | (((int) (field [0])) << 8);
506 return ((unsigned long) (field [3]))
507 | (((unsigned long) (field [2])) << 8)
508 | (((unsigned long) (field [1])) << 16)
509 | (((unsigned long) (field [0])) << 24);
512 /* Although we are extracing data from an 8 byte wide field, we
513 are returning only 4 bytes of data. */
514 return ((unsigned long) (field [7]))
515 | (((unsigned long) (field [6])) << 8)
516 | (((unsigned long) (field [5])) << 16)
517 | (((unsigned long) (field [4])) << 24);
521 /* This is a special case, generated by the BYTE_GET8 macro.
522 It means that we are loading an 8 byte value from a field
523 in an external structure into an 8 byte value in a field
524 in an internal strcuture. */
525 return ((bfd_vma) (field [7]))
526 | (((bfd_vma) (field [6])) << 8)
527 | (((bfd_vma) (field [5])) << 16)
528 | (((bfd_vma) (field [4])) << 24)
529 | (((bfd_vma) (field [3])) << 32)
530 | (((bfd_vma) (field [2])) << 40)
531 | (((bfd_vma) (field [1])) << 48)
532 | (((bfd_vma) (field [0])) << 56);
536 error (_("Unhandled data length: %d\n"), size);
541 /* Guess the relocation size commonly used by the specific machines. */
544 guess_is_rela (e_machine)
545 unsigned long e_machine;
549 /* Targets that use REL relocations. */
560 /* Targets that use RELA relocations. */
568 case EM_CYGNUS_MN10200:
569 case EM_CYGNUS_MN10300:
600 warn (_("Don't know about relocations on this machine architecture\n"));
605 /* Display the contents of the relocation data found at the specified offset. */
607 dump_relocations (file, rel_offset, rel_size, symtab, nsyms, strtab, is_rela)
609 unsigned long rel_offset;
610 unsigned long rel_size;
611 Elf_Internal_Sym * symtab;
617 Elf_Internal_Rel * rels;
618 Elf_Internal_Rela * relas;
621 if (is_rela == UNKNOWN)
622 is_rela = guess_is_rela (elf_header.e_machine);
628 Elf32_External_Rela * erelas;
630 GET_DATA_ALLOC (rel_offset, rel_size, erelas,
631 Elf32_External_Rela *, "relocs");
633 rel_size = rel_size / sizeof (Elf32_External_Rela);
635 relas = (Elf_Internal_Rela *)
636 malloc (rel_size * sizeof (Elf_Internal_Rela));
640 error(_("out of memory parsing relocs"));
644 for (i = 0; i < rel_size; i++)
646 relas[i].r_offset = BYTE_GET (erelas[i].r_offset);
647 relas[i].r_info = BYTE_GET (erelas[i].r_info);
648 relas[i].r_addend = BYTE_GET (erelas[i].r_addend);
653 rels = (Elf_Internal_Rel *) relas;
657 Elf64_External_Rela * erelas;
659 GET_DATA_ALLOC (rel_offset, rel_size, erelas,
660 Elf64_External_Rela *, "relocs");
662 rel_size = rel_size / sizeof (Elf64_External_Rela);
664 relas = (Elf_Internal_Rela *)
665 malloc (rel_size * sizeof (Elf_Internal_Rela));
669 error(_("out of memory parsing relocs"));
673 for (i = 0; i < rel_size; i++)
675 relas[i].r_offset = BYTE_GET8 (erelas[i].r_offset);
676 relas[i].r_info = BYTE_GET8 (erelas[i].r_info);
677 relas[i].r_addend = BYTE_GET8 (erelas[i].r_addend);
682 rels = (Elf_Internal_Rel *) relas;
689 Elf32_External_Rel * erels;
691 GET_DATA_ALLOC (rel_offset, rel_size, erels,
692 Elf32_External_Rel *, "relocs");
694 rel_size = rel_size / sizeof (Elf32_External_Rel);
696 rels = (Elf_Internal_Rel *)
697 malloc (rel_size * sizeof (Elf_Internal_Rel));
701 error(_("out of memory parsing relocs"));
705 for (i = 0; i < rel_size; i++)
707 rels[i].r_offset = BYTE_GET (erels[i].r_offset);
708 rels[i].r_info = BYTE_GET (erels[i].r_info);
713 relas = (Elf_Internal_Rela *) rels;
717 Elf64_External_Rel * erels;
719 GET_DATA_ALLOC (rel_offset, rel_size, erels,
720 Elf64_External_Rel *, "relocs");
722 rel_size = rel_size / sizeof (Elf64_External_Rel);
724 rels = (Elf_Internal_Rel *)
725 malloc (rel_size * sizeof (Elf_Internal_Rel));
729 error(_("out of memory parsing relocs"));
733 for (i = 0; i < rel_size; i++)
735 rels[i].r_offset = BYTE_GET8 (erels[i].r_offset);
736 rels[i].r_info = BYTE_GET8 (erels[i].r_info);
741 relas = (Elf_Internal_Rela *) rels;
747 (_(" Offset Info Type Symbol's Value Symbol's Name Addend\n"));
750 (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
752 for (i = 0; i < rel_size; i++)
757 bfd_vma symtab_index;
762 offset = relas [i].r_offset;
763 info = relas [i].r_info;
767 offset = rels [i].r_offset;
768 info = rels [i].r_info;
773 type = ELF32_R_TYPE (info);
774 symtab_index = ELF32_R_SYM (info);
778 if (elf_header.e_machine == EM_SPARCV9)
779 type = ELF64_R_TYPE_ID (info);
781 type = ELF64_R_TYPE (info);
782 /* The #ifdef BFD64 below is to prevent a compile time warning.
783 We know that if we do not have a 64 bit data type that we
784 will never execute this code anyway. */
786 symtab_index = ELF64_R_SYM (info);
790 #ifdef _bfd_int64_low
791 printf (" %8.8lx %5.5lx ", _bfd_int64_low (offset), _bfd_int64_low (info));
793 printf (" %8.8lx %5.5lx ", offset, info);
796 switch (elf_header.e_machine)
803 rtype = elf_m32r_reloc_type (type);
808 rtype = elf_i386_reloc_type (type);
812 rtype = elf_m68k_reloc_type (type);
816 rtype = elf_i960_reloc_type (type);
820 rtype = elf_avr_reloc_type (type);
827 rtype = elf_sparc_reloc_type (type);
831 rtype = v850_reloc_type (type);
835 rtype = elf_d10v_reloc_type (type);
839 rtype = elf_d30v_reloc_type (type);
843 rtype = elf_sh_reloc_type (type);
846 case EM_CYGNUS_MN10300:
847 rtype = elf_mn10300_reloc_type (type);
850 case EM_CYGNUS_MN10200:
851 rtype = elf_mn10200_reloc_type (type);
855 rtype = elf_fr30_reloc_type (type);
859 rtype = elf_mcore_reloc_type (type);
863 rtype = elf_ppc_reloc_type (type);
868 rtype = elf_mips_reloc_type (type);
872 rtype = elf_alpha_reloc_type (type);
876 rtype = elf_arm_reloc_type (type);
881 rtype = elf_arc_reloc_type (type);
885 rtype = elf_hppa_reloc_type (type);
889 rtype = elf_pj_reloc_type (type);
892 rtype = elf_ia64_reloc_type (type);
896 rtype = elf_cris_reloc_type (type);
900 rtype = elf_i860_reloc_type (type);
904 rtype = elf_x86_64_reloc_type (type);
909 #ifdef _bfd_int64_low
910 printf (_("unrecognised: %-7lx"), _bfd_int64_low (type));
912 printf (_("unrecognised: %-7lx"), type);
915 printf ("%-21.21s", rtype);
921 if (symtab_index >= nsyms)
922 printf (" bad symbol index: %08lx", (unsigned long) symtab_index);
925 Elf_Internal_Sym * psym;
927 psym = symtab + symtab_index;
930 print_vma (psym->st_value, LONG_HEX);
933 if (psym->st_name == 0)
935 SECTION_NAME (section_headers + psym->st_shndx));
936 else if (strtab == NULL)
937 printf (_("<string table index %3ld>"), psym->st_name);
939 printf ("%-25.25s", strtab + psym->st_name);
942 printf (" + %lx", (unsigned long) relas [i].r_addend);
948 printf ("%*c", is_32bit_elf ? 34 : 26, ' ');
949 print_vma (relas[i].r_addend, LONG_HEX);
952 if (elf_header.e_machine == EM_SPARCV9
953 && !strcmp (rtype, "R_SPARC_OLO10"))
954 printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (info));
965 get_mips_dynamic_type (type)
970 case DT_MIPS_RLD_VERSION: return "MIPS_RLD_VERSION";
971 case DT_MIPS_TIME_STAMP: return "MIPS_TIME_STAMP";
972 case DT_MIPS_ICHECKSUM: return "MIPS_ICHECKSUM";
973 case DT_MIPS_IVERSION: return "MIPS_IVERSION";
974 case DT_MIPS_FLAGS: return "MIPS_FLAGS";
975 case DT_MIPS_BASE_ADDRESS: return "MIPS_BASE_ADDRESS";
976 case DT_MIPS_MSYM: return "MIPS_MSYM";
977 case DT_MIPS_CONFLICT: return "MIPS_CONFLICT";
978 case DT_MIPS_LIBLIST: return "MIPS_LIBLIST";
979 case DT_MIPS_LOCAL_GOTNO: return "MIPS_LOCAL_GOTNO";
980 case DT_MIPS_CONFLICTNO: return "MIPS_CONFLICTNO";
981 case DT_MIPS_LIBLISTNO: return "MIPS_LIBLISTNO";
982 case DT_MIPS_SYMTABNO: return "MIPS_SYMTABNO";
983 case DT_MIPS_UNREFEXTNO: return "MIPS_UNREFEXTNO";
984 case DT_MIPS_GOTSYM: return "MIPS_GOTSYM";
985 case DT_MIPS_HIPAGENO: return "MIPS_HIPAGENO";
986 case DT_MIPS_RLD_MAP: return "MIPS_RLD_MAP";
987 case DT_MIPS_DELTA_CLASS: return "MIPS_DELTA_CLASS";
988 case DT_MIPS_DELTA_CLASS_NO: return "MIPS_DELTA_CLASS_NO";
989 case DT_MIPS_DELTA_INSTANCE: return "MIPS_DELTA_INSTANCE";
990 case DT_MIPS_DELTA_INSTANCE_NO: return "MIPS_DELTA_INSTANCE_NO";
991 case DT_MIPS_DELTA_RELOC: return "MIPS_DELTA_RELOC";
992 case DT_MIPS_DELTA_RELOC_NO: return "MIPS_DELTA_RELOC_NO";
993 case DT_MIPS_DELTA_SYM: return "MIPS_DELTA_SYM";
994 case DT_MIPS_DELTA_SYM_NO: return "MIPS_DELTA_SYM_NO";
995 case DT_MIPS_DELTA_CLASSSYM: return "MIPS_DELTA_CLASSSYM";
996 case DT_MIPS_DELTA_CLASSSYM_NO: return "MIPS_DELTA_CLASSSYM_NO";
997 case DT_MIPS_CXX_FLAGS: return "MIPS_CXX_FLAGS";
998 case DT_MIPS_PIXIE_INIT: return "MIPS_PIXIE_INIT";
999 case DT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB";
1000 case DT_MIPS_LOCALPAGE_GOTIDX: return "MIPS_LOCALPAGE_GOTIDX";
1001 case DT_MIPS_LOCAL_GOTIDX: return "MIPS_LOCAL_GOTIDX";
1002 case DT_MIPS_HIDDEN_GOTIDX: return "MIPS_HIDDEN_GOTIDX";
1003 case DT_MIPS_PROTECTED_GOTIDX: return "MIPS_PROTECTED_GOTIDX";
1004 case DT_MIPS_OPTIONS: return "MIPS_OPTIONS";
1005 case DT_MIPS_INTERFACE: return "MIPS_INTERFACE";
1006 case DT_MIPS_DYNSTR_ALIGN: return "MIPS_DYNSTR_ALIGN";
1007 case DT_MIPS_INTERFACE_SIZE: return "MIPS_INTERFACE_SIZE";
1008 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
1009 case DT_MIPS_PERF_SUFFIX: return "MIPS_PERF_SUFFIX";
1010 case DT_MIPS_COMPACT_SIZE: return "MIPS_COMPACT_SIZE";
1011 case DT_MIPS_GP_VALUE: return "MIPS_GP_VALUE";
1012 case DT_MIPS_AUX_DYNAMIC: return "MIPS_AUX_DYNAMIC";
1019 get_sparc64_dynamic_type (type)
1024 case DT_SPARC_REGISTER: return "SPARC_REGISTER";
1031 get_parisc_dynamic_type (type)
1036 case DT_HP_LOAD_MAP: return "HP_LOAD_MAP";
1037 case DT_HP_DLD_FLAGS: return "HP_DLD_FLAGS";
1038 case DT_HP_DLD_HOOK: return "HP_DLD_HOOK";
1039 case DT_HP_UX10_INIT: return "HP_UX10_INIT";
1040 case DT_HP_UX10_INITSZ: return "HP_UX10_INITSZ";
1041 case DT_HP_PREINIT: return "HP_PREINIT";
1042 case DT_HP_PREINITSZ: return "HP_PREINITSZ";
1043 case DT_HP_NEEDED: return "HP_NEEDED";
1044 case DT_HP_TIME_STAMP: return "HP_TIME_STAMP";
1045 case DT_HP_CHECKSUM: return "HP_CHECKSUM";
1046 case DT_HP_GST_SIZE: return "HP_GST_SIZE";
1047 case DT_HP_GST_VERSION: return "HP_GST_VERSION";
1048 case DT_HP_GST_HASHVAL: return "HP_GST_HASHVAL";
1055 get_dynamic_type (type)
1058 static char buff [32];
1062 case DT_NULL: return "NULL";
1063 case DT_NEEDED: return "NEEDED";
1064 case DT_PLTRELSZ: return "PLTRELSZ";
1065 case DT_PLTGOT: return "PLTGOT";
1066 case DT_HASH: return "HASH";
1067 case DT_STRTAB: return "STRTAB";
1068 case DT_SYMTAB: return "SYMTAB";
1069 case DT_RELA: return "RELA";
1070 case DT_RELASZ: return "RELASZ";
1071 case DT_RELAENT: return "RELAENT";
1072 case DT_STRSZ: return "STRSZ";
1073 case DT_SYMENT: return "SYMENT";
1074 case DT_INIT: return "INIT";
1075 case DT_FINI: return "FINI";
1076 case DT_SONAME: return "SONAME";
1077 case DT_RPATH: return "RPATH";
1078 case DT_SYMBOLIC: return "SYMBOLIC";
1079 case DT_REL: return "REL";
1080 case DT_RELSZ: return "RELSZ";
1081 case DT_RELENT: return "RELENT";
1082 case DT_PLTREL: return "PLTREL";
1083 case DT_DEBUG: return "DEBUG";
1084 case DT_TEXTREL: return "TEXTREL";
1085 case DT_JMPREL: return "JMPREL";
1086 case DT_BIND_NOW: return "BIND_NOW";
1087 case DT_INIT_ARRAY: return "INIT_ARRAY";
1088 case DT_FINI_ARRAY: return "FINI_ARRAY";
1089 case DT_INIT_ARRAYSZ: return "INIT_ARRAYSZ";
1090 case DT_FINI_ARRAYSZ: return "FINI_ARRAYSZ";
1091 case DT_RUNPATH: return "RUNPATH";
1092 case DT_FLAGS: return "FLAGS";
1094 case DT_PREINIT_ARRAY: return "PREINIT_ARRAY";
1095 case DT_PREINIT_ARRAYSZ: return "PREINIT_ARRAYSZ";
1097 case DT_CHECKSUM: return "CHECKSUM";
1098 case DT_PLTPADSZ: return "PLTPADSZ";
1099 case DT_MOVEENT: return "MOVEENT";
1100 case DT_MOVESZ: return "MOVESZ";
1101 case DT_FEATURE: return "FEATURE";
1102 case DT_POSFLAG_1: return "POSFLAG_1";
1103 case DT_SYMINSZ: return "SYMINSZ";
1104 case DT_SYMINENT: return "SYMINENT"; /* aka VALRNGHI */
1106 case DT_ADDRRNGLO: return "ADDRRNGLO";
1107 case DT_CONFIG: return "CONFIG";
1108 case DT_DEPAUDIT: return "DEPAUDIT";
1109 case DT_AUDIT: return "AUDIT";
1110 case DT_PLTPAD: return "PLTPAD";
1111 case DT_MOVETAB: return "MOVETAB";
1112 case DT_SYMINFO: return "SYMINFO"; /* aka ADDRRNGHI */
1114 case DT_VERSYM: return "VERSYM";
1116 case DT_RELACOUNT: return "RELACOUNT";
1117 case DT_RELCOUNT: return "RELCOUNT";
1118 case DT_FLAGS_1: return "FLAGS_1";
1119 case DT_VERDEF: return "VERDEF";
1120 case DT_VERDEFNUM: return "VERDEFNUM";
1121 case DT_VERNEED: return "VERNEED";
1122 case DT_VERNEEDNUM: return "VERNEEDNUM";
1124 case DT_AUXILIARY: return "AUXILIARY";
1125 case DT_USED: return "USED";
1126 case DT_FILTER: return "FILTER";
1129 if ((type >= DT_LOPROC) && (type <= DT_HIPROC))
1131 const char * result;
1133 switch (elf_header.e_machine)
1136 case EM_MIPS_RS4_BE:
1137 result = get_mips_dynamic_type (type);
1140 result = get_sparc64_dynamic_type (type);
1150 sprintf (buff, _("Processor Specific: %lx"), type);
1152 else if ((type >= DT_LOOS) && (type <= DT_HIOS))
1154 const char * result;
1156 switch (elf_header.e_machine)
1159 result = get_parisc_dynamic_type (type);
1169 sprintf (buff, _("Operating System specific: %lx"), type);
1172 sprintf (buff, _("<unknown>: %lx"), type);
1179 get_file_type (e_type)
1182 static char buff [32];
1186 case ET_NONE: return _("NONE (None)");
1187 case ET_REL: return _("REL (Relocatable file)");
1188 case ET_EXEC: return _("EXEC (Executable file)");
1189 case ET_DYN: return _("DYN (Shared object file)");
1190 case ET_CORE: return _("CORE (Core file)");
1193 if ((e_type >= ET_LOPROC) && (e_type <= ET_HIPROC))
1194 sprintf (buff, _("Processor Specific: (%x)"), e_type);
1195 else if ((e_type >= ET_LOOS) && (e_type <= ET_HIOS))
1196 sprintf (buff, _("OS Specific: (%x)"), e_type);
1198 sprintf (buff, _("<unknown>: %x"), e_type);
1204 get_machine_name (e_machine)
1207 static char buff [64]; /* XXX */
1211 case EM_NONE: return _("None");
1212 case EM_M32: return "WE32100";
1213 case EM_SPARC: return "Sparc";
1214 case EM_386: return "Intel 80386";
1215 case EM_68K: return "MC68000";
1216 case EM_88K: return "MC88000";
1217 case EM_486: return "Intel 80486";
1218 case EM_860: return "Intel 80860";
1219 case EM_MIPS: return "MIPS R3000";
1220 case EM_S370: return "IBM System/370";
1221 case EM_MIPS_RS4_BE: return "MIPS R4000 big-endian";
1222 case EM_OLD_SPARCV9: return "Sparc v9 (old)";
1223 case EM_PARISC: return "HPPA";
1224 case EM_PPC_OLD: return "Power PC (old)";
1225 case EM_SPARC32PLUS: return "Sparc v8+" ;
1226 case EM_960: return "Intel 90860";
1227 case EM_PPC: return "PowerPC";
1228 case EM_V800: return "NEC V800";
1229 case EM_FR20: return "Fujitsu FR20";
1230 case EM_RH32: return "TRW RH32";
1231 case EM_MCORE: return "MCORE";
1232 case EM_ARM: return "ARM";
1233 case EM_OLD_ALPHA: return "Digital Alpha (old)";
1234 case EM_SH: return "Hitachi SH";
1235 case EM_SPARCV9: return "Sparc v9";
1236 case EM_TRICORE: return "Siemens Tricore";
1237 case EM_ARC: return "ARC";
1238 case EM_H8_300: return "Hitachi H8/300";
1239 case EM_H8_300H: return "Hitachi H8/300H";
1240 case EM_H8S: return "Hitachi H8S";
1241 case EM_H8_500: return "Hitachi H8/500";
1242 case EM_IA_64: return "Intel IA-64";
1243 case EM_MIPS_X: return "Stanford MIPS-X";
1244 case EM_COLDFIRE: return "Motorola Coldfire";
1245 case EM_68HC12: return "Motorola M68HC12";
1246 case EM_ALPHA: return "Alpha";
1247 case EM_CYGNUS_D10V: return "d10v";
1248 case EM_CYGNUS_D30V: return "d30v";
1249 case EM_CYGNUS_ARC: return "ARC";
1250 case EM_CYGNUS_M32R: return "Mitsubishi M32r";
1251 case EM_CYGNUS_V850: return "NEC v850";
1252 case EM_CYGNUS_MN10300: return "mn10300";
1253 case EM_CYGNUS_MN10200: return "mn10200";
1254 case EM_CYGNUS_FR30: return "Fujitsu FR30";
1255 case EM_PJ: return "picoJava";
1256 case EM_MMA: return "Fujitsu Multimedia Accelerator";
1257 case EM_PCP: return "Siemens PCP";
1258 case EM_NCPU: return "Sony nCPU embedded RISC processor";
1259 case EM_NDR1: return "Denso NDR1 microprocesspr";
1260 case EM_STARCORE: return "Motorola Star*Core processor";
1261 case EM_ME16: return "Toyota ME16 processor";
1262 case EM_ST100: return "STMicroelectronics ST100 processor";
1263 case EM_TINYJ: return "Advanced Logic Corp. TinyJ embedded processor";
1264 case EM_FX66: return "Siemens FX66 microcontroller";
1265 case EM_ST9PLUS: return "STMicroelectronics ST9+ 8/16 bit microcontroller";
1266 case EM_ST7: return "STMicroelectronics ST7 8-bit microcontroller";
1267 case EM_68HC16: return "Motorola MC68HC16 Microcontroller";
1268 case EM_68HC11: return "Motorola MC68HC11 Microcontroller";
1269 case EM_68HC08: return "Motorola MC68HC08 Microcontroller";
1270 case EM_68HC05: return "Motorola MC68HC05 Microcontroller";
1271 case EM_SVX: return "Silicon Graphics SVx";
1272 case EM_ST19: return "STMicroelectronics ST19 8-bit microcontroller";
1273 case EM_VAX: return "Digital VAX";
1274 case EM_AVR: return "Atmel AVR 8-bit microcontroller";
1275 case EM_CRIS: return "Axis Communications 32-bit embedded processor";
1276 case EM_JAVELIN: return "Infineon Technologies 32-bit embedded cpu";
1277 case EM_FIREPATH: return "Element 14 64-bit DSP processor";
1278 case EM_ZSP: return "LSI Logic's 16-bit DSP processor";
1279 case EM_MMIX: return "Donald Knuth's educational 64-bit processor";
1280 case EM_HUANY: return "Harvard Universitys's machine-independent object format";
1281 case EM_PRISM: return "SiTera Prism";
1282 case EM_X86_64: return "Advanced Micro Devices X86-64";
1284 sprintf (buff, _("<unknown>: %x"), e_machine);
1290 decode_ARM_machine_flags (e_flags, buf)
1297 eabi = EF_ARM_EABI_VERSION (e_flags);
1298 e_flags &= ~ EF_ARM_EABIMASK;
1300 /* Handle "generic" ARM flags. */
1301 if (e_flags & EF_ARM_RELEXEC)
1303 strcat (buf, ", relocatable executable");
1304 e_flags &= ~ EF_ARM_RELEXEC;
1307 if (e_flags & EF_ARM_HASENTRY)
1309 strcat (buf, ", has entry point");
1310 e_flags &= ~ EF_ARM_HASENTRY;
1313 /* Now handle EABI specific flags. */
1317 strcat (buf, ", <unknown EABI>");
1322 case EF_ARM_EABI_VER1:
1327 /* Process flags one bit at a time. */
1328 flag = e_flags & - e_flags;
1333 case EF_ARM_SYMSARESORTED: /* Conflicts with EF_INTERWORK. */
1334 strcat (buf, ", sorted symbol tables");
1344 case EF_ARM_EABI_UNKNOWN:
1349 /* Process flags one bit at a time. */
1350 flag = e_flags & - e_flags;
1356 strcat (buf, ", interworking enabled");
1360 strcat (buf, ", uses APCS/26");
1364 strcat (buf, ", uses APCS/float");
1368 strcat (buf, ", position independent");
1372 strcat (buf, ", 8 bit structure alignment");
1376 strcat (buf, ", uses new ABI");
1380 strcat (buf, ", uses old ABI");
1384 strcat (buf, ", software FP");
1395 strcat (buf,", <unknown>");
1399 get_machine_flags (e_flags, e_machine)
1403 static char buf [1024];
1415 decode_ARM_machine_flags (e_flags, buf);
1419 if (e_flags & EF_CPU32)
1420 strcat (buf, ", cpu32");
1424 if (e_flags & EF_PPC_EMB)
1425 strcat (buf, ", emb");
1427 if (e_flags & EF_PPC_RELOCATABLE)
1428 strcat (buf, ", relocatable");
1430 if (e_flags & EF_PPC_RELOCATABLE_LIB)
1431 strcat (buf, ", relocatable-lib");
1434 case EM_CYGNUS_V850:
1435 switch (e_flags & EF_V850_ARCH)
1438 strcat (buf, ", v850e");
1441 strcat (buf, ", v850ea");
1444 strcat (buf, ", v850");
1447 strcat (buf, ", unknown v850 architecture variant");
1452 case EM_CYGNUS_M32R:
1453 if ((e_flags & EF_M32R_ARCH) == E_M32R_ARCH)
1454 strcat (buf, ", m32r");
1459 case EM_MIPS_RS4_BE:
1460 if (e_flags & EF_MIPS_NOREORDER)
1461 strcat (buf, ", noreorder");
1463 if (e_flags & EF_MIPS_PIC)
1464 strcat (buf, ", pic");
1466 if (e_flags & EF_MIPS_CPIC)
1467 strcat (buf, ", cpic");
1469 if (e_flags & EF_MIPS_ABI2)
1470 strcat (buf, ", abi2");
1472 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_1)
1473 strcat (buf, ", mips1");
1475 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_2)
1476 strcat (buf, ", mips2");
1478 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_3)
1479 strcat (buf, ", mips3");
1481 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_4)
1482 strcat (buf, ", mips4");
1484 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_5)
1485 strcat (buf, ", mips5");
1487 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_32)
1488 strcat (buf, ", mips32");
1490 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_64)
1491 strcat (buf, ", mips64");
1493 switch ((e_flags & EF_MIPS_MACH))
1495 case E_MIPS_MACH_3900: strcat (buf, ", 3900"); break;
1496 case E_MIPS_MACH_4010: strcat (buf, ", 4010"); break;
1497 case E_MIPS_MACH_4100: strcat (buf, ", 4100"); break;
1498 case E_MIPS_MACH_4650: strcat (buf, ", 4650"); break;
1499 case E_MIPS_MACH_4111: strcat (buf, ", 4111"); break;
1500 case E_MIPS_MACH_MIPS32_4K: strcat (buf, ", mips32-4k"); break;
1501 case E_MIPS_MACH_SB1: strcat (buf, ", sb1"); break;
1502 default: strcat (buf, " UNKNOWN"); break;
1507 if (e_flags & EF_SPARC_32PLUS)
1508 strcat (buf, ", v8+");
1510 if (e_flags & EF_SPARC_SUN_US1)
1511 strcat (buf, ", ultrasparcI");
1513 if (e_flags & EF_SPARC_SUN_US3)
1514 strcat (buf, ", ultrasparcIII");
1516 if (e_flags & EF_SPARC_HAL_R1)
1517 strcat (buf, ", halr1");
1519 if (e_flags & EF_SPARC_LEDATA)
1520 strcat (buf, ", ledata");
1522 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_TSO)
1523 strcat (buf, ", tso");
1525 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_PSO)
1526 strcat (buf, ", pso");
1528 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_RMO)
1529 strcat (buf, ", rmo");
1533 switch (e_flags & EF_PARISC_ARCH)
1535 case EFA_PARISC_1_0:
1536 strcpy (buf, ", PA-RISC 1.0");
1538 case EFA_PARISC_1_1:
1539 strcpy (buf, ", PA-RISC 1.1");
1541 case EFA_PARISC_2_0:
1542 strcpy (buf, ", PA-RISC 2.0");
1547 if (e_flags & EF_PARISC_TRAPNIL)
1548 strcat (buf, ", trapnil");
1549 if (e_flags & EF_PARISC_EXT)
1550 strcat (buf, ", ext");
1551 if (e_flags & EF_PARISC_LSB)
1552 strcat (buf, ", lsb");
1553 if (e_flags & EF_PARISC_WIDE)
1554 strcat (buf, ", wide");
1555 if (e_flags & EF_PARISC_NO_KABP)
1556 strcat (buf, ", no kabp");
1557 if (e_flags & EF_PARISC_LAZYSWAP)
1558 strcat (buf, ", lazyswap");
1562 if ((e_flags & EF_PICOJAVA_NEWCALLS) == EF_PICOJAVA_NEWCALLS)
1563 strcat (buf, ", new calling convention");
1565 if ((e_flags & EF_PICOJAVA_GNUCALLS) == EF_PICOJAVA_GNUCALLS)
1566 strcat (buf, ", gnu calling convention");
1575 get_mips_segment_type (type)
1580 case PT_MIPS_REGINFO:
1582 case PT_MIPS_RTPROC:
1584 case PT_MIPS_OPTIONS:
1594 get_parisc_segment_type (type)
1599 case PT_HP_TLS: return "HP_TLS";
1600 case PT_HP_CORE_NONE: return "HP_CORE_NONE";
1601 case PT_HP_CORE_VERSION: return "HP_CORE_VERSION";
1602 case PT_HP_CORE_KERNEL: return "HP_CORE_KERNEL";
1603 case PT_HP_CORE_COMM: return "HP_CORE_COMM";
1604 case PT_HP_CORE_PROC: return "HP_CORE_PROC";
1605 case PT_HP_CORE_LOADABLE: return "HP_CORE_LOADABLE";
1606 case PT_HP_CORE_STACK: return "HP_CORE_STACK";
1607 case PT_HP_CORE_SHM: return "HP_CORE_SHM";
1608 case PT_HP_CORE_MMF: return "HP_CORE_MMF";
1609 case PT_HP_PARALLEL: return "HP_PARALLEL";
1610 case PT_HP_FASTBIND: return "HP_FASTBIND";
1611 case PT_PARISC_ARCHEXT: return "PARISC_ARCHEXT";
1612 case PT_PARISC_UNWIND: return "PARISC_UNWIND";
1621 get_segment_type (p_type)
1622 unsigned long p_type;
1624 static char buff [32];
1628 case PT_NULL: return "NULL";
1629 case PT_LOAD: return "LOAD";
1630 case PT_DYNAMIC: return "DYNAMIC";
1631 case PT_INTERP: return "INTERP";
1632 case PT_NOTE: return "NOTE";
1633 case PT_SHLIB: return "SHLIB";
1634 case PT_PHDR: return "PHDR";
1637 if ((p_type >= PT_LOPROC) && (p_type <= PT_HIPROC))
1639 const char * result;
1641 switch (elf_header.e_machine)
1644 case EM_MIPS_RS4_BE:
1645 result = get_mips_segment_type (p_type);
1648 result = get_parisc_segment_type (p_type);
1658 sprintf (buff, "LOPROC+%lx", p_type - PT_LOPROC);
1660 else if ((p_type >= PT_LOOS) && (p_type <= PT_HIOS))
1662 const char * result;
1664 switch (elf_header.e_machine)
1667 result = get_parisc_segment_type (p_type);
1677 sprintf (buff, "LOOS+%lx", p_type - PT_LOOS);
1680 sprintf (buff, _("<unknown>: %lx"), p_type);
1687 get_mips_section_type_name (sh_type)
1688 unsigned int sh_type;
1692 case SHT_MIPS_LIBLIST: return "MIPS_LIBLIST";
1693 case SHT_MIPS_MSYM: return "MIPS_MSYM";
1694 case SHT_MIPS_CONFLICT: return "MIPS_CONFLICT";
1695 case SHT_MIPS_GPTAB: return "MIPS_GPTAB";
1696 case SHT_MIPS_UCODE: return "MIPS_UCODE";
1697 case SHT_MIPS_DEBUG: return "MIPS_DEBUG";
1698 case SHT_MIPS_REGINFO: return "MIPS_REGINFO";
1699 case SHT_MIPS_PACKAGE: return "MIPS_PACKAGE";
1700 case SHT_MIPS_PACKSYM: return "MIPS_PACKSYM";
1701 case SHT_MIPS_RELD: return "MIPS_RELD";
1702 case SHT_MIPS_IFACE: return "MIPS_IFACE";
1703 case SHT_MIPS_CONTENT: return "MIPS_CONTENT";
1704 case SHT_MIPS_OPTIONS: return "MIPS_OPTIONS";
1705 case SHT_MIPS_SHDR: return "MIPS_SHDR";
1706 case SHT_MIPS_FDESC: return "MIPS_FDESC";
1707 case SHT_MIPS_EXTSYM: return "MIPS_EXTSYM";
1708 case SHT_MIPS_DENSE: return "MIPS_DENSE";
1709 case SHT_MIPS_PDESC: return "MIPS_PDESC";
1710 case SHT_MIPS_LOCSYM: return "MIPS_LOCSYM";
1711 case SHT_MIPS_AUXSYM: return "MIPS_AUXSYM";
1712 case SHT_MIPS_OPTSYM: return "MIPS_OPTSYM";
1713 case SHT_MIPS_LOCSTR: return "MIPS_LOCSTR";
1714 case SHT_MIPS_LINE: return "MIPS_LINE";
1715 case SHT_MIPS_RFDESC: return "MIPS_RFDESC";
1716 case SHT_MIPS_DELTASYM: return "MIPS_DELTASYM";
1717 case SHT_MIPS_DELTAINST: return "MIPS_DELTAINST";
1718 case SHT_MIPS_DELTACLASS: return "MIPS_DELTACLASS";
1719 case SHT_MIPS_DWARF: return "MIPS_DWARF";
1720 case SHT_MIPS_DELTADECL: return "MIPS_DELTADECL";
1721 case SHT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB";
1722 case SHT_MIPS_EVENTS: return "MIPS_EVENTS";
1723 case SHT_MIPS_TRANSLATE: return "MIPS_TRANSLATE";
1724 case SHT_MIPS_PIXIE: return "MIPS_PIXIE";
1725 case SHT_MIPS_XLATE: return "MIPS_XLATE";
1726 case SHT_MIPS_XLATE_DEBUG: return "MIPS_XLATE_DEBUG";
1727 case SHT_MIPS_WHIRL: return "MIPS_WHIRL";
1728 case SHT_MIPS_EH_REGION: return "MIPS_EH_REGION";
1729 case SHT_MIPS_XLATE_OLD: return "MIPS_XLATE_OLD";
1730 case SHT_MIPS_PDR_EXCEPTION: return "MIPS_PDR_EXCEPTION";
1738 get_parisc_section_type_name (sh_type)
1739 unsigned int sh_type;
1743 case SHT_PARISC_EXT: return "PARISC_EXT";
1744 case SHT_PARISC_UNWIND: return "PARISC_UNWIND";
1745 case SHT_PARISC_DOC: return "PARISC_DOC";
1753 get_section_type_name (sh_type)
1754 unsigned int sh_type;
1756 static char buff [32];
1760 case SHT_NULL: return "NULL";
1761 case SHT_PROGBITS: return "PROGBITS";
1762 case SHT_SYMTAB: return "SYMTAB";
1763 case SHT_STRTAB: return "STRTAB";
1764 case SHT_RELA: return "RELA";
1765 case SHT_HASH: return "HASH";
1766 case SHT_DYNAMIC: return "DYNAMIC";
1767 case SHT_NOTE: return "NOTE";
1768 case SHT_NOBITS: return "NOBITS";
1769 case SHT_REL: return "REL";
1770 case SHT_SHLIB: return "SHLIB";
1771 case SHT_DYNSYM: return "DYNSYM";
1772 case SHT_INIT_ARRAY: return "INIT_ARRAY";
1773 case SHT_FINI_ARRAY: return "FINI_ARRAY";
1774 case SHT_PREINIT_ARRAY: return "PREINIT_ARRAY";
1775 case SHT_GROUP: return "GROUP";
1776 case SHT_SYMTAB_SHNDX: return "SYMTAB SECTION INDICIES";
1777 case SHT_GNU_verdef: return "VERDEF";
1778 case SHT_GNU_verneed: return "VERNEED";
1779 case SHT_GNU_versym: return "VERSYM";
1780 case 0x6ffffff0: return "VERSYM";
1781 case 0x6ffffffc: return "VERDEF";
1782 case 0x7ffffffd: return "AUXILIARY";
1783 case 0x7fffffff: return "FILTER";
1786 if ((sh_type >= SHT_LOPROC) && (sh_type <= SHT_HIPROC))
1788 const char * result;
1790 switch (elf_header.e_machine)
1793 case EM_MIPS_RS4_BE:
1794 result = get_mips_section_type_name (sh_type);
1797 result = get_parisc_section_type_name (sh_type);
1807 sprintf (buff, "SHT_LOPROC+%x", sh_type - SHT_LOPROC);
1809 else if ((sh_type >= SHT_LOOS) && (sh_type <= SHT_HIOS))
1810 sprintf (buff, "SHT_LOOS+%x", sh_type - SHT_LOOS);
1811 else if ((sh_type >= SHT_LOUSER) && (sh_type <= SHT_HIUSER))
1812 sprintf (buff, "SHT_LOUSER+%x", sh_type - SHT_LOUSER);
1814 sprintf (buff, _("<unknown>: %x"), sh_type);
1820 struct option options [] =
1822 {"all", no_argument, 0, 'a'},
1823 {"file-header", no_argument, 0, 'h'},
1824 {"program-headers", no_argument, 0, 'l'},
1825 {"headers", no_argument, 0, 'e'},
1826 {"histogram", no_argument, 0, 'I'},
1827 {"segments", no_argument, 0, 'l'},
1828 {"sections", no_argument, 0, 'S'},
1829 {"section-headers", no_argument, 0, 'S'},
1830 {"symbols", no_argument, 0, 's'},
1831 {"syms", no_argument, 0, 's'},
1832 {"relocs", no_argument, 0, 'r'},
1833 {"notes", no_argument, 0, 'n'},
1834 {"dynamic", no_argument, 0, 'd'},
1835 {"arch-specific", no_argument, 0, 'A'},
1836 {"version-info", no_argument, 0, 'V'},
1837 {"use-dynamic", no_argument, 0, 'D'},
1838 {"hex-dump", required_argument, 0, 'x'},
1839 {"debug-dump", optional_argument, 0, 'w'},
1840 #ifdef SUPPORT_DISASSEMBLY
1841 {"instruction-dump", required_argument, 0, 'i'},
1844 {"version", no_argument, 0, 'v'},
1845 {"help", no_argument, 0, 'H'},
1846 {0, no_argument, 0, 0}
1852 fprintf (stdout, _("Usage: readelf {options} elf-file(s)\n"));
1853 fprintf (stdout, _(" Options are:\n"));
1854 fprintf (stdout, _(" -a or --all Equivalent to: -h -l -S -s -r -d -V -A -I\n"));
1855 fprintf (stdout, _(" -h or --file-header Display the ELF file header\n"));
1856 fprintf (stdout, _(" -l or --program-headers or --segments\n"));
1857 fprintf (stdout, _(" Display the program headers\n"));
1858 fprintf (stdout, _(" -S or --section-headers or --sections\n"));
1859 fprintf (stdout, _(" Display the sections' header\n"));
1860 fprintf (stdout, _(" -e or --headers Equivalent to: -h -l -S\n"));
1861 fprintf (stdout, _(" -s or --syms or --symbols Display the symbol table\n"));
1862 fprintf (stdout, _(" -n or --notes Display the core notes (if present)\n"));
1863 fprintf (stdout, _(" -r or --relocs Display the relocations (if present)\n"));
1864 fprintf (stdout, _(" -d or --dynamic Display the dynamic segment (if present)\n"));
1865 fprintf (stdout, _(" -V or --version-info Display the version sections (if present)\n"));
1866 fprintf (stdout, _(" -A or --arch-specific Display architecture specific information (if any).\n"));
1867 fprintf (stdout, _(" -D or --use-dynamic Use the dynamic section info when displaying symbols\n"));
1868 fprintf (stdout, _(" -x <number> or --hex-dump=<number>\n"));
1869 fprintf (stdout, _(" Dump the contents of section <number>\n"));
1870 fprintf (stdout, _(" -w[liaprf] or --debug-dump[=line,=info,=abbrev,=pubnames,=ranges,=frames]\n"));
1871 fprintf (stdout, _(" Display the contents of DWARF2 debug sections\n"));
1872 #ifdef SUPPORT_DISASSEMBLY
1873 fprintf (stdout, _(" -i <number> or --instruction-dump=<number>\n"));
1874 fprintf (stdout, _(" Disassemble the contents of section <number>\n"));
1876 fprintf (stdout, _(" -I or --histogram Display histogram of bucket list lengths\n"));
1877 fprintf (stdout, _(" -v or --version Display the version number of readelf\n"));
1878 fprintf (stdout, _(" -H or --help Display this information\n"));
1879 fprintf (stdout, _("Report bugs to %s\n"), REPORT_BUGS_TO);
1885 request_dump (section, type)
1886 unsigned int section;
1889 if (section >= num_dump_sects)
1891 char * new_dump_sects;
1893 new_dump_sects = (char *) calloc (section + 1, 1);
1895 if (new_dump_sects == NULL)
1896 error (_("Out of memory allocating dump request table."));
1899 /* Copy current flag settings. */
1900 memcpy (new_dump_sects, dump_sects, num_dump_sects);
1904 dump_sects = new_dump_sects;
1905 num_dump_sects = section + 1;
1910 dump_sects [section] |= type;
1916 parse_args (argc, argv)
1925 while ((c = getopt_long
1926 (argc, argv, "ersahnldSDAIw::x:i:vV", options, NULL)) != EOF)
1961 do_using_dynamic ++;
1989 section = strtoul (optarg, & cp, 0);
1990 if (! * cp && section >= 0)
1992 request_dump (section, HEX_DUMP);
2012 do_debug_abbrevs = 1;
2022 do_debug_pubnames = 1;
2027 do_debug_aranges = 1;
2032 do_debug_frames = 1;
2036 warn (_("Unrecognised debug option '%s'\n"), optarg);
2041 #ifdef SUPPORT_DISASSEMBLY
2044 section = strtoul (optarg, & cp, 0);
2045 if (! * cp && section >= 0)
2047 request_dump (section, DISASS_DUMP);
2053 print_version (program_name);
2060 /* xgettext:c-format */
2061 error (_("Invalid option '-%c'\n"), c);
2068 if (!do_dynamic && !do_syms && !do_reloc && !do_sections
2069 && !do_segments && !do_header && !do_dump && !do_version
2070 && !do_histogram && !do_debugging && !do_arch && !do_notes)
2074 warn (_("Nothing to do.\n"));
2080 get_elf_class (elf_class)
2081 unsigned char elf_class;
2083 static char buff [32];
2087 case ELFCLASSNONE: return _("none");
2088 case ELFCLASS32: return _("ELF32");
2089 case ELFCLASS64: return _("ELF64");
2091 sprintf (buff, _("<unknown: %x>"), elf_class);
2097 get_data_encoding (encoding)
2098 unsigned char encoding;
2100 static char buff [32];
2104 case ELFDATANONE: return _("none");
2105 case ELFDATA2LSB: return _("2's complement, little endian");
2106 case ELFDATA2MSB: return _("2's complement, big endian");
2108 sprintf (buff, _("<unknown: %x>"), encoding);
2114 get_osabi_name (osabi)
2115 unsigned char osabi;
2117 static char buff [32];
2121 case ELFOSABI_NONE: return _("UNIX - System V");
2122 case ELFOSABI_HPUX: return _("UNIX - HP-UX");
2123 case ELFOSABI_NETBSD: return _("UNIX - NetBSD");
2124 case ELFOSABI_LINUX: return _("UNIX - Linux");
2125 case ELFOSABI_HURD: return _("GNU/Hurd");
2126 case ELFOSABI_SOLARIS: return _("UNIX - Solaris");
2127 case ELFOSABI_AIX: return _("UNIX - AIX");
2128 case ELFOSABI_IRIX: return _("UNIX - IRIX");
2129 case ELFOSABI_FREEBSD: return _("UNIX - FreeBSD");
2130 case ELFOSABI_TRU64: return _("UNIX - TRU64");
2131 case ELFOSABI_MODESTO: return _("Novell - Modesto");
2132 case ELFOSABI_OPENBSD: return _("UNIX - OpenBSD");
2133 case ELFOSABI_STANDALONE: return _("Standalone App");
2134 case ELFOSABI_ARM: return _("ARM");
2136 sprintf (buff, _("<unknown: %x>"), osabi);
2141 /* Decode the data held in 'elf_header'. */
2143 process_file_header ()
2145 if ( elf_header.e_ident [EI_MAG0] != ELFMAG0
2146 || elf_header.e_ident [EI_MAG1] != ELFMAG1
2147 || elf_header.e_ident [EI_MAG2] != ELFMAG2
2148 || elf_header.e_ident [EI_MAG3] != ELFMAG3)
2151 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
2159 printf (_("ELF Header:\n"));
2160 printf (_(" Magic: "));
2161 for (i = 0; i < EI_NIDENT; i ++)
2162 printf ("%2.2x ", elf_header.e_ident [i]);
2164 printf (_(" Class: %s\n"),
2165 get_elf_class (elf_header.e_ident [EI_CLASS]));
2166 printf (_(" Data: %s\n"),
2167 get_data_encoding (elf_header.e_ident [EI_DATA]));
2168 printf (_(" Version: %d %s\n"),
2169 elf_header.e_ident [EI_VERSION],
2170 (elf_header.e_ident [EI_VERSION] == EV_CURRENT
2172 : (elf_header.e_ident [EI_VERSION] != EV_NONE
2175 printf (_(" OS/ABI: %s\n"),
2176 get_osabi_name (elf_header.e_ident [EI_OSABI]));
2177 printf (_(" ABI Version: %d\n"),
2178 elf_header.e_ident [EI_ABIVERSION]);
2179 printf (_(" Type: %s\n"),
2180 get_file_type (elf_header.e_type));
2181 printf (_(" Machine: %s\n"),
2182 get_machine_name (elf_header.e_machine));
2183 printf (_(" Version: 0x%lx\n"),
2184 (unsigned long) elf_header.e_version);
2186 printf (_(" Entry point address: "));
2187 print_vma ((bfd_vma) elf_header.e_entry, PREFIX_HEX);
2188 printf (_("\n Start of program headers: "));
2189 print_vma ((bfd_vma) elf_header.e_phoff, DEC);
2190 printf (_(" (bytes into file)\n Start of section headers: "));
2191 print_vma ((bfd_vma) elf_header.e_shoff, DEC);
2192 printf (_(" (bytes into file)\n"));
2194 printf (_(" Flags: 0x%lx%s\n"),
2195 (unsigned long) elf_header.e_flags,
2196 get_machine_flags (elf_header.e_flags, elf_header.e_machine));
2197 printf (_(" Size of this header: %ld (bytes)\n"),
2198 (long) elf_header.e_ehsize);
2199 printf (_(" Size of program headers: %ld (bytes)\n"),
2200 (long) elf_header.e_phentsize);
2201 printf (_(" Number of program headers: %ld\n"),
2202 (long) elf_header.e_phnum);
2203 printf (_(" Size of section headers: %ld (bytes)\n"),
2204 (long) elf_header.e_shentsize);
2205 printf (_(" Number of section headers: %ld\n"),
2206 (long) elf_header.e_shnum);
2207 printf (_(" Section header string table index: %ld\n"),
2208 (long) elf_header.e_shstrndx);
2216 get_32bit_program_headers (file, program_headers)
2218 Elf_Internal_Phdr * program_headers;
2220 Elf32_External_Phdr * phdrs;
2221 Elf32_External_Phdr * external;
2222 Elf32_Internal_Phdr * internal;
2225 GET_DATA_ALLOC (elf_header.e_phoff,
2226 elf_header.e_phentsize * elf_header.e_phnum,
2227 phdrs, Elf32_External_Phdr *, "program headers");
2229 for (i = 0, internal = program_headers, external = phdrs;
2230 i < elf_header.e_phnum;
2231 i ++, internal ++, external ++)
2233 internal->p_type = BYTE_GET (external->p_type);
2234 internal->p_offset = BYTE_GET (external->p_offset);
2235 internal->p_vaddr = BYTE_GET (external->p_vaddr);
2236 internal->p_paddr = BYTE_GET (external->p_paddr);
2237 internal->p_filesz = BYTE_GET (external->p_filesz);
2238 internal->p_memsz = BYTE_GET (external->p_memsz);
2239 internal->p_flags = BYTE_GET (external->p_flags);
2240 internal->p_align = BYTE_GET (external->p_align);
2249 get_64bit_program_headers (file, program_headers)
2251 Elf_Internal_Phdr * program_headers;
2253 Elf64_External_Phdr * phdrs;
2254 Elf64_External_Phdr * external;
2255 Elf64_Internal_Phdr * internal;
2258 GET_DATA_ALLOC (elf_header.e_phoff,
2259 elf_header.e_phentsize * elf_header.e_phnum,
2260 phdrs, Elf64_External_Phdr *, "program headers");
2262 for (i = 0, internal = program_headers, external = phdrs;
2263 i < elf_header.e_phnum;
2264 i ++, internal ++, external ++)
2266 internal->p_type = BYTE_GET (external->p_type);
2267 internal->p_flags = BYTE_GET (external->p_flags);
2268 internal->p_offset = BYTE_GET8 (external->p_offset);
2269 internal->p_vaddr = BYTE_GET8 (external->p_vaddr);
2270 internal->p_paddr = BYTE_GET8 (external->p_paddr);
2271 internal->p_filesz = BYTE_GET8 (external->p_filesz);
2272 internal->p_memsz = BYTE_GET8 (external->p_memsz);
2273 internal->p_align = BYTE_GET8 (external->p_align);
2282 process_program_headers (file)
2285 Elf_Internal_Phdr * program_headers;
2286 Elf_Internal_Phdr * segment;
2289 if (elf_header.e_phnum == 0)
2292 printf (_("\nThere are no program headers in this file.\n"));
2296 if (do_segments && !do_header)
2298 printf (_("\nElf file type is %s\n"), get_file_type (elf_header.e_type));
2299 printf (_("Entry point "));
2300 print_vma ((bfd_vma) elf_header.e_entry, PREFIX_HEX);
2301 printf (_("\nThere are %d program headers, starting at offset "),
2302 elf_header.e_phnum);
2303 print_vma ((bfd_vma) elf_header.e_phoff, DEC);
2307 program_headers = (Elf_Internal_Phdr *) malloc
2308 (elf_header.e_phnum * sizeof (Elf_Internal_Phdr));
2310 if (program_headers == NULL)
2312 error (_("Out of memory\n"));
2317 i = get_32bit_program_headers (file, program_headers);
2319 i = get_64bit_program_headers (file, program_headers);
2323 free (program_headers);
2330 (_("\nProgram Header%s:\n"), elf_header.e_phnum > 1 ? "s" : "");
2334 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
2338 (_(" Type Offset VirtAddr PhysAddr\n"));
2340 (_(" FileSiz MemSiz Flags Align\n"));
2348 for (i = 0, segment = program_headers;
2349 i < elf_header.e_phnum;
2354 printf (" %-14.14s ", get_segment_type (segment->p_type));
2358 printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
2359 printf ("0x%8.8lx ", (unsigned long) segment->p_vaddr);
2360 printf ("0x%8.8lx ", (unsigned long) segment->p_paddr);
2361 printf ("0x%5.5lx ", (unsigned long) segment->p_filesz);
2362 printf ("0x%5.5lx ", (unsigned long) segment->p_memsz);
2364 (segment->p_flags & PF_R ? 'R' : ' '),
2365 (segment->p_flags & PF_W ? 'W' : ' '),
2366 (segment->p_flags & PF_X ? 'E' : ' '));
2367 printf ("%#lx", (unsigned long) segment->p_align);
2371 print_vma (segment->p_offset, FULL_HEX);
2373 print_vma (segment->p_vaddr, FULL_HEX);
2375 print_vma (segment->p_paddr, FULL_HEX);
2377 print_vma (segment->p_filesz, FULL_HEX);
2379 print_vma (segment->p_memsz, FULL_HEX);
2381 (segment->p_flags & PF_R ? 'R' : ' '),
2382 (segment->p_flags & PF_W ? 'W' : ' '),
2383 (segment->p_flags & PF_X ? 'E' : ' '));
2384 print_vma (segment->p_align, HEX);
2388 switch (segment->p_type)
2392 loadaddr = (segment->p_vaddr & 0xfffff000)
2393 - (segment->p_offset & 0xfffff000);
2398 error (_("more than one dynamic segment\n"));
2400 dynamic_addr = segment->p_offset;
2401 dynamic_size = segment->p_filesz;
2405 if (fseek (file, (long) segment->p_offset, SEEK_SET))
2406 error (_("Unable to find program interpreter name\n"));
2409 program_interpreter[0] = 0;
2410 fscanf (file, "%63s", program_interpreter);
2413 printf (_("\n [Requesting program interpreter: %s]"),
2414 program_interpreter);
2420 putc ('\n', stdout);
2429 if (do_segments && section_headers != NULL)
2431 printf (_("\n Section to Segment mapping:\n"));
2432 printf (_(" Segment Sections...\n"));
2434 assert (string_table != NULL);
2436 for (i = 0; i < elf_header.e_phnum; i++)
2439 Elf_Internal_Shdr * section;
2441 segment = program_headers + i;
2442 section = section_headers;
2444 printf (" %2.2d ", i);
2446 for (j = 0; j < elf_header.e_shnum; j++, section ++)
2448 if (section->sh_size > 0
2449 /* Compare allocated sections by VMA, unallocated
2450 sections by file offset. */
2451 && (section->sh_flags & SHF_ALLOC
2452 ? (section->sh_addr >= segment->p_vaddr
2453 && section->sh_addr + section->sh_size
2454 <= segment->p_vaddr + segment->p_memsz)
2455 : ((bfd_vma) section->sh_offset >= segment->p_offset
2456 && (section->sh_offset + section->sh_size
2457 <= segment->p_offset + segment->p_filesz))))
2458 printf ("%s ", SECTION_NAME (section));
2465 free (program_headers);
2472 get_32bit_section_headers (file)
2475 Elf32_External_Shdr * shdrs;
2476 Elf32_Internal_Shdr * internal;
2479 GET_DATA_ALLOC (elf_header.e_shoff,
2480 elf_header.e_shentsize * elf_header.e_shnum,
2481 shdrs, Elf32_External_Shdr *, "section headers");
2483 section_headers = (Elf_Internal_Shdr *) malloc
2484 (elf_header.e_shnum * sizeof (Elf_Internal_Shdr));
2486 if (section_headers == NULL)
2488 error (_("Out of memory\n"));
2492 for (i = 0, internal = section_headers;
2493 i < elf_header.e_shnum;
2496 internal->sh_name = BYTE_GET (shdrs[i].sh_name);
2497 internal->sh_type = BYTE_GET (shdrs[i].sh_type);
2498 internal->sh_flags = BYTE_GET (shdrs[i].sh_flags);
2499 internal->sh_addr = BYTE_GET (shdrs[i].sh_addr);
2500 internal->sh_offset = BYTE_GET (shdrs[i].sh_offset);
2501 internal->sh_size = BYTE_GET (shdrs[i].sh_size);
2502 internal->sh_link = BYTE_GET (shdrs[i].sh_link);
2503 internal->sh_info = BYTE_GET (shdrs[i].sh_info);
2504 internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
2505 internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize);
2514 get_64bit_section_headers (file)
2517 Elf64_External_Shdr * shdrs;
2518 Elf64_Internal_Shdr * internal;
2521 GET_DATA_ALLOC (elf_header.e_shoff,
2522 elf_header.e_shentsize * elf_header.e_shnum,
2523 shdrs, Elf64_External_Shdr *, "section headers");
2525 section_headers = (Elf_Internal_Shdr *) malloc
2526 (elf_header.e_shnum * sizeof (Elf_Internal_Shdr));
2528 if (section_headers == NULL)
2530 error (_("Out of memory\n"));
2534 for (i = 0, internal = section_headers;
2535 i < elf_header.e_shnum;
2538 internal->sh_name = BYTE_GET (shdrs[i].sh_name);
2539 internal->sh_type = BYTE_GET (shdrs[i].sh_type);
2540 internal->sh_flags = BYTE_GET8 (shdrs[i].sh_flags);
2541 internal->sh_addr = BYTE_GET8 (shdrs[i].sh_addr);
2542 internal->sh_size = BYTE_GET8 (shdrs[i].sh_size);
2543 internal->sh_entsize = BYTE_GET8 (shdrs[i].sh_entsize);
2544 internal->sh_link = BYTE_GET (shdrs[i].sh_link);
2545 internal->sh_info = BYTE_GET (shdrs[i].sh_info);
2546 internal->sh_offset = BYTE_GET (shdrs[i].sh_offset);
2547 internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
2555 static Elf_Internal_Sym *
2556 get_32bit_elf_symbols (file, offset, number)
2558 unsigned long offset;
2559 unsigned long number;
2561 Elf32_External_Sym * esyms;
2562 Elf_Internal_Sym * isyms;
2563 Elf_Internal_Sym * psym;
2566 GET_DATA_ALLOC (offset, number * sizeof (Elf32_External_Sym),
2567 esyms, Elf32_External_Sym *, "symbols");
2569 isyms = (Elf_Internal_Sym *) malloc (number * sizeof (Elf_Internal_Sym));
2573 error (_("Out of memory\n"));
2579 for (j = 0, psym = isyms;
2583 psym->st_name = BYTE_GET (esyms[j].st_name);
2584 psym->st_value = BYTE_GET (esyms[j].st_value);
2585 psym->st_size = BYTE_GET (esyms[j].st_size);
2586 psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
2587 psym->st_info = BYTE_GET (esyms[j].st_info);
2588 psym->st_other = BYTE_GET (esyms[j].st_other);
2596 static Elf_Internal_Sym *
2597 get_64bit_elf_symbols (file, offset, number)
2599 unsigned long offset;
2600 unsigned long number;
2602 Elf64_External_Sym * esyms;
2603 Elf_Internal_Sym * isyms;
2604 Elf_Internal_Sym * psym;
2607 GET_DATA_ALLOC (offset, number * sizeof (Elf64_External_Sym),
2608 esyms, Elf64_External_Sym *, "symbols");
2610 isyms = (Elf_Internal_Sym *) malloc (number * sizeof (Elf_Internal_Sym));
2614 error (_("Out of memory\n"));
2620 for (j = 0, psym = isyms;
2624 psym->st_name = BYTE_GET (esyms[j].st_name);
2625 psym->st_info = BYTE_GET (esyms[j].st_info);
2626 psym->st_other = BYTE_GET (esyms[j].st_other);
2627 psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
2628 psym->st_value = BYTE_GET8 (esyms[j].st_value);
2629 psym->st_size = BYTE_GET8 (esyms[j].st_size);
2638 get_elf_section_flags (sh_flags)
2641 static char buff [32];
2649 flag = sh_flags & - sh_flags;
2654 case SHF_WRITE: strcat (buff, "W"); break;
2655 case SHF_ALLOC: strcat (buff, "A"); break;
2656 case SHF_EXECINSTR: strcat (buff, "X"); break;
2657 case SHF_MERGE: strcat (buff, "M"); break;
2658 case SHF_STRINGS: strcat (buff, "S"); break;
2659 case SHF_INFO_LINK: strcat (buff, "I"); break;
2660 case SHF_LINK_ORDER: strcat (buff, "L"); break;
2661 case SHF_OS_NONCONFORMING: strcat (buff, "O"); break;
2662 case SHF_GROUP: strcat (buff, "G"); break;
2665 if (flag & SHF_MASKOS)
2668 sh_flags &= ~ SHF_MASKOS;
2670 else if (flag & SHF_MASKPROC)
2673 sh_flags &= ~ SHF_MASKPROC;
2685 process_section_headers (file)
2688 Elf_Internal_Shdr * section;
2691 section_headers = NULL;
2693 if (elf_header.e_shnum == 0)
2696 printf (_("\nThere are no sections in this file.\n"));
2701 if (do_sections && !do_header)
2702 printf (_("There are %d section headers, starting at offset 0x%lx:\n"),
2703 elf_header.e_shnum, (unsigned long) elf_header.e_shoff);
2707 if (! get_32bit_section_headers (file))
2710 else if (! get_64bit_section_headers (file))
2713 /* Read in the string table, so that we have names to display. */
2714 section = section_headers + elf_header.e_shstrndx;
2716 if (section->sh_size != 0)
2718 GET_DATA_ALLOC (section->sh_offset, section->sh_size,
2719 string_table, char *, "string table");
2721 string_table_length = section->sh_size;
2724 /* Scan the sections for the dynamic symbol table
2725 and dynamic string table and debug sections. */
2726 dynamic_symbols = NULL;
2727 dynamic_strings = NULL;
2728 dynamic_syminfo = NULL;
2730 for (i = 0, section = section_headers;
2731 i < elf_header.e_shnum;
2734 char * name = SECTION_NAME (section);
2736 if (section->sh_type == SHT_DYNSYM)
2738 if (dynamic_symbols != NULL)
2740 error (_("File contains multiple dynamic symbol tables\n"));
2744 num_dynamic_syms = section->sh_size / section->sh_entsize;
2746 GET_ELF_SYMBOLS (file, section->sh_offset, num_dynamic_syms);
2748 else if (section->sh_type == SHT_STRTAB
2749 && strcmp (name, ".dynstr") == 0)
2751 if (dynamic_strings != NULL)
2753 error (_("File contains multiple dynamic string tables\n"));
2757 GET_DATA_ALLOC (section->sh_offset, section->sh_size,
2758 dynamic_strings, char *, "dynamic strings");
2760 else if ((do_debugging || do_debug_info || do_debug_abbrevs
2761 || do_debug_lines || do_debug_pubnames || do_debug_aranges || do_debug_frames)
2762 && strncmp (name, ".debug_", 7) == 0)
2767 || (do_debug_info && (strcmp (name, "info") == 0))
2768 || (do_debug_abbrevs && (strcmp (name, "abbrev") == 0))
2769 || (do_debug_lines && (strcmp (name, "line") == 0))
2770 || (do_debug_pubnames && (strcmp (name, "pubnames") == 0))
2771 || (do_debug_aranges && (strcmp (name, "aranges") == 0))
2772 || (do_debug_frames && (strcmp (name, "frame") == 0))
2774 request_dump (i, DEBUG_DUMP);
2776 /* linkonce section to be combined with .debug_info at link time. */
2777 else if ((do_debugging || do_debug_info)
2778 && strncmp (name, ".gnu.linkonce.wi.", 17) == 0)
2779 request_dump (i, DEBUG_DUMP);
2780 else if (do_debug_frames && strcmp (name, ".eh_frame") == 0)
2781 request_dump (i, DEBUG_DUMP);
2787 printf (_("\nSection Header%s:\n"), elf_header.e_shnum > 1 ? "s" : "");
2791 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
2794 printf (_(" [Nr] Name Type Address Offset\n"));
2795 printf (_(" Size EntSize Flags Link Info Align\n"));
2798 for (i = 0, section = section_headers;
2799 i < elf_header.e_shnum;
2802 printf (" [%2d] %-17.17s %-15.15s ",
2804 SECTION_NAME (section),
2805 get_section_type_name (section->sh_type));
2809 print_vma (section->sh_addr, LONG_HEX);
2811 printf ( " %6.6lx %6.6lx %2.2lx",
2812 (unsigned long) section->sh_offset,
2813 (unsigned long) section->sh_size,
2814 (unsigned long) section->sh_entsize);
2816 printf (" %3s ", get_elf_section_flags (section->sh_flags));
2818 printf ("%2ld %3lx %2ld\n",
2819 (unsigned long) section->sh_link,
2820 (unsigned long) section->sh_info,
2821 (unsigned long) section->sh_addralign);
2826 print_vma (section->sh_addr, LONG_HEX);
2827 printf (" %8.8lx", section->sh_offset);
2829 print_vma (section->sh_size, LONG_HEX);
2831 print_vma (section->sh_entsize, LONG_HEX);
2833 printf (" %3s ", get_elf_section_flags (section->sh_flags));
2835 printf (" %2ld %3lx %ld\n",
2836 (unsigned long) section->sh_link,
2837 (unsigned long) section->sh_info,
2838 (unsigned long) section->sh_addralign);
2842 printf (_("Key to Flags:\n"));
2843 printf (_(" W (write), A (alloc), X (execute), M (merge), S (strings)\n"));
2844 printf (_(" I (info), L (link order), G (group), x (unknown)\n"));
2845 printf (_(" O (extra OS processing required) o (OS specific), p (processor specific)\n"));
2850 /* Process the reloc section. */
2852 process_relocs (file)
2855 unsigned long rel_size;
2856 unsigned long rel_offset;
2862 if (do_using_dynamic)
2864 int is_rela = FALSE;
2869 if (dynamic_info[DT_REL])
2871 rel_offset = dynamic_info[DT_REL];
2872 rel_size = dynamic_info[DT_RELSZ];
2875 else if (dynamic_info [DT_RELA])
2877 rel_offset = dynamic_info[DT_RELA];
2878 rel_size = dynamic_info[DT_RELASZ];
2881 else if (dynamic_info[DT_JMPREL])
2883 rel_offset = dynamic_info[DT_JMPREL];
2884 rel_size = dynamic_info[DT_PLTRELSZ];
2886 switch (dynamic_info[DT_PLTREL])
2903 (_("\nRelocation section at offset 0x%lx contains %ld bytes:\n"),
2904 rel_offset, rel_size);
2906 dump_relocations (file, rel_offset - loadaddr, rel_size,
2907 dynamic_symbols, num_dynamic_syms, dynamic_strings, is_rela);
2910 printf (_("\nThere are no dynamic relocations in this file.\n"));
2914 Elf32_Internal_Shdr * section;
2918 for (i = 0, section = section_headers;
2919 i < elf_header.e_shnum;
2922 if ( section->sh_type != SHT_RELA
2923 && section->sh_type != SHT_REL)
2926 rel_offset = section->sh_offset;
2927 rel_size = section->sh_size;
2931 Elf32_Internal_Shdr * strsec;
2932 Elf32_Internal_Shdr * symsec;
2933 Elf_Internal_Sym * symtab;
2936 unsigned long nsyms;
2938 printf (_("\nRelocation section "));
2940 if (string_table == NULL)
2941 printf ("%d", section->sh_name);
2943 printf ("'%s'", SECTION_NAME (section));
2945 printf (_(" at offset 0x%lx contains %lu entries:\n"),
2946 rel_offset, (unsigned long) (rel_size / section->sh_entsize));
2948 symsec = section_headers + section->sh_link;
2950 nsyms = symsec->sh_size / symsec->sh_entsize;
2951 symtab = GET_ELF_SYMBOLS (file, symsec->sh_offset, nsyms);
2956 strsec = section_headers + symsec->sh_link;
2958 GET_DATA_ALLOC (strsec->sh_offset, strsec->sh_size, strtab,
2959 char *, "string table");
2961 is_rela = section->sh_type == SHT_RELA;
2963 dump_relocations (file, rel_offset, rel_size, symtab, nsyms, strtab, is_rela);
2973 printf (_("\nThere are no relocations in this file.\n"));
2981 dynamic_segment_mips_val (entry)
2982 Elf_Internal_Dyn * entry;
2984 switch (entry->d_tag)
2987 if (entry->d_un.d_val == 0)
2991 static const char * opts[] =
2993 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
2994 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
2995 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
2996 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
3001 for (cnt = 0; cnt < NUM_ELEM (opts); ++ cnt)
3002 if (entry->d_un.d_val & (1 << cnt))
3004 printf ("%s%s", first ? "" : " ", opts[cnt]);
3011 case DT_MIPS_IVERSION:
3012 if (dynamic_strings != NULL)
3013 printf ("Interface Version: %s\n",
3014 dynamic_strings + entry->d_un.d_val);
3016 printf ("%ld\n", (long) entry->d_un.d_ptr);
3019 case DT_MIPS_TIME_STAMP:
3024 time_t time = entry->d_un.d_val;
3025 tmp = gmtime (&time);
3026 sprintf (timebuf, "%04u-%02u-%02uT%02u:%02u:%02u",
3027 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
3028 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
3029 printf ("Time Stamp: %s\n", timebuf);
3033 case DT_MIPS_RLD_VERSION:
3034 case DT_MIPS_LOCAL_GOTNO:
3035 case DT_MIPS_CONFLICTNO:
3036 case DT_MIPS_LIBLISTNO:
3037 case DT_MIPS_SYMTABNO:
3038 case DT_MIPS_UNREFEXTNO:
3039 case DT_MIPS_HIPAGENO:
3040 case DT_MIPS_DELTA_CLASS_NO:
3041 case DT_MIPS_DELTA_INSTANCE_NO:
3042 case DT_MIPS_DELTA_RELOC_NO:
3043 case DT_MIPS_DELTA_SYM_NO:
3044 case DT_MIPS_DELTA_CLASSSYM_NO:
3045 case DT_MIPS_COMPACT_SIZE:
3046 printf ("%ld\n", (long) entry->d_un.d_ptr);
3050 printf ("%#lx\n", (long) entry->d_un.d_ptr);
3056 dynamic_segment_parisc_val (entry)
3057 Elf_Internal_Dyn * entry;
3059 switch (entry->d_tag)
3061 case DT_HP_DLD_FLAGS:
3070 { DT_HP_DEBUG_PRIVATE, "HP_DEBUG_PRIVATE" },
3071 { DT_HP_DEBUG_CALLBACK, "HP_DEBUG_CALLBACK" },
3072 { DT_HP_DEBUG_CALLBACK_BOR, "HP_DEBUG_CALLBACK_BOR" },
3073 { DT_HP_NO_ENVVAR, "HP_NO_ENVVAR" },
3074 { DT_HP_BIND_NOW, "HP_BIND_NOW" },
3075 { DT_HP_BIND_NONFATAL, "HP_BIND_NONFATAL" },
3076 { DT_HP_BIND_VERBOSE, "HP_BIND_VERBOSE" },
3077 { DT_HP_BIND_RESTRICTED, "HP_BIND_RESTRICTED" },
3078 { DT_HP_BIND_SYMBOLIC, "HP_BIND_SYMBOLIC" },
3079 { DT_HP_RPATH_FIRST, "HP_RPATH_FIRST" },
3080 { DT_HP_BIND_DEPTH_FIRST, "HP_BIND_DEPTH_FIRST" }
3084 bfd_vma val = entry->d_un.d_val;
3086 for (cnt = 0; cnt < sizeof (flags) / sizeof (flags[0]); ++cnt)
3087 if (val & flags[cnt].bit)
3091 fputs (flags[cnt].str, stdout);
3093 val ^= flags[cnt].bit;
3096 if (val != 0 || first)
3100 print_vma (val, HEX);
3106 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
3112 get_32bit_dynamic_segment (file)
3115 Elf32_External_Dyn * edyn;
3116 Elf_Internal_Dyn * entry;
3119 GET_DATA_ALLOC (dynamic_addr, dynamic_size,
3120 edyn, Elf32_External_Dyn *, "dynamic segment");
3122 /* SGI's ELF has more than one section in the DYNAMIC segment. Determine
3123 how large this .dynamic is now. We can do this even before the byte
3124 swapping since the DT_NULL tag is recognizable. */
3126 while (*(Elf32_Word *) edyn [dynamic_size++].d_tag != DT_NULL)
3129 dynamic_segment = (Elf_Internal_Dyn *)
3130 malloc (dynamic_size * sizeof (Elf_Internal_Dyn));
3132 if (dynamic_segment == NULL)
3134 error (_("Out of memory\n"));
3139 for (i = 0, entry = dynamic_segment;
3143 entry->d_tag = BYTE_GET (edyn [i].d_tag);
3144 entry->d_un.d_val = BYTE_GET (edyn [i].d_un.d_val);
3153 get_64bit_dynamic_segment (file)
3156 Elf64_External_Dyn * edyn;
3157 Elf_Internal_Dyn * entry;
3160 GET_DATA_ALLOC (dynamic_addr, dynamic_size,
3161 edyn, Elf64_External_Dyn *, "dynamic segment");
3163 /* SGI's ELF has more than one section in the DYNAMIC segment. Determine
3164 how large this .dynamic is now. We can do this even before the byte
3165 swapping since the DT_NULL tag is recognizable. */
3167 while (*(bfd_vma *) edyn [dynamic_size ++].d_tag != DT_NULL)
3170 dynamic_segment = (Elf_Internal_Dyn *)
3171 malloc (dynamic_size * sizeof (Elf_Internal_Dyn));
3173 if (dynamic_segment == NULL)
3175 error (_("Out of memory\n"));
3180 for (i = 0, entry = dynamic_segment;
3184 entry->d_tag = BYTE_GET8 (edyn [i].d_tag);
3185 entry->d_un.d_val = BYTE_GET8 (edyn [i].d_un.d_val);
3194 get_dynamic_flags (flags)
3197 static char buff [64];
3202 flag = flags & - flags;
3207 case DF_ORIGIN: strcat (buff, "ORIGIN "); break;
3208 case DF_SYMBOLIC: strcat (buff, "SYMBOLIC "); break;
3209 case DF_TEXTREL: strcat (buff, "TEXTREL "); break;
3210 case DF_BIND_NOW: strcat (buff, "BIND_NOW "); break;
3211 default: strcat (buff, "unknown "); break;
3217 /* Parse and display the contents of the dynamic segment. */
3219 process_dynamic_segment (file)
3222 Elf_Internal_Dyn * entry;
3225 if (dynamic_size == 0)
3228 printf (_("\nThere is no dynamic segment in this file.\n"));
3235 if (! get_32bit_dynamic_segment (file))
3238 else if (! get_64bit_dynamic_segment (file))
3241 /* Find the appropriate symbol table. */
3242 if (dynamic_symbols == NULL)
3244 for (i = 0, entry = dynamic_segment;
3248 unsigned long offset;
3250 if (entry->d_tag != DT_SYMTAB)
3253 dynamic_info[DT_SYMTAB] = entry->d_un.d_val;
3255 /* Since we do not know how big the symbol table is,
3256 we default to reading in the entire file (!) and
3257 processing that. This is overkill, I know, but it
3259 offset = entry->d_un.d_val - loadaddr;
3261 if (fseek (file, 0, SEEK_END))
3262 error (_("Unable to seek to end of file!"));
3265 num_dynamic_syms = (ftell (file) - offset) / sizeof (Elf32_External_Sym);
3267 num_dynamic_syms = (ftell (file) - offset) / sizeof (Elf64_External_Sym);
3269 if (num_dynamic_syms < 1)
3271 error (_("Unable to determine the number of symbols to load\n"));
3275 dynamic_symbols = GET_ELF_SYMBOLS (file, offset, num_dynamic_syms);
3279 /* Similarly find a string table. */
3280 if (dynamic_strings == NULL)
3282 for (i = 0, entry = dynamic_segment;
3286 unsigned long offset;
3289 if (entry->d_tag != DT_STRTAB)
3292 dynamic_info[DT_STRTAB] = entry->d_un.d_val;
3294 /* Since we do not know how big the string table is,
3295 we default to reading in the entire file (!) and
3296 processing that. This is overkill, I know, but it
3299 offset = entry->d_un.d_val - loadaddr;
3300 if (fseek (file, 0, SEEK_END))
3301 error (_("Unable to seek to end of file\n"));
3302 str_tab_len = ftell (file) - offset;
3304 if (str_tab_len < 1)
3307 (_("Unable to determine the length of the dynamic string table\n"));
3311 GET_DATA_ALLOC (offset, str_tab_len, dynamic_strings, char *,
3312 "dynamic string table");
3318 /* And find the syminfo section if available. */
3319 if (dynamic_syminfo == NULL)
3321 unsigned int syminsz = 0;
3323 for (i = 0, entry = dynamic_segment;
3327 if (entry->d_tag == DT_SYMINENT)
3329 /* Note: these braces are necessary to avoid a syntax
3330 error from the SunOS4 C compiler. */
3331 assert (sizeof (Elf_External_Syminfo) == entry->d_un.d_val);
3333 else if (entry->d_tag == DT_SYMINSZ)
3334 syminsz = entry->d_un.d_val;
3335 else if (entry->d_tag == DT_SYMINFO)
3336 dynamic_syminfo_offset = entry->d_un.d_val - loadaddr;
3339 if (dynamic_syminfo_offset != 0 && syminsz != 0)
3341 Elf_External_Syminfo * extsyminfo;
3342 Elf_Internal_Syminfo * syminfo;
3344 /* There is a syminfo section. Read the data. */
3345 GET_DATA_ALLOC (dynamic_syminfo_offset, syminsz, extsyminfo,
3346 Elf_External_Syminfo *, "symbol information");
3348 dynamic_syminfo = (Elf_Internal_Syminfo *) malloc (syminsz);
3349 if (dynamic_syminfo == NULL)
3351 error (_("Out of memory\n"));
3355 dynamic_syminfo_nent = syminsz / sizeof (Elf_External_Syminfo);
3356 for (i = 0, syminfo = dynamic_syminfo; i < dynamic_syminfo_nent;
3359 syminfo->si_boundto = BYTE_GET (extsyminfo[i].si_boundto);
3360 syminfo->si_flags = BYTE_GET (extsyminfo[i].si_flags);
3367 if (do_dynamic && dynamic_addr)
3368 printf (_("\nDynamic segment at offset 0x%x contains %ld entries:\n"),
3369 dynamic_addr, (long) dynamic_size);
3371 printf (_(" Tag Type Name/Value\n"));
3373 for (i = 0, entry = dynamic_segment;
3382 print_vma (entry->d_tag, FULL_HEX);
3383 dtype = get_dynamic_type (entry->d_tag);
3384 printf (" (%s)%*s", dtype,
3385 ((is_32bit_elf ? 27 : 19)
3386 - (int) strlen (dtype)),
3390 switch (entry->d_tag)
3394 printf ("%s", get_dynamic_flags (entry->d_un.d_val));
3404 switch (entry->d_tag)
3407 printf (_("Auxiliary library"));
3411 printf (_("Filter library"));
3415 printf (_("Configuration file"));
3419 printf (_("Dependency audit library"));
3423 printf (_("Audit library"));
3427 if (dynamic_strings)
3428 printf (": [%s]\n", dynamic_strings + entry->d_un.d_val);
3432 print_vma (entry->d_un.d_val, PREFIX_HEX);
3441 printf (_("Flags:"));
3442 if (entry->d_un.d_val == 0)
3443 printf (_(" None\n"));
3446 unsigned long int val = entry->d_un.d_val;
3447 if (val & DTF_1_PARINIT)
3449 printf (" PARINIT");
3450 val ^= DTF_1_PARINIT;
3452 if (val & DTF_1_CONFEXP)
3454 printf (" CONFEXP");
3455 val ^= DTF_1_CONFEXP;
3458 printf (" %lx", val);
3467 printf (_("Flags:"));
3468 if (entry->d_un.d_val == 0)
3469 printf (_(" None\n"));
3472 unsigned long int val = entry->d_un.d_val;
3473 if (val & DF_P1_LAZYLOAD)
3475 printf (" LAZYLOAD");
3476 val ^= DF_P1_LAZYLOAD;
3478 if (val & DF_P1_GROUPPERM)
3480 printf (" GROUPPERM");
3481 val ^= DF_P1_GROUPPERM;
3484 printf (" %lx", val);
3493 printf (_("Flags:"));
3494 if (entry->d_un.d_val == 0)
3495 printf (_(" None\n"));
3498 unsigned long int val = entry->d_un.d_val;
3504 if (val & DF_1_GLOBAL)
3509 if (val & DF_1_GROUP)
3514 if (val & DF_1_NODELETE)
3516 printf (" NODELETE");
3517 val ^= DF_1_NODELETE;
3519 if (val & DF_1_LOADFLTR)
3521 printf (" LOADFLTR");
3522 val ^= DF_1_LOADFLTR;
3524 if (val & DF_1_INITFIRST)
3526 printf (" INITFIRST");
3527 val ^= DF_1_INITFIRST;
3529 if (val & DF_1_NOOPEN)
3534 if (val & DF_1_ORIGIN)
3539 if (val & DF_1_DIRECT)
3544 if (val & DF_1_TRANS)
3549 if (val & DF_1_INTERPOSE)
3551 printf (" INTERPOSE");
3552 val ^= DF_1_INTERPOSE;
3554 if (val & DF_1_NODEFLIB)
3556 printf (" NODEFLIB");
3557 val ^= DF_1_NODEFLIB;
3559 if (val & DF_1_NODUMP)
3564 if (val & DF_1_CONLFAT)
3566 printf (" CONLFAT");
3567 val ^= DF_1_CONLFAT;
3570 printf (" %lx", val);
3578 puts (get_dynamic_type (entry->d_un.d_val));
3598 dynamic_info[entry->d_tag] = entry->d_un.d_val;
3604 if (dynamic_strings == NULL)
3607 name = dynamic_strings + entry->d_un.d_val;
3611 switch (entry->d_tag)
3614 printf (_("Shared library: [%s]"), name);
3616 if (strcmp (name, program_interpreter) == 0)
3617 printf (_(" program interpreter"));
3621 printf (_("Library soname: [%s]"), name);
3625 printf (_("Library rpath: [%s]"), name);
3629 printf (_("Library runpath: [%s]"), name);
3633 print_vma (entry->d_un.d_val, PREFIX_HEX);
3638 print_vma (entry->d_un.d_val, PREFIX_HEX);
3654 case DT_INIT_ARRAYSZ:
3655 case DT_FINI_ARRAYSZ:
3658 print_vma (entry->d_un.d_val, UNSIGNED);
3659 printf (" (bytes)\n");
3669 print_vma (entry->d_un.d_val, UNSIGNED);
3682 if (dynamic_strings != NULL && entry->d_tag == DT_USED)
3686 name = dynamic_strings + entry->d_un.d_val;
3690 printf (_("Not needed object: [%s]\n"), name);
3695 print_vma (entry->d_un.d_val, PREFIX_HEX);
3701 /* The value of this entry is ignored. */
3705 if ((entry->d_tag >= DT_VERSYM) && (entry->d_tag <= DT_VERNEEDNUM))
3706 version_info [DT_VERSIONTAGIDX (entry->d_tag)] =
3711 switch (elf_header.e_machine)
3714 case EM_MIPS_RS4_BE:
3715 dynamic_segment_mips_val (entry);
3718 dynamic_segment_parisc_val (entry);
3721 print_vma (entry->d_un.d_val, PREFIX_HEX);
3733 get_ver_flags (flags)
3736 static char buff [32];
3743 if (flags & VER_FLG_BASE)
3744 strcat (buff, "BASE ");
3746 if (flags & VER_FLG_WEAK)
3748 if (flags & VER_FLG_BASE)
3749 strcat (buff, "| ");
3751 strcat (buff, "WEAK ");
3754 if (flags & ~(VER_FLG_BASE | VER_FLG_WEAK))
3755 strcat (buff, "| <unknown>");
3760 /* Display the contents of the version sections. */
3762 process_version_sections (file)
3765 Elf32_Internal_Shdr * section;
3772 for (i = 0, section = section_headers;
3773 i < elf_header.e_shnum;
3776 switch (section->sh_type)
3778 case SHT_GNU_verdef:
3780 Elf_External_Verdef * edefs;
3787 (_("\nVersion definition section '%s' contains %ld entries:\n"),
3788 SECTION_NAME (section), section->sh_info);
3790 printf (_(" Addr: 0x"));
3791 printf_vma (section->sh_addr);
3792 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
3793 (unsigned long) section->sh_offset, section->sh_link,
3794 SECTION_NAME (section_headers + section->sh_link));
3796 GET_DATA_ALLOC (section->sh_offset, section->sh_size,
3797 edefs, Elf_External_Verdef *,
3798 "version definition section");
3800 for (idx = cnt = 0; cnt < section->sh_info; ++ cnt)
3803 Elf_External_Verdef * edef;
3804 Elf_Internal_Verdef ent;
3805 Elf_External_Verdaux * eaux;
3806 Elf_Internal_Verdaux aux;
3810 vstart = ((char *) edefs) + idx;
3812 edef = (Elf_External_Verdef *) vstart;
3814 ent.vd_version = BYTE_GET (edef->vd_version);
3815 ent.vd_flags = BYTE_GET (edef->vd_flags);
3816 ent.vd_ndx = BYTE_GET (edef->vd_ndx);
3817 ent.vd_cnt = BYTE_GET (edef->vd_cnt);
3818 ent.vd_hash = BYTE_GET (edef->vd_hash);
3819 ent.vd_aux = BYTE_GET (edef->vd_aux);
3820 ent.vd_next = BYTE_GET (edef->vd_next);
3822 printf (_(" %#06x: Rev: %d Flags: %s"),
3823 idx, ent.vd_version, get_ver_flags (ent.vd_flags));
3825 printf (_(" Index: %d Cnt: %d "),
3826 ent.vd_ndx, ent.vd_cnt);
3828 vstart += ent.vd_aux;
3830 eaux = (Elf_External_Verdaux *) vstart;
3832 aux.vda_name = BYTE_GET (eaux->vda_name);
3833 aux.vda_next = BYTE_GET (eaux->vda_next);
3835 if (dynamic_strings)
3836 printf (_("Name: %s\n"), dynamic_strings + aux.vda_name);
3838 printf (_("Name index: %ld\n"), aux.vda_name);
3840 isum = idx + ent.vd_aux;
3842 for (j = 1; j < ent.vd_cnt; j ++)
3844 isum += aux.vda_next;
3845 vstart += aux.vda_next;
3847 eaux = (Elf_External_Verdaux *) vstart;
3849 aux.vda_name = BYTE_GET (eaux->vda_name);
3850 aux.vda_next = BYTE_GET (eaux->vda_next);
3852 if (dynamic_strings)
3853 printf (_(" %#06x: Parent %d: %s\n"),
3854 isum, j, dynamic_strings + aux.vda_name);
3856 printf (_(" %#06x: Parent %d, name index: %ld\n"),
3857 isum, j, aux.vda_name);
3867 case SHT_GNU_verneed:
3869 Elf_External_Verneed * eneed;
3875 printf (_("\nVersion needs section '%s' contains %ld entries:\n"),
3876 SECTION_NAME (section), section->sh_info);
3878 printf (_(" Addr: 0x"));
3879 printf_vma (section->sh_addr);
3880 printf (_(" Offset: %#08lx Link to section: %ld (%s)\n"),
3881 (unsigned long) section->sh_offset, section->sh_link,
3882 SECTION_NAME (section_headers + section->sh_link));
3884 GET_DATA_ALLOC (section->sh_offset, section->sh_size,
3885 eneed, Elf_External_Verneed *,
3886 "version need section");
3888 for (idx = cnt = 0; cnt < section->sh_info; ++cnt)
3890 Elf_External_Verneed * entry;
3891 Elf_Internal_Verneed ent;
3896 vstart = ((char *) eneed) + idx;
3898 entry = (Elf_External_Verneed *) vstart;
3900 ent.vn_version = BYTE_GET (entry->vn_version);
3901 ent.vn_cnt = BYTE_GET (entry->vn_cnt);
3902 ent.vn_file = BYTE_GET (entry->vn_file);
3903 ent.vn_aux = BYTE_GET (entry->vn_aux);
3904 ent.vn_next = BYTE_GET (entry->vn_next);
3906 printf (_(" %#06x: Version: %d"), idx, ent.vn_version);
3908 if (dynamic_strings)
3909 printf (_(" File: %s"), dynamic_strings + ent.vn_file);
3911 printf (_(" File: %lx"), ent.vn_file);
3913 printf (_(" Cnt: %d\n"), ent.vn_cnt);
3915 vstart += ent.vn_aux;
3917 for (j = 0, isum = idx + ent.vn_aux; j < ent.vn_cnt; ++j)
3919 Elf_External_Vernaux * eaux;
3920 Elf_Internal_Vernaux aux;
3922 eaux = (Elf_External_Vernaux *) vstart;
3924 aux.vna_hash = BYTE_GET (eaux->vna_hash);
3925 aux.vna_flags = BYTE_GET (eaux->vna_flags);
3926 aux.vna_other = BYTE_GET (eaux->vna_other);
3927 aux.vna_name = BYTE_GET (eaux->vna_name);
3928 aux.vna_next = BYTE_GET (eaux->vna_next);
3930 if (dynamic_strings)
3931 printf (_(" %#06x: Name: %s"),
3932 isum, dynamic_strings + aux.vna_name);
3934 printf (_(" %#06x: Name index: %lx"),
3935 isum, aux.vna_name);
3937 printf (_(" Flags: %s Version: %d\n"),
3938 get_ver_flags (aux.vna_flags), aux.vna_other);
3940 isum += aux.vna_next;
3941 vstart += aux.vna_next;
3951 case SHT_GNU_versym:
3953 Elf32_Internal_Shdr * link_section;
3956 unsigned char * edata;
3957 unsigned short * data;
3959 Elf_Internal_Sym * symbols;
3960 Elf32_Internal_Shdr * string_sec;
3962 link_section = section_headers + section->sh_link;
3963 total = section->sh_size / section->sh_entsize;
3967 symbols = GET_ELF_SYMBOLS (file, link_section->sh_offset,
3968 link_section->sh_size / link_section->sh_entsize);
3970 string_sec = section_headers + link_section->sh_link;
3972 GET_DATA_ALLOC (string_sec->sh_offset, string_sec->sh_size,
3973 strtab, char *, "version string table");
3975 printf (_("\nVersion symbols section '%s' contains %d entries:\n"),
3976 SECTION_NAME (section), total);
3978 printf (_(" Addr: "));
3979 printf_vma (section->sh_addr);
3980 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
3981 (unsigned long) section->sh_offset, section->sh_link,
3982 SECTION_NAME (link_section));
3984 GET_DATA_ALLOC (version_info [DT_VERSIONTAGIDX (DT_VERSYM)]
3986 total * sizeof (short), edata,
3987 unsigned char *, "version symbol data");
3989 data = (unsigned short *) malloc (total * sizeof (short));
3991 for (cnt = total; cnt --;)
3992 data [cnt] = byte_get (edata + cnt * sizeof (short),
3997 for (cnt = 0; cnt < total; cnt += 4)
4000 int check_def, check_need;
4003 printf (" %03x:", cnt);
4005 for (j = 0; (j < 4) && (cnt + j) < total; ++j)
4006 switch (data [cnt + j])
4009 fputs (_(" 0 (*local*) "), stdout);
4013 fputs (_(" 1 (*global*) "), stdout);
4017 nn = printf ("%4x%c", data [cnt + j] & 0x7fff,
4018 data [cnt + j] & 0x8000 ? 'h' : ' ');
4022 if (symbols [cnt + j].st_shndx >= SHN_LORESERVE
4023 || section_headers[symbols [cnt + j].st_shndx].sh_type
4026 if (symbols [cnt + j].st_shndx == SHN_UNDEF)
4033 && version_info [DT_VERSIONTAGIDX (DT_VERNEED)])
4035 Elf_Internal_Verneed ivn;
4036 unsigned long offset;
4038 offset = version_info [DT_VERSIONTAGIDX (DT_VERNEED)]
4043 Elf_Internal_Vernaux ivna;
4044 Elf_External_Verneed evn;
4045 Elf_External_Vernaux evna;
4046 unsigned long a_off;
4048 GET_DATA (offset, evn, "version need");
4050 ivn.vn_aux = BYTE_GET (evn.vn_aux);
4051 ivn.vn_next = BYTE_GET (evn.vn_next);
4053 a_off = offset + ivn.vn_aux;
4057 GET_DATA (a_off, evna,
4058 "version need aux (2)");
4060 ivna.vna_next = BYTE_GET (evna.vna_next);
4061 ivna.vna_other = BYTE_GET (evna.vna_other);
4063 a_off += ivna.vna_next;
4065 while (ivna.vna_other != data [cnt + j]
4066 && ivna.vna_next != 0);
4068 if (ivna.vna_other == data [cnt + j])
4070 ivna.vna_name = BYTE_GET (evna.vna_name);
4072 name = strtab + ivna.vna_name;
4073 nn += printf ("(%s%-*s",
4075 12 - (int) strlen (name),
4081 offset += ivn.vn_next;
4083 while (ivn.vn_next);
4086 if (check_def && data [cnt + j] != 0x8001
4087 && version_info [DT_VERSIONTAGIDX (DT_VERDEF)])
4089 Elf_Internal_Verdef ivd;
4090 Elf_External_Verdef evd;
4091 unsigned long offset;
4093 offset = version_info
4094 [DT_VERSIONTAGIDX (DT_VERDEF)] - loadaddr;
4098 GET_DATA (offset, evd, "version def");
4100 ivd.vd_next = BYTE_GET (evd.vd_next);
4101 ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
4103 offset += ivd.vd_next;
4105 while (ivd.vd_ndx != (data [cnt + j] & 0x7fff)
4106 && ivd.vd_next != 0);
4108 if (ivd.vd_ndx == (data [cnt + j] & 0x7fff))
4110 Elf_External_Verdaux evda;
4111 Elf_Internal_Verdaux ivda;
4113 ivd.vd_aux = BYTE_GET (evd.vd_aux);
4115 GET_DATA (offset - ivd.vd_next + ivd.vd_aux,
4116 evda, "version def aux");
4118 ivda.vda_name = BYTE_GET (evda.vda_name);
4120 name = strtab + ivda.vda_name;
4121 nn += printf ("(%s%-*s",
4123 12 - (int) strlen (name),
4129 printf ("%*c", 18 - nn, ' ');
4147 printf (_("\nNo version information found in this file.\n"));
4153 get_symbol_binding (binding)
4154 unsigned int binding;
4156 static char buff [32];
4160 case STB_LOCAL: return "LOCAL";
4161 case STB_GLOBAL: return "GLOBAL";
4162 case STB_WEAK: return "WEAK";
4164 if (binding >= STB_LOPROC && binding <= STB_HIPROC)
4165 sprintf (buff, _("<processor specific>: %d"), binding);
4166 else if (binding >= STB_LOOS && binding <= STB_HIOS)
4167 sprintf (buff, _("<OS specific>: %d"), binding);
4169 sprintf (buff, _("<unknown>: %d"), binding);
4175 get_symbol_type (type)
4178 static char buff [32];
4182 case STT_NOTYPE: return "NOTYPE";
4183 case STT_OBJECT: return "OBJECT";
4184 case STT_FUNC: return "FUNC";
4185 case STT_SECTION: return "SECTION";
4186 case STT_FILE: return "FILE";
4187 case STT_COMMON: return "COMMON";
4189 if (type >= STT_LOPROC && type <= STT_HIPROC)
4191 if (elf_header.e_machine == EM_ARM && type == STT_ARM_TFUNC)
4192 return "THUMB_FUNC";
4194 if (elf_header.e_machine == EM_SPARCV9 && type == STT_REGISTER)
4197 if (elf_header.e_machine == EM_PARISC && type == STT_PARISC_MILLI)
4198 return "PARISC_MILLI";
4200 sprintf (buff, _("<processor specific>: %d"), type);
4202 else if (type >= STT_LOOS && type <= STT_HIOS)
4204 if (elf_header.e_machine == EM_PARISC)
4206 if (type == STT_HP_OPAQUE)
4208 if (type == STT_HP_STUB)
4212 sprintf (buff, _("<OS specific>: %d"), type);
4215 sprintf (buff, _("<unknown>: %d"), type);
4221 get_symbol_visibility (visibility)
4222 unsigned int visibility;
4226 case STV_DEFAULT: return "DEFAULT";
4227 case STV_INTERNAL: return "INTERNAL";
4228 case STV_HIDDEN: return "HIDDEN";
4229 case STV_PROTECTED: return "PROTECTED";
4235 get_symbol_index_type (type)
4240 case SHN_UNDEF: return "UND";
4241 case SHN_ABS: return "ABS";
4242 case SHN_COMMON: return "COM";
4244 if (type >= SHN_LOPROC && type <= SHN_HIPROC)
4246 else if (type >= SHN_LORESERVE && type <= SHN_HIRESERVE)
4248 else if (type >= SHN_LOOS && type <= SHN_HIOS)
4252 static char buff [32];
4254 sprintf (buff, "%3d", type);
4261 get_dynamic_data (file, number)
4263 unsigned int number;
4265 unsigned char * e_data;
4268 e_data = (unsigned char *) malloc (number * 4);
4272 error (_("Out of memory\n"));
4276 if (fread (e_data, 4, number, file) != number)
4278 error (_("Unable to read in dynamic data\n"));
4282 i_data = (int *) malloc (number * sizeof (* i_data));
4286 error (_("Out of memory\n"));
4292 i_data [number] = byte_get (e_data + number * 4, 4);
4299 /* Dump the symbol table */
4301 process_symbol_table (file)
4304 Elf32_Internal_Shdr * section;
4305 unsigned char nb [4];
4306 unsigned char nc [4];
4309 int * buckets = NULL;
4310 int * chains = NULL;
4312 if (! do_syms && !do_histogram)
4315 if (dynamic_info[DT_HASH] && ((do_using_dynamic && dynamic_strings != NULL)
4318 if (fseek (file, dynamic_info[DT_HASH] - loadaddr, SEEK_SET))
4320 error (_("Unable to seek to start of dynamic information"));
4324 if (fread (nb, sizeof (nb), 1, file) != 1)
4326 error (_("Failed to read in number of buckets\n"));
4330 if (fread (nc, sizeof (nc), 1, file) != 1)
4332 error (_("Failed to read in number of chains\n"));
4336 nbuckets = byte_get (nb, 4);
4337 nchains = byte_get (nc, 4);
4339 buckets = get_dynamic_data (file, nbuckets);
4340 chains = get_dynamic_data (file, nchains);
4342 if (buckets == NULL || chains == NULL)
4347 && dynamic_info[DT_HASH] && do_using_dynamic && dynamic_strings != NULL)
4352 printf (_("\nSymbol table for image:\n"));
4354 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
4356 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
4358 for (hn = 0; hn < nbuckets; hn++)
4363 for (si = buckets [hn]; si < nchains && si > 0; si = chains [si])
4365 Elf_Internal_Sym * psym;
4367 psym = dynamic_symbols + si;
4369 printf (" %3d %3d: ", si, hn);
4370 print_vma (psym->st_value, LONG_HEX);
4372 print_vma (psym->st_size, DEC_5);
4374 printf (" %6s", get_symbol_type (ELF_ST_TYPE (psym->st_info)));
4375 printf (" %6s", get_symbol_binding (ELF_ST_BIND (psym->st_info)));
4376 printf (" %3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym->st_other)));
4377 printf (" %3.3s", get_symbol_index_type (psym->st_shndx));
4378 printf (" %s\n", dynamic_strings + psym->st_name);
4382 else if (do_syms && !do_using_dynamic)
4386 for (i = 0, section = section_headers;
4387 i < elf_header.e_shnum;
4392 Elf_Internal_Sym * symtab;
4393 Elf_Internal_Sym * psym;
4396 if ( section->sh_type != SHT_SYMTAB
4397 && section->sh_type != SHT_DYNSYM)
4400 printf (_("\nSymbol table '%s' contains %lu entries:\n"),
4401 SECTION_NAME (section),
4402 (unsigned long) (section->sh_size / section->sh_entsize));
4404 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
4406 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
4408 symtab = GET_ELF_SYMBOLS (file, section->sh_offset,
4409 section->sh_size / section->sh_entsize);
4413 if (section->sh_link == elf_header.e_shstrndx)
4414 strtab = string_table;
4417 Elf32_Internal_Shdr * string_sec;
4419 string_sec = section_headers + section->sh_link;
4421 GET_DATA_ALLOC (string_sec->sh_offset, string_sec->sh_size,
4422 strtab, char *, "string table");
4425 for (si = 0, psym = symtab;
4426 si < section->sh_size / section->sh_entsize;
4429 printf ("%6d: ", si);
4430 print_vma (psym->st_value, LONG_HEX);
4432 print_vma (psym->st_size, DEC_5);
4433 printf (" %-7s", get_symbol_type (ELF_ST_TYPE (psym->st_info)));
4434 printf (" %-6s", get_symbol_binding (ELF_ST_BIND (psym->st_info)));
4435 printf (" %-3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym->st_other)));
4436 printf (" %4s", get_symbol_index_type (psym->st_shndx));
4437 printf (" %s", strtab + psym->st_name);
4439 if (section->sh_type == SHT_DYNSYM &&
4440 version_info [DT_VERSIONTAGIDX (DT_VERSYM)] != 0)
4442 unsigned char data[2];
4443 unsigned short vers_data;
4444 unsigned long offset;
4448 offset = version_info [DT_VERSIONTAGIDX (DT_VERSYM)]
4451 GET_DATA (offset + si * sizeof (vers_data), data,
4454 vers_data = byte_get (data, 2);
4456 is_nobits = psym->st_shndx < SHN_LORESERVE ?
4457 (section_headers [psym->st_shndx].sh_type == SHT_NOBITS)
4460 check_def = (psym->st_shndx != SHN_UNDEF);
4462 if ((vers_data & 0x8000) || vers_data > 1)
4464 if (version_info [DT_VERSIONTAGIDX (DT_VERNEED)]
4465 && (is_nobits || ! check_def))
4467 Elf_External_Verneed evn;
4468 Elf_Internal_Verneed ivn;
4469 Elf_Internal_Vernaux ivna;
4471 /* We must test both. */
4472 offset = version_info
4473 [DT_VERSIONTAGIDX (DT_VERNEED)] - loadaddr;
4477 unsigned long vna_off;
4479 GET_DATA (offset, evn, "version need");
4481 ivn.vn_aux = BYTE_GET (evn.vn_aux);
4482 ivn.vn_next = BYTE_GET (evn.vn_next);
4484 vna_off = offset + ivn.vn_aux;
4488 Elf_External_Vernaux evna;
4490 GET_DATA (vna_off, evna,
4491 "version need aux (3)");
4493 ivna.vna_other = BYTE_GET (evna.vna_other);
4494 ivna.vna_next = BYTE_GET (evna.vna_next);
4495 ivna.vna_name = BYTE_GET (evna.vna_name);
4497 vna_off += ivna.vna_next;
4499 while (ivna.vna_other != vers_data
4500 && ivna.vna_next != 0);
4502 if (ivna.vna_other == vers_data)
4505 offset += ivn.vn_next;
4507 while (ivn.vn_next != 0);
4509 if (ivna.vna_other == vers_data)
4512 strtab + ivna.vna_name, ivna.vna_other);
4515 else if (! is_nobits)
4516 error (_("bad dynamic symbol"));
4523 if (vers_data != 0x8001
4524 && version_info [DT_VERSIONTAGIDX (DT_VERDEF)])
4526 Elf_Internal_Verdef ivd;
4527 Elf_Internal_Verdaux ivda;
4528 Elf_External_Verdaux evda;
4529 unsigned long offset;
4532 version_info [DT_VERSIONTAGIDX (DT_VERDEF)]
4537 Elf_External_Verdef evd;
4539 GET_DATA (offset, evd, "version def");
4541 ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
4542 ivd.vd_aux = BYTE_GET (evd.vd_aux);
4543 ivd.vd_next = BYTE_GET (evd.vd_next);
4545 offset += ivd.vd_next;
4547 while (ivd.vd_ndx != (vers_data & 0x7fff)
4548 && ivd.vd_next != 0);
4550 offset -= ivd.vd_next;
4551 offset += ivd.vd_aux;
4553 GET_DATA (offset, evda, "version def aux");
4555 ivda.vda_name = BYTE_GET (evda.vda_name);
4557 if (psym->st_name != ivda.vda_name)
4558 printf ((vers_data & 0x8000)
4560 strtab + ivda.vda_name);
4570 if (strtab != string_table)
4576 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
4578 if (do_histogram && buckets != NULL)
4585 int nzero_counts = 0;
4588 printf (_("\nHistogram for bucket list length (total of %d buckets):\n"),
4590 printf (_(" Length Number %% of total Coverage\n"));
4592 lengths = (int *) calloc (nbuckets, sizeof (int));
4593 if (lengths == NULL)
4595 error (_("Out of memory"));
4598 for (hn = 0; hn < nbuckets; ++hn)
4603 for (si = buckets[hn]; si > 0 && si < nchains; si = chains[si])
4606 if (maxlength < ++lengths[hn])
4611 counts = (int *) calloc (maxlength + 1, sizeof (int));
4614 error (_("Out of memory"));
4618 for (hn = 0; hn < nbuckets; ++hn)
4619 ++ counts [lengths [hn]];
4623 printf (" 0 %-10d (%5.1f%%)\n",
4624 counts[0], (counts[0] * 100.0) / nbuckets);
4625 for (si = 1; si <= maxlength; ++si)
4627 nzero_counts += counts[si] * si;
4628 printf ("%7d %-10d (%5.1f%%) %5.1f%%\n",
4629 si, counts[si], (counts[si] * 100.0) / nbuckets,
4630 (nzero_counts * 100.0) / nsyms);
4638 if (buckets != NULL)
4648 process_syminfo (file)
4649 FILE * file ATTRIBUTE_UNUSED;
4653 if (dynamic_syminfo == NULL
4655 /* No syminfo, this is ok. */
4658 /* There better should be a dynamic symbol section. */
4659 if (dynamic_symbols == NULL || dynamic_strings == NULL)
4663 printf (_("\nDynamic info segment at offset 0x%lx contains %d entries:\n"),
4664 dynamic_syminfo_offset, dynamic_syminfo_nent);
4666 printf (_(" Num: Name BoundTo Flags\n"));
4667 for (i = 0; i < dynamic_syminfo_nent; ++i)
4669 unsigned short int flags = dynamic_syminfo[i].si_flags;
4671 printf ("%4d: %-30s ", i,
4672 dynamic_strings + dynamic_symbols[i].st_name);
4674 switch (dynamic_syminfo[i].si_boundto)
4676 case SYMINFO_BT_SELF:
4677 fputs ("SELF ", stdout);
4679 case SYMINFO_BT_PARENT:
4680 fputs ("PARENT ", stdout);
4683 if (dynamic_syminfo[i].si_boundto > 0
4684 && dynamic_syminfo[i].si_boundto < dynamic_size)
4687 + dynamic_segment[dynamic_syminfo[i].si_boundto].d_un.d_val);
4689 printf ("%-10d ", dynamic_syminfo[i].si_boundto);
4693 if (flags & SYMINFO_FLG_DIRECT)
4695 if (flags & SYMINFO_FLG_PASSTHRU)
4696 printf (" PASSTHRU");
4697 if (flags & SYMINFO_FLG_COPY)
4699 if (flags & SYMINFO_FLG_LAZYLOAD)
4700 printf (" LAZYLOAD");
4708 #ifdef SUPPORT_DISASSEMBLY
4710 disassemble_section (section, file)
4711 Elf32_Internal_Shdr * section;
4714 printf (_("\nAssembly dump of section %s\n"),
4715 SECTION_NAME (section));
4717 /* XXX -- to be done --- XXX */
4724 dump_section (section, file)
4725 Elf32_Internal_Shdr * section;
4728 bfd_size_type bytes;
4730 unsigned char * data;
4731 unsigned char * start;
4733 bytes = section->sh_size;
4737 printf (_("\nSection '%s' has no data to dump.\n"),
4738 SECTION_NAME (section));
4742 printf (_("\nHex dump of section '%s':\n"), SECTION_NAME (section));
4744 addr = section->sh_addr;
4746 GET_DATA_ALLOC (section->sh_offset, bytes, start, unsigned char *,
4757 lbytes = (bytes > 16 ? 16 : bytes);
4759 printf (" 0x%8.8lx ", (unsigned long) addr);
4761 switch (elf_header.e_ident [EI_DATA])
4765 for (j = 15; j >= 0; j --)
4768 printf ("%2.2x", data [j]);
4778 for (j = 0; j < 16; j++)
4781 printf ("%2.2x", data [j]);
4791 for (j = 0; j < lbytes; j++)
4794 if (k >= ' ' && k < 0x80)
4813 static unsigned long int
4814 read_leb128 (data, length_return, sign)
4815 unsigned char * data;
4816 int * length_return;
4819 unsigned long int result = 0;
4820 unsigned int num_read = 0;
4829 result |= (byte & 0x7f) << shift;
4834 while (byte & 0x80);
4836 if (length_return != NULL)
4837 * length_return = num_read;
4839 if (sign && (shift < 32) && (byte & 0x40))
4840 result |= -1 << shift;
4845 typedef struct State_Machine_Registers
4847 unsigned long address;
4850 unsigned int column;
4854 /* This variable hold the number of the last entry seen
4855 in the File Table. */
4856 unsigned int last_file_entry;
4859 static SMR state_machine_regs;
4862 reset_state_machine (is_stmt)
4865 state_machine_regs.address = 0;
4866 state_machine_regs.file = 1;
4867 state_machine_regs.line = 1;
4868 state_machine_regs.column = 0;
4869 state_machine_regs.is_stmt = is_stmt;
4870 state_machine_regs.basic_block = 0;
4871 state_machine_regs.end_sequence = 0;
4872 state_machine_regs.last_file_entry = 0;
4875 /* Handled an extend line op. Returns true if this is the end
4878 process_extended_line_op (data, is_stmt, pointer_size)
4879 unsigned char * data;
4883 unsigned char op_code;
4886 unsigned char * name;
4889 len = read_leb128 (data, & bytes_read, 0);
4894 warn (_("badly formed extended line op encountered!"));
4899 op_code = * data ++;
4901 printf (_(" Extended opcode %d: "), op_code);
4905 case DW_LNE_end_sequence:
4906 printf (_("End of Sequence\n\n"));
4907 reset_state_machine (is_stmt);
4910 case DW_LNE_set_address:
4911 adr = byte_get (data, pointer_size);
4912 printf (_("set Address to 0x%lx\n"), adr);
4913 state_machine_regs.address = adr;
4916 case DW_LNE_define_file:
4917 printf (_(" define new File Table entry\n"));
4918 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
4920 printf (_(" %d\t"), ++ state_machine_regs.last_file_entry);
4922 data += strlen ((char *) data) + 1;
4923 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
4925 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
4927 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
4928 printf (_("%s\n\n"), name);
4932 printf (_("UNKNOWN: length %d\n"), len - bytes_read);
4939 /* Size of pointers in the .debug_line section. This information is not
4940 really present in that section. It's obtained before dumping the debug
4941 sections by doing some pre-scan of the .debug_info section. */
4942 static int debug_line_pointer_size = 4;
4945 display_debug_lines (section, start, file)
4946 Elf32_Internal_Shdr * section;
4947 unsigned char * start;
4948 FILE * file ATTRIBUTE_UNUSED;
4950 DWARF2_External_LineInfo * external;
4951 DWARF2_Internal_LineInfo info;
4952 unsigned char * standard_opcodes;
4953 unsigned char * data = start;
4954 unsigned char * end = start + section->sh_size;
4955 unsigned char * end_of_sequence;
4958 printf (_("\nDump of debug contents of section %s:\n\n"),
4959 SECTION_NAME (section));
4963 external = (DWARF2_External_LineInfo *) data;
4965 /* Check the length of the block. */
4966 info.li_length = BYTE_GET (external->li_length);
4967 if (info.li_length + sizeof (external->li_length) > section->sh_size)
4970 (_("The line info appears to be corrupt - the section is too small\n"));
4974 /* Check its version number. */
4975 info.li_version = BYTE_GET (external->li_version);
4976 if (info.li_version != 2)
4978 warn (_("Only DWARF version 2 line info is currently supported.\n"));
4982 info.li_prologue_length = BYTE_GET (external->li_prologue_length);
4983 info.li_min_insn_length = BYTE_GET (external->li_min_insn_length);
4984 info.li_default_is_stmt = BYTE_GET (external->li_default_is_stmt);
4985 info.li_line_base = BYTE_GET (external->li_line_base);
4986 info.li_line_range = BYTE_GET (external->li_line_range);
4987 info.li_opcode_base = BYTE_GET (external->li_opcode_base);
4989 /* Sign extend the line base field. */
4990 info.li_line_base <<= 24;
4991 info.li_line_base >>= 24;
4993 printf (_(" Length: %ld\n"), info.li_length);
4994 printf (_(" DWARF Version: %d\n"), info.li_version);
4995 printf (_(" Prolgue Length: %d\n"), info.li_prologue_length);
4996 printf (_(" Minimum Instruction Length: %d\n"), info.li_min_insn_length);
4997 printf (_(" Initial value of 'is_stmt': %d\n"), info.li_default_is_stmt);
4998 printf (_(" Line Base: %d\n"), info.li_line_base);
4999 printf (_(" Line Range: %d\n"), info.li_line_range);
5000 printf (_(" Opcode Base: %d\n"), info.li_opcode_base);
5002 end_of_sequence = data + info.li_length + sizeof (external->li_length);
5004 reset_state_machine (info.li_default_is_stmt);
5006 /* Display the contents of the Opcodes table. */
5007 standard_opcodes = data + sizeof (* external);
5009 printf (_("\n Opcodes:\n"));
5011 for (i = 1; i < info.li_opcode_base; i++)
5012 printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]);
5014 /* Display the contents of the Directory table. */
5015 data = standard_opcodes + info.li_opcode_base - 1;
5018 printf (_("\n The Directory Table is empty.\n"));
5021 printf (_("\n The Directory Table:\n"));
5025 printf (_(" %s\n"), data);
5027 data += strlen ((char *) data) + 1;
5031 /* Skip the NUL at the end of the table. */
5034 /* Display the contents of the File Name table. */
5036 printf (_("\n The File Name Table is empty.\n"));
5039 printf (_("\n The File Name Table:\n"));
5040 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
5044 unsigned char * name;
5047 printf (_(" %d\t"), ++ state_machine_regs.last_file_entry);
5050 data += strlen ((char *) data) + 1;
5052 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
5054 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
5056 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
5058 printf (_("%s\n"), name);
5062 /* Skip the NUL at the end of the table. */
5065 /* Now display the statements. */
5066 printf (_("\n Line Number Statements:\n"));
5069 while (data < end_of_sequence)
5071 unsigned char op_code;
5075 op_code = * data ++;
5079 case DW_LNS_extended_op:
5080 data += process_extended_line_op (data, info.li_default_is_stmt,
5081 debug_line_pointer_size);
5085 printf (_(" Copy\n"));
5088 case DW_LNS_advance_pc:
5089 adv = info.li_min_insn_length * read_leb128 (data, & bytes_read, 0);
5091 state_machine_regs.address += adv;
5092 printf (_(" Advance PC by %d to %lx\n"), adv,
5093 state_machine_regs.address);
5096 case DW_LNS_advance_line:
5097 adv = read_leb128 (data, & bytes_read, 1);
5099 state_machine_regs.line += adv;
5100 printf (_(" Advance Line by %d to %d\n"), adv,
5101 state_machine_regs.line);
5104 case DW_LNS_set_file:
5105 adv = read_leb128 (data, & bytes_read, 0);
5107 printf (_(" Set File Name to entry %d in the File Name Table\n"),
5109 state_machine_regs.file = adv;
5112 case DW_LNS_set_column:
5113 adv = read_leb128 (data, & bytes_read, 0);
5115 printf (_(" Set column to %d\n"), adv);
5116 state_machine_regs.column = adv;
5119 case DW_LNS_negate_stmt:
5120 adv = state_machine_regs.is_stmt;
5122 printf (_(" Set is_stmt to %d\n"), adv);
5123 state_machine_regs.is_stmt = adv;
5126 case DW_LNS_set_basic_block:
5127 printf (_(" Set basic block\n"));
5128 state_machine_regs.basic_block = 1;
5131 case DW_LNS_const_add_pc:
5132 adv = (((255 - info.li_opcode_base) / info.li_line_range)
5133 * info.li_min_insn_length);
5134 state_machine_regs.address += adv;
5135 printf (_(" Advance PC by constant %d to 0x%lx\n"), adv,
5136 state_machine_regs.address);
5139 case DW_LNS_fixed_advance_pc:
5140 adv = byte_get (data, 2);
5142 state_machine_regs.address += adv;
5143 printf (_(" Advance PC by fixed size amount %d to 0x%lx\n"),
5144 adv, state_machine_regs.address);
5148 op_code -= info.li_opcode_base;
5149 adv = (op_code / info.li_line_range) * info.li_min_insn_length;
5150 state_machine_regs.address += adv;
5151 printf (_(" Special opcode %d: advance Address by %d to 0x%lx"),
5152 op_code, adv, state_machine_regs.address);
5153 adv = (op_code % info.li_line_range) + info.li_line_base;
5154 state_machine_regs.line += adv;
5155 printf (_(" and Line by %d to %d\n"),
5156 adv, state_machine_regs.line);
5167 display_debug_pubnames (section, start, file)
5168 Elf32_Internal_Shdr * section;
5169 unsigned char * start;
5170 FILE * file ATTRIBUTE_UNUSED;
5172 DWARF2_External_PubNames * external;
5173 DWARF2_Internal_PubNames pubnames;
5174 unsigned char * end;
5176 end = start + section->sh_size;
5178 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section));
5182 unsigned char * data;
5183 unsigned long offset;
5185 external = (DWARF2_External_PubNames *) start;
5187 pubnames.pn_length = BYTE_GET (external->pn_length);
5188 pubnames.pn_version = BYTE_GET (external->pn_version);
5189 pubnames.pn_offset = BYTE_GET (external->pn_offset);
5190 pubnames.pn_size = BYTE_GET (external->pn_size);
5192 data = start + sizeof (* external);
5193 start += pubnames.pn_length + sizeof (external->pn_length);
5195 if (pubnames.pn_version != 2)
5197 static int warned = 0;
5201 warn (_("Only DWARF 2 pubnames are currently supported\n"));
5208 printf (_(" Length: %ld\n"),
5209 pubnames.pn_length);
5210 printf (_(" Version: %d\n"),
5211 pubnames.pn_version);
5212 printf (_(" Offset into .debug_info section: %ld\n"),
5213 pubnames.pn_offset);
5214 printf (_(" Size of area in .debug_info section: %ld\n"),
5217 printf (_("\n Offset\tName\n"));
5221 offset = byte_get (data, 4);
5226 printf (" %ld\t\t%s\n", offset, data);
5227 data += strlen ((char *) data) + 1;
5230 while (offset != 0);
5243 case DW_TAG_padding: return "DW_TAG_padding";
5244 case DW_TAG_array_type: return "DW_TAG_array_type";
5245 case DW_TAG_class_type: return "DW_TAG_class_type";
5246 case DW_TAG_entry_point: return "DW_TAG_entry_point";
5247 case DW_TAG_enumeration_type: return "DW_TAG_enumeration_type";
5248 case DW_TAG_formal_parameter: return "DW_TAG_formal_parameter";
5249 case DW_TAG_imported_declaration: return "DW_TAG_imported_declaration";
5250 case DW_TAG_label: return "DW_TAG_label";
5251 case DW_TAG_lexical_block: return "DW_TAG_lexical_block";
5252 case DW_TAG_member: return "DW_TAG_member";
5253 case DW_TAG_pointer_type: return "DW_TAG_pointer_type";
5254 case DW_TAG_reference_type: return "DW_TAG_reference_type";
5255 case DW_TAG_compile_unit: return "DW_TAG_compile_unit";
5256 case DW_TAG_string_type: return "DW_TAG_string_type";
5257 case DW_TAG_structure_type: return "DW_TAG_structure_type";
5258 case DW_TAG_subroutine_type: return "DW_TAG_subroutine_type";
5259 case DW_TAG_typedef: return "DW_TAG_typedef";
5260 case DW_TAG_union_type: return "DW_TAG_union_type";
5261 case DW_TAG_unspecified_parameters: return "DW_TAG_unspecified_parameters";
5262 case DW_TAG_variant: return "DW_TAG_variant";
5263 case DW_TAG_common_block: return "DW_TAG_common_block";
5264 case DW_TAG_common_inclusion: return "DW_TAG_common_inclusion";
5265 case DW_TAG_inheritance: return "DW_TAG_inheritance";
5266 case DW_TAG_inlined_subroutine: return "DW_TAG_inlined_subroutine";
5267 case DW_TAG_module: return "DW_TAG_module";
5268 case DW_TAG_ptr_to_member_type: return "DW_TAG_ptr_to_member_type";
5269 case DW_TAG_set_type: return "DW_TAG_set_type";
5270 case DW_TAG_subrange_type: return "DW_TAG_subrange_type";
5271 case DW_TAG_with_stmt: return "DW_TAG_with_stmt";
5272 case DW_TAG_access_declaration: return "DW_TAG_access_declaration";
5273 case DW_TAG_base_type: return "DW_TAG_base_type";
5274 case DW_TAG_catch_block: return "DW_TAG_catch_block";
5275 case DW_TAG_const_type: return "DW_TAG_const_type";
5276 case DW_TAG_constant: return "DW_TAG_constant";
5277 case DW_TAG_enumerator: return "DW_TAG_enumerator";
5278 case DW_TAG_file_type: return "DW_TAG_file_type";
5279 case DW_TAG_friend: return "DW_TAG_friend";
5280 case DW_TAG_namelist: return "DW_TAG_namelist";
5281 case DW_TAG_namelist_item: return "DW_TAG_namelist_item";
5282 case DW_TAG_packed_type: return "DW_TAG_packed_type";
5283 case DW_TAG_subprogram: return "DW_TAG_subprogram";
5284 case DW_TAG_template_type_param: return "DW_TAG_template_type_param";
5285 case DW_TAG_template_value_param: return "DW_TAG_template_value_param";
5286 case DW_TAG_thrown_type: return "DW_TAG_thrown_type";
5287 case DW_TAG_try_block: return "DW_TAG_try_block";
5288 case DW_TAG_variant_part: return "DW_TAG_variant_part";
5289 case DW_TAG_variable: return "DW_TAG_variable";
5290 case DW_TAG_volatile_type: return "DW_TAG_volatile_type";
5291 case DW_TAG_MIPS_loop: return "DW_TAG_MIPS_loop";
5292 case DW_TAG_format_label: return "DW_TAG_format_label";
5293 case DW_TAG_function_template: return "DW_TAG_function_template";
5294 case DW_TAG_class_template: return "DW_TAG_class_template";
5297 static char buffer [100];
5299 sprintf (buffer, _("Unknown TAG value: %lx"), tag);
5306 get_AT_name (attribute)
5307 unsigned long attribute;
5311 case DW_AT_sibling: return "DW_AT_sibling";
5312 case DW_AT_location: return "DW_AT_location";
5313 case DW_AT_name: return "DW_AT_name";
5314 case DW_AT_ordering: return "DW_AT_ordering";
5315 case DW_AT_subscr_data: return "DW_AT_subscr_data";
5316 case DW_AT_byte_size: return "DW_AT_byte_size";
5317 case DW_AT_bit_offset: return "DW_AT_bit_offset";
5318 case DW_AT_bit_size: return "DW_AT_bit_size";
5319 case DW_AT_element_list: return "DW_AT_element_list";
5320 case DW_AT_stmt_list: return "DW_AT_stmt_list";
5321 case DW_AT_low_pc: return "DW_AT_low_pc";
5322 case DW_AT_high_pc: return "DW_AT_high_pc";
5323 case DW_AT_language: return "DW_AT_language";
5324 case DW_AT_member: return "DW_AT_member";
5325 case DW_AT_discr: return "DW_AT_discr";
5326 case DW_AT_discr_value: return "DW_AT_discr_value";
5327 case DW_AT_visibility: return "DW_AT_visibility";
5328 case DW_AT_import: return "DW_AT_import";
5329 case DW_AT_string_length: return "DW_AT_string_length";
5330 case DW_AT_common_reference: return "DW_AT_common_reference";
5331 case DW_AT_comp_dir: return "DW_AT_comp_dir";
5332 case DW_AT_const_value: return "DW_AT_const_value";
5333 case DW_AT_containing_type: return "DW_AT_containing_type";
5334 case DW_AT_default_value: return "DW_AT_default_value";
5335 case DW_AT_inline: return "DW_AT_inline";
5336 case DW_AT_is_optional: return "DW_AT_is_optional";
5337 case DW_AT_lower_bound: return "DW_AT_lower_bound";
5338 case DW_AT_producer: return "DW_AT_producer";
5339 case DW_AT_prototyped: return "DW_AT_prototyped";
5340 case DW_AT_return_addr: return "DW_AT_return_addr";
5341 case DW_AT_start_scope: return "DW_AT_start_scope";
5342 case DW_AT_stride_size: return "DW_AT_stride_size";
5343 case DW_AT_upper_bound: return "DW_AT_upper_bound";
5344 case DW_AT_abstract_origin: return "DW_AT_abstract_origin";
5345 case DW_AT_accessibility: return "DW_AT_accessibility";
5346 case DW_AT_address_class: return "DW_AT_address_class";
5347 case DW_AT_artificial: return "DW_AT_artificial";
5348 case DW_AT_base_types: return "DW_AT_base_types";
5349 case DW_AT_calling_convention: return "DW_AT_calling_convention";
5350 case DW_AT_count: return "DW_AT_count";
5351 case DW_AT_data_member_location: return "DW_AT_data_member_location";
5352 case DW_AT_decl_column: return "DW_AT_decl_column";
5353 case DW_AT_decl_file: return "DW_AT_decl_file";
5354 case DW_AT_decl_line: return "DW_AT_decl_line";
5355 case DW_AT_declaration: return "DW_AT_declaration";
5356 case DW_AT_discr_list: return "DW_AT_discr_list";
5357 case DW_AT_encoding: return "DW_AT_encoding";
5358 case DW_AT_external: return "DW_AT_external";
5359 case DW_AT_frame_base: return "DW_AT_frame_base";
5360 case DW_AT_friend: return "DW_AT_friend";
5361 case DW_AT_identifier_case: return "DW_AT_identifier_case";
5362 case DW_AT_macro_info: return "DW_AT_macro_info";
5363 case DW_AT_namelist_items: return "DW_AT_namelist_items";
5364 case DW_AT_priority: return "DW_AT_priority";
5365 case DW_AT_segment: return "DW_AT_segment";
5366 case DW_AT_specification: return "DW_AT_specification";
5367 case DW_AT_static_link: return "DW_AT_static_link";
5368 case DW_AT_type: return "DW_AT_type";
5369 case DW_AT_use_location: return "DW_AT_use_location";
5370 case DW_AT_variable_parameter: return "DW_AT_variable_parameter";
5371 case DW_AT_virtuality: return "DW_AT_virtuality";
5372 case DW_AT_vtable_elem_location: return "DW_AT_vtable_elem_location";
5373 case DW_AT_MIPS_fde: return "DW_AT_MIPS_fde";
5374 case DW_AT_MIPS_loop_begin: return "DW_AT_MIPS_loop_begin";
5375 case DW_AT_MIPS_tail_loop_begin: return "DW_AT_MIPS_tail_loop_begin";
5376 case DW_AT_MIPS_epilog_begin: return "DW_AT_MIPS_epilog_begin";
5377 case DW_AT_MIPS_loop_unroll_factor: return "DW_AT_MIPS_loop_unroll_factor";
5378 case DW_AT_MIPS_software_pipeline_depth: return "DW_AT_MIPS_software_pipeline_depth";
5379 case DW_AT_MIPS_linkage_name: return "DW_AT_MIPS_linkage_name";
5380 case DW_AT_MIPS_stride: return "DW_AT_MIPS_stride";
5381 case DW_AT_MIPS_abstract_name: return "DW_AT_MIPS_abstract_name";
5382 case DW_AT_MIPS_clone_origin: return "DW_AT_MIPS_clone_origin";
5383 case DW_AT_MIPS_has_inlines: return "DW_AT_MIPS_has_inlines";
5384 case DW_AT_sf_names: return "DW_AT_sf_names";
5385 case DW_AT_src_info: return "DW_AT_src_info";
5386 case DW_AT_mac_info: return "DW_AT_mac_info";
5387 case DW_AT_src_coords: return "DW_AT_src_coords";
5388 case DW_AT_body_begin: return "DW_AT_body_begin";
5389 case DW_AT_body_end: return "DW_AT_body_end";
5392 static char buffer [100];
5394 sprintf (buffer, _("Unknown AT value: %lx"), attribute);
5401 get_FORM_name (form)
5406 case DW_FORM_addr: return "DW_FORM_addr";
5407 case DW_FORM_block2: return "DW_FORM_block2";
5408 case DW_FORM_block4: return "DW_FORM_block4";
5409 case DW_FORM_data2: return "DW_FORM_data2";
5410 case DW_FORM_data4: return "DW_FORM_data4";
5411 case DW_FORM_data8: return "DW_FORM_data8";
5412 case DW_FORM_string: return "DW_FORM_string";
5413 case DW_FORM_block: return "DW_FORM_block";
5414 case DW_FORM_block1: return "DW_FORM_block1";
5415 case DW_FORM_data1: return "DW_FORM_data1";
5416 case DW_FORM_flag: return "DW_FORM_flag";
5417 case DW_FORM_sdata: return "DW_FORM_sdata";
5418 case DW_FORM_strp: return "DW_FORM_strp";
5419 case DW_FORM_udata: return "DW_FORM_udata";
5420 case DW_FORM_ref_addr: return "DW_FORM_ref_addr";
5421 case DW_FORM_ref1: return "DW_FORM_ref1";
5422 case DW_FORM_ref2: return "DW_FORM_ref2";
5423 case DW_FORM_ref4: return "DW_FORM_ref4";
5424 case DW_FORM_ref8: return "DW_FORM_ref8";
5425 case DW_FORM_ref_udata: return "DW_FORM_ref_udata";
5426 case DW_FORM_indirect: return "DW_FORM_indirect";
5429 static char buffer [100];
5431 sprintf (buffer, _("Unknown FORM value: %lx"), form);
5437 /* FIXME: There are better and more effiecint ways to handle
5438 these structures. For now though, I just want something that
5439 is simple to implement. */
5440 typedef struct abbrev_attr
5442 unsigned long attribute;
5444 struct abbrev_attr * next;
5448 typedef struct abbrev_entry
5450 unsigned long entry;
5453 struct abbrev_attr * first_attr;
5454 struct abbrev_attr * last_attr;
5455 struct abbrev_entry * next;
5459 static abbrev_entry * first_abbrev = NULL;
5460 static abbrev_entry * last_abbrev = NULL;
5463 free_abbrevs PARAMS ((void))
5465 abbrev_entry * abbrev;
5467 for (abbrev = first_abbrev; abbrev;)
5469 abbrev_entry * next = abbrev->next;
5472 for (attr = abbrev->first_attr; attr;)
5474 abbrev_attr * next = attr->next;
5484 last_abbrev = first_abbrev = NULL;
5488 add_abbrev (number, tag, children)
5489 unsigned long number;
5493 abbrev_entry * entry;
5495 entry = (abbrev_entry *) malloc (sizeof (* entry));
5501 entry->entry = number;
5503 entry->children = children;
5504 entry->first_attr = NULL;
5505 entry->last_attr = NULL;
5508 if (first_abbrev == NULL)
5509 first_abbrev = entry;
5511 last_abbrev->next = entry;
5513 last_abbrev = entry;
5517 add_abbrev_attr (attribute, form)
5518 unsigned long attribute;
5523 attr = (abbrev_attr *) malloc (sizeof (* attr));
5529 attr->attribute = attribute;
5533 if (last_abbrev->first_attr == NULL)
5534 last_abbrev->first_attr = attr;
5536 last_abbrev->last_attr->next = attr;
5538 last_abbrev->last_attr = attr;
5541 /* Processes the (partial) contents of a .debug_abbrev section.
5542 Returns NULL if the end of the section was encountered.
5543 Returns the address after the last byte read if the end of
5544 an abbreviation set was found. */
5546 static unsigned char *
5547 process_abbrev_section (start, end)
5548 unsigned char * start;
5549 unsigned char * end;
5551 if (first_abbrev != NULL)
5557 unsigned long entry;
5559 unsigned long attribute;
5562 entry = read_leb128 (start, & bytes_read, 0);
5563 start += bytes_read;
5565 /* A single zero is supposed to end the section according
5566 to the standard. If there's more, then signal that to
5569 return start == end ? NULL : start;
5571 tag = read_leb128 (start, & bytes_read, 0);
5572 start += bytes_read;
5574 children = * start ++;
5576 add_abbrev (entry, tag, children);
5582 attribute = read_leb128 (start, & bytes_read, 0);
5583 start += bytes_read;
5585 form = read_leb128 (start, & bytes_read, 0);
5586 start += bytes_read;
5589 add_abbrev_attr (attribute, form);
5591 while (attribute != 0);
5599 display_debug_abbrev (section, start, file)
5600 Elf32_Internal_Shdr * section;
5601 unsigned char * start;
5602 FILE * file ATTRIBUTE_UNUSED;
5604 abbrev_entry * entry;
5605 unsigned char * end = start + section->sh_size;
5607 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section));
5611 start = process_abbrev_section (start, end);
5613 printf (_(" Number TAG\n"));
5615 for (entry = first_abbrev; entry; entry = entry->next)
5619 printf (_(" %ld %s [%s]\n"),
5621 get_TAG_name (entry->tag),
5622 entry->children ? _("has children") : _("no children"));
5624 for (attr = entry->first_attr; attr; attr = attr->next)
5626 printf (_(" %-18s %s\n"),
5627 get_AT_name (attr->attribute),
5628 get_FORM_name (attr->form));
5640 static unsigned char *
5641 display_block (data, length)
5642 unsigned char * data;
5643 unsigned long length;
5645 printf (_(" %lu byte block: "), length);
5648 printf ("%lx ", (unsigned long) byte_get (data ++, 1));
5654 decode_location_expression (data, pointer_size, length)
5655 unsigned char * data;
5656 unsigned int pointer_size;
5657 unsigned long length;
5661 unsigned long uvalue;
5662 unsigned char * end = data + length;
5671 printf ("DW_OP_addr: %lx",
5672 (unsigned long) byte_get (data, pointer_size));
5673 data += pointer_size;
5676 printf ("DW_OP_deref");
5679 printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data++, 1));
5682 printf ("DW_OP_const1s: %ld", (long) byte_get (data++, 1));
5685 printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data, 2));
5689 printf ("DW_OP_const2s: %ld", (long) byte_get (data, 2));
5693 printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data, 4));
5697 printf ("DW_OP_const4s: %ld", (long) byte_get (data, 4));
5701 printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data, 4),
5702 (unsigned long) byte_get (data + 4, 4));
5706 printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data, 4),
5707 (long) byte_get (data + 4, 4));
5711 printf ("DW_OP_constu: %lu", read_leb128 (data, &bytes_read, 0));
5715 printf ("DW_OP_consts: %ld", read_leb128 (data, &bytes_read, 1));
5719 printf ("DW_OP_dup");
5722 printf ("DW_OP_drop");
5725 printf ("DW_OP_over");
5728 printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data++, 1));
5731 printf ("DW_OP_swap");
5734 printf ("DW_OP_rot");
5737 printf ("DW_OP_xderef");
5740 printf ("DW_OP_abs");
5743 printf ("DW_OP_and");
5746 printf ("DW_OP_div");
5749 printf ("DW_OP_minus");
5752 printf ("DW_OP_mod");
5755 printf ("DW_OP_mul");
5758 printf ("DW_OP_neg");
5761 printf ("DW_OP_not");
5764 printf ("DW_OP_or");
5767 printf ("DW_OP_plus");
5769 case DW_OP_plus_uconst:
5770 printf ("DW_OP_plus_uconst: %lu",
5771 read_leb128 (data, &bytes_read, 0));
5775 printf ("DW_OP_shl");
5778 printf ("DW_OP_shr");
5781 printf ("DW_OP_shra");
5784 printf ("DW_OP_xor");
5787 printf ("DW_OP_bra: %ld", (long) byte_get (data, 2));
5791 printf ("DW_OP_eq");
5794 printf ("DW_OP_ge");
5797 printf ("DW_OP_gt");
5800 printf ("DW_OP_le");
5803 printf ("DW_OP_lt");
5806 printf ("DW_OP_ne");
5809 printf ("DW_OP_skip: %ld", (long) byte_get (data, 2));
5845 printf ("DW_OP_lit%d", op - DW_OP_lit0);
5880 printf ("DW_OP_reg%d", op - DW_OP_reg0);
5915 printf ("DW_OP_breg%d: %ld", op - DW_OP_breg0,
5916 read_leb128 (data, &bytes_read, 1));
5921 printf ("DW_OP_regx: %lu", read_leb128 (data, &bytes_read, 0));
5925 printf ("DW_OP_fbreg: %ld", read_leb128 (data, &bytes_read, 1));
5929 uvalue = read_leb128 (data, &bytes_read, 0);
5931 printf ("DW_OP_bregx: %lu %ld", uvalue,
5932 read_leb128 (data, &bytes_read, 1));
5936 printf ("DW_OP_piece: %lu", read_leb128 (data, &bytes_read, 0));
5939 case DW_OP_deref_size:
5940 printf ("DW_OP_deref_size: %ld", (long) byte_get (data++, 1));
5942 case DW_OP_xderef_size:
5943 printf ("DW_OP_xderef_size: %ld", (long) byte_get (data++, 1));
5946 printf ("DW_OP_nop");
5950 if (op >= DW_OP_lo_user
5951 && op <= DW_OP_hi_user)
5952 printf (_("(User defined location op)"));
5954 printf (_("(Unknown location op)"));
5955 /* No way to tell where the next op is, so just bail. */
5962 static unsigned char *
5963 read_and_display_attr (attribute, form, data, cu_offset, pointer_size)
5964 unsigned long attribute;
5966 unsigned char * data;
5967 unsigned long cu_offset;
5968 unsigned long pointer_size;
5970 unsigned long uvalue = 0;
5971 unsigned char * block_start = NULL;
5974 printf (" %-18s:", get_AT_name (attribute));
5981 case DW_FORM_ref_addr:
5983 uvalue = byte_get (data, pointer_size);
5984 data += pointer_size;
5990 uvalue = byte_get (data ++, 1);
5995 uvalue = byte_get (data, 2);
6001 uvalue = byte_get (data, 4);
6006 uvalue = read_leb128 (data, & bytes_read, 1);
6010 case DW_FORM_ref_udata:
6012 uvalue = read_leb128 (data, & bytes_read, 0);
6019 case DW_FORM_ref_addr:
6020 printf (" <#%lx>", uvalue);
6026 case DW_FORM_ref_udata:
6027 printf (" <%lx>", uvalue + cu_offset);
6031 printf (" %#lx", uvalue);
6039 printf (" %ld", uvalue);
6044 uvalue = byte_get (data, 4);
6045 printf (" %lx", uvalue);
6046 printf (" %lx", (unsigned long) byte_get (data + 4, 4));
6050 case DW_FORM_string:
6051 printf (" %s", data);
6052 data += strlen ((char *) data) + 1;
6056 uvalue = read_leb128 (data, & bytes_read, 0);
6057 block_start = data + bytes_read;
6058 data = display_block (block_start, uvalue);
6061 case DW_FORM_block1:
6062 uvalue = byte_get (data, 1);
6063 block_start = data + 1;
6064 data = display_block (block_start, uvalue);
6067 case DW_FORM_block2:
6068 uvalue = byte_get (data, 2);
6069 block_start = data + 2;
6070 data = display_block (block_start, uvalue);
6073 case DW_FORM_block4:
6074 uvalue = byte_get (data, 4);
6075 block_start = data + 4;
6076 data = display_block (block_start, uvalue);
6080 case DW_FORM_indirect:
6081 warn (_("Unable to handle FORM: %d"), form);
6085 warn (_("Unrecognised form: %d"), form);
6089 /* For some attributes we can display futher information. */
6098 case DW_INL_not_inlined: printf (_("(not inlined)")); break;
6099 case DW_INL_inlined: printf (_("(inlined)")); break;
6100 case DW_INL_declared_not_inlined: printf (_("(declared as inline but ignored)")); break;
6101 case DW_INL_declared_inlined: printf (_("(declared as inline and inlined)")); break;
6102 default: printf (_(" (Unknown inline attribute value: %lx)"), uvalue); break;
6106 case DW_AT_language:
6109 case DW_LANG_C: printf ("(non-ANSI C)"); break;
6110 case DW_LANG_C89: printf ("(ANSI C)"); break;
6111 case DW_LANG_C_plus_plus: printf ("(C++)"); break;
6112 case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break;
6113 case DW_LANG_Fortran90: printf ("(Fortran 90)"); break;
6114 case DW_LANG_Modula2: printf ("(Modula 2)"); break;
6115 case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break;
6116 case DW_LANG_Ada83: printf ("(Ada)"); break;
6117 case DW_LANG_Cobol74: printf ("(Cobol 74)"); break;
6118 case DW_LANG_Cobol85: printf ("(Cobol 85)"); break;
6119 case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break;
6120 default: printf ("(Unknown: %lx)", uvalue); break;
6124 case DW_AT_encoding:
6127 case DW_ATE_void: printf ("(void)"); break;
6128 case DW_ATE_address: printf ("(machine address)"); break;
6129 case DW_ATE_boolean: printf ("(boolean)"); break;
6130 case DW_ATE_complex_float: printf ("(complex float)"); break;
6131 case DW_ATE_float: printf ("(float)"); break;
6132 case DW_ATE_signed: printf ("(signed)"); break;
6133 case DW_ATE_signed_char: printf ("(signed char)"); break;
6134 case DW_ATE_unsigned: printf ("(unsigned)"); break;
6135 case DW_ATE_unsigned_char: printf ("(unsigned char)"); break;
6137 if (uvalue >= DW_ATE_lo_user
6138 && uvalue <= DW_ATE_hi_user)
6139 printf ("(user defined type)");
6141 printf ("(unknown type)");
6146 case DW_AT_accessibility:
6149 case DW_ACCESS_public: printf ("(public)"); break;
6150 case DW_ACCESS_protected: printf ("(protected)"); break;
6151 case DW_ACCESS_private: printf ("(private)"); break;
6152 default: printf ("(unknown accessibility)"); break;
6156 case DW_AT_visibility:
6159 case DW_VIS_local: printf ("(local)"); break;
6160 case DW_VIS_exported: printf ("(exported)"); break;
6161 case DW_VIS_qualified: printf ("(qualified)"); break;
6162 default: printf ("(unknown visibility)"); break;
6166 case DW_AT_virtuality:
6169 case DW_VIRTUALITY_none: printf ("(none)"); break;
6170 case DW_VIRTUALITY_virtual: printf ("(virtual)"); break;
6171 case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break;
6172 default: printf ("(unknown virtuality)"); break;
6176 case DW_AT_identifier_case:
6179 case DW_ID_case_sensitive: printf ("(case_sensitive)"); break;
6180 case DW_ID_up_case: printf ("(up_case)"); break;
6181 case DW_ID_down_case: printf ("(down_case)"); break;
6182 case DW_ID_case_insensitive: printf ("(case_insensitive)"); break;
6183 default: printf ("(unknown case)"); break;
6187 case DW_AT_calling_convention:
6190 case DW_CC_normal: printf ("(normal)"); break;
6191 case DW_CC_program: printf ("(program)"); break;
6192 case DW_CC_nocall: printf ("(nocall)"); break;
6194 if (uvalue >= DW_CC_lo_user
6195 && uvalue <= DW_CC_hi_user)
6196 printf ("(user defined)");
6198 printf ("(unknown convention)");
6202 case DW_AT_frame_base:
6203 case DW_AT_location:
6204 case DW_AT_data_member_location:
6205 case DW_AT_vtable_elem_location:
6209 decode_location_expression (block_start, pointer_size, uvalue);
6223 display_debug_info (section, start, file)
6224 Elf32_Internal_Shdr * section;
6225 unsigned char * start;
6228 unsigned char * end = start + section->sh_size;
6229 unsigned char * section_begin = start;
6231 printf (_("The section %s contains:\n\n"), SECTION_NAME (section));
6235 DWARF2_External_CompUnit * external;
6236 DWARF2_Internal_CompUnit compunit;
6237 unsigned char * tags;
6240 unsigned long cu_offset;
6242 external = (DWARF2_External_CompUnit *) start;
6244 compunit.cu_length = BYTE_GET (external->cu_length);
6245 compunit.cu_version = BYTE_GET (external->cu_version);
6246 compunit.cu_abbrev_offset = BYTE_GET (external->cu_abbrev_offset);
6247 compunit.cu_pointer_size = BYTE_GET (external->cu_pointer_size);
6249 tags = start + sizeof (* external);
6250 cu_offset = start - section_begin;
6251 start += compunit.cu_length + sizeof (external->cu_length);
6253 printf (_(" Compilation Unit @ %lx:\n"), cu_offset);
6254 printf (_(" Length: %ld\n"), compunit.cu_length);
6255 printf (_(" Version: %d\n"), compunit.cu_version);
6256 printf (_(" Abbrev Offset: %ld\n"), compunit.cu_abbrev_offset);
6257 printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size);
6259 if (compunit.cu_version != 2)
6261 warn (_("Only version 2 DWARF debug information is currently supported.\n"));
6265 if (first_abbrev != NULL)
6268 /* Read in the abbrevs used by this compilation unit. */
6271 Elf32_Internal_Shdr * sec;
6272 unsigned char * begin;
6274 /* Locate the .debug_abbrev section and process it. */
6275 for (i = 0, sec = section_headers;
6276 i < elf_header.e_shnum;
6278 if (strcmp (SECTION_NAME (sec), ".debug_abbrev") == 0)
6281 if (i == -1 || sec->sh_size == 0)
6283 warn (_("Unable to locate .debug_abbrev section!\n"));
6287 GET_DATA_ALLOC (sec->sh_offset, sec->sh_size, begin, unsigned char *,
6288 "debug_abbrev section data");
6290 process_abbrev_section (begin + compunit.cu_abbrev_offset,
6291 begin + sec->sh_size);
6297 while (tags < start)
6300 unsigned long abbrev_number;
6301 abbrev_entry * entry;
6304 abbrev_number = read_leb128 (tags, & bytes_read, 0);
6307 /* A null DIE marks the end of a list of children. */
6308 if (abbrev_number == 0)
6314 /* Scan through the abbreviation list until we reach the
6316 for (entry = first_abbrev;
6317 entry && entry->entry != abbrev_number;
6318 entry = entry->next)
6323 warn (_("Unable to locate entry %lu in the abbreviation table\n"),
6328 printf (_(" <%d><%x>: Abbrev Number: %lu (%s)\n"),
6329 level, tags - section_begin - bytes_read,
6331 get_TAG_name (entry->tag));
6333 for (attr = entry->first_attr; attr; attr = attr->next)
6334 tags = read_and_display_attr (attr->attribute,
6337 compunit.cu_pointer_size);
6339 if (entry->children)
6350 display_debug_aranges (section, start, file)
6351 Elf32_Internal_Shdr * section;
6352 unsigned char * start;
6353 FILE * file ATTRIBUTE_UNUSED;
6355 unsigned char * end = start + section->sh_size;
6357 printf (_("The section %s contains:\n\n"), SECTION_NAME (section));
6361 DWARF2_External_ARange * external;
6362 DWARF2_Internal_ARange arange;
6363 unsigned char * ranges;
6364 unsigned long length;
6365 unsigned long address;
6368 external = (DWARF2_External_ARange *) start;
6370 arange.ar_length = BYTE_GET (external->ar_length);
6371 arange.ar_version = BYTE_GET (external->ar_version);
6372 arange.ar_info_offset = BYTE_GET (external->ar_info_offset);
6373 arange.ar_pointer_size = BYTE_GET (external->ar_pointer_size);
6374 arange.ar_segment_size = BYTE_GET (external->ar_segment_size);
6376 if (arange.ar_version != 2)
6378 warn (_("Only DWARF 2 aranges are currently supported.\n"));
6382 printf (_(" Length: %ld\n"), arange.ar_length);
6383 printf (_(" Version: %d\n"), arange.ar_version);
6384 printf (_(" Offset into .debug_info: %lx\n"), arange.ar_info_offset);
6385 printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
6386 printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
6388 printf (_("\n Address Length\n"));
6390 ranges = start + sizeof (* external);
6392 /* Must pad to an alignment boundary that is twice the pointer size. */
6393 excess = sizeof (* external) % (2 * arange.ar_pointer_size);
6395 ranges += (2 * arange.ar_pointer_size) - excess;
6399 address = byte_get (ranges, arange.ar_pointer_size);
6401 ranges += arange.ar_pointer_size;
6403 length = byte_get (ranges, arange.ar_pointer_size);
6405 ranges += arange.ar_pointer_size;
6407 /* A pair of zeros marks the end of the list. */
6408 if (address == 0 && length == 0)
6411 printf (" %8.8lx %lu\n", address, length);
6414 start += arange.ar_length + sizeof (external->ar_length);
6422 typedef struct Frame_Chunk
6424 struct Frame_Chunk * next;
6425 unsigned char * chunk_start;
6427 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
6428 short int * col_type;
6430 char * augmentation;
6431 unsigned int code_factor;
6432 unsigned int data_factor;
6433 unsigned long pc_begin;
6434 unsigned long pc_range;
6441 /* A marker for a col_type that means this column was never referenced
6442 in the frame info. */
6443 #define DW_CFA_unreferenced (-1)
6446 frame_need_space (fc, reg)
6450 int prev = fc->ncols;
6452 if (reg < fc->ncols)
6455 fc->ncols = reg + 1;
6456 fc->col_type = (short int *) xrealloc (fc->col_type,
6457 fc->ncols * sizeof (short int));
6458 fc->col_offset = (int *) xrealloc (fc->col_offset,
6459 fc->ncols * sizeof (int));
6461 while (prev < fc->ncols)
6463 fc->col_type[prev] = DW_CFA_unreferenced;
6464 fc->col_offset[prev] = 0;
6470 frame_display_row (fc, need_col_headers, max_regs)
6472 int * need_col_headers;
6478 if (* max_regs < fc->ncols)
6479 * max_regs = fc->ncols;
6481 if (* need_col_headers)
6483 * need_col_headers = 0;
6485 printf (" LOC CFA ");
6487 for (r = 0; r < * max_regs; r++)
6488 if (fc->col_type[r] != DW_CFA_unreferenced)
6493 printf ("r%-4d", r);
6499 printf ("%08x ", (unsigned int) fc->pc_begin);
6500 sprintf (tmp, "r%d%+d", fc->cfa_reg, fc->cfa_offset);
6501 printf ("%-8s ", tmp);
6503 for (r = 0; r < fc->ncols; r++)
6505 if (fc->col_type[r] != DW_CFA_unreferenced)
6507 switch (fc->col_type[r])
6509 case DW_CFA_undefined:
6512 case DW_CFA_same_value:
6516 sprintf (tmp, "c%+d", fc->col_offset[r]);
6518 case DW_CFA_register:
6519 sprintf (tmp, "r%d", fc->col_offset[r]);
6522 strcpy (tmp, "n/a");
6525 printf ("%-5s", tmp);
6531 #define GET(N) byte_get (start, N); start += N
6532 #define LEB() read_leb128 (start, & length_return, 0); start += length_return
6533 #define SLEB() read_leb128 (start, & length_return, 1); start += length_return
6536 display_debug_frames (section, start, file)
6537 Elf32_Internal_Shdr * section;
6538 unsigned char * start;
6539 FILE * file ATTRIBUTE_UNUSED;
6541 unsigned char * end = start + section->sh_size;
6542 unsigned char * section_start = start;
6543 Frame_Chunk * chunks = 0;
6544 Frame_Chunk * remembered_state = 0;
6546 int is_eh = (strcmp (SECTION_NAME (section), ".eh_frame") == 0);
6550 printf (_("The section %s contains:\n"), SECTION_NAME (section));
6554 unsigned char * saved_start;
6555 unsigned char * block_end;
6556 unsigned long length;
6557 unsigned long cie_id;
6560 int need_col_headers = 1;
6562 saved_start = start;
6563 length = byte_get (start, 4); start += 4;
6568 block_end = saved_start + length + 4;
6569 cie_id = byte_get (start, 4); start += 4;
6571 printf ("\n%08x %08lx %08lx ", saved_start - section_start, length, cie_id);
6573 if (is_eh ? (cie_id == 0) : (cie_id == DW_CIE_ID))
6575 fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
6576 memset (fc, 0, sizeof (Frame_Chunk));
6580 fc->chunk_start = saved_start;
6582 fc->col_type = (short int *) xmalloc (sizeof (short int));
6583 fc->col_offset = (int *) xmalloc (sizeof (int));
6584 frame_need_space (fc, max_regs-1);
6586 start ++; /* version */
6587 fc->augmentation = start;
6592 start++; /* skip past NUL */
6594 if (fc->augmentation[0] == 'z')
6597 fc->code_factor = LEB ();
6598 fc->data_factor = SLEB ();
6599 fc->ra = byte_get (start, 1); start += 1;
6601 printf ("skipping %d extra bytes\n", xtra);
6604 else if (strcmp (fc->augmentation, "eh") == 0)
6607 fc->code_factor = LEB ();
6608 fc->data_factor = SLEB ();
6609 fc->ra = byte_get (start, 1); start += 1;
6613 fc->code_factor = LEB ();
6614 fc->data_factor = SLEB ();
6615 fc->ra = byte_get (start, 1); start += 1;
6618 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n",
6619 fc->augmentation, fc->code_factor, fc->data_factor, fc->ra);
6621 frame_need_space (fc, fc->ra);
6625 unsigned char * look_for;
6626 static Frame_Chunk fde_fc;
6629 memset (fc, 0, sizeof (Frame_Chunk));
6631 look_for = is_eh ? start-4-cie_id : (unsigned char *) cie_id;
6633 fc->pc_begin = byte_get (start, 4); start += 4;
6634 fc->pc_range = byte_get (start, 4); start += 4;
6636 for (cie=chunks; cie && (cie->chunk_start != look_for); cie = cie->next);
6639 warn ("Invalid CIE pointer %08x in FDE at %08x\n", cie_id, saved_start);
6642 fc->col_type = (short int *) xmalloc (sizeof (short int));
6643 fc->col_offset = (int *) xmalloc (sizeof (int));
6644 frame_need_space (fc, max_regs - 1);
6646 fc->augmentation = "";
6650 fc->ncols = cie->ncols;
6651 fc->col_type = (short int *) xmalloc (fc->ncols * sizeof (short int));
6652 fc->col_offset = (int *) xmalloc (fc->ncols * sizeof (int));
6653 memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int));
6654 memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int));
6655 fc->augmentation = cie->augmentation;
6656 fc->code_factor = cie->code_factor;
6657 fc->data_factor = cie->data_factor;
6658 fc->cfa_reg = cie->cfa_reg;
6659 fc->cfa_offset = cie->cfa_offset;
6661 frame_need_space (fc, max_regs-1);
6664 if (cie->augmentation[0] == 'z')
6666 unsigned long l = LEB ();
6670 printf ("FDE cie=%08x pc=%08lx..%08lx\n",
6671 cie->chunk_start-section_start, fc->pc_begin,
6672 fc->pc_begin + fc->pc_range);
6675 /* At this point, fc is the current chunk, cie (if any) is set, and we're
6676 about to interpret instructions for the chunk. */
6678 /* This exists for readelf maintainers. */
6682 /* Start by making a pass over the chunk, allocating storage
6683 and taking note of what registers are used. */
6684 unsigned char * tmp = start;
6686 while (start < block_end)
6697 /* Warning: if you add any more cases to this switch, be
6698 sure to add them to the corresponding switch below. */
6701 case DW_CFA_advance_loc:
6705 frame_need_space (fc, opa);
6706 fc->col_type[opa] = DW_CFA_undefined;
6708 case DW_CFA_restore:
6709 frame_need_space (fc, opa);
6710 fc->col_type[opa] = DW_CFA_undefined;
6712 case DW_CFA_set_loc:
6713 start += sizeof (vma);
6715 case DW_CFA_advance_loc1:
6718 case DW_CFA_advance_loc2:
6721 case DW_CFA_advance_loc4:
6724 case DW_CFA_offset_extended:
6725 reg = LEB (); LEB ();
6726 frame_need_space (fc, reg);
6727 fc->col_type[reg] = DW_CFA_undefined;
6729 case DW_CFA_restore_extended:
6731 frame_need_space (fc, reg);
6732 fc->col_type[reg] = DW_CFA_undefined;
6734 case DW_CFA_undefined:
6736 frame_need_space (fc, reg);
6737 fc->col_type[reg] = DW_CFA_undefined;
6739 case DW_CFA_same_value:
6741 frame_need_space (fc, reg);
6742 fc->col_type[reg] = DW_CFA_undefined;
6744 case DW_CFA_register:
6745 reg = LEB (); LEB ();
6746 frame_need_space (fc, reg);
6747 fc->col_type[reg] = DW_CFA_undefined;
6749 case DW_CFA_def_cfa:
6752 case DW_CFA_def_cfa_register:
6755 case DW_CFA_def_cfa_offset:
6758 #ifndef DW_CFA_GNU_args_size
6759 #define DW_CFA_GNU_args_size 0x2e
6761 case DW_CFA_GNU_args_size:
6764 #ifndef DW_CFA_GNU_negative_offset_extended
6765 #define DW_CFA_GNU_negative_offset_extended 0x2f
6767 case DW_CFA_GNU_negative_offset_extended:
6768 reg = LEB (); LEB ();
6769 frame_need_space (fc, reg);
6770 fc->col_type[reg] = DW_CFA_undefined;
6779 /* Now we know what registers are used, make a second pass over
6780 the chunk, this time actually printing out the info. */
6782 while (start < block_end)
6785 unsigned long ul, reg, roffs;
6794 /* Warning: if you add any more cases to this switch, be
6795 sure to add them to the corresponding switch above. */
6798 case DW_CFA_advance_loc:
6799 frame_display_row (fc, &need_col_headers, &max_regs);
6801 printf (" DW_CFA_advance_loc: %08x = %08x + %d*%d\n",
6802 fc->pc_begin + opa * fc->code_factor, fc->pc_begin, opa, fc->code_factor);
6804 fc->pc_begin += opa * fc->code_factor;
6810 printf (" DW_CFA_offset: r%d = cfa[%d*%d]\n", opa, roffs, fc->data_factor);
6812 fc->col_type[opa] = DW_CFA_offset;
6813 fc->col_offset[opa] = roffs * fc->data_factor;
6816 case DW_CFA_restore:
6818 printf (" DW_CFA_restore: r%d\n", opa);
6820 fc->col_type[opa] = cie->col_type[opa];
6821 fc->col_offset[opa] = cie->col_offset[opa];
6824 case DW_CFA_set_loc:
6825 frame_display_row (fc, &need_col_headers, &max_regs);
6826 vma = byte_get (start, sizeof (vma)); start += sizeof (vma);
6828 printf (" DW_CFA_set_loc: %08x\n", vma);
6833 case DW_CFA_advance_loc1:
6834 frame_display_row (fc, &need_col_headers, &max_regs);
6835 ofs = byte_get (start, 1); start += 1;
6837 printf (" DW_CFA_advance_loc1: %08x = %08x + %d*%d\n",
6838 fc->pc_begin + ofs * fc->code_factor, fc->pc_begin, ofs, fc->code_factor);
6840 fc->pc_begin += ofs * fc->code_factor;
6843 case DW_CFA_advance_loc2:
6844 frame_display_row (fc, &need_col_headers, &max_regs);
6845 ofs = byte_get (start, 2); start += 2;
6847 printf (" DW_CFA_advance_loc2: %08x = %08x + %d*%d\n",
6848 fc->pc_begin + ofs * fc->code_factor, fc->pc_begin, ofs, fc->code_factor);
6850 fc->pc_begin += ofs * fc->code_factor;
6853 case DW_CFA_advance_loc4:
6854 frame_display_row (fc, &need_col_headers, &max_regs);
6855 ofs = byte_get (start, 4); start += 4;
6857 printf (" DW_CFA_advance_loc4: %08x = %08x + %d*%d\n",
6858 fc->pc_begin + ofs * fc->code_factor, fc->pc_begin, ofs, fc->code_factor);
6860 fc->pc_begin += ofs * fc->code_factor;
6863 case DW_CFA_offset_extended:
6867 printf (" DW_CFA_offset_extended: r%d = cfa[%d*%d]\n", reg, roffs, fc->data_factor);
6869 fc->col_type[reg] = DW_CFA_offset;
6870 fc->col_offset[reg] = roffs * fc->data_factor;
6873 case DW_CFA_restore_extended:
6876 printf (" DW_CFA_restore_extended: r%d\n", reg);
6878 fc->col_type[reg] = cie->col_type[reg];
6879 fc->col_offset[reg] = cie->col_offset[reg];
6882 case DW_CFA_undefined:
6885 printf (" DW_CFA_undefined: r%d\n", reg);
6887 fc->col_type[reg] = DW_CFA_undefined;
6888 fc->col_offset[reg] = 0;
6891 case DW_CFA_same_value:
6894 printf (" DW_CFA_same_value: r%d\n", reg);
6896 fc->col_type[reg] = DW_CFA_same_value;
6897 fc->col_offset[reg] = 0;
6900 case DW_CFA_register:
6904 printf (" DW_CFA_register: r%d\n", reg);
6906 fc->col_type[reg] = DW_CFA_register;
6907 fc->col_offset[reg] = roffs;
6910 case DW_CFA_remember_state:
6912 printf (" DW_CFA_remember_state\n");
6914 rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
6915 rs->ncols = fc->ncols;
6916 rs->col_type = (short int *) xmalloc (rs->ncols * sizeof (short int));
6917 rs->col_offset = (int *) xmalloc (rs->ncols * sizeof (int));
6918 memcpy (rs->col_type, fc->col_type, rs->ncols);
6919 memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (int));
6920 rs->next = remembered_state;
6921 remembered_state = rs;
6924 case DW_CFA_restore_state:
6926 printf (" DW_CFA_restore_state\n");
6928 rs = remembered_state;
6929 remembered_state = rs->next;
6930 frame_need_space (fc, rs->ncols-1);
6931 memcpy (fc->col_type, rs->col_type, rs->ncols);
6932 memcpy (fc->col_offset, rs->col_offset, rs->ncols * sizeof (int));
6933 free (rs->col_type);
6934 free (rs->col_offset);
6938 case DW_CFA_def_cfa:
6939 fc->cfa_reg = LEB ();
6940 fc->cfa_offset = LEB ();
6942 printf (" DW_CFA_def_cfa: reg %d ofs %d\n", fc->cfa_reg, fc->cfa_offset);
6946 case DW_CFA_def_cfa_register:
6947 fc->cfa_reg = LEB ();
6949 printf (" DW_CFA_def_cfa_reg: %d\n", fc->cfa_reg);
6953 case DW_CFA_def_cfa_offset:
6954 fc->cfa_offset = LEB ();
6956 printf (" DW_CFA_def_cfa_offset: %d\n", fc->cfa_offset);
6962 printf (" DW_CFA_nop\n");
6966 #ifndef DW_CFA_GNU_window_save
6967 #define DW_CFA_GNU_window_save 0x2d
6969 case DW_CFA_GNU_window_save:
6971 printf (" DW_CFA_GNU_window_save\n");
6975 #ifndef DW_CFA_GNU_args_size
6976 #define DW_CFA_GNU_args_size 0x2e
6978 case DW_CFA_GNU_args_size:
6981 printf (" DW_CFA_GNU_args_size: %d\n", ul);
6985 #ifndef DW_CFA_GNU_negative_offset_extended
6986 #define DW_CFA_GNU_negative_offset_extended 0x2f
6988 case DW_CFA_GNU_negative_offset_extended:
6991 frame_need_space (fc, reg);
6993 printf (" DW_CFA_GNU_negative_offset_extended: r%d = cfa[%d*%d]\n", reg, l, fc->data_factor);
6995 fc->col_type[reg] = DW_CFA_offset;
6996 fc->col_offset[reg] = l * fc->data_factor;
7000 fprintf (stderr, "unsupported or unknown DW_CFA_%d\n", op);
7005 frame_display_row (fc, &need_col_headers, &max_regs);
7020 display_debug_not_supported (section, start, file)
7021 Elf32_Internal_Shdr * section;
7022 unsigned char * start ATTRIBUTE_UNUSED;
7023 FILE * file ATTRIBUTE_UNUSED;
7025 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
7026 SECTION_NAME (section));
7031 /* Pre-scan the .debug_info section to record the size of address.
7032 When dumping the .debug_line, we use that size information, assuming
7033 that all compilation units have the same address size. */
7035 prescan_debug_info (section, start, file)
7036 Elf32_Internal_Shdr * section ATTRIBUTE_UNUSED;
7037 unsigned char * start;
7038 FILE * file ATTRIBUTE_UNUSED;
7040 DWARF2_External_CompUnit * external;
7042 external = (DWARF2_External_CompUnit *) start;
7044 debug_line_pointer_size = BYTE_GET (external->cu_pointer_size);
7048 /* A structure containing the name of a debug section and a pointer
7049 to a function that can decode it. The third field is a prescan
7050 function to be run over the section before displaying any of the
7055 int (* display) PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
7056 int (* prescan) PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
7060 { ".debug_info", display_debug_info, prescan_debug_info },
7061 { ".debug_abbrev", display_debug_abbrev, NULL },
7062 { ".debug_line", display_debug_lines, NULL },
7063 { ".debug_aranges", display_debug_aranges, NULL },
7064 { ".debug_pubnames", display_debug_pubnames, NULL },
7065 { ".debug_frame", display_debug_frames, NULL },
7066 { ".eh_frame", display_debug_frames, NULL },
7067 { ".debug_macinfo", display_debug_not_supported, NULL },
7068 { ".debug_frame", display_debug_not_supported, NULL },
7069 { ".debug_str", display_debug_not_supported, NULL },
7070 { ".debug_static_func", display_debug_not_supported, NULL },
7071 { ".debug_static_vars", display_debug_not_supported, NULL },
7072 { ".debug_types", display_debug_not_supported, NULL },
7073 { ".debug_weaknames", display_debug_not_supported, NULL }
7077 display_debug_section (section, file)
7078 Elf32_Internal_Shdr * section;
7081 char * name = SECTION_NAME (section);
7082 bfd_size_type length;
7083 unsigned char * start;
7086 length = section->sh_size;
7089 printf (_("\nSection '%s' has no debugging data.\n"), name);
7093 GET_DATA_ALLOC (section->sh_offset, length, start, unsigned char *,
7094 "debug section data");
7096 /* See if we know how to display the contents of this section. */
7097 if (strncmp (name, ".gnu.linkonce.wi.", 17) == 0)
7098 name = ".debug_info";
7100 for (i = NUM_ELEM (debug_displays); i--;)
7101 if (strcmp (debug_displays[i].name, name) == 0)
7103 debug_displays[i].display (section, start, file);
7108 printf (_("Unrecognised debug section: %s\n"), name);
7112 /* If we loaded in the abbrev section at some point,
7113 we must release it here. */
7114 if (first_abbrev != NULL)
7121 process_section_contents (file)
7124 Elf32_Internal_Shdr * section;
7130 /* Pre-scan the debug sections to find some debug information not
7131 present in some of them. For the .debug_line, we must find out the
7132 size of address (specified in .debug_info and .debug_aranges). */
7133 for (i = 0, section = section_headers;
7134 i < elf_header.e_shnum && i < num_dump_sects;
7137 char * name = SECTION_NAME (section);
7140 if (section->sh_size == 0)
7143 /* See if there is some pre-scan operation for this section. */
7144 for (j = NUM_ELEM (debug_displays); j--;)
7145 if (strcmp (debug_displays[j].name, name) == 0)
7147 if (debug_displays[j].prescan != NULL)
7149 bfd_size_type length;
7150 unsigned char * start;
7152 length = section->sh_size;
7153 GET_DATA_ALLOC (section->sh_offset, length, start, unsigned char *,
7154 "debug section data");
7156 debug_displays[j].prescan (section, start, file);
7164 for (i = 0, section = section_headers;
7165 i < elf_header.e_shnum && i < num_dump_sects;
7168 #ifdef SUPPORT_DISASSEMBLY
7169 if (dump_sects[i] & DISASS_DUMP)
7170 disassemble_section (section, file);
7172 if (dump_sects[i] & HEX_DUMP)
7173 dump_section (section, file);
7175 if (dump_sects[i] & DEBUG_DUMP)
7176 display_debug_section (section, file);
7179 if (i < num_dump_sects)
7180 warn (_("Some sections were not dumped because they do not exist!\n"));
7186 process_mips_fpe_exception (mask)
7192 if (mask & OEX_FPU_INEX)
7193 fputs ("INEX", stdout), first = 0;
7194 if (mask & OEX_FPU_UFLO)
7195 printf ("%sUFLO", first ? "" : "|"), first = 0;
7196 if (mask & OEX_FPU_OFLO)
7197 printf ("%sOFLO", first ? "" : "|"), first = 0;
7198 if (mask & OEX_FPU_DIV0)
7199 printf ("%sDIV0", first ? "" : "|"), first = 0;
7200 if (mask & OEX_FPU_INVAL)
7201 printf ("%sINVAL", first ? "" : "|");
7204 fputs ("0", stdout);
7208 process_mips_specific (file)
7211 Elf_Internal_Dyn * entry;
7212 size_t liblist_offset = 0;
7213 size_t liblistno = 0;
7214 size_t conflictsno = 0;
7215 size_t options_offset = 0;
7216 size_t conflicts_offset = 0;
7218 /* We have a lot of special sections. Thanks SGI! */
7219 if (dynamic_segment == NULL)
7220 /* No information available. */
7223 for (entry = dynamic_segment; entry->d_tag != DT_NULL; ++entry)
7224 switch (entry->d_tag)
7226 case DT_MIPS_LIBLIST:
7227 liblist_offset = entry->d_un.d_val - loadaddr;
7229 case DT_MIPS_LIBLISTNO:
7230 liblistno = entry->d_un.d_val;
7232 case DT_MIPS_OPTIONS:
7233 options_offset = entry->d_un.d_val - loadaddr;
7235 case DT_MIPS_CONFLICT:
7236 conflicts_offset = entry->d_un.d_val - loadaddr;
7238 case DT_MIPS_CONFLICTNO:
7239 conflictsno = entry->d_un.d_val;
7245 if (liblist_offset != 0 && liblistno != 0 && do_dynamic)
7247 Elf32_External_Lib * elib;
7250 GET_DATA_ALLOC (liblist_offset, liblistno * sizeof (Elf32_External_Lib),
7251 elib, Elf32_External_Lib *, "liblist");
7253 printf ("\nSection '.liblist' contains %lu entries:\n",
7254 (unsigned long) liblistno);
7255 fputs (" Library Time Stamp Checksum Version Flags\n",
7258 for (cnt = 0; cnt < liblistno; ++cnt)
7265 liblist.l_name = BYTE_GET (elib[cnt].l_name);
7266 time = BYTE_GET (elib[cnt].l_time_stamp);
7267 liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum);
7268 liblist.l_version = BYTE_GET (elib[cnt].l_version);
7269 liblist.l_flags = BYTE_GET (elib[cnt].l_flags);
7271 tmp = gmtime (&time);
7272 sprintf (timebuf, "%04u-%02u-%02uT%02u:%02u:%02u",
7273 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
7274 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
7276 printf ("%3lu: %-20s %s %#10lx %-7ld", (unsigned long) cnt,
7277 dynamic_strings + liblist.l_name, timebuf,
7278 liblist.l_checksum, liblist.l_version);
7280 if (liblist.l_flags == 0)
7291 { " EXACT_MATCH", LL_EXACT_MATCH },
7292 { " IGNORE_INT_VER", LL_IGNORE_INT_VER },
7293 { " REQUIRE_MINOR", LL_REQUIRE_MINOR },
7294 { " EXPORTS", LL_EXPORTS },
7295 { " DELAY_LOAD", LL_DELAY_LOAD },
7296 { " DELTA", LL_DELTA }
7298 int flags = liblist.l_flags;
7302 fcnt < sizeof (l_flags_vals) / sizeof (l_flags_vals[0]);
7304 if ((flags & l_flags_vals[fcnt].bit) != 0)
7306 fputs (l_flags_vals[fcnt].name, stdout);
7307 flags ^= l_flags_vals[fcnt].bit;
7310 printf (" %#x", (unsigned int) flags);
7319 if (options_offset != 0)
7321 Elf_External_Options * eopt;
7322 Elf_Internal_Shdr * sect = section_headers;
7323 Elf_Internal_Options * iopt;
7324 Elf_Internal_Options * option;
7328 /* Find the section header so that we get the size. */
7329 while (sect->sh_type != SHT_MIPS_OPTIONS)
7332 GET_DATA_ALLOC (options_offset, sect->sh_size, eopt,
7333 Elf_External_Options *, "options");
7335 iopt = (Elf_Internal_Options *) malloc ((sect->sh_size / sizeof (eopt))
7339 error (_("Out of memory"));
7346 while (offset < sect->sh_size)
7348 Elf_External_Options * eoption;
7350 eoption = (Elf_External_Options *) ((char *) eopt + offset);
7352 option->kind = BYTE_GET (eoption->kind);
7353 option->size = BYTE_GET (eoption->size);
7354 option->section = BYTE_GET (eoption->section);
7355 option->info = BYTE_GET (eoption->info);
7357 offset += option->size;
7363 printf (_("\nSection '%s' contains %d entries:\n"),
7364 SECTION_NAME (sect), cnt);
7372 switch (option->kind)
7375 /* This shouldn't happen. */
7376 printf (" NULL %d %lx", option->section, option->info);
7379 printf (" REGINFO ");
7380 if (elf_header.e_machine == EM_MIPS)
7383 Elf32_External_RegInfo * ereg;
7384 Elf32_RegInfo reginfo;
7386 ereg = (Elf32_External_RegInfo *) (option + 1);
7387 reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask);
7388 reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
7389 reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
7390 reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
7391 reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
7392 reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value);
7394 printf ("GPR %08lx GP 0x%lx\n",
7396 (unsigned long) reginfo.ri_gp_value);
7397 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
7398 reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
7399 reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
7404 Elf64_External_RegInfo * ereg;
7405 Elf64_Internal_RegInfo reginfo;
7407 ereg = (Elf64_External_RegInfo *) (option + 1);
7408 reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask);
7409 reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
7410 reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
7411 reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
7412 reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
7413 reginfo.ri_gp_value = BYTE_GET8 (ereg->ri_gp_value);
7415 printf ("GPR %08lx GP 0x",
7416 reginfo.ri_gprmask);
7417 printf_vma (reginfo.ri_gp_value);
7420 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
7421 reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
7422 reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
7426 case ODK_EXCEPTIONS:
7427 fputs (" EXCEPTIONS fpe_min(", stdout);
7428 process_mips_fpe_exception (option->info & OEX_FPU_MIN);
7429 fputs (") fpe_max(", stdout);
7430 process_mips_fpe_exception ((option->info & OEX_FPU_MAX) >> 8);
7431 fputs (")", stdout);
7433 if (option->info & OEX_PAGE0)
7434 fputs (" PAGE0", stdout);
7435 if (option->info & OEX_SMM)
7436 fputs (" SMM", stdout);
7437 if (option->info & OEX_FPDBUG)
7438 fputs (" FPDBUG", stdout);
7439 if (option->info & OEX_DISMISS)
7440 fputs (" DISMISS", stdout);
7443 fputs (" PAD ", stdout);
7444 if (option->info & OPAD_PREFIX)
7445 fputs (" PREFIX", stdout);
7446 if (option->info & OPAD_POSTFIX)
7447 fputs (" POSTFIX", stdout);
7448 if (option->info & OPAD_SYMBOL)
7449 fputs (" SYMBOL", stdout);
7452 fputs (" HWPATCH ", stdout);
7453 if (option->info & OHW_R4KEOP)
7454 fputs (" R4KEOP", stdout);
7455 if (option->info & OHW_R8KPFETCH)
7456 fputs (" R8KPFETCH", stdout);
7457 if (option->info & OHW_R5KEOP)
7458 fputs (" R5KEOP", stdout);
7459 if (option->info & OHW_R5KCVTL)
7460 fputs (" R5KCVTL", stdout);
7463 fputs (" FILL ", stdout);
7464 /* XXX Print content of info word? */
7467 fputs (" TAGS ", stdout);
7468 /* XXX Print content of info word? */
7471 fputs (" HWAND ", stdout);
7472 if (option->info & OHWA0_R4KEOP_CHECKED)
7473 fputs (" R4KEOP_CHECKED", stdout);
7474 if (option->info & OHWA0_R4KEOP_CLEAN)
7475 fputs (" R4KEOP_CLEAN", stdout);
7478 fputs (" HWOR ", stdout);
7479 if (option->info & OHWA0_R4KEOP_CHECKED)
7480 fputs (" R4KEOP_CHECKED", stdout);
7481 if (option->info & OHWA0_R4KEOP_CLEAN)
7482 fputs (" R4KEOP_CLEAN", stdout);
7485 printf (" GP_GROUP %#06lx self-contained %#06lx",
7486 option->info & OGP_GROUP,
7487 (option->info & OGP_SELF) >> 16);
7490 printf (" IDENT %#06lx self-contained %#06lx",
7491 option->info & OGP_GROUP,
7492 (option->info & OGP_SELF) >> 16);
7495 /* This shouldn't happen. */
7496 printf (" %3d ??? %d %lx",
7497 option->kind, option->section, option->info);
7501 len = sizeof (* eopt);
7502 while (len < option->size)
7503 if (((char *) option)[len] >= ' '
7504 && ((char *) option)[len] < 0x7f)
7505 printf ("%c", ((char *) option)[len++]);
7507 printf ("\\%03o", ((char *) option)[len++]);
7509 fputs ("\n", stdout);
7516 if (conflicts_offset != 0 && conflictsno != 0)
7518 Elf32_External_Conflict * econf32;
7519 Elf64_External_Conflict * econf64;
7520 Elf32_Conflict * iconf;
7523 if (dynamic_symbols == NULL)
7525 error (_("conflict list with without table"));
7529 iconf = (Elf32_Conflict *) malloc (conflictsno * sizeof (* iconf));
7532 error (_("Out of memory"));
7538 GET_DATA_ALLOC (conflicts_offset, conflictsno * sizeof (* econf32),
7539 econf32, Elf32_External_Conflict *, "conflict");
7541 for (cnt = 0; cnt < conflictsno; ++cnt)
7542 iconf[cnt] = BYTE_GET (econf32[cnt]);
7546 GET_DATA_ALLOC (conflicts_offset, conflictsno * sizeof (* econf64),
7547 econf64, Elf64_External_Conflict *, "conflict");
7549 for (cnt = 0; cnt < conflictsno; ++cnt)
7550 iconf[cnt] = BYTE_GET (econf64[cnt]);
7553 printf (_("\nSection '.conflict' contains %d entries:\n"), conflictsno);
7554 puts (_(" Num: Index Value Name"));
7556 for (cnt = 0; cnt < conflictsno; ++cnt)
7558 Elf_Internal_Sym * psym = &dynamic_symbols[iconf[cnt]];
7560 printf ("%5lu: %8lu ", (unsigned long) cnt, iconf[cnt]);
7561 print_vma (psym->st_value, FULL_HEX);
7562 printf (" %s\n", dynamic_strings + psym->st_name);
7572 get_note_type (e_type)
7575 static char buff[64];
7579 case NT_PRSTATUS: return _("NT_PRSTATUS (prstatus structure)");
7580 case NT_FPREGSET: return _("NT_FPREGSET (floating point registers)");
7581 case NT_PRPSINFO: return _("NT_PRPSINFO (prpsinfo structure)");
7582 case NT_TASKSTRUCT: return _("NT_TASKSTRUCT (task structure)");
7583 case NT_PRXFPREG: return _("NT_PRXFPREG (user_xfpregs structure)");
7584 case NT_PSTATUS: return _("NT_PSTATUS (pstatus structure)");
7585 case NT_FPREGS: return _("NT_FPREGS (floating point registers)");
7586 case NT_PSINFO: return _("NT_PSINFO (psinfo structure)");
7587 case NT_LWPSTATUS: return _("NT_LWPSTATUS (lwpstatus_t structure)");
7588 case NT_LWPSINFO: return _("NT_LWPSINFO (lwpsinfo_t structure)");
7589 case NT_WIN32PSTATUS: return _("NT_WIN32PSTATUS (win32_pstatus strcuture)");
7591 sprintf (buff, _("Unknown note type: (0x%08x)"), e_type);
7596 /* Note that by the ELF standard, the name field is already null byte
7597 terminated, and namesz includes the terminating null byte.
7598 I.E. the value of namesz for the name "FSF" is 4.
7600 If the value of namesz is zero, there is no name present. */
7602 process_note (pnote)
7603 Elf32_Internal_Note * pnote;
7605 printf (" %s\t\t0x%08lx\t%s\n",
7606 pnote->namesz ? pnote->namedata : "(NONE)",
7607 pnote->descsz, get_note_type (pnote->type));
7613 process_corefile_note_segment (file, offset, length)
7618 Elf_External_Note * pnotes;
7619 Elf_External_Note * external;
7625 GET_DATA_ALLOC (offset, length, pnotes, Elf_External_Note *, "notes");
7629 printf (_("\nNotes at offset 0x%08lx with length 0x%08lx:\n"),
7630 (unsigned long) offset, (unsigned long) length);
7631 printf (_(" Owner\t\tData size\tDescription\n"));
7633 while (external < (Elf_External_Note *)((char *) pnotes + length))
7635 Elf32_Internal_Note inote;
7638 inote.type = BYTE_GET (external->type);
7639 inote.namesz = BYTE_GET (external->namesz);
7640 inote.namedata = external->name;
7641 inote.descsz = BYTE_GET (external->descsz);
7642 inote.descdata = inote.namedata + align_power (inote.namesz, 2);
7643 inote.descpos = offset + (inote.descdata - (char *) pnotes);
7645 external = (Elf_External_Note *)(inote.descdata + align_power (inote.descsz, 2));
7647 /* Verify that name is null terminated. It appears that at least
7648 one version of Linux (RedHat 6.0) generates corefiles that don't
7649 comply with the ELF spec by failing to include the null byte in
7651 if (inote.namedata[inote.namesz] != '\0')
7653 temp = malloc (inote.namesz + 1);
7657 error (_("Out of memory\n"));
7662 strncpy (temp, inote.namedata, inote.namesz);
7663 temp[inote.namesz] = 0;
7665 /* warn (_("'%s' NOTE name not properly null terminated\n"), temp); */
7666 inote.namedata = temp;
7669 res &= process_note (& inote);
7684 process_corefile_note_segments (file)
7687 Elf_Internal_Phdr * program_headers;
7688 Elf_Internal_Phdr * segment;
7692 program_headers = (Elf_Internal_Phdr *) malloc
7693 (elf_header.e_phnum * sizeof (Elf_Internal_Phdr));
7695 if (program_headers == NULL)
7697 error (_("Out of memory\n"));
7702 i = get_32bit_program_headers (file, program_headers);
7704 i = get_64bit_program_headers (file, program_headers);
7708 free (program_headers);
7712 for (i = 0, segment = program_headers;
7713 i < elf_header.e_phnum;
7716 if (segment->p_type == PT_NOTE)
7717 res &= process_corefile_note_segment (file,
7718 (bfd_vma) segment->p_offset,
7719 (bfd_vma) segment->p_filesz);
7722 free (program_headers);
7728 process_corefile_contents (file)
7731 /* If we have not been asked to display the notes then do nothing. */
7735 /* If file is not a core file then exit. */
7736 if (elf_header.e_type != ET_CORE)
7739 /* No program headers means no NOTE segment. */
7740 if (elf_header.e_phnum == 0)
7742 printf (_("No note segments present in the core file.\n"));
7746 return process_corefile_note_segments (file);
7750 process_arch_specific (file)
7756 switch (elf_header.e_machine)
7759 case EM_MIPS_RS4_BE:
7760 return process_mips_specific (file);
7769 get_file_header (file)
7772 /* Read in the identity array. */
7773 if (fread (elf_header.e_ident, EI_NIDENT, 1, file) != 1)
7776 /* Determine how to read the rest of the header. */
7777 switch (elf_header.e_ident [EI_DATA])
7779 default: /* fall through */
7780 case ELFDATANONE: /* fall through */
7781 case ELFDATA2LSB: byte_get = byte_get_little_endian; break;
7782 case ELFDATA2MSB: byte_get = byte_get_big_endian; break;
7785 /* For now we only support 32 bit and 64 bit ELF files. */
7786 is_32bit_elf = (elf_header.e_ident [EI_CLASS] != ELFCLASS64);
7788 /* Read in the rest of the header. */
7791 Elf32_External_Ehdr ehdr32;
7793 if (fread (ehdr32.e_type, sizeof (ehdr32) - EI_NIDENT, 1, file) != 1)
7796 elf_header.e_type = BYTE_GET (ehdr32.e_type);
7797 elf_header.e_machine = BYTE_GET (ehdr32.e_machine);
7798 elf_header.e_version = BYTE_GET (ehdr32.e_version);
7799 elf_header.e_entry = BYTE_GET (ehdr32.e_entry);
7800 elf_header.e_phoff = BYTE_GET (ehdr32.e_phoff);
7801 elf_header.e_shoff = BYTE_GET (ehdr32.e_shoff);
7802 elf_header.e_flags = BYTE_GET (ehdr32.e_flags);
7803 elf_header.e_ehsize = BYTE_GET (ehdr32.e_ehsize);
7804 elf_header.e_phentsize = BYTE_GET (ehdr32.e_phentsize);
7805 elf_header.e_phnum = BYTE_GET (ehdr32.e_phnum);
7806 elf_header.e_shentsize = BYTE_GET (ehdr32.e_shentsize);
7807 elf_header.e_shnum = BYTE_GET (ehdr32.e_shnum);
7808 elf_header.e_shstrndx = BYTE_GET (ehdr32.e_shstrndx);
7812 Elf64_External_Ehdr ehdr64;
7814 /* If we have been compiled with sizeof (bfd_vma) == 4, then
7815 we will not be able to cope with the 64bit data found in
7816 64 ELF files. Detect this now and abort before we start
7817 overwritting things. */
7818 if (sizeof (bfd_vma) < 8)
7820 error (_("This instance of readelf has been built without support for a\n"));
7821 error (_("64 bit data type and so it cannot read 64 bit ELF files.\n"));
7825 if (fread (ehdr64.e_type, sizeof (ehdr64) - EI_NIDENT, 1, file) != 1)
7828 elf_header.e_type = BYTE_GET (ehdr64.e_type);
7829 elf_header.e_machine = BYTE_GET (ehdr64.e_machine);
7830 elf_header.e_version = BYTE_GET (ehdr64.e_version);
7831 elf_header.e_entry = BYTE_GET8 (ehdr64.e_entry);
7832 elf_header.e_phoff = BYTE_GET8 (ehdr64.e_phoff);
7833 elf_header.e_shoff = BYTE_GET8 (ehdr64.e_shoff);
7834 elf_header.e_flags = BYTE_GET (ehdr64.e_flags);
7835 elf_header.e_ehsize = BYTE_GET (ehdr64.e_ehsize);
7836 elf_header.e_phentsize = BYTE_GET (ehdr64.e_phentsize);
7837 elf_header.e_phnum = BYTE_GET (ehdr64.e_phnum);
7838 elf_header.e_shentsize = BYTE_GET (ehdr64.e_shentsize);
7839 elf_header.e_shnum = BYTE_GET (ehdr64.e_shnum);
7840 elf_header.e_shstrndx = BYTE_GET (ehdr64.e_shstrndx);
7847 process_file (file_name)
7851 struct stat statbuf;
7854 if (stat (file_name, & statbuf) < 0)
7856 error (_("Cannot stat input file %s.\n"), file_name);
7860 file = fopen (file_name, "rb");
7863 error (_("Input file %s not found.\n"), file_name);
7867 if (! get_file_header (file))
7869 error (_("%s: Failed to read file header\n"), file_name);
7874 /* Initialise per file variables. */
7875 for (i = NUM_ELEM (version_info); i--;)
7876 version_info[i] = 0;
7878 for (i = NUM_ELEM (dynamic_info); i--;)
7879 dynamic_info[i] = 0;
7881 /* Process the file. */
7883 printf (_("\nFile: %s\n"), file_name);
7885 if (! process_file_header ())
7891 process_section_headers (file);
7893 process_program_headers (file);
7895 process_dynamic_segment (file);
7897 process_relocs (file);
7899 process_symbol_table (file);
7901 process_syminfo (file);
7903 process_version_sections (file);
7905 process_section_contents (file);
7907 process_corefile_contents (file);
7909 process_arch_specific (file);
7913 if (section_headers)
7915 free (section_headers);
7916 section_headers = NULL;
7921 free (string_table);
7922 string_table = NULL;
7923 string_table_length = 0;
7926 if (dynamic_strings)
7928 free (dynamic_strings);
7929 dynamic_strings = NULL;
7932 if (dynamic_symbols)
7934 free (dynamic_symbols);
7935 dynamic_symbols = NULL;
7936 num_dynamic_syms = 0;
7939 if (dynamic_syminfo)
7941 free (dynamic_syminfo);
7942 dynamic_syminfo = NULL;
7946 #ifdef SUPPORT_DISASSEMBLY
7947 /* Needed by the i386 disassembler. For extra credit, someone could
7948 fix this so that we insert symbolic addresses here, esp for GOT/PLT
7952 print_address (unsigned int addr, FILE * outfile)
7954 fprintf (outfile,"0x%8.8x", addr);
7957 /* Needed by the i386 disassembler. */
7959 db_task_printsym (unsigned int addr)
7961 print_address (addr, stderr);
7970 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
7971 setlocale (LC_MESSAGES, "");
7973 bindtextdomain (PACKAGE, LOCALEDIR);
7974 textdomain (PACKAGE);
7976 parse_args (argc, argv);
7978 if (optind < (argc - 1))
7981 while (optind < argc)
7982 process_file (argv [optind ++]);
7984 if (dump_sects != NULL)