1 /* readelf.c -- display contents of an ELF format file
2 Copyright (C) 1998, 1999 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
31 /* Define BFD64 here, even if our default architecture is 32 bit ELF
32 as this will allow us to read in and parse 64bit and 32bit ELF files.
33 Only do this if we belive that the compiler can support a 64 bit
34 data type. For now we only rely on GCC being able to do this. */
40 #include "elf/common.h"
41 #include "elf/external.h"
42 #include "elf/internal.h"
43 #include "elf/dwarf2.h"
45 /* The following headers use the elf/reloc-macros.h file to
46 automatically generate relocation recognition functions
47 such as elf_mips_reloc_type() */
49 #define RELOC_MACROS_GEN_FUNC
55 #include "elf/alpha.h"
58 #include "elf/sparc.h"
63 #include "elf/mn10200.h"
64 #include "elf/mn10300.h"
68 #include "elf/mcore.h"
75 #ifdef ANSI_PROTOTYPES
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 num_dynamic_syms;
89 Elf_Internal_Sym * dynamic_symbols;
90 Elf_Internal_Syminfo * dynamic_syminfo;
91 unsigned long dynamic_syminfo_offset;
92 unsigned int dynamic_syminfo_nent;
93 char program_interpreter [64];
94 int dynamic_info[DT_JMPREL + 1];
97 Elf_Internal_Ehdr elf_header;
98 Elf_Internal_Shdr * section_headers;
99 Elf_Internal_Dyn * dynamic_segment;
106 int do_using_dynamic;
113 int do_debug_abbrevs;
115 int do_debug_pubnames;
116 int do_debug_aranges;
121 /* A dynamic array of flags indicating which sections require dumping. */
122 char * dump_sects = NULL;
123 unsigned int num_dump_sects = 0;
125 #define HEX_DUMP (1 << 0)
126 #define DISASS_DUMP (1 << 1)
127 #define DEBUG_DUMP (1 << 2)
129 /* How to rpint a vma value. */
130 typedef enum print_mode
142 /* Forward declarations for dumb compilers. */
143 static void print_vma PARAMS ((bfd_vma, print_mode));
144 static bfd_vma (* byte_get) PARAMS ((unsigned char *, int));
145 static bfd_vma byte_get_little_endian PARAMS ((unsigned char *, int));
146 static bfd_vma byte_get_big_endian PARAMS ((unsigned char *, int));
147 static const char * get_mips_dynamic_type PARAMS ((unsigned long));
148 static const char * get_sparc64_dynamic_type PARAMS ((unsigned long));
149 static const char * get_parisc_dynamic_type PARAMS ((unsigned long));
150 static const char * get_dynamic_type PARAMS ((unsigned long));
151 static int dump_relocations PARAMS ((FILE *, unsigned long, unsigned long, Elf_Internal_Sym *, unsigned long, char *, int));
152 static char * get_file_type PARAMS ((unsigned));
153 static char * get_machine_name PARAMS ((unsigned));
154 static char * get_machine_flags PARAMS ((unsigned, unsigned));
155 static const char * get_mips_segment_type PARAMS ((unsigned long));
156 static const char * get_parisc_segment_type PARAMS ((unsigned long));
157 static const char * get_segment_type PARAMS ((unsigned long));
158 static const char * get_mips_section_type_name PARAMS ((unsigned int));
159 static const char * get_parisc_section_type_name PARAMS ((unsigned int));
160 static const char * get_section_type_name PARAMS ((unsigned int));
161 static char * get_symbol_binding PARAMS ((unsigned int));
162 static char * get_symbol_type PARAMS ((unsigned int));
163 static void usage PARAMS ((void));
164 static void parse_args PARAMS ((int, char **));
165 static int process_file_header PARAMS ((void));
166 static int process_program_headers PARAMS ((FILE *));
167 static int process_section_headers PARAMS ((FILE *));
168 static void dynamic_segment_mips_val PARAMS ((Elf_Internal_Dyn *));
169 static void dynamic_segment_parisc_val PARAMS ((Elf_Internal_Dyn *));
170 static int process_dynamic_segment PARAMS ((FILE *));
171 static int process_symbol_table PARAMS ((FILE *));
172 static int process_section_contents PARAMS ((FILE *));
173 static void process_file PARAMS ((char *));
174 static int process_relocs PARAMS ((FILE *));
175 static int process_version_sections PARAMS ((FILE *));
176 static char * get_ver_flags PARAMS ((unsigned int));
177 static char * get_symbol_index_type PARAMS ((unsigned int));
178 static int get_32bit_section_headers PARAMS ((FILE *));
179 static int get_64bit_section_headers PARAMS ((FILE *));
180 static int get_32bit_program_headers PARAMS ((FILE *, Elf_Internal_Phdr *));
181 static int get_64bit_program_headers PARAMS ((FILE *, Elf_Internal_Phdr *));
182 static int get_file_header PARAMS ((FILE *));
183 static Elf_Internal_Sym * get_32bit_elf_symbols PARAMS ((FILE *, unsigned long, unsigned long));
184 static Elf_Internal_Sym * get_64bit_elf_symbols PARAMS ((FILE *, unsigned long, unsigned long));
185 static int * get_dynamic_data PARAMS ((FILE *, unsigned int));
186 static int get_32bit_dynamic_segment PARAMS ((FILE *));
187 static int get_64bit_dynamic_segment PARAMS ((FILE *));
188 #ifdef SUPPORT_DISASSEMBLY
189 static int disassemble_section PARAMS ((Elf32_Internal_Shdr *, FILE *));
191 static int dump_section PARAMS ((Elf32_Internal_Shdr *, FILE *));
192 static int display_debug_section PARAMS ((Elf32_Internal_Shdr *, FILE *));
193 static int display_debug_info PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
194 static int display_debug_not_supported PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
195 static int display_debug_lines PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
196 static int display_debug_abbrev PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
197 static int display_debug_aranges PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
198 static unsigned char * process_abbrev_section PARAMS ((unsigned char *, unsigned char *));
199 static unsigned long read_leb128 PARAMS ((unsigned char *, int *, int));
200 static int process_extended_line_op PARAMS ((unsigned char *, int, int));
201 static void reset_state_machine PARAMS ((int));
202 static char * get_TAG_name PARAMS ((unsigned long));
203 static char * get_AT_name PARAMS ((unsigned long));
204 static char * get_FORM_name PARAMS ((unsigned long));
205 static void free_abbrevs PARAMS ((void));
206 static void add_abbrev PARAMS ((unsigned long, unsigned long, int));
207 static void add_abbrev_attr PARAMS ((unsigned long, unsigned long));
208 static unsigned char * read_and_display_attr PARAMS ((unsigned long, unsigned long, unsigned char *, unsigned long));
209 static unsigned char * display_block PARAMS ((unsigned char *, unsigned long));
210 static void decode_location_expression PARAMS ((unsigned char *, unsigned int));
211 static void request_dump PARAMS ((unsigned int, char));
212 static const char * get_elf_class PARAMS ((unsigned char));
213 static const char * get_data_encoding PARAMS ((unsigned char));
214 static const char * get_osabi_name PARAMS ((unsigned char));
215 static int guess_is_rela PARAMS ((unsigned long));
216 static char * get_note_type PARAMS ((unsigned int));
217 static int process_note PARAMS ((Elf32_Internal_Note *));
218 static int process_corefile_note_segment PARAMS ((FILE *, bfd_vma, bfd_vma));
219 static int process_corefile_note_segments PARAMS ((FILE *));
220 static int process_corefile_contents PARAMS ((FILE *));
222 typedef int Elf32_Word;
230 #define SECTION_NAME(X) (string_table + (X)->sh_name)
232 #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
234 #define BYTE_GET(field) byte_get (field, sizeof (field))
236 /* If we can support a 64 bit data type then BFD64 should be defined
237 and sizeof (bfd_vma) == 8. In this case when translating from an
238 external 8 byte field to an internal field, we can assume that the
239 internal field is also 8 bytes wide and so we can extact all the data.
240 If, however, BFD64 is not defined, then we must assume that the
241 internal data structure only has 4 byte wide fields that are the
242 equivalent of the 8 byte wide external counterparts, and so we must
243 truncate the data. */
245 #define BYTE_GET8(field) byte_get (field, -8)
247 #define BYTE_GET8(field) byte_get (field, 8)
250 #define NUM_ELEM(array) (sizeof (array) / sizeof ((array)[0]))
252 #define GET_DATA_ALLOC(offset, size, var, type, reason) \
253 if (fseek (file, offset, SEEK_SET)) \
255 error (_("Unable to seek to start of %s at %x\n"), reason, offset); \
259 var = (type) malloc (size); \
263 error (_("Out of memory allocating %d bytes for %s\n"), size, reason); \
267 if (fread (var, size, 1, file) != 1) \
269 error (_("Unable to read in %d bytes of %s\n"), size, reason); \
276 #define GET_DATA(offset, var, reason) \
277 if (fseek (file, offset, SEEK_SET)) \
279 error (_("Unable to seek to %x for %s\n"), offset, reason); \
282 else if (fread (& var, sizeof (var), 1, file) != 1) \
284 error (_("Unable to read data at %x for %s\n"), offset, reason); \
288 #define GET_ELF_SYMBOLS(file, offset, size) \
289 (is_32bit_elf ? get_32bit_elf_symbols (file, offset, size) \
290 : get_64bit_elf_symbols (file, offset, size))
293 #ifdef ANSI_PROTOTYPES
295 error (const char * message, ...)
299 fprintf (stderr, _("%s: Error: "), program_name);
300 va_start (args, message);
301 vfprintf (stderr, message, args);
307 warn (const char * message, ...)
311 fprintf (stderr, _("%s: Warning: "), program_name);
312 va_start (args, message);
313 vfprintf (stderr, message, args);
325 fprintf (stderr, _("%s: Error: "), program_name);
327 message = va_arg (args, char *);
328 vfprintf (stderr, message, args);
340 fprintf (stderr, _("%s: Warning: "), program_name);
342 message = va_arg (args, char *);
343 vfprintf (stderr, message, args);
350 byte_get_little_endian (field, size)
351 unsigned char * field;
360 return ((unsigned int) (field [0]))
361 | (((unsigned int) (field [1])) << 8);
364 /* We want to extract data from an 8 byte wide field and
365 place it into a 4 byte wide field. Since this is a little
366 endian source we can juts use the 4 byte extraction code. */
369 return ((unsigned long) (field [0]))
370 | (((unsigned long) (field [1])) << 8)
371 | (((unsigned long) (field [2])) << 16)
372 | (((unsigned long) (field [3])) << 24);
376 /* This is a special case, generated by the BYTE_GET8 macro.
377 It means that we are loading an 8 byte value from a field
378 in an external structure into an 8 byte value in a field
379 in an internal strcuture. */
380 return ((bfd_vma) (field [0]))
381 | (((bfd_vma) (field [1])) << 8)
382 | (((bfd_vma) (field [2])) << 16)
383 | (((bfd_vma) (field [3])) << 24)
384 | (((bfd_vma) (field [4])) << 32)
385 | (((bfd_vma) (field [5])) << 40)
386 | (((bfd_vma) (field [6])) << 48)
387 | (((bfd_vma) (field [7])) << 56);
390 error (_("Unhandled data length: %d\n"), size);
395 /* Print a VMA value. */
397 print_vma (vma, mode)
407 case FULL_HEX: printf ("0x"); /* drop through */
408 case LONG_HEX: printf ("%8.8lx", (unsigned long) vma); break;
409 case PREFIX_HEX: printf ("0x"); /* drop through */
410 case HEX: printf ("%lx", (unsigned long) vma); break;
411 case DEC: printf ("%ld", (unsigned long) vma); break;
412 case DEC_5: printf ("%5ld", (long) vma); break;
413 case UNSIGNED: printf ("%lu", (unsigned long) vma); break;
434 #if BFD_HOST_64BIT_LONG
437 if (_bfd_int64_high (vma))
438 printf ("%lx%lx", _bfd_int64_high (vma), _bfd_int64_low (vma));
440 printf ("%lx", _bfd_int64_low (vma));
445 #if BFD_HOST_64BIT_LONG
448 if (_bfd_int64_high (vma))
450 printf ("++%ld", _bfd_int64_low (vma));
452 printf ("%ld", _bfd_int64_low (vma));
457 #if BFD_HOST_64BIT_LONG
458 printf ("%5ld", vma);
460 if (_bfd_int64_high (vma))
462 printf ("++%ld", _bfd_int64_low (vma));
464 printf ("%5ld", _bfd_int64_low (vma));
469 #if BFD_HOST_64BIT_LONG
472 if (_bfd_int64_high (vma))
474 printf ("++%lu", _bfd_int64_low (vma));
476 printf ("%lu", _bfd_int64_low (vma));
485 byte_get_big_endian (field, size)
486 unsigned char * field;
495 return ((unsigned int) (field [1])) | (((int) (field [0])) << 8);
498 return ((unsigned long) (field [3]))
499 | (((unsigned long) (field [2])) << 8)
500 | (((unsigned long) (field [1])) << 16)
501 | (((unsigned long) (field [0])) << 24);
504 /* Although we are extracing data from an 8 byte wide field, we
505 are returning only 4 bytes of data. */
506 return ((unsigned long) (field [7]))
507 | (((unsigned long) (field [6])) << 8)
508 | (((unsigned long) (field [5])) << 16)
509 | (((unsigned long) (field [4])) << 24);
513 /* This is a special case, generated by the BYTE_GET8 macro.
514 It means that we are loading an 8 byte value from a field
515 in an external structure into an 8 byte value in a field
516 in an internal strcuture. */
517 return ((bfd_vma) (field [7]))
518 | (((bfd_vma) (field [6])) << 8)
519 | (((bfd_vma) (field [5])) << 16)
520 | (((bfd_vma) (field [4])) << 24)
521 | (((bfd_vma) (field [3])) << 32)
522 | (((bfd_vma) (field [2])) << 40)
523 | (((bfd_vma) (field [1])) << 48)
524 | (((bfd_vma) (field [0])) << 56);
528 error (_("Unhandled data length: %d\n"), size);
534 /* Guess the relocation sized based on the sized commonly used by the specific machine. */
536 guess_is_rela (e_machine)
537 unsigned long e_machine;
541 /* Targets that use REL relocations. */
552 /* Targets that use RELA relocations. */
560 case EM_CYGNUS_MN10200:
561 case EM_CYGNUS_MN10300:
569 warn (_("Don't know about relocations on this machine architecture\n"));
574 /* Display the contents of the relocation data found at the specified offset. */
576 dump_relocations (file, rel_offset, rel_size, symtab, nsyms, strtab, is_rela)
578 unsigned long rel_offset;
579 unsigned long rel_size;
580 Elf_Internal_Sym * symtab;
586 Elf_Internal_Rel * rels;
587 Elf_Internal_Rela * relas;
590 if (is_rela == UNKNOWN)
591 is_rela = guess_is_rela (elf_header.e_machine);
597 Elf32_External_Rela * erelas;
599 GET_DATA_ALLOC (rel_offset, rel_size, erelas,
600 Elf32_External_Rela *, "relocs");
602 rel_size = rel_size / sizeof (Elf32_External_Rela);
604 relas = (Elf_Internal_Rela *)
605 malloc (rel_size * sizeof (Elf_Internal_Rela));
609 error(_("out of memory parsing relocs"));
613 for (i = 0; i < rel_size; i++)
615 relas[i].r_offset = BYTE_GET (erelas[i].r_offset);
616 relas[i].r_info = BYTE_GET (erelas[i].r_info);
617 relas[i].r_addend = BYTE_GET (erelas[i].r_addend);
622 rels = (Elf_Internal_Rel *) relas;
626 Elf64_External_Rela * erelas;
628 GET_DATA_ALLOC (rel_offset, rel_size, erelas,
629 Elf64_External_Rela *, "relocs");
631 rel_size = rel_size / sizeof (Elf64_External_Rela);
633 relas = (Elf_Internal_Rela *)
634 malloc (rel_size * sizeof (Elf_Internal_Rela));
638 error(_("out of memory parsing relocs"));
642 for (i = 0; i < rel_size; i++)
644 relas[i].r_offset = BYTE_GET8 (erelas[i].r_offset);
645 relas[i].r_info = BYTE_GET8 (erelas[i].r_info);
646 relas[i].r_addend = BYTE_GET8 (erelas[i].r_addend);
651 rels = (Elf_Internal_Rel *) relas;
658 Elf32_External_Rel * erels;
660 GET_DATA_ALLOC (rel_offset, rel_size, erels,
661 Elf32_External_Rel *, "relocs");
663 rel_size = rel_size / sizeof (Elf32_External_Rel);
665 rels = (Elf_Internal_Rel *)
666 malloc (rel_size * sizeof (Elf_Internal_Rel));
670 error(_("out of memory parsing relocs"));
674 for (i = 0; i < rel_size; i++)
676 rels[i].r_offset = BYTE_GET (erels[i].r_offset);
677 rels[i].r_info = BYTE_GET (erels[i].r_info);
682 relas = (Elf_Internal_Rela *) rels;
686 Elf64_External_Rel * erels;
688 GET_DATA_ALLOC (rel_offset, rel_size, erels,
689 Elf64_External_Rel *, "relocs");
691 rel_size = rel_size / sizeof (Elf64_External_Rel);
693 rels = (Elf_Internal_Rel *)
694 malloc (rel_size * sizeof (Elf_Internal_Rel));
698 error(_("out of memory parsing relocs"));
702 for (i = 0; i < rel_size; i++)
704 rels[i].r_offset = BYTE_GET8 (erels[i].r_offset);
705 rels[i].r_info = BYTE_GET8 (erels[i].r_info);
710 relas = (Elf_Internal_Rela *) rels;
716 (_(" Offset Info Type Symbol's Value Symbol's Name Addend\n"));
719 (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
721 for (i = 0; i < rel_size; i++)
726 bfd_vma symtab_index;
731 offset = relas [i].r_offset;
732 info = relas [i].r_info;
736 offset = rels [i].r_offset;
737 info = rels [i].r_info;
742 type = ELF32_R_TYPE (info);
743 symtab_index = ELF32_R_SYM (info);
747 if (elf_header.e_machine == EM_SPARCV9)
748 type = ELF64_R_TYPE_ID (info);
750 type = ELF64_R_TYPE (info);
751 /* The #ifdef BFD64 below is to prevent a compile time warning.
752 We know that if we do not have a 64 bit data type that we
753 will never execute this code anyway. */
755 symtab_index = ELF64_R_SYM (info);
759 #ifdef _bfd_int64_low
760 printf (" %8.8lx %5.5lx ", _bfd_int64_low (offset), _bfd_int64_low (info));
762 printf (" %8.8lx %5.5lx ", offset, info);
765 switch (elf_header.e_machine)
772 rtype = elf_m32r_reloc_type (type);
777 rtype = elf_i386_reloc_type (type);
781 rtype = elf_m68k_reloc_type (type);
785 rtype = elf_i960_reloc_type (type);
792 rtype = elf_sparc_reloc_type (type);
796 rtype = v850_reloc_type (type);
800 rtype = elf_d10v_reloc_type (type);
804 rtype = elf_d30v_reloc_type (type);
808 rtype = elf_sh_reloc_type (type);
811 case EM_CYGNUS_MN10300:
812 rtype = elf_mn10300_reloc_type (type);
815 case EM_CYGNUS_MN10200:
816 rtype = elf_mn10200_reloc_type (type);
820 rtype = elf_fr30_reloc_type (type);
824 rtype = elf_mcore_reloc_type (type);
828 rtype = elf_ppc_reloc_type (type);
833 rtype = elf_mips_reloc_type (type);
837 rtype = elf_alpha_reloc_type (type);
841 rtype = elf_arm_reloc_type (type);
845 rtype = elf_arc_reloc_type (type);
849 rtype = elf_hppa_reloc_type (type);
853 rtype = elf_pj_reloc_type (type);
858 #ifdef _bfd_int64_low
859 printf (_("unrecognised: %-7lx"), _bfd_int64_low (type));
861 printf (_("unrecognised: %-7lx"), type);
864 printf ("%-21.21s", rtype);
870 if (symtab_index >= nsyms)
871 printf (" bad symbol index: %08lx", (unsigned long) symtab_index);
874 Elf_Internal_Sym * psym;
876 psym = symtab + symtab_index;
879 print_vma (psym->st_value, LONG_HEX);
882 if (psym->st_name == 0)
884 SECTION_NAME (section_headers + psym->st_shndx));
885 else if (strtab == NULL)
886 printf (_("<string table index %3ld>"), psym->st_name);
888 printf ("%-25.25s", strtab + psym->st_name);
891 printf (" + %lx", (unsigned long) relas [i].r_addend);
897 printf ("%*c", is_32bit_elf ? 34 : 26, ' ');
898 print_vma (relas[i].r_addend, LONG_HEX);
901 if (elf_header.e_machine == EM_SPARCV9
902 && !strcmp (rtype, "R_SPARC_OLO10"))
903 printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (info));
914 get_mips_dynamic_type (type)
919 case DT_MIPS_RLD_VERSION: return "MIPS_RLD_VERSION";
920 case DT_MIPS_TIME_STAMP: return "MIPS_TIME_STAMP";
921 case DT_MIPS_ICHECKSUM: return "MIPS_ICHECKSUM";
922 case DT_MIPS_IVERSION: return "MIPS_IVERSION";
923 case DT_MIPS_FLAGS: return "MIPS_FLAGS";
924 case DT_MIPS_BASE_ADDRESS: return "MIPS_BASE_ADDRESS";
925 case DT_MIPS_MSYM: return "MIPS_MSYM";
926 case DT_MIPS_CONFLICT: return "MIPS_CONFLICT";
927 case DT_MIPS_LIBLIST: return "MIPS_LIBLIST";
928 case DT_MIPS_LOCAL_GOTNO: return "MIPS_LOCAL_GOTNO";
929 case DT_MIPS_CONFLICTNO: return "MIPS_CONFLICTNO";
930 case DT_MIPS_LIBLISTNO: return "MIPS_LIBLISTNO";
931 case DT_MIPS_SYMTABNO: return "MIPS_SYMTABNO";
932 case DT_MIPS_UNREFEXTNO: return "MIPS_UNREFEXTNO";
933 case DT_MIPS_GOTSYM: return "MIPS_GOTSYM";
934 case DT_MIPS_HIPAGENO: return "MIPS_HIPAGENO";
935 case DT_MIPS_RLD_MAP: return "MIPS_RLD_MAP";
936 case DT_MIPS_DELTA_CLASS: return "MIPS_DELTA_CLASS";
937 case DT_MIPS_DELTA_CLASS_NO: return "MIPS_DELTA_CLASS_NO";
938 case DT_MIPS_DELTA_INSTANCE: return "MIPS_DELTA_INSTANCE";
939 case DT_MIPS_DELTA_INSTANCE_NO: return "MIPS_DELTA_INSTANCE_NO";
940 case DT_MIPS_DELTA_RELOC: return "MIPS_DELTA_RELOC";
941 case DT_MIPS_DELTA_RELOC_NO: return "MIPS_DELTA_RELOC_NO";
942 case DT_MIPS_DELTA_SYM: return "MIPS_DELTA_SYM";
943 case DT_MIPS_DELTA_SYM_NO: return "MIPS_DELTA_SYM_NO";
944 case DT_MIPS_DELTA_CLASSSYM: return "MIPS_DELTA_CLASSSYM";
945 case DT_MIPS_DELTA_CLASSSYM_NO: return "MIPS_DELTA_CLASSSYM_NO";
946 case DT_MIPS_CXX_FLAGS: return "MIPS_CXX_FLAGS";
947 case DT_MIPS_PIXIE_INIT: return "MIPS_PIXIE_INIT";
948 case DT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB";
949 case DT_MIPS_LOCALPAGE_GOTIDX: return "MIPS_LOCALPAGE_GOTIDX";
950 case DT_MIPS_LOCAL_GOTIDX: return "MIPS_LOCAL_GOTIDX";
951 case DT_MIPS_HIDDEN_GOTIDX: return "MIPS_HIDDEN_GOTIDX";
952 case DT_MIPS_PROTECTED_GOTIDX: return "MIPS_PROTECTED_GOTIDX";
953 case DT_MIPS_OPTIONS: return "MIPS_OPTIONS";
954 case DT_MIPS_INTERFACE: return "MIPS_INTERFACE";
955 case DT_MIPS_DYNSTR_ALIGN: return "MIPS_DYNSTR_ALIGN";
956 case DT_MIPS_INTERFACE_SIZE: return "MIPS_INTERFACE_SIZE";
957 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
958 case DT_MIPS_PERF_SUFFIX: return "MIPS_PERF_SUFFIX";
959 case DT_MIPS_COMPACT_SIZE: return "MIPS_COMPACT_SIZE";
960 case DT_MIPS_GP_VALUE: return "MIPS_GP_VALUE";
961 case DT_MIPS_AUX_DYNAMIC: return "MIPS_AUX_DYNAMIC";
968 get_sparc64_dynamic_type (type)
973 case DT_SPARC_REGISTER: return "SPARC_REGISTER";
980 get_parisc_dynamic_type (type)
985 case DT_HP_LOAD_MAP: return "HP_LOAD_MAP";
986 case DT_HP_DLD_FLAGS: return "HP_DLD_FLAGS";
987 case DT_HP_DLD_HOOK: return "HP_DLD_HOOK";
988 case DT_HP_UX10_INIT: return "HP_UX10_INIT";
989 case DT_HP_UX10_INITSZ: return "HP_UX10_INITSZ";
990 case DT_HP_PREINIT: return "HP_PREINIT";
991 case DT_HP_PREINITSZ: return "HP_PREINITSZ";
992 case DT_HP_NEEDED: return "HP_NEEDED";
993 case DT_HP_TIME_STAMP: return "HP_TIME_STAMP";
994 case DT_HP_CHECKSUM: return "HP_CHECKSUM";
995 case DT_HP_GST_SIZE: return "HP_GST_SIZE";
996 case DT_HP_GST_VERSION: return "HP_GST_VERSION";
997 case DT_HP_GST_HASHVAL: return "HP_GST_HASHVAL";
1004 get_dynamic_type (type)
1007 static char buff [32];
1011 case DT_NULL: return "NULL";
1012 case DT_NEEDED: return "NEEDED";
1013 case DT_PLTRELSZ: return "PLTRELSZ";
1014 case DT_PLTGOT: return "PLTGOT";
1015 case DT_HASH: return "HASH";
1016 case DT_STRTAB: return "STRTAB";
1017 case DT_SYMTAB: return "SYMTAB";
1018 case DT_RELA: return "RELA";
1019 case DT_RELASZ: return "RELASZ";
1020 case DT_RELAENT: return "RELAENT";
1021 case DT_STRSZ: return "STRSZ";
1022 case DT_SYMENT: return "SYMENT";
1023 case DT_INIT: return "INIT";
1024 case DT_FINI: return "FINI";
1025 case DT_SONAME: return "SONAME";
1026 case DT_RPATH: return "RPATH";
1027 case DT_SYMBOLIC: return "SYMBOLIC";
1028 case DT_REL: return "REL";
1029 case DT_RELSZ: return "RELSZ";
1030 case DT_RELENT: return "RELENT";
1031 case DT_PLTREL: return "PLTREL";
1032 case DT_DEBUG: return "DEBUG";
1033 case DT_TEXTREL: return "TEXTREL";
1034 case DT_JMPREL: return "JMPREL";
1035 case DT_BIND_NOW: return "BIND_NOW";
1036 case DT_INIT_ARRAY: return "INIT_ARRAY";
1037 case DT_FINI_ARRAY: return "FINI_ARRAY";
1038 case DT_INIT_ARRAYSZ: return "INIT_ARRAYSZ";
1039 case DT_FINI_ARRAYSZ: return "FINI_ARRAYSZ";
1041 case DT_PLTPADSZ: return "PLTPADSZ";
1042 case DT_MOVEENT: return "MOVEENT";
1043 case DT_MOVESZ: return "MOVESZ";
1044 case DT_FEATURE_1: return "FEATURE_1";
1045 case DT_POSFLAG_1: return "POSFLAG_1";
1046 case DT_SYMINSZ: return "SYMINSZ";
1047 case DT_SYMINENT: return "SYMINENT"; /* aka VALRNGHI */
1049 case DT_ADDRRNGLO: return "ADDRRNGLO";
1050 case DT_SYMINFO: return "SYMINFO"; /* aka ADDRRNGHI */
1052 case DT_VERSYM: return "VERSYM";
1054 case DT_RELACOUNT: return "RELACOUNT";
1055 case DT_RELCOUNT: return "RELCOUNT";
1056 case DT_FLAGS_1: return "FLAGS_1";
1057 case DT_VERDEF: return "VERDEF";
1058 case DT_VERDEFNUM: return "VERDEFNUM";
1059 case DT_VERNEED: return "VERNEED";
1060 case DT_VERNEEDNUM: return "VERNEEDNUM";
1062 case DT_AUXILIARY: return "AUXILARY";
1063 case DT_USED: return "USED";
1064 case DT_FILTER: return "FILTER";
1067 if ((type >= DT_LOPROC) && (type <= DT_HIPROC))
1069 const char * result;
1071 switch (elf_header.e_machine)
1074 case EM_MIPS_RS4_BE:
1075 result = get_mips_dynamic_type (type);
1078 result = get_sparc64_dynamic_type (type);
1088 sprintf (buff, _("Processor Specific: %lx"), type);
1090 else if ((type >= DT_LOOS) && (type <= DT_HIOS))
1092 const char * result;
1094 switch (elf_header.e_machine)
1097 result = get_parisc_dynamic_type (type);
1107 sprintf (buff, _("Operating System specific: %lx"), type);
1110 sprintf (buff, _("<unknown>: %lx"), type);
1117 get_file_type (e_type)
1120 static char buff [32];
1124 case ET_NONE: return _("NONE (None)");
1125 case ET_REL: return _("REL (Relocatable file)");
1126 case ET_EXEC: return _("EXEC (Executable file)");
1127 case ET_DYN: return _("DYN (Shared object file)");
1128 case ET_CORE: return _("CORE (Core file)");
1131 if ((e_type >= ET_LOPROC) && (e_type <= ET_HIPROC))
1132 sprintf (buff, _("Processor Specific: (%x)"), e_type);
1133 else if ((e_type >= ET_LOOS) && (e_type <= ET_HIOS))
1134 sprintf (buff, _("OS Specific: (%x)"), e_type);
1136 sprintf (buff, _("<unknown>: %x"), e_type);
1142 get_machine_name (e_machine)
1145 static char buff [32];
1149 case EM_NONE: return _("None");
1150 case EM_M32: return "WE32100";
1151 case EM_SPARC: return "Sparc";
1152 case EM_386: return "Intel 80386";
1153 case EM_68K: return "MC68000";
1154 case EM_88K: return "MC88000";
1155 case EM_486: return "Intel 80486";
1156 case EM_860: return "Intel 80860";
1157 case EM_MIPS: return "MIPS R3000 big-endian";
1158 case EM_S370: return "Amdahl";
1159 case EM_MIPS_RS4_BE: return "MIPS R4000 big-endian";
1160 case EM_OLD_SPARCV9: return "Sparc v9 (old)";
1161 case EM_PARISC: return "HPPA";
1162 case EM_PPC_OLD: return "Power PC (old)";
1163 case EM_SPARC32PLUS: return "Sparc v8+" ;
1164 case EM_960: return "Intel 90860";
1165 case EM_PPC: return "PowerPC";
1166 case EM_V800: return "NEC V800";
1167 case EM_FR20: return "Fujitsu FR20";
1168 case EM_RH32: return "TRW RH32";
1169 case EM_MCORE: return "MCORE";
1170 case EM_ARM: return "ARM";
1171 case EM_OLD_ALPHA: return "Digital Alpha (old)";
1172 case EM_SH: return "Hitachi SH";
1173 case EM_SPARCV9: return "Sparc v9";
1174 case EM_TRICORE: return "Siemens Tricore";
1175 case EM_ARC: return "Argonaut RISC Core";
1176 case EM_H8_300: return "Hitachi H8/300";
1177 case EM_H8_300H: return "Hitachi H8/300H";
1178 case EM_H8S: return "Hitachi H8S";
1179 case EM_H8_500: return "Hitachi H8/500";
1180 case EM_IA_64: return "Intel IA-64";
1181 case EM_MIPS_X: return "Stanford MIPS-X";
1182 case EM_COLDFIRE: return "Motorola Coldfire";
1183 case EM_68HC12: return "Motorola M68HC12";
1184 case EM_ALPHA: return "Alpha";
1185 case EM_CYGNUS_D10V: return "d10v";
1186 case EM_CYGNUS_D30V: return "d30v";
1187 case EM_CYGNUS_ARC: return "Arc";
1188 case EM_CYGNUS_M32R: return "Mitsubishi M32r";
1189 case EM_CYGNUS_V850: return "NEC v850";
1190 case EM_CYGNUS_MN10300: return "mn10300";
1191 case EM_CYGNUS_MN10200: return "mn10200";
1192 case EM_CYGNUS_FR30: return "Fujitsu FR30";
1193 case EM_PJ: return "picoJava";
1195 sprintf (buff, _("<unknown>: %x"), e_machine);
1201 get_machine_flags (e_flags, e_machine)
1205 static char buf [1024];
1216 if (e_flags & EF_CPU32)
1217 strcat (buf, ", cpu32");
1221 if (e_flags & EF_PPC_EMB)
1222 strcat (buf, ", emb");
1224 if (e_flags & EF_PPC_RELOCATABLE)
1225 strcat (buf, ", relocatable");
1227 if (e_flags & EF_PPC_RELOCATABLE_LIB)
1228 strcat (buf, ", relocatable-lib");
1231 case EM_CYGNUS_V850:
1232 switch (e_flags & EF_V850_ARCH)
1235 strcat (buf, ", v850e");
1238 strcat (buf, ", v850ea");
1241 strcat (buf, ", v850");
1244 strcat (buf, ", unknown v850 architecture variant");
1249 case EM_CYGNUS_M32R:
1250 if ((e_flags & EF_M32R_ARCH) == E_M32R_ARCH)
1251 strcat (buf, ", m32r");
1256 case EM_MIPS_RS4_BE:
1257 if (e_flags & EF_MIPS_NOREORDER)
1258 strcat (buf, ", noreorder");
1260 if (e_flags & EF_MIPS_PIC)
1261 strcat (buf, ", pic");
1263 if (e_flags & EF_MIPS_CPIC)
1264 strcat (buf, ", cpic");
1266 if (e_flags & EF_MIPS_ABI2)
1267 strcat (buf, ", abi2");
1269 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_1)
1270 strcat (buf, ", mips1");
1272 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_2)
1273 strcat (buf, ", mips2");
1275 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_3)
1276 strcat (buf, ", mips3");
1278 if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_4)
1279 strcat (buf, ", mips4");
1283 if (e_flags & EF_SPARC_32PLUS)
1284 strcat (buf, ", v8+");
1286 if (e_flags & EF_SPARC_SUN_US1)
1287 strcat (buf, ", ultrasparcI");
1289 if (e_flags & EF_SPARC_SUN_US3)
1290 strcat (buf, ", ultrasparcIII");
1292 if (e_flags & EF_SPARC_HAL_R1)
1293 strcat (buf, ", halr1");
1295 if (e_flags & EF_SPARC_LEDATA)
1296 strcat (buf, ", ledata");
1298 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_TSO)
1299 strcat (buf, ", tso");
1301 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_PSO)
1302 strcat (buf, ", pso");
1304 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_RMO)
1305 strcat (buf, ", rmo");
1309 switch (e_flags & EF_PARISC_ARCH)
1311 case EFA_PARISC_1_0:
1312 strcpy (buf, ", PA-RISC 1.0");
1314 case EFA_PARISC_1_1:
1315 strcpy (buf, ", PA-RISC 1.1");
1317 case EFA_PARISC_2_0:
1318 strcpy (buf, ", PA-RISC 2.0");
1323 if (e_flags & EF_PARISC_TRAPNIL)
1324 strcat (buf, ", trapnil");
1325 if (e_flags & EF_PARISC_EXT)
1326 strcat (buf, ", ext");
1327 if (e_flags & EF_PARISC_LSB)
1328 strcat (buf, ", lsb");
1329 if (e_flags & EF_PARISC_WIDE)
1330 strcat (buf, ", wide");
1331 if (e_flags & EF_PARISC_NO_KABP)
1332 strcat (buf, ", no kabp");
1333 if (e_flags & EF_PARISC_LAZYSWAP)
1334 strcat (buf, ", lazyswap");
1338 if ((e_flags & EF_PICOJAVA_NEWCALLS) == EF_PICOJAVA_NEWCALLS)
1339 strcat (buf, ", new calling convention");
1341 if ((e_flags & EF_PICOJAVA_GNUCALLS) == EF_PICOJAVA_GNUCALLS)
1342 strcat (buf, ", gnu calling convention");
1351 get_mips_segment_type (type)
1356 case PT_MIPS_REGINFO:
1358 case PT_MIPS_RTPROC:
1360 case PT_MIPS_OPTIONS:
1370 get_parisc_segment_type (type)
1375 case PT_HP_TLS: return "HP_TLS";
1376 case PT_HP_CORE_NONE: return "HP_CORE_NONE";
1377 case PT_HP_CORE_VERSION: return "HP_CORE_VERSION";
1378 case PT_HP_CORE_KERNEL: return "HP_CORE_KERNEL";
1379 case PT_HP_CORE_COMM: return "HP_CORE_COMM";
1380 case PT_HP_CORE_PROC: return "HP_CORE_PROC";
1381 case PT_HP_CORE_LOADABLE: return "HP_CORE_LOADABLE";
1382 case PT_HP_CORE_STACK: return "HP_CORE_STACK";
1383 case PT_HP_CORE_SHM: return "HP_CORE_SHM";
1384 case PT_HP_CORE_MMF: return "HP_CORE_MMF";
1385 case PT_HP_PARALLEL: return "HP_PARALLEL";
1386 case PT_HP_FASTBIND: return "HP_FASTBIND";
1387 case PT_PARISC_ARCHEXT: return "PARISC_ARCHEXT";
1388 case PT_PARISC_UNWIND: return "PARISC_UNWIND";
1397 get_segment_type (p_type)
1398 unsigned long p_type;
1400 static char buff [32];
1404 case PT_NULL: return "NULL";
1405 case PT_LOAD: return "LOAD";
1406 case PT_DYNAMIC: return "DYNAMIC";
1407 case PT_INTERP: return "INTERP";
1408 case PT_NOTE: return "NOTE";
1409 case PT_SHLIB: return "SHLIB";
1410 case PT_PHDR: return "PHDR";
1413 if ((p_type >= PT_LOPROC) && (p_type <= PT_HIPROC))
1415 const char * result;
1417 switch (elf_header.e_machine)
1420 case EM_MIPS_RS4_BE:
1421 result = get_mips_segment_type (p_type);
1424 result = get_parisc_segment_type (p_type);
1434 sprintf (buff, "LOPROC+%lx", p_type - PT_LOPROC);
1436 else if ((p_type >= PT_LOOS) && (p_type <= PT_HIOS))
1438 const char * result;
1440 switch (elf_header.e_machine)
1443 result = get_parisc_segment_type (p_type);
1453 sprintf (buff, "LOOS+%lx", p_type - PT_LOOS);
1456 sprintf (buff, _("<unknown>: %lx"), p_type);
1463 get_mips_section_type_name (sh_type)
1464 unsigned int sh_type;
1468 case SHT_MIPS_LIBLIST: return "MIPS_LIBLIST";
1469 case SHT_MIPS_MSYM: return "MIPS_MSYM";
1470 case SHT_MIPS_CONFLICT: return "MIPS_CONFLICT";
1471 case SHT_MIPS_GPTAB: return "MIPS_GPTAB";
1472 case SHT_MIPS_UCODE: return "MIPS_UCODE";
1473 case SHT_MIPS_DEBUG: return "MIPS_DEBUG";
1474 case SHT_MIPS_REGINFO: return "MIPS_REGINFO";
1475 case SHT_MIPS_PACKAGE: return "MIPS_PACKAGE";
1476 case SHT_MIPS_PACKSYM: return "MIPS_PACKSYM";
1477 case SHT_MIPS_RELD: return "MIPS_RELD";
1478 case SHT_MIPS_IFACE: return "MIPS_IFACE";
1479 case SHT_MIPS_CONTENT: return "MIPS_CONTENT";
1480 case SHT_MIPS_OPTIONS: return "MIPS_OPTIONS";
1481 case SHT_MIPS_SHDR: return "MIPS_SHDR";
1482 case SHT_MIPS_FDESC: return "MIPS_FDESC";
1483 case SHT_MIPS_EXTSYM: return "MIPS_EXTSYM";
1484 case SHT_MIPS_DENSE: return "MIPS_DENSE";
1485 case SHT_MIPS_PDESC: return "MIPS_PDESC";
1486 case SHT_MIPS_LOCSYM: return "MIPS_LOCSYM";
1487 case SHT_MIPS_AUXSYM: return "MIPS_AUXSYM";
1488 case SHT_MIPS_OPTSYM: return "MIPS_OPTSYM";
1489 case SHT_MIPS_LOCSTR: return "MIPS_LOCSTR";
1490 case SHT_MIPS_LINE: return "MIPS_LINE";
1491 case SHT_MIPS_RFDESC: return "MIPS_RFDESC";
1492 case SHT_MIPS_DELTASYM: return "MIPS_DELTASYM";
1493 case SHT_MIPS_DELTAINST: return "MIPS_DELTAINST";
1494 case SHT_MIPS_DELTACLASS: return "MIPS_DELTACLASS";
1495 case SHT_MIPS_DWARF: return "MIPS_DWARF";
1496 case SHT_MIPS_DELTADECL: return "MIPS_DELTADECL";
1497 case SHT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB";
1498 case SHT_MIPS_EVENTS: return "MIPS_EVENTS";
1499 case SHT_MIPS_TRANSLATE: return "MIPS_TRANSLATE";
1500 case SHT_MIPS_PIXIE: return "MIPS_PIXIE";
1501 case SHT_MIPS_XLATE: return "MIPS_XLATE";
1502 case SHT_MIPS_XLATE_DEBUG: return "MIPS_XLATE_DEBUG";
1503 case SHT_MIPS_WHIRL: return "MIPS_WHIRL";
1504 case SHT_MIPS_EH_REGION: return "MIPS_EH_REGION";
1505 case SHT_MIPS_XLATE_OLD: return "MIPS_XLATE_OLD";
1506 case SHT_MIPS_PDR_EXCEPTION: return "MIPS_PDR_EXCEPTION";
1514 get_parisc_section_type_name (sh_type)
1515 unsigned int sh_type;
1519 case SHT_PARISC_EXT: return "PARISC_EXT";
1520 case SHT_PARISC_UNWIND: return "PARISC_UNWIND";
1521 case SHT_PARISC_DOC: return "PARISC_DOC";
1529 get_section_type_name (sh_type)
1530 unsigned int sh_type;
1532 static char buff [32];
1536 case SHT_NULL: return "NULL";
1537 case SHT_PROGBITS: return "PROGBITS";
1538 case SHT_SYMTAB: return "SYMTAB";
1539 case SHT_STRTAB: return "STRTAB";
1540 case SHT_RELA: return "RELA";
1541 case SHT_HASH: return "HASH";
1542 case SHT_DYNAMIC: return "DYNAMIC";
1543 case SHT_NOTE: return "NOTE";
1544 case SHT_NOBITS: return "NOBITS";
1545 case SHT_REL: return "REL";
1546 case SHT_SHLIB: return "SHLIB";
1547 case SHT_DYNSYM: return "DYNSYM";
1548 case SHT_GNU_verdef: return "VERDEF";
1549 case SHT_GNU_verneed: return "VERNEED";
1550 case SHT_GNU_versym: return "VERSYM";
1551 case 0x6ffffff0: return "VERSYM";
1552 case 0x6ffffffc: return "VERDEF";
1553 case 0x7ffffffd: return "AUXILIARY";
1554 case 0x7fffffff: return "FILTER";
1557 if ((sh_type >= SHT_LOPROC) && (sh_type <= SHT_HIPROC))
1559 const char * result;
1561 switch (elf_header.e_machine)
1564 case EM_MIPS_RS4_BE:
1565 result = get_mips_section_type_name (sh_type);
1568 result = get_parisc_section_type_name (sh_type);
1578 sprintf (buff, "SHT_LOPROC+%x", sh_type - SHT_LOPROC);
1580 else if ((sh_type >= SHT_LOOS) && (sh_type <= SHT_HIOS))
1581 sprintf (buff, "SHT_LOOS+%x", sh_type - SHT_LOOS);
1582 else if ((sh_type >= SHT_LOUSER) && (sh_type <= SHT_HIUSER))
1583 sprintf (buff, "SHT_LOUSER+%x", sh_type - SHT_LOUSER);
1585 sprintf (buff, _("<unknown>: %x"), sh_type);
1591 struct option options [] =
1593 {"all", no_argument, 0, 'a'},
1594 {"file-header", no_argument, 0, 'h'},
1595 {"program-headers", no_argument, 0, 'l'},
1596 {"headers", no_argument, 0, 'e'},
1597 {"histogram", no_argument, 0, 'I'},
1598 {"segments", no_argument, 0, 'l'},
1599 {"sections", no_argument, 0, 'S'},
1600 {"section-headers", no_argument, 0, 'S'},
1601 {"symbols", no_argument, 0, 's'},
1602 {"syms", no_argument, 0, 's'},
1603 {"relocs", no_argument, 0, 'r'},
1604 {"notes", no_argument, 0, 'n'},
1605 {"dynamic", no_argument, 0, 'd'},
1606 {"arch-specific", no_argument, 0, 'A'},
1607 {"version-info", no_argument, 0, 'V'},
1608 {"use-dynamic", no_argument, 0, 'D'},
1609 {"hex-dump", required_argument, 0, 'x'},
1610 {"debug-dump", optional_argument, 0, 'w'},
1611 #ifdef SUPPORT_DISASSEMBLY
1612 {"instruction-dump", required_argument, 0, 'i'},
1615 {"version", no_argument, 0, 'v'},
1616 {"help", no_argument, 0, 'H'},
1617 {0, no_argument, 0, 0}
1623 fprintf (stdout, _("Usage: readelf {options} elf-file(s)\n"));
1624 fprintf (stdout, _(" Options are:\n"));
1625 fprintf (stdout, _(" -a or --all Equivalent to: -h -l -S -s -r -d -V -A -I\n"));
1626 fprintf (stdout, _(" -h or --file-header Display the ELF file header\n"));
1627 fprintf (stdout, _(" -l or --program-headers or --segments\n"));
1628 fprintf (stdout, _(" Display the program headers\n"));
1629 fprintf (stdout, _(" -S or --section-headers or --sections\n"));
1630 fprintf (stdout, _(" Display the sections' header\n"));
1631 fprintf (stdout, _(" -e or --headers Equivalent to: -h -l -S\n"));
1632 fprintf (stdout, _(" -s or --syms or --symbols Display the symbol table\n"));
1633 fprintf (stdout, _(" -n or --notes Display the core notes (if present)\n"));
1634 fprintf (stdout, _(" -r or --relocs Display the relocations (if present)\n"));
1635 fprintf (stdout, _(" -d or --dynamic Display the dynamic segment (if present)\n"));
1636 fprintf (stdout, _(" -V or --version-info Display the version sections (if present)\n"));
1637 fprintf (stdout, _(" -A or --arch-specific Display architecture specific information (if any).\n"));
1638 fprintf (stdout, _(" -D or --use-dynamic Use the dynamic section info when displaying symbols\n"));
1639 fprintf (stdout, _(" -x <number> or --hex-dump=<number>\n"));
1640 fprintf (stdout, _(" Dump the contents of section <number>\n"));
1641 fprintf (stdout, _(" -w[liapr] or --debug-dump[=line,=info,=abbrev,=pubnames,=ranges]\n"));
1642 fprintf (stdout, _(" Display the contents of DWARF2 debug sections\n"));
1643 #ifdef SUPPORT_DISASSEMBLY
1644 fprintf (stdout, _(" -i <number> or --instruction-dump=<number>\n"));
1645 fprintf (stdout, _(" Disassemble the contents of section <number>\n"));
1647 fprintf (stdout, _(" -I or --histogram Display histogram of bucket list lengths\n"));
1648 fprintf (stdout, _(" -v or --version Display the version number of readelf\n"));
1649 fprintf (stdout, _(" -H or --help Display this information\n"));
1650 fprintf (stdout, _("Report bugs to bug-gnu-utils@gnu.org\n"));
1656 request_dump (section, type)
1657 unsigned int section;
1660 if (section >= num_dump_sects)
1662 char * new_dump_sects;
1664 new_dump_sects = (char *) calloc (section + 1, 1);
1666 if (new_dump_sects == NULL)
1667 error (_("Out of memory allocating dump request table."));
1670 /* Copy current flag settings. */
1671 memcpy (new_dump_sects, dump_sects, num_dump_sects);
1675 dump_sects = new_dump_sects;
1676 num_dump_sects = section + 1;
1681 dump_sects [section] |= type;
1687 parse_args (argc, argv)
1696 while ((c = getopt_long
1697 (argc, argv, "ersahnldSDAIw::x:i:vV", options, NULL)) != EOF)
1732 do_using_dynamic ++;
1760 section = strtoul (optarg, & cp, 0);
1761 if (! * cp && section >= 0)
1763 request_dump (section, HEX_DUMP);
1783 do_debug_abbrevs = 1;
1793 do_debug_pubnames = 1;
1798 do_debug_aranges = 1;
1802 warn (_("Unrecognised debug option '%s'\n"), optarg);
1807 #ifdef SUPPORT_DISASSEMBLY
1810 section = strtoul (optarg, & cp, 0);
1811 if (! * cp && section >= 0)
1813 request_dump (section, DISASS_DUMP);
1819 print_version (program_name);
1826 /* xgettext:c-format */
1827 error (_("Invalid option '-%c'\n"), c);
1834 if (!do_dynamic && !do_syms && !do_reloc && !do_sections
1835 && !do_segments && !do_header && !do_dump && !do_version
1836 && !do_histogram && !do_debugging && !do_arch && !do_notes)
1840 warn (_("Nothing to do.\n"));
1846 get_elf_class (elf_class)
1847 unsigned char elf_class;
1849 static char buff [32];
1853 case ELFCLASSNONE: return _("none");
1854 case ELFCLASS32: return _("ELF32");
1855 case ELFCLASS64: return _("ELF64");
1857 sprintf (buff, _("<unknown: %x>"), elf_class);
1863 get_data_encoding (encoding)
1864 unsigned char encoding;
1866 static char buff [32];
1870 case ELFDATANONE: return _("none");
1871 case ELFDATA2LSB: return _("2's complement, little endian");
1872 case ELFDATA2MSB: return _("2's complement, big endian");
1874 sprintf (buff, _("<unknown: %x>"), encoding);
1880 get_osabi_name (osabi)
1881 unsigned char osabi;
1883 static char buff [32];
1887 case ELFOSABI_SYSV: return _("UNIX - System V");
1888 case ELFOSABI_HPUX: return _("UNIX - HP-UX");
1889 case ELFOSABI_STANDALONE: return _("Standalone App");
1891 sprintf (buff, _("<unknown: %x>"), osabi);
1896 /* Decode the data held in 'elf_header'. */
1898 process_file_header ()
1900 if ( elf_header.e_ident [EI_MAG0] != ELFMAG0
1901 || elf_header.e_ident [EI_MAG1] != ELFMAG1
1902 || elf_header.e_ident [EI_MAG2] != ELFMAG2
1903 || elf_header.e_ident [EI_MAG3] != ELFMAG3)
1906 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
1914 printf (_("ELF Header:\n"));
1915 printf (_(" Magic: "));
1916 for (i = 0; i < EI_NIDENT; i ++)
1917 printf ("%2.2x ", elf_header.e_ident [i]);
1919 printf (_(" Class: %s\n"),
1920 get_elf_class (elf_header.e_ident [EI_CLASS]));
1921 printf (_(" Data: %s\n"),
1922 get_data_encoding (elf_header.e_ident [EI_DATA]));
1923 printf (_(" Version: %d %s\n"),
1924 elf_header.e_ident [EI_VERSION],
1925 (elf_header.e_ident [EI_VERSION] == EV_CURRENT
1927 : (elf_header.e_ident [EI_VERSION] != EV_NONE
1930 printf (_(" OS/ABI: %s\n"),
1931 get_osabi_name (elf_header.e_ident [EI_OSABI]));
1932 printf (_(" ABI Version: %d\n"),
1933 elf_header.e_ident [EI_ABIVERSION]);
1934 printf (_(" Type: %s\n"),
1935 get_file_type (elf_header.e_type));
1936 printf (_(" Machine: %s\n"),
1937 get_machine_name (elf_header.e_machine));
1938 printf (_(" Version: 0x%lx\n"),
1939 (unsigned long) elf_header.e_version);
1941 printf (_(" Entry point address: "));
1942 print_vma ((bfd_vma) elf_header.e_entry, PREFIX_HEX);
1943 printf (_("\n Start of program headers: "));
1944 print_vma ((bfd_vma) elf_header.e_phoff, DEC);
1945 printf (_(" (bytes into file)\n Start of section headers: "));
1946 print_vma ((bfd_vma) elf_header.e_shoff, DEC);
1947 printf (_(" (bytes into file)\n"));
1949 printf (_(" Flags: 0x%lx%s\n"),
1950 (unsigned long) elf_header.e_flags,
1951 get_machine_flags (elf_header.e_flags, elf_header.e_machine));
1952 printf (_(" Size of this header: %ld (bytes)\n"),
1953 (long) elf_header.e_ehsize);
1954 printf (_(" Size of program headers: %ld (bytes)\n"),
1955 (long) elf_header.e_phentsize);
1956 printf (_(" Number of program headers: %ld\n"),
1957 (long) elf_header.e_phnum);
1958 printf (_(" Size of section headers: %ld (bytes)\n"),
1959 (long) elf_header.e_shentsize);
1960 printf (_(" Number of section headers: %ld\n"),
1961 (long) elf_header.e_shnum);
1962 printf (_(" Section header string table index: %ld\n"),
1963 (long) elf_header.e_shstrndx);
1971 get_32bit_program_headers (file, program_headers)
1973 Elf_Internal_Phdr * program_headers;
1975 Elf32_External_Phdr * phdrs;
1976 Elf32_External_Phdr * external;
1977 Elf32_Internal_Phdr * internal;
1980 GET_DATA_ALLOC (elf_header.e_phoff,
1981 elf_header.e_phentsize * elf_header.e_phnum,
1982 phdrs, Elf32_External_Phdr *, "program headers");
1984 for (i = 0, internal = program_headers, external = phdrs;
1985 i < elf_header.e_phnum;
1986 i ++, internal ++, external ++)
1988 internal->p_type = BYTE_GET (external->p_type);
1989 internal->p_offset = BYTE_GET (external->p_offset);
1990 internal->p_vaddr = BYTE_GET (external->p_vaddr);
1991 internal->p_paddr = BYTE_GET (external->p_paddr);
1992 internal->p_filesz = BYTE_GET (external->p_filesz);
1993 internal->p_memsz = BYTE_GET (external->p_memsz);
1994 internal->p_flags = BYTE_GET (external->p_flags);
1995 internal->p_align = BYTE_GET (external->p_align);
2004 get_64bit_program_headers (file, program_headers)
2006 Elf_Internal_Phdr * program_headers;
2008 Elf64_External_Phdr * phdrs;
2009 Elf64_External_Phdr * external;
2010 Elf64_Internal_Phdr * internal;
2013 GET_DATA_ALLOC (elf_header.e_phoff,
2014 elf_header.e_phentsize * elf_header.e_phnum,
2015 phdrs, Elf64_External_Phdr *, "program headers");
2017 for (i = 0, internal = program_headers, external = phdrs;
2018 i < elf_header.e_phnum;
2019 i ++, internal ++, external ++)
2021 internal->p_type = BYTE_GET (external->p_type);
2022 internal->p_flags = BYTE_GET (external->p_flags);
2023 internal->p_offset = BYTE_GET8 (external->p_offset);
2024 internal->p_vaddr = BYTE_GET8 (external->p_vaddr);
2025 internal->p_paddr = BYTE_GET8 (external->p_paddr);
2026 internal->p_filesz = BYTE_GET8 (external->p_filesz);
2027 internal->p_memsz = BYTE_GET8 (external->p_memsz);
2028 internal->p_align = BYTE_GET8 (external->p_align);
2037 process_program_headers (file)
2040 Elf_Internal_Phdr * program_headers;
2041 Elf_Internal_Phdr * segment;
2044 if (elf_header.e_phnum == 0)
2047 printf (_("\nThere are no program headers in this file.\n"));
2051 if (do_segments && !do_header)
2053 printf (_("\nElf file type is %s\n"), get_file_type (elf_header.e_type));
2054 printf (_("Entry point "));
2055 print_vma ((bfd_vma) elf_header.e_entry, PREFIX_HEX);
2056 printf (_("\nThere are %d program headers, starting at offset "),
2057 elf_header.e_phnum);
2058 print_vma ((bfd_vma) elf_header.e_phoff, DEC);
2062 program_headers = (Elf_Internal_Phdr *) malloc
2063 (elf_header.e_phnum * sizeof (Elf_Internal_Phdr));
2065 if (program_headers == NULL)
2067 error (_("Out of memory\n"));
2072 i = get_32bit_program_headers (file, program_headers);
2074 i = get_64bit_program_headers (file, program_headers);
2078 free (program_headers);
2085 (_("\nProgram Header%s:\n"), elf_header.e_phnum > 1 ? "s" : "");
2089 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
2093 (_(" Type Offset VirtAddr PhysAddr\n"));
2095 (_(" FileSiz MemSiz Flags Align\n"));
2103 for (i = 0, segment = program_headers;
2104 i < elf_header.e_phnum;
2109 printf (" %-14.14s ", get_segment_type (segment->p_type));
2113 printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
2114 printf ("0x%8.8lx ", (unsigned long) segment->p_vaddr);
2115 printf ("0x%8.8lx ", (unsigned long) segment->p_paddr);
2116 printf ("0x%5.5lx ", (unsigned long) segment->p_filesz);
2117 printf ("0x%5.5lx ", (unsigned long) segment->p_memsz);
2119 (segment->p_flags & PF_R ? 'R' : ' '),
2120 (segment->p_flags & PF_W ? 'W' : ' '),
2121 (segment->p_flags & PF_X ? 'E' : ' '));
2122 printf ("%#lx", (unsigned long) segment->p_align);
2126 print_vma (segment->p_offset, FULL_HEX);
2128 print_vma (segment->p_vaddr, FULL_HEX);
2130 print_vma (segment->p_paddr, FULL_HEX);
2132 print_vma (segment->p_filesz, FULL_HEX);
2134 print_vma (segment->p_memsz, FULL_HEX);
2136 (segment->p_flags & PF_R ? 'R' : ' '),
2137 (segment->p_flags & PF_W ? 'W' : ' '),
2138 (segment->p_flags & PF_X ? 'E' : ' '));
2139 print_vma (segment->p_align, HEX);
2143 switch (segment->p_type)
2147 loadaddr = (segment->p_vaddr & 0xfffff000)
2148 - (segment->p_offset & 0xfffff000);
2153 error (_("more than one dynamic segment\n"));
2155 dynamic_addr = segment->p_offset;
2156 dynamic_size = segment->p_filesz;
2160 if (fseek (file, (long) segment->p_offset, SEEK_SET))
2161 error (_("Unable to find program interpreter name\n"));
2164 program_interpreter[0] = 0;
2165 fscanf (file, "%63s", program_interpreter);
2168 printf (_("\n [Requesting program interpreter: %s]"),
2169 program_interpreter);
2175 putc ('\n', stdout);
2184 if (do_segments && section_headers != NULL)
2186 printf (_("\n Section to Segment mapping:\n"));
2187 printf (_(" Segment Sections...\n"));
2189 assert (string_table != NULL);
2191 for (i = 0; i < elf_header.e_phnum; i++)
2194 Elf_Internal_Shdr * section;
2196 segment = program_headers + i;
2197 section = section_headers;
2199 printf (" %2.2d ", i);
2201 for (j = 0; j < elf_header.e_shnum; j++, section ++)
2203 if (section->sh_size > 0
2204 /* Compare allocated sections by VMA, unallocated
2205 sections by file offset. */
2206 && (section->sh_flags & SHF_ALLOC
2207 ? (section->sh_addr >= segment->p_vaddr
2208 && section->sh_addr + section->sh_size
2209 <= segment->p_vaddr + segment->p_memsz)
2210 : ((bfd_vma) section->sh_offset >= segment->p_offset
2211 && (section->sh_offset + section->sh_size
2212 <= segment->p_offset + segment->p_filesz))))
2213 printf ("%s ", SECTION_NAME (section));
2220 free (program_headers);
2227 get_32bit_section_headers (file)
2230 Elf32_External_Shdr * shdrs;
2231 Elf32_Internal_Shdr * internal;
2234 GET_DATA_ALLOC (elf_header.e_shoff,
2235 elf_header.e_shentsize * elf_header.e_shnum,
2236 shdrs, Elf32_External_Shdr *, "section headers");
2238 section_headers = (Elf_Internal_Shdr *) malloc
2239 (elf_header.e_shnum * sizeof (Elf_Internal_Shdr));
2241 if (section_headers == NULL)
2243 error (_("Out of memory\n"));
2247 for (i = 0, internal = section_headers;
2248 i < elf_header.e_shnum;
2251 internal->sh_name = BYTE_GET (shdrs[i].sh_name);
2252 internal->sh_type = BYTE_GET (shdrs[i].sh_type);
2253 internal->sh_flags = BYTE_GET (shdrs[i].sh_flags);
2254 internal->sh_addr = BYTE_GET (shdrs[i].sh_addr);
2255 internal->sh_offset = BYTE_GET (shdrs[i].sh_offset);
2256 internal->sh_size = BYTE_GET (shdrs[i].sh_size);
2257 internal->sh_link = BYTE_GET (shdrs[i].sh_link);
2258 internal->sh_info = BYTE_GET (shdrs[i].sh_info);
2259 internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
2260 internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize);
2269 get_64bit_section_headers (file)
2272 Elf64_External_Shdr * shdrs;
2273 Elf64_Internal_Shdr * internal;
2276 GET_DATA_ALLOC (elf_header.e_shoff,
2277 elf_header.e_shentsize * elf_header.e_shnum,
2278 shdrs, Elf64_External_Shdr *, "section headers");
2280 section_headers = (Elf_Internal_Shdr *) malloc
2281 (elf_header.e_shnum * sizeof (Elf_Internal_Shdr));
2283 if (section_headers == NULL)
2285 error (_("Out of memory\n"));
2289 for (i = 0, internal = section_headers;
2290 i < elf_header.e_shnum;
2293 internal->sh_name = BYTE_GET (shdrs[i].sh_name);
2294 internal->sh_type = BYTE_GET (shdrs[i].sh_type);
2295 internal->sh_flags = BYTE_GET8 (shdrs[i].sh_flags);
2296 internal->sh_addr = BYTE_GET8 (shdrs[i].sh_addr);
2297 internal->sh_size = BYTE_GET8 (shdrs[i].sh_size);
2298 internal->sh_entsize = BYTE_GET8 (shdrs[i].sh_entsize);
2299 internal->sh_link = BYTE_GET (shdrs[i].sh_link);
2300 internal->sh_info = BYTE_GET (shdrs[i].sh_info);
2301 internal->sh_offset = BYTE_GET (shdrs[i].sh_offset);
2302 internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
2310 static Elf_Internal_Sym *
2311 get_32bit_elf_symbols (file, offset, number)
2313 unsigned long offset;
2314 unsigned long number;
2316 Elf32_External_Sym * esyms;
2317 Elf_Internal_Sym * isyms;
2318 Elf_Internal_Sym * psym;
2321 GET_DATA_ALLOC (offset, number * sizeof (Elf32_External_Sym),
2322 esyms, Elf32_External_Sym *, "symbols");
2324 isyms = (Elf_Internal_Sym *) malloc (number * sizeof (Elf_Internal_Sym));
2328 error (_("Out of memory\n"));
2334 for (j = 0, psym = isyms;
2338 psym->st_name = BYTE_GET (esyms[j].st_name);
2339 psym->st_value = BYTE_GET (esyms[j].st_value);
2340 psym->st_size = BYTE_GET (esyms[j].st_size);
2341 psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
2342 psym->st_info = BYTE_GET (esyms[j].st_info);
2343 psym->st_other = BYTE_GET (esyms[j].st_other);
2351 static Elf_Internal_Sym *
2352 get_64bit_elf_symbols (file, offset, number)
2354 unsigned long offset;
2355 unsigned long number;
2357 Elf64_External_Sym * esyms;
2358 Elf_Internal_Sym * isyms;
2359 Elf_Internal_Sym * psym;
2362 GET_DATA_ALLOC (offset, number * sizeof (Elf64_External_Sym),
2363 esyms, Elf64_External_Sym *, "symbols");
2365 isyms = (Elf_Internal_Sym *) malloc (number * sizeof (Elf_Internal_Sym));
2369 error (_("Out of memory\n"));
2375 for (j = 0, psym = isyms;
2379 psym->st_name = BYTE_GET (esyms[j].st_name);
2380 psym->st_info = BYTE_GET (esyms[j].st_info);
2381 psym->st_other = BYTE_GET (esyms[j].st_other);
2382 psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
2383 psym->st_value = BYTE_GET8 (esyms[j].st_value);
2384 psym->st_size = BYTE_GET8 (esyms[j].st_size);
2393 process_section_headers (file)
2396 Elf_Internal_Shdr * section;
2399 section_headers = NULL;
2401 if (elf_header.e_shnum == 0)
2404 printf (_("\nThere are no sections in this file.\n"));
2409 if (do_sections && !do_header)
2410 printf (_("There are %d section headers, starting at offset 0x%lx:\n"),
2411 elf_header.e_shnum, (unsigned long) elf_header.e_shoff);
2415 if (! get_32bit_section_headers (file))
2418 else if (! get_64bit_section_headers (file))
2421 /* Read in the string table, so that we have names to display. */
2422 section = section_headers + elf_header.e_shstrndx;
2424 if (section->sh_size != 0)
2426 unsigned long string_table_offset;
2428 string_table_offset = section->sh_offset;
2430 GET_DATA_ALLOC (section->sh_offset, section->sh_size,
2431 string_table, char *, "string table");
2434 /* Scan the sections for the dynamic symbol table
2435 and dynamic string table and debug sections. */
2436 dynamic_symbols = NULL;
2437 dynamic_strings = NULL;
2438 dynamic_syminfo = NULL;
2440 for (i = 0, section = section_headers;
2441 i < elf_header.e_shnum;
2444 char * name = SECTION_NAME (section);
2446 if (section->sh_type == SHT_DYNSYM)
2448 if (dynamic_symbols != NULL)
2450 error (_("File contains multiple dynamic symbol tables\n"));
2454 num_dynamic_syms = section->sh_size / section->sh_entsize;
2456 GET_ELF_SYMBOLS (file, section->sh_offset, num_dynamic_syms);
2458 else if (section->sh_type == SHT_STRTAB
2459 && strcmp (name, ".dynstr") == 0)
2461 if (dynamic_strings != NULL)
2463 error (_("File contains multiple dynamic string tables\n"));
2467 GET_DATA_ALLOC (section->sh_offset, section->sh_size,
2468 dynamic_strings, char *, "dynamic strings");
2470 else if ((do_debugging || do_debug_info || do_debug_abbrevs
2471 || do_debug_lines || do_debug_pubnames || do_debug_aranges)
2472 && strncmp (name, ".debug_", 7) == 0)
2477 || (do_debug_info && (strcmp (name, "info") == 0))
2478 || (do_debug_abbrevs && (strcmp (name, "abbrev") == 0))
2479 || (do_debug_lines && (strcmp (name, "line") == 0))
2480 || (do_debug_pubnames && (strcmp (name, "pubnames") == 0))
2481 || (do_debug_aranges && (strcmp (name, "aranges") == 0))
2483 request_dump (i, DEBUG_DUMP);
2490 printf (_("\nSection Header%s:\n"), elf_header.e_shnum > 1 ? "s" : "");
2493 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
2496 printf (_(" [Nr] Name Type Address Offset\n"));
2497 printf (_(" Size EntSize Flags Link Info Align\n"));
2500 for (i = 0, section = section_headers;
2501 i < elf_header.e_shnum;
2504 printf (" [%2d] %-17.17s %-15.15s ",
2506 SECTION_NAME (section),
2507 get_section_type_name (section->sh_type));
2511 print_vma (section->sh_addr, LONG_HEX);
2513 printf ( " %6.6lx %6.6lx %2.2lx",
2514 (unsigned long) section->sh_offset,
2515 (unsigned long) section->sh_size,
2516 (unsigned long) section->sh_entsize);
2518 printf (" %c%c%c %2ld %3lx %ld\n",
2519 (section->sh_flags & SHF_WRITE ? 'W' : ' '),
2520 (section->sh_flags & SHF_ALLOC ? 'A' : ' '),
2521 (section->sh_flags & SHF_EXECINSTR ? 'X' : ' '),
2522 (unsigned long) section->sh_link,
2523 (unsigned long) section->sh_info,
2524 (unsigned long) section->sh_addralign);
2529 print_vma (section->sh_addr, LONG_HEX);
2530 printf (" %8.8lx", section->sh_offset);
2532 print_vma (section->sh_size, LONG_HEX);
2534 print_vma (section->sh_entsize, LONG_HEX);
2537 (section->sh_flags & SHF_WRITE ? 'W' : ' '),
2538 (section->sh_flags & SHF_ALLOC ? 'A' : ' '),
2539 (section->sh_flags & SHF_EXECINSTR ? 'X' : ' '));
2541 printf (" %2ld %3lx %ld\n",
2542 (unsigned long) section->sh_link,
2543 (unsigned long) section->sh_info,
2544 (unsigned long) section->sh_addralign);
2551 /* Process the reloc section. */
2553 process_relocs (file)
2556 unsigned long rel_size;
2557 unsigned long rel_offset;
2563 if (do_using_dynamic)
2565 int is_rela = FALSE;
2570 if (dynamic_info[DT_REL])
2572 rel_offset = dynamic_info[DT_REL];
2573 rel_size = dynamic_info[DT_RELSZ];
2576 else if (dynamic_info [DT_RELA])
2578 rel_offset = dynamic_info[DT_RELA];
2579 rel_size = dynamic_info[DT_RELASZ];
2582 else if (dynamic_info[DT_JMPREL])
2584 rel_offset = dynamic_info[DT_JMPREL];
2585 rel_size = dynamic_info[DT_PLTRELSZ];
2587 switch (dynamic_info[DT_PLTREL])
2604 (_("\nRelocation section at offset 0x%lx contains %ld bytes:\n"),
2605 rel_offset, rel_size);
2607 dump_relocations (file, rel_offset - loadaddr, rel_size,
2608 dynamic_symbols, num_dynamic_syms, dynamic_strings, is_rela);
2611 printf (_("\nThere are no dynamic relocations in this file.\n"));
2615 Elf32_Internal_Shdr * section;
2619 for (i = 0, section = section_headers;
2620 i < elf_header.e_shnum;
2623 if ( section->sh_type != SHT_RELA
2624 && section->sh_type != SHT_REL)
2627 rel_offset = section->sh_offset;
2628 rel_size = section->sh_size;
2632 Elf32_Internal_Shdr * strsec;
2633 Elf32_Internal_Shdr * symsec;
2634 Elf_Internal_Sym * symtab;
2637 unsigned long nsyms;
2639 printf (_("\nRelocation section "));
2641 if (string_table == NULL)
2642 printf ("%d", section->sh_name);
2644 printf ("'%s'", SECTION_NAME (section));
2646 printf (_(" at offset 0x%lx contains %lu entries:\n"),
2647 rel_offset, (unsigned long) (rel_size / section->sh_entsize));
2649 symsec = section_headers + section->sh_link;
2651 nsyms = symsec->sh_size / symsec->sh_entsize;
2652 symtab = GET_ELF_SYMBOLS (file, symsec->sh_offset, nsyms);
2657 strsec = section_headers + symsec->sh_link;
2659 GET_DATA_ALLOC (strsec->sh_offset, strsec->sh_size, strtab,
2660 char *, "string table");
2662 is_rela = section->sh_type == SHT_RELA;
2664 dump_relocations (file, rel_offset, rel_size, symtab, nsyms, strtab, is_rela);
2674 printf (_("\nThere are no relocations in this file.\n"));
2682 dynamic_segment_mips_val (entry)
2683 Elf_Internal_Dyn * entry;
2685 switch (entry->d_tag)
2688 if (entry->d_un.d_val == 0)
2692 static const char * opts[] =
2694 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
2695 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
2696 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
2697 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
2702 for (cnt = 0; cnt < NUM_ELEM (opts); ++ cnt)
2703 if (entry->d_un.d_val & (1 << cnt))
2705 printf ("%s%s", first ? "" : " ", opts[cnt]);
2712 case DT_MIPS_IVERSION:
2713 if (dynamic_strings != NULL)
2714 printf ("Interface Version: %s\n",
2715 dynamic_strings + entry->d_un.d_val);
2717 printf ("%ld\n", (long) entry->d_un.d_ptr);
2720 case DT_MIPS_TIME_STAMP:
2723 time_t time = entry->d_un.d_val;
2724 strftime (timebuf, 20, "%Y-%m-%dT%H:%M:%S", gmtime (&time));
2725 printf ("Time Stamp: %s\n", timebuf);
2729 case DT_MIPS_RLD_VERSION:
2730 case DT_MIPS_LOCAL_GOTNO:
2731 case DT_MIPS_CONFLICTNO:
2732 case DT_MIPS_LIBLISTNO:
2733 case DT_MIPS_SYMTABNO:
2734 case DT_MIPS_UNREFEXTNO:
2735 case DT_MIPS_HIPAGENO:
2736 case DT_MIPS_DELTA_CLASS_NO:
2737 case DT_MIPS_DELTA_INSTANCE_NO:
2738 case DT_MIPS_DELTA_RELOC_NO:
2739 case DT_MIPS_DELTA_SYM_NO:
2740 case DT_MIPS_DELTA_CLASSSYM_NO:
2741 case DT_MIPS_COMPACT_SIZE:
2742 printf ("%ld\n", (long) entry->d_un.d_ptr);
2746 printf ("%#lx\n", (long) entry->d_un.d_ptr);
2752 dynamic_segment_parisc_val (entry)
2753 Elf_Internal_Dyn * entry;
2755 switch (entry->d_tag)
2757 case DT_HP_DLD_FLAGS:
2766 { DT_HP_DEBUG_PRIVATE, "HP_DEBUG_PRIVATE" },
2767 { DT_HP_DEBUG_CALLBACK, "HP_DEBUG_CALLBACK" },
2768 { DT_HP_DEBUG_CALLBACK_BOR, "HP_DEBUG_CALLBACK_BOR" },
2769 { DT_HP_NO_ENVVAR, "HP_NO_ENVVAR" },
2770 { DT_HP_BIND_NOW, "HP_BIND_NOW" },
2771 { DT_HP_BIND_NONFATAL, "HP_BIND_NONFATAL" },
2772 { DT_HP_BIND_VERBOSE, "HP_BIND_VERBOSE" },
2773 { DT_HP_BIND_RESTRICTED, "HP_BIND_RESTRICTED" },
2774 { DT_HP_BIND_SYMBOLIC, "HP_BIND_SYMBOLIC" },
2775 { DT_HP_RPATH_FIRST, "HP_RPATH_FIRST" },
2776 { DT_HP_BIND_DEPTH_FIRST, "HP_BIND_DEPTH_FIRST" }
2780 bfd_vma val = entry->d_un.d_val;
2782 for (cnt = 0; cnt < sizeof (flags) / sizeof (flags[0]); ++cnt)
2783 if (val & flags[cnt].bit)
2787 fputs (flags[cnt].str, stdout);
2789 val ^= flags[cnt].bit;
2792 if (val != 0 || first)
2796 print_vma (val, HEX);
2802 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
2808 get_32bit_dynamic_segment (file)
2811 Elf32_External_Dyn * edyn;
2812 Elf_Internal_Dyn * entry;
2815 GET_DATA_ALLOC (dynamic_addr, dynamic_size,
2816 edyn, Elf32_External_Dyn *, "dynamic segment");
2818 /* SGI's ELF has more than one section in the DYNAMIC segment. Determine
2819 how large this .dynamic is now. We can do this even before the byte
2820 swapping since the DT_NULL tag is recognizable. */
2822 while (*(Elf32_Word *) edyn [dynamic_size++].d_tag != DT_NULL)
2825 dynamic_segment = (Elf_Internal_Dyn *)
2826 malloc (dynamic_size * sizeof (Elf_Internal_Dyn));
2828 if (dynamic_segment == NULL)
2830 error (_("Out of memory\n"));
2835 for (i = 0, entry = dynamic_segment;
2839 entry->d_tag = BYTE_GET (edyn [i].d_tag);
2840 entry->d_un.d_val = BYTE_GET (edyn [i].d_un.d_val);
2849 get_64bit_dynamic_segment (file)
2852 Elf64_External_Dyn * edyn;
2853 Elf_Internal_Dyn * entry;
2856 GET_DATA_ALLOC (dynamic_addr, dynamic_size,
2857 edyn, Elf64_External_Dyn *, "dynamic segment");
2859 /* SGI's ELF has more than one section in the DYNAMIC segment. Determine
2860 how large this .dynamic is now. We can do this even before the byte
2861 swapping since the DT_NULL tag is recognizable. */
2863 while (*(bfd_vma *) edyn [dynamic_size ++].d_tag != DT_NULL)
2866 dynamic_segment = (Elf_Internal_Dyn *)
2867 malloc (dynamic_size * sizeof (Elf_Internal_Dyn));
2869 if (dynamic_segment == NULL)
2871 error (_("Out of memory\n"));
2876 for (i = 0, entry = dynamic_segment;
2880 entry->d_tag = BYTE_GET8 (edyn [i].d_tag);
2881 entry->d_un.d_val = BYTE_GET8 (edyn [i].d_un.d_val);
2889 /* Parse and display the contents of the dynamic segment. */
2891 process_dynamic_segment (file)
2894 Elf_Internal_Dyn * entry;
2897 if (dynamic_size == 0)
2900 printf (_("\nThere is no dynamic segment in this file.\n"));
2907 if (! get_32bit_dynamic_segment (file))
2910 else if (! get_64bit_dynamic_segment (file))
2913 /* Find the appropriate symbol table. */
2914 if (dynamic_symbols == NULL)
2916 for (i = 0, entry = dynamic_segment;
2920 unsigned long offset;
2922 if (entry->d_tag != DT_SYMTAB)
2925 dynamic_info[DT_SYMTAB] = entry->d_un.d_val;
2927 /* Since we do not know how big the symbol table is,
2928 we default to reading in the entire file (!) and
2929 processing that. This is overkill, I know, but it
2931 offset = entry->d_un.d_val - loadaddr;
2933 if (fseek (file, 0, SEEK_END))
2934 error (_("Unable to seek to end of file!"));
2937 num_dynamic_syms = (ftell (file) - offset) / sizeof (Elf32_External_Sym);
2939 num_dynamic_syms = (ftell (file) - offset) / sizeof (Elf64_External_Sym);
2941 if (num_dynamic_syms < 1)
2943 error (_("Unable to determine the number of symbols to load\n"));
2947 dynamic_symbols = GET_ELF_SYMBOLS (file, offset, num_dynamic_syms);
2951 /* Similarly find a string table. */
2952 if (dynamic_strings == NULL)
2954 for (i = 0, entry = dynamic_segment;
2958 unsigned long offset;
2961 if (entry->d_tag != DT_STRTAB)
2964 dynamic_info[DT_STRTAB] = entry->d_un.d_val;
2966 /* Since we do not know how big the string table is,
2967 we default to reading in the entire file (!) and
2968 processing that. This is overkill, I know, but it
2971 offset = entry->d_un.d_val - loadaddr;
2972 if (fseek (file, 0, SEEK_END))
2973 error (_("Unable to seek to end of file\n"));
2974 str_tab_len = ftell (file) - offset;
2976 if (str_tab_len < 1)
2979 (_("Unable to determine the length of the dynamic string table\n"));
2983 GET_DATA_ALLOC (offset, str_tab_len, dynamic_strings, char *,
2984 "dynamic string table");
2990 /* And find the syminfo section if available. */
2991 if (dynamic_syminfo == NULL)
2993 unsigned int syminsz = 0;
2995 for (i = 0, entry = dynamic_segment;
2999 if (entry->d_tag == DT_SYMINENT)
3001 /* Note: these braces are necessary to avoid a syntax
3002 error from the SunOS4 C compiler. */
3003 assert (sizeof (Elf_External_Syminfo) == entry->d_un.d_val);
3005 else if (entry->d_tag == DT_SYMINSZ)
3006 syminsz = entry->d_un.d_val;
3007 else if (entry->d_tag == DT_SYMINFO)
3008 dynamic_syminfo_offset = entry->d_un.d_val - loadaddr;
3011 if (dynamic_syminfo_offset != 0 && syminsz != 0)
3013 Elf_External_Syminfo * extsyminfo;
3014 Elf_Internal_Syminfo * syminfo;
3016 /* There is a syminfo section. Read the data. */
3017 GET_DATA_ALLOC (dynamic_syminfo_offset, syminsz, extsyminfo,
3018 Elf_External_Syminfo *, "symbol information");
3020 dynamic_syminfo = (Elf_Internal_Syminfo *) malloc (syminsz);
3021 if (dynamic_syminfo == NULL)
3023 error (_("Out of memory\n"));
3027 dynamic_syminfo_nent = syminsz / sizeof (Elf_External_Syminfo);
3028 for (i = 0, syminfo = dynamic_syminfo; i < dynamic_syminfo_nent;
3031 syminfo->si_boundto = BYTE_GET (extsyminfo[i].si_boundto);
3032 syminfo->si_flags = BYTE_GET (extsyminfo[i].si_flags);
3039 if (do_dynamic && dynamic_addr)
3040 printf (_("\nDynamic segment at offset 0x%x contains %ld entries:\n"),
3041 dynamic_addr, (long) dynamic_size);
3043 printf (_(" Tag Type Name/Value\n"));
3045 for (i = 0, entry = dynamic_segment;
3052 print_vma (entry->d_tag, FULL_HEX);
3054 get_dynamic_type (entry->d_tag),
3055 (is_32bit_elf ? 27 : 19) - strlen (get_dynamic_type (entry->d_tag)),
3059 switch (entry->d_tag)
3065 if (entry->d_tag == DT_AUXILIARY)
3066 printf (_("Auxiliary library"));
3068 printf (_("Filter library"));
3070 if (dynamic_strings)
3071 printf (": [%s]\n", dynamic_strings + entry->d_un.d_val);
3075 print_vma (entry->d_un.d_val, PREFIX_HEX);
3084 printf (_("Flags:"));
3085 if (entry->d_un.d_val == 0)
3086 printf (_(" None\n"));
3089 unsigned long int val = entry->d_un.d_val;
3090 if (val & DTF_1_PARINIT)
3092 printf (" PARINIT");
3093 val ^= DTF_1_PARINIT;
3096 printf (" %lx", val);
3105 printf (_("Flags:"));
3106 if (entry->d_un.d_val == 0)
3107 printf (_(" None\n"));
3110 unsigned long int val = entry->d_un.d_val;
3111 if (val & DF_P1_LAZYLOAD)
3113 printf (" LAZYLOAD");
3114 val ^= DF_P1_LAZYLOAD;
3116 if (val & DF_P1_GROUPPERM)
3118 printf (" GROUPPERM");
3119 val ^= DF_P1_GROUPPERM;
3122 printf (" %lx", val);
3131 printf (_("Flags:"));
3132 if (entry->d_un.d_val == 0)
3133 printf (_(" None\n"));
3136 unsigned long int val = entry->d_un.d_val;
3142 if (val & DF_1_GLOBAL)
3147 if (val & DF_1_GROUP)
3152 if (val & DF_1_NODELETE)
3154 printf (" NODELETE");
3155 val ^= DF_1_NODELETE;
3157 if (val & DF_1_LOADFLTR)
3159 printf (" LOADFLTR");
3160 val ^= DF_1_LOADFLTR;
3162 if (val & DF_1_INITFIRST)
3164 printf (" INITFIRST");
3165 val ^= DF_1_INITFIRST;
3167 if (val & DF_1_NOOPEN)
3172 if (val & DF_1_ORIGIN)
3177 if (val & DF_1_DIRECT)
3182 if (val & DF_1_TRANS)
3187 if (val & DF_1_INTERPOSE)
3189 printf (" INTERPOSE");
3190 val ^= DF_1_INTERPOSE;
3193 printf (" %lx", val);
3201 puts (get_dynamic_type (entry->d_un.d_val));
3220 dynamic_info[entry->d_tag] = entry->d_un.d_val;
3226 if (dynamic_strings == NULL)
3229 name = dynamic_strings + entry->d_un.d_val;
3233 switch (entry->d_tag)
3236 printf (_("Shared library: [%s]"), name);
3238 if (strcmp (name, program_interpreter) == 0)
3239 printf (_(" program interpreter"));
3243 printf (_("Library soname: [%s]"), name);
3247 printf (_("Library rpath: [%s]"), name);
3251 print_vma (entry->d_un.d_val, PREFIX_HEX);
3256 print_vma (entry->d_un.d_val, PREFIX_HEX);
3272 case DT_INIT_ARRAYSZ:
3273 case DT_FINI_ARRAYSZ:
3276 print_vma (entry->d_un.d_val, UNSIGNED);
3277 printf (" (bytes)\n");
3287 print_vma (entry->d_un.d_val, UNSIGNED);
3300 if (dynamic_strings != NULL && entry->d_tag == DT_USED)
3304 name = dynamic_strings + entry->d_un.d_val;
3308 printf (_("Not needed object: [%s]\n"), name);
3313 print_vma (entry->d_un.d_val, PREFIX_HEX);
3319 /* The value of this entry is ignored. */
3323 if ((entry->d_tag >= DT_VERSYM) && (entry->d_tag <= DT_VERNEEDNUM))
3324 version_info [DT_VERSIONTAGIDX (entry->d_tag)] =
3329 switch (elf_header.e_machine)
3332 case EM_MIPS_RS4_BE:
3333 dynamic_segment_mips_val (entry);
3336 dynamic_segment_parisc_val (entry);
3339 print_vma (entry->d_un.d_val, PREFIX_HEX);
3351 get_ver_flags (flags)
3354 static char buff [32];
3361 if (flags & VER_FLG_BASE)
3362 strcat (buff, "BASE ");
3364 if (flags & VER_FLG_WEAK)
3366 if (flags & VER_FLG_BASE)
3367 strcat (buff, "| ");
3369 strcat (buff, "WEAK ");
3372 if (flags & ~(VER_FLG_BASE | VER_FLG_WEAK))
3373 strcat (buff, "| <unknown>");
3378 /* Display the contents of the version sections. */
3380 process_version_sections (file)
3383 Elf32_Internal_Shdr * section;
3390 for (i = 0, section = section_headers;
3391 i < elf_header.e_shnum;
3394 switch (section->sh_type)
3396 case SHT_GNU_verdef:
3398 Elf_External_Verdef * edefs;
3405 (_("\nVersion definition section '%s' contains %ld entries:\n"),
3406 SECTION_NAME (section), section->sh_info);
3408 printf (_(" Addr: 0x"));
3409 printf_vma (section->sh_addr);
3410 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
3411 (unsigned long) section->sh_offset, section->sh_link,
3412 SECTION_NAME (section_headers + section->sh_link));
3414 GET_DATA_ALLOC (section->sh_offset, section->sh_size,
3415 edefs, Elf_External_Verdef *,
3416 "version definition section");
3418 for (idx = cnt = 0; cnt < section->sh_info; ++ cnt)
3421 Elf_External_Verdef * edef;
3422 Elf_Internal_Verdef ent;
3423 Elf_External_Verdaux * eaux;
3424 Elf_Internal_Verdaux aux;
3428 vstart = ((char *) edefs) + idx;
3430 edef = (Elf_External_Verdef *) vstart;
3432 ent.vd_version = BYTE_GET (edef->vd_version);
3433 ent.vd_flags = BYTE_GET (edef->vd_flags);
3434 ent.vd_ndx = BYTE_GET (edef->vd_ndx);
3435 ent.vd_cnt = BYTE_GET (edef->vd_cnt);
3436 ent.vd_hash = BYTE_GET (edef->vd_hash);
3437 ent.vd_aux = BYTE_GET (edef->vd_aux);
3438 ent.vd_next = BYTE_GET (edef->vd_next);
3440 printf (_(" %#06x: Rev: %d Flags: %s"),
3441 idx, ent.vd_version, get_ver_flags (ent.vd_flags));
3443 printf (_(" Index: %d Cnt: %d "),
3444 ent.vd_ndx, ent.vd_cnt);
3446 vstart += ent.vd_aux;
3448 eaux = (Elf_External_Verdaux *) vstart;
3450 aux.vda_name = BYTE_GET (eaux->vda_name);
3451 aux.vda_next = BYTE_GET (eaux->vda_next);
3453 if (dynamic_strings)
3454 printf (_("Name: %s\n"), dynamic_strings + aux.vda_name);
3456 printf (_("Name index: %ld\n"), aux.vda_name);
3458 isum = idx + ent.vd_aux;
3460 for (j = 1; j < ent.vd_cnt; j ++)
3462 isum += aux.vda_next;
3463 vstart += aux.vda_next;
3465 eaux = (Elf_External_Verdaux *) vstart;
3467 aux.vda_name = BYTE_GET (eaux->vda_name);
3468 aux.vda_next = BYTE_GET (eaux->vda_next);
3470 if (dynamic_strings)
3471 printf (_(" %#06x: Parent %d: %s\n"),
3472 isum, j, dynamic_strings + aux.vda_name);
3474 printf (_(" %#06x: Parent %d, name index: %ld\n"),
3475 isum, j, aux.vda_name);
3485 case SHT_GNU_verneed:
3487 Elf_External_Verneed * eneed;
3493 printf (_("\nVersion needs section '%s' contains %ld entries:\n"),
3494 SECTION_NAME (section), section->sh_info);
3496 printf (_(" Addr: 0x"));
3497 printf_vma (section->sh_addr);
3498 printf (_(" Offset: %#08lx Link to section: %ld (%s)\n"),
3499 (unsigned long) section->sh_offset, section->sh_link,
3500 SECTION_NAME (section_headers + section->sh_link));
3502 GET_DATA_ALLOC (section->sh_offset, section->sh_size,
3503 eneed, Elf_External_Verneed *,
3504 "version need section");
3506 for (idx = cnt = 0; cnt < section->sh_info; ++cnt)
3508 Elf_External_Verneed * entry;
3509 Elf_Internal_Verneed ent;
3514 vstart = ((char *) eneed) + idx;
3516 entry = (Elf_External_Verneed *) vstart;
3518 ent.vn_version = BYTE_GET (entry->vn_version);
3519 ent.vn_cnt = BYTE_GET (entry->vn_cnt);
3520 ent.vn_file = BYTE_GET (entry->vn_file);
3521 ent.vn_aux = BYTE_GET (entry->vn_aux);
3522 ent.vn_next = BYTE_GET (entry->vn_next);
3524 printf (_(" %#06x: Version: %d"), idx, ent.vn_version);
3526 if (dynamic_strings)
3527 printf (_(" File: %s"), dynamic_strings + ent.vn_file);
3529 printf (_(" File: %lx"), ent.vn_file);
3531 printf (_(" Cnt: %d\n"), ent.vn_cnt);
3533 vstart += ent.vn_aux;
3535 for (j = 0, isum = idx + ent.vn_aux; j < ent.vn_cnt; ++j)
3537 Elf_External_Vernaux * eaux;
3538 Elf_Internal_Vernaux aux;
3540 eaux = (Elf_External_Vernaux *) vstart;
3542 aux.vna_hash = BYTE_GET (eaux->vna_hash);
3543 aux.vna_flags = BYTE_GET (eaux->vna_flags);
3544 aux.vna_other = BYTE_GET (eaux->vna_other);
3545 aux.vna_name = BYTE_GET (eaux->vna_name);
3546 aux.vna_next = BYTE_GET (eaux->vna_next);
3548 if (dynamic_strings)
3549 printf (_(" %#06x: Name: %s"),
3550 isum, dynamic_strings + aux.vna_name);
3552 printf (_(" %#06x: Name index: %lx"),
3553 isum, aux.vna_name);
3555 printf (_(" Flags: %s Version: %d\n"),
3556 get_ver_flags (aux.vna_flags), aux.vna_other);
3558 isum += aux.vna_next;
3559 vstart += aux.vna_next;
3569 case SHT_GNU_versym:
3571 Elf32_Internal_Shdr * link_section;
3574 unsigned char * edata;
3575 unsigned short * data;
3577 Elf_Internal_Sym * symbols;
3578 Elf32_Internal_Shdr * string_sec;
3580 link_section = section_headers + section->sh_link;
3581 total = section->sh_size / section->sh_entsize;
3585 symbols = GET_ELF_SYMBOLS (file, link_section->sh_offset,
3586 link_section->sh_size / link_section->sh_entsize);
3588 string_sec = section_headers + link_section->sh_link;
3590 GET_DATA_ALLOC (string_sec->sh_offset, string_sec->sh_size,
3591 strtab, char *, "version string table");
3593 printf (_("\nVersion symbols section '%s' contains %d entries:\n"),
3594 SECTION_NAME (section), total);
3596 printf (_(" Addr: "));
3597 printf_vma (section->sh_addr);
3598 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
3599 (unsigned long) section->sh_offset, section->sh_link,
3600 SECTION_NAME (link_section));
3602 GET_DATA_ALLOC (version_info [DT_VERSIONTAGIDX (DT_VERSYM)]
3604 total * sizeof (short), edata,
3605 unsigned char *, "version symbol data");
3607 data = (unsigned short *) malloc (total * sizeof (short));
3609 for (cnt = total; cnt --;)
3610 data [cnt] = byte_get (edata + cnt * sizeof (short),
3615 for (cnt = 0; cnt < total; cnt += 4)
3619 printf (" %03x:", cnt);
3621 for (j = 0; (j < 4) && (cnt + j) < total; ++j)
3622 switch (data [cnt + j])
3625 fputs (_(" 0 (*local*) "), stdout);
3629 fputs (_(" 1 (*global*) "), stdout);
3633 nn = printf ("%4x%c", data [cnt + j] & 0x7fff,
3634 data [cnt + j] & 0x8000 ? 'h' : ' ');
3636 if (symbols [cnt + j].st_shndx < SHN_LORESERVE
3637 && section_headers[symbols [cnt + j].st_shndx].sh_type
3640 /* We must test both. */
3641 Elf_Internal_Verneed ivn;
3642 unsigned long offset;
3644 offset = version_info [DT_VERSIONTAGIDX (DT_VERNEED)]
3649 Elf_External_Verneed evn;
3650 Elf_External_Vernaux evna;
3651 Elf_Internal_Vernaux ivna;
3652 unsigned long vna_off;
3654 GET_DATA (offset, evn, "version need");
3656 ivn.vn_aux = BYTE_GET (evn.vn_aux);
3657 ivn.vn_next = BYTE_GET (evn.vn_next);
3659 vna_off = offset + ivn.vn_aux;
3663 GET_DATA (vna_off, evna,
3664 "version need aux (1)");
3666 ivna.vna_next = BYTE_GET (evna.vna_next);
3667 ivna.vna_other = BYTE_GET (evna.vna_other);
3669 vna_off += ivna.vna_next;
3671 while (ivna.vna_other != data [cnt + j]
3672 && ivna.vna_next != 0);
3674 if (ivna.vna_other == data [cnt + j])
3676 ivna.vna_name = BYTE_GET (evna.vna_name);
3678 nn += printf ("(%s%-*s",
3679 strtab + ivna.vna_name,
3685 else if (ivn.vn_next == 0)
3687 if (data [cnt + j] != 0x8001)
3689 Elf_Internal_Verdef ivd;
3690 Elf_External_Verdef evd;
3692 offset = version_info
3693 [DT_VERSIONTAGIDX (DT_VERDEF)]
3698 GET_DATA (offset, evd,
3699 "version definition");
3701 ivd.vd_next = BYTE_GET (evd.vd_next);
3702 ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
3704 offset += ivd.vd_next;
3707 != (data [cnt + j] & 0x7fff)
3708 && ivd.vd_next != 0);
3711 == (data [cnt + j] & 0x7fff))
3713 Elf_External_Verdaux evda;
3714 Elf_Internal_Verdaux ivda;
3716 ivd.vd_aux = BYTE_GET (evd.vd_aux);
3718 GET_DATA (offset + ivd.vd_aux, evda,
3719 "version definition aux");
3722 BYTE_GET (evda.vda_name);
3726 strtab + ivda.vda_name,
3737 offset += ivn.vn_next;
3739 while (ivn.vn_next);
3741 else if (symbols [cnt + j].st_shndx == SHN_UNDEF)
3743 Elf_Internal_Verneed ivn;
3744 unsigned long offset;
3746 offset = version_info [DT_VERSIONTAGIDX (DT_VERNEED)]
3751 Elf_Internal_Vernaux ivna;
3752 Elf_External_Verneed evn;
3753 Elf_External_Vernaux evna;
3754 unsigned long a_off;
3756 GET_DATA (offset, evn, "version need");
3758 ivn.vn_aux = BYTE_GET (evn.vn_aux);
3759 ivn.vn_next = BYTE_GET (evn.vn_next);
3761 a_off = offset + ivn.vn_aux;
3765 GET_DATA (a_off, evna,
3766 "version need aux (2)");
3768 ivna.vna_next = BYTE_GET (evna.vna_next);
3769 ivna.vna_other = BYTE_GET (evna.vna_other);
3771 a_off += ivna.vna_next;
3773 while (ivna.vna_other != data [cnt + j]
3774 && ivna.vna_next != 0);
3776 if (ivna.vna_other == data [cnt + j])
3778 ivna.vna_name = BYTE_GET (evna.vna_name);
3780 nn += printf ("(%s%-*s",
3781 strtab + ivna.vna_name,
3788 offset += ivn.vn_next;
3790 while (ivn.vn_next);
3792 else if (data [cnt + j] != 0x8001)
3794 Elf_Internal_Verdef ivd;
3795 Elf_External_Verdef evd;
3796 unsigned long offset;
3798 offset = version_info
3799 [DT_VERSIONTAGIDX (DT_VERDEF)] - loadaddr;
3803 GET_DATA (offset, evd, "version def");
3805 ivd.vd_next = BYTE_GET (evd.vd_next);
3806 ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
3808 offset += ivd.vd_next;
3810 while (ivd.vd_ndx != (data [cnt + j] & 0x7fff)
3811 && ivd.vd_next != 0);
3813 if (ivd.vd_ndx == (data [cnt + j] & 0x7fff))
3815 Elf_External_Verdaux evda;
3816 Elf_Internal_Verdaux ivda;
3818 ivd.vd_aux = BYTE_GET (evd.vd_aux);
3820 GET_DATA (offset - ivd.vd_next + ivd.vd_aux,
3821 evda, "version def aux");
3823 ivda.vda_name = BYTE_GET (evda.vda_name);
3825 nn += printf ("(%s%-*s",
3826 strtab + ivda.vda_name,
3834 printf ("%*c", 18 - nn, ' ');
3852 printf (_("\nNo version information found in this file.\n"));
3858 get_symbol_binding (binding)
3859 unsigned int binding;
3861 static char buff [32];
3865 case STB_LOCAL: return "LOCAL";
3866 case STB_GLOBAL: return "GLOBAL";
3867 case STB_WEAK: return "WEAK";
3869 if (binding >= STB_LOPROC && binding <= STB_HIPROC)
3870 sprintf (buff, _("<processor specific>: %d"), binding);
3871 else if (binding >= STB_LOOS && binding <= STB_HIOS)
3872 sprintf (buff, _("<OS specific>: %d"), binding);
3874 sprintf (buff, _("<unknown>: %d"), binding);
3880 get_symbol_type (type)
3883 static char buff [32];
3887 case STT_NOTYPE: return "NOTYPE";
3888 case STT_OBJECT: return "OBJECT";
3889 case STT_FUNC: return "FUNC";
3890 case STT_SECTION: return "SECTION";
3891 case STT_FILE: return "FILE";
3893 if (type >= STT_LOPROC && type <= STT_HIPROC)
3895 if (elf_header.e_machine == EM_ARM && type == STT_ARM_TFUNC)
3896 return "THUMB_FUNC";
3898 if (elf_header.e_machine == EM_SPARCV9 && type == STT_REGISTER)
3901 if (elf_header.e_machine == EM_PARISC && type == STT_PARISC_MILLI)
3902 return "PARISC_MILLI";
3904 sprintf (buff, _("<processor specific>: %d"), type);
3906 else if (type >= STT_LOOS && type <= STT_HIOS)
3908 if (elf_header.e_machine == EM_PARISC)
3910 if (type == STT_HP_OPAQUE)
3912 if (type == STT_HP_STUB)
3916 sprintf (buff, _("<OS specific>: %d"), type);
3919 sprintf (buff, _("<unknown>: %d"), type);
3925 get_symbol_index_type (type)
3930 case SHN_UNDEF: return "UND";
3931 case SHN_ABS: return "ABS";
3932 case SHN_COMMON: return "COM";
3934 if (type >= SHN_LOPROC && type <= SHN_HIPROC)
3936 else if (type >= SHN_LORESERVE && type <= SHN_HIRESERVE)
3938 else if (type >= SHN_LOOS && type <= SHN_HIOS)
3942 static char buff [32];
3944 sprintf (buff, "%3d", type);
3952 get_dynamic_data (file, number)
3954 unsigned int number;
3959 e_data = (char *) malloc (number * 4);
3963 error (_("Out of memory\n"));
3967 if (fread (e_data, 4, number, file) != number)
3969 error (_("Unable to read in dynamic data\n"));
3973 i_data = (int *) malloc (number * sizeof (* i_data));
3977 error (_("Out of memory\n"));
3983 i_data [number] = byte_get (e_data + number * 4, 4);
3990 /* Dump the symbol table */
3992 process_symbol_table (file)
3995 Elf32_Internal_Shdr * section;
4000 int * buckets = NULL;
4001 int * chains = NULL;
4003 if (! do_syms && !do_histogram)
4006 if (dynamic_info[DT_HASH] && ((do_using_dynamic && dynamic_strings != NULL)
4009 if (fseek (file, dynamic_info[DT_HASH] - loadaddr, SEEK_SET))
4011 error (_("Unable to seek to start of dynamic information"));
4015 if (fread (nb, sizeof (nb), 1, file) != 1)
4017 error (_("Failed to read in number of buckets\n"));
4021 if (fread (nc, sizeof (nc), 1, file) != 1)
4023 error (_("Failed to read in number of chains\n"));
4027 nbuckets = byte_get (nb, 4);
4028 nchains = byte_get (nc, 4);
4030 buckets = get_dynamic_data (file, nbuckets);
4031 chains = get_dynamic_data (file, nchains);
4033 if (buckets == NULL || chains == NULL)
4038 && dynamic_info[DT_HASH] && do_using_dynamic && dynamic_strings != NULL)
4043 printf (_("\nSymbol table for image:\n"));
4045 printf (_(" Num Buc: Value Size Type Bind Ot Ndx Name\n"));
4047 printf (_(" Num Buc: Value Size Type Bind Ot Ndx Name\n"));
4049 for (hn = 0; hn < nbuckets; hn++)
4054 for (si = buckets [hn]; si < nchains && si > 0; si = chains [si])
4056 Elf_Internal_Sym * psym;
4058 psym = dynamic_symbols + si;
4060 printf (" %3d %3d: ", si, hn);
4061 print_vma (psym->st_value, LONG_HEX);
4063 print_vma (psym->st_size, DEC_5);
4065 printf (" %6s %6s %2d ",
4066 get_symbol_type (ELF_ST_TYPE (psym->st_info)),
4067 get_symbol_binding (ELF_ST_BIND (psym->st_info)),
4070 printf ("%3.3s", get_symbol_index_type (psym->st_shndx));
4072 printf (" %s\n", dynamic_strings + psym->st_name);
4076 else if (do_syms && !do_using_dynamic)
4080 for (i = 0, section = section_headers;
4081 i < elf_header.e_shnum;
4086 Elf_Internal_Sym * symtab;
4087 Elf_Internal_Sym * psym;
4090 if ( section->sh_type != SHT_SYMTAB
4091 && section->sh_type != SHT_DYNSYM)
4094 printf (_("\nSymbol table '%s' contains %lu entries:\n"),
4095 SECTION_NAME (section),
4096 (unsigned long) (section->sh_size / section->sh_entsize));
4098 printf (_(" Num: Value Size Type Bind Ot Ndx Name\n"));
4100 printf (_(" Num: Value Size Type Bind Ot Ndx Name\n"));
4102 symtab = GET_ELF_SYMBOLS (file, section->sh_offset,
4103 section->sh_size / section->sh_entsize);
4107 if (section->sh_link == elf_header.e_shstrndx)
4108 strtab = string_table;
4111 Elf32_Internal_Shdr * string_sec;
4113 string_sec = section_headers + section->sh_link;
4115 GET_DATA_ALLOC (string_sec->sh_offset, string_sec->sh_size,
4116 strtab, char *, "string table");
4119 for (si = 0, psym = symtab;
4120 si < section->sh_size / section->sh_entsize;
4123 printf ("%6d: ", si);
4124 print_vma (psym->st_value, LONG_HEX);
4126 print_vma (psym->st_size, DEC_5);
4127 printf (" %-7s %-6s %2d ",
4128 get_symbol_type (ELF_ST_TYPE (psym->st_info)),
4129 get_symbol_binding (ELF_ST_BIND (psym->st_info)),
4132 printf ("%4s", get_symbol_index_type (psym->st_shndx));
4134 printf (" %s", strtab + psym->st_name);
4136 if (section->sh_type == SHT_DYNSYM &&
4137 version_info [DT_VERSIONTAGIDX (DT_VERSYM)] != 0)
4139 unsigned char data[2];
4140 unsigned short vers_data;
4141 unsigned long offset;
4145 offset = version_info [DT_VERSIONTAGIDX (DT_VERSYM)]
4148 GET_DATA (offset + si * sizeof (vers_data), data,
4151 vers_data = byte_get (data, 2);
4153 is_nobits = psym->st_shndx < SHN_LORESERVE ?
4154 (section_headers [psym->st_shndx].sh_type == SHT_NOBITS)
4157 check_def = (psym->st_shndx != SHN_UNDEF);
4159 if ((vers_data & 0x8000) || vers_data > 1)
4161 if (is_nobits || ! check_def)
4163 Elf_External_Verneed evn;
4164 Elf_Internal_Verneed ivn;
4165 Elf_Internal_Vernaux ivna;
4167 /* We must test both. */
4168 offset = version_info
4169 [DT_VERSIONTAGIDX (DT_VERNEED)] - loadaddr;
4171 GET_DATA (offset, evn, "version need");
4173 ivn.vn_aux = BYTE_GET (evn.vn_aux);
4174 ivn.vn_next = BYTE_GET (evn.vn_next);
4178 unsigned long vna_off;
4180 vna_off = offset + ivn.vn_aux;
4184 Elf_External_Vernaux evna;
4186 GET_DATA (vna_off, evna,
4187 "version need aux (3)");
4189 ivna.vna_other = BYTE_GET (evna.vna_other);
4190 ivna.vna_next = BYTE_GET (evna.vna_next);
4191 ivna.vna_name = BYTE_GET (evna.vna_name);
4193 vna_off += ivna.vna_next;
4195 while (ivna.vna_other != vers_data
4196 && ivna.vna_next != 0);
4198 if (ivna.vna_other == vers_data)
4201 offset += ivn.vn_next;
4203 while (ivn.vn_next != 0);
4205 if (ivna.vna_other == vers_data)
4208 strtab + ivna.vna_name, ivna.vna_other);
4211 else if (! is_nobits)
4212 error (_("bad dynamic symbol"));
4219 if (vers_data != 0x8001)
4221 Elf_Internal_Verdef ivd;
4222 Elf_Internal_Verdaux ivda;
4223 Elf_External_Verdaux evda;
4224 unsigned long offset;
4227 version_info [DT_VERSIONTAGIDX (DT_VERDEF)]
4232 Elf_External_Verdef evd;
4234 GET_DATA (offset, evd, "version def");
4236 ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
4237 ivd.vd_aux = BYTE_GET (evd.vd_aux);
4238 ivd.vd_next = BYTE_GET (evd.vd_next);
4240 offset += ivd.vd_next;
4242 while (ivd.vd_ndx != (vers_data & 0x7fff)
4243 && ivd.vd_next != 0);
4245 offset -= ivd.vd_next;
4246 offset += ivd.vd_aux;
4248 GET_DATA (offset, evda, "version def aux");
4250 ivda.vda_name = BYTE_GET (evda.vda_name);
4252 if (psym->st_name != ivda.vda_name)
4253 printf ((vers_data & 0x8000)
4255 strtab + ivda.vda_name);
4265 if (strtab != string_table)
4271 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
4273 if (do_histogram && buckets != NULL)
4280 int nzero_counts = 0;
4283 printf (_("\nHistogram for bucket list length (total of %d buckets):\n"),
4285 printf (_(" Length Number %% of total Coverage\n"));
4287 lengths = (int *) calloc (nbuckets, sizeof (int));
4288 if (lengths == NULL)
4290 error (_("Out of memory"));
4293 for (hn = 0; hn < nbuckets; ++hn)
4298 for (si = buckets[hn]; si > 0 && si < nchains; si = chains[si])
4301 if (maxlength < ++lengths[hn])
4306 counts = (int *) calloc (maxlength + 1, sizeof (int));
4309 error (_("Out of memory"));
4313 for (hn = 0; hn < nbuckets; ++hn)
4314 ++ counts [lengths [hn]];
4318 printf (" 0 %-10d (%5.1f%%)\n",
4319 counts[0], (counts[0] * 100.0) / nbuckets);
4320 for (si = 1; si <= maxlength; ++si)
4322 nzero_counts += counts[si] * si;
4323 printf ("%7d %-10d (%5.1f%%) %5.1f%%\n",
4324 si, counts[si], (counts[si] * 100.0) / nbuckets,
4325 (nzero_counts * 100.0) / nsyms);
4333 if (buckets != NULL)
4343 process_syminfo (file)
4344 FILE * file ATTRIBUTE_UNUSED;
4348 if (dynamic_syminfo == NULL
4350 /* No syminfo, this is ok. */
4353 /* There better should be a dynamic symbol section. */
4354 if (dynamic_symbols == NULL || dynamic_strings == NULL)
4358 printf (_("\nDynamic info segment at offset 0x%lx contains %d entries:\n"),
4359 dynamic_syminfo_offset, dynamic_syminfo_nent);
4361 printf (_(" Num: Name BoundTo Flags\n"));
4362 for (i = 0; i < dynamic_syminfo_nent; ++i)
4364 unsigned short int flags = dynamic_syminfo[i].si_flags;
4366 printf ("%4d: %-30s ", i,
4367 dynamic_strings + dynamic_symbols[i].st_name);
4369 switch (dynamic_syminfo[i].si_boundto)
4371 case SYMINFO_BT_SELF:
4372 fputs ("SELF ", stdout);
4374 case SYMINFO_BT_PARENT:
4375 fputs ("PARENT ", stdout);
4378 if (dynamic_syminfo[i].si_boundto > 0
4379 && dynamic_syminfo[i].si_boundto < dynamic_size)
4382 + dynamic_segment[dynamic_syminfo[i].si_boundto].d_un.d_val);
4384 printf ("%-10d ", dynamic_syminfo[i].si_boundto);
4388 if (flags & SYMINFO_FLG_DIRECT)
4390 if (flags & SYMINFO_FLG_PASSTHRU)
4391 printf (" PASSTHRU");
4392 if (flags & SYMINFO_FLG_COPY)
4394 if (flags & SYMINFO_FLG_LAZYLOAD)
4395 printf (" LAZYLOAD");
4403 #ifdef SUPPORT_DISASSEMBLY
4405 disassemble_section (section, file)
4406 Elf32_Internal_Shdr * section;
4409 printf (_("\nAssembly dump of section %s\n"),
4410 SECTION_NAME (section));
4412 /* XXX -- to be done --- XXX */
4419 dump_section (section, file)
4420 Elf32_Internal_Shdr * section;
4423 bfd_size_type bytes;
4425 unsigned char * data;
4426 unsigned char * start;
4428 bytes = section->sh_size;
4432 printf (_("\nSection '%s' has no data to dump.\n"),
4433 SECTION_NAME (section));
4437 printf (_("\nHex dump of section '%s':\n"), SECTION_NAME (section));
4439 addr = section->sh_addr;
4441 GET_DATA_ALLOC (section->sh_offset, bytes, start, unsigned char *,
4452 lbytes = (bytes > 16 ? 16 : bytes);
4454 printf (" 0x%8.8lx ", (unsigned long) addr);
4456 switch (elf_header.e_ident [EI_DATA])
4460 for (j = 15; j >= 0; j --)
4463 printf ("%2.2x", data [j]);
4473 for (j = 0; j < 16; j++)
4476 printf ("%2.2x", data [j]);
4486 for (j = 0; j < lbytes; j++)
4489 if (k >= ' ' && k < 0x80)
4508 static unsigned long int
4509 read_leb128 (data, length_return, sign)
4510 unsigned char * data;
4511 int * length_return;
4514 unsigned long int result = 0;
4515 unsigned int num_read = 0;
4524 result |= (byte & 0x7f) << shift;
4529 while (byte & 0x80);
4531 if (length_return != NULL)
4532 * length_return = num_read;
4534 if (sign && (shift < 32) && (byte & 0x40))
4535 result |= -1 << shift;
4540 typedef struct State_Machine_Registers
4542 unsigned long address;
4545 unsigned int column;
4549 /* This variable hold the number of the last entry seen
4550 in the File Table. */
4551 unsigned int last_file_entry;
4554 static SMR state_machine_regs;
4557 reset_state_machine (is_stmt)
4560 state_machine_regs.address = 0;
4561 state_machine_regs.file = 1;
4562 state_machine_regs.line = 1;
4563 state_machine_regs.column = 0;
4564 state_machine_regs.is_stmt = is_stmt;
4565 state_machine_regs.basic_block = 0;
4566 state_machine_regs.end_sequence = 0;
4567 state_machine_regs.last_file_entry = 0;
4570 /* Handled an extend line op. Returns true if this is the end
4573 process_extended_line_op (data, is_stmt, pointer_size)
4574 unsigned char * data;
4578 unsigned char op_code;
4581 unsigned char * name;
4584 len = read_leb128 (data, & bytes_read, 0);
4589 warn (_("badly formed extended line op encountered!"));
4594 op_code = * data ++;
4596 printf (_(" Extended opcode %d: "), op_code);
4600 case DW_LNE_end_sequence:
4601 printf (_("End of Sequence\n\n"));
4602 reset_state_machine (is_stmt);
4605 case DW_LNE_set_address:
4606 adr = byte_get (data, pointer_size);
4607 printf (_("set Address to 0x%lx\n"), adr);
4608 state_machine_regs.address = adr;
4611 case DW_LNE_define_file:
4612 printf (_(" define new File Table entry\n"));
4613 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
4615 printf (_(" %d\t"), ++ state_machine_regs.last_file_entry);
4617 data += strlen (data) + 1;
4618 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
4620 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
4622 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
4623 printf (_("%s\n\n"), name);
4627 printf (_("UNKNOWN: length %d\n"), len - bytes_read);
4634 /* Size of pointers in the .debug_line section. This information is not
4635 really present in that section. It's obtained before dumping the debug
4636 sections by doing some pre-scan of the .debug_info section. */
4637 static int debug_line_pointer_size = 4;
4640 display_debug_lines (section, start, file)
4641 Elf32_Internal_Shdr * section;
4642 unsigned char * start;
4643 FILE * file ATTRIBUTE_UNUSED;
4645 DWARF2_External_LineInfo * external;
4646 DWARF2_Internal_LineInfo info;
4647 unsigned char * standard_opcodes;
4648 unsigned char * data = start;
4649 unsigned char * end = start + section->sh_size;
4650 unsigned char * end_of_sequence;
4653 printf (_("\nDump of debug contents of section %s:\n\n"),
4654 SECTION_NAME (section));
4658 external = (DWARF2_External_LineInfo *) data;
4660 /* Check the length of the block. */
4661 info.li_length = BYTE_GET (external->li_length);
4662 if (info.li_length > section->sh_size)
4665 (_("The line info appears to be corrupt - the section is too small\n"));
4669 /* Check its version number. */
4670 info.li_version = BYTE_GET (external->li_version);
4671 if (info.li_version != 2)
4673 warn (_("Only DWARF version 2 line info is currently supported.\n"));
4677 info.li_prologue_length = BYTE_GET (external->li_prologue_length);
4678 info.li_min_insn_length = BYTE_GET (external->li_min_insn_length);
4679 info.li_default_is_stmt = BYTE_GET (external->li_default_is_stmt);
4680 info.li_line_base = BYTE_GET (external->li_line_base);
4681 info.li_line_range = BYTE_GET (external->li_line_range);
4682 info.li_opcode_base = BYTE_GET (external->li_opcode_base);
4684 /* Sign extend the line base field. */
4685 info.li_line_base <<= 24;
4686 info.li_line_base >>= 24;
4688 printf (_(" Length: %ld\n"), info.li_length);
4689 printf (_(" DWARF Version: %d\n"), info.li_version);
4690 printf (_(" Prolgue Length: %d\n"), info.li_prologue_length);
4691 printf (_(" Minimum Instruction Length: %d\n"), info.li_min_insn_length);
4692 printf (_(" Initial value of 'is_stmt': %d\n"), info.li_default_is_stmt);
4693 printf (_(" Line Base: %d\n"), info.li_line_base);
4694 printf (_(" Line Range: %d\n"), info.li_line_range);
4695 printf (_(" Opcode Base: %d\n"), info.li_opcode_base);
4697 end_of_sequence = data + info.li_length + sizeof (info.li_length);
4699 reset_state_machine (info.li_default_is_stmt);
4701 /* Display the contents of the Opcodes table. */
4702 standard_opcodes = data + sizeof (* external);
4704 printf (_("\n Opcodes:\n"));
4706 for (i = 1; i < info.li_opcode_base; i++)
4707 printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]);
4709 /* Display the contents of the Directory table. */
4710 data = standard_opcodes + info.li_opcode_base - 1;
4713 printf (_("\n The Directory Table is empty.\n"));
4716 printf (_("\n The Directory Table:\n"));
4720 printf (_(" %s\n"), data);
4722 data += strlen (data) + 1;
4726 /* Skip the NUL at the end of the table. */
4729 /* Display the contents of the File Name table. */
4731 printf (_("\n The File Name Table is empty.\n"));
4734 printf (_("\n The File Name Table:\n"));
4735 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
4742 printf (_(" %d\t"), ++ state_machine_regs.last_file_entry);
4745 data += strlen (data) + 1;
4747 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
4749 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
4751 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
4753 printf (_("%s\n"), name);
4757 /* Skip the NUL at the end of the table. */
4760 /* Now display the statements. */
4761 printf (_("\n Line Number Statements:\n"));
4764 while (data < end_of_sequence)
4766 unsigned char op_code;
4770 op_code = * data ++;
4774 case DW_LNS_extended_op:
4775 data += process_extended_line_op (data, info.li_default_is_stmt,
4776 debug_line_pointer_size);
4780 printf (_(" Copy\n"));
4783 case DW_LNS_advance_pc:
4784 adv = info.li_min_insn_length * read_leb128 (data, & bytes_read, 0);
4786 state_machine_regs.address += adv;
4787 printf (_(" Advance PC by %d to %lx\n"), adv,
4788 state_machine_regs.address);
4791 case DW_LNS_advance_line:
4792 adv = read_leb128 (data, & bytes_read, 1);
4794 state_machine_regs.line += adv;
4795 printf (_(" Advance Line by %d to %d\n"), adv,
4796 state_machine_regs.line);
4799 case DW_LNS_set_file:
4800 adv = read_leb128 (data, & bytes_read, 0);
4802 printf (_(" Set File Name to entry %d in the File Name Table\n"),
4804 state_machine_regs.file = adv;
4807 case DW_LNS_set_column:
4808 adv = read_leb128 (data, & bytes_read, 0);
4810 printf (_(" Set column to %d\n"), adv);
4811 state_machine_regs.column = adv;
4814 case DW_LNS_negate_stmt:
4815 adv = state_machine_regs.is_stmt;
4817 printf (_(" Set is_stmt to %d\n"), adv);
4818 state_machine_regs.is_stmt = adv;
4821 case DW_LNS_set_basic_block:
4822 printf (_(" Set basic block\n"));
4823 state_machine_regs.basic_block = 1;
4826 case DW_LNS_const_add_pc:
4827 adv = (((255 - info.li_opcode_base) / info.li_line_range)
4828 * info.li_min_insn_length);
4829 state_machine_regs.address += adv;
4830 printf (_(" Advance PC by constant %d to 0x%lx\n"), adv,
4831 state_machine_regs.address);
4834 case DW_LNS_fixed_advance_pc:
4835 adv = byte_get (data, 2);
4837 state_machine_regs.address += adv;
4838 printf (_(" Advance PC by fixed size amount %d to 0x%lx\n"),
4839 adv, state_machine_regs.address);
4843 op_code -= info.li_opcode_base;
4844 adv = (op_code / info.li_line_range) * info.li_min_insn_length;
4845 state_machine_regs.address += adv;
4846 printf (_(" Special opcode %d: advance Address by %d to 0x%lx"),
4847 op_code, adv, state_machine_regs.address);
4848 adv = (op_code % info.li_line_range) + info.li_line_base;
4849 state_machine_regs.line += adv;
4850 printf (_(" and Line by %d to %d\n"),
4851 adv, state_machine_regs.line);
4862 display_debug_pubnames (section, start, file)
4863 Elf32_Internal_Shdr * section;
4864 unsigned char * start;
4865 FILE * file ATTRIBUTE_UNUSED;
4867 DWARF2_External_PubNames * external;
4868 DWARF2_Internal_PubNames pubnames;
4869 unsigned char * end;
4871 end = start + section->sh_size;
4873 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section));
4877 unsigned char * data;
4878 unsigned long offset;
4880 external = (DWARF2_External_PubNames *) start;
4882 pubnames.pn_length = BYTE_GET (external->pn_length);
4883 pubnames.pn_version = BYTE_GET (external->pn_version);
4884 pubnames.pn_offset = BYTE_GET (external->pn_offset);
4885 pubnames.pn_size = BYTE_GET (external->pn_size);
4887 data = start + sizeof (* external);
4888 start += pubnames.pn_length + sizeof (external->pn_length);
4890 if (pubnames.pn_version != 2)
4892 warn (_("Only DWARF 2 pubnames are currently supported"));
4896 printf (_(" Length: %ld\n"),
4897 pubnames.pn_length);
4898 printf (_(" Version: %d\n"),
4899 pubnames.pn_version);
4900 printf (_(" Offset into .debug_info section: %ld\n"),
4901 pubnames.pn_offset);
4902 printf (_(" Size of area in .debug_info section: %ld\n"),
4905 printf (_("\n Offset\tName\n"));
4909 offset = byte_get (data, 4);
4914 printf (" %ld\t\t%s\n", offset, data);
4915 data += strlen (data) + 1;
4918 while (offset != 0);
4931 case DW_TAG_padding: return "DW_TAG_padding";
4932 case DW_TAG_array_type: return "DW_TAG_array_type";
4933 case DW_TAG_class_type: return "DW_TAG_class_type";
4934 case DW_TAG_entry_point: return "DW_TAG_entry_point";
4935 case DW_TAG_enumeration_type: return "DW_TAG_enumeration_type";
4936 case DW_TAG_formal_parameter: return "DW_TAG_formal_parameter";
4937 case DW_TAG_imported_declaration: return "DW_TAG_imported_declaration";
4938 case DW_TAG_label: return "DW_TAG_label";
4939 case DW_TAG_lexical_block: return "DW_TAG_lexical_block";
4940 case DW_TAG_member: return "DW_TAG_member";
4941 case DW_TAG_pointer_type: return "DW_TAG_pointer_type";
4942 case DW_TAG_reference_type: return "DW_TAG_reference_type";
4943 case DW_TAG_compile_unit: return "DW_TAG_compile_unit";
4944 case DW_TAG_string_type: return "DW_TAG_string_type";
4945 case DW_TAG_structure_type: return "DW_TAG_structure_type";
4946 case DW_TAG_subroutine_type: return "DW_TAG_subroutine_type";
4947 case DW_TAG_typedef: return "DW_TAG_typedef";
4948 case DW_TAG_union_type: return "DW_TAG_union_type";
4949 case DW_TAG_unspecified_parameters: return "DW_TAG_unspecified_parameters";
4950 case DW_TAG_variant: return "DW_TAG_variant";
4951 case DW_TAG_common_block: return "DW_TAG_common_block";
4952 case DW_TAG_common_inclusion: return "DW_TAG_common_inclusion";
4953 case DW_TAG_inheritance: return "DW_TAG_inheritance";
4954 case DW_TAG_inlined_subroutine: return "DW_TAG_inlined_subroutine";
4955 case DW_TAG_module: return "DW_TAG_module";
4956 case DW_TAG_ptr_to_member_type: return "DW_TAG_ptr_to_member_type";
4957 case DW_TAG_set_type: return "DW_TAG_set_type";
4958 case DW_TAG_subrange_type: return "DW_TAG_subrange_type";
4959 case DW_TAG_with_stmt: return "DW_TAG_with_stmt";
4960 case DW_TAG_access_declaration: return "DW_TAG_access_declaration";
4961 case DW_TAG_base_type: return "DW_TAG_base_type";
4962 case DW_TAG_catch_block: return "DW_TAG_catch_block";
4963 case DW_TAG_const_type: return "DW_TAG_const_type";
4964 case DW_TAG_constant: return "DW_TAG_constant";
4965 case DW_TAG_enumerator: return "DW_TAG_enumerator";
4966 case DW_TAG_file_type: return "DW_TAG_file_type";
4967 case DW_TAG_friend: return "DW_TAG_friend";
4968 case DW_TAG_namelist: return "DW_TAG_namelist";
4969 case DW_TAG_namelist_item: return "DW_TAG_namelist_item";
4970 case DW_TAG_packed_type: return "DW_TAG_packed_type";
4971 case DW_TAG_subprogram: return "DW_TAG_subprogram";
4972 case DW_TAG_template_type_param: return "DW_TAG_template_type_param";
4973 case DW_TAG_template_value_param: return "DW_TAG_template_value_param";
4974 case DW_TAG_thrown_type: return "DW_TAG_thrown_type";
4975 case DW_TAG_try_block: return "DW_TAG_try_block";
4976 case DW_TAG_variant_part: return "DW_TAG_variant_part";
4977 case DW_TAG_variable: return "DW_TAG_variable";
4978 case DW_TAG_volatile_type: return "DW_TAG_volatile_type";
4979 case DW_TAG_MIPS_loop: return "DW_TAG_MIPS_loop";
4980 case DW_TAG_format_label: return "DW_TAG_format_label";
4981 case DW_TAG_function_template: return "DW_TAG_function_template";
4982 case DW_TAG_class_template: return "DW_TAG_class_template";
4985 static char buffer [100];
4987 sprintf (buffer, _("Unknown TAG value: %lx"), tag);
4994 get_AT_name (attribute)
4995 unsigned long attribute;
4999 case DW_AT_sibling: return "DW_AT_sibling";
5000 case DW_AT_location: return "DW_AT_location";
5001 case DW_AT_name: return "DW_AT_name";
5002 case DW_AT_ordering: return "DW_AT_ordering";
5003 case DW_AT_subscr_data: return "DW_AT_subscr_data";
5004 case DW_AT_byte_size: return "DW_AT_byte_size";
5005 case DW_AT_bit_offset: return "DW_AT_bit_offset";
5006 case DW_AT_bit_size: return "DW_AT_bit_size";
5007 case DW_AT_element_list: return "DW_AT_element_list";
5008 case DW_AT_stmt_list: return "DW_AT_stmt_list";
5009 case DW_AT_low_pc: return "DW_AT_low_pc";
5010 case DW_AT_high_pc: return "DW_AT_high_pc";
5011 case DW_AT_language: return "DW_AT_language";
5012 case DW_AT_member: return "DW_AT_member";
5013 case DW_AT_discr: return "DW_AT_discr";
5014 case DW_AT_discr_value: return "DW_AT_discr_value";
5015 case DW_AT_visibility: return "DW_AT_visibility";
5016 case DW_AT_import: return "DW_AT_import";
5017 case DW_AT_string_length: return "DW_AT_string_length";
5018 case DW_AT_common_reference: return "DW_AT_common_reference";
5019 case DW_AT_comp_dir: return "DW_AT_comp_dir";
5020 case DW_AT_const_value: return "DW_AT_const_value";
5021 case DW_AT_containing_type: return "DW_AT_containing_type";
5022 case DW_AT_default_value: return "DW_AT_default_value";
5023 case DW_AT_inline: return "DW_AT_inline";
5024 case DW_AT_is_optional: return "DW_AT_is_optional";
5025 case DW_AT_lower_bound: return "DW_AT_lower_bound";
5026 case DW_AT_producer: return "DW_AT_producer";
5027 case DW_AT_prototyped: return "DW_AT_prototyped";
5028 case DW_AT_return_addr: return "DW_AT_return_addr";
5029 case DW_AT_start_scope: return "DW_AT_start_scope";
5030 case DW_AT_stride_size: return "DW_AT_stride_size";
5031 case DW_AT_upper_bound: return "DW_AT_upper_bound";
5032 case DW_AT_abstract_origin: return "DW_AT_abstract_origin";
5033 case DW_AT_accessibility: return "DW_AT_accessibility";
5034 case DW_AT_address_class: return "DW_AT_address_class";
5035 case DW_AT_artificial: return "DW_AT_artificial";
5036 case DW_AT_base_types: return "DW_AT_base_types";
5037 case DW_AT_calling_convention: return "DW_AT_calling_convention";
5038 case DW_AT_count: return "DW_AT_count";
5039 case DW_AT_data_member_location: return "DW_AT_data_member_location";
5040 case DW_AT_decl_column: return "DW_AT_decl_column";
5041 case DW_AT_decl_file: return "DW_AT_decl_file";
5042 case DW_AT_decl_line: return "DW_AT_decl_line";
5043 case DW_AT_declaration: return "DW_AT_declaration";
5044 case DW_AT_discr_list: return "DW_AT_discr_list";
5045 case DW_AT_encoding: return "DW_AT_encoding";
5046 case DW_AT_external: return "DW_AT_external";
5047 case DW_AT_frame_base: return "DW_AT_frame_base";
5048 case DW_AT_friend: return "DW_AT_friend";
5049 case DW_AT_identifier_case: return "DW_AT_identifier_case";
5050 case DW_AT_macro_info: return "DW_AT_macro_info";
5051 case DW_AT_namelist_items: return "DW_AT_namelist_items";
5052 case DW_AT_priority: return "DW_AT_priority";
5053 case DW_AT_segment: return "DW_AT_segment";
5054 case DW_AT_specification: return "DW_AT_specification";
5055 case DW_AT_static_link: return "DW_AT_static_link";
5056 case DW_AT_type: return "DW_AT_type";
5057 case DW_AT_use_location: return "DW_AT_use_location";
5058 case DW_AT_variable_parameter: return "DW_AT_variable_parameter";
5059 case DW_AT_virtuality: return "DW_AT_virtuality";
5060 case DW_AT_vtable_elem_location: return "DW_AT_vtable_elem_location";
5061 case DW_AT_MIPS_fde: return "DW_AT_MIPS_fde";
5062 case DW_AT_MIPS_loop_begin: return "DW_AT_MIPS_loop_begin";
5063 case DW_AT_MIPS_tail_loop_begin: return "DW_AT_MIPS_tail_loop_begin";
5064 case DW_AT_MIPS_epilog_begin: return "DW_AT_MIPS_epilog_begin";
5065 case DW_AT_MIPS_loop_unroll_factor: return "DW_AT_MIPS_loop_unroll_factor";
5066 case DW_AT_MIPS_software_pipeline_depth: return "DW_AT_MIPS_software_pipeline_depth";
5067 case DW_AT_MIPS_linkage_name: return "DW_AT_MIPS_linkage_name";
5068 case DW_AT_MIPS_stride: return "DW_AT_MIPS_stride";
5069 case DW_AT_MIPS_abstract_name: return "DW_AT_MIPS_abstract_name";
5070 case DW_AT_MIPS_clone_origin: return "DW_AT_MIPS_clone_origin";
5071 case DW_AT_MIPS_has_inlines: return "DW_AT_MIPS_has_inlines";
5072 case DW_AT_sf_names: return "DW_AT_sf_names";
5073 case DW_AT_src_info: return "DW_AT_src_info";
5074 case DW_AT_mac_info: return "DW_AT_mac_info";
5075 case DW_AT_src_coords: return "DW_AT_src_coords";
5076 case DW_AT_body_begin: return "DW_AT_body_begin";
5077 case DW_AT_body_end: return "DW_AT_body_end";
5080 static char buffer [100];
5082 sprintf (buffer, _("Unknown AT value: %lx"), attribute);
5089 get_FORM_name (form)
5094 case DW_FORM_addr: return "DW_FORM_addr";
5095 case DW_FORM_block2: return "DW_FORM_block2";
5096 case DW_FORM_block4: return "DW_FORM_block4";
5097 case DW_FORM_data2: return "DW_FORM_data2";
5098 case DW_FORM_data4: return "DW_FORM_data4";
5099 case DW_FORM_data8: return "DW_FORM_data8";
5100 case DW_FORM_string: return "DW_FORM_string";
5101 case DW_FORM_block: return "DW_FORM_block";
5102 case DW_FORM_block1: return "DW_FORM_block1";
5103 case DW_FORM_data1: return "DW_FORM_data1";
5104 case DW_FORM_flag: return "DW_FORM_flag";
5105 case DW_FORM_sdata: return "DW_FORM_sdata";
5106 case DW_FORM_strp: return "DW_FORM_strp";
5107 case DW_FORM_udata: return "DW_FORM_udata";
5108 case DW_FORM_ref_addr: return "DW_FORM_ref_addr";
5109 case DW_FORM_ref1: return "DW_FORM_ref1";
5110 case DW_FORM_ref2: return "DW_FORM_ref2";
5111 case DW_FORM_ref4: return "DW_FORM_ref4";
5112 case DW_FORM_ref8: return "DW_FORM_ref8";
5113 case DW_FORM_ref_udata: return "DW_FORM_ref_udata";
5114 case DW_FORM_indirect: return "DW_FORM_indirect";
5117 static char buffer [100];
5119 sprintf (buffer, _("Unknown FORM value: %lx"), form);
5125 /* FIXME: There are better and more effiecint ways to handle
5126 these structures. For now though, I just want something that
5127 is simple to implement. */
5128 typedef struct abbrev_attr
5130 unsigned long attribute;
5132 struct abbrev_attr * next;
5136 typedef struct abbrev_entry
5138 unsigned long entry;
5141 struct abbrev_attr * first_attr;
5142 struct abbrev_attr * last_attr;
5143 struct abbrev_entry * next;
5147 static abbrev_entry * first_abbrev = NULL;
5148 static abbrev_entry * last_abbrev = NULL;
5151 free_abbrevs PARAMS ((void))
5153 abbrev_entry * abbrev;
5155 for (abbrev = first_abbrev; abbrev;)
5157 abbrev_entry * next = abbrev->next;
5160 for (attr = abbrev->first_attr; attr;)
5162 abbrev_attr * next = attr->next;
5172 last_abbrev = first_abbrev = NULL;
5176 add_abbrev (number, tag, children)
5177 unsigned long number;
5181 abbrev_entry * entry;
5183 entry = (abbrev_entry *) malloc (sizeof (* entry));
5189 entry->entry = number;
5191 entry->children = children;
5192 entry->first_attr = NULL;
5193 entry->last_attr = NULL;
5196 if (first_abbrev == NULL)
5197 first_abbrev = entry;
5199 last_abbrev->next = entry;
5201 last_abbrev = entry;
5205 add_abbrev_attr (attribute, form)
5206 unsigned long attribute;
5211 attr = (abbrev_attr *) malloc (sizeof (* attr));
5217 attr->attribute = attribute;
5221 if (last_abbrev->first_attr == NULL)
5222 last_abbrev->first_attr = attr;
5224 last_abbrev->last_attr->next = attr;
5226 last_abbrev->last_attr = attr;
5229 /* Processes the (partial) contents of a .debug_abbrev section.
5230 Returns NULL if the end of the section was encountered.
5231 Returns the address after the last byte read if the end of
5232 an abbreviation set was found. */
5234 static unsigned char *
5235 process_abbrev_section (start, end)
5236 unsigned char * start;
5237 unsigned char * end;
5239 if (first_abbrev != NULL)
5245 unsigned long entry;
5247 unsigned long attribute;
5250 entry = read_leb128 (start, & bytes_read, 0);
5251 start += bytes_read;
5253 /* A single zero is supposed to end the section according
5254 to the standard. If there's more, then signal that to
5257 return start == end ? NULL : start;
5259 tag = read_leb128 (start, & bytes_read, 0);
5260 start += bytes_read;
5262 children = * start ++;
5264 add_abbrev (entry, tag, children);
5270 attribute = read_leb128 (start, & bytes_read, 0);
5271 start += bytes_read;
5273 form = read_leb128 (start, & bytes_read, 0);
5274 start += bytes_read;
5277 add_abbrev_attr (attribute, form);
5279 while (attribute != 0);
5287 display_debug_abbrev (section, start, file)
5288 Elf32_Internal_Shdr * section;
5289 unsigned char * start;
5290 FILE * file ATTRIBUTE_UNUSED;
5292 abbrev_entry * entry;
5293 unsigned char * end = start + section->sh_size;
5295 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section));
5299 start = process_abbrev_section (start, end);
5301 printf (_(" Number TAG\n"));
5303 for (entry = first_abbrev; entry; entry = entry->next)
5307 printf (_(" %ld %s [%s]\n"),
5309 get_TAG_name (entry->tag),
5310 entry->children ? _("has children") : _("no children"));
5312 for (attr = entry->first_attr; attr; attr = attr->next)
5314 printf (_(" %-18s %s\n"),
5315 get_AT_name (attr->attribute),
5316 get_FORM_name (attr->form));
5328 static unsigned char *
5329 display_block (data, length)
5330 unsigned char * data;
5331 unsigned long length;
5333 printf (_(" %lu byte block: "), length);
5336 printf ("%lx ", (unsigned long) byte_get (data ++, 1));
5342 decode_location_expression (data, pointer_size)
5343 unsigned char * data;
5344 unsigned int pointer_size;
5348 unsigned long uvalue;
5355 printf ("DW_OP_addr: %lx", (unsigned long) byte_get (data, pointer_size));
5358 printf ("DW_OP_deref");
5361 printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data, 1));
5364 printf ("DW_OP_const1s: %ld", (long) byte_get (data, 1));
5367 printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data, 2));
5370 printf ("DW_OP_const2s: %ld", (long) byte_get (data, 2));
5373 printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data, 4));
5376 printf ("DW_OP_const4s: %ld", (long) byte_get (data, 4));
5379 printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data, 4),
5380 (unsigned long) byte_get (data + 4, 4));
5383 printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data, 4),
5384 (long) byte_get (data + 4, 4));
5387 printf ("DW_OP_constu: %lu", read_leb128 (data, NULL, 0));
5390 printf ("DW_OP_consts: %ld", read_leb128 (data, NULL, 1));
5393 printf ("DW_OP_dup");
5396 printf ("DW_OP_drop");
5399 printf ("DW_OP_over");
5402 printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data, 1));
5405 printf ("DW_OP_swap");
5408 printf ("DW_OP_rot");
5411 printf ("DW_OP_xderef");
5414 printf ("DW_OP_abs");
5417 printf ("DW_OP_and");
5420 printf ("DW_OP_div");
5423 printf ("DW_OP_minus");
5426 printf ("DW_OP_mod");
5429 printf ("DW_OP_mul");
5432 printf ("DW_OP_neg");
5435 printf ("DW_OP_not");
5438 printf ("DW_OP_or");
5441 printf ("DW_OP_plus");
5443 case DW_OP_plus_uconst:
5444 printf ("DW_OP_plus_uconst: %lu", read_leb128 (data, NULL, 0));
5447 printf ("DW_OP_shl");
5450 printf ("DW_OP_shr");
5453 printf ("DW_OP_shra");
5456 printf ("DW_OP_xor");
5459 printf ("DW_OP_bra: %ld", (long) byte_get (data, 2));
5462 printf ("DW_OP_eq");
5465 printf ("DW_OP_ge");
5468 printf ("DW_OP_gt");
5471 printf ("DW_OP_le");
5474 printf ("DW_OP_lt");
5477 printf ("DW_OP_ne");
5480 printf ("DW_OP_skip: %ld", (long) byte_get (data, 2));
5483 printf ("DW_OP_lit0");
5486 printf ("DW_OP_lit1");
5489 printf ("DW_OP_lit2");
5492 printf ("DW_OP_lit3");
5495 printf ("DW_OP_lit4");
5498 printf ("DW_OP_lit5");
5501 printf ("DW_OP_lit6");
5504 printf ("DW_OP_lit7");
5507 printf ("DW_OP_lit8");
5510 printf ("DW_OP_lit9");
5513 printf ("DW_OP_lit10");
5516 printf ("DW_OP_lit11");
5519 printf ("DW_OP_lit12");
5522 printf ("DW_OP_lit13");
5525 printf ("DW_OP_lit14");
5528 printf ("DW_OP_lit15");
5531 printf ("DW_OP_lit16");
5534 printf ("DW_OP_lit17");
5537 printf ("DW_OP_lit18");
5540 printf ("DW_OP_lit19");
5543 printf ("DW_OP_lit20");
5546 printf ("DW_OP_lit21");
5549 printf ("DW_OP_lit22");
5552 printf ("DW_OP_lit23");
5555 printf ("DW_OP_lit24");
5558 printf ("DW_OP_lit25");
5561 printf ("DW_OP_lit26");
5564 printf ("DW_OP_lit27");
5567 printf ("DW_OP_lit28");
5570 printf ("DW_OP_lit29");
5573 printf ("DW_OP_lit30");
5576 printf ("DW_OP_lit31");
5579 printf ("DW_OP_reg0");
5582 printf ("DW_OP_reg1");
5585 printf ("DW_OP_reg2");
5588 printf ("DW_OP_reg3");
5591 printf ("DW_OP_reg4");
5594 printf ("DW_OP_reg5");
5597 printf ("DW_OP_reg6");
5600 printf ("DW_OP_reg7");
5603 printf ("DW_OP_reg8");
5606 printf ("DW_OP_reg9");
5609 printf ("DW_OP_reg10");
5612 printf ("DW_OP_reg11");
5615 printf ("DW_OP_reg12");
5618 printf ("DW_OP_reg13");
5621 printf ("DW_OP_reg14");
5624 printf ("DW_OP_reg15");
5627 printf ("DW_OP_reg16");
5630 printf ("DW_OP_reg17");
5633 printf ("DW_OP_reg18");
5636 printf ("DW_OP_reg19");
5639 printf ("DW_OP_reg20");
5642 printf ("DW_OP_reg21");
5645 printf ("DW_OP_reg22");
5648 printf ("DW_OP_reg23");
5651 printf ("DW_OP_reg24");
5654 printf ("DW_OP_reg25");
5657 printf ("DW_OP_reg26");
5660 printf ("DW_OP_reg27");
5663 printf ("DW_OP_reg28");
5666 printf ("DW_OP_reg29");
5669 printf ("DW_OP_reg30");
5672 printf ("DW_OP_reg31");
5675 printf ("DW_OP_breg0: %ld", read_leb128 (data, NULL, 1));
5678 printf ("DW_OP_breg1: %ld", read_leb128 (data, NULL, 1));
5681 printf ("DW_OP_breg2: %ld", read_leb128 (data, NULL, 1));
5684 printf ("DW_OP_breg3: %ld", read_leb128 (data, NULL, 1));
5687 printf ("DW_OP_breg4: %ld", read_leb128 (data, NULL, 1));
5690 printf ("DW_OP_breg5: %ld", read_leb128 (data, NULL, 1));
5693 printf ("DW_OP_breg6: %ld", read_leb128 (data, NULL, 1));
5696 printf ("DW_OP_breg7: %ld", read_leb128 (data, NULL, 1));
5699 printf ("DW_OP_breg8: %ld", read_leb128 (data, NULL, 1));
5702 printf ("DW_OP_breg9: %ld", read_leb128 (data, NULL, 1));
5705 printf ("DW_OP_breg10: %ld", read_leb128 (data, NULL, 1));
5708 printf ("DW_OP_breg11: %ld", read_leb128 (data, NULL, 1));
5711 printf ("DW_OP_breg12: %ld", read_leb128 (data, NULL, 1));
5714 printf ("DW_OP_breg13: %ld", read_leb128 (data, NULL, 1));
5717 printf ("DW_OP_breg14: %ld", read_leb128 (data, NULL, 1));
5720 printf ("DW_OP_breg15: %ld", read_leb128 (data, NULL, 1));
5723 printf ("DW_OP_breg16: %ld", read_leb128 (data, NULL, 1));
5726 printf ("DW_OP_breg17: %ld", read_leb128 (data, NULL, 1));
5729 printf ("DW_OP_breg18: %ld", read_leb128 (data, NULL, 1));
5732 printf ("DW_OP_breg19: %ld", read_leb128 (data, NULL, 1));
5735 printf ("DW_OP_breg20: %ld", read_leb128 (data, NULL, 1));
5738 printf ("DW_OP_breg21: %ld", read_leb128 (data, NULL, 1));
5741 printf ("DW_OP_breg22: %ld", read_leb128 (data, NULL, 1));
5744 printf ("DW_OP_breg23: %ld", read_leb128 (data, NULL, 1));
5747 printf ("DW_OP_breg24: %ld", read_leb128 (data, NULL, 1));
5750 printf ("DW_OP_breg25: %ld", read_leb128 (data, NULL, 1));
5753 printf ("DW_OP_breg26: %ld", read_leb128 (data, NULL, 1));
5756 printf ("DW_OP_breg27: %ld", read_leb128 (data, NULL, 1));
5759 printf ("DW_OP_breg28: %ld", read_leb128 (data, NULL, 1));
5762 printf ("DW_OP_breg29: %ld", read_leb128 (data, NULL, 1));
5765 printf ("DW_OP_breg30: %ld", read_leb128 (data, NULL, 1));
5768 printf ("DW_OP_breg31: %ld", read_leb128 (data, NULL, 1));
5771 printf ("DW_OP_regx: %lu", read_leb128 (data, NULL, 0));
5774 printf ("DW_OP_fbreg: %ld", read_leb128 (data, NULL, 1));
5777 uvalue = read_leb128 (data, &bytes_read, 0);
5778 printf ("DW_OP_bregx: %lu %ld", uvalue,
5779 read_leb128 (data + bytes_read, NULL, 1));
5782 printf ("DW_OP_piece: %lu", read_leb128 (data, NULL, 0));
5784 case DW_OP_deref_size:
5785 printf ("DW_OP_deref_size: %ld", (long) byte_get (data, 1));
5787 case DW_OP_xderef_size:
5788 printf ("DW_OP_xderef_size: %ld", (long) byte_get (data, 1));
5791 printf ("DW_OP_nop");
5795 if (op >= DW_OP_lo_user
5796 && op <= DW_OP_hi_user)
5797 printf (_("(User defined location op)"));
5799 printf (_("(Unknown location op)"));
5805 static unsigned char *
5806 read_and_display_attr (attribute, form, data, pointer_size)
5807 unsigned long attribute;
5809 unsigned char * data;
5810 unsigned long pointer_size;
5812 unsigned long uvalue = 0;
5813 unsigned char * block_start = NULL;
5817 printf (" %-18s:", get_AT_name (attribute));
5821 case DW_FORM_ref_addr:
5826 case DW_FORM_ref_udata:
5832 case DW_FORM_ref_addr:
5834 uvalue = byte_get (data, pointer_size);
5835 printf (is_ref ? " <%x>" : " %#x", uvalue);
5836 data += pointer_size;
5842 uvalue = byte_get (data ++, 1);
5843 printf (is_ref ? " <%x>" : " %d", uvalue);
5848 uvalue = byte_get (data, 2);
5850 printf (is_ref ? " <%x>" : " %d", uvalue);
5855 uvalue = byte_get (data, 4);
5857 printf (is_ref ? " <%x>" : " %d", uvalue);
5862 uvalue = byte_get (data, 4);
5863 printf (" %lx", uvalue);
5864 printf (" %lx", (unsigned long) byte_get (data + 4, 4));
5868 case DW_FORM_string:
5869 printf (" %s", data);
5870 data += strlen (data) + 1;
5874 uvalue = read_leb128 (data, & bytes_read, 1);
5876 printf (" %ld", (long) uvalue);
5879 case DW_FORM_ref_udata:
5881 uvalue = read_leb128 (data, & bytes_read, 0);
5883 printf (is_ref ? " <%lx>" : " %ld", uvalue);
5887 uvalue = read_leb128 (data, & bytes_read, 0);
5888 block_start = data + bytes_read;
5889 data = display_block (block_start, uvalue);
5890 uvalue = * block_start;
5893 case DW_FORM_block1:
5894 uvalue = byte_get (data, 1);
5895 block_start = data + 1;
5896 data = display_block (block_start, uvalue);
5897 uvalue = * block_start;
5900 case DW_FORM_block2:
5901 uvalue = byte_get (data, 2);
5902 block_start = data + 2;
5903 data = display_block (block_start, uvalue);
5904 uvalue = * block_start;
5907 case DW_FORM_block4:
5908 uvalue = byte_get (data, 4);
5909 block_start = data + 4;
5910 data = display_block (block_start, uvalue);
5911 uvalue = * block_start;
5915 case DW_FORM_indirect:
5916 warn (_("Unable to handle FORM: %d"), form);
5920 warn (_("Unrecognised form: %d"), form);
5924 /* For some attributes we can display futher information. */
5933 case DW_INL_not_inlined: printf (_("(not inlined)")); break;
5934 case DW_INL_inlined: printf (_("(inlined)")); break;
5935 case DW_INL_declared_not_inlined: printf (_("(declared as inline but ignored)")); break;
5936 case DW_INL_declared_inlined: printf (_("(declared as inline and inlined)")); break;
5937 default: printf (_(" (Unknown inline attribute value: %lx)"), uvalue); break;
5941 case DW_AT_frame_base:
5942 if (uvalue >= DW_OP_reg0 && uvalue <= DW_OP_reg31)
5943 printf ("(reg %ld)", uvalue - DW_OP_reg0);
5946 case DW_AT_language:
5949 case DW_LANG_C: printf ("(non-ANSI C)"); break;
5950 case DW_LANG_C89: printf ("(ANSI C)"); break;
5951 case DW_LANG_C_plus_plus: printf ("(C++)"); break;
5952 case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break;
5953 case DW_LANG_Fortran90: printf ("(Fortran 90)"); break;
5954 case DW_LANG_Modula2: printf ("(Modula 2)"); break;
5955 case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break;
5956 case DW_LANG_Ada83: printf ("(Ada)"); break;
5957 case DW_LANG_Cobol74: printf ("(Cobol 74)"); break;
5958 case DW_LANG_Cobol85: printf ("(Cobol 85)"); break;
5959 case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break;
5960 default: printf ("(Unknown: %lx)", uvalue); break;
5964 case DW_AT_encoding:
5967 case DW_ATE_void: printf ("(void)"); break;
5968 case DW_ATE_address: printf ("(machine address)"); break;
5969 case DW_ATE_boolean: printf ("(boolean)"); break;
5970 case DW_ATE_complex_float: printf ("(complex float)"); break;
5971 case DW_ATE_float: printf ("(float)"); break;
5972 case DW_ATE_signed: printf ("(signed)"); break;
5973 case DW_ATE_signed_char: printf ("(signed char)"); break;
5974 case DW_ATE_unsigned: printf ("(unsigned)"); break;
5975 case DW_ATE_unsigned_char: printf ("(unsigned char)"); break;
5977 if (uvalue >= DW_ATE_lo_user
5978 && uvalue <= DW_ATE_hi_user)
5979 printf ("(user defined type)");
5981 printf ("(unknown type)");
5986 case DW_AT_accessibility:
5989 case DW_ACCESS_public: printf ("(public)"); break;
5990 case DW_ACCESS_protected: printf ("(protected)"); break;
5991 case DW_ACCESS_private: printf ("(private)"); break;
5992 default: printf ("(unknown accessibility)"); break;
5996 case DW_AT_visibility:
5999 case DW_VIS_local: printf ("(local)"); break;
6000 case DW_VIS_exported: printf ("(exported)"); break;
6001 case DW_VIS_qualified: printf ("(qualified)"); break;
6002 default: printf ("(unknown visibility)"); break;
6006 case DW_AT_virtuality:
6009 case DW_VIRTUALITY_none: printf ("(none)"); break;
6010 case DW_VIRTUALITY_virtual: printf ("(virtual)"); break;
6011 case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break;
6012 default: printf ("(unknown virtuality)"); break;
6016 case DW_AT_identifier_case:
6019 case DW_ID_case_sensitive: printf ("(case_sensitive)"); break;
6020 case DW_ID_up_case: printf ("(up_case)"); break;
6021 case DW_ID_down_case: printf ("(down_case)"); break;
6022 case DW_ID_case_insensitive: printf ("(case_insensitive)"); break;
6023 default: printf ("(unknown case)"); break;
6027 case DW_AT_calling_convention:
6030 case DW_CC_normal: printf ("(normal)"); break;
6031 case DW_CC_program: printf ("(program)"); break;
6032 case DW_CC_nocall: printf ("(nocall)"); break;
6034 if (uvalue >= DW_CC_lo_user
6035 && uvalue <= DW_CC_hi_user)
6036 printf ("(user defined)");
6038 printf ("(unknown convention)");
6042 case DW_AT_location:
6043 case DW_AT_data_member_location:
6044 case DW_AT_vtable_elem_location:
6046 decode_location_expression (block_start, pointer_size);
6059 display_debug_info (section, start, file)
6060 Elf32_Internal_Shdr * section;
6061 unsigned char * start;
6064 unsigned char * end = start + section->sh_size;
6065 unsigned char * section_begin = start;
6067 printf (_("The section %s contains:\n\n"), SECTION_NAME (section));
6071 DWARF2_External_CompUnit * external;
6072 DWARF2_Internal_CompUnit compunit;
6073 unsigned char * tags;
6077 external = (DWARF2_External_CompUnit *) start;
6079 compunit.cu_length = BYTE_GET (external->cu_length);
6080 compunit.cu_version = BYTE_GET (external->cu_version);
6081 compunit.cu_abbrev_offset = BYTE_GET (external->cu_abbrev_offset);
6082 compunit.cu_pointer_size = BYTE_GET (external->cu_pointer_size);
6084 tags = start + sizeof (* external);
6085 start += compunit.cu_length + sizeof (external->cu_length);
6087 if (compunit.cu_version != 2)
6089 warn (_("Only version 2 DWARF debug information is currently supported.\n"));
6093 printf (_(" Compilation Unit:\n"));
6094 printf (_(" Length: %ld\n"), compunit.cu_length);
6095 printf (_(" Version: %d\n"), compunit.cu_version);
6096 printf (_(" Abbrev Offset: %ld\n"), compunit.cu_abbrev_offset);
6097 printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size);
6099 if (first_abbrev != NULL)
6102 /* Read in the abbrevs used by this compilation unit. */
6105 Elf32_Internal_Shdr * sec;
6106 unsigned char * begin;
6108 /* Locate the .debug_abbrev section and process it. */
6109 for (i = 0, sec = section_headers;
6110 i < elf_header.e_shnum;
6112 if (strcmp (SECTION_NAME (sec), ".debug_abbrev") == 0)
6115 if (i == -1 || sec->sh_size == 0)
6117 warn (_("Unable to locate .debug_abbrev section!\n"));
6121 GET_DATA_ALLOC (sec->sh_offset, sec->sh_size, begin, unsigned char *,
6122 "debug_abbrev section data");
6124 process_abbrev_section (begin + compunit.cu_abbrev_offset,
6125 begin + sec->sh_size);
6131 while (tags < start)
6134 unsigned long abbrev_number;
6135 abbrev_entry * entry;
6138 abbrev_number = read_leb128 (tags, & bytes_read, 0);
6141 /* A null DIE marks the end of a list of children. */
6142 if (abbrev_number == 0)
6148 /* Scan through the abbreviation list until we reach the
6150 for (entry = first_abbrev;
6151 entry && entry->entry != abbrev_number;
6152 entry = entry->next)
6157 warn (_("Unable to locate entry %lu in the abbreviation table\n"),
6162 printf (_(" <%d><%x>: Abbrev Number: %lu (%s)\n"),
6163 level, tags - section_begin - bytes_read,
6165 get_TAG_name (entry->tag));
6167 for (attr = entry->first_attr; attr; attr = attr->next)
6168 tags = read_and_display_attr (attr->attribute,
6171 compunit.cu_pointer_size);
6173 if (entry->children)
6184 display_debug_aranges (section, start, file)
6185 Elf32_Internal_Shdr * section;
6186 unsigned char * start;
6187 FILE * file ATTRIBUTE_UNUSED;
6189 unsigned char * end = start + section->sh_size;
6191 printf (_("The section %s contains:\n\n"), SECTION_NAME (section));
6195 DWARF2_External_ARange * external;
6196 DWARF2_Internal_ARange arange;
6197 unsigned char * ranges;
6198 unsigned long length;
6199 unsigned long address;
6202 external = (DWARF2_External_ARange *) start;
6204 arange.ar_length = BYTE_GET (external->ar_length);
6205 arange.ar_version = BYTE_GET (external->ar_version);
6206 arange.ar_info_offset = BYTE_GET (external->ar_info_offset);
6207 arange.ar_pointer_size = BYTE_GET (external->ar_pointer_size);
6208 arange.ar_segment_size = BYTE_GET (external->ar_segment_size);
6210 printf (_(" Length: %ld\n"), arange.ar_length);
6211 printf (_(" Version: %d\n"), arange.ar_version);
6212 printf (_(" Offset into .debug_info: %lx\n"), arange.ar_info_offset);
6213 printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
6214 printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
6216 printf (_("\n Address Length\n"));
6218 ranges = start + sizeof (* external);
6220 /* Must pad to an alignment boundary that is twice the pointer size. */
6221 excess = sizeof (*external) % (2 * arange.ar_pointer_size);
6223 ranges += (2 * arange.ar_pointer_size) - excess;
6227 address = byte_get (ranges, arange.ar_pointer_size);
6229 ranges += arange.ar_pointer_size;
6231 length = byte_get (ranges, arange.ar_pointer_size);
6233 ranges += arange.ar_pointer_size;
6235 /* A pair of zeros marks the end of the list. */
6236 if (address == 0 && length == 0)
6239 printf (" %8.8lx %lu\n", address, length);
6242 start += arange.ar_length + sizeof (external->ar_length);
6252 display_debug_not_supported (section, start, file)
6253 Elf32_Internal_Shdr * section;
6254 unsigned char * start ATTRIBUTE_UNUSED;
6255 FILE * file ATTRIBUTE_UNUSED;
6257 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
6258 SECTION_NAME (section));
6263 /* Pre-scan the .debug_info section to record the size of address.
6264 When dumping the .debug_line, we use that size information, assuming
6265 that all compilation units have the same address size. */
6267 prescan_debug_info (section, start, file)
6268 Elf32_Internal_Shdr * section ATTRIBUTE_UNUSED;
6269 unsigned char * start;
6270 FILE * file ATTRIBUTE_UNUSED;
6272 DWARF2_External_CompUnit * external;
6274 external = (DWARF2_External_CompUnit *) start;
6276 debug_line_pointer_size = BYTE_GET (external->cu_pointer_size);
6280 /* A structure containing the name of a debug section and a pointer
6281 to a function that can decode it. The third field is a prescan
6282 function to be run over the section before displaying any of the
6287 int (* display) PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
6288 int (* prescan) PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
6292 { ".debug_info", display_debug_info, prescan_debug_info },
6293 { ".debug_abbrev", display_debug_abbrev, NULL },
6294 { ".debug_line", display_debug_lines, NULL },
6295 { ".debug_aranges", display_debug_aranges, NULL },
6296 { ".debug_pubnames", display_debug_pubnames, NULL },
6297 { ".debug_macinfo", display_debug_not_supported, NULL },
6298 { ".debug_frame", display_debug_not_supported, NULL },
6299 { ".debug_str", display_debug_not_supported, NULL },
6300 { ".debug_static_func", display_debug_not_supported, NULL },
6301 { ".debug_static_vars", display_debug_not_supported, NULL },
6302 { ".debug_types", display_debug_not_supported, NULL },
6303 { ".debug_weaknames", display_debug_not_supported, NULL }
6307 display_debug_section (section, file)
6308 Elf32_Internal_Shdr * section;
6311 char * name = SECTION_NAME (section);
6312 bfd_size_type length;
6313 unsigned char * start;
6316 length = section->sh_size;
6319 printf (_("\nSection '%s' has no debugging data.\n"), name);
6323 GET_DATA_ALLOC (section->sh_offset, length, start, unsigned char *,
6324 "debug section data");
6326 /* See if we know how to display the contents of this section. */
6327 for (i = NUM_ELEM (debug_displays); i--;)
6328 if (strcmp (debug_displays[i].name, name) == 0)
6330 debug_displays[i].display (section, start, file);
6335 printf (_("Unrecognised debug section: %s\n"), name);
6339 /* If we loaded in the abbrev section at some point,
6340 we must release it here. */
6341 if (first_abbrev != NULL)
6348 process_section_contents (file)
6351 Elf32_Internal_Shdr * section;
6357 /* Pre-scan the debug sections to find some debug information not
6358 present in some of them. For the .debug_line, we must find out the
6359 size of address (specified in .debug_info and .debug_aranges). */
6360 for (i = 0, section = section_headers;
6361 i < elf_header.e_shnum && i < num_dump_sects;
6364 char * name = SECTION_NAME (section);
6367 if (section->sh_size == 0)
6370 /* See if there is some pre-scan operation for this section. */
6371 for (j = NUM_ELEM (debug_displays); j--;)
6372 if (strcmp (debug_displays[j].name, name) == 0)
6374 if (debug_displays[j].prescan != NULL)
6376 bfd_size_type length;
6377 unsigned char * start;
6379 length = section->sh_size;
6380 GET_DATA_ALLOC (section->sh_offset, length, start, unsigned char *,
6381 "debug section data");
6383 debug_displays[j].prescan (section, start, file);
6391 for (i = 0, section = section_headers;
6392 i < elf_header.e_shnum && i < num_dump_sects;
6395 #ifdef SUPPORT_DISASSEMBLY
6396 if (dump_sects[i] & DISASS_DUMP)
6397 disassemble_section (section, file);
6399 if (dump_sects[i] & HEX_DUMP)
6400 dump_section (section, file);
6402 if (dump_sects[i] & DEBUG_DUMP)
6403 display_debug_section (section, file);
6406 if (i < num_dump_sects)
6407 warn (_("Some sections were not dumped because they do not exist!\n"));
6413 process_mips_fpe_exception (mask)
6419 if (mask & OEX_FPU_INEX)
6420 fputs ("INEX", stdout), first = 0;
6421 if (mask & OEX_FPU_UFLO)
6422 printf ("%sUFLO", first ? "" : "|"), first = 0;
6423 if (mask & OEX_FPU_OFLO)
6424 printf ("%sOFLO", first ? "" : "|"), first = 0;
6425 if (mask & OEX_FPU_DIV0)
6426 printf ("%sDIV0", first ? "" : "|"), first = 0;
6427 if (mask & OEX_FPU_INVAL)
6428 printf ("%sINVAL", first ? "" : "|");
6431 fputs ("0", stdout);
6435 process_mips_specific (file)
6438 Elf_Internal_Dyn * entry;
6439 size_t liblist_offset = 0;
6440 size_t liblistno = 0;
6441 size_t conflictsno = 0;
6442 size_t options_offset = 0;
6443 size_t conflicts_offset = 0;
6445 /* We have a lot of special sections. Thanks SGI! */
6446 if (dynamic_segment == NULL)
6447 /* No information available. */
6450 for (entry = dynamic_segment; entry->d_tag != DT_NULL; ++entry)
6451 switch (entry->d_tag)
6453 case DT_MIPS_LIBLIST:
6454 liblist_offset = entry->d_un.d_val - loadaddr;
6456 case DT_MIPS_LIBLISTNO:
6457 liblistno = entry->d_un.d_val;
6459 case DT_MIPS_OPTIONS:
6460 options_offset = entry->d_un.d_val - loadaddr;
6462 case DT_MIPS_CONFLICT:
6463 conflicts_offset = entry->d_un.d_val - loadaddr;
6465 case DT_MIPS_CONFLICTNO:
6466 conflictsno = entry->d_un.d_val;
6472 if (liblist_offset != 0 && liblistno != 0 && do_dynamic)
6474 Elf32_External_Lib * elib;
6477 GET_DATA_ALLOC (liblist_offset, liblistno * sizeof (Elf32_External_Lib),
6478 elib, Elf32_External_Lib *, "liblist");
6480 printf ("\nSection '.liblist' contains %d entries:\n", liblistno);
6481 fputs (" Library Time Stamp Checksum Version Flags\n",
6484 for (cnt = 0; cnt < liblistno; ++cnt)
6490 liblist.l_name = BYTE_GET (elib[cnt].l_name);
6491 time = BYTE_GET (elib[cnt].l_time_stamp);
6492 liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum);
6493 liblist.l_version = BYTE_GET (elib[cnt].l_version);
6494 liblist.l_flags = BYTE_GET (elib[cnt].l_flags);
6496 strftime (timebuf, 20, "%Y-%m-%dT%H:%M:%S", gmtime (&time));
6498 printf ("%3d: %-20s %s %#10lx %-7ld", cnt,
6499 dynamic_strings + liblist.l_name, timebuf,
6500 liblist.l_checksum, liblist.l_version);
6502 if (liblist.l_flags == 0)
6513 { " EXACT_MATCH", LL_EXACT_MATCH },
6514 { " IGNORE_INT_VER", LL_IGNORE_INT_VER },
6515 { " REQUIRE_MINOR", LL_REQUIRE_MINOR },
6516 { " EXPORTS", LL_EXPORTS },
6517 { " DELAY_LOAD", LL_DELAY_LOAD },
6518 { " DELTA", LL_DELTA }
6520 int flags = liblist.l_flags;
6524 fcnt < sizeof (l_flags_vals) / sizeof (l_flags_vals[0]);
6526 if ((flags & l_flags_vals[fcnt].bit) != 0)
6528 fputs (l_flags_vals[fcnt].name, stdout);
6529 flags ^= l_flags_vals[fcnt].bit;
6532 printf (" %#x", (unsigned int) flags);
6541 if (options_offset != 0)
6543 Elf_External_Options * eopt;
6544 Elf_Internal_Shdr * sect = section_headers;
6545 Elf_Internal_Options * iopt;
6546 Elf_Internal_Options * option;
6550 /* Find the section header so that we get the size. */
6551 while (sect->sh_type != SHT_MIPS_OPTIONS)
6554 GET_DATA_ALLOC (options_offset, sect->sh_size, eopt,
6555 Elf_External_Options *, "options");
6557 iopt = (Elf_Internal_Options *) malloc ((sect->sh_size / sizeof (eopt))
6561 error (_("Out of memory"));
6567 while (offset < sect->sh_size)
6569 Elf_External_Options * eoption;
6571 eoption = (Elf_External_Options *) ((char *) eopt + offset);
6573 option->kind = BYTE_GET (eoption->kind);
6574 option->size = BYTE_GET (eoption->size);
6575 option->section = BYTE_GET (eoption->section);
6576 option->info = BYTE_GET (eoption->info);
6578 offset += option->size;
6583 printf (_("\nSection '%s' contains %d entries:\n"),
6584 string_table + sect->sh_name, cnt);
6591 switch (option->kind)
6594 /* This shouldn't happen. */
6595 printf (" NULL %d %lx", option->section, option->info);
6598 printf (" REGINFO ");
6599 if (elf_header.e_machine == EM_MIPS)
6602 Elf32_External_RegInfo *ereg;
6603 Elf32_RegInfo reginfo;
6605 ereg = (Elf32_External_RegInfo *) (option + 1);
6606 reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask);
6607 reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
6608 reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
6609 reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
6610 reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
6611 reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value);
6613 printf ("GPR %08lx GP 0x%lx\n",
6615 (unsigned long) reginfo.ri_gp_value);
6616 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
6617 reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
6618 reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
6623 Elf64_External_RegInfo * ereg;
6624 Elf64_Internal_RegInfo reginfo;
6626 ereg = (Elf64_External_RegInfo *) (option + 1);
6627 reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask);
6628 reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
6629 reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
6630 reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
6631 reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
6632 reginfo.ri_gp_value = BYTE_GET8 (ereg->ri_gp_value);
6634 printf ("GPR %08lx GP 0x",
6635 reginfo.ri_gprmask);
6636 printf_vma (reginfo.ri_gp_value);
6639 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
6640 reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
6641 reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
6645 case ODK_EXCEPTIONS:
6646 fputs (" EXCEPTIONS fpe_min(", stdout);
6647 process_mips_fpe_exception (option->info & OEX_FPU_MIN);
6648 fputs (") fpe_max(", stdout);
6649 process_mips_fpe_exception ((option->info & OEX_FPU_MAX) >> 8);
6650 fputs (")", stdout);
6652 if (option->info & OEX_PAGE0)
6653 fputs (" PAGE0", stdout);
6654 if (option->info & OEX_SMM)
6655 fputs (" SMM", stdout);
6656 if (option->info & OEX_FPDBUG)
6657 fputs (" FPDBUG", stdout);
6658 if (option->info & OEX_DISMISS)
6659 fputs (" DISMISS", stdout);
6662 fputs (" PAD ", stdout);
6663 if (option->info & OPAD_PREFIX)
6664 fputs (" PREFIX", stdout);
6665 if (option->info & OPAD_POSTFIX)
6666 fputs (" POSTFIX", stdout);
6667 if (option->info & OPAD_SYMBOL)
6668 fputs (" SYMBOL", stdout);
6671 fputs (" HWPATCH ", stdout);
6672 if (option->info & OHW_R4KEOP)
6673 fputs (" R4KEOP", stdout);
6674 if (option->info & OHW_R8KPFETCH)
6675 fputs (" R8KPFETCH", stdout);
6676 if (option->info & OHW_R5KEOP)
6677 fputs (" R5KEOP", stdout);
6678 if (option->info & OHW_R5KCVTL)
6679 fputs (" R5KCVTL", stdout);
6682 fputs (" FILL ", stdout);
6683 /* XXX Print content of info word? */
6686 fputs (" TAGS ", stdout);
6687 /* XXX Print content of info word? */
6690 fputs (" HWAND ", stdout);
6691 if (option->info & OHWA0_R4KEOP_CHECKED)
6692 fputs (" R4KEOP_CHECKED", stdout);
6693 if (option->info & OHWA0_R4KEOP_CLEAN)
6694 fputs (" R4KEOP_CLEAN", stdout);
6697 fputs (" HWOR ", stdout);
6698 if (option->info & OHWA0_R4KEOP_CHECKED)
6699 fputs (" R4KEOP_CHECKED", stdout);
6700 if (option->info & OHWA0_R4KEOP_CLEAN)
6701 fputs (" R4KEOP_CLEAN", stdout);
6704 printf (" GP_GROUP %#06lx self-contained %#06lx",
6705 option->info & OGP_GROUP,
6706 (option->info & OGP_SELF) >> 16);
6709 printf (" IDENT %#06lx self-contained %#06lx",
6710 option->info & OGP_GROUP,
6711 (option->info & OGP_SELF) >> 16);
6714 /* This shouldn't happen. */
6715 printf (" %3d ??? %d %lx",
6716 option->kind, option->section, option->info);
6720 len = sizeof (*eopt);
6721 while (len < option->size)
6722 if (((char *) option)[len] >= ' '
6723 && ((char *) option)[len] < 0x7f)
6724 printf ("%c", ((char *) option)[len++]);
6726 printf ("\\%03o", ((char *) option)[len++]);
6728 fputs ("\n", stdout);
6735 if (conflicts_offset != 0 && conflictsno != 0)
6737 Elf32_External_Conflict * econf32;
6738 Elf64_External_Conflict * econf64;
6739 Elf32_Conflict * iconf;
6742 if (dynamic_symbols == NULL)
6744 error (_("conflict list with without table"));
6748 iconf = (Elf32_Conflict *) malloc (conflictsno * sizeof (*iconf));
6751 error (_("Out of memory"));
6757 GET_DATA_ALLOC (conflicts_offset, conflictsno * sizeof (*econf32),
6758 econf32, Elf32_External_Conflict *, "conflict");
6760 for (cnt = 0; cnt < conflictsno; ++cnt)
6761 iconf[cnt] = BYTE_GET (econf32[cnt]);
6765 GET_DATA_ALLOC (conflicts_offset, conflictsno * sizeof (*econf64),
6766 econf64, Elf64_External_Conflict *, "conflict");
6768 for (cnt = 0; cnt < conflictsno; ++cnt)
6769 iconf[cnt] = BYTE_GET (econf64[cnt]);
6772 printf (_("\nSection '.conflict' contains %d entries:\n"), conflictsno);
6773 puts (_(" Num: Index Value Name"));
6775 for (cnt = 0; cnt < conflictsno; ++cnt)
6777 Elf_Internal_Sym * psym = &dynamic_symbols[iconf[cnt]];
6779 printf ("%5u: %8lu ", cnt, iconf[cnt]);
6780 print_vma (psym->st_value, FULL_HEX);
6781 printf (" %s\n", dynamic_strings + psym->st_name);
6791 get_note_type (e_type)
6794 static char buff[64];
6798 case NT_PRSTATUS: return _("NT_PRSTATUS (prstatus structure)");
6799 case NT_FPREGSET: return _("NT_FPREGSET (floating point registers)");
6800 case NT_PRPSINFO: return _("NT_PRPSINFO (prpsinfo structure)");
6801 case NT_TASKSTRUCT: return _("NT_TASKSTRUCT (task structure)");
6802 case NT_PSTATUS: return _("NT_PSTATUS (pstatus structure)");
6803 case NT_FPREGS: return _("NT_FPREGS (floating point registers)");
6804 case NT_PSINFO: return _("NT_PSINFO (psinfo structure)");
6805 case NT_LWPSTATUS: return _("NT_LWPSTATUS (lwpstatus_t structure)");
6806 case NT_LWPSINFO: return _("NT_LWPSINFO (lwpsinfo_t structure)");
6808 sprintf (buff, _("Unknown note type: (0x%08x)"), e_type);
6813 /* Note that by the ELF standard, the name field is already null byte
6814 terminated, and namesz includes the terminating null byte.
6815 I.E. the value of namesz for the name "FSF" is 4.
6817 If the value of namesz is zero, there is no name present. */
6819 process_note (pnote)
6820 Elf32_Internal_Note * pnote;
6822 printf (" %s\t\t0x%08lx\t%s\n",
6823 pnote->namesz ? pnote->namedata : "(NONE)",
6824 pnote->descsz, get_note_type (pnote->type));
6830 process_corefile_note_segment (file, offset, length)
6835 Elf_External_Note * pnotes;
6836 Elf_External_Note * external;
6842 GET_DATA_ALLOC (offset, length, pnotes, Elf_External_Note *, "notes");
6846 printf (_("\nNotes at offset 0x%08lx with length 0x%08lx:\n"), offset, length);
6847 printf (_(" Owner\t\tData size\tDescription\n"));
6849 while (external < (Elf_External_Note *)((char *) pnotes + length))
6851 Elf32_Internal_Note inote;
6854 inote.type = BYTE_GET (external->type);
6855 inote.namesz = BYTE_GET (external->namesz);
6856 inote.namedata = external->name;
6857 inote.descsz = BYTE_GET (external->descsz);
6858 inote.descdata = inote.namedata + align_power (inote.namesz, 2);
6859 inote.descpos = offset + (inote.descdata - (char *) pnotes);
6861 external = (Elf_External_Note *)(inote.descdata + align_power (inote.descsz, 2));
6863 /* Verify that name is null terminated. It appears that at least
6864 one version of Linux (RedHat 6.0) generates corefiles that don't
6865 comply with the ELF spec by failing to include the null byte in
6867 if (inote.namedata[inote.namesz] != '\0')
6869 temp = malloc (inote.namesz + 1);
6873 error (_("Out of memory\n"));
6878 strncpy (temp, inote.namedata, inote.namesz);
6879 temp[inote.namesz] = 0;
6881 /* warn (_("'%s' NOTE name not properly null terminated\n"), temp); */
6882 inote.namedata = temp;
6885 res &= process_note (& inote);
6900 process_corefile_note_segments (file)
6903 Elf_Internal_Phdr * program_headers;
6904 Elf_Internal_Phdr * segment;
6908 program_headers = (Elf_Internal_Phdr *) malloc
6909 (elf_header.e_phnum * sizeof (Elf_Internal_Phdr));
6911 if (program_headers == NULL)
6913 error (_("Out of memory\n"));
6918 i = get_32bit_program_headers (file, program_headers);
6920 i = get_64bit_program_headers (file, program_headers);
6924 free (program_headers);
6928 for (i = 0, segment = program_headers;
6929 i < elf_header.e_phnum;
6932 if (segment->p_type == PT_NOTE)
6933 res &= process_corefile_note_segment (file,
6934 (bfd_vma) segment->p_offset,
6935 (bfd_vma) segment->p_filesz);
6938 free (program_headers);
6944 process_corefile_contents (file)
6947 /* If we have not been asked to display the notes then do nothing. */
6951 /* If file is not a core file then exit. */
6952 if (elf_header.e_type != ET_CORE)
6955 /* No program headers means no NOTE segment. */
6956 if (elf_header.e_phnum == 0)
6958 printf (_("No note segments present in the core file.\n"));
6962 return process_corefile_note_segments (file);
6966 process_arch_specific (file)
6972 switch (elf_header.e_machine)
6975 case EM_MIPS_RS4_BE:
6976 return process_mips_specific (file);
6985 get_file_header (file)
6988 /* Read in the identity array. */
6989 if (fread (elf_header.e_ident, EI_NIDENT, 1, file) != 1)
6992 /* Determine how to read the rest of the header. */
6993 switch (elf_header.e_ident [EI_DATA])
6995 default: /* fall through */
6996 case ELFDATANONE: /* fall through */
6997 case ELFDATA2LSB: byte_get = byte_get_little_endian; break;
6998 case ELFDATA2MSB: byte_get = byte_get_big_endian; break;
7001 /* For now we only support 32 bit and 64 bit ELF files. */
7002 is_32bit_elf = (elf_header.e_ident [EI_CLASS] != ELFCLASS64);
7004 /* Read in the rest of the header. */
7007 Elf32_External_Ehdr ehdr32;
7009 if (fread (ehdr32.e_type, sizeof (ehdr32) - EI_NIDENT, 1, file) != 1)
7012 elf_header.e_type = BYTE_GET (ehdr32.e_type);
7013 elf_header.e_machine = BYTE_GET (ehdr32.e_machine);
7014 elf_header.e_version = BYTE_GET (ehdr32.e_version);
7015 elf_header.e_entry = BYTE_GET (ehdr32.e_entry);
7016 elf_header.e_phoff = BYTE_GET (ehdr32.e_phoff);
7017 elf_header.e_shoff = BYTE_GET (ehdr32.e_shoff);
7018 elf_header.e_flags = BYTE_GET (ehdr32.e_flags);
7019 elf_header.e_ehsize = BYTE_GET (ehdr32.e_ehsize);
7020 elf_header.e_phentsize = BYTE_GET (ehdr32.e_phentsize);
7021 elf_header.e_phnum = BYTE_GET (ehdr32.e_phnum);
7022 elf_header.e_shentsize = BYTE_GET (ehdr32.e_shentsize);
7023 elf_header.e_shnum = BYTE_GET (ehdr32.e_shnum);
7024 elf_header.e_shstrndx = BYTE_GET (ehdr32.e_shstrndx);
7028 Elf64_External_Ehdr ehdr64;
7030 /* If we have been compiled with sizeof (bfd_vma) == 4, then
7031 we will not be able to cope with the 64bit data found in
7032 64 ELF files. Detect this now and abort before we start
7033 overwritting things. */
7034 if (sizeof (bfd_vma) < 8)
7036 error (_("This instance of readelf has been built without support for a\n"));
7037 error (_("64 bit data type and so it cannot read 64 bit ELF files.\n"));
7041 if (fread (ehdr64.e_type, sizeof (ehdr64) - EI_NIDENT, 1, file) != 1)
7044 elf_header.e_type = BYTE_GET (ehdr64.e_type);
7045 elf_header.e_machine = BYTE_GET (ehdr64.e_machine);
7046 elf_header.e_version = BYTE_GET (ehdr64.e_version);
7047 elf_header.e_entry = BYTE_GET8 (ehdr64.e_entry);
7048 elf_header.e_phoff = BYTE_GET8 (ehdr64.e_phoff);
7049 elf_header.e_shoff = BYTE_GET8 (ehdr64.e_shoff);
7050 elf_header.e_flags = BYTE_GET (ehdr64.e_flags);
7051 elf_header.e_ehsize = BYTE_GET (ehdr64.e_ehsize);
7052 elf_header.e_phentsize = BYTE_GET (ehdr64.e_phentsize);
7053 elf_header.e_phnum = BYTE_GET (ehdr64.e_phnum);
7054 elf_header.e_shentsize = BYTE_GET (ehdr64.e_shentsize);
7055 elf_header.e_shnum = BYTE_GET (ehdr64.e_shnum);
7056 elf_header.e_shstrndx = BYTE_GET (ehdr64.e_shstrndx);
7063 process_file (file_name)
7067 struct stat statbuf;
7070 if (stat (file_name, & statbuf) < 0)
7072 error (_("Cannot stat input file %s.\n"), file_name);
7076 file = fopen (file_name, "rb");
7079 error (_("Input file %s not found.\n"), file_name);
7083 if (! get_file_header (file))
7085 error (_("%s: Failed to read file header\n"), file_name);
7090 /* Initialise per file variables. */
7091 for (i = NUM_ELEM (version_info); i--;)
7092 version_info[i] = 0;
7094 for (i = NUM_ELEM (dynamic_info); i--;)
7095 dynamic_info[i] = 0;
7097 /* Process the file. */
7099 printf (_("\nFile: %s\n"), file_name);
7101 if (! process_file_header ())
7107 process_section_headers (file);
7109 process_program_headers (file);
7111 process_dynamic_segment (file);
7113 process_relocs (file);
7115 process_symbol_table (file);
7117 process_syminfo (file);
7119 process_version_sections (file);
7121 process_section_contents (file);
7123 process_corefile_contents (file);
7125 process_arch_specific (file);
7129 if (section_headers)
7131 free (section_headers);
7132 section_headers = NULL;
7137 free (string_table);
7138 string_table = NULL;
7141 if (dynamic_strings)
7143 free (dynamic_strings);
7144 dynamic_strings = NULL;
7147 if (dynamic_symbols)
7149 free (dynamic_symbols);
7150 dynamic_symbols = NULL;
7151 num_dynamic_syms = 0;
7154 if (dynamic_syminfo)
7156 free (dynamic_syminfo);
7157 dynamic_syminfo = NULL;
7161 #ifdef SUPPORT_DISASSEMBLY
7162 /* Needed by the i386 disassembler. For extra credit, someone could
7163 fix this so that we insert symbolic addresses here, esp for GOT/PLT
7167 print_address (unsigned int addr, FILE * outfile)
7169 fprintf (outfile,"0x%8.8x", addr);
7172 /* Needed by the i386 disassembler. */
7174 db_task_printsym (unsigned int addr)
7176 print_address (addr, stderr);
7185 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
7186 setlocale (LC_MESSAGES, "");
7188 bindtextdomain (PACKAGE, LOCALEDIR);
7189 textdomain (PACKAGE);
7191 parse_args (argc, argv);
7193 if (optind < (argc - 1))
7196 while (optind < argc)
7197 process_file (argv [optind ++]);
7199 if (dump_sects != NULL)