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
;
120 /* A dynamic array of flags indicating which sections require dumping. */
121 char * dump_sects
= NULL
;
122 unsigned int num_dump_sects
= 0;
124 #define HEX_DUMP (1 << 0)
125 #define DISASS_DUMP (1 << 1)
126 #define DEBUG_DUMP (1 << 2)
128 /* Forward declarations for dumb compilers. */
129 static bfd_vma (* byte_get
) PARAMS ((unsigned char *, int));
130 static bfd_vma byte_get_little_endian
PARAMS ((unsigned char *, int));
131 static bfd_vma byte_get_big_endian
PARAMS ((unsigned char *, int));
132 static const char * get_mips_dynamic_type
PARAMS ((unsigned long));
133 static const char * get_sparc64_dynamic_type
PARAMS ((unsigned long));
134 static const char * get_dynamic_type
PARAMS ((unsigned long));
135 static int dump_relocations
PARAMS ((FILE *, unsigned long, unsigned long, Elf_Internal_Sym
*, unsigned long, char *, int));
136 static char * get_file_type
PARAMS ((unsigned));
137 static char * get_machine_name
PARAMS ((unsigned));
138 static char * get_machine_flags
PARAMS ((unsigned, unsigned));
139 static const char * get_mips_segment_type
PARAMS ((unsigned long));
140 static const char * get_segment_type
PARAMS ((unsigned long));
141 static const char * get_mips_section_type_name
PARAMS ((unsigned int));
142 static const char * get_section_type_name
PARAMS ((unsigned int));
143 static char * get_symbol_binding
PARAMS ((unsigned int));
144 static char * get_symbol_type
PARAMS ((unsigned int));
145 static void usage
PARAMS ((void));
146 static void parse_args
PARAMS ((int, char **));
147 static int process_file_header
PARAMS ((void));
148 static int process_program_headers
PARAMS ((FILE *));
149 static int process_section_headers
PARAMS ((FILE *));
150 static void dynamic_segment_mips_val
PARAMS ((Elf_Internal_Dyn
*));
151 static int process_dynamic_segment
PARAMS ((FILE *));
152 static int process_symbol_table
PARAMS ((FILE *));
153 static int process_section_contents
PARAMS ((FILE *));
154 static void process_file
PARAMS ((char *));
155 static int process_relocs
PARAMS ((FILE *));
156 static int process_version_sections
PARAMS ((FILE *));
157 static char * get_ver_flags
PARAMS ((unsigned int));
158 static char * get_symbol_index_type
PARAMS ((unsigned int));
159 static int get_32bit_section_headers
PARAMS ((FILE *));
160 static int get_64bit_section_headers
PARAMS ((FILE *));
161 static int get_32bit_program_headers
PARAMS ((FILE *, Elf_Internal_Phdr
*));
162 static int get_64bit_program_headers
PARAMS ((FILE *, Elf_Internal_Phdr
*));
163 static int get_file_header
PARAMS ((FILE *));
164 static Elf_Internal_Sym
* get_32bit_elf_symbols
PARAMS ((FILE *, unsigned long, unsigned long));
165 static Elf_Internal_Sym
* get_64bit_elf_symbols
PARAMS ((FILE *, unsigned long, unsigned long));
166 static int * get_dynamic_data
PARAMS ((FILE *, unsigned int));
167 static int get_32bit_dynamic_segment
PARAMS ((FILE *));
168 static int get_64bit_dynamic_segment
PARAMS ((FILE *));
169 #ifdef SUPPORT_DISASSEMBLY
170 static int disassemble_section
PARAMS ((Elf32_Internal_Shdr
*, FILE *));
172 static int dump_section
PARAMS ((Elf32_Internal_Shdr
*, FILE *));
173 static int display_debug_section
PARAMS ((Elf32_Internal_Shdr
*, FILE *));
174 static int display_debug_info
PARAMS ((Elf32_Internal_Shdr
*, unsigned char *, FILE *));
175 static int display_debug_not_supported
PARAMS ((Elf32_Internal_Shdr
*, unsigned char *, FILE *));
176 static int display_debug_lines
PARAMS ((Elf32_Internal_Shdr
*, unsigned char *, FILE *));
177 static int display_debug_abbrev
PARAMS ((Elf32_Internal_Shdr
*, unsigned char *, FILE *));
178 static int display_debug_aranges
PARAMS ((Elf32_Internal_Shdr
*, unsigned char *, FILE *));
179 static unsigned char * process_abbrev_section
PARAMS ((unsigned char *, unsigned char *));
180 static unsigned long read_leb128
PARAMS ((unsigned char *, int *, int));
181 static int process_extended_line_op
PARAMS ((unsigned char *, int, int));
182 static void reset_state_machine
PARAMS ((int));
183 static char * get_TAG_name
PARAMS ((unsigned long));
184 static char * get_AT_name
PARAMS ((unsigned long));
185 static char * get_FORM_name
PARAMS ((unsigned long));
186 static void free_abbrevs
PARAMS ((void));
187 static void add_abbrev
PARAMS ((unsigned long, unsigned long, int));
188 static void add_abbrev_attr
PARAMS ((unsigned long, unsigned long));
189 static unsigned char * read_and_display_attr
PARAMS ((unsigned long, unsigned long, unsigned char *, unsigned long));
190 static unsigned char * display_block
PARAMS ((unsigned char *, unsigned long));
191 static void decode_location_expression
PARAMS ((unsigned char *, unsigned int));
192 static void request_dump
PARAMS ((unsigned int, char));
193 static const char * get_elf_class
PARAMS ((unsigned char));
194 static const char * get_data_encoding
PARAMS ((unsigned char));
195 static const char * get_osabi_name
PARAMS ((unsigned char));
196 static int guess_is_rela
PARAMS ((unsigned long));
197 static char * get_note_type
PARAMS ((unsigned int));
198 static int process_note
PARAMS ((Elf_External_Note
*));
199 static int process_corefile_note_segment
PARAMS ((FILE *, unsigned long, unsigned long));
200 static int process_corefile_note_segments
PARAMS ((FILE *));
201 static int process_corefile_contents
PARAMS ((FILE *));
203 typedef int Elf32_Word
;
211 #define SECTION_NAME(X) (string_table + (X)->sh_name)
213 #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
215 #define BYTE_GET(field) byte_get (field, sizeof (field))
217 /* If we can support a 64 bit data type then BFD64 should be defined
218 and sizeof (bfd_vma) == 8. In this case when translating from an
219 external 8 byte field to an internal field, we can assume that the
220 internal field is also 8 bytes wide and so we can extact all the data.
221 If, however, BFD64 is not defined, then we must assume that the
222 internal data structure only has 4 byte wide fields that are the
223 equivalent of the 8 byte wide external counterparts, and so we must
224 truncate the data. */
226 #define BYTE_GET8(field) byte_get (field, -8)
228 #define BYTE_GET8(field) byte_get (field, 8)
231 #define NUM_ELEM(array) (sizeof (array) / sizeof ((array)[0]))
233 #define GET_DATA_ALLOC(offset, size, var, type, reason) \
234 if (fseek (file, offset, SEEK_SET)) \
236 error (_("Unable to seek to start of %s at %x\n"), reason, offset); \
240 var = (type) malloc (size); \
244 error (_("Out of memory allocating %d bytes for %s\n"), size, reason); \
248 if (fread (var, size, 1, file) != 1) \
250 error (_("Unable to read in %d bytes of %s\n"), size, reason); \
257 #define GET_DATA(offset, var, reason) \
258 if (fseek (file, offset, SEEK_SET)) \
260 error (_("Unable to seek to %x for %s\n"), offset, reason); \
263 else if (fread (& var, sizeof (var), 1, file) != 1) \
265 error (_("Unable to read data at %x for %s\n"), offset, reason); \
269 #define GET_ELF_SYMBOLS(file, offset, size) \
270 (is_32bit_elf ? get_32bit_elf_symbols (file, offset, size) \
271 : get_64bit_elf_symbols (file, offset, size))
274 #ifdef ANSI_PROTOTYPES
276 error (const char * message
, ...)
280 fprintf (stderr
, _("%s: Error: "), program_name
);
281 va_start (args
, message
);
282 vfprintf (stderr
, message
, args
);
288 warn (const char * message
, ...)
292 fprintf (stderr
, _("%s: Warning: "), program_name
);
293 va_start (args
, message
);
294 vfprintf (stderr
, message
, args
);
306 fprintf (stderr
, _("%s: Error: "), program_name
);
308 message
= va_arg (args
, char *);
309 vfprintf (stderr
, message
, args
);
321 fprintf (stderr
, _("%s: Warning: "), program_name
);
323 message
= va_arg (args
, char *);
324 vfprintf (stderr
, message
, args
);
331 byte_get_little_endian (field
, size
)
332 unsigned char * field
;
341 return ((unsigned int) (field
[0]))
342 | (((unsigned int) (field
[1])) << 8);
345 /* We want to extract data from an 8 byte wide field and
346 place it into a 4 byte wide field. Since this is a little
347 endian source we can juts use the 4 byte extraction code. */
350 return ((unsigned long) (field
[0]))
351 | (((unsigned long) (field
[1])) << 8)
352 | (((unsigned long) (field
[2])) << 16)
353 | (((unsigned long) (field
[3])) << 24);
357 /* This is a special case, generated by the BYTE_GET8 macro.
358 It means that we are loading an 8 byte value from a field
359 in an external structure into an 8 byte value in a field
360 in an internal strcuture. */
361 return ((bfd_vma
) (field
[0]))
362 | (((bfd_vma
) (field
[1])) << 8)
363 | (((bfd_vma
) (field
[2])) << 16)
364 | (((bfd_vma
) (field
[3])) << 24)
365 | (((bfd_vma
) (field
[4])) << 32)
366 | (((bfd_vma
) (field
[5])) << 40)
367 | (((bfd_vma
) (field
[6])) << 48)
368 | (((bfd_vma
) (field
[7])) << 56);
371 error (_("Unhandled data length: %d\n"), size
);
377 byte_get_big_endian (field
, size
)
378 unsigned char * field
;
387 return ((unsigned int) (field
[1])) | (((int) (field
[0])) << 8);
390 return ((unsigned long) (field
[3]))
391 | (((unsigned long) (field
[2])) << 8)
392 | (((unsigned long) (field
[1])) << 16)
393 | (((unsigned long) (field
[0])) << 24);
396 /* Although we are extracing data from an 8 byte wide field, we
397 are returning only 4 bytes of data. */
398 return ((unsigned long) (field
[7]))
399 | (((unsigned long) (field
[6])) << 8)
400 | (((unsigned long) (field
[5])) << 16)
401 | (((unsigned long) (field
[4])) << 24);
405 /* This is a special case, generated by the BYTE_GET8 macro.
406 It means that we are loading an 8 byte value from a field
407 in an external structure into an 8 byte value in a field
408 in an internal strcuture. */
409 return ((bfd_vma
) (field
[7]))
410 | (((bfd_vma
) (field
[6])) << 8)
411 | (((bfd_vma
) (field
[5])) << 16)
412 | (((bfd_vma
) (field
[4])) << 24)
413 | (((bfd_vma
) (field
[3])) << 32)
414 | (((bfd_vma
) (field
[2])) << 40)
415 | (((bfd_vma
) (field
[1])) << 48)
416 | (((bfd_vma
) (field
[0])) << 56);
420 error (_("Unhandled data length: %d\n"), size
);
426 /* Guess the relocation sized based on the sized commonly used by the specific machine. */
428 guess_is_rela (e_machine
)
429 unsigned long e_machine
;
433 /* Targets that use REL relocations. */
444 /* Targets that use RELA relocations. */
452 case EM_CYGNUS_MN10200
:
453 case EM_CYGNUS_MN10300
:
461 warn (_("Don't know about relocations on this machine architecture\n"));
466 /* Display the contents of the relocation data found at the specified offset. */
468 dump_relocations (file
, rel_offset
, rel_size
, symtab
, nsyms
, strtab
, is_rela
)
470 unsigned long rel_offset
;
471 unsigned long rel_size
;
472 Elf_Internal_Sym
* symtab
;
478 Elf_Internal_Rel
* rels
;
479 Elf_Internal_Rela
* relas
;
482 if (is_rela
== UNKNOWN
)
483 is_rela
= guess_is_rela (elf_header
.e_machine
);
489 Elf32_External_Rela
* erelas
;
491 GET_DATA_ALLOC (rel_offset
, rel_size
, erelas
,
492 Elf32_External_Rela
*, "relocs");
494 rel_size
= rel_size
/ sizeof (Elf32_External_Rela
);
496 relas
= (Elf_Internal_Rela
*)
497 malloc (rel_size
* sizeof (Elf_Internal_Rela
));
501 error(_("out of memory parsing relocs"));
505 for (i
= 0; i
< rel_size
; i
++)
507 relas
[i
].r_offset
= BYTE_GET (erelas
[i
].r_offset
);
508 relas
[i
].r_info
= BYTE_GET (erelas
[i
].r_info
);
509 relas
[i
].r_addend
= BYTE_GET (erelas
[i
].r_addend
);
514 rels
= (Elf_Internal_Rel
*) relas
;
518 Elf64_External_Rela
* erelas
;
520 GET_DATA_ALLOC (rel_offset
, rel_size
, erelas
,
521 Elf64_External_Rela
*, "relocs");
523 rel_size
= rel_size
/ sizeof (Elf64_External_Rela
);
525 relas
= (Elf_Internal_Rela
*)
526 malloc (rel_size
* sizeof (Elf_Internal_Rela
));
530 error(_("out of memory parsing relocs"));
534 for (i
= 0; i
< rel_size
; i
++)
536 relas
[i
].r_offset
= BYTE_GET8 (erelas
[i
].r_offset
);
537 relas
[i
].r_info
= BYTE_GET8 (erelas
[i
].r_info
);
538 relas
[i
].r_addend
= BYTE_GET8 (erelas
[i
].r_addend
);
543 rels
= (Elf_Internal_Rel
*) relas
;
550 Elf32_External_Rel
* erels
;
552 GET_DATA_ALLOC (rel_offset
, rel_size
, erels
,
553 Elf32_External_Rel
*, "relocs");
555 rel_size
= rel_size
/ sizeof (Elf32_External_Rel
);
557 rels
= (Elf_Internal_Rel
*)
558 malloc (rel_size
* sizeof (Elf_Internal_Rel
));
562 error(_("out of memory parsing relocs"));
566 for (i
= 0; i
< rel_size
; i
++)
568 rels
[i
].r_offset
= BYTE_GET (erels
[i
].r_offset
);
569 rels
[i
].r_info
= BYTE_GET (erels
[i
].r_info
);
574 relas
= (Elf_Internal_Rela
*) rels
;
578 Elf64_External_Rel
* erels
;
580 GET_DATA_ALLOC (rel_offset
, rel_size
, erels
,
581 Elf64_External_Rel
*, "relocs");
583 rel_size
= rel_size
/ sizeof (Elf64_External_Rel
);
585 rels
= (Elf_Internal_Rel
*)
586 malloc (rel_size
* sizeof (Elf_Internal_Rel
));
590 error(_("out of memory parsing relocs"));
594 for (i
= 0; i
< rel_size
; i
++)
596 rels
[i
].r_offset
= BYTE_GET8 (erels
[i
].r_offset
);
597 rels
[i
].r_info
= BYTE_GET8 (erels
[i
].r_info
);
602 relas
= (Elf_Internal_Rela
*) rels
;
608 (_(" Offset Info Type Symbol's Value Symbol's Name Addend\n"));
611 (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
613 for (i
= 0; i
< rel_size
; i
++)
618 bfd_vma symtab_index
;
623 offset
= relas
[i
].r_offset
;
624 info
= relas
[i
].r_info
;
628 offset
= rels
[i
].r_offset
;
629 info
= rels
[i
].r_info
;
634 type
= ELF32_R_TYPE (info
);
635 symtab_index
= ELF32_R_SYM (info
);
639 if (elf_header
.e_machine
== EM_SPARCV9
)
640 type
= ELF64_R_TYPE_ID (info
);
642 type
= ELF64_R_TYPE (info
);
643 /* The #ifdef BFD64 below is to prevent a compile time warning.
644 We know that if we do not have a 64 bit data type that we
645 will never execute this code anyway. */
647 symtab_index
= ELF64_R_SYM (info
);
651 #ifdef _bfd_int64_low
652 printf (" %8.8lx %5.5lx ", _bfd_int64_low (offset
), _bfd_int64_low (info
));
654 printf (" %8.8lx %5.5lx ", offset
, info
);
657 switch (elf_header
.e_machine
)
664 rtype
= elf_m32r_reloc_type (type
);
669 rtype
= elf_i386_reloc_type (type
);
673 rtype
= elf_m68k_reloc_type (type
);
677 rtype
= elf_i960_reloc_type (type
);
684 rtype
= elf_sparc_reloc_type (type
);
688 rtype
= v850_reloc_type (type
);
692 rtype
= elf_d10v_reloc_type (type
);
696 rtype
= elf_d30v_reloc_type (type
);
700 rtype
= elf_sh_reloc_type (type
);
703 case EM_CYGNUS_MN10300
:
704 rtype
= elf_mn10300_reloc_type (type
);
707 case EM_CYGNUS_MN10200
:
708 rtype
= elf_mn10200_reloc_type (type
);
712 rtype
= elf_fr30_reloc_type (type
);
716 rtype
= elf_mcore_reloc_type (type
);
720 rtype
= elf_ppc_reloc_type (type
);
725 rtype
= elf_mips_reloc_type (type
);
729 rtype
= elf_alpha_reloc_type (type
);
733 rtype
= elf_arm_reloc_type (type
);
737 rtype
= elf_arc_reloc_type (type
);
741 rtype
= elf_hppa_reloc_type (type
);
746 #ifdef _bfd_int64_low
747 printf (_("unrecognised: %-7lx"), _bfd_int64_low (type
));
749 printf (_("unrecognised: %-7lx"), type
);
752 printf ("%-21.21s", rtype
);
758 if (symtab_index
>= nsyms
)
759 printf (" bad symbol index: %08lx", (unsigned long) symtab_index
);
762 Elf_Internal_Sym
* psym
;
764 psym
= symtab
+ symtab_index
;
766 printf (" %08lx ", (unsigned long) psym
->st_value
);
768 if (psym
->st_name
== 0)
770 SECTION_NAME (section_headers
+ psym
->st_shndx
));
771 else if (strtab
== NULL
)
772 printf (_("<string table index %3ld>"), psym
->st_name
);
774 printf ("%-25.25s", strtab
+ psym
->st_name
);
777 printf (" + %lx", (unsigned long) relas
[i
].r_addend
);
782 printf ("%34c%lx", ' ', (unsigned long) relas
[i
].r_addend
);
784 if (elf_header
.e_machine
== EM_SPARCV9
785 && !strcmp (rtype
, "R_SPARC_OLO10"))
786 printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (info
));
797 get_mips_dynamic_type (type
)
802 case DT_MIPS_RLD_VERSION
: return "MIPS_RLD_VERSION";
803 case DT_MIPS_TIME_STAMP
: return "MIPS_TIME_STAMP";
804 case DT_MIPS_ICHECKSUM
: return "MIPS_ICHECKSUM";
805 case DT_MIPS_IVERSION
: return "MIPS_IVERSION";
806 case DT_MIPS_FLAGS
: return "MIPS_FLAGS";
807 case DT_MIPS_BASE_ADDRESS
: return "MIPS_BASE_ADDRESS";
808 case DT_MIPS_MSYM
: return "MIPS_MSYM";
809 case DT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
810 case DT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
811 case DT_MIPS_LOCAL_GOTNO
: return "MIPS_LOCAL_GOTNO";
812 case DT_MIPS_CONFLICTNO
: return "MIPS_CONFLICTNO";
813 case DT_MIPS_LIBLISTNO
: return "MIPS_LIBLISTNO";
814 case DT_MIPS_SYMTABNO
: return "MIPS_SYMTABNO";
815 case DT_MIPS_UNREFEXTNO
: return "MIPS_UNREFEXTNO";
816 case DT_MIPS_GOTSYM
: return "MIPS_GOTSYM";
817 case DT_MIPS_HIPAGENO
: return "MIPS_HIPAGENO";
818 case DT_MIPS_RLD_MAP
: return "MIPS_RLD_MAP";
819 case DT_MIPS_DELTA_CLASS
: return "MIPS_DELTA_CLASS";
820 case DT_MIPS_DELTA_CLASS_NO
: return "MIPS_DELTA_CLASS_NO";
821 case DT_MIPS_DELTA_INSTANCE
: return "MIPS_DELTA_INSTANCE";
822 case DT_MIPS_DELTA_INSTANCE_NO
: return "MIPS_DELTA_INSTANCE_NO";
823 case DT_MIPS_DELTA_RELOC
: return "MIPS_DELTA_RELOC";
824 case DT_MIPS_DELTA_RELOC_NO
: return "MIPS_DELTA_RELOC_NO";
825 case DT_MIPS_DELTA_SYM
: return "MIPS_DELTA_SYM";
826 case DT_MIPS_DELTA_SYM_NO
: return "MIPS_DELTA_SYM_NO";
827 case DT_MIPS_DELTA_CLASSSYM
: return "MIPS_DELTA_CLASSSYM";
828 case DT_MIPS_DELTA_CLASSSYM_NO
: return "MIPS_DELTA_CLASSSYM_NO";
829 case DT_MIPS_CXX_FLAGS
: return "MIPS_CXX_FLAGS";
830 case DT_MIPS_PIXIE_INIT
: return "MIPS_PIXIE_INIT";
831 case DT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
832 case DT_MIPS_LOCALPAGE_GOTIDX
: return "MIPS_LOCALPAGE_GOTIDX";
833 case DT_MIPS_LOCAL_GOTIDX
: return "MIPS_LOCAL_GOTIDX";
834 case DT_MIPS_HIDDEN_GOTIDX
: return "MIPS_HIDDEN_GOTIDX";
835 case DT_MIPS_PROTECTED_GOTIDX
: return "MIPS_PROTECTED_GOTIDX";
836 case DT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
837 case DT_MIPS_INTERFACE
: return "MIPS_INTERFACE";
838 case DT_MIPS_DYNSTR_ALIGN
: return "MIPS_DYNSTR_ALIGN";
839 case DT_MIPS_INTERFACE_SIZE
: return "MIPS_INTERFACE_SIZE";
840 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR
: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
841 case DT_MIPS_PERF_SUFFIX
: return "MIPS_PERF_SUFFIX";
842 case DT_MIPS_COMPACT_SIZE
: return "MIPS_COMPACT_SIZE";
843 case DT_MIPS_GP_VALUE
: return "MIPS_GP_VALUE";
844 case DT_MIPS_AUX_DYNAMIC
: return "MIPS_AUX_DYNAMIC";
851 get_sparc64_dynamic_type (type
)
856 case DT_SPARC_REGISTER
: return "SPARC_REGISTER";
863 get_dynamic_type (type
)
866 static char buff
[32];
870 case DT_NULL
: return "NULL";
871 case DT_NEEDED
: return "NEEDED";
872 case DT_PLTRELSZ
: return "PLTRELSZ";
873 case DT_PLTGOT
: return "PLTGOT";
874 case DT_HASH
: return "HASH";
875 case DT_STRTAB
: return "STRTAB";
876 case DT_SYMTAB
: return "SYMTAB";
877 case DT_RELA
: return "RELA";
878 case DT_RELASZ
: return "RELASZ";
879 case DT_RELAENT
: return "RELAENT";
880 case DT_STRSZ
: return "STRSZ";
881 case DT_SYMENT
: return "SYMENT";
882 case DT_INIT
: return "INIT";
883 case DT_FINI
: return "FINI";
884 case DT_SONAME
: return "SONAME";
885 case DT_RPATH
: return "RPATH";
886 case DT_SYMBOLIC
: return "SYMBOLIC";
887 case DT_REL
: return "REL";
888 case DT_RELSZ
: return "RELSZ";
889 case DT_RELENT
: return "RELENT";
890 case DT_PLTREL
: return "PLTREL";
891 case DT_DEBUG
: return "DEBUG";
892 case DT_TEXTREL
: return "TEXTREL";
893 case DT_JMPREL
: return "JMPREL";
894 case DT_BIND_NOW
: return "BIND_NOW";
895 case DT_INIT_ARRAY
: return "INIT_ARRAY";
896 case DT_FINI_ARRAY
: return "FINI_ARRAY";
897 case DT_INIT_ARRAYSZ
: return "INIT_ARRAYSZ";
898 case DT_FINI_ARRAYSZ
: return "FINI_ARRAYSZ";
900 case DT_PLTPADSZ
: return "PLTPADSZ";
901 case DT_MOVEENT
: return "MOVEENT";
902 case DT_MOVESZ
: return "MOVESZ";
903 case DT_FEATURE_1
: return "FEATURE_1";
904 case DT_POSFLAG_1
: return "POSFLAG_1";
905 case DT_SYMINSZ
: return "SYMINSZ";
906 case DT_SYMINENT
: return "SYMINENT"; /* aka VALRNGHI */
908 case DT_ADDRRNGLO
: return "ADDRRNGLO";
909 case DT_SYMINFO
: return "SYMINFO"; /* aka ADDRRNGHI */
911 case DT_VERSYM
: return "VERSYM";
913 case DT_RELACOUNT
: return "RELACOUNT";
914 case DT_RELCOUNT
: return "RELCOUNT";
915 case DT_FLAGS_1
: return "FLAGS_1";
916 case DT_VERDEF
: return "VERDEF";
917 case DT_VERDEFNUM
: return "VERDEFNUM";
918 case DT_VERNEED
: return "VERNEED";
919 case DT_VERNEEDNUM
: return "VERNEEDNUM";
921 case DT_AUXILIARY
: return "AUXILARY";
922 case DT_USED
: return "USED";
923 case DT_FILTER
: return "FILTER";
926 if ((type
>= DT_LOPROC
) && (type
<= DT_HIPROC
))
930 switch (elf_header
.e_machine
)
934 result
= get_mips_dynamic_type (type
);
937 result
= get_sparc64_dynamic_type (type
);
947 sprintf (buff
, _("Processor Specific: %lx"), type
);
949 else if ((type
>= DT_LOOS
) && (type
<= DT_HIOS
))
950 sprintf (buff
, _("Operating System specific: %lx"), type
);
952 sprintf (buff
, _("<unknown>: %lx"), type
);
959 get_file_type (e_type
)
962 static char buff
[32];
966 case ET_NONE
: return _("NONE (None)");
967 case ET_REL
: return _("REL (Relocatable file)");
968 case ET_EXEC
: return _("EXEC (Executable file)");
969 case ET_DYN
: return _("DYN (Shared object file)");
970 case ET_CORE
: return _("CORE (Core file)");
973 if ((e_type
>= ET_LOPROC
) && (e_type
<= ET_HIPROC
))
974 sprintf (buff
, _("Processor Specific: (%x)"), e_type
);
975 else if ((e_type
>= ET_LOOS
) && (e_type
<= ET_HIOS
))
976 sprintf (buff
, _("OS Specific: (%x)"), e_type
);
978 sprintf (buff
, _("<unknown>: %x"), e_type
);
984 get_machine_name (e_machine
)
987 static char buff
[32];
991 case EM_NONE
: return _("None");
992 case EM_M32
: return "WE32100";
993 case EM_SPARC
: return "Sparc";
994 case EM_386
: return "Intel 80386";
995 case EM_68K
: return "MC68000";
996 case EM_88K
: return "MC88000";
997 case EM_486
: return "Intel 80486";
998 case EM_860
: return "Intel 80860";
999 case EM_MIPS
: return "MIPS R3000 big-endian";
1000 case EM_S370
: return "Amdahl";
1001 case EM_MIPS_RS4_BE
: return "MIPS R4000 big-endian";
1002 case EM_OLD_SPARCV9
: return "Sparc v9 (old)";
1003 case EM_PARISC
: return "HPPA";
1004 case EM_PPC_OLD
: return "Power PC (old)";
1005 case EM_SPARC32PLUS
: return "Sparc v8+" ;
1006 case EM_960
: return "Intel 90860";
1007 case EM_PPC
: return "PowerPC";
1008 case EM_V800
: return "NEC V800";
1009 case EM_FR20
: return "Fujitsu FR20";
1010 case EM_RH32
: return "TRW RH32";
1011 case EM_MCORE
: return "MCORE";
1012 case EM_ARM
: return "ARM";
1013 case EM_OLD_ALPHA
: return "Digital Alpha (old)";
1014 case EM_SH
: return "Hitachi SH";
1015 case EM_SPARCV9
: return "Sparc v9";
1016 case EM_TRICORE
: return "Siemens Tricore";
1017 case EM_ARC
: return "Argonaut RISC Core";
1018 case EM_H8_300
: return "Hitachi H8/300";
1019 case EM_H8_300H
: return "Hitachi H8/300H";
1020 case EM_H8S
: return "Hitachi H8S";
1021 case EM_H8_500
: return "Hitachi H8/500";
1022 case EM_IA_64
: return "Intel Merced";
1023 case EM_MIPS_X
: return "Stanford MIPS-X";
1024 case EM_COLDFIRE
: return "Motorola Coldfire";
1025 case EM_68HC12
: return "Motorola M68HC12";
1026 case EM_ALPHA
: return "Alpha";
1027 case EM_CYGNUS_D10V
: return "d10v";
1028 case EM_CYGNUS_D30V
: return "d30v";
1029 case EM_CYGNUS_ARC
: return "Arc";
1030 case EM_CYGNUS_M32R
: return "Mitsubishi M32r";
1031 case EM_CYGNUS_V850
: return "NEC v850";
1032 case EM_CYGNUS_MN10300
: return "mn10300";
1033 case EM_CYGNUS_MN10200
: return "mn10200";
1034 case EM_CYGNUS_FR30
: return "Fujitsu FR30";
1037 sprintf (buff
, _("<unknown>: %x"), e_machine
);
1043 get_machine_flags (e_flags
, e_machine
)
1047 static char buf
[1024];
1058 if (e_flags
& EF_CPU32
)
1059 strcat (buf
, ", cpu32");
1063 if (e_flags
& EF_PPC_EMB
)
1064 strcat (buf
, ", emb");
1066 if (e_flags
& EF_PPC_RELOCATABLE
)
1067 strcat (buf
, ", relocatable");
1069 if (e_flags
& EF_PPC_RELOCATABLE_LIB
)
1070 strcat (buf
, ", relocatable-lib");
1073 case EM_CYGNUS_V850
:
1074 switch (e_flags
& EF_V850_ARCH
)
1077 strcat (buf
, ", v850e");
1080 strcat (buf
, ", v850ea");
1083 strcat (buf
, ", v850");
1086 strcat (buf
, ", unknown v850 architecture variant");
1091 case EM_CYGNUS_M32R
:
1092 if ((e_flags
& EF_M32R_ARCH
) == E_M32R_ARCH
)
1093 strcat (buf
, ", m32r");
1098 case EM_MIPS_RS4_BE
:
1099 if (e_flags
& EF_MIPS_NOREORDER
)
1100 strcat (buf
, ", noreorder");
1102 if (e_flags
& EF_MIPS_PIC
)
1103 strcat (buf
, ", pic");
1105 if (e_flags
& EF_MIPS_CPIC
)
1106 strcat (buf
, ", cpic");
1108 if (e_flags
& EF_MIPS_ABI2
)
1109 strcat (buf
, ", abi2");
1111 if ((e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_1
)
1112 strcat (buf
, ", mips1");
1114 if ((e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_2
)
1115 strcat (buf
, ", mips2");
1117 if ((e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_3
)
1118 strcat (buf
, ", mips3");
1120 if ((e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_4
)
1121 strcat (buf
, ", mips4");
1125 if (e_flags
& EF_SPARC_32PLUS
)
1126 strcat (buf
, ", v8+");
1128 if (e_flags
& EF_SPARC_SUN_US1
)
1129 strcat (buf
, ", ultrasparcI");
1131 if (e_flags
& EF_SPARC_SUN_US3
)
1132 strcat (buf
, ", ultrasparcIII");
1134 if (e_flags
& EF_SPARC_HAL_R1
)
1135 strcat (buf
, ", halr1");
1137 if (e_flags
& EF_SPARC_LEDATA
)
1138 strcat (buf
, ", ledata");
1140 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_TSO
)
1141 strcat (buf
, ", tso");
1143 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_PSO
)
1144 strcat (buf
, ", pso");
1146 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_RMO
)
1147 strcat (buf
, ", rmo");
1156 get_mips_segment_type (type
)
1161 case PT_MIPS_REGINFO
:
1163 case PT_MIPS_RTPROC
:
1165 case PT_MIPS_OPTIONS
:
1175 get_segment_type (p_type
)
1176 unsigned long p_type
;
1178 static char buff
[32];
1182 case PT_NULL
: return "NULL";
1183 case PT_LOAD
: return "LOAD";
1184 case PT_DYNAMIC
: return "DYNAMIC";
1185 case PT_INTERP
: return "INTERP";
1186 case PT_NOTE
: return "NOTE";
1187 case PT_SHLIB
: return "SHLIB";
1188 case PT_PHDR
: return "PHDR";
1191 if ((p_type
>= PT_LOPROC
) && (p_type
<= PT_HIPROC
))
1193 const char * result
;
1195 switch (elf_header
.e_machine
)
1198 case EM_MIPS_RS4_BE
:
1199 result
= get_mips_segment_type (p_type
);
1209 sprintf (buff
, "LOPROC+%lx", p_type
- PT_LOPROC
);
1211 else if ((p_type
>= PT_LOOS
) && (p_type
<= PT_HIOS
))
1212 sprintf (buff
, "LOOS+%lx", p_type
- PT_LOOS
);
1214 sprintf (buff
, _("<unknown>: %lx"), p_type
);
1221 get_mips_section_type_name (sh_type
)
1222 unsigned int sh_type
;
1226 case SHT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
1227 case SHT_MIPS_MSYM
: return "MIPS_MSYM";
1228 case SHT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
1229 case SHT_MIPS_GPTAB
: return "MIPS_GPTAB";
1230 case SHT_MIPS_UCODE
: return "MIPS_UCODE";
1231 case SHT_MIPS_DEBUG
: return "MIPS_DEBUG";
1232 case SHT_MIPS_REGINFO
: return "MIPS_REGINFO";
1233 case SHT_MIPS_PACKAGE
: return "MIPS_PACKAGE";
1234 case SHT_MIPS_PACKSYM
: return "MIPS_PACKSYM";
1235 case SHT_MIPS_RELD
: return "MIPS_RELD";
1236 case SHT_MIPS_IFACE
: return "MIPS_IFACE";
1237 case SHT_MIPS_CONTENT
: return "MIPS_CONTENT";
1238 case SHT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
1239 case SHT_MIPS_SHDR
: return "MIPS_SHDR";
1240 case SHT_MIPS_FDESC
: return "MIPS_FDESC";
1241 case SHT_MIPS_EXTSYM
: return "MIPS_EXTSYM";
1242 case SHT_MIPS_DENSE
: return "MIPS_DENSE";
1243 case SHT_MIPS_PDESC
: return "MIPS_PDESC";
1244 case SHT_MIPS_LOCSYM
: return "MIPS_LOCSYM";
1245 case SHT_MIPS_AUXSYM
: return "MIPS_AUXSYM";
1246 case SHT_MIPS_OPTSYM
: return "MIPS_OPTSYM";
1247 case SHT_MIPS_LOCSTR
: return "MIPS_LOCSTR";
1248 case SHT_MIPS_LINE
: return "MIPS_LINE";
1249 case SHT_MIPS_RFDESC
: return "MIPS_RFDESC";
1250 case SHT_MIPS_DELTASYM
: return "MIPS_DELTASYM";
1251 case SHT_MIPS_DELTAINST
: return "MIPS_DELTAINST";
1252 case SHT_MIPS_DELTACLASS
: return "MIPS_DELTACLASS";
1253 case SHT_MIPS_DWARF
: return "MIPS_DWARF";
1254 case SHT_MIPS_DELTADECL
: return "MIPS_DELTADECL";
1255 case SHT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
1256 case SHT_MIPS_EVENTS
: return "MIPS_EVENTS";
1257 case SHT_MIPS_TRANSLATE
: return "MIPS_TRANSLATE";
1258 case SHT_MIPS_PIXIE
: return "MIPS_PIXIE";
1259 case SHT_MIPS_XLATE
: return "MIPS_XLATE";
1260 case SHT_MIPS_XLATE_DEBUG
: return "MIPS_XLATE_DEBUG";
1261 case SHT_MIPS_WHIRL
: return "MIPS_WHIRL";
1262 case SHT_MIPS_EH_REGION
: return "MIPS_EH_REGION";
1263 case SHT_MIPS_XLATE_OLD
: return "MIPS_XLATE_OLD";
1264 case SHT_MIPS_PDR_EXCEPTION
: return "MIPS_PDR_EXCEPTION";
1272 get_section_type_name (sh_type
)
1273 unsigned int sh_type
;
1275 static char buff
[32];
1279 case SHT_NULL
: return "NULL";
1280 case SHT_PROGBITS
: return "PROGBITS";
1281 case SHT_SYMTAB
: return "SYMTAB";
1282 case SHT_STRTAB
: return "STRTAB";
1283 case SHT_RELA
: return "RELA";
1284 case SHT_HASH
: return "HASH";
1285 case SHT_DYNAMIC
: return "DYNAMIC";
1286 case SHT_NOTE
: return "NOTE";
1287 case SHT_NOBITS
: return "NOBITS";
1288 case SHT_REL
: return "REL";
1289 case SHT_SHLIB
: return "SHLIB";
1290 case SHT_DYNSYM
: return "DYNSYM";
1291 case SHT_GNU_verdef
: return "VERDEF";
1292 case SHT_GNU_verneed
: return "VERNEED";
1293 case SHT_GNU_versym
: return "VERSYM";
1294 case 0x6ffffff0: return "VERSYM";
1295 case 0x6ffffffc: return "VERDEF";
1296 case 0x7ffffffd: return "AUXILIARY";
1297 case 0x7fffffff: return "FILTER";
1300 if ((sh_type
>= SHT_LOPROC
) && (sh_type
<= SHT_HIPROC
))
1302 const char * result
;
1304 switch (elf_header
.e_machine
)
1307 case EM_MIPS_RS4_BE
:
1308 result
= get_mips_section_type_name (sh_type
);
1318 sprintf (buff
, "SHT_LOPROC+%x", sh_type
- SHT_LOPROC
);
1320 else if ((sh_type
>= SHT_LOOS
) && (sh_type
<= SHT_HIOS
))
1321 sprintf (buff
, "SHT_LOOS+%x", sh_type
- SHT_LOOS
);
1322 else if ((sh_type
>= SHT_LOUSER
) && (sh_type
<= SHT_HIUSER
))
1323 sprintf (buff
, "SHT_LOUSER+%x", sh_type
- SHT_LOUSER
);
1325 sprintf (buff
, _("<unknown>: %x"), sh_type
);
1331 struct option options
[] =
1333 {"all", no_argument
, 0, 'a'},
1334 {"file-header", no_argument
, 0, 'h'},
1335 {"program-headers", no_argument
, 0, 'l'},
1336 {"headers", no_argument
, 0, 'e'},
1337 {"histogram", no_argument
, 0, 'I'},
1338 {"segments", no_argument
, 0, 'l'},
1339 {"sections", no_argument
, 0, 'S'},
1340 {"section-headers", no_argument
, 0, 'S'},
1341 {"symbols", no_argument
, 0, 's'},
1342 {"syms", no_argument
, 0, 's'},
1343 {"relocs", no_argument
, 0, 'r'},
1344 {"notes", no_argument
, 0, 'n'},
1345 {"dynamic", no_argument
, 0, 'd'},
1346 {"arch-specific", no_argument
, 0, 'A'},
1347 {"version-info", no_argument
, 0, 'V'},
1348 {"use-dynamic", no_argument
, 0, 'D'},
1349 {"hex-dump", required_argument
, 0, 'x'},
1350 {"debug-dump", optional_argument
, 0, 'w'},
1351 #ifdef SUPPORT_DISASSEMBLY
1352 {"instruction-dump", required_argument
, 0, 'i'},
1355 {"version", no_argument
, 0, 'v'},
1356 {"help", no_argument
, 0, 'H'},
1357 {0, no_argument
, 0, 0}
1363 fprintf (stdout
, _("Usage: readelf {options} elf-file(s)\n"));
1364 fprintf (stdout
, _(" Options are:\n"));
1365 fprintf (stdout
, _(" -a or --all Equivalent to: -h -l -S -s -r -d -V -A -I\n"));
1366 fprintf (stdout
, _(" -h or --file-header Display the ELF file header\n"));
1367 fprintf (stdout
, _(" -l or --program-headers or --segments\n"));
1368 fprintf (stdout
, _(" Display the program headers\n"));
1369 fprintf (stdout
, _(" -S or --section-headers or --sections\n"));
1370 fprintf (stdout
, _(" Display the sections' header\n"));
1371 fprintf (stdout
, _(" -e or --headers Equivalent to: -h -l -S\n"));
1372 fprintf (stdout
, _(" -s or --syms or --symbols Display the symbol table\n"));
1373 fprintf (stdout
, _(" -n or --notes Display the core notes (if present)\n"));
1374 fprintf (stdout
, _(" -r or --relocs Display the relocations (if present)\n"));
1375 fprintf (stdout
, _(" -d or --dynamic Display the dynamic segment (if present)\n"));
1376 fprintf (stdout
, _(" -V or --version-info Display the version sections (if present)\n"));
1377 fprintf (stdout
, _(" -A or --arch-specific Display architecture specific information (if any).\n"));
1378 fprintf (stdout
, _(" -D or --use-dynamic Use the dynamic section info when displaying symbols\n"));
1379 fprintf (stdout
, _(" -x <number> or --hex-dump=<number>\n"));
1380 fprintf (stdout
, _(" Dump the contents of section <number>\n"));
1381 fprintf (stdout
, _(" -w[liapr] or --debug-dump[=line,=info,=abbrev,=pubnames,=ranges]\n"));
1382 fprintf (stdout
, _(" Display the contents of DWARF2 debug sections\n"));
1383 #ifdef SUPPORT_DISASSEMBLY
1384 fprintf (stdout
, _(" -i <number> or --instruction-dump=<number>\n"));
1385 fprintf (stdout
, _(" Disassemble the contents of section <number>\n"));
1387 fprintf (stdout
, _(" -I or --histogram Display histogram of bucket list lengths\n"));
1388 fprintf (stdout
, _(" -v or --version Display the version number of readelf\n"));
1389 fprintf (stdout
, _(" -H or --help Display this information\n"));
1390 fprintf (stdout
, _("Report bugs to bug-gnu-utils@gnu.org\n"));
1396 request_dump (section
, type
)
1397 unsigned int section
;
1400 if (section
>= num_dump_sects
)
1402 char * new_dump_sects
;
1404 new_dump_sects
= (char *) calloc (section
+ 1, 1);
1406 if (new_dump_sects
== NULL
)
1407 error (_("Out of memory allocating dump request table."));
1410 /* Copy current flag settings. */
1411 memcpy (new_dump_sects
, dump_sects
, num_dump_sects
);
1415 dump_sects
= new_dump_sects
;
1416 num_dump_sects
= section
+ 1;
1421 dump_sects
[section
] |= type
;
1427 parse_args (argc
, argv
)
1436 while ((c
= getopt_long
1437 (argc
, argv
, "ersahnldSDAIw::x:i:vV", options
, NULL
)) != EOF
)
1472 do_using_dynamic
++;
1500 section
= strtoul (optarg
, & cp
, 0);
1501 if (! * cp
&& section
>= 0)
1503 request_dump (section
, HEX_DUMP
);
1523 do_debug_abbrevs
= 1;
1533 do_debug_pubnames
= 1;
1538 do_debug_aranges
= 1;
1542 warn (_("Unrecognised debug option '%s'\n"), optarg
);
1547 #ifdef SUPPORT_DISASSEMBLY
1550 section
= strtoul (optarg
, & cp
, 0);
1551 if (! * cp
&& section
>= 0)
1553 request_dump (section
, DISASS_DUMP
);
1559 print_version (program_name
);
1566 /* xgettext:c-format */
1567 error (_("Invalid option '-%c'\n"), c
);
1574 if (!do_dynamic
&& !do_syms
&& !do_reloc
&& !do_sections
1575 && !do_segments
&& !do_header
&& !do_dump
&& !do_version
1576 && !do_histogram
&& !do_debugging
&& !do_arch
&& !do_notes
)
1580 warn (_("Nothing to do.\n"));
1586 get_elf_class (elf_class
)
1587 unsigned char elf_class
;
1589 static char buff
[32];
1593 case ELFCLASSNONE
: return _("none");
1594 case ELFCLASS32
: return _("ELF32");
1595 case ELFCLASS64
: return _("ELF64");
1597 sprintf (buff
, _("<unknown: %x>"), elf_class
);
1603 get_data_encoding (encoding
)
1604 unsigned char encoding
;
1606 static char buff
[32];
1610 case ELFDATANONE
: return _("none");
1611 case ELFDATA2LSB
: return _("2's complement, little endian");
1612 case ELFDATA2MSB
: return _("2's complement, big endian");
1614 sprintf (buff
, _("<unknown: %x>"), encoding
);
1620 get_osabi_name (osabi
)
1621 unsigned char osabi
;
1623 static char buff
[32];
1627 case ELFOSABI_SYSV
: return _("UNIX - System V");
1628 case ELFOSABI_HPUX
: return _("UNIX - HP-UX");
1629 case ELFOSABI_STANDALONE
: return _("Standalone App");
1631 sprintf (buff
, _("<unknown: %x>"), osabi
);
1636 /* Decode the data held in 'elf_header'. */
1638 process_file_header ()
1640 if ( elf_header
.e_ident
[EI_MAG0
] != ELFMAG0
1641 || elf_header
.e_ident
[EI_MAG1
] != ELFMAG1
1642 || elf_header
.e_ident
[EI_MAG2
] != ELFMAG2
1643 || elf_header
.e_ident
[EI_MAG3
] != ELFMAG3
)
1646 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
1654 printf (_("ELF Header:\n"));
1655 printf (_(" Magic: "));
1656 for (i
= 0; i
< EI_NIDENT
; i
++)
1657 printf ("%2.2x ", elf_header
.e_ident
[i
]);
1659 printf (_(" Class: %s\n"),
1660 get_elf_class (elf_header
.e_ident
[EI_CLASS
]));
1661 printf (_(" Data: %s\n"),
1662 get_data_encoding (elf_header
.e_ident
[EI_DATA
]));
1663 printf (_(" Version: %d %s\n"),
1664 elf_header
.e_ident
[EI_VERSION
],
1665 (elf_header
.e_ident
[EI_VERSION
] == EV_CURRENT
1667 : (elf_header
.e_ident
[EI_VERSION
] != EV_NONE
1670 printf (_(" OS/ABI: %s\n"),
1671 get_osabi_name (elf_header
.e_ident
[EI_OSABI
]));
1672 printf (_(" ABI Version: %d\n"),
1673 elf_header
.e_ident
[EI_ABIVERSION
]);
1674 printf (_(" Type: %s\n"),
1675 get_file_type (elf_header
.e_type
));
1676 printf (_(" Machine: %s\n"),
1677 get_machine_name (elf_header
.e_machine
));
1678 printf (_(" Version: 0x%lx\n"),
1679 (unsigned long) elf_header
.e_version
);
1680 printf (_(" Entry point address: 0x%lx\n"),
1681 (unsigned long) elf_header
.e_entry
);
1682 printf (_(" Start of program headers: %ld (bytes into file)\n"),
1683 (long) elf_header
.e_phoff
);
1684 printf (_(" Start of section headers: %ld (bytes into file)\n"),
1685 (long) elf_header
.e_shoff
);
1686 printf (_(" Flags: 0x%lx%s\n"),
1687 (unsigned long) elf_header
.e_flags
,
1688 get_machine_flags (elf_header
.e_flags
, elf_header
.e_machine
));
1689 printf (_(" Size of this header: %ld (bytes)\n"),
1690 (long) elf_header
.e_ehsize
);
1691 printf (_(" Size of program headers: %ld (bytes)\n"),
1692 (long) elf_header
.e_phentsize
);
1693 printf (_(" Number of program headers: %ld\n"),
1694 (long) elf_header
.e_phnum
);
1695 printf (_(" Size of section headers: %ld (bytes)\n"),
1696 (long) elf_header
.e_shentsize
);
1697 printf (_(" Number of section headers: %ld\n"),
1698 (long) elf_header
.e_shnum
);
1699 printf (_(" Section header string table index: %ld\n"),
1700 (long) elf_header
.e_shstrndx
);
1708 get_32bit_program_headers (file
, program_headers
)
1710 Elf_Internal_Phdr
* program_headers
;
1712 Elf32_External_Phdr
* phdrs
;
1713 Elf32_External_Phdr
* external
;
1714 Elf32_Internal_Phdr
* internal
;
1717 GET_DATA_ALLOC (elf_header
.e_phoff
,
1718 elf_header
.e_phentsize
* elf_header
.e_phnum
,
1719 phdrs
, Elf32_External_Phdr
*, "program headers");
1721 for (i
= 0, internal
= program_headers
, external
= phdrs
;
1722 i
< elf_header
.e_phnum
;
1723 i
++, internal
++, external
++)
1725 internal
->p_type
= BYTE_GET (external
->p_type
);
1726 internal
->p_offset
= BYTE_GET (external
->p_offset
);
1727 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
1728 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
1729 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
1730 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
1731 internal
->p_flags
= BYTE_GET (external
->p_flags
);
1732 internal
->p_align
= BYTE_GET (external
->p_align
);
1741 get_64bit_program_headers (file
, program_headers
)
1743 Elf_Internal_Phdr
* program_headers
;
1745 Elf64_External_Phdr
* phdrs
;
1746 Elf64_External_Phdr
* external
;
1747 Elf64_Internal_Phdr
* internal
;
1750 GET_DATA_ALLOC (elf_header
.e_phoff
,
1751 elf_header
.e_phentsize
* elf_header
.e_phnum
,
1752 phdrs
, Elf64_External_Phdr
*, "program headers");
1754 for (i
= 0, internal
= program_headers
, external
= phdrs
;
1755 i
< elf_header
.e_phnum
;
1756 i
++, internal
++, external
++)
1758 internal
->p_type
= BYTE_GET (external
->p_type
);
1759 internal
->p_flags
= BYTE_GET (external
->p_flags
);
1760 internal
->p_offset
= BYTE_GET8 (external
->p_offset
);
1761 internal
->p_vaddr
= BYTE_GET8 (external
->p_vaddr
);
1762 internal
->p_paddr
= BYTE_GET8 (external
->p_paddr
);
1763 internal
->p_filesz
= BYTE_GET8 (external
->p_filesz
);
1764 internal
->p_memsz
= BYTE_GET8 (external
->p_memsz
);
1765 internal
->p_align
= BYTE_GET8 (external
->p_align
);
1774 process_program_headers (file
)
1777 Elf_Internal_Phdr
* program_headers
;
1778 Elf_Internal_Phdr
* segment
;
1781 if (elf_header
.e_phnum
== 0)
1784 printf (_("\nThere are no program headers in this file.\n"));
1788 if (do_segments
&& !do_header
)
1790 printf (_("\nElf file is %s\n"), get_file_type (elf_header
.e_type
));
1791 printf (_("Entry point 0x%lx\n"), (unsigned long) elf_header
.e_entry
);
1792 printf (_("There are %d program headers, starting at offset %lx:\n"),
1793 elf_header
.e_phnum
, (unsigned long) elf_header
.e_phoff
);
1796 program_headers
= (Elf_Internal_Phdr
*) malloc
1797 (elf_header
.e_phnum
* sizeof (Elf_Internal_Phdr
));
1799 if (program_headers
== NULL
)
1801 error (_("Out of memory\n"));
1806 i
= get_32bit_program_headers (file
, program_headers
);
1808 i
= get_64bit_program_headers (file
, program_headers
);
1812 free (program_headers
);
1819 (_("\nProgram Header%s:\n"), elf_header
.e_phnum
> 1 ? "s" : "");
1821 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
1828 for (i
= 0, segment
= program_headers
;
1829 i
< elf_header
.e_phnum
;
1834 printf (" %-11.11s ", get_segment_type (segment
->p_type
));
1835 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
1836 printf ("0x%8.8lx ", (unsigned long) segment
->p_vaddr
);
1837 printf ("0x%8.8lx ", (unsigned long) segment
->p_paddr
);
1838 printf ("0x%5.5lx ", (unsigned long) segment
->p_filesz
);
1839 printf ("0x%5.5lx ", (unsigned long) segment
->p_memsz
);
1841 (segment
->p_flags
& PF_R
? 'R' : ' '),
1842 (segment
->p_flags
& PF_W
? 'W' : ' '),
1843 (segment
->p_flags
& PF_X
? 'E' : ' '));
1844 printf ("%#lx", (unsigned long) segment
->p_align
);
1847 switch (segment
->p_type
)
1851 loadaddr
= (segment
->p_vaddr
& 0xfffff000)
1852 - (segment
->p_offset
& 0xfffff000);
1857 error (_("more than one dynamic segment\n"));
1859 dynamic_addr
= segment
->p_offset
;
1860 dynamic_size
= segment
->p_filesz
;
1864 if (fseek (file
, segment
->p_offset
, SEEK_SET
))
1865 error (_("Unable to find program interpreter name\n"));
1868 program_interpreter
[0] = 0;
1869 fscanf (file
, "%63s", program_interpreter
);
1872 printf (_("\n [Requesting program interpreter: %s]"),
1873 program_interpreter
);
1879 putc ('\n', stdout
);
1888 if (do_segments
&& section_headers
!= NULL
)
1890 printf (_("\n Section to Segment mapping:\n"));
1891 printf (_(" Segment Sections...\n"));
1893 assert (string_table
!= NULL
);
1895 for (i
= 0; i
< elf_header
.e_phnum
; i
++)
1898 Elf_Internal_Shdr
* section
;
1900 segment
= program_headers
+ i
;
1901 section
= section_headers
;
1903 printf (" %2.2d ", i
);
1905 for (j
= 0; j
< elf_header
.e_shnum
; j
++, section
++)
1907 if (section
->sh_size
> 0
1908 /* Compare allocated sections by VMA, unallocated
1909 sections by file offset. */
1910 && (section
->sh_flags
& SHF_ALLOC
1911 ? (section
->sh_addr
>= segment
->p_vaddr
1912 && section
->sh_addr
+ section
->sh_size
1913 <= segment
->p_vaddr
+ segment
->p_memsz
)
1914 : ((bfd_vma
) section
->sh_offset
>= segment
->p_offset
1915 && (section
->sh_offset
+ section
->sh_size
1916 <= segment
->p_offset
+ segment
->p_filesz
))))
1917 printf ("%s ", SECTION_NAME (section
));
1924 free (program_headers
);
1931 get_32bit_section_headers (file
)
1934 Elf32_External_Shdr
* shdrs
;
1935 Elf32_Internal_Shdr
* internal
;
1938 GET_DATA_ALLOC (elf_header
.e_shoff
,
1939 elf_header
.e_shentsize
* elf_header
.e_shnum
,
1940 shdrs
, Elf32_External_Shdr
*, "section headers");
1942 section_headers
= (Elf_Internal_Shdr
*) malloc
1943 (elf_header
.e_shnum
* sizeof (Elf_Internal_Shdr
));
1945 if (section_headers
== NULL
)
1947 error (_("Out of memory\n"));
1951 for (i
= 0, internal
= section_headers
;
1952 i
< elf_header
.e_shnum
;
1955 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
1956 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
1957 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
1958 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
1959 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
1960 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
1961 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
1962 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
1963 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
1964 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
1973 get_64bit_section_headers (file
)
1976 Elf64_External_Shdr
* shdrs
;
1977 Elf64_Internal_Shdr
* internal
;
1980 GET_DATA_ALLOC (elf_header
.e_shoff
,
1981 elf_header
.e_shentsize
* elf_header
.e_shnum
,
1982 shdrs
, Elf64_External_Shdr
*, "section headers");
1984 section_headers
= (Elf_Internal_Shdr
*) malloc
1985 (elf_header
.e_shnum
* sizeof (Elf_Internal_Shdr
));
1987 if (section_headers
== NULL
)
1989 error (_("Out of memory\n"));
1993 for (i
= 0, internal
= section_headers
;
1994 i
< elf_header
.e_shnum
;
1997 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
1998 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
1999 internal
->sh_flags
= BYTE_GET8 (shdrs
[i
].sh_flags
);
2000 internal
->sh_addr
= BYTE_GET8 (shdrs
[i
].sh_addr
);
2001 internal
->sh_size
= BYTE_GET8 (shdrs
[i
].sh_size
);
2002 internal
->sh_entsize
= BYTE_GET8 (shdrs
[i
].sh_entsize
);
2003 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
2004 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
2005 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
2006 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
2014 static Elf_Internal_Sym
*
2015 get_32bit_elf_symbols (file
, offset
, number
)
2017 unsigned long offset
;
2018 unsigned long number
;
2020 Elf32_External_Sym
* esyms
;
2021 Elf_Internal_Sym
* isyms
;
2022 Elf_Internal_Sym
* psym
;
2025 GET_DATA_ALLOC (offset
, number
* sizeof (Elf32_External_Sym
),
2026 esyms
, Elf32_External_Sym
*, "symbols");
2028 isyms
= (Elf_Internal_Sym
*) malloc (number
* sizeof (Elf_Internal_Sym
));
2032 error (_("Out of memory\n"));
2038 for (j
= 0, psym
= isyms
;
2042 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
2043 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
2044 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
2045 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
2046 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
2047 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
2055 static Elf_Internal_Sym
*
2056 get_64bit_elf_symbols (file
, offset
, number
)
2058 unsigned long offset
;
2059 unsigned long number
;
2061 Elf64_External_Sym
* esyms
;
2062 Elf_Internal_Sym
* isyms
;
2063 Elf_Internal_Sym
* psym
;
2066 GET_DATA_ALLOC (offset
, number
* sizeof (Elf64_External_Sym
),
2067 esyms
, Elf64_External_Sym
*, "symbols");
2069 isyms
= (Elf_Internal_Sym
*) malloc (number
* sizeof (Elf_Internal_Sym
));
2073 error (_("Out of memory\n"));
2079 for (j
= 0, psym
= isyms
;
2083 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
2084 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
2085 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
2086 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
2087 psym
->st_value
= BYTE_GET8 (esyms
[j
].st_value
);
2088 psym
->st_size
= BYTE_GET8 (esyms
[j
].st_size
);
2097 process_section_headers (file
)
2100 Elf_Internal_Shdr
* section
;
2103 section_headers
= NULL
;
2105 if (elf_header
.e_shnum
== 0)
2108 printf (_("\nThere are no sections in this file.\n"));
2113 if (do_sections
&& !do_header
)
2114 printf (_("There are %d section headers, starting at offset 0x%lx:\n"),
2115 elf_header
.e_shnum
, (unsigned long) elf_header
.e_shoff
);
2119 if (! get_32bit_section_headers (file
))
2122 else if (! get_64bit_section_headers (file
))
2125 /* Read in the string table, so that we have names to display. */
2126 section
= section_headers
+ elf_header
.e_shstrndx
;
2128 if (section
->sh_size
!= 0)
2130 unsigned long string_table_offset
;
2132 string_table_offset
= section
->sh_offset
;
2134 GET_DATA_ALLOC (section
->sh_offset
, section
->sh_size
,
2135 string_table
, char *, "string table");
2138 /* Scan the sections for the dynamic symbol table
2139 and dynamic string table and debug sections. */
2140 dynamic_symbols
= NULL
;
2141 dynamic_strings
= NULL
;
2142 dynamic_syminfo
= NULL
;
2144 for (i
= 0, section
= section_headers
;
2145 i
< elf_header
.e_shnum
;
2148 char * name
= SECTION_NAME (section
);
2150 if (section
->sh_type
== SHT_DYNSYM
)
2152 if (dynamic_symbols
!= NULL
)
2154 error (_("File contains multiple dynamic symbol tables\n"));
2158 num_dynamic_syms
= section
->sh_size
/ section
->sh_entsize
;
2160 GET_ELF_SYMBOLS (file
, section
->sh_offset
, num_dynamic_syms
);
2162 else if (section
->sh_type
== SHT_STRTAB
2163 && strcmp (name
, ".dynstr") == 0)
2165 if (dynamic_strings
!= NULL
)
2167 error (_("File contains multiple dynamic string tables\n"));
2171 GET_DATA_ALLOC (section
->sh_offset
, section
->sh_size
,
2172 dynamic_strings
, char *, "dynamic strings");
2174 else if ((do_debugging
|| do_debug_info
|| do_debug_abbrevs
2175 || do_debug_lines
|| do_debug_pubnames
|| do_debug_aranges
)
2176 && strncmp (name
, ".debug_", 7) == 0)
2181 || (do_debug_info
&& (strcmp (name
, "info") == 0))
2182 || (do_debug_abbrevs
&& (strcmp (name
, "abbrev") == 0))
2183 || (do_debug_lines
&& (strcmp (name
, "line") == 0))
2184 || (do_debug_pubnames
&& (strcmp (name
, "pubnames") == 0))
2185 || (do_debug_aranges
&& (strcmp (name
, "aranges") == 0))
2187 request_dump (i
, DEBUG_DUMP
);
2194 printf (_("\nSection Header%s:\n"), elf_header
.e_shnum
> 1 ? "s" : "");
2196 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
2198 for (i
= 0, section
= section_headers
;
2199 i
< elf_header
.e_shnum
;
2202 printf (" [%2d] %-17.17s %-15.15s ",
2204 SECTION_NAME (section
),
2205 get_section_type_name (section
->sh_type
));
2207 printf ( "%8.8lx %6.6lx %6.6lx %2.2lx",
2208 (unsigned long) section
->sh_addr
,
2209 (unsigned long) section
->sh_offset
,
2210 (unsigned long) section
->sh_size
,
2211 (unsigned long) section
->sh_entsize
);
2213 printf (" %c%c%c %2ld %3lx %ld\n",
2214 (section
->sh_flags
& SHF_WRITE
? 'W' : ' '),
2215 (section
->sh_flags
& SHF_ALLOC
? 'A' : ' '),
2216 (section
->sh_flags
& SHF_EXECINSTR
? 'X' : ' '),
2217 (unsigned long) section
->sh_link
,
2218 (unsigned long) section
->sh_info
,
2219 (unsigned long) section
->sh_addralign
);
2225 /* Process the reloc section. */
2227 process_relocs (file
)
2230 unsigned long rel_size
;
2231 unsigned long rel_offset
;
2237 if (do_using_dynamic
)
2239 int is_rela
= FALSE
;
2244 if (dynamic_info
[DT_REL
])
2246 rel_offset
= dynamic_info
[DT_REL
];
2247 rel_size
= dynamic_info
[DT_RELSZ
];
2250 else if (dynamic_info
[DT_RELA
])
2252 rel_offset
= dynamic_info
[DT_RELA
];
2253 rel_size
= dynamic_info
[DT_RELASZ
];
2256 else if (dynamic_info
[DT_JMPREL
])
2258 rel_offset
= dynamic_info
[DT_JMPREL
];
2259 rel_size
= dynamic_info
[DT_PLTRELSZ
];
2261 switch (dynamic_info
[DT_PLTREL
])
2278 (_("\nRelocation section at offset 0x%lx contains %ld bytes:\n"),
2279 rel_offset
, rel_size
);
2281 dump_relocations (file
, rel_offset
- loadaddr
, rel_size
,
2282 dynamic_symbols
, num_dynamic_syms
, dynamic_strings
, is_rela
);
2285 printf (_("\nThere are no dynamic relocations in this file.\n"));
2289 Elf32_Internal_Shdr
* section
;
2293 for (i
= 0, section
= section_headers
;
2294 i
< elf_header
.e_shnum
;
2297 if ( section
->sh_type
!= SHT_RELA
2298 && section
->sh_type
!= SHT_REL
)
2301 rel_offset
= section
->sh_offset
;
2302 rel_size
= section
->sh_size
;
2306 Elf32_Internal_Shdr
* strsec
;
2307 Elf32_Internal_Shdr
* symsec
;
2308 Elf_Internal_Sym
* symtab
;
2311 unsigned long nsyms
;
2313 printf (_("\nRelocation section "));
2315 if (string_table
== NULL
)
2316 printf ("%d", section
->sh_name
);
2318 printf ("'%s'", SECTION_NAME (section
));
2320 printf (_(" at offset 0x%lx contains %lu entries:\n"),
2321 rel_offset
, (unsigned long) (rel_size
/ section
->sh_entsize
));
2323 symsec
= section_headers
+ section
->sh_link
;
2325 nsyms
= symsec
->sh_size
/ symsec
->sh_entsize
;
2326 symtab
= GET_ELF_SYMBOLS (file
, symsec
->sh_offset
, nsyms
);
2331 strsec
= section_headers
+ symsec
->sh_link
;
2333 GET_DATA_ALLOC (strsec
->sh_offset
, strsec
->sh_size
, strtab
,
2334 char *, "string table");
2336 is_rela
= section
->sh_type
== SHT_RELA
;
2338 dump_relocations (file
, rel_offset
, rel_size
, symtab
, nsyms
, strtab
, is_rela
);
2348 printf (_("\nThere are no relocations in this file.\n"));
2356 dynamic_segment_mips_val (entry
)
2357 Elf_Internal_Dyn
* entry
;
2359 switch (entry
->d_tag
)
2362 if (entry
->d_un
.d_val
== 0)
2366 static const char * opts
[] =
2368 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
2369 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
2370 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
2371 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
2376 for (cnt
= 0; cnt
< NUM_ELEM (opts
); ++ cnt
)
2377 if (entry
->d_un
.d_val
& (1 << cnt
))
2379 printf ("%s%s", first
? "" : " ", opts
[cnt
]);
2386 case DT_MIPS_IVERSION
:
2387 if (dynamic_strings
!= NULL
)
2388 printf ("Interface Version: %s\n",
2389 dynamic_strings
+ entry
->d_un
.d_val
);
2391 printf ("%ld\n", (long) entry
->d_un
.d_ptr
);
2394 case DT_MIPS_TIME_STAMP
:
2397 time_t time
= entry
->d_un
.d_val
;
2398 strftime (timebuf
, 20, "%Y-%m-%dT%H:%M:%S", gmtime (&time
));
2399 printf ("Time Stamp: %s\n", timebuf
);
2403 case DT_MIPS_RLD_VERSION
:
2404 case DT_MIPS_LOCAL_GOTNO
:
2405 case DT_MIPS_CONFLICTNO
:
2406 case DT_MIPS_LIBLISTNO
:
2407 case DT_MIPS_SYMTABNO
:
2408 case DT_MIPS_UNREFEXTNO
:
2409 case DT_MIPS_HIPAGENO
:
2410 case DT_MIPS_DELTA_CLASS_NO
:
2411 case DT_MIPS_DELTA_INSTANCE_NO
:
2412 case DT_MIPS_DELTA_RELOC_NO
:
2413 case DT_MIPS_DELTA_SYM_NO
:
2414 case DT_MIPS_DELTA_CLASSSYM_NO
:
2415 case DT_MIPS_COMPACT_SIZE
:
2416 printf ("%ld\n", (long) entry
->d_un
.d_ptr
);
2420 printf ("%#lx\n", (long) entry
->d_un
.d_ptr
);
2425 get_32bit_dynamic_segment (file
)
2428 Elf32_External_Dyn
* edyn
;
2429 Elf_Internal_Dyn
* entry
;
2432 GET_DATA_ALLOC (dynamic_addr
, dynamic_size
,
2433 edyn
, Elf32_External_Dyn
*, "dynamic segment");
2435 /* SGI's ELF has more than one section in the DYNAMIC segment. Determine
2436 how large this .dynamic is now. We can do this even before the byte
2437 swapping since the DT_NULL tag is recognizable. */
2439 while (*(Elf32_Word
*) edyn
[dynamic_size
++].d_tag
!= DT_NULL
)
2442 dynamic_segment
= (Elf_Internal_Dyn
*)
2443 malloc (dynamic_size
* sizeof (Elf_Internal_Dyn
));
2445 if (dynamic_segment
== NULL
)
2447 error (_("Out of memory\n"));
2452 for (i
= 0, entry
= dynamic_segment
;
2456 entry
->d_tag
= BYTE_GET (edyn
[i
].d_tag
);
2457 entry
->d_un
.d_val
= BYTE_GET (edyn
[i
].d_un
.d_val
);
2466 get_64bit_dynamic_segment (file
)
2469 Elf64_External_Dyn
* edyn
;
2470 Elf_Internal_Dyn
* entry
;
2473 GET_DATA_ALLOC (dynamic_addr
, dynamic_size
,
2474 edyn
, Elf64_External_Dyn
*, "dynamic segment");
2476 /* SGI's ELF has more than one section in the DYNAMIC segment. Determine
2477 how large this .dynamic is now. We can do this even before the byte
2478 swapping since the DT_NULL tag is recognizable. */
2480 while (*(bfd_vma
*) edyn
[dynamic_size
++].d_tag
!= DT_NULL
)
2483 dynamic_segment
= (Elf_Internal_Dyn
*)
2484 malloc (dynamic_size
* sizeof (Elf_Internal_Dyn
));
2486 if (dynamic_segment
== NULL
)
2488 error (_("Out of memory\n"));
2493 for (i
= 0, entry
= dynamic_segment
;
2497 entry
->d_tag
= BYTE_GET8 (edyn
[i
].d_tag
);
2498 entry
->d_un
.d_val
= BYTE_GET8 (edyn
[i
].d_un
.d_val
);
2506 /* Parse and display the contents of the dynamic segment. */
2508 process_dynamic_segment (file
)
2511 Elf_Internal_Dyn
* entry
;
2514 if (dynamic_size
== 0)
2517 printf (_("\nThere is no dynamic segment in this file.\n"));
2524 if (! get_32bit_dynamic_segment (file
))
2527 else if (! get_64bit_dynamic_segment (file
))
2530 /* Find the appropriate symbol table. */
2531 if (dynamic_symbols
== NULL
)
2533 for (i
= 0, entry
= dynamic_segment
;
2537 unsigned long offset
;
2539 if (entry
->d_tag
!= DT_SYMTAB
)
2542 dynamic_info
[DT_SYMTAB
] = entry
->d_un
.d_val
;
2544 /* Since we do not know how big the symbol table is,
2545 we default to reading in the entire file (!) and
2546 processing that. This is overkill, I know, but it
2548 offset
= entry
->d_un
.d_val
- loadaddr
;
2550 if (fseek (file
, 0, SEEK_END
))
2551 error (_("Unable to seek to end of file!"));
2554 num_dynamic_syms
= (ftell (file
) - offset
) / sizeof (Elf32_External_Sym
);
2556 num_dynamic_syms
= (ftell (file
) - offset
) / sizeof (Elf64_External_Sym
);
2558 if (num_dynamic_syms
< 1)
2560 error (_("Unable to determine the number of symbols to load\n"));
2564 dynamic_symbols
= GET_ELF_SYMBOLS (file
, offset
, num_dynamic_syms
);
2568 /* Similarly find a string table. */
2569 if (dynamic_strings
== NULL
)
2571 for (i
= 0, entry
= dynamic_segment
;
2575 unsigned long offset
;
2578 if (entry
->d_tag
!= DT_STRTAB
)
2581 dynamic_info
[DT_STRTAB
] = entry
->d_un
.d_val
;
2583 /* Since we do not know how big the string table is,
2584 we default to reading in the entire file (!) and
2585 processing that. This is overkill, I know, but it
2588 offset
= entry
->d_un
.d_val
- loadaddr
;
2589 if (fseek (file
, 0, SEEK_END
))
2590 error (_("Unable to seek to end of file\n"));
2591 str_tab_len
= ftell (file
) - offset
;
2593 if (str_tab_len
< 1)
2596 (_("Unable to determine the length of the dynamic string table\n"));
2600 GET_DATA_ALLOC (offset
, str_tab_len
, dynamic_strings
, char *,
2601 "dynamic string table");
2607 /* And find the syminfo section if available. */
2608 if (dynamic_syminfo
== NULL
)
2610 unsigned int syminsz
= 0;
2612 for (i
= 0, entry
= dynamic_segment
;
2616 if (entry
->d_tag
== DT_SYMINENT
)
2618 /* Note: these braces are necessary to avoid a syntax
2619 error from the SunOS4 C compiler. */
2620 assert (sizeof (Elf_External_Syminfo
) == entry
->d_un
.d_val
);
2622 else if (entry
->d_tag
== DT_SYMINSZ
)
2623 syminsz
= entry
->d_un
.d_val
;
2624 else if (entry
->d_tag
== DT_SYMINFO
)
2625 dynamic_syminfo_offset
= entry
->d_un
.d_val
- loadaddr
;
2628 if (dynamic_syminfo_offset
!= 0 && syminsz
!= 0)
2630 Elf_External_Syminfo
* extsyminfo
;
2631 Elf_Internal_Syminfo
* syminfo
;
2633 /* There is a syminfo section. Read the data. */
2634 GET_DATA_ALLOC (dynamic_syminfo_offset
, syminsz
, extsyminfo
,
2635 Elf_External_Syminfo
*, "symbol information");
2637 dynamic_syminfo
= (Elf_Internal_Syminfo
*) malloc (syminsz
);
2638 if (dynamic_syminfo
== NULL
)
2640 error (_("Out of memory\n"));
2644 dynamic_syminfo_nent
= syminsz
/ sizeof (Elf_External_Syminfo
);
2645 for (i
= 0, syminfo
= dynamic_syminfo
; i
< dynamic_syminfo_nent
;
2648 syminfo
->si_boundto
= BYTE_GET (extsyminfo
[i
].si_boundto
);
2649 syminfo
->si_flags
= BYTE_GET (extsyminfo
[i
].si_flags
);
2656 if (do_dynamic
&& dynamic_addr
)
2657 printf (_("\nDynamic segment at offset 0x%x contains %ld entries:\n"),
2658 dynamic_addr
, (long) dynamic_size
);
2660 printf (_(" Tag Type Name/Value\n"));
2662 for (i
= 0, entry
= dynamic_segment
;
2667 printf (_(" 0x%-8.8lx (%s)%*s"),
2668 (unsigned long) entry
->d_tag
,
2669 get_dynamic_type (entry
->d_tag
),
2670 27 - strlen (get_dynamic_type (entry
->d_tag
)),
2673 switch (entry
->d_tag
)
2679 if (entry
->d_tag
== DT_AUXILIARY
)
2680 printf (_("Auxiliary library"));
2682 printf (_("Filter library"));
2684 if (dynamic_strings
)
2685 printf (": [%s]\n", dynamic_strings
+ entry
->d_un
.d_val
);
2687 printf (": %#lx\n", (long) entry
->d_un
.d_val
);
2694 printf (_("Flags:"));
2695 if (entry
->d_un
.d_val
== 0)
2696 printf (_(" None\n"));
2699 unsigned long int val
= entry
->d_un
.d_val
;
2700 if (val
& DTF_1_PARINIT
)
2702 printf (" PARINIT");
2703 val
^= DTF_1_PARINIT
;
2706 printf (" %lx", val
);
2715 printf (_("Flags:"));
2716 if (entry
->d_un
.d_val
== 0)
2717 printf (_(" None\n"));
2720 unsigned long int val
= entry
->d_un
.d_val
;
2721 if (val
& DF_P1_LAZYLOAD
)
2723 printf (" LAZYLOAD");
2724 val
^= DF_P1_LAZYLOAD
;
2726 if (val
& DF_P1_GROUPPERM
)
2728 printf (" GROUPPERM");
2729 val
^= DF_P1_GROUPPERM
;
2732 printf (" %lx", val
);
2741 printf (_("Flags:"));
2742 if (entry
->d_un
.d_val
== 0)
2743 printf (_(" None\n"));
2746 unsigned long int val
= entry
->d_un
.d_val
;
2752 if (val
& DF_1_GLOBAL
)
2757 if (val
& DF_1_GROUP
)
2762 if (val
& DF_1_NODELETE
)
2764 printf (" NODELETE");
2765 val
^= DF_1_NODELETE
;
2767 if (val
& DF_1_LOADFLTR
)
2769 printf (" LOADFLTR");
2770 val
^= DF_1_LOADFLTR
;
2772 if (val
& DF_1_INITFIRST
)
2774 printf (" INITFIRST");
2775 val
^= DF_1_INITFIRST
;
2777 if (val
& DF_1_NOOPEN
)
2782 if (val
& DF_1_ORIGIN
)
2787 if (val
& DF_1_DIRECT
)
2792 if (val
& DF_1_TRANS
)
2797 if (val
& DF_1_INTERPOSE
)
2799 printf (" INTERPOSE");
2800 val
^= DF_1_INTERPOSE
;
2803 printf (" %lx", val
);
2811 puts (get_dynamic_type (entry
->d_un
.d_val
));
2830 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
2836 if (dynamic_strings
== NULL
)
2839 name
= dynamic_strings
+ entry
->d_un
.d_val
;
2843 switch (entry
->d_tag
)
2846 printf (_("Shared library: [%s]"), name
);
2848 if (strcmp (name
, program_interpreter
))
2851 printf (_(" program interpreter\n"));
2855 printf (_("Library soname: [%s]\n"), name
);
2859 printf (_("Library rpath: [%s]\n"), name
);
2863 printf ("%#lx\n", (long) entry
->d_un
.d_val
);
2867 printf ("%#lx\n", (long) entry
->d_un
.d_val
);
2881 case DT_INIT_ARRAYSZ
:
2882 case DT_FINI_ARRAYSZ
:
2884 printf ("%lu (bytes)\n", (unsigned long) entry
->d_un
.d_val
);
2892 printf ("%lu\n", (unsigned long) entry
->d_un
.d_val
);
2903 if (dynamic_strings
!= NULL
&& entry
->d_tag
== DT_USED
)
2907 name
= dynamic_strings
+ entry
->d_un
.d_val
;
2911 printf (_("Not needed object: [%s]\n"), name
);
2916 printf ("%#lx\n", (long) entry
->d_un
.d_val
);
2921 /* The value of this entry is ignored. */
2925 if ((entry
->d_tag
>= DT_VERSYM
) && (entry
->d_tag
<= DT_VERNEEDNUM
))
2926 version_info
[DT_VERSIONTAGIDX (entry
->d_tag
)] =
2931 switch (elf_header
.e_machine
)
2934 case EM_MIPS_RS4_BE
:
2935 dynamic_segment_mips_val (entry
);
2938 printf ("%#lx\n", (long) entry
->d_un
.d_ptr
);
2949 get_ver_flags (flags
)
2952 static char buff
[32];
2959 if (flags
& VER_FLG_BASE
)
2960 strcat (buff
, "BASE ");
2962 if (flags
& VER_FLG_WEAK
)
2964 if (flags
& VER_FLG_BASE
)
2965 strcat (buff
, "| ");
2967 strcat (buff
, "WEAK ");
2970 if (flags
& ~(VER_FLG_BASE
| VER_FLG_WEAK
))
2971 strcat (buff
, "| <unknown>");
2976 /* Display the contents of the version sections. */
2978 process_version_sections (file
)
2981 Elf32_Internal_Shdr
* section
;
2988 for (i
= 0, section
= section_headers
;
2989 i
< elf_header
.e_shnum
;
2992 switch (section
->sh_type
)
2994 case SHT_GNU_verdef
:
2996 Elf_External_Verdef
* edefs
;
3003 (_("\nVersion definition section '%s' contains %ld entries:\n"),
3004 SECTION_NAME (section
), section
->sh_info
);
3006 printf (_(" Addr: 0x"));
3007 printf_vma (section
->sh_addr
);
3008 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
3009 (unsigned long) section
->sh_offset
, section
->sh_link
,
3010 SECTION_NAME (section_headers
+ section
->sh_link
));
3012 GET_DATA_ALLOC (section
->sh_offset
, section
->sh_size
,
3013 edefs
, Elf_External_Verdef
*,
3014 "version definition section");
3016 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++ cnt
)
3019 Elf_External_Verdef
* edef
;
3020 Elf_Internal_Verdef ent
;
3021 Elf_External_Verdaux
* eaux
;
3022 Elf_Internal_Verdaux aux
;
3026 vstart
= ((char *) edefs
) + idx
;
3028 edef
= (Elf_External_Verdef
*) vstart
;
3030 ent
.vd_version
= BYTE_GET (edef
->vd_version
);
3031 ent
.vd_flags
= BYTE_GET (edef
->vd_flags
);
3032 ent
.vd_ndx
= BYTE_GET (edef
->vd_ndx
);
3033 ent
.vd_cnt
= BYTE_GET (edef
->vd_cnt
);
3034 ent
.vd_hash
= BYTE_GET (edef
->vd_hash
);
3035 ent
.vd_aux
= BYTE_GET (edef
->vd_aux
);
3036 ent
.vd_next
= BYTE_GET (edef
->vd_next
);
3038 printf (_(" %#06x: Rev: %d Flags: %s"),
3039 idx
, ent
.vd_version
, get_ver_flags (ent
.vd_flags
));
3041 printf (_(" Index: %d Cnt: %d "),
3042 ent
.vd_ndx
, ent
.vd_cnt
);
3044 vstart
+= ent
.vd_aux
;
3046 eaux
= (Elf_External_Verdaux
*) vstart
;
3048 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
3049 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
3051 if (dynamic_strings
)
3052 printf (_("Name: %s\n"), dynamic_strings
+ aux
.vda_name
);
3054 printf (_("Name index: %ld\n"), aux
.vda_name
);
3056 isum
= idx
+ ent
.vd_aux
;
3058 for (j
= 1; j
< ent
.vd_cnt
; j
++)
3060 isum
+= aux
.vda_next
;
3061 vstart
+= aux
.vda_next
;
3063 eaux
= (Elf_External_Verdaux
*) vstart
;
3065 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
3066 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
3068 if (dynamic_strings
)
3069 printf (_(" %#06x: Parent %d: %s\n"),
3070 isum
, j
, dynamic_strings
+ aux
.vda_name
);
3072 printf (_(" %#06x: Parent %d, name index: %ld\n"),
3073 isum
, j
, aux
.vda_name
);
3083 case SHT_GNU_verneed
:
3085 Elf_External_Verneed
* eneed
;
3091 printf (_("\nVersion needs section '%s' contains %ld entries:\n"),
3092 SECTION_NAME (section
), section
->sh_info
);
3094 printf (_(" Addr: 0x"));
3095 printf_vma (section
->sh_addr
);
3096 printf (_(" Offset: %#08lx Link to section: %ld (%s)\n"),
3097 (unsigned long) section
->sh_offset
, section
->sh_link
,
3098 SECTION_NAME (section_headers
+ section
->sh_link
));
3100 GET_DATA_ALLOC (section
->sh_offset
, section
->sh_size
,
3101 eneed
, Elf_External_Verneed
*,
3102 "version need section");
3104 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
3106 Elf_External_Verneed
* entry
;
3107 Elf_Internal_Verneed ent
;
3112 vstart
= ((char *) eneed
) + idx
;
3114 entry
= (Elf_External_Verneed
*) vstart
;
3116 ent
.vn_version
= BYTE_GET (entry
->vn_version
);
3117 ent
.vn_cnt
= BYTE_GET (entry
->vn_cnt
);
3118 ent
.vn_file
= BYTE_GET (entry
->vn_file
);
3119 ent
.vn_aux
= BYTE_GET (entry
->vn_aux
);
3120 ent
.vn_next
= BYTE_GET (entry
->vn_next
);
3122 printf (_(" %#06x: Version: %d"), idx
, ent
.vn_version
);
3124 if (dynamic_strings
)
3125 printf (_(" File: %s"), dynamic_strings
+ ent
.vn_file
);
3127 printf (_(" File: %lx"), ent
.vn_file
);
3129 printf (_(" Cnt: %d\n"), ent
.vn_cnt
);
3131 vstart
+= ent
.vn_aux
;
3133 for (j
= 0, isum
= idx
+ ent
.vn_aux
; j
< ent
.vn_cnt
; ++j
)
3135 Elf_External_Vernaux
* eaux
;
3136 Elf_Internal_Vernaux aux
;
3138 eaux
= (Elf_External_Vernaux
*) vstart
;
3140 aux
.vna_hash
= BYTE_GET (eaux
->vna_hash
);
3141 aux
.vna_flags
= BYTE_GET (eaux
->vna_flags
);
3142 aux
.vna_other
= BYTE_GET (eaux
->vna_other
);
3143 aux
.vna_name
= BYTE_GET (eaux
->vna_name
);
3144 aux
.vna_next
= BYTE_GET (eaux
->vna_next
);
3146 if (dynamic_strings
)
3147 printf (_(" %#06x: Name: %s"),
3148 isum
, dynamic_strings
+ aux
.vna_name
);
3150 printf (_(" %#06x: Name index: %lx"),
3151 isum
, aux
.vna_name
);
3153 printf (_(" Flags: %s Version: %d\n"),
3154 get_ver_flags (aux
.vna_flags
), aux
.vna_other
);
3156 isum
+= aux
.vna_next
;
3157 vstart
+= aux
.vna_next
;
3167 case SHT_GNU_versym
:
3169 Elf32_Internal_Shdr
* link_section
;
3172 unsigned char * edata
;
3173 unsigned short * data
;
3175 Elf_Internal_Sym
* symbols
;
3176 Elf32_Internal_Shdr
* string_sec
;
3178 link_section
= section_headers
+ section
->sh_link
;
3179 total
= section
->sh_size
/ section
->sh_entsize
;
3183 symbols
= GET_ELF_SYMBOLS (file
, link_section
->sh_offset
,
3184 link_section
->sh_size
/ link_section
->sh_entsize
);
3186 string_sec
= section_headers
+ link_section
->sh_link
;
3188 GET_DATA_ALLOC (string_sec
->sh_offset
, string_sec
->sh_size
,
3189 strtab
, char *, "version string table");
3191 printf (_("\nVersion symbols section '%s' contains %d entries:\n"),
3192 SECTION_NAME (section
), total
);
3194 printf (_(" Addr: "));
3195 printf_vma (section
->sh_addr
);
3196 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
3197 (unsigned long) section
->sh_offset
, section
->sh_link
,
3198 SECTION_NAME (link_section
));
3200 GET_DATA_ALLOC (version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)]
3202 total
* sizeof (short), edata
,
3203 unsigned char *, "version symbol data");
3205 data
= (unsigned short *) malloc (total
* sizeof (short));
3207 for (cnt
= total
; cnt
--;)
3208 data
[cnt
] = byte_get (edata
+ cnt
* sizeof (short),
3213 for (cnt
= 0; cnt
< total
; cnt
+= 4)
3217 printf (" %03x:", cnt
);
3219 for (j
= 0; (j
< 4) && (cnt
+ j
) < total
; ++j
)
3220 switch (data
[cnt
+ j
])
3223 fputs (_(" 0 (*local*) "), stdout
);
3227 fputs (_(" 1 (*global*) "), stdout
);
3231 nn
= printf ("%4x%c", data
[cnt
+ j
] & 0x7fff,
3232 data
[cnt
+ j
] & 0x8000 ? 'h' : ' ');
3234 if (symbols
[cnt
+ j
].st_shndx
< SHN_LORESERVE
3235 && section_headers
[symbols
[cnt
+ j
].st_shndx
].sh_type
3238 /* We must test both. */
3239 Elf_Internal_Verneed ivn
;
3240 unsigned long offset
;
3242 offset
= version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)]
3247 Elf_External_Verneed evn
;
3248 Elf_External_Vernaux evna
;
3249 Elf_Internal_Vernaux ivna
;
3250 unsigned long vna_off
;
3252 GET_DATA (offset
, evn
, "version need");
3254 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
3255 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
3257 vna_off
= offset
+ ivn
.vn_aux
;
3261 GET_DATA (vna_off
, evna
,
3262 "version need aux (1)");
3264 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
3265 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
3267 vna_off
+= ivna
.vna_next
;
3269 while (ivna
.vna_other
!= data
[cnt
+ j
]
3270 && ivna
.vna_next
!= 0);
3272 if (ivna
.vna_other
== data
[cnt
+ j
])
3274 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
3276 nn
+= printf ("(%s%-*s",
3277 strtab
+ ivna
.vna_name
,
3283 else if (ivn
.vn_next
== 0)
3285 if (data
[cnt
+ j
] != 0x8001)
3287 Elf_Internal_Verdef ivd
;
3288 Elf_External_Verdef evd
;
3290 offset
= version_info
3291 [DT_VERSIONTAGIDX (DT_VERDEF
)]
3296 GET_DATA (offset
, evd
,
3297 "version definition");
3299 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
3300 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
3302 offset
+= ivd
.vd_next
;
3305 != (data
[cnt
+ j
] & 0x7fff)
3306 && ivd
.vd_next
!= 0);
3309 == (data
[cnt
+ j
] & 0x7fff))
3311 Elf_External_Verdaux evda
;
3312 Elf_Internal_Verdaux ivda
;
3314 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
3316 GET_DATA (offset
+ ivd
.vd_aux
, evda
,
3317 "version definition aux");
3320 BYTE_GET (evda
.vda_name
);
3324 strtab
+ ivda
.vda_name
,
3335 offset
+= ivn
.vn_next
;
3337 while (ivn
.vn_next
);
3339 else if (symbols
[cnt
+ j
].st_shndx
== SHN_UNDEF
)
3341 Elf_Internal_Verneed ivn
;
3342 unsigned long offset
;
3344 offset
= version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)]
3349 Elf_Internal_Vernaux ivna
;
3350 Elf_External_Verneed evn
;
3351 Elf_External_Vernaux evna
;
3352 unsigned long a_off
;
3354 GET_DATA (offset
, evn
, "version need");
3356 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
3357 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
3359 a_off
= offset
+ ivn
.vn_aux
;
3363 GET_DATA (a_off
, evna
,
3364 "version need aux (2)");
3366 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
3367 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
3369 a_off
+= ivna
.vna_next
;
3371 while (ivna
.vna_other
!= data
[cnt
+ j
]
3372 && ivna
.vna_next
!= 0);
3374 if (ivna
.vna_other
== data
[cnt
+ j
])
3376 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
3378 nn
+= printf ("(%s%-*s",
3379 strtab
+ ivna
.vna_name
,
3386 offset
+= ivn
.vn_next
;
3388 while (ivn
.vn_next
);
3390 else if (data
[cnt
+ j
] != 0x8001)
3392 Elf_Internal_Verdef ivd
;
3393 Elf_External_Verdef evd
;
3394 unsigned long offset
;
3396 offset
= version_info
3397 [DT_VERSIONTAGIDX (DT_VERDEF
)] - loadaddr
;
3401 GET_DATA (offset
, evd
, "version def");
3403 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
3404 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
3406 offset
+= ivd
.vd_next
;
3408 while (ivd
.vd_ndx
!= (data
[cnt
+ j
] & 0x7fff)
3409 && ivd
.vd_next
!= 0);
3411 if (ivd
.vd_ndx
== (data
[cnt
+ j
] & 0x7fff))
3413 Elf_External_Verdaux evda
;
3414 Elf_Internal_Verdaux ivda
;
3416 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
3418 GET_DATA (offset
- ivd
.vd_next
+ ivd
.vd_aux
,
3419 evda
, "version def aux");
3421 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
3423 nn
+= printf ("(%s%-*s",
3424 strtab
+ ivda
.vda_name
,
3432 printf ("%*c", 18 - nn
, ' ');
3450 printf (_("\nNo version information found in this file.\n"));
3456 get_symbol_binding (binding
)
3457 unsigned int binding
;
3459 static char buff
[32];
3463 case STB_LOCAL
: return _("LOCAL");
3464 case STB_GLOBAL
: return _("GLOBAL");
3465 case STB_WEAK
: return _("WEAK");
3467 if (binding
>= STB_LOPROC
&& binding
<= STB_HIPROC
)
3468 sprintf (buff
, _("<processor specific>: %d"), binding
);
3469 else if (binding
>= STB_LOOS
&& binding
<= STB_HIOS
)
3470 sprintf (buff
, _("<OS specific>: %d"), binding
);
3472 sprintf (buff
, _("<unknown>: %d"), binding
);
3478 get_symbol_type (type
)
3481 static char buff
[32];
3485 case STT_NOTYPE
: return _("NOTYPE");
3486 case STT_OBJECT
: return _("OBJECT");
3487 case STT_FUNC
: return _("FUNC");
3488 case STT_SECTION
: return _("SECTION");
3489 case STT_FILE
: return _("FILE");
3491 if (type
>= STT_LOPROC
&& type
<= STT_HIPROC
)
3493 if (elf_header
.e_machine
== EM_ARM
&& type
== STT_ARM_TFUNC
)
3494 return _("THUMB_FUNC");
3496 if (elf_header
.e_machine
== EM_SPARCV9
&& type
== STT_REGISTER
)
3497 return _("REGISTER");
3499 sprintf (buff
, _("<processor specific>: %d"), type
);
3501 else if (type
>= STT_LOOS
&& type
<= STT_HIOS
)
3502 sprintf (buff
, _("<OS specific>: %d"), type
);
3504 sprintf (buff
, _("<unknown>: %d"), type
);
3510 get_symbol_index_type (type
)
3515 case SHN_UNDEF
: return "UND";
3516 case SHN_ABS
: return "ABS";
3517 case SHN_COMMON
: return "COM";
3519 if (type
>= SHN_LOPROC
&& type
<= SHN_HIPROC
)
3521 else if (type
>= SHN_LORESERVE
&& type
<= SHN_HIRESERVE
)
3523 else if (type
>= SHN_LOOS
&& type
<= SHN_HIOS
)
3527 static char buff
[32];
3529 sprintf (buff
, "%3d", type
);
3537 get_dynamic_data (file
, number
)
3539 unsigned int number
;
3544 e_data
= (char *) malloc (number
* 4);
3548 error (_("Out of memory\n"));
3552 if (fread (e_data
, 4, number
, file
) != number
)
3554 error (_("Unable to read in dynamic data\n"));
3558 i_data
= (int *) malloc (number
* sizeof (* i_data
));
3562 error (_("Out of memory\n"));
3568 i_data
[number
] = byte_get (e_data
+ number
* 4, 4);
3575 /* Dump the symbol table */
3577 process_symbol_table (file
)
3580 Elf32_Internal_Shdr
* section
;
3585 int * buckets
= NULL
;
3586 int * chains
= NULL
;
3588 if (! do_syms
&& !do_histogram
)
3591 if (dynamic_info
[DT_HASH
] && ((do_using_dynamic
&& dynamic_strings
!= NULL
)
3594 if (fseek (file
, dynamic_info
[DT_HASH
] - loadaddr
, SEEK_SET
))
3596 error (_("Unable to seek to start of dynamic information"));
3600 if (fread (nb
, sizeof (nb
), 1, file
) != 1)
3602 error (_("Failed to read in number of buckets\n"));
3606 if (fread (nc
, sizeof (nc
), 1, file
) != 1)
3608 error (_("Failed to read in number of chains\n"));
3612 nbuckets
= byte_get (nb
, 4);
3613 nchains
= byte_get (nc
, 4);
3615 buckets
= get_dynamic_data (file
, nbuckets
);
3616 chains
= get_dynamic_data (file
, nchains
);
3618 if (buckets
== NULL
|| chains
== NULL
)
3623 && dynamic_info
[DT_HASH
] && do_using_dynamic
&& dynamic_strings
!= NULL
)
3628 printf (_("\nSymbol table for image:\n"));
3629 printf (_(" Num Buc: Value Size Type Bind Ot Ndx Name\n"));
3631 for (hn
= 0; hn
< nbuckets
; hn
++)
3636 for (si
= buckets
[hn
]; si
; si
= chains
[si
])
3638 Elf_Internal_Sym
* psym
;
3640 psym
= dynamic_symbols
+ si
;
3642 printf (" %3d %3d: %8lx %5ld %6s %6s %2d ",
3644 (unsigned long) psym
->st_value
,
3645 (unsigned long) psym
->st_size
,
3646 get_symbol_type (ELF_ST_TYPE (psym
->st_info
)),
3647 get_symbol_binding (ELF_ST_BIND (psym
->st_info
)),
3650 printf ("%3.3s", get_symbol_index_type (psym
->st_shndx
));
3652 printf (" %s\n", dynamic_strings
+ psym
->st_name
);
3656 else if (do_syms
&& !do_using_dynamic
)
3660 for (i
= 0, section
= section_headers
;
3661 i
< elf_header
.e_shnum
;
3666 Elf_Internal_Sym
* symtab
;
3667 Elf_Internal_Sym
* psym
;
3670 if ( section
->sh_type
!= SHT_SYMTAB
3671 && section
->sh_type
!= SHT_DYNSYM
)
3674 printf (_("\nSymbol table '%s' contains %lu entries:\n"),
3675 SECTION_NAME (section
),
3676 (unsigned long) (section
->sh_size
/ section
->sh_entsize
));
3677 fputs (_(" Num: Value Size Type Bind Ot Ndx Name\n"),
3680 symtab
= GET_ELF_SYMBOLS (file
, section
->sh_offset
,
3681 section
->sh_size
/ section
->sh_entsize
);
3685 if (section
->sh_link
== elf_header
.e_shstrndx
)
3686 strtab
= string_table
;
3689 Elf32_Internal_Shdr
* string_sec
;
3691 string_sec
= section_headers
+ section
->sh_link
;
3693 GET_DATA_ALLOC (string_sec
->sh_offset
, string_sec
->sh_size
,
3694 strtab
, char *, "string table");
3697 for (si
= 0, psym
= symtab
;
3698 si
< section
->sh_size
/ section
->sh_entsize
;
3701 printf (" %3d: %8lx %5ld %-7s %-6s %2d ",
3703 (unsigned long) psym
->st_value
,
3704 (unsigned long) psym
->st_size
,
3705 get_symbol_type (ELF_ST_TYPE (psym
->st_info
)),
3706 get_symbol_binding (ELF_ST_BIND (psym
->st_info
)),
3709 printf ("%4s", get_symbol_index_type (psym
->st_shndx
));
3711 printf (" %s", strtab
+ psym
->st_name
);
3713 if (section
->sh_type
== SHT_DYNSYM
&&
3714 version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)] != 0)
3716 unsigned char data
[2];
3717 unsigned short vers_data
;
3718 unsigned long offset
;
3722 offset
= version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)]
3725 GET_DATA (offset
+ si
* sizeof (vers_data
), data
,
3728 vers_data
= byte_get (data
, 2);
3730 is_nobits
= psym
->st_shndx
< SHN_LORESERVE
?
3731 (section_headers
[psym
->st_shndx
].sh_type
== SHT_NOBITS
)
3734 check_def
= (psym
->st_shndx
!= SHN_UNDEF
);
3736 if ((vers_data
& 0x8000) || vers_data
> 1)
3738 if (is_nobits
|| ! check_def
)
3740 Elf_External_Verneed evn
;
3741 Elf_Internal_Verneed ivn
;
3742 Elf_Internal_Vernaux ivna
;
3744 /* We must test both. */
3745 offset
= version_info
3746 [DT_VERSIONTAGIDX (DT_VERNEED
)] - loadaddr
;
3748 GET_DATA (offset
, evn
, "version need");
3750 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
3751 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
3755 unsigned long vna_off
;
3757 vna_off
= offset
+ ivn
.vn_aux
;
3761 Elf_External_Vernaux evna
;
3763 GET_DATA (vna_off
, evna
,
3764 "version need aux (3)");
3766 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
3767 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
3768 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
3770 vna_off
+= ivna
.vna_next
;
3772 while (ivna
.vna_other
!= vers_data
3773 && ivna
.vna_next
!= 0);
3775 if (ivna
.vna_other
== vers_data
)
3778 offset
+= ivn
.vn_next
;
3780 while (ivn
.vn_next
!= 0);
3782 if (ivna
.vna_other
== vers_data
)
3785 strtab
+ ivna
.vna_name
, ivna
.vna_other
);
3788 else if (! is_nobits
)
3789 error (_("bad dynamic symbol"));
3796 if (vers_data
!= 0x8001)
3798 Elf_Internal_Verdef ivd
;
3799 Elf_Internal_Verdaux ivda
;
3800 Elf_External_Verdaux evda
;
3801 unsigned long offset
;
3804 version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)]
3809 Elf_External_Verdef evd
;
3811 GET_DATA (offset
, evd
, "version def");
3813 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
3814 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
3815 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
3817 offset
+= ivd
.vd_next
;
3819 while (ivd
.vd_ndx
!= (vers_data
& 0x7fff)
3820 && ivd
.vd_next
!= 0);
3822 offset
-= ivd
.vd_next
;
3823 offset
+= ivd
.vd_aux
;
3825 GET_DATA (offset
, evda
, "version def aux");
3827 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
3829 if (psym
->st_name
!= ivda
.vda_name
)
3830 printf ((vers_data
& 0x8000)
3832 strtab
+ ivda
.vda_name
);
3842 if (strtab
!= string_table
)
3848 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
3850 if (do_histogram
&& buckets
!= NULL
)
3857 int nzero_counts
= 0;
3860 printf (_("\nHistogram for bucket list length (total of %d buckets):\n"),
3862 printf (_(" Length Number %% of total Coverage\n"));
3864 lengths
= (int *) calloc (nbuckets
, sizeof (int));
3865 if (lengths
== NULL
)
3867 error (_("Out of memory"));
3870 for (hn
= 0; hn
< nbuckets
; ++hn
)
3875 for (si
= buckets
[hn
]; si
; si
= chains
[si
])
3878 if (maxlength
< ++lengths
[hn
])
3883 counts
= (int *) calloc (maxlength
+ 1, sizeof (int));
3886 error (_("Out of memory"));
3890 for (hn
= 0; hn
< nbuckets
; ++hn
)
3891 ++ counts
[lengths
[hn
]];
3893 printf (" 0 %-10d (%5.1f%%)\n",
3894 counts
[0], (counts
[0] * 100.0) / nbuckets
);
3895 for (si
= 1; si
<= maxlength
; ++si
)
3897 nzero_counts
+= counts
[si
] * si
;
3898 printf ("%7d %-10d (%5.1f%%) %5.1f%%\n",
3899 si
, counts
[si
], (counts
[si
] * 100.0) / nbuckets
,
3900 (nzero_counts
* 100.0) / nsyms
);
3907 if (buckets
!= NULL
)
3917 process_syminfo (file
)
3918 FILE * file ATTRIBUTE_UNUSED
;
3922 if (dynamic_syminfo
== NULL
3924 /* No syminfo, this is ok. */
3927 /* There better should be a dynamic symbol section. */
3928 if (dynamic_symbols
== NULL
|| dynamic_strings
== NULL
)
3932 printf (_("\nDynamic info segment at offset 0x%lx contains %d entries:\n"),
3933 dynamic_syminfo_offset
, dynamic_syminfo_nent
);
3935 printf (_(" Num: Name BoundTo Flags\n"));
3936 for (i
= 0; i
< dynamic_syminfo_nent
; ++i
)
3938 unsigned short int flags
= dynamic_syminfo
[i
].si_flags
;
3940 printf ("%4d: %-30s ", i
,
3941 dynamic_strings
+ dynamic_symbols
[i
].st_name
);
3943 switch (dynamic_syminfo
[i
].si_boundto
)
3945 case SYMINFO_BT_SELF
:
3946 fputs ("SELF ", stdout
);
3948 case SYMINFO_BT_PARENT
:
3949 fputs ("PARENT ", stdout
);
3952 if (dynamic_syminfo
[i
].si_boundto
> 0
3953 && dynamic_syminfo
[i
].si_boundto
< dynamic_size
)
3956 + dynamic_segment
[dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
);
3958 printf ("%-10d ", dynamic_syminfo
[i
].si_boundto
);
3962 if (flags
& SYMINFO_FLG_DIRECT
)
3964 if (flags
& SYMINFO_FLG_PASSTHRU
)
3965 printf (" PASSTHRU");
3966 if (flags
& SYMINFO_FLG_COPY
)
3968 if (flags
& SYMINFO_FLG_LAZYLOAD
)
3969 printf (" LAZYLOAD");
3977 #ifdef SUPPORT_DISASSEMBLY
3979 disassemble_section (section
, file
)
3980 Elf32_Internal_Shdr
* section
;
3983 printf (_("\nAssembly dump of section %s\n"),
3984 SECTION_NAME (section
));
3986 /* XXX -- to be done --- XXX */
3993 dump_section (section
, file
)
3994 Elf32_Internal_Shdr
* section
;
3997 bfd_size_type bytes
;
3999 unsigned char * data
;
4000 unsigned char * start
;
4002 bytes
= section
->sh_size
;
4006 printf (_("\nSection '%s' has no data to dump.\n"),
4007 SECTION_NAME (section
));
4011 printf (_("\nHex dump of section '%s':\n"), SECTION_NAME (section
));
4013 addr
= section
->sh_addr
;
4015 GET_DATA_ALLOC (section
->sh_offset
, bytes
, start
, unsigned char *,
4026 lbytes
= (bytes
> 16 ? 16 : bytes
);
4028 printf (" 0x%8.8lx ", (unsigned long) addr
);
4030 switch (elf_header
.e_ident
[EI_DATA
])
4034 for (j
= 15; j
>= 0; j
--)
4037 printf ("%2.2x", data
[j
]);
4047 for (j
= 0; j
< 16; j
++)
4050 printf ("%2.2x", data
[j
]);
4060 for (j
= 0; j
< lbytes
; j
++)
4063 if (k
>= ' ' && k
< 0x80)
4082 static unsigned long int
4083 read_leb128 (data
, length_return
, sign
)
4084 unsigned char * data
;
4085 int * length_return
;
4088 unsigned long int result
= 0;
4089 unsigned int num_read
= 0;
4098 result
|= (byte
& 0x7f) << shift
;
4103 while (byte
& 0x80);
4105 if (length_return
!= NULL
)
4106 * length_return
= num_read
;
4108 if (sign
&& (shift
< 32) && (byte
& 0x40))
4109 result
|= -1 << shift
;
4114 typedef struct State_Machine_Registers
4116 unsigned long address
;
4119 unsigned int column
;
4123 /* This variable hold the number of the last entry seen
4124 in the File Table. */
4125 unsigned int last_file_entry
;
4128 static SMR state_machine_regs
;
4131 reset_state_machine (is_stmt
)
4134 state_machine_regs
.address
= 0;
4135 state_machine_regs
.file
= 1;
4136 state_machine_regs
.line
= 1;
4137 state_machine_regs
.column
= 0;
4138 state_machine_regs
.is_stmt
= is_stmt
;
4139 state_machine_regs
.basic_block
= 0;
4140 state_machine_regs
.end_sequence
= 0;
4141 state_machine_regs
.last_file_entry
= 0;
4144 /* Handled an extend line op. Returns true if this is the end
4147 process_extended_line_op (data
, is_stmt
, pointer_size
)
4148 unsigned char * data
;
4152 unsigned char op_code
;
4155 unsigned char * name
;
4158 len
= read_leb128 (data
, & bytes_read
, 0);
4163 warn (_("badly formed extended line op encountered!"));
4168 op_code
= * data
++;
4170 printf (_(" Extended opcode %d: "), op_code
);
4174 case DW_LNE_end_sequence
:
4175 printf (_("End of Sequence\n\n"));
4176 reset_state_machine (is_stmt
);
4179 case DW_LNE_set_address
:
4180 adr
= byte_get (data
, pointer_size
);
4181 printf (_("set Address to 0x%lx\n"), adr
);
4182 state_machine_regs
.address
= adr
;
4185 case DW_LNE_define_file
:
4186 printf (_(" define new File Table entry\n"));
4187 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
4189 printf (_(" %d\t"), ++ state_machine_regs
.last_file_entry
);
4191 data
+= strlen (data
) + 1;
4192 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
4194 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
4196 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
4197 printf (_("%s\n\n"), name
);
4201 printf (_("UNKNOWN: length %d\n"), len
- bytes_read
);
4208 /* Size of pointers in the .debug_line section. This information is not
4209 really present in that section. It's obtained before dumping the debug
4210 sections by doing some pre-scan of the .debug_info section. */
4211 static int debug_line_pointer_size
= 4;
4214 display_debug_lines (section
, start
, file
)
4215 Elf32_Internal_Shdr
* section
;
4216 unsigned char * start
;
4217 FILE * file ATTRIBUTE_UNUSED
;
4219 DWARF2_External_LineInfo
* external
;
4220 DWARF2_Internal_LineInfo info
;
4221 unsigned char * standard_opcodes
;
4222 unsigned char * data
= start
;
4223 unsigned char * end
= start
+ section
->sh_size
;
4224 unsigned char * end_of_sequence
;
4227 printf (_("\nDump of debug contents of section %s:\n\n"),
4228 SECTION_NAME (section
));
4232 external
= (DWARF2_External_LineInfo
*) data
;
4234 /* Check the length of the block. */
4235 info
.li_length
= BYTE_GET (external
->li_length
);
4236 if (info
.li_length
> section
->sh_size
)
4239 (_("The line info appears to be corrupt - the section is too small\n"));
4243 /* Check its version number. */
4244 info
.li_version
= BYTE_GET (external
->li_version
);
4245 if (info
.li_version
!= 2)
4247 warn (_("Only DWARF version 2 line info is currently supported.\n"));
4251 info
.li_prologue_length
= BYTE_GET (external
->li_prologue_length
);
4252 info
.li_min_insn_length
= BYTE_GET (external
->li_min_insn_length
);
4253 info
.li_default_is_stmt
= BYTE_GET (external
->li_default_is_stmt
);
4254 info
.li_line_base
= BYTE_GET (external
->li_line_base
);
4255 info
.li_line_range
= BYTE_GET (external
->li_line_range
);
4256 info
.li_opcode_base
= BYTE_GET (external
->li_opcode_base
);
4258 /* Sign extend the line base field. */
4259 info
.li_line_base
<<= 24;
4260 info
.li_line_base
>>= 24;
4262 printf (_(" Length: %ld\n"), info
.li_length
);
4263 printf (_(" DWARF Version: %d\n"), info
.li_version
);
4264 printf (_(" Prolgue Length: %d\n"), info
.li_prologue_length
);
4265 printf (_(" Minimum Instruction Length: %d\n"), info
.li_min_insn_length
);
4266 printf (_(" Initial value of 'is_stmt': %d\n"), info
.li_default_is_stmt
);
4267 printf (_(" Line Base: %d\n"), info
.li_line_base
);
4268 printf (_(" Line Range: %d\n"), info
.li_line_range
);
4269 printf (_(" Opcode Base: %d\n"), info
.li_opcode_base
);
4271 end_of_sequence
= data
+ info
.li_length
+ sizeof (info
.li_length
);
4273 reset_state_machine (info
.li_default_is_stmt
);
4275 /* Display the contents of the Opcodes table. */
4276 standard_opcodes
= data
+ sizeof (* external
);
4278 printf (_("\n Opcodes:\n"));
4280 for (i
= 1; i
< info
.li_opcode_base
; i
++)
4281 printf (_(" Opcode %d has %d args\n"), i
, standard_opcodes
[i
- 1]);
4283 /* Display the contents of the Directory table. */
4284 data
= standard_opcodes
+ info
.li_opcode_base
- 1;
4287 printf (_("\n The Directory Table is empty.\n"));
4290 printf (_("\n The Directory Table:\n"));
4294 printf (_(" %s\n"), data
);
4296 data
+= strlen (data
) + 1;
4300 /* Skip the NUL at the end of the table. */
4303 /* Display the contents of the File Name table. */
4305 printf (_("\n The File Name Table is empty.\n"));
4308 printf (_("\n The File Name Table:\n"));
4309 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
4316 printf (_(" %d\t"), ++ state_machine_regs
.last_file_entry
);
4319 data
+= strlen (data
) + 1;
4321 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
4323 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
4325 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
4327 printf (_("%s\n"), name
);
4331 /* Skip the NUL at the end of the table. */
4334 /* Now display the statements. */
4335 printf (_("\n Line Number Statements:\n"));
4338 while (data
< end_of_sequence
)
4340 unsigned char op_code
;
4344 op_code
= * data
++;
4348 case DW_LNS_extended_op
:
4349 data
+= process_extended_line_op (data
, info
.li_default_is_stmt
,
4350 debug_line_pointer_size
);
4354 printf (_(" Copy\n"));
4357 case DW_LNS_advance_pc
:
4358 adv
= info
.li_min_insn_length
* read_leb128 (data
, & bytes_read
, 0);
4360 state_machine_regs
.address
+= adv
;
4361 printf (_(" Advance PC by %d to %lx\n"), adv
,
4362 state_machine_regs
.address
);
4365 case DW_LNS_advance_line
:
4366 adv
= read_leb128 (data
, & bytes_read
, 1);
4368 state_machine_regs
.line
+= adv
;
4369 printf (_(" Advance Line by %d to %d\n"), adv
,
4370 state_machine_regs
.line
);
4373 case DW_LNS_set_file
:
4374 adv
= read_leb128 (data
, & bytes_read
, 0);
4376 printf (_(" Set File Name to entry %d in the File Name Table\n"),
4378 state_machine_regs
.file
= adv
;
4381 case DW_LNS_set_column
:
4382 adv
= read_leb128 (data
, & bytes_read
, 0);
4384 printf (_(" Set column to %d\n"), adv
);
4385 state_machine_regs
.column
= adv
;
4388 case DW_LNS_negate_stmt
:
4389 adv
= state_machine_regs
.is_stmt
;
4391 printf (_(" Set is_stmt to %d\n"), adv
);
4392 state_machine_regs
.is_stmt
= adv
;
4395 case DW_LNS_set_basic_block
:
4396 printf (_(" Set basic block\n"));
4397 state_machine_regs
.basic_block
= 1;
4400 case DW_LNS_const_add_pc
:
4401 adv
= (((255 - info
.li_opcode_base
) / info
.li_line_range
)
4402 * info
.li_min_insn_length
);
4403 state_machine_regs
.address
+= adv
;
4404 printf (_(" Advance PC by constant %d to 0x%lx\n"), adv
,
4405 state_machine_regs
.address
);
4408 case DW_LNS_fixed_advance_pc
:
4409 adv
= byte_get (data
, 2);
4411 state_machine_regs
.address
+= adv
;
4412 printf (_(" Advance PC by fixed size amount %d to 0x%lx\n"),
4413 adv
, state_machine_regs
.address
);
4417 op_code
-= info
.li_opcode_base
;
4418 adv
= (op_code
/ info
.li_line_range
) * info
.li_min_insn_length
;
4419 state_machine_regs
.address
+= adv
;
4420 printf (_(" Special opcode %d: advance Address by %d to 0x%lx"),
4421 op_code
, adv
, state_machine_regs
.address
);
4422 adv
= (op_code
% info
.li_line_range
) + info
.li_line_base
;
4423 state_machine_regs
.line
+= adv
;
4424 printf (_(" and Line by %d to %d\n"),
4425 adv
, state_machine_regs
.line
);
4436 display_debug_pubnames (section
, start
, file
)
4437 Elf32_Internal_Shdr
* section
;
4438 unsigned char * start
;
4439 FILE * file ATTRIBUTE_UNUSED
;
4441 DWARF2_External_PubNames
* external
;
4442 DWARF2_Internal_PubNames pubnames
;
4443 unsigned char * end
;
4445 end
= start
+ section
->sh_size
;
4447 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section
));
4451 unsigned char * data
;
4452 unsigned long offset
;
4454 external
= (DWARF2_External_PubNames
*) start
;
4456 pubnames
.pn_length
= BYTE_GET (external
->pn_length
);
4457 pubnames
.pn_version
= BYTE_GET (external
->pn_version
);
4458 pubnames
.pn_offset
= BYTE_GET (external
->pn_offset
);
4459 pubnames
.pn_size
= BYTE_GET (external
->pn_size
);
4461 data
= start
+ sizeof (* external
);
4462 start
+= pubnames
.pn_length
+ sizeof (external
->pn_length
);
4464 if (pubnames
.pn_version
!= 2)
4466 warn (_("Only DWARF 2 pubnames are currently supported"));
4470 printf (_(" Length: %ld\n"),
4471 pubnames
.pn_length
);
4472 printf (_(" Version: %d\n"),
4473 pubnames
.pn_version
);
4474 printf (_(" Offset into .debug_info section: %ld\n"),
4475 pubnames
.pn_offset
);
4476 printf (_(" Size of area in .debug_info section: %ld\n"),
4479 printf (_("\n Offset\tName\n"));
4483 offset
= byte_get (data
, 4);
4488 printf (" %ld\t\t%s\n", offset
, data
);
4489 data
+= strlen (data
) + 1;
4492 while (offset
!= 0);
4505 case DW_TAG_padding
: return "DW_TAG_padding";
4506 case DW_TAG_array_type
: return "DW_TAG_array_type";
4507 case DW_TAG_class_type
: return "DW_TAG_class_type";
4508 case DW_TAG_entry_point
: return "DW_TAG_entry_point";
4509 case DW_TAG_enumeration_type
: return "DW_TAG_enumeration_type";
4510 case DW_TAG_formal_parameter
: return "DW_TAG_formal_parameter";
4511 case DW_TAG_imported_declaration
: return "DW_TAG_imported_declaration";
4512 case DW_TAG_label
: return "DW_TAG_label";
4513 case DW_TAG_lexical_block
: return "DW_TAG_lexical_block";
4514 case DW_TAG_member
: return "DW_TAG_member";
4515 case DW_TAG_pointer_type
: return "DW_TAG_pointer_type";
4516 case DW_TAG_reference_type
: return "DW_TAG_reference_type";
4517 case DW_TAG_compile_unit
: return "DW_TAG_compile_unit";
4518 case DW_TAG_string_type
: return "DW_TAG_string_type";
4519 case DW_TAG_structure_type
: return "DW_TAG_structure_type";
4520 case DW_TAG_subroutine_type
: return "DW_TAG_subroutine_type";
4521 case DW_TAG_typedef
: return "DW_TAG_typedef";
4522 case DW_TAG_union_type
: return "DW_TAG_union_type";
4523 case DW_TAG_unspecified_parameters
: return "DW_TAG_unspecified_parameters";
4524 case DW_TAG_variant
: return "DW_TAG_variant";
4525 case DW_TAG_common_block
: return "DW_TAG_common_block";
4526 case DW_TAG_common_inclusion
: return "DW_TAG_common_inclusion";
4527 case DW_TAG_inheritance
: return "DW_TAG_inheritance";
4528 case DW_TAG_inlined_subroutine
: return "DW_TAG_inlined_subroutine";
4529 case DW_TAG_module
: return "DW_TAG_module";
4530 case DW_TAG_ptr_to_member_type
: return "DW_TAG_ptr_to_member_type";
4531 case DW_TAG_set_type
: return "DW_TAG_set_type";
4532 case DW_TAG_subrange_type
: return "DW_TAG_subrange_type";
4533 case DW_TAG_with_stmt
: return "DW_TAG_with_stmt";
4534 case DW_TAG_access_declaration
: return "DW_TAG_access_declaration";
4535 case DW_TAG_base_type
: return "DW_TAG_base_type";
4536 case DW_TAG_catch_block
: return "DW_TAG_catch_block";
4537 case DW_TAG_const_type
: return "DW_TAG_const_type";
4538 case DW_TAG_constant
: return "DW_TAG_constant";
4539 case DW_TAG_enumerator
: return "DW_TAG_enumerator";
4540 case DW_TAG_file_type
: return "DW_TAG_file_type";
4541 case DW_TAG_friend
: return "DW_TAG_friend";
4542 case DW_TAG_namelist
: return "DW_TAG_namelist";
4543 case DW_TAG_namelist_item
: return "DW_TAG_namelist_item";
4544 case DW_TAG_packed_type
: return "DW_TAG_packed_type";
4545 case DW_TAG_subprogram
: return "DW_TAG_subprogram";
4546 case DW_TAG_template_type_param
: return "DW_TAG_template_type_param";
4547 case DW_TAG_template_value_param
: return "DW_TAG_template_value_param";
4548 case DW_TAG_thrown_type
: return "DW_TAG_thrown_type";
4549 case DW_TAG_try_block
: return "DW_TAG_try_block";
4550 case DW_TAG_variant_part
: return "DW_TAG_variant_part";
4551 case DW_TAG_variable
: return "DW_TAG_variable";
4552 case DW_TAG_volatile_type
: return "DW_TAG_volatile_type";
4553 case DW_TAG_MIPS_loop
: return "DW_TAG_MIPS_loop";
4554 case DW_TAG_format_label
: return "DW_TAG_format_label";
4555 case DW_TAG_function_template
: return "DW_TAG_function_template";
4556 case DW_TAG_class_template
: return "DW_TAG_class_template";
4559 static char buffer
[100];
4561 sprintf (buffer
, _("Unknown TAG value: %lx"), tag
);
4568 get_AT_name (attribute
)
4569 unsigned long attribute
;
4573 case DW_AT_sibling
: return "DW_AT_sibling";
4574 case DW_AT_location
: return "DW_AT_location";
4575 case DW_AT_name
: return "DW_AT_name";
4576 case DW_AT_ordering
: return "DW_AT_ordering";
4577 case DW_AT_subscr_data
: return "DW_AT_subscr_data";
4578 case DW_AT_byte_size
: return "DW_AT_byte_size";
4579 case DW_AT_bit_offset
: return "DW_AT_bit_offset";
4580 case DW_AT_bit_size
: return "DW_AT_bit_size";
4581 case DW_AT_element_list
: return "DW_AT_element_list";
4582 case DW_AT_stmt_list
: return "DW_AT_stmt_list";
4583 case DW_AT_low_pc
: return "DW_AT_low_pc";
4584 case DW_AT_high_pc
: return "DW_AT_high_pc";
4585 case DW_AT_language
: return "DW_AT_language";
4586 case DW_AT_member
: return "DW_AT_member";
4587 case DW_AT_discr
: return "DW_AT_discr";
4588 case DW_AT_discr_value
: return "DW_AT_discr_value";
4589 case DW_AT_visibility
: return "DW_AT_visibility";
4590 case DW_AT_import
: return "DW_AT_import";
4591 case DW_AT_string_length
: return "DW_AT_string_length";
4592 case DW_AT_common_reference
: return "DW_AT_common_reference";
4593 case DW_AT_comp_dir
: return "DW_AT_comp_dir";
4594 case DW_AT_const_value
: return "DW_AT_const_value";
4595 case DW_AT_containing_type
: return "DW_AT_containing_type";
4596 case DW_AT_default_value
: return "DW_AT_default_value";
4597 case DW_AT_inline
: return "DW_AT_inline";
4598 case DW_AT_is_optional
: return "DW_AT_is_optional";
4599 case DW_AT_lower_bound
: return "DW_AT_lower_bound";
4600 case DW_AT_producer
: return "DW_AT_producer";
4601 case DW_AT_prototyped
: return "DW_AT_prototyped";
4602 case DW_AT_return_addr
: return "DW_AT_return_addr";
4603 case DW_AT_start_scope
: return "DW_AT_start_scope";
4604 case DW_AT_stride_size
: return "DW_AT_stride_size";
4605 case DW_AT_upper_bound
: return "DW_AT_upper_bound";
4606 case DW_AT_abstract_origin
: return "DW_AT_abstract_origin";
4607 case DW_AT_accessibility
: return "DW_AT_accessibility";
4608 case DW_AT_address_class
: return "DW_AT_address_class";
4609 case DW_AT_artificial
: return "DW_AT_artificial";
4610 case DW_AT_base_types
: return "DW_AT_base_types";
4611 case DW_AT_calling_convention
: return "DW_AT_calling_convention";
4612 case DW_AT_count
: return "DW_AT_count";
4613 case DW_AT_data_member_location
: return "DW_AT_data_member_location";
4614 case DW_AT_decl_column
: return "DW_AT_decl_column";
4615 case DW_AT_decl_file
: return "DW_AT_decl_file";
4616 case DW_AT_decl_line
: return "DW_AT_decl_line";
4617 case DW_AT_declaration
: return "DW_AT_declaration";
4618 case DW_AT_discr_list
: return "DW_AT_discr_list";
4619 case DW_AT_encoding
: return "DW_AT_encoding";
4620 case DW_AT_external
: return "DW_AT_external";
4621 case DW_AT_frame_base
: return "DW_AT_frame_base";
4622 case DW_AT_friend
: return "DW_AT_friend";
4623 case DW_AT_identifier_case
: return "DW_AT_identifier_case";
4624 case DW_AT_macro_info
: return "DW_AT_macro_info";
4625 case DW_AT_namelist_items
: return "DW_AT_namelist_items";
4626 case DW_AT_priority
: return "DW_AT_priority";
4627 case DW_AT_segment
: return "DW_AT_segment";
4628 case DW_AT_specification
: return "DW_AT_specification";
4629 case DW_AT_static_link
: return "DW_AT_static_link";
4630 case DW_AT_type
: return "DW_AT_type";
4631 case DW_AT_use_location
: return "DW_AT_use_location";
4632 case DW_AT_variable_parameter
: return "DW_AT_variable_parameter";
4633 case DW_AT_virtuality
: return "DW_AT_virtuality";
4634 case DW_AT_vtable_elem_location
: return "DW_AT_vtable_elem_location";
4635 case DW_AT_MIPS_fde
: return "DW_AT_MIPS_fde";
4636 case DW_AT_MIPS_loop_begin
: return "DW_AT_MIPS_loop_begin";
4637 case DW_AT_MIPS_tail_loop_begin
: return "DW_AT_MIPS_tail_loop_begin";
4638 case DW_AT_MIPS_epilog_begin
: return "DW_AT_MIPS_epilog_begin";
4639 case DW_AT_MIPS_loop_unroll_factor
: return "DW_AT_MIPS_loop_unroll_factor";
4640 case DW_AT_MIPS_software_pipeline_depth
: return "DW_AT_MIPS_software_pipeline_depth";
4641 case DW_AT_MIPS_linkage_name
: return "DW_AT_MIPS_linkage_name";
4642 case DW_AT_MIPS_stride
: return "DW_AT_MIPS_stride";
4643 case DW_AT_MIPS_abstract_name
: return "DW_AT_MIPS_abstract_name";
4644 case DW_AT_MIPS_clone_origin
: return "DW_AT_MIPS_clone_origin";
4645 case DW_AT_MIPS_has_inlines
: return "DW_AT_MIPS_has_inlines";
4646 case DW_AT_sf_names
: return "DW_AT_sf_names";
4647 case DW_AT_src_info
: return "DW_AT_src_info";
4648 case DW_AT_mac_info
: return "DW_AT_mac_info";
4649 case DW_AT_src_coords
: return "DW_AT_src_coords";
4650 case DW_AT_body_begin
: return "DW_AT_body_begin";
4651 case DW_AT_body_end
: return "DW_AT_body_end";
4654 static char buffer
[100];
4656 sprintf (buffer
, _("Unknown AT value: %lx"), attribute
);
4663 get_FORM_name (form
)
4668 case DW_FORM_addr
: return "DW_FORM_addr";
4669 case DW_FORM_block2
: return "DW_FORM_block2";
4670 case DW_FORM_block4
: return "DW_FORM_block4";
4671 case DW_FORM_data2
: return "DW_FORM_data2";
4672 case DW_FORM_data4
: return "DW_FORM_data4";
4673 case DW_FORM_data8
: return "DW_FORM_data8";
4674 case DW_FORM_string
: return "DW_FORM_string";
4675 case DW_FORM_block
: return "DW_FORM_block";
4676 case DW_FORM_block1
: return "DW_FORM_block1";
4677 case DW_FORM_data1
: return "DW_FORM_data1";
4678 case DW_FORM_flag
: return "DW_FORM_flag";
4679 case DW_FORM_sdata
: return "DW_FORM_sdata";
4680 case DW_FORM_strp
: return "DW_FORM_strp";
4681 case DW_FORM_udata
: return "DW_FORM_udata";
4682 case DW_FORM_ref_addr
: return "DW_FORM_ref_addr";
4683 case DW_FORM_ref1
: return "DW_FORM_ref1";
4684 case DW_FORM_ref2
: return "DW_FORM_ref2";
4685 case DW_FORM_ref4
: return "DW_FORM_ref4";
4686 case DW_FORM_ref8
: return "DW_FORM_ref8";
4687 case DW_FORM_ref_udata
: return "DW_FORM_ref_udata";
4688 case DW_FORM_indirect
: return "DW_FORM_indirect";
4691 static char buffer
[100];
4693 sprintf (buffer
, _("Unknown FORM value: %lx"), form
);
4699 /* FIXME: There are better and more effiecint ways to handle
4700 these structures. For now though, I just want something that
4701 is simple to implement. */
4702 typedef struct abbrev_attr
4704 unsigned long attribute
;
4706 struct abbrev_attr
* next
;
4710 typedef struct abbrev_entry
4712 unsigned long entry
;
4715 struct abbrev_attr
* first_attr
;
4716 struct abbrev_attr
* last_attr
;
4717 struct abbrev_entry
* next
;
4721 static abbrev_entry
* first_abbrev
= NULL
;
4722 static abbrev_entry
* last_abbrev
= NULL
;
4725 free_abbrevs
PARAMS ((void))
4727 abbrev_entry
* abbrev
;
4729 for (abbrev
= first_abbrev
; abbrev
;)
4731 abbrev_entry
* next
= abbrev
->next
;
4734 for (attr
= abbrev
->first_attr
; attr
;)
4736 abbrev_attr
* next
= attr
->next
;
4746 last_abbrev
= first_abbrev
= NULL
;
4750 add_abbrev (number
, tag
, children
)
4751 unsigned long number
;
4755 abbrev_entry
* entry
;
4757 entry
= (abbrev_entry
*) malloc (sizeof (* entry
));
4763 entry
->entry
= number
;
4765 entry
->children
= children
;
4766 entry
->first_attr
= NULL
;
4767 entry
->last_attr
= NULL
;
4770 if (first_abbrev
== NULL
)
4771 first_abbrev
= entry
;
4773 last_abbrev
->next
= entry
;
4775 last_abbrev
= entry
;
4779 add_abbrev_attr (attribute
, form
)
4780 unsigned long attribute
;
4785 attr
= (abbrev_attr
*) malloc (sizeof (* attr
));
4791 attr
->attribute
= attribute
;
4795 if (last_abbrev
->first_attr
== NULL
)
4796 last_abbrev
->first_attr
= attr
;
4798 last_abbrev
->last_attr
->next
= attr
;
4800 last_abbrev
->last_attr
= attr
;
4803 /* Processes the (partial) contents of a .debug_abbrev section.
4804 Returns NULL if the end of the section was encountered.
4805 Returns the address after the last byte read if the end of
4806 an abbreviation set was found. */
4808 static unsigned char *
4809 process_abbrev_section (start
, end
)
4810 unsigned char * start
;
4811 unsigned char * end
;
4813 if (first_abbrev
!= NULL
)
4819 unsigned long entry
;
4821 unsigned long attribute
;
4824 entry
= read_leb128 (start
, & bytes_read
, 0);
4825 start
+= bytes_read
;
4827 /* A single zero is supposed to end the section according
4828 to the standard. If there's more, then signal that to
4831 return start
== end
? NULL
: start
;
4833 tag
= read_leb128 (start
, & bytes_read
, 0);
4834 start
+= bytes_read
;
4836 children
= * start
++;
4838 add_abbrev (entry
, tag
, children
);
4844 attribute
= read_leb128 (start
, & bytes_read
, 0);
4845 start
+= bytes_read
;
4847 form
= read_leb128 (start
, & bytes_read
, 0);
4848 start
+= bytes_read
;
4851 add_abbrev_attr (attribute
, form
);
4853 while (attribute
!= 0);
4861 display_debug_abbrev (section
, start
, file
)
4862 Elf32_Internal_Shdr
* section
;
4863 unsigned char * start
;
4864 FILE * file ATTRIBUTE_UNUSED
;
4866 abbrev_entry
* entry
;
4867 unsigned char * end
= start
+ section
->sh_size
;
4869 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section
));
4873 start
= process_abbrev_section (start
, end
);
4875 printf (_(" Number TAG\n"));
4877 for (entry
= first_abbrev
; entry
; entry
= entry
->next
)
4881 printf (_(" %ld %s [%s]\n"),
4883 get_TAG_name (entry
->tag
),
4884 entry
->children
? _("has children") : _("no children"));
4886 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
4888 printf (_(" %-18s %s\n"),
4889 get_AT_name (attr
->attribute
),
4890 get_FORM_name (attr
->form
));
4902 static unsigned char *
4903 display_block (data
, length
)
4904 unsigned char * data
;
4905 unsigned long length
;
4907 printf (_(" %lu byte block: "), length
);
4910 printf ("%lx ", (unsigned long) byte_get (data
++, 1));
4916 decode_location_expression (data
, pointer_size
)
4917 unsigned char * data
;
4918 unsigned int pointer_size
;
4922 unsigned long uvalue
;
4929 printf ("DW_OP_addr: %lx", (unsigned long) byte_get (data
, pointer_size
));
4932 printf ("DW_OP_deref");
4935 printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data
, 1));
4938 printf ("DW_OP_const1s: %ld", (long) byte_get (data
, 1));
4941 printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data
, 2));
4944 printf ("DW_OP_const2s: %ld", (long) byte_get (data
, 2));
4947 printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data
, 4));
4950 printf ("DW_OP_const4s: %ld", (long) byte_get (data
, 4));
4953 printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data
, 4),
4954 (unsigned long) byte_get (data
+ 4, 4));
4957 printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data
, 4),
4958 (long) byte_get (data
+ 4, 4));
4961 printf ("DW_OP_constu: %lu", read_leb128 (data
, NULL
, 0));
4964 printf ("DW_OP_consts: %ld", read_leb128 (data
, NULL
, 1));
4967 printf ("DW_OP_dup");
4970 printf ("DW_OP_drop");
4973 printf ("DW_OP_over");
4976 printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data
, 1));
4979 printf ("DW_OP_swap");
4982 printf ("DW_OP_rot");
4985 printf ("DW_OP_xderef");
4988 printf ("DW_OP_abs");
4991 printf ("DW_OP_and");
4994 printf ("DW_OP_div");
4997 printf ("DW_OP_minus");
5000 printf ("DW_OP_mod");
5003 printf ("DW_OP_mul");
5006 printf ("DW_OP_neg");
5009 printf ("DW_OP_not");
5012 printf ("DW_OP_or");
5015 printf ("DW_OP_plus");
5017 case DW_OP_plus_uconst
:
5018 printf ("DW_OP_plus_uconst: %lu", read_leb128 (data
, NULL
, 0));
5021 printf ("DW_OP_shl");
5024 printf ("DW_OP_shr");
5027 printf ("DW_OP_shra");
5030 printf ("DW_OP_xor");
5033 printf ("DW_OP_bra: %ld", (long) byte_get (data
, 2));
5036 printf ("DW_OP_eq");
5039 printf ("DW_OP_ge");
5042 printf ("DW_OP_gt");
5045 printf ("DW_OP_le");
5048 printf ("DW_OP_lt");
5051 printf ("DW_OP_ne");
5054 printf ("DW_OP_skip: %ld", (long) byte_get (data
, 2));
5057 printf ("DW_OP_lit0");
5060 printf ("DW_OP_lit1");
5063 printf ("DW_OP_lit2");
5066 printf ("DW_OP_lit3");
5069 printf ("DW_OP_lit4");
5072 printf ("DW_OP_lit5");
5075 printf ("DW_OP_lit6");
5078 printf ("DW_OP_lit7");
5081 printf ("DW_OP_lit8");
5084 printf ("DW_OP_lit9");
5087 printf ("DW_OP_lit10");
5090 printf ("DW_OP_lit11");
5093 printf ("DW_OP_lit12");
5096 printf ("DW_OP_lit13");
5099 printf ("DW_OP_lit14");
5102 printf ("DW_OP_lit15");
5105 printf ("DW_OP_lit16");
5108 printf ("DW_OP_lit17");
5111 printf ("DW_OP_lit18");
5114 printf ("DW_OP_lit19");
5117 printf ("DW_OP_lit20");
5120 printf ("DW_OP_lit21");
5123 printf ("DW_OP_lit22");
5126 printf ("DW_OP_lit23");
5129 printf ("DW_OP_lit24");
5132 printf ("DW_OP_lit25");
5135 printf ("DW_OP_lit26");
5138 printf ("DW_OP_lit27");
5141 printf ("DW_OP_lit28");
5144 printf ("DW_OP_lit29");
5147 printf ("DW_OP_lit30");
5150 printf ("DW_OP_lit31");
5153 printf ("DW_OP_reg0");
5156 printf ("DW_OP_reg1");
5159 printf ("DW_OP_reg2");
5162 printf ("DW_OP_reg3");
5165 printf ("DW_OP_reg4");
5168 printf ("DW_OP_reg5");
5171 printf ("DW_OP_reg6");
5174 printf ("DW_OP_reg7");
5177 printf ("DW_OP_reg8");
5180 printf ("DW_OP_reg9");
5183 printf ("DW_OP_reg10");
5186 printf ("DW_OP_reg11");
5189 printf ("DW_OP_reg12");
5192 printf ("DW_OP_reg13");
5195 printf ("DW_OP_reg14");
5198 printf ("DW_OP_reg15");
5201 printf ("DW_OP_reg16");
5204 printf ("DW_OP_reg17");
5207 printf ("DW_OP_reg18");
5210 printf ("DW_OP_reg19");
5213 printf ("DW_OP_reg20");
5216 printf ("DW_OP_reg21");
5219 printf ("DW_OP_reg22");
5222 printf ("DW_OP_reg23");
5225 printf ("DW_OP_reg24");
5228 printf ("DW_OP_reg25");
5231 printf ("DW_OP_reg26");
5234 printf ("DW_OP_reg27");
5237 printf ("DW_OP_reg28");
5240 printf ("DW_OP_reg29");
5243 printf ("DW_OP_reg30");
5246 printf ("DW_OP_reg31");
5249 printf ("DW_OP_breg0: %ld", read_leb128 (data
, NULL
, 1));
5252 printf ("DW_OP_breg1: %ld", read_leb128 (data
, NULL
, 1));
5255 printf ("DW_OP_breg2: %ld", read_leb128 (data
, NULL
, 1));
5258 printf ("DW_OP_breg3: %ld", read_leb128 (data
, NULL
, 1));
5261 printf ("DW_OP_breg4: %ld", read_leb128 (data
, NULL
, 1));
5264 printf ("DW_OP_breg5: %ld", read_leb128 (data
, NULL
, 1));
5267 printf ("DW_OP_breg6: %ld", read_leb128 (data
, NULL
, 1));
5270 printf ("DW_OP_breg7: %ld", read_leb128 (data
, NULL
, 1));
5273 printf ("DW_OP_breg8: %ld", read_leb128 (data
, NULL
, 1));
5276 printf ("DW_OP_breg9: %ld", read_leb128 (data
, NULL
, 1));
5279 printf ("DW_OP_breg10: %ld", read_leb128 (data
, NULL
, 1));
5282 printf ("DW_OP_breg11: %ld", read_leb128 (data
, NULL
, 1));
5285 printf ("DW_OP_breg12: %ld", read_leb128 (data
, NULL
, 1));
5288 printf ("DW_OP_breg13: %ld", read_leb128 (data
, NULL
, 1));
5291 printf ("DW_OP_breg14: %ld", read_leb128 (data
, NULL
, 1));
5294 printf ("DW_OP_breg15: %ld", read_leb128 (data
, NULL
, 1));
5297 printf ("DW_OP_breg16: %ld", read_leb128 (data
, NULL
, 1));
5300 printf ("DW_OP_breg17: %ld", read_leb128 (data
, NULL
, 1));
5303 printf ("DW_OP_breg18: %ld", read_leb128 (data
, NULL
, 1));
5306 printf ("DW_OP_breg19: %ld", read_leb128 (data
, NULL
, 1));
5309 printf ("DW_OP_breg20: %ld", read_leb128 (data
, NULL
, 1));
5312 printf ("DW_OP_breg21: %ld", read_leb128 (data
, NULL
, 1));
5315 printf ("DW_OP_breg22: %ld", read_leb128 (data
, NULL
, 1));
5318 printf ("DW_OP_breg23: %ld", read_leb128 (data
, NULL
, 1));
5321 printf ("DW_OP_breg24: %ld", read_leb128 (data
, NULL
, 1));
5324 printf ("DW_OP_breg25: %ld", read_leb128 (data
, NULL
, 1));
5327 printf ("DW_OP_breg26: %ld", read_leb128 (data
, NULL
, 1));
5330 printf ("DW_OP_breg27: %ld", read_leb128 (data
, NULL
, 1));
5333 printf ("DW_OP_breg28: %ld", read_leb128 (data
, NULL
, 1));
5336 printf ("DW_OP_breg29: %ld", read_leb128 (data
, NULL
, 1));
5339 printf ("DW_OP_breg30: %ld", read_leb128 (data
, NULL
, 1));
5342 printf ("DW_OP_breg31: %ld", read_leb128 (data
, NULL
, 1));
5345 printf ("DW_OP_regx: %lu", read_leb128 (data
, NULL
, 0));
5348 printf ("DW_OP_fbreg: %ld", read_leb128 (data
, NULL
, 1));
5351 uvalue
= read_leb128 (data
, &bytes_read
, 0);
5352 printf ("DW_OP_bregx: %lu %ld", uvalue
,
5353 read_leb128 (data
+ bytes_read
, NULL
, 1));
5356 printf ("DW_OP_piece: %lu", read_leb128 (data
, NULL
, 0));
5358 case DW_OP_deref_size
:
5359 printf ("DW_OP_deref_size: %ld", (long) byte_get (data
, 1));
5361 case DW_OP_xderef_size
:
5362 printf ("DW_OP_xderef_size: %ld", (long) byte_get (data
, 1));
5365 printf ("DW_OP_nop");
5369 if (op
>= DW_OP_lo_user
5370 && op
<= DW_OP_hi_user
)
5371 printf (_("(User defined location op)"));
5373 printf (_("(Unknown location op)"));
5379 static unsigned char *
5380 read_and_display_attr (attribute
, form
, data
, pointer_size
)
5381 unsigned long attribute
;
5383 unsigned char * data
;
5384 unsigned long pointer_size
;
5386 unsigned long uvalue
= 0;
5387 unsigned char * block_start
= NULL
;
5391 printf (" %-18s:", get_AT_name (attribute
));
5395 case DW_FORM_ref_addr
:
5400 case DW_FORM_ref_udata
:
5406 case DW_FORM_ref_addr
:
5408 uvalue
= byte_get (data
, pointer_size
);
5409 printf (is_ref
? " <%x>" : " %#x", uvalue
);
5410 data
+= pointer_size
;
5416 uvalue
= byte_get (data
++, 1);
5417 printf (is_ref
? " <%x>" : " %d", uvalue
);
5422 uvalue
= byte_get (data
, 2);
5424 printf (is_ref
? " <%x>" : " %d", uvalue
);
5429 uvalue
= byte_get (data
, 4);
5431 printf (is_ref
? " <%x>" : " %d", uvalue
);
5436 uvalue
= byte_get (data
, 4);
5437 printf (" %lx", uvalue
);
5438 printf (" %lx", (unsigned long) byte_get (data
+ 4, 4));
5442 case DW_FORM_string
:
5443 printf (" %s", data
);
5444 data
+= strlen (data
) + 1;
5448 uvalue
= read_leb128 (data
, & bytes_read
, 1);
5450 printf (" %ld", (long) uvalue
);
5453 case DW_FORM_ref_udata
:
5455 uvalue
= read_leb128 (data
, & bytes_read
, 0);
5457 printf (is_ref
? " <%lx>" : " %ld", uvalue
);
5461 uvalue
= read_leb128 (data
, & bytes_read
, 0);
5462 block_start
= data
+ bytes_read
;
5463 data
= display_block (block_start
, uvalue
);
5464 uvalue
= * block_start
;
5467 case DW_FORM_block1
:
5468 uvalue
= byte_get (data
, 1);
5469 block_start
= data
+ 1;
5470 data
= display_block (block_start
, uvalue
);
5471 uvalue
= * block_start
;
5474 case DW_FORM_block2
:
5475 uvalue
= byte_get (data
, 2);
5476 block_start
= data
+ 2;
5477 data
= display_block (block_start
, uvalue
);
5478 uvalue
= * block_start
;
5481 case DW_FORM_block4
:
5482 uvalue
= byte_get (data
, 4);
5483 block_start
= data
+ 4;
5484 data
= display_block (block_start
, uvalue
);
5485 uvalue
= * block_start
;
5489 case DW_FORM_indirect
:
5490 warn (_("Unable to handle FORM: %d"), form
);
5494 warn (_("Unrecognised form: %d"), form
);
5498 /* For some attributes we can display futher information. */
5507 case DW_INL_not_inlined
: printf (_("(not inlined)")); break;
5508 case DW_INL_inlined
: printf (_("(inlined)")); break;
5509 case DW_INL_declared_not_inlined
: printf (_("(declared as inline but ignored)")); break;
5510 case DW_INL_declared_inlined
: printf (_("(declared as inline and inlined)")); break;
5511 default: printf (_(" (Unknown inline attribute value: %lx)"), uvalue
); break;
5515 case DW_AT_frame_base
:
5516 if (uvalue
>= DW_OP_reg0
&& uvalue
<= DW_OP_reg31
)
5517 printf ("(reg %ld)", uvalue
- DW_OP_reg0
);
5520 case DW_AT_language
:
5523 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
5524 case DW_LANG_C89
: printf ("(ANSI C)"); break;
5525 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
5526 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
5527 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
5528 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
5529 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
5530 case DW_LANG_Ada83
: printf ("(Ada)"); break;
5531 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
5532 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
5533 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
5534 default: printf ("(Unknown: %lx)", uvalue
); break;
5538 case DW_AT_encoding
:
5541 case DW_ATE_void
: printf ("(void)"); break;
5542 case DW_ATE_address
: printf ("(machine address)"); break;
5543 case DW_ATE_boolean
: printf ("(boolean)"); break;
5544 case DW_ATE_complex_float
: printf ("(complex float)"); break;
5545 case DW_ATE_float
: printf ("(float)"); break;
5546 case DW_ATE_signed
: printf ("(signed)"); break;
5547 case DW_ATE_signed_char
: printf ("(signed char)"); break;
5548 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
5549 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
5551 if (uvalue
>= DW_ATE_lo_user
5552 && uvalue
<= DW_ATE_hi_user
)
5553 printf ("(user defined type)");
5555 printf ("(unknown type)");
5560 case DW_AT_accessibility
:
5563 case DW_ACCESS_public
: printf ("(public)"); break;
5564 case DW_ACCESS_protected
: printf ("(protected)"); break;
5565 case DW_ACCESS_private
: printf ("(private)"); break;
5566 default: printf ("(unknown accessibility)"); break;
5570 case DW_AT_visibility
:
5573 case DW_VIS_local
: printf ("(local)"); break;
5574 case DW_VIS_exported
: printf ("(exported)"); break;
5575 case DW_VIS_qualified
: printf ("(qualified)"); break;
5576 default: printf ("(unknown visibility)"); break;
5580 case DW_AT_virtuality
:
5583 case DW_VIRTUALITY_none
: printf ("(none)"); break;
5584 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
5585 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
5586 default: printf ("(unknown virtuality)"); break;
5590 case DW_AT_identifier_case
:
5593 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
5594 case DW_ID_up_case
: printf ("(up_case)"); break;
5595 case DW_ID_down_case
: printf ("(down_case)"); break;
5596 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
5597 default: printf ("(unknown case)"); break;
5601 case DW_AT_calling_convention
:
5604 case DW_CC_normal
: printf ("(normal)"); break;
5605 case DW_CC_program
: printf ("(program)"); break;
5606 case DW_CC_nocall
: printf ("(nocall)"); break;
5608 if (uvalue
>= DW_CC_lo_user
5609 && uvalue
<= DW_CC_hi_user
)
5610 printf ("(user defined)");
5612 printf ("(unknown convention)");
5616 case DW_AT_location
:
5617 case DW_AT_data_member_location
:
5618 case DW_AT_vtable_elem_location
:
5620 decode_location_expression (block_start
, pointer_size
);
5633 display_debug_info (section
, start
, file
)
5634 Elf32_Internal_Shdr
* section
;
5635 unsigned char * start
;
5638 unsigned char * end
= start
+ section
->sh_size
;
5639 unsigned char * section_begin
= start
;
5641 printf (_("The section %s contains:\n\n"), SECTION_NAME (section
));
5645 DWARF2_External_CompUnit
* external
;
5646 DWARF2_Internal_CompUnit compunit
;
5647 unsigned char * tags
;
5651 external
= (DWARF2_External_CompUnit
*) start
;
5653 compunit
.cu_length
= BYTE_GET (external
->cu_length
);
5654 compunit
.cu_version
= BYTE_GET (external
->cu_version
);
5655 compunit
.cu_abbrev_offset
= BYTE_GET (external
->cu_abbrev_offset
);
5656 compunit
.cu_pointer_size
= BYTE_GET (external
->cu_pointer_size
);
5658 tags
= start
+ sizeof (* external
);
5659 start
+= compunit
.cu_length
+ sizeof (external
->cu_length
);
5661 if (compunit
.cu_version
!= 2)
5663 warn (_("Only version 2 DWARF debug information is currently supported.\n"));
5667 printf (_(" Compilation Unit:\n"));
5668 printf (_(" Length: %ld\n"), compunit
.cu_length
);
5669 printf (_(" Version: %d\n"), compunit
.cu_version
);
5670 printf (_(" Abbrev Offset: %ld\n"), compunit
.cu_abbrev_offset
);
5671 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
5673 if (first_abbrev
!= NULL
)
5676 /* Read in the abbrevs used by this compilation unit. */
5679 Elf32_Internal_Shdr
* sec
;
5680 unsigned char * begin
;
5682 /* Locate the .debug_abbrev section and process it. */
5683 for (i
= 0, sec
= section_headers
;
5684 i
< elf_header
.e_shnum
;
5686 if (strcmp (SECTION_NAME (sec
), ".debug_abbrev") == 0)
5689 if (i
== -1 || sec
->sh_size
== 0)
5691 warn (_("Unable to locate .debug_abbrev section!\n"));
5695 GET_DATA_ALLOC (sec
->sh_offset
, sec
->sh_size
, begin
, unsigned char *,
5696 "debug_abbrev section data");
5698 process_abbrev_section (begin
+ compunit
.cu_abbrev_offset
,
5699 begin
+ sec
->sh_size
);
5705 while (tags
< start
)
5708 unsigned long abbrev_number
;
5709 abbrev_entry
* entry
;
5712 abbrev_number
= read_leb128 (tags
, & bytes_read
, 0);
5715 /* A null DIE marks the end of a list of children. */
5716 if (abbrev_number
== 0)
5722 /* Scan through the abbreviation list until we reach the
5724 for (entry
= first_abbrev
;
5725 entry
&& entry
->entry
!= abbrev_number
;
5726 entry
= entry
->next
)
5731 warn (_("Unable to locate entry %lu in the abbreviation table\n"),
5736 printf (_(" <%d><%x>: Abbrev Number: %lu (%s)\n"),
5737 level
, tags
- section_begin
- bytes_read
,
5739 get_TAG_name (entry
->tag
));
5741 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
5742 tags
= read_and_display_attr (attr
->attribute
,
5745 compunit
.cu_pointer_size
);
5747 if (entry
->children
)
5758 display_debug_aranges (section
, start
, file
)
5759 Elf32_Internal_Shdr
* section
;
5760 unsigned char * start
;
5761 FILE * file ATTRIBUTE_UNUSED
;
5763 unsigned char * end
= start
+ section
->sh_size
;
5765 printf (_("The section %s contains:\n\n"), SECTION_NAME (section
));
5769 DWARF2_External_ARange
* external
;
5770 DWARF2_Internal_ARange arange
;
5771 unsigned char * ranges
;
5772 unsigned long length
;
5773 unsigned long address
;
5776 external
= (DWARF2_External_ARange
*) start
;
5778 arange
.ar_length
= BYTE_GET (external
->ar_length
);
5779 arange
.ar_version
= BYTE_GET (external
->ar_version
);
5780 arange
.ar_info_offset
= BYTE_GET (external
->ar_info_offset
);
5781 arange
.ar_pointer_size
= BYTE_GET (external
->ar_pointer_size
);
5782 arange
.ar_segment_size
= BYTE_GET (external
->ar_segment_size
);
5784 printf (_(" Length: %ld\n"), arange
.ar_length
);
5785 printf (_(" Version: %d\n"), arange
.ar_version
);
5786 printf (_(" Offset into .debug_info: %lx\n"), arange
.ar_info_offset
);
5787 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
5788 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
5790 printf (_("\n Address Length\n"));
5792 ranges
= start
+ sizeof (* external
);
5794 /* Must pad to an alignment boundary that is twice the pointer size. */
5795 excess
= sizeof (*external
) % (2 * arange
.ar_pointer_size
);
5797 ranges
+= (2 * arange
.ar_pointer_size
) - excess
;
5801 address
= byte_get (ranges
, arange
.ar_pointer_size
);
5803 ranges
+= arange
.ar_pointer_size
;
5805 length
= byte_get (ranges
, arange
.ar_pointer_size
);
5807 ranges
+= arange
.ar_pointer_size
;
5809 /* A pair of zeros marks the end of the list. */
5810 if (address
== 0 && length
== 0)
5813 printf (" %8.8lx %lu\n", address
, length
);
5816 start
+= arange
.ar_length
+ sizeof (external
->ar_length
);
5826 display_debug_not_supported (section
, start
, file
)
5827 Elf32_Internal_Shdr
* section
;
5828 unsigned char * start ATTRIBUTE_UNUSED
;
5829 FILE * file ATTRIBUTE_UNUSED
;
5831 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
5832 SECTION_NAME (section
));
5837 /* Pre-scan the .debug_info section to record the size of address.
5838 When dumping the .debug_line, we use that size information, assuming
5839 that all compilation units have the same address size. */
5841 prescan_debug_info (section
, start
, file
)
5842 Elf32_Internal_Shdr
* section ATTRIBUTE_UNUSED
;
5843 unsigned char * start
;
5844 FILE * file ATTRIBUTE_UNUSED
;
5846 DWARF2_External_CompUnit
* external
;
5848 external
= (DWARF2_External_CompUnit
*) start
;
5850 debug_line_pointer_size
= BYTE_GET (external
->cu_pointer_size
);
5854 /* A structure containing the name of a debug section and a pointer
5855 to a function that can decode it. The third field is a prescan
5856 function to be run over the section before displaying any of the
5861 int (* display
) PARAMS ((Elf32_Internal_Shdr
*, unsigned char *, FILE *));
5862 int (* prescan
) PARAMS ((Elf32_Internal_Shdr
*, unsigned char *, FILE *));
5866 { ".debug_info", display_debug_info
, prescan_debug_info
},
5867 { ".debug_abbrev", display_debug_abbrev
, NULL
},
5868 { ".debug_line", display_debug_lines
, NULL
},
5869 { ".debug_aranges", display_debug_aranges
, NULL
},
5870 { ".debug_pubnames", display_debug_pubnames
, NULL
},
5871 { ".debug_macinfo", display_debug_not_supported
, NULL
},
5872 { ".debug_frame", display_debug_not_supported
, NULL
},
5873 { ".debug_str", display_debug_not_supported
, NULL
},
5874 { ".debug_static_func", display_debug_not_supported
, NULL
},
5875 { ".debug_static_vars", display_debug_not_supported
, NULL
},
5876 { ".debug_types", display_debug_not_supported
, NULL
},
5877 { ".debug_weaknames", display_debug_not_supported
, NULL
}
5881 display_debug_section (section
, file
)
5882 Elf32_Internal_Shdr
* section
;
5885 char * name
= SECTION_NAME (section
);
5886 bfd_size_type length
;
5887 unsigned char * start
;
5890 length
= section
->sh_size
;
5893 printf (_("\nSection '%s' has no debugging data.\n"), name
);
5897 GET_DATA_ALLOC (section
->sh_offset
, length
, start
, unsigned char *,
5898 "debug section data");
5900 /* See if we know how to display the contents of this section. */
5901 for (i
= NUM_ELEM (debug_displays
); i
--;)
5902 if (strcmp (debug_displays
[i
].name
, name
) == 0)
5904 debug_displays
[i
].display (section
, start
, file
);
5909 printf (_("Unrecognised debug section: %s\n"), name
);
5913 /* If we loaded in the abbrev section at some point,
5914 we must release it here. */
5915 if (first_abbrev
!= NULL
)
5922 process_section_contents (file
)
5925 Elf32_Internal_Shdr
* section
;
5931 /* Pre-scan the debug sections to find some debug information not
5932 present in some of them. For the .debug_line, we must find out the
5933 size of address (specified in .debug_info and .debug_aranges). */
5934 for (i
= 0, section
= section_headers
;
5935 i
< elf_header
.e_shnum
&& i
< num_dump_sects
;
5938 char * name
= SECTION_NAME (section
);
5941 if (section
->sh_size
== 0)
5944 /* See if there is some pre-scan operation for this section. */
5945 for (j
= NUM_ELEM (debug_displays
); j
--;)
5946 if (strcmp (debug_displays
[j
].name
, name
) == 0)
5948 if (debug_displays
[j
].prescan
!= NULL
)
5950 bfd_size_type length
;
5951 unsigned char * start
;
5953 length
= section
->sh_size
;
5954 GET_DATA_ALLOC (section
->sh_offset
, length
, start
, unsigned char *,
5955 "debug section data");
5957 debug_displays
[j
].prescan (section
, start
, file
);
5965 for (i
= 0, section
= section_headers
;
5966 i
< elf_header
.e_shnum
&& i
< num_dump_sects
;
5969 #ifdef SUPPORT_DISASSEMBLY
5970 if (dump_sects
[i
] & DISASS_DUMP
)
5971 disassemble_section (section
, file
);
5973 if (dump_sects
[i
] & HEX_DUMP
)
5974 dump_section (section
, file
);
5976 if (dump_sects
[i
] & DEBUG_DUMP
)
5977 display_debug_section (section
, file
);
5980 if (i
< num_dump_sects
)
5981 warn (_("Some sections were not dumped because they do not exist!\n"));
5987 process_mips_fpe_exception (mask
)
5993 if (mask
& OEX_FPU_INEX
)
5994 fputs ("INEX", stdout
), first
= 0;
5995 if (mask
& OEX_FPU_UFLO
)
5996 printf ("%sUFLO", first
? "" : "|"), first
= 0;
5997 if (mask
& OEX_FPU_OFLO
)
5998 printf ("%sOFLO", first
? "" : "|"), first
= 0;
5999 if (mask
& OEX_FPU_DIV0
)
6000 printf ("%sDIV0", first
? "" : "|"), first
= 0;
6001 if (mask
& OEX_FPU_INVAL
)
6002 printf ("%sINVAL", first
? "" : "|");
6005 fputs ("0", stdout
);
6009 process_mips_specific (file
)
6012 Elf_Internal_Dyn
* entry
;
6013 size_t liblist_offset
= 0;
6014 size_t liblistno
= 0;
6015 size_t conflictsno
= 0;
6016 size_t options_offset
= 0;
6017 size_t conflicts_offset
= 0;
6019 /* We have a lot of special sections. Thanks SGI! */
6020 if (dynamic_segment
== NULL
)
6021 /* No information available. */
6024 for (entry
= dynamic_segment
; entry
->d_tag
!= DT_NULL
; ++entry
)
6025 switch (entry
->d_tag
)
6027 case DT_MIPS_LIBLIST
:
6028 liblist_offset
= entry
->d_un
.d_val
- loadaddr
;
6030 case DT_MIPS_LIBLISTNO
:
6031 liblistno
= entry
->d_un
.d_val
;
6033 case DT_MIPS_OPTIONS
:
6034 options_offset
= entry
->d_un
.d_val
- loadaddr
;
6036 case DT_MIPS_CONFLICT
:
6037 conflicts_offset
= entry
->d_un
.d_val
- loadaddr
;
6039 case DT_MIPS_CONFLICTNO
:
6040 conflictsno
= entry
->d_un
.d_val
;
6046 if (liblist_offset
!= 0 && liblistno
!= 0 && do_dynamic
)
6048 Elf32_External_Lib
* elib
;
6051 GET_DATA_ALLOC (liblist_offset
, liblistno
* sizeof (Elf32_External_Lib
),
6052 elib
, Elf32_External_Lib
*, "liblist");
6054 printf ("\nSection '.liblist' contains %d entries:\n", liblistno
);
6055 fputs (" Library Time Stamp Checksum Version Flags\n",
6058 for (cnt
= 0; cnt
< liblistno
; ++cnt
)
6064 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
6065 time
= BYTE_GET (elib
[cnt
].l_time_stamp
);
6066 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
6067 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
6068 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
6070 strftime (timebuf
, 20, "%Y-%m-%dT%H:%M:%S", gmtime (&time
));
6072 printf ("%3d: %-20s %s %#10lx %-7ld", cnt
,
6073 dynamic_strings
+ liblist
.l_name
, timebuf
,
6074 liblist
.l_checksum
, liblist
.l_version
);
6076 if (liblist
.l_flags
== 0)
6086 { " EXACT_MATCH", LL_EXACT_MATCH
},
6087 { " IGNORE_INT_VER", LL_IGNORE_INT_VER
},
6088 { " REQUIRE_MINOR", LL_REQUIRE_MINOR
},
6089 { " EXPORTS", LL_EXPORTS
},
6090 { " DELAY_LOAD", LL_DELAY_LOAD
},
6091 { " DELTA", LL_DELTA
}
6093 int flags
= liblist
.l_flags
;
6097 fcnt
< sizeof (l_flags_vals
) / sizeof (l_flags_vals
[0]);
6099 if ((flags
& l_flags_vals
[fcnt
].bit
) != 0)
6101 fputs (l_flags_vals
[fcnt
].name
, stdout
);
6102 flags
^= l_flags_vals
[fcnt
].bit
;
6105 printf (" %#x", (unsigned int) flags
);
6114 if (options_offset
!= 0)
6116 Elf_External_Options
* eopt
;
6117 Elf_Internal_Shdr
* sect
= section_headers
;
6118 Elf_Internal_Options
* iopt
;
6119 Elf_Internal_Options
* option
;
6123 /* Find the section header so that we get the size. */
6124 while (sect
->sh_type
!= SHT_MIPS_OPTIONS
)
6127 GET_DATA_ALLOC (options_offset
, sect
->sh_size
, eopt
,
6128 Elf_External_Options
*, "options");
6130 iopt
= (Elf_Internal_Options
*) malloc ((sect
->sh_size
/ sizeof (eopt
))
6134 error (_("Out of memory"));
6140 while (offset
< sect
->sh_size
)
6142 Elf_External_Options
* eoption
;
6144 eoption
= (Elf_External_Options
*) ((char *) eopt
+ offset
);
6146 option
->kind
= BYTE_GET (eoption
->kind
);
6147 option
->size
= BYTE_GET (eoption
->size
);
6148 option
->section
= BYTE_GET (eoption
->section
);
6149 option
->info
= BYTE_GET (eoption
->info
);
6151 offset
+= option
->size
;
6156 printf (_("\nSection '%s' contains %d entries:\n"),
6157 string_table
+ sect
->sh_name
, cnt
);
6164 switch (option
->kind
)
6167 /* This shouldn't happen. */
6168 printf (" NULL %d %lx", option
->section
, option
->info
);
6171 printf (" REGINFO ");
6172 if (elf_header
.e_machine
== EM_MIPS
)
6175 Elf32_External_RegInfo
*ereg
;
6176 Elf32_RegInfo reginfo
;
6178 ereg
= (Elf32_External_RegInfo
*) (option
+ 1);
6179 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
6180 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
6181 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
6182 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
6183 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
6184 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
6186 printf ("GPR %08lx GP 0x%lx\n",
6188 (unsigned long) reginfo
.ri_gp_value
);
6189 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
6190 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
6191 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
6196 Elf64_External_RegInfo
* ereg
;
6197 Elf64_Internal_RegInfo reginfo
;
6199 ereg
= (Elf64_External_RegInfo
*) (option
+ 1);
6200 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
6201 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
6202 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
6203 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
6204 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
6205 reginfo
.ri_gp_value
= BYTE_GET8 (ereg
->ri_gp_value
);
6207 printf ("GPR %08lx GP 0x",
6208 reginfo
.ri_gprmask
);
6209 printf_vma (reginfo
.ri_gp_value
);
6212 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
6213 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
6214 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
6218 case ODK_EXCEPTIONS
:
6219 fputs (" EXCEPTIONS fpe_min(", stdout
);
6220 process_mips_fpe_exception (option
->info
& OEX_FPU_MIN
);
6221 fputs (") fpe_max(", stdout
);
6222 process_mips_fpe_exception ((option
->info
& OEX_FPU_MAX
) >> 8);
6223 fputs (")", stdout
);
6225 if (option
->info
& OEX_PAGE0
)
6226 fputs (" PAGE0", stdout
);
6227 if (option
->info
& OEX_SMM
)
6228 fputs (" SMM", stdout
);
6229 if (option
->info
& OEX_FPDBUG
)
6230 fputs (" FPDBUG", stdout
);
6231 if (option
->info
& OEX_DISMISS
)
6232 fputs (" DISMISS", stdout
);
6235 fputs (" PAD ", stdout
);
6236 if (option
->info
& OPAD_PREFIX
)
6237 fputs (" PREFIX", stdout
);
6238 if (option
->info
& OPAD_POSTFIX
)
6239 fputs (" POSTFIX", stdout
);
6240 if (option
->info
& OPAD_SYMBOL
)
6241 fputs (" SYMBOL", stdout
);
6244 fputs (" HWPATCH ", stdout
);
6245 if (option
->info
& OHW_R4KEOP
)
6246 fputs (" R4KEOP", stdout
);
6247 if (option
->info
& OHW_R8KPFETCH
)
6248 fputs (" R8KPFETCH", stdout
);
6249 if (option
->info
& OHW_R5KEOP
)
6250 fputs (" R5KEOP", stdout
);
6251 if (option
->info
& OHW_R5KCVTL
)
6252 fputs (" R5KCVTL", stdout
);
6255 fputs (" FILL ", stdout
);
6256 /* XXX Print content of info word? */
6259 fputs (" TAGS ", stdout
);
6260 /* XXX Print content of info word? */
6263 fputs (" HWAND ", stdout
);
6264 if (option
->info
& OHWA0_R4KEOP_CHECKED
)
6265 fputs (" R4KEOP_CHECKED", stdout
);
6266 if (option
->info
& OHWA0_R4KEOP_CLEAN
)
6267 fputs (" R4KEOP_CLEAN", stdout
);
6270 fputs (" HWOR ", stdout
);
6271 if (option
->info
& OHWA0_R4KEOP_CHECKED
)
6272 fputs (" R4KEOP_CHECKED", stdout
);
6273 if (option
->info
& OHWA0_R4KEOP_CLEAN
)
6274 fputs (" R4KEOP_CLEAN", stdout
);
6277 printf (" GP_GROUP %#06lx self-contained %#06lx",
6278 option
->info
& OGP_GROUP
,
6279 (option
->info
& OGP_SELF
) >> 16);
6282 printf (" IDENT %#06lx self-contained %#06lx",
6283 option
->info
& OGP_GROUP
,
6284 (option
->info
& OGP_SELF
) >> 16);
6287 /* This shouldn't happen. */
6288 printf (" %3d ??? %d %lx",
6289 option
->kind
, option
->section
, option
->info
);
6293 len
= sizeof (*eopt
);
6294 while (len
< option
->size
)
6295 if (((char *) option
)[len
] >= ' '
6296 && ((char *) option
)[len
] < 0x7f)
6297 printf ("%c", ((char *) option
)[len
++]);
6299 printf ("\\%03o", ((char *) option
)[len
++]);
6301 fputs ("\n", stdout
);
6308 if (conflicts_offset
!= 0 && conflictsno
!= 0)
6310 Elf32_External_Conflict
* econf32
;
6311 Elf64_External_Conflict
* econf64
;
6312 Elf32_Conflict
* iconf
;
6315 if (dynamic_symbols
== NULL
)
6317 error (_("conflict list with without table"));
6321 iconf
= (Elf32_Conflict
*) malloc (conflictsno
* sizeof (*iconf
));
6324 error (_("Out of memory"));
6330 GET_DATA_ALLOC (conflicts_offset
, conflictsno
* sizeof (*econf32
),
6331 econf32
, Elf32_External_Conflict
*, "conflict");
6333 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
6334 iconf
[cnt
] = BYTE_GET (econf32
[cnt
]);
6338 GET_DATA_ALLOC (conflicts_offset
, conflictsno
* sizeof (*econf64
),
6339 econf64
, Elf64_External_Conflict
*, "conflict");
6341 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
6342 iconf
[cnt
] = BYTE_GET (econf64
[cnt
]);
6345 printf (_("\nSection '.conflict' contains %d entries:\n"), conflictsno
);
6346 puts (_(" Num: Index Value Name"));
6348 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
6350 Elf_Internal_Sym
* psym
= &dynamic_symbols
[iconf
[cnt
]];
6352 printf ("%5u: %8lu %#10lx %s\n",
6353 cnt
, iconf
[cnt
], (unsigned long) psym
->st_value
,
6354 dynamic_strings
+ psym
->st_name
);
6365 get_note_type (e_type
)
6368 static char buff
[64];
6372 case NT_PRSTATUS
: return _("NT_PRSTATUS (prstatus structure)");
6373 case NT_FPREGSET
: return _("NT_FPREGSET (floating point registers)");
6374 case NT_PRPSINFO
: return _("NT_PRPSINFO (prpsinfo structure)");
6375 case NT_TASKSTRUCT
: return _("NT_TASKSTRUCT (task structure)");
6376 case NT_PSTATUS
: return _("NT_PSTATUS (pstatus structure)");
6377 case NT_FPREGS
: return _("NT_FPREGS (floating point registers)");
6378 case NT_PSINFO
: return _("NT_PSINFO (psinfo structure)");
6379 case NT_LWPSTATUS
: return _("NT_LWPSTATUS (lwpstatus_t structure)");
6380 case NT_LWPSINFO
: return _("NT_LWPSINFO (lwpsinfo_t structure)");
6382 sprintf (buff
, _("Unknown note type: (0x%08x)"), e_type
);
6388 process_note (pnote
)
6389 Elf_External_Note
* pnote
;
6391 Elf32_Internal_Note
* internal
;
6394 internal
= (Elf32_Internal_Note
*) pnote
;
6395 pname
= malloc (internal
->namesz
+ 1);
6399 error (_("Out of memory\n"));
6403 memcpy (pname
, pnote
->name
, internal
->namesz
);
6404 pname
[internal
->namesz
] = '\0';
6406 printf (" %s\t\t0x%08lx\t%s\n",
6407 pname
, internal
->descsz
, get_note_type (internal
->type
));
6415 process_corefile_note_segment (file
, offset
, length
)
6417 unsigned long offset
;
6418 unsigned long length
;
6420 Elf_External_Note
* pnotes
;
6421 Elf_External_Note
* external
;
6422 Elf32_Internal_Note
* internal
;
6423 unsigned int notesz
;
6424 unsigned int nlength
;
6431 GET_DATA_ALLOC (offset
, length
, pnotes
, Elf_External_Note
*, "notes");
6434 p
= (unsigned char *) pnotes
;
6437 printf (_("\nNotes at offset 0x%08lx with length 0x%08lx:\n"), offset
, length
);
6438 printf (_(" Owner\t\tData size\tDescription\n"));
6442 res
&= process_note (external
);
6444 internal
= (Elf32_Internal_Note
*) p
;
6445 notesz
= 3 * sizeof(unsigned long) + internal
->namesz
+ internal
->descsz
;
6448 external
= (Elf_External_Note
*) p
;
6457 process_corefile_note_segments (file
)
6460 Elf_Internal_Phdr
* program_headers
;
6461 Elf_Internal_Phdr
* segment
;
6465 program_headers
= (Elf_Internal_Phdr
*) malloc
6466 (elf_header
.e_phnum
* sizeof (Elf_Internal_Phdr
));
6468 if (program_headers
== NULL
)
6470 error (_("Out of memory\n"));
6475 i
= get_32bit_program_headers (file
, program_headers
);
6477 i
= get_64bit_program_headers (file
, program_headers
);
6481 free (program_headers
);
6485 for (i
= 0, segment
= program_headers
;
6486 i
< elf_header
.e_phnum
;
6489 if (segment
->p_type
== PT_NOTE
)
6490 res
&= process_corefile_note_segment (file
,
6491 (unsigned long)segment
->p_offset
,
6492 (unsigned long)segment
->p_filesz
);
6495 free (program_headers
);
6501 process_corefile_contents (file
)
6504 /* If we have not been asked to display the notes then do nothing. */
6508 /* If file is not a core file then exit. */
6509 if (elf_header
.e_type
!= ET_CORE
)
6512 /* No program headers means no NOTE segment. */
6513 if (elf_header
.e_phnum
== 0)
6515 printf (_("No note segments present in the core file.\n"));
6519 return process_corefile_note_segments (file
);
6523 process_arch_specific (file
)
6529 switch (elf_header
.e_machine
)
6532 case EM_MIPS_RS4_BE
:
6533 return process_mips_specific (file
);
6542 get_file_header (file
)
6545 /* Read in the identity array. */
6546 if (fread (elf_header
.e_ident
, EI_NIDENT
, 1, file
) != 1)
6549 /* Determine how to read the rest of the header. */
6550 switch (elf_header
.e_ident
[EI_DATA
])
6552 default: /* fall through */
6553 case ELFDATANONE
: /* fall through */
6554 case ELFDATA2LSB
: byte_get
= byte_get_little_endian
; break;
6555 case ELFDATA2MSB
: byte_get
= byte_get_big_endian
; break;
6558 /* For now we only support 32 bit and 64 bit ELF files. */
6559 is_32bit_elf
= (elf_header
.e_ident
[EI_CLASS
] != ELFCLASS64
);
6561 /* Read in the rest of the header. */
6564 Elf32_External_Ehdr ehdr32
;
6566 if (fread (ehdr32
.e_type
, sizeof (ehdr32
) - EI_NIDENT
, 1, file
) != 1)
6569 elf_header
.e_type
= BYTE_GET (ehdr32
.e_type
);
6570 elf_header
.e_machine
= BYTE_GET (ehdr32
.e_machine
);
6571 elf_header
.e_version
= BYTE_GET (ehdr32
.e_version
);
6572 elf_header
.e_entry
= BYTE_GET (ehdr32
.e_entry
);
6573 elf_header
.e_phoff
= BYTE_GET (ehdr32
.e_phoff
);
6574 elf_header
.e_shoff
= BYTE_GET (ehdr32
.e_shoff
);
6575 elf_header
.e_flags
= BYTE_GET (ehdr32
.e_flags
);
6576 elf_header
.e_ehsize
= BYTE_GET (ehdr32
.e_ehsize
);
6577 elf_header
.e_phentsize
= BYTE_GET (ehdr32
.e_phentsize
);
6578 elf_header
.e_phnum
= BYTE_GET (ehdr32
.e_phnum
);
6579 elf_header
.e_shentsize
= BYTE_GET (ehdr32
.e_shentsize
);
6580 elf_header
.e_shnum
= BYTE_GET (ehdr32
.e_shnum
);
6581 elf_header
.e_shstrndx
= BYTE_GET (ehdr32
.e_shstrndx
);
6585 Elf64_External_Ehdr ehdr64
;
6587 /* If we have been compiled with sizeof (bfd_vma) == 4, then
6588 we will not be able to cope with the 64bit data found in
6589 64 ELF files. Detect this now and abort before we start
6590 overwritting things. */
6591 if (sizeof (bfd_vma
) < 8)
6593 error (_("This instance of readelf has been built without support for a\n"));
6594 error (_("64 bit data type and so it cannot read 64 bit ELF files.\n"));
6598 if (fread (ehdr64
.e_type
, sizeof (ehdr64
) - EI_NIDENT
, 1, file
) != 1)
6601 elf_header
.e_type
= BYTE_GET (ehdr64
.e_type
);
6602 elf_header
.e_machine
= BYTE_GET (ehdr64
.e_machine
);
6603 elf_header
.e_version
= BYTE_GET (ehdr64
.e_version
);
6604 elf_header
.e_entry
= BYTE_GET8 (ehdr64
.e_entry
);
6605 elf_header
.e_phoff
= BYTE_GET8 (ehdr64
.e_phoff
);
6606 elf_header
.e_shoff
= BYTE_GET8 (ehdr64
.e_shoff
);
6607 elf_header
.e_flags
= BYTE_GET (ehdr64
.e_flags
);
6608 elf_header
.e_ehsize
= BYTE_GET (ehdr64
.e_ehsize
);
6609 elf_header
.e_phentsize
= BYTE_GET (ehdr64
.e_phentsize
);
6610 elf_header
.e_phnum
= BYTE_GET (ehdr64
.e_phnum
);
6611 elf_header
.e_shentsize
= BYTE_GET (ehdr64
.e_shentsize
);
6612 elf_header
.e_shnum
= BYTE_GET (ehdr64
.e_shnum
);
6613 elf_header
.e_shstrndx
= BYTE_GET (ehdr64
.e_shstrndx
);
6620 process_file (file_name
)
6624 struct stat statbuf
;
6627 if (stat (file_name
, & statbuf
) < 0)
6629 error (_("Cannot stat input file %s.\n"), file_name
);
6633 file
= fopen (file_name
, "rb");
6636 error (_("Input file %s not found.\n"), file_name
);
6640 if (! get_file_header (file
))
6642 error (_("%s: Failed to read file header\n"), file_name
);
6647 /* Initialise per file variables. */
6648 for (i
= NUM_ELEM (version_info
); i
--;)
6649 version_info
[i
] = 0;
6651 for (i
= NUM_ELEM (dynamic_info
); i
--;)
6652 dynamic_info
[i
] = 0;
6654 /* Process the file. */
6656 printf (_("\nFile: %s\n"), file_name
);
6658 if (! process_file_header ())
6664 process_section_headers (file
);
6666 process_program_headers (file
);
6668 process_dynamic_segment (file
);
6670 process_relocs (file
);
6672 process_symbol_table (file
);
6674 process_syminfo (file
);
6676 process_version_sections (file
);
6678 process_section_contents (file
);
6680 process_corefile_contents (file
);
6682 process_arch_specific (file
);
6686 if (section_headers
)
6688 free (section_headers
);
6689 section_headers
= NULL
;
6694 free (string_table
);
6695 string_table
= NULL
;
6698 if (dynamic_strings
)
6700 free (dynamic_strings
);
6701 dynamic_strings
= NULL
;
6704 if (dynamic_symbols
)
6706 free (dynamic_symbols
);
6707 dynamic_symbols
= NULL
;
6708 num_dynamic_syms
= 0;
6711 if (dynamic_syminfo
)
6713 free (dynamic_syminfo
);
6714 dynamic_syminfo
= NULL
;
6718 #ifdef SUPPORT_DISASSEMBLY
6719 /* Needed by the i386 disassembler. For extra credit, someone could
6720 fix this so that we insert symbolic addresses here, esp for GOT/PLT
6724 print_address (unsigned int addr
, FILE * outfile
)
6726 fprintf (outfile
,"0x%8.8x", addr
);
6729 /* Needed by the i386 disassembler. */
6731 db_task_printsym (unsigned int addr
)
6733 print_address (addr
, stderr
);
6742 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
6743 setlocale (LC_MESSAGES
, "");
6745 bindtextdomain (PACKAGE
, LOCALEDIR
);
6746 textdomain (PACKAGE
);
6748 parse_args (argc
, argv
);
6750 if (optind
< (argc
- 1))
6753 while (optind
< argc
)
6754 process_file (argv
[optind
++]);
6756 if (dump_sects
!= NULL
)