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"
74 #ifdef ANSI_PROTOTYPES
80 char * program_name
= "readelf";
81 unsigned int dynamic_addr
;
82 bfd_size_type dynamic_size
;
83 unsigned int rela_addr
;
84 unsigned int rela_size
;
85 char * dynamic_strings
;
87 unsigned long num_dynamic_syms
;
88 Elf_Internal_Sym
* dynamic_symbols
;
89 Elf_Internal_Syminfo
* dynamic_syminfo
;
90 unsigned long dynamic_syminfo_offset
;
91 unsigned int dynamic_syminfo_nent
;
92 char program_interpreter
[64];
93 int dynamic_info
[DT_JMPREL
+ 1];
96 Elf_Internal_Ehdr elf_header
;
97 Elf_Internal_Shdr
* section_headers
;
98 Elf_Internal_Dyn
* dynamic_segment
;
105 int do_using_dynamic
;
112 int do_debug_abbrevs
;
114 int do_debug_pubnames
;
115 int do_debug_aranges
;
119 /* A dynamic array of flags indicating which sections require dumping. */
120 char * dump_sects
= NULL
;
121 unsigned int num_dump_sects
= 0;
123 #define HEX_DUMP (1 << 0)
124 #define DISASS_DUMP (1 << 1)
125 #define DEBUG_DUMP (1 << 2)
127 /* Forward declarations for dumb compilers. */
128 static bfd_vma (* byte_get
) PARAMS ((unsigned char *, int));
129 static bfd_vma byte_get_little_endian
PARAMS ((unsigned char *, int));
130 static bfd_vma byte_get_big_endian
PARAMS ((unsigned char *, int));
131 static const char * get_mips_dynamic_type
PARAMS ((unsigned long));
132 static const char * get_dynamic_type
PARAMS ((unsigned long));
133 static int dump_relocations
PARAMS ((FILE *, unsigned long, unsigned long, Elf_Internal_Sym
*, unsigned long, char *, int));
134 static char * get_file_type
PARAMS ((unsigned));
135 static char * get_machine_name
PARAMS ((unsigned));
136 static char * get_machine_flags
PARAMS ((unsigned, unsigned));
137 static const char * get_mips_segment_type
PARAMS ((unsigned long));
138 static const char * get_segment_type
PARAMS ((unsigned long));
139 static const char * get_mips_section_type_name
PARAMS ((unsigned int));
140 static const char * get_section_type_name
PARAMS ((unsigned int));
141 static char * get_symbol_binding
PARAMS ((unsigned int));
142 static char * get_symbol_type
PARAMS ((unsigned int));
143 static void usage
PARAMS ((void));
144 static void parse_args
PARAMS ((int, char **));
145 static int process_file_header
PARAMS ((void));
146 static int process_program_headers
PARAMS ((FILE *));
147 static int process_section_headers
PARAMS ((FILE *));
148 static void dynamic_segment_mips_val
PARAMS ((Elf_Internal_Dyn
*));
149 static int process_dynamic_segment
PARAMS ((FILE *));
150 static int process_symbol_table
PARAMS ((FILE *));
151 static int process_section_contents
PARAMS ((FILE *));
152 static void process_file
PARAMS ((char *));
153 static int process_relocs
PARAMS ((FILE *));
154 static int process_version_sections
PARAMS ((FILE *));
155 static char * get_ver_flags
PARAMS ((unsigned int));
156 static char * get_symbol_index_type
PARAMS ((unsigned int));
157 static int get_32bit_section_headers
PARAMS ((FILE *));
158 static int get_64bit_section_headers
PARAMS ((FILE *));
159 static int get_32bit_program_headers
PARAMS ((FILE *, Elf_Internal_Phdr
*));
160 static int get_64bit_program_headers
PARAMS ((FILE *, Elf_Internal_Phdr
*));
161 static int get_file_header
PARAMS ((FILE *));
162 static Elf_Internal_Sym
* get_32bit_elf_symbols
PARAMS ((FILE *, unsigned long, unsigned long));
163 static Elf_Internal_Sym
* get_64bit_elf_symbols
PARAMS ((FILE *, unsigned long, unsigned long));
164 static int * get_dynamic_data
PARAMS ((FILE *, unsigned int));
165 static int get_32bit_dynamic_segment
PARAMS ((FILE *));
166 static int get_64bit_dynamic_segment
PARAMS ((FILE *));
167 #ifdef SUPPORT_DISASSEMBLY
168 static int disassemble_section
PARAMS ((Elf32_Internal_Shdr
*, FILE *));
170 static int dump_section
PARAMS ((Elf32_Internal_Shdr
*, FILE *));
171 static int display_debug_section
PARAMS ((Elf32_Internal_Shdr
*, FILE *));
172 static int display_debug_info
PARAMS ((Elf32_Internal_Shdr
*, unsigned char *, FILE *));
173 static int display_debug_not_supported
PARAMS ((Elf32_Internal_Shdr
*, unsigned char *, FILE *));
174 static int display_debug_lines
PARAMS ((Elf32_Internal_Shdr
*, unsigned char *, FILE *));
175 static int display_debug_abbrev
PARAMS ((Elf32_Internal_Shdr
*, unsigned char *, FILE *));
176 static int display_debug_aranges
PARAMS ((Elf32_Internal_Shdr
*, unsigned char *, FILE *));
177 static unsigned char * process_abbrev_section
PARAMS ((unsigned char *, unsigned char *));
178 static unsigned long read_leb128
PARAMS ((unsigned char *, int *, int));
179 static int process_extended_line_op
PARAMS ((unsigned char *, int));
180 static void reset_state_machine
PARAMS ((int));
181 static char * get_TAG_name
PARAMS ((unsigned long));
182 static char * get_AT_name
PARAMS ((unsigned long));
183 static char * get_FORM_name
PARAMS ((unsigned long));
184 static void free_abbrevs
PARAMS ((void));
185 static void add_abbrev
PARAMS ((unsigned long, unsigned long, int));
186 static void add_abbrev_attr
PARAMS ((unsigned long, unsigned long));
187 static unsigned char * read_and_display_attr
PARAMS ((unsigned long, unsigned long, unsigned char *, unsigned long));
188 static unsigned char * display_block
PARAMS ((unsigned char *, unsigned long));
189 static void decode_location_expression
PARAMS ((unsigned char *, unsigned int));
190 static void request_dump
PARAMS ((unsigned int, char));
191 static const char * get_elf_class
PARAMS ((unsigned char));
192 static const char * get_data_encoding
PARAMS ((unsigned char));
193 static const char * get_osabi_name
PARAMS ((unsigned char));
194 static int guess_is_rela
PARAMS ((unsigned long));
196 typedef int Elf32_Word
;
204 #define SECTION_NAME(X) (string_table + (X)->sh_name)
206 #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
208 #define BYTE_GET(field) byte_get (field, sizeof (field))
210 /* If we can support a 64 bit data type then BFD64 should be defined
211 and sizeof (bfd_vma) == 8. In this case when translating from an
212 external 8 byte field to an internal field, we can assume that the
213 internal field is also 8 bytes wide and so we can extact all the data.
214 If, however, BFD64 is not defined, then we must assume that the
215 internal data structure only has 4 byte wide fields that are the
216 equivalent of the 8 byte wide external counterparts, and so we must
217 truncate the data. */
219 #define BYTE_GET8(field) byte_get (field, -8)
221 #define BYTE_GET8(field) byte_get (field, 8)
224 #define NUM_ELEM(array) (sizeof (array) / sizeof ((array)[0]))
226 #define GET_DATA_ALLOC(offset, size, var, type, reason) \
227 if (fseek (file, offset, SEEK_SET)) \
229 error (_("Unable to seek to start of %s at %x\n"), reason, offset); \
233 var = (type) malloc (size); \
237 error (_("Out of memory allocating %d bytes for %s\n"), size, reason); \
241 if (fread (var, size, 1, file) != 1) \
243 error (_("Unable to read in %d bytes of %s\n"), size, reason); \
250 #define GET_DATA(offset, var, reason) \
251 if (fseek (file, offset, SEEK_SET)) \
253 error (_("Unable to seek to %x for %s\n"), offset, reason); \
256 else if (fread (& var, sizeof (var), 1, file) != 1) \
258 error (_("Unable to read data at %x for %s\n"), offset, reason); \
262 #define GET_ELF_SYMBOLS(file, offset, size) \
263 (is_32bit_elf ? get_32bit_elf_symbols (file, offset, size) \
264 : get_64bit_elf_symbols (file, offset, size))
267 #ifdef ANSI_PROTOTYPES
269 error (const char * message
, ...)
273 fprintf (stderr
, _("%s: Error: "), program_name
);
274 va_start (args
, message
);
275 vfprintf (stderr
, message
, args
);
281 warn (const char * message
, ...)
285 fprintf (stderr
, _("%s: Warning: "), program_name
);
286 va_start (args
, message
);
287 vfprintf (stderr
, message
, args
);
299 fprintf (stderr
, _("%s: Error: "), program_name
);
301 message
= va_arg (args
, char *);
302 vfprintf (stderr
, message
, args
);
314 fprintf (stderr
, _("%s: Warning: "), program_name
);
316 message
= va_arg (args
, char *);
317 vfprintf (stderr
, message
, args
);
324 byte_get_little_endian (field
, size
)
325 unsigned char * field
;
334 return ((unsigned int) (field
[0]))
335 | (((unsigned int) (field
[1])) << 8);
338 /* We want to extract data from an 8 byte wide field and
339 place it into a 4 byte wide field. Since this is a little
340 endian source we can juts use the 4 byte extraction code. */
343 return ((unsigned long) (field
[0]))
344 | (((unsigned long) (field
[1])) << 8)
345 | (((unsigned long) (field
[2])) << 16)
346 | (((unsigned long) (field
[3])) << 24);
350 /* This is a special case, generated by the BYTE_GET8 macro.
351 It means that we are loading an 8 byte value from a field
352 in an external structure into an 8 byte value in a field
353 in an internal strcuture. */
354 return ((bfd_vma
) (field
[0]))
355 | (((bfd_vma
) (field
[1])) << 8)
356 | (((bfd_vma
) (field
[2])) << 16)
357 | (((bfd_vma
) (field
[3])) << 24)
358 | (((bfd_vma
) (field
[4])) << 32)
359 | (((bfd_vma
) (field
[5])) << 40)
360 | (((bfd_vma
) (field
[6])) << 48)
361 | (((bfd_vma
) (field
[7])) << 56);
364 error (_("Unhandled data length: %d\n"), size
);
370 byte_get_big_endian (field
, size
)
371 unsigned char * field
;
380 return ((unsigned int) (field
[1])) | (((int) (field
[0])) << 8);
383 return ((unsigned long) (field
[3]))
384 | (((unsigned long) (field
[2])) << 8)
385 | (((unsigned long) (field
[1])) << 16)
386 | (((unsigned long) (field
[0])) << 24);
389 /* Although we are extracing data from an 8 byte wide field, we
390 are returning only 4 bytes of data. */
391 return ((unsigned long) (field
[7]))
392 | (((unsigned long) (field
[6])) << 8)
393 | (((unsigned long) (field
[5])) << 16)
394 | (((unsigned long) (field
[4])) << 24);
398 /* This is a special case, generated by the BYTE_GET8 macro.
399 It means that we are loading an 8 byte value from a field
400 in an external structure into an 8 byte value in a field
401 in an internal strcuture. */
402 return ((bfd_vma
) (field
[7]))
403 | (((bfd_vma
) (field
[6])) << 8)
404 | (((bfd_vma
) (field
[5])) << 16)
405 | (((bfd_vma
) (field
[4])) << 24)
406 | (((bfd_vma
) (field
[3])) << 32)
407 | (((bfd_vma
) (field
[2])) << 40)
408 | (((bfd_vma
) (field
[1])) << 48)
409 | (((bfd_vma
) (field
[0])) << 56);
413 error (_("Unhandled data length: %d\n"), size
);
419 /* Guess the relocation sized based on the sized commonly used by the specific machine. */
421 guess_is_rela (e_machine
)
422 unsigned long e_machine
;
426 /* Targets that use REL relocations. */
437 /* Targets that use RELA relocations. */
445 case EM_CYGNUS_MN10200
:
446 case EM_CYGNUS_MN10300
:
454 warn (_("Don't know about relocations on this machine architecture\n"));
459 /* Display the contents of the relocation data found at the specified offset. */
461 dump_relocations (file
, rel_offset
, rel_size
, symtab
, nsyms
, strtab
, is_rela
)
463 unsigned long rel_offset
;
464 unsigned long rel_size
;
465 Elf_Internal_Sym
* symtab
;
471 Elf_Internal_Rel
* rels
;
472 Elf_Internal_Rela
* relas
;
475 if (is_rela
== UNKNOWN
)
476 is_rela
= guess_is_rela (elf_header
.e_machine
);
482 Elf32_External_Rela
* erelas
;
484 GET_DATA_ALLOC (rel_offset
, rel_size
, erelas
,
485 Elf32_External_Rela
*, "relocs");
487 rel_size
= rel_size
/ sizeof (Elf32_External_Rela
);
489 relas
= (Elf_Internal_Rela
*)
490 malloc (rel_size
* sizeof (Elf_Internal_Rela
));
494 error(_("out of memory parsing relocs"));
498 for (i
= 0; i
< rel_size
; i
++)
500 relas
[i
].r_offset
= BYTE_GET (erelas
[i
].r_offset
);
501 relas
[i
].r_info
= BYTE_GET (erelas
[i
].r_info
);
502 relas
[i
].r_addend
= BYTE_GET (erelas
[i
].r_addend
);
507 rels
= (Elf_Internal_Rel
*) relas
;
511 Elf64_External_Rela
* erelas
;
513 GET_DATA_ALLOC (rel_offset
, rel_size
, erelas
,
514 Elf64_External_Rela
*, "relocs");
516 rel_size
= rel_size
/ sizeof (Elf64_External_Rela
);
518 relas
= (Elf_Internal_Rela
*)
519 malloc (rel_size
* sizeof (Elf_Internal_Rela
));
523 error(_("out of memory parsing relocs"));
527 for (i
= 0; i
< rel_size
; i
++)
529 relas
[i
].r_offset
= BYTE_GET8 (erelas
[i
].r_offset
);
530 relas
[i
].r_info
= BYTE_GET8 (erelas
[i
].r_info
);
531 relas
[i
].r_addend
= BYTE_GET8 (erelas
[i
].r_addend
);
536 rels
= (Elf_Internal_Rel
*) relas
;
543 Elf32_External_Rel
* erels
;
545 GET_DATA_ALLOC (rel_offset
, rel_size
, erels
,
546 Elf32_External_Rel
*, "relocs");
548 rel_size
= rel_size
/ sizeof (Elf32_External_Rel
);
550 rels
= (Elf_Internal_Rel
*)
551 malloc (rel_size
* sizeof (Elf_Internal_Rel
));
555 error(_("out of memory parsing relocs"));
559 for (i
= 0; i
< rel_size
; i
++)
561 rels
[i
].r_offset
= BYTE_GET (erels
[i
].r_offset
);
562 rels
[i
].r_info
= BYTE_GET (erels
[i
].r_info
);
567 relas
= (Elf_Internal_Rela
*) rels
;
571 Elf64_External_Rel
* erels
;
573 GET_DATA_ALLOC (rel_offset
, rel_size
, erels
,
574 Elf64_External_Rel
*, "relocs");
576 rel_size
= rel_size
/ sizeof (Elf64_External_Rel
);
578 rels
= (Elf_Internal_Rel
*)
579 malloc (rel_size
* sizeof (Elf_Internal_Rel
));
583 error(_("out of memory parsing relocs"));
587 for (i
= 0; i
< rel_size
; i
++)
589 rels
[i
].r_offset
= BYTE_GET8 (erels
[i
].r_offset
);
590 rels
[i
].r_info
= BYTE_GET8 (erels
[i
].r_info
);
595 relas
= (Elf_Internal_Rela
*) rels
;
601 (_(" Offset Info Type Symbol's Value Symbol's Name Addend\n"));
604 (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
606 for (i
= 0; i
< rel_size
; i
++)
611 bfd_vma symtab_index
;
616 offset
= relas
[i
].r_offset
;
617 info
= relas
[i
].r_info
;
621 offset
= rels
[i
].r_offset
;
622 info
= rels
[i
].r_info
;
627 type
= ELF32_R_TYPE (info
);
628 symtab_index
= ELF32_R_SYM (info
);
632 if (elf_header
.e_machine
== EM_SPARCV9
)
633 type
= ELF64_R_TYPE_ID (info
);
635 type
= ELF64_R_TYPE (info
);
636 /* The #ifdef BFD64 below is to prevent a compile time warning.
637 We know that if we do not have a 64 bit data type that we
638 will never execute this code anyway. */
640 symtab_index
= ELF64_R_SYM (info
);
644 #ifdef _bfd_int64_low
645 printf (" %8.8lx %5.5lx ", _bfd_int64_low (offset
), _bfd_int64_low (info
));
647 printf (" %8.8lx %5.5lx ", offset
, info
);
650 switch (elf_header
.e_machine
)
657 rtype
= elf_m32r_reloc_type (type
);
662 rtype
= elf_i386_reloc_type (type
);
666 rtype
= elf_m68k_reloc_type (type
);
670 rtype
= elf_i960_reloc_type (type
);
677 rtype
= elf_sparc_reloc_type (type
);
681 rtype
= v850_reloc_type (type
);
685 rtype
= elf_d10v_reloc_type (type
);
689 rtype
= elf_d30v_reloc_type (type
);
693 rtype
= elf_sh_reloc_type (type
);
696 case EM_CYGNUS_MN10300
:
697 rtype
= elf_mn10300_reloc_type (type
);
700 case EM_CYGNUS_MN10200
:
701 rtype
= elf_mn10200_reloc_type (type
);
705 rtype
= elf_fr30_reloc_type (type
);
709 rtype
= elf_mcore_reloc_type (type
);
713 rtype
= elf_ppc_reloc_type (type
);
718 rtype
= elf_mips_reloc_type (type
);
722 rtype
= elf_alpha_reloc_type (type
);
726 rtype
= elf_arm_reloc_type (type
);
730 rtype
= elf_arc_reloc_type (type
);
734 rtype
= elf_hppa_reloc_type (type
);
739 #ifdef _bfd_int64_low
740 printf (_("unrecognised: %-7lx"), _bfd_int64_low (type
));
742 printf (_("unrecognised: %-7lx"), type
);
745 printf ("%-21.21s", rtype
);
751 if (symtab_index
>= nsyms
)
752 printf (" bad symbol index: %08lx", (unsigned long) symtab_index
);
755 Elf_Internal_Sym
* psym
;
757 psym
= symtab
+ symtab_index
;
759 printf (" %08lx ", (unsigned long) psym
->st_value
);
761 if (psym
->st_name
== 0)
763 SECTION_NAME (section_headers
+ psym
->st_shndx
));
764 else if (strtab
== NULL
)
765 printf (_("<string table index %3ld>"), psym
->st_name
);
767 printf ("%-25.25s", strtab
+ psym
->st_name
);
770 printf (" + %lx", (unsigned long) relas
[i
].r_addend
);
775 printf ("%34c%lx", ' ', (unsigned long) relas
[i
].r_addend
);
777 if (elf_header
.e_machine
== EM_SPARCV9
778 && !strcmp (rtype
, "R_SPARC_OLO10"))
779 printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (info
));
790 get_mips_dynamic_type (type
)
795 case DT_MIPS_RLD_VERSION
: return "MIPS_RLD_VERSION";
796 case DT_MIPS_TIME_STAMP
: return "MIPS_TIME_STAMP";
797 case DT_MIPS_ICHECKSUM
: return "MIPS_ICHECKSUM";
798 case DT_MIPS_IVERSION
: return "MIPS_IVERSION";
799 case DT_MIPS_FLAGS
: return "MIPS_FLAGS";
800 case DT_MIPS_BASE_ADDRESS
: return "MIPS_BASE_ADDRESS";
801 case DT_MIPS_MSYM
: return "MIPS_MSYM";
802 case DT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
803 case DT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
804 case DT_MIPS_LOCAL_GOTNO
: return "MIPS_LOCAL_GOTNO";
805 case DT_MIPS_CONFLICTNO
: return "MIPS_CONFLICTNO";
806 case DT_MIPS_LIBLISTNO
: return "MIPS_LIBLISTNO";
807 case DT_MIPS_SYMTABNO
: return "MIPS_SYMTABNO";
808 case DT_MIPS_UNREFEXTNO
: return "MIPS_UNREFEXTNO";
809 case DT_MIPS_GOTSYM
: return "MIPS_GOTSYM";
810 case DT_MIPS_HIPAGENO
: return "MIPS_HIPAGENO";
811 case DT_MIPS_RLD_MAP
: return "MIPS_RLD_MAP";
812 case DT_MIPS_DELTA_CLASS
: return "MIPS_DELTA_CLASS";
813 case DT_MIPS_DELTA_CLASS_NO
: return "MIPS_DELTA_CLASS_NO";
814 case DT_MIPS_DELTA_INSTANCE
: return "MIPS_DELTA_INSTANCE";
815 case DT_MIPS_DELTA_INSTANCE_NO
: return "MIPS_DELTA_INSTANCE_NO";
816 case DT_MIPS_DELTA_RELOC
: return "MIPS_DELTA_RELOC";
817 case DT_MIPS_DELTA_RELOC_NO
: return "MIPS_DELTA_RELOC_NO";
818 case DT_MIPS_DELTA_SYM
: return "MIPS_DELTA_SYM";
819 case DT_MIPS_DELTA_SYM_NO
: return "MIPS_DELTA_SYM_NO";
820 case DT_MIPS_DELTA_CLASSSYM
: return "MIPS_DELTA_CLASSSYM";
821 case DT_MIPS_DELTA_CLASSSYM_NO
: return "MIPS_DELTA_CLASSSYM_NO";
822 case DT_MIPS_CXX_FLAGS
: return "MIPS_CXX_FLAGS";
823 case DT_MIPS_PIXIE_INIT
: return "MIPS_PIXIE_INIT";
824 case DT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
825 case DT_MIPS_LOCALPAGE_GOTIDX
: return "MIPS_LOCALPAGE_GOTIDX";
826 case DT_MIPS_LOCAL_GOTIDX
: return "MIPS_LOCAL_GOTIDX";
827 case DT_MIPS_HIDDEN_GOTIDX
: return "MIPS_HIDDEN_GOTIDX";
828 case DT_MIPS_PROTECTED_GOTIDX
: return "MIPS_PROTECTED_GOTIDX";
829 case DT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
830 case DT_MIPS_INTERFACE
: return "MIPS_INTERFACE";
831 case DT_MIPS_DYNSTR_ALIGN
: return "MIPS_DYNSTR_ALIGN";
832 case DT_MIPS_INTERFACE_SIZE
: return "MIPS_INTERFACE_SIZE";
833 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR
: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
834 case DT_MIPS_PERF_SUFFIX
: return "MIPS_PERF_SUFFIX";
835 case DT_MIPS_COMPACT_SIZE
: return "MIPS_COMPACT_SIZE";
836 case DT_MIPS_GP_VALUE
: return "MIPS_GP_VALUE";
837 case DT_MIPS_AUX_DYNAMIC
: return "MIPS_AUX_DYNAMIC";
844 get_dynamic_type (type
)
847 static char buff
[32];
851 case DT_NULL
: return "NULL";
852 case DT_NEEDED
: return "NEEDED";
853 case DT_PLTRELSZ
: return "PLTRELSZ";
854 case DT_PLTGOT
: return "PLTGOT";
855 case DT_HASH
: return "HASH";
856 case DT_STRTAB
: return "STRTAB";
857 case DT_SYMTAB
: return "SYMTAB";
858 case DT_RELA
: return "RELA";
859 case DT_RELASZ
: return "RELASZ";
860 case DT_RELAENT
: return "RELAENT";
861 case DT_STRSZ
: return "STRSZ";
862 case DT_SYMENT
: return "SYMENT";
863 case DT_INIT
: return "INIT";
864 case DT_FINI
: return "FINI";
865 case DT_SONAME
: return "SONAME";
866 case DT_RPATH
: return "RPATH";
867 case DT_SYMBOLIC
: return "SYMBOLIC";
868 case DT_REL
: return "REL";
869 case DT_RELSZ
: return "RELSZ";
870 case DT_RELENT
: return "RELENT";
871 case DT_PLTREL
: return "PLTREL";
872 case DT_DEBUG
: return "DEBUG";
873 case DT_TEXTREL
: return "TEXTREL";
874 case DT_JMPREL
: return "JMPREL";
875 case DT_BIND_NOW
: return "BIND_NOW";
876 case DT_INIT_ARRAY
: return "INIT_ARRAY";
877 case DT_FINI_ARRAY
: return "FINI_ARRAY";
878 case DT_INIT_ARRAYSZ
: return "INIT_ARRAYSZ";
879 case DT_FINI_ARRAYSZ
: return "FINI_ARRAYSZ";
881 case DT_PLTPADSZ
: return "PLTPADSZ";
882 case DT_MOVEENT
: return "MOVEENT";
883 case DT_MOVESZ
: return "MOVESZ";
884 case DT_FEATURE_1
: return "FEATURE_1";
885 case DT_POSFLAG_1
: return "POSFLAG_1";
886 case DT_SYMINSZ
: return "SYMINSZ";
887 case DT_SYMINENT
: return "SYMINENT"; /* aka VALRNGHI */
889 case DT_ADDRRNGLO
: return "ADDRRNGLO";
890 case DT_SYMINFO
: return "SYMINFO"; /* aka ADDRRNGHI */
892 case DT_VERSYM
: return "VERSYM";
894 case DT_RELACOUNT
: return "RELACOUNT";
895 case DT_RELCOUNT
: return "RELCOUNT";
896 case DT_FLAGS_1
: return "FLAGS_1";
897 case DT_VERDEF
: return "VERDEF";
898 case DT_VERDEFNUM
: return "VERDEFNUM";
899 case DT_VERNEED
: return "VERNEED";
900 case DT_VERNEEDNUM
: return "VERNEEDNUM";
902 case DT_AUXILIARY
: return "AUXILARY";
903 case DT_USED
: return "USED";
904 case DT_FILTER
: return "FILTER";
907 if ((type
>= DT_LOPROC
) && (type
<= DT_HIPROC
))
911 switch (elf_header
.e_machine
)
915 result
= get_mips_dynamic_type (type
);
925 sprintf (buff
, _("Processor Specific: %lx"), type
);
927 else if ((type
>= DT_LOOS
) && (type
<= DT_HIOS
))
928 sprintf (buff
, _("Operating System specific: %lx"), type
);
930 sprintf (buff
, _("<unknown>: %lx"), type
);
937 get_file_type (e_type
)
940 static char buff
[32];
944 case ET_NONE
: return _("NONE (None)");
945 case ET_REL
: return _("REL (Relocatable file)");
946 case ET_EXEC
: return _("EXEC (Executable file)");
947 case ET_DYN
: return _("DYN (Shared object file)");
948 case ET_CORE
: return _("CORE (Core file)");
951 if ((e_type
>= ET_LOPROC
) && (e_type
<= ET_HIPROC
))
952 sprintf (buff
, _("Processor Specific: (%x)"), e_type
);
953 else if ((e_type
>= ET_LOOS
) && (e_type
<= ET_HIOS
))
954 sprintf (buff
, _("OS Specific: (%x)"), e_type
);
956 sprintf (buff
, _("<unknown>: %x"), e_type
);
962 get_machine_name (e_machine
)
965 static char buff
[32];
969 case EM_NONE
: return _("None");
970 case EM_M32
: return "WE32100";
971 case EM_SPARC
: return "Sparc";
972 case EM_386
: return "Intel 80386";
973 case EM_68K
: return "MC68000";
974 case EM_88K
: return "MC88000";
975 case EM_486
: return "Intel 80486";
976 case EM_860
: return "Intel 80860";
977 case EM_MIPS
: return "MIPS R3000 big-endian";
978 case EM_S370
: return "Amdahl";
979 case EM_MIPS_RS4_BE
: return "MIPS R4000 big-endian";
980 case EM_OLD_SPARCV9
: return "Sparc v9 (old)";
981 case EM_PARISC
: return "HPPA";
982 case EM_PPC_OLD
: return "Power PC (old)";
983 case EM_SPARC32PLUS
: return "Sparc v8+" ;
984 case EM_960
: return "Intel 90860";
985 case EM_PPC
: return "PowerPC";
986 case EM_V800
: return "NEC V800";
987 case EM_FR20
: return "Fujitsu FR20";
988 case EM_RH32
: return "TRW RH32";
989 case EM_MCORE
: return "MCORE";
990 case EM_ARM
: return "ARM";
991 case EM_OLD_ALPHA
: return "Digital Alpha (old)";
992 case EM_SH
: return "Hitachi SH";
993 case EM_SPARCV9
: return "Sparc v9";
994 case EM_TRICORE
: return "Siemens Tricore";
995 case EM_ARC
: return "Argonaut RISC Core";
996 case EM_H8_300
: return "Hitachi H8/300";
997 case EM_H8_300H
: return "Hitachi H8/300H";
998 case EM_H8S
: return "Hitachi H8S";
999 case EM_H8_500
: return "Hitachi H8/500";
1000 case EM_IA_64
: return "Intel Merced";
1001 case EM_MIPS_X
: return "Stanford MIPS-X";
1002 case EM_COLDFIRE
: return "Motorola Coldfire";
1003 case EM_68HC12
: return "Motorola M68HC12";
1004 case EM_ALPHA
: return "Alpha";
1005 case EM_CYGNUS_D10V
: return "d10v";
1006 case EM_CYGNUS_D30V
: return "d30v";
1007 case EM_CYGNUS_ARC
: return "Arc";
1008 case EM_CYGNUS_M32R
: return "Mitsubishi M32r";
1009 case EM_CYGNUS_V850
: return "NEC v850";
1010 case EM_CYGNUS_MN10300
: return "mn10300";
1011 case EM_CYGNUS_MN10200
: return "mn10200";
1012 case EM_CYGNUS_FR30
: return "Fujitsu FR30";
1015 sprintf (buff
, _("<unknown>: %x"), e_machine
);
1021 get_machine_flags (e_flags
, e_machine
)
1025 static char buf
[1024];
1036 if (e_flags
& EF_CPU32
)
1037 strcat (buf
, ", cpu32");
1041 if (e_flags
& EF_PPC_EMB
)
1042 strcat (buf
, ", emb");
1044 if (e_flags
& EF_PPC_RELOCATABLE
)
1045 strcat (buf
, ", relocatable");
1047 if (e_flags
& EF_PPC_RELOCATABLE_LIB
)
1048 strcat (buf
, ", relocatable-lib");
1051 case EM_CYGNUS_V850
:
1052 switch (e_flags
& EF_V850_ARCH
)
1055 strcat (buf
, ", v850e");
1058 strcat (buf
, ", v850ea");
1061 strcat (buf
, ", v850");
1064 strcat (buf
, ", unknown v850 architecture variant");
1069 case EM_CYGNUS_M32R
:
1070 if ((e_flags
& EF_M32R_ARCH
) == E_M32R_ARCH
)
1071 strcat (buf
, ", m32r");
1076 case EM_MIPS_RS4_BE
:
1077 if (e_flags
& EF_MIPS_NOREORDER
)
1078 strcat (buf
, ", noreorder");
1080 if (e_flags
& EF_MIPS_PIC
)
1081 strcat (buf
, ", pic");
1083 if (e_flags
& EF_MIPS_CPIC
)
1084 strcat (buf
, ", cpic");
1086 if (e_flags
& EF_MIPS_ABI2
)
1087 strcat (buf
, ", abi2");
1089 if ((e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_1
)
1090 strcat (buf
, ", mips1");
1092 if ((e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_2
)
1093 strcat (buf
, ", mips2");
1095 if ((e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_3
)
1096 strcat (buf
, ", mips3");
1098 if ((e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_4
)
1099 strcat (buf
, ", mips4");
1103 if (e_flags
& EF_SPARC_32PLUS
)
1104 strcat (buf
, ", v8+");
1106 if (e_flags
& EF_SPARC_SUN_US1
)
1107 strcat (buf
, ", ultrasparc");
1109 if (e_flags
& EF_SPARC_HAL_R1
)
1110 strcat (buf
, ", halr1");
1112 if (e_flags
& EF_SPARC_LEDATA
)
1113 strcat (buf
, ", ledata");
1115 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_TSO
)
1116 strcat (buf
, ", tso");
1118 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_PSO
)
1119 strcat (buf
, ", pso");
1121 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_RMO
)
1122 strcat (buf
, ", rmo");
1131 get_mips_segment_type (type
)
1136 case PT_MIPS_REGINFO
:
1138 case PT_MIPS_RTPROC
:
1140 case PT_MIPS_OPTIONS
:
1150 get_segment_type (p_type
)
1151 unsigned long p_type
;
1153 static char buff
[32];
1157 case PT_NULL
: return "NULL";
1158 case PT_LOAD
: return "LOAD";
1159 case PT_DYNAMIC
: return "DYNAMIC";
1160 case PT_INTERP
: return "INTERP";
1161 case PT_NOTE
: return "NOTE";
1162 case PT_SHLIB
: return "SHLIB";
1163 case PT_PHDR
: return "PHDR";
1166 if ((p_type
>= PT_LOPROC
) && (p_type
<= PT_HIPROC
))
1168 const char * result
;
1170 switch (elf_header
.e_machine
)
1173 case EM_MIPS_RS4_BE
:
1174 result
= get_mips_segment_type (p_type
);
1184 sprintf (buff
, "LOPROC+%lx", p_type
- PT_LOPROC
);
1186 else if ((p_type
>= PT_LOOS
) && (p_type
<= PT_HIOS
))
1187 sprintf (buff
, "LOOS+%lx", p_type
- PT_LOOS
);
1189 sprintf (buff
, _("<unknown>: %lx"), p_type
);
1196 get_mips_section_type_name (sh_type
)
1197 unsigned int sh_type
;
1201 case SHT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
1202 case SHT_MIPS_MSYM
: return "MIPS_MSYM";
1203 case SHT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
1204 case SHT_MIPS_GPTAB
: return "MIPS_GPTAB";
1205 case SHT_MIPS_UCODE
: return "MIPS_UCODE";
1206 case SHT_MIPS_DEBUG
: return "MIPS_DEBUG";
1207 case SHT_MIPS_REGINFO
: return "MIPS_REGINFO";
1208 case SHT_MIPS_PACKAGE
: return "MIPS_PACKAGE";
1209 case SHT_MIPS_PACKSYM
: return "MIPS_PACKSYM";
1210 case SHT_MIPS_RELD
: return "MIPS_RELD";
1211 case SHT_MIPS_IFACE
: return "MIPS_IFACE";
1212 case SHT_MIPS_CONTENT
: return "MIPS_CONTENT";
1213 case SHT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
1214 case SHT_MIPS_SHDR
: return "MIPS_SHDR";
1215 case SHT_MIPS_FDESC
: return "MIPS_FDESC";
1216 case SHT_MIPS_EXTSYM
: return "MIPS_EXTSYM";
1217 case SHT_MIPS_DENSE
: return "MIPS_DENSE";
1218 case SHT_MIPS_PDESC
: return "MIPS_PDESC";
1219 case SHT_MIPS_LOCSYM
: return "MIPS_LOCSYM";
1220 case SHT_MIPS_AUXSYM
: return "MIPS_AUXSYM";
1221 case SHT_MIPS_OPTSYM
: return "MIPS_OPTSYM";
1222 case SHT_MIPS_LOCSTR
: return "MIPS_LOCSTR";
1223 case SHT_MIPS_LINE
: return "MIPS_LINE";
1224 case SHT_MIPS_RFDESC
: return "MIPS_RFDESC";
1225 case SHT_MIPS_DELTASYM
: return "MIPS_DELTASYM";
1226 case SHT_MIPS_DELTAINST
: return "MIPS_DELTAINST";
1227 case SHT_MIPS_DELTACLASS
: return "MIPS_DELTACLASS";
1228 case SHT_MIPS_DWARF
: return "MIPS_DWARF";
1229 case SHT_MIPS_DELTADECL
: return "MIPS_DELTADECL";
1230 case SHT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
1231 case SHT_MIPS_EVENTS
: return "MIPS_EVENTS";
1232 case SHT_MIPS_TRANSLATE
: return "MIPS_TRANSLATE";
1233 case SHT_MIPS_PIXIE
: return "MIPS_PIXIE";
1234 case SHT_MIPS_XLATE
: return "MIPS_XLATE";
1235 case SHT_MIPS_XLATE_DEBUG
: return "MIPS_XLATE_DEBUG";
1236 case SHT_MIPS_WHIRL
: return "MIPS_WHIRL";
1237 case SHT_MIPS_EH_REGION
: return "MIPS_EH_REGION";
1238 case SHT_MIPS_XLATE_OLD
: return "MIPS_XLATE_OLD";
1239 case SHT_MIPS_PDR_EXCEPTION
: return "MIPS_PDR_EXCEPTION";
1247 get_section_type_name (sh_type
)
1248 unsigned int sh_type
;
1250 static char buff
[32];
1254 case SHT_NULL
: return "NULL";
1255 case SHT_PROGBITS
: return "PROGBITS";
1256 case SHT_SYMTAB
: return "SYMTAB";
1257 case SHT_STRTAB
: return "STRTAB";
1258 case SHT_RELA
: return "RELA";
1259 case SHT_HASH
: return "HASH";
1260 case SHT_DYNAMIC
: return "DYNAMIC";
1261 case SHT_NOTE
: return "NOTE";
1262 case SHT_NOBITS
: return "NOBITS";
1263 case SHT_REL
: return "REL";
1264 case SHT_SHLIB
: return "SHLIB";
1265 case SHT_DYNSYM
: return "DYNSYM";
1266 case SHT_GNU_verdef
: return "VERDEF";
1267 case SHT_GNU_verneed
: return "VERNEED";
1268 case SHT_GNU_versym
: return "VERSYM";
1269 case 0x6ffffff0: return "VERSYM";
1270 case 0x6ffffffc: return "VERDEF";
1271 case 0x7ffffffd: return "AUXILIARY";
1272 case 0x7fffffff: return "FILTER";
1275 if ((sh_type
>= SHT_LOPROC
) && (sh_type
<= SHT_HIPROC
))
1277 const char * result
;
1279 switch (elf_header
.e_machine
)
1282 case EM_MIPS_RS4_BE
:
1283 result
= get_mips_section_type_name (sh_type
);
1293 sprintf (buff
, "SHT_LOPROC+%x", sh_type
- SHT_LOPROC
);
1295 else if ((sh_type
>= SHT_LOOS
) && (sh_type
<= SHT_HIOS
))
1296 sprintf (buff
, "SHT_LOOS+%x", sh_type
- SHT_LOOS
);
1297 else if ((sh_type
>= SHT_LOUSER
) && (sh_type
<= SHT_HIUSER
))
1298 sprintf (buff
, "SHT_LOUSER+%x", sh_type
- SHT_LOUSER
);
1300 sprintf (buff
, _("<unknown>: %x"), sh_type
);
1306 struct option options
[] =
1308 {"all", no_argument
, 0, 'a'},
1309 {"file-header", no_argument
, 0, 'h'},
1310 {"program-headers", no_argument
, 0, 'l'},
1311 {"headers", no_argument
, 0, 'e'},
1312 {"histogram", no_argument
, 0, 'I'},
1313 {"segments", no_argument
, 0, 'l'},
1314 {"sections", no_argument
, 0, 'S'},
1315 {"section-headers", no_argument
, 0, 'S'},
1316 {"symbols", no_argument
, 0, 's'},
1317 {"syms", no_argument
, 0, 's'},
1318 {"relocs", no_argument
, 0, 'r'},
1319 {"dynamic", no_argument
, 0, 'd'},
1320 {"arch-specific", no_argument
, 0, 'A'},
1321 {"version-info", no_argument
, 0, 'V'},
1322 {"use-dynamic", no_argument
, 0, 'D'},
1323 {"hex-dump", required_argument
, 0, 'x'},
1324 {"debug-dump", optional_argument
, 0, 'w'},
1325 #ifdef SUPPORT_DISASSEMBLY
1326 {"instruction-dump", required_argument
, 0, 'i'},
1329 {"version", no_argument
, 0, 'v'},
1330 {"help", no_argument
, 0, 'H'},
1331 {0, no_argument
, 0, 0}
1337 fprintf (stdout
, _("Usage: readelf {options} elf-file(s)\n"));
1338 fprintf (stdout
, _(" Options are:\n"));
1339 fprintf (stdout
, _(" -a or --all Equivalent to: -h -l -S -s -r -d -V -A -I\n"));
1340 fprintf (stdout
, _(" -h or --file-header Display the ELF file header\n"));
1341 fprintf (stdout
, _(" -l or --program-headers or --segments\n"));
1342 fprintf (stdout
, _(" Display the program headers\n"));
1343 fprintf (stdout
, _(" -S or --section-headers or --sections\n"));
1344 fprintf (stdout
, _(" Display the sections' header\n"));
1345 fprintf (stdout
, _(" -e or --headers Equivalent to: -h -l -S\n"));
1346 fprintf (stdout
, _(" -s or --syms or --symbols Display the symbol table\n"));
1347 fprintf (stdout
, _(" -r or --relocs Display the relocations (if present)\n"));
1348 fprintf (stdout
, _(" -d or --dynamic Display the dynamic segment (if present)\n"));
1349 fprintf (stdout
, _(" -V or --version-info Display the version sections (if present)\n"));
1350 fprintf (stdout
, _(" -A or --arch-specific Display architecture specific information (if any).\n"));
1351 fprintf (stdout
, _(" -D or --use-dynamic Use the dynamic section info when displaying symbols\n"));
1352 fprintf (stdout
, _(" -x <number> or --hex-dump=<number>\n"));
1353 fprintf (stdout
, _(" Dump the contents of section <number>\n"));
1354 fprintf (stdout
, _(" -w[liapr] or --debug-dump[=line,=info,=abbrev,=pubnames,=ranges]\n"));
1355 fprintf (stdout
, _(" Display the contents of DWARF2 debug sections\n"));
1356 #ifdef SUPPORT_DISASSEMBLY
1357 fprintf (stdout
, _(" -i <number> or --instruction-dump=<number>\n"));
1358 fprintf (stdout
, _(" Disassemble the contents of section <number>\n"));
1360 fprintf (stdout
, _(" -I or --histogram Display histogram of bucket list lengths\n"));
1361 fprintf (stdout
, _(" -v or --version Display the version number of readelf\n"));
1362 fprintf (stdout
, _(" -H or --help Display this information\n"));
1363 fprintf (stdout
, _("Report bugs to bug-gnu-utils@gnu.org\n"));
1369 request_dump (section
, type
)
1370 unsigned int section
;
1373 if (section
>= num_dump_sects
)
1375 char * new_dump_sects
;
1377 new_dump_sects
= (char *) calloc (section
+ 1, 1);
1379 if (new_dump_sects
== NULL
)
1380 error (_("Out of memory allocating dump request table."));
1383 /* Copy current flag settings. */
1384 memcpy (new_dump_sects
, dump_sects
, num_dump_sects
);
1388 dump_sects
= new_dump_sects
;
1389 num_dump_sects
= section
+ 1;
1394 dump_sects
[section
] |= type
;
1400 parse_args (argc
, argv
)
1409 while ((c
= getopt_long
1410 (argc
, argv
, "ersahldSDAIw::x:i:vV", options
, NULL
)) != EOF
)
1444 do_using_dynamic
++;
1469 section
= strtoul (optarg
, & cp
, 0);
1470 if (! * cp
&& section
>= 0)
1472 request_dump (section
, HEX_DUMP
);
1492 do_debug_abbrevs
= 1;
1502 do_debug_pubnames
= 1;
1507 do_debug_aranges
= 1;
1511 warn (_("Unrecognised debug option '%s'\n"), optarg
);
1516 #ifdef SUPPORT_DISASSEMBLY
1519 section
= strtoul (optarg
, & cp
, 0);
1520 if (! * cp
&& section
>= 0)
1522 request_dump (section
, DISASS_DUMP
);
1528 print_version (program_name
);
1535 /* xgettext:c-format */
1536 error (_("Invalid option '-%c'\n"), c
);
1543 if (!do_dynamic
&& !do_syms
&& !do_reloc
&& !do_sections
1544 && !do_segments
&& !do_header
&& !do_dump
&& !do_version
1545 && !do_histogram
&& !do_debugging
&& !do_arch
)
1549 warn (_("Nothing to do.\n"));
1555 get_elf_class (elf_class
)
1556 unsigned char elf_class
;
1558 static char buff
[32];
1562 case ELFCLASSNONE
: return _("none");
1563 case ELFCLASS32
: return _("ELF32");
1564 case ELFCLASS64
: return _("ELF64");
1566 sprintf (buff
, _("<unknown: %x>"), elf_class
);
1572 get_data_encoding (encoding
)
1573 unsigned char encoding
;
1575 static char buff
[32];
1579 case ELFDATANONE
: return _("none");
1580 case ELFDATA2LSB
: return _("2's complement, little endian");
1581 case ELFDATA2MSB
: return _("2's complement, big endian");
1583 sprintf (buff
, _("<unknown: %x>"), encoding
);
1589 get_osabi_name (osabi
)
1590 unsigned char osabi
;
1592 static char buff
[32];
1596 case ELFOSABI_SYSV
: return _("UNIX - System V");
1597 case ELFOSABI_HPUX
: return _("UNIX - HP-UX");
1598 case ELFOSABI_STANDALONE
: return _("Standalone App");
1600 sprintf (buff
, _("<unknown: %x>"), osabi
);
1605 /* Decode the data held in 'elf_header'. */
1607 process_file_header ()
1609 if ( elf_header
.e_ident
[EI_MAG0
] != ELFMAG0
1610 || elf_header
.e_ident
[EI_MAG1
] != ELFMAG1
1611 || elf_header
.e_ident
[EI_MAG2
] != ELFMAG2
1612 || elf_header
.e_ident
[EI_MAG3
] != ELFMAG3
)
1615 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
1623 printf (_("ELF Header:\n"));
1624 printf (_(" Magic: "));
1625 for (i
= 0; i
< EI_NIDENT
; i
++)
1626 printf ("%2.2x ", elf_header
.e_ident
[i
]);
1628 printf (_(" Class: %s\n"),
1629 get_elf_class (elf_header
.e_ident
[EI_CLASS
]));
1630 printf (_(" Data: %s\n"),
1631 get_data_encoding (elf_header
.e_ident
[EI_DATA
]));
1632 printf (_(" Version: %d %s\n"),
1633 elf_header
.e_ident
[EI_VERSION
],
1634 (elf_header
.e_ident
[EI_VERSION
] == EV_CURRENT
1636 : (elf_header
.e_ident
[EI_VERSION
] != EV_NONE
1639 printf (_(" OS/ABI: %s\n"),
1640 get_osabi_name (elf_header
.e_ident
[EI_OSABI
]));
1641 printf (_(" ABI Version: %d\n"),
1642 elf_header
.e_ident
[EI_ABIVERSION
]);
1643 printf (_(" Type: %s\n"),
1644 get_file_type (elf_header
.e_type
));
1645 printf (_(" Machine: %s\n"),
1646 get_machine_name (elf_header
.e_machine
));
1647 printf (_(" Version: 0x%lx\n"),
1648 (unsigned long) elf_header
.e_version
);
1649 printf (_(" Entry point address: 0x%lx\n"),
1650 (unsigned long) elf_header
.e_entry
);
1651 printf (_(" Start of program headers: %ld (bytes into file)\n"),
1652 (long) elf_header
.e_phoff
);
1653 printf (_(" Start of section headers: %ld (bytes into file)\n"),
1654 (long) elf_header
.e_shoff
);
1655 printf (_(" Flags: 0x%lx%s\n"),
1656 (unsigned long) elf_header
.e_flags
,
1657 get_machine_flags (elf_header
.e_flags
, elf_header
.e_machine
));
1658 printf (_(" Size of this header: %ld (bytes)\n"),
1659 (long) elf_header
.e_ehsize
);
1660 printf (_(" Size of program headers: %ld (bytes)\n"),
1661 (long) elf_header
.e_phentsize
);
1662 printf (_(" Number of program headers: %ld\n"),
1663 (long) elf_header
.e_phnum
);
1664 printf (_(" Size of section headers: %ld (bytes)\n"),
1665 (long) elf_header
.e_shentsize
);
1666 printf (_(" Number of section headers: %ld\n"),
1667 (long) elf_header
.e_shnum
);
1668 printf (_(" Section header string table index: %ld\n"),
1669 (long) elf_header
.e_shstrndx
);
1677 get_32bit_program_headers (file
, program_headers
)
1679 Elf_Internal_Phdr
* program_headers
;
1681 Elf32_External_Phdr
* phdrs
;
1682 Elf32_External_Phdr
* external
;
1683 Elf32_Internal_Phdr
* internal
;
1686 GET_DATA_ALLOC (elf_header
.e_phoff
,
1687 elf_header
.e_phentsize
* elf_header
.e_phnum
,
1688 phdrs
, Elf32_External_Phdr
*, "program headers");
1690 for (i
= 0, internal
= program_headers
, external
= phdrs
;
1691 i
< elf_header
.e_phnum
;
1692 i
++, internal
++, external
++)
1694 internal
->p_type
= BYTE_GET (external
->p_type
);
1695 internal
->p_offset
= BYTE_GET (external
->p_offset
);
1696 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
1697 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
1698 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
1699 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
1700 internal
->p_flags
= BYTE_GET (external
->p_flags
);
1701 internal
->p_align
= BYTE_GET (external
->p_align
);
1710 get_64bit_program_headers (file
, program_headers
)
1712 Elf_Internal_Phdr
* program_headers
;
1714 Elf64_External_Phdr
* phdrs
;
1715 Elf64_External_Phdr
* external
;
1716 Elf64_Internal_Phdr
* internal
;
1719 GET_DATA_ALLOC (elf_header
.e_phoff
,
1720 elf_header
.e_phentsize
* elf_header
.e_phnum
,
1721 phdrs
, Elf64_External_Phdr
*, "program headers");
1723 for (i
= 0, internal
= program_headers
, external
= phdrs
;
1724 i
< elf_header
.e_phnum
;
1725 i
++, internal
++, external
++)
1727 internal
->p_type
= BYTE_GET (external
->p_type
);
1728 internal
->p_flags
= BYTE_GET (external
->p_flags
);
1729 internal
->p_offset
= BYTE_GET8 (external
->p_offset
);
1730 internal
->p_vaddr
= BYTE_GET8 (external
->p_vaddr
);
1731 internal
->p_paddr
= BYTE_GET8 (external
->p_paddr
);
1732 internal
->p_filesz
= BYTE_GET8 (external
->p_filesz
);
1733 internal
->p_memsz
= BYTE_GET8 (external
->p_memsz
);
1734 internal
->p_align
= BYTE_GET8 (external
->p_align
);
1743 process_program_headers (file
)
1746 Elf_Internal_Phdr
* program_headers
;
1747 Elf_Internal_Phdr
* segment
;
1750 if (elf_header
.e_phnum
== 0)
1753 printf (_("\nThere are no program headers in this file.\n"));
1757 if (do_segments
&& !do_header
)
1759 printf (_("\nElf file is %s\n"), get_file_type (elf_header
.e_type
));
1760 printf (_("Entry point 0x%lx\n"), (unsigned long) elf_header
.e_entry
);
1761 printf (_("There are %d program headers, starting at offset %lx:\n"),
1762 elf_header
.e_phnum
, (unsigned long) elf_header
.e_phoff
);
1765 program_headers
= (Elf_Internal_Phdr
*) malloc
1766 (elf_header
.e_phnum
* sizeof (Elf_Internal_Phdr
));
1768 if (program_headers
== NULL
)
1770 error (_("Out of memory\n"));
1775 i
= get_32bit_program_headers (file
, program_headers
);
1777 i
= get_64bit_program_headers (file
, program_headers
);
1781 free (program_headers
);
1788 (_("\nProgram Header%s:\n"), elf_header
.e_phnum
> 1 ? "s" : "");
1790 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
1797 for (i
= 0, segment
= program_headers
;
1798 i
< elf_header
.e_phnum
;
1803 printf (" %-11.11s ", get_segment_type (segment
->p_type
));
1804 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
1805 printf ("0x%8.8lx ", (unsigned long) segment
->p_vaddr
);
1806 printf ("0x%8.8lx ", (unsigned long) segment
->p_paddr
);
1807 printf ("0x%5.5lx ", (unsigned long) segment
->p_filesz
);
1808 printf ("0x%5.5lx ", (unsigned long) segment
->p_memsz
);
1810 (segment
->p_flags
& PF_R
? 'R' : ' '),
1811 (segment
->p_flags
& PF_W
? 'W' : ' '),
1812 (segment
->p_flags
& PF_X
? 'E' : ' '));
1813 printf ("%#lx", (unsigned long) segment
->p_align
);
1816 switch (segment
->p_type
)
1820 loadaddr
= (segment
->p_vaddr
& 0xfffff000)
1821 - (segment
->p_offset
& 0xfffff000);
1826 error (_("more than one dynamic segment\n"));
1828 dynamic_addr
= segment
->p_offset
;
1829 dynamic_size
= segment
->p_filesz
;
1833 if (fseek (file
, segment
->p_offset
, SEEK_SET
))
1834 error (_("Unable to find program interpreter name\n"));
1837 program_interpreter
[0] = 0;
1838 fscanf (file
, "%63s", program_interpreter
);
1841 printf (_("\n [Requesting program interpreter: %s]"),
1842 program_interpreter
);
1848 putc ('\n', stdout
);
1857 if (do_segments
&& section_headers
!= NULL
)
1859 printf (_("\n Section to Segment mapping:\n"));
1860 printf (_(" Segment Sections...\n"));
1862 assert (string_table
!= NULL
);
1864 for (i
= 0; i
< elf_header
.e_phnum
; i
++)
1867 Elf_Internal_Shdr
* section
;
1869 segment
= program_headers
+ i
;
1870 section
= section_headers
;
1872 printf (" %2.2d ", i
);
1874 for (j
= 0; j
< elf_header
.e_shnum
; j
++, section
++)
1876 if (section
->sh_size
> 0
1877 /* Compare allocated sections by VMA, unallocated
1878 sections by file offset. */
1879 && (section
->sh_flags
& SHF_ALLOC
1880 ? (section
->sh_addr
>= segment
->p_vaddr
1881 && section
->sh_addr
+ section
->sh_size
1882 <= segment
->p_vaddr
+ segment
->p_memsz
)
1883 : ((bfd_vma
) section
->sh_offset
>= segment
->p_offset
1884 && (section
->sh_offset
+ section
->sh_size
1885 <= segment
->p_offset
+ segment
->p_filesz
))))
1886 printf ("%s ", SECTION_NAME (section
));
1893 free (program_headers
);
1900 get_32bit_section_headers (file
)
1903 Elf32_External_Shdr
* shdrs
;
1904 Elf32_Internal_Shdr
* internal
;
1907 GET_DATA_ALLOC (elf_header
.e_shoff
,
1908 elf_header
.e_shentsize
* elf_header
.e_shnum
,
1909 shdrs
, Elf32_External_Shdr
*, "section headers");
1911 section_headers
= (Elf_Internal_Shdr
*) malloc
1912 (elf_header
.e_shnum
* sizeof (Elf_Internal_Shdr
));
1914 if (section_headers
== NULL
)
1916 error (_("Out of memory\n"));
1920 for (i
= 0, internal
= section_headers
;
1921 i
< elf_header
.e_shnum
;
1924 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
1925 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
1926 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
1927 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
1928 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
1929 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
1930 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
1931 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
1932 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
1933 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
1942 get_64bit_section_headers (file
)
1945 Elf64_External_Shdr
* shdrs
;
1946 Elf64_Internal_Shdr
* internal
;
1949 GET_DATA_ALLOC (elf_header
.e_shoff
,
1950 elf_header
.e_shentsize
* elf_header
.e_shnum
,
1951 shdrs
, Elf64_External_Shdr
*, "section headers");
1953 section_headers
= (Elf_Internal_Shdr
*) malloc
1954 (elf_header
.e_shnum
* sizeof (Elf_Internal_Shdr
));
1956 if (section_headers
== NULL
)
1958 error (_("Out of memory\n"));
1962 for (i
= 0, internal
= section_headers
;
1963 i
< elf_header
.e_shnum
;
1966 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
1967 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
1968 internal
->sh_flags
= BYTE_GET8 (shdrs
[i
].sh_flags
);
1969 internal
->sh_addr
= BYTE_GET8 (shdrs
[i
].sh_addr
);
1970 internal
->sh_size
= BYTE_GET8 (shdrs
[i
].sh_size
);
1971 internal
->sh_entsize
= BYTE_GET8 (shdrs
[i
].sh_entsize
);
1972 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
1973 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
1974 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
1975 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
1983 static Elf_Internal_Sym
*
1984 get_32bit_elf_symbols (file
, offset
, number
)
1986 unsigned long offset
;
1987 unsigned long number
;
1989 Elf32_External_Sym
* esyms
;
1990 Elf_Internal_Sym
* isyms
;
1991 Elf_Internal_Sym
* psym
;
1994 GET_DATA_ALLOC (offset
, number
* sizeof (Elf32_External_Sym
),
1995 esyms
, Elf32_External_Sym
*, "symbols");
1997 isyms
= (Elf_Internal_Sym
*) malloc (number
* sizeof (Elf_Internal_Sym
));
2001 error (_("Out of memory\n"));
2007 for (j
= 0, psym
= isyms
;
2011 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
2012 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
2013 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
2014 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
2015 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
2016 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
2024 static Elf_Internal_Sym
*
2025 get_64bit_elf_symbols (file
, offset
, number
)
2027 unsigned long offset
;
2028 unsigned long number
;
2030 Elf64_External_Sym
* esyms
;
2031 Elf_Internal_Sym
* isyms
;
2032 Elf_Internal_Sym
* psym
;
2035 GET_DATA_ALLOC (offset
, number
* sizeof (Elf64_External_Sym
),
2036 esyms
, Elf64_External_Sym
*, "symbols");
2038 isyms
= (Elf_Internal_Sym
*) malloc (number
* sizeof (Elf_Internal_Sym
));
2042 error (_("Out of memory\n"));
2048 for (j
= 0, psym
= isyms
;
2052 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
2053 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
2054 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
2055 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
2056 psym
->st_value
= BYTE_GET8 (esyms
[j
].st_value
);
2057 psym
->st_size
= BYTE_GET8 (esyms
[j
].st_size
);
2066 process_section_headers (file
)
2069 Elf_Internal_Shdr
* section
;
2072 section_headers
= NULL
;
2074 if (elf_header
.e_shnum
== 0)
2077 printf (_("\nThere are no sections in this file.\n"));
2082 if (do_sections
&& !do_header
)
2083 printf (_("There are %d section headers, starting at offset 0x%lx:\n"),
2084 elf_header
.e_shnum
, (unsigned long) elf_header
.e_shoff
);
2088 if (! get_32bit_section_headers (file
))
2091 else if (! get_64bit_section_headers (file
))
2094 /* Read in the string table, so that we have names to display. */
2095 section
= section_headers
+ elf_header
.e_shstrndx
;
2097 if (section
->sh_size
!= 0)
2099 unsigned long string_table_offset
;
2101 string_table_offset
= section
->sh_offset
;
2103 GET_DATA_ALLOC (section
->sh_offset
, section
->sh_size
,
2104 string_table
, char *, "string table");
2107 /* Scan the sections for the dynamic symbol table
2108 and dynamic string table and debug sections. */
2109 dynamic_symbols
= NULL
;
2110 dynamic_strings
= NULL
;
2111 dynamic_syminfo
= NULL
;
2113 for (i
= 0, section
= section_headers
;
2114 i
< elf_header
.e_shnum
;
2117 char * name
= SECTION_NAME (section
);
2119 if (section
->sh_type
== SHT_DYNSYM
)
2121 if (dynamic_symbols
!= NULL
)
2123 error (_("File contains multiple dynamic symbol tables\n"));
2127 num_dynamic_syms
= section
->sh_size
/ section
->sh_entsize
;
2129 GET_ELF_SYMBOLS (file
, section
->sh_offset
, num_dynamic_syms
);
2131 else if (section
->sh_type
== SHT_STRTAB
2132 && strcmp (name
, ".dynstr") == 0)
2134 if (dynamic_strings
!= NULL
)
2136 error (_("File contains multiple dynamic string tables\n"));
2140 GET_DATA_ALLOC (section
->sh_offset
, section
->sh_size
,
2141 dynamic_strings
, char *, "dynamic strings");
2143 else if ((do_debugging
|| do_debug_info
|| do_debug_abbrevs
2144 || do_debug_lines
|| do_debug_pubnames
|| do_debug_aranges
)
2145 && strncmp (name
, ".debug_", 7) == 0)
2150 || (do_debug_info
&& (strcmp (name
, "info") == 0))
2151 || (do_debug_abbrevs
&& (strcmp (name
, "abbrev") == 0))
2152 || (do_debug_lines
&& (strcmp (name
, "line") == 0))
2153 || (do_debug_pubnames
&& (strcmp (name
, "pubnames") == 0))
2154 || (do_debug_aranges
&& (strcmp (name
, "aranges") == 0))
2156 request_dump (i
, DEBUG_DUMP
);
2163 printf (_("\nSection Header%s:\n"), elf_header
.e_shnum
> 1 ? "s" : "");
2165 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
2167 for (i
= 0, section
= section_headers
;
2168 i
< elf_header
.e_shnum
;
2171 printf (" [%2d] %-17.17s %-15.15s ",
2173 SECTION_NAME (section
),
2174 get_section_type_name (section
->sh_type
));
2176 printf ( "%8.8lx %6.6lx %6.6lx %2.2lx",
2177 (unsigned long) section
->sh_addr
,
2178 (unsigned long) section
->sh_offset
,
2179 (unsigned long) section
->sh_size
,
2180 (unsigned long) section
->sh_entsize
);
2182 printf (" %c%c%c %2ld %3lx %ld\n",
2183 (section
->sh_flags
& SHF_WRITE
? 'W' : ' '),
2184 (section
->sh_flags
& SHF_ALLOC
? 'A' : ' '),
2185 (section
->sh_flags
& SHF_EXECINSTR
? 'X' : ' '),
2186 (unsigned long) section
->sh_link
,
2187 (unsigned long) section
->sh_info
,
2188 (unsigned long) section
->sh_addralign
);
2194 /* Process the reloc section. */
2196 process_relocs (file
)
2199 unsigned long rel_size
;
2200 unsigned long rel_offset
;
2206 if (do_using_dynamic
)
2208 int is_rela
= FALSE
;
2213 if (dynamic_info
[DT_REL
])
2215 rel_offset
= dynamic_info
[DT_REL
];
2216 rel_size
= dynamic_info
[DT_RELSZ
];
2219 else if (dynamic_info
[DT_RELA
])
2221 rel_offset
= dynamic_info
[DT_RELA
];
2222 rel_size
= dynamic_info
[DT_RELASZ
];
2225 else if (dynamic_info
[DT_JMPREL
])
2227 rel_offset
= dynamic_info
[DT_JMPREL
];
2228 rel_size
= dynamic_info
[DT_PLTRELSZ
];
2230 switch (dynamic_info
[DT_PLTREL
])
2247 (_("\nRelocation section at offset 0x%lx contains %ld bytes:\n"),
2248 rel_offset
, rel_size
);
2250 dump_relocations (file
, rel_offset
- loadaddr
, rel_size
,
2251 dynamic_symbols
, num_dynamic_syms
, dynamic_strings
, is_rela
);
2254 printf (_("\nThere are no dynamic relocations in this file.\n"));
2258 Elf32_Internal_Shdr
* section
;
2262 for (i
= 0, section
= section_headers
;
2263 i
< elf_header
.e_shnum
;
2266 if ( section
->sh_type
!= SHT_RELA
2267 && section
->sh_type
!= SHT_REL
)
2270 rel_offset
= section
->sh_offset
;
2271 rel_size
= section
->sh_size
;
2275 Elf32_Internal_Shdr
* strsec
;
2276 Elf32_Internal_Shdr
* symsec
;
2277 Elf_Internal_Sym
* symtab
;
2280 unsigned long nsyms
;
2282 printf (_("\nRelocation section "));
2284 if (string_table
== NULL
)
2285 printf ("%d", section
->sh_name
);
2287 printf ("'%s'", SECTION_NAME (section
));
2289 printf (_(" at offset 0x%lx contains %lu entries:\n"),
2290 rel_offset
, (unsigned long) (rel_size
/ section
->sh_entsize
));
2292 symsec
= section_headers
+ section
->sh_link
;
2294 nsyms
= symsec
->sh_size
/ symsec
->sh_entsize
;
2295 symtab
= GET_ELF_SYMBOLS (file
, symsec
->sh_offset
, nsyms
);
2300 strsec
= section_headers
+ symsec
->sh_link
;
2302 GET_DATA_ALLOC (strsec
->sh_offset
, strsec
->sh_size
, strtab
,
2303 char *, "string table");
2305 is_rela
= section
->sh_type
== SHT_RELA
;
2307 dump_relocations (file
, rel_offset
, rel_size
, symtab
, nsyms
, strtab
, is_rela
);
2317 printf (_("\nThere are no relocations in this file.\n"));
2325 dynamic_segment_mips_val (entry
)
2326 Elf_Internal_Dyn
* entry
;
2328 switch (entry
->d_tag
)
2331 if (entry
->d_un
.d_val
== 0)
2335 static const char * opts
[] =
2337 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
2338 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
2339 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
2340 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
2345 for (cnt
= 0; cnt
< NUM_ELEM (opts
); ++ cnt
)
2346 if (entry
->d_un
.d_val
& (1 << cnt
))
2348 printf ("%s%s", first
? "" : " ", opts
[cnt
]);
2355 case DT_MIPS_IVERSION
:
2356 if (dynamic_strings
!= NULL
)
2357 printf ("Interface Version: %s\n",
2358 dynamic_strings
+ entry
->d_un
.d_val
);
2360 printf ("%ld\n", (long) entry
->d_un
.d_ptr
);
2363 case DT_MIPS_TIME_STAMP
:
2366 time_t time
= entry
->d_un
.d_val
;
2367 strftime (timebuf
, 20, "%Y-%m-%dT%H:%M:%S", gmtime (&time
));
2368 printf ("Time Stamp: %s\n", timebuf
);
2372 case DT_MIPS_RLD_VERSION
:
2373 case DT_MIPS_LOCAL_GOTNO
:
2374 case DT_MIPS_CONFLICTNO
:
2375 case DT_MIPS_LIBLISTNO
:
2376 case DT_MIPS_SYMTABNO
:
2377 case DT_MIPS_UNREFEXTNO
:
2378 case DT_MIPS_HIPAGENO
:
2379 case DT_MIPS_DELTA_CLASS_NO
:
2380 case DT_MIPS_DELTA_INSTANCE_NO
:
2381 case DT_MIPS_DELTA_RELOC_NO
:
2382 case DT_MIPS_DELTA_SYM_NO
:
2383 case DT_MIPS_DELTA_CLASSSYM_NO
:
2384 case DT_MIPS_COMPACT_SIZE
:
2385 printf ("%ld\n", (long) entry
->d_un
.d_ptr
);
2389 printf ("%#lx\n", (long) entry
->d_un
.d_ptr
);
2394 get_32bit_dynamic_segment (file
)
2397 Elf32_External_Dyn
* edyn
;
2398 Elf_Internal_Dyn
* entry
;
2401 GET_DATA_ALLOC (dynamic_addr
, dynamic_size
,
2402 edyn
, Elf32_External_Dyn
*, "dynamic segment");
2404 /* SGI's ELF has more than one section in the DYNAMIC segment. Determine
2405 how large this .dynamic is now. We can do this even before the byte
2406 swapping since the DT_NULL tag is recognizable. */
2408 while (*(Elf32_Word
*) edyn
[dynamic_size
++].d_tag
!= DT_NULL
)
2411 dynamic_segment
= (Elf_Internal_Dyn
*)
2412 malloc (dynamic_size
* sizeof (Elf_Internal_Dyn
));
2414 if (dynamic_segment
== NULL
)
2416 error (_("Out of memory\n"));
2421 for (i
= 0, entry
= dynamic_segment
;
2425 entry
->d_tag
= BYTE_GET (edyn
[i
].d_tag
);
2426 entry
->d_un
.d_val
= BYTE_GET (edyn
[i
].d_un
.d_val
);
2435 get_64bit_dynamic_segment (file
)
2438 Elf64_External_Dyn
* edyn
;
2439 Elf_Internal_Dyn
* entry
;
2442 GET_DATA_ALLOC (dynamic_addr
, dynamic_size
,
2443 edyn
, Elf64_External_Dyn
*, "dynamic segment");
2445 /* SGI's ELF has more than one section in the DYNAMIC segment. Determine
2446 how large this .dynamic is now. We can do this even before the byte
2447 swapping since the DT_NULL tag is recognizable. */
2449 while (*(bfd_vma
*) edyn
[dynamic_size
++].d_tag
!= DT_NULL
)
2452 dynamic_segment
= (Elf_Internal_Dyn
*)
2453 malloc (dynamic_size
* sizeof (Elf_Internal_Dyn
));
2455 if (dynamic_segment
== NULL
)
2457 error (_("Out of memory\n"));
2462 for (i
= 0, entry
= dynamic_segment
;
2466 entry
->d_tag
= BYTE_GET8 (edyn
[i
].d_tag
);
2467 entry
->d_un
.d_val
= BYTE_GET8 (edyn
[i
].d_un
.d_val
);
2475 /* Parse and display the contents of the dynamic segment. */
2477 process_dynamic_segment (file
)
2480 Elf_Internal_Dyn
* entry
;
2483 if (dynamic_size
== 0)
2486 printf (_("\nThere is no dynamic segment in this file.\n"));
2493 if (! get_32bit_dynamic_segment (file
))
2496 else if (! get_64bit_dynamic_segment (file
))
2499 /* Find the appropriate symbol table. */
2500 if (dynamic_symbols
== NULL
)
2502 for (i
= 0, entry
= dynamic_segment
;
2506 unsigned long offset
;
2508 if (entry
->d_tag
!= DT_SYMTAB
)
2511 dynamic_info
[DT_SYMTAB
] = entry
->d_un
.d_val
;
2513 /* Since we do not know how big the symbol table is,
2514 we default to reading in the entire file (!) and
2515 processing that. This is overkill, I know, but it
2517 offset
= entry
->d_un
.d_val
- loadaddr
;
2519 if (fseek (file
, 0, SEEK_END
))
2520 error (_("Unable to seek to end of file!"));
2523 num_dynamic_syms
= (ftell (file
) - offset
) / sizeof (Elf32_External_Sym
);
2525 num_dynamic_syms
= (ftell (file
) - offset
) / sizeof (Elf64_External_Sym
);
2527 if (num_dynamic_syms
< 1)
2529 error (_("Unable to determine the number of symbols to load\n"));
2533 dynamic_symbols
= GET_ELF_SYMBOLS (file
, offset
, num_dynamic_syms
);
2537 /* Similarly find a string table. */
2538 if (dynamic_strings
== NULL
)
2540 for (i
= 0, entry
= dynamic_segment
;
2544 unsigned long offset
;
2547 if (entry
->d_tag
!= DT_STRTAB
)
2550 dynamic_info
[DT_STRTAB
] = entry
->d_un
.d_val
;
2552 /* Since we do not know how big the string table is,
2553 we default to reading in the entire file (!) and
2554 processing that. This is overkill, I know, but it
2557 offset
= entry
->d_un
.d_val
- loadaddr
;
2558 if (fseek (file
, 0, SEEK_END
))
2559 error (_("Unable to seek to end of file\n"));
2560 str_tab_len
= ftell (file
) - offset
;
2562 if (str_tab_len
< 1)
2565 (_("Unable to determine the length of the dynamic string table\n"));
2569 GET_DATA_ALLOC (offset
, str_tab_len
, dynamic_strings
, char *,
2570 "dynamic string table");
2576 /* And find the syminfo section if available. */
2577 if (dynamic_syminfo
== NULL
)
2579 unsigned int syminsz
= 0;
2581 for (i
= 0, entry
= dynamic_segment
;
2585 if (entry
->d_tag
== DT_SYMINENT
)
2587 /* Note: these braces are necessary to avoid a syntax
2588 error from the SunOS4 C compiler. */
2589 assert (sizeof (Elf_External_Syminfo
) == entry
->d_un
.d_val
);
2591 else if (entry
->d_tag
== DT_SYMINSZ
)
2592 syminsz
= entry
->d_un
.d_val
;
2593 else if (entry
->d_tag
== DT_SYMINFO
)
2594 dynamic_syminfo_offset
= entry
->d_un
.d_val
- loadaddr
;
2597 if (dynamic_syminfo_offset
!= 0 && syminsz
!= 0)
2599 Elf_External_Syminfo
* extsyminfo
;
2600 Elf_Internal_Syminfo
* syminfo
;
2602 /* There is a syminfo section. Read the data. */
2603 GET_DATA_ALLOC (dynamic_syminfo_offset
, syminsz
, extsyminfo
,
2604 Elf_External_Syminfo
*, "symbol information");
2606 dynamic_syminfo
= (Elf_Internal_Syminfo
*) malloc (syminsz
);
2607 if (dynamic_syminfo
== NULL
)
2609 error (_("Out of memory\n"));
2613 dynamic_syminfo_nent
= syminsz
/ sizeof (Elf_External_Syminfo
);
2614 for (i
= 0, syminfo
= dynamic_syminfo
; i
< dynamic_syminfo_nent
;
2617 syminfo
->si_boundto
= BYTE_GET (extsyminfo
[i
].si_boundto
);
2618 syminfo
->si_flags
= BYTE_GET (extsyminfo
[i
].si_flags
);
2625 if (do_dynamic
&& dynamic_addr
)
2626 printf (_("\nDynamic segment at offset 0x%x contains %ld entries:\n"),
2627 dynamic_addr
, (long) dynamic_size
);
2629 printf (_(" Tag Type Name/Value\n"));
2631 for (i
= 0, entry
= dynamic_segment
;
2636 printf (_(" 0x%-8.8lx (%s)%*s"),
2637 (unsigned long) entry
->d_tag
,
2638 get_dynamic_type (entry
->d_tag
),
2639 27 - strlen (get_dynamic_type (entry
->d_tag
)),
2642 switch (entry
->d_tag
)
2648 if (entry
->d_tag
== DT_AUXILIARY
)
2649 printf (_("Auxiliary library"));
2651 printf (_("Filter library"));
2653 if (dynamic_strings
)
2654 printf (": [%s]\n", dynamic_strings
+ entry
->d_un
.d_val
);
2656 printf (": %#lx\n", (long) entry
->d_un
.d_val
);
2663 printf (_("Flags:"));
2664 if (entry
->d_un
.d_val
== 0)
2665 printf (_(" None\n"));
2668 unsigned long int val
= entry
->d_un
.d_val
;
2669 if (val
& DTF_1_PARINIT
)
2671 printf (" PARINIT");
2672 val
^= DTF_1_PARINIT
;
2675 printf (" %lx", val
);
2684 printf (_("Flags:"));
2685 if (entry
->d_un
.d_val
== 0)
2686 printf (_(" None\n"));
2689 unsigned long int val
= entry
->d_un
.d_val
;
2690 if (val
& DF_P1_LAZYLOAD
)
2692 printf (" LAZYLOAD");
2693 val
^= DF_P1_LAZYLOAD
;
2695 if (val
& DF_P1_GROUPPERM
)
2697 printf (" GROUPPERM");
2698 val
^= DF_P1_GROUPPERM
;
2701 printf (" %lx", val
);
2710 printf (_("Flags:"));
2711 if (entry
->d_un
.d_val
== 0)
2712 printf (_(" None\n"));
2715 unsigned long int val
= entry
->d_un
.d_val
;
2721 if (val
& DF_1_GLOBAL
)
2726 if (val
& DF_1_GROUP
)
2731 if (val
& DF_1_NODELETE
)
2733 printf (" NODELETE");
2734 val
^= DF_1_NODELETE
;
2736 if (val
& DF_1_LOADFLTR
)
2738 printf (" LOADFLTR");
2739 val
^= DF_1_LOADFLTR
;
2741 if (val
& DF_1_INITFIRST
)
2743 printf (" INITFIRST");
2744 val
^= DF_1_INITFIRST
;
2746 if (val
& DF_1_NOOPEN
)
2751 if (val
& DF_1_ORIGIN
)
2756 if (val
& DF_1_DIRECT
)
2761 if (val
& DF_1_TRANS
)
2766 if (val
& DF_1_INTERPOSE
)
2768 printf (" INTERPOSE");
2769 val
^= DF_1_INTERPOSE
;
2772 printf (" %lx", val
);
2780 puts (get_dynamic_type (entry
->d_un
.d_val
));
2799 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
2805 if (dynamic_strings
== NULL
)
2808 name
= dynamic_strings
+ entry
->d_un
.d_val
;
2812 switch (entry
->d_tag
)
2815 printf (_("Shared library: [%s]"), name
);
2817 if (strcmp (name
, program_interpreter
))
2820 printf (_(" program interpreter\n"));
2824 printf (_("Library soname: [%s]\n"), name
);
2828 printf (_("Library rpath: [%s]\n"), name
);
2832 printf ("%#lx\n", (long) entry
->d_un
.d_val
);
2836 printf ("%#lx\n", (long) entry
->d_un
.d_val
);
2850 case DT_INIT_ARRAYSZ
:
2851 case DT_FINI_ARRAYSZ
:
2853 printf ("%lu (bytes)\n", (unsigned long) entry
->d_un
.d_val
);
2861 printf ("%lu\n", (unsigned long) entry
->d_un
.d_val
);
2872 if (dynamic_strings
!= NULL
&& entry
->d_tag
== DT_USED
)
2876 name
= dynamic_strings
+ entry
->d_un
.d_val
;
2880 printf (_("Not needed object: [%s]\n"), name
);
2885 printf ("%#lx\n", (long) entry
->d_un
.d_val
);
2890 /* The value of this entry is ignored. */
2894 if ((entry
->d_tag
>= DT_VERSYM
) && (entry
->d_tag
<= DT_VERNEEDNUM
))
2895 version_info
[DT_VERSIONTAGIDX (entry
->d_tag
)] =
2900 switch (elf_header
.e_machine
)
2903 case EM_MIPS_RS4_BE
:
2904 dynamic_segment_mips_val (entry
);
2907 printf ("%#lx\n", (long) entry
->d_un
.d_ptr
);
2918 get_ver_flags (flags
)
2921 static char buff
[32];
2928 if (flags
& VER_FLG_BASE
)
2929 strcat (buff
, "BASE ");
2931 if (flags
& VER_FLG_WEAK
)
2933 if (flags
& VER_FLG_BASE
)
2934 strcat (buff
, "| ");
2936 strcat (buff
, "WEAK ");
2939 if (flags
& ~(VER_FLG_BASE
| VER_FLG_WEAK
))
2940 strcat (buff
, "| <unknown>");
2945 /* Display the contents of the version sections. */
2947 process_version_sections (file
)
2950 Elf32_Internal_Shdr
* section
;
2957 for (i
= 0, section
= section_headers
;
2958 i
< elf_header
.e_shnum
;
2961 switch (section
->sh_type
)
2963 case SHT_GNU_verdef
:
2965 Elf_External_Verdef
* edefs
;
2972 (_("\nVersion definition section '%s' contains %ld entries:\n"),
2973 SECTION_NAME (section
), section
->sh_info
);
2975 printf (_(" Addr: 0x"));
2976 printf_vma (section
->sh_addr
);
2977 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
2978 (unsigned long) section
->sh_offset
, section
->sh_link
,
2979 SECTION_NAME (section_headers
+ section
->sh_link
));
2981 GET_DATA_ALLOC (section
->sh_offset
, section
->sh_size
,
2982 edefs
, Elf_External_Verdef
*,
2983 "version definition section");
2985 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++ cnt
)
2988 Elf_External_Verdef
* edef
;
2989 Elf_Internal_Verdef ent
;
2990 Elf_External_Verdaux
* eaux
;
2991 Elf_Internal_Verdaux aux
;
2995 vstart
= ((char *) edefs
) + idx
;
2997 edef
= (Elf_External_Verdef
*) vstart
;
2999 ent
.vd_version
= BYTE_GET (edef
->vd_version
);
3000 ent
.vd_flags
= BYTE_GET (edef
->vd_flags
);
3001 ent
.vd_ndx
= BYTE_GET (edef
->vd_ndx
);
3002 ent
.vd_cnt
= BYTE_GET (edef
->vd_cnt
);
3003 ent
.vd_hash
= BYTE_GET (edef
->vd_hash
);
3004 ent
.vd_aux
= BYTE_GET (edef
->vd_aux
);
3005 ent
.vd_next
= BYTE_GET (edef
->vd_next
);
3007 printf (_(" %#06x: Rev: %d Flags: %s"),
3008 idx
, ent
.vd_version
, get_ver_flags (ent
.vd_flags
));
3010 printf (_(" Index: %d Cnt: %d "),
3011 ent
.vd_ndx
, ent
.vd_cnt
);
3013 vstart
+= ent
.vd_aux
;
3015 eaux
= (Elf_External_Verdaux
*) vstart
;
3017 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
3018 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
3020 if (dynamic_strings
)
3021 printf (_("Name: %s\n"), dynamic_strings
+ aux
.vda_name
);
3023 printf (_("Name index: %ld\n"), aux
.vda_name
);
3025 isum
= idx
+ ent
.vd_aux
;
3027 for (j
= 1; j
< ent
.vd_cnt
; j
++)
3029 isum
+= aux
.vda_next
;
3030 vstart
+= aux
.vda_next
;
3032 eaux
= (Elf_External_Verdaux
*) vstart
;
3034 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
3035 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
3037 if (dynamic_strings
)
3038 printf (_(" %#06x: Parent %d: %s\n"),
3039 isum
, j
, dynamic_strings
+ aux
.vda_name
);
3041 printf (_(" %#06x: Parent %d, name index: %ld\n"),
3042 isum
, j
, aux
.vda_name
);
3052 case SHT_GNU_verneed
:
3054 Elf_External_Verneed
* eneed
;
3060 printf (_("\nVersion needs section '%s' contains %ld entries:\n"),
3061 SECTION_NAME (section
), section
->sh_info
);
3063 printf (_(" Addr: 0x"));
3064 printf_vma (section
->sh_addr
);
3065 printf (_(" Offset: %#08lx Link to section: %ld (%s)\n"),
3066 (unsigned long) section
->sh_offset
, section
->sh_link
,
3067 SECTION_NAME (section_headers
+ section
->sh_link
));
3069 GET_DATA_ALLOC (section
->sh_offset
, section
->sh_size
,
3070 eneed
, Elf_External_Verneed
*,
3071 "version need section");
3073 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
3075 Elf_External_Verneed
* entry
;
3076 Elf_Internal_Verneed ent
;
3081 vstart
= ((char *) eneed
) + idx
;
3083 entry
= (Elf_External_Verneed
*) vstart
;
3085 ent
.vn_version
= BYTE_GET (entry
->vn_version
);
3086 ent
.vn_cnt
= BYTE_GET (entry
->vn_cnt
);
3087 ent
.vn_file
= BYTE_GET (entry
->vn_file
);
3088 ent
.vn_aux
= BYTE_GET (entry
->vn_aux
);
3089 ent
.vn_next
= BYTE_GET (entry
->vn_next
);
3091 printf (_(" %#06x: Version: %d"), idx
, ent
.vn_version
);
3093 if (dynamic_strings
)
3094 printf (_(" File: %s"), dynamic_strings
+ ent
.vn_file
);
3096 printf (_(" File: %lx"), ent
.vn_file
);
3098 printf (_(" Cnt: %d\n"), ent
.vn_cnt
);
3100 vstart
+= ent
.vn_aux
;
3102 for (j
= 0, isum
= idx
+ ent
.vn_aux
; j
< ent
.vn_cnt
; ++j
)
3104 Elf_External_Vernaux
* eaux
;
3105 Elf_Internal_Vernaux aux
;
3107 eaux
= (Elf_External_Vernaux
*) vstart
;
3109 aux
.vna_hash
= BYTE_GET (eaux
->vna_hash
);
3110 aux
.vna_flags
= BYTE_GET (eaux
->vna_flags
);
3111 aux
.vna_other
= BYTE_GET (eaux
->vna_other
);
3112 aux
.vna_name
= BYTE_GET (eaux
->vna_name
);
3113 aux
.vna_next
= BYTE_GET (eaux
->vna_next
);
3115 if (dynamic_strings
)
3116 printf (_(" %#06x: Name: %s"),
3117 isum
, dynamic_strings
+ aux
.vna_name
);
3119 printf (_(" %#06x: Name index: %lx"),
3120 isum
, aux
.vna_name
);
3122 printf (_(" Flags: %s Version: %d\n"),
3123 get_ver_flags (aux
.vna_flags
), aux
.vna_other
);
3125 isum
+= aux
.vna_next
;
3126 vstart
+= aux
.vna_next
;
3136 case SHT_GNU_versym
:
3138 Elf32_Internal_Shdr
* link_section
;
3141 unsigned char * edata
;
3142 unsigned short * data
;
3144 Elf_Internal_Sym
* symbols
;
3145 Elf32_Internal_Shdr
* string_sec
;
3147 link_section
= section_headers
+ section
->sh_link
;
3148 total
= section
->sh_size
/ section
->sh_entsize
;
3152 symbols
= GET_ELF_SYMBOLS (file
, link_section
->sh_offset
,
3153 link_section
->sh_size
/ link_section
->sh_entsize
);
3155 string_sec
= section_headers
+ link_section
->sh_link
;
3157 GET_DATA_ALLOC (string_sec
->sh_offset
, string_sec
->sh_size
,
3158 strtab
, char *, "version string table");
3160 printf (_("\nVersion symbols section '%s' contains %d entries:\n"),
3161 SECTION_NAME (section
), total
);
3163 printf (_(" Addr: "));
3164 printf_vma (section
->sh_addr
);
3165 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
3166 (unsigned long) section
->sh_offset
, section
->sh_link
,
3167 SECTION_NAME (link_section
));
3169 GET_DATA_ALLOC (version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)]
3171 total
* sizeof (short), edata
,
3172 unsigned char *, "version symbol data");
3174 data
= (unsigned short *) malloc (total
* sizeof (short));
3176 for (cnt
= total
; cnt
--;)
3177 data
[cnt
] = byte_get (edata
+ cnt
* sizeof (short),
3182 for (cnt
= 0; cnt
< total
; cnt
+= 4)
3186 printf (" %03x:", cnt
);
3188 for (j
= 0; (j
< 4) && (cnt
+ j
) < total
; ++j
)
3189 switch (data
[cnt
+ j
])
3192 fputs (_(" 0 (*local*) "), stdout
);
3196 fputs (_(" 1 (*global*) "), stdout
);
3200 nn
= printf ("%4x%c", data
[cnt
+ j
] & 0x7fff,
3201 data
[cnt
+ j
] & 0x8000 ? 'h' : ' ');
3203 if (symbols
[cnt
+ j
].st_shndx
< SHN_LORESERVE
3204 && section_headers
[symbols
[cnt
+ j
].st_shndx
].sh_type
3207 /* We must test both. */
3208 Elf_Internal_Verneed ivn
;
3209 unsigned long offset
;
3211 offset
= version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)]
3216 Elf_External_Verneed evn
;
3217 Elf_External_Vernaux evna
;
3218 Elf_Internal_Vernaux ivna
;
3219 unsigned long vna_off
;
3221 GET_DATA (offset
, evn
, "version need");
3223 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
3224 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
3226 vna_off
= offset
+ ivn
.vn_aux
;
3230 GET_DATA (vna_off
, evna
,
3231 "version need aux (1)");
3233 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
3234 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
3236 vna_off
+= ivna
.vna_next
;
3238 while (ivna
.vna_other
!= data
[cnt
+ j
]
3239 && ivna
.vna_next
!= 0);
3241 if (ivna
.vna_other
== data
[cnt
+ j
])
3243 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
3245 nn
+= printf ("(%s%-*s",
3246 strtab
+ ivna
.vna_name
,
3252 else if (ivn
.vn_next
== 0)
3254 if (data
[cnt
+ j
] != 0x8001)
3256 Elf_Internal_Verdef ivd
;
3257 Elf_External_Verdef evd
;
3259 offset
= version_info
3260 [DT_VERSIONTAGIDX (DT_VERDEF
)]
3265 GET_DATA (offset
, evd
,
3266 "version definition");
3268 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
3269 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
3271 offset
+= ivd
.vd_next
;
3274 != (data
[cnt
+ j
] & 0x7fff)
3275 && ivd
.vd_next
!= 0);
3278 == (data
[cnt
+ j
] & 0x7fff))
3280 Elf_External_Verdaux evda
;
3281 Elf_Internal_Verdaux ivda
;
3283 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
3285 GET_DATA (offset
+ ivd
.vd_aux
, evda
,
3286 "version definition aux");
3289 BYTE_GET (evda
.vda_name
);
3293 strtab
+ ivda
.vda_name
,
3304 offset
+= ivn
.vn_next
;
3306 while (ivn
.vn_next
);
3308 else if (symbols
[cnt
+ j
].st_shndx
== SHN_UNDEF
)
3310 Elf_Internal_Verneed ivn
;
3311 unsigned long offset
;
3313 offset
= version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)]
3318 Elf_Internal_Vernaux ivna
;
3319 Elf_External_Verneed evn
;
3320 Elf_External_Vernaux evna
;
3321 unsigned long a_off
;
3323 GET_DATA (offset
, evn
, "version need");
3325 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
3326 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
3328 a_off
= offset
+ ivn
.vn_aux
;
3332 GET_DATA (a_off
, evna
,
3333 "version need aux (2)");
3335 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
3336 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
3338 a_off
+= ivna
.vna_next
;
3340 while (ivna
.vna_other
!= data
[cnt
+ j
]
3341 && ivna
.vna_next
!= 0);
3343 if (ivna
.vna_other
== data
[cnt
+ j
])
3345 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
3347 nn
+= printf ("(%s%-*s",
3348 strtab
+ ivna
.vna_name
,
3355 offset
+= ivn
.vn_next
;
3357 while (ivn
.vn_next
);
3359 else if (data
[cnt
+ j
] != 0x8001)
3361 Elf_Internal_Verdef ivd
;
3362 Elf_External_Verdef evd
;
3363 unsigned long offset
;
3365 offset
= version_info
3366 [DT_VERSIONTAGIDX (DT_VERDEF
)] - loadaddr
;
3370 GET_DATA (offset
, evd
, "version def");
3372 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
3373 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
3375 offset
+= ivd
.vd_next
;
3377 while (ivd
.vd_ndx
!= (data
[cnt
+ j
] & 0x7fff)
3378 && ivd
.vd_next
!= 0);
3380 if (ivd
.vd_ndx
== (data
[cnt
+ j
] & 0x7fff))
3382 Elf_External_Verdaux evda
;
3383 Elf_Internal_Verdaux ivda
;
3385 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
3387 GET_DATA (offset
- ivd
.vd_next
+ ivd
.vd_aux
,
3388 evda
, "version def aux");
3390 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
3392 nn
+= printf ("(%s%-*s",
3393 strtab
+ ivda
.vda_name
,
3401 printf ("%*c", 18 - nn
, ' ');
3419 printf (_("\nNo version information found in this file.\n"));
3425 get_symbol_binding (binding
)
3426 unsigned int binding
;
3428 static char buff
[32];
3432 case STB_LOCAL
: return _("LOCAL");
3433 case STB_GLOBAL
: return _("GLOBAL");
3434 case STB_WEAK
: return _("WEAK");
3436 if (binding
>= STB_LOPROC
&& binding
<= STB_HIPROC
)
3437 sprintf (buff
, _("<processor specific>: %d"), binding
);
3438 else if (binding
>= STB_LOOS
&& binding
<= STB_HIOS
)
3439 sprintf (buff
, _("<OS specific>: %d"), binding
);
3441 sprintf (buff
, _("<unknown>: %d"), binding
);
3447 get_symbol_type (type
)
3450 static char buff
[32];
3454 case STT_NOTYPE
: return _("NOTYPE");
3455 case STT_OBJECT
: return _("OBJECT");
3456 case STT_FUNC
: return _("FUNC");
3457 case STT_SECTION
: return _("SECTION");
3458 case STT_FILE
: return _("FILE");
3460 if (type
>= STT_LOPROC
&& type
<= STT_HIPROC
)
3462 if (elf_header
.e_machine
== EM_ARM
&& type
== STT_ARM_TFUNC
)
3463 return _("THUMB_FUNC");
3465 if (elf_header
.e_machine
== EM_SPARCV9
&& type
== STT_REGISTER
)
3466 return _("REGISTER");
3468 sprintf (buff
, _("<processor specific>: %d"), type
);
3470 else if (type
>= STT_LOOS
&& type
<= STT_HIOS
)
3471 sprintf (buff
, _("<OS specific>: %d"), type
);
3473 sprintf (buff
, _("<unknown>: %d"), type
);
3479 get_symbol_index_type (type
)
3484 case SHN_UNDEF
: return "UND";
3485 case SHN_ABS
: return "ABS";
3486 case SHN_COMMON
: return "COM";
3488 if (type
>= SHN_LOPROC
&& type
<= SHN_HIPROC
)
3490 else if (type
>= SHN_LORESERVE
&& type
<= SHN_HIRESERVE
)
3492 else if (type
>= SHN_LOOS
&& type
<= SHN_HIOS
)
3496 static char buff
[32];
3498 sprintf (buff
, "%3d", type
);
3506 get_dynamic_data (file
, number
)
3508 unsigned int number
;
3513 e_data
= (char *) malloc (number
* 4);
3517 error (_("Out of memory\n"));
3521 if (fread (e_data
, 4, number
, file
) != number
)
3523 error (_("Unable to read in dynamic data\n"));
3527 i_data
= (int *) malloc (number
* sizeof (* i_data
));
3531 error (_("Out of memory\n"));
3537 i_data
[number
] = byte_get (e_data
+ number
* 4, 4);
3544 /* Dump the symbol table */
3546 process_symbol_table (file
)
3549 Elf32_Internal_Shdr
* section
;
3554 int * buckets
= NULL
;
3555 int * chains
= NULL
;
3557 if (! do_syms
&& !do_histogram
)
3560 if (dynamic_info
[DT_HASH
] && ((do_using_dynamic
&& dynamic_strings
!= NULL
)
3563 if (fseek (file
, dynamic_info
[DT_HASH
] - loadaddr
, SEEK_SET
))
3565 error (_("Unable to seek to start of dynamic information"));
3569 if (fread (nb
, sizeof (nb
), 1, file
) != 1)
3571 error (_("Failed to read in number of buckets\n"));
3575 if (fread (nc
, sizeof (nc
), 1, file
) != 1)
3577 error (_("Failed to read in number of chains\n"));
3581 nbuckets
= byte_get (nb
, 4);
3582 nchains
= byte_get (nc
, 4);
3584 buckets
= get_dynamic_data (file
, nbuckets
);
3585 chains
= get_dynamic_data (file
, nchains
);
3587 if (buckets
== NULL
|| chains
== NULL
)
3592 && dynamic_info
[DT_HASH
] && do_using_dynamic
&& dynamic_strings
!= NULL
)
3597 printf (_("\nSymbol table for image:\n"));
3598 printf (_(" Num Buc: Value Size Type Bind Ot Ndx Name\n"));
3600 for (hn
= 0; hn
< nbuckets
; hn
++)
3605 for (si
= buckets
[hn
]; si
; si
= chains
[si
])
3607 Elf_Internal_Sym
* psym
;
3609 psym
= dynamic_symbols
+ si
;
3611 printf (" %3d %3d: %8lx %5ld %6s %6s %2d ",
3613 (unsigned long) psym
->st_value
,
3614 (unsigned long) psym
->st_size
,
3615 get_symbol_type (ELF_ST_TYPE (psym
->st_info
)),
3616 get_symbol_binding (ELF_ST_BIND (psym
->st_info
)),
3619 printf ("%3.3s", get_symbol_index_type (psym
->st_shndx
));
3621 printf (" %s\n", dynamic_strings
+ psym
->st_name
);
3625 else if (do_syms
&& !do_using_dynamic
)
3629 for (i
= 0, section
= section_headers
;
3630 i
< elf_header
.e_shnum
;
3635 Elf_Internal_Sym
* symtab
;
3636 Elf_Internal_Sym
* psym
;
3639 if ( section
->sh_type
!= SHT_SYMTAB
3640 && section
->sh_type
!= SHT_DYNSYM
)
3643 printf (_("\nSymbol table '%s' contains %lu entries:\n"),
3644 SECTION_NAME (section
),
3645 (unsigned long) (section
->sh_size
/ section
->sh_entsize
));
3646 fputs (_(" Num: Value Size Type Bind Ot Ndx Name\n"),
3649 symtab
= GET_ELF_SYMBOLS (file
, section
->sh_offset
,
3650 section
->sh_size
/ section
->sh_entsize
);
3654 if (section
->sh_link
== elf_header
.e_shstrndx
)
3655 strtab
= string_table
;
3658 Elf32_Internal_Shdr
* string_sec
;
3660 string_sec
= section_headers
+ section
->sh_link
;
3662 GET_DATA_ALLOC (string_sec
->sh_offset
, string_sec
->sh_size
,
3663 strtab
, char *, "string table");
3666 for (si
= 0, psym
= symtab
;
3667 si
< section
->sh_size
/ section
->sh_entsize
;
3670 printf (" %3d: %8lx %5ld %-7s %-6s %2d ",
3672 (unsigned long) psym
->st_value
,
3673 (unsigned long) psym
->st_size
,
3674 get_symbol_type (ELF_ST_TYPE (psym
->st_info
)),
3675 get_symbol_binding (ELF_ST_BIND (psym
->st_info
)),
3678 printf ("%4s", get_symbol_index_type (psym
->st_shndx
));
3680 printf (" %s", strtab
+ psym
->st_name
);
3682 if (section
->sh_type
== SHT_DYNSYM
&&
3683 version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)] != 0)
3685 unsigned char data
[2];
3686 unsigned short vers_data
;
3687 unsigned long offset
;
3691 offset
= version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)]
3694 GET_DATA (offset
+ si
* sizeof (vers_data
), data
,
3697 vers_data
= byte_get (data
, 2);
3699 is_nobits
= psym
->st_shndx
< SHN_LORESERVE
?
3700 (section_headers
[psym
->st_shndx
].sh_type
== SHT_NOBITS
)
3703 check_def
= (psym
->st_shndx
!= SHN_UNDEF
);
3705 if ((vers_data
& 0x8000) || vers_data
> 1)
3707 if (is_nobits
|| ! check_def
)
3709 Elf_External_Verneed evn
;
3710 Elf_Internal_Verneed ivn
;
3711 Elf_Internal_Vernaux ivna
;
3713 /* We must test both. */
3714 offset
= version_info
3715 [DT_VERSIONTAGIDX (DT_VERNEED
)] - loadaddr
;
3717 GET_DATA (offset
, evn
, "version need");
3719 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
3720 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
3724 unsigned long vna_off
;
3726 vna_off
= offset
+ ivn
.vn_aux
;
3730 Elf_External_Vernaux evna
;
3732 GET_DATA (vna_off
, evna
,
3733 "version need aux (3)");
3735 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
3736 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
3737 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
3739 vna_off
+= ivna
.vna_next
;
3741 while (ivna
.vna_other
!= vers_data
3742 && ivna
.vna_next
!= 0);
3744 if (ivna
.vna_other
== vers_data
)
3747 offset
+= ivn
.vn_next
;
3749 while (ivn
.vn_next
!= 0);
3751 if (ivna
.vna_other
== vers_data
)
3754 strtab
+ ivna
.vna_name
, ivna
.vna_other
);
3757 else if (! is_nobits
)
3758 error (_("bad dynamic symbol"));
3765 if (vers_data
!= 0x8001)
3767 Elf_Internal_Verdef ivd
;
3768 Elf_Internal_Verdaux ivda
;
3769 Elf_External_Verdaux evda
;
3770 unsigned long offset
;
3773 version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)]
3778 Elf_External_Verdef evd
;
3780 GET_DATA (offset
, evd
, "version def");
3782 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
3783 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
3784 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
3786 offset
+= ivd
.vd_next
;
3788 while (ivd
.vd_ndx
!= (vers_data
& 0x7fff)
3789 && ivd
.vd_next
!= 0);
3791 offset
-= ivd
.vd_next
;
3792 offset
+= ivd
.vd_aux
;
3794 GET_DATA (offset
, evda
, "version def aux");
3796 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
3798 if (psym
->st_name
!= ivda
.vda_name
)
3799 printf ((vers_data
& 0x8000)
3801 strtab
+ ivda
.vda_name
);
3811 if (strtab
!= string_table
)
3817 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
3819 if (do_histogram
&& buckets
!= NULL
)
3826 int nzero_counts
= 0;
3829 printf (_("\nHistogram for bucket list length (total of %d buckets):\n"),
3831 printf (_(" Length Number %% of total Coverage\n"));
3833 lengths
= (int *) calloc (nbuckets
, sizeof (int));
3834 if (lengths
== NULL
)
3836 error (_("Out of memory"));
3839 for (hn
= 0; hn
< nbuckets
; ++hn
)
3844 for (si
= buckets
[hn
]; si
; si
= chains
[si
])
3847 if (maxlength
< ++lengths
[hn
])
3852 counts
= (int *) calloc (maxlength
+ 1, sizeof (int));
3855 error (_("Out of memory"));
3859 for (hn
= 0; hn
< nbuckets
; ++hn
)
3860 ++ counts
[lengths
[hn
]];
3862 printf (" 0 %-10d (%5.1f%%)\n",
3863 counts
[0], (counts
[0] * 100.0) / nbuckets
);
3864 for (si
= 1; si
<= maxlength
; ++si
)
3866 nzero_counts
+= counts
[si
] * si
;
3867 printf ("%7d %-10d (%5.1f%%) %5.1f%%\n",
3868 si
, counts
[si
], (counts
[si
] * 100.0) / nbuckets
,
3869 (nzero_counts
* 100.0) / nsyms
);
3876 if (buckets
!= NULL
)
3886 process_syminfo (file
)
3887 FILE * file ATTRIBUTE_UNUSED
;
3891 if (dynamic_syminfo
== NULL
3893 /* No syminfo, this is ok. */
3896 /* There better should be a dynamic symbol section. */
3897 if (dynamic_symbols
== NULL
|| dynamic_strings
== NULL
)
3901 printf (_("\nDynamic info segment at offset 0x%lx contains %d entries:\n"),
3902 dynamic_syminfo_offset
, dynamic_syminfo_nent
);
3904 printf (_(" Num: Name BoundTo Flags\n"));
3905 for (i
= 0; i
< dynamic_syminfo_nent
; ++i
)
3907 unsigned short int flags
= dynamic_syminfo
[i
].si_flags
;
3909 printf ("%4d: %-30s ", i
,
3910 dynamic_strings
+ dynamic_symbols
[i
].st_name
);
3912 switch (dynamic_syminfo
[i
].si_boundto
)
3914 case SYMINFO_BT_SELF
:
3915 fputs ("SELF ", stdout
);
3917 case SYMINFO_BT_PARENT
:
3918 fputs ("PARENT ", stdout
);
3921 if (dynamic_syminfo
[i
].si_boundto
> 0
3922 && dynamic_syminfo
[i
].si_boundto
< dynamic_size
)
3925 + dynamic_segment
[dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
);
3927 printf ("%-10d ", dynamic_syminfo
[i
].si_boundto
);
3931 if (flags
& SYMINFO_FLG_DIRECT
)
3933 if (flags
& SYMINFO_FLG_PASSTHRU
)
3934 printf (" PASSTHRU");
3935 if (flags
& SYMINFO_FLG_COPY
)
3937 if (flags
& SYMINFO_FLG_LAZYLOAD
)
3938 printf (" LAZYLOAD");
3946 #ifdef SUPPORT_DISASSEMBLY
3948 disassemble_section (section
, file
)
3949 Elf32_Internal_Shdr
* section
;
3952 printf (_("\nAssembly dump of section %s\n"),
3953 SECTION_NAME (section
));
3955 /* XXX -- to be done --- XXX */
3962 dump_section (section
, file
)
3963 Elf32_Internal_Shdr
* section
;
3966 bfd_size_type bytes
;
3968 unsigned char * data
;
3969 unsigned char * start
;
3971 bytes
= section
->sh_size
;
3975 printf (_("\nSection '%s' has no data to dump.\n"),
3976 SECTION_NAME (section
));
3980 printf (_("\nHex dump of section '%s':\n"), SECTION_NAME (section
));
3982 addr
= section
->sh_addr
;
3984 GET_DATA_ALLOC (section
->sh_offset
, bytes
, start
, unsigned char *,
3995 lbytes
= (bytes
> 16 ? 16 : bytes
);
3997 printf (" 0x%8.8lx ", (unsigned long) addr
);
3999 switch (elf_header
.e_ident
[EI_DATA
])
4003 for (j
= 15; j
>= 0; j
--)
4006 printf ("%2.2x", data
[j
]);
4016 for (j
= 0; j
< 16; j
++)
4019 printf ("%2.2x", data
[j
]);
4029 for (j
= 0; j
< lbytes
; j
++)
4032 if (k
>= ' ' && k
< 0x80)
4051 static unsigned long int
4052 read_leb128 (data
, length_return
, sign
)
4053 unsigned char * data
;
4054 int * length_return
;
4057 unsigned long int result
= 0;
4058 unsigned int num_read
= 0;
4067 result
|= (byte
& 0x7f) << shift
;
4072 while (byte
& 0x80);
4074 if (length_return
!= NULL
)
4075 * length_return
= num_read
;
4077 if (sign
&& (shift
< 32) && (byte
& 0x40))
4078 result
|= -1 << shift
;
4083 typedef struct State_Machine_Registers
4085 unsigned long address
;
4088 unsigned int column
;
4092 /* This variable hold the number of the last entry seen
4093 in the File Table. */
4094 unsigned int last_file_entry
;
4097 static SMR state_machine_regs
;
4100 reset_state_machine (is_stmt
)
4103 state_machine_regs
.address
= 0;
4104 state_machine_regs
.file
= 1;
4105 state_machine_regs
.line
= 1;
4106 state_machine_regs
.column
= 0;
4107 state_machine_regs
.is_stmt
= is_stmt
;
4108 state_machine_regs
.basic_block
= 0;
4109 state_machine_regs
.end_sequence
= 0;
4110 state_machine_regs
.last_file_entry
= 0;
4113 /* Handled an extend line op. Returns true if this is the end
4116 process_extended_line_op (data
, is_stmt
)
4117 unsigned char * data
;
4120 unsigned char op_code
;
4123 unsigned char * name
;
4126 len
= read_leb128 (data
, & bytes_read
, 0);
4131 warn (_("badly formed extended line op encountered!"));
4136 op_code
= * data
++;
4138 printf (_(" Extended opcode %d: "), op_code
);
4142 case DW_LNE_end_sequence
:
4143 printf (_("End of Sequence\n\n"));
4144 reset_state_machine (is_stmt
);
4147 case DW_LNE_set_address
:
4148 /* XXX - assumption here that address size is 4! */
4149 adr
= byte_get (data
, 4);
4150 printf (_("set Address to 0x%lx\n"), adr
);
4151 state_machine_regs
.address
= adr
;
4154 case DW_LNE_define_file
:
4155 printf (_(" define new File Table entry\n"));
4156 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
4158 printf (_(" %d\t"), ++ state_machine_regs
.last_file_entry
);
4160 data
+= strlen (data
) + 1;
4161 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
4163 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
4165 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
4166 printf (_("%s\n\n"), name
);
4170 printf (_("UNKNOWN: length %d\n"), len
- bytes_read
);
4179 display_debug_lines (section
, start
, file
)
4180 Elf32_Internal_Shdr
* section
;
4181 unsigned char * start
;
4182 FILE * file ATTRIBUTE_UNUSED
;
4184 DWARF2_External_LineInfo
* external
;
4185 DWARF2_Internal_LineInfo info
;
4186 unsigned char * standard_opcodes
;
4187 unsigned char * data
= start
;
4188 unsigned char * end
= start
+ section
->sh_size
;
4189 unsigned char * end_of_sequence
;
4192 printf (_("\nDump of debug contents of section %s:\n\n"),
4193 SECTION_NAME (section
));
4197 external
= (DWARF2_External_LineInfo
*) data
;
4199 /* Check the length of the block. */
4200 info
.li_length
= BYTE_GET (external
->li_length
);
4201 if (info
.li_length
> section
->sh_size
)
4204 (_("The line info appears to be corrupt - the section is too small\n"));
4208 /* Check its version number. */
4209 info
.li_version
= BYTE_GET (external
->li_version
);
4210 if (info
.li_version
!= 2)
4212 warn (_("Only DWARF version 2 line info is currently supported.\n"));
4216 info
.li_prologue_length
= BYTE_GET (external
->li_prologue_length
);
4217 info
.li_min_insn_length
= BYTE_GET (external
->li_min_insn_length
);
4218 info
.li_default_is_stmt
= BYTE_GET (external
->li_default_is_stmt
);
4219 info
.li_line_base
= BYTE_GET (external
->li_line_base
);
4220 info
.li_line_range
= BYTE_GET (external
->li_line_range
);
4221 info
.li_opcode_base
= BYTE_GET (external
->li_opcode_base
);
4223 /* Sign extend the line base field. */
4224 info
.li_line_base
<<= 24;
4225 info
.li_line_base
>>= 24;
4227 printf (_(" Length: %ld\n"), info
.li_length
);
4228 printf (_(" DWARF Version: %d\n"), info
.li_version
);
4229 printf (_(" Prolgue Length: %d\n"), info
.li_prologue_length
);
4230 printf (_(" Minimum Instruction Length: %d\n"), info
.li_min_insn_length
);
4231 printf (_(" Initial value of 'is_stmt': %d\n"), info
.li_default_is_stmt
);
4232 printf (_(" Line Base: %d\n"), info
.li_line_base
);
4233 printf (_(" Line Range: %d\n"), info
.li_line_range
);
4234 printf (_(" Opcode Base: %d\n"), info
.li_opcode_base
);
4236 end_of_sequence
= data
+ info
.li_length
+ sizeof (info
.li_length
);
4238 reset_state_machine (info
.li_default_is_stmt
);
4240 /* Display the contents of the Opcodes table. */
4241 standard_opcodes
= data
+ sizeof (* external
);
4243 printf (_("\n Opcodes:\n"));
4245 for (i
= 1; i
< info
.li_opcode_base
; i
++)
4246 printf (_(" Opcode %d has %d args\n"), i
, standard_opcodes
[i
]);
4248 /* Display the contents of the Directory table. */
4249 data
= standard_opcodes
+ info
.li_opcode_base
- 1;
4252 printf (_("\n The Directory Table is empty.\n"));
4255 printf (_("\n The Directory Table:\n"));
4259 printf (_(" %s\n"), data
);
4261 data
+= strlen (data
) + 1;
4265 /* Skip the NUL at the end of the table. */
4268 /* Display the contents of the File Name table. */
4270 printf (_("\n The File Name Table is empty.\n"));
4273 printf (_("\n The File Name Table:\n"));
4274 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
4281 printf (_(" %d\t"), ++ state_machine_regs
.last_file_entry
);
4284 data
+= strlen (data
) + 1;
4286 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
4288 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
4290 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
4292 printf (_("%s\n"), name
);
4296 /* Skip the NUL at the end of the table. */
4299 /* Now display the statements. */
4300 printf (_("\n Line Number Statements:\n"));
4303 while (data
< end_of_sequence
)
4305 unsigned char op_code
;
4309 op_code
= * data
++;
4313 case DW_LNS_extended_op
:
4314 data
+= process_extended_line_op (data
, info
.li_default_is_stmt
);
4318 printf (_(" Copy\n"));
4321 case DW_LNS_advance_pc
:
4322 adv
= info
.li_min_insn_length
* read_leb128 (data
, & bytes_read
, 0);
4324 state_machine_regs
.address
+= adv
;
4325 printf (_(" Advance PC by %d to %lx\n"), adv
,
4326 state_machine_regs
.address
);
4329 case DW_LNS_advance_line
:
4330 adv
= read_leb128 (data
, & bytes_read
, 1);
4332 state_machine_regs
.line
+= adv
;
4333 printf (_(" Advance Line by %d to %d\n"), adv
,
4334 state_machine_regs
.line
);
4337 case DW_LNS_set_file
:
4338 adv
= read_leb128 (data
, & bytes_read
, 0);
4340 printf (_(" Set File Name to entry %d in the File Name Table\n"),
4342 state_machine_regs
.file
= adv
;
4345 case DW_LNS_set_column
:
4346 adv
= read_leb128 (data
, & bytes_read
, 0);
4348 printf (_(" Set column to %d\n"), adv
);
4349 state_machine_regs
.column
= adv
;
4352 case DW_LNS_negate_stmt
:
4353 adv
= state_machine_regs
.is_stmt
;
4355 printf (_(" Set is_stmt to %d\n"), adv
);
4356 state_machine_regs
.is_stmt
= adv
;
4359 case DW_LNS_set_basic_block
:
4360 printf (_(" Set basic block\n"));
4361 state_machine_regs
.basic_block
= 1;
4364 case DW_LNS_const_add_pc
:
4365 adv
= (255 - info
.li_opcode_base
) / info
.li_line_range
;
4366 state_machine_regs
.address
+= adv
;
4367 printf (_(" Advance PC by constant %d to 0x%lx\n"), adv
,
4368 state_machine_regs
.address
);
4371 case DW_LNS_fixed_advance_pc
:
4372 adv
= byte_get (data
, 2);
4374 state_machine_regs
.address
+= adv
;
4375 printf (_(" Advance PC by fixed size amount %d to 0x%lx\n"),
4376 adv
, state_machine_regs
.address
);
4380 op_code
-= info
.li_opcode_base
;
4381 adv
= (op_code
/ info
.li_line_range
) * info
.li_min_insn_length
;
4382 state_machine_regs
.address
+= adv
;
4383 printf (_(" Special opcode %d: advance Address by %d to 0x%lx"),
4384 op_code
, adv
, state_machine_regs
.address
);
4385 adv
+= (op_code
% info
.li_line_range
) + info
.li_line_base
;
4386 state_machine_regs
.line
+= adv
;
4387 printf (_(" and Line by %d to %d\n"),
4388 adv
, state_machine_regs
.line
);
4399 display_debug_pubnames (section
, start
, file
)
4400 Elf32_Internal_Shdr
* section
;
4401 unsigned char * start
;
4402 FILE * file ATTRIBUTE_UNUSED
;
4404 DWARF2_External_PubNames
* external
;
4405 DWARF2_Internal_PubNames pubnames
;
4406 unsigned char * end
;
4408 end
= start
+ section
->sh_size
;
4410 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section
));
4414 unsigned char * data
;
4415 unsigned long offset
;
4417 external
= (DWARF2_External_PubNames
*) start
;
4419 pubnames
.pn_length
= BYTE_GET (external
->pn_length
);
4420 pubnames
.pn_version
= BYTE_GET (external
->pn_version
);
4421 pubnames
.pn_offset
= BYTE_GET (external
->pn_offset
);
4422 pubnames
.pn_size
= BYTE_GET (external
->pn_size
);
4424 data
= start
+ sizeof (* external
);
4425 start
+= pubnames
.pn_length
+ sizeof (external
->pn_length
);
4427 if (pubnames
.pn_version
!= 2)
4429 warn (_("Only DWARF 2 pubnames are currently supported"));
4433 printf (_(" Length: %ld\n"),
4434 pubnames
.pn_length
);
4435 printf (_(" Version: %d\n"),
4436 pubnames
.pn_version
);
4437 printf (_(" Offset into .debug_info section: %ld\n"),
4438 pubnames
.pn_offset
);
4439 printf (_(" Size of area in .debug_info section: %ld\n"),
4442 printf (_("\n Offset\tName\n"));
4446 offset
= byte_get (data
, 4);
4451 printf (" %ld\t\t%s\n", offset
, data
);
4452 data
+= strlen (data
) + 1;
4455 while (offset
!= 0);
4468 case DW_TAG_padding
: return "DW_TAG_padding";
4469 case DW_TAG_array_type
: return "DW_TAG_array_type";
4470 case DW_TAG_class_type
: return "DW_TAG_class_type";
4471 case DW_TAG_entry_point
: return "DW_TAG_entry_point";
4472 case DW_TAG_enumeration_type
: return "DW_TAG_enumeration_type";
4473 case DW_TAG_formal_parameter
: return "DW_TAG_formal_parameter";
4474 case DW_TAG_imported_declaration
: return "DW_TAG_imported_declaration";
4475 case DW_TAG_label
: return "DW_TAG_label";
4476 case DW_TAG_lexical_block
: return "DW_TAG_lexical_block";
4477 case DW_TAG_member
: return "DW_TAG_member";
4478 case DW_TAG_pointer_type
: return "DW_TAG_pointer_type";
4479 case DW_TAG_reference_type
: return "DW_TAG_reference_type";
4480 case DW_TAG_compile_unit
: return "DW_TAG_compile_unit";
4481 case DW_TAG_string_type
: return "DW_TAG_string_type";
4482 case DW_TAG_structure_type
: return "DW_TAG_structure_type";
4483 case DW_TAG_subroutine_type
: return "DW_TAG_subroutine_type";
4484 case DW_TAG_typedef
: return "DW_TAG_typedef";
4485 case DW_TAG_union_type
: return "DW_TAG_union_type";
4486 case DW_TAG_unspecified_parameters
: return "DW_TAG_unspecified_parameters";
4487 case DW_TAG_variant
: return "DW_TAG_variant";
4488 case DW_TAG_common_block
: return "DW_TAG_common_block";
4489 case DW_TAG_common_inclusion
: return "DW_TAG_common_inclusion";
4490 case DW_TAG_inheritance
: return "DW_TAG_inheritance";
4491 case DW_TAG_inlined_subroutine
: return "DW_TAG_inlined_subroutine";
4492 case DW_TAG_module
: return "DW_TAG_module";
4493 case DW_TAG_ptr_to_member_type
: return "DW_TAG_ptr_to_member_type";
4494 case DW_TAG_set_type
: return "DW_TAG_set_type";
4495 case DW_TAG_subrange_type
: return "DW_TAG_subrange_type";
4496 case DW_TAG_with_stmt
: return "DW_TAG_with_stmt";
4497 case DW_TAG_access_declaration
: return "DW_TAG_access_declaration";
4498 case DW_TAG_base_type
: return "DW_TAG_base_type";
4499 case DW_TAG_catch_block
: return "DW_TAG_catch_block";
4500 case DW_TAG_const_type
: return "DW_TAG_const_type";
4501 case DW_TAG_constant
: return "DW_TAG_constant";
4502 case DW_TAG_enumerator
: return "DW_TAG_enumerator";
4503 case DW_TAG_file_type
: return "DW_TAG_file_type";
4504 case DW_TAG_friend
: return "DW_TAG_friend";
4505 case DW_TAG_namelist
: return "DW_TAG_namelist";
4506 case DW_TAG_namelist_item
: return "DW_TAG_namelist_item";
4507 case DW_TAG_packed_type
: return "DW_TAG_packed_type";
4508 case DW_TAG_subprogram
: return "DW_TAG_subprogram";
4509 case DW_TAG_template_type_param
: return "DW_TAG_template_type_param";
4510 case DW_TAG_template_value_param
: return "DW_TAG_template_value_param";
4511 case DW_TAG_thrown_type
: return "DW_TAG_thrown_type";
4512 case DW_TAG_try_block
: return "DW_TAG_try_block";
4513 case DW_TAG_variant_part
: return "DW_TAG_variant_part";
4514 case DW_TAG_variable
: return "DW_TAG_variable";
4515 case DW_TAG_volatile_type
: return "DW_TAG_volatile_type";
4516 case DW_TAG_MIPS_loop
: return "DW_TAG_MIPS_loop";
4517 case DW_TAG_format_label
: return "DW_TAG_format_label";
4518 case DW_TAG_function_template
: return "DW_TAG_function_template";
4519 case DW_TAG_class_template
: return "DW_TAG_class_template";
4522 static char buffer
[100];
4524 sprintf (buffer
, _("Unknown TAG value: %lx"), tag
);
4531 get_AT_name (attribute
)
4532 unsigned long attribute
;
4536 case DW_AT_sibling
: return "DW_AT_sibling";
4537 case DW_AT_location
: return "DW_AT_location";
4538 case DW_AT_name
: return "DW_AT_name";
4539 case DW_AT_ordering
: return "DW_AT_ordering";
4540 case DW_AT_subscr_data
: return "DW_AT_subscr_data";
4541 case DW_AT_byte_size
: return "DW_AT_byte_size";
4542 case DW_AT_bit_offset
: return "DW_AT_bit_offset";
4543 case DW_AT_bit_size
: return "DW_AT_bit_size";
4544 case DW_AT_element_list
: return "DW_AT_element_list";
4545 case DW_AT_stmt_list
: return "DW_AT_stmt_list";
4546 case DW_AT_low_pc
: return "DW_AT_low_pc";
4547 case DW_AT_high_pc
: return "DW_AT_high_pc";
4548 case DW_AT_language
: return "DW_AT_language";
4549 case DW_AT_member
: return "DW_AT_member";
4550 case DW_AT_discr
: return "DW_AT_discr";
4551 case DW_AT_discr_value
: return "DW_AT_discr_value";
4552 case DW_AT_visibility
: return "DW_AT_visibility";
4553 case DW_AT_import
: return "DW_AT_import";
4554 case DW_AT_string_length
: return "DW_AT_string_length";
4555 case DW_AT_common_reference
: return "DW_AT_common_reference";
4556 case DW_AT_comp_dir
: return "DW_AT_comp_dir";
4557 case DW_AT_const_value
: return "DW_AT_const_value";
4558 case DW_AT_containing_type
: return "DW_AT_containing_type";
4559 case DW_AT_default_value
: return "DW_AT_default_value";
4560 case DW_AT_inline
: return "DW_AT_inline";
4561 case DW_AT_is_optional
: return "DW_AT_is_optional";
4562 case DW_AT_lower_bound
: return "DW_AT_lower_bound";
4563 case DW_AT_producer
: return "DW_AT_producer";
4564 case DW_AT_prototyped
: return "DW_AT_prototyped";
4565 case DW_AT_return_addr
: return "DW_AT_return_addr";
4566 case DW_AT_start_scope
: return "DW_AT_start_scope";
4567 case DW_AT_stride_size
: return "DW_AT_stride_size";
4568 case DW_AT_upper_bound
: return "DW_AT_upper_bound";
4569 case DW_AT_abstract_origin
: return "DW_AT_abstract_origin";
4570 case DW_AT_accessibility
: return "DW_AT_accessibility";
4571 case DW_AT_address_class
: return "DW_AT_address_class";
4572 case DW_AT_artificial
: return "DW_AT_artificial";
4573 case DW_AT_base_types
: return "DW_AT_base_types";
4574 case DW_AT_calling_convention
: return "DW_AT_calling_convention";
4575 case DW_AT_count
: return "DW_AT_count";
4576 case DW_AT_data_member_location
: return "DW_AT_data_member_location";
4577 case DW_AT_decl_column
: return "DW_AT_decl_column";
4578 case DW_AT_decl_file
: return "DW_AT_decl_file";
4579 case DW_AT_decl_line
: return "DW_AT_decl_line";
4580 case DW_AT_declaration
: return "DW_AT_declaration";
4581 case DW_AT_discr_list
: return "DW_AT_discr_list";
4582 case DW_AT_encoding
: return "DW_AT_encoding";
4583 case DW_AT_external
: return "DW_AT_external";
4584 case DW_AT_frame_base
: return "DW_AT_frame_base";
4585 case DW_AT_friend
: return "DW_AT_friend";
4586 case DW_AT_identifier_case
: return "DW_AT_identifier_case";
4587 case DW_AT_macro_info
: return "DW_AT_macro_info";
4588 case DW_AT_namelist_items
: return "DW_AT_namelist_items";
4589 case DW_AT_priority
: return "DW_AT_priority";
4590 case DW_AT_segment
: return "DW_AT_segment";
4591 case DW_AT_specification
: return "DW_AT_specification";
4592 case DW_AT_static_link
: return "DW_AT_static_link";
4593 case DW_AT_type
: return "DW_AT_type";
4594 case DW_AT_use_location
: return "DW_AT_use_location";
4595 case DW_AT_variable_parameter
: return "DW_AT_variable_parameter";
4596 case DW_AT_virtuality
: return "DW_AT_virtuality";
4597 case DW_AT_vtable_elem_location
: return "DW_AT_vtable_elem_location";
4598 case DW_AT_MIPS_fde
: return "DW_AT_MIPS_fde";
4599 case DW_AT_MIPS_loop_begin
: return "DW_AT_MIPS_loop_begin";
4600 case DW_AT_MIPS_tail_loop_begin
: return "DW_AT_MIPS_tail_loop_begin";
4601 case DW_AT_MIPS_epilog_begin
: return "DW_AT_MIPS_epilog_begin";
4602 case DW_AT_MIPS_loop_unroll_factor
: return "DW_AT_MIPS_loop_unroll_factor";
4603 case DW_AT_MIPS_software_pipeline_depth
: return "DW_AT_MIPS_software_pipeline_depth";
4604 case DW_AT_MIPS_linkage_name
: return "DW_AT_MIPS_linkage_name";
4605 case DW_AT_MIPS_stride
: return "DW_AT_MIPS_stride";
4606 case DW_AT_MIPS_abstract_name
: return "DW_AT_MIPS_abstract_name";
4607 case DW_AT_MIPS_clone_origin
: return "DW_AT_MIPS_clone_origin";
4608 case DW_AT_MIPS_has_inlines
: return "DW_AT_MIPS_has_inlines";
4609 case DW_AT_sf_names
: return "DW_AT_sf_names";
4610 case DW_AT_src_info
: return "DW_AT_src_info";
4611 case DW_AT_mac_info
: return "DW_AT_mac_info";
4612 case DW_AT_src_coords
: return "DW_AT_src_coords";
4613 case DW_AT_body_begin
: return "DW_AT_body_begin";
4614 case DW_AT_body_end
: return "DW_AT_body_end";
4617 static char buffer
[100];
4619 sprintf (buffer
, _("Unknown AT value: %lx"), attribute
);
4626 get_FORM_name (form
)
4631 case DW_FORM_addr
: return "DW_FORM_addr";
4632 case DW_FORM_block2
: return "DW_FORM_block2";
4633 case DW_FORM_block4
: return "DW_FORM_block4";
4634 case DW_FORM_data2
: return "DW_FORM_data2";
4635 case DW_FORM_data4
: return "DW_FORM_data4";
4636 case DW_FORM_data8
: return "DW_FORM_data8";
4637 case DW_FORM_string
: return "DW_FORM_string";
4638 case DW_FORM_block
: return "DW_FORM_block";
4639 case DW_FORM_block1
: return "DW_FORM_block1";
4640 case DW_FORM_data1
: return "DW_FORM_data1";
4641 case DW_FORM_flag
: return "DW_FORM_flag";
4642 case DW_FORM_sdata
: return "DW_FORM_sdata";
4643 case DW_FORM_strp
: return "DW_FORM_strp";
4644 case DW_FORM_udata
: return "DW_FORM_udata";
4645 case DW_FORM_ref_addr
: return "DW_FORM_ref_addr";
4646 case DW_FORM_ref1
: return "DW_FORM_ref1";
4647 case DW_FORM_ref2
: return "DW_FORM_ref2";
4648 case DW_FORM_ref4
: return "DW_FORM_ref4";
4649 case DW_FORM_ref8
: return "DW_FORM_ref8";
4650 case DW_FORM_ref_udata
: return "DW_FORM_ref_udata";
4651 case DW_FORM_indirect
: return "DW_FORM_indirect";
4654 static char buffer
[100];
4656 sprintf (buffer
, _("Unknown FORM value: %lx"), form
);
4662 /* FIXME: There are better and more effiecint ways to handle
4663 these structures. For now though, I just want something that
4664 is simple to implement. */
4665 typedef struct abbrev_attr
4667 unsigned long attribute
;
4669 struct abbrev_attr
* next
;
4673 typedef struct abbrev_entry
4675 unsigned long entry
;
4678 struct abbrev_attr
* first_attr
;
4679 struct abbrev_attr
* last_attr
;
4680 struct abbrev_entry
* next
;
4684 static abbrev_entry
* first_abbrev
= NULL
;
4685 static abbrev_entry
* last_abbrev
= NULL
;
4688 free_abbrevs
PARAMS ((void))
4690 abbrev_entry
* abbrev
;
4692 for (abbrev
= first_abbrev
; abbrev
;)
4694 abbrev_entry
* next
= abbrev
->next
;
4697 for (attr
= abbrev
->first_attr
; attr
;)
4699 abbrev_attr
* next
= attr
->next
;
4709 last_abbrev
= first_abbrev
= NULL
;
4713 add_abbrev (number
, tag
, children
)
4714 unsigned long number
;
4718 abbrev_entry
* entry
;
4720 entry
= (abbrev_entry
*) malloc (sizeof (* entry
));
4726 entry
->entry
= number
;
4728 entry
->children
= children
;
4729 entry
->first_attr
= NULL
;
4730 entry
->last_attr
= NULL
;
4733 if (first_abbrev
== NULL
)
4734 first_abbrev
= entry
;
4736 last_abbrev
->next
= entry
;
4738 last_abbrev
= entry
;
4742 add_abbrev_attr (attribute
, form
)
4743 unsigned long attribute
;
4748 attr
= (abbrev_attr
*) malloc (sizeof (* attr
));
4754 attr
->attribute
= attribute
;
4758 if (last_abbrev
->first_attr
== NULL
)
4759 last_abbrev
->first_attr
= attr
;
4761 last_abbrev
->last_attr
->next
= attr
;
4763 last_abbrev
->last_attr
= attr
;
4766 /* Processes the (partial) contents of a .debug_abbrev section.
4767 Returns NULL if the end of the section was encountered.
4768 Returns the address after the last byte read if the end of
4769 an abbreviation set was found. */
4771 static unsigned char *
4772 process_abbrev_section (start
, end
)
4773 unsigned char * start
;
4774 unsigned char * end
;
4776 if (first_abbrev
!= NULL
)
4782 unsigned long entry
;
4784 unsigned long attribute
;
4787 entry
= read_leb128 (start
, & bytes_read
, 0);
4788 start
+= bytes_read
;
4793 tag
= read_leb128 (start
, & bytes_read
, 0);
4794 start
+= bytes_read
;
4796 children
= * start
++;
4798 add_abbrev (entry
, tag
, children
);
4804 attribute
= read_leb128 (start
, & bytes_read
, 0);
4805 start
+= bytes_read
;
4807 form
= read_leb128 (start
, & bytes_read
, 0);
4808 start
+= bytes_read
;
4811 add_abbrev_attr (attribute
, form
);
4813 while (attribute
!= 0);
4821 display_debug_abbrev (section
, start
, file
)
4822 Elf32_Internal_Shdr
* section
;
4823 unsigned char * start
;
4824 FILE * file ATTRIBUTE_UNUSED
;
4826 abbrev_entry
* entry
;
4827 unsigned char * end
= start
+ section
->sh_size
;
4829 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section
));
4833 start
= process_abbrev_section (start
, end
);
4835 printf (_(" Number TAG\n"));
4837 for (entry
= first_abbrev
; entry
; entry
= entry
->next
)
4841 printf (_(" %ld %s [%s]\n"),
4843 get_TAG_name (entry
->tag
),
4844 entry
->children
? _("has children") : _("no children"));
4846 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
4848 printf (_(" %-18s %s\n"),
4849 get_AT_name (attr
->attribute
),
4850 get_FORM_name (attr
->form
));
4862 static unsigned char *
4863 display_block (data
, length
)
4864 unsigned char * data
;
4865 unsigned long length
;
4867 printf (_(" %lu byte block: "), length
);
4870 printf ("%lx ", (unsigned long) byte_get (data
++, 1));
4876 decode_location_expression (data
, pointer_size
)
4877 unsigned char * data
;
4878 unsigned int pointer_size
;
4882 unsigned long uvalue
;
4889 printf ("DW_OP_addr: %lx", (unsigned long) byte_get (data
, pointer_size
));
4892 printf ("DW_OP_deref");
4895 printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data
, 1));
4898 printf ("DW_OP_const1s: %ld", (long) byte_get (data
, 1));
4901 printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data
, 2));
4904 printf ("DW_OP_const2s: %ld", (long) byte_get (data
, 2));
4907 printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data
, 4));
4910 printf ("DW_OP_const4s: %ld", (long) byte_get (data
, 4));
4913 printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data
, 4),
4914 (unsigned long) byte_get (data
+ 4, 4));
4917 printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data
, 4),
4918 (long) byte_get (data
+ 4, 4));
4921 printf ("DW_OP_constu: %lu", read_leb128 (data
, NULL
, 0));
4924 printf ("DW_OP_consts: %ld", read_leb128 (data
, NULL
, 1));
4927 printf ("DW_OP_dup");
4930 printf ("DW_OP_drop");
4933 printf ("DW_OP_over");
4936 printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data
, 1));
4939 printf ("DW_OP_swap");
4942 printf ("DW_OP_rot");
4945 printf ("DW_OP_xderef");
4948 printf ("DW_OP_abs");
4951 printf ("DW_OP_and");
4954 printf ("DW_OP_div");
4957 printf ("DW_OP_minus");
4960 printf ("DW_OP_mod");
4963 printf ("DW_OP_mul");
4966 printf ("DW_OP_neg");
4969 printf ("DW_OP_not");
4972 printf ("DW_OP_or");
4975 printf ("DW_OP_plus");
4977 case DW_OP_plus_uconst
:
4978 printf ("DW_OP_plus_uconst: %lu", read_leb128 (data
, NULL
, 0));
4981 printf ("DW_OP_shl");
4984 printf ("DW_OP_shr");
4987 printf ("DW_OP_shra");
4990 printf ("DW_OP_xor");
4993 printf ("DW_OP_bra: %ld", (long) byte_get (data
, 2));
4996 printf ("DW_OP_eq");
4999 printf ("DW_OP_ge");
5002 printf ("DW_OP_gt");
5005 printf ("DW_OP_le");
5008 printf ("DW_OP_lt");
5011 printf ("DW_OP_ne");
5014 printf ("DW_OP_skip: %ld", (long) byte_get (data
, 2));
5017 printf ("DW_OP_lit0");
5020 printf ("DW_OP_lit1");
5023 printf ("DW_OP_lit2");
5026 printf ("DW_OP_lit3");
5029 printf ("DW_OP_lit4");
5032 printf ("DW_OP_lit5");
5035 printf ("DW_OP_lit6");
5038 printf ("DW_OP_lit7");
5041 printf ("DW_OP_lit8");
5044 printf ("DW_OP_lit9");
5047 printf ("DW_OP_lit10");
5050 printf ("DW_OP_lit11");
5053 printf ("DW_OP_lit12");
5056 printf ("DW_OP_lit13");
5059 printf ("DW_OP_lit14");
5062 printf ("DW_OP_lit15");
5065 printf ("DW_OP_lit16");
5068 printf ("DW_OP_lit17");
5071 printf ("DW_OP_lit18");
5074 printf ("DW_OP_lit19");
5077 printf ("DW_OP_lit20");
5080 printf ("DW_OP_lit21");
5083 printf ("DW_OP_lit22");
5086 printf ("DW_OP_lit23");
5089 printf ("DW_OP_lit24");
5092 printf ("DW_OP_lit25");
5095 printf ("DW_OP_lit26");
5098 printf ("DW_OP_lit27");
5101 printf ("DW_OP_lit28");
5104 printf ("DW_OP_lit29");
5107 printf ("DW_OP_lit30");
5110 printf ("DW_OP_lit31");
5113 printf ("DW_OP_reg0");
5116 printf ("DW_OP_reg1");
5119 printf ("DW_OP_reg2");
5122 printf ("DW_OP_reg3");
5125 printf ("DW_OP_reg4");
5128 printf ("DW_OP_reg5");
5131 printf ("DW_OP_reg6");
5134 printf ("DW_OP_reg7");
5137 printf ("DW_OP_reg8");
5140 printf ("DW_OP_reg9");
5143 printf ("DW_OP_reg10");
5146 printf ("DW_OP_reg11");
5149 printf ("DW_OP_reg12");
5152 printf ("DW_OP_reg13");
5155 printf ("DW_OP_reg14");
5158 printf ("DW_OP_reg15");
5161 printf ("DW_OP_reg16");
5164 printf ("DW_OP_reg17");
5167 printf ("DW_OP_reg18");
5170 printf ("DW_OP_reg19");
5173 printf ("DW_OP_reg20");
5176 printf ("DW_OP_reg21");
5179 printf ("DW_OP_reg22");
5182 printf ("DW_OP_reg23");
5185 printf ("DW_OP_reg24");
5188 printf ("DW_OP_reg25");
5191 printf ("DW_OP_reg26");
5194 printf ("DW_OP_reg27");
5197 printf ("DW_OP_reg28");
5200 printf ("DW_OP_reg29");
5203 printf ("DW_OP_reg30");
5206 printf ("DW_OP_reg31");
5209 printf ("DW_OP_breg0: %ld", read_leb128 (data
, NULL
, 1));
5212 printf ("DW_OP_breg1: %ld", read_leb128 (data
, NULL
, 1));
5215 printf ("DW_OP_breg2: %ld", read_leb128 (data
, NULL
, 1));
5218 printf ("DW_OP_breg3: %ld", read_leb128 (data
, NULL
, 1));
5221 printf ("DW_OP_breg4: %ld", read_leb128 (data
, NULL
, 1));
5224 printf ("DW_OP_breg5: %ld", read_leb128 (data
, NULL
, 1));
5227 printf ("DW_OP_breg6: %ld", read_leb128 (data
, NULL
, 1));
5230 printf ("DW_OP_breg7: %ld", read_leb128 (data
, NULL
, 1));
5233 printf ("DW_OP_breg8: %ld", read_leb128 (data
, NULL
, 1));
5236 printf ("DW_OP_breg9: %ld", read_leb128 (data
, NULL
, 1));
5239 printf ("DW_OP_breg10: %ld", read_leb128 (data
, NULL
, 1));
5242 printf ("DW_OP_breg11: %ld", read_leb128 (data
, NULL
, 1));
5245 printf ("DW_OP_breg12: %ld", read_leb128 (data
, NULL
, 1));
5248 printf ("DW_OP_breg13: %ld", read_leb128 (data
, NULL
, 1));
5251 printf ("DW_OP_breg14: %ld", read_leb128 (data
, NULL
, 1));
5254 printf ("DW_OP_breg15: %ld", read_leb128 (data
, NULL
, 1));
5257 printf ("DW_OP_breg16: %ld", read_leb128 (data
, NULL
, 1));
5260 printf ("DW_OP_breg17: %ld", read_leb128 (data
, NULL
, 1));
5263 printf ("DW_OP_breg18: %ld", read_leb128 (data
, NULL
, 1));
5266 printf ("DW_OP_breg19: %ld", read_leb128 (data
, NULL
, 1));
5269 printf ("DW_OP_breg20: %ld", read_leb128 (data
, NULL
, 1));
5272 printf ("DW_OP_breg21: %ld", read_leb128 (data
, NULL
, 1));
5275 printf ("DW_OP_breg22: %ld", read_leb128 (data
, NULL
, 1));
5278 printf ("DW_OP_breg23: %ld", read_leb128 (data
, NULL
, 1));
5281 printf ("DW_OP_breg24: %ld", read_leb128 (data
, NULL
, 1));
5284 printf ("DW_OP_breg25: %ld", read_leb128 (data
, NULL
, 1));
5287 printf ("DW_OP_breg26: %ld", read_leb128 (data
, NULL
, 1));
5290 printf ("DW_OP_breg27: %ld", read_leb128 (data
, NULL
, 1));
5293 printf ("DW_OP_breg28: %ld", read_leb128 (data
, NULL
, 1));
5296 printf ("DW_OP_breg29: %ld", read_leb128 (data
, NULL
, 1));
5299 printf ("DW_OP_breg30: %ld", read_leb128 (data
, NULL
, 1));
5302 printf ("DW_OP_breg31: %ld", read_leb128 (data
, NULL
, 1));
5305 printf ("DW_OP_regx: %lu", read_leb128 (data
, NULL
, 0));
5308 printf ("DW_OP_fbreg: %ld", read_leb128 (data
, NULL
, 1));
5311 uvalue
= read_leb128 (data
, &bytes_read
, 0);
5312 printf ("DW_OP_bregx: %lu %ld", uvalue
,
5313 read_leb128 (data
+ bytes_read
, NULL
, 1));
5316 printf ("DW_OP_piece: %lu", read_leb128 (data
, NULL
, 0));
5318 case DW_OP_deref_size
:
5319 printf ("DW_OP_deref_size: %ld", (long) byte_get (data
, 1));
5321 case DW_OP_xderef_size
:
5322 printf ("DW_OP_xderef_size: %ld", (long) byte_get (data
, 1));
5325 printf ("DW_OP_nop");
5329 if (op
>= DW_OP_lo_user
5330 && op
<= DW_OP_hi_user
)
5331 printf (_("(User defined location op)"));
5333 printf (_("(Unknown location op)"));
5339 static unsigned char *
5340 read_and_display_attr (attribute
, form
, data
, pointer_size
)
5341 unsigned long attribute
;
5343 unsigned char * data
;
5344 unsigned long pointer_size
;
5346 unsigned long uvalue
= 0;
5347 unsigned char * block_start
= NULL
;
5351 printf (" %-18s:", get_AT_name (attribute
));
5355 case DW_FORM_ref_addr
:
5360 case DW_FORM_ref_udata
:
5366 case DW_FORM_ref_addr
:
5368 uvalue
= byte_get (data
, pointer_size
);
5369 printf (is_ref
? " <%x>" : " %#x", uvalue
);
5370 data
+= pointer_size
;
5376 uvalue
= byte_get (data
++, 1);
5377 printf (is_ref
? " <%x>" : " %d", uvalue
);
5382 uvalue
= byte_get (data
, 2);
5384 printf (is_ref
? " <%x>" : " %d", uvalue
);
5389 uvalue
= byte_get (data
, 4);
5391 printf (is_ref
? " <%x>" : " %d", uvalue
);
5396 uvalue
= byte_get (data
, 4);
5397 printf (" %lx", uvalue
);
5398 printf (" %lx", (unsigned long) byte_get (data
+ 4, 4));
5402 case DW_FORM_string
:
5403 printf (" %s", data
);
5404 data
+= strlen (data
) + 1;
5408 uvalue
= read_leb128 (data
, & bytes_read
, 1);
5410 printf (" %ld", (long) uvalue
);
5413 case DW_FORM_ref_udata
:
5415 uvalue
= read_leb128 (data
, & bytes_read
, 0);
5417 printf (is_ref
? " <%lx>" : " %ld", uvalue
);
5421 uvalue
= read_leb128 (data
, & bytes_read
, 0);
5422 block_start
= data
+ bytes_read
;
5423 data
= display_block (block_start
, uvalue
);
5424 uvalue
= * block_start
;
5427 case DW_FORM_block1
:
5428 uvalue
= byte_get (data
, 1);
5429 block_start
= data
+ 1;
5430 data
= display_block (block_start
, uvalue
);
5431 uvalue
= * block_start
;
5434 case DW_FORM_block2
:
5435 uvalue
= byte_get (data
, 2);
5436 block_start
= data
+ 2;
5437 data
= display_block (block_start
, uvalue
);
5438 uvalue
= * block_start
;
5441 case DW_FORM_block4
:
5442 uvalue
= byte_get (data
, 4);
5443 block_start
= data
+ 4;
5444 data
= display_block (block_start
, uvalue
);
5445 uvalue
= * block_start
;
5449 case DW_FORM_indirect
:
5450 warn (_("Unable to handle FORM: %d"), form
);
5454 warn (_("Unrecognised form: %d"), form
);
5458 /* For some attributes we can display futher information. */
5467 case DW_INL_not_inlined
: printf (_("(not inlined)")); break;
5468 case DW_INL_inlined
: printf (_("(inlined)")); break;
5469 case DW_INL_declared_not_inlined
: printf (_("(declared as inline but ignored)")); break;
5470 case DW_INL_declared_inlined
: printf (_("(declared as inline and inlined)")); break;
5471 default: printf (_(" (Unknown inline attribute value: %lx)"), uvalue
); break;
5475 case DW_AT_frame_base
:
5476 if (uvalue
>= DW_OP_reg0
&& uvalue
<= DW_OP_reg31
)
5477 printf ("(reg %ld)", uvalue
- DW_OP_reg0
);
5480 case DW_AT_language
:
5483 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
5484 case DW_LANG_C89
: printf ("(ANSI C)"); break;
5485 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
5486 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
5487 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
5488 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
5489 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
5490 case DW_LANG_Ada83
: printf ("(Ada)"); break;
5491 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
5492 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
5493 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
5494 default: printf ("(Unknown: %lx)", uvalue
); break;
5498 case DW_AT_encoding
:
5501 case DW_ATE_void
: printf ("(void)"); break;
5502 case DW_ATE_address
: printf ("(machine address)"); break;
5503 case DW_ATE_boolean
: printf ("(boolean)"); break;
5504 case DW_ATE_complex_float
: printf ("(complex float)"); break;
5505 case DW_ATE_float
: printf ("(float)"); break;
5506 case DW_ATE_signed
: printf ("(signed)"); break;
5507 case DW_ATE_signed_char
: printf ("(signed char)"); break;
5508 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
5509 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
5511 if (uvalue
>= DW_ATE_lo_user
5512 && uvalue
<= DW_ATE_hi_user
)
5513 printf ("(user defined type)");
5515 printf ("(unknown type)");
5520 case DW_AT_accessibility
:
5523 case DW_ACCESS_public
: printf ("(public)"); break;
5524 case DW_ACCESS_protected
: printf ("(protected)"); break;
5525 case DW_ACCESS_private
: printf ("(private)"); break;
5526 default: printf ("(unknown accessibility)"); break;
5530 case DW_AT_visibility
:
5533 case DW_VIS_local
: printf ("(local)"); break;
5534 case DW_VIS_exported
: printf ("(exported)"); break;
5535 case DW_VIS_qualified
: printf ("(qualified)"); break;
5536 default: printf ("(unknown visibility)"); break;
5540 case DW_AT_virtuality
:
5543 case DW_VIRTUALITY_none
: printf ("(none)"); break;
5544 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
5545 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
5546 default: printf ("(unknown virtuality)"); break;
5550 case DW_AT_identifier_case
:
5553 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
5554 case DW_ID_up_case
: printf ("(up_case)"); break;
5555 case DW_ID_down_case
: printf ("(down_case)"); break;
5556 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
5557 default: printf ("(unknown case)"); break;
5561 case DW_AT_calling_convention
:
5564 case DW_CC_normal
: printf ("(normal)"); break;
5565 case DW_CC_program
: printf ("(program)"); break;
5566 case DW_CC_nocall
: printf ("(nocall)"); break;
5568 if (uvalue
>= DW_CC_lo_user
5569 && uvalue
<= DW_CC_hi_user
)
5570 printf ("(user defined)");
5572 printf ("(unknown convention)");
5576 case DW_AT_location
:
5577 case DW_AT_data_member_location
:
5578 case DW_AT_vtable_elem_location
:
5580 decode_location_expression (block_start
, pointer_size
);
5593 display_debug_info (section
, start
, file
)
5594 Elf32_Internal_Shdr
* section
;
5595 unsigned char * start
;
5598 unsigned char * end
= start
+ section
->sh_size
;
5599 unsigned char * section_begin
= start
;
5601 printf (_("The section %s contains:\n\n"), SECTION_NAME (section
));
5605 DWARF2_External_CompUnit
* external
;
5606 DWARF2_Internal_CompUnit compunit
;
5607 unsigned char * tags
;
5611 external
= (DWARF2_External_CompUnit
*) start
;
5613 compunit
.cu_length
= BYTE_GET (external
->cu_length
);
5614 compunit
.cu_version
= BYTE_GET (external
->cu_version
);
5615 compunit
.cu_abbrev_offset
= BYTE_GET (external
->cu_abbrev_offset
);
5616 compunit
.cu_pointer_size
= BYTE_GET (external
->cu_pointer_size
);
5618 tags
= start
+ sizeof (* external
);
5619 start
+= compunit
.cu_length
+ sizeof (external
->cu_length
);
5621 if (compunit
.cu_version
!= 2)
5623 warn (_("Only version 2 DWARF debug information is currently supported.\n"));
5627 printf (_(" Compilation Unit:\n"));
5628 printf (_(" Length: %ld\n"), compunit
.cu_length
);
5629 printf (_(" Version: %d\n"), compunit
.cu_version
);
5630 printf (_(" Abbrev Offset: %ld\n"), compunit
.cu_abbrev_offset
);
5631 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
5633 if (first_abbrev
!= NULL
)
5636 /* Read in the abbrevs used by this compilation unit. */
5639 Elf32_Internal_Shdr
* sec
;
5640 unsigned char * begin
;
5642 /* Locate the .debug_abbrev section and process it. */
5643 for (i
= 0, sec
= section_headers
;
5644 i
< elf_header
.e_shnum
;
5646 if (strcmp (SECTION_NAME (sec
), ".debug_abbrev") == 0)
5649 if (i
== -1 || sec
->sh_size
== 0)
5651 warn (_("Unable to locate .debug_abbrev section!\n"));
5655 GET_DATA_ALLOC (sec
->sh_offset
, sec
->sh_size
, begin
, unsigned char *,
5656 "debug_abbrev section data");
5658 process_abbrev_section (begin
+ compunit
.cu_abbrev_offset
,
5659 begin
+ sec
->sh_size
);
5665 while (tags
< start
)
5668 unsigned long abbrev_number
;
5669 abbrev_entry
* entry
;
5672 abbrev_number
= read_leb128 (tags
, & bytes_read
, 0);
5675 /* A null DIE marks the end of a list of children. */
5676 if (abbrev_number
== 0)
5682 /* Scan through the abbreviation list until we reach the
5684 for (entry
= first_abbrev
;
5685 entry
&& entry
->entry
!= abbrev_number
;
5686 entry
= entry
->next
)
5691 warn (_("Unable to locate entry %lu in the abbreviation table\n"),
5696 printf (_(" <%d><%x>: Abbrev Number: %lu (%s)\n"),
5697 level
, tags
- section_begin
- bytes_read
,
5699 get_TAG_name (entry
->tag
));
5701 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
5702 tags
= read_and_display_attr (attr
->attribute
,
5705 compunit
.cu_pointer_size
);
5707 if (entry
->children
)
5718 display_debug_aranges (section
, start
, file
)
5719 Elf32_Internal_Shdr
* section
;
5720 unsigned char * start
;
5721 FILE * file ATTRIBUTE_UNUSED
;
5723 unsigned char * end
= start
+ section
->sh_size
;
5725 printf (_("The section %s contains:\n\n"), SECTION_NAME (section
));
5729 DWARF2_External_ARange
* external
;
5730 DWARF2_Internal_ARange arange
;
5731 unsigned char * ranges
;
5732 unsigned long length
;
5733 unsigned long address
;
5735 external
= (DWARF2_External_ARange
*) start
;
5737 arange
.ar_length
= BYTE_GET (external
->ar_length
);
5738 arange
.ar_version
= BYTE_GET (external
->ar_version
);
5739 arange
.ar_info_offset
= BYTE_GET (external
->ar_info_offset
);
5740 arange
.ar_pointer_size
= BYTE_GET (external
->ar_pointer_size
);
5741 arange
.ar_segment_size
= BYTE_GET (external
->ar_segment_size
);
5743 printf (_(" Length: %ld\n"), arange
.ar_length
);
5744 printf (_(" Version: %d\n"), arange
.ar_version
);
5745 printf (_(" Offset into .debug_info: %lx\n"), arange
.ar_info_offset
);
5746 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
5747 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
5749 printf (_("\n Address Length\n"));
5751 ranges
= start
+ sizeof (* external
);
5755 address
= byte_get (ranges
, arange
.ar_pointer_size
);
5760 ranges
+= arange
.ar_pointer_size
;
5762 length
= byte_get (ranges
, arange
.ar_pointer_size
);
5764 ranges
+= arange
.ar_pointer_size
;
5766 printf (" %8.8lx %lu\n", address
, length
);
5769 start
+= arange
.ar_length
+ sizeof (external
->ar_length
);
5779 display_debug_not_supported (section
, start
, file
)
5780 Elf32_Internal_Shdr
* section
;
5781 unsigned char * start ATTRIBUTE_UNUSED
;
5782 FILE * file ATTRIBUTE_UNUSED
;
5784 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
5785 SECTION_NAME (section
));
5790 /* A structure containing the name of a debug section and a pointer
5791 to a function that can decode it. */
5795 int (* display
) PARAMS((Elf32_Internal_Shdr
*, unsigned char *, FILE *));
5799 { ".debug_info", display_debug_info
},
5800 { ".debug_abbrev", display_debug_abbrev
},
5801 { ".debug_line", display_debug_lines
},
5802 { ".debug_aranges", display_debug_aranges
},
5803 { ".debug_pubnames", display_debug_pubnames
},
5804 { ".debug_macinfo", display_debug_not_supported
},
5805 { ".debug_frame", display_debug_not_supported
},
5806 { ".debug_str", display_debug_not_supported
},
5807 { ".debug_static_func", display_debug_not_supported
},
5808 { ".debug_static_vars", display_debug_not_supported
},
5809 { ".debug_types", display_debug_not_supported
},
5810 { ".debug_weaknames", display_debug_not_supported
}
5814 display_debug_section (section
, file
)
5815 Elf32_Internal_Shdr
* section
;
5818 char * name
= SECTION_NAME (section
);
5819 bfd_size_type length
;
5820 unsigned char * start
;
5823 length
= section
->sh_size
;
5826 printf (_("\nSection '%s' has no debugging data.\n"), name
);
5830 GET_DATA_ALLOC (section
->sh_offset
, length
, start
, unsigned char *,
5831 "debug section data");
5833 /* See if we know how to display the contents of this section. */
5834 for (i
= NUM_ELEM (debug_displays
); i
--;)
5835 if (strcmp (debug_displays
[i
].name
, name
) == 0)
5837 debug_displays
[i
].display (section
, start
, file
);
5842 printf (_("Unrecognised debug section: %s\n"), name
);
5846 /* If we loaded in the abbrev section at some point,
5847 we must release it here. */
5848 if (first_abbrev
!= NULL
)
5855 process_section_contents (file
)
5858 Elf32_Internal_Shdr
* section
;
5864 for (i
= 0, section
= section_headers
;
5865 i
< elf_header
.e_shnum
5866 && i
< num_dump_sects
;
5869 #ifdef SUPPORT_DISASSEMBLY
5870 if (dump_sects
[i
] & DISASS_DUMP
)
5871 disassemble_section (section
, file
);
5873 if (dump_sects
[i
] & HEX_DUMP
)
5874 dump_section (section
, file
);
5876 if (dump_sects
[i
] & DEBUG_DUMP
)
5877 display_debug_section (section
, file
);
5880 if (i
< num_dump_sects
)
5881 warn (_("Some sections were not dumped because they do not exist!\n"));
5887 process_mips_fpe_exception (mask
)
5893 if (mask
& OEX_FPU_INEX
)
5894 fputs ("INEX", stdout
), first
= 0;
5895 if (mask
& OEX_FPU_UFLO
)
5896 printf ("%sUFLO", first
? "" : "|"), first
= 0;
5897 if (mask
& OEX_FPU_OFLO
)
5898 printf ("%sOFLO", first
? "" : "|"), first
= 0;
5899 if (mask
& OEX_FPU_DIV0
)
5900 printf ("%sDIV0", first
? "" : "|"), first
= 0;
5901 if (mask
& OEX_FPU_INVAL
)
5902 printf ("%sINVAL", first
? "" : "|");
5905 fputs ("0", stdout
);
5909 process_mips_specific (file
)
5912 Elf_Internal_Dyn
* entry
;
5913 size_t liblist_offset
= 0;
5914 size_t liblistno
= 0;
5915 size_t conflictsno
= 0;
5916 size_t options_offset
= 0;
5917 size_t conflicts_offset
= 0;
5919 /* We have a lot of special sections. Thanks SGI! */
5920 if (dynamic_segment
== NULL
)
5921 /* No information available. */
5924 for (entry
= dynamic_segment
; entry
->d_tag
!= DT_NULL
; ++entry
)
5925 switch (entry
->d_tag
)
5927 case DT_MIPS_LIBLIST
:
5928 liblist_offset
= entry
->d_un
.d_val
- loadaddr
;
5930 case DT_MIPS_LIBLISTNO
:
5931 liblistno
= entry
->d_un
.d_val
;
5933 case DT_MIPS_OPTIONS
:
5934 options_offset
= entry
->d_un
.d_val
- loadaddr
;
5936 case DT_MIPS_CONFLICT
:
5937 conflicts_offset
= entry
->d_un
.d_val
- loadaddr
;
5939 case DT_MIPS_CONFLICTNO
:
5940 conflictsno
= entry
->d_un
.d_val
;
5946 if (liblist_offset
!= 0 && liblistno
!= 0 && do_dynamic
)
5948 Elf32_External_Lib
* elib
;
5951 GET_DATA_ALLOC (liblist_offset
, liblistno
* sizeof (Elf32_External_Lib
),
5952 elib
, Elf32_External_Lib
*, "liblist");
5954 printf ("\nSection '.liblist' contains %d entries:\n", liblistno
);
5955 fputs (" Library Time Stamp Checksum Version Flags\n",
5958 for (cnt
= 0; cnt
< liblistno
; ++cnt
)
5964 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
5965 time
= BYTE_GET (elib
[cnt
].l_time_stamp
);
5966 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
5967 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
5968 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
5970 strftime (timebuf
, 20, "%Y-%m-%dT%H:%M:%S", gmtime (&time
));
5972 printf ("%3d: %-20s %s %#10lx %-7ld", cnt
,
5973 dynamic_strings
+ liblist
.l_name
, timebuf
,
5974 liblist
.l_checksum
, liblist
.l_version
);
5976 if (liblist
.l_flags
== 0)
5986 { " EXACT_MATCH", LL_EXACT_MATCH
},
5987 { " IGNORE_INT_VER", LL_IGNORE_INT_VER
},
5988 { " REQUIRE_MINOR", LL_REQUIRE_MINOR
},
5989 { " EXPORTS", LL_EXPORTS
},
5990 { " DELAY_LOAD", LL_DELAY_LOAD
},
5991 { " DELTA", LL_DELTA
}
5993 int flags
= liblist
.l_flags
;
5997 fcnt
< sizeof (l_flags_vals
) / sizeof (l_flags_vals
[0]);
5999 if ((flags
& l_flags_vals
[fcnt
].bit
) != 0)
6001 fputs (l_flags_vals
[fcnt
].name
, stdout
);
6002 flags
^= l_flags_vals
[fcnt
].bit
;
6005 printf (" %#x", (unsigned int) flags
);
6014 if (options_offset
!= 0)
6016 Elf_External_Options
* eopt
;
6017 Elf_Internal_Shdr
* sect
= section_headers
;
6018 Elf_Internal_Options
* iopt
;
6019 Elf_Internal_Options
* option
;
6023 /* Find the section header so that we get the size. */
6024 while (sect
->sh_type
!= SHT_MIPS_OPTIONS
)
6027 GET_DATA_ALLOC (options_offset
, sect
->sh_size
, eopt
,
6028 Elf_External_Options
*, "options");
6030 iopt
= (Elf_Internal_Options
*) malloc ((sect
->sh_size
/ sizeof (eopt
))
6034 error (_("Out of memory"));
6040 while (offset
< sect
->sh_size
)
6042 Elf_External_Options
* eoption
;
6044 eoption
= (Elf_External_Options
*) ((char *) eopt
+ offset
);
6046 option
->kind
= BYTE_GET (eoption
->kind
);
6047 option
->size
= BYTE_GET (eoption
->size
);
6048 option
->section
= BYTE_GET (eoption
->section
);
6049 option
->info
= BYTE_GET (eoption
->info
);
6051 offset
+= option
->size
;
6056 printf (_("\nSection '%s' contains %d entries:\n"),
6057 string_table
+ sect
->sh_name
, cnt
);
6064 switch (option
->kind
)
6067 /* This shouldn't happen. */
6068 printf (" NULL %d %lx", option
->section
, option
->info
);
6071 printf (" REGINFO ");
6072 if (elf_header
.e_machine
== EM_MIPS
)
6075 Elf32_External_RegInfo
*ereg
;
6076 Elf32_RegInfo reginfo
;
6078 ereg
= (Elf32_External_RegInfo
*) (option
+ 1);
6079 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
6080 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
6081 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
6082 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
6083 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
6084 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
6086 printf ("GPR %08lx GP 0x%lx\n",
6088 (unsigned long) reginfo
.ri_gp_value
);
6089 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
6090 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
6091 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
6096 Elf64_External_RegInfo
* ereg
;
6097 Elf64_Internal_RegInfo reginfo
;
6099 ereg
= (Elf64_External_RegInfo
*) (option
+ 1);
6100 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
6101 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
6102 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
6103 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
6104 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
6105 reginfo
.ri_gp_value
= BYTE_GET8 (ereg
->ri_gp_value
);
6107 printf ("GPR %08lx GP 0x",
6108 reginfo
.ri_gprmask
);
6109 printf_vma (reginfo
.ri_gp_value
);
6112 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
6113 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
6114 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
6118 case ODK_EXCEPTIONS
:
6119 fputs (" EXCEPTIONS fpe_min(", stdout
);
6120 process_mips_fpe_exception (option
->info
& OEX_FPU_MIN
);
6121 fputs (") fpe_max(", stdout
);
6122 process_mips_fpe_exception ((option
->info
& OEX_FPU_MAX
) >> 8);
6123 fputs (")", stdout
);
6125 if (option
->info
& OEX_PAGE0
)
6126 fputs (" PAGE0", stdout
);
6127 if (option
->info
& OEX_SMM
)
6128 fputs (" SMM", stdout
);
6129 if (option
->info
& OEX_FPDBUG
)
6130 fputs (" FPDBUG", stdout
);
6131 if (option
->info
& OEX_DISMISS
)
6132 fputs (" DISMISS", stdout
);
6135 fputs (" PAD ", stdout
);
6136 if (option
->info
& OPAD_PREFIX
)
6137 fputs (" PREFIX", stdout
);
6138 if (option
->info
& OPAD_POSTFIX
)
6139 fputs (" POSTFIX", stdout
);
6140 if (option
->info
& OPAD_SYMBOL
)
6141 fputs (" SYMBOL", stdout
);
6144 fputs (" HWPATCH ", stdout
);
6145 if (option
->info
& OHW_R4KEOP
)
6146 fputs (" R4KEOP", stdout
);
6147 if (option
->info
& OHW_R8KPFETCH
)
6148 fputs (" R8KPFETCH", stdout
);
6149 if (option
->info
& OHW_R5KEOP
)
6150 fputs (" R5KEOP", stdout
);
6151 if (option
->info
& OHW_R5KCVTL
)
6152 fputs (" R5KCVTL", stdout
);
6155 fputs (" FILL ", stdout
);
6156 /* XXX Print content of info word? */
6159 fputs (" TAGS ", stdout
);
6160 /* XXX Print content of info word? */
6163 fputs (" HWAND ", stdout
);
6164 if (option
->info
& OHWA0_R4KEOP_CHECKED
)
6165 fputs (" R4KEOP_CHECKED", stdout
);
6166 if (option
->info
& OHWA0_R4KEOP_CLEAN
)
6167 fputs (" R4KEOP_CLEAN", stdout
);
6170 fputs (" HWOR ", stdout
);
6171 if (option
->info
& OHWA0_R4KEOP_CHECKED
)
6172 fputs (" R4KEOP_CHECKED", stdout
);
6173 if (option
->info
& OHWA0_R4KEOP_CLEAN
)
6174 fputs (" R4KEOP_CLEAN", stdout
);
6177 printf (" GP_GROUP %#06lx self-contained %#06lx",
6178 option
->info
& OGP_GROUP
,
6179 (option
->info
& OGP_SELF
) >> 16);
6182 printf (" IDENT %#06lx self-contained %#06lx",
6183 option
->info
& OGP_GROUP
,
6184 (option
->info
& OGP_SELF
) >> 16);
6187 /* This shouldn't happen. */
6188 printf (" %3d ??? %d %lx",
6189 option
->kind
, option
->section
, option
->info
);
6193 len
= sizeof (*eopt
);
6194 while (len
< option
->size
)
6195 if (((char *) option
)[len
] >= ' '
6196 && ((char *) option
)[len
] < 0x7f)
6197 printf ("%c", ((char *) option
)[len
++]);
6199 printf ("\\%03o", ((char *) option
)[len
++]);
6201 fputs ("\n", stdout
);
6208 if (conflicts_offset
!= 0 && conflictsno
!= 0)
6210 Elf32_External_Conflict
* econf32
;
6211 Elf64_External_Conflict
* econf64
;
6212 Elf32_Conflict
* iconf
;
6215 if (dynamic_symbols
== NULL
)
6217 error (_("conflict list with without table"));
6221 iconf
= (Elf32_Conflict
*) malloc (conflictsno
* sizeof (*iconf
));
6224 error (_("Out of memory"));
6230 GET_DATA_ALLOC (conflicts_offset
, conflictsno
* sizeof (*econf32
),
6231 econf32
, Elf32_External_Conflict
*, "conflict");
6233 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
6234 iconf
[cnt
] = BYTE_GET (econf32
[cnt
]);
6238 GET_DATA_ALLOC (conflicts_offset
, conflictsno
* sizeof (*econf64
),
6239 econf64
, Elf64_External_Conflict
*, "conflict");
6241 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
6242 iconf
[cnt
] = BYTE_GET (econf64
[cnt
]);
6245 printf (_("\nSection '.conflict' contains %d entries:\n"), conflictsno
);
6246 puts (_(" Num: Index Value Name"));
6248 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
6250 Elf_Internal_Sym
* psym
= &dynamic_symbols
[iconf
[cnt
]];
6252 printf ("%5u: %8lu %#10lx %s\n",
6253 cnt
, iconf
[cnt
], (unsigned long) psym
->st_value
,
6254 dynamic_strings
+ psym
->st_name
);
6265 process_arch_specific (file
)
6271 switch (elf_header
.e_machine
)
6274 case EM_MIPS_RS4_BE
:
6275 return process_mips_specific (file
);
6284 get_file_header (file
)
6287 /* Read in the identity array. */
6288 if (fread (elf_header
.e_ident
, EI_NIDENT
, 1, file
) != 1)
6291 /* Determine how to read the rest of the header. */
6292 switch (elf_header
.e_ident
[EI_DATA
])
6294 default: /* fall through */
6295 case ELFDATANONE
: /* fall through */
6296 case ELFDATA2LSB
: byte_get
= byte_get_little_endian
; break;
6297 case ELFDATA2MSB
: byte_get
= byte_get_big_endian
; break;
6300 /* For now we only support 32 bit and 64 bit ELF files. */
6301 is_32bit_elf
= (elf_header
.e_ident
[EI_CLASS
] != ELFCLASS64
);
6303 /* Read in the rest of the header. */
6306 Elf32_External_Ehdr ehdr32
;
6308 if (fread (ehdr32
.e_type
, sizeof (ehdr32
) - EI_NIDENT
, 1, file
) != 1)
6311 elf_header
.e_type
= BYTE_GET (ehdr32
.e_type
);
6312 elf_header
.e_machine
= BYTE_GET (ehdr32
.e_machine
);
6313 elf_header
.e_version
= BYTE_GET (ehdr32
.e_version
);
6314 elf_header
.e_entry
= BYTE_GET (ehdr32
.e_entry
);
6315 elf_header
.e_phoff
= BYTE_GET (ehdr32
.e_phoff
);
6316 elf_header
.e_shoff
= BYTE_GET (ehdr32
.e_shoff
);
6317 elf_header
.e_flags
= BYTE_GET (ehdr32
.e_flags
);
6318 elf_header
.e_ehsize
= BYTE_GET (ehdr32
.e_ehsize
);
6319 elf_header
.e_phentsize
= BYTE_GET (ehdr32
.e_phentsize
);
6320 elf_header
.e_phnum
= BYTE_GET (ehdr32
.e_phnum
);
6321 elf_header
.e_shentsize
= BYTE_GET (ehdr32
.e_shentsize
);
6322 elf_header
.e_shnum
= BYTE_GET (ehdr32
.e_shnum
);
6323 elf_header
.e_shstrndx
= BYTE_GET (ehdr32
.e_shstrndx
);
6327 Elf64_External_Ehdr ehdr64
;
6329 /* If we have been compiled with sizeof (bfd_vma) == 4, then
6330 we will not be able to cope with the 64bit data found in
6331 64 ELF files. Detect this now and abort before we start
6332 overwritting things. */
6333 if (sizeof (bfd_vma
) < 8)
6335 error (_("This instance of readelf has been built without support for a\n"));
6336 error (_("64 bit data type and so it cannot read 64 bit ELF files.\n"));
6340 if (fread (ehdr64
.e_type
, sizeof (ehdr64
) - EI_NIDENT
, 1, file
) != 1)
6343 elf_header
.e_type
= BYTE_GET (ehdr64
.e_type
);
6344 elf_header
.e_machine
= BYTE_GET (ehdr64
.e_machine
);
6345 elf_header
.e_version
= BYTE_GET (ehdr64
.e_version
);
6346 elf_header
.e_entry
= BYTE_GET8 (ehdr64
.e_entry
);
6347 elf_header
.e_phoff
= BYTE_GET8 (ehdr64
.e_phoff
);
6348 elf_header
.e_shoff
= BYTE_GET8 (ehdr64
.e_shoff
);
6349 elf_header
.e_flags
= BYTE_GET (ehdr64
.e_flags
);
6350 elf_header
.e_ehsize
= BYTE_GET (ehdr64
.e_ehsize
);
6351 elf_header
.e_phentsize
= BYTE_GET (ehdr64
.e_phentsize
);
6352 elf_header
.e_phnum
= BYTE_GET (ehdr64
.e_phnum
);
6353 elf_header
.e_shentsize
= BYTE_GET (ehdr64
.e_shentsize
);
6354 elf_header
.e_shnum
= BYTE_GET (ehdr64
.e_shnum
);
6355 elf_header
.e_shstrndx
= BYTE_GET (ehdr64
.e_shstrndx
);
6362 process_file (file_name
)
6366 struct stat statbuf
;
6369 if (stat (file_name
, & statbuf
) < 0)
6371 error (_("Cannot stat input file %s.\n"), file_name
);
6375 file
= fopen (file_name
, "rb");
6378 error (_("Input file %s not found.\n"), file_name
);
6382 if (! get_file_header (file
))
6384 error (_("%s: Failed to read file header\n"), file_name
);
6389 /* Initialise per file variables. */
6390 for (i
= NUM_ELEM (version_info
); i
--;)
6391 version_info
[i
] = 0;
6393 for (i
= NUM_ELEM (dynamic_info
); i
--;)
6394 dynamic_info
[i
] = 0;
6396 /* Process the file. */
6398 printf (_("\nFile: %s\n"), file_name
);
6400 if (! process_file_header ())
6406 process_section_headers (file
);
6408 process_program_headers (file
);
6410 process_dynamic_segment (file
);
6412 process_relocs (file
);
6414 process_symbol_table (file
);
6416 process_syminfo (file
);
6418 process_version_sections (file
);
6420 process_section_contents (file
);
6422 process_arch_specific (file
);
6426 if (section_headers
)
6428 free (section_headers
);
6429 section_headers
= NULL
;
6434 free (string_table
);
6435 string_table
= NULL
;
6438 if (dynamic_strings
)
6440 free (dynamic_strings
);
6441 dynamic_strings
= NULL
;
6444 if (dynamic_symbols
)
6446 free (dynamic_symbols
);
6447 dynamic_symbols
= NULL
;
6448 num_dynamic_syms
= 0;
6451 if (dynamic_syminfo
)
6453 free (dynamic_syminfo
);
6454 dynamic_syminfo
= NULL
;
6458 #ifdef SUPPORT_DISASSEMBLY
6459 /* Needed by the i386 disassembler. For extra credit, someone could
6460 fix this so that we insert symbolic addresses here, esp for GOT/PLT
6464 print_address (unsigned int addr
, FILE * outfile
)
6466 fprintf (outfile
,"0x%8.8x", addr
);
6469 /* Needed by the i386 disassembler. */
6471 db_task_printsym (unsigned int addr
)
6473 print_address (addr
, stderr
);
6482 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
6483 setlocale (LC_MESSAGES
, "");
6485 bindtextdomain (PACKAGE
, LOCALEDIR
);
6486 textdomain (PACKAGE
);
6488 parse_args (argc
, argv
);
6490 if (optind
< (argc
- 1))
6493 while (optind
< argc
)
6494 process_file (argv
[optind
++]);
6496 if (dump_sects
!= NULL
)