1 /* readelf.c -- display contents of an ELF format file
2 Copyright (C) 1998, 99, 2000 Free Software Foundation, Inc.
4 Originally developed by Eric Youngdale <eric@andante.jic.com>
5 Modifications by Nick Clifton <nickc@cygnus.com>
7 This file is part of GNU Binutils.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26 #include <sys/types.h>
32 /* Define BFD64 here, even if our default architecture is 32 bit ELF
33 as this will allow us to read in and parse 64bit and 32bit ELF files.
34 Only do this if we belive that the compiler can support a 64 bit
35 data type. For now we only rely on GCC being able to do this. */
41 #include "elf/common.h"
42 #include "elf/external.h"
43 #include "elf/internal.h"
44 #include "elf/dwarf2.h"
46 /* The following headers use the elf/reloc-macros.h file to
47 automatically generate relocation recognition functions
48 such as elf_mips_reloc_type() */
50 #define RELOC_MACROS_GEN_FUNC
56 #include "elf/alpha.h"
59 #include "elf/sparc.h"
64 #include "elf/mn10200.h"
65 #include "elf/mn10300.h"
69 #include "elf/mcore.h"
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
;
121 /* A dynamic array of flags indicating which sections require dumping. */
122 char * dump_sects
= NULL
;
123 unsigned int num_dump_sects
= 0;
125 #define HEX_DUMP (1 << 0)
126 #define DISASS_DUMP (1 << 1)
127 #define DEBUG_DUMP (1 << 2)
129 /* How to rpint a vma value. */
130 typedef enum print_mode
142 /* Forward declarations for dumb compilers. */
143 static void print_vma
PARAMS ((bfd_vma
, print_mode
));
144 static bfd_vma (* byte_get
) PARAMS ((unsigned char *, int));
145 static bfd_vma byte_get_little_endian
PARAMS ((unsigned char *, int));
146 static bfd_vma byte_get_big_endian
PARAMS ((unsigned char *, int));
147 static const char * get_mips_dynamic_type
PARAMS ((unsigned long));
148 static const char * get_sparc64_dynamic_type
PARAMS ((unsigned long));
149 static const char * get_parisc_dynamic_type
PARAMS ((unsigned long));
150 static const char * get_dynamic_type
PARAMS ((unsigned long));
151 static int dump_relocations
PARAMS ((FILE *, unsigned long, unsigned long, Elf_Internal_Sym
*, unsigned long, char *, int));
152 static char * get_file_type
PARAMS ((unsigned));
153 static char * get_machine_name
PARAMS ((unsigned));
154 static void decode_ARM_machine_flags
PARAMS ((unsigned, char []));
155 static char * get_machine_flags
PARAMS ((unsigned, unsigned));
156 static const char * get_mips_segment_type
PARAMS ((unsigned long));
157 static const char * get_parisc_segment_type
PARAMS ((unsigned long));
158 static const char * get_segment_type
PARAMS ((unsigned long));
159 static const char * get_mips_section_type_name
PARAMS ((unsigned int));
160 static const char * get_parisc_section_type_name
PARAMS ((unsigned int));
161 static const char * get_section_type_name
PARAMS ((unsigned int));
162 static const char * get_symbol_binding
PARAMS ((unsigned int));
163 static const char * get_symbol_type
PARAMS ((unsigned int));
164 static const char * get_symbol_visibility
PARAMS ((unsigned int));
165 static const char * get_symbol_index_type
PARAMS ((unsigned int));
166 static const char * get_dynamic_flags
PARAMS ((bfd_vma
));
167 static void usage
PARAMS ((void));
168 static void parse_args
PARAMS ((int, char **));
169 static int process_file_header
PARAMS ((void));
170 static int process_program_headers
PARAMS ((FILE *));
171 static int process_section_headers
PARAMS ((FILE *));
172 static void dynamic_segment_mips_val
PARAMS ((Elf_Internal_Dyn
*));
173 static void dynamic_segment_parisc_val
PARAMS ((Elf_Internal_Dyn
*));
174 static int process_dynamic_segment
PARAMS ((FILE *));
175 static int process_symbol_table
PARAMS ((FILE *));
176 static int process_section_contents
PARAMS ((FILE *));
177 static void process_file
PARAMS ((char *));
178 static int process_relocs
PARAMS ((FILE *));
179 static int process_version_sections
PARAMS ((FILE *));
180 static char * get_ver_flags
PARAMS ((unsigned int));
181 static int get_32bit_section_headers
PARAMS ((FILE *));
182 static int get_64bit_section_headers
PARAMS ((FILE *));
183 static int get_32bit_program_headers
PARAMS ((FILE *, Elf_Internal_Phdr
*));
184 static int get_64bit_program_headers
PARAMS ((FILE *, Elf_Internal_Phdr
*));
185 static int get_file_header
PARAMS ((FILE *));
186 static Elf_Internal_Sym
* get_32bit_elf_symbols
PARAMS ((FILE *, unsigned long, unsigned long));
187 static Elf_Internal_Sym
* get_64bit_elf_symbols
PARAMS ((FILE *, unsigned long, unsigned long));
188 static int * get_dynamic_data
PARAMS ((FILE *, unsigned int));
189 static int get_32bit_dynamic_segment
PARAMS ((FILE *));
190 static int get_64bit_dynamic_segment
PARAMS ((FILE *));
191 #ifdef SUPPORT_DISASSEMBLY
192 static int disassemble_section
PARAMS ((Elf32_Internal_Shdr
*, FILE *));
194 static int dump_section
PARAMS ((Elf32_Internal_Shdr
*, FILE *));
195 static int display_debug_section
PARAMS ((Elf32_Internal_Shdr
*, FILE *));
196 static int display_debug_info
PARAMS ((Elf32_Internal_Shdr
*, unsigned char *, FILE *));
197 static int display_debug_not_supported
PARAMS ((Elf32_Internal_Shdr
*, unsigned char *, FILE *));
198 static int display_debug_lines
PARAMS ((Elf32_Internal_Shdr
*, unsigned char *, FILE *));
199 static int display_debug_abbrev
PARAMS ((Elf32_Internal_Shdr
*, unsigned char *, FILE *));
200 static int display_debug_aranges
PARAMS ((Elf32_Internal_Shdr
*, unsigned char *, FILE *));
201 static int display_debug_frames
PARAMS ((Elf32_Internal_Shdr
*, unsigned char *, FILE *));
202 static unsigned char * process_abbrev_section
PARAMS ((unsigned char *, unsigned char *));
203 static unsigned long read_leb128
PARAMS ((unsigned char *, int *, int));
204 static int process_extended_line_op
PARAMS ((unsigned char *, int, int));
205 static void reset_state_machine
PARAMS ((int));
206 static char * get_TAG_name
PARAMS ((unsigned long));
207 static char * get_AT_name
PARAMS ((unsigned long));
208 static char * get_FORM_name
PARAMS ((unsigned long));
209 static void free_abbrevs
PARAMS ((void));
210 static void add_abbrev
PARAMS ((unsigned long, unsigned long, int));
211 static void add_abbrev_attr
PARAMS ((unsigned long, unsigned long));
212 static unsigned char * read_and_display_attr
PARAMS ((unsigned long, unsigned long, unsigned char *, unsigned long, unsigned long));
213 static unsigned char * display_block
PARAMS ((unsigned char *, unsigned long));
214 static void decode_location_expression
PARAMS ((unsigned char *, unsigned int, unsigned long));
215 static void request_dump
PARAMS ((unsigned int, char));
216 static const char * get_elf_class
PARAMS ((unsigned char));
217 static const char * get_data_encoding
PARAMS ((unsigned char));
218 static const char * get_osabi_name
PARAMS ((unsigned char));
219 static int guess_is_rela
PARAMS ((unsigned long));
220 static char * get_note_type
PARAMS ((unsigned int));
221 static int process_note
PARAMS ((Elf32_Internal_Note
*));
222 static int process_corefile_note_segment
PARAMS ((FILE *, bfd_vma
, bfd_vma
));
223 static int process_corefile_note_segments
PARAMS ((FILE *));
224 static int process_corefile_contents
PARAMS ((FILE *));
226 typedef int Elf32_Word
;
234 #define SECTION_NAME(X) (string_table + (X)->sh_name)
236 #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
238 #define BYTE_GET(field) byte_get (field, sizeof (field))
240 /* If we can support a 64 bit data type then BFD64 should be defined
241 and sizeof (bfd_vma) == 8. In this case when translating from an
242 external 8 byte field to an internal field, we can assume that the
243 internal field is also 8 bytes wide and so we can extact all the data.
244 If, however, BFD64 is not defined, then we must assume that the
245 internal data structure only has 4 byte wide fields that are the
246 equivalent of the 8 byte wide external counterparts, and so we must
247 truncate the data. */
249 #define BYTE_GET8(field) byte_get (field, -8)
251 #define BYTE_GET8(field) byte_get (field, 8)
254 #define NUM_ELEM(array) (sizeof (array) / sizeof ((array)[0]))
256 #define GET_DATA_ALLOC(offset, size, var, type, reason) \
257 if (fseek (file, offset, SEEK_SET)) \
259 error (_("Unable to seek to start of %s at %x\n"), reason, offset); \
263 var = (type) malloc (size); \
267 error (_("Out of memory allocating %d bytes for %s\n"), size, reason); \
271 if (fread (var, size, 1, file) != 1) \
273 error (_("Unable to read in %d bytes of %s\n"), size, reason); \
280 #define GET_DATA(offset, var, reason) \
281 if (fseek (file, offset, SEEK_SET)) \
283 error (_("Unable to seek to %x for %s\n"), offset, reason); \
286 else if (fread (& var, sizeof (var), 1, file) != 1) \
288 error (_("Unable to read data at %x for %s\n"), offset, reason); \
292 #define GET_ELF_SYMBOLS(file, offset, size) \
293 (is_32bit_elf ? get_32bit_elf_symbols (file, offset, size) \
294 : get_64bit_elf_symbols (file, offset, size))
297 #ifdef ANSI_PROTOTYPES
299 error (const char * message
, ...)
303 fprintf (stderr
, _("%s: Error: "), program_name
);
304 va_start (args
, message
);
305 vfprintf (stderr
, message
, args
);
311 warn (const char * message
, ...)
315 fprintf (stderr
, _("%s: Warning: "), program_name
);
316 va_start (args
, message
);
317 vfprintf (stderr
, message
, args
);
329 fprintf (stderr
, _("%s: Error: "), program_name
);
331 message
= va_arg (args
, char *);
332 vfprintf (stderr
, message
, args
);
344 fprintf (stderr
, _("%s: Warning: "), program_name
);
346 message
= va_arg (args
, char *);
347 vfprintf (stderr
, message
, args
);
354 byte_get_little_endian (field
, size
)
355 unsigned char * field
;
364 return ((unsigned int) (field
[0]))
365 | (((unsigned int) (field
[1])) << 8);
368 /* We want to extract data from an 8 byte wide field and
369 place it into a 4 byte wide field. Since this is a little
370 endian source we can juts use the 4 byte extraction code. */
373 return ((unsigned long) (field
[0]))
374 | (((unsigned long) (field
[1])) << 8)
375 | (((unsigned long) (field
[2])) << 16)
376 | (((unsigned long) (field
[3])) << 24);
380 /* This is a special case, generated by the BYTE_GET8 macro.
381 It means that we are loading an 8 byte value from a field
382 in an external structure into an 8 byte value in a field
383 in an internal strcuture. */
384 return ((bfd_vma
) (field
[0]))
385 | (((bfd_vma
) (field
[1])) << 8)
386 | (((bfd_vma
) (field
[2])) << 16)
387 | (((bfd_vma
) (field
[3])) << 24)
388 | (((bfd_vma
) (field
[4])) << 32)
389 | (((bfd_vma
) (field
[5])) << 40)
390 | (((bfd_vma
) (field
[6])) << 48)
391 | (((bfd_vma
) (field
[7])) << 56);
394 error (_("Unhandled data length: %d\n"), size
);
399 /* Print a VMA value. */
401 print_vma (vma
, mode
)
411 case FULL_HEX
: printf ("0x"); /* drop through */
412 case LONG_HEX
: printf ("%8.8lx", (unsigned long) vma
); break;
413 case PREFIX_HEX
: printf ("0x"); /* drop through */
414 case HEX
: printf ("%lx", (unsigned long) vma
); break;
415 case DEC
: printf ("%ld", (unsigned long) vma
); break;
416 case DEC_5
: printf ("%5ld", (long) vma
); break;
417 case UNSIGNED
: printf ("%lu", (unsigned long) vma
); break;
438 #if BFD_HOST_64BIT_LONG
441 if (_bfd_int64_high (vma
))
442 printf ("%lx%lx", _bfd_int64_high (vma
), _bfd_int64_low (vma
));
444 printf ("%lx", _bfd_int64_low (vma
));
449 #if BFD_HOST_64BIT_LONG
452 if (_bfd_int64_high (vma
))
454 printf ("++%ld", _bfd_int64_low (vma
));
456 printf ("%ld", _bfd_int64_low (vma
));
461 #if BFD_HOST_64BIT_LONG
462 printf ("%5ld", vma
);
464 if (_bfd_int64_high (vma
))
466 printf ("++%ld", _bfd_int64_low (vma
));
468 printf ("%5ld", _bfd_int64_low (vma
));
473 #if BFD_HOST_64BIT_LONG
476 if (_bfd_int64_high (vma
))
478 printf ("++%lu", _bfd_int64_low (vma
));
480 printf ("%lu", _bfd_int64_low (vma
));
489 byte_get_big_endian (field
, size
)
490 unsigned char * field
;
499 return ((unsigned int) (field
[1])) | (((int) (field
[0])) << 8);
502 return ((unsigned long) (field
[3]))
503 | (((unsigned long) (field
[2])) << 8)
504 | (((unsigned long) (field
[1])) << 16)
505 | (((unsigned long) (field
[0])) << 24);
508 /* Although we are extracing data from an 8 byte wide field, we
509 are returning only 4 bytes of data. */
510 return ((unsigned long) (field
[7]))
511 | (((unsigned long) (field
[6])) << 8)
512 | (((unsigned long) (field
[5])) << 16)
513 | (((unsigned long) (field
[4])) << 24);
517 /* This is a special case, generated by the BYTE_GET8 macro.
518 It means that we are loading an 8 byte value from a field
519 in an external structure into an 8 byte value in a field
520 in an internal strcuture. */
521 return ((bfd_vma
) (field
[7]))
522 | (((bfd_vma
) (field
[6])) << 8)
523 | (((bfd_vma
) (field
[5])) << 16)
524 | (((bfd_vma
) (field
[4])) << 24)
525 | (((bfd_vma
) (field
[3])) << 32)
526 | (((bfd_vma
) (field
[2])) << 40)
527 | (((bfd_vma
) (field
[1])) << 48)
528 | (((bfd_vma
) (field
[0])) << 56);
532 error (_("Unhandled data length: %d\n"), size
);
538 /* Guess the relocation sized based on the sized commonly used by the specific machine. */
540 guess_is_rela (e_machine
)
541 unsigned long e_machine
;
545 /* Targets that use REL relocations. */
556 /* Targets that use RELA relocations. */
564 case EM_CYGNUS_MN10200
:
565 case EM_CYGNUS_MN10300
:
595 warn (_("Don't know about relocations on this machine architecture\n"));
600 /* Display the contents of the relocation data found at the specified offset. */
602 dump_relocations (file
, rel_offset
, rel_size
, symtab
, nsyms
, strtab
, is_rela
)
604 unsigned long rel_offset
;
605 unsigned long rel_size
;
606 Elf_Internal_Sym
* symtab
;
612 Elf_Internal_Rel
* rels
;
613 Elf_Internal_Rela
* relas
;
616 if (is_rela
== UNKNOWN
)
617 is_rela
= guess_is_rela (elf_header
.e_machine
);
623 Elf32_External_Rela
* erelas
;
625 GET_DATA_ALLOC (rel_offset
, rel_size
, erelas
,
626 Elf32_External_Rela
*, "relocs");
628 rel_size
= rel_size
/ sizeof (Elf32_External_Rela
);
630 relas
= (Elf_Internal_Rela
*)
631 malloc (rel_size
* sizeof (Elf_Internal_Rela
));
635 error(_("out of memory parsing relocs"));
639 for (i
= 0; i
< rel_size
; i
++)
641 relas
[i
].r_offset
= BYTE_GET (erelas
[i
].r_offset
);
642 relas
[i
].r_info
= BYTE_GET (erelas
[i
].r_info
);
643 relas
[i
].r_addend
= BYTE_GET (erelas
[i
].r_addend
);
648 rels
= (Elf_Internal_Rel
*) relas
;
652 Elf64_External_Rela
* erelas
;
654 GET_DATA_ALLOC (rel_offset
, rel_size
, erelas
,
655 Elf64_External_Rela
*, "relocs");
657 rel_size
= rel_size
/ sizeof (Elf64_External_Rela
);
659 relas
= (Elf_Internal_Rela
*)
660 malloc (rel_size
* sizeof (Elf_Internal_Rela
));
664 error(_("out of memory parsing relocs"));
668 for (i
= 0; i
< rel_size
; i
++)
670 relas
[i
].r_offset
= BYTE_GET8 (erelas
[i
].r_offset
);
671 relas
[i
].r_info
= BYTE_GET8 (erelas
[i
].r_info
);
672 relas
[i
].r_addend
= BYTE_GET8 (erelas
[i
].r_addend
);
677 rels
= (Elf_Internal_Rel
*) relas
;
684 Elf32_External_Rel
* erels
;
686 GET_DATA_ALLOC (rel_offset
, rel_size
, erels
,
687 Elf32_External_Rel
*, "relocs");
689 rel_size
= rel_size
/ sizeof (Elf32_External_Rel
);
691 rels
= (Elf_Internal_Rel
*)
692 malloc (rel_size
* sizeof (Elf_Internal_Rel
));
696 error(_("out of memory parsing relocs"));
700 for (i
= 0; i
< rel_size
; i
++)
702 rels
[i
].r_offset
= BYTE_GET (erels
[i
].r_offset
);
703 rels
[i
].r_info
= BYTE_GET (erels
[i
].r_info
);
708 relas
= (Elf_Internal_Rela
*) rels
;
712 Elf64_External_Rel
* erels
;
714 GET_DATA_ALLOC (rel_offset
, rel_size
, erels
,
715 Elf64_External_Rel
*, "relocs");
717 rel_size
= rel_size
/ sizeof (Elf64_External_Rel
);
719 rels
= (Elf_Internal_Rel
*)
720 malloc (rel_size
* sizeof (Elf_Internal_Rel
));
724 error(_("out of memory parsing relocs"));
728 for (i
= 0; i
< rel_size
; i
++)
730 rels
[i
].r_offset
= BYTE_GET8 (erels
[i
].r_offset
);
731 rels
[i
].r_info
= BYTE_GET8 (erels
[i
].r_info
);
736 relas
= (Elf_Internal_Rela
*) rels
;
742 (_(" Offset Info Type Symbol's Value Symbol's Name Addend\n"));
745 (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
747 for (i
= 0; i
< rel_size
; i
++)
752 bfd_vma symtab_index
;
757 offset
= relas
[i
].r_offset
;
758 info
= relas
[i
].r_info
;
762 offset
= rels
[i
].r_offset
;
763 info
= rels
[i
].r_info
;
768 type
= ELF32_R_TYPE (info
);
769 symtab_index
= ELF32_R_SYM (info
);
773 if (elf_header
.e_machine
== EM_SPARCV9
)
774 type
= ELF64_R_TYPE_ID (info
);
776 type
= ELF64_R_TYPE (info
);
777 /* The #ifdef BFD64 below is to prevent a compile time warning.
778 We know that if we do not have a 64 bit data type that we
779 will never execute this code anyway. */
781 symtab_index
= ELF64_R_SYM (info
);
785 #ifdef _bfd_int64_low
786 printf (" %8.8lx %5.5lx ", _bfd_int64_low (offset
), _bfd_int64_low (info
));
788 printf (" %8.8lx %5.5lx ", offset
, info
);
791 switch (elf_header
.e_machine
)
798 rtype
= elf_m32r_reloc_type (type
);
803 rtype
= elf_i386_reloc_type (type
);
807 rtype
= elf_m68k_reloc_type (type
);
811 rtype
= elf_i960_reloc_type (type
);
815 rtype
= elf_avr_reloc_type (type
);
822 rtype
= elf_sparc_reloc_type (type
);
826 rtype
= v850_reloc_type (type
);
830 rtype
= elf_d10v_reloc_type (type
);
834 rtype
= elf_d30v_reloc_type (type
);
838 rtype
= elf_sh_reloc_type (type
);
841 case EM_CYGNUS_MN10300
:
842 rtype
= elf_mn10300_reloc_type (type
);
845 case EM_CYGNUS_MN10200
:
846 rtype
= elf_mn10200_reloc_type (type
);
850 rtype
= elf_fr30_reloc_type (type
);
854 rtype
= elf_mcore_reloc_type (type
);
858 rtype
= elf_ppc_reloc_type (type
);
863 rtype
= elf_mips_reloc_type (type
);
867 rtype
= elf_alpha_reloc_type (type
);
871 rtype
= elf_arm_reloc_type (type
);
875 rtype
= elf_arc_reloc_type (type
);
879 rtype
= elf_hppa_reloc_type (type
);
883 rtype
= elf_pj_reloc_type (type
);
886 rtype
= elf_ia64_reloc_type (type
);
890 rtype
= elf_cris_reloc_type (type
);
894 rtype
= elf_i860_reloc_type (type
);
899 #ifdef _bfd_int64_low
900 printf (_("unrecognised: %-7lx"), _bfd_int64_low (type
));
902 printf (_("unrecognised: %-7lx"), type
);
905 printf ("%-21.21s", rtype
);
911 if (symtab_index
>= nsyms
)
912 printf (" bad symbol index: %08lx", (unsigned long) symtab_index
);
915 Elf_Internal_Sym
* psym
;
917 psym
= symtab
+ symtab_index
;
920 print_vma (psym
->st_value
, LONG_HEX
);
923 if (psym
->st_name
== 0)
925 SECTION_NAME (section_headers
+ psym
->st_shndx
));
926 else if (strtab
== NULL
)
927 printf (_("<string table index %3ld>"), psym
->st_name
);
929 printf ("%-25.25s", strtab
+ psym
->st_name
);
932 printf (" + %lx", (unsigned long) relas
[i
].r_addend
);
938 printf ("%*c", is_32bit_elf
? 34 : 26, ' ');
939 print_vma (relas
[i
].r_addend
, LONG_HEX
);
942 if (elf_header
.e_machine
== EM_SPARCV9
943 && !strcmp (rtype
, "R_SPARC_OLO10"))
944 printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (info
));
955 get_mips_dynamic_type (type
)
960 case DT_MIPS_RLD_VERSION
: return "MIPS_RLD_VERSION";
961 case DT_MIPS_TIME_STAMP
: return "MIPS_TIME_STAMP";
962 case DT_MIPS_ICHECKSUM
: return "MIPS_ICHECKSUM";
963 case DT_MIPS_IVERSION
: return "MIPS_IVERSION";
964 case DT_MIPS_FLAGS
: return "MIPS_FLAGS";
965 case DT_MIPS_BASE_ADDRESS
: return "MIPS_BASE_ADDRESS";
966 case DT_MIPS_MSYM
: return "MIPS_MSYM";
967 case DT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
968 case DT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
969 case DT_MIPS_LOCAL_GOTNO
: return "MIPS_LOCAL_GOTNO";
970 case DT_MIPS_CONFLICTNO
: return "MIPS_CONFLICTNO";
971 case DT_MIPS_LIBLISTNO
: return "MIPS_LIBLISTNO";
972 case DT_MIPS_SYMTABNO
: return "MIPS_SYMTABNO";
973 case DT_MIPS_UNREFEXTNO
: return "MIPS_UNREFEXTNO";
974 case DT_MIPS_GOTSYM
: return "MIPS_GOTSYM";
975 case DT_MIPS_HIPAGENO
: return "MIPS_HIPAGENO";
976 case DT_MIPS_RLD_MAP
: return "MIPS_RLD_MAP";
977 case DT_MIPS_DELTA_CLASS
: return "MIPS_DELTA_CLASS";
978 case DT_MIPS_DELTA_CLASS_NO
: return "MIPS_DELTA_CLASS_NO";
979 case DT_MIPS_DELTA_INSTANCE
: return "MIPS_DELTA_INSTANCE";
980 case DT_MIPS_DELTA_INSTANCE_NO
: return "MIPS_DELTA_INSTANCE_NO";
981 case DT_MIPS_DELTA_RELOC
: return "MIPS_DELTA_RELOC";
982 case DT_MIPS_DELTA_RELOC_NO
: return "MIPS_DELTA_RELOC_NO";
983 case DT_MIPS_DELTA_SYM
: return "MIPS_DELTA_SYM";
984 case DT_MIPS_DELTA_SYM_NO
: return "MIPS_DELTA_SYM_NO";
985 case DT_MIPS_DELTA_CLASSSYM
: return "MIPS_DELTA_CLASSSYM";
986 case DT_MIPS_DELTA_CLASSSYM_NO
: return "MIPS_DELTA_CLASSSYM_NO";
987 case DT_MIPS_CXX_FLAGS
: return "MIPS_CXX_FLAGS";
988 case DT_MIPS_PIXIE_INIT
: return "MIPS_PIXIE_INIT";
989 case DT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
990 case DT_MIPS_LOCALPAGE_GOTIDX
: return "MIPS_LOCALPAGE_GOTIDX";
991 case DT_MIPS_LOCAL_GOTIDX
: return "MIPS_LOCAL_GOTIDX";
992 case DT_MIPS_HIDDEN_GOTIDX
: return "MIPS_HIDDEN_GOTIDX";
993 case DT_MIPS_PROTECTED_GOTIDX
: return "MIPS_PROTECTED_GOTIDX";
994 case DT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
995 case DT_MIPS_INTERFACE
: return "MIPS_INTERFACE";
996 case DT_MIPS_DYNSTR_ALIGN
: return "MIPS_DYNSTR_ALIGN";
997 case DT_MIPS_INTERFACE_SIZE
: return "MIPS_INTERFACE_SIZE";
998 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR
: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
999 case DT_MIPS_PERF_SUFFIX
: return "MIPS_PERF_SUFFIX";
1000 case DT_MIPS_COMPACT_SIZE
: return "MIPS_COMPACT_SIZE";
1001 case DT_MIPS_GP_VALUE
: return "MIPS_GP_VALUE";
1002 case DT_MIPS_AUX_DYNAMIC
: return "MIPS_AUX_DYNAMIC";
1009 get_sparc64_dynamic_type (type
)
1014 case DT_SPARC_REGISTER
: return "SPARC_REGISTER";
1021 get_parisc_dynamic_type (type
)
1026 case DT_HP_LOAD_MAP
: return "HP_LOAD_MAP";
1027 case DT_HP_DLD_FLAGS
: return "HP_DLD_FLAGS";
1028 case DT_HP_DLD_HOOK
: return "HP_DLD_HOOK";
1029 case DT_HP_UX10_INIT
: return "HP_UX10_INIT";
1030 case DT_HP_UX10_INITSZ
: return "HP_UX10_INITSZ";
1031 case DT_HP_PREINIT
: return "HP_PREINIT";
1032 case DT_HP_PREINITSZ
: return "HP_PREINITSZ";
1033 case DT_HP_NEEDED
: return "HP_NEEDED";
1034 case DT_HP_TIME_STAMP
: return "HP_TIME_STAMP";
1035 case DT_HP_CHECKSUM
: return "HP_CHECKSUM";
1036 case DT_HP_GST_SIZE
: return "HP_GST_SIZE";
1037 case DT_HP_GST_VERSION
: return "HP_GST_VERSION";
1038 case DT_HP_GST_HASHVAL
: return "HP_GST_HASHVAL";
1045 get_dynamic_type (type
)
1048 static char buff
[32];
1052 case DT_NULL
: return "NULL";
1053 case DT_NEEDED
: return "NEEDED";
1054 case DT_PLTRELSZ
: return "PLTRELSZ";
1055 case DT_PLTGOT
: return "PLTGOT";
1056 case DT_HASH
: return "HASH";
1057 case DT_STRTAB
: return "STRTAB";
1058 case DT_SYMTAB
: return "SYMTAB";
1059 case DT_RELA
: return "RELA";
1060 case DT_RELASZ
: return "RELASZ";
1061 case DT_RELAENT
: return "RELAENT";
1062 case DT_STRSZ
: return "STRSZ";
1063 case DT_SYMENT
: return "SYMENT";
1064 case DT_INIT
: return "INIT";
1065 case DT_FINI
: return "FINI";
1066 case DT_SONAME
: return "SONAME";
1067 case DT_RPATH
: return "RPATH";
1068 case DT_SYMBOLIC
: return "SYMBOLIC";
1069 case DT_REL
: return "REL";
1070 case DT_RELSZ
: return "RELSZ";
1071 case DT_RELENT
: return "RELENT";
1072 case DT_PLTREL
: return "PLTREL";
1073 case DT_DEBUG
: return "DEBUG";
1074 case DT_TEXTREL
: return "TEXTREL";
1075 case DT_JMPREL
: return "JMPREL";
1076 case DT_BIND_NOW
: return "BIND_NOW";
1077 case DT_INIT_ARRAY
: return "INIT_ARRAY";
1078 case DT_FINI_ARRAY
: return "FINI_ARRAY";
1079 case DT_INIT_ARRAYSZ
: return "INIT_ARRAYSZ";
1080 case DT_FINI_ARRAYSZ
: return "FINI_ARRAYSZ";
1081 case DT_RUNPATH
: return "RUNPATH";
1082 case DT_FLAGS
: return "FLAGS";
1084 case DT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
1085 case DT_PREINIT_ARRAYSZ
: return "PREINIT_ARRAYSZ";
1087 case DT_CHECKSUM
: return "CHECKSUM";
1088 case DT_PLTPADSZ
: return "PLTPADSZ";
1089 case DT_MOVEENT
: return "MOVEENT";
1090 case DT_MOVESZ
: return "MOVESZ";
1091 case DT_FEATURE
: return "FEATURE";
1092 case DT_POSFLAG_1
: return "POSFLAG_1";
1093 case DT_SYMINSZ
: return "SYMINSZ";
1094 case DT_SYMINENT
: return "SYMINENT"; /* aka VALRNGHI */
1096 case DT_ADDRRNGLO
: return "ADDRRNGLO";
1097 case DT_CONFIG
: return "CONFIG";
1098 case DT_DEPAUDIT
: return "DEPAUDIT";
1099 case DT_AUDIT
: return "AUDIT";
1100 case DT_PLTPAD
: return "PLTPAD";
1101 case DT_MOVETAB
: return "MOVETAB";
1102 case DT_SYMINFO
: return "SYMINFO"; /* aka ADDRRNGHI */
1104 case DT_VERSYM
: return "VERSYM";
1106 case DT_RELACOUNT
: return "RELACOUNT";
1107 case DT_RELCOUNT
: return "RELCOUNT";
1108 case DT_FLAGS_1
: return "FLAGS_1";
1109 case DT_VERDEF
: return "VERDEF";
1110 case DT_VERDEFNUM
: return "VERDEFNUM";
1111 case DT_VERNEED
: return "VERNEED";
1112 case DT_VERNEEDNUM
: return "VERNEEDNUM";
1114 case DT_AUXILIARY
: return "AUXILIARY";
1115 case DT_USED
: return "USED";
1116 case DT_FILTER
: return "FILTER";
1119 if ((type
>= DT_LOPROC
) && (type
<= DT_HIPROC
))
1121 const char * result
;
1123 switch (elf_header
.e_machine
)
1126 case EM_MIPS_RS4_BE
:
1127 result
= get_mips_dynamic_type (type
);
1130 result
= get_sparc64_dynamic_type (type
);
1140 sprintf (buff
, _("Processor Specific: %lx"), type
);
1142 else if ((type
>= DT_LOOS
) && (type
<= DT_HIOS
))
1144 const char * result
;
1146 switch (elf_header
.e_machine
)
1149 result
= get_parisc_dynamic_type (type
);
1159 sprintf (buff
, _("Operating System specific: %lx"), type
);
1162 sprintf (buff
, _("<unknown>: %lx"), type
);
1169 get_file_type (e_type
)
1172 static char buff
[32];
1176 case ET_NONE
: return _("NONE (None)");
1177 case ET_REL
: return _("REL (Relocatable file)");
1178 case ET_EXEC
: return _("EXEC (Executable file)");
1179 case ET_DYN
: return _("DYN (Shared object file)");
1180 case ET_CORE
: return _("CORE (Core file)");
1183 if ((e_type
>= ET_LOPROC
) && (e_type
<= ET_HIPROC
))
1184 sprintf (buff
, _("Processor Specific: (%x)"), e_type
);
1185 else if ((e_type
>= ET_LOOS
) && (e_type
<= ET_HIOS
))
1186 sprintf (buff
, _("OS Specific: (%x)"), e_type
);
1188 sprintf (buff
, _("<unknown>: %x"), e_type
);
1194 get_machine_name (e_machine
)
1197 static char buff
[64]; /* XXX */
1201 case EM_NONE
: return _("None");
1202 case EM_M32
: return "WE32100";
1203 case EM_SPARC
: return "Sparc";
1204 case EM_386
: return "Intel 80386";
1205 case EM_68K
: return "MC68000";
1206 case EM_88K
: return "MC88000";
1207 case EM_486
: return "Intel 80486";
1208 case EM_860
: return "Intel 80860";
1209 case EM_MIPS
: return "MIPS R3000";
1210 case EM_S370
: return "IBM System/370";
1211 case EM_MIPS_RS4_BE
: return "MIPS R4000 big-endian";
1212 case EM_OLD_SPARCV9
: return "Sparc v9 (old)";
1213 case EM_PARISC
: return "HPPA";
1214 case EM_PPC_OLD
: return "Power PC (old)";
1215 case EM_SPARC32PLUS
: return "Sparc v8+" ;
1216 case EM_960
: return "Intel 90860";
1217 case EM_PPC
: return "PowerPC";
1218 case EM_V800
: return "NEC V800";
1219 case EM_FR20
: return "Fujitsu FR20";
1220 case EM_RH32
: return "TRW RH32";
1221 case EM_MCORE
: return "MCORE";
1222 case EM_ARM
: return "ARM";
1223 case EM_OLD_ALPHA
: return "Digital Alpha (old)";
1224 case EM_SH
: return "Hitachi SH";
1225 case EM_SPARCV9
: return "Sparc v9";
1226 case EM_TRICORE
: return "Siemens Tricore";
1227 case EM_ARC
: return "Argonaut RISC Core";
1228 case EM_H8_300
: return "Hitachi H8/300";
1229 case EM_H8_300H
: return "Hitachi H8/300H";
1230 case EM_H8S
: return "Hitachi H8S";
1231 case EM_H8_500
: return "Hitachi H8/500";
1232 case EM_IA_64
: return "Intel IA-64";
1233 case EM_MIPS_X
: return "Stanford MIPS-X";
1234 case EM_COLDFIRE
: return "Motorola Coldfire";
1235 case EM_68HC12
: return "Motorola M68HC12";
1236 case EM_ALPHA
: return "Alpha";
1237 case EM_CYGNUS_D10V
: return "d10v";
1238 case EM_CYGNUS_D30V
: return "d30v";
1239 case EM_CYGNUS_ARC
: return "Arc";
1240 case EM_CYGNUS_M32R
: return "Mitsubishi M32r";
1241 case EM_CYGNUS_V850
: return "NEC v850";
1242 case EM_CYGNUS_MN10300
: return "mn10300";
1243 case EM_CYGNUS_MN10200
: return "mn10200";
1244 case EM_CYGNUS_FR30
: return "Fujitsu FR30";
1245 case EM_PJ
: return "picoJava";
1246 case EM_MMA
: return "Fujitsu Multimedia Accelerator";
1247 case EM_PCP
: return "Siemens PCP";
1248 case EM_NCPU
: return "Sony nCPU embedded RISC processor";
1249 case EM_NDR1
: return "Denso NDR1 microprocesspr";
1250 case EM_STARCORE
: return "Motorola Star*Core processor";
1251 case EM_ME16
: return "Toyota ME16 processor";
1252 case EM_ST100
: return "STMicroelectronics ST100 processor";
1253 case EM_TINYJ
: return "Advanced Logic Corp. TinyJ embedded processor";
1254 case EM_FX66
: return "Siemens FX66 microcontroller";
1255 case EM_ST9PLUS
: return "STMicroelectronics ST9+ 8/16 bit microcontroller";
1256 case EM_ST7
: return "STMicroelectronics ST7 8-bit microcontroller";
1257 case EM_68HC16
: return "Motorola MC68HC16 Microcontroller";
1258 case EM_68HC11
: return "Motorola MC68HC11 Microcontroller";
1259 case EM_68HC08
: return "Motorola MC68HC08 Microcontroller";
1260 case EM_68HC05
: return "Motorola MC68HC05 Microcontroller";
1261 case EM_SVX
: return "Silicon Graphics SVx";
1262 case EM_ST19
: return "STMicroelectronics ST19 8-bit microcontroller";
1263 case EM_VAX
: return "Digital VAX";
1264 case EM_AVR
: return "Atmel AVR 8-bit microcontroller";
1265 case EM_CRIS
: return "Axis Communications 32-bit embedded processor";
1266 case EM_JAVELIN
: return "Infineon Technologies 32-bit embedded cpu";
1267 case EM_FIREPATH
: return "Element 14 64-bit DSP processor";
1268 case EM_ZSP
: return "LSI Logic's 16-bit DSP processor";
1269 case EM_MMIX
: return "Donald Knuth's educational 64-bit processor";
1270 case EM_HUANY
: return "Harvard Universitys's machine-independent object format";
1271 case EM_PRISM
: return "SiTera Prism";
1274 sprintf (buff
, _("<unknown>: %x"), e_machine
);
1280 decode_ARM_machine_flags (e_flags
, buf
)
1287 eabi
= EF_ARM_EABI_VERSION (e_flags
);
1288 e_flags
&= ~ EF_ARM_EABIMASK
;
1290 /* Handle "generic" ARM flags. */
1291 if (e_flags
& EF_ARM_RELEXEC
)
1293 strcat (buf
, ", relocatable executable");
1294 e_flags
&= ~ EF_ARM_RELEXEC
;
1297 if (e_flags
& EF_ARM_HASENTRY
)
1299 strcat (buf
, ", has entry point");
1300 e_flags
&= ~ EF_ARM_HASENTRY
;
1303 /* Now handle EABI specific flags. */
1307 strcat (buf
, ", <unknown EABI>");
1312 case EF_ARM_EABI_VER1
:
1317 /* Process flags one bit at a time. */
1318 flag
= e_flags
& - e_flags
;
1323 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_INTERWORK. */
1324 strcat (buf
, ", sorted symbol tables");
1334 case EF_ARM_EABI_UNKNOWN
:
1339 /* Process flags one bit at a time. */
1340 flag
= e_flags
& - e_flags
;
1346 strcat (buf
, ", interworking enabled");
1350 strcat (buf
, ", uses APCS/26");
1354 strcat (buf
, ", uses APCS/float");
1358 strcat (buf
, ", position independent");
1362 strcat (buf
, ", 8 bit structure alignment");
1366 strcat (buf
, ", uses new ABI");
1370 strcat (buf
, ", uses old ABI");
1374 strcat (buf
, ", software FP");
1385 strcat (buf
,", <unknown>");
1389 get_machine_flags (e_flags
, e_machine
)
1393 static char buf
[1024];
1405 decode_ARM_machine_flags (e_flags
, buf
);
1409 if (e_flags
& EF_CPU32
)
1410 strcat (buf
, ", cpu32");
1414 if (e_flags
& EF_PPC_EMB
)
1415 strcat (buf
, ", emb");
1417 if (e_flags
& EF_PPC_RELOCATABLE
)
1418 strcat (buf
, ", relocatable");
1420 if (e_flags
& EF_PPC_RELOCATABLE_LIB
)
1421 strcat (buf
, ", relocatable-lib");
1424 case EM_CYGNUS_V850
:
1425 switch (e_flags
& EF_V850_ARCH
)
1428 strcat (buf
, ", v850e");
1431 strcat (buf
, ", v850ea");
1434 strcat (buf
, ", v850");
1437 strcat (buf
, ", unknown v850 architecture variant");
1442 case EM_CYGNUS_M32R
:
1443 if ((e_flags
& EF_M32R_ARCH
) == E_M32R_ARCH
)
1444 strcat (buf
, ", m32r");
1449 case EM_MIPS_RS4_BE
:
1450 if (e_flags
& EF_MIPS_NOREORDER
)
1451 strcat (buf
, ", noreorder");
1453 if (e_flags
& EF_MIPS_PIC
)
1454 strcat (buf
, ", pic");
1456 if (e_flags
& EF_MIPS_CPIC
)
1457 strcat (buf
, ", cpic");
1459 if (e_flags
& EF_MIPS_ABI2
)
1460 strcat (buf
, ", abi2");
1462 if ((e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_1
)
1463 strcat (buf
, ", mips1");
1465 if ((e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_2
)
1466 strcat (buf
, ", mips2");
1468 if ((e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_3
)
1469 strcat (buf
, ", mips3");
1471 if ((e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_4
)
1472 strcat (buf
, ", mips4");
1474 if ((e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_5
)
1475 strcat (buf
, ", mips5");
1477 if ((e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32
)
1478 strcat (buf
, ", mips32");
1480 if ((e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_64
)
1481 strcat (buf
, ", mips64");
1483 switch ((e_flags
& EF_MIPS_MACH
))
1485 case E_MIPS_MACH_3900
: strcat (buf
, ", 3900"); break;
1486 case E_MIPS_MACH_4010
: strcat (buf
, ", 4010"); break;
1487 case E_MIPS_MACH_4100
: strcat (buf
, ", 4100"); break;
1488 case E_MIPS_MACH_4650
: strcat (buf
, ", 4650"); break;
1489 case E_MIPS_MACH_4111
: strcat (buf
, ", 4111"); break;
1490 case E_MIPS_MACH_MIPS32_4K
: strcat (buf
, ", mips32-4k"); break;
1491 default: strcat (buf
, " UNKNOWN"); break;
1496 if (e_flags
& EF_SPARC_32PLUS
)
1497 strcat (buf
, ", v8+");
1499 if (e_flags
& EF_SPARC_SUN_US1
)
1500 strcat (buf
, ", ultrasparcI");
1502 if (e_flags
& EF_SPARC_SUN_US3
)
1503 strcat (buf
, ", ultrasparcIII");
1505 if (e_flags
& EF_SPARC_HAL_R1
)
1506 strcat (buf
, ", halr1");
1508 if (e_flags
& EF_SPARC_LEDATA
)
1509 strcat (buf
, ", ledata");
1511 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_TSO
)
1512 strcat (buf
, ", tso");
1514 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_PSO
)
1515 strcat (buf
, ", pso");
1517 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_RMO
)
1518 strcat (buf
, ", rmo");
1522 switch (e_flags
& EF_PARISC_ARCH
)
1524 case EFA_PARISC_1_0
:
1525 strcpy (buf
, ", PA-RISC 1.0");
1527 case EFA_PARISC_1_1
:
1528 strcpy (buf
, ", PA-RISC 1.1");
1530 case EFA_PARISC_2_0
:
1531 strcpy (buf
, ", PA-RISC 2.0");
1536 if (e_flags
& EF_PARISC_TRAPNIL
)
1537 strcat (buf
, ", trapnil");
1538 if (e_flags
& EF_PARISC_EXT
)
1539 strcat (buf
, ", ext");
1540 if (e_flags
& EF_PARISC_LSB
)
1541 strcat (buf
, ", lsb");
1542 if (e_flags
& EF_PARISC_WIDE
)
1543 strcat (buf
, ", wide");
1544 if (e_flags
& EF_PARISC_NO_KABP
)
1545 strcat (buf
, ", no kabp");
1546 if (e_flags
& EF_PARISC_LAZYSWAP
)
1547 strcat (buf
, ", lazyswap");
1551 if ((e_flags
& EF_PICOJAVA_NEWCALLS
) == EF_PICOJAVA_NEWCALLS
)
1552 strcat (buf
, ", new calling convention");
1554 if ((e_flags
& EF_PICOJAVA_GNUCALLS
) == EF_PICOJAVA_GNUCALLS
)
1555 strcat (buf
, ", gnu calling convention");
1564 get_mips_segment_type (type
)
1569 case PT_MIPS_REGINFO
:
1571 case PT_MIPS_RTPROC
:
1573 case PT_MIPS_OPTIONS
:
1583 get_parisc_segment_type (type
)
1588 case PT_HP_TLS
: return "HP_TLS";
1589 case PT_HP_CORE_NONE
: return "HP_CORE_NONE";
1590 case PT_HP_CORE_VERSION
: return "HP_CORE_VERSION";
1591 case PT_HP_CORE_KERNEL
: return "HP_CORE_KERNEL";
1592 case PT_HP_CORE_COMM
: return "HP_CORE_COMM";
1593 case PT_HP_CORE_PROC
: return "HP_CORE_PROC";
1594 case PT_HP_CORE_LOADABLE
: return "HP_CORE_LOADABLE";
1595 case PT_HP_CORE_STACK
: return "HP_CORE_STACK";
1596 case PT_HP_CORE_SHM
: return "HP_CORE_SHM";
1597 case PT_HP_CORE_MMF
: return "HP_CORE_MMF";
1598 case PT_HP_PARALLEL
: return "HP_PARALLEL";
1599 case PT_HP_FASTBIND
: return "HP_FASTBIND";
1600 case PT_PARISC_ARCHEXT
: return "PARISC_ARCHEXT";
1601 case PT_PARISC_UNWIND
: return "PARISC_UNWIND";
1610 get_segment_type (p_type
)
1611 unsigned long p_type
;
1613 static char buff
[32];
1617 case PT_NULL
: return "NULL";
1618 case PT_LOAD
: return "LOAD";
1619 case PT_DYNAMIC
: return "DYNAMIC";
1620 case PT_INTERP
: return "INTERP";
1621 case PT_NOTE
: return "NOTE";
1622 case PT_SHLIB
: return "SHLIB";
1623 case PT_PHDR
: return "PHDR";
1626 if ((p_type
>= PT_LOPROC
) && (p_type
<= PT_HIPROC
))
1628 const char * result
;
1630 switch (elf_header
.e_machine
)
1633 case EM_MIPS_RS4_BE
:
1634 result
= get_mips_segment_type (p_type
);
1637 result
= get_parisc_segment_type (p_type
);
1647 sprintf (buff
, "LOPROC+%lx", p_type
- PT_LOPROC
);
1649 else if ((p_type
>= PT_LOOS
) && (p_type
<= PT_HIOS
))
1651 const char * result
;
1653 switch (elf_header
.e_machine
)
1656 result
= get_parisc_segment_type (p_type
);
1666 sprintf (buff
, "LOOS+%lx", p_type
- PT_LOOS
);
1669 sprintf (buff
, _("<unknown>: %lx"), p_type
);
1676 get_mips_section_type_name (sh_type
)
1677 unsigned int sh_type
;
1681 case SHT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
1682 case SHT_MIPS_MSYM
: return "MIPS_MSYM";
1683 case SHT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
1684 case SHT_MIPS_GPTAB
: return "MIPS_GPTAB";
1685 case SHT_MIPS_UCODE
: return "MIPS_UCODE";
1686 case SHT_MIPS_DEBUG
: return "MIPS_DEBUG";
1687 case SHT_MIPS_REGINFO
: return "MIPS_REGINFO";
1688 case SHT_MIPS_PACKAGE
: return "MIPS_PACKAGE";
1689 case SHT_MIPS_PACKSYM
: return "MIPS_PACKSYM";
1690 case SHT_MIPS_RELD
: return "MIPS_RELD";
1691 case SHT_MIPS_IFACE
: return "MIPS_IFACE";
1692 case SHT_MIPS_CONTENT
: return "MIPS_CONTENT";
1693 case SHT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
1694 case SHT_MIPS_SHDR
: return "MIPS_SHDR";
1695 case SHT_MIPS_FDESC
: return "MIPS_FDESC";
1696 case SHT_MIPS_EXTSYM
: return "MIPS_EXTSYM";
1697 case SHT_MIPS_DENSE
: return "MIPS_DENSE";
1698 case SHT_MIPS_PDESC
: return "MIPS_PDESC";
1699 case SHT_MIPS_LOCSYM
: return "MIPS_LOCSYM";
1700 case SHT_MIPS_AUXSYM
: return "MIPS_AUXSYM";
1701 case SHT_MIPS_OPTSYM
: return "MIPS_OPTSYM";
1702 case SHT_MIPS_LOCSTR
: return "MIPS_LOCSTR";
1703 case SHT_MIPS_LINE
: return "MIPS_LINE";
1704 case SHT_MIPS_RFDESC
: return "MIPS_RFDESC";
1705 case SHT_MIPS_DELTASYM
: return "MIPS_DELTASYM";
1706 case SHT_MIPS_DELTAINST
: return "MIPS_DELTAINST";
1707 case SHT_MIPS_DELTACLASS
: return "MIPS_DELTACLASS";
1708 case SHT_MIPS_DWARF
: return "MIPS_DWARF";
1709 case SHT_MIPS_DELTADECL
: return "MIPS_DELTADECL";
1710 case SHT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
1711 case SHT_MIPS_EVENTS
: return "MIPS_EVENTS";
1712 case SHT_MIPS_TRANSLATE
: return "MIPS_TRANSLATE";
1713 case SHT_MIPS_PIXIE
: return "MIPS_PIXIE";
1714 case SHT_MIPS_XLATE
: return "MIPS_XLATE";
1715 case SHT_MIPS_XLATE_DEBUG
: return "MIPS_XLATE_DEBUG";
1716 case SHT_MIPS_WHIRL
: return "MIPS_WHIRL";
1717 case SHT_MIPS_EH_REGION
: return "MIPS_EH_REGION";
1718 case SHT_MIPS_XLATE_OLD
: return "MIPS_XLATE_OLD";
1719 case SHT_MIPS_PDR_EXCEPTION
: return "MIPS_PDR_EXCEPTION";
1727 get_parisc_section_type_name (sh_type
)
1728 unsigned int sh_type
;
1732 case SHT_PARISC_EXT
: return "PARISC_EXT";
1733 case SHT_PARISC_UNWIND
: return "PARISC_UNWIND";
1734 case SHT_PARISC_DOC
: return "PARISC_DOC";
1742 get_section_type_name (sh_type
)
1743 unsigned int sh_type
;
1745 static char buff
[32];
1749 case SHT_NULL
: return "NULL";
1750 case SHT_PROGBITS
: return "PROGBITS";
1751 case SHT_SYMTAB
: return "SYMTAB";
1752 case SHT_STRTAB
: return "STRTAB";
1753 case SHT_RELA
: return "RELA";
1754 case SHT_HASH
: return "HASH";
1755 case SHT_DYNAMIC
: return "DYNAMIC";
1756 case SHT_NOTE
: return "NOTE";
1757 case SHT_NOBITS
: return "NOBITS";
1758 case SHT_REL
: return "REL";
1759 case SHT_SHLIB
: return "SHLIB";
1760 case SHT_DYNSYM
: return "DYNSYM";
1761 case SHT_INIT_ARRAY
: return "INIT_ARRAY";
1762 case SHT_FINI_ARRAY
: return "FINI_ARRAY";
1763 case SHT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
1764 case SHT_GROUP
: return "GROUP";
1765 case SHT_SYMTAB_SHNDX
: return "SYMTAB SECTION INDICIES";
1766 case SHT_GNU_verdef
: return "VERDEF";
1767 case SHT_GNU_verneed
: return "VERNEED";
1768 case SHT_GNU_versym
: return "VERSYM";
1769 case 0x6ffffff0: return "VERSYM";
1770 case 0x6ffffffc: return "VERDEF";
1771 case 0x7ffffffd: return "AUXILIARY";
1772 case 0x7fffffff: return "FILTER";
1775 if ((sh_type
>= SHT_LOPROC
) && (sh_type
<= SHT_HIPROC
))
1777 const char * result
;
1779 switch (elf_header
.e_machine
)
1782 case EM_MIPS_RS4_BE
:
1783 result
= get_mips_section_type_name (sh_type
);
1786 result
= get_parisc_section_type_name (sh_type
);
1796 sprintf (buff
, "SHT_LOPROC+%x", sh_type
- SHT_LOPROC
);
1798 else if ((sh_type
>= SHT_LOOS
) && (sh_type
<= SHT_HIOS
))
1799 sprintf (buff
, "SHT_LOOS+%x", sh_type
- SHT_LOOS
);
1800 else if ((sh_type
>= SHT_LOUSER
) && (sh_type
<= SHT_HIUSER
))
1801 sprintf (buff
, "SHT_LOUSER+%x", sh_type
- SHT_LOUSER
);
1803 sprintf (buff
, _("<unknown>: %x"), sh_type
);
1809 struct option options
[] =
1811 {"all", no_argument
, 0, 'a'},
1812 {"file-header", no_argument
, 0, 'h'},
1813 {"program-headers", no_argument
, 0, 'l'},
1814 {"headers", no_argument
, 0, 'e'},
1815 {"histogram", no_argument
, 0, 'I'},
1816 {"segments", no_argument
, 0, 'l'},
1817 {"sections", no_argument
, 0, 'S'},
1818 {"section-headers", no_argument
, 0, 'S'},
1819 {"symbols", no_argument
, 0, 's'},
1820 {"syms", no_argument
, 0, 's'},
1821 {"relocs", no_argument
, 0, 'r'},
1822 {"notes", no_argument
, 0, 'n'},
1823 {"dynamic", no_argument
, 0, 'd'},
1824 {"arch-specific", no_argument
, 0, 'A'},
1825 {"version-info", no_argument
, 0, 'V'},
1826 {"use-dynamic", no_argument
, 0, 'D'},
1827 {"hex-dump", required_argument
, 0, 'x'},
1828 {"debug-dump", optional_argument
, 0, 'w'},
1829 #ifdef SUPPORT_DISASSEMBLY
1830 {"instruction-dump", required_argument
, 0, 'i'},
1833 {"version", no_argument
, 0, 'v'},
1834 {"help", no_argument
, 0, 'H'},
1835 {0, no_argument
, 0, 0}
1841 fprintf (stdout
, _("Usage: readelf {options} elf-file(s)\n"));
1842 fprintf (stdout
, _(" Options are:\n"));
1843 fprintf (stdout
, _(" -a or --all Equivalent to: -h -l -S -s -r -d -V -A -I\n"));
1844 fprintf (stdout
, _(" -h or --file-header Display the ELF file header\n"));
1845 fprintf (stdout
, _(" -l or --program-headers or --segments\n"));
1846 fprintf (stdout
, _(" Display the program headers\n"));
1847 fprintf (stdout
, _(" -S or --section-headers or --sections\n"));
1848 fprintf (stdout
, _(" Display the sections' header\n"));
1849 fprintf (stdout
, _(" -e or --headers Equivalent to: -h -l -S\n"));
1850 fprintf (stdout
, _(" -s or --syms or --symbols Display the symbol table\n"));
1851 fprintf (stdout
, _(" -n or --notes Display the core notes (if present)\n"));
1852 fprintf (stdout
, _(" -r or --relocs Display the relocations (if present)\n"));
1853 fprintf (stdout
, _(" -d or --dynamic Display the dynamic segment (if present)\n"));
1854 fprintf (stdout
, _(" -V or --version-info Display the version sections (if present)\n"));
1855 fprintf (stdout
, _(" -A or --arch-specific Display architecture specific information (if any).\n"));
1856 fprintf (stdout
, _(" -D or --use-dynamic Use the dynamic section info when displaying symbols\n"));
1857 fprintf (stdout
, _(" -x <number> or --hex-dump=<number>\n"));
1858 fprintf (stdout
, _(" Dump the contents of section <number>\n"));
1859 fprintf (stdout
, _(" -w[liaprf] or --debug-dump[=line,=info,=abbrev,=pubnames,=ranges,=frames]\n"));
1860 fprintf (stdout
, _(" Display the contents of DWARF2 debug sections\n"));
1861 #ifdef SUPPORT_DISASSEMBLY
1862 fprintf (stdout
, _(" -i <number> or --instruction-dump=<number>\n"));
1863 fprintf (stdout
, _(" Disassemble the contents of section <number>\n"));
1865 fprintf (stdout
, _(" -I or --histogram Display histogram of bucket list lengths\n"));
1866 fprintf (stdout
, _(" -v or --version Display the version number of readelf\n"));
1867 fprintf (stdout
, _(" -H or --help Display this information\n"));
1868 fprintf (stdout
, _("Report bugs to %s\n"), REPORT_BUGS_TO
);
1874 request_dump (section
, type
)
1875 unsigned int section
;
1878 if (section
>= num_dump_sects
)
1880 char * new_dump_sects
;
1882 new_dump_sects
= (char *) calloc (section
+ 1, 1);
1884 if (new_dump_sects
== NULL
)
1885 error (_("Out of memory allocating dump request table."));
1888 /* Copy current flag settings. */
1889 memcpy (new_dump_sects
, dump_sects
, num_dump_sects
);
1893 dump_sects
= new_dump_sects
;
1894 num_dump_sects
= section
+ 1;
1899 dump_sects
[section
] |= type
;
1905 parse_args (argc
, argv
)
1914 while ((c
= getopt_long
1915 (argc
, argv
, "ersahnldSDAIw::x:i:vV", options
, NULL
)) != EOF
)
1950 do_using_dynamic
++;
1978 section
= strtoul (optarg
, & cp
, 0);
1979 if (! * cp
&& section
>= 0)
1981 request_dump (section
, HEX_DUMP
);
2001 do_debug_abbrevs
= 1;
2011 do_debug_pubnames
= 1;
2016 do_debug_aranges
= 1;
2021 do_debug_frames
= 1;
2025 warn (_("Unrecognised debug option '%s'\n"), optarg
);
2030 #ifdef SUPPORT_DISASSEMBLY
2033 section
= strtoul (optarg
, & cp
, 0);
2034 if (! * cp
&& section
>= 0)
2036 request_dump (section
, DISASS_DUMP
);
2042 print_version (program_name
);
2049 /* xgettext:c-format */
2050 error (_("Invalid option '-%c'\n"), c
);
2057 if (!do_dynamic
&& !do_syms
&& !do_reloc
&& !do_sections
2058 && !do_segments
&& !do_header
&& !do_dump
&& !do_version
2059 && !do_histogram
&& !do_debugging
&& !do_arch
&& !do_notes
)
2063 warn (_("Nothing to do.\n"));
2069 get_elf_class (elf_class
)
2070 unsigned char elf_class
;
2072 static char buff
[32];
2076 case ELFCLASSNONE
: return _("none");
2077 case ELFCLASS32
: return _("ELF32");
2078 case ELFCLASS64
: return _("ELF64");
2080 sprintf (buff
, _("<unknown: %x>"), elf_class
);
2086 get_data_encoding (encoding
)
2087 unsigned char encoding
;
2089 static char buff
[32];
2093 case ELFDATANONE
: return _("none");
2094 case ELFDATA2LSB
: return _("2's complement, little endian");
2095 case ELFDATA2MSB
: return _("2's complement, big endian");
2097 sprintf (buff
, _("<unknown: %x>"), encoding
);
2103 get_osabi_name (osabi
)
2104 unsigned char osabi
;
2106 static char buff
[32];
2110 case ELFOSABI_NONE
: return _("UNIX - System V");
2111 case ELFOSABI_HPUX
: return _("UNIX - HP-UX");
2112 case ELFOSABI_NETBSD
: return _("UNIX - NetBSD");
2113 case ELFOSABI_LINUX
: return _("UNIX - Linux");
2114 case ELFOSABI_HURD
: return _("GNU/Hurd");
2115 case ELFOSABI_SOLARIS
: return _("UNIX - Solaris");
2116 case ELFOSABI_AIX
: return _("UNIX - AIX");
2117 case ELFOSABI_IRIX
: return _("UNIX - IRIX");
2118 case ELFOSABI_FREEBSD
: return _("UNIX - FreeBSD");
2119 case ELFOSABI_TRU64
: return _("UNIX - TRU64");
2120 case ELFOSABI_MODESTO
: return _("Novell - Modesto");
2121 case ELFOSABI_OPENBSD
: return _("UNIX - OpenBSD");
2122 case ELFOSABI_STANDALONE
: return _("Standalone App");
2123 case ELFOSABI_ARM
: return _("ARM");
2125 sprintf (buff
, _("<unknown: %x>"), osabi
);
2130 /* Decode the data held in 'elf_header'. */
2132 process_file_header ()
2134 if ( elf_header
.e_ident
[EI_MAG0
] != ELFMAG0
2135 || elf_header
.e_ident
[EI_MAG1
] != ELFMAG1
2136 || elf_header
.e_ident
[EI_MAG2
] != ELFMAG2
2137 || elf_header
.e_ident
[EI_MAG3
] != ELFMAG3
)
2140 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
2148 printf (_("ELF Header:\n"));
2149 printf (_(" Magic: "));
2150 for (i
= 0; i
< EI_NIDENT
; i
++)
2151 printf ("%2.2x ", elf_header
.e_ident
[i
]);
2153 printf (_(" Class: %s\n"),
2154 get_elf_class (elf_header
.e_ident
[EI_CLASS
]));
2155 printf (_(" Data: %s\n"),
2156 get_data_encoding (elf_header
.e_ident
[EI_DATA
]));
2157 printf (_(" Version: %d %s\n"),
2158 elf_header
.e_ident
[EI_VERSION
],
2159 (elf_header
.e_ident
[EI_VERSION
] == EV_CURRENT
2161 : (elf_header
.e_ident
[EI_VERSION
] != EV_NONE
2164 printf (_(" OS/ABI: %s\n"),
2165 get_osabi_name (elf_header
.e_ident
[EI_OSABI
]));
2166 printf (_(" ABI Version: %d\n"),
2167 elf_header
.e_ident
[EI_ABIVERSION
]);
2168 printf (_(" Type: %s\n"),
2169 get_file_type (elf_header
.e_type
));
2170 printf (_(" Machine: %s\n"),
2171 get_machine_name (elf_header
.e_machine
));
2172 printf (_(" Version: 0x%lx\n"),
2173 (unsigned long) elf_header
.e_version
);
2175 printf (_(" Entry point address: "));
2176 print_vma ((bfd_vma
) elf_header
.e_entry
, PREFIX_HEX
);
2177 printf (_("\n Start of program headers: "));
2178 print_vma ((bfd_vma
) elf_header
.e_phoff
, DEC
);
2179 printf (_(" (bytes into file)\n Start of section headers: "));
2180 print_vma ((bfd_vma
) elf_header
.e_shoff
, DEC
);
2181 printf (_(" (bytes into file)\n"));
2183 printf (_(" Flags: 0x%lx%s\n"),
2184 (unsigned long) elf_header
.e_flags
,
2185 get_machine_flags (elf_header
.e_flags
, elf_header
.e_machine
));
2186 printf (_(" Size of this header: %ld (bytes)\n"),
2187 (long) elf_header
.e_ehsize
);
2188 printf (_(" Size of program headers: %ld (bytes)\n"),
2189 (long) elf_header
.e_phentsize
);
2190 printf (_(" Number of program headers: %ld\n"),
2191 (long) elf_header
.e_phnum
);
2192 printf (_(" Size of section headers: %ld (bytes)\n"),
2193 (long) elf_header
.e_shentsize
);
2194 printf (_(" Number of section headers: %ld\n"),
2195 (long) elf_header
.e_shnum
);
2196 printf (_(" Section header string table index: %ld\n"),
2197 (long) elf_header
.e_shstrndx
);
2205 get_32bit_program_headers (file
, program_headers
)
2207 Elf_Internal_Phdr
* program_headers
;
2209 Elf32_External_Phdr
* phdrs
;
2210 Elf32_External_Phdr
* external
;
2211 Elf32_Internal_Phdr
* internal
;
2214 GET_DATA_ALLOC (elf_header
.e_phoff
,
2215 elf_header
.e_phentsize
* elf_header
.e_phnum
,
2216 phdrs
, Elf32_External_Phdr
*, "program headers");
2218 for (i
= 0, internal
= program_headers
, external
= phdrs
;
2219 i
< elf_header
.e_phnum
;
2220 i
++, internal
++, external
++)
2222 internal
->p_type
= BYTE_GET (external
->p_type
);
2223 internal
->p_offset
= BYTE_GET (external
->p_offset
);
2224 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
2225 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
2226 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
2227 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
2228 internal
->p_flags
= BYTE_GET (external
->p_flags
);
2229 internal
->p_align
= BYTE_GET (external
->p_align
);
2238 get_64bit_program_headers (file
, program_headers
)
2240 Elf_Internal_Phdr
* program_headers
;
2242 Elf64_External_Phdr
* phdrs
;
2243 Elf64_External_Phdr
* external
;
2244 Elf64_Internal_Phdr
* internal
;
2247 GET_DATA_ALLOC (elf_header
.e_phoff
,
2248 elf_header
.e_phentsize
* elf_header
.e_phnum
,
2249 phdrs
, Elf64_External_Phdr
*, "program headers");
2251 for (i
= 0, internal
= program_headers
, external
= phdrs
;
2252 i
< elf_header
.e_phnum
;
2253 i
++, internal
++, external
++)
2255 internal
->p_type
= BYTE_GET (external
->p_type
);
2256 internal
->p_flags
= BYTE_GET (external
->p_flags
);
2257 internal
->p_offset
= BYTE_GET8 (external
->p_offset
);
2258 internal
->p_vaddr
= BYTE_GET8 (external
->p_vaddr
);
2259 internal
->p_paddr
= BYTE_GET8 (external
->p_paddr
);
2260 internal
->p_filesz
= BYTE_GET8 (external
->p_filesz
);
2261 internal
->p_memsz
= BYTE_GET8 (external
->p_memsz
);
2262 internal
->p_align
= BYTE_GET8 (external
->p_align
);
2271 process_program_headers (file
)
2274 Elf_Internal_Phdr
* program_headers
;
2275 Elf_Internal_Phdr
* segment
;
2278 if (elf_header
.e_phnum
== 0)
2281 printf (_("\nThere are no program headers in this file.\n"));
2285 if (do_segments
&& !do_header
)
2287 printf (_("\nElf file type is %s\n"), get_file_type (elf_header
.e_type
));
2288 printf (_("Entry point "));
2289 print_vma ((bfd_vma
) elf_header
.e_entry
, PREFIX_HEX
);
2290 printf (_("\nThere are %d program headers, starting at offset "),
2291 elf_header
.e_phnum
);
2292 print_vma ((bfd_vma
) elf_header
.e_phoff
, DEC
);
2296 program_headers
= (Elf_Internal_Phdr
*) malloc
2297 (elf_header
.e_phnum
* sizeof (Elf_Internal_Phdr
));
2299 if (program_headers
== NULL
)
2301 error (_("Out of memory\n"));
2306 i
= get_32bit_program_headers (file
, program_headers
);
2308 i
= get_64bit_program_headers (file
, program_headers
);
2312 free (program_headers
);
2319 (_("\nProgram Header%s:\n"), elf_header
.e_phnum
> 1 ? "s" : "");
2323 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
2327 (_(" Type Offset VirtAddr PhysAddr\n"));
2329 (_(" FileSiz MemSiz Flags Align\n"));
2337 for (i
= 0, segment
= program_headers
;
2338 i
< elf_header
.e_phnum
;
2343 printf (" %-14.14s ", get_segment_type (segment
->p_type
));
2347 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
2348 printf ("0x%8.8lx ", (unsigned long) segment
->p_vaddr
);
2349 printf ("0x%8.8lx ", (unsigned long) segment
->p_paddr
);
2350 printf ("0x%5.5lx ", (unsigned long) segment
->p_filesz
);
2351 printf ("0x%5.5lx ", (unsigned long) segment
->p_memsz
);
2353 (segment
->p_flags
& PF_R
? 'R' : ' '),
2354 (segment
->p_flags
& PF_W
? 'W' : ' '),
2355 (segment
->p_flags
& PF_X
? 'E' : ' '));
2356 printf ("%#lx", (unsigned long) segment
->p_align
);
2360 print_vma (segment
->p_offset
, FULL_HEX
);
2362 print_vma (segment
->p_vaddr
, FULL_HEX
);
2364 print_vma (segment
->p_paddr
, FULL_HEX
);
2366 print_vma (segment
->p_filesz
, FULL_HEX
);
2368 print_vma (segment
->p_memsz
, FULL_HEX
);
2370 (segment
->p_flags
& PF_R
? 'R' : ' '),
2371 (segment
->p_flags
& PF_W
? 'W' : ' '),
2372 (segment
->p_flags
& PF_X
? 'E' : ' '));
2373 print_vma (segment
->p_align
, HEX
);
2377 switch (segment
->p_type
)
2381 loadaddr
= (segment
->p_vaddr
& 0xfffff000)
2382 - (segment
->p_offset
& 0xfffff000);
2387 error (_("more than one dynamic segment\n"));
2389 dynamic_addr
= segment
->p_offset
;
2390 dynamic_size
= segment
->p_filesz
;
2394 if (fseek (file
, (long) segment
->p_offset
, SEEK_SET
))
2395 error (_("Unable to find program interpreter name\n"));
2398 program_interpreter
[0] = 0;
2399 fscanf (file
, "%63s", program_interpreter
);
2402 printf (_("\n [Requesting program interpreter: %s]"),
2403 program_interpreter
);
2409 putc ('\n', stdout
);
2418 if (do_segments
&& section_headers
!= NULL
)
2420 printf (_("\n Section to Segment mapping:\n"));
2421 printf (_(" Segment Sections...\n"));
2423 assert (string_table
!= NULL
);
2425 for (i
= 0; i
< elf_header
.e_phnum
; i
++)
2428 Elf_Internal_Shdr
* section
;
2430 segment
= program_headers
+ i
;
2431 section
= section_headers
;
2433 printf (" %2.2d ", i
);
2435 for (j
= 0; j
< elf_header
.e_shnum
; j
++, section
++)
2437 if (section
->sh_size
> 0
2438 /* Compare allocated sections by VMA, unallocated
2439 sections by file offset. */
2440 && (section
->sh_flags
& SHF_ALLOC
2441 ? (section
->sh_addr
>= segment
->p_vaddr
2442 && section
->sh_addr
+ section
->sh_size
2443 <= segment
->p_vaddr
+ segment
->p_memsz
)
2444 : ((bfd_vma
) section
->sh_offset
>= segment
->p_offset
2445 && (section
->sh_offset
+ section
->sh_size
2446 <= segment
->p_offset
+ segment
->p_filesz
))))
2447 printf ("%s ", SECTION_NAME (section
));
2454 free (program_headers
);
2461 get_32bit_section_headers (file
)
2464 Elf32_External_Shdr
* shdrs
;
2465 Elf32_Internal_Shdr
* internal
;
2468 GET_DATA_ALLOC (elf_header
.e_shoff
,
2469 elf_header
.e_shentsize
* elf_header
.e_shnum
,
2470 shdrs
, Elf32_External_Shdr
*, "section headers");
2472 section_headers
= (Elf_Internal_Shdr
*) malloc
2473 (elf_header
.e_shnum
* sizeof (Elf_Internal_Shdr
));
2475 if (section_headers
== NULL
)
2477 error (_("Out of memory\n"));
2481 for (i
= 0, internal
= section_headers
;
2482 i
< elf_header
.e_shnum
;
2485 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
2486 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
2487 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
2488 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
2489 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
2490 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
2491 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
2492 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
2493 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
2494 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
2503 get_64bit_section_headers (file
)
2506 Elf64_External_Shdr
* shdrs
;
2507 Elf64_Internal_Shdr
* internal
;
2510 GET_DATA_ALLOC (elf_header
.e_shoff
,
2511 elf_header
.e_shentsize
* elf_header
.e_shnum
,
2512 shdrs
, Elf64_External_Shdr
*, "section headers");
2514 section_headers
= (Elf_Internal_Shdr
*) malloc
2515 (elf_header
.e_shnum
* sizeof (Elf_Internal_Shdr
));
2517 if (section_headers
== NULL
)
2519 error (_("Out of memory\n"));
2523 for (i
= 0, internal
= section_headers
;
2524 i
< elf_header
.e_shnum
;
2527 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
2528 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
2529 internal
->sh_flags
= BYTE_GET8 (shdrs
[i
].sh_flags
);
2530 internal
->sh_addr
= BYTE_GET8 (shdrs
[i
].sh_addr
);
2531 internal
->sh_size
= BYTE_GET8 (shdrs
[i
].sh_size
);
2532 internal
->sh_entsize
= BYTE_GET8 (shdrs
[i
].sh_entsize
);
2533 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
2534 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
2535 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
2536 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
2544 static Elf_Internal_Sym
*
2545 get_32bit_elf_symbols (file
, offset
, number
)
2547 unsigned long offset
;
2548 unsigned long number
;
2550 Elf32_External_Sym
* esyms
;
2551 Elf_Internal_Sym
* isyms
;
2552 Elf_Internal_Sym
* psym
;
2555 GET_DATA_ALLOC (offset
, number
* sizeof (Elf32_External_Sym
),
2556 esyms
, Elf32_External_Sym
*, "symbols");
2558 isyms
= (Elf_Internal_Sym
*) malloc (number
* sizeof (Elf_Internal_Sym
));
2562 error (_("Out of memory\n"));
2568 for (j
= 0, psym
= isyms
;
2572 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
2573 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
2574 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
2575 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
2576 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
2577 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
2585 static Elf_Internal_Sym
*
2586 get_64bit_elf_symbols (file
, offset
, number
)
2588 unsigned long offset
;
2589 unsigned long number
;
2591 Elf64_External_Sym
* esyms
;
2592 Elf_Internal_Sym
* isyms
;
2593 Elf_Internal_Sym
* psym
;
2596 GET_DATA_ALLOC (offset
, number
* sizeof (Elf64_External_Sym
),
2597 esyms
, Elf64_External_Sym
*, "symbols");
2599 isyms
= (Elf_Internal_Sym
*) malloc (number
* sizeof (Elf_Internal_Sym
));
2603 error (_("Out of memory\n"));
2609 for (j
= 0, psym
= isyms
;
2613 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
2614 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
2615 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
2616 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
2617 psym
->st_value
= BYTE_GET8 (esyms
[j
].st_value
);
2618 psym
->st_size
= BYTE_GET8 (esyms
[j
].st_size
);
2627 get_elf_section_flags (sh_flags
)
2630 static char buff
[32];
2638 flag
= sh_flags
& - sh_flags
;
2643 case SHF_WRITE
: strcat (buff
, "W"); break;
2644 case SHF_ALLOC
: strcat (buff
, "A"); break;
2645 case SHF_EXECINSTR
: strcat (buff
, "X"); break;
2646 case SHF_MERGE
: strcat (buff
, "M"); break;
2647 case SHF_STRINGS
: strcat (buff
, "S"); break;
2648 case SHF_INFO_LINK
: strcat (buff
, "I"); break;
2649 case SHF_LINK_ORDER
: strcat (buff
, "L"); break;
2650 case SHF_OS_NONCONFORMING
: strcat (buff
, "O"); break;
2651 case SHF_GROUP
: strcat (buff
, "G"); break;
2654 if (flag
& SHF_MASKOS
)
2657 sh_flags
&= ~ SHF_MASKOS
;
2659 else if (flag
& SHF_MASKPROC
)
2662 sh_flags
&= ~ SHF_MASKPROC
;
2674 process_section_headers (file
)
2677 Elf_Internal_Shdr
* section
;
2680 section_headers
= NULL
;
2682 if (elf_header
.e_shnum
== 0)
2685 printf (_("\nThere are no sections in this file.\n"));
2690 if (do_sections
&& !do_header
)
2691 printf (_("There are %d section headers, starting at offset 0x%lx:\n"),
2692 elf_header
.e_shnum
, (unsigned long) elf_header
.e_shoff
);
2696 if (! get_32bit_section_headers (file
))
2699 else if (! get_64bit_section_headers (file
))
2702 /* Read in the string table, so that we have names to display. */
2703 section
= section_headers
+ elf_header
.e_shstrndx
;
2705 if (section
->sh_size
!= 0)
2707 unsigned long string_table_offset
;
2709 string_table_offset
= section
->sh_offset
;
2711 GET_DATA_ALLOC (section
->sh_offset
, section
->sh_size
,
2712 string_table
, char *, "string table");
2715 /* Scan the sections for the dynamic symbol table
2716 and dynamic string table and debug sections. */
2717 dynamic_symbols
= NULL
;
2718 dynamic_strings
= NULL
;
2719 dynamic_syminfo
= NULL
;
2721 for (i
= 0, section
= section_headers
;
2722 i
< elf_header
.e_shnum
;
2725 char * name
= SECTION_NAME (section
);
2727 if (section
->sh_type
== SHT_DYNSYM
)
2729 if (dynamic_symbols
!= NULL
)
2731 error (_("File contains multiple dynamic symbol tables\n"));
2735 num_dynamic_syms
= section
->sh_size
/ section
->sh_entsize
;
2737 GET_ELF_SYMBOLS (file
, section
->sh_offset
, num_dynamic_syms
);
2739 else if (section
->sh_type
== SHT_STRTAB
2740 && strcmp (name
, ".dynstr") == 0)
2742 if (dynamic_strings
!= NULL
)
2744 error (_("File contains multiple dynamic string tables\n"));
2748 GET_DATA_ALLOC (section
->sh_offset
, section
->sh_size
,
2749 dynamic_strings
, char *, "dynamic strings");
2751 else if ((do_debugging
|| do_debug_info
|| do_debug_abbrevs
2752 || do_debug_lines
|| do_debug_pubnames
|| do_debug_aranges
|| do_debug_frames
)
2753 && strncmp (name
, ".debug_", 7) == 0)
2758 || (do_debug_info
&& (strcmp (name
, "info") == 0))
2759 || (do_debug_abbrevs
&& (strcmp (name
, "abbrev") == 0))
2760 || (do_debug_lines
&& (strcmp (name
, "line") == 0))
2761 || (do_debug_pubnames
&& (strcmp (name
, "pubnames") == 0))
2762 || (do_debug_aranges
&& (strcmp (name
, "aranges") == 0))
2763 || (do_debug_frames
&& (strcmp (name
, "frame") == 0))
2765 request_dump (i
, DEBUG_DUMP
);
2767 else if (do_debug_frames
&& strcmp (name
, ".eh_frame") == 0)
2768 request_dump (i
, DEBUG_DUMP
);
2774 printf (_("\nSection Header%s:\n"), elf_header
.e_shnum
> 1 ? "s" : "");
2778 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
2781 printf (_(" [Nr] Name Type Address Offset\n"));
2782 printf (_(" Size EntSize Flags Link Info Align\n"));
2785 for (i
= 0, section
= section_headers
;
2786 i
< elf_header
.e_shnum
;
2789 printf (" [%2d] %-17.17s %-15.15s ",
2791 SECTION_NAME (section
),
2792 get_section_type_name (section
->sh_type
));
2796 print_vma (section
->sh_addr
, LONG_HEX
);
2798 printf ( " %6.6lx %6.6lx %2.2lx",
2799 (unsigned long) section
->sh_offset
,
2800 (unsigned long) section
->sh_size
,
2801 (unsigned long) section
->sh_entsize
);
2803 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
2805 printf ("%2ld %3lx %2ld\n",
2806 (unsigned long) section
->sh_link
,
2807 (unsigned long) section
->sh_info
,
2808 (unsigned long) section
->sh_addralign
);
2813 print_vma (section
->sh_addr
, LONG_HEX
);
2814 printf (" %8.8lx", section
->sh_offset
);
2816 print_vma (section
->sh_size
, LONG_HEX
);
2818 print_vma (section
->sh_entsize
, LONG_HEX
);
2820 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
2822 printf (" %2ld %3lx %ld\n",
2823 (unsigned long) section
->sh_link
,
2824 (unsigned long) section
->sh_info
,
2825 (unsigned long) section
->sh_addralign
);
2829 printf (_("Key to Flags:\n"));
2830 printf (_(" W (write), A (alloc), X (execute), M (merge), S (strings)\n"));
2831 printf (_(" I (info), L (link order), G (group), x (unknown)\n"));
2832 printf (_(" O (extra OS processing required) o (OS specific), p (processor specific)\n"));
2837 /* Process the reloc section. */
2839 process_relocs (file
)
2842 unsigned long rel_size
;
2843 unsigned long rel_offset
;
2849 if (do_using_dynamic
)
2851 int is_rela
= FALSE
;
2856 if (dynamic_info
[DT_REL
])
2858 rel_offset
= dynamic_info
[DT_REL
];
2859 rel_size
= dynamic_info
[DT_RELSZ
];
2862 else if (dynamic_info
[DT_RELA
])
2864 rel_offset
= dynamic_info
[DT_RELA
];
2865 rel_size
= dynamic_info
[DT_RELASZ
];
2868 else if (dynamic_info
[DT_JMPREL
])
2870 rel_offset
= dynamic_info
[DT_JMPREL
];
2871 rel_size
= dynamic_info
[DT_PLTRELSZ
];
2873 switch (dynamic_info
[DT_PLTREL
])
2890 (_("\nRelocation section at offset 0x%lx contains %ld bytes:\n"),
2891 rel_offset
, rel_size
);
2893 dump_relocations (file
, rel_offset
- loadaddr
, rel_size
,
2894 dynamic_symbols
, num_dynamic_syms
, dynamic_strings
, is_rela
);
2897 printf (_("\nThere are no dynamic relocations in this file.\n"));
2901 Elf32_Internal_Shdr
* section
;
2905 for (i
= 0, section
= section_headers
;
2906 i
< elf_header
.e_shnum
;
2909 if ( section
->sh_type
!= SHT_RELA
2910 && section
->sh_type
!= SHT_REL
)
2913 rel_offset
= section
->sh_offset
;
2914 rel_size
= section
->sh_size
;
2918 Elf32_Internal_Shdr
* strsec
;
2919 Elf32_Internal_Shdr
* symsec
;
2920 Elf_Internal_Sym
* symtab
;
2923 unsigned long nsyms
;
2925 printf (_("\nRelocation section "));
2927 if (string_table
== NULL
)
2928 printf ("%d", section
->sh_name
);
2930 printf ("'%s'", SECTION_NAME (section
));
2932 printf (_(" at offset 0x%lx contains %lu entries:\n"),
2933 rel_offset
, (unsigned long) (rel_size
/ section
->sh_entsize
));
2935 symsec
= section_headers
+ section
->sh_link
;
2937 nsyms
= symsec
->sh_size
/ symsec
->sh_entsize
;
2938 symtab
= GET_ELF_SYMBOLS (file
, symsec
->sh_offset
, nsyms
);
2943 strsec
= section_headers
+ symsec
->sh_link
;
2945 GET_DATA_ALLOC (strsec
->sh_offset
, strsec
->sh_size
, strtab
,
2946 char *, "string table");
2948 is_rela
= section
->sh_type
== SHT_RELA
;
2950 dump_relocations (file
, rel_offset
, rel_size
, symtab
, nsyms
, strtab
, is_rela
);
2960 printf (_("\nThere are no relocations in this file.\n"));
2968 dynamic_segment_mips_val (entry
)
2969 Elf_Internal_Dyn
* entry
;
2971 switch (entry
->d_tag
)
2974 if (entry
->d_un
.d_val
== 0)
2978 static const char * opts
[] =
2980 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
2981 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
2982 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
2983 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
2988 for (cnt
= 0; cnt
< NUM_ELEM (opts
); ++ cnt
)
2989 if (entry
->d_un
.d_val
& (1 << cnt
))
2991 printf ("%s%s", first
? "" : " ", opts
[cnt
]);
2998 case DT_MIPS_IVERSION
:
2999 if (dynamic_strings
!= NULL
)
3000 printf ("Interface Version: %s\n",
3001 dynamic_strings
+ entry
->d_un
.d_val
);
3003 printf ("%ld\n", (long) entry
->d_un
.d_ptr
);
3006 case DT_MIPS_TIME_STAMP
:
3011 time_t time
= entry
->d_un
.d_val
;
3012 tmp
= gmtime (&time
);
3013 sprintf (timebuf
, "%04u-%02u-%02uT%02u:%02u:%02u",
3014 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
3015 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
3016 printf ("Time Stamp: %s\n", timebuf
);
3020 case DT_MIPS_RLD_VERSION
:
3021 case DT_MIPS_LOCAL_GOTNO
:
3022 case DT_MIPS_CONFLICTNO
:
3023 case DT_MIPS_LIBLISTNO
:
3024 case DT_MIPS_SYMTABNO
:
3025 case DT_MIPS_UNREFEXTNO
:
3026 case DT_MIPS_HIPAGENO
:
3027 case DT_MIPS_DELTA_CLASS_NO
:
3028 case DT_MIPS_DELTA_INSTANCE_NO
:
3029 case DT_MIPS_DELTA_RELOC_NO
:
3030 case DT_MIPS_DELTA_SYM_NO
:
3031 case DT_MIPS_DELTA_CLASSSYM_NO
:
3032 case DT_MIPS_COMPACT_SIZE
:
3033 printf ("%ld\n", (long) entry
->d_un
.d_ptr
);
3037 printf ("%#lx\n", (long) entry
->d_un
.d_ptr
);
3043 dynamic_segment_parisc_val (entry
)
3044 Elf_Internal_Dyn
* entry
;
3046 switch (entry
->d_tag
)
3048 case DT_HP_DLD_FLAGS
:
3057 { DT_HP_DEBUG_PRIVATE
, "HP_DEBUG_PRIVATE" },
3058 { DT_HP_DEBUG_CALLBACK
, "HP_DEBUG_CALLBACK" },
3059 { DT_HP_DEBUG_CALLBACK_BOR
, "HP_DEBUG_CALLBACK_BOR" },
3060 { DT_HP_NO_ENVVAR
, "HP_NO_ENVVAR" },
3061 { DT_HP_BIND_NOW
, "HP_BIND_NOW" },
3062 { DT_HP_BIND_NONFATAL
, "HP_BIND_NONFATAL" },
3063 { DT_HP_BIND_VERBOSE
, "HP_BIND_VERBOSE" },
3064 { DT_HP_BIND_RESTRICTED
, "HP_BIND_RESTRICTED" },
3065 { DT_HP_BIND_SYMBOLIC
, "HP_BIND_SYMBOLIC" },
3066 { DT_HP_RPATH_FIRST
, "HP_RPATH_FIRST" },
3067 { DT_HP_BIND_DEPTH_FIRST
, "HP_BIND_DEPTH_FIRST" }
3071 bfd_vma val
= entry
->d_un
.d_val
;
3073 for (cnt
= 0; cnt
< sizeof (flags
) / sizeof (flags
[0]); ++cnt
)
3074 if (val
& flags
[cnt
].bit
)
3078 fputs (flags
[cnt
].str
, stdout
);
3080 val
^= flags
[cnt
].bit
;
3083 if (val
!= 0 || first
)
3087 print_vma (val
, HEX
);
3093 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
3099 get_32bit_dynamic_segment (file
)
3102 Elf32_External_Dyn
* edyn
;
3103 Elf_Internal_Dyn
* entry
;
3106 GET_DATA_ALLOC (dynamic_addr
, dynamic_size
,
3107 edyn
, Elf32_External_Dyn
*, "dynamic segment");
3109 /* SGI's ELF has more than one section in the DYNAMIC segment. Determine
3110 how large this .dynamic is now. We can do this even before the byte
3111 swapping since the DT_NULL tag is recognizable. */
3113 while (*(Elf32_Word
*) edyn
[dynamic_size
++].d_tag
!= DT_NULL
)
3116 dynamic_segment
= (Elf_Internal_Dyn
*)
3117 malloc (dynamic_size
* sizeof (Elf_Internal_Dyn
));
3119 if (dynamic_segment
== NULL
)
3121 error (_("Out of memory\n"));
3126 for (i
= 0, entry
= dynamic_segment
;
3130 entry
->d_tag
= BYTE_GET (edyn
[i
].d_tag
);
3131 entry
->d_un
.d_val
= BYTE_GET (edyn
[i
].d_un
.d_val
);
3140 get_64bit_dynamic_segment (file
)
3143 Elf64_External_Dyn
* edyn
;
3144 Elf_Internal_Dyn
* entry
;
3147 GET_DATA_ALLOC (dynamic_addr
, dynamic_size
,
3148 edyn
, Elf64_External_Dyn
*, "dynamic segment");
3150 /* SGI's ELF has more than one section in the DYNAMIC segment. Determine
3151 how large this .dynamic is now. We can do this even before the byte
3152 swapping since the DT_NULL tag is recognizable. */
3154 while (*(bfd_vma
*) edyn
[dynamic_size
++].d_tag
!= DT_NULL
)
3157 dynamic_segment
= (Elf_Internal_Dyn
*)
3158 malloc (dynamic_size
* sizeof (Elf_Internal_Dyn
));
3160 if (dynamic_segment
== NULL
)
3162 error (_("Out of memory\n"));
3167 for (i
= 0, entry
= dynamic_segment
;
3171 entry
->d_tag
= BYTE_GET8 (edyn
[i
].d_tag
);
3172 entry
->d_un
.d_val
= BYTE_GET8 (edyn
[i
].d_un
.d_val
);
3181 get_dynamic_flags (flags
)
3184 static char buff
[64];
3189 flag
= flags
& - flags
;
3194 case DF_ORIGIN
: strcat (buff
, "ORIGIN "); break;
3195 case DF_SYMBOLIC
: strcat (buff
, "SYMBOLIC "); break;
3196 case DF_TEXTREL
: strcat (buff
, "TEXTREL "); break;
3197 case DF_BIND_NOW
: strcat (buff
, "BIND_NOW "); break;
3198 default: strcat (buff
, "unknown "); break;
3204 /* Parse and display the contents of the dynamic segment. */
3206 process_dynamic_segment (file
)
3209 Elf_Internal_Dyn
* entry
;
3212 if (dynamic_size
== 0)
3215 printf (_("\nThere is no dynamic segment in this file.\n"));
3222 if (! get_32bit_dynamic_segment (file
))
3225 else if (! get_64bit_dynamic_segment (file
))
3228 /* Find the appropriate symbol table. */
3229 if (dynamic_symbols
== NULL
)
3231 for (i
= 0, entry
= dynamic_segment
;
3235 unsigned long offset
;
3237 if (entry
->d_tag
!= DT_SYMTAB
)
3240 dynamic_info
[DT_SYMTAB
] = entry
->d_un
.d_val
;
3242 /* Since we do not know how big the symbol table is,
3243 we default to reading in the entire file (!) and
3244 processing that. This is overkill, I know, but it
3246 offset
= entry
->d_un
.d_val
- loadaddr
;
3248 if (fseek (file
, 0, SEEK_END
))
3249 error (_("Unable to seek to end of file!"));
3252 num_dynamic_syms
= (ftell (file
) - offset
) / sizeof (Elf32_External_Sym
);
3254 num_dynamic_syms
= (ftell (file
) - offset
) / sizeof (Elf64_External_Sym
);
3256 if (num_dynamic_syms
< 1)
3258 error (_("Unable to determine the number of symbols to load\n"));
3262 dynamic_symbols
= GET_ELF_SYMBOLS (file
, offset
, num_dynamic_syms
);
3266 /* Similarly find a string table. */
3267 if (dynamic_strings
== NULL
)
3269 for (i
= 0, entry
= dynamic_segment
;
3273 unsigned long offset
;
3276 if (entry
->d_tag
!= DT_STRTAB
)
3279 dynamic_info
[DT_STRTAB
] = entry
->d_un
.d_val
;
3281 /* Since we do not know how big the string table is,
3282 we default to reading in the entire file (!) and
3283 processing that. This is overkill, I know, but it
3286 offset
= entry
->d_un
.d_val
- loadaddr
;
3287 if (fseek (file
, 0, SEEK_END
))
3288 error (_("Unable to seek to end of file\n"));
3289 str_tab_len
= ftell (file
) - offset
;
3291 if (str_tab_len
< 1)
3294 (_("Unable to determine the length of the dynamic string table\n"));
3298 GET_DATA_ALLOC (offset
, str_tab_len
, dynamic_strings
, char *,
3299 "dynamic string table");
3305 /* And find the syminfo section if available. */
3306 if (dynamic_syminfo
== NULL
)
3308 unsigned int syminsz
= 0;
3310 for (i
= 0, entry
= dynamic_segment
;
3314 if (entry
->d_tag
== DT_SYMINENT
)
3316 /* Note: these braces are necessary to avoid a syntax
3317 error from the SunOS4 C compiler. */
3318 assert (sizeof (Elf_External_Syminfo
) == entry
->d_un
.d_val
);
3320 else if (entry
->d_tag
== DT_SYMINSZ
)
3321 syminsz
= entry
->d_un
.d_val
;
3322 else if (entry
->d_tag
== DT_SYMINFO
)
3323 dynamic_syminfo_offset
= entry
->d_un
.d_val
- loadaddr
;
3326 if (dynamic_syminfo_offset
!= 0 && syminsz
!= 0)
3328 Elf_External_Syminfo
* extsyminfo
;
3329 Elf_Internal_Syminfo
* syminfo
;
3331 /* There is a syminfo section. Read the data. */
3332 GET_DATA_ALLOC (dynamic_syminfo_offset
, syminsz
, extsyminfo
,
3333 Elf_External_Syminfo
*, "symbol information");
3335 dynamic_syminfo
= (Elf_Internal_Syminfo
*) malloc (syminsz
);
3336 if (dynamic_syminfo
== NULL
)
3338 error (_("Out of memory\n"));
3342 dynamic_syminfo_nent
= syminsz
/ sizeof (Elf_External_Syminfo
);
3343 for (i
= 0, syminfo
= dynamic_syminfo
; i
< dynamic_syminfo_nent
;
3346 syminfo
->si_boundto
= BYTE_GET (extsyminfo
[i
].si_boundto
);
3347 syminfo
->si_flags
= BYTE_GET (extsyminfo
[i
].si_flags
);
3354 if (do_dynamic
&& dynamic_addr
)
3355 printf (_("\nDynamic segment at offset 0x%x contains %ld entries:\n"),
3356 dynamic_addr
, (long) dynamic_size
);
3358 printf (_(" Tag Type Name/Value\n"));
3360 for (i
= 0, entry
= dynamic_segment
;
3369 print_vma (entry
->d_tag
, FULL_HEX
);
3370 dtype
= get_dynamic_type (entry
->d_tag
);
3371 printf (" (%s)%*s", dtype
,
3372 ((is_32bit_elf
? 27 : 19)
3373 - (int) strlen (dtype
)),
3377 switch (entry
->d_tag
)
3381 printf ("%s", get_dynamic_flags (entry
->d_un
.d_val
));
3391 switch (entry
->d_tag
)
3394 printf (_("Auxiliary library"));
3398 printf (_("Filter library"));
3402 printf (_("Configuration file"));
3406 printf (_("Dependency audit library"));
3410 printf (_("Audit library"));
3414 if (dynamic_strings
)
3415 printf (": [%s]\n", dynamic_strings
+ entry
->d_un
.d_val
);
3419 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
3428 printf (_("Flags:"));
3429 if (entry
->d_un
.d_val
== 0)
3430 printf (_(" None\n"));
3433 unsigned long int val
= entry
->d_un
.d_val
;
3434 if (val
& DTF_1_PARINIT
)
3436 printf (" PARINIT");
3437 val
^= DTF_1_PARINIT
;
3439 if (val
& DTF_1_CONFEXP
)
3441 printf (" CONFEXP");
3442 val
^= DTF_1_CONFEXP
;
3445 printf (" %lx", val
);
3454 printf (_("Flags:"));
3455 if (entry
->d_un
.d_val
== 0)
3456 printf (_(" None\n"));
3459 unsigned long int val
= entry
->d_un
.d_val
;
3460 if (val
& DF_P1_LAZYLOAD
)
3462 printf (" LAZYLOAD");
3463 val
^= DF_P1_LAZYLOAD
;
3465 if (val
& DF_P1_GROUPPERM
)
3467 printf (" GROUPPERM");
3468 val
^= DF_P1_GROUPPERM
;
3471 printf (" %lx", val
);
3480 printf (_("Flags:"));
3481 if (entry
->d_un
.d_val
== 0)
3482 printf (_(" None\n"));
3485 unsigned long int val
= entry
->d_un
.d_val
;
3491 if (val
& DF_1_GLOBAL
)
3496 if (val
& DF_1_GROUP
)
3501 if (val
& DF_1_NODELETE
)
3503 printf (" NODELETE");
3504 val
^= DF_1_NODELETE
;
3506 if (val
& DF_1_LOADFLTR
)
3508 printf (" LOADFLTR");
3509 val
^= DF_1_LOADFLTR
;
3511 if (val
& DF_1_INITFIRST
)
3513 printf (" INITFIRST");
3514 val
^= DF_1_INITFIRST
;
3516 if (val
& DF_1_NOOPEN
)
3521 if (val
& DF_1_ORIGIN
)
3526 if (val
& DF_1_DIRECT
)
3531 if (val
& DF_1_TRANS
)
3536 if (val
& DF_1_INTERPOSE
)
3538 printf (" INTERPOSE");
3539 val
^= DF_1_INTERPOSE
;
3541 if (val
& DF_1_NODEFLIB
)
3543 printf (" NODEFLIB");
3544 val
^= DF_1_NODEFLIB
;
3546 if (val
& DF_1_NODUMP
)
3551 if (val
& DF_1_CONLFAT
)
3553 printf (" CONLFAT");
3554 val
^= DF_1_CONLFAT
;
3557 printf (" %lx", val
);
3565 puts (get_dynamic_type (entry
->d_un
.d_val
));
3585 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
3591 if (dynamic_strings
== NULL
)
3594 name
= dynamic_strings
+ entry
->d_un
.d_val
;
3598 switch (entry
->d_tag
)
3601 printf (_("Shared library: [%s]"), name
);
3603 if (strcmp (name
, program_interpreter
) == 0)
3604 printf (_(" program interpreter"));
3608 printf (_("Library soname: [%s]"), name
);
3612 printf (_("Library rpath: [%s]"), name
);
3616 printf (_("Library runpath: [%s]"), name
);
3620 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
3625 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
3641 case DT_INIT_ARRAYSZ
:
3642 case DT_FINI_ARRAYSZ
:
3645 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
3646 printf (" (bytes)\n");
3656 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
3669 if (dynamic_strings
!= NULL
&& entry
->d_tag
== DT_USED
)
3673 name
= dynamic_strings
+ entry
->d_un
.d_val
;
3677 printf (_("Not needed object: [%s]\n"), name
);
3682 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
3688 /* The value of this entry is ignored. */
3692 if ((entry
->d_tag
>= DT_VERSYM
) && (entry
->d_tag
<= DT_VERNEEDNUM
))
3693 version_info
[DT_VERSIONTAGIDX (entry
->d_tag
)] =
3698 switch (elf_header
.e_machine
)
3701 case EM_MIPS_RS4_BE
:
3702 dynamic_segment_mips_val (entry
);
3705 dynamic_segment_parisc_val (entry
);
3708 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
3720 get_ver_flags (flags
)
3723 static char buff
[32];
3730 if (flags
& VER_FLG_BASE
)
3731 strcat (buff
, "BASE ");
3733 if (flags
& VER_FLG_WEAK
)
3735 if (flags
& VER_FLG_BASE
)
3736 strcat (buff
, "| ");
3738 strcat (buff
, "WEAK ");
3741 if (flags
& ~(VER_FLG_BASE
| VER_FLG_WEAK
))
3742 strcat (buff
, "| <unknown>");
3747 /* Display the contents of the version sections. */
3749 process_version_sections (file
)
3752 Elf32_Internal_Shdr
* section
;
3759 for (i
= 0, section
= section_headers
;
3760 i
< elf_header
.e_shnum
;
3763 switch (section
->sh_type
)
3765 case SHT_GNU_verdef
:
3767 Elf_External_Verdef
* edefs
;
3774 (_("\nVersion definition section '%s' contains %ld entries:\n"),
3775 SECTION_NAME (section
), section
->sh_info
);
3777 printf (_(" Addr: 0x"));
3778 printf_vma (section
->sh_addr
);
3779 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
3780 (unsigned long) section
->sh_offset
, section
->sh_link
,
3781 SECTION_NAME (section_headers
+ section
->sh_link
));
3783 GET_DATA_ALLOC (section
->sh_offset
, section
->sh_size
,
3784 edefs
, Elf_External_Verdef
*,
3785 "version definition section");
3787 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++ cnt
)
3790 Elf_External_Verdef
* edef
;
3791 Elf_Internal_Verdef ent
;
3792 Elf_External_Verdaux
* eaux
;
3793 Elf_Internal_Verdaux aux
;
3797 vstart
= ((char *) edefs
) + idx
;
3799 edef
= (Elf_External_Verdef
*) vstart
;
3801 ent
.vd_version
= BYTE_GET (edef
->vd_version
);
3802 ent
.vd_flags
= BYTE_GET (edef
->vd_flags
);
3803 ent
.vd_ndx
= BYTE_GET (edef
->vd_ndx
);
3804 ent
.vd_cnt
= BYTE_GET (edef
->vd_cnt
);
3805 ent
.vd_hash
= BYTE_GET (edef
->vd_hash
);
3806 ent
.vd_aux
= BYTE_GET (edef
->vd_aux
);
3807 ent
.vd_next
= BYTE_GET (edef
->vd_next
);
3809 printf (_(" %#06x: Rev: %d Flags: %s"),
3810 idx
, ent
.vd_version
, get_ver_flags (ent
.vd_flags
));
3812 printf (_(" Index: %d Cnt: %d "),
3813 ent
.vd_ndx
, ent
.vd_cnt
);
3815 vstart
+= ent
.vd_aux
;
3817 eaux
= (Elf_External_Verdaux
*) vstart
;
3819 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
3820 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
3822 if (dynamic_strings
)
3823 printf (_("Name: %s\n"), dynamic_strings
+ aux
.vda_name
);
3825 printf (_("Name index: %ld\n"), aux
.vda_name
);
3827 isum
= idx
+ ent
.vd_aux
;
3829 for (j
= 1; j
< ent
.vd_cnt
; j
++)
3831 isum
+= aux
.vda_next
;
3832 vstart
+= aux
.vda_next
;
3834 eaux
= (Elf_External_Verdaux
*) vstart
;
3836 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
3837 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
3839 if (dynamic_strings
)
3840 printf (_(" %#06x: Parent %d: %s\n"),
3841 isum
, j
, dynamic_strings
+ aux
.vda_name
);
3843 printf (_(" %#06x: Parent %d, name index: %ld\n"),
3844 isum
, j
, aux
.vda_name
);
3854 case SHT_GNU_verneed
:
3856 Elf_External_Verneed
* eneed
;
3862 printf (_("\nVersion needs section '%s' contains %ld entries:\n"),
3863 SECTION_NAME (section
), section
->sh_info
);
3865 printf (_(" Addr: 0x"));
3866 printf_vma (section
->sh_addr
);
3867 printf (_(" Offset: %#08lx Link to section: %ld (%s)\n"),
3868 (unsigned long) section
->sh_offset
, section
->sh_link
,
3869 SECTION_NAME (section_headers
+ section
->sh_link
));
3871 GET_DATA_ALLOC (section
->sh_offset
, section
->sh_size
,
3872 eneed
, Elf_External_Verneed
*,
3873 "version need section");
3875 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
3877 Elf_External_Verneed
* entry
;
3878 Elf_Internal_Verneed ent
;
3883 vstart
= ((char *) eneed
) + idx
;
3885 entry
= (Elf_External_Verneed
*) vstart
;
3887 ent
.vn_version
= BYTE_GET (entry
->vn_version
);
3888 ent
.vn_cnt
= BYTE_GET (entry
->vn_cnt
);
3889 ent
.vn_file
= BYTE_GET (entry
->vn_file
);
3890 ent
.vn_aux
= BYTE_GET (entry
->vn_aux
);
3891 ent
.vn_next
= BYTE_GET (entry
->vn_next
);
3893 printf (_(" %#06x: Version: %d"), idx
, ent
.vn_version
);
3895 if (dynamic_strings
)
3896 printf (_(" File: %s"), dynamic_strings
+ ent
.vn_file
);
3898 printf (_(" File: %lx"), ent
.vn_file
);
3900 printf (_(" Cnt: %d\n"), ent
.vn_cnt
);
3902 vstart
+= ent
.vn_aux
;
3904 for (j
= 0, isum
= idx
+ ent
.vn_aux
; j
< ent
.vn_cnt
; ++j
)
3906 Elf_External_Vernaux
* eaux
;
3907 Elf_Internal_Vernaux aux
;
3909 eaux
= (Elf_External_Vernaux
*) vstart
;
3911 aux
.vna_hash
= BYTE_GET (eaux
->vna_hash
);
3912 aux
.vna_flags
= BYTE_GET (eaux
->vna_flags
);
3913 aux
.vna_other
= BYTE_GET (eaux
->vna_other
);
3914 aux
.vna_name
= BYTE_GET (eaux
->vna_name
);
3915 aux
.vna_next
= BYTE_GET (eaux
->vna_next
);
3917 if (dynamic_strings
)
3918 printf (_(" %#06x: Name: %s"),
3919 isum
, dynamic_strings
+ aux
.vna_name
);
3921 printf (_(" %#06x: Name index: %lx"),
3922 isum
, aux
.vna_name
);
3924 printf (_(" Flags: %s Version: %d\n"),
3925 get_ver_flags (aux
.vna_flags
), aux
.vna_other
);
3927 isum
+= aux
.vna_next
;
3928 vstart
+= aux
.vna_next
;
3938 case SHT_GNU_versym
:
3940 Elf32_Internal_Shdr
* link_section
;
3943 unsigned char * edata
;
3944 unsigned short * data
;
3946 Elf_Internal_Sym
* symbols
;
3947 Elf32_Internal_Shdr
* string_sec
;
3949 link_section
= section_headers
+ section
->sh_link
;
3950 total
= section
->sh_size
/ section
->sh_entsize
;
3954 symbols
= GET_ELF_SYMBOLS (file
, link_section
->sh_offset
,
3955 link_section
->sh_size
/ link_section
->sh_entsize
);
3957 string_sec
= section_headers
+ link_section
->sh_link
;
3959 GET_DATA_ALLOC (string_sec
->sh_offset
, string_sec
->sh_size
,
3960 strtab
, char *, "version string table");
3962 printf (_("\nVersion symbols section '%s' contains %d entries:\n"),
3963 SECTION_NAME (section
), total
);
3965 printf (_(" Addr: "));
3966 printf_vma (section
->sh_addr
);
3967 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
3968 (unsigned long) section
->sh_offset
, section
->sh_link
,
3969 SECTION_NAME (link_section
));
3971 GET_DATA_ALLOC (version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)]
3973 total
* sizeof (short), edata
,
3974 unsigned char *, "version symbol data");
3976 data
= (unsigned short *) malloc (total
* sizeof (short));
3978 for (cnt
= total
; cnt
--;)
3979 data
[cnt
] = byte_get (edata
+ cnt
* sizeof (short),
3984 for (cnt
= 0; cnt
< total
; cnt
+= 4)
3989 printf (" %03x:", cnt
);
3991 for (j
= 0; (j
< 4) && (cnt
+ j
) < total
; ++j
)
3992 switch (data
[cnt
+ j
])
3995 fputs (_(" 0 (*local*) "), stdout
);
3999 fputs (_(" 1 (*global*) "), stdout
);
4003 nn
= printf ("%4x%c", data
[cnt
+ j
] & 0x7fff,
4004 data
[cnt
+ j
] & 0x8000 ? 'h' : ' ');
4006 if (symbols
[cnt
+ j
].st_shndx
< SHN_LORESERVE
4007 && section_headers
[symbols
[cnt
+ j
].st_shndx
].sh_type
4010 /* We must test both. */
4011 Elf_Internal_Verneed ivn
;
4012 unsigned long offset
;
4014 offset
= version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)]
4019 Elf_External_Verneed evn
;
4020 Elf_External_Vernaux evna
;
4021 Elf_Internal_Vernaux ivna
;
4022 unsigned long vna_off
;
4024 GET_DATA (offset
, evn
, "version need");
4026 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
4027 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
4029 vna_off
= offset
+ ivn
.vn_aux
;
4033 GET_DATA (vna_off
, evna
,
4034 "version need aux (1)");
4036 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
4037 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
4039 vna_off
+= ivna
.vna_next
;
4041 while (ivna
.vna_other
!= data
[cnt
+ j
]
4042 && ivna
.vna_next
!= 0);
4044 if (ivna
.vna_other
== data
[cnt
+ j
])
4046 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
4048 name
= strtab
+ ivna
.vna_name
;
4049 nn
+= printf ("(%s%-*s",
4051 12 - (int) strlen (name
),
4055 else if (ivn
.vn_next
== 0)
4057 if (data
[cnt
+ j
] != 0x8001)
4059 Elf_Internal_Verdef ivd
;
4060 Elf_External_Verdef evd
;
4062 offset
= version_info
4063 [DT_VERSIONTAGIDX (DT_VERDEF
)]
4068 GET_DATA (offset
, evd
,
4069 "version definition");
4071 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
4072 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
4074 offset
+= ivd
.vd_next
;
4077 != (data
[cnt
+ j
] & 0x7fff)
4078 && ivd
.vd_next
!= 0);
4081 == (data
[cnt
+ j
] & 0x7fff))
4083 Elf_External_Verdaux evda
;
4084 Elf_Internal_Verdaux ivda
;
4086 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
4088 GET_DATA (offset
+ ivd
.vd_aux
, evda
,
4089 "version definition aux");
4092 BYTE_GET (evda
.vda_name
);
4094 name
= strtab
+ ivda
.vda_name
;
4098 12 - (int) strlen (name
),
4106 offset
+= ivn
.vn_next
;
4108 while (ivn
.vn_next
);
4110 else if (symbols
[cnt
+ j
].st_shndx
== SHN_UNDEF
)
4112 Elf_Internal_Verneed ivn
;
4113 unsigned long offset
;
4115 offset
= version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)]
4120 Elf_Internal_Vernaux ivna
;
4121 Elf_External_Verneed evn
;
4122 Elf_External_Vernaux evna
;
4123 unsigned long a_off
;
4125 GET_DATA (offset
, evn
, "version need");
4127 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
4128 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
4130 a_off
= offset
+ ivn
.vn_aux
;
4134 GET_DATA (a_off
, evna
,
4135 "version need aux (2)");
4137 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
4138 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
4140 a_off
+= ivna
.vna_next
;
4142 while (ivna
.vna_other
!= data
[cnt
+ j
]
4143 && ivna
.vna_next
!= 0);
4145 if (ivna
.vna_other
== data
[cnt
+ j
])
4147 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
4149 name
= strtab
+ ivna
.vna_name
;
4150 nn
+= printf ("(%s%-*s",
4152 12 - (int) strlen (name
),
4157 offset
+= ivn
.vn_next
;
4159 while (ivn
.vn_next
);
4161 else if (data
[cnt
+ j
] != 0x8001)
4163 Elf_Internal_Verdef ivd
;
4164 Elf_External_Verdef evd
;
4165 unsigned long offset
;
4167 offset
= version_info
4168 [DT_VERSIONTAGIDX (DT_VERDEF
)] - loadaddr
;
4172 GET_DATA (offset
, evd
, "version def");
4174 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
4175 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
4177 offset
+= ivd
.vd_next
;
4179 while (ivd
.vd_ndx
!= (data
[cnt
+ j
] & 0x7fff)
4180 && ivd
.vd_next
!= 0);
4182 if (ivd
.vd_ndx
== (data
[cnt
+ j
] & 0x7fff))
4184 Elf_External_Verdaux evda
;
4185 Elf_Internal_Verdaux ivda
;
4187 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
4189 GET_DATA (offset
- ivd
.vd_next
+ ivd
.vd_aux
,
4190 evda
, "version def aux");
4192 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
4194 name
= strtab
+ ivda
.vda_name
;
4195 nn
+= printf ("(%s%-*s",
4197 12 - (int) strlen (name
),
4203 printf ("%*c", 18 - nn
, ' ');
4221 printf (_("\nNo version information found in this file.\n"));
4227 get_symbol_binding (binding
)
4228 unsigned int binding
;
4230 static char buff
[32];
4234 case STB_LOCAL
: return "LOCAL";
4235 case STB_GLOBAL
: return "GLOBAL";
4236 case STB_WEAK
: return "WEAK";
4238 if (binding
>= STB_LOPROC
&& binding
<= STB_HIPROC
)
4239 sprintf (buff
, _("<processor specific>: %d"), binding
);
4240 else if (binding
>= STB_LOOS
&& binding
<= STB_HIOS
)
4241 sprintf (buff
, _("<OS specific>: %d"), binding
);
4243 sprintf (buff
, _("<unknown>: %d"), binding
);
4249 get_symbol_type (type
)
4252 static char buff
[32];
4256 case STT_NOTYPE
: return "NOTYPE";
4257 case STT_OBJECT
: return "OBJECT";
4258 case STT_FUNC
: return "FUNC";
4259 case STT_SECTION
: return "SECTION";
4260 case STT_FILE
: return "FILE";
4261 case STT_COMMON
: return "COMMON";
4263 if (type
>= STT_LOPROC
&& type
<= STT_HIPROC
)
4265 if (elf_header
.e_machine
== EM_ARM
&& type
== STT_ARM_TFUNC
)
4266 return "THUMB_FUNC";
4268 if (elf_header
.e_machine
== EM_SPARCV9
&& type
== STT_REGISTER
)
4271 if (elf_header
.e_machine
== EM_PARISC
&& type
== STT_PARISC_MILLI
)
4272 return "PARISC_MILLI";
4274 sprintf (buff
, _("<processor specific>: %d"), type
);
4276 else if (type
>= STT_LOOS
&& type
<= STT_HIOS
)
4278 if (elf_header
.e_machine
== EM_PARISC
)
4280 if (type
== STT_HP_OPAQUE
)
4282 if (type
== STT_HP_STUB
)
4286 sprintf (buff
, _("<OS specific>: %d"), type
);
4289 sprintf (buff
, _("<unknown>: %d"), type
);
4295 get_symbol_visibility (visibility
)
4296 unsigned int visibility
;
4300 case STV_DEFAULT
: return "DEFAULT";
4301 case STV_INTERNAL
: return "INTERNAL";
4302 case STV_HIDDEN
: return "HIDDEN";
4303 case STV_PROTECTED
: return "PROTECTED";
4309 get_symbol_index_type (type
)
4314 case SHN_UNDEF
: return "UND";
4315 case SHN_ABS
: return "ABS";
4316 case SHN_COMMON
: return "COM";
4318 if (type
>= SHN_LOPROC
&& type
<= SHN_HIPROC
)
4320 else if (type
>= SHN_LORESERVE
&& type
<= SHN_HIRESERVE
)
4322 else if (type
>= SHN_LOOS
&& type
<= SHN_HIOS
)
4326 static char buff
[32];
4328 sprintf (buff
, "%3d", type
);
4335 get_dynamic_data (file
, number
)
4337 unsigned int number
;
4339 unsigned char * e_data
;
4342 e_data
= (unsigned char *) malloc (number
* 4);
4346 error (_("Out of memory\n"));
4350 if (fread (e_data
, 4, number
, file
) != number
)
4352 error (_("Unable to read in dynamic data\n"));
4356 i_data
= (int *) malloc (number
* sizeof (* i_data
));
4360 error (_("Out of memory\n"));
4366 i_data
[number
] = byte_get (e_data
+ number
* 4, 4);
4373 /* Dump the symbol table */
4375 process_symbol_table (file
)
4378 Elf32_Internal_Shdr
* section
;
4379 unsigned char nb
[4];
4380 unsigned char nc
[4];
4383 int * buckets
= NULL
;
4384 int * chains
= NULL
;
4386 if (! do_syms
&& !do_histogram
)
4389 if (dynamic_info
[DT_HASH
] && ((do_using_dynamic
&& dynamic_strings
!= NULL
)
4392 if (fseek (file
, dynamic_info
[DT_HASH
] - loadaddr
, SEEK_SET
))
4394 error (_("Unable to seek to start of dynamic information"));
4398 if (fread (nb
, sizeof (nb
), 1, file
) != 1)
4400 error (_("Failed to read in number of buckets\n"));
4404 if (fread (nc
, sizeof (nc
), 1, file
) != 1)
4406 error (_("Failed to read in number of chains\n"));
4410 nbuckets
= byte_get (nb
, 4);
4411 nchains
= byte_get (nc
, 4);
4413 buckets
= get_dynamic_data (file
, nbuckets
);
4414 chains
= get_dynamic_data (file
, nchains
);
4416 if (buckets
== NULL
|| chains
== NULL
)
4421 && dynamic_info
[DT_HASH
] && do_using_dynamic
&& dynamic_strings
!= NULL
)
4426 printf (_("\nSymbol table for image:\n"));
4428 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
4430 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
4432 for (hn
= 0; hn
< nbuckets
; hn
++)
4437 for (si
= buckets
[hn
]; si
< nchains
&& si
> 0; si
= chains
[si
])
4439 Elf_Internal_Sym
* psym
;
4441 psym
= dynamic_symbols
+ si
;
4443 printf (" %3d %3d: ", si
, hn
);
4444 print_vma (psym
->st_value
, LONG_HEX
);
4446 print_vma (psym
->st_size
, DEC_5
);
4448 printf (" %6s", get_symbol_type (ELF_ST_TYPE (psym
->st_info
)));
4449 printf (" %6s", get_symbol_binding (ELF_ST_BIND (psym
->st_info
)));
4450 printf (" %3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym
->st_other
)));
4451 printf (" %3.3s", get_symbol_index_type (psym
->st_shndx
));
4452 printf (" %s\n", dynamic_strings
+ psym
->st_name
);
4456 else if (do_syms
&& !do_using_dynamic
)
4460 for (i
= 0, section
= section_headers
;
4461 i
< elf_header
.e_shnum
;
4466 Elf_Internal_Sym
* symtab
;
4467 Elf_Internal_Sym
* psym
;
4470 if ( section
->sh_type
!= SHT_SYMTAB
4471 && section
->sh_type
!= SHT_DYNSYM
)
4474 printf (_("\nSymbol table '%s' contains %lu entries:\n"),
4475 SECTION_NAME (section
),
4476 (unsigned long) (section
->sh_size
/ section
->sh_entsize
));
4478 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
4480 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
4482 symtab
= GET_ELF_SYMBOLS (file
, section
->sh_offset
,
4483 section
->sh_size
/ section
->sh_entsize
);
4487 if (section
->sh_link
== elf_header
.e_shstrndx
)
4488 strtab
= string_table
;
4491 Elf32_Internal_Shdr
* string_sec
;
4493 string_sec
= section_headers
+ section
->sh_link
;
4495 GET_DATA_ALLOC (string_sec
->sh_offset
, string_sec
->sh_size
,
4496 strtab
, char *, "string table");
4499 for (si
= 0, psym
= symtab
;
4500 si
< section
->sh_size
/ section
->sh_entsize
;
4503 printf ("%6d: ", si
);
4504 print_vma (psym
->st_value
, LONG_HEX
);
4506 print_vma (psym
->st_size
, DEC_5
);
4507 printf (" %-7s", get_symbol_type (ELF_ST_TYPE (psym
->st_info
)));
4508 printf (" %-6s", get_symbol_binding (ELF_ST_BIND (psym
->st_info
)));
4509 printf (" %-3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym
->st_other
)));
4510 printf (" %4s", get_symbol_index_type (psym
->st_shndx
));
4511 printf (" %s", strtab
+ psym
->st_name
);
4513 if (section
->sh_type
== SHT_DYNSYM
&&
4514 version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)] != 0)
4516 unsigned char data
[2];
4517 unsigned short vers_data
;
4518 unsigned long offset
;
4522 offset
= version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)]
4525 GET_DATA (offset
+ si
* sizeof (vers_data
), data
,
4528 vers_data
= byte_get (data
, 2);
4530 is_nobits
= psym
->st_shndx
< SHN_LORESERVE
?
4531 (section_headers
[psym
->st_shndx
].sh_type
== SHT_NOBITS
)
4534 check_def
= (psym
->st_shndx
!= SHN_UNDEF
);
4536 if ((vers_data
& 0x8000) || vers_data
> 1)
4538 if (is_nobits
|| ! check_def
)
4540 Elf_External_Verneed evn
;
4541 Elf_Internal_Verneed ivn
;
4542 Elf_Internal_Vernaux ivna
;
4544 /* We must test both. */
4545 offset
= version_info
4546 [DT_VERSIONTAGIDX (DT_VERNEED
)] - loadaddr
;
4550 unsigned long vna_off
;
4552 GET_DATA (offset
, evn
, "version need");
4554 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
4555 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
4557 vna_off
= offset
+ ivn
.vn_aux
;
4561 Elf_External_Vernaux evna
;
4563 GET_DATA (vna_off
, evna
,
4564 "version need aux (3)");
4566 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
4567 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
4568 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
4570 vna_off
+= ivna
.vna_next
;
4572 while (ivna
.vna_other
!= vers_data
4573 && ivna
.vna_next
!= 0);
4575 if (ivna
.vna_other
== vers_data
)
4578 offset
+= ivn
.vn_next
;
4580 while (ivn
.vn_next
!= 0);
4582 if (ivna
.vna_other
== vers_data
)
4585 strtab
+ ivna
.vna_name
, ivna
.vna_other
);
4588 else if (! is_nobits
)
4589 error (_("bad dynamic symbol"));
4596 if (vers_data
!= 0x8001)
4598 Elf_Internal_Verdef ivd
;
4599 Elf_Internal_Verdaux ivda
;
4600 Elf_External_Verdaux evda
;
4601 unsigned long offset
;
4604 version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)]
4609 Elf_External_Verdef evd
;
4611 GET_DATA (offset
, evd
, "version def");
4613 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
4614 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
4615 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
4617 offset
+= ivd
.vd_next
;
4619 while (ivd
.vd_ndx
!= (vers_data
& 0x7fff)
4620 && ivd
.vd_next
!= 0);
4622 offset
-= ivd
.vd_next
;
4623 offset
+= ivd
.vd_aux
;
4625 GET_DATA (offset
, evda
, "version def aux");
4627 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
4629 if (psym
->st_name
!= ivda
.vda_name
)
4630 printf ((vers_data
& 0x8000)
4632 strtab
+ ivda
.vda_name
);
4642 if (strtab
!= string_table
)
4648 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
4650 if (do_histogram
&& buckets
!= NULL
)
4657 int nzero_counts
= 0;
4660 printf (_("\nHistogram for bucket list length (total of %d buckets):\n"),
4662 printf (_(" Length Number %% of total Coverage\n"));
4664 lengths
= (int *) calloc (nbuckets
, sizeof (int));
4665 if (lengths
== NULL
)
4667 error (_("Out of memory"));
4670 for (hn
= 0; hn
< nbuckets
; ++hn
)
4675 for (si
= buckets
[hn
]; si
> 0 && si
< nchains
; si
= chains
[si
])
4678 if (maxlength
< ++lengths
[hn
])
4683 counts
= (int *) calloc (maxlength
+ 1, sizeof (int));
4686 error (_("Out of memory"));
4690 for (hn
= 0; hn
< nbuckets
; ++hn
)
4691 ++ counts
[lengths
[hn
]];
4695 printf (" 0 %-10d (%5.1f%%)\n",
4696 counts
[0], (counts
[0] * 100.0) / nbuckets
);
4697 for (si
= 1; si
<= maxlength
; ++si
)
4699 nzero_counts
+= counts
[si
] * si
;
4700 printf ("%7d %-10d (%5.1f%%) %5.1f%%\n",
4701 si
, counts
[si
], (counts
[si
] * 100.0) / nbuckets
,
4702 (nzero_counts
* 100.0) / nsyms
);
4710 if (buckets
!= NULL
)
4720 process_syminfo (file
)
4721 FILE * file ATTRIBUTE_UNUSED
;
4725 if (dynamic_syminfo
== NULL
4727 /* No syminfo, this is ok. */
4730 /* There better should be a dynamic symbol section. */
4731 if (dynamic_symbols
== NULL
|| dynamic_strings
== NULL
)
4735 printf (_("\nDynamic info segment at offset 0x%lx contains %d entries:\n"),
4736 dynamic_syminfo_offset
, dynamic_syminfo_nent
);
4738 printf (_(" Num: Name BoundTo Flags\n"));
4739 for (i
= 0; i
< dynamic_syminfo_nent
; ++i
)
4741 unsigned short int flags
= dynamic_syminfo
[i
].si_flags
;
4743 printf ("%4d: %-30s ", i
,
4744 dynamic_strings
+ dynamic_symbols
[i
].st_name
);
4746 switch (dynamic_syminfo
[i
].si_boundto
)
4748 case SYMINFO_BT_SELF
:
4749 fputs ("SELF ", stdout
);
4751 case SYMINFO_BT_PARENT
:
4752 fputs ("PARENT ", stdout
);
4755 if (dynamic_syminfo
[i
].si_boundto
> 0
4756 && dynamic_syminfo
[i
].si_boundto
< dynamic_size
)
4759 + dynamic_segment
[dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
);
4761 printf ("%-10d ", dynamic_syminfo
[i
].si_boundto
);
4765 if (flags
& SYMINFO_FLG_DIRECT
)
4767 if (flags
& SYMINFO_FLG_PASSTHRU
)
4768 printf (" PASSTHRU");
4769 if (flags
& SYMINFO_FLG_COPY
)
4771 if (flags
& SYMINFO_FLG_LAZYLOAD
)
4772 printf (" LAZYLOAD");
4780 #ifdef SUPPORT_DISASSEMBLY
4782 disassemble_section (section
, file
)
4783 Elf32_Internal_Shdr
* section
;
4786 printf (_("\nAssembly dump of section %s\n"),
4787 SECTION_NAME (section
));
4789 /* XXX -- to be done --- XXX */
4796 dump_section (section
, file
)
4797 Elf32_Internal_Shdr
* section
;
4800 bfd_size_type bytes
;
4802 unsigned char * data
;
4803 unsigned char * start
;
4805 bytes
= section
->sh_size
;
4809 printf (_("\nSection '%s' has no data to dump.\n"),
4810 SECTION_NAME (section
));
4814 printf (_("\nHex dump of section '%s':\n"), SECTION_NAME (section
));
4816 addr
= section
->sh_addr
;
4818 GET_DATA_ALLOC (section
->sh_offset
, bytes
, start
, unsigned char *,
4829 lbytes
= (bytes
> 16 ? 16 : bytes
);
4831 printf (" 0x%8.8lx ", (unsigned long) addr
);
4833 switch (elf_header
.e_ident
[EI_DATA
])
4837 for (j
= 15; j
>= 0; j
--)
4840 printf ("%2.2x", data
[j
]);
4850 for (j
= 0; j
< 16; j
++)
4853 printf ("%2.2x", data
[j
]);
4863 for (j
= 0; j
< lbytes
; j
++)
4866 if (k
>= ' ' && k
< 0x80)
4885 static unsigned long int
4886 read_leb128 (data
, length_return
, sign
)
4887 unsigned char * data
;
4888 int * length_return
;
4891 unsigned long int result
= 0;
4892 unsigned int num_read
= 0;
4901 result
|= (byte
& 0x7f) << shift
;
4906 while (byte
& 0x80);
4908 if (length_return
!= NULL
)
4909 * length_return
= num_read
;
4911 if (sign
&& (shift
< 32) && (byte
& 0x40))
4912 result
|= -1 << shift
;
4917 typedef struct State_Machine_Registers
4919 unsigned long address
;
4922 unsigned int column
;
4926 /* This variable hold the number of the last entry seen
4927 in the File Table. */
4928 unsigned int last_file_entry
;
4931 static SMR state_machine_regs
;
4934 reset_state_machine (is_stmt
)
4937 state_machine_regs
.address
= 0;
4938 state_machine_regs
.file
= 1;
4939 state_machine_regs
.line
= 1;
4940 state_machine_regs
.column
= 0;
4941 state_machine_regs
.is_stmt
= is_stmt
;
4942 state_machine_regs
.basic_block
= 0;
4943 state_machine_regs
.end_sequence
= 0;
4944 state_machine_regs
.last_file_entry
= 0;
4947 /* Handled an extend line op. Returns true if this is the end
4950 process_extended_line_op (data
, is_stmt
, pointer_size
)
4951 unsigned char * data
;
4955 unsigned char op_code
;
4958 unsigned char * name
;
4961 len
= read_leb128 (data
, & bytes_read
, 0);
4966 warn (_("badly formed extended line op encountered!"));
4971 op_code
= * data
++;
4973 printf (_(" Extended opcode %d: "), op_code
);
4977 case DW_LNE_end_sequence
:
4978 printf (_("End of Sequence\n\n"));
4979 reset_state_machine (is_stmt
);
4982 case DW_LNE_set_address
:
4983 adr
= byte_get (data
, pointer_size
);
4984 printf (_("set Address to 0x%lx\n"), adr
);
4985 state_machine_regs
.address
= adr
;
4988 case DW_LNE_define_file
:
4989 printf (_(" define new File Table entry\n"));
4990 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
4992 printf (_(" %d\t"), ++ state_machine_regs
.last_file_entry
);
4994 data
+= strlen ((char *) data
) + 1;
4995 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
4997 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
4999 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
5000 printf (_("%s\n\n"), name
);
5004 printf (_("UNKNOWN: length %d\n"), len
- bytes_read
);
5011 /* Size of pointers in the .debug_line section. This information is not
5012 really present in that section. It's obtained before dumping the debug
5013 sections by doing some pre-scan of the .debug_info section. */
5014 static int debug_line_pointer_size
= 4;
5017 display_debug_lines (section
, start
, file
)
5018 Elf32_Internal_Shdr
* section
;
5019 unsigned char * start
;
5020 FILE * file ATTRIBUTE_UNUSED
;
5022 DWARF2_External_LineInfo
* external
;
5023 DWARF2_Internal_LineInfo info
;
5024 unsigned char * standard_opcodes
;
5025 unsigned char * data
= start
;
5026 unsigned char * end
= start
+ section
->sh_size
;
5027 unsigned char * end_of_sequence
;
5030 printf (_("\nDump of debug contents of section %s:\n\n"),
5031 SECTION_NAME (section
));
5035 external
= (DWARF2_External_LineInfo
*) data
;
5037 /* Check the length of the block. */
5038 info
.li_length
= BYTE_GET (external
->li_length
);
5039 if (info
.li_length
+ sizeof (external
->li_length
) > section
->sh_size
)
5042 (_("The line info appears to be corrupt - the section is too small\n"));
5046 /* Check its version number. */
5047 info
.li_version
= BYTE_GET (external
->li_version
);
5048 if (info
.li_version
!= 2)
5050 warn (_("Only DWARF version 2 line info is currently supported.\n"));
5054 info
.li_prologue_length
= BYTE_GET (external
->li_prologue_length
);
5055 info
.li_min_insn_length
= BYTE_GET (external
->li_min_insn_length
);
5056 info
.li_default_is_stmt
= BYTE_GET (external
->li_default_is_stmt
);
5057 info
.li_line_base
= BYTE_GET (external
->li_line_base
);
5058 info
.li_line_range
= BYTE_GET (external
->li_line_range
);
5059 info
.li_opcode_base
= BYTE_GET (external
->li_opcode_base
);
5061 /* Sign extend the line base field. */
5062 info
.li_line_base
<<= 24;
5063 info
.li_line_base
>>= 24;
5065 printf (_(" Length: %ld\n"), info
.li_length
);
5066 printf (_(" DWARF Version: %d\n"), info
.li_version
);
5067 printf (_(" Prolgue Length: %d\n"), info
.li_prologue_length
);
5068 printf (_(" Minimum Instruction Length: %d\n"), info
.li_min_insn_length
);
5069 printf (_(" Initial value of 'is_stmt': %d\n"), info
.li_default_is_stmt
);
5070 printf (_(" Line Base: %d\n"), info
.li_line_base
);
5071 printf (_(" Line Range: %d\n"), info
.li_line_range
);
5072 printf (_(" Opcode Base: %d\n"), info
.li_opcode_base
);
5074 end_of_sequence
= data
+ info
.li_length
+ sizeof (external
->li_length
);
5076 reset_state_machine (info
.li_default_is_stmt
);
5078 /* Display the contents of the Opcodes table. */
5079 standard_opcodes
= data
+ sizeof (* external
);
5081 printf (_("\n Opcodes:\n"));
5083 for (i
= 1; i
< info
.li_opcode_base
; i
++)
5084 printf (_(" Opcode %d has %d args\n"), i
, standard_opcodes
[i
- 1]);
5086 /* Display the contents of the Directory table. */
5087 data
= standard_opcodes
+ info
.li_opcode_base
- 1;
5090 printf (_("\n The Directory Table is empty.\n"));
5093 printf (_("\n The Directory Table:\n"));
5097 printf (_(" %s\n"), data
);
5099 data
+= strlen ((char *) data
) + 1;
5103 /* Skip the NUL at the end of the table. */
5106 /* Display the contents of the File Name table. */
5108 printf (_("\n The File Name Table is empty.\n"));
5111 printf (_("\n The File Name Table:\n"));
5112 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
5116 unsigned char * name
;
5119 printf (_(" %d\t"), ++ state_machine_regs
.last_file_entry
);
5122 data
+= strlen ((char *) data
) + 1;
5124 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
5126 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
5128 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
5130 printf (_("%s\n"), name
);
5134 /* Skip the NUL at the end of the table. */
5137 /* Now display the statements. */
5138 printf (_("\n Line Number Statements:\n"));
5141 while (data
< end_of_sequence
)
5143 unsigned char op_code
;
5147 op_code
= * data
++;
5151 case DW_LNS_extended_op
:
5152 data
+= process_extended_line_op (data
, info
.li_default_is_stmt
,
5153 debug_line_pointer_size
);
5157 printf (_(" Copy\n"));
5160 case DW_LNS_advance_pc
:
5161 adv
= info
.li_min_insn_length
* read_leb128 (data
, & bytes_read
, 0);
5163 state_machine_regs
.address
+= adv
;
5164 printf (_(" Advance PC by %d to %lx\n"), adv
,
5165 state_machine_regs
.address
);
5168 case DW_LNS_advance_line
:
5169 adv
= read_leb128 (data
, & bytes_read
, 1);
5171 state_machine_regs
.line
+= adv
;
5172 printf (_(" Advance Line by %d to %d\n"), adv
,
5173 state_machine_regs
.line
);
5176 case DW_LNS_set_file
:
5177 adv
= read_leb128 (data
, & bytes_read
, 0);
5179 printf (_(" Set File Name to entry %d in the File Name Table\n"),
5181 state_machine_regs
.file
= adv
;
5184 case DW_LNS_set_column
:
5185 adv
= read_leb128 (data
, & bytes_read
, 0);
5187 printf (_(" Set column to %d\n"), adv
);
5188 state_machine_regs
.column
= adv
;
5191 case DW_LNS_negate_stmt
:
5192 adv
= state_machine_regs
.is_stmt
;
5194 printf (_(" Set is_stmt to %d\n"), adv
);
5195 state_machine_regs
.is_stmt
= adv
;
5198 case DW_LNS_set_basic_block
:
5199 printf (_(" Set basic block\n"));
5200 state_machine_regs
.basic_block
= 1;
5203 case DW_LNS_const_add_pc
:
5204 adv
= (((255 - info
.li_opcode_base
) / info
.li_line_range
)
5205 * info
.li_min_insn_length
);
5206 state_machine_regs
.address
+= adv
;
5207 printf (_(" Advance PC by constant %d to 0x%lx\n"), adv
,
5208 state_machine_regs
.address
);
5211 case DW_LNS_fixed_advance_pc
:
5212 adv
= byte_get (data
, 2);
5214 state_machine_regs
.address
+= adv
;
5215 printf (_(" Advance PC by fixed size amount %d to 0x%lx\n"),
5216 adv
, state_machine_regs
.address
);
5220 op_code
-= info
.li_opcode_base
;
5221 adv
= (op_code
/ info
.li_line_range
) * info
.li_min_insn_length
;
5222 state_machine_regs
.address
+= adv
;
5223 printf (_(" Special opcode %d: advance Address by %d to 0x%lx"),
5224 op_code
, adv
, state_machine_regs
.address
);
5225 adv
= (op_code
% info
.li_line_range
) + info
.li_line_base
;
5226 state_machine_regs
.line
+= adv
;
5227 printf (_(" and Line by %d to %d\n"),
5228 adv
, state_machine_regs
.line
);
5239 display_debug_pubnames (section
, start
, file
)
5240 Elf32_Internal_Shdr
* section
;
5241 unsigned char * start
;
5242 FILE * file ATTRIBUTE_UNUSED
;
5244 DWARF2_External_PubNames
* external
;
5245 DWARF2_Internal_PubNames pubnames
;
5246 unsigned char * end
;
5248 end
= start
+ section
->sh_size
;
5250 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section
));
5254 unsigned char * data
;
5255 unsigned long offset
;
5257 external
= (DWARF2_External_PubNames
*) start
;
5259 pubnames
.pn_length
= BYTE_GET (external
->pn_length
);
5260 pubnames
.pn_version
= BYTE_GET (external
->pn_version
);
5261 pubnames
.pn_offset
= BYTE_GET (external
->pn_offset
);
5262 pubnames
.pn_size
= BYTE_GET (external
->pn_size
);
5264 data
= start
+ sizeof (* external
);
5265 start
+= pubnames
.pn_length
+ sizeof (external
->pn_length
);
5267 if (pubnames
.pn_version
!= 2)
5269 static int warned
= 0;
5273 warn (_("Only DWARF 2 pubnames are currently supported\n"));
5280 printf (_(" Length: %ld\n"),
5281 pubnames
.pn_length
);
5282 printf (_(" Version: %d\n"),
5283 pubnames
.pn_version
);
5284 printf (_(" Offset into .debug_info section: %ld\n"),
5285 pubnames
.pn_offset
);
5286 printf (_(" Size of area in .debug_info section: %ld\n"),
5289 printf (_("\n Offset\tName\n"));
5293 offset
= byte_get (data
, 4);
5298 printf (" %ld\t\t%s\n", offset
, data
);
5299 data
+= strlen ((char *) data
) + 1;
5302 while (offset
!= 0);
5315 case DW_TAG_padding
: return "DW_TAG_padding";
5316 case DW_TAG_array_type
: return "DW_TAG_array_type";
5317 case DW_TAG_class_type
: return "DW_TAG_class_type";
5318 case DW_TAG_entry_point
: return "DW_TAG_entry_point";
5319 case DW_TAG_enumeration_type
: return "DW_TAG_enumeration_type";
5320 case DW_TAG_formal_parameter
: return "DW_TAG_formal_parameter";
5321 case DW_TAG_imported_declaration
: return "DW_TAG_imported_declaration";
5322 case DW_TAG_label
: return "DW_TAG_label";
5323 case DW_TAG_lexical_block
: return "DW_TAG_lexical_block";
5324 case DW_TAG_member
: return "DW_TAG_member";
5325 case DW_TAG_pointer_type
: return "DW_TAG_pointer_type";
5326 case DW_TAG_reference_type
: return "DW_TAG_reference_type";
5327 case DW_TAG_compile_unit
: return "DW_TAG_compile_unit";
5328 case DW_TAG_string_type
: return "DW_TAG_string_type";
5329 case DW_TAG_structure_type
: return "DW_TAG_structure_type";
5330 case DW_TAG_subroutine_type
: return "DW_TAG_subroutine_type";
5331 case DW_TAG_typedef
: return "DW_TAG_typedef";
5332 case DW_TAG_union_type
: return "DW_TAG_union_type";
5333 case DW_TAG_unspecified_parameters
: return "DW_TAG_unspecified_parameters";
5334 case DW_TAG_variant
: return "DW_TAG_variant";
5335 case DW_TAG_common_block
: return "DW_TAG_common_block";
5336 case DW_TAG_common_inclusion
: return "DW_TAG_common_inclusion";
5337 case DW_TAG_inheritance
: return "DW_TAG_inheritance";
5338 case DW_TAG_inlined_subroutine
: return "DW_TAG_inlined_subroutine";
5339 case DW_TAG_module
: return "DW_TAG_module";
5340 case DW_TAG_ptr_to_member_type
: return "DW_TAG_ptr_to_member_type";
5341 case DW_TAG_set_type
: return "DW_TAG_set_type";
5342 case DW_TAG_subrange_type
: return "DW_TAG_subrange_type";
5343 case DW_TAG_with_stmt
: return "DW_TAG_with_stmt";
5344 case DW_TAG_access_declaration
: return "DW_TAG_access_declaration";
5345 case DW_TAG_base_type
: return "DW_TAG_base_type";
5346 case DW_TAG_catch_block
: return "DW_TAG_catch_block";
5347 case DW_TAG_const_type
: return "DW_TAG_const_type";
5348 case DW_TAG_constant
: return "DW_TAG_constant";
5349 case DW_TAG_enumerator
: return "DW_TAG_enumerator";
5350 case DW_TAG_file_type
: return "DW_TAG_file_type";
5351 case DW_TAG_friend
: return "DW_TAG_friend";
5352 case DW_TAG_namelist
: return "DW_TAG_namelist";
5353 case DW_TAG_namelist_item
: return "DW_TAG_namelist_item";
5354 case DW_TAG_packed_type
: return "DW_TAG_packed_type";
5355 case DW_TAG_subprogram
: return "DW_TAG_subprogram";
5356 case DW_TAG_template_type_param
: return "DW_TAG_template_type_param";
5357 case DW_TAG_template_value_param
: return "DW_TAG_template_value_param";
5358 case DW_TAG_thrown_type
: return "DW_TAG_thrown_type";
5359 case DW_TAG_try_block
: return "DW_TAG_try_block";
5360 case DW_TAG_variant_part
: return "DW_TAG_variant_part";
5361 case DW_TAG_variable
: return "DW_TAG_variable";
5362 case DW_TAG_volatile_type
: return "DW_TAG_volatile_type";
5363 case DW_TAG_MIPS_loop
: return "DW_TAG_MIPS_loop";
5364 case DW_TAG_format_label
: return "DW_TAG_format_label";
5365 case DW_TAG_function_template
: return "DW_TAG_function_template";
5366 case DW_TAG_class_template
: return "DW_TAG_class_template";
5369 static char buffer
[100];
5371 sprintf (buffer
, _("Unknown TAG value: %lx"), tag
);
5378 get_AT_name (attribute
)
5379 unsigned long attribute
;
5383 case DW_AT_sibling
: return "DW_AT_sibling";
5384 case DW_AT_location
: return "DW_AT_location";
5385 case DW_AT_name
: return "DW_AT_name";
5386 case DW_AT_ordering
: return "DW_AT_ordering";
5387 case DW_AT_subscr_data
: return "DW_AT_subscr_data";
5388 case DW_AT_byte_size
: return "DW_AT_byte_size";
5389 case DW_AT_bit_offset
: return "DW_AT_bit_offset";
5390 case DW_AT_bit_size
: return "DW_AT_bit_size";
5391 case DW_AT_element_list
: return "DW_AT_element_list";
5392 case DW_AT_stmt_list
: return "DW_AT_stmt_list";
5393 case DW_AT_low_pc
: return "DW_AT_low_pc";
5394 case DW_AT_high_pc
: return "DW_AT_high_pc";
5395 case DW_AT_language
: return "DW_AT_language";
5396 case DW_AT_member
: return "DW_AT_member";
5397 case DW_AT_discr
: return "DW_AT_discr";
5398 case DW_AT_discr_value
: return "DW_AT_discr_value";
5399 case DW_AT_visibility
: return "DW_AT_visibility";
5400 case DW_AT_import
: return "DW_AT_import";
5401 case DW_AT_string_length
: return "DW_AT_string_length";
5402 case DW_AT_common_reference
: return "DW_AT_common_reference";
5403 case DW_AT_comp_dir
: return "DW_AT_comp_dir";
5404 case DW_AT_const_value
: return "DW_AT_const_value";
5405 case DW_AT_containing_type
: return "DW_AT_containing_type";
5406 case DW_AT_default_value
: return "DW_AT_default_value";
5407 case DW_AT_inline
: return "DW_AT_inline";
5408 case DW_AT_is_optional
: return "DW_AT_is_optional";
5409 case DW_AT_lower_bound
: return "DW_AT_lower_bound";
5410 case DW_AT_producer
: return "DW_AT_producer";
5411 case DW_AT_prototyped
: return "DW_AT_prototyped";
5412 case DW_AT_return_addr
: return "DW_AT_return_addr";
5413 case DW_AT_start_scope
: return "DW_AT_start_scope";
5414 case DW_AT_stride_size
: return "DW_AT_stride_size";
5415 case DW_AT_upper_bound
: return "DW_AT_upper_bound";
5416 case DW_AT_abstract_origin
: return "DW_AT_abstract_origin";
5417 case DW_AT_accessibility
: return "DW_AT_accessibility";
5418 case DW_AT_address_class
: return "DW_AT_address_class";
5419 case DW_AT_artificial
: return "DW_AT_artificial";
5420 case DW_AT_base_types
: return "DW_AT_base_types";
5421 case DW_AT_calling_convention
: return "DW_AT_calling_convention";
5422 case DW_AT_count
: return "DW_AT_count";
5423 case DW_AT_data_member_location
: return "DW_AT_data_member_location";
5424 case DW_AT_decl_column
: return "DW_AT_decl_column";
5425 case DW_AT_decl_file
: return "DW_AT_decl_file";
5426 case DW_AT_decl_line
: return "DW_AT_decl_line";
5427 case DW_AT_declaration
: return "DW_AT_declaration";
5428 case DW_AT_discr_list
: return "DW_AT_discr_list";
5429 case DW_AT_encoding
: return "DW_AT_encoding";
5430 case DW_AT_external
: return "DW_AT_external";
5431 case DW_AT_frame_base
: return "DW_AT_frame_base";
5432 case DW_AT_friend
: return "DW_AT_friend";
5433 case DW_AT_identifier_case
: return "DW_AT_identifier_case";
5434 case DW_AT_macro_info
: return "DW_AT_macro_info";
5435 case DW_AT_namelist_items
: return "DW_AT_namelist_items";
5436 case DW_AT_priority
: return "DW_AT_priority";
5437 case DW_AT_segment
: return "DW_AT_segment";
5438 case DW_AT_specification
: return "DW_AT_specification";
5439 case DW_AT_static_link
: return "DW_AT_static_link";
5440 case DW_AT_type
: return "DW_AT_type";
5441 case DW_AT_use_location
: return "DW_AT_use_location";
5442 case DW_AT_variable_parameter
: return "DW_AT_variable_parameter";
5443 case DW_AT_virtuality
: return "DW_AT_virtuality";
5444 case DW_AT_vtable_elem_location
: return "DW_AT_vtable_elem_location";
5445 case DW_AT_MIPS_fde
: return "DW_AT_MIPS_fde";
5446 case DW_AT_MIPS_loop_begin
: return "DW_AT_MIPS_loop_begin";
5447 case DW_AT_MIPS_tail_loop_begin
: return "DW_AT_MIPS_tail_loop_begin";
5448 case DW_AT_MIPS_epilog_begin
: return "DW_AT_MIPS_epilog_begin";
5449 case DW_AT_MIPS_loop_unroll_factor
: return "DW_AT_MIPS_loop_unroll_factor";
5450 case DW_AT_MIPS_software_pipeline_depth
: return "DW_AT_MIPS_software_pipeline_depth";
5451 case DW_AT_MIPS_linkage_name
: return "DW_AT_MIPS_linkage_name";
5452 case DW_AT_MIPS_stride
: return "DW_AT_MIPS_stride";
5453 case DW_AT_MIPS_abstract_name
: return "DW_AT_MIPS_abstract_name";
5454 case DW_AT_MIPS_clone_origin
: return "DW_AT_MIPS_clone_origin";
5455 case DW_AT_MIPS_has_inlines
: return "DW_AT_MIPS_has_inlines";
5456 case DW_AT_sf_names
: return "DW_AT_sf_names";
5457 case DW_AT_src_info
: return "DW_AT_src_info";
5458 case DW_AT_mac_info
: return "DW_AT_mac_info";
5459 case DW_AT_src_coords
: return "DW_AT_src_coords";
5460 case DW_AT_body_begin
: return "DW_AT_body_begin";
5461 case DW_AT_body_end
: return "DW_AT_body_end";
5464 static char buffer
[100];
5466 sprintf (buffer
, _("Unknown AT value: %lx"), attribute
);
5473 get_FORM_name (form
)
5478 case DW_FORM_addr
: return "DW_FORM_addr";
5479 case DW_FORM_block2
: return "DW_FORM_block2";
5480 case DW_FORM_block4
: return "DW_FORM_block4";
5481 case DW_FORM_data2
: return "DW_FORM_data2";
5482 case DW_FORM_data4
: return "DW_FORM_data4";
5483 case DW_FORM_data8
: return "DW_FORM_data8";
5484 case DW_FORM_string
: return "DW_FORM_string";
5485 case DW_FORM_block
: return "DW_FORM_block";
5486 case DW_FORM_block1
: return "DW_FORM_block1";
5487 case DW_FORM_data1
: return "DW_FORM_data1";
5488 case DW_FORM_flag
: return "DW_FORM_flag";
5489 case DW_FORM_sdata
: return "DW_FORM_sdata";
5490 case DW_FORM_strp
: return "DW_FORM_strp";
5491 case DW_FORM_udata
: return "DW_FORM_udata";
5492 case DW_FORM_ref_addr
: return "DW_FORM_ref_addr";
5493 case DW_FORM_ref1
: return "DW_FORM_ref1";
5494 case DW_FORM_ref2
: return "DW_FORM_ref2";
5495 case DW_FORM_ref4
: return "DW_FORM_ref4";
5496 case DW_FORM_ref8
: return "DW_FORM_ref8";
5497 case DW_FORM_ref_udata
: return "DW_FORM_ref_udata";
5498 case DW_FORM_indirect
: return "DW_FORM_indirect";
5501 static char buffer
[100];
5503 sprintf (buffer
, _("Unknown FORM value: %lx"), form
);
5509 /* FIXME: There are better and more effiecint ways to handle
5510 these structures. For now though, I just want something that
5511 is simple to implement. */
5512 typedef struct abbrev_attr
5514 unsigned long attribute
;
5516 struct abbrev_attr
* next
;
5520 typedef struct abbrev_entry
5522 unsigned long entry
;
5525 struct abbrev_attr
* first_attr
;
5526 struct abbrev_attr
* last_attr
;
5527 struct abbrev_entry
* next
;
5531 static abbrev_entry
* first_abbrev
= NULL
;
5532 static abbrev_entry
* last_abbrev
= NULL
;
5535 free_abbrevs
PARAMS ((void))
5537 abbrev_entry
* abbrev
;
5539 for (abbrev
= first_abbrev
; abbrev
;)
5541 abbrev_entry
* next
= abbrev
->next
;
5544 for (attr
= abbrev
->first_attr
; attr
;)
5546 abbrev_attr
* next
= attr
->next
;
5556 last_abbrev
= first_abbrev
= NULL
;
5560 add_abbrev (number
, tag
, children
)
5561 unsigned long number
;
5565 abbrev_entry
* entry
;
5567 entry
= (abbrev_entry
*) malloc (sizeof (* entry
));
5573 entry
->entry
= number
;
5575 entry
->children
= children
;
5576 entry
->first_attr
= NULL
;
5577 entry
->last_attr
= NULL
;
5580 if (first_abbrev
== NULL
)
5581 first_abbrev
= entry
;
5583 last_abbrev
->next
= entry
;
5585 last_abbrev
= entry
;
5589 add_abbrev_attr (attribute
, form
)
5590 unsigned long attribute
;
5595 attr
= (abbrev_attr
*) malloc (sizeof (* attr
));
5601 attr
->attribute
= attribute
;
5605 if (last_abbrev
->first_attr
== NULL
)
5606 last_abbrev
->first_attr
= attr
;
5608 last_abbrev
->last_attr
->next
= attr
;
5610 last_abbrev
->last_attr
= attr
;
5613 /* Processes the (partial) contents of a .debug_abbrev section.
5614 Returns NULL if the end of the section was encountered.
5615 Returns the address after the last byte read if the end of
5616 an abbreviation set was found. */
5618 static unsigned char *
5619 process_abbrev_section (start
, end
)
5620 unsigned char * start
;
5621 unsigned char * end
;
5623 if (first_abbrev
!= NULL
)
5629 unsigned long entry
;
5631 unsigned long attribute
;
5634 entry
= read_leb128 (start
, & bytes_read
, 0);
5635 start
+= bytes_read
;
5637 /* A single zero is supposed to end the section according
5638 to the standard. If there's more, then signal that to
5641 return start
== end
? NULL
: start
;
5643 tag
= read_leb128 (start
, & bytes_read
, 0);
5644 start
+= bytes_read
;
5646 children
= * start
++;
5648 add_abbrev (entry
, tag
, children
);
5654 attribute
= read_leb128 (start
, & bytes_read
, 0);
5655 start
+= bytes_read
;
5657 form
= read_leb128 (start
, & bytes_read
, 0);
5658 start
+= bytes_read
;
5661 add_abbrev_attr (attribute
, form
);
5663 while (attribute
!= 0);
5671 display_debug_abbrev (section
, start
, file
)
5672 Elf32_Internal_Shdr
* section
;
5673 unsigned char * start
;
5674 FILE * file ATTRIBUTE_UNUSED
;
5676 abbrev_entry
* entry
;
5677 unsigned char * end
= start
+ section
->sh_size
;
5679 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section
));
5683 start
= process_abbrev_section (start
, end
);
5685 printf (_(" Number TAG\n"));
5687 for (entry
= first_abbrev
; entry
; entry
= entry
->next
)
5691 printf (_(" %ld %s [%s]\n"),
5693 get_TAG_name (entry
->tag
),
5694 entry
->children
? _("has children") : _("no children"));
5696 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
5698 printf (_(" %-18s %s\n"),
5699 get_AT_name (attr
->attribute
),
5700 get_FORM_name (attr
->form
));
5712 static unsigned char *
5713 display_block (data
, length
)
5714 unsigned char * data
;
5715 unsigned long length
;
5717 printf (_(" %lu byte block: "), length
);
5720 printf ("%lx ", (unsigned long) byte_get (data
++, 1));
5726 decode_location_expression (data
, pointer_size
, length
)
5727 unsigned char * data
;
5728 unsigned int pointer_size
;
5729 unsigned long length
;
5733 unsigned long uvalue
;
5734 unsigned char *end
= data
+ length
;
5743 printf ("DW_OP_addr: %lx",
5744 (unsigned long) byte_get (data
, pointer_size
));
5745 data
+= pointer_size
;
5748 printf ("DW_OP_deref");
5751 printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data
++, 1));
5754 printf ("DW_OP_const1s: %ld", (long) byte_get (data
++, 1));
5757 printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data
, 2));
5761 printf ("DW_OP_const2s: %ld", (long) byte_get (data
, 2));
5765 printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data
, 4));
5769 printf ("DW_OP_const4s: %ld", (long) byte_get (data
, 4));
5773 printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data
, 4),
5774 (unsigned long) byte_get (data
+ 4, 4));
5778 printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data
, 4),
5779 (long) byte_get (data
+ 4, 4));
5783 printf ("DW_OP_constu: %lu", read_leb128 (data
, &bytes_read
, 0));
5787 printf ("DW_OP_consts: %ld", read_leb128 (data
, &bytes_read
, 1));
5791 printf ("DW_OP_dup");
5794 printf ("DW_OP_drop");
5797 printf ("DW_OP_over");
5800 printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data
++, 1));
5803 printf ("DW_OP_swap");
5806 printf ("DW_OP_rot");
5809 printf ("DW_OP_xderef");
5812 printf ("DW_OP_abs");
5815 printf ("DW_OP_and");
5818 printf ("DW_OP_div");
5821 printf ("DW_OP_minus");
5824 printf ("DW_OP_mod");
5827 printf ("DW_OP_mul");
5830 printf ("DW_OP_neg");
5833 printf ("DW_OP_not");
5836 printf ("DW_OP_or");
5839 printf ("DW_OP_plus");
5841 case DW_OP_plus_uconst
:
5842 printf ("DW_OP_plus_uconst: %lu",
5843 read_leb128 (data
, &bytes_read
, 0));
5847 printf ("DW_OP_shl");
5850 printf ("DW_OP_shr");
5853 printf ("DW_OP_shra");
5856 printf ("DW_OP_xor");
5859 printf ("DW_OP_bra: %ld", (long) byte_get (data
, 2));
5863 printf ("DW_OP_eq");
5866 printf ("DW_OP_ge");
5869 printf ("DW_OP_gt");
5872 printf ("DW_OP_le");
5875 printf ("DW_OP_lt");
5878 printf ("DW_OP_ne");
5881 printf ("DW_OP_skip: %ld", (long) byte_get (data
, 2));
5917 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
5952 printf ("DW_OP_reg%d", op
- DW_OP_reg0
);
5987 printf ("DW_OP_breg%d: %ld", op
- DW_OP_breg0
,
5988 read_leb128 (data
, &bytes_read
, 1));
5993 printf ("DW_OP_regx: %lu", read_leb128 (data
, &bytes_read
, 0));
5997 printf ("DW_OP_fbreg: %ld", read_leb128 (data
, &bytes_read
, 1));
6001 uvalue
= read_leb128 (data
, &bytes_read
, 0);
6003 printf ("DW_OP_bregx: %lu %ld", uvalue
,
6004 read_leb128 (data
, &bytes_read
, 1));
6008 printf ("DW_OP_piece: %lu", read_leb128 (data
, &bytes_read
, 0));
6011 case DW_OP_deref_size
:
6012 printf ("DW_OP_deref_size: %ld", (long) byte_get (data
++, 1));
6014 case DW_OP_xderef_size
:
6015 printf ("DW_OP_xderef_size: %ld", (long) byte_get (data
++, 1));
6018 printf ("DW_OP_nop");
6022 if (op
>= DW_OP_lo_user
6023 && op
<= DW_OP_hi_user
)
6024 printf (_("(User defined location op)"));
6026 printf (_("(Unknown location op)"));
6027 /* No way to tell where the next op is, so just bail. */
6034 static unsigned char *
6035 read_and_display_attr (attribute
, form
, data
, cu_offset
, pointer_size
)
6036 unsigned long attribute
;
6038 unsigned char * data
;
6039 unsigned long cu_offset
;
6040 unsigned long pointer_size
;
6042 unsigned long uvalue
= 0;
6043 unsigned char * block_start
= NULL
;
6046 printf (" %-18s:", get_AT_name (attribute
));
6053 case DW_FORM_ref_addr
:
6055 uvalue
= byte_get (data
, pointer_size
);
6056 data
+= pointer_size
;
6062 uvalue
= byte_get (data
++, 1);
6067 uvalue
= byte_get (data
, 2);
6073 uvalue
= byte_get (data
, 4);
6078 uvalue
= read_leb128 (data
, & bytes_read
, 1);
6082 case DW_FORM_ref_udata
:
6084 uvalue
= read_leb128 (data
, & bytes_read
, 0);
6091 case DW_FORM_ref_addr
:
6092 printf (" <#%lx>", uvalue
);
6098 case DW_FORM_ref_udata
:
6099 printf (" <%lx>", uvalue
+ cu_offset
);
6103 printf (" %#lx", uvalue
);
6111 printf (" %ld", uvalue
);
6116 uvalue
= byte_get (data
, 4);
6117 printf (" %lx", uvalue
);
6118 printf (" %lx", (unsigned long) byte_get (data
+ 4, 4));
6122 case DW_FORM_string
:
6123 printf (" %s", data
);
6124 data
+= strlen ((char *) data
) + 1;
6128 uvalue
= read_leb128 (data
, & bytes_read
, 0);
6129 block_start
= data
+ bytes_read
;
6130 data
= display_block (block_start
, uvalue
);
6133 case DW_FORM_block1
:
6134 uvalue
= byte_get (data
, 1);
6135 block_start
= data
+ 1;
6136 data
= display_block (block_start
, uvalue
);
6139 case DW_FORM_block2
:
6140 uvalue
= byte_get (data
, 2);
6141 block_start
= data
+ 2;
6142 data
= display_block (block_start
, uvalue
);
6145 case DW_FORM_block4
:
6146 uvalue
= byte_get (data
, 4);
6147 block_start
= data
+ 4;
6148 data
= display_block (block_start
, uvalue
);
6152 case DW_FORM_indirect
:
6153 warn (_("Unable to handle FORM: %d"), form
);
6157 warn (_("Unrecognised form: %d"), form
);
6161 /* For some attributes we can display futher information. */
6170 case DW_INL_not_inlined
: printf (_("(not inlined)")); break;
6171 case DW_INL_inlined
: printf (_("(inlined)")); break;
6172 case DW_INL_declared_not_inlined
: printf (_("(declared as inline but ignored)")); break;
6173 case DW_INL_declared_inlined
: printf (_("(declared as inline and inlined)")); break;
6174 default: printf (_(" (Unknown inline attribute value: %lx)"), uvalue
); break;
6178 case DW_AT_language
:
6181 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
6182 case DW_LANG_C89
: printf ("(ANSI C)"); break;
6183 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
6184 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
6185 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
6186 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
6187 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
6188 case DW_LANG_Ada83
: printf ("(Ada)"); break;
6189 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
6190 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
6191 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
6192 default: printf ("(Unknown: %lx)", uvalue
); break;
6196 case DW_AT_encoding
:
6199 case DW_ATE_void
: printf ("(void)"); break;
6200 case DW_ATE_address
: printf ("(machine address)"); break;
6201 case DW_ATE_boolean
: printf ("(boolean)"); break;
6202 case DW_ATE_complex_float
: printf ("(complex float)"); break;
6203 case DW_ATE_float
: printf ("(float)"); break;
6204 case DW_ATE_signed
: printf ("(signed)"); break;
6205 case DW_ATE_signed_char
: printf ("(signed char)"); break;
6206 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
6207 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
6209 if (uvalue
>= DW_ATE_lo_user
6210 && uvalue
<= DW_ATE_hi_user
)
6211 printf ("(user defined type)");
6213 printf ("(unknown type)");
6218 case DW_AT_accessibility
:
6221 case DW_ACCESS_public
: printf ("(public)"); break;
6222 case DW_ACCESS_protected
: printf ("(protected)"); break;
6223 case DW_ACCESS_private
: printf ("(private)"); break;
6224 default: printf ("(unknown accessibility)"); break;
6228 case DW_AT_visibility
:
6231 case DW_VIS_local
: printf ("(local)"); break;
6232 case DW_VIS_exported
: printf ("(exported)"); break;
6233 case DW_VIS_qualified
: printf ("(qualified)"); break;
6234 default: printf ("(unknown visibility)"); break;
6238 case DW_AT_virtuality
:
6241 case DW_VIRTUALITY_none
: printf ("(none)"); break;
6242 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
6243 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
6244 default: printf ("(unknown virtuality)"); break;
6248 case DW_AT_identifier_case
:
6251 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
6252 case DW_ID_up_case
: printf ("(up_case)"); break;
6253 case DW_ID_down_case
: printf ("(down_case)"); break;
6254 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
6255 default: printf ("(unknown case)"); break;
6259 case DW_AT_calling_convention
:
6262 case DW_CC_normal
: printf ("(normal)"); break;
6263 case DW_CC_program
: printf ("(program)"); break;
6264 case DW_CC_nocall
: printf ("(nocall)"); break;
6266 if (uvalue
>= DW_CC_lo_user
6267 && uvalue
<= DW_CC_hi_user
)
6268 printf ("(user defined)");
6270 printf ("(unknown convention)");
6274 case DW_AT_frame_base
:
6275 case DW_AT_location
:
6276 case DW_AT_data_member_location
:
6277 case DW_AT_vtable_elem_location
:
6281 decode_location_expression (block_start
, pointer_size
, uvalue
);
6295 display_debug_info (section
, start
, file
)
6296 Elf32_Internal_Shdr
* section
;
6297 unsigned char * start
;
6300 unsigned char * end
= start
+ section
->sh_size
;
6301 unsigned char * section_begin
= start
;
6303 printf (_("The section %s contains:\n\n"), SECTION_NAME (section
));
6307 DWARF2_External_CompUnit
* external
;
6308 DWARF2_Internal_CompUnit compunit
;
6309 unsigned char * tags
;
6312 unsigned long cu_offset
;
6314 external
= (DWARF2_External_CompUnit
*) start
;
6316 compunit
.cu_length
= BYTE_GET (external
->cu_length
);
6317 compunit
.cu_version
= BYTE_GET (external
->cu_version
);
6318 compunit
.cu_abbrev_offset
= BYTE_GET (external
->cu_abbrev_offset
);
6319 compunit
.cu_pointer_size
= BYTE_GET (external
->cu_pointer_size
);
6321 tags
= start
+ sizeof (* external
);
6322 cu_offset
= start
- section_begin
;
6323 start
+= compunit
.cu_length
+ sizeof (external
->cu_length
);
6325 if (compunit
.cu_version
!= 2)
6327 warn (_("Only version 2 DWARF debug information is currently supported.\n"));
6331 printf (_(" Compilation Unit:\n"));
6332 printf (_(" Length: %ld\n"), compunit
.cu_length
);
6333 printf (_(" Version: %d\n"), compunit
.cu_version
);
6334 printf (_(" Abbrev Offset: %ld\n"), compunit
.cu_abbrev_offset
);
6335 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
6337 if (first_abbrev
!= NULL
)
6340 /* Read in the abbrevs used by this compilation unit. */
6343 Elf32_Internal_Shdr
* sec
;
6344 unsigned char * begin
;
6346 /* Locate the .debug_abbrev section and process it. */
6347 for (i
= 0, sec
= section_headers
;
6348 i
< elf_header
.e_shnum
;
6350 if (strcmp (SECTION_NAME (sec
), ".debug_abbrev") == 0)
6353 if (i
== -1 || sec
->sh_size
== 0)
6355 warn (_("Unable to locate .debug_abbrev section!\n"));
6359 GET_DATA_ALLOC (sec
->sh_offset
, sec
->sh_size
, begin
, unsigned char *,
6360 "debug_abbrev section data");
6362 process_abbrev_section (begin
+ compunit
.cu_abbrev_offset
,
6363 begin
+ sec
->sh_size
);
6369 while (tags
< start
)
6372 unsigned long abbrev_number
;
6373 abbrev_entry
* entry
;
6376 abbrev_number
= read_leb128 (tags
, & bytes_read
, 0);
6379 /* A null DIE marks the end of a list of children. */
6380 if (abbrev_number
== 0)
6386 /* Scan through the abbreviation list until we reach the
6388 for (entry
= first_abbrev
;
6389 entry
&& entry
->entry
!= abbrev_number
;
6390 entry
= entry
->next
)
6395 warn (_("Unable to locate entry %lu in the abbreviation table\n"),
6400 printf (_(" <%d><%x>: Abbrev Number: %lu (%s)\n"),
6401 level
, tags
- section_begin
- bytes_read
,
6403 get_TAG_name (entry
->tag
));
6405 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
6406 tags
= read_and_display_attr (attr
->attribute
,
6409 compunit
.cu_pointer_size
);
6411 if (entry
->children
)
6422 display_debug_aranges (section
, start
, file
)
6423 Elf32_Internal_Shdr
* section
;
6424 unsigned char * start
;
6425 FILE * file ATTRIBUTE_UNUSED
;
6427 unsigned char * end
= start
+ section
->sh_size
;
6429 printf (_("The section %s contains:\n\n"), SECTION_NAME (section
));
6433 DWARF2_External_ARange
* external
;
6434 DWARF2_Internal_ARange arange
;
6435 unsigned char * ranges
;
6436 unsigned long length
;
6437 unsigned long address
;
6440 external
= (DWARF2_External_ARange
*) start
;
6442 arange
.ar_length
= BYTE_GET (external
->ar_length
);
6443 arange
.ar_version
= BYTE_GET (external
->ar_version
);
6444 arange
.ar_info_offset
= BYTE_GET (external
->ar_info_offset
);
6445 arange
.ar_pointer_size
= BYTE_GET (external
->ar_pointer_size
);
6446 arange
.ar_segment_size
= BYTE_GET (external
->ar_segment_size
);
6448 if (arange
.ar_version
!= 2)
6450 warn (_("Only DWARF 2 aranges are currently supported.\n"));
6454 printf (_(" Length: %ld\n"), arange
.ar_length
);
6455 printf (_(" Version: %d\n"), arange
.ar_version
);
6456 printf (_(" Offset into .debug_info: %lx\n"), arange
.ar_info_offset
);
6457 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
6458 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
6460 printf (_("\n Address Length\n"));
6462 ranges
= start
+ sizeof (* external
);
6464 /* Must pad to an alignment boundary that is twice the pointer size. */
6465 excess
= sizeof (*external
) % (2 * arange
.ar_pointer_size
);
6467 ranges
+= (2 * arange
.ar_pointer_size
) - excess
;
6471 address
= byte_get (ranges
, arange
.ar_pointer_size
);
6473 ranges
+= arange
.ar_pointer_size
;
6475 length
= byte_get (ranges
, arange
.ar_pointer_size
);
6477 ranges
+= arange
.ar_pointer_size
;
6479 /* A pair of zeros marks the end of the list. */
6480 if (address
== 0 && length
== 0)
6483 printf (" %8.8lx %lu\n", address
, length
);
6486 start
+= arange
.ar_length
+ sizeof (external
->ar_length
);
6494 typedef struct Frame_Chunk
6496 struct Frame_Chunk
*next
;
6497 unsigned char *chunk_start
;
6499 /* DW_CFA_{undefined,same_value,offset,register} */
6500 unsigned char *col_type
;
6503 unsigned int code_factor
;
6504 unsigned int data_factor
;
6505 unsigned long pc_begin
;
6506 unsigned long pc_range
;
6514 frame_need_space (fc
, reg
)
6518 int prev
= fc
->ncols
;
6520 if (reg
< fc
->ncols
)
6522 fc
->ncols
= reg
+ 1;
6523 fc
->col_type
= (unsigned char *) xrealloc (fc
->col_type
,
6524 fc
->ncols
* sizeof (unsigned char));
6525 fc
->col_offset
= (int *) xrealloc (fc
->col_offset
,
6526 fc
->ncols
* sizeof (int));
6528 while (prev
< fc
->ncols
)
6530 fc
->col_type
[prev
] = DW_CFA_undefined
;
6531 fc
->col_offset
[prev
] = 0;
6537 frame_display_row (fc
, need_col_headers
, max_regs
)
6539 int *need_col_headers
;
6545 if (*max_regs
< fc
->ncols
)
6546 *max_regs
= fc
->ncols
;
6547 if (*need_col_headers
)
6549 *need_col_headers
= 0;
6550 printf (" LOC CFA ");
6551 for (r
=0; r
<*max_regs
; r
++)
6555 printf ("r%-4d", r
);
6558 printf ("%08x ", (unsigned int) fc
->pc_begin
);
6559 sprintf (tmp
, "r%d%+d", fc
->cfa_reg
, fc
->cfa_offset
);
6560 printf ("%-8s ", tmp
);
6561 for (r
=0; r
<fc
->ncols
; r
++)
6563 switch (fc
->col_type
[r
])
6565 case DW_CFA_undefined
:
6568 case DW_CFA_same_value
:
6572 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
6574 case DW_CFA_register
:
6575 sprintf (tmp
, "r%d", fc
->col_offset
[r
]);
6578 strcpy (tmp
, "n/a");
6581 printf ("%-5s", tmp
);
6586 #define GET(N) byte_get (start, N); start += N
6587 #define LEB() read_leb128 (start, &length_return, 0); start += length_return
6588 #define SLEB() read_leb128 (start, &length_return, 1); start += length_return
6591 display_debug_frames (section
, start
, file
)
6592 Elf32_Internal_Shdr
* section
;
6593 unsigned char * start
;
6594 FILE * file ATTRIBUTE_UNUSED
;
6596 unsigned char * end
= start
+ section
->sh_size
;
6597 unsigned char *section_start
= start
;
6598 Frame_Chunk
*chunks
= 0;
6599 Frame_Chunk
*remembered_state
= 0, *rs
;
6600 int is_eh
= (strcmp (SECTION_NAME (section
), ".eh_frame") == 0);
6604 printf (_("The section %s contains:\n"), SECTION_NAME (section
));
6608 unsigned char *saved_start
, *block_end
;
6609 unsigned long length
, cie_id
;
6610 Frame_Chunk
*fc
, *cie
;
6611 int need_col_headers
= 1;
6613 saved_start
= start
;
6614 length
= byte_get (start
, 4); start
+= 4;
6619 block_end
= saved_start
+ length
+ 4;
6620 cie_id
= byte_get (start
, 4); start
+= 4;
6622 printf ("\n%08x %08lx %08lx ", saved_start
- section_start
, length
, cie_id
);
6624 if (is_eh
? (cie_id
== 0) : (cie_id
== DW_CIE_ID
))
6626 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
6627 memset (fc
, 0, sizeof (Frame_Chunk
));
6631 fc
->chunk_start
= saved_start
;
6633 fc
->col_type
= (unsigned char *) xmalloc (sizeof (unsigned char));
6634 fc
->col_offset
= (int *) xmalloc (sizeof (int));
6635 frame_need_space (fc
, max_regs
-1);
6637 start
++; /* version */
6638 fc
->augmentation
= start
;
6639 while (*start
) start
++; start
++; /* skip past NUL */
6640 if (fc
->augmentation
[0] == 'z')
6643 fc
->code_factor
= LEB ();
6644 fc
->data_factor
= SLEB ();
6645 fc
->ra
= byte_get (start
, 1); start
+= 1;
6647 printf ("skipping %d extra bytes\n", xtra
);
6650 else if (strcmp (fc
->augmentation
, "eh") == 0)
6653 fc
->code_factor
= LEB ();
6654 fc
->data_factor
= SLEB ();
6655 fc
->ra
= byte_get (start
, 1); start
+= 1;
6659 fc
->code_factor
= LEB ();
6660 fc
->data_factor
= SLEB ();
6661 fc
->ra
= byte_get (start
, 1); start
+= 1;
6664 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n",
6665 fc
->augmentation
, fc
->code_factor
, fc
->data_factor
, fc
->ra
);
6667 frame_need_space (fc
, fc
->ra
);
6671 unsigned char *look_for
;
6672 static Frame_Chunk fde_fc
;
6674 memset (fc
, 0, sizeof (Frame_Chunk
));
6676 look_for
= is_eh
? start
-4-cie_id
: (unsigned char *) cie_id
;
6678 fc
->pc_begin
= byte_get (start
, 4); start
+= 4;
6679 fc
->pc_range
= byte_get (start
, 4); start
+= 4;
6681 for (cie
=chunks
; cie
&& (cie
->chunk_start
!= look_for
); cie
= cie
->next
);
6684 warn ("Invalid CIE pointer %08x in FDE at %08x\n", cie_id
, saved_start
);
6687 fc
->col_type
= (unsigned char *) xmalloc (sizeof (unsigned char));
6688 fc
->col_offset
= (int *) xmalloc (sizeof (int));
6689 frame_need_space (fc
, max_regs
-1);
6691 fc
->augmentation
= "";
6695 fc
->ncols
= cie
->ncols
;
6696 fc
->col_type
= (unsigned char *) xmalloc (fc
->ncols
* sizeof (unsigned char));
6697 fc
->col_offset
= (int *) xmalloc (fc
->ncols
* sizeof (int));
6698 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
);
6699 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
6700 fc
->augmentation
= cie
->augmentation
;
6701 fc
->code_factor
= cie
->code_factor
;
6702 fc
->data_factor
= cie
->data_factor
;
6703 fc
->cfa_reg
= cie
->cfa_reg
;
6704 fc
->cfa_offset
= cie
->cfa_offset
;
6706 frame_need_space (fc
, max_regs
-1);
6709 if (cie
->augmentation
[0] == 'z')
6711 unsigned long l
= LEB ();
6715 printf ("FDE cie=%08x pc=%08lx..%08lx\n",
6716 cie
->chunk_start
-section_start
, fc
->pc_begin
,
6717 fc
->pc_begin
+ fc
->pc_range
);
6720 /* At this point, fc is the current chunk, cie (if any) is set, and we're
6721 about to interpret instructions for the chunk. */
6723 /* This exists for readelf maintainers. */
6726 while (start
< block_end
)
6729 unsigned long ul
, reg
, roffs
;
6740 case DW_CFA_advance_loc
:
6741 frame_display_row (fc
, &need_col_headers
, &max_regs
);
6743 printf (" DW_CFA_advance_loc: %08x = %08x + %d*%d\n",
6744 fc
->pc_begin
+ opa
* fc
->code_factor
, fc
->pc_begin
, opa
, fc
->code_factor
);
6746 fc
->pc_begin
+= opa
* fc
->code_factor
;
6750 frame_need_space (fc
, opa
);
6753 printf (" DW_CFA_offset: r%d = cfa[%d*%d]\n", opa
, roffs
, fc
->data_factor
);
6755 fc
->col_type
[opa
] = DW_CFA_offset
;
6756 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
6759 case DW_CFA_restore
:
6760 frame_need_space (fc
, opa
);
6762 printf (" DW_CFA_restore: r%d\n", opa
);
6764 fc
->col_type
[opa
] = cie
->col_type
[opa
];
6765 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
6768 case DW_CFA_set_loc
:
6769 frame_display_row (fc
, &need_col_headers
, &max_regs
);
6770 vma
= byte_get (start
, sizeof (vma
)); start
+= sizeof (vma
);
6772 printf (" DW_CFA_set_loc: %08x\n", vma
);
6777 case DW_CFA_advance_loc1
:
6778 frame_display_row (fc
, &need_col_headers
, &max_regs
);
6779 ofs
= byte_get (start
, 1); start
+= 1;
6781 printf (" DW_CFA_advance_loc1: %08x = %08x + %d*%d\n",
6782 fc
->pc_begin
+ ofs
* fc
->code_factor
, fc
->pc_begin
, ofs
, fc
->code_factor
);
6784 fc
->pc_begin
+= ofs
* fc
->code_factor
;
6787 case DW_CFA_advance_loc2
:
6788 frame_display_row (fc
, &need_col_headers
, &max_regs
);
6789 ofs
= byte_get (start
, 2); start
+= 2;
6791 printf (" DW_CFA_advance_loc2: %08x = %08x + %d*%d\n",
6792 fc
->pc_begin
+ ofs
* fc
->code_factor
, fc
->pc_begin
, ofs
, fc
->code_factor
);
6794 fc
->pc_begin
+= ofs
* fc
->code_factor
;
6797 case DW_CFA_advance_loc4
:
6798 frame_display_row (fc
, &need_col_headers
, &max_regs
);
6799 ofs
= byte_get (start
, 4); start
+= 4;
6801 printf (" DW_CFA_advance_loc4: %08x = %08x + %d*%d\n",
6802 fc
->pc_begin
+ ofs
* fc
->code_factor
, fc
->pc_begin
, ofs
, fc
->code_factor
);
6804 fc
->pc_begin
+= ofs
* fc
->code_factor
;
6807 case DW_CFA_offset_extended
:
6810 frame_need_space (fc
, reg
);
6812 printf (" DW_CFA_offset_extended: r%d = cfa[%d*%d]\n", reg
, roffs
, fc
->data_factor
);
6814 fc
->col_type
[reg
] = DW_CFA_offset
;
6815 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
6818 case DW_CFA_restore_extended
:
6820 frame_need_space (fc
, reg
);
6822 printf (" DW_CFA_restore_extended: r%d\n", reg
);
6824 fc
->col_type
[reg
] = cie
->col_type
[reg
];
6825 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
6828 case DW_CFA_undefined
:
6830 frame_need_space (fc
, reg
);
6832 printf (" DW_CFA_undefined: r%d\n", reg
);
6834 fc
->col_type
[reg
] = DW_CFA_undefined
;
6835 fc
->col_offset
[reg
] = 0;
6838 case DW_CFA_same_value
:
6840 frame_need_space (fc
, reg
);
6842 printf (" DW_CFA_same_value: r%d\n", reg
);
6844 fc
->col_type
[reg
] = DW_CFA_same_value
;
6845 fc
->col_offset
[reg
] = 0;
6848 case DW_CFA_register
:
6851 frame_need_space (fc
, reg
);
6853 printf (" DW_CFA_ame_value: r%d\n", reg
);
6855 fc
->col_type
[reg
] = DW_CFA_register
;
6856 fc
->col_offset
[reg
] = roffs
;
6859 case DW_CFA_remember_state
:
6861 printf (" DW_CFA_remember_state\n");
6863 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
6864 rs
->ncols
= fc
->ncols
;
6865 rs
->col_type
= (unsigned char *) xmalloc (rs
->ncols
);
6866 rs
->col_offset
= (int *) xmalloc (rs
->ncols
* sizeof (int));
6867 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
);
6868 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (int));
6869 rs
->next
= remembered_state
;
6870 remembered_state
= rs
;
6873 case DW_CFA_restore_state
:
6875 printf (" DW_CFA_restore_state\n");
6877 rs
= remembered_state
;
6878 remembered_state
= rs
->next
;
6879 frame_need_space (fc
, rs
->ncols
-1);
6880 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
);
6881 memcpy (fc
->col_offset
, rs
->col_offset
, rs
->ncols
* sizeof (int));
6882 free (rs
->col_type
);
6883 free (rs
->col_offset
);
6887 case DW_CFA_def_cfa
:
6888 fc
->cfa_reg
= LEB ();
6889 fc
->cfa_offset
= LEB ();
6891 printf (" DW_CFA_def_cfa: reg %d ofs %d\n", fc
->cfa_reg
, fc
->cfa_offset
);
6895 case DW_CFA_def_cfa_register
:
6896 fc
->cfa_reg
= LEB ();
6898 printf (" DW_CFA_def_cfa_reg: %d\n", fc
->cfa_reg
);
6902 case DW_CFA_def_cfa_offset
:
6903 fc
->cfa_offset
= LEB ();
6905 printf (" DW_CFA_def_cfa_offset: %d\n", fc
->cfa_offset
);
6911 printf (" DW_CFA_nop\n");
6915 #ifndef DW_CFA_GNU_window_save
6916 #define DW_CFA_GNU_window_save 0x2d
6918 case DW_CFA_GNU_window_save
:
6920 printf (" DW_CFA_GNU_window_save\n");
6924 #ifndef DW_CFA_GNU_args_size
6925 #define DW_CFA_GNU_args_size 0x2e
6927 case DW_CFA_GNU_args_size
:
6930 printf (" DW_CFA_GNU_args_size: %d\n", ul
);
6934 #ifndef DW_CFA_GNU_negative_offset_extended
6935 #define DW_CFA_GNU_negative_offset_extended 0x2f
6937 case DW_CFA_GNU_negative_offset_extended
:
6940 frame_need_space (fc
, reg
);
6942 printf (" DW_CFA_GNU_negative_offset_extended: r%d = cfa[%d*%d]\n", reg
, l
, fc
->data_factor
);
6944 fc
->col_type
[reg
] = DW_CFA_offset
;
6945 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
6949 fprintf (stderr
, "unsupported or unknown DW_CFA_%d\n", op
);
6954 frame_display_row (fc
, &need_col_headers
, &max_regs
);
6969 display_debug_not_supported (section
, start
, file
)
6970 Elf32_Internal_Shdr
* section
;
6971 unsigned char * start ATTRIBUTE_UNUSED
;
6972 FILE * file ATTRIBUTE_UNUSED
;
6974 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
6975 SECTION_NAME (section
));
6980 /* Pre-scan the .debug_info section to record the size of address.
6981 When dumping the .debug_line, we use that size information, assuming
6982 that all compilation units have the same address size. */
6984 prescan_debug_info (section
, start
, file
)
6985 Elf32_Internal_Shdr
* section ATTRIBUTE_UNUSED
;
6986 unsigned char * start
;
6987 FILE * file ATTRIBUTE_UNUSED
;
6989 DWARF2_External_CompUnit
* external
;
6991 external
= (DWARF2_External_CompUnit
*) start
;
6993 debug_line_pointer_size
= BYTE_GET (external
->cu_pointer_size
);
6997 /* A structure containing the name of a debug section and a pointer
6998 to a function that can decode it. The third field is a prescan
6999 function to be run over the section before displaying any of the
7004 int (* display
) PARAMS ((Elf32_Internal_Shdr
*, unsigned char *, FILE *));
7005 int (* prescan
) PARAMS ((Elf32_Internal_Shdr
*, unsigned char *, FILE *));
7009 { ".debug_info", display_debug_info
, prescan_debug_info
},
7010 { ".debug_abbrev", display_debug_abbrev
, NULL
},
7011 { ".debug_line", display_debug_lines
, NULL
},
7012 { ".debug_aranges", display_debug_aranges
, NULL
},
7013 { ".debug_pubnames", display_debug_pubnames
, NULL
},
7014 { ".debug_frame", display_debug_frames
, NULL
},
7015 { ".eh_frame", display_debug_frames
, NULL
},
7016 { ".debug_macinfo", display_debug_not_supported
, NULL
},
7017 { ".debug_frame", display_debug_not_supported
, NULL
},
7018 { ".debug_str", display_debug_not_supported
, NULL
},
7019 { ".debug_static_func", display_debug_not_supported
, NULL
},
7020 { ".debug_static_vars", display_debug_not_supported
, NULL
},
7021 { ".debug_types", display_debug_not_supported
, NULL
},
7022 { ".debug_weaknames", display_debug_not_supported
, NULL
}
7026 display_debug_section (section
, file
)
7027 Elf32_Internal_Shdr
* section
;
7030 char * name
= SECTION_NAME (section
);
7031 bfd_size_type length
;
7032 unsigned char * start
;
7035 length
= section
->sh_size
;
7038 printf (_("\nSection '%s' has no debugging data.\n"), name
);
7042 GET_DATA_ALLOC (section
->sh_offset
, length
, start
, unsigned char *,
7043 "debug section data");
7045 /* See if we know how to display the contents of this section. */
7046 for (i
= NUM_ELEM (debug_displays
); i
--;)
7047 if (strcmp (debug_displays
[i
].name
, name
) == 0)
7049 debug_displays
[i
].display (section
, start
, file
);
7054 printf (_("Unrecognised debug section: %s\n"), name
);
7058 /* If we loaded in the abbrev section at some point,
7059 we must release it here. */
7060 if (first_abbrev
!= NULL
)
7067 process_section_contents (file
)
7070 Elf32_Internal_Shdr
* section
;
7076 /* Pre-scan the debug sections to find some debug information not
7077 present in some of them. For the .debug_line, we must find out the
7078 size of address (specified in .debug_info and .debug_aranges). */
7079 for (i
= 0, section
= section_headers
;
7080 i
< elf_header
.e_shnum
&& i
< num_dump_sects
;
7083 char * name
= SECTION_NAME (section
);
7086 if (section
->sh_size
== 0)
7089 /* See if there is some pre-scan operation for this section. */
7090 for (j
= NUM_ELEM (debug_displays
); j
--;)
7091 if (strcmp (debug_displays
[j
].name
, name
) == 0)
7093 if (debug_displays
[j
].prescan
!= NULL
)
7095 bfd_size_type length
;
7096 unsigned char * start
;
7098 length
= section
->sh_size
;
7099 GET_DATA_ALLOC (section
->sh_offset
, length
, start
, unsigned char *,
7100 "debug section data");
7102 debug_displays
[j
].prescan (section
, start
, file
);
7110 for (i
= 0, section
= section_headers
;
7111 i
< elf_header
.e_shnum
&& i
< num_dump_sects
;
7114 #ifdef SUPPORT_DISASSEMBLY
7115 if (dump_sects
[i
] & DISASS_DUMP
)
7116 disassemble_section (section
, file
);
7118 if (dump_sects
[i
] & HEX_DUMP
)
7119 dump_section (section
, file
);
7121 if (dump_sects
[i
] & DEBUG_DUMP
)
7122 display_debug_section (section
, file
);
7125 if (i
< num_dump_sects
)
7126 warn (_("Some sections were not dumped because they do not exist!\n"));
7132 process_mips_fpe_exception (mask
)
7138 if (mask
& OEX_FPU_INEX
)
7139 fputs ("INEX", stdout
), first
= 0;
7140 if (mask
& OEX_FPU_UFLO
)
7141 printf ("%sUFLO", first
? "" : "|"), first
= 0;
7142 if (mask
& OEX_FPU_OFLO
)
7143 printf ("%sOFLO", first
? "" : "|"), first
= 0;
7144 if (mask
& OEX_FPU_DIV0
)
7145 printf ("%sDIV0", first
? "" : "|"), first
= 0;
7146 if (mask
& OEX_FPU_INVAL
)
7147 printf ("%sINVAL", first
? "" : "|");
7150 fputs ("0", stdout
);
7154 process_mips_specific (file
)
7157 Elf_Internal_Dyn
* entry
;
7158 size_t liblist_offset
= 0;
7159 size_t liblistno
= 0;
7160 size_t conflictsno
= 0;
7161 size_t options_offset
= 0;
7162 size_t conflicts_offset
= 0;
7164 /* We have a lot of special sections. Thanks SGI! */
7165 if (dynamic_segment
== NULL
)
7166 /* No information available. */
7169 for (entry
= dynamic_segment
; entry
->d_tag
!= DT_NULL
; ++entry
)
7170 switch (entry
->d_tag
)
7172 case DT_MIPS_LIBLIST
:
7173 liblist_offset
= entry
->d_un
.d_val
- loadaddr
;
7175 case DT_MIPS_LIBLISTNO
:
7176 liblistno
= entry
->d_un
.d_val
;
7178 case DT_MIPS_OPTIONS
:
7179 options_offset
= entry
->d_un
.d_val
- loadaddr
;
7181 case DT_MIPS_CONFLICT
:
7182 conflicts_offset
= entry
->d_un
.d_val
- loadaddr
;
7184 case DT_MIPS_CONFLICTNO
:
7185 conflictsno
= entry
->d_un
.d_val
;
7191 if (liblist_offset
!= 0 && liblistno
!= 0 && do_dynamic
)
7193 Elf32_External_Lib
* elib
;
7196 GET_DATA_ALLOC (liblist_offset
, liblistno
* sizeof (Elf32_External_Lib
),
7197 elib
, Elf32_External_Lib
*, "liblist");
7199 printf ("\nSection '.liblist' contains %lu entries:\n",
7200 (unsigned long) liblistno
);
7201 fputs (" Library Time Stamp Checksum Version Flags\n",
7204 for (cnt
= 0; cnt
< liblistno
; ++cnt
)
7211 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
7212 time
= BYTE_GET (elib
[cnt
].l_time_stamp
);
7213 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
7214 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
7215 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
7217 tmp
= gmtime (&time
);
7218 sprintf (timebuf
, "%04u-%02u-%02uT%02u:%02u:%02u",
7219 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
7220 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
7222 printf ("%3lu: %-20s %s %#10lx %-7ld", (unsigned long) cnt
,
7223 dynamic_strings
+ liblist
.l_name
, timebuf
,
7224 liblist
.l_checksum
, liblist
.l_version
);
7226 if (liblist
.l_flags
== 0)
7237 { " EXACT_MATCH", LL_EXACT_MATCH
},
7238 { " IGNORE_INT_VER", LL_IGNORE_INT_VER
},
7239 { " REQUIRE_MINOR", LL_REQUIRE_MINOR
},
7240 { " EXPORTS", LL_EXPORTS
},
7241 { " DELAY_LOAD", LL_DELAY_LOAD
},
7242 { " DELTA", LL_DELTA
}
7244 int flags
= liblist
.l_flags
;
7248 fcnt
< sizeof (l_flags_vals
) / sizeof (l_flags_vals
[0]);
7250 if ((flags
& l_flags_vals
[fcnt
].bit
) != 0)
7252 fputs (l_flags_vals
[fcnt
].name
, stdout
);
7253 flags
^= l_flags_vals
[fcnt
].bit
;
7256 printf (" %#x", (unsigned int) flags
);
7265 if (options_offset
!= 0)
7267 Elf_External_Options
* eopt
;
7268 Elf_Internal_Shdr
* sect
= section_headers
;
7269 Elf_Internal_Options
* iopt
;
7270 Elf_Internal_Options
* option
;
7274 /* Find the section header so that we get the size. */
7275 while (sect
->sh_type
!= SHT_MIPS_OPTIONS
)
7278 GET_DATA_ALLOC (options_offset
, sect
->sh_size
, eopt
,
7279 Elf_External_Options
*, "options");
7281 iopt
= (Elf_Internal_Options
*) malloc ((sect
->sh_size
/ sizeof (eopt
))
7285 error (_("Out of memory"));
7292 while (offset
< sect
->sh_size
)
7294 Elf_External_Options
* eoption
;
7296 eoption
= (Elf_External_Options
*) ((char *) eopt
+ offset
);
7298 option
->kind
= BYTE_GET (eoption
->kind
);
7299 option
->size
= BYTE_GET (eoption
->size
);
7300 option
->section
= BYTE_GET (eoption
->section
);
7301 option
->info
= BYTE_GET (eoption
->info
);
7303 offset
+= option
->size
;
7309 printf (_("\nSection '%s' contains %d entries:\n"),
7310 string_table
+ sect
->sh_name
, cnt
);
7318 switch (option
->kind
)
7321 /* This shouldn't happen. */
7322 printf (" NULL %d %lx", option
->section
, option
->info
);
7325 printf (" REGINFO ");
7326 if (elf_header
.e_machine
== EM_MIPS
)
7329 Elf32_External_RegInfo
*ereg
;
7330 Elf32_RegInfo reginfo
;
7332 ereg
= (Elf32_External_RegInfo
*) (option
+ 1);
7333 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
7334 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
7335 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
7336 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
7337 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
7338 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
7340 printf ("GPR %08lx GP 0x%lx\n",
7342 (unsigned long) reginfo
.ri_gp_value
);
7343 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
7344 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
7345 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
7350 Elf64_External_RegInfo
* ereg
;
7351 Elf64_Internal_RegInfo reginfo
;
7353 ereg
= (Elf64_External_RegInfo
*) (option
+ 1);
7354 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
7355 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
7356 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
7357 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
7358 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
7359 reginfo
.ri_gp_value
= BYTE_GET8 (ereg
->ri_gp_value
);
7361 printf ("GPR %08lx GP 0x",
7362 reginfo
.ri_gprmask
);
7363 printf_vma (reginfo
.ri_gp_value
);
7366 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
7367 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
7368 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
7372 case ODK_EXCEPTIONS
:
7373 fputs (" EXCEPTIONS fpe_min(", stdout
);
7374 process_mips_fpe_exception (option
->info
& OEX_FPU_MIN
);
7375 fputs (") fpe_max(", stdout
);
7376 process_mips_fpe_exception ((option
->info
& OEX_FPU_MAX
) >> 8);
7377 fputs (")", stdout
);
7379 if (option
->info
& OEX_PAGE0
)
7380 fputs (" PAGE0", stdout
);
7381 if (option
->info
& OEX_SMM
)
7382 fputs (" SMM", stdout
);
7383 if (option
->info
& OEX_FPDBUG
)
7384 fputs (" FPDBUG", stdout
);
7385 if (option
->info
& OEX_DISMISS
)
7386 fputs (" DISMISS", stdout
);
7389 fputs (" PAD ", stdout
);
7390 if (option
->info
& OPAD_PREFIX
)
7391 fputs (" PREFIX", stdout
);
7392 if (option
->info
& OPAD_POSTFIX
)
7393 fputs (" POSTFIX", stdout
);
7394 if (option
->info
& OPAD_SYMBOL
)
7395 fputs (" SYMBOL", stdout
);
7398 fputs (" HWPATCH ", stdout
);
7399 if (option
->info
& OHW_R4KEOP
)
7400 fputs (" R4KEOP", stdout
);
7401 if (option
->info
& OHW_R8KPFETCH
)
7402 fputs (" R8KPFETCH", stdout
);
7403 if (option
->info
& OHW_R5KEOP
)
7404 fputs (" R5KEOP", stdout
);
7405 if (option
->info
& OHW_R5KCVTL
)
7406 fputs (" R5KCVTL", stdout
);
7409 fputs (" FILL ", stdout
);
7410 /* XXX Print content of info word? */
7413 fputs (" TAGS ", stdout
);
7414 /* XXX Print content of info word? */
7417 fputs (" HWAND ", stdout
);
7418 if (option
->info
& OHWA0_R4KEOP_CHECKED
)
7419 fputs (" R4KEOP_CHECKED", stdout
);
7420 if (option
->info
& OHWA0_R4KEOP_CLEAN
)
7421 fputs (" R4KEOP_CLEAN", stdout
);
7424 fputs (" HWOR ", stdout
);
7425 if (option
->info
& OHWA0_R4KEOP_CHECKED
)
7426 fputs (" R4KEOP_CHECKED", stdout
);
7427 if (option
->info
& OHWA0_R4KEOP_CLEAN
)
7428 fputs (" R4KEOP_CLEAN", stdout
);
7431 printf (" GP_GROUP %#06lx self-contained %#06lx",
7432 option
->info
& OGP_GROUP
,
7433 (option
->info
& OGP_SELF
) >> 16);
7436 printf (" IDENT %#06lx self-contained %#06lx",
7437 option
->info
& OGP_GROUP
,
7438 (option
->info
& OGP_SELF
) >> 16);
7441 /* This shouldn't happen. */
7442 printf (" %3d ??? %d %lx",
7443 option
->kind
, option
->section
, option
->info
);
7447 len
= sizeof (*eopt
);
7448 while (len
< option
->size
)
7449 if (((char *) option
)[len
] >= ' '
7450 && ((char *) option
)[len
] < 0x7f)
7451 printf ("%c", ((char *) option
)[len
++]);
7453 printf ("\\%03o", ((char *) option
)[len
++]);
7455 fputs ("\n", stdout
);
7462 if (conflicts_offset
!= 0 && conflictsno
!= 0)
7464 Elf32_External_Conflict
* econf32
;
7465 Elf64_External_Conflict
* econf64
;
7466 Elf32_Conflict
* iconf
;
7469 if (dynamic_symbols
== NULL
)
7471 error (_("conflict list with without table"));
7475 iconf
= (Elf32_Conflict
*) malloc (conflictsno
* sizeof (*iconf
));
7478 error (_("Out of memory"));
7484 GET_DATA_ALLOC (conflicts_offset
, conflictsno
* sizeof (*econf32
),
7485 econf32
, Elf32_External_Conflict
*, "conflict");
7487 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
7488 iconf
[cnt
] = BYTE_GET (econf32
[cnt
]);
7492 GET_DATA_ALLOC (conflicts_offset
, conflictsno
* sizeof (*econf64
),
7493 econf64
, Elf64_External_Conflict
*, "conflict");
7495 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
7496 iconf
[cnt
] = BYTE_GET (econf64
[cnt
]);
7499 printf (_("\nSection '.conflict' contains %d entries:\n"), conflictsno
);
7500 puts (_(" Num: Index Value Name"));
7502 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
7504 Elf_Internal_Sym
* psym
= &dynamic_symbols
[iconf
[cnt
]];
7506 printf ("%5lu: %8lu ", (unsigned long) cnt
, iconf
[cnt
]);
7507 print_vma (psym
->st_value
, FULL_HEX
);
7508 printf (" %s\n", dynamic_strings
+ psym
->st_name
);
7518 get_note_type (e_type
)
7521 static char buff
[64];
7525 case NT_PRSTATUS
: return _("NT_PRSTATUS (prstatus structure)");
7526 case NT_FPREGSET
: return _("NT_FPREGSET (floating point registers)");
7527 case NT_PRPSINFO
: return _("NT_PRPSINFO (prpsinfo structure)");
7528 case NT_TASKSTRUCT
: return _("NT_TASKSTRUCT (task structure)");
7529 case NT_PRXFPREG
: return _("NT_PRXFPREG (user_xfpregs structure)");
7530 case NT_PSTATUS
: return _("NT_PSTATUS (pstatus structure)");
7531 case NT_FPREGS
: return _("NT_FPREGS (floating point registers)");
7532 case NT_PSINFO
: return _("NT_PSINFO (psinfo structure)");
7533 case NT_LWPSTATUS
: return _("NT_LWPSTATUS (lwpstatus_t structure)");
7534 case NT_LWPSINFO
: return _("NT_LWPSINFO (lwpsinfo_t structure)");
7535 case NT_WIN32PSTATUS
: return _("NT_WIN32PSTATUS (win32_pstatus strcuture)");
7537 sprintf (buff
, _("Unknown note type: (0x%08x)"), e_type
);
7542 /* Note that by the ELF standard, the name field is already null byte
7543 terminated, and namesz includes the terminating null byte.
7544 I.E. the value of namesz for the name "FSF" is 4.
7546 If the value of namesz is zero, there is no name present. */
7548 process_note (pnote
)
7549 Elf32_Internal_Note
* pnote
;
7551 printf (" %s\t\t0x%08lx\t%s\n",
7552 pnote
->namesz
? pnote
->namedata
: "(NONE)",
7553 pnote
->descsz
, get_note_type (pnote
->type
));
7559 process_corefile_note_segment (file
, offset
, length
)
7564 Elf_External_Note
* pnotes
;
7565 Elf_External_Note
* external
;
7571 GET_DATA_ALLOC (offset
, length
, pnotes
, Elf_External_Note
*, "notes");
7575 printf (_("\nNotes at offset 0x%08lx with length 0x%08lx:\n"),
7576 (unsigned long) offset
, (unsigned long) length
);
7577 printf (_(" Owner\t\tData size\tDescription\n"));
7579 while (external
< (Elf_External_Note
*)((char *) pnotes
+ length
))
7581 Elf32_Internal_Note inote
;
7584 inote
.type
= BYTE_GET (external
->type
);
7585 inote
.namesz
= BYTE_GET (external
->namesz
);
7586 inote
.namedata
= external
->name
;
7587 inote
.descsz
= BYTE_GET (external
->descsz
);
7588 inote
.descdata
= inote
.namedata
+ align_power (inote
.namesz
, 2);
7589 inote
.descpos
= offset
+ (inote
.descdata
- (char *) pnotes
);
7591 external
= (Elf_External_Note
*)(inote
.descdata
+ align_power (inote
.descsz
, 2));
7593 /* Verify that name is null terminated. It appears that at least
7594 one version of Linux (RedHat 6.0) generates corefiles that don't
7595 comply with the ELF spec by failing to include the null byte in
7597 if (inote
.namedata
[inote
.namesz
] != '\0')
7599 temp
= malloc (inote
.namesz
+ 1);
7603 error (_("Out of memory\n"));
7608 strncpy (temp
, inote
.namedata
, inote
.namesz
);
7609 temp
[inote
.namesz
] = 0;
7611 /* warn (_("'%s' NOTE name not properly null terminated\n"), temp); */
7612 inote
.namedata
= temp
;
7615 res
&= process_note (& inote
);
7630 process_corefile_note_segments (file
)
7633 Elf_Internal_Phdr
* program_headers
;
7634 Elf_Internal_Phdr
* segment
;
7638 program_headers
= (Elf_Internal_Phdr
*) malloc
7639 (elf_header
.e_phnum
* sizeof (Elf_Internal_Phdr
));
7641 if (program_headers
== NULL
)
7643 error (_("Out of memory\n"));
7648 i
= get_32bit_program_headers (file
, program_headers
);
7650 i
= get_64bit_program_headers (file
, program_headers
);
7654 free (program_headers
);
7658 for (i
= 0, segment
= program_headers
;
7659 i
< elf_header
.e_phnum
;
7662 if (segment
->p_type
== PT_NOTE
)
7663 res
&= process_corefile_note_segment (file
,
7664 (bfd_vma
) segment
->p_offset
,
7665 (bfd_vma
) segment
->p_filesz
);
7668 free (program_headers
);
7674 process_corefile_contents (file
)
7677 /* If we have not been asked to display the notes then do nothing. */
7681 /* If file is not a core file then exit. */
7682 if (elf_header
.e_type
!= ET_CORE
)
7685 /* No program headers means no NOTE segment. */
7686 if (elf_header
.e_phnum
== 0)
7688 printf (_("No note segments present in the core file.\n"));
7692 return process_corefile_note_segments (file
);
7696 process_arch_specific (file
)
7702 switch (elf_header
.e_machine
)
7705 case EM_MIPS_RS4_BE
:
7706 return process_mips_specific (file
);
7715 get_file_header (file
)
7718 /* Read in the identity array. */
7719 if (fread (elf_header
.e_ident
, EI_NIDENT
, 1, file
) != 1)
7722 /* Determine how to read the rest of the header. */
7723 switch (elf_header
.e_ident
[EI_DATA
])
7725 default: /* fall through */
7726 case ELFDATANONE
: /* fall through */
7727 case ELFDATA2LSB
: byte_get
= byte_get_little_endian
; break;
7728 case ELFDATA2MSB
: byte_get
= byte_get_big_endian
; break;
7731 /* For now we only support 32 bit and 64 bit ELF files. */
7732 is_32bit_elf
= (elf_header
.e_ident
[EI_CLASS
] != ELFCLASS64
);
7734 /* Read in the rest of the header. */
7737 Elf32_External_Ehdr ehdr32
;
7739 if (fread (ehdr32
.e_type
, sizeof (ehdr32
) - EI_NIDENT
, 1, file
) != 1)
7742 elf_header
.e_type
= BYTE_GET (ehdr32
.e_type
);
7743 elf_header
.e_machine
= BYTE_GET (ehdr32
.e_machine
);
7744 elf_header
.e_version
= BYTE_GET (ehdr32
.e_version
);
7745 elf_header
.e_entry
= BYTE_GET (ehdr32
.e_entry
);
7746 elf_header
.e_phoff
= BYTE_GET (ehdr32
.e_phoff
);
7747 elf_header
.e_shoff
= BYTE_GET (ehdr32
.e_shoff
);
7748 elf_header
.e_flags
= BYTE_GET (ehdr32
.e_flags
);
7749 elf_header
.e_ehsize
= BYTE_GET (ehdr32
.e_ehsize
);
7750 elf_header
.e_phentsize
= BYTE_GET (ehdr32
.e_phentsize
);
7751 elf_header
.e_phnum
= BYTE_GET (ehdr32
.e_phnum
);
7752 elf_header
.e_shentsize
= BYTE_GET (ehdr32
.e_shentsize
);
7753 elf_header
.e_shnum
= BYTE_GET (ehdr32
.e_shnum
);
7754 elf_header
.e_shstrndx
= BYTE_GET (ehdr32
.e_shstrndx
);
7758 Elf64_External_Ehdr ehdr64
;
7760 /* If we have been compiled with sizeof (bfd_vma) == 4, then
7761 we will not be able to cope with the 64bit data found in
7762 64 ELF files. Detect this now and abort before we start
7763 overwritting things. */
7764 if (sizeof (bfd_vma
) < 8)
7766 error (_("This instance of readelf has been built without support for a\n"));
7767 error (_("64 bit data type and so it cannot read 64 bit ELF files.\n"));
7771 if (fread (ehdr64
.e_type
, sizeof (ehdr64
) - EI_NIDENT
, 1, file
) != 1)
7774 elf_header
.e_type
= BYTE_GET (ehdr64
.e_type
);
7775 elf_header
.e_machine
= BYTE_GET (ehdr64
.e_machine
);
7776 elf_header
.e_version
= BYTE_GET (ehdr64
.e_version
);
7777 elf_header
.e_entry
= BYTE_GET8 (ehdr64
.e_entry
);
7778 elf_header
.e_phoff
= BYTE_GET8 (ehdr64
.e_phoff
);
7779 elf_header
.e_shoff
= BYTE_GET8 (ehdr64
.e_shoff
);
7780 elf_header
.e_flags
= BYTE_GET (ehdr64
.e_flags
);
7781 elf_header
.e_ehsize
= BYTE_GET (ehdr64
.e_ehsize
);
7782 elf_header
.e_phentsize
= BYTE_GET (ehdr64
.e_phentsize
);
7783 elf_header
.e_phnum
= BYTE_GET (ehdr64
.e_phnum
);
7784 elf_header
.e_shentsize
= BYTE_GET (ehdr64
.e_shentsize
);
7785 elf_header
.e_shnum
= BYTE_GET (ehdr64
.e_shnum
);
7786 elf_header
.e_shstrndx
= BYTE_GET (ehdr64
.e_shstrndx
);
7793 process_file (file_name
)
7797 struct stat statbuf
;
7800 if (stat (file_name
, & statbuf
) < 0)
7802 error (_("Cannot stat input file %s.\n"), file_name
);
7806 file
= fopen (file_name
, "rb");
7809 error (_("Input file %s not found.\n"), file_name
);
7813 if (! get_file_header (file
))
7815 error (_("%s: Failed to read file header\n"), file_name
);
7820 /* Initialise per file variables. */
7821 for (i
= NUM_ELEM (version_info
); i
--;)
7822 version_info
[i
] = 0;
7824 for (i
= NUM_ELEM (dynamic_info
); i
--;)
7825 dynamic_info
[i
] = 0;
7827 /* Process the file. */
7829 printf (_("\nFile: %s\n"), file_name
);
7831 if (! process_file_header ())
7837 process_section_headers (file
);
7839 process_program_headers (file
);
7841 process_dynamic_segment (file
);
7843 process_relocs (file
);
7845 process_symbol_table (file
);
7847 process_syminfo (file
);
7849 process_version_sections (file
);
7851 process_section_contents (file
);
7853 process_corefile_contents (file
);
7855 process_arch_specific (file
);
7859 if (section_headers
)
7861 free (section_headers
);
7862 section_headers
= NULL
;
7867 free (string_table
);
7868 string_table
= NULL
;
7871 if (dynamic_strings
)
7873 free (dynamic_strings
);
7874 dynamic_strings
= NULL
;
7877 if (dynamic_symbols
)
7879 free (dynamic_symbols
);
7880 dynamic_symbols
= NULL
;
7881 num_dynamic_syms
= 0;
7884 if (dynamic_syminfo
)
7886 free (dynamic_syminfo
);
7887 dynamic_syminfo
= NULL
;
7891 #ifdef SUPPORT_DISASSEMBLY
7892 /* Needed by the i386 disassembler. For extra credit, someone could
7893 fix this so that we insert symbolic addresses here, esp for GOT/PLT
7897 print_address (unsigned int addr
, FILE * outfile
)
7899 fprintf (outfile
,"0x%8.8x", addr
);
7902 /* Needed by the i386 disassembler. */
7904 db_task_printsym (unsigned int addr
)
7906 print_address (addr
, stderr
);
7915 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
7916 setlocale (LC_MESSAGES
, "");
7918 bindtextdomain (PACKAGE
, LOCALEDIR
);
7919 textdomain (PACKAGE
);
7921 parse_args (argc
, argv
);
7923 if (optind
< (argc
- 1))
7926 while (optind
< argc
)
7927 process_file (argv
[optind
++]);
7929 if (dump_sects
!= NULL
)