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_sparc64_dynamic_type
PARAMS ((unsigned long));
133 static const char * get_dynamic_type
PARAMS ((unsigned long));
134 static int dump_relocations
PARAMS ((FILE *, unsigned long, unsigned long, Elf_Internal_Sym
*, unsigned long, char *, int));
135 static char * get_file_type
PARAMS ((unsigned));
136 static char * get_machine_name
PARAMS ((unsigned));
137 static char * get_machine_flags
PARAMS ((unsigned, unsigned));
138 static const char * get_mips_segment_type
PARAMS ((unsigned long));
139 static const char * get_segment_type
PARAMS ((unsigned long));
140 static const char * get_mips_section_type_name
PARAMS ((unsigned int));
141 static const char * get_section_type_name
PARAMS ((unsigned int));
142 static char * get_symbol_binding
PARAMS ((unsigned int));
143 static char * get_symbol_type
PARAMS ((unsigned int));
144 static void usage
PARAMS ((void));
145 static void parse_args
PARAMS ((int, char **));
146 static int process_file_header
PARAMS ((void));
147 static int process_program_headers
PARAMS ((FILE *));
148 static int process_section_headers
PARAMS ((FILE *));
149 static void dynamic_segment_mips_val
PARAMS ((Elf_Internal_Dyn
*));
150 static int process_dynamic_segment
PARAMS ((FILE *));
151 static int process_symbol_table
PARAMS ((FILE *));
152 static int process_section_contents
PARAMS ((FILE *));
153 static void process_file
PARAMS ((char *));
154 static int process_relocs
PARAMS ((FILE *));
155 static int process_version_sections
PARAMS ((FILE *));
156 static char * get_ver_flags
PARAMS ((unsigned int));
157 static char * get_symbol_index_type
PARAMS ((unsigned int));
158 static int get_32bit_section_headers
PARAMS ((FILE *));
159 static int get_64bit_section_headers
PARAMS ((FILE *));
160 static int get_32bit_program_headers
PARAMS ((FILE *, Elf_Internal_Phdr
*));
161 static int get_64bit_program_headers
PARAMS ((FILE *, Elf_Internal_Phdr
*));
162 static int get_file_header
PARAMS ((FILE *));
163 static Elf_Internal_Sym
* get_32bit_elf_symbols
PARAMS ((FILE *, unsigned long, unsigned long));
164 static Elf_Internal_Sym
* get_64bit_elf_symbols
PARAMS ((FILE *, unsigned long, unsigned long));
165 static int * get_dynamic_data
PARAMS ((FILE *, unsigned int));
166 static int get_32bit_dynamic_segment
PARAMS ((FILE *));
167 static int get_64bit_dynamic_segment
PARAMS ((FILE *));
168 #ifdef SUPPORT_DISASSEMBLY
169 static int disassemble_section
PARAMS ((Elf32_Internal_Shdr
*, FILE *));
171 static int dump_section
PARAMS ((Elf32_Internal_Shdr
*, FILE *));
172 static int display_debug_section
PARAMS ((Elf32_Internal_Shdr
*, FILE *));
173 static int display_debug_info
PARAMS ((Elf32_Internal_Shdr
*, unsigned char *, FILE *));
174 static int display_debug_not_supported
PARAMS ((Elf32_Internal_Shdr
*, unsigned char *, FILE *));
175 static int display_debug_lines
PARAMS ((Elf32_Internal_Shdr
*, unsigned char *, FILE *));
176 static int display_debug_abbrev
PARAMS ((Elf32_Internal_Shdr
*, unsigned char *, FILE *));
177 static int display_debug_aranges
PARAMS ((Elf32_Internal_Shdr
*, unsigned char *, FILE *));
178 static unsigned char * process_abbrev_section
PARAMS ((unsigned char *, unsigned char *));
179 static unsigned long read_leb128
PARAMS ((unsigned char *, int *, int));
180 static int process_extended_line_op
PARAMS ((unsigned char *, int));
181 static void reset_state_machine
PARAMS ((int));
182 static char * get_TAG_name
PARAMS ((unsigned long));
183 static char * get_AT_name
PARAMS ((unsigned long));
184 static char * get_FORM_name
PARAMS ((unsigned long));
185 static void free_abbrevs
PARAMS ((void));
186 static void add_abbrev
PARAMS ((unsigned long, unsigned long, int));
187 static void add_abbrev_attr
PARAMS ((unsigned long, unsigned long));
188 static unsigned char * read_and_display_attr
PARAMS ((unsigned long, unsigned long, unsigned char *, unsigned long));
189 static unsigned char * display_block
PARAMS ((unsigned char *, unsigned long));
190 static void decode_location_expression
PARAMS ((unsigned char *, unsigned int));
191 static void request_dump
PARAMS ((unsigned int, char));
192 static const char * get_elf_class
PARAMS ((unsigned char));
193 static const char * get_data_encoding
PARAMS ((unsigned char));
194 static const char * get_osabi_name
PARAMS ((unsigned char));
195 static int guess_is_rela
PARAMS ((unsigned long));
197 typedef int Elf32_Word
;
205 #define SECTION_NAME(X) (string_table + (X)->sh_name)
207 #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
209 #define BYTE_GET(field) byte_get (field, sizeof (field))
211 /* If we can support a 64 bit data type then BFD64 should be defined
212 and sizeof (bfd_vma) == 8. In this case when translating from an
213 external 8 byte field to an internal field, we can assume that the
214 internal field is also 8 bytes wide and so we can extact all the data.
215 If, however, BFD64 is not defined, then we must assume that the
216 internal data structure only has 4 byte wide fields that are the
217 equivalent of the 8 byte wide external counterparts, and so we must
218 truncate the data. */
220 #define BYTE_GET8(field) byte_get (field, -8)
222 #define BYTE_GET8(field) byte_get (field, 8)
225 #define NUM_ELEM(array) (sizeof (array) / sizeof ((array)[0]))
227 #define GET_DATA_ALLOC(offset, size, var, type, reason) \
228 if (fseek (file, offset, SEEK_SET)) \
230 error (_("Unable to seek to start of %s at %x\n"), reason, offset); \
234 var = (type) malloc (size); \
238 error (_("Out of memory allocating %d bytes for %s\n"), size, reason); \
242 if (fread (var, size, 1, file) != 1) \
244 error (_("Unable to read in %d bytes of %s\n"), size, reason); \
251 #define GET_DATA(offset, var, reason) \
252 if (fseek (file, offset, SEEK_SET)) \
254 error (_("Unable to seek to %x for %s\n"), offset, reason); \
257 else if (fread (& var, sizeof (var), 1, file) != 1) \
259 error (_("Unable to read data at %x for %s\n"), offset, reason); \
263 #define GET_ELF_SYMBOLS(file, offset, size) \
264 (is_32bit_elf ? get_32bit_elf_symbols (file, offset, size) \
265 : get_64bit_elf_symbols (file, offset, size))
268 #ifdef ANSI_PROTOTYPES
270 error (const char * message
, ...)
274 fprintf (stderr
, _("%s: Error: "), program_name
);
275 va_start (args
, message
);
276 vfprintf (stderr
, message
, args
);
282 warn (const char * message
, ...)
286 fprintf (stderr
, _("%s: Warning: "), program_name
);
287 va_start (args
, message
);
288 vfprintf (stderr
, message
, args
);
300 fprintf (stderr
, _("%s: Error: "), program_name
);
302 message
= va_arg (args
, char *);
303 vfprintf (stderr
, message
, args
);
315 fprintf (stderr
, _("%s: Warning: "), program_name
);
317 message
= va_arg (args
, char *);
318 vfprintf (stderr
, message
, args
);
325 byte_get_little_endian (field
, size
)
326 unsigned char * field
;
335 return ((unsigned int) (field
[0]))
336 | (((unsigned int) (field
[1])) << 8);
339 /* We want to extract data from an 8 byte wide field and
340 place it into a 4 byte wide field. Since this is a little
341 endian source we can juts use the 4 byte extraction code. */
344 return ((unsigned long) (field
[0]))
345 | (((unsigned long) (field
[1])) << 8)
346 | (((unsigned long) (field
[2])) << 16)
347 | (((unsigned long) (field
[3])) << 24);
351 /* This is a special case, generated by the BYTE_GET8 macro.
352 It means that we are loading an 8 byte value from a field
353 in an external structure into an 8 byte value in a field
354 in an internal strcuture. */
355 return ((bfd_vma
) (field
[0]))
356 | (((bfd_vma
) (field
[1])) << 8)
357 | (((bfd_vma
) (field
[2])) << 16)
358 | (((bfd_vma
) (field
[3])) << 24)
359 | (((bfd_vma
) (field
[4])) << 32)
360 | (((bfd_vma
) (field
[5])) << 40)
361 | (((bfd_vma
) (field
[6])) << 48)
362 | (((bfd_vma
) (field
[7])) << 56);
365 error (_("Unhandled data length: %d\n"), size
);
371 byte_get_big_endian (field
, size
)
372 unsigned char * field
;
381 return ((unsigned int) (field
[1])) | (((int) (field
[0])) << 8);
384 return ((unsigned long) (field
[3]))
385 | (((unsigned long) (field
[2])) << 8)
386 | (((unsigned long) (field
[1])) << 16)
387 | (((unsigned long) (field
[0])) << 24);
390 /* Although we are extracing data from an 8 byte wide field, we
391 are returning only 4 bytes of data. */
392 return ((unsigned long) (field
[7]))
393 | (((unsigned long) (field
[6])) << 8)
394 | (((unsigned long) (field
[5])) << 16)
395 | (((unsigned long) (field
[4])) << 24);
399 /* This is a special case, generated by the BYTE_GET8 macro.
400 It means that we are loading an 8 byte value from a field
401 in an external structure into an 8 byte value in a field
402 in an internal strcuture. */
403 return ((bfd_vma
) (field
[7]))
404 | (((bfd_vma
) (field
[6])) << 8)
405 | (((bfd_vma
) (field
[5])) << 16)
406 | (((bfd_vma
) (field
[4])) << 24)
407 | (((bfd_vma
) (field
[3])) << 32)
408 | (((bfd_vma
) (field
[2])) << 40)
409 | (((bfd_vma
) (field
[1])) << 48)
410 | (((bfd_vma
) (field
[0])) << 56);
414 error (_("Unhandled data length: %d\n"), size
);
420 /* Guess the relocation sized based on the sized commonly used by the specific machine. */
422 guess_is_rela (e_machine
)
423 unsigned long e_machine
;
427 /* Targets that use REL relocations. */
438 /* Targets that use RELA relocations. */
446 case EM_CYGNUS_MN10200
:
447 case EM_CYGNUS_MN10300
:
455 warn (_("Don't know about relocations on this machine architecture\n"));
460 /* Display the contents of the relocation data found at the specified offset. */
462 dump_relocations (file
, rel_offset
, rel_size
, symtab
, nsyms
, strtab
, is_rela
)
464 unsigned long rel_offset
;
465 unsigned long rel_size
;
466 Elf_Internal_Sym
* symtab
;
472 Elf_Internal_Rel
* rels
;
473 Elf_Internal_Rela
* relas
;
476 if (is_rela
== UNKNOWN
)
477 is_rela
= guess_is_rela (elf_header
.e_machine
);
483 Elf32_External_Rela
* erelas
;
485 GET_DATA_ALLOC (rel_offset
, rel_size
, erelas
,
486 Elf32_External_Rela
*, "relocs");
488 rel_size
= rel_size
/ sizeof (Elf32_External_Rela
);
490 relas
= (Elf_Internal_Rela
*)
491 malloc (rel_size
* sizeof (Elf_Internal_Rela
));
495 error(_("out of memory parsing relocs"));
499 for (i
= 0; i
< rel_size
; i
++)
501 relas
[i
].r_offset
= BYTE_GET (erelas
[i
].r_offset
);
502 relas
[i
].r_info
= BYTE_GET (erelas
[i
].r_info
);
503 relas
[i
].r_addend
= BYTE_GET (erelas
[i
].r_addend
);
508 rels
= (Elf_Internal_Rel
*) relas
;
512 Elf64_External_Rela
* erelas
;
514 GET_DATA_ALLOC (rel_offset
, rel_size
, erelas
,
515 Elf64_External_Rela
*, "relocs");
517 rel_size
= rel_size
/ sizeof (Elf64_External_Rela
);
519 relas
= (Elf_Internal_Rela
*)
520 malloc (rel_size
* sizeof (Elf_Internal_Rela
));
524 error(_("out of memory parsing relocs"));
528 for (i
= 0; i
< rel_size
; i
++)
530 relas
[i
].r_offset
= BYTE_GET8 (erelas
[i
].r_offset
);
531 relas
[i
].r_info
= BYTE_GET8 (erelas
[i
].r_info
);
532 relas
[i
].r_addend
= BYTE_GET8 (erelas
[i
].r_addend
);
537 rels
= (Elf_Internal_Rel
*) relas
;
544 Elf32_External_Rel
* erels
;
546 GET_DATA_ALLOC (rel_offset
, rel_size
, erels
,
547 Elf32_External_Rel
*, "relocs");
549 rel_size
= rel_size
/ sizeof (Elf32_External_Rel
);
551 rels
= (Elf_Internal_Rel
*)
552 malloc (rel_size
* sizeof (Elf_Internal_Rel
));
556 error(_("out of memory parsing relocs"));
560 for (i
= 0; i
< rel_size
; i
++)
562 rels
[i
].r_offset
= BYTE_GET (erels
[i
].r_offset
);
563 rels
[i
].r_info
= BYTE_GET (erels
[i
].r_info
);
568 relas
= (Elf_Internal_Rela
*) rels
;
572 Elf64_External_Rel
* erels
;
574 GET_DATA_ALLOC (rel_offset
, rel_size
, erels
,
575 Elf64_External_Rel
*, "relocs");
577 rel_size
= rel_size
/ sizeof (Elf64_External_Rel
);
579 rels
= (Elf_Internal_Rel
*)
580 malloc (rel_size
* sizeof (Elf_Internal_Rel
));
584 error(_("out of memory parsing relocs"));
588 for (i
= 0; i
< rel_size
; i
++)
590 rels
[i
].r_offset
= BYTE_GET8 (erels
[i
].r_offset
);
591 rels
[i
].r_info
= BYTE_GET8 (erels
[i
].r_info
);
596 relas
= (Elf_Internal_Rela
*) rels
;
602 (_(" Offset Info Type Symbol's Value Symbol's Name Addend\n"));
605 (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
607 for (i
= 0; i
< rel_size
; i
++)
612 bfd_vma symtab_index
;
617 offset
= relas
[i
].r_offset
;
618 info
= relas
[i
].r_info
;
622 offset
= rels
[i
].r_offset
;
623 info
= rels
[i
].r_info
;
628 type
= ELF32_R_TYPE (info
);
629 symtab_index
= ELF32_R_SYM (info
);
633 if (elf_header
.e_machine
== EM_SPARCV9
)
634 type
= ELF64_R_TYPE_ID (info
);
636 type
= ELF64_R_TYPE (info
);
637 /* The #ifdef BFD64 below is to prevent a compile time warning.
638 We know that if we do not have a 64 bit data type that we
639 will never execute this code anyway. */
641 symtab_index
= ELF64_R_SYM (info
);
645 #ifdef _bfd_int64_low
646 printf (" %8.8lx %5.5lx ", _bfd_int64_low (offset
), _bfd_int64_low (info
));
648 printf (" %8.8lx %5.5lx ", offset
, info
);
651 switch (elf_header
.e_machine
)
658 rtype
= elf_m32r_reloc_type (type
);
663 rtype
= elf_i386_reloc_type (type
);
667 rtype
= elf_m68k_reloc_type (type
);
671 rtype
= elf_i960_reloc_type (type
);
678 rtype
= elf_sparc_reloc_type (type
);
682 rtype
= v850_reloc_type (type
);
686 rtype
= elf_d10v_reloc_type (type
);
690 rtype
= elf_d30v_reloc_type (type
);
694 rtype
= elf_sh_reloc_type (type
);
697 case EM_CYGNUS_MN10300
:
698 rtype
= elf_mn10300_reloc_type (type
);
701 case EM_CYGNUS_MN10200
:
702 rtype
= elf_mn10200_reloc_type (type
);
706 rtype
= elf_fr30_reloc_type (type
);
710 rtype
= elf_mcore_reloc_type (type
);
714 rtype
= elf_ppc_reloc_type (type
);
719 rtype
= elf_mips_reloc_type (type
);
723 rtype
= elf_alpha_reloc_type (type
);
727 rtype
= elf_arm_reloc_type (type
);
731 rtype
= elf_arc_reloc_type (type
);
735 rtype
= elf_hppa_reloc_type (type
);
740 #ifdef _bfd_int64_low
741 printf (_("unrecognised: %-7lx"), _bfd_int64_low (type
));
743 printf (_("unrecognised: %-7lx"), type
);
746 printf ("%-21.21s", rtype
);
752 if (symtab_index
>= nsyms
)
753 printf (" bad symbol index: %08lx", (unsigned long) symtab_index
);
756 Elf_Internal_Sym
* psym
;
758 psym
= symtab
+ symtab_index
;
760 printf (" %08lx ", (unsigned long) psym
->st_value
);
762 if (psym
->st_name
== 0)
764 SECTION_NAME (section_headers
+ psym
->st_shndx
));
765 else if (strtab
== NULL
)
766 printf (_("<string table index %3ld>"), psym
->st_name
);
768 printf ("%-25.25s", strtab
+ psym
->st_name
);
771 printf (" + %lx", (unsigned long) relas
[i
].r_addend
);
776 printf ("%34c%lx", ' ', (unsigned long) relas
[i
].r_addend
);
778 if (elf_header
.e_machine
== EM_SPARCV9
779 && !strcmp (rtype
, "R_SPARC_OLO10"))
780 printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (info
));
791 get_mips_dynamic_type (type
)
796 case DT_MIPS_RLD_VERSION
: return "MIPS_RLD_VERSION";
797 case DT_MIPS_TIME_STAMP
: return "MIPS_TIME_STAMP";
798 case DT_MIPS_ICHECKSUM
: return "MIPS_ICHECKSUM";
799 case DT_MIPS_IVERSION
: return "MIPS_IVERSION";
800 case DT_MIPS_FLAGS
: return "MIPS_FLAGS";
801 case DT_MIPS_BASE_ADDRESS
: return "MIPS_BASE_ADDRESS";
802 case DT_MIPS_MSYM
: return "MIPS_MSYM";
803 case DT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
804 case DT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
805 case DT_MIPS_LOCAL_GOTNO
: return "MIPS_LOCAL_GOTNO";
806 case DT_MIPS_CONFLICTNO
: return "MIPS_CONFLICTNO";
807 case DT_MIPS_LIBLISTNO
: return "MIPS_LIBLISTNO";
808 case DT_MIPS_SYMTABNO
: return "MIPS_SYMTABNO";
809 case DT_MIPS_UNREFEXTNO
: return "MIPS_UNREFEXTNO";
810 case DT_MIPS_GOTSYM
: return "MIPS_GOTSYM";
811 case DT_MIPS_HIPAGENO
: return "MIPS_HIPAGENO";
812 case DT_MIPS_RLD_MAP
: return "MIPS_RLD_MAP";
813 case DT_MIPS_DELTA_CLASS
: return "MIPS_DELTA_CLASS";
814 case DT_MIPS_DELTA_CLASS_NO
: return "MIPS_DELTA_CLASS_NO";
815 case DT_MIPS_DELTA_INSTANCE
: return "MIPS_DELTA_INSTANCE";
816 case DT_MIPS_DELTA_INSTANCE_NO
: return "MIPS_DELTA_INSTANCE_NO";
817 case DT_MIPS_DELTA_RELOC
: return "MIPS_DELTA_RELOC";
818 case DT_MIPS_DELTA_RELOC_NO
: return "MIPS_DELTA_RELOC_NO";
819 case DT_MIPS_DELTA_SYM
: return "MIPS_DELTA_SYM";
820 case DT_MIPS_DELTA_SYM_NO
: return "MIPS_DELTA_SYM_NO";
821 case DT_MIPS_DELTA_CLASSSYM
: return "MIPS_DELTA_CLASSSYM";
822 case DT_MIPS_DELTA_CLASSSYM_NO
: return "MIPS_DELTA_CLASSSYM_NO";
823 case DT_MIPS_CXX_FLAGS
: return "MIPS_CXX_FLAGS";
824 case DT_MIPS_PIXIE_INIT
: return "MIPS_PIXIE_INIT";
825 case DT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
826 case DT_MIPS_LOCALPAGE_GOTIDX
: return "MIPS_LOCALPAGE_GOTIDX";
827 case DT_MIPS_LOCAL_GOTIDX
: return "MIPS_LOCAL_GOTIDX";
828 case DT_MIPS_HIDDEN_GOTIDX
: return "MIPS_HIDDEN_GOTIDX";
829 case DT_MIPS_PROTECTED_GOTIDX
: return "MIPS_PROTECTED_GOTIDX";
830 case DT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
831 case DT_MIPS_INTERFACE
: return "MIPS_INTERFACE";
832 case DT_MIPS_DYNSTR_ALIGN
: return "MIPS_DYNSTR_ALIGN";
833 case DT_MIPS_INTERFACE_SIZE
: return "MIPS_INTERFACE_SIZE";
834 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR
: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
835 case DT_MIPS_PERF_SUFFIX
: return "MIPS_PERF_SUFFIX";
836 case DT_MIPS_COMPACT_SIZE
: return "MIPS_COMPACT_SIZE";
837 case DT_MIPS_GP_VALUE
: return "MIPS_GP_VALUE";
838 case DT_MIPS_AUX_DYNAMIC
: return "MIPS_AUX_DYNAMIC";
845 get_sparc64_dynamic_type (type
)
850 case DT_SPARC_REGISTER
: return "SPARC_REGISTER";
857 get_dynamic_type (type
)
860 static char buff
[32];
864 case DT_NULL
: return "NULL";
865 case DT_NEEDED
: return "NEEDED";
866 case DT_PLTRELSZ
: return "PLTRELSZ";
867 case DT_PLTGOT
: return "PLTGOT";
868 case DT_HASH
: return "HASH";
869 case DT_STRTAB
: return "STRTAB";
870 case DT_SYMTAB
: return "SYMTAB";
871 case DT_RELA
: return "RELA";
872 case DT_RELASZ
: return "RELASZ";
873 case DT_RELAENT
: return "RELAENT";
874 case DT_STRSZ
: return "STRSZ";
875 case DT_SYMENT
: return "SYMENT";
876 case DT_INIT
: return "INIT";
877 case DT_FINI
: return "FINI";
878 case DT_SONAME
: return "SONAME";
879 case DT_RPATH
: return "RPATH";
880 case DT_SYMBOLIC
: return "SYMBOLIC";
881 case DT_REL
: return "REL";
882 case DT_RELSZ
: return "RELSZ";
883 case DT_RELENT
: return "RELENT";
884 case DT_PLTREL
: return "PLTREL";
885 case DT_DEBUG
: return "DEBUG";
886 case DT_TEXTREL
: return "TEXTREL";
887 case DT_JMPREL
: return "JMPREL";
888 case DT_BIND_NOW
: return "BIND_NOW";
889 case DT_INIT_ARRAY
: return "INIT_ARRAY";
890 case DT_FINI_ARRAY
: return "FINI_ARRAY";
891 case DT_INIT_ARRAYSZ
: return "INIT_ARRAYSZ";
892 case DT_FINI_ARRAYSZ
: return "FINI_ARRAYSZ";
894 case DT_PLTPADSZ
: return "PLTPADSZ";
895 case DT_MOVEENT
: return "MOVEENT";
896 case DT_MOVESZ
: return "MOVESZ";
897 case DT_FEATURE_1
: return "FEATURE_1";
898 case DT_POSFLAG_1
: return "POSFLAG_1";
899 case DT_SYMINSZ
: return "SYMINSZ";
900 case DT_SYMINENT
: return "SYMINENT"; /* aka VALRNGHI */
902 case DT_ADDRRNGLO
: return "ADDRRNGLO";
903 case DT_SYMINFO
: return "SYMINFO"; /* aka ADDRRNGHI */
905 case DT_VERSYM
: return "VERSYM";
907 case DT_RELACOUNT
: return "RELACOUNT";
908 case DT_RELCOUNT
: return "RELCOUNT";
909 case DT_FLAGS_1
: return "FLAGS_1";
910 case DT_VERDEF
: return "VERDEF";
911 case DT_VERDEFNUM
: return "VERDEFNUM";
912 case DT_VERNEED
: return "VERNEED";
913 case DT_VERNEEDNUM
: return "VERNEEDNUM";
915 case DT_AUXILIARY
: return "AUXILARY";
916 case DT_USED
: return "USED";
917 case DT_FILTER
: return "FILTER";
920 if ((type
>= DT_LOPROC
) && (type
<= DT_HIPROC
))
924 switch (elf_header
.e_machine
)
928 result
= get_mips_dynamic_type (type
);
931 result
= get_sparc64_dynamic_type (type
);
941 sprintf (buff
, _("Processor Specific: %lx"), type
);
943 else if ((type
>= DT_LOOS
) && (type
<= DT_HIOS
))
944 sprintf (buff
, _("Operating System specific: %lx"), type
);
946 sprintf (buff
, _("<unknown>: %lx"), type
);
953 get_file_type (e_type
)
956 static char buff
[32];
960 case ET_NONE
: return _("NONE (None)");
961 case ET_REL
: return _("REL (Relocatable file)");
962 case ET_EXEC
: return _("EXEC (Executable file)");
963 case ET_DYN
: return _("DYN (Shared object file)");
964 case ET_CORE
: return _("CORE (Core file)");
967 if ((e_type
>= ET_LOPROC
) && (e_type
<= ET_HIPROC
))
968 sprintf (buff
, _("Processor Specific: (%x)"), e_type
);
969 else if ((e_type
>= ET_LOOS
) && (e_type
<= ET_HIOS
))
970 sprintf (buff
, _("OS Specific: (%x)"), e_type
);
972 sprintf (buff
, _("<unknown>: %x"), e_type
);
978 get_machine_name (e_machine
)
981 static char buff
[32];
985 case EM_NONE
: return _("None");
986 case EM_M32
: return "WE32100";
987 case EM_SPARC
: return "Sparc";
988 case EM_386
: return "Intel 80386";
989 case EM_68K
: return "MC68000";
990 case EM_88K
: return "MC88000";
991 case EM_486
: return "Intel 80486";
992 case EM_860
: return "Intel 80860";
993 case EM_MIPS
: return "MIPS R3000 big-endian";
994 case EM_S370
: return "Amdahl";
995 case EM_MIPS_RS4_BE
: return "MIPS R4000 big-endian";
996 case EM_OLD_SPARCV9
: return "Sparc v9 (old)";
997 case EM_PARISC
: return "HPPA";
998 case EM_PPC_OLD
: return "Power PC (old)";
999 case EM_SPARC32PLUS
: return "Sparc v8+" ;
1000 case EM_960
: return "Intel 90860";
1001 case EM_PPC
: return "PowerPC";
1002 case EM_V800
: return "NEC V800";
1003 case EM_FR20
: return "Fujitsu FR20";
1004 case EM_RH32
: return "TRW RH32";
1005 case EM_MCORE
: return "MCORE";
1006 case EM_ARM
: return "ARM";
1007 case EM_OLD_ALPHA
: return "Digital Alpha (old)";
1008 case EM_SH
: return "Hitachi SH";
1009 case EM_SPARCV9
: return "Sparc v9";
1010 case EM_TRICORE
: return "Siemens Tricore";
1011 case EM_ARC
: return "Argonaut RISC Core";
1012 case EM_H8_300
: return "Hitachi H8/300";
1013 case EM_H8_300H
: return "Hitachi H8/300H";
1014 case EM_H8S
: return "Hitachi H8S";
1015 case EM_H8_500
: return "Hitachi H8/500";
1016 case EM_IA_64
: return "Intel Merced";
1017 case EM_MIPS_X
: return "Stanford MIPS-X";
1018 case EM_COLDFIRE
: return "Motorola Coldfire";
1019 case EM_68HC12
: return "Motorola M68HC12";
1020 case EM_ALPHA
: return "Alpha";
1021 case EM_CYGNUS_D10V
: return "d10v";
1022 case EM_CYGNUS_D30V
: return "d30v";
1023 case EM_CYGNUS_ARC
: return "Arc";
1024 case EM_CYGNUS_M32R
: return "Mitsubishi M32r";
1025 case EM_CYGNUS_V850
: return "NEC v850";
1026 case EM_CYGNUS_MN10300
: return "mn10300";
1027 case EM_CYGNUS_MN10200
: return "mn10200";
1028 case EM_CYGNUS_FR30
: return "Fujitsu FR30";
1031 sprintf (buff
, _("<unknown>: %x"), e_machine
);
1037 get_machine_flags (e_flags
, e_machine
)
1041 static char buf
[1024];
1052 if (e_flags
& EF_CPU32
)
1053 strcat (buf
, ", cpu32");
1057 if (e_flags
& EF_PPC_EMB
)
1058 strcat (buf
, ", emb");
1060 if (e_flags
& EF_PPC_RELOCATABLE
)
1061 strcat (buf
, ", relocatable");
1063 if (e_flags
& EF_PPC_RELOCATABLE_LIB
)
1064 strcat (buf
, ", relocatable-lib");
1067 case EM_CYGNUS_V850
:
1068 switch (e_flags
& EF_V850_ARCH
)
1071 strcat (buf
, ", v850e");
1074 strcat (buf
, ", v850ea");
1077 strcat (buf
, ", v850");
1080 strcat (buf
, ", unknown v850 architecture variant");
1085 case EM_CYGNUS_M32R
:
1086 if ((e_flags
& EF_M32R_ARCH
) == E_M32R_ARCH
)
1087 strcat (buf
, ", m32r");
1092 case EM_MIPS_RS4_BE
:
1093 if (e_flags
& EF_MIPS_NOREORDER
)
1094 strcat (buf
, ", noreorder");
1096 if (e_flags
& EF_MIPS_PIC
)
1097 strcat (buf
, ", pic");
1099 if (e_flags
& EF_MIPS_CPIC
)
1100 strcat (buf
, ", cpic");
1102 if (e_flags
& EF_MIPS_ABI2
)
1103 strcat (buf
, ", abi2");
1105 if ((e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_1
)
1106 strcat (buf
, ", mips1");
1108 if ((e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_2
)
1109 strcat (buf
, ", mips2");
1111 if ((e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_3
)
1112 strcat (buf
, ", mips3");
1114 if ((e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_4
)
1115 strcat (buf
, ", mips4");
1119 if (e_flags
& EF_SPARC_32PLUS
)
1120 strcat (buf
, ", v8+");
1122 if (e_flags
& EF_SPARC_SUN_US1
)
1123 strcat (buf
, ", ultrasparcI");
1125 if (e_flags
& EF_SPARC_SUN_US3
)
1126 strcat (buf
, ", ultrasparcIII");
1128 if (e_flags
& EF_SPARC_HAL_R1
)
1129 strcat (buf
, ", halr1");
1131 if (e_flags
& EF_SPARC_LEDATA
)
1132 strcat (buf
, ", ledata");
1134 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_TSO
)
1135 strcat (buf
, ", tso");
1137 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_PSO
)
1138 strcat (buf
, ", pso");
1140 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_RMO
)
1141 strcat (buf
, ", rmo");
1150 get_mips_segment_type (type
)
1155 case PT_MIPS_REGINFO
:
1157 case PT_MIPS_RTPROC
:
1159 case PT_MIPS_OPTIONS
:
1169 get_segment_type (p_type
)
1170 unsigned long p_type
;
1172 static char buff
[32];
1176 case PT_NULL
: return "NULL";
1177 case PT_LOAD
: return "LOAD";
1178 case PT_DYNAMIC
: return "DYNAMIC";
1179 case PT_INTERP
: return "INTERP";
1180 case PT_NOTE
: return "NOTE";
1181 case PT_SHLIB
: return "SHLIB";
1182 case PT_PHDR
: return "PHDR";
1185 if ((p_type
>= PT_LOPROC
) && (p_type
<= PT_HIPROC
))
1187 const char * result
;
1189 switch (elf_header
.e_machine
)
1192 case EM_MIPS_RS4_BE
:
1193 result
= get_mips_segment_type (p_type
);
1203 sprintf (buff
, "LOPROC+%lx", p_type
- PT_LOPROC
);
1205 else if ((p_type
>= PT_LOOS
) && (p_type
<= PT_HIOS
))
1206 sprintf (buff
, "LOOS+%lx", p_type
- PT_LOOS
);
1208 sprintf (buff
, _("<unknown>: %lx"), p_type
);
1215 get_mips_section_type_name (sh_type
)
1216 unsigned int sh_type
;
1220 case SHT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
1221 case SHT_MIPS_MSYM
: return "MIPS_MSYM";
1222 case SHT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
1223 case SHT_MIPS_GPTAB
: return "MIPS_GPTAB";
1224 case SHT_MIPS_UCODE
: return "MIPS_UCODE";
1225 case SHT_MIPS_DEBUG
: return "MIPS_DEBUG";
1226 case SHT_MIPS_REGINFO
: return "MIPS_REGINFO";
1227 case SHT_MIPS_PACKAGE
: return "MIPS_PACKAGE";
1228 case SHT_MIPS_PACKSYM
: return "MIPS_PACKSYM";
1229 case SHT_MIPS_RELD
: return "MIPS_RELD";
1230 case SHT_MIPS_IFACE
: return "MIPS_IFACE";
1231 case SHT_MIPS_CONTENT
: return "MIPS_CONTENT";
1232 case SHT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
1233 case SHT_MIPS_SHDR
: return "MIPS_SHDR";
1234 case SHT_MIPS_FDESC
: return "MIPS_FDESC";
1235 case SHT_MIPS_EXTSYM
: return "MIPS_EXTSYM";
1236 case SHT_MIPS_DENSE
: return "MIPS_DENSE";
1237 case SHT_MIPS_PDESC
: return "MIPS_PDESC";
1238 case SHT_MIPS_LOCSYM
: return "MIPS_LOCSYM";
1239 case SHT_MIPS_AUXSYM
: return "MIPS_AUXSYM";
1240 case SHT_MIPS_OPTSYM
: return "MIPS_OPTSYM";
1241 case SHT_MIPS_LOCSTR
: return "MIPS_LOCSTR";
1242 case SHT_MIPS_LINE
: return "MIPS_LINE";
1243 case SHT_MIPS_RFDESC
: return "MIPS_RFDESC";
1244 case SHT_MIPS_DELTASYM
: return "MIPS_DELTASYM";
1245 case SHT_MIPS_DELTAINST
: return "MIPS_DELTAINST";
1246 case SHT_MIPS_DELTACLASS
: return "MIPS_DELTACLASS";
1247 case SHT_MIPS_DWARF
: return "MIPS_DWARF";
1248 case SHT_MIPS_DELTADECL
: return "MIPS_DELTADECL";
1249 case SHT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
1250 case SHT_MIPS_EVENTS
: return "MIPS_EVENTS";
1251 case SHT_MIPS_TRANSLATE
: return "MIPS_TRANSLATE";
1252 case SHT_MIPS_PIXIE
: return "MIPS_PIXIE";
1253 case SHT_MIPS_XLATE
: return "MIPS_XLATE";
1254 case SHT_MIPS_XLATE_DEBUG
: return "MIPS_XLATE_DEBUG";
1255 case SHT_MIPS_WHIRL
: return "MIPS_WHIRL";
1256 case SHT_MIPS_EH_REGION
: return "MIPS_EH_REGION";
1257 case SHT_MIPS_XLATE_OLD
: return "MIPS_XLATE_OLD";
1258 case SHT_MIPS_PDR_EXCEPTION
: return "MIPS_PDR_EXCEPTION";
1266 get_section_type_name (sh_type
)
1267 unsigned int sh_type
;
1269 static char buff
[32];
1273 case SHT_NULL
: return "NULL";
1274 case SHT_PROGBITS
: return "PROGBITS";
1275 case SHT_SYMTAB
: return "SYMTAB";
1276 case SHT_STRTAB
: return "STRTAB";
1277 case SHT_RELA
: return "RELA";
1278 case SHT_HASH
: return "HASH";
1279 case SHT_DYNAMIC
: return "DYNAMIC";
1280 case SHT_NOTE
: return "NOTE";
1281 case SHT_NOBITS
: return "NOBITS";
1282 case SHT_REL
: return "REL";
1283 case SHT_SHLIB
: return "SHLIB";
1284 case SHT_DYNSYM
: return "DYNSYM";
1285 case SHT_GNU_verdef
: return "VERDEF";
1286 case SHT_GNU_verneed
: return "VERNEED";
1287 case SHT_GNU_versym
: return "VERSYM";
1288 case 0x6ffffff0: return "VERSYM";
1289 case 0x6ffffffc: return "VERDEF";
1290 case 0x7ffffffd: return "AUXILIARY";
1291 case 0x7fffffff: return "FILTER";
1294 if ((sh_type
>= SHT_LOPROC
) && (sh_type
<= SHT_HIPROC
))
1296 const char * result
;
1298 switch (elf_header
.e_machine
)
1301 case EM_MIPS_RS4_BE
:
1302 result
= get_mips_section_type_name (sh_type
);
1312 sprintf (buff
, "SHT_LOPROC+%x", sh_type
- SHT_LOPROC
);
1314 else if ((sh_type
>= SHT_LOOS
) && (sh_type
<= SHT_HIOS
))
1315 sprintf (buff
, "SHT_LOOS+%x", sh_type
- SHT_LOOS
);
1316 else if ((sh_type
>= SHT_LOUSER
) && (sh_type
<= SHT_HIUSER
))
1317 sprintf (buff
, "SHT_LOUSER+%x", sh_type
- SHT_LOUSER
);
1319 sprintf (buff
, _("<unknown>: %x"), sh_type
);
1325 struct option options
[] =
1327 {"all", no_argument
, 0, 'a'},
1328 {"file-header", no_argument
, 0, 'h'},
1329 {"program-headers", no_argument
, 0, 'l'},
1330 {"headers", no_argument
, 0, 'e'},
1331 {"histogram", no_argument
, 0, 'I'},
1332 {"segments", no_argument
, 0, 'l'},
1333 {"sections", no_argument
, 0, 'S'},
1334 {"section-headers", no_argument
, 0, 'S'},
1335 {"symbols", no_argument
, 0, 's'},
1336 {"syms", no_argument
, 0, 's'},
1337 {"relocs", no_argument
, 0, 'r'},
1338 {"dynamic", no_argument
, 0, 'd'},
1339 {"arch-specific", no_argument
, 0, 'A'},
1340 {"version-info", no_argument
, 0, 'V'},
1341 {"use-dynamic", no_argument
, 0, 'D'},
1342 {"hex-dump", required_argument
, 0, 'x'},
1343 {"debug-dump", optional_argument
, 0, 'w'},
1344 #ifdef SUPPORT_DISASSEMBLY
1345 {"instruction-dump", required_argument
, 0, 'i'},
1348 {"version", no_argument
, 0, 'v'},
1349 {"help", no_argument
, 0, 'H'},
1350 {0, no_argument
, 0, 0}
1356 fprintf (stdout
, _("Usage: readelf {options} elf-file(s)\n"));
1357 fprintf (stdout
, _(" Options are:\n"));
1358 fprintf (stdout
, _(" -a or --all Equivalent to: -h -l -S -s -r -d -V -A -I\n"));
1359 fprintf (stdout
, _(" -h or --file-header Display the ELF file header\n"));
1360 fprintf (stdout
, _(" -l or --program-headers or --segments\n"));
1361 fprintf (stdout
, _(" Display the program headers\n"));
1362 fprintf (stdout
, _(" -S or --section-headers or --sections\n"));
1363 fprintf (stdout
, _(" Display the sections' header\n"));
1364 fprintf (stdout
, _(" -e or --headers Equivalent to: -h -l -S\n"));
1365 fprintf (stdout
, _(" -s or --syms or --symbols Display the symbol table\n"));
1366 fprintf (stdout
, _(" -r or --relocs Display the relocations (if present)\n"));
1367 fprintf (stdout
, _(" -d or --dynamic Display the dynamic segment (if present)\n"));
1368 fprintf (stdout
, _(" -V or --version-info Display the version sections (if present)\n"));
1369 fprintf (stdout
, _(" -A or --arch-specific Display architecture specific information (if any).\n"));
1370 fprintf (stdout
, _(" -D or --use-dynamic Use the dynamic section info when displaying symbols\n"));
1371 fprintf (stdout
, _(" -x <number> or --hex-dump=<number>\n"));
1372 fprintf (stdout
, _(" Dump the contents of section <number>\n"));
1373 fprintf (stdout
, _(" -w[liapr] or --debug-dump[=line,=info,=abbrev,=pubnames,=ranges]\n"));
1374 fprintf (stdout
, _(" Display the contents of DWARF2 debug sections\n"));
1375 #ifdef SUPPORT_DISASSEMBLY
1376 fprintf (stdout
, _(" -i <number> or --instruction-dump=<number>\n"));
1377 fprintf (stdout
, _(" Disassemble the contents of section <number>\n"));
1379 fprintf (stdout
, _(" -I or --histogram Display histogram of bucket list lengths\n"));
1380 fprintf (stdout
, _(" -v or --version Display the version number of readelf\n"));
1381 fprintf (stdout
, _(" -H or --help Display this information\n"));
1382 fprintf (stdout
, _("Report bugs to bug-gnu-utils@gnu.org\n"));
1388 request_dump (section
, type
)
1389 unsigned int section
;
1392 if (section
>= num_dump_sects
)
1394 char * new_dump_sects
;
1396 new_dump_sects
= (char *) calloc (section
+ 1, 1);
1398 if (new_dump_sects
== NULL
)
1399 error (_("Out of memory allocating dump request table."));
1402 /* Copy current flag settings. */
1403 memcpy (new_dump_sects
, dump_sects
, num_dump_sects
);
1407 dump_sects
= new_dump_sects
;
1408 num_dump_sects
= section
+ 1;
1413 dump_sects
[section
] |= type
;
1419 parse_args (argc
, argv
)
1428 while ((c
= getopt_long
1429 (argc
, argv
, "ersahldSDAIw::x:i:vV", options
, NULL
)) != EOF
)
1463 do_using_dynamic
++;
1488 section
= strtoul (optarg
, & cp
, 0);
1489 if (! * cp
&& section
>= 0)
1491 request_dump (section
, HEX_DUMP
);
1511 do_debug_abbrevs
= 1;
1521 do_debug_pubnames
= 1;
1526 do_debug_aranges
= 1;
1530 warn (_("Unrecognised debug option '%s'\n"), optarg
);
1535 #ifdef SUPPORT_DISASSEMBLY
1538 section
= strtoul (optarg
, & cp
, 0);
1539 if (! * cp
&& section
>= 0)
1541 request_dump (section
, DISASS_DUMP
);
1547 print_version (program_name
);
1554 /* xgettext:c-format */
1555 error (_("Invalid option '-%c'\n"), c
);
1562 if (!do_dynamic
&& !do_syms
&& !do_reloc
&& !do_sections
1563 && !do_segments
&& !do_header
&& !do_dump
&& !do_version
1564 && !do_histogram
&& !do_debugging
&& !do_arch
)
1568 warn (_("Nothing to do.\n"));
1574 get_elf_class (elf_class
)
1575 unsigned char elf_class
;
1577 static char buff
[32];
1581 case ELFCLASSNONE
: return _("none");
1582 case ELFCLASS32
: return _("ELF32");
1583 case ELFCLASS64
: return _("ELF64");
1585 sprintf (buff
, _("<unknown: %x>"), elf_class
);
1591 get_data_encoding (encoding
)
1592 unsigned char encoding
;
1594 static char buff
[32];
1598 case ELFDATANONE
: return _("none");
1599 case ELFDATA2LSB
: return _("2's complement, little endian");
1600 case ELFDATA2MSB
: return _("2's complement, big endian");
1602 sprintf (buff
, _("<unknown: %x>"), encoding
);
1608 get_osabi_name (osabi
)
1609 unsigned char osabi
;
1611 static char buff
[32];
1615 case ELFOSABI_SYSV
: return _("UNIX - System V");
1616 case ELFOSABI_HPUX
: return _("UNIX - HP-UX");
1617 case ELFOSABI_STANDALONE
: return _("Standalone App");
1619 sprintf (buff
, _("<unknown: %x>"), osabi
);
1624 /* Decode the data held in 'elf_header'. */
1626 process_file_header ()
1628 if ( elf_header
.e_ident
[EI_MAG0
] != ELFMAG0
1629 || elf_header
.e_ident
[EI_MAG1
] != ELFMAG1
1630 || elf_header
.e_ident
[EI_MAG2
] != ELFMAG2
1631 || elf_header
.e_ident
[EI_MAG3
] != ELFMAG3
)
1634 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
1642 printf (_("ELF Header:\n"));
1643 printf (_(" Magic: "));
1644 for (i
= 0; i
< EI_NIDENT
; i
++)
1645 printf ("%2.2x ", elf_header
.e_ident
[i
]);
1647 printf (_(" Class: %s\n"),
1648 get_elf_class (elf_header
.e_ident
[EI_CLASS
]));
1649 printf (_(" Data: %s\n"),
1650 get_data_encoding (elf_header
.e_ident
[EI_DATA
]));
1651 printf (_(" Version: %d %s\n"),
1652 elf_header
.e_ident
[EI_VERSION
],
1653 (elf_header
.e_ident
[EI_VERSION
] == EV_CURRENT
1655 : (elf_header
.e_ident
[EI_VERSION
] != EV_NONE
1658 printf (_(" OS/ABI: %s\n"),
1659 get_osabi_name (elf_header
.e_ident
[EI_OSABI
]));
1660 printf (_(" ABI Version: %d\n"),
1661 elf_header
.e_ident
[EI_ABIVERSION
]);
1662 printf (_(" Type: %s\n"),
1663 get_file_type (elf_header
.e_type
));
1664 printf (_(" Machine: %s\n"),
1665 get_machine_name (elf_header
.e_machine
));
1666 printf (_(" Version: 0x%lx\n"),
1667 (unsigned long) elf_header
.e_version
);
1668 printf (_(" Entry point address: 0x%lx\n"),
1669 (unsigned long) elf_header
.e_entry
);
1670 printf (_(" Start of program headers: %ld (bytes into file)\n"),
1671 (long) elf_header
.e_phoff
);
1672 printf (_(" Start of section headers: %ld (bytes into file)\n"),
1673 (long) elf_header
.e_shoff
);
1674 printf (_(" Flags: 0x%lx%s\n"),
1675 (unsigned long) elf_header
.e_flags
,
1676 get_machine_flags (elf_header
.e_flags
, elf_header
.e_machine
));
1677 printf (_(" Size of this header: %ld (bytes)\n"),
1678 (long) elf_header
.e_ehsize
);
1679 printf (_(" Size of program headers: %ld (bytes)\n"),
1680 (long) elf_header
.e_phentsize
);
1681 printf (_(" Number of program headers: %ld\n"),
1682 (long) elf_header
.e_phnum
);
1683 printf (_(" Size of section headers: %ld (bytes)\n"),
1684 (long) elf_header
.e_shentsize
);
1685 printf (_(" Number of section headers: %ld\n"),
1686 (long) elf_header
.e_shnum
);
1687 printf (_(" Section header string table index: %ld\n"),
1688 (long) elf_header
.e_shstrndx
);
1696 get_32bit_program_headers (file
, program_headers
)
1698 Elf_Internal_Phdr
* program_headers
;
1700 Elf32_External_Phdr
* phdrs
;
1701 Elf32_External_Phdr
* external
;
1702 Elf32_Internal_Phdr
* internal
;
1705 GET_DATA_ALLOC (elf_header
.e_phoff
,
1706 elf_header
.e_phentsize
* elf_header
.e_phnum
,
1707 phdrs
, Elf32_External_Phdr
*, "program headers");
1709 for (i
= 0, internal
= program_headers
, external
= phdrs
;
1710 i
< elf_header
.e_phnum
;
1711 i
++, internal
++, external
++)
1713 internal
->p_type
= BYTE_GET (external
->p_type
);
1714 internal
->p_offset
= BYTE_GET (external
->p_offset
);
1715 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
1716 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
1717 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
1718 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
1719 internal
->p_flags
= BYTE_GET (external
->p_flags
);
1720 internal
->p_align
= BYTE_GET (external
->p_align
);
1729 get_64bit_program_headers (file
, program_headers
)
1731 Elf_Internal_Phdr
* program_headers
;
1733 Elf64_External_Phdr
* phdrs
;
1734 Elf64_External_Phdr
* external
;
1735 Elf64_Internal_Phdr
* internal
;
1738 GET_DATA_ALLOC (elf_header
.e_phoff
,
1739 elf_header
.e_phentsize
* elf_header
.e_phnum
,
1740 phdrs
, Elf64_External_Phdr
*, "program headers");
1742 for (i
= 0, internal
= program_headers
, external
= phdrs
;
1743 i
< elf_header
.e_phnum
;
1744 i
++, internal
++, external
++)
1746 internal
->p_type
= BYTE_GET (external
->p_type
);
1747 internal
->p_flags
= BYTE_GET (external
->p_flags
);
1748 internal
->p_offset
= BYTE_GET8 (external
->p_offset
);
1749 internal
->p_vaddr
= BYTE_GET8 (external
->p_vaddr
);
1750 internal
->p_paddr
= BYTE_GET8 (external
->p_paddr
);
1751 internal
->p_filesz
= BYTE_GET8 (external
->p_filesz
);
1752 internal
->p_memsz
= BYTE_GET8 (external
->p_memsz
);
1753 internal
->p_align
= BYTE_GET8 (external
->p_align
);
1762 process_program_headers (file
)
1765 Elf_Internal_Phdr
* program_headers
;
1766 Elf_Internal_Phdr
* segment
;
1769 if (elf_header
.e_phnum
== 0)
1772 printf (_("\nThere are no program headers in this file.\n"));
1776 if (do_segments
&& !do_header
)
1778 printf (_("\nElf file is %s\n"), get_file_type (elf_header
.e_type
));
1779 printf (_("Entry point 0x%lx\n"), (unsigned long) elf_header
.e_entry
);
1780 printf (_("There are %d program headers, starting at offset %lx:\n"),
1781 elf_header
.e_phnum
, (unsigned long) elf_header
.e_phoff
);
1784 program_headers
= (Elf_Internal_Phdr
*) malloc
1785 (elf_header
.e_phnum
* sizeof (Elf_Internal_Phdr
));
1787 if (program_headers
== NULL
)
1789 error (_("Out of memory\n"));
1794 i
= get_32bit_program_headers (file
, program_headers
);
1796 i
= get_64bit_program_headers (file
, program_headers
);
1800 free (program_headers
);
1807 (_("\nProgram Header%s:\n"), elf_header
.e_phnum
> 1 ? "s" : "");
1809 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
1816 for (i
= 0, segment
= program_headers
;
1817 i
< elf_header
.e_phnum
;
1822 printf (" %-11.11s ", get_segment_type (segment
->p_type
));
1823 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
1824 printf ("0x%8.8lx ", (unsigned long) segment
->p_vaddr
);
1825 printf ("0x%8.8lx ", (unsigned long) segment
->p_paddr
);
1826 printf ("0x%5.5lx ", (unsigned long) segment
->p_filesz
);
1827 printf ("0x%5.5lx ", (unsigned long) segment
->p_memsz
);
1829 (segment
->p_flags
& PF_R
? 'R' : ' '),
1830 (segment
->p_flags
& PF_W
? 'W' : ' '),
1831 (segment
->p_flags
& PF_X
? 'E' : ' '));
1832 printf ("%#lx", (unsigned long) segment
->p_align
);
1835 switch (segment
->p_type
)
1839 loadaddr
= (segment
->p_vaddr
& 0xfffff000)
1840 - (segment
->p_offset
& 0xfffff000);
1845 error (_("more than one dynamic segment\n"));
1847 dynamic_addr
= segment
->p_offset
;
1848 dynamic_size
= segment
->p_filesz
;
1852 if (fseek (file
, segment
->p_offset
, SEEK_SET
))
1853 error (_("Unable to find program interpreter name\n"));
1856 program_interpreter
[0] = 0;
1857 fscanf (file
, "%63s", program_interpreter
);
1860 printf (_("\n [Requesting program interpreter: %s]"),
1861 program_interpreter
);
1867 putc ('\n', stdout
);
1876 if (do_segments
&& section_headers
!= NULL
)
1878 printf (_("\n Section to Segment mapping:\n"));
1879 printf (_(" Segment Sections...\n"));
1881 assert (string_table
!= NULL
);
1883 for (i
= 0; i
< elf_header
.e_phnum
; i
++)
1886 Elf_Internal_Shdr
* section
;
1888 segment
= program_headers
+ i
;
1889 section
= section_headers
;
1891 printf (" %2.2d ", i
);
1893 for (j
= 0; j
< elf_header
.e_shnum
; j
++, section
++)
1895 if (section
->sh_size
> 0
1896 /* Compare allocated sections by VMA, unallocated
1897 sections by file offset. */
1898 && (section
->sh_flags
& SHF_ALLOC
1899 ? (section
->sh_addr
>= segment
->p_vaddr
1900 && section
->sh_addr
+ section
->sh_size
1901 <= segment
->p_vaddr
+ segment
->p_memsz
)
1902 : ((bfd_vma
) section
->sh_offset
>= segment
->p_offset
1903 && (section
->sh_offset
+ section
->sh_size
1904 <= segment
->p_offset
+ segment
->p_filesz
))))
1905 printf ("%s ", SECTION_NAME (section
));
1912 free (program_headers
);
1919 get_32bit_section_headers (file
)
1922 Elf32_External_Shdr
* shdrs
;
1923 Elf32_Internal_Shdr
* internal
;
1926 GET_DATA_ALLOC (elf_header
.e_shoff
,
1927 elf_header
.e_shentsize
* elf_header
.e_shnum
,
1928 shdrs
, Elf32_External_Shdr
*, "section headers");
1930 section_headers
= (Elf_Internal_Shdr
*) malloc
1931 (elf_header
.e_shnum
* sizeof (Elf_Internal_Shdr
));
1933 if (section_headers
== NULL
)
1935 error (_("Out of memory\n"));
1939 for (i
= 0, internal
= section_headers
;
1940 i
< elf_header
.e_shnum
;
1943 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
1944 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
1945 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
1946 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
1947 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
1948 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
1949 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
1950 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
1951 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
1952 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
1961 get_64bit_section_headers (file
)
1964 Elf64_External_Shdr
* shdrs
;
1965 Elf64_Internal_Shdr
* internal
;
1968 GET_DATA_ALLOC (elf_header
.e_shoff
,
1969 elf_header
.e_shentsize
* elf_header
.e_shnum
,
1970 shdrs
, Elf64_External_Shdr
*, "section headers");
1972 section_headers
= (Elf_Internal_Shdr
*) malloc
1973 (elf_header
.e_shnum
* sizeof (Elf_Internal_Shdr
));
1975 if (section_headers
== NULL
)
1977 error (_("Out of memory\n"));
1981 for (i
= 0, internal
= section_headers
;
1982 i
< elf_header
.e_shnum
;
1985 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
1986 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
1987 internal
->sh_flags
= BYTE_GET8 (shdrs
[i
].sh_flags
);
1988 internal
->sh_addr
= BYTE_GET8 (shdrs
[i
].sh_addr
);
1989 internal
->sh_size
= BYTE_GET8 (shdrs
[i
].sh_size
);
1990 internal
->sh_entsize
= BYTE_GET8 (shdrs
[i
].sh_entsize
);
1991 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
1992 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
1993 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
1994 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
2002 static Elf_Internal_Sym
*
2003 get_32bit_elf_symbols (file
, offset
, number
)
2005 unsigned long offset
;
2006 unsigned long number
;
2008 Elf32_External_Sym
* esyms
;
2009 Elf_Internal_Sym
* isyms
;
2010 Elf_Internal_Sym
* psym
;
2013 GET_DATA_ALLOC (offset
, number
* sizeof (Elf32_External_Sym
),
2014 esyms
, Elf32_External_Sym
*, "symbols");
2016 isyms
= (Elf_Internal_Sym
*) malloc (number
* sizeof (Elf_Internal_Sym
));
2020 error (_("Out of memory\n"));
2026 for (j
= 0, psym
= isyms
;
2030 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
2031 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
2032 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
2033 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
2034 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
2035 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
2043 static Elf_Internal_Sym
*
2044 get_64bit_elf_symbols (file
, offset
, number
)
2046 unsigned long offset
;
2047 unsigned long number
;
2049 Elf64_External_Sym
* esyms
;
2050 Elf_Internal_Sym
* isyms
;
2051 Elf_Internal_Sym
* psym
;
2054 GET_DATA_ALLOC (offset
, number
* sizeof (Elf64_External_Sym
),
2055 esyms
, Elf64_External_Sym
*, "symbols");
2057 isyms
= (Elf_Internal_Sym
*) malloc (number
* sizeof (Elf_Internal_Sym
));
2061 error (_("Out of memory\n"));
2067 for (j
= 0, psym
= isyms
;
2071 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
2072 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
2073 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
2074 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
2075 psym
->st_value
= BYTE_GET8 (esyms
[j
].st_value
);
2076 psym
->st_size
= BYTE_GET8 (esyms
[j
].st_size
);
2085 process_section_headers (file
)
2088 Elf_Internal_Shdr
* section
;
2091 section_headers
= NULL
;
2093 if (elf_header
.e_shnum
== 0)
2096 printf (_("\nThere are no sections in this file.\n"));
2101 if (do_sections
&& !do_header
)
2102 printf (_("There are %d section headers, starting at offset 0x%lx:\n"),
2103 elf_header
.e_shnum
, (unsigned long) elf_header
.e_shoff
);
2107 if (! get_32bit_section_headers (file
))
2110 else if (! get_64bit_section_headers (file
))
2113 /* Read in the string table, so that we have names to display. */
2114 section
= section_headers
+ elf_header
.e_shstrndx
;
2116 if (section
->sh_size
!= 0)
2118 unsigned long string_table_offset
;
2120 string_table_offset
= section
->sh_offset
;
2122 GET_DATA_ALLOC (section
->sh_offset
, section
->sh_size
,
2123 string_table
, char *, "string table");
2126 /* Scan the sections for the dynamic symbol table
2127 and dynamic string table and debug sections. */
2128 dynamic_symbols
= NULL
;
2129 dynamic_strings
= NULL
;
2130 dynamic_syminfo
= NULL
;
2132 for (i
= 0, section
= section_headers
;
2133 i
< elf_header
.e_shnum
;
2136 char * name
= SECTION_NAME (section
);
2138 if (section
->sh_type
== SHT_DYNSYM
)
2140 if (dynamic_symbols
!= NULL
)
2142 error (_("File contains multiple dynamic symbol tables\n"));
2146 num_dynamic_syms
= section
->sh_size
/ section
->sh_entsize
;
2148 GET_ELF_SYMBOLS (file
, section
->sh_offset
, num_dynamic_syms
);
2150 else if (section
->sh_type
== SHT_STRTAB
2151 && strcmp (name
, ".dynstr") == 0)
2153 if (dynamic_strings
!= NULL
)
2155 error (_("File contains multiple dynamic string tables\n"));
2159 GET_DATA_ALLOC (section
->sh_offset
, section
->sh_size
,
2160 dynamic_strings
, char *, "dynamic strings");
2162 else if ((do_debugging
|| do_debug_info
|| do_debug_abbrevs
2163 || do_debug_lines
|| do_debug_pubnames
|| do_debug_aranges
)
2164 && strncmp (name
, ".debug_", 7) == 0)
2169 || (do_debug_info
&& (strcmp (name
, "info") == 0))
2170 || (do_debug_abbrevs
&& (strcmp (name
, "abbrev") == 0))
2171 || (do_debug_lines
&& (strcmp (name
, "line") == 0))
2172 || (do_debug_pubnames
&& (strcmp (name
, "pubnames") == 0))
2173 || (do_debug_aranges
&& (strcmp (name
, "aranges") == 0))
2175 request_dump (i
, DEBUG_DUMP
);
2182 printf (_("\nSection Header%s:\n"), elf_header
.e_shnum
> 1 ? "s" : "");
2184 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
2186 for (i
= 0, section
= section_headers
;
2187 i
< elf_header
.e_shnum
;
2190 printf (" [%2d] %-17.17s %-15.15s ",
2192 SECTION_NAME (section
),
2193 get_section_type_name (section
->sh_type
));
2195 printf ( "%8.8lx %6.6lx %6.6lx %2.2lx",
2196 (unsigned long) section
->sh_addr
,
2197 (unsigned long) section
->sh_offset
,
2198 (unsigned long) section
->sh_size
,
2199 (unsigned long) section
->sh_entsize
);
2201 printf (" %c%c%c %2ld %3lx %ld\n",
2202 (section
->sh_flags
& SHF_WRITE
? 'W' : ' '),
2203 (section
->sh_flags
& SHF_ALLOC
? 'A' : ' '),
2204 (section
->sh_flags
& SHF_EXECINSTR
? 'X' : ' '),
2205 (unsigned long) section
->sh_link
,
2206 (unsigned long) section
->sh_info
,
2207 (unsigned long) section
->sh_addralign
);
2213 /* Process the reloc section. */
2215 process_relocs (file
)
2218 unsigned long rel_size
;
2219 unsigned long rel_offset
;
2225 if (do_using_dynamic
)
2227 int is_rela
= FALSE
;
2232 if (dynamic_info
[DT_REL
])
2234 rel_offset
= dynamic_info
[DT_REL
];
2235 rel_size
= dynamic_info
[DT_RELSZ
];
2238 else if (dynamic_info
[DT_RELA
])
2240 rel_offset
= dynamic_info
[DT_RELA
];
2241 rel_size
= dynamic_info
[DT_RELASZ
];
2244 else if (dynamic_info
[DT_JMPREL
])
2246 rel_offset
= dynamic_info
[DT_JMPREL
];
2247 rel_size
= dynamic_info
[DT_PLTRELSZ
];
2249 switch (dynamic_info
[DT_PLTREL
])
2266 (_("\nRelocation section at offset 0x%lx contains %ld bytes:\n"),
2267 rel_offset
, rel_size
);
2269 dump_relocations (file
, rel_offset
- loadaddr
, rel_size
,
2270 dynamic_symbols
, num_dynamic_syms
, dynamic_strings
, is_rela
);
2273 printf (_("\nThere are no dynamic relocations in this file.\n"));
2277 Elf32_Internal_Shdr
* section
;
2281 for (i
= 0, section
= section_headers
;
2282 i
< elf_header
.e_shnum
;
2285 if ( section
->sh_type
!= SHT_RELA
2286 && section
->sh_type
!= SHT_REL
)
2289 rel_offset
= section
->sh_offset
;
2290 rel_size
= section
->sh_size
;
2294 Elf32_Internal_Shdr
* strsec
;
2295 Elf32_Internal_Shdr
* symsec
;
2296 Elf_Internal_Sym
* symtab
;
2299 unsigned long nsyms
;
2301 printf (_("\nRelocation section "));
2303 if (string_table
== NULL
)
2304 printf ("%d", section
->sh_name
);
2306 printf ("'%s'", SECTION_NAME (section
));
2308 printf (_(" at offset 0x%lx contains %lu entries:\n"),
2309 rel_offset
, (unsigned long) (rel_size
/ section
->sh_entsize
));
2311 symsec
= section_headers
+ section
->sh_link
;
2313 nsyms
= symsec
->sh_size
/ symsec
->sh_entsize
;
2314 symtab
= GET_ELF_SYMBOLS (file
, symsec
->sh_offset
, nsyms
);
2319 strsec
= section_headers
+ symsec
->sh_link
;
2321 GET_DATA_ALLOC (strsec
->sh_offset
, strsec
->sh_size
, strtab
,
2322 char *, "string table");
2324 is_rela
= section
->sh_type
== SHT_RELA
;
2326 dump_relocations (file
, rel_offset
, rel_size
, symtab
, nsyms
, strtab
, is_rela
);
2336 printf (_("\nThere are no relocations in this file.\n"));
2344 dynamic_segment_mips_val (entry
)
2345 Elf_Internal_Dyn
* entry
;
2347 switch (entry
->d_tag
)
2350 if (entry
->d_un
.d_val
== 0)
2354 static const char * opts
[] =
2356 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
2357 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
2358 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
2359 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
2364 for (cnt
= 0; cnt
< NUM_ELEM (opts
); ++ cnt
)
2365 if (entry
->d_un
.d_val
& (1 << cnt
))
2367 printf ("%s%s", first
? "" : " ", opts
[cnt
]);
2374 case DT_MIPS_IVERSION
:
2375 if (dynamic_strings
!= NULL
)
2376 printf ("Interface Version: %s\n",
2377 dynamic_strings
+ entry
->d_un
.d_val
);
2379 printf ("%ld\n", (long) entry
->d_un
.d_ptr
);
2382 case DT_MIPS_TIME_STAMP
:
2385 time_t time
= entry
->d_un
.d_val
;
2386 strftime (timebuf
, 20, "%Y-%m-%dT%H:%M:%S", gmtime (&time
));
2387 printf ("Time Stamp: %s\n", timebuf
);
2391 case DT_MIPS_RLD_VERSION
:
2392 case DT_MIPS_LOCAL_GOTNO
:
2393 case DT_MIPS_CONFLICTNO
:
2394 case DT_MIPS_LIBLISTNO
:
2395 case DT_MIPS_SYMTABNO
:
2396 case DT_MIPS_UNREFEXTNO
:
2397 case DT_MIPS_HIPAGENO
:
2398 case DT_MIPS_DELTA_CLASS_NO
:
2399 case DT_MIPS_DELTA_INSTANCE_NO
:
2400 case DT_MIPS_DELTA_RELOC_NO
:
2401 case DT_MIPS_DELTA_SYM_NO
:
2402 case DT_MIPS_DELTA_CLASSSYM_NO
:
2403 case DT_MIPS_COMPACT_SIZE
:
2404 printf ("%ld\n", (long) entry
->d_un
.d_ptr
);
2408 printf ("%#lx\n", (long) entry
->d_un
.d_ptr
);
2413 get_32bit_dynamic_segment (file
)
2416 Elf32_External_Dyn
* edyn
;
2417 Elf_Internal_Dyn
* entry
;
2420 GET_DATA_ALLOC (dynamic_addr
, dynamic_size
,
2421 edyn
, Elf32_External_Dyn
*, "dynamic segment");
2423 /* SGI's ELF has more than one section in the DYNAMIC segment. Determine
2424 how large this .dynamic is now. We can do this even before the byte
2425 swapping since the DT_NULL tag is recognizable. */
2427 while (*(Elf32_Word
*) edyn
[dynamic_size
++].d_tag
!= DT_NULL
)
2430 dynamic_segment
= (Elf_Internal_Dyn
*)
2431 malloc (dynamic_size
* sizeof (Elf_Internal_Dyn
));
2433 if (dynamic_segment
== NULL
)
2435 error (_("Out of memory\n"));
2440 for (i
= 0, entry
= dynamic_segment
;
2444 entry
->d_tag
= BYTE_GET (edyn
[i
].d_tag
);
2445 entry
->d_un
.d_val
= BYTE_GET (edyn
[i
].d_un
.d_val
);
2454 get_64bit_dynamic_segment (file
)
2457 Elf64_External_Dyn
* edyn
;
2458 Elf_Internal_Dyn
* entry
;
2461 GET_DATA_ALLOC (dynamic_addr
, dynamic_size
,
2462 edyn
, Elf64_External_Dyn
*, "dynamic segment");
2464 /* SGI's ELF has more than one section in the DYNAMIC segment. Determine
2465 how large this .dynamic is now. We can do this even before the byte
2466 swapping since the DT_NULL tag is recognizable. */
2468 while (*(bfd_vma
*) edyn
[dynamic_size
++].d_tag
!= DT_NULL
)
2471 dynamic_segment
= (Elf_Internal_Dyn
*)
2472 malloc (dynamic_size
* sizeof (Elf_Internal_Dyn
));
2474 if (dynamic_segment
== NULL
)
2476 error (_("Out of memory\n"));
2481 for (i
= 0, entry
= dynamic_segment
;
2485 entry
->d_tag
= BYTE_GET8 (edyn
[i
].d_tag
);
2486 entry
->d_un
.d_val
= BYTE_GET8 (edyn
[i
].d_un
.d_val
);
2494 /* Parse and display the contents of the dynamic segment. */
2496 process_dynamic_segment (file
)
2499 Elf_Internal_Dyn
* entry
;
2502 if (dynamic_size
== 0)
2505 printf (_("\nThere is no dynamic segment in this file.\n"));
2512 if (! get_32bit_dynamic_segment (file
))
2515 else if (! get_64bit_dynamic_segment (file
))
2518 /* Find the appropriate symbol table. */
2519 if (dynamic_symbols
== NULL
)
2521 for (i
= 0, entry
= dynamic_segment
;
2525 unsigned long offset
;
2527 if (entry
->d_tag
!= DT_SYMTAB
)
2530 dynamic_info
[DT_SYMTAB
] = entry
->d_un
.d_val
;
2532 /* Since we do not know how big the symbol table is,
2533 we default to reading in the entire file (!) and
2534 processing that. This is overkill, I know, but it
2536 offset
= entry
->d_un
.d_val
- loadaddr
;
2538 if (fseek (file
, 0, SEEK_END
))
2539 error (_("Unable to seek to end of file!"));
2542 num_dynamic_syms
= (ftell (file
) - offset
) / sizeof (Elf32_External_Sym
);
2544 num_dynamic_syms
= (ftell (file
) - offset
) / sizeof (Elf64_External_Sym
);
2546 if (num_dynamic_syms
< 1)
2548 error (_("Unable to determine the number of symbols to load\n"));
2552 dynamic_symbols
= GET_ELF_SYMBOLS (file
, offset
, num_dynamic_syms
);
2556 /* Similarly find a string table. */
2557 if (dynamic_strings
== NULL
)
2559 for (i
= 0, entry
= dynamic_segment
;
2563 unsigned long offset
;
2566 if (entry
->d_tag
!= DT_STRTAB
)
2569 dynamic_info
[DT_STRTAB
] = entry
->d_un
.d_val
;
2571 /* Since we do not know how big the string table is,
2572 we default to reading in the entire file (!) and
2573 processing that. This is overkill, I know, but it
2576 offset
= entry
->d_un
.d_val
- loadaddr
;
2577 if (fseek (file
, 0, SEEK_END
))
2578 error (_("Unable to seek to end of file\n"));
2579 str_tab_len
= ftell (file
) - offset
;
2581 if (str_tab_len
< 1)
2584 (_("Unable to determine the length of the dynamic string table\n"));
2588 GET_DATA_ALLOC (offset
, str_tab_len
, dynamic_strings
, char *,
2589 "dynamic string table");
2595 /* And find the syminfo section if available. */
2596 if (dynamic_syminfo
== NULL
)
2598 unsigned int syminsz
= 0;
2600 for (i
= 0, entry
= dynamic_segment
;
2604 if (entry
->d_tag
== DT_SYMINENT
)
2606 /* Note: these braces are necessary to avoid a syntax
2607 error from the SunOS4 C compiler. */
2608 assert (sizeof (Elf_External_Syminfo
) == entry
->d_un
.d_val
);
2610 else if (entry
->d_tag
== DT_SYMINSZ
)
2611 syminsz
= entry
->d_un
.d_val
;
2612 else if (entry
->d_tag
== DT_SYMINFO
)
2613 dynamic_syminfo_offset
= entry
->d_un
.d_val
- loadaddr
;
2616 if (dynamic_syminfo_offset
!= 0 && syminsz
!= 0)
2618 Elf_External_Syminfo
* extsyminfo
;
2619 Elf_Internal_Syminfo
* syminfo
;
2621 /* There is a syminfo section. Read the data. */
2622 GET_DATA_ALLOC (dynamic_syminfo_offset
, syminsz
, extsyminfo
,
2623 Elf_External_Syminfo
*, "symbol information");
2625 dynamic_syminfo
= (Elf_Internal_Syminfo
*) malloc (syminsz
);
2626 if (dynamic_syminfo
== NULL
)
2628 error (_("Out of memory\n"));
2632 dynamic_syminfo_nent
= syminsz
/ sizeof (Elf_External_Syminfo
);
2633 for (i
= 0, syminfo
= dynamic_syminfo
; i
< dynamic_syminfo_nent
;
2636 syminfo
->si_boundto
= BYTE_GET (extsyminfo
[i
].si_boundto
);
2637 syminfo
->si_flags
= BYTE_GET (extsyminfo
[i
].si_flags
);
2644 if (do_dynamic
&& dynamic_addr
)
2645 printf (_("\nDynamic segment at offset 0x%x contains %ld entries:\n"),
2646 dynamic_addr
, (long) dynamic_size
);
2648 printf (_(" Tag Type Name/Value\n"));
2650 for (i
= 0, entry
= dynamic_segment
;
2655 printf (_(" 0x%-8.8lx (%s)%*s"),
2656 (unsigned long) entry
->d_tag
,
2657 get_dynamic_type (entry
->d_tag
),
2658 27 - strlen (get_dynamic_type (entry
->d_tag
)),
2661 switch (entry
->d_tag
)
2667 if (entry
->d_tag
== DT_AUXILIARY
)
2668 printf (_("Auxiliary library"));
2670 printf (_("Filter library"));
2672 if (dynamic_strings
)
2673 printf (": [%s]\n", dynamic_strings
+ entry
->d_un
.d_val
);
2675 printf (": %#lx\n", (long) entry
->d_un
.d_val
);
2682 printf (_("Flags:"));
2683 if (entry
->d_un
.d_val
== 0)
2684 printf (_(" None\n"));
2687 unsigned long int val
= entry
->d_un
.d_val
;
2688 if (val
& DTF_1_PARINIT
)
2690 printf (" PARINIT");
2691 val
^= DTF_1_PARINIT
;
2694 printf (" %lx", val
);
2703 printf (_("Flags:"));
2704 if (entry
->d_un
.d_val
== 0)
2705 printf (_(" None\n"));
2708 unsigned long int val
= entry
->d_un
.d_val
;
2709 if (val
& DF_P1_LAZYLOAD
)
2711 printf (" LAZYLOAD");
2712 val
^= DF_P1_LAZYLOAD
;
2714 if (val
& DF_P1_GROUPPERM
)
2716 printf (" GROUPPERM");
2717 val
^= DF_P1_GROUPPERM
;
2720 printf (" %lx", val
);
2729 printf (_("Flags:"));
2730 if (entry
->d_un
.d_val
== 0)
2731 printf (_(" None\n"));
2734 unsigned long int val
= entry
->d_un
.d_val
;
2740 if (val
& DF_1_GLOBAL
)
2745 if (val
& DF_1_GROUP
)
2750 if (val
& DF_1_NODELETE
)
2752 printf (" NODELETE");
2753 val
^= DF_1_NODELETE
;
2755 if (val
& DF_1_LOADFLTR
)
2757 printf (" LOADFLTR");
2758 val
^= DF_1_LOADFLTR
;
2760 if (val
& DF_1_INITFIRST
)
2762 printf (" INITFIRST");
2763 val
^= DF_1_INITFIRST
;
2765 if (val
& DF_1_NOOPEN
)
2770 if (val
& DF_1_ORIGIN
)
2775 if (val
& DF_1_DIRECT
)
2780 if (val
& DF_1_TRANS
)
2785 if (val
& DF_1_INTERPOSE
)
2787 printf (" INTERPOSE");
2788 val
^= DF_1_INTERPOSE
;
2791 printf (" %lx", val
);
2799 puts (get_dynamic_type (entry
->d_un
.d_val
));
2818 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
2824 if (dynamic_strings
== NULL
)
2827 name
= dynamic_strings
+ entry
->d_un
.d_val
;
2831 switch (entry
->d_tag
)
2834 printf (_("Shared library: [%s]"), name
);
2836 if (strcmp (name
, program_interpreter
))
2839 printf (_(" program interpreter\n"));
2843 printf (_("Library soname: [%s]\n"), name
);
2847 printf (_("Library rpath: [%s]\n"), name
);
2851 printf ("%#lx\n", (long) entry
->d_un
.d_val
);
2855 printf ("%#lx\n", (long) entry
->d_un
.d_val
);
2869 case DT_INIT_ARRAYSZ
:
2870 case DT_FINI_ARRAYSZ
:
2872 printf ("%lu (bytes)\n", (unsigned long) entry
->d_un
.d_val
);
2880 printf ("%lu\n", (unsigned long) entry
->d_un
.d_val
);
2891 if (dynamic_strings
!= NULL
&& entry
->d_tag
== DT_USED
)
2895 name
= dynamic_strings
+ entry
->d_un
.d_val
;
2899 printf (_("Not needed object: [%s]\n"), name
);
2904 printf ("%#lx\n", (long) entry
->d_un
.d_val
);
2909 /* The value of this entry is ignored. */
2913 if ((entry
->d_tag
>= DT_VERSYM
) && (entry
->d_tag
<= DT_VERNEEDNUM
))
2914 version_info
[DT_VERSIONTAGIDX (entry
->d_tag
)] =
2919 switch (elf_header
.e_machine
)
2922 case EM_MIPS_RS4_BE
:
2923 dynamic_segment_mips_val (entry
);
2926 printf ("%#lx\n", (long) entry
->d_un
.d_ptr
);
2937 get_ver_flags (flags
)
2940 static char buff
[32];
2947 if (flags
& VER_FLG_BASE
)
2948 strcat (buff
, "BASE ");
2950 if (flags
& VER_FLG_WEAK
)
2952 if (flags
& VER_FLG_BASE
)
2953 strcat (buff
, "| ");
2955 strcat (buff
, "WEAK ");
2958 if (flags
& ~(VER_FLG_BASE
| VER_FLG_WEAK
))
2959 strcat (buff
, "| <unknown>");
2964 /* Display the contents of the version sections. */
2966 process_version_sections (file
)
2969 Elf32_Internal_Shdr
* section
;
2976 for (i
= 0, section
= section_headers
;
2977 i
< elf_header
.e_shnum
;
2980 switch (section
->sh_type
)
2982 case SHT_GNU_verdef
:
2984 Elf_External_Verdef
* edefs
;
2991 (_("\nVersion definition section '%s' contains %ld entries:\n"),
2992 SECTION_NAME (section
), section
->sh_info
);
2994 printf (_(" Addr: 0x"));
2995 printf_vma (section
->sh_addr
);
2996 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
2997 (unsigned long) section
->sh_offset
, section
->sh_link
,
2998 SECTION_NAME (section_headers
+ section
->sh_link
));
3000 GET_DATA_ALLOC (section
->sh_offset
, section
->sh_size
,
3001 edefs
, Elf_External_Verdef
*,
3002 "version definition section");
3004 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++ cnt
)
3007 Elf_External_Verdef
* edef
;
3008 Elf_Internal_Verdef ent
;
3009 Elf_External_Verdaux
* eaux
;
3010 Elf_Internal_Verdaux aux
;
3014 vstart
= ((char *) edefs
) + idx
;
3016 edef
= (Elf_External_Verdef
*) vstart
;
3018 ent
.vd_version
= BYTE_GET (edef
->vd_version
);
3019 ent
.vd_flags
= BYTE_GET (edef
->vd_flags
);
3020 ent
.vd_ndx
= BYTE_GET (edef
->vd_ndx
);
3021 ent
.vd_cnt
= BYTE_GET (edef
->vd_cnt
);
3022 ent
.vd_hash
= BYTE_GET (edef
->vd_hash
);
3023 ent
.vd_aux
= BYTE_GET (edef
->vd_aux
);
3024 ent
.vd_next
= BYTE_GET (edef
->vd_next
);
3026 printf (_(" %#06x: Rev: %d Flags: %s"),
3027 idx
, ent
.vd_version
, get_ver_flags (ent
.vd_flags
));
3029 printf (_(" Index: %d Cnt: %d "),
3030 ent
.vd_ndx
, ent
.vd_cnt
);
3032 vstart
+= ent
.vd_aux
;
3034 eaux
= (Elf_External_Verdaux
*) vstart
;
3036 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
3037 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
3039 if (dynamic_strings
)
3040 printf (_("Name: %s\n"), dynamic_strings
+ aux
.vda_name
);
3042 printf (_("Name index: %ld\n"), aux
.vda_name
);
3044 isum
= idx
+ ent
.vd_aux
;
3046 for (j
= 1; j
< ent
.vd_cnt
; j
++)
3048 isum
+= aux
.vda_next
;
3049 vstart
+= aux
.vda_next
;
3051 eaux
= (Elf_External_Verdaux
*) vstart
;
3053 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
3054 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
3056 if (dynamic_strings
)
3057 printf (_(" %#06x: Parent %d: %s\n"),
3058 isum
, j
, dynamic_strings
+ aux
.vda_name
);
3060 printf (_(" %#06x: Parent %d, name index: %ld\n"),
3061 isum
, j
, aux
.vda_name
);
3071 case SHT_GNU_verneed
:
3073 Elf_External_Verneed
* eneed
;
3079 printf (_("\nVersion needs section '%s' contains %ld entries:\n"),
3080 SECTION_NAME (section
), section
->sh_info
);
3082 printf (_(" Addr: 0x"));
3083 printf_vma (section
->sh_addr
);
3084 printf (_(" Offset: %#08lx Link to section: %ld (%s)\n"),
3085 (unsigned long) section
->sh_offset
, section
->sh_link
,
3086 SECTION_NAME (section_headers
+ section
->sh_link
));
3088 GET_DATA_ALLOC (section
->sh_offset
, section
->sh_size
,
3089 eneed
, Elf_External_Verneed
*,
3090 "version need section");
3092 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
3094 Elf_External_Verneed
* entry
;
3095 Elf_Internal_Verneed ent
;
3100 vstart
= ((char *) eneed
) + idx
;
3102 entry
= (Elf_External_Verneed
*) vstart
;
3104 ent
.vn_version
= BYTE_GET (entry
->vn_version
);
3105 ent
.vn_cnt
= BYTE_GET (entry
->vn_cnt
);
3106 ent
.vn_file
= BYTE_GET (entry
->vn_file
);
3107 ent
.vn_aux
= BYTE_GET (entry
->vn_aux
);
3108 ent
.vn_next
= BYTE_GET (entry
->vn_next
);
3110 printf (_(" %#06x: Version: %d"), idx
, ent
.vn_version
);
3112 if (dynamic_strings
)
3113 printf (_(" File: %s"), dynamic_strings
+ ent
.vn_file
);
3115 printf (_(" File: %lx"), ent
.vn_file
);
3117 printf (_(" Cnt: %d\n"), ent
.vn_cnt
);
3119 vstart
+= ent
.vn_aux
;
3121 for (j
= 0, isum
= idx
+ ent
.vn_aux
; j
< ent
.vn_cnt
; ++j
)
3123 Elf_External_Vernaux
* eaux
;
3124 Elf_Internal_Vernaux aux
;
3126 eaux
= (Elf_External_Vernaux
*) vstart
;
3128 aux
.vna_hash
= BYTE_GET (eaux
->vna_hash
);
3129 aux
.vna_flags
= BYTE_GET (eaux
->vna_flags
);
3130 aux
.vna_other
= BYTE_GET (eaux
->vna_other
);
3131 aux
.vna_name
= BYTE_GET (eaux
->vna_name
);
3132 aux
.vna_next
= BYTE_GET (eaux
->vna_next
);
3134 if (dynamic_strings
)
3135 printf (_(" %#06x: Name: %s"),
3136 isum
, dynamic_strings
+ aux
.vna_name
);
3138 printf (_(" %#06x: Name index: %lx"),
3139 isum
, aux
.vna_name
);
3141 printf (_(" Flags: %s Version: %d\n"),
3142 get_ver_flags (aux
.vna_flags
), aux
.vna_other
);
3144 isum
+= aux
.vna_next
;
3145 vstart
+= aux
.vna_next
;
3155 case SHT_GNU_versym
:
3157 Elf32_Internal_Shdr
* link_section
;
3160 unsigned char * edata
;
3161 unsigned short * data
;
3163 Elf_Internal_Sym
* symbols
;
3164 Elf32_Internal_Shdr
* string_sec
;
3166 link_section
= section_headers
+ section
->sh_link
;
3167 total
= section
->sh_size
/ section
->sh_entsize
;
3171 symbols
= GET_ELF_SYMBOLS (file
, link_section
->sh_offset
,
3172 link_section
->sh_size
/ link_section
->sh_entsize
);
3174 string_sec
= section_headers
+ link_section
->sh_link
;
3176 GET_DATA_ALLOC (string_sec
->sh_offset
, string_sec
->sh_size
,
3177 strtab
, char *, "version string table");
3179 printf (_("\nVersion symbols section '%s' contains %d entries:\n"),
3180 SECTION_NAME (section
), total
);
3182 printf (_(" Addr: "));
3183 printf_vma (section
->sh_addr
);
3184 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
3185 (unsigned long) section
->sh_offset
, section
->sh_link
,
3186 SECTION_NAME (link_section
));
3188 GET_DATA_ALLOC (version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)]
3190 total
* sizeof (short), edata
,
3191 unsigned char *, "version symbol data");
3193 data
= (unsigned short *) malloc (total
* sizeof (short));
3195 for (cnt
= total
; cnt
--;)
3196 data
[cnt
] = byte_get (edata
+ cnt
* sizeof (short),
3201 for (cnt
= 0; cnt
< total
; cnt
+= 4)
3205 printf (" %03x:", cnt
);
3207 for (j
= 0; (j
< 4) && (cnt
+ j
) < total
; ++j
)
3208 switch (data
[cnt
+ j
])
3211 fputs (_(" 0 (*local*) "), stdout
);
3215 fputs (_(" 1 (*global*) "), stdout
);
3219 nn
= printf ("%4x%c", data
[cnt
+ j
] & 0x7fff,
3220 data
[cnt
+ j
] & 0x8000 ? 'h' : ' ');
3222 if (symbols
[cnt
+ j
].st_shndx
< SHN_LORESERVE
3223 && section_headers
[symbols
[cnt
+ j
].st_shndx
].sh_type
3226 /* We must test both. */
3227 Elf_Internal_Verneed ivn
;
3228 unsigned long offset
;
3230 offset
= version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)]
3235 Elf_External_Verneed evn
;
3236 Elf_External_Vernaux evna
;
3237 Elf_Internal_Vernaux ivna
;
3238 unsigned long vna_off
;
3240 GET_DATA (offset
, evn
, "version need");
3242 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
3243 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
3245 vna_off
= offset
+ ivn
.vn_aux
;
3249 GET_DATA (vna_off
, evna
,
3250 "version need aux (1)");
3252 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
3253 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
3255 vna_off
+= ivna
.vna_next
;
3257 while (ivna
.vna_other
!= data
[cnt
+ j
]
3258 && ivna
.vna_next
!= 0);
3260 if (ivna
.vna_other
== data
[cnt
+ j
])
3262 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
3264 nn
+= printf ("(%s%-*s",
3265 strtab
+ ivna
.vna_name
,
3271 else if (ivn
.vn_next
== 0)
3273 if (data
[cnt
+ j
] != 0x8001)
3275 Elf_Internal_Verdef ivd
;
3276 Elf_External_Verdef evd
;
3278 offset
= version_info
3279 [DT_VERSIONTAGIDX (DT_VERDEF
)]
3284 GET_DATA (offset
, evd
,
3285 "version definition");
3287 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
3288 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
3290 offset
+= ivd
.vd_next
;
3293 != (data
[cnt
+ j
] & 0x7fff)
3294 && ivd
.vd_next
!= 0);
3297 == (data
[cnt
+ j
] & 0x7fff))
3299 Elf_External_Verdaux evda
;
3300 Elf_Internal_Verdaux ivda
;
3302 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
3304 GET_DATA (offset
+ ivd
.vd_aux
, evda
,
3305 "version definition aux");
3308 BYTE_GET (evda
.vda_name
);
3312 strtab
+ ivda
.vda_name
,
3323 offset
+= ivn
.vn_next
;
3325 while (ivn
.vn_next
);
3327 else if (symbols
[cnt
+ j
].st_shndx
== SHN_UNDEF
)
3329 Elf_Internal_Verneed ivn
;
3330 unsigned long offset
;
3332 offset
= version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)]
3337 Elf_Internal_Vernaux ivna
;
3338 Elf_External_Verneed evn
;
3339 Elf_External_Vernaux evna
;
3340 unsigned long a_off
;
3342 GET_DATA (offset
, evn
, "version need");
3344 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
3345 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
3347 a_off
= offset
+ ivn
.vn_aux
;
3351 GET_DATA (a_off
, evna
,
3352 "version need aux (2)");
3354 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
3355 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
3357 a_off
+= ivna
.vna_next
;
3359 while (ivna
.vna_other
!= data
[cnt
+ j
]
3360 && ivna
.vna_next
!= 0);
3362 if (ivna
.vna_other
== data
[cnt
+ j
])
3364 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
3366 nn
+= printf ("(%s%-*s",
3367 strtab
+ ivna
.vna_name
,
3374 offset
+= ivn
.vn_next
;
3376 while (ivn
.vn_next
);
3378 else if (data
[cnt
+ j
] != 0x8001)
3380 Elf_Internal_Verdef ivd
;
3381 Elf_External_Verdef evd
;
3382 unsigned long offset
;
3384 offset
= version_info
3385 [DT_VERSIONTAGIDX (DT_VERDEF
)] - loadaddr
;
3389 GET_DATA (offset
, evd
, "version def");
3391 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
3392 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
3394 offset
+= ivd
.vd_next
;
3396 while (ivd
.vd_ndx
!= (data
[cnt
+ j
] & 0x7fff)
3397 && ivd
.vd_next
!= 0);
3399 if (ivd
.vd_ndx
== (data
[cnt
+ j
] & 0x7fff))
3401 Elf_External_Verdaux evda
;
3402 Elf_Internal_Verdaux ivda
;
3404 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
3406 GET_DATA (offset
- ivd
.vd_next
+ ivd
.vd_aux
,
3407 evda
, "version def aux");
3409 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
3411 nn
+= printf ("(%s%-*s",
3412 strtab
+ ivda
.vda_name
,
3420 printf ("%*c", 18 - nn
, ' ');
3438 printf (_("\nNo version information found in this file.\n"));
3444 get_symbol_binding (binding
)
3445 unsigned int binding
;
3447 static char buff
[32];
3451 case STB_LOCAL
: return _("LOCAL");
3452 case STB_GLOBAL
: return _("GLOBAL");
3453 case STB_WEAK
: return _("WEAK");
3455 if (binding
>= STB_LOPROC
&& binding
<= STB_HIPROC
)
3456 sprintf (buff
, _("<processor specific>: %d"), binding
);
3457 else if (binding
>= STB_LOOS
&& binding
<= STB_HIOS
)
3458 sprintf (buff
, _("<OS specific>: %d"), binding
);
3460 sprintf (buff
, _("<unknown>: %d"), binding
);
3466 get_symbol_type (type
)
3469 static char buff
[32];
3473 case STT_NOTYPE
: return _("NOTYPE");
3474 case STT_OBJECT
: return _("OBJECT");
3475 case STT_FUNC
: return _("FUNC");
3476 case STT_SECTION
: return _("SECTION");
3477 case STT_FILE
: return _("FILE");
3479 if (type
>= STT_LOPROC
&& type
<= STT_HIPROC
)
3481 if (elf_header
.e_machine
== EM_ARM
&& type
== STT_ARM_TFUNC
)
3482 return _("THUMB_FUNC");
3484 if (elf_header
.e_machine
== EM_SPARCV9
&& type
== STT_REGISTER
)
3485 return _("REGISTER");
3487 sprintf (buff
, _("<processor specific>: %d"), type
);
3489 else if (type
>= STT_LOOS
&& type
<= STT_HIOS
)
3490 sprintf (buff
, _("<OS specific>: %d"), type
);
3492 sprintf (buff
, _("<unknown>: %d"), type
);
3498 get_symbol_index_type (type
)
3503 case SHN_UNDEF
: return "UND";
3504 case SHN_ABS
: return "ABS";
3505 case SHN_COMMON
: return "COM";
3507 if (type
>= SHN_LOPROC
&& type
<= SHN_HIPROC
)
3509 else if (type
>= SHN_LORESERVE
&& type
<= SHN_HIRESERVE
)
3511 else if (type
>= SHN_LOOS
&& type
<= SHN_HIOS
)
3515 static char buff
[32];
3517 sprintf (buff
, "%3d", type
);
3525 get_dynamic_data (file
, number
)
3527 unsigned int number
;
3532 e_data
= (char *) malloc (number
* 4);
3536 error (_("Out of memory\n"));
3540 if (fread (e_data
, 4, number
, file
) != number
)
3542 error (_("Unable to read in dynamic data\n"));
3546 i_data
= (int *) malloc (number
* sizeof (* i_data
));
3550 error (_("Out of memory\n"));
3556 i_data
[number
] = byte_get (e_data
+ number
* 4, 4);
3563 /* Dump the symbol table */
3565 process_symbol_table (file
)
3568 Elf32_Internal_Shdr
* section
;
3573 int * buckets
= NULL
;
3574 int * chains
= NULL
;
3576 if (! do_syms
&& !do_histogram
)
3579 if (dynamic_info
[DT_HASH
] && ((do_using_dynamic
&& dynamic_strings
!= NULL
)
3582 if (fseek (file
, dynamic_info
[DT_HASH
] - loadaddr
, SEEK_SET
))
3584 error (_("Unable to seek to start of dynamic information"));
3588 if (fread (nb
, sizeof (nb
), 1, file
) != 1)
3590 error (_("Failed to read in number of buckets\n"));
3594 if (fread (nc
, sizeof (nc
), 1, file
) != 1)
3596 error (_("Failed to read in number of chains\n"));
3600 nbuckets
= byte_get (nb
, 4);
3601 nchains
= byte_get (nc
, 4);
3603 buckets
= get_dynamic_data (file
, nbuckets
);
3604 chains
= get_dynamic_data (file
, nchains
);
3606 if (buckets
== NULL
|| chains
== NULL
)
3611 && dynamic_info
[DT_HASH
] && do_using_dynamic
&& dynamic_strings
!= NULL
)
3616 printf (_("\nSymbol table for image:\n"));
3617 printf (_(" Num Buc: Value Size Type Bind Ot Ndx Name\n"));
3619 for (hn
= 0; hn
< nbuckets
; hn
++)
3624 for (si
= buckets
[hn
]; si
; si
= chains
[si
])
3626 Elf_Internal_Sym
* psym
;
3628 psym
= dynamic_symbols
+ si
;
3630 printf (" %3d %3d: %8lx %5ld %6s %6s %2d ",
3632 (unsigned long) psym
->st_value
,
3633 (unsigned long) psym
->st_size
,
3634 get_symbol_type (ELF_ST_TYPE (psym
->st_info
)),
3635 get_symbol_binding (ELF_ST_BIND (psym
->st_info
)),
3638 printf ("%3.3s", get_symbol_index_type (psym
->st_shndx
));
3640 printf (" %s\n", dynamic_strings
+ psym
->st_name
);
3644 else if (do_syms
&& !do_using_dynamic
)
3648 for (i
= 0, section
= section_headers
;
3649 i
< elf_header
.e_shnum
;
3654 Elf_Internal_Sym
* symtab
;
3655 Elf_Internal_Sym
* psym
;
3658 if ( section
->sh_type
!= SHT_SYMTAB
3659 && section
->sh_type
!= SHT_DYNSYM
)
3662 printf (_("\nSymbol table '%s' contains %lu entries:\n"),
3663 SECTION_NAME (section
),
3664 (unsigned long) (section
->sh_size
/ section
->sh_entsize
));
3665 fputs (_(" Num: Value Size Type Bind Ot Ndx Name\n"),
3668 symtab
= GET_ELF_SYMBOLS (file
, section
->sh_offset
,
3669 section
->sh_size
/ section
->sh_entsize
);
3673 if (section
->sh_link
== elf_header
.e_shstrndx
)
3674 strtab
= string_table
;
3677 Elf32_Internal_Shdr
* string_sec
;
3679 string_sec
= section_headers
+ section
->sh_link
;
3681 GET_DATA_ALLOC (string_sec
->sh_offset
, string_sec
->sh_size
,
3682 strtab
, char *, "string table");
3685 for (si
= 0, psym
= symtab
;
3686 si
< section
->sh_size
/ section
->sh_entsize
;
3689 printf (" %3d: %8lx %5ld %-7s %-6s %2d ",
3691 (unsigned long) psym
->st_value
,
3692 (unsigned long) psym
->st_size
,
3693 get_symbol_type (ELF_ST_TYPE (psym
->st_info
)),
3694 get_symbol_binding (ELF_ST_BIND (psym
->st_info
)),
3697 printf ("%4s", get_symbol_index_type (psym
->st_shndx
));
3699 printf (" %s", strtab
+ psym
->st_name
);
3701 if (section
->sh_type
== SHT_DYNSYM
&&
3702 version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)] != 0)
3704 unsigned char data
[2];
3705 unsigned short vers_data
;
3706 unsigned long offset
;
3710 offset
= version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)]
3713 GET_DATA (offset
+ si
* sizeof (vers_data
), data
,
3716 vers_data
= byte_get (data
, 2);
3718 is_nobits
= psym
->st_shndx
< SHN_LORESERVE
?
3719 (section_headers
[psym
->st_shndx
].sh_type
== SHT_NOBITS
)
3722 check_def
= (psym
->st_shndx
!= SHN_UNDEF
);
3724 if ((vers_data
& 0x8000) || vers_data
> 1)
3726 if (is_nobits
|| ! check_def
)
3728 Elf_External_Verneed evn
;
3729 Elf_Internal_Verneed ivn
;
3730 Elf_Internal_Vernaux ivna
;
3732 /* We must test both. */
3733 offset
= version_info
3734 [DT_VERSIONTAGIDX (DT_VERNEED
)] - loadaddr
;
3736 GET_DATA (offset
, evn
, "version need");
3738 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
3739 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
3743 unsigned long vna_off
;
3745 vna_off
= offset
+ ivn
.vn_aux
;
3749 Elf_External_Vernaux evna
;
3751 GET_DATA (vna_off
, evna
,
3752 "version need aux (3)");
3754 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
3755 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
3756 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
3758 vna_off
+= ivna
.vna_next
;
3760 while (ivna
.vna_other
!= vers_data
3761 && ivna
.vna_next
!= 0);
3763 if (ivna
.vna_other
== vers_data
)
3766 offset
+= ivn
.vn_next
;
3768 while (ivn
.vn_next
!= 0);
3770 if (ivna
.vna_other
== vers_data
)
3773 strtab
+ ivna
.vna_name
, ivna
.vna_other
);
3776 else if (! is_nobits
)
3777 error (_("bad dynamic symbol"));
3784 if (vers_data
!= 0x8001)
3786 Elf_Internal_Verdef ivd
;
3787 Elf_Internal_Verdaux ivda
;
3788 Elf_External_Verdaux evda
;
3789 unsigned long offset
;
3792 version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)]
3797 Elf_External_Verdef evd
;
3799 GET_DATA (offset
, evd
, "version def");
3801 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
3802 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
3803 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
3805 offset
+= ivd
.vd_next
;
3807 while (ivd
.vd_ndx
!= (vers_data
& 0x7fff)
3808 && ivd
.vd_next
!= 0);
3810 offset
-= ivd
.vd_next
;
3811 offset
+= ivd
.vd_aux
;
3813 GET_DATA (offset
, evda
, "version def aux");
3815 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
3817 if (psym
->st_name
!= ivda
.vda_name
)
3818 printf ((vers_data
& 0x8000)
3820 strtab
+ ivda
.vda_name
);
3830 if (strtab
!= string_table
)
3836 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
3838 if (do_histogram
&& buckets
!= NULL
)
3845 int nzero_counts
= 0;
3848 printf (_("\nHistogram for bucket list length (total of %d buckets):\n"),
3850 printf (_(" Length Number %% of total Coverage\n"));
3852 lengths
= (int *) calloc (nbuckets
, sizeof (int));
3853 if (lengths
== NULL
)
3855 error (_("Out of memory"));
3858 for (hn
= 0; hn
< nbuckets
; ++hn
)
3863 for (si
= buckets
[hn
]; si
; si
= chains
[si
])
3866 if (maxlength
< ++lengths
[hn
])
3871 counts
= (int *) calloc (maxlength
+ 1, sizeof (int));
3874 error (_("Out of memory"));
3878 for (hn
= 0; hn
< nbuckets
; ++hn
)
3879 ++ counts
[lengths
[hn
]];
3881 printf (" 0 %-10d (%5.1f%%)\n",
3882 counts
[0], (counts
[0] * 100.0) / nbuckets
);
3883 for (si
= 1; si
<= maxlength
; ++si
)
3885 nzero_counts
+= counts
[si
] * si
;
3886 printf ("%7d %-10d (%5.1f%%) %5.1f%%\n",
3887 si
, counts
[si
], (counts
[si
] * 100.0) / nbuckets
,
3888 (nzero_counts
* 100.0) / nsyms
);
3895 if (buckets
!= NULL
)
3905 process_syminfo (file
)
3906 FILE * file ATTRIBUTE_UNUSED
;
3910 if (dynamic_syminfo
== NULL
3912 /* No syminfo, this is ok. */
3915 /* There better should be a dynamic symbol section. */
3916 if (dynamic_symbols
== NULL
|| dynamic_strings
== NULL
)
3920 printf (_("\nDynamic info segment at offset 0x%lx contains %d entries:\n"),
3921 dynamic_syminfo_offset
, dynamic_syminfo_nent
);
3923 printf (_(" Num: Name BoundTo Flags\n"));
3924 for (i
= 0; i
< dynamic_syminfo_nent
; ++i
)
3926 unsigned short int flags
= dynamic_syminfo
[i
].si_flags
;
3928 printf ("%4d: %-30s ", i
,
3929 dynamic_strings
+ dynamic_symbols
[i
].st_name
);
3931 switch (dynamic_syminfo
[i
].si_boundto
)
3933 case SYMINFO_BT_SELF
:
3934 fputs ("SELF ", stdout
);
3936 case SYMINFO_BT_PARENT
:
3937 fputs ("PARENT ", stdout
);
3940 if (dynamic_syminfo
[i
].si_boundto
> 0
3941 && dynamic_syminfo
[i
].si_boundto
< dynamic_size
)
3944 + dynamic_segment
[dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
);
3946 printf ("%-10d ", dynamic_syminfo
[i
].si_boundto
);
3950 if (flags
& SYMINFO_FLG_DIRECT
)
3952 if (flags
& SYMINFO_FLG_PASSTHRU
)
3953 printf (" PASSTHRU");
3954 if (flags
& SYMINFO_FLG_COPY
)
3956 if (flags
& SYMINFO_FLG_LAZYLOAD
)
3957 printf (" LAZYLOAD");
3965 #ifdef SUPPORT_DISASSEMBLY
3967 disassemble_section (section
, file
)
3968 Elf32_Internal_Shdr
* section
;
3971 printf (_("\nAssembly dump of section %s\n"),
3972 SECTION_NAME (section
));
3974 /* XXX -- to be done --- XXX */
3981 dump_section (section
, file
)
3982 Elf32_Internal_Shdr
* section
;
3985 bfd_size_type bytes
;
3987 unsigned char * data
;
3988 unsigned char * start
;
3990 bytes
= section
->sh_size
;
3994 printf (_("\nSection '%s' has no data to dump.\n"),
3995 SECTION_NAME (section
));
3999 printf (_("\nHex dump of section '%s':\n"), SECTION_NAME (section
));
4001 addr
= section
->sh_addr
;
4003 GET_DATA_ALLOC (section
->sh_offset
, bytes
, start
, unsigned char *,
4014 lbytes
= (bytes
> 16 ? 16 : bytes
);
4016 printf (" 0x%8.8lx ", (unsigned long) addr
);
4018 switch (elf_header
.e_ident
[EI_DATA
])
4022 for (j
= 15; j
>= 0; j
--)
4025 printf ("%2.2x", data
[j
]);
4035 for (j
= 0; j
< 16; j
++)
4038 printf ("%2.2x", data
[j
]);
4048 for (j
= 0; j
< lbytes
; j
++)
4051 if (k
>= ' ' && k
< 0x80)
4070 static unsigned long int
4071 read_leb128 (data
, length_return
, sign
)
4072 unsigned char * data
;
4073 int * length_return
;
4076 unsigned long int result
= 0;
4077 unsigned int num_read
= 0;
4086 result
|= (byte
& 0x7f) << shift
;
4091 while (byte
& 0x80);
4093 if (length_return
!= NULL
)
4094 * length_return
= num_read
;
4096 if (sign
&& (shift
< 32) && (byte
& 0x40))
4097 result
|= -1 << shift
;
4102 typedef struct State_Machine_Registers
4104 unsigned long address
;
4107 unsigned int column
;
4111 /* This variable hold the number of the last entry seen
4112 in the File Table. */
4113 unsigned int last_file_entry
;
4116 static SMR state_machine_regs
;
4119 reset_state_machine (is_stmt
)
4122 state_machine_regs
.address
= 0;
4123 state_machine_regs
.file
= 1;
4124 state_machine_regs
.line
= 1;
4125 state_machine_regs
.column
= 0;
4126 state_machine_regs
.is_stmt
= is_stmt
;
4127 state_machine_regs
.basic_block
= 0;
4128 state_machine_regs
.end_sequence
= 0;
4129 state_machine_regs
.last_file_entry
= 0;
4132 /* Handled an extend line op. Returns true if this is the end
4135 process_extended_line_op (data
, is_stmt
)
4136 unsigned char * data
;
4139 unsigned char op_code
;
4142 unsigned char * name
;
4145 len
= read_leb128 (data
, & bytes_read
, 0);
4150 warn (_("badly formed extended line op encountered!"));
4155 op_code
= * data
++;
4157 printf (_(" Extended opcode %d: "), op_code
);
4161 case DW_LNE_end_sequence
:
4162 printf (_("End of Sequence\n\n"));
4163 reset_state_machine (is_stmt
);
4166 case DW_LNE_set_address
:
4167 /* XXX - assumption here that address size is 4! */
4168 adr
= byte_get (data
, 4);
4169 printf (_("set Address to 0x%lx\n"), adr
);
4170 state_machine_regs
.address
= adr
;
4173 case DW_LNE_define_file
:
4174 printf (_(" define new File Table entry\n"));
4175 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
4177 printf (_(" %d\t"), ++ state_machine_regs
.last_file_entry
);
4179 data
+= strlen (data
) + 1;
4180 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
4182 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
4184 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
4185 printf (_("%s\n\n"), name
);
4189 printf (_("UNKNOWN: length %d\n"), len
- bytes_read
);
4198 display_debug_lines (section
, start
, file
)
4199 Elf32_Internal_Shdr
* section
;
4200 unsigned char * start
;
4201 FILE * file ATTRIBUTE_UNUSED
;
4203 DWARF2_External_LineInfo
* external
;
4204 DWARF2_Internal_LineInfo info
;
4205 unsigned char * standard_opcodes
;
4206 unsigned char * data
= start
;
4207 unsigned char * end
= start
+ section
->sh_size
;
4208 unsigned char * end_of_sequence
;
4211 printf (_("\nDump of debug contents of section %s:\n\n"),
4212 SECTION_NAME (section
));
4216 external
= (DWARF2_External_LineInfo
*) data
;
4218 /* Check the length of the block. */
4219 info
.li_length
= BYTE_GET (external
->li_length
);
4220 if (info
.li_length
> section
->sh_size
)
4223 (_("The line info appears to be corrupt - the section is too small\n"));
4227 /* Check its version number. */
4228 info
.li_version
= BYTE_GET (external
->li_version
);
4229 if (info
.li_version
!= 2)
4231 warn (_("Only DWARF version 2 line info is currently supported.\n"));
4235 info
.li_prologue_length
= BYTE_GET (external
->li_prologue_length
);
4236 info
.li_min_insn_length
= BYTE_GET (external
->li_min_insn_length
);
4237 info
.li_default_is_stmt
= BYTE_GET (external
->li_default_is_stmt
);
4238 info
.li_line_base
= BYTE_GET (external
->li_line_base
);
4239 info
.li_line_range
= BYTE_GET (external
->li_line_range
);
4240 info
.li_opcode_base
= BYTE_GET (external
->li_opcode_base
);
4242 /* Sign extend the line base field. */
4243 info
.li_line_base
<<= 24;
4244 info
.li_line_base
>>= 24;
4246 printf (_(" Length: %ld\n"), info
.li_length
);
4247 printf (_(" DWARF Version: %d\n"), info
.li_version
);
4248 printf (_(" Prolgue Length: %d\n"), info
.li_prologue_length
);
4249 printf (_(" Minimum Instruction Length: %d\n"), info
.li_min_insn_length
);
4250 printf (_(" Initial value of 'is_stmt': %d\n"), info
.li_default_is_stmt
);
4251 printf (_(" Line Base: %d\n"), info
.li_line_base
);
4252 printf (_(" Line Range: %d\n"), info
.li_line_range
);
4253 printf (_(" Opcode Base: %d\n"), info
.li_opcode_base
);
4255 end_of_sequence
= data
+ info
.li_length
+ sizeof (info
.li_length
);
4257 reset_state_machine (info
.li_default_is_stmt
);
4259 /* Display the contents of the Opcodes table. */
4260 standard_opcodes
= data
+ sizeof (* external
);
4262 printf (_("\n Opcodes:\n"));
4264 for (i
= 1; i
< info
.li_opcode_base
; i
++)
4265 printf (_(" Opcode %d has %d args\n"), i
, standard_opcodes
[i
]);
4267 /* Display the contents of the Directory table. */
4268 data
= standard_opcodes
+ info
.li_opcode_base
- 1;
4271 printf (_("\n The Directory Table is empty.\n"));
4274 printf (_("\n The Directory Table:\n"));
4278 printf (_(" %s\n"), data
);
4280 data
+= strlen (data
) + 1;
4284 /* Skip the NUL at the end of the table. */
4287 /* Display the contents of the File Name table. */
4289 printf (_("\n The File Name Table is empty.\n"));
4292 printf (_("\n The File Name Table:\n"));
4293 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
4300 printf (_(" %d\t"), ++ state_machine_regs
.last_file_entry
);
4303 data
+= strlen (data
) + 1;
4305 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
4307 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
4309 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
4311 printf (_("%s\n"), name
);
4315 /* Skip the NUL at the end of the table. */
4318 /* Now display the statements. */
4319 printf (_("\n Line Number Statements:\n"));
4322 while (data
< end_of_sequence
)
4324 unsigned char op_code
;
4328 op_code
= * data
++;
4332 case DW_LNS_extended_op
:
4333 data
+= process_extended_line_op (data
, info
.li_default_is_stmt
);
4337 printf (_(" Copy\n"));
4340 case DW_LNS_advance_pc
:
4341 adv
= info
.li_min_insn_length
* read_leb128 (data
, & bytes_read
, 0);
4343 state_machine_regs
.address
+= adv
;
4344 printf (_(" Advance PC by %d to %lx\n"), adv
,
4345 state_machine_regs
.address
);
4348 case DW_LNS_advance_line
:
4349 adv
= read_leb128 (data
, & bytes_read
, 1);
4351 state_machine_regs
.line
+= adv
;
4352 printf (_(" Advance Line by %d to %d\n"), adv
,
4353 state_machine_regs
.line
);
4356 case DW_LNS_set_file
:
4357 adv
= read_leb128 (data
, & bytes_read
, 0);
4359 printf (_(" Set File Name to entry %d in the File Name Table\n"),
4361 state_machine_regs
.file
= adv
;
4364 case DW_LNS_set_column
:
4365 adv
= read_leb128 (data
, & bytes_read
, 0);
4367 printf (_(" Set column to %d\n"), adv
);
4368 state_machine_regs
.column
= adv
;
4371 case DW_LNS_negate_stmt
:
4372 adv
= state_machine_regs
.is_stmt
;
4374 printf (_(" Set is_stmt to %d\n"), adv
);
4375 state_machine_regs
.is_stmt
= adv
;
4378 case DW_LNS_set_basic_block
:
4379 printf (_(" Set basic block\n"));
4380 state_machine_regs
.basic_block
= 1;
4383 case DW_LNS_const_add_pc
:
4384 adv
= (255 - info
.li_opcode_base
) / info
.li_line_range
;
4385 state_machine_regs
.address
+= adv
;
4386 printf (_(" Advance PC by constant %d to 0x%lx\n"), adv
,
4387 state_machine_regs
.address
);
4390 case DW_LNS_fixed_advance_pc
:
4391 adv
= byte_get (data
, 2);
4393 state_machine_regs
.address
+= adv
;
4394 printf (_(" Advance PC by fixed size amount %d to 0x%lx\n"),
4395 adv
, state_machine_regs
.address
);
4399 op_code
-= info
.li_opcode_base
;
4400 adv
= (op_code
/ info
.li_line_range
) * info
.li_min_insn_length
;
4401 state_machine_regs
.address
+= adv
;
4402 printf (_(" Special opcode %d: advance Address by %d to 0x%lx"),
4403 op_code
, adv
, state_machine_regs
.address
);
4404 adv
= (op_code
% info
.li_line_range
) + info
.li_line_base
;
4405 state_machine_regs
.line
+= adv
;
4406 printf (_(" and Line by %d to %d\n"),
4407 adv
, state_machine_regs
.line
);
4418 display_debug_pubnames (section
, start
, file
)
4419 Elf32_Internal_Shdr
* section
;
4420 unsigned char * start
;
4421 FILE * file ATTRIBUTE_UNUSED
;
4423 DWARF2_External_PubNames
* external
;
4424 DWARF2_Internal_PubNames pubnames
;
4425 unsigned char * end
;
4427 end
= start
+ section
->sh_size
;
4429 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section
));
4433 unsigned char * data
;
4434 unsigned long offset
;
4436 external
= (DWARF2_External_PubNames
*) start
;
4438 pubnames
.pn_length
= BYTE_GET (external
->pn_length
);
4439 pubnames
.pn_version
= BYTE_GET (external
->pn_version
);
4440 pubnames
.pn_offset
= BYTE_GET (external
->pn_offset
);
4441 pubnames
.pn_size
= BYTE_GET (external
->pn_size
);
4443 data
= start
+ sizeof (* external
);
4444 start
+= pubnames
.pn_length
+ sizeof (external
->pn_length
);
4446 if (pubnames
.pn_version
!= 2)
4448 warn (_("Only DWARF 2 pubnames are currently supported"));
4452 printf (_(" Length: %ld\n"),
4453 pubnames
.pn_length
);
4454 printf (_(" Version: %d\n"),
4455 pubnames
.pn_version
);
4456 printf (_(" Offset into .debug_info section: %ld\n"),
4457 pubnames
.pn_offset
);
4458 printf (_(" Size of area in .debug_info section: %ld\n"),
4461 printf (_("\n Offset\tName\n"));
4465 offset
= byte_get (data
, 4);
4470 printf (" %ld\t\t%s\n", offset
, data
);
4471 data
+= strlen (data
) + 1;
4474 while (offset
!= 0);
4487 case DW_TAG_padding
: return "DW_TAG_padding";
4488 case DW_TAG_array_type
: return "DW_TAG_array_type";
4489 case DW_TAG_class_type
: return "DW_TAG_class_type";
4490 case DW_TAG_entry_point
: return "DW_TAG_entry_point";
4491 case DW_TAG_enumeration_type
: return "DW_TAG_enumeration_type";
4492 case DW_TAG_formal_parameter
: return "DW_TAG_formal_parameter";
4493 case DW_TAG_imported_declaration
: return "DW_TAG_imported_declaration";
4494 case DW_TAG_label
: return "DW_TAG_label";
4495 case DW_TAG_lexical_block
: return "DW_TAG_lexical_block";
4496 case DW_TAG_member
: return "DW_TAG_member";
4497 case DW_TAG_pointer_type
: return "DW_TAG_pointer_type";
4498 case DW_TAG_reference_type
: return "DW_TAG_reference_type";
4499 case DW_TAG_compile_unit
: return "DW_TAG_compile_unit";
4500 case DW_TAG_string_type
: return "DW_TAG_string_type";
4501 case DW_TAG_structure_type
: return "DW_TAG_structure_type";
4502 case DW_TAG_subroutine_type
: return "DW_TAG_subroutine_type";
4503 case DW_TAG_typedef
: return "DW_TAG_typedef";
4504 case DW_TAG_union_type
: return "DW_TAG_union_type";
4505 case DW_TAG_unspecified_parameters
: return "DW_TAG_unspecified_parameters";
4506 case DW_TAG_variant
: return "DW_TAG_variant";
4507 case DW_TAG_common_block
: return "DW_TAG_common_block";
4508 case DW_TAG_common_inclusion
: return "DW_TAG_common_inclusion";
4509 case DW_TAG_inheritance
: return "DW_TAG_inheritance";
4510 case DW_TAG_inlined_subroutine
: return "DW_TAG_inlined_subroutine";
4511 case DW_TAG_module
: return "DW_TAG_module";
4512 case DW_TAG_ptr_to_member_type
: return "DW_TAG_ptr_to_member_type";
4513 case DW_TAG_set_type
: return "DW_TAG_set_type";
4514 case DW_TAG_subrange_type
: return "DW_TAG_subrange_type";
4515 case DW_TAG_with_stmt
: return "DW_TAG_with_stmt";
4516 case DW_TAG_access_declaration
: return "DW_TAG_access_declaration";
4517 case DW_TAG_base_type
: return "DW_TAG_base_type";
4518 case DW_TAG_catch_block
: return "DW_TAG_catch_block";
4519 case DW_TAG_const_type
: return "DW_TAG_const_type";
4520 case DW_TAG_constant
: return "DW_TAG_constant";
4521 case DW_TAG_enumerator
: return "DW_TAG_enumerator";
4522 case DW_TAG_file_type
: return "DW_TAG_file_type";
4523 case DW_TAG_friend
: return "DW_TAG_friend";
4524 case DW_TAG_namelist
: return "DW_TAG_namelist";
4525 case DW_TAG_namelist_item
: return "DW_TAG_namelist_item";
4526 case DW_TAG_packed_type
: return "DW_TAG_packed_type";
4527 case DW_TAG_subprogram
: return "DW_TAG_subprogram";
4528 case DW_TAG_template_type_param
: return "DW_TAG_template_type_param";
4529 case DW_TAG_template_value_param
: return "DW_TAG_template_value_param";
4530 case DW_TAG_thrown_type
: return "DW_TAG_thrown_type";
4531 case DW_TAG_try_block
: return "DW_TAG_try_block";
4532 case DW_TAG_variant_part
: return "DW_TAG_variant_part";
4533 case DW_TAG_variable
: return "DW_TAG_variable";
4534 case DW_TAG_volatile_type
: return "DW_TAG_volatile_type";
4535 case DW_TAG_MIPS_loop
: return "DW_TAG_MIPS_loop";
4536 case DW_TAG_format_label
: return "DW_TAG_format_label";
4537 case DW_TAG_function_template
: return "DW_TAG_function_template";
4538 case DW_TAG_class_template
: return "DW_TAG_class_template";
4541 static char buffer
[100];
4543 sprintf (buffer
, _("Unknown TAG value: %lx"), tag
);
4550 get_AT_name (attribute
)
4551 unsigned long attribute
;
4555 case DW_AT_sibling
: return "DW_AT_sibling";
4556 case DW_AT_location
: return "DW_AT_location";
4557 case DW_AT_name
: return "DW_AT_name";
4558 case DW_AT_ordering
: return "DW_AT_ordering";
4559 case DW_AT_subscr_data
: return "DW_AT_subscr_data";
4560 case DW_AT_byte_size
: return "DW_AT_byte_size";
4561 case DW_AT_bit_offset
: return "DW_AT_bit_offset";
4562 case DW_AT_bit_size
: return "DW_AT_bit_size";
4563 case DW_AT_element_list
: return "DW_AT_element_list";
4564 case DW_AT_stmt_list
: return "DW_AT_stmt_list";
4565 case DW_AT_low_pc
: return "DW_AT_low_pc";
4566 case DW_AT_high_pc
: return "DW_AT_high_pc";
4567 case DW_AT_language
: return "DW_AT_language";
4568 case DW_AT_member
: return "DW_AT_member";
4569 case DW_AT_discr
: return "DW_AT_discr";
4570 case DW_AT_discr_value
: return "DW_AT_discr_value";
4571 case DW_AT_visibility
: return "DW_AT_visibility";
4572 case DW_AT_import
: return "DW_AT_import";
4573 case DW_AT_string_length
: return "DW_AT_string_length";
4574 case DW_AT_common_reference
: return "DW_AT_common_reference";
4575 case DW_AT_comp_dir
: return "DW_AT_comp_dir";
4576 case DW_AT_const_value
: return "DW_AT_const_value";
4577 case DW_AT_containing_type
: return "DW_AT_containing_type";
4578 case DW_AT_default_value
: return "DW_AT_default_value";
4579 case DW_AT_inline
: return "DW_AT_inline";
4580 case DW_AT_is_optional
: return "DW_AT_is_optional";
4581 case DW_AT_lower_bound
: return "DW_AT_lower_bound";
4582 case DW_AT_producer
: return "DW_AT_producer";
4583 case DW_AT_prototyped
: return "DW_AT_prototyped";
4584 case DW_AT_return_addr
: return "DW_AT_return_addr";
4585 case DW_AT_start_scope
: return "DW_AT_start_scope";
4586 case DW_AT_stride_size
: return "DW_AT_stride_size";
4587 case DW_AT_upper_bound
: return "DW_AT_upper_bound";
4588 case DW_AT_abstract_origin
: return "DW_AT_abstract_origin";
4589 case DW_AT_accessibility
: return "DW_AT_accessibility";
4590 case DW_AT_address_class
: return "DW_AT_address_class";
4591 case DW_AT_artificial
: return "DW_AT_artificial";
4592 case DW_AT_base_types
: return "DW_AT_base_types";
4593 case DW_AT_calling_convention
: return "DW_AT_calling_convention";
4594 case DW_AT_count
: return "DW_AT_count";
4595 case DW_AT_data_member_location
: return "DW_AT_data_member_location";
4596 case DW_AT_decl_column
: return "DW_AT_decl_column";
4597 case DW_AT_decl_file
: return "DW_AT_decl_file";
4598 case DW_AT_decl_line
: return "DW_AT_decl_line";
4599 case DW_AT_declaration
: return "DW_AT_declaration";
4600 case DW_AT_discr_list
: return "DW_AT_discr_list";
4601 case DW_AT_encoding
: return "DW_AT_encoding";
4602 case DW_AT_external
: return "DW_AT_external";
4603 case DW_AT_frame_base
: return "DW_AT_frame_base";
4604 case DW_AT_friend
: return "DW_AT_friend";
4605 case DW_AT_identifier_case
: return "DW_AT_identifier_case";
4606 case DW_AT_macro_info
: return "DW_AT_macro_info";
4607 case DW_AT_namelist_items
: return "DW_AT_namelist_items";
4608 case DW_AT_priority
: return "DW_AT_priority";
4609 case DW_AT_segment
: return "DW_AT_segment";
4610 case DW_AT_specification
: return "DW_AT_specification";
4611 case DW_AT_static_link
: return "DW_AT_static_link";
4612 case DW_AT_type
: return "DW_AT_type";
4613 case DW_AT_use_location
: return "DW_AT_use_location";
4614 case DW_AT_variable_parameter
: return "DW_AT_variable_parameter";
4615 case DW_AT_virtuality
: return "DW_AT_virtuality";
4616 case DW_AT_vtable_elem_location
: return "DW_AT_vtable_elem_location";
4617 case DW_AT_MIPS_fde
: return "DW_AT_MIPS_fde";
4618 case DW_AT_MIPS_loop_begin
: return "DW_AT_MIPS_loop_begin";
4619 case DW_AT_MIPS_tail_loop_begin
: return "DW_AT_MIPS_tail_loop_begin";
4620 case DW_AT_MIPS_epilog_begin
: return "DW_AT_MIPS_epilog_begin";
4621 case DW_AT_MIPS_loop_unroll_factor
: return "DW_AT_MIPS_loop_unroll_factor";
4622 case DW_AT_MIPS_software_pipeline_depth
: return "DW_AT_MIPS_software_pipeline_depth";
4623 case DW_AT_MIPS_linkage_name
: return "DW_AT_MIPS_linkage_name";
4624 case DW_AT_MIPS_stride
: return "DW_AT_MIPS_stride";
4625 case DW_AT_MIPS_abstract_name
: return "DW_AT_MIPS_abstract_name";
4626 case DW_AT_MIPS_clone_origin
: return "DW_AT_MIPS_clone_origin";
4627 case DW_AT_MIPS_has_inlines
: return "DW_AT_MIPS_has_inlines";
4628 case DW_AT_sf_names
: return "DW_AT_sf_names";
4629 case DW_AT_src_info
: return "DW_AT_src_info";
4630 case DW_AT_mac_info
: return "DW_AT_mac_info";
4631 case DW_AT_src_coords
: return "DW_AT_src_coords";
4632 case DW_AT_body_begin
: return "DW_AT_body_begin";
4633 case DW_AT_body_end
: return "DW_AT_body_end";
4636 static char buffer
[100];
4638 sprintf (buffer
, _("Unknown AT value: %lx"), attribute
);
4645 get_FORM_name (form
)
4650 case DW_FORM_addr
: return "DW_FORM_addr";
4651 case DW_FORM_block2
: return "DW_FORM_block2";
4652 case DW_FORM_block4
: return "DW_FORM_block4";
4653 case DW_FORM_data2
: return "DW_FORM_data2";
4654 case DW_FORM_data4
: return "DW_FORM_data4";
4655 case DW_FORM_data8
: return "DW_FORM_data8";
4656 case DW_FORM_string
: return "DW_FORM_string";
4657 case DW_FORM_block
: return "DW_FORM_block";
4658 case DW_FORM_block1
: return "DW_FORM_block1";
4659 case DW_FORM_data1
: return "DW_FORM_data1";
4660 case DW_FORM_flag
: return "DW_FORM_flag";
4661 case DW_FORM_sdata
: return "DW_FORM_sdata";
4662 case DW_FORM_strp
: return "DW_FORM_strp";
4663 case DW_FORM_udata
: return "DW_FORM_udata";
4664 case DW_FORM_ref_addr
: return "DW_FORM_ref_addr";
4665 case DW_FORM_ref1
: return "DW_FORM_ref1";
4666 case DW_FORM_ref2
: return "DW_FORM_ref2";
4667 case DW_FORM_ref4
: return "DW_FORM_ref4";
4668 case DW_FORM_ref8
: return "DW_FORM_ref8";
4669 case DW_FORM_ref_udata
: return "DW_FORM_ref_udata";
4670 case DW_FORM_indirect
: return "DW_FORM_indirect";
4673 static char buffer
[100];
4675 sprintf (buffer
, _("Unknown FORM value: %lx"), form
);
4681 /* FIXME: There are better and more effiecint ways to handle
4682 these structures. For now though, I just want something that
4683 is simple to implement. */
4684 typedef struct abbrev_attr
4686 unsigned long attribute
;
4688 struct abbrev_attr
* next
;
4692 typedef struct abbrev_entry
4694 unsigned long entry
;
4697 struct abbrev_attr
* first_attr
;
4698 struct abbrev_attr
* last_attr
;
4699 struct abbrev_entry
* next
;
4703 static abbrev_entry
* first_abbrev
= NULL
;
4704 static abbrev_entry
* last_abbrev
= NULL
;
4707 free_abbrevs
PARAMS ((void))
4709 abbrev_entry
* abbrev
;
4711 for (abbrev
= first_abbrev
; abbrev
;)
4713 abbrev_entry
* next
= abbrev
->next
;
4716 for (attr
= abbrev
->first_attr
; attr
;)
4718 abbrev_attr
* next
= attr
->next
;
4728 last_abbrev
= first_abbrev
= NULL
;
4732 add_abbrev (number
, tag
, children
)
4733 unsigned long number
;
4737 abbrev_entry
* entry
;
4739 entry
= (abbrev_entry
*) malloc (sizeof (* entry
));
4745 entry
->entry
= number
;
4747 entry
->children
= children
;
4748 entry
->first_attr
= NULL
;
4749 entry
->last_attr
= NULL
;
4752 if (first_abbrev
== NULL
)
4753 first_abbrev
= entry
;
4755 last_abbrev
->next
= entry
;
4757 last_abbrev
= entry
;
4761 add_abbrev_attr (attribute
, form
)
4762 unsigned long attribute
;
4767 attr
= (abbrev_attr
*) malloc (sizeof (* attr
));
4773 attr
->attribute
= attribute
;
4777 if (last_abbrev
->first_attr
== NULL
)
4778 last_abbrev
->first_attr
= attr
;
4780 last_abbrev
->last_attr
->next
= attr
;
4782 last_abbrev
->last_attr
= attr
;
4785 /* Processes the (partial) contents of a .debug_abbrev section.
4786 Returns NULL if the end of the section was encountered.
4787 Returns the address after the last byte read if the end of
4788 an abbreviation set was found. */
4790 static unsigned char *
4791 process_abbrev_section (start
, end
)
4792 unsigned char * start
;
4793 unsigned char * end
;
4795 if (first_abbrev
!= NULL
)
4801 unsigned long entry
;
4803 unsigned long attribute
;
4806 entry
= read_leb128 (start
, & bytes_read
, 0);
4807 start
+= bytes_read
;
4809 /* A single zero is supposed to end the section according
4810 to the standard. If there's more, then signal that to
4813 return start
== end
? NULL
: start
;
4815 tag
= read_leb128 (start
, & bytes_read
, 0);
4816 start
+= bytes_read
;
4818 children
= * start
++;
4820 add_abbrev (entry
, tag
, children
);
4826 attribute
= read_leb128 (start
, & bytes_read
, 0);
4827 start
+= bytes_read
;
4829 form
= read_leb128 (start
, & bytes_read
, 0);
4830 start
+= bytes_read
;
4833 add_abbrev_attr (attribute
, form
);
4835 while (attribute
!= 0);
4843 display_debug_abbrev (section
, start
, file
)
4844 Elf32_Internal_Shdr
* section
;
4845 unsigned char * start
;
4846 FILE * file ATTRIBUTE_UNUSED
;
4848 abbrev_entry
* entry
;
4849 unsigned char * end
= start
+ section
->sh_size
;
4851 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section
));
4855 start
= process_abbrev_section (start
, end
);
4857 printf (_(" Number TAG\n"));
4859 for (entry
= first_abbrev
; entry
; entry
= entry
->next
)
4863 printf (_(" %ld %s [%s]\n"),
4865 get_TAG_name (entry
->tag
),
4866 entry
->children
? _("has children") : _("no children"));
4868 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
4870 printf (_(" %-18s %s\n"),
4871 get_AT_name (attr
->attribute
),
4872 get_FORM_name (attr
->form
));
4884 static unsigned char *
4885 display_block (data
, length
)
4886 unsigned char * data
;
4887 unsigned long length
;
4889 printf (_(" %lu byte block: "), length
);
4892 printf ("%lx ", (unsigned long) byte_get (data
++, 1));
4898 decode_location_expression (data
, pointer_size
)
4899 unsigned char * data
;
4900 unsigned int pointer_size
;
4904 unsigned long uvalue
;
4911 printf ("DW_OP_addr: %lx", (unsigned long) byte_get (data
, pointer_size
));
4914 printf ("DW_OP_deref");
4917 printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data
, 1));
4920 printf ("DW_OP_const1s: %ld", (long) byte_get (data
, 1));
4923 printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data
, 2));
4926 printf ("DW_OP_const2s: %ld", (long) byte_get (data
, 2));
4929 printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data
, 4));
4932 printf ("DW_OP_const4s: %ld", (long) byte_get (data
, 4));
4935 printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data
, 4),
4936 (unsigned long) byte_get (data
+ 4, 4));
4939 printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data
, 4),
4940 (long) byte_get (data
+ 4, 4));
4943 printf ("DW_OP_constu: %lu", read_leb128 (data
, NULL
, 0));
4946 printf ("DW_OP_consts: %ld", read_leb128 (data
, NULL
, 1));
4949 printf ("DW_OP_dup");
4952 printf ("DW_OP_drop");
4955 printf ("DW_OP_over");
4958 printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data
, 1));
4961 printf ("DW_OP_swap");
4964 printf ("DW_OP_rot");
4967 printf ("DW_OP_xderef");
4970 printf ("DW_OP_abs");
4973 printf ("DW_OP_and");
4976 printf ("DW_OP_div");
4979 printf ("DW_OP_minus");
4982 printf ("DW_OP_mod");
4985 printf ("DW_OP_mul");
4988 printf ("DW_OP_neg");
4991 printf ("DW_OP_not");
4994 printf ("DW_OP_or");
4997 printf ("DW_OP_plus");
4999 case DW_OP_plus_uconst
:
5000 printf ("DW_OP_plus_uconst: %lu", read_leb128 (data
, NULL
, 0));
5003 printf ("DW_OP_shl");
5006 printf ("DW_OP_shr");
5009 printf ("DW_OP_shra");
5012 printf ("DW_OP_xor");
5015 printf ("DW_OP_bra: %ld", (long) byte_get (data
, 2));
5018 printf ("DW_OP_eq");
5021 printf ("DW_OP_ge");
5024 printf ("DW_OP_gt");
5027 printf ("DW_OP_le");
5030 printf ("DW_OP_lt");
5033 printf ("DW_OP_ne");
5036 printf ("DW_OP_skip: %ld", (long) byte_get (data
, 2));
5039 printf ("DW_OP_lit0");
5042 printf ("DW_OP_lit1");
5045 printf ("DW_OP_lit2");
5048 printf ("DW_OP_lit3");
5051 printf ("DW_OP_lit4");
5054 printf ("DW_OP_lit5");
5057 printf ("DW_OP_lit6");
5060 printf ("DW_OP_lit7");
5063 printf ("DW_OP_lit8");
5066 printf ("DW_OP_lit9");
5069 printf ("DW_OP_lit10");
5072 printf ("DW_OP_lit11");
5075 printf ("DW_OP_lit12");
5078 printf ("DW_OP_lit13");
5081 printf ("DW_OP_lit14");
5084 printf ("DW_OP_lit15");
5087 printf ("DW_OP_lit16");
5090 printf ("DW_OP_lit17");
5093 printf ("DW_OP_lit18");
5096 printf ("DW_OP_lit19");
5099 printf ("DW_OP_lit20");
5102 printf ("DW_OP_lit21");
5105 printf ("DW_OP_lit22");
5108 printf ("DW_OP_lit23");
5111 printf ("DW_OP_lit24");
5114 printf ("DW_OP_lit25");
5117 printf ("DW_OP_lit26");
5120 printf ("DW_OP_lit27");
5123 printf ("DW_OP_lit28");
5126 printf ("DW_OP_lit29");
5129 printf ("DW_OP_lit30");
5132 printf ("DW_OP_lit31");
5135 printf ("DW_OP_reg0");
5138 printf ("DW_OP_reg1");
5141 printf ("DW_OP_reg2");
5144 printf ("DW_OP_reg3");
5147 printf ("DW_OP_reg4");
5150 printf ("DW_OP_reg5");
5153 printf ("DW_OP_reg6");
5156 printf ("DW_OP_reg7");
5159 printf ("DW_OP_reg8");
5162 printf ("DW_OP_reg9");
5165 printf ("DW_OP_reg10");
5168 printf ("DW_OP_reg11");
5171 printf ("DW_OP_reg12");
5174 printf ("DW_OP_reg13");
5177 printf ("DW_OP_reg14");
5180 printf ("DW_OP_reg15");
5183 printf ("DW_OP_reg16");
5186 printf ("DW_OP_reg17");
5189 printf ("DW_OP_reg18");
5192 printf ("DW_OP_reg19");
5195 printf ("DW_OP_reg20");
5198 printf ("DW_OP_reg21");
5201 printf ("DW_OP_reg22");
5204 printf ("DW_OP_reg23");
5207 printf ("DW_OP_reg24");
5210 printf ("DW_OP_reg25");
5213 printf ("DW_OP_reg26");
5216 printf ("DW_OP_reg27");
5219 printf ("DW_OP_reg28");
5222 printf ("DW_OP_reg29");
5225 printf ("DW_OP_reg30");
5228 printf ("DW_OP_reg31");
5231 printf ("DW_OP_breg0: %ld", read_leb128 (data
, NULL
, 1));
5234 printf ("DW_OP_breg1: %ld", read_leb128 (data
, NULL
, 1));
5237 printf ("DW_OP_breg2: %ld", read_leb128 (data
, NULL
, 1));
5240 printf ("DW_OP_breg3: %ld", read_leb128 (data
, NULL
, 1));
5243 printf ("DW_OP_breg4: %ld", read_leb128 (data
, NULL
, 1));
5246 printf ("DW_OP_breg5: %ld", read_leb128 (data
, NULL
, 1));
5249 printf ("DW_OP_breg6: %ld", read_leb128 (data
, NULL
, 1));
5252 printf ("DW_OP_breg7: %ld", read_leb128 (data
, NULL
, 1));
5255 printf ("DW_OP_breg8: %ld", read_leb128 (data
, NULL
, 1));
5258 printf ("DW_OP_breg9: %ld", read_leb128 (data
, NULL
, 1));
5261 printf ("DW_OP_breg10: %ld", read_leb128 (data
, NULL
, 1));
5264 printf ("DW_OP_breg11: %ld", read_leb128 (data
, NULL
, 1));
5267 printf ("DW_OP_breg12: %ld", read_leb128 (data
, NULL
, 1));
5270 printf ("DW_OP_breg13: %ld", read_leb128 (data
, NULL
, 1));
5273 printf ("DW_OP_breg14: %ld", read_leb128 (data
, NULL
, 1));
5276 printf ("DW_OP_breg15: %ld", read_leb128 (data
, NULL
, 1));
5279 printf ("DW_OP_breg16: %ld", read_leb128 (data
, NULL
, 1));
5282 printf ("DW_OP_breg17: %ld", read_leb128 (data
, NULL
, 1));
5285 printf ("DW_OP_breg18: %ld", read_leb128 (data
, NULL
, 1));
5288 printf ("DW_OP_breg19: %ld", read_leb128 (data
, NULL
, 1));
5291 printf ("DW_OP_breg20: %ld", read_leb128 (data
, NULL
, 1));
5294 printf ("DW_OP_breg21: %ld", read_leb128 (data
, NULL
, 1));
5297 printf ("DW_OP_breg22: %ld", read_leb128 (data
, NULL
, 1));
5300 printf ("DW_OP_breg23: %ld", read_leb128 (data
, NULL
, 1));
5303 printf ("DW_OP_breg24: %ld", read_leb128 (data
, NULL
, 1));
5306 printf ("DW_OP_breg25: %ld", read_leb128 (data
, NULL
, 1));
5309 printf ("DW_OP_breg26: %ld", read_leb128 (data
, NULL
, 1));
5312 printf ("DW_OP_breg27: %ld", read_leb128 (data
, NULL
, 1));
5315 printf ("DW_OP_breg28: %ld", read_leb128 (data
, NULL
, 1));
5318 printf ("DW_OP_breg29: %ld", read_leb128 (data
, NULL
, 1));
5321 printf ("DW_OP_breg30: %ld", read_leb128 (data
, NULL
, 1));
5324 printf ("DW_OP_breg31: %ld", read_leb128 (data
, NULL
, 1));
5327 printf ("DW_OP_regx: %lu", read_leb128 (data
, NULL
, 0));
5330 printf ("DW_OP_fbreg: %ld", read_leb128 (data
, NULL
, 1));
5333 uvalue
= read_leb128 (data
, &bytes_read
, 0);
5334 printf ("DW_OP_bregx: %lu %ld", uvalue
,
5335 read_leb128 (data
+ bytes_read
, NULL
, 1));
5338 printf ("DW_OP_piece: %lu", read_leb128 (data
, NULL
, 0));
5340 case DW_OP_deref_size
:
5341 printf ("DW_OP_deref_size: %ld", (long) byte_get (data
, 1));
5343 case DW_OP_xderef_size
:
5344 printf ("DW_OP_xderef_size: %ld", (long) byte_get (data
, 1));
5347 printf ("DW_OP_nop");
5351 if (op
>= DW_OP_lo_user
5352 && op
<= DW_OP_hi_user
)
5353 printf (_("(User defined location op)"));
5355 printf (_("(Unknown location op)"));
5361 static unsigned char *
5362 read_and_display_attr (attribute
, form
, data
, pointer_size
)
5363 unsigned long attribute
;
5365 unsigned char * data
;
5366 unsigned long pointer_size
;
5368 unsigned long uvalue
= 0;
5369 unsigned char * block_start
= NULL
;
5373 printf (" %-18s:", get_AT_name (attribute
));
5377 case DW_FORM_ref_addr
:
5382 case DW_FORM_ref_udata
:
5388 case DW_FORM_ref_addr
:
5390 uvalue
= byte_get (data
, pointer_size
);
5391 printf (is_ref
? " <%x>" : " %#x", uvalue
);
5392 data
+= pointer_size
;
5398 uvalue
= byte_get (data
++, 1);
5399 printf (is_ref
? " <%x>" : " %d", uvalue
);
5404 uvalue
= byte_get (data
, 2);
5406 printf (is_ref
? " <%x>" : " %d", uvalue
);
5411 uvalue
= byte_get (data
, 4);
5413 printf (is_ref
? " <%x>" : " %d", uvalue
);
5418 uvalue
= byte_get (data
, 4);
5419 printf (" %lx", uvalue
);
5420 printf (" %lx", (unsigned long) byte_get (data
+ 4, 4));
5424 case DW_FORM_string
:
5425 printf (" %s", data
);
5426 data
+= strlen (data
) + 1;
5430 uvalue
= read_leb128 (data
, & bytes_read
, 1);
5432 printf (" %ld", (long) uvalue
);
5435 case DW_FORM_ref_udata
:
5437 uvalue
= read_leb128 (data
, & bytes_read
, 0);
5439 printf (is_ref
? " <%lx>" : " %ld", uvalue
);
5443 uvalue
= read_leb128 (data
, & bytes_read
, 0);
5444 block_start
= data
+ bytes_read
;
5445 data
= display_block (block_start
, uvalue
);
5446 uvalue
= * block_start
;
5449 case DW_FORM_block1
:
5450 uvalue
= byte_get (data
, 1);
5451 block_start
= data
+ 1;
5452 data
= display_block (block_start
, uvalue
);
5453 uvalue
= * block_start
;
5456 case DW_FORM_block2
:
5457 uvalue
= byte_get (data
, 2);
5458 block_start
= data
+ 2;
5459 data
= display_block (block_start
, uvalue
);
5460 uvalue
= * block_start
;
5463 case DW_FORM_block4
:
5464 uvalue
= byte_get (data
, 4);
5465 block_start
= data
+ 4;
5466 data
= display_block (block_start
, uvalue
);
5467 uvalue
= * block_start
;
5471 case DW_FORM_indirect
:
5472 warn (_("Unable to handle FORM: %d"), form
);
5476 warn (_("Unrecognised form: %d"), form
);
5480 /* For some attributes we can display futher information. */
5489 case DW_INL_not_inlined
: printf (_("(not inlined)")); break;
5490 case DW_INL_inlined
: printf (_("(inlined)")); break;
5491 case DW_INL_declared_not_inlined
: printf (_("(declared as inline but ignored)")); break;
5492 case DW_INL_declared_inlined
: printf (_("(declared as inline and inlined)")); break;
5493 default: printf (_(" (Unknown inline attribute value: %lx)"), uvalue
); break;
5497 case DW_AT_frame_base
:
5498 if (uvalue
>= DW_OP_reg0
&& uvalue
<= DW_OP_reg31
)
5499 printf ("(reg %ld)", uvalue
- DW_OP_reg0
);
5502 case DW_AT_language
:
5505 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
5506 case DW_LANG_C89
: printf ("(ANSI C)"); break;
5507 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
5508 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
5509 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
5510 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
5511 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
5512 case DW_LANG_Ada83
: printf ("(Ada)"); break;
5513 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
5514 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
5515 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
5516 default: printf ("(Unknown: %lx)", uvalue
); break;
5520 case DW_AT_encoding
:
5523 case DW_ATE_void
: printf ("(void)"); break;
5524 case DW_ATE_address
: printf ("(machine address)"); break;
5525 case DW_ATE_boolean
: printf ("(boolean)"); break;
5526 case DW_ATE_complex_float
: printf ("(complex float)"); break;
5527 case DW_ATE_float
: printf ("(float)"); break;
5528 case DW_ATE_signed
: printf ("(signed)"); break;
5529 case DW_ATE_signed_char
: printf ("(signed char)"); break;
5530 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
5531 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
5533 if (uvalue
>= DW_ATE_lo_user
5534 && uvalue
<= DW_ATE_hi_user
)
5535 printf ("(user defined type)");
5537 printf ("(unknown type)");
5542 case DW_AT_accessibility
:
5545 case DW_ACCESS_public
: printf ("(public)"); break;
5546 case DW_ACCESS_protected
: printf ("(protected)"); break;
5547 case DW_ACCESS_private
: printf ("(private)"); break;
5548 default: printf ("(unknown accessibility)"); break;
5552 case DW_AT_visibility
:
5555 case DW_VIS_local
: printf ("(local)"); break;
5556 case DW_VIS_exported
: printf ("(exported)"); break;
5557 case DW_VIS_qualified
: printf ("(qualified)"); break;
5558 default: printf ("(unknown visibility)"); break;
5562 case DW_AT_virtuality
:
5565 case DW_VIRTUALITY_none
: printf ("(none)"); break;
5566 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
5567 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
5568 default: printf ("(unknown virtuality)"); break;
5572 case DW_AT_identifier_case
:
5575 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
5576 case DW_ID_up_case
: printf ("(up_case)"); break;
5577 case DW_ID_down_case
: printf ("(down_case)"); break;
5578 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
5579 default: printf ("(unknown case)"); break;
5583 case DW_AT_calling_convention
:
5586 case DW_CC_normal
: printf ("(normal)"); break;
5587 case DW_CC_program
: printf ("(program)"); break;
5588 case DW_CC_nocall
: printf ("(nocall)"); break;
5590 if (uvalue
>= DW_CC_lo_user
5591 && uvalue
<= DW_CC_hi_user
)
5592 printf ("(user defined)");
5594 printf ("(unknown convention)");
5598 case DW_AT_location
:
5599 case DW_AT_data_member_location
:
5600 case DW_AT_vtable_elem_location
:
5602 decode_location_expression (block_start
, pointer_size
);
5615 display_debug_info (section
, start
, file
)
5616 Elf32_Internal_Shdr
* section
;
5617 unsigned char * start
;
5620 unsigned char * end
= start
+ section
->sh_size
;
5621 unsigned char * section_begin
= start
;
5623 printf (_("The section %s contains:\n\n"), SECTION_NAME (section
));
5627 DWARF2_External_CompUnit
* external
;
5628 DWARF2_Internal_CompUnit compunit
;
5629 unsigned char * tags
;
5633 external
= (DWARF2_External_CompUnit
*) start
;
5635 compunit
.cu_length
= BYTE_GET (external
->cu_length
);
5636 compunit
.cu_version
= BYTE_GET (external
->cu_version
);
5637 compunit
.cu_abbrev_offset
= BYTE_GET (external
->cu_abbrev_offset
);
5638 compunit
.cu_pointer_size
= BYTE_GET (external
->cu_pointer_size
);
5640 tags
= start
+ sizeof (* external
);
5641 start
+= compunit
.cu_length
+ sizeof (external
->cu_length
);
5643 if (compunit
.cu_version
!= 2)
5645 warn (_("Only version 2 DWARF debug information is currently supported.\n"));
5649 printf (_(" Compilation Unit:\n"));
5650 printf (_(" Length: %ld\n"), compunit
.cu_length
);
5651 printf (_(" Version: %d\n"), compunit
.cu_version
);
5652 printf (_(" Abbrev Offset: %ld\n"), compunit
.cu_abbrev_offset
);
5653 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
5655 if (first_abbrev
!= NULL
)
5658 /* Read in the abbrevs used by this compilation unit. */
5661 Elf32_Internal_Shdr
* sec
;
5662 unsigned char * begin
;
5664 /* Locate the .debug_abbrev section and process it. */
5665 for (i
= 0, sec
= section_headers
;
5666 i
< elf_header
.e_shnum
;
5668 if (strcmp (SECTION_NAME (sec
), ".debug_abbrev") == 0)
5671 if (i
== -1 || sec
->sh_size
== 0)
5673 warn (_("Unable to locate .debug_abbrev section!\n"));
5677 GET_DATA_ALLOC (sec
->sh_offset
, sec
->sh_size
, begin
, unsigned char *,
5678 "debug_abbrev section data");
5680 process_abbrev_section (begin
+ compunit
.cu_abbrev_offset
,
5681 begin
+ sec
->sh_size
);
5687 while (tags
< start
)
5690 unsigned long abbrev_number
;
5691 abbrev_entry
* entry
;
5694 abbrev_number
= read_leb128 (tags
, & bytes_read
, 0);
5697 /* A null DIE marks the end of a list of children. */
5698 if (abbrev_number
== 0)
5704 /* Scan through the abbreviation list until we reach the
5706 for (entry
= first_abbrev
;
5707 entry
&& entry
->entry
!= abbrev_number
;
5708 entry
= entry
->next
)
5713 warn (_("Unable to locate entry %lu in the abbreviation table\n"),
5718 printf (_(" <%d><%x>: Abbrev Number: %lu (%s)\n"),
5719 level
, tags
- section_begin
- bytes_read
,
5721 get_TAG_name (entry
->tag
));
5723 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
5724 tags
= read_and_display_attr (attr
->attribute
,
5727 compunit
.cu_pointer_size
);
5729 if (entry
->children
)
5740 display_debug_aranges (section
, start
, file
)
5741 Elf32_Internal_Shdr
* section
;
5742 unsigned char * start
;
5743 FILE * file ATTRIBUTE_UNUSED
;
5745 unsigned char * end
= start
+ section
->sh_size
;
5747 printf (_("The section %s contains:\n\n"), SECTION_NAME (section
));
5751 DWARF2_External_ARange
* external
;
5752 DWARF2_Internal_ARange arange
;
5753 unsigned char * ranges
;
5754 unsigned long length
;
5755 unsigned long address
;
5757 external
= (DWARF2_External_ARange
*) start
;
5759 arange
.ar_length
= BYTE_GET (external
->ar_length
);
5760 arange
.ar_version
= BYTE_GET (external
->ar_version
);
5761 arange
.ar_info_offset
= BYTE_GET (external
->ar_info_offset
);
5762 arange
.ar_pointer_size
= BYTE_GET (external
->ar_pointer_size
);
5763 arange
.ar_segment_size
= BYTE_GET (external
->ar_segment_size
);
5765 printf (_(" Length: %ld\n"), arange
.ar_length
);
5766 printf (_(" Version: %d\n"), arange
.ar_version
);
5767 printf (_(" Offset into .debug_info: %lx\n"), arange
.ar_info_offset
);
5768 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
5769 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
5771 printf (_("\n Address Length\n"));
5773 ranges
= start
+ sizeof (* external
);
5777 address
= byte_get (ranges
, arange
.ar_pointer_size
);
5782 ranges
+= arange
.ar_pointer_size
;
5784 length
= byte_get (ranges
, arange
.ar_pointer_size
);
5786 ranges
+= arange
.ar_pointer_size
;
5788 printf (" %8.8lx %lu\n", address
, length
);
5791 start
+= arange
.ar_length
+ sizeof (external
->ar_length
);
5801 display_debug_not_supported (section
, start
, file
)
5802 Elf32_Internal_Shdr
* section
;
5803 unsigned char * start ATTRIBUTE_UNUSED
;
5804 FILE * file ATTRIBUTE_UNUSED
;
5806 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
5807 SECTION_NAME (section
));
5812 /* A structure containing the name of a debug section and a pointer
5813 to a function that can decode it. */
5817 int (* display
) PARAMS((Elf32_Internal_Shdr
*, unsigned char *, FILE *));
5821 { ".debug_info", display_debug_info
},
5822 { ".debug_abbrev", display_debug_abbrev
},
5823 { ".debug_line", display_debug_lines
},
5824 { ".debug_aranges", display_debug_aranges
},
5825 { ".debug_pubnames", display_debug_pubnames
},
5826 { ".debug_macinfo", display_debug_not_supported
},
5827 { ".debug_frame", display_debug_not_supported
},
5828 { ".debug_str", display_debug_not_supported
},
5829 { ".debug_static_func", display_debug_not_supported
},
5830 { ".debug_static_vars", display_debug_not_supported
},
5831 { ".debug_types", display_debug_not_supported
},
5832 { ".debug_weaknames", display_debug_not_supported
}
5836 display_debug_section (section
, file
)
5837 Elf32_Internal_Shdr
* section
;
5840 char * name
= SECTION_NAME (section
);
5841 bfd_size_type length
;
5842 unsigned char * start
;
5845 length
= section
->sh_size
;
5848 printf (_("\nSection '%s' has no debugging data.\n"), name
);
5852 GET_DATA_ALLOC (section
->sh_offset
, length
, start
, unsigned char *,
5853 "debug section data");
5855 /* See if we know how to display the contents of this section. */
5856 for (i
= NUM_ELEM (debug_displays
); i
--;)
5857 if (strcmp (debug_displays
[i
].name
, name
) == 0)
5859 debug_displays
[i
].display (section
, start
, file
);
5864 printf (_("Unrecognised debug section: %s\n"), name
);
5868 /* If we loaded in the abbrev section at some point,
5869 we must release it here. */
5870 if (first_abbrev
!= NULL
)
5877 process_section_contents (file
)
5880 Elf32_Internal_Shdr
* section
;
5886 for (i
= 0, section
= section_headers
;
5887 i
< elf_header
.e_shnum
5888 && i
< num_dump_sects
;
5891 #ifdef SUPPORT_DISASSEMBLY
5892 if (dump_sects
[i
] & DISASS_DUMP
)
5893 disassemble_section (section
, file
);
5895 if (dump_sects
[i
] & HEX_DUMP
)
5896 dump_section (section
, file
);
5898 if (dump_sects
[i
] & DEBUG_DUMP
)
5899 display_debug_section (section
, file
);
5902 if (i
< num_dump_sects
)
5903 warn (_("Some sections were not dumped because they do not exist!\n"));
5909 process_mips_fpe_exception (mask
)
5915 if (mask
& OEX_FPU_INEX
)
5916 fputs ("INEX", stdout
), first
= 0;
5917 if (mask
& OEX_FPU_UFLO
)
5918 printf ("%sUFLO", first
? "" : "|"), first
= 0;
5919 if (mask
& OEX_FPU_OFLO
)
5920 printf ("%sOFLO", first
? "" : "|"), first
= 0;
5921 if (mask
& OEX_FPU_DIV0
)
5922 printf ("%sDIV0", first
? "" : "|"), first
= 0;
5923 if (mask
& OEX_FPU_INVAL
)
5924 printf ("%sINVAL", first
? "" : "|");
5927 fputs ("0", stdout
);
5931 process_mips_specific (file
)
5934 Elf_Internal_Dyn
* entry
;
5935 size_t liblist_offset
= 0;
5936 size_t liblistno
= 0;
5937 size_t conflictsno
= 0;
5938 size_t options_offset
= 0;
5939 size_t conflicts_offset
= 0;
5941 /* We have a lot of special sections. Thanks SGI! */
5942 if (dynamic_segment
== NULL
)
5943 /* No information available. */
5946 for (entry
= dynamic_segment
; entry
->d_tag
!= DT_NULL
; ++entry
)
5947 switch (entry
->d_tag
)
5949 case DT_MIPS_LIBLIST
:
5950 liblist_offset
= entry
->d_un
.d_val
- loadaddr
;
5952 case DT_MIPS_LIBLISTNO
:
5953 liblistno
= entry
->d_un
.d_val
;
5955 case DT_MIPS_OPTIONS
:
5956 options_offset
= entry
->d_un
.d_val
- loadaddr
;
5958 case DT_MIPS_CONFLICT
:
5959 conflicts_offset
= entry
->d_un
.d_val
- loadaddr
;
5961 case DT_MIPS_CONFLICTNO
:
5962 conflictsno
= entry
->d_un
.d_val
;
5968 if (liblist_offset
!= 0 && liblistno
!= 0 && do_dynamic
)
5970 Elf32_External_Lib
* elib
;
5973 GET_DATA_ALLOC (liblist_offset
, liblistno
* sizeof (Elf32_External_Lib
),
5974 elib
, Elf32_External_Lib
*, "liblist");
5976 printf ("\nSection '.liblist' contains %d entries:\n", liblistno
);
5977 fputs (" Library Time Stamp Checksum Version Flags\n",
5980 for (cnt
= 0; cnt
< liblistno
; ++cnt
)
5986 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
5987 time
= BYTE_GET (elib
[cnt
].l_time_stamp
);
5988 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
5989 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
5990 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
5992 strftime (timebuf
, 20, "%Y-%m-%dT%H:%M:%S", gmtime (&time
));
5994 printf ("%3d: %-20s %s %#10lx %-7ld", cnt
,
5995 dynamic_strings
+ liblist
.l_name
, timebuf
,
5996 liblist
.l_checksum
, liblist
.l_version
);
5998 if (liblist
.l_flags
== 0)
6008 { " EXACT_MATCH", LL_EXACT_MATCH
},
6009 { " IGNORE_INT_VER", LL_IGNORE_INT_VER
},
6010 { " REQUIRE_MINOR", LL_REQUIRE_MINOR
},
6011 { " EXPORTS", LL_EXPORTS
},
6012 { " DELAY_LOAD", LL_DELAY_LOAD
},
6013 { " DELTA", LL_DELTA
}
6015 int flags
= liblist
.l_flags
;
6019 fcnt
< sizeof (l_flags_vals
) / sizeof (l_flags_vals
[0]);
6021 if ((flags
& l_flags_vals
[fcnt
].bit
) != 0)
6023 fputs (l_flags_vals
[fcnt
].name
, stdout
);
6024 flags
^= l_flags_vals
[fcnt
].bit
;
6027 printf (" %#x", (unsigned int) flags
);
6036 if (options_offset
!= 0)
6038 Elf_External_Options
* eopt
;
6039 Elf_Internal_Shdr
* sect
= section_headers
;
6040 Elf_Internal_Options
* iopt
;
6041 Elf_Internal_Options
* option
;
6045 /* Find the section header so that we get the size. */
6046 while (sect
->sh_type
!= SHT_MIPS_OPTIONS
)
6049 GET_DATA_ALLOC (options_offset
, sect
->sh_size
, eopt
,
6050 Elf_External_Options
*, "options");
6052 iopt
= (Elf_Internal_Options
*) malloc ((sect
->sh_size
/ sizeof (eopt
))
6056 error (_("Out of memory"));
6062 while (offset
< sect
->sh_size
)
6064 Elf_External_Options
* eoption
;
6066 eoption
= (Elf_External_Options
*) ((char *) eopt
+ offset
);
6068 option
->kind
= BYTE_GET (eoption
->kind
);
6069 option
->size
= BYTE_GET (eoption
->size
);
6070 option
->section
= BYTE_GET (eoption
->section
);
6071 option
->info
= BYTE_GET (eoption
->info
);
6073 offset
+= option
->size
;
6078 printf (_("\nSection '%s' contains %d entries:\n"),
6079 string_table
+ sect
->sh_name
, cnt
);
6086 switch (option
->kind
)
6089 /* This shouldn't happen. */
6090 printf (" NULL %d %lx", option
->section
, option
->info
);
6093 printf (" REGINFO ");
6094 if (elf_header
.e_machine
== EM_MIPS
)
6097 Elf32_External_RegInfo
*ereg
;
6098 Elf32_RegInfo reginfo
;
6100 ereg
= (Elf32_External_RegInfo
*) (option
+ 1);
6101 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
6102 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
6103 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
6104 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
6105 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
6106 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
6108 printf ("GPR %08lx GP 0x%lx\n",
6110 (unsigned long) reginfo
.ri_gp_value
);
6111 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
6112 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
6113 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
6118 Elf64_External_RegInfo
* ereg
;
6119 Elf64_Internal_RegInfo reginfo
;
6121 ereg
= (Elf64_External_RegInfo
*) (option
+ 1);
6122 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
6123 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
6124 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
6125 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
6126 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
6127 reginfo
.ri_gp_value
= BYTE_GET8 (ereg
->ri_gp_value
);
6129 printf ("GPR %08lx GP 0x",
6130 reginfo
.ri_gprmask
);
6131 printf_vma (reginfo
.ri_gp_value
);
6134 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
6135 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
6136 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
6140 case ODK_EXCEPTIONS
:
6141 fputs (" EXCEPTIONS fpe_min(", stdout
);
6142 process_mips_fpe_exception (option
->info
& OEX_FPU_MIN
);
6143 fputs (") fpe_max(", stdout
);
6144 process_mips_fpe_exception ((option
->info
& OEX_FPU_MAX
) >> 8);
6145 fputs (")", stdout
);
6147 if (option
->info
& OEX_PAGE0
)
6148 fputs (" PAGE0", stdout
);
6149 if (option
->info
& OEX_SMM
)
6150 fputs (" SMM", stdout
);
6151 if (option
->info
& OEX_FPDBUG
)
6152 fputs (" FPDBUG", stdout
);
6153 if (option
->info
& OEX_DISMISS
)
6154 fputs (" DISMISS", stdout
);
6157 fputs (" PAD ", stdout
);
6158 if (option
->info
& OPAD_PREFIX
)
6159 fputs (" PREFIX", stdout
);
6160 if (option
->info
& OPAD_POSTFIX
)
6161 fputs (" POSTFIX", stdout
);
6162 if (option
->info
& OPAD_SYMBOL
)
6163 fputs (" SYMBOL", stdout
);
6166 fputs (" HWPATCH ", stdout
);
6167 if (option
->info
& OHW_R4KEOP
)
6168 fputs (" R4KEOP", stdout
);
6169 if (option
->info
& OHW_R8KPFETCH
)
6170 fputs (" R8KPFETCH", stdout
);
6171 if (option
->info
& OHW_R5KEOP
)
6172 fputs (" R5KEOP", stdout
);
6173 if (option
->info
& OHW_R5KCVTL
)
6174 fputs (" R5KCVTL", stdout
);
6177 fputs (" FILL ", stdout
);
6178 /* XXX Print content of info word? */
6181 fputs (" TAGS ", stdout
);
6182 /* XXX Print content of info word? */
6185 fputs (" HWAND ", stdout
);
6186 if (option
->info
& OHWA0_R4KEOP_CHECKED
)
6187 fputs (" R4KEOP_CHECKED", stdout
);
6188 if (option
->info
& OHWA0_R4KEOP_CLEAN
)
6189 fputs (" R4KEOP_CLEAN", stdout
);
6192 fputs (" HWOR ", stdout
);
6193 if (option
->info
& OHWA0_R4KEOP_CHECKED
)
6194 fputs (" R4KEOP_CHECKED", stdout
);
6195 if (option
->info
& OHWA0_R4KEOP_CLEAN
)
6196 fputs (" R4KEOP_CLEAN", stdout
);
6199 printf (" GP_GROUP %#06lx self-contained %#06lx",
6200 option
->info
& OGP_GROUP
,
6201 (option
->info
& OGP_SELF
) >> 16);
6204 printf (" IDENT %#06lx self-contained %#06lx",
6205 option
->info
& OGP_GROUP
,
6206 (option
->info
& OGP_SELF
) >> 16);
6209 /* This shouldn't happen. */
6210 printf (" %3d ??? %d %lx",
6211 option
->kind
, option
->section
, option
->info
);
6215 len
= sizeof (*eopt
);
6216 while (len
< option
->size
)
6217 if (((char *) option
)[len
] >= ' '
6218 && ((char *) option
)[len
] < 0x7f)
6219 printf ("%c", ((char *) option
)[len
++]);
6221 printf ("\\%03o", ((char *) option
)[len
++]);
6223 fputs ("\n", stdout
);
6230 if (conflicts_offset
!= 0 && conflictsno
!= 0)
6232 Elf32_External_Conflict
* econf32
;
6233 Elf64_External_Conflict
* econf64
;
6234 Elf32_Conflict
* iconf
;
6237 if (dynamic_symbols
== NULL
)
6239 error (_("conflict list with without table"));
6243 iconf
= (Elf32_Conflict
*) malloc (conflictsno
* sizeof (*iconf
));
6246 error (_("Out of memory"));
6252 GET_DATA_ALLOC (conflicts_offset
, conflictsno
* sizeof (*econf32
),
6253 econf32
, Elf32_External_Conflict
*, "conflict");
6255 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
6256 iconf
[cnt
] = BYTE_GET (econf32
[cnt
]);
6260 GET_DATA_ALLOC (conflicts_offset
, conflictsno
* sizeof (*econf64
),
6261 econf64
, Elf64_External_Conflict
*, "conflict");
6263 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
6264 iconf
[cnt
] = BYTE_GET (econf64
[cnt
]);
6267 printf (_("\nSection '.conflict' contains %d entries:\n"), conflictsno
);
6268 puts (_(" Num: Index Value Name"));
6270 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
6272 Elf_Internal_Sym
* psym
= &dynamic_symbols
[iconf
[cnt
]];
6274 printf ("%5u: %8lu %#10lx %s\n",
6275 cnt
, iconf
[cnt
], (unsigned long) psym
->st_value
,
6276 dynamic_strings
+ psym
->st_name
);
6287 process_arch_specific (file
)
6293 switch (elf_header
.e_machine
)
6296 case EM_MIPS_RS4_BE
:
6297 return process_mips_specific (file
);
6306 get_file_header (file
)
6309 /* Read in the identity array. */
6310 if (fread (elf_header
.e_ident
, EI_NIDENT
, 1, file
) != 1)
6313 /* Determine how to read the rest of the header. */
6314 switch (elf_header
.e_ident
[EI_DATA
])
6316 default: /* fall through */
6317 case ELFDATANONE
: /* fall through */
6318 case ELFDATA2LSB
: byte_get
= byte_get_little_endian
; break;
6319 case ELFDATA2MSB
: byte_get
= byte_get_big_endian
; break;
6322 /* For now we only support 32 bit and 64 bit ELF files. */
6323 is_32bit_elf
= (elf_header
.e_ident
[EI_CLASS
] != ELFCLASS64
);
6325 /* Read in the rest of the header. */
6328 Elf32_External_Ehdr ehdr32
;
6330 if (fread (ehdr32
.e_type
, sizeof (ehdr32
) - EI_NIDENT
, 1, file
) != 1)
6333 elf_header
.e_type
= BYTE_GET (ehdr32
.e_type
);
6334 elf_header
.e_machine
= BYTE_GET (ehdr32
.e_machine
);
6335 elf_header
.e_version
= BYTE_GET (ehdr32
.e_version
);
6336 elf_header
.e_entry
= BYTE_GET (ehdr32
.e_entry
);
6337 elf_header
.e_phoff
= BYTE_GET (ehdr32
.e_phoff
);
6338 elf_header
.e_shoff
= BYTE_GET (ehdr32
.e_shoff
);
6339 elf_header
.e_flags
= BYTE_GET (ehdr32
.e_flags
);
6340 elf_header
.e_ehsize
= BYTE_GET (ehdr32
.e_ehsize
);
6341 elf_header
.e_phentsize
= BYTE_GET (ehdr32
.e_phentsize
);
6342 elf_header
.e_phnum
= BYTE_GET (ehdr32
.e_phnum
);
6343 elf_header
.e_shentsize
= BYTE_GET (ehdr32
.e_shentsize
);
6344 elf_header
.e_shnum
= BYTE_GET (ehdr32
.e_shnum
);
6345 elf_header
.e_shstrndx
= BYTE_GET (ehdr32
.e_shstrndx
);
6349 Elf64_External_Ehdr ehdr64
;
6351 /* If we have been compiled with sizeof (bfd_vma) == 4, then
6352 we will not be able to cope with the 64bit data found in
6353 64 ELF files. Detect this now and abort before we start
6354 overwritting things. */
6355 if (sizeof (bfd_vma
) < 8)
6357 error (_("This instance of readelf has been built without support for a\n"));
6358 error (_("64 bit data type and so it cannot read 64 bit ELF files.\n"));
6362 if (fread (ehdr64
.e_type
, sizeof (ehdr64
) - EI_NIDENT
, 1, file
) != 1)
6365 elf_header
.e_type
= BYTE_GET (ehdr64
.e_type
);
6366 elf_header
.e_machine
= BYTE_GET (ehdr64
.e_machine
);
6367 elf_header
.e_version
= BYTE_GET (ehdr64
.e_version
);
6368 elf_header
.e_entry
= BYTE_GET8 (ehdr64
.e_entry
);
6369 elf_header
.e_phoff
= BYTE_GET8 (ehdr64
.e_phoff
);
6370 elf_header
.e_shoff
= BYTE_GET8 (ehdr64
.e_shoff
);
6371 elf_header
.e_flags
= BYTE_GET (ehdr64
.e_flags
);
6372 elf_header
.e_ehsize
= BYTE_GET (ehdr64
.e_ehsize
);
6373 elf_header
.e_phentsize
= BYTE_GET (ehdr64
.e_phentsize
);
6374 elf_header
.e_phnum
= BYTE_GET (ehdr64
.e_phnum
);
6375 elf_header
.e_shentsize
= BYTE_GET (ehdr64
.e_shentsize
);
6376 elf_header
.e_shnum
= BYTE_GET (ehdr64
.e_shnum
);
6377 elf_header
.e_shstrndx
= BYTE_GET (ehdr64
.e_shstrndx
);
6384 process_file (file_name
)
6388 struct stat statbuf
;
6391 if (stat (file_name
, & statbuf
) < 0)
6393 error (_("Cannot stat input file %s.\n"), file_name
);
6397 file
= fopen (file_name
, "rb");
6400 error (_("Input file %s not found.\n"), file_name
);
6404 if (! get_file_header (file
))
6406 error (_("%s: Failed to read file header\n"), file_name
);
6411 /* Initialise per file variables. */
6412 for (i
= NUM_ELEM (version_info
); i
--;)
6413 version_info
[i
] = 0;
6415 for (i
= NUM_ELEM (dynamic_info
); i
--;)
6416 dynamic_info
[i
] = 0;
6418 /* Process the file. */
6420 printf (_("\nFile: %s\n"), file_name
);
6422 if (! process_file_header ())
6428 process_section_headers (file
);
6430 process_program_headers (file
);
6432 process_dynamic_segment (file
);
6434 process_relocs (file
);
6436 process_symbol_table (file
);
6438 process_syminfo (file
);
6440 process_version_sections (file
);
6442 process_section_contents (file
);
6444 process_arch_specific (file
);
6448 if (section_headers
)
6450 free (section_headers
);
6451 section_headers
= NULL
;
6456 free (string_table
);
6457 string_table
= NULL
;
6460 if (dynamic_strings
)
6462 free (dynamic_strings
);
6463 dynamic_strings
= NULL
;
6466 if (dynamic_symbols
)
6468 free (dynamic_symbols
);
6469 dynamic_symbols
= NULL
;
6470 num_dynamic_syms
= 0;
6473 if (dynamic_syminfo
)
6475 free (dynamic_syminfo
);
6476 dynamic_syminfo
= NULL
;
6480 #ifdef SUPPORT_DISASSEMBLY
6481 /* Needed by the i386 disassembler. For extra credit, someone could
6482 fix this so that we insert symbolic addresses here, esp for GOT/PLT
6486 print_address (unsigned int addr
, FILE * outfile
)
6488 fprintf (outfile
,"0x%8.8x", addr
);
6491 /* Needed by the i386 disassembler. */
6493 db_task_printsym (unsigned int addr
)
6495 print_address (addr
, stderr
);
6504 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
6505 setlocale (LC_MESSAGES
, "");
6507 bindtextdomain (PACKAGE
, LOCALEDIR
);
6508 textdomain (PACKAGE
);
6510 parse_args (argc
, argv
);
6512 if (optind
< (argc
- 1))
6515 while (optind
< argc
)
6516 process_file (argv
[optind
++]);
6518 if (dump_sects
!= NULL
)